How do i use the with statement in this case?
f_spam = open(spam,'r')
f_bar = open(eggs,'r')
...
do something with these files
...
f_spam.close()
f_bar.close()
Files number could be greater than two.
...
The scenario I want two different protocols interact with each other is as below:
A and B is two different protocols.
First A will interact with the server and retrieve some values.
Only after A finishes retrieving the values , B will start to interact with the server.
Now my problem is that is there an elegant way to initial B when A ...
Here's my code:
import cx_Oracle
conn = cx_Oracle.connect(usr, pwd, url)
cursor = conn.cursor()
cursor.execute("UPDATE SO SET STATUS='PE' WHERE ID='100'")
conn.commit()
If I remove the conn.commit(), the table isn't updated. But for select statements, I don't need that conn.commit(). I'm curious why?
...
I am trying to automate a downloading process. In this I want to know, whether a particular file's save is completed or not. The scenario is like this.
Open a site address using either Chrome or Firefox (any browser)
Save the page to disk using 'Crtl + S' (I work on windows)
Now if the page is very big, then it takes few seconds to sav...
I am developing a small application for home use in Python. It is supposed to act as a slide show screensaver, but also as a primitive image manager. I have the slide show and image manager aspects covered (I am using Tkinter), but I haven't implemented the screensaver bit yet. So, starting the app from the command line works fine.
I am...
I have 3 files. xxx which imports xxx2 and xxx2 imports xxx3 which one raises OppsError exception.
xxx3.py:
class OppsError(Exception):pass
def go():
raise OppsError()
xxx2.py:
import xxx3
xxx3.go()
xxx.py:
try:
import xxx2
except xxx3.OppsError:
print 'ops'
When i run xxx.py i get error NameError: name 'xxx3' is n...
In Python 2.x, using backticks to get decimal string from int object is Horrible?
Because backticks are repr(), not str()? I have noticed that when I answering this question.
In Python source, they have same function in Python source, intobject.c
(reprfunc)int_to_decimal_string, /* tp_repr */
....
(reprfunc)int_to_decimal_s...
sometimes i have to send a message to a specific ip and sometimes have to broadcast the message to all ip's in my network. at the other side i have to distinguish between a broadcasted and a normal one, but recvfrom() just returns the address the message came from,
and there is no difference between them, can any one help me distinguish ...
Hi,
Can someone gives me an example of how to save a 2-d matrix in a file and reloading it for furthur use?
thanks
...
How to convert pyunicodeobject type to pybytesobject type?
Example:
function(PyBytesObject* byteobj){
....operation..
}
PyUnicodeObject* Uniobj;
function((PyBytesObject*) Uniobj);
got a bus error as a result.
...
In asynchronous environments, threading.local is not guaranteed to be context-local anymore, because several contexts may coexist within a single thread. Most asynchronous frameworks (gevent, eventlet) provide a get_current_context() functionality to identify the current context. Some offer a way to monkey-patch threading.local so it is ...
Hi,
I've installed PL/Python on my postgresql server under postgres privilleges:
netherlands=# CREATE PROCEDURAL LANGUAGE plpythonu;
CREATE LANGUAGE
Now I need to grant permissions so I can use it as a normal user:
netherlands=# GRANT ALL ON LANGUAGE plpythonu TO adam;
ERROR: language "plpythonu" is not trusted
HINT: Only su...
Am surprised there's 3 different forms: RawConfigParser, SafeConfigParser and ConfigParser. I read the differences but why isn't everyone using SafeConfigParser, since it seems, well, safe? I can understand that in the case for Python 2 that the other two were kept for backward compatibility.
...
I need to write authentication function with asynchronous callback from remote Auth API. Simple authentication with login is working well, but authorization with cookie key, does not work. It should checks if in cookies present key "lp_login", fetch API url like async and execute on_response function.
The code almost works, but I see tw...
Hi,
I'm new to Python (from Java+Ant) and was wondering if someone could detail how to best use Fabric+Pip+Virtualenv to set up a Python web application package skeleton.
The end goal is to be able to do any of the following with a single command:
Set up a development environment on a fresh dev box (installing all deps)
Run all tests...
I'm doing some indexing and memory is sufficient but CPU isn't. So I have one huge dictionary and then a smaller dictionary I'm merging into the bigger one:
big_dict = {"the" : {"1" : 1, "2" : 1, "3" : 1, "4" : 1, "5" : 1}}
smaller_dict = {"the" : {"6" : 1, "7" : 1}}
#after merging
resulting_dict = {"the" : {"1" : 1, "2" : 1, "3" : 1, "...
How can you check the type of a many-to-many-field in django?
I wanted to do it this way:
import django
field.__class__ == django.db.models.fields.related.ManyRelatedManager
This doesn't work, because the class ManyRelatedManager can't be found.
But if i do field.__class__ the output is django.db.models.fields.related.ManyRelatedManager...
I am developing a website which is aimed at being a GUI for several image processing algorithms (referred to as 'tasks').
At the moment, only one of these algorithms is finished, but there are more to come (which will have a similar, but not quite the same, workflow)
Basically, the algorithm works as follows (not that it matters a lot,...
How can I set the y axis range of the second subplot to e.g. [0,1000] ?
The FFT plot of my data (a column in a text file) results in a (inf.?) spike so that the actual data is not visible.
pylab.ylim([0,1000])
has no effect, unfortunately. This is the whole script:
# based on http://www.swharden.com/blog/2009-01-21-signal-filtering-w...
Is there a way to test the html from the response of:
response = self.client.get('/user/login/')
I want a detailed check like input ids, and other attributes. Also, how about sessions that has been set? is it possible to check their values in the test?
...