python

How to perform a signed PUT request with OAuth in Python

How is this meant to work? Where are all the oauth_* values meant to go if not in an encoded body like a POST request? In what form do you sign it? All the Python OAuth libraries I can find only support GET and POST. Does anyone know any that support all methods? ...

Python XML need help with programming error

Hi, I am having the below code. import xml.dom.minidom def get_a_document(name): return xml.dom.minidom.parse(name) doc = get_a_document("sources.xml") sources = doc.childNodes[1] for e in sources.childNodes: if e.nodeType == e.ELEMENT_NODE and e.localName == "source": for source in e.childNodes: ...

Python, dynamically invoke script

I want to run a python script from within another. By within I mean any state changes from the child script effect the parent's state. So if a variable is set in the child, it gets changed in the parent. Normally you could do something like import module But the issue is here the child script being run is an argument to the parent s...

Some doubts on implementing custom error pages in Web2Py

I'm trying to implement a decorator for custom error pages in web2py as per one of the haiti Todos. Ref - http://web2py.com/AlterEgo/default/show/75 I'm trying to keep it as a module in /modules directory so that I can import it into the controllers and place the decorator appropriately. I have kept error handling decorator as /modules...

Python virtualbox

how can i start a virtual machine from virtualbox as HEADLESS using pyvb modules???? pls help me.... ...

Models in database speed vs static dictionaries speed

I have a need for some kind of information that is in essence static. There is not much of this information, but alot of objects will use that information. Since there is not a lot of that information (few dictionaries and some lists), I thought that I have 2 options - create models for holding that information in the database or write ...

Which GUI framework to learn when you know scripting and HCI

I have some knowledge about Human computer interaction and some basic knowledge programming scripts (Python) that run from start to finish and automate some tasks I want to do or calculations. In the past I built interfaces in HTML with PHP behind it. I would like my python scripts to evolve from the command line and build some applicat...

SQLite or flat text file?

I process a lot of text/data that I exchange between Python, R, and sometimes Matlab. My go-to is the flat text file, but also use SQLite occasionally to store the data and access from each program (not Matlab yet though). I don't use GROUPBY, AVG, etc. in SQL as much as I do these operations in R, so I don't necessarily require the dat...

How to detect mouse and keyboard inactivity in linux

I am developing an app on python which will check for user inactivity. Is there a way to check for key press and mouse move events in linux? ...

Sending MESSAGE to a person on facebook using python

I want to make a script that can be used to send messages to our friends on facebook. How do I proceed? Which is the best module to use? ...

Integration testing: Start a blocking server during `unittest.setUp` before testing it?

I'm writing a service using Thrift and need to apply some tests to ensure that it operates/responds as expected. To accomplish this, the most robust approach seems to be to use the unittest module. I'd like to start the service in "test" mode (starts on a specific "test" port, uses "test" data, etc) from directly within the unit test's...

Calculating very large exponents in python

Dear All, Currently i am simulating my cryptographic scheme to test it. I have developed the code but i am stuck at one point. I am trying to take: g**x where g = 256 bit number x = 256 bit number Python hangs at this point, i have read alot of forums, threads etcc but only come to the conclusion that python hangs, as its hard fo...

python json loads and unicode

I have the following case where I get the result of UTF-8 encoded HTTP response. I want to load the response content(JSON). However I don't know why I have to do 2 json.loads so that I get the final list: result = urllib2.urlopen(req).read() print result, type(result) #=> "[{\"pk\": 66, \"model\": \"core.job\", \"fields\": {\"customer\"...

Suppose I have this loop in Django...how do I display this?

{% for p in profiles %} <div class="result"> {{ p.first_name }} </div> {% endfor %} Suppose I have 1000 of these, in a huge list. How would I make this code appear every 15 times? <div class="menu">abc</div> ...

replace multiple string in a file

Hi, I am trying to replace multiple string in a file. fp1 = open(final,"w") data = open(initial).read() for key, value in mydict.items(): fp1.write(re.sub(key,value, data) fp1.close() But only my last key value get replaced. how can I replace all the key,value in the file. Is there any better ways of replacing multiple string in a...

How do you run a python script from within notepad++?

When I'm using textmate, I simply hit "apple+r" and the program gets interpreted. How can I run a program from within notepad++? I see that F5 is for "Run", but pointing that to Python.exe simply opens up a terminal with python running. It does not run my script. ...

Do python packages (multi-file modules) behave exactly as one big module?

I've just read an article that supposedly introduced me to a new concept: Up to now I was sure that python packages (i.e directories with an __init__.py file) behave exactly the same as java packages, that is - little namespaces to help arrange the code (minus java's "package" scoping). But, according to this link: http://diveintopython3...

SQLite, python, unicode, and non-utf data

I started by trying to store strings in sqlite using python, and got the message: sqlite3.ProgrammingError: You must not use 8-bit bytestrings unless you use a text_factory that can interpret 8-bit bytestrings (like text_factory = str). It is highly recommended that you instead just switch your application to Unicode stri...

pyqt signal problem

Hi! I'm working on a plugin for Avogadro (chemistry software) that uses pyqt. I've some problem with connecting a method to the clicked signal of a button. I've my class: class Controller(object): def __init__(self): self.ui = MyDialog() # self.ui.run is a QPushButton self.ui.run.clicked.connect(self.on_run_click) ...

Python: Simple Dictionary referencing Problem

I have a simple problem that i cannot solve. I have a dictionary: aa = {'ALA':'A'} test = 'ALA' I'm have trouble writing code where that value from test is taken and referenced in the dictionary aa and 'A' is printed. I'm assuming i would have to use a for loop? something like... for i in test: if i in aa: print i I un...