content stringlengths 85 101k | title stringlengths 0 150 | question stringlengths 15 48k | answers list | answers_scores list | non_answers list | non_answers_scores list | tags list | name stringlengths 35 137 |
|---|---|---|---|---|---|---|---|---|
Q:
Perl equivalent of (Python-) list comprehension
I'm looking for ways to express this Python snippet in Perl:
data = {"A": None, "B": "yes", "C": None}
key_list = [k for k in data if data[k]]
# in this case the same as filter(lambda k: data[k], data) but let's ignore that
So looking at it one way, I just want th... | Perl equivalent of (Python-) list comprehension | I'm looking for ways to express this Python snippet in Perl:
data = {"A": None, "B": "yes", "C": None}
key_list = [k for k in data if data[k]]
# in this case the same as filter(lambda k: data[k], data) but let's ignore that
So looking at it one way, I just want the keys where the values are None or undef. Looking at... | [
"I think you want grep:\n#!/usr/bin/env perl\nuse strict;\nuse warnings;\n\nmy %data = ( A => undef, B => 'yes', C => undef );\n\nmy @keys = grep { defined $data{$_} } keys %data;\n\nprint \"Key: $_\\n\" for @keys;\n\nI also think that I type too slowly, and that I should reload the page before posting answers. By ... | [
20,
13,
6
] | [] | [] | [
"list_comprehension",
"perl",
"python"
] | stackoverflow_0001112444_list_comprehension_perl_python.txt |
Q:
Safety of Python 'eval' For List Deserialization
Are there any security exploits that could occur in this scenario:
eval(repr(unsanitized_user_input), {"__builtins__": None}, {"True":True, "False":False})
where unsanitized_user_input is a str object. The string is user-generated and could be nasty. Assuming our w... | Safety of Python 'eval' For List Deserialization | Are there any security exploits that could occur in this scenario:
eval(repr(unsanitized_user_input), {"__builtins__": None}, {"True":True, "False":False})
where unsanitized_user_input is a str object. The string is user-generated and could be nasty. Assuming our web framework hasn't failed us, it's a real honest-to-g... | [
"It is indeed dangerous and the safest alternative is ast.literal_eval (see the ast module in the standard library). You can of course build and alter an ast to provide e.g. evaluation of variables and the like before you eval the resulting AST (when it's down to literals).\nThe possible exploit of eval starts with... | [
19,
8,
5,
3,
1
] | [] | [] | [
"eval",
"python"
] | stackoverflow_0001112665_eval_python.txt |
Q:
Is it possible to pass a variable out of a pdb session into the original interactive session?
I am using pdb to examine a script having called run -d in an ipython session.
It would be useful to be able to plot some of the variables but I need them in the main ipython environment in order to do that.
So what I a... | Is it possible to pass a variable out of a pdb session into the original interactive session? | I am using pdb to examine a script having called run -d in an ipython session.
It would be useful to be able to plot some of the variables but I need them in the main ipython environment in order to do that.
So what I am looking for is some way to make a variable available back in the main interactive session after I... | [
"Per ipython's docs, and also a run? command from the ipython prompt,\n\nafter execution, the IPython\n interactive namespace gets\n updated with all variables defined in the program (except for __name__\n and sys.argv)\n\nBy \"defined in the program\" (a slightly sloppy use of terms), it doesn't mean \"... | [
3
] | [] | [] | [
"debugging",
"ipython",
"python"
] | stackoverflow_0001114080_debugging_ipython_python.txt |
Q:
Does main.py or app.yaml determine the URL used by the App Engine cron task in this example?
In this sample code the URL of the app seems to be determined by this line within the app:
application = webapp.WSGIApplication([('/mailjob', MailJob)], debug=True)
but also by this line within the app handler of app.yaml... | Does main.py or app.yaml determine the URL used by the App Engine cron task in this example? | In this sample code the URL of the app seems to be determined by this line within the app:
application = webapp.WSGIApplication([('/mailjob', MailJob)], debug=True)
but also by this line within the app handler of app.yaml:
- url: /.*
script: main.py
However, the URL of the cron task is set by this line:
url: /tasks... | [
"You could do it like this:\napp.yaml\napplication: yourappname\nversion: 1\nruntime: python\napi_version: 1\n\nhandlers:\n\n- url: /tasks/.*\n script: main.py\n\ncron.yaml\ncron:\n - description: daily mailing job\n url: /tasks/summary\n schedule: every 24 hours\n\nmain.py\n#!/usr/bin/env python \n\nimp... | [
3,
1
] | [] | [] | [
"cron",
"google_app_engine",
"python",
"url_routing"
] | stackoverflow_0001114601_cron_google_app_engine_python_url_routing.txt |
Q:
Python converts string into tuple
Example:
regular_string = "%s %s" % ("foo", "bar")
result = {}
result["somekey"] = regular_string,
print result["somekey"]
# ('foo bar',)
Why result["somekey"] tuple now not string?
A:
Because of comma at the end of the line.
A:
When you write
result["somekey"] = regular_st... | Python converts string into tuple | Example:
regular_string = "%s %s" % ("foo", "bar")
result = {}
result["somekey"] = regular_string,
print result["somekey"]
# ('foo bar',)
Why result["somekey"] tuple now not string?
| [
"Because of comma at the end of the line.\n",
"When you write\nresult[\"somekey\"] = regular_string,\n\nPython reads\nresult[\"somekey\"] = (regular_string,)\n\n(x,) is the syntax for a tuple with a single element. Parentheses are assumed. And you really end up putting a tuple, instead of a string there.\n"
] | [
16,
9
] | [] | [] | [
"python"
] | stackoverflow_0001114813_python.txt |
Q:
How to set default button in PyGTK?
I have very simple window where I have 2 buttons - one for cancel, one for apply. How to set the button for apply as default one? (When I press enter, "apply" button is pressed)
However, I want to set focus to the first input widget (I can't use grab_focus() on the button)
Any s... | How to set default button in PyGTK? | I have very simple window where I have 2 buttons - one for cancel, one for apply. How to set the button for apply as default one? (When I press enter, "apply" button is pressed)
However, I want to set focus to the first input widget (I can't use grab_focus() on the button)
Any suggestions?
Edit:
After wuub's answer it ... | [
"http://www.pygtk.org/docs/pygtk/class-gtkdialog.html#method-gtkdialog--set-default-response\nhttp://www.pygtk.org/docs/pygtk/class-gtkwindow.html#method-gtkwindow--set-default\n"
] | [
4
] | [] | [] | [
"pygtk",
"python",
"user_interface"
] | stackoverflow_0001114568_pygtk_python_user_interface.txt |
Q:
Sorting disk I/O errors in Python
How do I sort out (distinguish) an error derived from a "disk full condition" from "trying to write to a read-only file system"?
I don't want to fill my HD to find out :)
What I want is to know who to catch each exception, so my code can say something to the user when he is trying... | Sorting disk I/O errors in Python | How do I sort out (distinguish) an error derived from a "disk full condition" from "trying to write to a read-only file system"?
I don't want to fill my HD to find out :)
What I want is to know who to catch each exception, so my code can say something to the user when he is trying to write to a ReadOnly FS and another ... | [
"Once you catch IOError, e.g. with an except IOError, e: clause in Python 2.*, you can examine e.errno to find out exactly what kind of I/O error it was (unfortunately in a way that's not necessarily fully portable among different operating systems).\nSee the errno module in Python standard library; opening a file ... | [
10,
2
] | [] | [] | [
"exception",
"python"
] | stackoverflow_0001115203_exception_python.txt |
Q:
Making a Makefile
How I can make a Makefile, because it's the best way when you distribute a program by source code. Remember that this is for a C++ program and I'm starting in the C development world. But is it possible to make a Makefile for my Python programs?
A:
From your question it sounds like a tutorial o... | Making a Makefile | How I can make a Makefile, because it's the best way when you distribute a program by source code. Remember that this is for a C++ program and I'm starting in the C development world. But is it possible to make a Makefile for my Python programs?
| [
"From your question it sounds like a tutorial or an overview of what Makefiles actually do might benefit you.\nA good places to start is the GNU Make documentation.\nIt includes the following overview \"The make utility automatically determines which pieces of a large program need to be recompiled, and issues comma... | [
11,
6,
4,
4,
3,
1
] | [] | [] | [
"c",
"c++",
"makefile",
"python"
] | stackoverflow_0001114667_c_c++_makefile_python.txt |
Q:
PyQt Automatic Repeating Forms
I'm currently attempting to migrate a legacy VBA/Microsoft Access application to Python and PyQt. I've had no problems migrating any of the logic, and most of the forms have been a snap, as well. However, I've hit a problem on the most important part of the application--the main data... | PyQt Automatic Repeating Forms | I'm currently attempting to migrate a legacy VBA/Microsoft Access application to Python and PyQt. I've had no problems migrating any of the logic, and most of the forms have been a snap, as well. However, I've hit a problem on the most important part of the application--the main data-entry form.
The form is basically a... | [
"You should look into QSqlTableModel, and the QTableView Objects. QSqlTableModel offers an abstraction of a relational table that can be used inside on of the Qt view classes. A QTableView for example. The functionality you describe can be implemented with moderate effort just by using these two classes. \nThe QSql... | [
3
] | [] | [] | [
"pyqt",
"pyqt4",
"python",
"qt",
"qt4"
] | stackoverflow_0001114678_pyqt_pyqt4_python_qt_qt4.txt |
Q:
Which version of python is currently best for os x?
After going through hell trying to install the latest version of postgresql and psycopg2 today I'm going for a complete reinstall of Leopard.
I've been sticking with macpython 2.5 for the past year but now I'm considering macports even 2.6
For me it's most import... | Which version of python is currently best for os x? | After going through hell trying to install the latest version of postgresql and psycopg2 today I'm going for a complete reinstall of Leopard.
I've been sticking with macpython 2.5 for the past year but now I'm considering macports even 2.6
For me it's most important for Twisted, PIL and psycopg2 to be working without a... | [
"You can install them side-by-side. If you've encounter problems just set python 2.5 as the standard python and use e.g. python26 for a newer version.\n",
"Read this\nhttp://farmdev.com/thoughts/66/python-3-0-on-mac-os-x-alongside-2-6-2-5-etc-/\n",
"I still use macports python25, because so many other packages ... | [
4,
3,
3,
2,
1,
1,
1,
1,
0,
0
] | [] | [] | [
"macos",
"python"
] | stackoverflow_0000651717_macos_python.txt |
Q:
Does "from-import" exec the whole module?
OK, so I know that from-import is "exactly" the same as import, except that it's obviously not because namespaces are populated differently.
My question is primarily motivated because I have a utils module which has one or two functions that are used by every other module ... | Does "from-import" exec the whole module? | OK, so I know that from-import is "exactly" the same as import, except that it's obviously not because namespaces are populated differently.
My question is primarily motivated because I have a utils module which has one or two functions that are used by every other module in my app, and I'm working on incorporating the... | [
"The answer to your question is yes. \nFor a good explanation of the import process, please see Frederik Lundh's \"Importing Python Modules\". \nIn particular, I'll quote the sections that answer your query.\n\nWhat Does Python Do to Import a Module?\n[...]\n\nCreate a new, empty module object (this is essentiall... | [
7,
6,
3,
0
] | [] | [] | [
"import",
"logging",
"python"
] | stackoverflow_0001114787_import_logging_python.txt |
Q:
Static methods and thread safety
In python with all this idea of "Everything is an object" where is thread-safety?
I am developing django website with wsgi. Also it would work in linux, and as I know they use effective process management, so we could not think about thread-safety alot. I am not doubt in how module... | Static methods and thread safety | In python with all this idea of "Everything is an object" where is thread-safety?
I am developing django website with wsgi. Also it would work in linux, and as I know they use effective process management, so we could not think about thread-safety alot. I am not doubt in how module loads, and there functions are static... | [
"Functions in a module are equivalent to static methods in a class. The issue of thread safety arises when multiple threads may be modifying shared data, or even one thread may be modifying such data while others are reading it; it's best avoided by making data be owned by ONE module (accessed via Queue.Queue from ... | [
8,
0
] | [] | [] | [
"django",
"python",
"thread_safety"
] | stackoverflow_0001115420_django_python_thread_safety.txt |
Q:
Determine proxy type
I have the following code to download a URL through a proxy:
proxy_handler = urllib2.ProxyHandler({'http': p})
opener = urllib2.build_opener(proxy_handler)
urllib2.install_opener(opener)
req = urllib2.Request(url)
sock = urllib2.urlopen(req)
How can I use Python to determine the type of proxy... | Determine proxy type | I have the following code to download a URL through a proxy:
proxy_handler = urllib2.ProxyHandler({'http': p})
opener = urllib2.build_opener(proxy_handler)
urllib2.install_opener(opener)
req = urllib2.Request(url)
sock = urllib2.urlopen(req)
How can I use Python to determine the type of proxy it is (transparent, anony... | [
"\nOne solution would be to use an external server\n\nYou must have a server of some sort.\nThe best option you can hope of doing is to host your own web server and print the headers to see if it is leaking any variables.\n"
] | [
1
] | [
"Do you mean retrieving the current proxy configuration?\nYou can with urllib.getproxies:\nimport urllib\nurllib.getproxies()\n{'http': 'http://your_proxy_servername:8080'}\n\nNote: I was not able to find any documentation about urllib.getproxies. I am using Python 2.5, and it just works.\n"
] | [
-1
] | [
"anonymous",
"proxy",
"python"
] | stackoverflow_0001115039_anonymous_proxy_python.txt |
Q:
Google App Engine: how to unescape POST body?
Newbie question...
I am using silverlight to POST data to my GAE application
class XmlCrud(webapp.RequestHandler):
def post(self):
body = self.request.body
The data comes in fine but it is escaped like this:
%3C%3Fxml+version=%221.0%22+encoding%3D%22utf-1... | Google App Engine: how to unescape POST body? | Newbie question...
I am using silverlight to POST data to my GAE application
class XmlCrud(webapp.RequestHandler):
def post(self):
body = self.request.body
The data comes in fine but it is escaped like this:
%3C%3Fxml+version=%221.0%22+encoding%3D%22utf-16%22%3F%3E%0D%0A%3CBosses+xmlns%3Axsi%3D%22http%3A%... | [
"I agree with Hank.\nThe answer to your actual question, though, is that your example is URL encoded. To decode, replace each %XX with the character having hex value 0xXX, and + with space.\nurllib.unquote_plus does this, and according to the docs it's in App Engine\nurllib docs: https://docs.python.org/library/url... | [
3,
0
] | [] | [] | [
"google_app_engine",
"python"
] | stackoverflow_0001116066_google_app_engine_python.txt |
Q:
"Python.exe" crashes when PyQt's setPixmap() is called with a Pixmap
I have a program that sends and receives images to each other using sockets.
The server sends the image data using 'image.tostring()' and the client side receives it and turns it back into an image using 'Image.fromstring', then into a QImage usi... | "Python.exe" crashes when PyQt's setPixmap() is called with a Pixmap | I have a program that sends and receives images to each other using sockets.
The server sends the image data using 'image.tostring()' and the client side receives it and turns it back into an image using 'Image.fromstring', then into a QImage using 'ImageQt.ImageQt(image)', turns it into a QPixmap using 'QPixmap.fromim... | [
"It may be worth dumping the image data to a file and checking that you have all the data by loading it into an image viewer. If you get incomplete data, you may still be able to obtain a QImage and create a QPixmap, but it may be invalid.\n"
] | [
0
] | [] | [] | [
"pyqt",
"python",
"qpixmap"
] | stackoverflow_0001029033_pyqt_python_qpixmap.txt |
Q:
PyQT: QTableWidget.setItemPrototype not working?
In a QTableWidget i want to display all values only with two decimals places. For that I subclassed QTableWidgetItem.
class MyCell(QTableWidgetItem):
def __init__(self, *args):
QTableWidgetItem.__init__(self, *args)
def clone(self):
return M... | PyQT: QTableWidget.setItemPrototype not working? | In a QTableWidget i want to display all values only with two decimals places. For that I subclassed QTableWidgetItem.
class MyCell(QTableWidgetItem):
def __init__(self, *args):
QTableWidgetItem.__init__(self, *args)
def clone(self):
return MyCell()
def data(self, role):
t = QTableW... | [
"There are two issues here. One may be a problem with your code, the other may be a bug in PyQt.\nIn your data() method implementation, you probably meant to write this:\ndef data(self, role):\n t = QTableWidgetItem.data(self, role)\n ...\n\nThis calls the superclass's data() method rather than creating a new... | [
1
] | [] | [] | [
"pyqt",
"pyqt4",
"python"
] | stackoverflow_0001078947_pyqt_pyqt4_python.txt |
Q:
Finding content between two words withou RegEx, BeautifulSoup, lXml ... etc
How to find out the content between two words or two sets of random characters?
The scraped page is not guaranteed to be Html only and the important data can be inside a javascript block. So, I can't remove the JavaScript.
consider this:
<... | Finding content between two words withou RegEx, BeautifulSoup, lXml ... etc | How to find out the content between two words or two sets of random characters?
The scraped page is not guaranteed to be Html only and the important data can be inside a javascript block. So, I can't remove the JavaScript.
consider this:
<html>
<body>
<div>StartYYYY "Extract HTML", ENDYYYY
</body>
Some Java Scripts c... | [
"if you are sure your markers are unique, do something like this\ns=\"\"\"\n<html>\n<body>\n<div>StartYYYY \"Extract HTML\", ENDYYYY\n\n</body>\n\nSome Java Scripts code STARTXXXX \"Extract JS Code\" ENDXXXX.\n\n</html>\n\"\"\"\n\ndef FindBetweenText(startMarker, endMarker, text):\n startPos = text.find(startMar... | [
2,
0,
0,
0
] | [] | [] | [
"fetch",
"python",
"screen_scraping"
] | stackoverflow_0001116172_fetch_python_screen_scraping.txt |
Q:
Advanced SAX Parser in C#
See Below is the XML Arch.
I want to display it in row / column wize.
What I need is I need to convert this xml file to Hashtable like,
{"form" : {"attrs" : { "string" : " Partners" }
{"child1": { "group" : { "attrs" : { "col" : "6", "colspan":"1" } }
... | Advanced SAX Parser in C# | See Below is the XML Arch.
I want to display it in row / column wize.
What I need is I need to convert this xml file to Hashtable like,
{"form" : {"attrs" : { "string" : " Partners" }
{"child1": { "group" : { "attrs" : { "col" : "6", "colspan":"1" } }
{ "child1": { "field" : {... | [
"\nfrom xml.sax.handler import\n ContentHandler import xml class\n my_handler(ContentHandler):\ndef get_attr_dict(self, attrs):\n ret_dict = {}\n for name in attrs.getNames():\n ret_dict[name] = attrs.getValue(name)\n #end for name in attrs.getNames():\n return ret_dict\n\ndef setDocumentLocato... | [
0
] | [] | [] | [
".net",
"parsing",
"python",
"sax",
"xml"
] | stackoverflow_0001078902_.net_parsing_python_sax_xml.txt |
Q:
python program choice
My program is ICAPServer (similar with httpserver), it's main job is to receive data from clients and save the data to DB.
There are two main steps and two threads:
ICAPServer receives data from clients, puts the data in a queue (50kb <1ms);
another thread pops data from the queue, and write... | python program choice | My program is ICAPServer (similar with httpserver), it's main job is to receive data from clients and save the data to DB.
There are two main steps and two threads:
ICAPServer receives data from clients, puts the data in a queue (50kb <1ms);
another thread pops data from the queue, and writes them to DB SO, if 2nd ste... | [
"It is hard to say for sure, but perhaps using two processes instead of threads will help in this situation. Since Python has the Global Interpreter Lock (GIL), it has the effect of only allowing any one thread to execute Python instructions at any time. \nHaving a system designed around processes might have the fo... | [
2,
0,
0
] | [] | [] | [
"python",
"sqlalchemy",
"twisted"
] | stackoverflow_0001116163_python_sqlalchemy_twisted.txt |
Q:
Should I use Unicode string by default?
Is it considered as a good practice to pick Unicode string over regular string when coding in Python? I mainly work on the Windows platform, where most of the string types are Unicode these days (i.e. .NET String, '_UNICODE' turned on by default on a new c++ project, etc ). ... | Should I use Unicode string by default? | Is it considered as a good practice to pick Unicode string over regular string when coding in Python? I mainly work on the Windows platform, where most of the string types are Unicode these days (i.e. .NET String, '_UNICODE' turned on by default on a new c++ project, etc ). Therefore, I tend to think that the case wher... | [
"From my practice -- use unicode. \nAt beginning of one project we used usuall strings, however our project was growing, we were implementing new features and using new third-party libraries. In that mess with non-unicode/unicode string some functions started failing. We started spending time localizing this proble... | [
19,
13,
13,
6,
4,
2
] | [] | [] | [
"python",
"unicode"
] | stackoverflow_0001116449_python_unicode.txt |
Q:
What's the point of this code pattern?
I was trying to create a python wrapper for an tk extension, so I looked at Tkinter.py to learn how to do it.
While looking at that file, I found the following pattern appears a lot of times: an internal method (hinted by the leading "_" in the method name) is defined, then ... | What's the point of this code pattern? | I was trying to create a python wrapper for an tk extension, so I looked at Tkinter.py to learn how to do it.
While looking at that file, I found the following pattern appears a lot of times: an internal method (hinted by the leading "_" in the method name) is defined, then a public method is defined just to be the in... | [
"Sometimes, you may want to change a method's behavior. For example, I could do this (hypothetically within the Misc class):\ndef _another_register(self, func, subst=None, needcleanup=1):\n ...\n\ndef change_register(self):\n self.register = self._another_register\n\ndef restore_register(self):\n self.reg... | [
8,
2,
1
] | [] | [] | [
"python"
] | stackoverflow_0001116693_python.txt |
Q:
lucene / python
Can I use lucene directly from python, preferably without using a binary module?
I am interested mainly in read access -- being able to perform queries from python over existing lucene indexes.
A:
You can't use Lucene itself from CPython without using a binary module, no.
You could use it direct... | lucene / python | Can I use lucene directly from python, preferably without using a binary module?
I am interested mainly in read access -- being able to perform queries from python over existing lucene indexes.
| [
"You can't use Lucene itself from CPython without using a binary module, no.\nYou could use it directly from Jython, or you could use a Python port of Lucene, eg. Lupy (though Lupy is no longer under development).\nIf you're prepared to relax your non-binary requirement, PyLucene is a wrapper that embeds Java Lucen... | [
8,
8
] | [] | [] | [
"lucene",
"python"
] | stackoverflow_0001116967_lucene_python.txt |
Q:
Error running twisted application
I am trying to run a simple twisted application echo bot that metajack blogged about, everything looks like it is going to load fine, but at the very end I get an error:
2009/07/12 15:46 -0600 [-] ImportError: cannot import name toResponse
2009/07/12 15:46 -0600 [-] Failed to load... | Error running twisted application | I am trying to run a simple twisted application echo bot that metajack blogged about, everything looks like it is going to load fine, but at the very end I get an error:
2009/07/12 15:46 -0600 [-] ImportError: cannot import name toResponse
2009/07/12 15:46 -0600 [-] Failed to load application: cannot import name toResp... | [
"This error is caused because I have an outdated version of Twisted. Off to find a way to update twisted itself as the installer doesnt seem to be doing the trick.\n",
"There's not really enough information to go on, but if I had to guess, I'd say that you've given your program the same name as one of the module... | [
2,
1
] | [] | [] | [
"python",
"twisted"
] | stackoverflow_0001117072_python_twisted.txt |
Q:
How do I tell a Python script (cygwin) to work in current (or relative) directories?
I have lots of directories with text files written using (g)vim, and I have written a handful of utilities that I find useful in Python. I start off the utilities with a pound-bang-/usr/bin/env python line in order to use the Pyt... | How do I tell a Python script (cygwin) to work in current (or relative) directories? | I have lots of directories with text files written using (g)vim, and I have written a handful of utilities that I find useful in Python. I start off the utilities with a pound-bang-/usr/bin/env python line in order to use the Python that is installed under cygwin. I would like to type commands like this:
%cd ~/SomeBo... | [
"Look at os.getcwd:\n\nhttp://docs.python.org/library/os.html#os-file-dir\n\nEdit: For relative paths, please take a look at the os.path module:\n\nhttp://docs.python.org/library/os.path.html\n\nin particular, os.path.join and os.path.normpath. For instance:\nimport os\nprint os.path.normpath(os.path.join(os.getc... | [
4,
0,
0
] | [] | [] | [
"cygwin",
"filesystems",
"path",
"python",
"utilities"
] | stackoverflow_0001117414_cygwin_filesystems_path_python_utilities.txt |
Q:
Cleaning up nested Try/Excepts
I've just written a chunk of code that strikes me as being far more nested than is optimal. I'd like advice on how to improve the style of this, particularly so that it conforms more with "Flat is better than nested."
for app in apps:
if app.split('.', 1)[0] == 'zc': #only look f... | Cleaning up nested Try/Excepts | I've just written a chunk of code that strikes me as being far more nested than is optimal. I'd like advice on how to improve the style of this, particularly so that it conforms more with "Flat is better than nested."
for app in apps:
if app.split('.', 1)[0] == 'zc': #only look for cron in zc apps
try:
... | [
"The main problem is that your try clauses are too broad, particularly the outermost one: with that kind of habit, you WILL sooner or later run into a mysterious bug because one of your try/except has accidentally hidden an unexpected exception \"bubbling up\" from some other function you're calling.\nSo I'd sugges... | [
8,
1,
0,
0
] | [] | [] | [
"python"
] | stackoverflow_0001117460_python.txt |
Q:
Efficiently importing modules in Django views
I was wondering - how do people handle importing large numbers of commonly used modules within django views? And whats the best method to do this efficiently?
For instance, I've got some views like,
admin_views.py
search_views.py
.
.
and from what I've seen, every one... | Efficiently importing modules in Django views | I was wondering - how do people handle importing large numbers of commonly used modules within django views? And whats the best method to do this efficiently?
For instance, I've got some views like,
admin_views.py
search_views.py
.
.
and from what I've seen, every one of them needs to use HttpResponse or other such co... | [
"Python itself guarantees that a module is loaded just once (unless reload is explicitly called, which is not the case here): after the first time, import of that module just binds its name directly from sys.modules[themodulename], an extremely fast operation. So Django does not have to do any further optimization,... | [
6,
0,
0
] | [] | [] | [
"django",
"import",
"performance",
"python",
"python_module"
] | stackoverflow_0001117451_django_import_performance_python_python_module.txt |
Q:
Django Initialization
I have a big array, that I would like to load into memory only once when django starts up and then treat it as a read only global variable. What is the best place to put the code for the initialization of that array?
If I put it in settings.py it will be reinitialized every time the settings ... | Django Initialization | I have a big array, that I would like to load into memory only once when django starts up and then treat it as a read only global variable. What is the best place to put the code for the initialization of that array?
If I put it in settings.py it will be reinitialized every time the settings module is imported, correct... | [
"settings.py is for Django settings; it's fine to put your own settings in there, but using it for arbitrary non-configuration data structures isn't good practice.\nJust put it in the module it logically belongs to, and it'll be run just once per instance. If you want to guarantee that the module is loaded on star... | [
19,
9
] | [] | [] | [
"django",
"python"
] | stackoverflow_0001116948_django_python.txt |
Q:
How to find the number of parameters to a Python function from C?
I'm using the Python C API to call Python functions from my application. I'd like to present a list of functions that could be called and would like to be able to limit this list to just the ones with the expected number of parameters.
I'm happy tha... | How to find the number of parameters to a Python function from C? | I'm using the Python C API to call Python functions from my application. I'd like to present a list of functions that could be called and would like to be able to limit this list to just the ones with the expected number of parameters.
I'm happy that I can walk the dictionary to extract a list of functions and use PyCa... | [
"Okay, so in the end I've discovered how to do it. User-defined Python functions have a member called func_code (in Python 3.0+ it's __code__), which itself has a member co_argcount, which is presumably what Boost::Python extracts in the example given by Christophe.\nThe code I'm using looks like this (it's heavily... | [
5,
1,
0
] | [] | [] | [
"c",
"python"
] | stackoverflow_0001117164_c_python.txt |
Q:
In Python, is there a way to detect the use of incorrect variable names; something like VB's "Option Explicit"?
I do most of my development in Java and C++ but recently had to write various scripts and picked up Python. I run python from the command line on scripts; not in interactive mode. I'm wondering if
I lik... | In Python, is there a way to detect the use of incorrect variable names; something like VB's "Option Explicit"? | I do most of my development in Java and C++ but recently had to write various scripts and picked up Python. I run python from the command line on scripts; not in interactive mode. I'm wondering if
I like a lot of things about the language, but one thing that keeps reducing my productivity is the fact that I get no adv... | [
"there are some tools like pylint or pyflakes which may catch some of those. pyflakes is quite fast, and usable on many projects for this reason\nAs reported on pyflakes webpage, the two primary categories of defects reported by PyFlakes are:\n\nNames which are used but not defined or used before they are defined\n... | [
2,
2
] | [] | [] | [
"python"
] | stackoverflow_0001117661_python.txt |
Q:
Updating part of a surface in python, or transparent surfaces
I have an application written in python that's basically an etch-a-sketch, you move pixels around with WASD and arrow keys and it leaves a trail. However, I want to add a counter for the amount of pixels on the screen. How do I have the counter update w... | Updating part of a surface in python, or transparent surfaces | I have an application written in python that's basically an etch-a-sketch, you move pixels around with WASD and arrow keys and it leaves a trail. However, I want to add a counter for the amount of pixels on the screen. How do I have the counter update without updating the entire surface and pwning the pixel drawings?
A... | [
"To solve this problem, you want to have a separate surface for your Etch-a-Sketch pixels, so that they do not get clobbered when you go to refresh the screen. Unfortunately, with Rigo's scheme, the font will continue to render on top of itself, which will get messy for more than two pixel count changes.\nSo, here... | [
1,
0
] | [] | [] | [
"pygame",
"python"
] | stackoverflow_0001072734_pygame_python.txt |
Q:
Most "pythonic" way of organising class attributes, constructor arguments and subclass constructor defaults?
Being relatively new to Python 2, I'm uncertain how best to organise my class files in the most 'pythonic' way. I wouldn't be asking this but for the fact that Python seems to have quite a few ways of doing... | Most "pythonic" way of organising class attributes, constructor arguments and subclass constructor defaults? | Being relatively new to Python 2, I'm uncertain how best to organise my class files in the most 'pythonic' way. I wouldn't be asking this but for the fact that Python seems to have quite a few ways of doing things that are very different to what I have come to expect from the languages I am used to.
Initially, I was ju... | [
"\nIf attributes will vary from instance\nto instance make them instance\nattribute i.e. create them\ninside__init__ using self else if they need to\nbe shared between class instances\nlike a constant, put them at class\nlevel.\nIf your class really need to pass, so\nmany arguments in __init__, let\nderive class us... | [
7
] | [] | [] | [
"python",
"python_2.6"
] | stackoverflow_0001118006_python_python_2.6.txt |
Q:
Fake a cookie to scrape a site in python
The site that I'm trying to scrape uses js to create a cookie. What I was thinking was that I can create a cookie in python and then use that cookie to scrape the site. However, I don't know any way of doing that. Does anybody have any ideas?
A:
Please see Python httplib2... | Fake a cookie to scrape a site in python | The site that I'm trying to scrape uses js to create a cookie. What I was thinking was that I can create a cookie in python and then use that cookie to scrape the site. However, I don't know any way of doing that. Does anybody have any ideas?
| [
"Please see Python httplib2 - Handling Cookies in HTTP Form Posts for an example of adding a cookie to a request.\n\nI often need to automate tasks in web\n based applications. I like to do this\n at the protocol level by simulating a\n real user's interactions via HTTP. \n Python comes with two built-in modul... | [
2,
2
] | [] | [] | [
"cookiejar",
"cookies",
"python"
] | stackoverflow_0001117491_cookiejar_cookies_python.txt |
Q:
Retrieve cookie created using javascript in python
I've had a look at many tutorials regarding cookiejar, but my problem is that the webpage that i want to scape creates the cookie using javascript and I can't seem to retrieve the cookie. Does anybody have a solution to this problem?
A:
If all pages have the sam... | Retrieve cookie created using javascript in python | I've had a look at many tutorials regarding cookiejar, but my problem is that the webpage that i want to scape creates the cookie using javascript and I can't seem to retrieve the cookie. Does anybody have a solution to this problem?
| [
"If all pages have the same JavaScript then maybe you could parse the HTML to find that piece of code, and from that get the value the cookie would be set to? \nThat would make your scraping quite vulnerable to changes in the third party website, but that's most often the case while scraping. (Please bear in mind t... | [
3,
1,
0,
0
] | [] | [] | [
"cookiejar",
"cookies",
"python",
"urllib2"
] | stackoverflow_0001116362_cookiejar_cookies_python_urllib2.txt |
Q:
Python MySQLdb exceptions
Just starting to get to grips with python and MySQLdb and was wondering
Where is the best play to put a try/catch block for the connection to MySQL. At the MySQLdb.connect point? Also should there be one when ever i query?
What exceptions should i be catching on any of these blocks?
tha... | Python MySQLdb exceptions | Just starting to get to grips with python and MySQLdb and was wondering
Where is the best play to put a try/catch block for the connection to MySQL. At the MySQLdb.connect point? Also should there be one when ever i query?
What exceptions should i be catching on any of these blocks?
thanks for any help
Cheers
Mark
| [
"Catch the MySQLdb.Error, while connecting and while executing query\n",
"I think that the connections and the query can raised errors so you should have try/excepy for both of them. \n"
] | [
16,
1
] | [] | [] | [
"exception",
"mysql",
"python"
] | stackoverflow_0001117828_exception_mysql_python.txt |
Q:
Is there a database implementation that has notifications and revisions?
I am looking for a database library that can be used within an editor to replace a custom document format. In my case the document would contain a functional program.
I want application data to be persistent even while editing, so that when t... | Is there a database implementation that has notifications and revisions? | I am looking for a database library that can be used within an editor to replace a custom document format. In my case the document would contain a functional program.
I want application data to be persistent even while editing, so that when the program crashes, no data is lost. I know that all databases offer that.
On ... | [
"Berkeley DB is an undemanding, light-weight key-value database that supports locking and transactions. There are bindings for it in a lot of programming languages, including C++ and python. You'll have to implement revisions and notifications yourself, but that's actually not all that difficult.\n",
"It might b... | [
1,
1,
0
] | [] | [] | [
"c++",
"database_design",
"editor",
"python"
] | stackoverflow_0001118272_c++_database_design_editor_python.txt |
Q:
Is there a way to know which versions of python are supported by my code?
You may know the Windows compliance tool that helps people to know if their code is supported by any version of the MS OS.
I am looking something similar for Python.
I am writing a lib with Python 2.6 and I realized that it was not compatib... | Is there a way to know which versions of python are supported by my code? | You may know the Windows compliance tool that helps people to know if their code is supported by any version of the MS OS.
I am looking something similar for Python.
I am writing a lib with Python 2.6 and I realized that it was not compatible with Python 2.5 due to the use of the with keyword.
I would like to know if... | [
"In response to a previous question about this, I wrote pyqver. If you have any improvements, please feel free to fork and contribute!\n",
"I recommend you rather use automated tests than a code analysis tool.\nBe aware that there are subtle behaviour changes in the Python standard library that your code may or m... | [
7,
6,
0
] | [] | [] | [
"dependencies",
"python",
"versioning"
] | stackoverflow_0001118208_dependencies_python_versioning.txt |
Q:
Wavelet plot with Python libraries
I know that SciPy has some signal processing tools for wavelets in scipy.signal.wavelets and a chart can be drawn using Matplotlib, but it seems I can't get it right. I have tried plotting a Daubechies wavelet against a linear space, but it's not what I am looking for. I am highl... | Wavelet plot with Python libraries | I know that SciPy has some signal processing tools for wavelets in scipy.signal.wavelets and a chart can be drawn using Matplotlib, but it seems I can't get it right. I have tried plotting a Daubechies wavelet against a linear space, but it's not what I am looking for. I am highly unskilled about wavelets and math in g... | [
"With a recent trunk version of PyWavelets, getting approximations of scaling function and wavelet function on x-grid is pretty straightforward:\n[phi, psi, x] = pywt.Wavelet('db2').wavefun(level=4)\n\nNote that x-grid output is not available in v0.1.6, so if you need that you will have to use the trunk version.\nH... | [
14
] | [] | [] | [
"matplotlib",
"python",
"pywt",
"scipy",
"wavelet"
] | stackoverflow_0001094655_matplotlib_python_pywt_scipy_wavelet.txt |
Q:
Interpret this particular REGEX
I did a REGEX pattern some time ago and I don't remember its meaning. For me this is a write-only language :)
Here is the REGEX:
"(?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{8,10})$"
I need to know, in plain English, what does it means.
A:
(?!^[0-9]*$)
don't match only numbers,
(?!... | Interpret this particular REGEX | I did a REGEX pattern some time ago and I don't remember its meaning. For me this is a write-only language :)
Here is the REGEX:
"(?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{8,10})$"
I need to know, in plain English, what does it means.
| [
"(?!^[0-9]*$)\n\ndon't match only numbers,\n(?!^[a-zA-Z]*$)\n\ndon't match only letters,\n^([a-zA-Z0-9]{8,10})$\n\nmatch letters and number 8 to 10 characters long.\n",
"Perl (and Python accordingly) says to the (?!...) part:\n\nA zero-width negative lookahead assertion. For example /foo(?!bar)/ matches any occur... | [
5,
4,
2
] | [] | [] | [
"python",
"regex"
] | stackoverflow_0001118672_python_regex.txt |
Q:
Python script: import sys failing on WinXP setup
I'm trying out a hello world python script on WinXP. When I execute:
python test.py arg1.log
I get an error for the first line of the script, which is 'import sys':
File "test.py", line 1, in <module>
i
NameError: name 'i' is not defined
Any suggestions?
A:
You... | Python script: import sys failing on WinXP setup | I'm trying out a hello world python script on WinXP. When I execute:
python test.py arg1.log
I get an error for the first line of the script, which is 'import sys':
File "test.py", line 1, in <module>
i
NameError: name 'i' is not defined
Any suggestions?
| [
"You've saved the file as Windows Unicode (aka UTF-16, aka UCS-2) rather than ASCII or UTF-8.\nIf your editor has an Encoding option (or something under \"Save As\" for the encoding) change it to UTF-8.\nIf your editor has no such option, you can load it into Notepad and save it as UTF-8.\n"
] | [
10
] | [] | [] | [
"python",
"windows_xp"
] | stackoverflow_0001118979_python_windows_xp.txt |
Q:
swfupload failing in my django runserver
I have copied and pasted the code from http://demo.swfupload.org/v220/simpledemo/ into a django template, but when I upload a photo, the demo says "Server (IO) Error" before it actually uploads the entire file. The runserver is getting the request and returning a 200. Is th... | swfupload failing in my django runserver | I have copied and pasted the code from http://demo.swfupload.org/v220/simpledemo/ into a django template, but when I upload a photo, the demo says "Server (IO) Error" before it actually uploads the entire file. The runserver is getting the request and returning a 200. Is there something I am missing here? What steps sh... | [
"Found it. I was uploading to a dummy view, and for some reason if you don't actually access request.POST or request.FILES it gives that error message.\n",
"Make sure you have write permission to your server. In the folder you installed that thing. Check the user that is running runserver. If in windows - check f... | [
1,
0
] | [] | [] | [
"django",
"python",
"swfupload"
] | stackoverflow_0001110082_django_python_swfupload.txt |
Q:
PyQt: event is not triggered, what's wrong with my code?
I'm a Python newbie and I'm trying to write a trivial app with an event handler that gets activated when an item in a custom QTreeWidget is clicked. For some reason it doesn't work. Since I'm only at the beginning of learning it, I can't figure out what I'm ... | PyQt: event is not triggered, what's wrong with my code? | I'm a Python newbie and I'm trying to write a trivial app with an event handler that gets activated when an item in a custom QTreeWidget is clicked. For some reason it doesn't work. Since I'm only at the beginning of learning it, I can't figure out what I'm doing wrong. Here is the code:
#!/usr/bin/env python
import s... | [
"You should have said\nself.connect(self, SIGNAL('itemClicked(QTreeWidgetItem*, int)'), self.onClick)\n\nNotice it says int rather than column in the first argument to SIGNAL. You also only need to do the connect call once for the tree widget, not once for each node in the tree.\n"
] | [
10
] | [] | [] | [
"pyqt",
"python"
] | stackoverflow_0001119110_pyqt_python.txt |
Q:
How to put infinity and minus infinity in Django FloatField?
I am trying to put infinity in a FloatField, but that doesn't seem to work. How do I solve this?
f = DjangoModel(float_value=float('inf')) #ok
f.save() #crashes
Results in:
Traceback (most recent call last):
...
ProgrammingError: column "inf" does not e... | How to put infinity and minus infinity in Django FloatField? | I am trying to put infinity in a FloatField, but that doesn't seem to work. How do I solve this?
f = DjangoModel(float_value=float('inf')) #ok
f.save() #crashes
Results in:
Traceback (most recent call last):
...
ProgrammingError: column "inf" does not exist
LINE 1: ... "float_value") VALUES (inf)
I'm using Django 1.0... | [
"It seems like Djangos ORM doesn't have any special handling for this. Pythons representaton of the values are inf and -inf, while PostgrSQL wants 'Infinity' and '-Infinity'. Obviously Djangos ORM doesn't handle that conversion.\nSo you need to fix the ORM, I guess. And then think about the fact that other SQL data... | [
5,
0
] | [] | [] | [
"django",
"infinity",
"python"
] | stackoverflow_0001119497_django_infinity_python.txt |
Q:
Emulator Framework
Are there any good open source frameworks for developing computer system emulators? I am particularly interested in something written in Python or Java that can reduce the effort involved in developing emulators for 8-bit processors (e.g. 6502, 6510, etc.).
A:
Isn't the 6510 in the C64?
You m... | Emulator Framework | Are there any good open source frameworks for developing computer system emulators? I am particularly interested in something written in Python or Java that can reduce the effort involved in developing emulators for 8-bit processors (e.g. 6502, 6510, etc.).
| [
"Isn't the 6510 in the C64? \nYou might be able to make use of the java libraries that emulate c64 code\nhttp://www.dreamfabric.com/c64/\nhttp://www.jac64.com/jac64-java-based-c64-emulator.html\nIf you aren't afraid of C++ try this general purpose one:\nhttp://cef.sourceforge.net/index.php\n",
"You may want to ch... | [
2,
2,
1
] | [] | [] | [
"6502",
"6510",
"emulation",
"java",
"python"
] | stackoverflow_0001120709_6502_6510_emulation_java_python.txt |
Q:
Django templates: adding sections conditionally
I just started using django for development. At the moment, I have the following issue: I have to write a page template able to represent different categories of data. For example, suppose I have a medical record of a patient. The represented information about this p... | Django templates: adding sections conditionally | I just started using django for development. At the moment, I have the following issue: I have to write a page template able to represent different categories of data. For example, suppose I have a medical record of a patient. The represented information about this patient are, for example:
name, surname and similar d... | [
"See this example: http://www.djangosnippets.org/snippets/1057/\nEssentially, you can loop through a model's fields in the template.\nI assume you just want to display the data present in all of these different fields correct? Looping through each field should provide you with the results you're looking for.\nAlter... | [
2,
1
] | [] | [] | [
"django",
"django_templates",
"python"
] | stackoverflow_0001120914_django_django_templates_python.txt |
Q:
How to use QTP to test the application which operates in citrix of Remote Machine?
When i tried recording using QTP, every thing goes well till the application sign in. i.e it gets upto the user Id and password entry, But QTP fails to recognise afterthat. Is there any way to handle this?
Application is to be invok... | How to use QTP to test the application which operates in citrix of Remote Machine? | When i tried recording using QTP, every thing goes well till the application sign in. i.e it gets upto the user Id and password entry, But QTP fails to recognise afterthat. Is there any way to handle this?
Application is to be invoked using Citirx, in VPN.
| [
"QTP performs GUI recognition and interaction through Windows Handle. \nSo it has to be running under Citrix (i.e. installed on the same virtual machine as your Application Under Test). \nIf you have the above, make sure Screen Resolution, Windows Theme, Font size, and other global GUI settings are the same.\n"
] | [
0
] | [] | [] | [
"c#",
"python",
"ruby"
] | stackoverflow_0001086758_c#_python_ruby.txt |
Q:
How do you address data returned to a socket in python?
Say you are telneting into IRC to figure out how it all works. As you issue commands the IRC server returns data telling you what it's doing. Once I have created a default script that basically is how a normal IRC connection between server and client occurs... | How do you address data returned to a socket in python? | Say you are telneting into IRC to figure out how it all works. As you issue commands the IRC server returns data telling you what it's doing. Once I have created a default script that basically is how a normal IRC connection between server and client occurs, if it ever deviates from that it won't tell me what is wron... | [
"Here's a tutorial which pretty much walks you through an IRC client using sockets in Python:\n\nPython and IRC\n\n",
"Twisted is an event-driven networking engine written in Python, and includes support for IRC protocols. To access IRC functionality, import it:\nfrom twisted.words.protocols import irc\n\nSee an ... | [
1,
0
] | [] | [] | [
"irc",
"python",
"sockets"
] | stackoverflow_0001120976_irc_python_sockets.txt |
Q:
Improve a IRC Client in Python
How i can make some improvement in my IRC client made in Python. The improvement is: How i can put something that the user can type the HOST, PORT, NICK, INDENT and REALNAME strings and the message? And here is the code of the program:
simplebot.py
import sys
import socket
import st... | Improve a IRC Client in Python | How i can make some improvement in my IRC client made in Python. The improvement is: How i can put something that the user can type the HOST, PORT, NICK, INDENT and REALNAME strings and the message? And here is the code of the program:
simplebot.py
import sys
import socket
import string
HOST="irc.freenode.net"
PORT=6... | [
"You already have the blueprint there for what you want it to do. You're doing:\nif(line[0]==\"PING\"):\n\nNo reason you couldn't adapt that scheme to accept input of PORT, NICK, etc.\nAlso, while 1 isn't very Pythonic. Yes it works, but really there is no reason not to use True. It's not a big deal, but it makes t... | [
2,
2,
1,
1,
0
] | [] | [] | [
"client",
"irc",
"python",
"python_3.x",
"sockets"
] | stackoverflow_0001121002_client_irc_python_python_3.x_sockets.txt |
Q:
Eliminating certain Django Session Calls
I was wondering if I could eliminate django session calls for specific views. For example, if I have a password reset form I don't want a call to the DB to check for a session or not. Thanks!
A:
Sessions are lazily loaded: if you don't use the session during a request, ... | Eliminating certain Django Session Calls | I was wondering if I could eliminate django session calls for specific views. For example, if I have a password reset form I don't want a call to the DB to check for a session or not. Thanks!
| [
"Sessions are lazily loaded: if you don't use the session during a request, Django won't load it.\nThis includes request.user: if you access it, it accesses the session to find the user. (It loads lazily, too--if you don't access request.user, it won't access the session, either.)\nSo, figure out what's accessing ... | [
1
] | [] | [] | [
"django",
"python",
"session"
] | stackoverflow_0001121299_django_python_session.txt |
Q:
Python to drive Emacs; pymacs doesn't work
I've got a python script that loops indefinitely waiting for input, and then
does something when the input happens. My problem is then making python
tell emacs to do something. I just need some way to send emacs input
and make emacs evaluate that input.
Here's some code ... | Python to drive Emacs; pymacs doesn't work | I've got a python script that loops indefinitely waiting for input, and then
does something when the input happens. My problem is then making python
tell emacs to do something. I just need some way to send emacs input
and make emacs evaluate that input.
Here's some code to illustrate my problem...
while(1):
on_off ... | [
"You can use gnuclient (shipped with Emacs 22) (or emacsclient for earlier Emacsen), to evaluate code from external programs and connect to a running Emacs.\nGetting Emacs to evaluate code by itself would look something like this:\ngnuclient -q -batch -eval \"(setq 'lightswitch t)\"\n\n"
] | [
4
] | [] | [] | [
"emacs",
"pymacs",
"python"
] | stackoverflow_0001121759_emacs_pymacs_python.txt |
Q:
python windows directory mtime: how to detect package directory new file?
I'm working on an auto-reload feature for WHIFF
http://whiff.sourceforge.net
(so you have to restart the HTTP server less often, ideally never).
I have the following code to reload a package module "location"
if a file is added to the packag... | python windows directory mtime: how to detect package directory new file? | I'm working on an auto-reload feature for WHIFF
http://whiff.sourceforge.net
(so you have to restart the HTTP server less often, ideally never).
I have the following code to reload a package module "location"
if a file is added to the package directory. It doesn't work on Windows XP.
How can I fix it? I think the pro... | [
"long time no see. I'm not sure exactly what you're doing, but the equivalent of your code:\nGET_MODULE_FUNCTION = \"\"\"\ndef f():\n import %(parent)s\n try:\n from %(parent)s import %(child)s\n except ImportError:\n # one more time...\n reload(%(parent)s)\n from %(parent)s imp... | [
2,
0,
0,
0
] | [] | [] | [
"python",
"windows_xp"
] | stackoverflow_0001116144_python_windows_xp.txt |
Q:
How do you extract a JAR in a UNIX filesystem with a single command and specify its target directory using the JAR command?
I am creating a Python script within which I am executing UNIX system commands. I have a
war archive named Binaries.war which is within an ear archive named Portal.ear
The Portal ear file res... | How do you extract a JAR in a UNIX filesystem with a single command and specify its target directory using the JAR command? | I am creating a Python script within which I am executing UNIX system commands. I have a
war archive named Binaries.war which is within an ear archive named Portal.ear
The Portal ear file resides in, say /home/foo/bar/
jar xf /home/foo/bar/Portal.ear Binaries.war
Will extract the Binaries.war file out of the /home/foo... | [
"If your jar file already has an absolute pathname as shown, it is particularly easy:\ncd /where/you/want/it; jar xf /path/to/jarfile.jar\n\nThat is, you have the shell executed by Python change directory for you and then run the extraction.\nIf your jar file does not already have an absolute pathname, then you hav... | [
77,
66,
1,
1
] | [] | [] | [
"jar",
"java",
"linux",
"python",
"unix"
] | stackoverflow_0001079693_jar_java_linux_python_unix.txt |
Q:
Per-session transactions in Django
I'm making a Django web-app which allows a user to build up a set of changes over a series of GETs/POSTs before committing them to the database (or reverting) with a final POST. I have to keep the updates isolated from any concurrent database users until they are confirmed (this ... | Per-session transactions in Django | I'm making a Django web-app which allows a user to build up a set of changes over a series of GETs/POSTs before committing them to the database (or reverting) with a final POST. I have to keep the updates isolated from any concurrent database users until they are confirmed (this is a configuration front-end), ruling ou... | [
"Multiple, concurrent, session-scale transactions will generally lead to deadlocks or worse (worse == livelock, long delays while locks are held by another session.)\nThis design is not the best policy, which is why Django discourages it.\nThe better solution is the following.\n\nDesign a Memento class that records... | [
8,
2,
2
] | [] | [] | [
"django",
"python",
"transactions"
] | stackoverflow_0001033934_django_python_transactions.txt |
Q:
What is the maximum simultaneous HTTP connections allowed on one machine (windows server 2008) using python
To be more specific, I'm using python and making a pool of HTTPConnection (httplib) and was wondering if there is an limit on the number of concurrent HTTP connections on a windows server.
A:
AFAIK, the nu... | What is the maximum simultaneous HTTP connections allowed on one machine (windows server 2008) using python | To be more specific, I'm using python and making a pool of HTTPConnection (httplib) and was wondering if there is an limit on the number of concurrent HTTP connections on a windows server.
| [
"AFAIK, the numbers of internet sockets (necessary to make TCP/IP connections) is naturally limited on every machine, but it's pretty high. 1000 simulatneous connections shouldn't be a problem for the client machine, as each socket uses only little memory. If you start receiving data through all these channels, thi... | [
3,
3
] | [] | [] | [
"python"
] | stackoverflow_0001121951_python.txt |
Q:
Platform for developing all things google?
I am interested in developing things for google apps and android using python and java. I am new to both and was wondering if a environment set in windows or linux would be more productive for these tasks?
A:
Google has tools for Eclipse only for both Android and for Go... | Platform for developing all things google? | I am interested in developing things for google apps and android using python and java. I am new to both and was wondering if a environment set in windows or linux would be more productive for these tasks?
| [
"Google has tools for Eclipse only for both Android and for Google Apps. They haven't made any other tools as far as I know.\nOh yeah, so to answer your question, it doesn't matter that much. Windows, Unix, or Mac, all the same really (people in our office use all of them).\n",
"I'd throw down another vote for ... | [
1,
0,
0
] | [] | [] | [
"android",
"java",
"platform",
"python"
] | stackoverflow_0001120297_android_java_platform_python.txt |
Q:
How to model one way one-to-one relationship in Django
I want to model an article with revisions in Django:
I have following in my article's models.py:
class Article(models.Model):
title = models.CharField(blank=False, max_length=80)
slug = models.SlugField(max_length=80)
def __unicode__(self):
... | How to model one way one-to-one relationship in Django | I want to model an article with revisions in Django:
I have following in my article's models.py:
class Article(models.Model):
title = models.CharField(blank=False, max_length=80)
slug = models.SlugField(max_length=80)
def __unicode__(self):
return self.title
class ArticleRevision(models.Model):
... | [
"The back-references that Django produces are programatic, and do not affect the underlying Database schema. In other words, if you have a one-to-one or foreign key field on your Article pointing to your Revision, a column will be added to the Article table in the database, but not to the Revision table.\nThus, rem... | [
5,
4
] | [] | [] | [
"django",
"django_models",
"python"
] | stackoverflow_0001121488_django_django_models_python.txt |
Q:
How do I satisfy a 3rd-party shared library reference to stat when I'm creating a shared library shim rather than an executable?
I am the new maintainer for an in-house Python system that uses a set of 3rd-party shared C libraries via a shared library shim that is created using a combination of swig and a setup.py... | How do I satisfy a 3rd-party shared library reference to stat when I'm creating a shared library shim rather than an executable? | I am the new maintainer for an in-house Python system that uses a set of 3rd-party shared C libraries via a shared library shim that is created using a combination of swig and a setup.py script. This has been working well until recently.
The 3rd-party shared C libraries were updated for new functionality and now I get ... | [
"The solution was to create to a new Centos 5.3 VM and re-build and/or re-install components as needed.\n",
"As it turns out, while moving to Centos 5.3 was probably a good thing in the long run, the actual problem turns out to have been the way that libz4lnx was built on the DVD that I was originally using. In t... | [
1,
1
] | [] | [] | [
"c",
"python",
"swig"
] | stackoverflow_0001072068_c_python_swig.txt |
Q:
Join Records on Multiple Line File based on Criteria
I am trying to write a python script
that takes record data like this
6xxxxxxxx
7xxxxxxxx
6xxxxxxxx
7xxxxxxxx
7xxxxxxxx
6xxxxxxxx
6xxxxxxxx
6xxxxxxxx
7xxxxxxxx
7xxxxxxxx
7xxxxxxxx
and performs the following logic
newline = ""
read in a record
if the record ... | Join Records on Multiple Line File based on Criteria | I am trying to write a python script
that takes record data like this
6xxxxxxxx
7xxxxxxxx
6xxxxxxxx
7xxxxxxxx
7xxxxxxxx
6xxxxxxxx
6xxxxxxxx
6xxxxxxxx
7xxxxxxxx
7xxxxxxxx
7xxxxxxxx
and performs the following logic
newline = ""
read in a record
if the record starts with a 6 and newline = ''
newline = record
... | [
"None of the branches in your if statement finish with newline set to \"\". Therefore, the first branch will never evaluate because newline is never \"\" except for the very first case.\n",
"You can simplify this by simply appending a newline for a record that starts with 6, and not appending one if it doens't.\... | [
0,
0,
0
] | [] | [] | [
"file_io",
"python"
] | stackoverflow_0001120555_file_io_python.txt |
Q:
bash/cygwin/$PATH: Do I really have to reboot to alter $PATH?
I wanted to use the Python installed under cygwin rather than one installed under WinXP directly, so I edited ~/.bashrc and sourced it. Nothing changed. I tried other things, but nothing I did changed $PATH in any way. So I rebooted. Aha; now $PATH ... | bash/cygwin/$PATH: Do I really have to reboot to alter $PATH? | I wanted to use the Python installed under cygwin rather than one installed under WinXP directly, so I edited ~/.bashrc and sourced it. Nothing changed. I tried other things, but nothing I did changed $PATH in any way. So I rebooted. Aha; now $PATH has changed to what I wanted.
But, can anyone explain WHY this happ... | [
"Try:\nPATH=\"${PATH}:${PYTHON}\"; export PATH\n\nOr:\nexport PATH=\"${PATH}:${PYTHON}\"\n\nthe quotes preserve the spaces and newlines that you don't have in your directory names. I repeat \"don't\".\nIf you want to change the path for the current environment and any subsequent processes, use something similar to ... | [
3,
2,
1,
0
] | [] | [] | [
"bash",
"cygwin",
"path",
"python",
"reboot"
] | stackoverflow_0001122924_bash_cygwin_path_python_reboot.txt |
Q:
Migrating Django Application to Google App Engine?
I'm developing a web application and considering Django, Google App Engine, and several other options. I wondered what kind of "penalty" I will incur if I develop a complete Django application assuming it runs on a dedicated server, and then later want to migrate ... | Migrating Django Application to Google App Engine? | I'm developing a web application and considering Django, Google App Engine, and several other options. I wondered what kind of "penalty" I will incur if I develop a complete Django application assuming it runs on a dedicated server, and then later want to migrate it to Google App Engine.
I have a basic understanding of... | [
"Most (all?) of Django is available in GAE, so your main task is to avoid basing your designs around a reliance on anything from Django or the Python standard libraries which is not available on GAE.\nYou've identified the glaring difference, which is the database, so I'll assume you're on top of that. Another diff... | [
8,
2,
2,
1
] | [] | [] | [
"django",
"google_app_engine",
"python"
] | stackoverflow_0001118761_django_google_app_engine_python.txt |
Q:
Python Function Decorators in Google App Engine
I'm having trouble using python function decorators in Google's AppEngine. I'm not that familiar with decorators, but they seem useful in web programming when you might want to force a user to login before executing certain functions.
Anyway, I was following along... | Python Function Decorators in Google App Engine | I'm having trouble using python function decorators in Google's AppEngine. I'm not that familiar with decorators, but they seem useful in web programming when you might want to force a user to login before executing certain functions.
Anyway, I was following along with a flickr login example here that uses django an... | [
"You're calling content() without any arguments, but the decorated version protected_view requires the request argument. Either add the argument to content or remove it from protected_view.\nIf you're getting that error with your simple version then I'd suspect that content is a class method as Alex suggested. Othe... | [
3,
1,
0,
0
] | [] | [] | [
"decorator",
"google_app_engine",
"python"
] | stackoverflow_0001123117_decorator_google_app_engine_python.txt |
Q:
Setting a timeout function in django
So I'm creating a django app that allows a user to add a new line of text to an existing group of text lines. However I don't want multiple users adding lines to the same group of text lines concurrently. So I created a BoolField isBeingEdited that is set to True once a user de... | Setting a timeout function in django | So I'm creating a django app that allows a user to add a new line of text to an existing group of text lines. However I don't want multiple users adding lines to the same group of text lines concurrently. So I created a BoolField isBeingEdited that is set to True once a user decides to append a specific group. Once the... | [
"Change the boolean to a \"lock time\"\n\nTo lock the model, set the Lock time to the current time. \nTo unlock the model, set the lock time to None\nAdd an \"is_locked\" method. That method returns \"not locked\" if the current time is more than 10 minutes after the lock time. \n\nThis gives you your timeout witho... | [
4
] | [] | [] | [
"django",
"python"
] | stackoverflow_0001123367_django_python.txt |
Q:
Django ManyToMany Template rendering and performance issues
I've got a django model that contains a manytomany relationship, of the type,
class MyModel(models.Model):
name = ..
refby = models.ManyToManyField(MyModel2)
..
class MyModel2(..):
name = ..
date = ..
I need to render it in my template such th... | Django ManyToMany Template rendering and performance issues | I've got a django model that contains a manytomany relationship, of the type,
class MyModel(models.Model):
name = ..
refby = models.ManyToManyField(MyModel2)
..
class MyModel2(..):
name = ..
date = ..
I need to render it in my template such that I am able to render all the mymodel2 objects that refer to mym... | [
"I assume mymodel_obj_list is a QuerySet. You're accessing a foreign key field inside the loop, which means, by default, Django will look up each object's refby one at a time, when you access it. If you're displaying a lot of rows, this is extremely slow.\nCall select_related on the QuerySet, to pull in all of th... | [
4,
0
] | [] | [] | [
"django",
"django_templates",
"many_to_many",
"performance",
"python"
] | stackoverflow_0001122605_django_django_templates_many_to_many_performance_python.txt |
Q:
How do I grab an instance of a dynamic php script output?
The following link outputs a different image every time you visit it:
http://www.biglickmedia.com/art/random/index.php
From a web browser, you can obviously right click it and save what you see. But if I were to visit this link from a command line (like thr... | How do I grab an instance of a dynamic php script output? | The following link outputs a different image every time you visit it:
http://www.biglickmedia.com/art/random/index.php
From a web browser, you can obviously right click it and save what you see. But if I were to visit this link from a command line (like through python+mechanize), how would I save the image that would o... | [
"you might need something that creates a socket to the server and then issues a http GET request for \"art/random/index.php\". save the payload from the HTTP response, and then you have your data\nwhat you would be creating is a simple HTTP client\nthe unix command wget does this:\n$ wget http://www.biglickmedia.co... | [
4,
1,
1
] | [] | [] | [
"download",
"image",
"php",
"python",
"screen_scraping"
] | stackoverflow_0001123622_download_image_php_python_screen_scraping.txt |
Q:
Modifying Collection when using a foreach loop in c#
Basically, I would like to remove an item from a list whilst inside the foreach loop. I know that this is possible when using a for loop, but for other purposes, I would like to know if this is achievable using a foreach loop.
In python we can achieve this by do... | Modifying Collection when using a foreach loop in c# | Basically, I would like to remove an item from a list whilst inside the foreach loop. I know that this is possible when using a for loop, but for other purposes, I would like to know if this is achievable using a foreach loop.
In python we can achieve this by doing the following:
a = [1, 2, 3, 4, 5, 6, 7, 8, 9]
for i ... | [
"You can't do this. From the docs for IEnumerator<T>:\n\nAn enumerator remains valid as long as\n the collection remains unchanged. If\n changes are made to the collection,\n such as adding, modifying, or deleting\n elements, the enumerator is\n irrecoverably invalidated and its\n behavior is undefined.\n\nAl... | [
26,
6,
1
] | [] | [] | [
"c#",
"invalidoperationexception",
"python"
] | stackoverflow_0001124221_c#_invalidoperationexception_python.txt |
Q:
Socket? python -m SimpleHTTPServer
Problem: to get the command working here. My domain is http://cs.edu.com/user/share_dir, but I cannot get the command working by typing it to a browser:
http://cs.edu.com/user/share_dir:8000
Question: How can I get the command working?
A:
Your URL is incorrect. The port number... | Socket? python -m SimpleHTTPServer | Problem: to get the command working here. My domain is http://cs.edu.com/user/share_dir, but I cannot get the command working by typing it to a browser:
http://cs.edu.com/user/share_dir:8000
Question: How can I get the command working?
| [
"Your URL is incorrect. The port number should be specified after the domain name:\nhttp://cs.edu.com:8000/\nSome other things you should keep in mind:\n\nIf this is a shared host, port 8000 might already be in use by someone else\nThe host might not be accessible from 'outside' of the network, due to firewall rest... | [
5
] | [] | [] | [
"python",
"sockets"
] | stackoverflow_0001124420_python_sockets.txt |
Q:
Python's subprocess.Popen returns the same stdout even though it shouldn't
I'm having a very strange issue with Python's subprocess.Popen. I'm using it to call several times an external exe and keep the output in a list.
Every time you call this external exe, it will return a different string. However, if I call... | Python's subprocess.Popen returns the same stdout even though it shouldn't | I'm having a very strange issue with Python's subprocess.Popen. I'm using it to call several times an external exe and keep the output in a list.
Every time you call this external exe, it will return a different string. However, if I call it several times using Popen, it will always return the SAME string. =:-O
It ... | [
"It is possible (if C_KEY_MAKER's random behaviour is based on the current time in seconds, or similar) that when you run it twice on the command line, the time has changed in between runs and so you get a different output, but when python runs it, it runs it twice in such quick succession that the time hasn't chan... | [
3,
1,
1,
0
] | [] | [] | [
"popen",
"python",
"stdout",
"subprocess"
] | stackoverflow_0000717120_popen_python_stdout_subprocess.txt |
Q:
Problem deploying Python program (packaged with py2exe)
I have a problem: I used py2exe for my program, and it worked on my computer. I packaged it with Inno Setup (still worked on my computer), but when I sent it to a different computer, I got the following error when trying to run the application: "CreateProcess... | Problem deploying Python program (packaged with py2exe) | I have a problem: I used py2exe for my program, and it worked on my computer. I packaged it with Inno Setup (still worked on my computer), but when I sent it to a different computer, I got the following error when trying to run the application: "CreateProcess failed; code 14001." The app won't run.
(Note: I am using wx... | [
"You need to include msvcr90.dll, Microsoft.VC90.CRT.manifest, and python.exe.manifest (renamed to [yourappname].exe.manifest) in your install directory. These files will be in the Python26 directory on your system if you installed Python with the \"Just for me\" option.\nInstructions for doing this can be found he... | [
3,
1,
1,
0
] | [] | [] | [
"deployment",
"multiprocessing",
"py2exe",
"python",
"wxpython"
] | stackoverflow_0001048651_deployment_multiprocessing_py2exe_python_wxpython.txt |
Q:
What's the simplest possible buildout.cfg to install Zope 2?
I know that the reccomended way to install Zope is with Buildout, but I can't seem to find a simple buildout.cfg to install a minimal Zope 2 environment. There are lots to install Plone and other things.
I've tried:
[buildout]
parts = zope
[zope]
recipe... | What's the simplest possible buildout.cfg to install Zope 2? | I know that the reccomended way to install Zope is with Buildout, but I can't seem to find a simple buildout.cfg to install a minimal Zope 2 environment. There are lots to install Plone and other things.
I've tried:
[buildout]
parts = zope
[zope]
recipe = plone.recipe.zope2install
eggs =
But I get:
An internal error... | [
"You need to tell plone.recipe.zope2install where to download Zope. Also, you'll need a zope2instance section, to create a Zope instance for you. These recipes are only needed for Zope up to version 2.11, as of 2.12 Zope has been fully eggified.\nHere is a minimal Zope 2.11 buildout.cfg:\n[buildout]\nparts = instan... | [
5
] | [] | [] | [
"buildout",
"python",
"zope"
] | stackoverflow_0001120758_buildout_python_zope.txt |
Q:
What is the best practice in deploying application on Windows?
I have an application that consists of several .dlls, .libs, .pyd (python library), .exe, .class-es.
What is the best practice in the deployment process?
I plan to put .dlls - managed into GAC and unmanaged into WinSxS folder.
What should I do with .li... | What is the best practice in deploying application on Windows? | I have an application that consists of several .dlls, .libs, .pyd (python library), .exe, .class-es.
What is the best practice in the deployment process?
I plan to put .dlls - managed into GAC and unmanaged into WinSxS folder.
What should I do with .libs, .exe, .class and .pyd?
Is it ok to put it to
/ProgramFiles/Appl... | [
"The current convention seems to be \n\"/ProgramFiles/YourCompany/YourApplication/...\" \nAs for how to structure things under that folder, it is really dependent on what your application is doing, and how it's structured. Do make sure to store per-user information in Isolated Storage.\n",
"I agree that /Progra... | [
2,
1
] | [] | [] | [
"deployment",
"python",
"windows"
] | stackoverflow_0001124667_deployment_python_windows.txt |
Q:
Generic object "ownership" in Django
Suppose I have the following models:
class User(models.Model):
pass
class A(models.Model):
user = models.ForeignKey(User)
class B(models.Model):
a = models.ForeignKey(A)
That is, each user owns some objects of type A, and also some of type B. Now, I'm writing a ... | Generic object "ownership" in Django | Suppose I have the following models:
class User(models.Model):
pass
class A(models.Model):
user = models.ForeignKey(User)
class B(models.Model):
a = models.ForeignKey(A)
That is, each user owns some objects of type A, and also some of type B. Now, I'm writing a generic interface that will allow the use... | [
"The way I would do it is to simply go through the object 'a' on class B. So in the view, I would do:\nobjects = B.objects.get(user=a.user)\nobjects += A.objects.get(user=user)\n\nThe reason I would do it this way is because these are essentially two database queries, one to retrieve a bunch of object A's and one t... | [
0
] | [] | [] | [
"django",
"python"
] | stackoverflow_0001125006_django_python.txt |
Q:
Caching PHP script outputs on the client side
I have a php script that outputs a random image each time it's called. So when I open the script in a web browser, it shows one image and if I refresh, another image shows up.
I'm trying to capture the correct image from visiting the web site through a command line (vi... | Caching PHP script outputs on the client side | I have a php script that outputs a random image each time it's called. So when I open the script in a web browser, it shows one image and if I refresh, another image shows up.
I'm trying to capture the correct image from visiting the web site through a command line (via mechanize). I used urllib2.urlopen(...) to grab t... | [
"Most likely your image is cached by browser set this:\n<?php\n header(\"Cache-Control: no-cache, must-revalidate\"); // HTTP/1.1\n header(\"Expires: Sat, 26 Jul 1997 05:00:00 GMT\"); // Date in the past\n?>\n\nand each time you generating the image use another name for it (can be done by adding milliseco... | [
1,
1,
1,
0
] | [] | [] | [
"caching",
"mechanize",
"php",
"python"
] | stackoverflow_0001117890_caching_mechanize_php_python.txt |
Q:
Question about paths in Python
let's say i have directory paths looking like this:
this/is/the/basedir/path/a/include
this/is/the/basedir/path/b/include
this/is/the/basedir/path/a
this/is/the/basedir/path/b
In Python, how can i split these paths up so they will look like this instead:
a/include
b/include
a
b
If ... | Question about paths in Python | let's say i have directory paths looking like this:
this/is/the/basedir/path/a/include
this/is/the/basedir/path/b/include
this/is/the/basedir/path/a
this/is/the/basedir/path/b
In Python, how can i split these paths up so they will look like this instead:
a/include
b/include
a
b
If i run os.path.split(path)[1] it will... | [
"Perhaps something like this, depends on how hardcoded your prefix is:\ndef removePrefix(path, prefix):\n plist = path.split(os.sep)\n pflist = prefix.split(os.sep)\n rest = plist[len(pflist):]\n return os.path.join(*rest)\n\nUsage:\nprint removePrefix(\"this/is/the/basedir/path/b/include\", \"this/is/t... | [
3,
1,
1,
0
] | [] | [] | [
"operating_system",
"python"
] | stackoverflow_0001125399_operating_system_python.txt |
Q:
Running Python code from a server?
Problem: to run one.py from a server.
Error
When I try to do it in Mac, I get errors:
$python http://cs.edu.com/u/user/TEST/one.py ~
/Library/Frameworks/Python.framework/Versions/2.5/Resources/Python.app/Contents/MacOS/Python: can't open file 'http://cs.edu... | Running Python code from a server? | Problem: to run one.py from a server.
Error
When I try to do it in Mac, I get errors:
$python http://cs.edu.com/u/user/TEST/one.py ~
/Library/Frameworks/Python.framework/Versions/2.5/Resources/Python.app/Contents/MacOS/Python: can't open file 'http://cs.edu.com/u/user/TEST/one.py': [Errno 2] No s... | [
"So far as I know, the standard Python shell doesn't know how to execute remote scripts. Try using curl or wget to retrieve the script and run it from the local copy.\n$ wget http://cs.edu.com/u/user/TEST/one.py\n$ python one.py\n\nUPDATE: Based on the question referenced in the comment to this answer, you need to ... | [
3,
3,
1,
1,
1,
1,
1
] | [] | [] | [
"python"
] | stackoverflow_0001125637_python.txt |
Q:
List comprehension python
What is the equivalent list comprehension in python of the following Common Lisp code:
(loop for x = input then (if (evenp x)
(/ x 2)
(+1 (* 3 x)))
collect x
until (= x 1))
A:
A list comprehension is used to take an e... | List comprehension python | What is the equivalent list comprehension in python of the following Common Lisp code:
(loop for x = input then (if (evenp x)
(/ x 2)
(+1 (* 3 x)))
collect x
until (= x 1))
| [
"A list comprehension is used to take an existing sequence and perform some function and/or filter to it, resulting in a new list. So, in this case a list comprehension is not appropriate since you don't have a starting sequence. An example with a while loop:\nnumbers = []\nx=input()\nwhile x != 1:\n numbers.appen... | [
10,
9,
4,
4,
3,
0
] | [] | [] | [
"lisp",
"list_comprehension",
"python"
] | stackoverflow_0001122612_lisp_list_comprehension_python.txt |
Q:
webdav for wsgi/python?
I want to add WebDAV to whiff. This would be easy if I could find a simple WSGI component that implements WebDAV. I found http://pyfilesync.berlios.de/pyfileserver.html, but it seems to insist on using an external configuration file. I want to control everything via a Python API. Any ideas?... | webdav for wsgi/python? | I want to add WebDAV to whiff. This would be easy if I could find a simple WSGI component that implements WebDAV. I found http://pyfilesync.berlios.de/pyfileserver.html, but it seems to insist on using an external configuration file. I want to control everything via a Python API. Any ideas?
Thanks!
| [
"I recently picked up PyFileServer for further development:\n http://code.google.com/p/wsgidav/\nAfter the config file is read, it's only a plain dictionary, that is passed to the WSGI Application object's constructor.\nSo it should be pretty easy to do what you want.\nI didn't use whiff yet, but you are invited... | [
3
] | [] | [] | [
"python",
"webdav",
"wsgi"
] | stackoverflow_0001050217_python_webdav_wsgi.txt |
Q:
Platform-independent version of /var/lib and ~/.config
We see that programs like apt-get store information in several places:
/var/cache/apt <- cache
/var/lib/apt <- keyrings, package db, states, locks, mirrors
/etc/apt <- configuration file
~/.aptitude/config <- user configuration file
So... | Platform-independent version of /var/lib and ~/.config | We see that programs like apt-get store information in several places:
/var/cache/apt <- cache
/var/lib/apt <- keyrings, package db, states, locks, mirrors
/etc/apt <- configuration file
~/.aptitude/config <- user configuration file
So we see four kinds of paths here:
Cache path
Data path
Syst... | [
"For Linux, check out the Filesystem Hierarchy Standard (but be aware that these standards are for software being part of distribution, software installed locally should not interfere with distribution's package management and stay in /usr/local/ and /var/local/).\nIf you want to be truly cross-platform, IMO best w... | [
1
] | [
"Do you mean something like virtualenv?\n"
] | [
-1
] | [
"configuration",
"cross_platform",
"path",
"python"
] | stackoverflow_0001107213_configuration_cross_platform_path_python.txt |
Q:
writeline problem in python
I have a very basic problem. I am learning my first steps with python & scripting in general and so even this makes me wonder:
I want to read & write lines to new file:
ifile=open("C:\Python24\OtsakkeillaSPSS.csv", "r")
ofile = open("C:\Python24\OtsakkeillaSPSSout.csv", "w")
#read firs... | writeline problem in python | I have a very basic problem. I am learning my first steps with python & scripting in general and so even this makes me wonder:
I want to read & write lines to new file:
ifile=open("C:\Python24\OtsakkeillaSPSS.csv", "r")
ofile = open("C:\Python24\OtsakkeillaSPSSout.csv", "w")
#read first line with headers
line1 = ifile... | [
"#read following lines which contain data & write it to ofile\nfor line in ifile:\n if not line:\n continue #break stops the loop, you should use continue\n ofile.write(line)\n\n",
"You should be calling ofile.close() according to python docs.\nI'm not sure that writes are fully flushed out ... | [
4,
4,
3,
1,
0
] | [] | [] | [
"python"
] | stackoverflow_0001126477_python.txt |
Q:
Special chars in Python
i have to use special chars in my python-application.
For example: ƃ
I have information like this:
U+0183 LATIN SMALL LETTER B WITH TOPBAR
General Character Properties
In Unicode since: 1.1
Unicode category: Letter, Lowercase
Various Useful Representations
UTF-8: 0xC6 0x83
UTF-16: 0x018... | Special chars in Python | i have to use special chars in my python-application.
For example: ƃ
I have information like this:
U+0183 LATIN SMALL LETTER B WITH TOPBAR
General Character Properties
In Unicode since: 1.1
Unicode category: Letter, Lowercase
Various Useful Representations
UTF-8: 0xC6 0x83
UTF-16: 0x0183
C octal escaped UTF-8: \30... | [
"You should tell the interpreter which encoding you're using, because apparently on your system it defaults to ascii. See PEP 263. In your case, place the following at the top of your file:\n# -*- coding: utf-8 -*-\n\nNote that you don't have to write exactly that; PEP 263 allows more freedom, to accommodate severa... | [
11,
3,
3,
1,
0,
0
] | [] | [] | [
"chars",
"python"
] | stackoverflow_0001127786_chars_python.txt |
Q:
Unable to find an internet page blocked by robots.txt
Problem: to find answers and exercises of lectures in Mathematics at Uni. Helsinki
Practical problems
to make a list of sites with .com which has Disallow in robots.txt
to make a list of sites at (1) which contain files with *.pdf
to make a list of sites at (2... | Unable to find an internet page blocked by robots.txt | Problem: to find answers and exercises of lectures in Mathematics at Uni. Helsinki
Practical problems
to make a list of sites with .com which has Disallow in robots.txt
to make a list of sites at (1) which contain files with *.pdf
to make a list of sites at (2) which contain the word "analyysi" in pdf-files
Suggestio... | [
"\nI am trying to find every web site on the internet that has a pdf-file which has the word \"Analyysi\"\n\nNot an answer to your question, but: PLEASE respect the site owner's wish to NOT be indexed.\n",
"Your questions are faulty.\nWith respect to (2), you are making the faulty assumption that you can find all... | [
6,
4,
3,
1,
0,
0
] | [] | [] | [
"data_mining",
"python",
"web_crawler"
] | stackoverflow_0001009686_data_mining_python_web_crawler.txt |
Q:
django-timezones
I am trying to setup django-timezones but am unfamiliar on how to go about this. The only info that I have found is here: http://www.ohloh.net/p/django-timezones
class MyModel(Model):
timezone = TimeZoneField()
datetime = LocalizedDateTime('timezone')
I also tried looking through the p... | django-timezones | I am trying to setup django-timezones but am unfamiliar on how to go about this. The only info that I have found is here: http://www.ohloh.net/p/django-timezones
class MyModel(Model):
timezone = TimeZoneField()
datetime = LocalizedDateTime('timezone')
I also tried looking through the pinax code or any other... | [
"Well, the firs thing you need to do when installing any Django app, is add it to your INSTALLED_APPS in settings.py. This particular app doesn't do to much other then give you some handy fields and things that you can use in other parts of your Django project. Your best bet to understand it is reading the source, ... | [
4
] | [] | [] | [
"django",
"python",
"timezone"
] | stackoverflow_0001126811_django_python_timezone.txt |
Q:
How can I obtain the full AST in Python?
I like the options offered by the _ast module, it's really powerful. Is there a way of getting the full AST from it?
For example, if I get the AST of the following code :
import os
os.listdir(".")
by using :
ast = compile(source_string,"<string>","exec",_ast.PyCF_ON... | How can I obtain the full AST in Python? | I like the options offered by the _ast module, it's really powerful. Is there a way of getting the full AST from it?
For example, if I get the AST of the following code :
import os
os.listdir(".")
by using :
ast = compile(source_string,"<string>","exec",_ast.PyCF_ONLY_AST)
the body of the ast object will have ... | [
"You do get the whole tree this way -- all the way to the bottom -- but, it IS held as a tree, exactly... so at each level to get the children you have to explicitly visit the needed attributes. For example (i'm naming the compile result cf rather than ast because that would hide the standard library ast module -- ... | [
8,
5
] | [] | [] | [
"abstract_syntax_tree",
"python"
] | stackoverflow_0001128234_abstract_syntax_tree_python.txt |
Q:
To understand Typeset for PythonPath
One recommends me the following code apparently only in .zshrc without explaining its purpose clearly.
typeset -U PYTHONPATH
I am interested in how you can use the code in .bashrc. My Bash goes upset about the command.
How can you use the command in Bash?
A:
That zsh command... | To understand Typeset for PythonPath | One recommends me the following code apparently only in .zshrc without explaining its purpose clearly.
typeset -U PYTHONPATH
I am interested in how you can use the code in .bashrc. My Bash goes upset about the command.
How can you use the command in Bash?
| [
"That zsh command is useful because zsh can treat the environment variable PYTHONPATH as an actual array of paths. The -U argument to typeset says, then when representing the array in the environment value passed to the program (Python, in this case), only include the first instance of each unique value.\nIn bash,... | [
3
] | [] | [] | [
"bash",
"path",
"python",
"typeset",
"zsh"
] | stackoverflow_0001128366_bash_path_python_typeset_zsh.txt |
Q:
Need some help with python string / slicing operations
This is a very newbie question and i will probably get downvoted for it, but i quite honestly couldn't find the answer after at least an hour googling. I learned how to slice strings based on "exact locations" where you have to know exactly where the word ends... | Need some help with python string / slicing operations | This is a very newbie question and i will probably get downvoted for it, but i quite honestly couldn't find the answer after at least an hour googling. I learned how to slice strings based on "exact locations" where you have to know exactly where the word ends. But i did not find any article that explained how do it on... | [
"Why is split overkill?\nverb, title, definition = myString.split (' ', 2)\n\n",
"If you have spaces between your command, title, and definition you could:\nwordList = myString.split()\ncmd = wordList[0] # !save\ntitle = wordList[1] # python\ndefinition = ' '.join(wordList[2:]) # Python is a high-level object or... | [
12,
2,
1
] | [] | [] | [
"python",
"slice",
"string"
] | stackoverflow_0001128431_python_slice_string.txt |
Q:
What can I attach to pylons.request in Pylons?
I want keep track of a unique identifier for each browser that connects to my web application (that is written in Pylons.) I keep a cookie on the client to keep track of this, but if the cookie isn't present, then I want to generate a new unique identifier that will ... | What can I attach to pylons.request in Pylons? | I want keep track of a unique identifier for each browser that connects to my web application (that is written in Pylons.) I keep a cookie on the client to keep track of this, but if the cookie isn't present, then I want to generate a new unique identifier that will be sent back to the client with the response, but I ... | [
"Why do you want a unique identifier? Basically every visitor already gets a unique identifier, his Session. Beaker, Pylons session and caching middleware, does all the work and tracks visitors, usually with a Session cookie. So don't care about tracking users, just use the Session for what it's made for, to store ... | [
3,
0
] | [] | [] | [
"pylons",
"python",
"thread_safety"
] | stackoverflow_0001122537_pylons_python_thread_safety.txt |
Q:
wxPython, how do I fire events?
I am making my own button class, subclass of a panel where I draw with a DC, and I need to fire wx.EVT_BUTTON when my custom button is pressed. How do I do it?
A:
The Wiki is pretty nice for reference. Andrea Gavana has a pretty complete recipe for building your own custom contro... | wxPython, how do I fire events? | I am making my own button class, subclass of a panel where I draw with a DC, and I need to fire wx.EVT_BUTTON when my custom button is pressed. How do I do it?
| [
"The Wiki is pretty nice for reference. Andrea Gavana has a pretty complete recipe for building your own custom controls. The following is taken directly from there and extends what FogleBird answered with (note self is referring to a subclass of wx.PyControl):\ndef SendCheckBoxEvent(self):\n \"\"\" Actually s... | [
9,
6
] | [] | [] | [
"events",
"python",
"wxpython"
] | stackoverflow_0001128074_events_python_wxpython.txt |
Q:
how do i filter an itertools chain() result?
in my views,
if i import an itertools module:
from itertools import chain
and i chain some objects with it:
franktags = Frank.objects.order_by('date_added').reverse().filter(topic__exact='art')
amytags = Amy.objects.order_by('date_added').reverse().filter(topic__exact... | how do i filter an itertools chain() result? | in my views,
if i import an itertools module:
from itertools import chain
and i chain some objects with it:
franktags = Frank.objects.order_by('date_added').reverse().filter(topic__exact='art')
amytags = Amy.objects.order_by('date_added').reverse().filter(topic__exact='art')
timtags = Tim.objects.order_by('date_adde... | [
"import operator\n\nourtags = sorted(ourtags, key=operator.attrgetter('date_added'))\n\n",
"By this point in the code, you've already loaded up all of the objects into memory and into a list. Just sort the list like you would any old Python list.\n>>> import operator\n>>> ourtags.sort(key=operator.attrgetter('da... | [
14,
5
] | [] | [] | [
"django",
"django_views",
"python",
"python_itertools"
] | stackoverflow_0001129344_django_django_views_python_python_itertools.txt |
Q:
How to split two nested lists and combine the parts to create two new nested lists
I'm trying to code a simple genetic programming utility in python. But right now I'm stuck at the crossover/mate function for my trees. The trees are built by nested lists and look something like this:
# f = internal node (a functio... | How to split two nested lists and combine the parts to create two new nested lists | I'm trying to code a simple genetic programming utility in python. But right now I'm stuck at the crossover/mate function for my trees. The trees are built by nested lists and look something like this:
# f = internal node (a function), c = leaf node (a constant)
tree1 = [f, [f, [f, c, c], [f, c, c]], [f, [f, c, c], [f,... | [
"I ended up implementing most of this as an exercise.\nFirst, find the number of possible locations to split: the number of non-function nodes.\ndef count(obj):\n total = 0\n for o in obj[1:]:\n # Add the node itself.\n total += 1\n\n if isinstance(o, list):\n total += count(o)... | [
2,
0
] | [] | [] | [
"genetic_programming",
"list",
"python"
] | stackoverflow_0001128924_genetic_programming_list_python.txt |
Q:
key=operator.attrgetter sort order?
in my django view, if i import operator, and use the following code:
multitags = sorted(multitags, key=operator.attrgetter('date_added'))
is there an easy way to reverse the order – such that i get the dates in descending order
(today at top; last week underneath)?
A:
This sh... | key=operator.attrgetter sort order? | in my django view, if i import operator, and use the following code:
multitags = sorted(multitags, key=operator.attrgetter('date_added'))
is there an easy way to reverse the order – such that i get the dates in descending order
(today at top; last week underneath)?
| [
"This should work:\nsorted(multitags, key=operator.attrgetter('date_added'), reverse=True)\n\nThis document on the python wiki is worth reading through at least once to get an idea of other things worth knowing:\n\nSorting Mini HOWTO\n\n",
"Sure, just add reverse=True to the keyword arguments with which you're ca... | [
10,
3
] | [] | [] | [
"django",
"python",
"python_itertools"
] | stackoverflow_0001129548_django_python_python_itertools.txt |
Q:
creating non-reloading dynamic webapps using Django
As far as I know, for a new request coming from a webapp, you need to reload the page to process and respond to that request.
For example, if you want to show a comment on a post, you need to reload the page, process the comment, and then show it. What I want,... | creating non-reloading dynamic webapps using Django | As far as I know, for a new request coming from a webapp, you need to reload the page to process and respond to that request.
For example, if you want to show a comment on a post, you need to reload the page, process the comment, and then show it. What I want, however, is I want to be able to add comments (something... | [
"You want to do that with out any client side code (javascript and ajax are just examples) and with out reloading your page (or at least part of it)?\nIf that is your question, then the answer unfortunately is you can't. You need to either have client side code or reload your page.\nThink about it, once the client ... | [
8,
3,
1,
1
] | [] | [] | [
"ajax",
"django",
"python"
] | stackoverflow_0001129210_ajax_django_python.txt |
Q:
Is it possible to encode (asdf) in python Textile?
I'm using python Textile to store markup in the database. I would like to yield the following HTML snippet:
(<em>asdf</em>)
The obvious doesn't get encoded:
(_asdf_) -> <p>(_asdf_)</p>
The following works, but yields an ugly space:
( _asdf_) -> <p>( <em... | Is it possible to encode (asdf) in python Textile? | I'm using python Textile to store markup in the database. I would like to yield the following HTML snippet:
(<em>asdf</em>)
The obvious doesn't get encoded:
(_asdf_) -> <p>(_asdf_)</p>
The following works, but yields an ugly space:
( _asdf_) -> <p>( <em>asdf</em>)
Am I missing something obvious or is this j... | [
"It's hard to say if this is a bug or not; in the form on the Textile website, (_foo_) works as you want, but in the downloadable PHP implementation, it doesn't.\nYou should be able to do this:\n([_asdf_]) -> <p>(<em>asdf</em>)</p>\n\nHowever, this doesn't work, which is a bug in py-textile. You either need to u... | [
1
] | [] | [] | [
"markup",
"python",
"textile"
] | stackoverflow_0001128951_markup_python_textile.txt |
Q:
Django: reverse function fails with an exception
I'm following the Django tutorial and got stuck with an error at part 4 of the tutorial. I got to the part where I'm writing the vote view, which uses reverse to redirect to another view. For some reason, reverse fails with the following exception:
import() argumen... | Django: reverse function fails with an exception | I'm following the Django tutorial and got stuck with an error at part 4 of the tutorial. I got to the part where I'm writing the vote view, which uses reverse to redirect to another view. For some reason, reverse fails with the following exception:
import() argument 1 must be string, not instancemethod
Currently my p... | [
"The way you include the admin URLs has changed a few times over the last couple of versions. It's likely that you are using the wrong instructions for the version of Django you have installed.\nIf you are using the current trunk - ie not an official release - then the documentation at http://docs.djangoproject.com... | [
6
] | [] | [] | [
"admin",
"django",
"python",
"reverse"
] | stackoverflow_0001129769_admin_django_python_reverse.txt |
Q:
Is there an option to configure a priority in memcached? (Similiar to Expiry)
A hashtable in memcached will be discarded either when it's Expired or when there's not enough memory and it's choosen to die based on the Least Recently Used algorithm.
Can we put a Priority to hint or influence the LRU algorithm? I wan... | Is there an option to configure a priority in memcached? (Similiar to Expiry) | A hashtable in memcached will be discarded either when it's Expired or when there's not enough memory and it's choosen to die based on the Least Recently Used algorithm.
Can we put a Priority to hint or influence the LRU algorithm? I want to use memcached to store Web Sessions so i can use the cheap round-robin.
I nee... | [
"Not that I know of.\nmemcached is designed to be very fast and very straightforward, no fancy weights and priorities keep it simple.\nYou should not rely on memcache for persistent session storage. You should keep your sessions in the DB, but you can cache them in memcache. This way you can enjoy both worlds.\n"
] | [
1
] | [] | [] | [
"caching",
"database",
"memcached",
"python",
"session"
] | stackoverflow_0001000540_caching_database_memcached_python_session.txt |
Q:
virtualenv with all Python libraries
I need to get Python code, which relies on Python 2.6, running on a machine with only Python 2.3 (I have no root access).
This is a typical scenario for virtualenv. The only problem is that I cannot convince it to copy all libraries to the new environment as well.
virtualenv --... | virtualenv with all Python libraries | I need to get Python code, which relies on Python 2.6, running on a machine with only Python 2.3 (I have no root access).
This is a typical scenario for virtualenv. The only problem is that I cannot convince it to copy all libraries to the new environment as well.
virtualenv --no-site-packages my_py26
does not do wha... | [
"No, I think you completely misunderstood what virtualenv does. Virtualenv is to create a new environment on the same machine that is isolated from the main environment. In such an environment you can install packages that do not get installed in the main environment, and with --no-site-packages you can also isolat... | [
4,
4,
0
] | [] | [] | [
"linux",
"python",
"virtualenv"
] | stackoverflow_0001130402_linux_python_virtualenv.txt |
Q:
Get POST data from a complex Django form?
I have a Django form that uses a different number of fields based on the year/month. So I create the fields in the form like this:
for entry in entry_list:
self.fields[entry] = forms.DecimalField([stuffhere])
but now I don't know how to get the submitted data from the... | Get POST data from a complex Django form? | I have a Django form that uses a different number of fields based on the year/month. So I create the fields in the form like this:
for entry in entry_list:
self.fields[entry] = forms.DecimalField([stuffhere])
but now I don't know how to get the submitted data from the form.
Normally I would do something like:
form... | [
"I think you might be better off using formsets here. They're designed for exactly what you seem to be trying to do - dealing with a variable number of items within a form.\n",
"In this line:\n\nself.fields[entry] = forms.DecimalField(max_digits=4, decimal_places=1, label=nice_label)\n\nentry is a model instance.... | [
5,
0
] | [] | [] | [
"django",
"django_forms",
"python"
] | stackoverflow_0001130575_django_django_forms_python.txt |
Q:
which exception catches xxxx error in python
given a traceback error log, i don't always know how to catch a particular exception.
my question is in general, how do i determine which "except" clause to write in order to handle a certain exception.
example 1:
File "c:\programs\python\lib\httplib.py", line 683, in... | which exception catches xxxx error in python | given a traceback error log, i don't always know how to catch a particular exception.
my question is in general, how do i determine which "except" clause to write in order to handle a certain exception.
example 1:
File "c:\programs\python\lib\httplib.py", line 683, in connect
raise socket.error, msg
error: (10065... | [
"Look at the stack trace. The code that raises the exception is: raise socket.error, msg.\nSo the answer to your question is: You have to catch socket.error.\nimport socket\n...\ntry:\n ...\nexcept socket.error:\n ...\n\n",
"First one is also obvious, as second one e.g.\n>>> try:\n... socket.socket().co... | [
4,
3,
0
] | [] | [] | [
"exception",
"python"
] | stackoverflow_0001130764_exception_python.txt |
Q:
most efficient data structure for a read-only list of strings (about 100,000) with fast prefix search
I'm writing an application that needs to read a list of strings from a file, save them in a data structure, and then look up those strings by prefixes. The list of strings is simply a list of words in a given lang... | most efficient data structure for a read-only list of strings (about 100,000) with fast prefix search | I'm writing an application that needs to read a list of strings from a file, save them in a data structure, and then look up those strings by prefixes. The list of strings is simply a list of words in a given language. For example, if the search function gets "stup" as a parameter, it should return ["stupid", "stupidit... | [
"You want a trie.\nhttp://en.wikipedia.org/wiki/Trie\nI've used them in Scrabble and Boggle programs. They're perfect for the use case you described (fast prefix lookup).\nHere's some sample code for building up a trie in Python. This is from a Boggle program I whipped together a few months ago. The rest is left... | [
15,
4,
2
] | [
"string array.\nthen binary search through it to search the first match\nthen step one by one through it for all subsequent matches\n(i originally had linked list here too... but of course this doesn't have random access so this was 'bs' (which probably explains why I was downvoted). My binary search algorithm stil... | [
-1
] | [
"data_structures",
"dictionary",
"lookup",
"python"
] | stackoverflow_0001130992_data_structures_dictionary_lookup_python.txt |
Q:
Following a javascript postback using COM + IE automation to save text file
I want to automate the archiving of the data on this page http://energywatch.natgrid.co.uk/EDP-PublicUI/Public/InstantaneousFlowsIntoNTS.aspx, and upload into a database.
I have been using python and win32com (behind a corporate proxy, so... | Following a javascript postback using COM + IE automation to save text file | I want to automate the archiving of the data on this page http://energywatch.natgrid.co.uk/EDP-PublicUI/Public/InstantaneousFlowsIntoNTS.aspx, and upload into a database.
I have been using python and win32com (behind a corporate proxy, so no direct net access, hence I am using IE to do so) on other pages to do this. M... | [
"Here's a better way, using the mechanize library.\n\nimport mechanize\n\nb = mechanize.Browser()\nb.set_proxies({'http': 'yourproxy.corporation.com:3128' })\n\nb.addheaders = [('User-agent', 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)')]\nb.open(\"http://energywatch.natgrid.co.uk/EDP-PublicUI/Public/Instantane... | [
1
] | [] | [] | [
"com",
"javascript",
"python",
"web",
"webpage"
] | stackoverflow_0001130857_com_javascript_python_web_webpage.txt |
Q:
Getting "Comment post not allowed (400)" when using Django Comments
I'm going through a Django book and I seem to be stuck. The code base used in the book is .96 and I'm using 1.0 for my Django install. The portion I'm stuck at is related to Django comments (django.contrib.comments). When I submit my comments I... | Getting "Comment post not allowed (400)" when using Django Comments | I'm going through a Django book and I seem to be stuck. The code base used in the book is .96 and I'm using 1.0 for my Django install. The portion I'm stuck at is related to Django comments (django.contrib.comments). When I submit my comments I get "Comment post not allowed (400) Why: Missing content_type or object_... | [
"Django underwent a huge amount of change between 0.96 and 1.0, so it's not surprising you're having problems.\nFor your specific issue, see here.\nHowever I would suggest you find a more up-to-date book. It's not just the comments, but whole areas of Django are completely different from 0.96 - in particular the ad... | [
0,
0
] | [] | [] | [
"comments",
"django",
"python"
] | stackoverflow_0001120139_comments_django_python.txt |
Q:
Eliminating multiple inheritance
I have the following problem and I'm wondering if there's a nice way to model these objects without using multiple inheritance. If it makes any difference, I am using Python.
Students need contact information plus student information. Adults need contact information plus billing i... | Eliminating multiple inheritance | I have the following problem and I'm wondering if there's a nice way to model these objects without using multiple inheritance. If it makes any difference, I am using Python.
Students need contact information plus student information. Adults need contact information plus billing information. Students can be adult stud... | [
"What you have is an example of Role -- it's a common trap to model Role by inheritance, but Roles can change, and changing an object's inheritance structure (even in languages where it's possible, like Python) is not recommended. Children grow and become adults, and some adults will also be parents of children stu... | [
8,
5,
2,
2,
1,
1,
0,
0
] | [] | [] | [
"multiple_inheritance",
"oop",
"python"
] | stackoverflow_0001131599_multiple_inheritance_oop_python.txt |
Q:
Write unit tests for restish in Python
I'm writing a RESTful API in Python using the restish framework. I would like to write some unit tests (using the unittest package, for example), that will make different requests to my application and validate the results. The unit tests should be able to run as-is, withou... | Write unit tests for restish in Python | I'm writing a RESTful API in Python using the restish framework. I would like to write some unit tests (using the unittest package, for example), that will make different requests to my application and validate the results. The unit tests should be able to run as-is, without needing to start a separate web-server pro... | [
"I test everything using WebTest and NoseTests and I can strongly recommend it. It's fast, flexible and easy to set up. Just pass it your wsgi function and you're good to go.\n",
"Since restish is a WSGI framework, you can take advantage of any one of a number of WSGI testing tools:\n\nhttp://wsgi.org/wsgi/Testin... | [
1,
1,
1
] | [] | [] | [
"python",
"unit_testing"
] | stackoverflow_0001122192_python_unit_testing.txt |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.