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:
Python object has no referrers but still accessible via a weakref?
Should it be possible for gc.get_referrers(obj) to return an empty list for an object, but the object still be accessible through a weak reference?
If so how would I start trying to identify the cause for this object not being garbage collected?
Ed... | Python object has no referrers but still accessible via a weakref? | Should it be possible for gc.get_referrers(obj) to return an empty list for an object, but the object still be accessible through a weak reference?
If so how would I start trying to identify the cause for this object not being garbage collected?
Edit: I'm not sure exactly how a code sample would help in this case - the... | [
"Yes: http://docs.python.org/library/weakref.html\nA weak reference won't be keeping the object alive.\nThe get_referrers() function will only locate those containers which support garbage collection; extension types which do refer to other objects but do not support garbage collection will not be found.\nWhat make... | [
1,
1,
1,
0,
0
] | [] | [] | [
"cpython",
"garbage_collection",
"python"
] | stackoverflow_0001127836_cpython_garbage_collection_python.txt |
Q:
Python programming help
I have this python file that I'm working on:
class Range:
""" An object that has a non-negative start position and a non-negative length"""
def __init__(self, start, end):
"""
Function: generates a new Range
Returns : a new range
... | Python programming help | I have this python file that I'm working on:
class Range:
""" An object that has a non-negative start position and a non-negative length"""
def __init__(self, start, end):
"""
Function: generates a new Range
Returns : a new range
Args : start - ... | [
"There are several things wrong:\nFirstly:\nIn your test function, testGeneModelConstructorDefaults, you have the comment: \"Default values for display_id, transl_start, transl_stop should be None\".\nThe problem you are seeing is that you have only set up the defaults on 1 of the 3 arguments; whereas this test fun... | [
2,
1,
1
] | [] | [] | [
"python"
] | stackoverflow_0004093530_python.txt |
Q:
finding all float literals in Python code
I am trying to find all occurrences of a literal float value in Python code. Can I do that in Komodo (or in any other way)?
In other words, I want to find every line where something like 0.0 or 1.5 or 1e5 is used, assuming it is interpreted by Python as a float literal (so... | finding all float literals in Python code | I am trying to find all occurrences of a literal float value in Python code. Can I do that in Komodo (or in any other way)?
In other words, I want to find every line where something like 0.0 or 1.5 or 1e5 is used, assuming it is interpreted by Python as a float literal (so no comments, for example).
I'm using Komodo 6.... | [
"You could do that by selecting what you need with regular expressions.\nThis command (run it on a terminal) should do the trick:\nsed -r \"s/^([^#]*)#.*$/\\1/g\" YOUR_FILE | grep -P \"[^'\\\"\\w]-?[1-9]\\d*[.e]\\d*[^'\\\"\\w]\"\n\nYou'll probably need to tweak it to get a better result.\n`sed' cuts out comments, w... | [
1,
1
] | [] | [] | [
"ide",
"komodo",
"python"
] | stackoverflow_0004092595_ide_komodo_python.txt |
Q:
How can I save / copy classes & functions I've written in the python interpreter?
How can you save functions/ classes you've writing in a python interactive session to a file? Specifically, is there a way in pydev / eclipse's interactive session (on a mac) to do this?
I just started learning python - and am enjoy... | How can I save / copy classes & functions I've written in the python interpreter? | How can you save functions/ classes you've writing in a python interactive session to a file? Specifically, is there a way in pydev / eclipse's interactive session (on a mac) to do this?
I just started learning python - and am enjoying using the interpreter's interactive session for testing and playing with modules I'... | [
"The best environment for interactive coding sessions has to be IPython, in my opinion. It's built on and extends the basic Python interpreter with a lot of magic, including history. For example, you can issue the command %logstart to dump all subsequent input to a file, which still needs to be edited afterward b... | [
5,
2,
2,
0
] | [] | [] | [
"python"
] | stackoverflow_0004093088_python.txt |
Q:
Python error calculating
I am having a problem with my code here. The error that I am receiving is on the bottom.
I have to enter payroll in and calculate pay with overtime or without.
enter code here
####################### Functions ########################
def Input():
try:
name=raw_input("Ente... | Python error calculating | I am having a problem with my code here. The error that I am receiving is on the bottom.
I have to enter payroll in and calculate pay with overtime or without.
enter code here
####################### Functions ########################
def Input():
try:
name=raw_input("Enter your first and last name: ")... | [
"In Input, Hours and Pay, you assign to a variable of the same name as the functions; perhaps you mean to return these values instead?\n",
"gPay=calcHours(Hours, Pay)\n\nYou meant WorkHours, which is what you called the variable; Hours is still the function, that returned it. There are plenty of other places in t... | [
0,
0
] | [] | [] | [
"python"
] | stackoverflow_0004093803_python.txt |
Q:
Learning Glade along with PyGTK
I've got my self sort of familiar with pygtk. I find it to be a lot of work to build GUI from code. So I turned to Glade. I'm trying to follow tutorials for Glade and PyGTK, and how they work together, however, I can't seems to find any tutorial for the GTKBuilder format.
I found a... | Learning Glade along with PyGTK | I've got my self sort of familiar with pygtk. I find it to be a lot of work to build GUI from code. So I turned to Glade. I'm trying to follow tutorials for Glade and PyGTK, and how they work together, however, I can't seems to find any tutorial for the GTKBuilder format.
I found a couple tutorials, like http://www.wm... | [
"libglade has been replaced by GTK Builder which is basically a slight modification of libglade's API that's part of GTK+ proper.\nHere are some links which should help you with that:\n\nGTK+ and Glade3 GUI Programming Tutorial - Part 1\nLibglade to GtkBuilder F.A.Q.\nlearnpygtk.org - libglade vs gtkbuilder\nPyGTK ... | [
6
] | [] | [] | [
"glade",
"gtk",
"pygtk",
"python"
] | stackoverflow_0004093507_glade_gtk_pygtk_python.txt |
Q:
Python BeautifulSoup XML Parsing
I've written a simple script to parse XML chat logs using the BeautifulSoup module. The standard soup.prettify() works ok except chat logs have a lot of fluff in them. You can see both the script code and some of the XML input file I'm working with below:
Code
import sys
from Beaut... | Python BeautifulSoup XML Parsing | I've written a simple script to parse XML chat logs using the BeautifulSoup module. The standard soup.prettify() works ok except chat logs have a lot of fluff in them. You can see both the script code and some of the XML input file I'm working with below:
Code
import sys
from BeautifulSoup import BeautifulSoup as Soup
... | [
"BeautifulSoup makes getting at attributes and values in xml really simple. I tweaked your example function to use these features. \nimport sys\nfrom BeautifulSoup import BeautifulSoup as Soup\n\ndef parseLog(file):\n file = sys.argv[1]\n handler = open(file).read()\n soup = Soup(handler)\n for message ... | [
37,
8
] | [] | [] | [
"beautifulsoup",
"parsing",
"python",
"xml"
] | stackoverflow_0004071696_beautifulsoup_parsing_python_xml.txt |
Q:
how to extract values of different field from the string in python
I am newbie in python, i have to extract values from a string:
str='x:10 y:12 time : 01/01/2010 11:55:55'
now i have to create a dictionary in which value is stored in such a way that:
x=10
y=12
time=01/01/2010 11:55:55
Please let me know how to do... | how to extract values of different field from the string in python | I am newbie in python, i have to extract values from a string:
str='x:10 y:12 time : 01/01/2010 11:55:55'
now i have to create a dictionary in which value is stored in such a way that:
x=10
y=12
time=01/01/2010 11:55:55
Please let me know how to do this?
| [
"Have you tried anything yet?\nIf not, here are some ideas... \nUsing the built-in string manipulation tools\nFor x and y: \n>>> s = 'x:10 y:12 time : 01/01/2010 11:55:55'\n>>> [pair.split(':') for pair in s.split(' ',2)[0:2]]\n[['x', '10'], ['y', '12']]\n\nand let's say that you then assigned that to a variable:... | [
1
] | [] | [] | [
"python"
] | stackoverflow_0004093935_python.txt |
Q:
Python3:Save File to Specified Location
I have a rather simple program that writes HTML code ready for use.
It works fine, except that if one were to run the program from the Python command line, as is the default, the HTML file that is created is created where python.exe is, not where the program I wrote is. And... | Python3:Save File to Specified Location | I have a rather simple program that writes HTML code ready for use.
It works fine, except that if one were to run the program from the Python command line, as is the default, the HTML file that is created is created where python.exe is, not where the program I wrote is. And that's a problem.
Do you know a way of ge... | [
"The first problem is probably that you are not including the full path when you open the file for writing. For details on opening a web browser, read this fine manual.\nimport os\ntarget_dir = r\"C:\\full\\path\\to\\where\\you\\want\\it\"\n\nfullname = os.path.join(target_dir,filename)\nwith open(fullname,\"w\") ... | [
1,
0
] | [] | [] | [
"python"
] | stackoverflow_0004093387_python.txt |
Q:
How can this very long if-statement be simplified?
How can this if-statement be simplified? It makes a plus sign:
http://i.stack.imgur.com/PtHO1.png
If the statement is completed, then a block is set at the x and y coordinates.
for y in range(MAP_HEIGHT):
for x in range(MAP_WIDTH):
if (x%5 == 2 or x%5 ... | How can this very long if-statement be simplified? | How can this if-statement be simplified? It makes a plus sign:
http://i.stack.imgur.com/PtHO1.png
If the statement is completed, then a block is set at the x and y coordinates.
for y in range(MAP_HEIGHT):
for x in range(MAP_WIDTH):
if (x%5 == 2 or x%5 == 3 or x%5 == 4) and \
(y%5 == 2 or y%5 == ... | [
"This is the same:\nif (x % 5 == 3 and y % 5 > 1) or (y % 5 == 3 and x % 5 > 1): \n\n",
"Basically you're tiling a 5x5 binary pattern. Here's a clear expression of that:\npattern = [[0, 0, 0, 0, 0],\n [0, 0, 0, 0, 0],\n [0, 0, 0, 1, 0],\n [0, 0, 1, 1, 1],\n [0, 0, 0, 1, 0]]... | [
15,
12,
7,
2,
1,
0
] | [] | [] | [
"graphics",
"if_statement",
"modulus",
"python",
"simplification"
] | stackoverflow_0004088145_graphics_if_statement_modulus_python_simplification.txt |
Q:
What is the difference between Mac OS X pre-installed Python and the one from Python.org?
I am a new Mac (Snow Leopard) user and I found that Python is pre-installed in Mac OS X. What is the difference between Mac OS X pre-installed Python and the one from Python.org?
If I install the one from Python.org, will it ... | What is the difference between Mac OS X pre-installed Python and the one from Python.org? | I am a new Mac (Snow Leopard) user and I found that Python is pre-installed in Mac OS X. What is the difference between Mac OS X pre-installed Python and the one from Python.org?
If I install the one from Python.org, will it break anything? Will it be redundant?
EDIT
What would be a good reason to prefer the Python.org... | [
"The Apple-supplied Python 2.6 in Mac OS X 10.6 (Snow Leopard) is currently 2.6.1 (and, based on previous OS X releases, it is unlikely Apple will update it to a newer version in a 10.6.x maintenance release). The most recent (and likely final) release of Python 2.6 is 2.6.6. So if you install the most recent pyt... | [
3,
0
] | [] | [] | [
"osx_snow_leopard",
"python"
] | stackoverflow_0004093015_osx_snow_leopard_python.txt |
Q:
dot product in python
Does this Python code actually find the dot product of two vectors?
import operator
vector1 = (2,3,5)
vector2 = (3,4,6)
dotProduct = reduce( operator.add, map( operator.mul, vector1, vector2))
A:
Yes it does. Here is another way
>>> sum(map( operator.mul, vector1, vector2))
48
and another... | dot product in python | Does this Python code actually find the dot product of two vectors?
import operator
vector1 = (2,3,5)
vector2 = (3,4,6)
dotProduct = reduce( operator.add, map( operator.mul, vector1, vector2))
| [
"Yes it does. Here is another way\n>>> sum(map( operator.mul, vector1, vector2))\n48\n\nand another that doesn't use operator at all\n>>> vector1 = (2,3,5)\n>>> vector2 = (3,4,6)\n>>> sum(p*q for p,q in zip(vector1, vector2))\n48\n\n",
"You can also use the numpy implementation of dot product which has large arra... | [
48,
7
] | [] | [] | [
"dot_product",
"python"
] | stackoverflow_0004093989_dot_product_python.txt |
Q:
Pyjamas framework significance
I am learning Pyjamas framework of python to generate the frontend which is basically a javascript code generated by Pyjamas. Though, being a new concept and a GWT equivalent in python I am interested in learning it, but I can not really find out what is the actual significance of it... | Pyjamas framework significance | I am learning Pyjamas framework of python to generate the frontend which is basically a javascript code generated by Pyjamas. Though, being a new concept and a GWT equivalent in python I am interested in learning it, but I can not really find out what is the actual significance of it? I mean we are coding in python, co... | [
"GWT and Pyjamas were created to remove the drugery of coding Javascript and compensating for all of the different browser implementations and object models.\n\nYes, you still need a designer. \nYes, you can code in python and not\nhave to learn Javascript (in theory).\nNo, you won't have to recode to work \naroun... | [
3
] | [] | [] | [
"pyjamas",
"python"
] | stackoverflow_0004093982_pyjamas_python.txt |
Q:
why my os.listdir return the same folder?
sory, if my english bad...
i'm trying to get a list of my dir this way:
import os, os.path
_path = "/opt/local"#this because i use mac
_dir_path = os.listdir(_path)
_tmp_attr = {"name":"","type":""}
_tmp_data =[]
for _dir_name in _dir_path:
_tmp_attr["name"] = _dir_... | why my os.listdir return the same folder? | sory, if my english bad...
i'm trying to get a list of my dir this way:
import os, os.path
_path = "/opt/local"#this because i use mac
_dir_path = os.listdir(_path)
_tmp_attr = {"name":"","type":""}
_tmp_data =[]
for _dir_name in _dir_path:
_tmp_attr["name"] = _dir_name
if os.path.isdir(_path+'/'+_dir_name):
... | [
"You're re-using the same \"_tmp_attr\" dictionary in every loop iteration, so you're just re-adding the same instance to the _tmp_data collection and overwriting its contents in every iteration.\nYou need to initialize a new dictionary in every iteration:\n_tmp_attr = { }\n\n",
"What you have here is an object r... | [
1,
1,
1
] | [] | [] | [
"python"
] | stackoverflow_0004094190_python.txt |
Q:
Downloading Pyscripter problem?
I keep trying to download Pyscripter on my 32bit Netbook, and I keep getting a range of errors such as "The installation package could not be opened". Any clue on how to make pyscripter work?
A:
Make sure your download is not corrupt:
>>> import hashlib
>>> f = open("PyScripter-v2... | Downloading Pyscripter problem? | I keep trying to download Pyscripter on my 32bit Netbook, and I keep getting a range of errors such as "The installation package could not be opened". Any clue on how to make pyscripter work?
| [
"Make sure your download is not corrupt:\n>>> import hashlib\n>>> f = open(\"PyScripter-v2.3.3-Setup.exe\",\"rb\")\n>>> s = hashlib.sha1(f.read())\n>>> f.close()\n>>> s.hexdigest()\n'dda9da0bb466c28db804c7989d14329c25cdcec8'\n>>>\n\n"
] | [
0
] | [] | [] | [
"download",
"pyscripter",
"python"
] | stackoverflow_0004094215_download_pyscripter_python.txt |
Q:
Why does Google Search return HTTP Error 403?
Consider the following Python code:
30 url = "http://www.google.com/search?hl=en&safe=off&q=Monkey"
31 url_object = urllib.request.urlopen(url);
32 print(url_object.read());
When this is run, an Exception is thrown:
File "/usr/local/lib/python3.0/urllib/r... | Why does Google Search return HTTP Error 403? | Consider the following Python code:
30 url = "http://www.google.com/search?hl=en&safe=off&q=Monkey"
31 url_object = urllib.request.urlopen(url);
32 print(url_object.read());
When this is run, an Exception is thrown:
File "/usr/local/lib/python3.0/urllib/request.py", line 485, in http_error_default
rais... | [
"this should do the trick\nuser_agent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7'\n\nurl = \"http://www.google.com/search?hl=en&safe=off&q=Monkey\"\nheaders={'User-Agent':user_agent,} \n\nrequest=urllib2.Request(url,None,headers) //The assembled request\nresponse =... | [
27,
26,
2,
0
] | [] | [] | [
"google_search",
"python"
] | stackoverflow_0000600536_google_search_python.txt |
Q:
how to send a ajax not using open the webpage on google app engine
you know send a ajax you can use javascript lib like: jquery $.ajax or $.post ..
but this need to open the webpage
but how to send a ajax and get the ajax return value not using open the webpage on google app engine
thanks( i use python)
updated
... | how to send a ajax not using open the webpage on google app engine | you know send a ajax you can use javascript lib like: jquery $.ajax or $.post ..
but this need to open the webpage
but how to send a ajax and get the ajax return value not using open the webpage on google app engine
thanks( i use python)
updated
class CounterHandler(BaseRequestHandler):
def get(self):
self... | [
"You can use app engine's urlfetch library to fetch a url from another server (ie the blog you want to fetch a value from).\n"
] | [
1
] | [] | [] | [
"ajax",
"google_app_engine",
"javascript",
"jquery",
"python"
] | stackoverflow_0004094114_ajax_google_app_engine_javascript_jquery_python.txt |
Q:
python re - split a string before a character
how to split a string at positions before a character?
split a string before 'a'
input: "fffagggahhh"
output: ["fff", "aggg", "ahhh"]
the obvious way doesn't work:
>>> h=re.compile("(?=a)")
>>> h.split("fffagggahhh")
['fffagggahhh']
>>>
A:
Ok, not exactly the s... | python re - split a string before a character | how to split a string at positions before a character?
split a string before 'a'
input: "fffagggahhh"
output: ["fff", "aggg", "ahhh"]
the obvious way doesn't work:
>>> h=re.compile("(?=a)")
>>> h.split("fffagggahhh")
['fffagggahhh']
>>>
| [
"Ok, not exactly the solution you want but I thought it will be a useful addition to problem here.\n\nSolution without re\n\nWithout re:\n>>> x = \"fffagggahhh\"\n>>> k = x.split('a')\n>>> j = [k[0]] + ['a'+l for l in k[1:]]\n>>> j\n['fff', 'aggg', 'ahhh']\n>>> \n\n",
">>> rx = re.compile(\"(?:a|^)[^a]*\")\n>>> r... | [
21,
5,
4,
3,
1
] | [
">>> foo = \"abbcaaaabbbbcaaab\"\n>>> bar = foo.split(\"c\")\n>>> baz = [bar[0]] + [\"c\"+x for x in bar[1:]]\n>>> baz\n['abb', 'caaaabbbb', 'caaab']\n\nDue to how slicing works, this will work properly even if there are no occurrences of c in foo.\n",
"split() takes an argument for the character to split on:\n>>... | [
-1,
-3
] | [
"python",
"regex",
"split"
] | stackoverflow_0004094382_python_regex_split.txt |
Q:
Python error: builtin function or method object has no attribute 'StringIO'
I just want to download an image. Then upload it to Amazon S3. But it's not working.
'builtin_function_or_method' object has no attribute 'StringIO'
Traceback (most recent call last):
File "flickrDump.py", line 16, in <module>
imgpat... | Python error: builtin function or method object has no attribute 'StringIO' | I just want to download an image. Then upload it to Amazon S3. But it's not working.
'builtin_function_or_method' object has no attribute 'StringIO'
Traceback (most recent call last):
File "flickrDump.py", line 16, in <module>
imgpath = s3.upload_thumbnail(thumbnail_name=tools.randomString(10), thumbnail_data=tda... | [
"In your code:\nreturn self.bucket.connection.make_request('PUT', self.bucket.name,......\nAttributeError: 'str' object has no attribute 'connection'\n\nThis means that some how self.bucket is evaluated to a string and you can not obviously call method \"connection\" on it. \nSo for further analysis, look at the fu... | [
3
] | [] | [] | [
"amazon_s3",
"debugging",
"http",
"image",
"python"
] | stackoverflow_0004094537_amazon_s3_debugging_http_image_python.txt |
Q:
Steps to install py2cairo?
Seems that pycairo was branched to py2cairo for 2.x versions back in May. There are no pip or easy_install installation options for py2cairo. I've grabbed the latest py2cairo tar, as well as the cairo 1.8.10 package which is registered as a dependency. When I try to configure cairo first... | Steps to install py2cairo? | Seems that pycairo was branched to py2cairo for 2.x versions back in May. There are no pip or easy_install installation options for py2cairo. I've grabbed the latest py2cairo tar, as well as the cairo 1.8.10 package which is registered as a dependency. When I try to configure cairo first, it errors out at the end that ... | [
"pkg-config is a helper tool used when compiling applications and libraries.\nIf you are using macports then the package name is pkgconfig.\nport install pkgconfig\n\nSee the portfile at : http://trac.macports.org/browser/trunk/dports/devel/pkgconfig/Portfile\nThe details are at : http://pkg-config.freedesktop.org/... | [
1
] | [] | [] | [
"cairo",
"easy_install",
"pip",
"pycairo",
"python"
] | stackoverflow_0004094777_cairo_easy_install_pip_pycairo_python.txt |
Q:
Is there a standard function to iterate over base classes?
I would like to be able to iterate over all the base classes, both direct and indirect, of a given class, including the class itself. This is useful in the case where you have a metaclass that examines an internal Options class of all its bases.
To do thi... | Is there a standard function to iterate over base classes? | I would like to be able to iterate over all the base classes, both direct and indirect, of a given class, including the class itself. This is useful in the case where you have a metaclass that examines an internal Options class of all its bases.
To do this, I wrote the following:
def bases(cls):
yield cls
for ... | [
"There is a method that can return them all, in Method Resolution Order (MRO): inspect.getmro. See here:\nhttp://docs.python.org/library/inspect.html#inspect.getmro\nIt returns them as a tuple, which you can then iterate over in a single loop yourself:\nimport inspect\nfor base_class in inspect.getmro(cls):\n # ... | [
16,
2,
0
] | [] | [] | [
"python"
] | stackoverflow_0004094624_python.txt |
Q:
has any easy way to get full url using python on gae
this is my code:
url = "/aa"
result = urlfetch.fetch(url)
but it will be error , because you have to get the full url , like this :http://digu.com
so any easy way to get the full url in my code ,
thanks
A:
Do you mean the full URL of your own app?
You might w... | has any easy way to get full url using python on gae | this is my code:
url = "/aa"
result = urlfetch.fetch(url)
but it will be error , because you have to get the full url , like this :http://digu.com
so any easy way to get the full url in my code ,
thanks
| [
"Do you mean the full URL of your own app?\nYou might want self.request.host (which would be eg digu.com) or self.request.host_url (which would be eg http://digu.com).\nSee the documentation for the app engine Request class, and also the WebOb Request class it is based on.\nHowever, why would you make a urlfetch to... | [
5
] | [] | [] | [
"google_app_engine",
"python",
"url"
] | stackoverflow_0004094715_google_app_engine_python_url.txt |
Q:
Extract fields from the string in python
I have text line by line which contains many field name and their value seperated by : , if any line does not have any field value then that field would not exist in that line
for example
First line:
A:30 B: 40 TS:1/1/1990 22:22:22
Second line
A:30 TS:1/1/1990 22:22:22
thir... | Extract fields from the string in python | I have text line by line which contains many field name and their value seperated by : , if any line does not have any field value then that field would not exist in that line
for example
First line:
A:30 B: 40 TS:1/1/1990 22:22:22
Second line
A:30 TS:1/1/1990 22:22:22
third line
A:30 B: 40
But it is confirmed that at... | [
"import re\na = [\"A:30 B: 40 TS:1/1/1990 22:22:22\", \"A:30 TS:1/1/1990 22:22:22\", \"A:30 B: 40\"]\nregex = re.compile(r\"^\\s*(?:(A)\\s*:\\s*(\\d+))?\\s*(?:(B)\\s*:\\s*(\\d+))?\\s*(?:(TS)\\s*:\\s*(.*))?$\")\nfor item in a:\n matches = regex.search(item).groups()\n print {k:v for k,v in zip(matches[::2], ma... | [
2,
1
] | [] | [] | [
"python"
] | stackoverflow_0004094979_python.txt |
Q:
Set field value in Django Form clean() method, if this field not passed in constructor
I need set field value, not passed to Django Form constructor.
I have model and form like this:
class Message(models.Model):
created = models.DateTimeField()
text = models.CharField(max_length=200, blank=True,... | Set field value in Django Form clean() method, if this field not passed in constructor | I need set field value, not passed to Django Form constructor.
I have model and form like this:
class Message(models.Model):
created = models.DateTimeField()
text = models.CharField(max_length=200, blank=True, null=True)
active = models.BooleanField(default=False)
class MessageForm(forms.Mo... | [
"The previous answer would work, but I like encapsulating all the form's internal operations like what to show and what not, within the form. I know you mentioned you don't want to send a field value to the constructor, but if you don't mind sending the user, your solution would work.\ni.e., your constructor:\ndef ... | [
5,
3,
1
] | [] | [] | [
"django",
"django_forms",
"django_models",
"python"
] | stackoverflow_0004088309_django_django_forms_django_models_python.txt |
Q:
where is my code error using urlfetch on google app engine
this is my code:
class save(BaseRequestHandler):
def get(self):
counter = Counter.get_by_key_name('aa-s')
counter.count += 1
url = "http://www.google.com"
result = urlfetch.fetch(url)
if result.status_code == 2... | where is my code error using urlfetch on google app engine | this is my code:
class save(BaseRequestHandler):
def get(self):
counter = Counter.get_by_key_name('aa-s')
counter.count += 1
url = "http://www.google.com"
result = urlfetch.fetch(url)
if result.status_code == 200:
counter.ajax = result.content
counter... | [
"You're attempting to store the result into counter.ajax, which is a StringProperty that does not have multiline=True. Either set multiline=True in the definition of 'ajax', or replace it with a TextProperty(). The latter is almost certainly the correct answer - TextProperties can be longer, and aren't indexed.\n",... | [
5,
3
] | [] | [] | [
"google_app_engine",
"python",
"urlfetch"
] | stackoverflow_0004094896_google_app_engine_python_urlfetch.txt |
Q:
How do I see what the "type" of an object is, in Python?
I don't know what type it is. How do I check and print it out to console?
A:
a type is basically a value kind and operations that are valid on that value
type(object) #gives you the type
if you want to test for a type
import types
class foo(object):
... | How do I see what the "type" of an object is, in Python? | I don't know what type it is. How do I check and print it out to console?
| [
"a type is basically a value kind and operations that are valid on that value\n\ntype(object) #gives you the type\n\nif you want to test for a type\n\n\nimport types\nclass foo(object):\n pass\n\n>>> foo is types.ClassType # test if foo is a class\nTrue\n\n",
"Call the type() function. See the types module for... | [
3,
2,
1,
1,
0
] | [] | [] | [
"python"
] | stackoverflow_0004094626_python.txt |
Q:
Limit urls to a domain - Django
I need to lock down various urls to a certain domain.
Any ideas?
A:
In the view, check the get_host result on the request. If it's a bad host, return either HttpResponseNotFound or HttpResponseForbidden (depending on your specific need).
Edit: perhaps you want to lock down based ... | Limit urls to a domain - Django | I need to lock down various urls to a certain domain.
Any ideas?
| [
"In the view, check the get_host result on the request. If it's a bad host, return either HttpResponseNotFound or HttpResponseForbidden (depending on your specific need). \nEdit: perhaps you want to lock down based on the client domain. Then you should check REMOTE_HOST.\n",
"You could also consider altering URLc... | [
2,
1
] | [] | [] | [
"django",
"django_urls",
"python"
] | stackoverflow_0004083068_django_django_urls_python.txt |
Q:
Python - print until marker (a la PHP)?
In PHP I can do this:
print <<<END
This uses the "here document" syntax to output
multiple lines
END;
Is there a way to do something similar in Python?
I want to dump a big chunk of HTML without worrying about escaping e.g. angle brackets.
A:
Python doesn't have heredocs ... | Python - print until marker (a la PHP)? | In PHP I can do this:
print <<<END
This uses the "here document" syntax to output
multiple lines
END;
Is there a way to do something similar in Python?
I want to dump a big chunk of HTML without worrying about escaping e.g. angle brackets.
| [
"Python doesn't have heredocs with arbitrary start/end markers. You can use triple quotes (either single or double) to achieve something very similar:\nprint '''\nThis uses the \"here document\" syntax to output\nmultiple lines\n'''\n\nAdd an r to make it a raw string so that backslash is also not treated specially... | [
4
] | [] | [] | [
"escaping",
"heredoc",
"python"
] | stackoverflow_0004095533_escaping_heredoc_python.txt |
Q:
Think in python, Chapter 8(lists)
As an exercise, describe the relationship
between string.join(string.split(song)) and song.
(they both refer to a string)
Are they the same for all strings? When would they be different?
I am a little ashamed to ask such a question for a likely simple question but,
I don't get i... | Think in python, Chapter 8(lists) | As an exercise, describe the relationship
between string.join(string.split(song)) and song.
(they both refer to a string)
Are they the same for all strings? When would they be different?
I am a little ashamed to ask such a question for a likely simple question but,
I don't get it, what is/are the exception(s)? when a... | [
"By default the split method groups consecutive delimiters together, so if you have them in your original string they'll be lost:\n>>> import string\n>>> song = \"I am the Walrus\"\n>>> string.join(string.split(song))\n'I am the Walrus'\n\nHowever, if you specify delimiters to split on then consecutiv... | [
3,
1
] | [] | [] | [
"list",
"python"
] | stackoverflow_0004095634_list_python.txt |
Q:
Simple / Smart, Pythonic database solution, can use Python types + syntax? (Key / Value Dict, Array, maybe Ordered Dict)
Looking for solutions that push the envelope and:
Avoid
Manually writing SQL queries(Python can be more OO not passing DSL strings)
Using non-Python datatypes for a supposedly required model de... | Simple / Smart, Pythonic database solution, can use Python types + syntax? (Key / Value Dict, Array, maybe Ordered Dict) | Looking for solutions that push the envelope and:
Avoid
Manually writing SQL queries(Python can be more OO not passing DSL strings)
Using non-Python datatypes for a supposedly required model definition
Using a new class of types rather than perfectly good native Python types
Boast
Using Python objects
Using Object O... | [
"I've was actually working on something like this earlier today. There is no readme or sufficient tests yet, but... http://github.com/mikeboers/LiteMap/blob/master/litemap.py\nThe LiteMap class behaves much like the builtin dict, but it persists into a SQLite database. You did not indicate what particular database ... | [
2,
1,
1,
1,
1
] | [] | [] | [
"database",
"nosql",
"python"
] | stackoverflow_0002970382_database_nosql_python.txt |
Q:
Pylint doesn't handle imports when several projects have same base module name
We've got a series of code projects in different parts of our source tree that all have a base package company_name, and some of them import functionality from eachother. This works just fine when running the code, setuptools and declar... | Pylint doesn't handle imports when several projects have same base module name | We've got a series of code projects in different parts of our source tree that all have a base package company_name, and some of them import functionality from eachother. This works just fine when running the code, setuptools and declare_namespace handle peicing together the modules. However, pylint doesn't seem to be ... | [
"I have similar problem with import directory-based settings from many projects at once.\nMy dirty solution is to make symlinks, each with different name (eg. projectA/settings -> projA_settings, projectB/settings -> projB_settings) and then use that import:\nimport projA_settings\n\nor\nimport projB_settings\n\n"
... | [
0
] | [] | [] | [
"import",
"pylint",
"python"
] | stackoverflow_0004087966_import_pylint_python.txt |
Q:
Combinatorics in Python
I have a sort of a one level tree structure as:
Where p are parent nodes, c are child nodes and b are hypothetical branches.
I want to find all combinations of branches under the constraint that only one parent can branch to only one child node, and two branches can not share parent and/or... | Combinatorics in Python | I have a sort of a one level tree structure as:
Where p are parent nodes, c are child nodes and b are hypothetical branches.
I want to find all combinations of branches under the constraint that only one parent can branch to only one child node, and two branches can not share parent and/or child.
E.g. if combo is the ... | [
"Here's one way to do it. There are lot's of micro-optimizations that could be made but their efficacy would depend on the sizes involved.\nimport collections as co\nimport itertools as it\n\ndef unique(list_):\n return len(set(list_)) == len(list_)\n\ndef get_combos(branches):\n by_parent = co.defaultdict(li... | [
5,
4
] | [] | [] | [
"bipartite",
"combinatorics",
"directed_acyclic_graphs",
"python"
] | stackoverflow_0004095749_bipartite_combinatorics_directed_acyclic_graphs_python.txt |
Q:
How To Build a Template Engine
I'll be building this in Google App Engine and I'll be Building it using Python.
What I'd like to do is have a template that holds each section. With the sections probably being header, sidebar, content and footer.
The way I would build it is so that I can call page.header(arg) and ... | How To Build a Template Engine | I'll be building this in Google App Engine and I'll be Building it using Python.
What I'd like to do is have a template that holds each section. With the sections probably being header, sidebar, content and footer.
The way I would build it is so that I can call page.header(arg) and it will load the header that the arg... | [
"I would check out Webpy sources;\nwebpy templating uses a syntax similar to yours, calling the views with something like:\nname = 'Bob' \nreturn render.index(name)\n\nwhere index is the templating file to render.\nHave a look to templating.py specifically.\n"
] | [
2
] | [] | [] | [
"google_app_engine",
"python",
"template_engine"
] | stackoverflow_0004092920_google_app_engine_python_template_engine.txt |
Q:
python: how to make threads wait for specific response?
could anyone please provide on how to achieve below scenario ?
2 queues - destination queue, response queue
thread picks task up from destination queue
finds out needs more details
submits new task to destination queue
waits for his request to be processed an... | python: how to make threads wait for specific response? | could anyone please provide on how to achieve below scenario ?
2 queues - destination queue, response queue
thread picks task up from destination queue
finds out needs more details
submits new task to destination queue
waits for his request to be processed and result appear in response queue
or
monitors response queue ... | [
"If a threads waits for a specific task completion, i.e it shouldn't pick any completed task except that one it put, you can use locks to wait for the task:\n\n def run(self):\n # get a task, do somethings, put a new task\n newTask.waitFor()\n ...\nclass Task:\n ...\n def waitFor(self):\n self._lock.... | [
1
] | [] | [] | [
"multithreading",
"python",
"queue"
] | stackoverflow_0004095925_multithreading_python_queue.txt |
Q:
adding a doRead() method to an existing socket object
is there any way to add a doRead() method to an existing socket object?
the socket needs a doRead method to be able to be passed to twisted's reactor via the addWriter method.
i've tried using the new module's instance method but it doesn't seem to work...
>>> ... | adding a doRead() method to an existing socket object | is there any way to add a doRead() method to an existing socket object?
the socket needs a doRead method to be able to be passed to twisted's reactor via the addWriter method.
i've tried using the new module's instance method but it doesn't seem to work...
>>> c
<socket._socketobject object at 0x7fcb03cc8b40>
>>> c.doR... | [
"It's not new.instancemethod that's failing here. It's the fact that you have a socket._socketobject, an instance of an extension type, which doesn't have a __dict__ so cannot be given arbitrary new attributes.\nThe typical way in which you make one kind of object look like another kind of object is to use wrappin... | [
2
] | [] | [] | [
"python",
"sockets",
"twisted"
] | stackoverflow_0004095473_python_sockets_twisted.txt |
Q:
django import with csvimport.py fails when trying to create a reference to a foreign key
current django project is a mini shop thing.
im trying to create the concept of having products which could have a foreign key of a Brand and a Category. however the import im using is this one http://djangosnippets.org/snippe... | django import with csvimport.py fails when trying to create a reference to a foreign key | current django project is a mini shop thing.
im trying to create the concept of having products which could have a foreign key of a Brand and a Category. however the import im using is this one http://djangosnippets.org/snippets/788/
and it fails when trying to create the object on the foreign key field. it puts the er... | [
"if in the import file you have the ID of an existing brand you have two choiches:\nbrand = Brand.objects.get(pk= csv_val)\nproduct.brand = brand\n\nor \nProduct.brand_id = csv_val\n\nhope it helps\n"
] | [
0
] | [] | [] | [
"django",
"python"
] | stackoverflow_0004095616_django_python.txt |
Q:
Django is returning RuntimeError instead of 404
In my Django project I am having RUntimeError when I'm supposed to get a 404. The description says:
Exception Value: maximum recursion depth exceeded
The error only occurs when I try to access a non-existent page (the correct result would be a 404 page isn't it?). ... | Django is returning RuntimeError instead of 404 | In my Django project I am having RUntimeError when I'm supposed to get a 404. The description says:
Exception Value: maximum recursion depth exceeded
The error only occurs when I try to access a non-existent page (the correct result would be a 404 page isn't it?). Is this a Django bug or is it my fault? I will provid... | [
"I guess this is your fault :). I also had a RuntimeError yesteday. It was caused by giving the wrong class as argument of the super method when inheriting a ModelAdmin class.\nclass MyAdmin(admin.ModelAdmin):\n def queryset(self, request):\n qs = super(AnotherAdmin, self).queryset(request)\n ...\n... | [
0,
0
] | [] | [] | [
"django",
"http_status_code_404",
"python",
"runtime_error"
] | stackoverflow_0004093541_django_http_status_code_404_python_runtime_error.txt |
Q:
What's the advantage of stack-less Python's microthread than Lua's coroutine in state machine implementation for game?
Any advantage on stack-less python implentation than Lua's coroutine?
What's the difference of them?
A:
stackless python and tasklets (I haven't done any programming with stackless python, but I... | What's the advantage of stack-less Python's microthread than Lua's coroutine in state machine implementation for game? | Any advantage on stack-less python implentation than Lua's coroutine?
What's the difference of them?
| [
"stackless python and tasklets (I haven't done any programming with stackless python, but I have read some of the details about how it is implemented):\nPros:\n\nLightweight most of the time.\nHas scheduler to manage which tasklet get resume next after the current one yields.\nSupport for Preemptive Scheduling. (i... | [
9
] | [] | [] | [
"coroutine",
"lua",
"python",
"python_stackless",
"stackless"
] | stackoverflow_0004064594_coroutine_lua_python_python_stackless_stackless.txt |
Q:
Where's the standard python exception list for programmes to raise?
There is a list standard python exceptions that we should watch out, but I don't think these are the ones we should raise ourselves, cause they are rarely applicable.
I'm curious if there exists a list within standard python library, with exceptio... | Where's the standard python exception list for programmes to raise? | There is a list standard python exceptions that we should watch out, but I don't think these are the ones we should raise ourselves, cause they are rarely applicable.
I'm curious if there exists a list within standard python library, with exceptions similar to .NET's ApplicationException, ArgumentNullException, Argumen... | [
"If the error matches the description of one of the standard python exception classes, then by all means throw it.\nCommon ones to use are TypeError and ValueError, the list you linked to already is the standard list.\nIf you want to have application specific ones, then subclassing Exception or one of it's descenda... | [
15,
14,
5,
2
] | [] | [] | [
"error_handling",
"exception",
"python"
] | stackoverflow_0004096087_error_handling_exception_python.txt |
Q:
Python syntax and other things checking?
I wrote a nice little script to do some lightweight work. I set it to run all night, and when I eagerly checked it this morning, I found that I had left a module name prefix out of one of its variables. Is there any way to check for this kind of chicanery statically? The tr... | Python syntax and other things checking? | I wrote a nice little script to do some lightweight work. I set it to run all night, and when I eagerly checked it this morning, I found that I had left a module name prefix out of one of its variables. Is there any way to check for this kind of chicanery statically? The trouble is that this thing sleeps a lot, so runn... | [
"There are three most popular tools: pylint, pyflakes and pycheker.\nPyflakes will show you unused imports, variables, variable usage before assignment, syntax errors and things like that. Pychecker, AFAIK is similar to pyflakes.\nPylint, on the other hand, is a much more comprehensive tool: apart from the listed a... | [
5,
4
] | [] | [] | [
"python"
] | stackoverflow_0004096751_python.txt |
Q:
operating on lists, find index, python
I should find out an index of an item from a list of words.
The function:
def index(lst_words, word):
should return the index of word in lst_words.
e.g.
>>> index (['how, 'to', 'find'], ['how'])
shoud return 0
why this one doesn't work for me?
def index (lst_words, word):
... | operating on lists, find index, python | I should find out an index of an item from a list of words.
The function:
def index(lst_words, word):
should return the index of word in lst_words.
e.g.
>>> index (['how, 'to', 'find'], ['how'])
shoud return 0
why this one doesn't work for me?
def index (lst_words, word):
find = lst_words.index(word)
return ... | [
"You probably meant \n\n\n\n['how', 'to', 'find'].index('how').\n\n\n\nNOT \n\n\n\n['how', 'to', 'find'].index(['how'])\n\n\n\nThis is not searching for a string, it's searching for a list. It would have matched\n\n\n\n['how', 'to', 'find', ['how']].index(['how'])\n\n\n\n",
">>> def index(lst_words, word):\n ... | [
3,
1
] | [] | [] | [
"find",
"indexing",
"python"
] | stackoverflow_0004096964_find_indexing_python.txt |
Q:
How can I retrieve a single record from the Google App Engine Datastore?
Using Google App Engine and GQL and Python:
in my datastore I have something like the following
class Thing(db.Model):
domain = db.StringProperty(required=True)
name = db.StringProperty()
...more...
and in my handler I have
currentT... | How can I retrieve a single record from the Google App Engine Datastore? | Using Google App Engine and GQL and Python:
in my datastore I have something like the following
class Thing(db.Model):
domain = db.StringProperty(required=True)
name = db.StringProperty()
...more...
and in my handler I have
currentThing = db.GqlQuery("SELECT * FROM Thing WHERE domain=:1 LIMIT 1",
... | [
"Just add a .get() onto the end of either of your queries. From the docs:\n\nExecutes the query, then returns the first result, or None if the query returned no results.\nget() implies a \"limit\" of 1, and overrides the LIMIT clause of the GQL query, if any. At most 1 result is fetched from the datastore.\n\nSee ... | [
7
] | [] | [] | [
"google_app_engine",
"python"
] | stackoverflow_0004096948_google_app_engine_python.txt |
Q:
Python equivalent to Java's Class.getResource
I have some XML files on my PYTHONPATH that I would like to load using their path on the PYTHONPATH, rather than their (relative or absolute) path on the filesystem. I could simply inline them as strings in a Python module (yay multiline string literals), and then load... | Python equivalent to Java's Class.getResource | I have some XML files on my PYTHONPATH that I would like to load using their path on the PYTHONPATH, rather than their (relative or absolute) path on the filesystem. I could simply inline them as strings in a Python module (yay multiline string literals), and then load them using a regular import statement, but I'd lik... | [
"Take a look at pkg_resources, it includes apis for the inclusion to generic resources. It is thought to work with python eggs and so it could be much more of you need.\nJust an example taken from the doc:\nimport pkg_resources\nmy_data = pkg_resources.resource_string(__name__, \"foo.dat\")\n\n",
"I don't know of... | [
8,
7
] | [] | [] | [
"java",
"module",
"python",
"resources",
"xml"
] | stackoverflow_0004096770_java_module_python_resources_xml.txt |
Q:
sending random data with Twisted
I'm trying to create an application that maxes out the user's downstream by continuously sending data. Is there a variable that tells how many bytes are in the out buffer? And I say "out buffer," but is there a better term for the data that is being buffered before its sent to th... | sending random data with Twisted | I'm trying to create an application that maxes out the user's downstream by continuously sending data. Is there a variable that tells how many bytes are in the out buffer? And I say "out buffer," but is there a better term for the data that is being buffered before its sent to the client? Am I going about this the r... | [
"The way Twisted exposes this information is with a pair of APIs commonly referred to as \"producers\" and \"consumers\". You can find a document about them on the Twisted site.\nIn your case, a \"pull producer\" is probably appropriate, since your random data probably isn't coming from an event source, but can be... | [
2
] | [] | [] | [
"python",
"twisted"
] | stackoverflow_0004096836_python_twisted.txt |
Q:
Python networkx DFS or BFS missing?
I am interested in finding a path (not necessarily shortest) in a short amount of time. Dijsktra and AStar in networkx is taking too long.
Why is there no DFS or BFS in networkx?
I plan to write my own DFS and BFS search (I am leaning more towards BFS because my graph is pretty... | Python networkx DFS or BFS missing? | I am interested in finding a path (not necessarily shortest) in a short amount of time. Dijsktra and AStar in networkx is taking too long.
Why is there no DFS or BFS in networkx?
I plan to write my own DFS and BFS search (I am leaning more towards BFS because my graph is pretty deep). Is there anything that I can use ... | [
"The Traversal module has multiple depth-first-search variations. Breadth-first-search is implemented in the connected components functions, also in that module. Either use that, or if you need custom behaviour, re-implement your own using that as the example.\n",
"There is now a depth-first search and breadth-fi... | [
4,
4
] | [] | [] | [
"networkx",
"python"
] | stackoverflow_0002449382_networkx_python.txt |
Q:
How can I take an image and get a 3x2 ratio image cropped from the center?
Is there an easy way to do this?
In Python, I created a script to get a "square box" from an image...based on the center.
However, that killed some of my brain cells. Is there an easy way to do this for a 3x2 (3 width, 2 height), based on ... | How can I take an image and get a 3x2 ratio image cropped from the center? | Is there an easy way to do this?
In Python, I created a script to get a "square box" from an image...based on the center.
However, that killed some of my brain cells. Is there an easy way to do this for a 3x2 (3 width, 2 height), based on the center?
This is my "square box" script, but I don't feel like modifying it f... | [
"Use an aspect ratio which is defined as imagex/imagey, so you use 3/2 for 3:2, 16/9 for 16:9 etc.\ndef letterbox(f,aspect_ratio=1):\n try:\n im = Image.open(StringIO(f))\n imagex = int(im.size[0])\n imagey = int(im.size[1])\n width = min(imagex, imagey*aspect_ratio)\n height =... | [
2,
0
] | [] | [] | [
"algorithm",
"image_processing",
"python",
"python_imaging_library"
] | stackoverflow_0004094744_algorithm_image_processing_python_python_imaging_library.txt |
Q:
How to find links with all uppercase text using Python (without a 3rd party parser)?
I am using BeautifulSoup in a simple function to extract links that have all uppercase text:
def findAllCapsUrls(page_contents):
""" given HTML, returns a list of URLs that have ALL CAPS text
"""
soup = BeautifulSoup.B... | How to find links with all uppercase text using Python (without a 3rd party parser)? | I am using BeautifulSoup in a simple function to extract links that have all uppercase text:
def findAllCapsUrls(page_contents):
""" given HTML, returns a list of URLs that have ALL CAPS text
"""
soup = BeautifulSoup.BeautifulSoup(page_contents)
all_urls = node_with_links.findAll(name='a')
# if the... | [
"If the html pages are malformed, there is not a lot of solutions that can really help you. BeautifulSoup or other parsing library are the way to go to parse html files. \nIf you want to avoir the library path, you could use a regexp to match all your links see regular-expression-to-extract-url-from-an-html-link us... | [
2,
1,
0
] | [] | [] | [
"html",
"parsing",
"python"
] | stackoverflow_0004097095_html_parsing_python.txt |
Q:
How to change edges' weight by designated rule?
I have a weighted graph:
F=nx.path_graph(10)
G=nx.Graph()
for (u, v) in F.edges():
G.add_edge(u,v,weight=1)
Get the nodes list:
[(0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 7), (7, 8), (8, 9)]
I want to change each edge's weight by this rule:
Remove one... | How to change edges' weight by designated rule? | I have a weighted graph:
F=nx.path_graph(10)
G=nx.Graph()
for (u, v) in F.edges():
G.add_edge(u,v,weight=1)
Get the nodes list:
[(0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 7), (7, 8), (8, 9)]
I want to change each edge's weight by this rule:
Remove one node, such as node 5, clearly, edge (4, 5), and (5, ... | [
"You can access the edge weight as G[u][v]['weight'] or by iterating over the edge data. So you can e.g.\nIn [1]: import networkx as nx\n\nIn [2]: G=nx.DiGraph()\n\nIn [3]: G.add_edge(1,2,weight=10)\n\nIn [4]: G.add_edge(2,3,weight=20)\n\nIn [5]: G[2][3]['weight']\nOut[5]: 20\n\nIn [6]: G[2][3]['weight']=200\n\nIn... | [
36
] | [] | [] | [
"algorithm",
"edge_list",
"networkx",
"python"
] | stackoverflow_0003965360_algorithm_edge_list_networkx_python.txt |
Q:
Fibers in Python
I'm looking for a very simple way to implement fibers in Python. I'm sure there's a really simple way to do it using generators, but my mind is crapping out on me. This isn't for a huge application, so I don't need the fanciness (or the overhead) of something like Diesel or Tornado or Twisted, I j... | Fibers in Python | I'm looking for a very simple way to implement fibers in Python. I'm sure there's a really simple way to do it using generators, but my mind is crapping out on me. This isn't for a huge application, so I don't need the fanciness (or the overhead) of something like Diesel or Tornado or Twisted, I just want a neat little... | [
"Google around for Python coroutines. There's a lot of stuff out there with varying levels of complexity.\n",
"I've discovered that Greenlets do pretty much exactly what I've been looking to do. Sweet!\n"
] | [
0,
0
] | [] | [] | [
"fibers",
"generator",
"python"
] | stackoverflow_0004029236_fibers_generator_python.txt |
Q:
Odd error when helping a friend install apsw
First off, I don't know if this goes on stackoverflow or one of the other related sites.
So, I have apsw on my system, and am using python 2.6 32 bit. My friend is using Python 64 bit, and when I tried to install apsw on his system, we got a multitude of errors, dependi... | Odd error when helping a friend install apsw | First off, I don't know if this goes on stackoverflow or one of the other related sites.
So, I have apsw on my system, and am using python 2.6 32 bit. My friend is using Python 64 bit, and when I tried to install apsw on his system, we got a multitude of errors, depending on how we installed it. First off, installing v... | [
"Disclosure: I am the APSW author\nThe APSW web site includes an entire page listing reasons why you'd use APSW over pysqlite. Also note that the pysqlite included in the standard library is even older than current pysqlite code.\nCurrently I only provide compiled Windows APSW extensions for 32 bit Pythons. You c... | [
5,
2
] | [] | [] | [
"installation",
"module",
"python"
] | stackoverflow_0004093447_installation_module_python.txt |
Q:
How do I loop through a large dataset in python without getting a MemoryError?
I have a large series of raster datasets representing monthly rainfall over several decades. I've written a script in Python that loops over each raster and does the following:
Converts the raster to a numpy masked array,
Performs lots... | How do I loop through a large dataset in python without getting a MemoryError? | I have a large series of raster datasets representing monthly rainfall over several decades. I've written a script in Python that loops over each raster and does the following:
Converts the raster to a numpy masked array,
Performs lots of array algebra to calculate a new water level,
Writes the result to an output ras... | [
"You don't need to concern youself with memory management, especially not with the garbage collector that has a very specific task that you most likely don't even use. Python will always collect the memory it can and reuse it.\nThere are just two reasons for your problem: Either the data you try to load is too much... | [
5,
4
] | [] | [] | [
"memory",
"python"
] | stackoverflow_0004098162_memory_python.txt |
Q:
Python SQLite3 Problem with?
Im currently learning SQLite3 with Python. I'm looking at the manual, and it tells me to do something like the following:
data = (tablename, )
c.execute("CREATE TABLE IF NOT EXISTS ?(uid INTEGER PRIMARY KEY, title TEXT NOT NULL, duedate INTEGER NOT NULL, description TEXT, archived INTE... | Python SQLite3 Problem with? | Im currently learning SQLite3 with Python. I'm looking at the manual, and it tells me to do something like the following:
data = (tablename, )
c.execute("CREATE TABLE IF NOT EXISTS ?(uid INTEGER PRIMARY KEY, title TEXT NOT NULL, duedate INTEGER NOT NULL, description TEXT, archived INTEGER)", data)
I'm getting an error... | [
"sadly the DB-API’s parameter substitution ? don't work with table name , columns name .. and it's the same in all DB API in python.\nthe DB-API’s parameter substitution just work for value like in SELECT * FROM table WHERE id = ?, so you will have to do string formating or just put the name table in the string dir... | [
3
] | [] | [] | [
"python",
"sql",
"sqlite"
] | stackoverflow_0004098197_python_sql_sqlite.txt |
Q:
Google App Engine gives spurious content at beginning of page after quiescent period
I'm developing an app in Python for Google App Engine.
When I run the deployed app from appspot, it works fine unless I'm accessing it for the first time in over, say, 5 minutes. The problem is that if I haven't accessed the app ... | Google App Engine gives spurious content at beginning of page after quiescent period | I'm developing an app in Python for Google App Engine.
When I run the deployed app from appspot, it works fine unless I'm accessing it for the first time in over, say, 5 minutes. The problem is that if I haven't accessed the app for a while, the page renders with the message
Status: 200 OK Content-Type: text/html; c... | [
"Somewhere in your top level module code is something that uses Python print statements. Print outputs to standard out, which is what is returned as the response body; if it outputs a pair of newlines, the content before that is treated by the browser as the response header. The 'junk' you're seeing is the real res... | [
6
] | [] | [] | [
"google_app_engine",
"python"
] | stackoverflow_0004098119_google_app_engine_python.txt |
Q:
get list item which have count more than specific number by Python
I have nested list :
ip[0] = ['23:30:42.476071', '55729', '192.168.98.138.49341', '201.20.49.239.80', '562034568', -1]
ip[1] = ['23:30:43.110194', '20442', '201.20.49.239.80', '192.168.98.138.49341', '364925831', '562034569']
ip[2] = ['23... | get list item which have count more than specific number by Python | I have nested list :
ip[0] = ['23:30:42.476071', '55729', '192.168.98.138.49341', '201.20.49.239.80', '562034568', -1]
ip[1] = ['23:30:43.110194', '20442', '201.20.49.239.80', '192.168.98.138.49341', '364925831', '562034569']
ip[2] = ['23:30:43.110290', '55730', '192.168.98.138.49341', '201.20.49.239.80', -1,... | [
"Thanks for clarifying. Use a list comprehension:\n>>> ip = [['23:30:42.476071', '55729', '192.168.98.138.49341', '201.20.49.239.80', '562034568', -1], \n['23:30:43.110194', '20442', '201.20.49.239.80', '192.168.98.138.49341', '364925831', '562034569'],\n['23:30:43.110290', '55730', '192.168.98.138.49341', '201.20.... | [
2,
2,
2,
1
] | [] | [] | [
"list",
"python"
] | stackoverflow_0004098309_list_python.txt |
Q:
MySQL Update reports error, What am I missing?
I noticed a few posts on SO regarding MySQL updates using python and still cannot seem to get this correct.
def updateEmployee(employee):
print employee["firstName"]+" "+employee["lastName"]+" "+employee["nameN"]
cursor = db.cursor()
if(len(employee["name... | MySQL Update reports error, What am I missing? | I noticed a few posts on SO regarding MySQL updates using python and still cannot seem to get this correct.
def updateEmployee(employee):
print employee["firstName"]+" "+employee["lastName"]+" "+employee["nameN"]
cursor = db.cursor()
if(len(employee["nameN"]) > 0):
cursor.execute("""
... | [
"I think you have an extra comma before your WHERE clause.\nAn update should look like this:\nupdate foo\nset a = 1,\nb = 2\nwhere type = 0\n\nI think yours looks like this:\nupdate foo\nset a = 1,\nb = 2,\nwhere type = 0\n\n"
] | [
1
] | [] | [] | [
"mysql",
"python"
] | stackoverflow_0004098463_mysql_python.txt |
Q:
Using gtk dialog chooser widget to list files of a remote destination
Well the question says it all.I am trying to create a file transfer application using python, and pygtk for UI.Most of the code is complete,the only problem being the UI for listing remote host's file list.
I really like the Gtk Dialog Chooser w... | Using gtk dialog chooser widget to list files of a remote destination | Well the question says it all.I am trying to create a file transfer application using python, and pygtk for UI.Most of the code is complete,the only problem being the UI for listing remote host's file list.
I really like the Gtk Dialog Chooser widget,and already use it to list the local machine file list.I really would... | [
"From the paramiko tag, I assume you're using that to work with SSH. The GTK+ file chooser can't be populated manually, so what you're trying to do is not possible.\nHowever, most GTK+ packages come with GIO+GVFS [1]. This is a completely separate framework from Paramiko, but you should be able to use both (or even... | [
2
] | [] | [] | [
"gtk",
"paramiko",
"pygtk",
"python"
] | stackoverflow_0004097319_gtk_paramiko_pygtk_python.txt |
Q:
Strange result in python
Could someone explain me this strange result on python 2.6.6 ?
>>> a = "xx"
>>> b = "xx"
>>> a.__hash__() == b.__hash__()
True
>>> a is b
True # ok.. was just to be sure
>>> a = "x" * 2
>>> b = "x" * 2
>>> a.__hash__() == b.__hash__()
True
>>> a is b
True # yeah.. looks ok so far !
>>> n... | Strange result in python | Could someone explain me this strange result on python 2.6.6 ?
>>> a = "xx"
>>> b = "xx"
>>> a.__hash__() == b.__hash__()
True
>>> a is b
True # ok.. was just to be sure
>>> a = "x" * 2
>>> b = "x" * 2
>>> a.__hash__() == b.__hash__()
True
>>> a is b
True # yeah.. looks ok so far !
>>> n = 2
>>> a = "x" * n
>>> b = "... | [
"The is operator tells you whether two variables point to the same object in memory. It is rarely useful and often confused with the == operator, which tells you whether two objects \"look the same\".\nIt is particularly confusing when used with things like short string literals, because the Python compiler interns... | [
18,
12
] | [] | [] | [
"identity",
"python",
"string"
] | stackoverflow_0004098425_identity_python_string.txt |
Q:
How to get download progress info from I.D.Manager to python?
im working a project lately to get download progress info remotely when im away.
i googled a bit but i couldnt find any useful info. on this issue
im using Internet Download Manager.
please help :/ i appreciate any suggestions
im thinking about making s... | How to get download progress info from I.D.Manager to python? | im working a project lately to get download progress info remotely when im away.
i googled a bit but i couldnt find any useful info. on this issue
im using Internet Download Manager.
please help :/ i appreciate any suggestions
im thinking about making software with python but Also C is Ok. if there is a solution
| [
"I dont know exactly how to do it but you can get IDM download progress( such as Transfer rate, TimeLeft... ) by reading the values of the ListView of Internet Download Manager windows (they call it \"hook\"? )\n",
"i just found idm has log file for every download in its temporary folder im trying to parse inform... | [
1,
0
] | [] | [] | [
"download",
"python",
"status"
] | stackoverflow_0004050653_download_python_status.txt |
Q:
Apache+django pythonpath confusion: ImportError: Could not import settings 'mysite.settings'
I use python 2.4 and django 1.2.2 and apache 2.2.3
Write httpd.conf section like this:
<Location "/mysite/">
PythonPath "['/home/usr/www'] + sys.path"
SetHandler python-program
PythonHandler django.core.handler... | Apache+django pythonpath confusion: ImportError: Could not import settings 'mysite.settings' | I use python 2.4 and django 1.2.2 and apache 2.2.3
Write httpd.conf section like this:
<Location "/mysite/">
PythonPath "['/home/usr/www'] + sys.path"
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE mysite.settings
PythonOption django.root /mysite... | [
"Are you using SELinux? Compare the output of \nls -laZ /var/www\n\nand \nls -laZ /home/usr/www\n\nChances are that your home directory cannot be accessed by the apache process. If this is the problem, it might be solved as simply as\nchcon -R --reference=/var/www /home/usr/www\nchmod og+x /home/usr /home/usr/www\n... | [
1,
0
] | [] | [] | [
"apache",
"django",
"mod_python",
"python"
] | stackoverflow_0004093872_apache_django_mod_python_python.txt |
Q:
Python urllib2.urlopen returning 302 error even though page exists
I am using the Python function urllib2.urlopen to read the http://www.bad.org.uk/ website but I keep getting a 302 error even though when I visit the site it loads ok. Anyone have any idea why?
import socket
headers = { 'User-Agent' : 'Mozilla/4... | Python urllib2.urlopen returning 302 error even though page exists | I am using the Python function urllib2.urlopen to read the http://www.bad.org.uk/ website but I keep getting a 302 error even though when I visit the site it loads ok. Anyone have any idea why?
import socket
headers = { 'User-Agent' : 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)' }
socket.setdefaulttimeout(10)
... | [
"The page at http://www.bad.org.uk/ is broken when cookies are disabled.\nhttp://www.bad.org.uk/ returns:\nHTTP/1.1 302 Found\nLocation: http://www.bad.org.uk/DesktopDefault.aspx\nSet-Cookie: Esperantus_Language_bad=en-GB; path=/\nSet-Cookie: Esperantus_Language_rainbow=en-GB; path=/\nSet-Cookie: PortalAlias=rainbo... | [
20,
3
] | [] | [] | [
"python"
] | stackoverflow_0004098702_python.txt |
Q:
Problem to initialize a object
I got a weird error when I try to create a Screen object. Before It worked without any problem, but I got this error when I added a new attribute to the User class. This attribute is related to Screen in a relation many to many through user_screens. This is the error:
"InvalidReques... | Problem to initialize a object | I got a weird error when I try to create a Screen object. Before It worked without any problem, but I got this error when I added a new attribute to the User class. This attribute is related to Screen in a relation many to many through user_screens. This is the error:
"InvalidRequestError: One or more mappers failed t... | [
"Try to specify the primary join via the primaryjoin keyword argument on one (don't know which one) of your relationships. Sometimes (in complex relationship graphs) SQLAlchemy has a hard time to figure out how it should go about. Worked for me more than once, albeit on 0.5.x.\n"
] | [
0
] | [] | [] | [
"python",
"sqlalchemy"
] | stackoverflow_0004072663_python_sqlalchemy.txt |
Q:
how to search in line/point shapefile using mapnik?
I'm using mapnik in my django app to display esri shapefiles on a map. When a user clicks on an object (polygon, point or line), a popup should appear with info on that particular object.
I'm able to search polygons by using the function query_point:
mapnik_map ... | how to search in line/point shapefile using mapnik? | I'm using mapnik in my django app to display esri shapefiles on a map. When a user clicks on an object (polygon, point or line), a popup should appear with info on that particular object.
I'm able to search polygons by using the function query_point:
mapnik_map = mapnik.Map(400, 400)
mapnik_map.layers.append(layer)
ma... | [
"This is a bug in Mapnik, which we are aware of: http://trac.mapnik.org/ticket/503 and I am planning to work on soon for inclusion in Mapnik2. In the meantime you can try applying the patch listed their against Mapnik 0.7.x. If you have trouble please comment on that ticket.\n"
] | [
0
] | [] | [] | [
"mapnik",
"python",
"shapefile"
] | stackoverflow_0004096026_mapnik_python_shapefile.txt |
Q:
Python error calculating program
Ask the user to enter payroll information for the company. Set up a loop that continues to ask for information until they enter “DONE”. For each employee ask three questions:
name (first & last)
hours worked this week (only allow 1 through 60)
hourly wage (only allow 6.00 through... | Python error calculating program | Ask the user to enter payroll information for the company. Set up a loop that continues to ask for information until they enter “DONE”. For each employee ask three questions:
name (first & last)
hours worked this week (only allow 1 through 60)
hourly wage (only allow 6.00 through 20.00)
VALIDATE the hours worked and ... | [
"There's several problems with this code:\n\nThe indentation is all over the place. For example, the while loop ends at that first if statement\nThe test for the while loop is almost certainly false (since eName isn't initialised), so the loop never enters\nthe code at ePass.upper() == \"DONE\" is trying to set th... | [
2,
1,
1,
1
] | [] | [] | [
"loops",
"python"
] | stackoverflow_0004099160_loops_python.txt |
Q:
Great flask / other python micro framework code I could learn from
I'd like to look at some good web-app code written in python, just so I can learn some of the patterns / see how I can improve my code.
I've already googled around a bit, used google code search and run a search on github too - but haven't come acr... | Great flask / other python micro framework code I could learn from | I'd like to look at some good web-app code written in python, just so I can learn some of the patterns / see how I can improve my code.
I've already googled around a bit, used google code search and run a search on github too - but haven't come across a well built, comprehensive app.
Perhaps a book could work as well. ... | [
"Why not start with the publicly available flask.pocoo.org? \nNote: I'm linking to the Github repository on which he has published the code for his website (which runs on flask) rather than the website itself.\n",
"IMHO your time would be better invested learning something like Django, because much of what you co... | [
3,
0
] | [] | [] | [
"flask",
"python",
"web_applications"
] | stackoverflow_0004083440_flask_python_web_applications.txt |
Q:
Sequence of vowels count
This is not a homework question, it is an exam preparation question.
I should define a function syllables(word) that counts the number of syllables in
A word in the following way:
• a maximal sequence of vowels is a syllable;
• a final e in a word is not a syllable (or the vowel sequence it ... | Sequence of vowels count | This is not a homework question, it is an exam preparation question.
I should define a function syllables(word) that counts the number of syllables in
A word in the following way:
• a maximal sequence of vowels is a syllable;
• a final e in a word is not a syllable (or the vowel sequence it is a part
Of).
I do not have t... | [
"I find regular expressions natural for this question. (I think a non-regex answer would take more coding. I use two string methods, 'lower' and 'endswith' to make the answer more clear.)\nimport re\ndef syllables(word):\n word = word.lower()\n if word.endswith('e'):\n word = word[:-1]\n count = l... | [
3,
2,
1,
1,
1,
0,
0,
0,
0
] | [] | [] | [
"nlp",
"python",
"regex"
] | stackoverflow_0004099042_nlp_python_regex.txt |
Q:
How to find index of an element in Python list?
Possible Duplicate:
How to find positions of the list maximum?
A question from homework:
Define a function censor(words,nasty) that takes a list of words, and
replaces all the words appearing in nasty with the word CENSORED, and
returns the censored list of words.
>... | How to find index of an element in Python list? |
Possible Duplicate:
How to find positions of the list maximum?
A question from homework:
Define a function censor(words,nasty) that takes a list of words, and
replaces all the words appearing in nasty with the word CENSORED, and
returns the censored list of words.
>>> censor([’it’,’is’,’raining’], [’raining’])
[’it’,... | [
"You can find the index of any element of a list by using the .index method.\n>>> l=['a','b','c']\n>>> l.index('b')\n1\n\n",
"Your approach might work, but it’s unnecessarily complicated.\nPython allows a very simple syntax to check whether something is contained in a list:\ncensor = [ 'bugger', 'nickle' ]\nword ... | [
38,
1,
1,
0
] | [] | [] | [
"indexing",
"list",
"python"
] | stackoverflow_0004097338_indexing_list_python.txt |
Q:
using a colon in a string in python
i am using python 2.6.5 to develop an app for google app engine - i am not too familiar with python, but i'm learning.
i am trying to put a url into a string so variable = "string http://domain.name"
then i print the string out. the problem is, if the colon (after http) is in th... | using a colon in a string in python | i am using python 2.6.5 to develop an app for google app engine - i am not too familiar with python, but i'm learning.
i am trying to put a url into a string so variable = "string http://domain.name"
then i print the string out. the problem is, if the colon (after http) is in the string, i don't get any output and i do... | [
"If I'm not terrible mistaken, GAE uses WSGI, you do not simply print things, you are supposed to return a proper HTTP response object (it is not PHP).\nI guess that if you access the page using firefox+firebug and look at the network->header you will see that the browser is taking http: as an HTTP header with valu... | [
7,
0
] | [] | [] | [
"google_app_engine",
"python"
] | stackoverflow_0004092159_google_app_engine_python.txt |
Q:
Will Python be faster if I put commonly called code into separate methods or files?
I thought I once read on SO that Python will compile and run slightly more quickly if commonly called code is placed into methods or separate files. Does putting Python code in methods have an advantage over separate files or vice ... | Will Python be faster if I put commonly called code into separate methods or files? | I thought I once read on SO that Python will compile and run slightly more quickly if commonly called code is placed into methods or separate files. Does putting Python code in methods have an advantage over separate files or vice versa? Could someone explain why this is? I'd assume it has to do with memory allocation ... | [
"It doesn't matter. Don't structure your program around code speed; structure it around coder speed. If you write something in Python and it's too slow, find the bottleneck with cProfile and speed it up. How do you speed it up? You try things and profile them. In general, function call overhead in critical loops is... | [
4,
2,
1
] | [] | [] | [
"performance",
"python",
"runtime"
] | stackoverflow_0004100532_performance_python_runtime.txt |
Q:
General question regarding wether or not use Twisted in TCP proxy project
I need to write simple but effective and scalable TCP proxy, that would accept connections on one IP:PORT and forward the data to, possibly large, number of clients listening on their IP:PORT pairs.
The question is, if there is a reason to u... | General question regarding wether or not use Twisted in TCP proxy project | I need to write simple but effective and scalable TCP proxy, that would accept connections on one IP:PORT and forward the data to, possibly large, number of clients listening on their IP:PORT pairs.
The question is, if there is a reason to use Twisted here? Will there be any gain, I cant see now, but will see upon proj... | [
"Twisted will make your code simpler, as it already does a lot of the work for you. For example, here is an echo server using Twisted:\nfrom twisted.internet.protocol import Protocol\nclass Echo(Protocol):\n def dataReceived(self, data):\n self.transport.write(data)\n\nAnd here's a round-robin TCP load b... | [
4
] | [] | [] | [
"proxy",
"python",
"sockets",
"twisted"
] | stackoverflow_0004096061_proxy_python_sockets_twisted.txt |
Q:
Why can my Django app not write to its log file?
$ sudo /etc/init.d/apache2 restart
* Restarting web server apache2
... waiting . ...done.
username@servername Thu Nov 04 18:54:37 ~/public_html/IDM_app
$ sudo tail -n 60 /var/log/apache2/error.log
[Thu Nov 04 18:54:27 2010] [error] [client 8.17.58.38] mod... | Why can my Django app not write to its log file? | $ sudo /etc/init.d/apache2 restart
* Restarting web server apache2
... waiting . ...done.
username@servername Thu Nov 04 18:54:37 ~/public_html/IDM_app
$ sudo tail -n 60 /var/log/apache2/error.log
[Thu Nov 04 18:54:27 2010] [error] [client 8.17.58.38] mod_wsgi (pid=28760): Exception occurred processing WSGI ... | [
"Apache's probably running as the apache user, meaning that it doesn't have write access to the log file. It starts up fine because it only has to read the wsgi file, which has read permissions for all users. either chmod a+w django.osqa.log or chown <apache-user> django.osqa.log.\nNote: the preferred method woul... | [
17
] | [] | [] | [
"apache2",
"django",
"mod_wsgi",
"python"
] | stackoverflow_0004100584_apache2_django_mod_wsgi_python.txt |
Q:
Workaround OSError with os.listdir
I have a directory with 90K files in it. This is such a preposterously huge number of files that bash functions like ls fail. So of course, does os.listdir() from my python (Mac Python, version 2.5) script; it fails with OSError: [Errno 12] Cannot allocate memory: '.'
People will... | Workaround OSError with os.listdir | I have a directory with 90K files in it. This is such a preposterously huge number of files that bash functions like ls fail. So of course, does os.listdir() from my python (Mac Python, version 2.5) script; it fails with OSError: [Errno 12] Cannot allocate memory: '.'
People will say "Don't put that many files in a sin... | [
"You're hitting a historical artifact in Python: os.listdir should return an iterator, not an array. I think this function predates iterators--it's odd that no os.xlistdir has been added.\nThis has more effects than just memory usage on huge directories. Even on a directory with just a few thousand files, you're ... | [
8,
4,
2,
2
] | [] | [] | [
"macos",
"python"
] | stackoverflow_0004098831_macos_python.txt |
Q:
Can't get Scrapy pipeline to work
I have spider that I have written using the Scrapy framework. I am having some trouble getting any pipelines to work. I have the following code in my pipelines.py:
class FilePipeline(object):
def __init__(self):
self.file = open('items.txt', 'wb')
def process_ite... | Can't get Scrapy pipeline to work | I have spider that I have written using the Scrapy framework. I am having some trouble getting any pipelines to work. I have the following code in my pipelines.py:
class FilePipeline(object):
def __init__(self):
self.file = open('items.txt', 'wb')
def process_item(self, item, spider):
line = i... | [
"Got it! The line needs to go in the settings module for the project. Now it works!\n",
"I'm willing to bet that it's a capitalisation difference in the word pipeline somewhere:\nPipeline vs. PipeLine\nI notice 'event.pipelines.FilePipeline' uses the former, whereas your code uses the latter: which do your filena... | [
8,
0
] | [] | [] | [
"pipeline",
"python",
"scraper",
"scrapy",
"web_crawler"
] | stackoverflow_0004090795_pipeline_python_scraper_scrapy_web_crawler.txt |
Q:
How to write Python bindings for command line applications
I'm interested in writing a python binding or wrapper for an existing command line utility that I use on Linux, so that I can access its features in my python programs. Is there a standard approach to doing this that someone could point me to?
At the mome... | How to write Python bindings for command line applications | I'm interested in writing a python binding or wrapper for an existing command line utility that I use on Linux, so that I can access its features in my python programs. Is there a standard approach to doing this that someone could point me to?
At the moment, I have wrapped the command line executable in a subprocess.P... | [
"If you must use a command line interface, then subprocess.Popen is your best bet. Remember that you can use shell=True to let it pick the path variables, you can use os.path.join to use OS-dependent path separators etc.\nIf, however, your command line utility has shared libraries, look at ctypes, which allows you ... | [
5,
1
] | [] | [] | [
"binding",
"c",
"c++",
"python"
] | stackoverflow_0004101130_binding_c_c++_python.txt |
Q:
Simple server/client string exchange protocol
i am looking for an abstract and clean way to exchange strings between two python programs. The protocol is really simple: client/server sends a string to the server/client and it takes the corresponding action - via a handler, i suppose - and replies OR NOT to the oth... | Simple server/client string exchange protocol | i am looking for an abstract and clean way to exchange strings between two python programs. The protocol is really simple: client/server sends a string to the server/client and it takes the corresponding action - via a handler, i suppose - and replies OR NOT to the other side with another string. Strings can be three t... | [
"Python also provides an asyncchat module that simplifies much of the server/client behavior common to chat-like communications. \n",
"What you want to do seems a lot like RPC, so the things that come to my mind are XMLRPC or JSON RPC, if you dont want to use XML . \nPython has a XMLRPC library that you can use, ... | [
0,
0
] | [] | [] | [
"networking",
"protocols",
"python",
"string"
] | stackoverflow_0004097639_networking_protocols_python_string.txt |
Q:
Executemany confusion
Ok, so I have a function that selects certain rows in a sqlite database based on input from a plugin. I got the plugin to select and fetch rows when just one statement is involved, but since I want to add some flexibility to this, I tried making the function use executemany when encountering ... | Executemany confusion | Ok, so I have a function that selects certain rows in a sqlite database based on input from a plugin. I got the plugin to select and fetch rows when just one statement is involved, but since I want to add some flexibility to this, I tried making the function use executemany when encountering lists or tuples. Yet, despi... | [
"Look at http://www.python.org/dev/peps/pep-0249/\n\nUse of this method for an operation\n which produces one or\n more result sets constitutes undefined behavior, and\n the implementation is permitted\n\nSo, executemany can be used for INSERT's and UPDATE's but not for SELECT\nYou can try following code:\nelif ... | [
5,
3
] | [] | [] | [
"database",
"executemany",
"python",
"sqlite"
] | stackoverflow_0004101076_database_executemany_python_sqlite.txt |
Q:
urllib2 freezes GUI
I'm using PyGTK for a small app I've developing. The usage of URLlib2 through a proxy will freeze my GUI. Is there anyway to prevent that?
My code that actually does the work is seperate from the GUI, so I was thinking may be using subprocess to call the python file. However, how would that wor... | urllib2 freezes GUI | I'm using PyGTK for a small app I've developing. The usage of URLlib2 through a proxy will freeze my GUI. Is there anyway to prevent that?
My code that actually does the work is seperate from the GUI, so I was thinking may be using subprocess to call the python file. However, how would that work if I was to convert the... | [
"Calling urllib2 from the main thread blocks the Gtk event loop and consequently freezes the user interface. This is not specific to urllib2, but happens with any longer running function (e.g. subprocess.call).\nEither use the asynchronous IO facilities from glib or call urllib2 in a separate thread to avoid this ... | [
6,
0
] | [] | [] | [
"pygtk",
"python"
] | stackoverflow_0004100628_pygtk_python.txt |
Q:
can i use panel without a frame in wxpython?
there are some people?
i have some question about wxpython ,
can i use panel without a frame?
A:
The simple answer is "no". The panel is not a TopLevelWindow. Top level windows are Frames and Windows. Panels typically go in Frames, although you can nest panels in pan... | can i use panel without a frame in wxpython? | there are some people?
i have some question about wxpython ,
can i use panel without a frame?
| [
"The simple answer is \"no\". The panel is not a TopLevelWindow. Top level windows are Frames and Windows. Panels typically go in Frames, although you can nest panels in panels or frames. Telling us what to do, as Ryan suggested, would be the best way to get a good answer though.\n",
"In the wxpython scheme of th... | [
5,
4
] | [] | [] | [
"python",
"wxpython",
"wxwidgets"
] | stackoverflow_0004096417_python_wxpython_wxwidgets.txt |
Q:
Is wx.richtext supported in wxpython 2.8?
im using wxpython 2.8 ansi with python 2.6 ,and richtext class seems to not exist as an error message prompts that wx module does not contain richtext attribute, i've searched the web but couldn't find a clear answer,therefore i come to you:)
any thoughts?
thanks in advanc... | Is wx.richtext supported in wxpython 2.8? | im using wxpython 2.8 ansi with python 2.6 ,and richtext class seems to not exist as an error message prompts that wx module does not contain richtext attribute, i've searched the web but couldn't find a clear answer,therefore i come to you:)
any thoughts?
thanks in advance
Nataly
| [
"I just downloaded and installed version 2.8.11-ansi. RichTextControl is the first demo listed, and works fine.\nIt sounds like there is something messed up with your installation.\nUnless you have to support windows 98/ME, I don't know any good reason to prefer the ansi version over unicode.\nCan you provide the e... | [
1,
1
] | [] | [] | [
"python",
"wxpython"
] | stackoverflow_0004092333_python_wxpython.txt |
Q:
"BadValueError: Property xxxx is not multi-line" on db.TextProperty()
I'm using python, django and google app engine and I'm getting the error below. However, bookdescription is a TextProperty not a StringProperty so I don't understand why the multi-line error is happening.
The error is intermittent, sometimes th... | "BadValueError: Property xxxx is not multi-line" on db.TextProperty() | I'm using python, django and google app engine and I'm getting the error below. However, bookdescription is a TextProperty not a StringProperty so I don't understand why the multi-line error is happening.
The error is intermittent, sometimes the page will render fine, sometimes not. I'm new to coding so any and all he... | [
"It seems like the runtime environment is somehow referring to a different definition of the Book model which has bookdescription defined as a StringProperty because the error is being raised from the StringProperty.validate() function.\nDo you have the Book model defined in multiple places by any chance?\n"
] | [
4
] | [] | [] | [
"django",
"google_app_engine",
"python"
] | stackoverflow_0004101538_django_google_app_engine_python.txt |
Q:
Multi-dimensional char array (array of strings) in python ctypes
I'm trying to pass an array of character arrays to a C function using ctypes.
void cfunction(char ** strings)
{
strings[1] = "bad"; //works not what I need.
strings[1][2] = 'd'; //this will segfault.
return;
}
char *input[] = {"foo","bar"};
cfunc... | Multi-dimensional char array (array of strings) in python ctypes | I'm trying to pass an array of character arrays to a C function using ctypes.
void cfunction(char ** strings)
{
strings[1] = "bad"; //works not what I need.
strings[1][2] = 'd'; //this will segfault.
return;
}
char *input[] = {"foo","bar"};
cfunction(input);
Since the array that I throw around is statically define... | [
"Use something like\ninput = ((c_char * 4) * 2)()\ninput[0].value = \"str\"\ninput[0][0] == \"s\"\ninput[0][1] == \"t\" # and so on...\n\nSimple usage:\n>>> a =((c_char * 4) * 2)()\n>>> a\n<__main__.c_char_Array_4_Array_2 object at 0x9348d1c>\n>>> a[0]\n<__main__.c_char_Array_4 object at 0x9348c8c>\n>>> a[0].raw\n'... | [
9
] | [] | [] | [
"ctypes",
"multidimensional_array",
"python"
] | stackoverflow_0004101536_ctypes_multidimensional_array_python.txt |
Q:
Python 3.1 - Error while adding a library in Blender
For this problem (stackoverflow.com/questions/4086435/), I tried to make a Python 3 version of the library python-websocket (github.com/mtah/python-websocket/), here is my code: https://gist.github.com/663175.
Blender comes with his own Python 3.1 package, so I ... | Python 3.1 - Error while adding a library in Blender | For this problem (stackoverflow.com/questions/4086435/), I tried to make a Python 3 version of the library python-websocket (github.com/mtah/python-websocket/), here is my code: https://gist.github.com/663175.
Blender comes with his own Python 3.1 package, so I added my file directly in its «site-packages» folder. I ge... | [
"It looks like you called your script websocket.py, so the import of websocket finds the script itself, instead of the installed module by that name. Rename the script to something else (and if it created a websocket.pyc file, delete that.)\n"
] | [
3
] | [] | [] | [
"blender",
"python",
"websocket"
] | stackoverflow_0004101621_blender_python_websocket.txt |
Q:
why did virtualenv not include all of the system paths?
I created a virtualenv, and while it has many system paths, it doesn't have others. Specifically, pyshared and dist-packages don't seem to be included. As a result, my system-wide MySQLdb and psycopg2 aren't available. Any ideas why?
A:
Seems to be related ... | why did virtualenv not include all of the system paths? | I created a virtualenv, and while it has many system paths, it doesn't have others. Specifically, pyshared and dist-packages don't seem to be included. As a result, my system-wide MySQLdb and psycopg2 aren't available. Any ideas why?
| [
"Seems to be related to Ubuntu's messing with python and virtualenv\n",
"The only possible way that i'm aware of, is if you have created your virtualenv with the argument --no-site-packages:\nfrom Here:\n\nIf you build with virtualenv\n --no-site-packages ENV it will not inherit any packages from\n /usr/lib/pyt... | [
2,
1
] | [] | [] | [
"path",
"python",
"virtualenv"
] | stackoverflow_0004101931_path_python_virtualenv.txt |
Q:
This my script that check a number is prime or not, but when the number is 99 or 77, the scripyt failed to check, why? how to fix it?
num = input("Please enter an integer: ")
def is_Prime():
h = num / 2
for x in range(2, h +1):
if (num%x) == 0:
return False
return True
def main():
... | This my script that check a number is prime or not, but when the number is 99 or 77, the scripyt failed to check, why? how to fix it? | num = input("Please enter an integer: ")
def is_Prime():
h = num / 2
for x in range(2, h +1):
if (num%x) == 0:
return False
return True
def main():
if is_Prime():
print num, "is a prime number"
else:
print num, "is not a prime number"
main()
| [
"You are always returning true or false after checking divisibility with 2:\nfor x in range(2, h + 1):\n if (num%x) == 0:\n return False # <<< here\n else:\n int(h) != h\n return True # <<< and here\n\nAlso I'm not sure what the line int(h) != h is supposed to do. You are evaluating an... | [
1,
0,
0
] | [] | [] | [
"python"
] | stackoverflow_0004101920_python.txt |
Q:
Loop control, what is more efficient
Which one of the two alternatives below is more efficient? Any recommendations to further improve it?
Alternative A:
for i in BAR_Items:
if BAR_Items[i] != A and SHAPE[i+"_SHP"] != A: continue
if i in Selection:
Selection.remove(i)
BAR_Items[i].clearActi... | Loop control, what is more efficient | Which one of the two alternatives below is more efficient? Any recommendations to further improve it?
Alternative A:
for i in BAR_Items:
if BAR_Items[i] != A and SHAPE[i+"_SHP"] != A: continue
if i in Selection:
Selection.remove(i)
BAR_Items[i].clearActions()
BAR_Items[i].add(vizact.spin... | [
"One of the best ways to test efficiency is with the timeit module. I would put each alternative in a function, run timeit on each function, and compare.\n",
"Ok here is a contrived way to look at the performance. Since we are trying to see the difference between using \"continue\" or pull the code inside the \"i... | [
5,
3,
0
] | [] | [] | [
"loops",
"performance",
"python"
] | stackoverflow_0004101596_loops_performance_python.txt |
Q:
python memory leak, leaking frames
I have this code to get the caller of my function's file name, line number, and function. It seems to be leaking frames though and I don't understand why. Is this just throwing me off and my leak must be elsewhere?
rv = "(unknown file)", 0, "(unknown function)"
... | python memory leak, leaking frames | I have this code to get the caller of my function's file name, line number, and function. It seems to be leaking frames though and I don't understand why. Is this just throwing me off and my leak must be elsewhere?
rv = "(unknown file)", 0, "(unknown function)"
for f in inspect.stack()[1:]:
... | [
"EDIT I just realized that's wrong, the f reference and f_back both point the same way. I'll leave it in case it inspires someone else:\nEach frame has an f_back pointer, so when you set f = inspect.stack()[1] then inspect.stack()[0][0].f_locals (which contains f) now has a reference to ...stack()[1] and ...stack(... | [
1,
1
] | [] | [] | [
"memory_leaks",
"python"
] | stackoverflow_0004093139_memory_leaks_python.txt |
Q:
PyGTK: Controlling interface from within joined thread
I have a thread in PyGTK, inside my mainloop. It's a Timer, so it needed to be joined with .join(). The problem is, I now cannot edit my UI from in that thread - change text and so on - because of the .join(). Is there a way I can change things from outside (w... | PyGTK: Controlling interface from within joined thread | I have a thread in PyGTK, inside my mainloop. It's a Timer, so it needed to be joined with .join(). The problem is, I now cannot edit my UI from in that thread - change text and so on - because of the .join(). Is there a way I can change things from outside (well, you know what I mean) the mainloop?
Thanks.
| [
"instead of using a Timer thread, use glib.timeout_add to do your thing.\nIt works together with gtk's mainloop and runs in the same thread, so you don't have to do anything special.\n"
] | [
2
] | [] | [] | [
"gtk",
"join",
"multithreading",
"python"
] | stackoverflow_0004101861_gtk_join_multithreading_python.txt |
Q:
Is this a Python or SQL server bug?
I am running the following: Windows 7, Python 2.5, and SQL server 2005, with SQLNCLI as provider. I have one table, its name is TABLE and its fields are FIELD0, FIELD1, FIELD2.
You can find SQLNCLI.msi here: http://www.microsoft.com/downloads/en/details.aspx?FamilyID=d09c1d60-a1... | Is this a Python or SQL server bug? | I am running the following: Windows 7, Python 2.5, and SQL server 2005, with SQLNCLI as provider. I have one table, its name is TABLE and its fields are FIELD0, FIELD1, FIELD2.
You can find SQLNCLI.msi here: http://www.microsoft.com/downloads/en/details.aspx?FamilyID=d09c1d60-a13c-4479-9b91-9e8b9d835cdc&displaylang=en
... | [
"I fix it:\nset ANSI_NULLS ON\nset QUOTED_IDENTIFIER ON\ngo\n\nalter procedure [dbo].[TEST0]\n @FIELD0 varchar(200) \nas\nbegin\n set nocount on <=============================add this\n declare @exist varchar(MAX)\n\n set @exist = (select top 1 [FIELD0] from [TABLE] where [FIELD0] = @FIELD0)... | [
0
] | [] | [] | [
"python",
"sql_server"
] | stackoverflow_0004102323_python_sql_server.txt |
Q:
Where can you download an installer file for PyQT?
Where can you download an installer file for PyQT? I am unable to figure out how to build it with the source code. Is there a prepackaged version?
A:
Here (http://www.riverbankcomputing.co.uk/software/pyqt/download, found by doing a google search for pyqt instal... | Where can you download an installer file for PyQT? | Where can you download an installer file for PyQT? I am unable to figure out how to build it with the source code. Is there a prepackaged version?
| [
"Here (http://www.riverbankcomputing.co.uk/software/pyqt/download, found by doing a google search for pyqt installer :-) )\n"
] | [
2
] | [] | [] | [
"pyqt",
"python"
] | stackoverflow_0004102509_pyqt_python.txt |
Q:
Find "string" in Text File - Add it to Excel File Using Python
I ran a grep command and found several hundred instances of a string in a large directory of data. This file is 2 MB and has strings that I would like to extract out and put into an Excel file for easy access later. The part that I'm extracting is a ... | Find "string" in Text File - Add it to Excel File Using Python | I ran a grep command and found several hundred instances of a string in a large directory of data. This file is 2 MB and has strings that I would like to extract out and put into an Excel file for easy access later. The part that I'm extracting is a path to a data file I need to work on later.
I have been reading abo... | [
"All this is quite easily done with standard Python, but for \"excel\" (xls,or xlsx) files -- you'd have to install a third party library for that. However, if you need just a 2D table that cna open up on a spreadsheed you can use Comma Separated Values (CSV) files - these are comaptible with Excel and other spread... | [
3,
1
] | [] | [] | [
"excel",
"grep",
"python",
"string"
] | stackoverflow_0004099792_excel_grep_python_string.txt |
Q:
python config parser cache to reduce I/O on an embedded system
In my project we use a config file that's parsed with the configparser module. Is there any way to cache the entire config file, and then use configparser methods to read it from memory? I'm hoping to not have to just store the config variables in a di... | python config parser cache to reduce I/O on an embedded system | In my project we use a config file that's parsed with the configparser module. Is there any way to cache the entire config file, and then use configparser methods to read it from memory? I'm hoping to not have to just store the config variables in a dictionary and look them up that way since using the configparser is r... | [
"Yep. If you use the StringIO module, you can create a file-like object that is in memory. \nThen you can use the method (ConfigParser inherits from RawConfigParser): \n\nRawConfigParser.readfp(fp[, filename])\n Read and parse configuration data from the file or file-like object in fp (only the readline() m... | [
4
] | [] | [] | [
"configparser",
"configuration_files",
"file_io",
"python"
] | stackoverflow_0004102761_configparser_configuration_files_file_io_python.txt |
Q:
Odd python search-path behavior, what's going wrong here?
We have an application based on Excel 2003 and Python 2.4 on Windows XP 32bit. The application consists of a large collection of Python functions which can be called from a number of excel worksheets.
We've notcied an anomolous behavior which is that someti... | Odd python search-path behavior, what's going wrong here? | We have an application based on Excel 2003 and Python 2.4 on Windows XP 32bit. The application consists of a large collection of Python functions which can be called from a number of excel worksheets.
We've notcied an anomolous behavior which is that sometimes in the middle of one of these calls the python interpreter ... | [
"Python programs can import modules at any time, not just during program load. Try searching the modules you are using for import.\nIf this doesn't work, you can write an import hook to catch and report all attempted imports before they occur. For example, if you run this before everything else, you will get a dump... | [
2,
1
] | [] | [] | [
"excel",
"python",
"windows"
] | stackoverflow_0004099817_excel_python_windows.txt |
Q:
python: avoiding bug with variable use before assignment in a loop
for element in container:
# some code here
temp_variable = f1(element)
# more code
# much later in the code
for element in container:
# some code
another_variable = g(temp_variable)
# more code
temp_variable = f2(element)
# more c... | python: avoiding bug with variable use before assignment in a loop | for element in container:
# some code here
temp_variable = f1(element)
# more code
# much later in the code
for element in container:
# some code
another_variable = g(temp_variable)
# more code
temp_variable = f2(element)
# more code
In the second for loop, I accidentally used variable temp_variable ... | [
"If it's 'much later' in the code, then you should probably break the code up into multiple functions. It sounds like the function is too long.\nAnother tip is to use meaningful names. temp_variable, tmp, temp, etc. are not good names. Use a name that describes the value that it points to. This will eliminate a lar... | [
8,
4,
4,
3,
0,
0
] | [] | [] | [
"coding_style",
"namespaces",
"python"
] | stackoverflow_0004103031_coding_style_namespaces_python.txt |
Q:
Using Nose to test txmongo dependent code
I want to use nose to test an application that I am writing using twisted and txmongo. I can't even get simple use cases like the following working:
from nose.twistedtools import reactor, deferred, threaded_reactor
import logging
from twisted.internet import de... | Using Nose to test txmongo dependent code | I want to use nose to test an application that I am writing using twisted and txmongo. I can't even get simple use cases like the following working:
from nose.twistedtools import reactor, deferred, threaded_reactor
import logging
from twisted.internet import defer
import txmongo
log = logging.getLogger(... | [
"MongoConnectionPool will return a deferred, which is fired when the connection is established passing the connection handler as argument to the callback. You should conn = yield MongoConnectionPool().\nlazyMongoConnectionPool will return the connection handler directly, without waiting for the connection to be est... | [
1
] | [] | [] | [
"nose",
"python",
"twisted"
] | stackoverflow_0004100455_nose_python_twisted.txt |
Q:
Integer to Unique String
There's probably someone else who asked a similar question, but I didn't take much time to search for this, so just point me to it if someone's already answered this.
I'm trying to take an integer (or long) and turn it into a string, in a very specific way.
The goal is essentially to split... | Integer to Unique String | There's probably someone else who asked a similar question, but I didn't take much time to search for this, so just point me to it if someone's already answered this.
I'm trying to take an integer (or long) and turn it into a string, in a very specific way.
The goal is essentially to split the integer into 8-bit segmen... | [
"struct can easily do this for integers up to 64 bits in size. Any larger will require you to carve the number up first.\n>>> struct.pack('>Q', 12345678901234567890)\n'\\xabT\\xa9\\x8c\\xeb\\x1f\\n\\xd2'\n\n"
] | [
3
] | [] | [] | [
"ascii",
"python"
] | stackoverflow_0004103631_ascii_python.txt |
Q:
Need a regex :(
I'm using Python and I need to be able to take a string of the form
abc | pqr | [1,2,3,4,5]
and get the actual array of integers [1,2,3,4,5] from it. Any suggestions?
A:
Assuming the abc | pqr | part is literal characters, you want:
import re
import ast
m = re.match(r"abc \| pqr \| (\[[-0-9,]*... | Need a regex :( | I'm using Python and I need to be able to take a string of the form
abc | pqr | [1,2,3,4,5]
and get the actual array of integers [1,2,3,4,5] from it. Any suggestions?
| [
"Assuming the abc | pqr | part is literal characters, you want:\nimport re\nimport ast\n\nm = re.match(r\"abc \\| pqr \\| (\\[[-0-9,]*\\])\", inString)\nif m is not None:\n theList = ast.literal_eval(m.group(1))\n\nUse search instead of match if you want to skip over leading non-matching characters.\n",
"The f... | [
1,
0,
0,
0,
0
] | [] | [] | [
"python",
"regex"
] | stackoverflow_0004103544_python_regex.txt |
Q:
When instancing an imported "class" from a package, how can i avoid using the package.class() declaration?
I'm kinda new to Python, so i'm still lost in the whole namespace thing.
I've created a package, with the init file in it and also a classname.py file, with the class, obviously.
For instance:
from parachute ... | When instancing an imported "class" from a package, how can i avoid using the package.class() declaration? | I'm kinda new to Python, so i'm still lost in the whole namespace thing.
I've created a package, with the init file in it and also a classname.py file, with the class, obviously.
For instance:
from parachute import container, emitter
I tried to instance the class Container directly, but it gave me an error, so i had to... | [
"from module import Class\nclassInst = Class()\n\nThis will work if your class is in module.py\n",
"Don't put the class in it's own file. Put Container and Emitter directly in parachute.py. \nYou can then do\nfrom parachute import Container, Emitter\n\nor \nimport parachute\n\ncontainer = parachute.Container()\n\... | [
2,
2
] | [] | [] | [
"class",
"python"
] | stackoverflow_0004103763_class_python.txt |
Q:
Sending an Email with python using the SMTP Library
import smtplib
def prompt(prompt):
return raw_input(prompt).strip()
fromaddr = prompt("From: ")
toaddrs = prompt("To: ").split()
print "Enter message, end with ^D (Unix) or ^Z (Windows):"
msg = ("From: %s\r\nTo: %s\r\n\r\n"
% (fromaddr, ", ".join(t... | Sending an Email with python using the SMTP Library | import smtplib
def prompt(prompt):
return raw_input(prompt).strip()
fromaddr = prompt("From: ")
toaddrs = prompt("To: ").split()
print "Enter message, end with ^D (Unix) or ^Z (Windows):"
msg = ("From: %s\r\nTo: %s\r\n\r\n"
% (fromaddr, ", ".join(toaddrs)))
while 1:
try:
line = raw_input()
... | [
"Your call to smtplib.SMTP() uses invalid arguments. According to the smtplib docs:\n\nSMTP([host[, port[, local_hostname[,\n timeout]]]])\n\nSo, the SMTP constructor takes the optional arguments for hostname, port etc. But you've passed port and hostname as one argument (server = smtplib.SMTP('smtp.live.com:25'))... | [
2
] | [] | [] | [
"email",
"python",
"smtp"
] | stackoverflow_0004103317_email_python_smtp.txt |
Q:
Help with Tkinter in py2exe
I'm trying to convert a basic tkinter GUI program to an .exe using py2exe. However I've run into an error using the following conversion script.
# C:\Python26\test_hello_con.py py2exe
from distutils.core import setup
import py2exe
setup(windows=[r'C:\Python26\py2exe_test_tk.py'])
C:\... | Help with Tkinter in py2exe | I'm trying to convert a basic tkinter GUI program to an .exe using py2exe. However I've run into an error using the following conversion script.
# C:\Python26\test_hello_con.py py2exe
from distutils.core import setup
import py2exe
setup(windows=[r'C:\Python26\py2exe_test_tk.py'])
C:\Python26\py2exe_test_tk.py is the... | [
"Such errors in Unix world are usually due to incorrect PATH settings or/and incorrectly installed third party modules (the GUI ones you're using). Have you seen this post: py2exe fails to generate an executable ?\n"
] | [
0
] | [] | [] | [
"py2exe",
"python",
"tkinter",
"user_interface"
] | stackoverflow_0004104074_py2exe_python_tkinter_user_interface.txt |
Q:
What is the vim feature: --enable-pythoninterp
I am going to build vim and see that it supports the pythoninterp feature by
--enable-pythoninterp. What is it? Since I am a big Python fan, I'd like to know more about it.
And also, what's the --with-python-config-dir=PATH for?
A:
vim supports scripting in various ... | What is the vim feature: --enable-pythoninterp | I am going to build vim and see that it supports the pythoninterp feature by
--enable-pythoninterp. What is it? Since I am a big Python fan, I'd like to know more about it.
And also, what's the --with-python-config-dir=PATH for?
| [
"vim supports scripting in various languages, Python being one of them. See :h python for more details.\n"
] | [
8
] | [] | [] | [
"python",
"vim"
] | stackoverflow_0004104202_python_vim.txt |
Q:
Thread locals in Python - negatives, with regards to scalability?
I'm wondering if there are some serious implications I might be creating for myself by using thread locals. I noticed that in the case of Flask, they use thread locals, and mention that it can cause issues with servers that aren't built with threads... | Thread locals in Python - negatives, with regards to scalability? | I'm wondering if there are some serious implications I might be creating for myself by using thread locals. I noticed that in the case of Flask, they use thread locals, and mention that it can cause issues with servers that aren't built with threads in mind. Is this an outdated concern? I'm using thread locals with Dja... | [
"Threadlocals aren't the most robust or secure way to do things - check out this note, for instance. [ Though also see Glenn's comment, below ]\nI suppose if you have coded cleanly, with the idea that you're putting stuff into a big global pot of info, accepting unguaranteed data consistency in those threaded local... | [
0
] | [] | [] | [
"django",
"multithreading",
"python",
"thread_local"
] | stackoverflow_0004103741_django_multithreading_python_thread_local.txt |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.