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 convert formatted string to list I have a string "[u'foo']" (Yes, it includes the square brackets and the u''). I have to convert that to a list which looks like [u'foo']. list("[u'foo']") won't work. Any suggestions? A: >>> import ast >>> s = "[u'foo']" >>> ast.literal_eval(s) [u'foo'] documentation A:...
Python convert formatted string to list
I have a string "[u'foo']" (Yes, it includes the square brackets and the u''). I have to convert that to a list which looks like [u'foo']. list("[u'foo']") won't work. Any suggestions?
[ ">>> import ast\n>>> s = \"[u'foo']\"\n>>> ast.literal_eval(s)\n[u'foo']\n\ndocumentation\n", "eval(\"[u'foo']\", {'__builtins__':[]}, {})\n\n" ]
[ 18, 1 ]
[]
[]
[ "list", "python", "string" ]
stackoverflow_0003622643_list_python_string.txt
Q: Python programmer: Learning ruby (for rails) I'm a moderately competent Python programmer, and am considering working on my first web-app; it seems a very large number of FOSS webapp code is written in Ruby (i.e. Rails), and I suspect that might help with my learning curve (i.e. for building a decent, if useless w...
Python programmer: Learning ruby (for rails)
I'm a moderately competent Python programmer, and am considering working on my first web-app; it seems a very large number of FOSS webapp code is written in Ruby (i.e. Rails), and I suspect that might help with my learning curve (i.e. for building a decent, if useless webapp). There is lots of material for learning Rub...
[ "Michael Hartl's Ruby on Rails Tutorial is by far the best introduction to Rails I've been able to find online. It's very easy to understand what's going on if you've already got experience in web application development in general. Versions of the tutorial for Rails 2.3.8 and Rails 3 are available. The introduc...
[ 7, 2 ]
[]
[]
[ "python", "ruby", "ruby_on_rails" ]
stackoverflow_0003622611_python_ruby_ruby_on_rails.txt
Q: Returning a file to a WSGI GET request I'm new to WSGI on python; but have a windows server that's got isapi_wsgi installed on it. I also have a script that handles my GET requests all up and running great. The thing is, someone sends me a request, and I need to return a zip file to the requester. The following co...
Returning a file to a WSGI GET request
I'm new to WSGI on python; but have a windows server that's got isapi_wsgi installed on it. I also have a script that handles my GET requests all up and running great. The thing is, someone sends me a request, and I need to return a zip file to the requester. The following code is in my GET handler and it works, but do...
[ "Taken directly from PEP 333:\nif 'wsgi.file_wrapper' in environ:\n return environ['wsgi.file_wrapper'](filelike, block_size)\nelse:\n return iter(lambda: filelike.read(block_size), '')\n\nAlso you probably want the Content-Disposition header for providing the file name to the client.\n" ]
[ 12 ]
[]
[]
[ "download", "forms", "get", "python", "wsgi" ]
stackoverflow_0003622675_download_forms_get_python_wsgi.txt
Q: A way to "listen" for changes to a file system from Python on Linux? I want to be able to detect whenever new files are created or existing files are modified or deleted within a given directory tree (or set of trees). The brute force way to do this would be to just rescan the tree looking for changes, but I'm loo...
A way to "listen" for changes to a file system from Python on Linux?
I want to be able to detect whenever new files are created or existing files are modified or deleted within a given directory tree (or set of trees). The brute force way to do this would be to just rescan the tree looking for changes, but I'm looking for a more "interrupt driven" solution where the file system tells my...
[ "pyinotify is IMHO the only way to get system changes without scanning the directory.\n", "twisted.internet.inotify! It's much more useful to have an event loop attached than just free-floating inotify. Using twisted also gives you filepath for free, which is a nice library for more easily manipulating file paths...
[ 8, 8 ]
[]
[]
[ "linux", "python" ]
stackoverflow_0003622796_linux_python.txt
Q: Python accelerator I'm planning to use Python to develop a web application. Anybody has any idea about any accelerator for python? (something like eAccelerator or apc for php) if not, is there any way to cache the pre-compiled python bytecode ? Any idea about the performance comparison between python and php (ass...
Python accelerator
I'm planning to use Python to develop a web application. Anybody has any idea about any accelerator for python? (something like eAccelerator or apc for php) if not, is there any way to cache the pre-compiled python bytecode ? Any idea about the performance comparison between python and php (assuming db/network latenci...
[ "There's a trick to this.\nIt's called mod_wsgi.\nThe essence of it works like this.\n\nFor \"static\" content (.css, .js, images, etc.) put them in a directory so they're served by Apache, without your Python program knowing they were sent.\nFor \"dynamic\" content (the main HTML page itself) you use mod_wsgi to f...
[ 8, 5, 3, 2 ]
[]
[]
[ "accelerator", "php", "python" ]
stackoverflow_0003619063_accelerator_php_python.txt
Q: How can I exit a while with a key ? [Python] Possible Duplicate: How can I make a while True break if certain key is pressed? [Python] I have this code: def enterCategory(): time.sleep(0.2) if entercount == 1: mouseMove(*position[5]) while win32gui.GetCursorInfo()[1] != 65567: ...
How can I exit a while with a key ? [Python]
Possible Duplicate: How can I make a while True break if certain key is pressed? [Python] I have this code: def enterCategory(): time.sleep(0.2) if entercount == 1: mouseMove(*position[5]) while win32gui.GetCursorInfo()[1] != 65567: mouseMove(*position[5]) mouseMove(*p...
[ "You could use the handling of F2 to set a global flag (e.g., one named proceed) to False, and where you now have while win32gui..., have, instead\nglobal proceed\nproceed = True\nwhile proceed and win32gui...\n\nNot elegant, but then neither is the cursor-shape analysis to find out if the mouse is on a link;-).\n"...
[ 0 ]
[]
[]
[ "python", "while_loop", "windows" ]
stackoverflow_0003622624_python_while_loop_windows.txt
Q: Django: Exposing model method to admin Example model: class Contestant(models.Model): first_name = models.CharField(max_length=255) last_name = models.CharField(max_length=255) email = models.EmailField() ... def send_registration_email(self): ... I'd like to be able to expose this me...
Django: Exposing model method to admin
Example model: class Contestant(models.Model): first_name = models.CharField(max_length=255) last_name = models.CharField(max_length=255) email = models.EmailField() ... def send_registration_email(self): ... I'd like to be able to expose this method to the admin so that managers can login...
[ "You could register it as an admin action.\nfrom django.contrib import admin\nfrom myapp.models import Contestant\n\ndef send_mail(modeladmin, request, queryset):\n for obj in queryset:\n obj.send_registration_email()\n\nmake_published.short_description = \"Resend activation mails for selected users\"\n\n...
[ 7 ]
[]
[]
[ "django", "django_admin", "django_models", "python" ]
stackoverflow_0003623021_django_django_admin_django_models_python.txt
Q: HTML page to PDF in Python? Is there a library available to convert a HTML page (text, images, layout elements etc. ) to a PDF file. I have an HTML page with figures, text and tables with numbers etc. which I want my clients to be able to download as PDF. How do I do this with Python? A: Not too familiar with p...
HTML page to PDF in Python?
Is there a library available to convert a HTML page (text, images, layout elements etc. ) to a PDF file. I have an HTML page with figures, text and tables with numbers etc. which I want my clients to be able to download as PDF. How do I do this with Python?
[ "Not too familiar with python, and prince is nice if you are willing to shell out the cash. There is this http://github.com/antialize/wkhtmltopdf that uses webkit. It is a simple command line utility that you can call and it will honor html+css. As far as I know, it is the only free tool to do so well. There is...
[ 3, 1, 0 ]
[]
[]
[ "html", "pdf_generation", "python" ]
stackoverflow_0003209202_html_pdf_generation_python.txt
Q: Help, the insertion cursor moves one line lower each time! Every time this code is reopened the insertion cursor moves one line lower, how do I stop this? import Tkinter,pickle class Note(Tkinter.Tk): def __init__(self,parent): Tkinter.Tk.__init__(self,parent) self.parent = parent self...
Help, the insertion cursor moves one line lower each time!
Every time this code is reopened the insertion cursor moves one line lower, how do I stop this? import Tkinter,pickle class Note(Tkinter.Tk): def __init__(self,parent): Tkinter.Tk.__init__(self,parent) self.parent = parent self.Main() self.load_data() self.protocol("WM_DELET...
[ "The text widget is guaranteed to always have a trailing newline at the end of its contents. The proper way to get the data is to use the index \"end-1c\" so that you don't get that extra newline. If you use \"end\", each save and load cycle adds one blank lone.\n" ]
[ 1 ]
[]
[]
[ "pickle", "python", "tkinter" ]
stackoverflow_0003623091_pickle_python_tkinter.txt
Q: CSS Templating system for Django / Python? I'm wondering if there is anything like Django's HTML templating system, for for CSS.. my searches on this aren't turning up anything of use. I am aware of things like SASS and CleverCSS but, as far as I can tell, these still don't solve my issue as I want to dynamically ...
CSS Templating system for Django / Python?
I'm wondering if there is anything like Django's HTML templating system, for for CSS.. my searches on this aren't turning up anything of use. I am aware of things like SASS and CleverCSS but, as far as I can tell, these still don't solve my issue as I want to dynamically generate a CSS file based on certain conditions,...
[ "The Django templating system can be used for any text you like. It's used for HTML most of the time, but it could also be used to create CSS. The CSS reference in your HTML can be to a dynamic URL instead of to a static file, and the view function can create whatever context you like, then a .css template file c...
[ 8 ]
[]
[]
[ "css", "django", "django_templates", "dynamic", "python" ]
stackoverflow_0003623070_css_django_django_templates_dynamic_python.txt
Q: Is there a way to save a captcha image and view it later in python? I am scripting in python for some web automation. I know i can not automate captchas but here is what i want to do: I want to automate everything i can up to the captcha. When i open the page (usuing urllib2) and parse it to find that it contains ...
Is there a way to save a captcha image and view it later in python?
I am scripting in python for some web automation. I know i can not automate captchas but here is what i want to do: I want to automate everything i can up to the captcha. When i open the page (usuing urllib2) and parse it to find that it contains a captcha, i want to open the captcha using Tkinter. Now i know that i wi...
[ "Of course the captcha's served by a page which will serve a new one each time (if it was repeated, then once it was solved for one fake userid, a spammer could automatically make a million!). I think you need some \"screenshot\" functionality to capture the image you want -- there is no cross-platform way to invo...
[ 2 ]
[]
[]
[ "firebug", "python", "tkinter", "urllib2", "web_applications" ]
stackoverflow_0003623077_firebug_python_tkinter_urllib2_web_applications.txt
Q: socket.getaddrinfo raises "Unknown host" mystery I'm having a problem resolving a hostname using python's (2.6.2) socket class. From the shell I'm able to ping the hostname, and also resolve the hostname using the host command: host myhostname.mydomain.com When I attempt to resolve it with python, a socket.herror...
socket.getaddrinfo raises "Unknown host" mystery
I'm having a problem resolving a hostname using python's (2.6.2) socket class. From the shell I'm able to ping the hostname, and also resolve the hostname using the host command: host myhostname.mydomain.com When I attempt to resolve it with python, a socket.herror exception is raised with the message "[Errno 1] Unkno...
[ "You need to use gethostbyname, not gethostbyaddr (which does reverse lookup).\n>>> socket.gethostbyname('car.spillville.com')\n'209.20.76.192'\n>>> socket.gethostbyaddr('209.20.76.192')\n('car.spillville.com', [], ['209.20.76.192'])\n\n" ]
[ 8 ]
[]
[]
[ "dns", "networking", "python" ]
stackoverflow_0003623287_dns_networking_python.txt
Q: newbie python csv writer question: why every character separated? please excuse me for simple question: i tried to write simple csv file using csv module. however, the result is this: Spam |Baked Beans| / s e a r c h | | , | | A d v a n c e d | | S e a r c h / a b o u t / | | , | | A b o u t / n e w s / | | , | | ...
newbie python csv writer question: why every character separated?
please excuse me for simple question: i tried to write simple csv file using csv module. however, the result is this: Spam |Baked Beans| / s e a r c h | | , | | A d v a n c e d | | S e a r c h / a b o u t / | | , | | A b o u t / n e w s / | | , | | N e w s / d o c / | | , | | D o c u m e n t a t i o n / d o w n l o a d...
[ "writerow's argument is a sequence... and a string, which is what you're passing, is a sequence of single characters. To fix your bug, in the 2nd call to writerow, pass, instead, [self.linkvalue, data] as the argument.\n" ]
[ 9 ]
[]
[]
[ "csv", "python" ]
stackoverflow_0003623303_csv_python.txt
Q: Using a Python GEDCOM parser: Receiving bad output (gedcom.Element instance at 0x00...) I'm new to Python, and I can say off the bat my programming experience is nominal compared to many of you. Brace yourselves :) I have 2 files. A GEDCOM parser written in Python that I found from a user on this site (gedcom.py ...
Using a Python GEDCOM parser: Receiving bad output (gedcom.Element instance at 0x00...)
I'm new to Python, and I can say off the bat my programming experience is nominal compared to many of you. Brace yourselves :) I have 2 files. A GEDCOM parser written in Python that I found from a user on this site (gedcom.py - http://ilab.cs.byu.edu/cs460/2006w/assignments/program1.html) and a simple GEDCOM file that...
[ "someclass instance at 0xdeadbeef is the result of the the standard __repr__ method for classes that don't define one, as apparently class gedcom.Element doesn't, so the problem is only with you printing a list of such instances. If such class defines __str__, you could\nfor x in g.element_list():\n print x\n\n...
[ 1, 0 ]
[]
[]
[ "gedcom", "parsing", "python" ]
stackoverflow_0003623349_gedcom_parsing_python.txt
Q: Using Ruby/Python code in an iPhone OS app? My app needs to use a library which is only available for Python and Ruby. From my understanding, Apple allows Ruby to run on iPhone as long as users can't execute arbitrary code (Rhomobile uses Ruby). How can I bundle Ruby/Python with my app, call a function from my Obj...
Using Ruby/Python code in an iPhone OS app?
My app needs to use a library which is only available for Python and Ruby. From my understanding, Apple allows Ruby to run on iPhone as long as users can't execute arbitrary code (Rhomobile uses Ruby). How can I bundle Ruby/Python with my app, call a function from my Obj-C code, and get the result (a string) back in C ...
[ "You can't. The new SDK agreement prohibits using original languages other than C, C++, or Objective-C, and the SDK agreement has always prohibited dynamically interpreting code. There's some ambiguity about how these rules will be enforced, but to be safe, it's best to avoid other languages until the kinks get w...
[ 3, 3 ]
[]
[]
[ "iphone", "python", "ruby" ]
stackoverflow_0002702208_iphone_python_ruby.txt
Q: python Ctype : problem with callback in making python custom library The whole scenario is like this: there is a function setmessagelistener(a_structure,function_pointer) in my c library. i am writing a python library which is a wrapper on above mentioned c library using Ctypes. so what i did is something like th...
python Ctype : problem with callback in making python custom library
The whole scenario is like this: there is a function setmessagelistener(a_structure,function_pointer) in my c library. i am writing a python library which is a wrapper on above mentioned c library using Ctypes. so what i did is something like this: def setlistener(a_structure,function_pointer) listenerDeclaration = ...
[ "As you suspect, you need to keep a reference to listenerFunction as long as it is needed. Perhaps wrap the function in a class, create an instance and set the listenerFunction as a member variable.\nSee the Python documentation for ctypes callbacks, especially the important note at the end of the section.\n" ]
[ 1 ]
[]
[]
[ "callback", "ctypes", "python" ]
stackoverflow_0003530002_callback_ctypes_python.txt
Q: Removing python module installed in develop mode I was trying the python packaging using setuptools and to test I installed the module in develop mode. i.e python setup.py develop This has added my modules directory to sys.path. Now I want to remove the module. Is there any way to do this? A: Use the --uninstal...
Removing python module installed in develop mode
I was trying the python packaging using setuptools and to test I installed the module in develop mode. i.e python setup.py develop This has added my modules directory to sys.path. Now I want to remove the module. Is there any way to do this?
[ "Use the --uninstall or -u option to develop, i.e:\npython setup.py develop --uninstall\n\nThis will remove it from easy-install.pth and delete the .egg-link. The only thing it doesn't do is delete scripts (yet).\n", "Edit easy-install.pth in your site-packages directory and remove the line that points to your d...
[ 231, 18, 1 ]
[]
[]
[ "python", "setuptools" ]
stackoverflow_0003606457_python_setuptools.txt
Q: Do I need *.egg-info directories when using setuptools/distribute to create a python package I have a "standard" python package layout like this: setup.py - using setuptools README src/moduleA test/ However, when I execute setup.py it decides to create the directory src/moduleA.egg-info. The question is, do I n...
Do I need *.egg-info directories when using setuptools/distribute to create a python package
I have a "standard" python package layout like this: setup.py - using setuptools README src/moduleA test/ However, when I execute setup.py it decides to create the directory src/moduleA.egg-info. The question is, do I need to worry about the contents of this directory and check it in with the rest of my code, or sho...
[ "The automatically generated bits don't need to be checked in, unless you're actually extending setuptools itself as part of your build process.\nHowever, if you're putting files of your own in .egg-info (like i18n resources for EggTranslations), then those should definitely be checked in, since setuptools obviousl...
[ 4 ]
[]
[]
[ "packaging", "python", "setuptools" ]
stackoverflow_0003575493_packaging_python_setuptools.txt
Q: Python: Check the value of a variable passed as a parameter in another method? Somewhat related to my earlier question. I'm making a simple html parser to play around with in Python 2.7. I would like to have multiple parse types, IE can parse for links, script tags, images, ect. I'm using the HTMLParser module, so...
Python: Check the value of a variable passed as a parameter in another method?
Somewhat related to my earlier question. I'm making a simple html parser to play around with in Python 2.7. I would like to have multiple parse types, IE can parse for links, script tags, images, ect. I'm using the HTMLParser module, so my initial thoughts were just make a separate class for each thing I want to parse....
[ "class TagParser(HTMLParser):\n\n def __init__(self, url, tag):\n HTMLParser.__init__(self)\n self.tag = tag\n req = urllib2.urlopen(url)\n self.feed(req.read())\n\n def handle_starttag(self, tag, attrs):\n if tag != self.tag: return\n for name, value in attrs:\n ...
[ 1, 0 ]
[]
[]
[ "html_parsing", "python" ]
stackoverflow_0003623949_html_parsing_python.txt
Q: How does python load Boost.Python libraries? Considering the following archetypal Boost.Python module, which brings a class "D" from a separate C++ header file. /* file: a/b.cpp */ BOOST_PYTHON_MODULE(c) { class_<d>("D") } When I compile this to a shared library, I'm confused how I can expose it to Python. W...
How does python load Boost.Python libraries?
Considering the following archetypal Boost.Python module, which brings a class "D" from a separate C++ header file. /* file: a/b.cpp */ BOOST_PYTHON_MODULE(c) { class_<d>("D") } When I compile this to a shared library, I'm confused how I can expose it to Python. What should I call the library? a.so? liba.so? b.so...
[ "We prefer to call the library _c.so, put it in a module, and then add an __init__.py that basically does from _c import *. So you have:\n\npackage\n\n_c.so\n__init__.py\n\n\n" ]
[ 3 ]
[]
[]
[ "boost_python", "python", "shared_libraries" ]
stackoverflow_0003608649_boost_python_python_shared_libraries.txt
Q: svcrack.py and svwar.py i found out that my server is getting slower and slower. on command top i get response that i have a lot svcrack.py and svwar.py processes active. can you tell me what are those? thank you in advance! A: Somebody is running a password cracker on your server. If it's not you, then your ser...
svcrack.py and svwar.py
i found out that my server is getting slower and slower. on command top i get response that i have a lot svcrack.py and svwar.py processes active. can you tell me what are those? thank you in advance!
[ "Somebody is running a password cracker on your server. If it's not you, then your server has been compromised. Tread carefully.\n", "as everyone else said, that's part of SIPVicious, of which I'm the original author. Your server got compromised (somehow) and is being used to scan and compromise PBX servers open ...
[ 3, 2, 0 ]
[]
[]
[ "apache", "python" ]
stackoverflow_0003624521_apache_python.txt
Q: VoteHandler in Google App Engine I am trying to have this function limit a user to only one vote per image. However it currently lets all votes through. If I change "if existing_vote != 0:" to "if existing_vote == 0:" it lets no votes through. Thoughts? class VoteHandler(webapp.RequestHandler): def get(self): ...
VoteHandler in Google App Engine
I am trying to have this function limit a user to only one vote per image. However it currently lets all votes through. If I change "if existing_vote != 0:" to "if existing_vote == 0:" it lets no votes through. Thoughts? class VoteHandler(webapp.RequestHandler): def get(self): #See if logged in self.Session = ...
[ "Looks like your filter on user is wiping out every existing vote, i.e., the equality there is never satisfied. And indeed I'm not sure how I'd satistfy an equality check on a reference propertly. Why not change\nuser = db.ReferenceProperty(User) #See if voted on this site yet\n\nto, e.g.,\nuseraccount = db.Strin...
[ 1, 1 ]
[]
[]
[ "function", "google_app_engine", "python", "vote" ]
stackoverflow_0003622207_function_google_app_engine_python_vote.txt
Q: Is it possible to get a list of all versions of an app? the title speaks for itself. I play with GAE and some of my apps have versions like (1,2,3,4 and dev). So, is there a way to get all of them, so I could use it in my app to generate links to different versions ? A: No, there's no way to get a list of app ve...
Is it possible to get a list of all versions of an app?
the title speaks for itself. I play with GAE and some of my apps have versions like (1,2,3,4 and dev). So, is there a way to get all of them, so I could use it in my app to generate links to different versions ?
[ "No, there's no way to get a list of app versions from inside an app.\n" ]
[ 4 ]
[]
[]
[ "google_app_engine", "python", "version_control" ]
stackoverflow_0003622165_google_app_engine_python_version_control.txt
Q: RPC frameworks available? I am looking to use a RPC framework for internal use. The framework has to be cross language. I am exploring Apache Thrift right now. Google protocol Buffers does not provide RPC capabilities exactly. What are the choices I have got apart from Thrift. (my servers will be primarily Java an...
RPC frameworks available?
I am looking to use a RPC framework for internal use. The framework has to be cross language. I am exploring Apache Thrift right now. Google protocol Buffers does not provide RPC capabilities exactly. What are the choices I have got apart from Thrift. (my servers will be primarily Java and the clients will be Java, Pyt...
[ "There is also MessagePack\nwhich claims to be faster than Protocol Buffers and have more features than Thrift.\n", "I would look at REST as a first option because it is ubiquitous and no-nonsense. \nIf performance and representation really needs to be compact, I have heard good things about Apache AVRO and my fi...
[ 4, 2, 1 ]
[]
[]
[ "java", "php", "python", "rpc", "thrift" ]
stackoverflow_0003624568_java_php_python_rpc_thrift.txt
Q: How to redirect to a url with non-English characters? I'm using pylons, and some of my urls contains non-English characters, such as: http://localhost:5000/article/111/文章标题 At most cases, it won't be a problem, but in my login module, after a user has logging out, I try to get the referer from the request.headers...
How to redirect to a url with non-English characters?
I'm using pylons, and some of my urls contains non-English characters, such as: http://localhost:5000/article/111/文章标题 At most cases, it won't be a problem, but in my login module, after a user has logging out, I try to get the referer from the request.headers, and redirect to that url. if user_logout: referer = r...
[ "Try checking the RFC for non-ascii URLs. They are converted to an ascii equivalent if I remember correctly. You could then redirect to that.\nEdit: According to @ssokolov (see comments below): \n\nThe specific terms to look up are IDN\n (Internationalized Domain Names) and\n Punycode\n\n", "At last, I still no...
[ 1, 1, 0 ]
[]
[]
[ "non_english", "pylons", "python", "url", "webob" ]
stackoverflow_0003624063_non_english_pylons_python_url_webob.txt
Q: Python error "NameError: global name 'self' is not defined" when calling another method in same class I get a weird error: Traceback (most recent call last): File "/remote/us01home15/ldagan/python/add_parallel_definition.py", line 36, in <module> new_netlist.lines=orig_netlist.add_parallel_extention(cell_name,para...
Python error "NameError: global name 'self' is not defined" when calling another method in same class
I get a weird error: Traceback (most recent call last): File "/remote/us01home15/ldagan/python/add_parallel_definition.py", line 36, in <module> new_netlist.lines=orig_netlist.add_parallel_extention(cell_name,parallel,int(level)) File "/remote/us01home15/ldagan/python/hspice_netlist.py", line 70, in add_parallel_extent...
[ "You are missing self in two method declarations.\nThese\ndef gen_parallel_hierarchy(num_of_parallel,level,cell_1st_line):\ndef gen_parallel_inst(num,cell_1st_line):\n\nshould be\ndef gen_parallel_hierarchy(self,num_of_parallel,level,cell_1st_line):\ndef gen_parallel_inst(self,num,cell_1st_line):\n\nThe error happe...
[ 17 ]
[]
[]
[ "class", "python" ]
stackoverflow_0003625726_class_python.txt
Q: Parsing document with python minidom I have the following XML document that I have to parse using python's minidom: <?xml version="1.0" encoding="UTF-8"?> <root> <bash-function activated="True"> <name>lsal</name> <description>List directory content (-al)</description> <code>ls -al</cod...
Parsing document with python minidom
I have the following XML document that I have to parse using python's minidom: <?xml version="1.0" encoding="UTF-8"?> <root> <bash-function activated="True"> <name>lsal</name> <description>List directory content (-al)</description> <code>ls -al</code> </bash-function> <bash-functio...
[ "I imagine you are passing in a file handle, in the following way:\n>>> from xml.dom.minidom import parse\n>>> xmldoc = open(\"xmltestfile.xml\", \"rU\")\n>>> x = FuncDoc(xmldoc)\n\nI'm getting the same error as you do if I try to parse the same document twice without closing it in-between. Try this -- the error ap...
[ 7 ]
[]
[]
[ "dom", "minidom", "parsing", "python" ]
stackoverflow_0003625897_dom_minidom_parsing_python.txt
Q: Is this possible to draw GtkTreeView listed like GtkIconView? I am working on a GTK+ application written in python. I obviously use PyGtk. My application is about collections of videos. It's a kind of F-spot or Picasa, but for video. As you can see in these two apps, you have a central area where you can see all o...
Is this possible to draw GtkTreeView listed like GtkIconView?
I am working on a GTK+ application written in python. I obviously use PyGtk. My application is about collections of videos. It's a kind of F-spot or Picasa, but for video. As you can see in these two apps, you have a central area where you can see all of your photos with tag thumbnails under. In my app, I want to imple...
[ "IconView is what you need. In the ListStore every row represent just one pixbuf but the IconView adjusts the images in a grid. Here a small example, launch it with the image files you want to show as arguments, for example:\npython example.py /usr/share/icons/hicolor/16x16/apps/*\n\n.\nimport sys\nimport gtk\n\n\n...
[ 1, 0 ]
[]
[]
[ "gtk", "gtktreeview", "pygtk", "python" ]
stackoverflow_0003596926_gtk_gtktreeview_pygtk_python.txt
Q: Is it safe to use sys.platform=='win32' check on 64-bit Python? The usual check to differentiate between running Python-application on Windows and on other OSes (Linux typically) is to use conditional: if sys.platform == 'win32': ... But I wonder is it safe to use today when 64-bit Python is more widely used ...
Is it safe to use sys.platform=='win32' check on 64-bit Python?
The usual check to differentiate between running Python-application on Windows and on other OSes (Linux typically) is to use conditional: if sys.platform == 'win32': ... But I wonder is it safe to use today when 64-bit Python is more widely used in last years? Does 32 really means 32-bit, or basically it refers to...
[ "sys.platform will be win32 regardless of the bitness of the underlying Windows system, as you can see in PC/pyconfig.h (from the Python 2.6 source distribution):\n#if defined(MS_WIN64)\n/* maintain \"win32\" sys.platform for backward compatibility of Python code,\n the Win64 API should be close enough to the Win...
[ 46, 6, 5, 2 ]
[]
[]
[ "32bit_64bit", "64_bit", "cross_platform", "python", "windows" ]
stackoverflow_0002144748_32bit_64bit_64_bit_cross_platform_python_windows.txt
Q: how to increase the number of pages comes in google search? I am using google search api But by default it shows 4 and maximum 8 results per page. I want more results per page. A: Add the rsz=8 parameter to this google search demonstration code, then use the start=... parameter to control which group of results ...
how to increase the number of pages comes in google search?
I am using google search api But by default it shows 4 and maximum 8 results per page. I want more results per page.
[ "Add the rsz=8 parameter to this google search demonstration code,\nthen use the start=... parameter to control which group of results you receive.\nThis, for example, gives you 50 results:\nimport urllib\nimport json\nimport sys\nimport itertools\n\ndef hits(astr):\n for start in itertools.count():\n que...
[ 0 ]
[]
[]
[ "google_api", "python" ]
stackoverflow_0003626039_google_api_python.txt
Q: Dealing with metaclass conflict with SQL Alchemy declarative base I have a class X which derives from a class with its own metaclass Meta. I want to also derive X from the declarative base in SQL Alchemy. But I can't do the simple def class MyBase(metaclass = Meta): #... def class X(declarative_base(), MyBase...
Dealing with metaclass conflict with SQL Alchemy declarative base
I have a class X which derives from a class with its own metaclass Meta. I want to also derive X from the declarative base in SQL Alchemy. But I can't do the simple def class MyBase(metaclass = Meta): #... def class X(declarative_base(), MyBase): #... since I would get metaclass conflict error: 'the metaclas...
[ "Edit: Now having looked at IterRegistry and DeclarativeMeta, I think you're code is okay.\nIterRegistry defines __new__ and __iter__, while DeclarativeMeta defines __init__ and __setattr__. Since there is no overlap, there's no direct need to call super. Nevertheless, it would good to do so, to future-proof your c...
[ 3 ]
[]
[]
[ "metaclass", "python", "sqlalchemy" ]
stackoverflow_0003626615_metaclass_python_sqlalchemy.txt
Q: Can one use negative numbers as seeds for random number generation? This is not a coding question, but am hoping that someone has come across this in the forums here. I am using Python to run some simulations. I need to run many replications using different random number seeds. I have two questions: Are negative ...
Can one use negative numbers as seeds for random number generation?
This is not a coding question, but am hoping that someone has come across this in the forums here. I am using Python to run some simulations. I need to run many replications using different random number seeds. I have two questions: Are negative numbers okay as seeds? Should I keep some distance in the seeds? Curren...
[ "Quoting random.seed([x]):\n\nOptional argument x can be any hashable object.\n\nBoth positive and negative numbers are hashable, and many other objects besides.\n>>> hash(42)\n42\n>>> hash(-42)\n-42\n>>> hash(\"hello\")\n-1267296259\n>>> hash((\"hello\", \"world\"))\n759311865\n\n", "Is it important that your si...
[ 8, 5 ]
[]
[]
[ "python", "random", "seed" ]
stackoverflow_0003626846_python_random_seed.txt
Q: Django multiple form factory What is the best way to deal with multiple forms? I want to combine several forms into one. For example, I want to combine ImangeFormSet and EntryForm into one form: class ImageForm(forms.Form): image = forms.ImageField() ImageFormSet = formset_factory(ImageForm) class EntryForm(f...
Django multiple form factory
What is the best way to deal with multiple forms? I want to combine several forms into one. For example, I want to combine ImangeFormSet and EntryForm into one form: class ImageForm(forms.Form): image = forms.ImageField() ImageFormSet = formset_factory(ImageForm) class EntryForm(forms.Form): title = forms.Char...
[ "An idea (not checked if it works):\nclass MySuperForm(CombinedForm):\n includes = (ImageForm, EntryForm, )\n\nYou see here how the form is built. You can make your own Form by extending from BaseForm and supplying another __metaclass__.\nclass CombinedForm(BaseForm):\n __metaclass__ = DeclarativeFieldsMetaclas...
[ 4, 3 ]
[]
[]
[ "django", "django_forms", "python" ]
stackoverflow_0003612726_django_django_forms_python.txt
Q: SQL-like JOIN on two text files in Python, is there a built-in way? A common task I have to perform is an SQL-like JOIN on two text files. i.e. create a new file from the "left hand" and "right hand" files, using some sort of join on an identifier column shared between them. Variations such as outer joins etc are ...
SQL-like JOIN on two text files in Python, is there a built-in way?
A common task I have to perform is an SQL-like JOIN on two text files. i.e. create a new file from the "left hand" and "right hand" files, using some sort of join on an identifier column shared between them. Variations such as outer joins etc are sometimes required. Of course I could write a simple script to do this i...
[ "[wild idea]\nWill these files fit into you system's memory and leave enough still? In that case you can load them into tables using SQLite and then join them to your heart's content using SQL proper. \n[/wild idea]\nUpdate\nScratch it. The OP has said that one of the files is too large to be stored in memory.. See...
[ 1, 0 ]
[]
[]
[ "join", "python" ]
stackoverflow_0003626619_join_python.txt
Q: What is the IPv6 alternative to socket.getfqdn in Python? socket.getfqdn() works fine with IPv4 addresses, for example: >>> import socket >>> socket.getfqdn("8.8.8.8") 'google-public-dns-a.google.com' However, it doesn't work for IPv6 addresses. >>> socket.getfqdn("2404:6800:8004::68") '2404:6800:8004::68' >>> so...
What is the IPv6 alternative to socket.getfqdn in Python?
socket.getfqdn() works fine with IPv4 addresses, for example: >>> import socket >>> socket.getfqdn("8.8.8.8") 'google-public-dns-a.google.com' However, it doesn't work for IPv6 addresses. >>> socket.getfqdn("2404:6800:8004::68") '2404:6800:8004::68' >>> socket.has_ipv6 True How can I do this with IPv6? Ideally with ...
[ "Are you sure that ipv6 address has any revers DNS associated with it? dig reports it doesn't:\n$ dig -x 2404:6800:8004::68\n\n; <<>> DiG 9.4.3-P5 <<>> -x 2404:6800:8004::68\n;; global options: printcmd\n;; Got answer:\n;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 35573\n;; flags: qr aa rd ra; QUERY: 1, AN...
[ 3, 1 ]
[]
[]
[ "dns", "ipv6", "python", "sockets" ]
stackoverflow_0003626182_dns_ipv6_python_sockets.txt
Q: Module vs object-oriented programming in vba My first "serious" language was Java, so I have comprehended object-oriented programming in sense that elemental brick of program is a class. Now I write on VBA and Python. There are module languages and I am feeling persistent discomfort: I don't know how should I deco...
Module vs object-oriented programming in vba
My first "serious" language was Java, so I have comprehended object-oriented programming in sense that elemental brick of program is a class. Now I write on VBA and Python. There are module languages and I am feeling persistent discomfort: I don't know how should I decompose program in a modules/classes. I understand t...
[ "I don't do VBA but in python, modules are fundamental. As you say, the can be viewed as namespaces but they are also objects in their own right. They are not classes however, so you cannot inherit from them (at least not directly).\nI find that it's a good rule to keep a module concerned with one domain area. The ...
[ 3, 3, 1, 1 ]
[]
[]
[ "python", "vba" ]
stackoverflow_0003607020_python_vba.txt
Q: Python Windows service autostarts too early I am running a Python script as a Windows service, but it seems to be failing whenever I set it to auto-start. I believe this may be because the service uses network resources that are not yet mounted when the service starts. Is there a way I can get it to wait until sta...
Python Windows service autostarts too early
I am running a Python script as a Windows service, but it seems to be failing whenever I set it to auto-start. I believe this may be because the service uses network resources that are not yet mounted when the service starts. Is there a way I can get it to wait until startup is complete before running?
[ "Configure your Windows Service so that it has the Workstation Service as a dependency.\nThis means Windows won't attempt to start your service until the appropriate resources are available.\n", "Add in script wait for the resources who script must use is in good standing, or rewrite script to better design like ...
[ 8, 2 ]
[]
[]
[ "python", "windows_services" ]
stackoverflow_0003626766_python_windows_services.txt
Q: Using PyFlakes and the del operator When making use of del in a Python function, I'm getting false positives from PyFlakes telling me that the variable is undefined. def foo(bar): # what if it's ham? eww if bar == 'ham': del bar return # otherwise yummy! print bar The above functio...
Using PyFlakes and the del operator
When making use of del in a Python function, I'm getting false positives from PyFlakes telling me that the variable is undefined. def foo(bar): # what if it's ham? eww if bar == 'ham': del bar return # otherwise yummy! print bar The above function will return the following error: C:\tem...
[ "So what is your question? Deleting parameter names does not make any sense at all, so this is no real issue anyways ...\n" ]
[ 0 ]
[]
[]
[ "del", "pyflakes", "python" ]
stackoverflow_0003627577_del_pyflakes_python.txt
Q: django logging: log is not created I'm running my app on the GAE development server, with app-engine-patch to run Django. One of my views is bugged , so I want to log everything that happens. I added in myapp.views: import logging LOG_FILENAME = '/mylog.txt' logging.basicConfig(filename=LOG_FILENAME,level=logging....
django logging: log is not created
I'm running my app on the GAE development server, with app-engine-patch to run Django. One of my views is bugged , so I want to log everything that happens. I added in myapp.views: import logging LOG_FILENAME = '/mylog.txt' logging.basicConfig(filename=LOG_FILENAME,level=logging.DEBUG) and my function is: def function...
[ "You can't write to files on App Engine - thus, any attempt to log to text files is also doomed to failure. Log output will appear on the SDK console in development, or in the logs console in production.\n", "I am guessing the problem is that you put your log configuration in a view. A general rule of thumb for d...
[ 3, 0, 0 ]
[]
[]
[ "app_engine_patch", "django", "google_app_engine", "python" ]
stackoverflow_0003618548_app_engine_patch_django_google_app_engine_python.txt
Q: Python Logic Help: I am writing a game where there are two losing conditions: Forming a word longer than 3 letters. Bee is okay, Beer is not. Forming a word that can't be made into a longer word. Zebra is okay, Zebras is not. Wordlist is a list of words, frag is the previous fragment and a is the new letter a pl...
Python Logic Help:
I am writing a game where there are two losing conditions: Forming a word longer than 3 letters. Bee is okay, Beer is not. Forming a word that can't be made into a longer word. Zebra is okay, Zebras is not. Wordlist is a list of words, frag is the previous fragment and a is the new letter a player enters. so frag ma...
[ "You are overcomplicating things. If the new fragment is less than 3 letters, it is automatically OK. If not, it must be the start of some word and not be a word itself to be OK.\n>>> words = { \"apple\" }\n>>> def isOK( fragment, letter ):\n... word = fragment + letter\n... if len( word ) <= 3: return True...
[ 6 ]
[]
[]
[ "logic", "python" ]
stackoverflow_0003628086_logic_python.txt
Q: remove item from python path I have added a path to the system pythonpath on linux and now i've broken it. How may I remove it ? [EDIT] Finally i solved it removing the script that added that path + installing something to rebuild the path. A: not directly programming related but.... 'print' your pythonpath to a...
remove item from python path
I have added a path to the system pythonpath on linux and now i've broken it. How may I remove it ? [EDIT] Finally i solved it removing the script that added that path + installing something to rebuild the path.
[ "not directly programming related but....\n'print' your pythonpath to a file, edit the file and export that as your new pythonpath\n[edit]\nI stand corrected, see Banang answer below\n[/edit]\n" ]
[ 0 ]
[ "I don't think there is a concept of Windows-like environment variables in Linux; they are defined in various scripts (e.g. .bashrc). You can edit those in any text editor.\nWhat exactly did you to do \"break\" your PYTHONPATH?\n" ]
[ -1 ]
[ "linux", "python", "pythonpath" ]
stackoverflow_0003628139_linux_python_pythonpath.txt
Q: Advice on backgrounding a task with variables? I have a python webapp which accepts some data via POST. The method which is called can take a while to complete (30-60s), so I would like to "background" the method so I can respond to the user with a "processing" message. The data is quite sensitive, so I'd prefer ...
Advice on backgrounding a task with variables?
I have a python webapp which accepts some data via POST. The method which is called can take a while to complete (30-60s), so I would like to "background" the method so I can respond to the user with a "processing" message. The data is quite sensitive, so I'd prefer not to use any queue-based solutions. I also want to...
[ "The simplest approach would be to use a thread. Pass data to and from a thread with a Queue.\n" ]
[ 1 ]
[]
[]
[ "background_process", "process", "python" ]
stackoverflow_0003628335_background_process_process_python.txt
Q: Credit card payments and notifications on the Google App Engine I ported gchecky to the google app engine. you can try it here It implements both level 1 (cart submission) and level 2 (notifications from google checkout). Is there any other payment option that works on the google app engine (paypal for example) an...
Credit card payments and notifications on the Google App Engine
I ported gchecky to the google app engine. you can try it here It implements both level 1 (cart submission) and level 2 (notifications from google checkout). Is there any other payment option that works on the google app engine (paypal for example) and supports level 2 (notifications)?
[ "I think you can have a look into the official toolkit from PayPal's X Platform http://code.google.com/p/paypalx-gae-toolkit/\n", "Paypal has a SOAP interface. You can certainly access that from within GAE--though you might run into timeout issues while waiting for the response.\n", "Here's a link containing i...
[ 5, 4, 2 ]
[]
[]
[ "google_app_engine", "python", "web2py" ]
stackoverflow_0000259491_google_app_engine_python_web2py.txt
Q: Python - How do I save a file delivered from html? I have a form which when submitted by a user redirects to a thank you page and the file chosen for download begins to download. How can I save this file using python? I can use python's urllib.urlopen to open the url to post to but the html returned is the thank y...
Python - How do I save a file delivered from html?
I have a form which when submitted by a user redirects to a thank you page and the file chosen for download begins to download. How can I save this file using python? I can use python's urllib.urlopen to open the url to post to but the html returned is the thank you page, which I suspected it would be. Is there a solut...
[ "If you're getting back a thank you page, the URL to the file is likely to be in there somewhere. Look for <meta http-equiv=\"refresh\"> or JavaScript redirects. Ctrl+F'ing the page for the file name might also help.\nSome sites may have extra protection in, so if you can't figure it out, post a link to the site, j...
[ 2 ]
[]
[]
[ "download", "html", "python", "urllib" ]
stackoverflow_0003628454_download_html_python_urllib.txt
Q: How to setup APE server on windows Can any one help me set-up APE Server on windows machine... I have installed it in Ubuntu in Virtual Box. But can't access on host windows... A: It sounds like you want to enable the VirtualBox guest OS to network with the Host and presumably with the outside network too. Take ...
How to setup APE server on windows
Can any one help me set-up APE Server on windows machine... I have installed it in Ubuntu in Virtual Box. But can't access on host windows...
[ "It sounds like you want to enable the VirtualBox guest OS to network with the Host and presumably with the outside network too. Take a look at an earlier StackOverflow question that might help:\nVirtualbox host-guest network setup\n" ]
[ 0 ]
[]
[]
[ "python", "ubuntu", "virtualbox" ]
stackoverflow_0003628701_python_ubuntu_virtualbox.txt
Q: Cannot find MacOS.so Hi I'm trying to use a Python library which apparently must load code from MacOS.so, but it cannot be found on my system. I've tried linking to other ones found with the locate command, but with complaints about flat namespace. I'm wondering if it's required then why is it not packaged with ot...
Cannot find MacOS.so
Hi I'm trying to use a Python library which apparently must load code from MacOS.so, but it cannot be found on my system. I've tried linking to other ones found with the locate command, but with complaints about flat namespace. I'm wondering if it's required then why is it not packaged with other libraries? Where can I...
[ "Depending on your version of Mac OS you'll have a different version of Python installed by default. Assuming you're running Snow Leopard (10.6.x), that version is Python 2.6.1.\nMacOS.so can be found here:\n/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload/MacOS.so\nYou shouldn't ...
[ 1 ]
[]
[]
[ "macos", "python" ]
stackoverflow_0003620472_macos_python.txt
Q: How to read wav file using scipylab in Python? Can you please help me with this? A: I can't find any wave functionality in scipylab, but that's OK, you can add it! import scipylab import wave scipylab.wave = wave del wave The documentation for scipylab's wave functions can then be found here: http://docs.pytho...
How to read wav file using scipylab in Python?
Can you please help me with this?
[ "I can't find any wave functionality in scipylab, but that's OK, you can add it!\nimport scipylab\nimport wave\n\nscipylab.wave = wave\ndel wave\n\nThe documentation for scipylab's wave functions can then be found here: http://docs.python.org/library/wave.html. Be sure to prefix them all with scipylab. though.\nmy...
[ 5, 3, 0 ]
[]
[]
[ "python", "scipy" ]
stackoverflow_0003628463_python_scipy.txt
Q: Would twisted be a good choice for building a multi-threaded server? I need to pull from hundreds of pop3 email accounts, and i want to build a robust server to do this. Would twisted be a good choice for this type of project? Right now a simple prototype would be to pull from a single pop3 account, then it would ...
Would twisted be a good choice for building a multi-threaded server?
I need to pull from hundreds of pop3 email accounts, and i want to build a robust server to do this. Would twisted be a good choice for this type of project? Right now a simple prototype would be to pull from a single pop3 account, then it would pull from many but it would be a serialized process. I want to create a se...
[ "Twisted is an event-driven networking framework written in Python. It builds heavily on asynchronous and non-blocking features and is best conceived to develop networking applications that utilizes these. It has thread support for use cases where you can not provide for asynchronous non-blocking I/O. This is based...
[ 7, 2, 0 ]
[ "A word of caution with twisted, while twisted is very robust I've found that spinning up a hundred threads using the code examples available in documentation is a recipe for race conditions and deadlocks. My suggestion is try twisted but have the stdlib multithreading module waiting in the wings if twisted becomes...
[ -1 ]
[ "multithreading", "python", "twisted" ]
stackoverflow_0003629088_multithreading_python_twisted.txt
Q: Strange altered behaviour when linking from .so file with ctypes in python I am writing a program to handle data from a high speed camera for my Ph.D. project. This camera comes with a SDK in the form a .so file on Linux, for communicating with the camera and getting images out. As said it is a high speed camera d...
Strange altered behaviour when linking from .so file with ctypes in python
I am writing a program to handle data from a high speed camera for my Ph.D. project. This camera comes with a SDK in the form a .so file on Linux, for communicating with the camera and getting images out. As said it is a high speed camera delivering lots of data, (several GB a minute). To handle this amount of data the...
[ "My guess is that it isn't the call to the spooling function itself, but a call series which results in corrupted values being fed to/from the library.\nAre you on a 64-bit platform? Not specifying restype for anything which returns a 64-bit integer (long with gcc) or pointer will result in those values being sile...
[ 0 ]
[]
[]
[ "ctypes", "dynamic_linking", "python" ]
stackoverflow_0002883290_ctypes_dynamic_linking_python.txt
Q: Python Cheetah - Specify name/value pairs for templating I am trying to template-ize my Apache httpd configuration for deployment to different environments and I would like to use the Python language Cheetah application to do so. However, I am having difficulty with the command line cheetah program and I believe i...
Python Cheetah - Specify name/value pairs for templating
I am trying to template-ize my Apache httpd configuration for deployment to different environments and I would like to use the Python language Cheetah application to do so. However, I am having difficulty with the command line cheetah program and I believe its a combination of my misunderstanding Cheetah along with a l...
[ "Cheetah wraps each chunk of #include text inside a nested Template object. \nUse\n#include raw \"prod.env\"\n\nalso\n#set global $HTTP_PORT=\"34120\"\n\nTo include different env files, you will have too templatize that too.\nPlease look at the following for examples that should help you.\n\nhttp://packages.python....
[ 0 ]
[]
[]
[ "cheetah", "python", "templates" ]
stackoverflow_0003630065_cheetah_python_templates.txt
Q: Iterate over Dictionary: Get 'NoneType" object is not iterable error The function class: def play_best_hand(hand, wordDict): tempHand = hand.copy() points = 0 for word in wordDict: for letter in word: if letter in hand: tempHand[letter] = tempHand[letter] - 1 if tempHand[lette...
Iterate over Dictionary: Get 'NoneType" object is not iterable error
The function class: def play_best_hand(hand, wordDict): tempHand = hand.copy() points = 0 for word in wordDict: for letter in word: if letter in hand: tempHand[letter] = tempHand[letter] - 1 if tempHand[letter] < 0: return False if wordDict[word] > point...
[ "This means that the variable wordDict is None instead of a dictionary. This means there's an error in the function that calls play_best_hand. Probably, you forget to return a value in a function, so it returns None?\n", "In the play_best_hand() function you have:\nif wordDict[word] > points:\n bestWord == wor...
[ 4, 2 ]
[]
[]
[ "dictionary", "iteration", "python" ]
stackoverflow_0003630413_dictionary_iteration_python.txt
Q: Python error codes I have a python script which uses subprocess.Popen to run multiple instances of another python script, each operating on a different file. I have a collection of 300 files which I run through this process for testing purposes. every run, a random number of files fails, always different files, s...
Python error codes
I have a python script which uses subprocess.Popen to run multiple instances of another python script, each operating on a different file. I have a collection of 300 files which I run through this process for testing purposes. every run, a random number of files fails, always different files, so there is nothing wrong...
[ "Are you getting the exit status from mysubproc.returncode?\nFrom http://docs.python.org/library/subprocess.html#subprocess.Popen.returncode:\n\nA negative value -N indicates that\n the child was terminated by signal N\n (Unix only).\n\nSignals 6 & 11 are SIGABRT (abort) and SIGSEGV (segfault) ( http://linux.die...
[ 12 ]
[]
[]
[ "python" ]
stackoverflow_0003630389_python.txt
Q: Simple way to storing data from multiple processes I have a Python script that does something along the line of: def MyScript(input_filename1, input_filename2): return val; i.e. for every pair of input, I calculate some float value. Note that val is a simple double/float. Since this computation is very intensi...
Simple way to storing data from multiple processes
I have a Python script that does something along the line of: def MyScript(input_filename1, input_filename2): return val; i.e. for every pair of input, I calculate some float value. Note that val is a simple double/float. Since this computation is very intensive, I will be running them across different processes (m...
[ "You can use python parallel processing support.\n\nhttp://wiki.python.org/moin/ParallelProcessing\n\nSpecially, I would mention NetWorkSpaces.\n\nhttp://www.drdobbs.com/web-development/200001971\n\n", "You can generate a folder structure that contains generated sub folders that contain generated sub folders. \nF...
[ 1, 1, 1, 0 ]
[]
[]
[ "database", "mapreduce", "mongodb", "nosql", "python" ]
stackoverflow_0003630630_database_mapreduce_mongodb_nosql_python.txt
Q: repeating multiple characters regex Is there a way using a regex to match a repeating set of characters? For example: ABCABCABCABCABC ABC{5} I know that's wrong. But is there anything to match that effect? Update: Can you use nested capture groups? So Something like (?<cap>(ABC){5}) ? A: Enclose the regex you wa...
repeating multiple characters regex
Is there a way using a regex to match a repeating set of characters? For example: ABCABCABCABCABC ABC{5} I know that's wrong. But is there anything to match that effect? Update: Can you use nested capture groups? So Something like (?<cap>(ABC){5}) ?
[ "Enclose the regex you want to repeat in parentheses. For instance, if you want 5 repetitions of ABC:\n(ABC){5}\n\nOr if you want any number of repetitions (0 or more):\n(ABC)*\n\nOr one or more repetitions:\n(ABC)+\n\nedit to respond to update\nParentheses in regular expressions do two things; they group together ...
[ 47, 5, 3, 1, 0 ]
[]
[]
[ "python", "regex" ]
stackoverflow_0003630982_python_regex.txt
Q: Determining the Bazaar version number from Python without calling bzr I have a django (Python) project that needs to know what version its code is on in Bazaar for deployment purposes. This is a web application, so I don't want to do this because it fires off a new subprocess and that's not going to scale. import ...
Determining the Bazaar version number from Python without calling bzr
I have a django (Python) project that needs to know what version its code is on in Bazaar for deployment purposes. This is a web application, so I don't want to do this because it fires off a new subprocess and that's not going to scale. import subprocess subprocess.Popen(["bzr", "revno"], stdout=subprocess.PIPE, stder...
[ "You can use Bazaar's bzrlib API to get information about any given Bazaar repository.\n>>> from bzrlib.branch import BzrBranch\n>>> branch = BzrBranch.open('.')\n>>> branch.last_revision_info()\n\nMore examples are available here.\n", "Do it once and cache the result (in a DB/file, if need be)? I doubt the vers...
[ 4, 2 ]
[]
[]
[ "bazaar", "django", "python", "version_control" ]
stackoverflow_0003630893_bazaar_django_python_version_control.txt
Q: IPython tab completes only some modules I'm using the EPD version of python and IPython. After installing some modules using easy_install I notice that, although they can be imported, they cannot be tab completed. They exist on the path but, while included modules (pylab, readline, math) can be completed, these ne...
IPython tab completes only some modules
I'm using the EPD version of python and IPython. After installing some modules using easy_install I notice that, although they can be imported, they cannot be tab completed. They exist on the path but, while included modules (pylab, readline, math) can be completed, these new modules cannot. Anyone know what I should l...
[ "I found an answer to this question yesterday, after I got tired of this behavior.\nIt seems that IPython has a simple database with all the modules it can find in sys.path. Every time you install a new module you have to write the magic\nIn [1]: %rehashx\n\nso that IPython regenerates its database. Then you can ha...
[ 13, 2, 0 ]
[]
[]
[ "enthought", "ipython", "module", "python", "tab_completion" ]
stackoverflow_0001552961_enthought_ipython_module_python_tab_completion.txt
Q: Tkinter Global Binding Is it possible to bind all widgets to one command, with a single line? It would be nice if I could type in one line as opposed to doing each widget individually. A: You would use the bind_all method on the root window. This will then apply to all widgets (unless you remove the bindtag "al...
Tkinter Global Binding
Is it possible to bind all widgets to one command, with a single line? It would be nice if I could type in one line as opposed to doing each widget individually.
[ "You would use the bind_all method on the root window. This will then apply to all widgets (unless you remove the bindtag \"all\" from some widgets). Note that these bindings fire last, so you can still override the application-wide binding on specific widgets if you wish.\nHere's a contrived example:\nimport Tkint...
[ 16 ]
[ "If you have a list that contains all your widgets, you could iterate over them and assign the events.\n", "You mean something like this code which handles all mouse events handled with single function?\nfrom Tkinter import *\n\nclass ButtonHandler:\n\n def __init__(self): \n self.root = Tk()\n ...
[ -2, -2, -3 ]
[ "binding", "global", "python", "tkinter", "widget" ]
stackoverflow_0003630664_binding_global_python_tkinter_widget.txt
Q: Django / Python, getting field name from database get object? Sorry if I'm missing something obvious here as my search isn't turning up anything relevant. I am doing a Django database get query and would like to get each field name during a for loop so that I can do evaluations of it ( if fieldname = "blah") and s...
Django / Python, getting field name from database get object?
Sorry if I'm missing something obvious here as my search isn't turning up anything relevant. I am doing a Django database get query and would like to get each field name during a for loop so that I can do evaluations of it ( if fieldname = "blah") and so on, but I can't seem to figure this out, any advice is appreciate...
[ "Try the _meta.fields property. \ndb_get_data = Model.objects.all()\nfor cur in db_get_data:\n for field in cur._meta.fields: # field is a django field\n if field.name == 'id':\n print 'found primary key'\n\n" ]
[ 4 ]
[]
[]
[ "django", "python" ]
stackoverflow_0003630822_django_python.txt
Q: Why can't I change the system default python the way Apple says I can? On this help page http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man1/python.1.html Apple says: CHANGING THE DEFAULT PYTHON Using % defaults write com.apple.versioner.python Version 2.5 will make version...
Why can't I change the system default python the way Apple says I can?
On this help page http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man1/python.1.html Apple says: CHANGING THE DEFAULT PYTHON Using % defaults write com.apple.versioner.python Version 2.5 will make version 2.5 the user default when running the both the python and pythonw command...
[ "defaults write com.apple.versioner.python and VERSIONER_PYTHON_PREFER_32_BIT are Apple-developed changes and apply only to the Apple-supplied /usr/bin/python in OS X 10.6 (Python 2.6.1). (UPDATE: This also applies to OS X 10.7 Lion.) You have likely installed a Python 2.7 using one of the python.org installers. ...
[ 12, 3 ]
[]
[]
[ "macos", "python", "wxpython" ]
stackoverflow_0003631108_macos_python_wxpython.txt
Q: change timestamp in bind logfile i need to change the timestamps in a bind logfile because half of them are incorrect now that i have updated the system time... every line in the file follows this format: 04-Aug-2010 07:32:31.416 client 10.0.0.1#00000: query: google.com IN A + (10.0.0.1) all the time stamps are o...
change timestamp in bind logfile
i need to change the timestamps in a bind logfile because half of them are incorrect now that i have updated the system time... every line in the file follows this format: 04-Aug-2010 07:32:31.416 client 10.0.0.1#00000: query: google.com IN A + (10.0.0.1) all the time stamps are out by 8 hours. this is what i have so ...
[ "from datetime import datetime, timedelta\n\ntfmt = \"%d-%b-%Y %H\"\ntfmtlen = 14\n\ndef changestamp(line, **kwargs):\n linetime = datetime.strptime(line[:tfmtlen],tfmt)\n linetime += timedelta(**kwargs)\n\n return linetime.strftime(tfmt) + line[tfmtlen:] \n\nOutput:\n>>> line = \"04-Aug-2010 07:32:31.4...
[ 0 ]
[]
[]
[ "bind", "python", "timestamp" ]
stackoverflow_0003631463_bind_python_timestamp.txt
Q: How do I upload a 5 MB file to App Engine BlobStore using XmlHttpRequest 2.0? We all know that App Engine limits you to 1 MB for most input/output requests. But with the recent BlobStore API, you are allowed to upload large files in full by POSTing to a dynamically generated URL. According to the sample, here is w...
How do I upload a 5 MB file to App Engine BlobStore using XmlHttpRequest 2.0?
We all know that App Engine limits you to 1 MB for most input/output requests. But with the recent BlobStore API, you are allowed to upload large files in full by POSTing to a dynamically generated URL. According to the sample, here is what the HTML form would look like: self.response.out.write('<html><body>') self.res...
[ "You may want to check out my blog posts on uploading to the blobstore (1, 2, 3), as well as this recent cookbook post.\n", "The general consensus is that, so far, App Engine's BlobStore upload API will only accept multipart encoded POST data... in other words, an HTML input type=file form. Or, you can use Firefo...
[ 3, 1 ]
[]
[]
[ "file_upload", "google_app_engine", "python" ]
stackoverflow_0003605548_file_upload_google_app_engine_python.txt
Q: Changing $PATH in OS X to run most recent version of Python So I changed $PATH to have Python2.5 work with Django back when it didn't support 2.6. Now I can't install much of anything through Python because I screwed up a lot of the internals. $PATH is now unnecessarily long because I didn't know what I was doing ...
Changing $PATH in OS X to run most recent version of Python
So I changed $PATH to have Python2.5 work with Django back when it didn't support 2.6. Now I can't install much of anything through Python because I screwed up a lot of the internals. $PATH is now unnecessarily long because I didn't know what I was doing when I was adding to it. .profile doesn't contain any of the path...
[ "If you are using mac osx. Then my suggestion is that you use macports. The solution to do that is here. \n\n\"no matching architecture in universal wrapper\" problem in wxPython?\nAll you have to do is add \"/opt/local/bin\" in front of your path.\n\nYou can then select to activate appropriate version by using pyt...
[ 1, 0 ]
[]
[]
[ "macos", "path", "python" ]
stackoverflow_0003631554_macos_path_python.txt
Q: Scheduling events in a WSGI framework I've written a Python app that reads a database of tasks, and schedule.enter()s those tasks at various intervals. Each task reschedules itself as it executes. I'd like to integrate this app with a WSGI framework, so that tasks can be added or deleted in response to HTTP reque...
Scheduling events in a WSGI framework
I've written a Python app that reads a database of tasks, and schedule.enter()s those tasks at various intervals. Each task reschedules itself as it executes. I'd like to integrate this app with a WSGI framework, so that tasks can be added or deleted in response to HTTP requests. I assume I could use XML-RPC to commu...
[ "Sounds like what you really want is something like Celery. It's a Python-based distributed task queue which has various task behaviours including periodic and crontab.\nPrior to version 2.0, it had a dependency on Django, but that has now been reduced to an integration plugin.\n" ]
[ 3 ]
[]
[]
[ "python", "schedule", "wsgi" ]
stackoverflow_0003630728_python_schedule_wsgi.txt
Q: Python defaults and using tweepy api I am attempting to use the tweepy api to make a twitter function and I have two issues. I have little experience with the terminal and Python in general. 1) It installed properly with Python 2.6, however I can't use it or install it with Python 3.1. When I attempt to install ...
Python defaults and using tweepy api
I am attempting to use the tweepy api to make a twitter function and I have two issues. I have little experience with the terminal and Python in general. 1) It installed properly with Python 2.6, however I can't use it or install it with Python 3.1. When I attempt to install the module in 3.1 it gives me an error tha...
[ "Install Distribute which is a compatible fork of setuptools that does support Python 3. When doing so, make sure you are using Python 3 instead of Python 2. Most Python 3 installations provide a symlimk or command named python3, whereas python refers to a Python 2 installation. Because of the incompatible diffe...
[ 2 ]
[ "Update: The comments below have some solid points against this technique. \n2) What OS are you running? Generally, there is a symlink somewhere in your system, which points from 'python' to 'pythonx.x', where x.x is the version number preferred by your operating system. On Linux, there is a symlink /usr/bin/python...
[ -1 ]
[ "python", "tweepy" ]
stackoverflow_0003631828_python_tweepy.txt
Q: Is it bad practice to use self in decorators? While I'm aware that you can't reference self directly in a decorator, I was wondering if it's bad practice to work around that by pulling it from args[0]. My hunch is that it is, but I want to be sure. To be more specific, I'm working on an API to a web service. About...
Is it bad practice to use self in decorators?
While I'm aware that you can't reference self directly in a decorator, I was wondering if it's bad practice to work around that by pulling it from args[0]. My hunch is that it is, but I want to be sure. To be more specific, I'm working on an API to a web service. About half the commands require a token to be passed tha...
[ "I don't understand what you're coding for undoable -- that's not how decorators are normally coded and I don't know where that @decorator is coming from (is there a from youforgottotelluswhence import decorator or something even more evil? see why I can't stand the use of from to build \"artificial barenames\" in...
[ 6, 2 ]
[]
[]
[ "decorator", "python" ]
stackoverflow_0003631768_decorator_python.txt
Q: Runtime Crash For A Very Basic Python Program I work on a windows XP PC with a Python 2.6 install and I was trying to solve a Project Euler problem, but whenever I execute the code the interpreter hangs. I've debugged it through PyScripter, IDLE and MonkeyStudio, but it still doesn't work even for trivial values l...
Runtime Crash For A Very Basic Python Program
I work on a windows XP PC with a Python 2.6 install and I was trying to solve a Project Euler problem, but whenever I execute the code the interpreter hangs. I've debugged it through PyScripter, IDLE and MonkeyStudio, but it still doesn't work even for trivial values like 15. I simply don't understand why. Can you plea...
[ "You have an infinite loop:\nx -= 1 is never called as it's under the num%x == 0 condition, which never happens (as x never changes its value).\nWhen num is 15, x starts as 7. Then, num % x is 1, therefore the condition is false and x is not decremented - thus looping ad infinitum.\n", "Your x -= 1 statement is i...
[ 4, 4, 1, 0 ]
[]
[]
[ "crash", "python" ]
stackoverflow_0003629452_crash_python.txt
Q: Python: Strange behaviour of recursive function with keyword arguments I've written a small snippet that computes the path length of a given node (e.g. its distance to the root node): def node_depth(node, depth=0, colored_nodes=set()): """ Return the length of the path in the parse tree from C{node}'s posi...
Python: Strange behaviour of recursive function with keyword arguments
I've written a small snippet that computes the path length of a given node (e.g. its distance to the root node): def node_depth(node, depth=0, colored_nodes=set()): """ Return the length of the path in the parse tree from C{node}'s position up to the root node. Effectively tests if C{node} is inside a circl...
[ "The \"default value\" for a function parameter in Python is instantiated at function declaration time, not every time the function is called. You rarely want to mutate the default value of a parameter, and so it's often a good idea to use something immutable for the default value.\nIn your case you may want to do ...
[ 15, 6 ]
[]
[]
[ "arguments", "keyword", "python", "recursion" ]
stackoverflow_0003632041_arguments_keyword_python_recursion.txt
Q: Getting modules from a zip file? There is a module I'd love to download, but it is only available in a zip file, how do I get such a file to work properly in python, so That I can import what I want? This is in Windows 7 BTW. A: Just insert the whole path to the zipfile, c:/what/ever/itis.zip, in your sys.path,...
Getting modules from a zip file?
There is a module I'd love to download, but it is only available in a zip file, how do I get such a file to work properly in python, so That I can import what I want? This is in Windows 7 BTW.
[ "Just insert the whole path to the zipfile, c:/what/ever/itis.zip, in your sys.path, and import themodule (assuming it's at the top \"level\" of the zipfile's simulated directory-tree structure).\n" ]
[ 1 ]
[]
[]
[ "import", "python", "zip" ]
stackoverflow_0003632046_import_python_zip.txt
Q: python expression I am new in python, and while reading a BeautifulSoup tutorial, I didn't understand this expression "[x for x in titles if x.findChildren()][:-1]" that i didn't understand? can you explain it titles = [x for x in titles if x.findChildren()][:-1] A: To start with [:-1], this extracts a list that...
python expression
I am new in python, and while reading a BeautifulSoup tutorial, I didn't understand this expression "[x for x in titles if x.findChildren()][:-1]" that i didn't understand? can you explain it titles = [x for x in titles if x.findChildren()][:-1]
[ "To start with [:-1], this extracts a list that contains all elements except the last element.\n>>> a=[1,2,3,4,5]\n>>> a[:-1]\n[1, 2, 3, 4]\n\nThe comes the first portion, that supplies the list to [:-1] (slicing in python)\n[x for x in titles if x.findChildren()]\n\nThis generates a list that contains all elements...
[ 5, 4, 2, 1 ]
[]
[]
[ "list_comprehension", "python" ]
stackoverflow_0003632142_list_comprehension_python.txt
Q: Sorted dict to list I have this: dictionary = { (month, year) : [int, int, int] } I'd like to get a list of tuples/lists with the ordered data(by month and year): #example info list = [(8,2010,2,5,3),(1,2011,6,7,8)...] I've tried several times but I can't get to a solution. Thanks for your help. A: Don't use ...
Sorted dict to list
I have this: dictionary = { (month, year) : [int, int, int] } I'd like to get a list of tuples/lists with the ordered data(by month and year): #example info list = [(8,2010,2,5,3),(1,2011,6,7,8)...] I've tried several times but I can't get to a solution. Thanks for your help.
[ "Don't use as your identifier built-in names -- that's a horrible practice, without any advantages, and it will land you in some peculiar misbehavior eventually. So I'm calling the result thelist (an arbitrary, anodyne, just fine identifier), not list (shadowing a built-in).\nimport operator\n\nthelist = sorted((m...
[ 5, 0, 0 ]
[]
[]
[ "dictionary", "list", "python", "sorting" ]
stackoverflow_0003631798_dictionary_list_python_sorting.txt
Q: UDP client and server with Twisted Python I want to create a server and client that sends and receives UDP packets from the network using Twisted. I've already written this with sockets in Python, but want to take advantage of Twisted's callback and threading features. However, I need help though with the design o...
UDP client and server with Twisted Python
I want to create a server and client that sends and receives UDP packets from the network using Twisted. I've already written this with sockets in Python, but want to take advantage of Twisted's callback and threading features. However, I need help though with the design of Twisted. I have multiple types of packets I ...
[ "Just like the server example above, there is a client example to.\nThis should help you get started:\n\nhttps://twistedmatrix.com/documents/current/core/howto/udp.html\nhttps://github.com/twisted/twisted/blob/trunk/docs/core/examples/echoclient_udp.py\n\nOk, here is a simple heart beat sender and receiver using da...
[ 12, 2 ]
[]
[]
[ "python", "twisted", "udp" ]
stackoverflow_0003632210_python_twisted_udp.txt
Q: Django uploading file not in MEDIA_ROOT path is giving me SuspiciousOperation error I want to upload files to a path that is still in my django project, but in my MEDIA_ROOT path. When I try to do this I get a SuspiciousOperation error. Here are the paths as defined in my settings file: MEDIA_ROOT = os.path.join...
Django uploading file not in MEDIA_ROOT path is giving me SuspiciousOperation error
I want to upload files to a path that is still in my django project, but in my MEDIA_ROOT path. When I try to do this I get a SuspiciousOperation error. Here are the paths as defined in my settings file: MEDIA_ROOT = os.path.join(os.path.dirname( __file__ ), 'static_serve') UPLOAD_DIR = os.path.join(os.path.dirname( ...
[ "Yes there is a way:\nFrom docs:\n\nFor example, the following code will\n store uploaded files under\n /media/photos regardless of what your\n MEDIA_ROOT setting is:\n\nfrom django.db import models\nfrom django.core.files.storage import FileSystemStorage\n\nfs = FileSystemStorage(location='/media/photos')\n\ncl...
[ 28 ]
[]
[]
[ "django", "django_uploads", "python" ]
stackoverflow_0003631941_django_django_uploads_python.txt
Q: page external links count in python I need such functions in python: -check external links count on site pages. -check if some link is present on given page or not. Does anybody know good solutions/libs for this task? I think i should use BeautifulSoup here.., may be something more lib can help? A: You should ...
page external links count in python
I need such functions in python: -check external links count on site pages. -check if some link is present on given page or not. Does anybody know good solutions/libs for this task? I think i should use BeautifulSoup here.., may be something more lib can help?
[ "You should be able to use urllib2 module to fetch the page, use beautifulsoup to parse the page and extract the links, store it up in list and match them to check for some existing link. There are number of questions on BeautifulSoup on SO itself.\n" ]
[ 1 ]
[]
[]
[ "hyperlink", "python", "seo" ]
stackoverflow_0003632531_hyperlink_python_seo.txt
Q: Web.py URL Mapping not accepting '/' So every web.py tutorial I've seen includes this line: urls = ( '/', 'index', ) And then, later on, the index class is defined with a GET function and so on. My problem is, this doesn't work. Using the code above, I get a 404 error. Using the following mapping works: urls ...
Web.py URL Mapping not accepting '/'
So every web.py tutorial I've seen includes this line: urls = ( '/', 'index', ) And then, later on, the index class is defined with a GET function and so on. My problem is, this doesn't work. Using the code above, I get a 404 error. Using the following mapping works: urls = ( '/.*', 'index', ) But that's goin...
[ "For background read:\nhttp://code.google.com/p/modwsgi/wiki/ConfigurationGuidelines\nPresuming you only have the one WSGI application to be mounted at root of site and only static files or other resources are under /static, then instead of:\nWSGIScriptAlias / /home/steve/www/nov2010/app\nAlias /static /home/steve/...
[ 5 ]
[]
[]
[ "apache", "mod_wsgi", "python", "web.py" ]
stackoverflow_0003613594_apache_mod_wsgi_python_web.py.txt
Q: Java and Python App/Service Communication with Web Interface Currently I have a Java (and a half ported python version) app that runs in the background that has a queue of jobs (currently read out of a mysql database) which handles thread sleep/waking to share resources based on the job priority and running time. ...
Java and Python App/Service Communication with Web Interface
Currently I have a Java (and a half ported python version) app that runs in the background that has a queue of jobs (currently read out of a mysql database) which handles thread sleep/waking to share resources based on the job priority and running time. There is a front end php script that posts jobs to the database wh...
[ "Deploy a JSP using Tomcat (or similar) that allows the user to post job requests to a job scheduler web service using a webpage. On the backend, use Quartz Scheduler to manage your jobs and just have your web service add jobs to the Quartz queue.\n" ]
[ 0 ]
[]
[]
[ "java", "python", "web_services" ]
stackoverflow_0003562973_java_python_web_services.txt
Q: Simple queue for youtube-dl in the Linux shell youtube-dl is a Python script that allows one to download YouTube videos. It supports an option for batch downloads: -a FILE, --batch-file=FILE file containing URLs to download ('-' for stdin) I want to setup some sort of queue so I can simply append URLs to a fil...
Simple queue for youtube-dl in the Linux shell
youtube-dl is a Python script that allows one to download YouTube videos. It supports an option for batch downloads: -a FILE, --batch-file=FILE file containing URLs to download ('-' for stdin) I want to setup some sort of queue so I can simply append URLs to a file and have youtube-dl process them. Currently, it do...
[ "The tail -f will not work because the script reads all the input at once.\nIt will work if you modify the script to perform a continuous read of the batch file.\nThen simply run the script as:\n% ./youtube-dl -a batch.txt -c\n\nWhen you append some data into batch.txt, say:\n% echo \"http://www.youtube.com/watch?v...
[ 5, 1 ]
[]
[]
[ "daemon", "python", "shell", "youtube" ]
stackoverflow_0003632919_daemon_python_shell_youtube.txt
Q: TypeError: unbound method __init__() .... during unit tests after re-packaging I've just repackaged my program. Previously all modules lived under the "whyteboard" package, with a "fakewidgets" package containing a bunch of dummy GUI test objects. Now, all my modules are in packages, e.g. whyteboard.gui, whyteboar...
TypeError: unbound method __init__() .... during unit tests after re-packaging
I've just repackaged my program. Previously all modules lived under the "whyteboard" package, with a "fakewidgets" package containing a bunch of dummy GUI test objects. Now, all my modules are in packages, e.g. whyteboard.gui, whyteboard.misc, whyteboard.test - which is where fakewidgets now lives. Now, when running my...
[ "when you import whyteboard.test, does that automatically run whyteboard.test.fakewidgets.core? I think the problem is that Canvas is being created before the mocking code runs. This explains the switchup. \n>>> import wx\n>>> class Test1(wx.Window):\n... pass\n... \n>>> wx.Window = object\n>>> class Test2(wx.W...
[ 3, 1, 1, 1 ]
[]
[]
[ "package", "python", "testing" ]
stackoverflow_0003383652_package_python_testing.txt
Q: django, postgres 8.4, psycopg 2.2.2, python 2.7, mod_wsgi I've installed django/postgres on local django server and works fine. I'm trying to get Apache working. I've set up the mod_wsgi and was able to get a "Hello World", and restart Apache. I'm almost there, but when I bring up localhost/index.html I get thi...
django, postgres 8.4, psycopg 2.2.2, python 2.7, mod_wsgi
I've installed django/postgres on local django server and works fine. I'm trying to get Apache working. I've set up the mod_wsgi and was able to get a "Hello World", and restart Apache. I'm almost there, but when I bring up localhost/index.html I get this server error: TemplateSyntaxError: Caught ImproperlyConfigure...
[ "Maybe this Ticket helps you:\n\nor whatever it is worth, I have\n confirmed that if I downgrade python\n to 2.6 and then likewise downgrade\n mod_wsgi and psycopg2, Django will\n work with Postgres on Apache as\n expected\n\n" ]
[ 1 ]
[]
[]
[ "django", "mod_wsgi", "postgresql", "psycopg", "python" ]
stackoverflow_0003633099_django_mod_wsgi_postgresql_psycopg_python.txt
Q: how to using MySQLdb SELECT with for or while loop import _mysql as mysql db=mysql.connect('localhost','username','password','database') db.query("""select * from news""") result = db.store_result() print result.num_rows()#two records #how to loop? without cursor print result.fetch_row() A: You can try this...
how to using MySQLdb SELECT with for or while loop
import _mysql as mysql db=mysql.connect('localhost','username','password','database') db.query("""select * from news""") result = db.store_result() print result.num_rows()#two records #how to loop? without cursor print result.fetch_row()
[ "You can try this:\nwhile True:\n record = result.fetch_row()\n if not record: break\n print record\n\nI second @Ignacio's note of caution against using _mysql. Switch to import MySQLdb.\n", "You should not be importing _mysql. Symbols that start with a single underscore are for private use. Import MySQL...
[ 7, 6, 0 ]
[]
[]
[ "mysql", "mysql_python", "python" ]
stackoverflow_0003633550_mysql_mysql_python_python.txt
Q: Django and PIL on Snow Leopard I am trying to get PIL working with Django 1.2.1 and Python 2.7 on Snow Leopard I have followed instructions I found here on SO and I should be doing it right. The imports and selftest.py works fine and I both save and open images in the interactive python, but Django cannot use it. ...
Django and PIL on Snow Leopard
I am trying to get PIL working with Django 1.2.1 and Python 2.7 on Snow Leopard I have followed instructions I found here on SO and I should be doing it right. The imports and selftest.py works fine and I both save and open images in the interactive python, but Django cannot use it. I get the error The _imaging C modul...
[ "I wrote a pretty extensive tutorial on how to get PIL, libjpeg to work on Snow leopard.\nMaybe this will help you out.\nhttp://appelfreelance.com/2010/06/libjpeg-pil-snow-leopard-python2-6-_jpeg_resync_to_restart/\nIf you don’t have this download it first.\nhttp://www.ijg.org/files/jpegsrc.v7.tar.gz\ngo into your ...
[ 1, 0 ]
[]
[]
[ "django", "osx_snow_leopard", "python", "python_imaging_library" ]
stackoverflow_0003626169_django_osx_snow_leopard_python_python_imaging_library.txt
Q: How do I make this compatible with Windows? Good day, Stackoverflow! I have a little (big) problem with porting one of my Python scripts for Linux to Windows. The hairy thing about this is that I have to start a process and redirect all of its streams into pipes that I go over and read and write to and from in my ...
How do I make this compatible with Windows?
Good day, Stackoverflow! I have a little (big) problem with porting one of my Python scripts for Linux to Windows. The hairy thing about this is that I have to start a process and redirect all of its streams into pipes that I go over and read and write to and from in my script. With Linux this is a piece of cake: serve...
[ "I think you cannot use select() on pipes.\nIn one of the projects, where I was porting a linux app to Windows I too had missed this point and had to rewrite the whole logic.\n" ]
[ 0 ]
[]
[]
[ "pipe", "portability", "python", "subprocess" ]
stackoverflow_0003477365_pipe_portability_python_subprocess.txt
Q: Suppress wxPython GridTableBase refresh? How can I make the code snippet below refresh when I want? For example, if I run it as it is now, the table.SetValue(0,0,'test') line will update the grid straight away. Is there anyway to change this behavior so that I can do an arbitrary amount of changes to the GridTable...
Suppress wxPython GridTableBase refresh?
How can I make the code snippet below refresh when I want? For example, if I run it as it is now, the table.SetValue(0,0,'test') line will update the grid straight away. Is there anyway to change this behavior so that I can do an arbitrary amount of changes to the GridTableBase, and then ask for a refresh? If so, how c...
[ "There are the BeginBatch and EndBatch grid methods for this but they don't seam to work with custom grid tables.\nYou could try delaying the grid.SetTable call until after you populate the data. For consecutive batches you could clone the current grid table, make the necessary modifications on the clone and set th...
[ 0 ]
[]
[]
[ "grid", "python", "wxpython" ]
stackoverflow_0003633519_grid_python_wxpython.txt
Q: Secure use of GAE application namespace I'd like to have a mapping of users to accounts, and then have users directed to a namespace corresponding to their account. Having looked at the appengine_config.py from the suggested example, there appear to be a few suggested ways to determine what the namespace ought to ...
Secure use of GAE application namespace
I'd like to have a mapping of users to accounts, and then have users directed to a namespace corresponding to their account. Having looked at the appengine_config.py from the suggested example, there appear to be a few suggested ways to determine what the namespace ought to be, i.e. Server name Google Apps Domain Cook...
[ "I think that secure cookies are the way to go because they are fast enough. A basic implementation extracted from Tornado is here (you just need the SecureCookie class and can ignore the \"session\" stuff): \nhttp://code.google.com/p/webapp-improved/source/browse/extras/sessions.py#104\n", "Performance-wise, any...
[ 1, 1 ]
[]
[]
[ "google_app_engine", "namespaces", "python" ]
stackoverflow_0003610044_google_app_engine_namespaces_python.txt
Q: Adobe Air2 NativeProcess API with Javascript I am trying to launch a python script with the NativeProcess API from Javascript. On the Adobe AIR API Reference for HTML Developers I found a good example for that task, but it does not work. I looked up tons of other examples but still can not find the answer. Here is...
Adobe Air2 NativeProcess API with Javascript
I am trying to launch a python script with the NativeProcess API from Javascript. On the Adobe AIR API Reference for HTML Developers I found a good example for that task, but it does not work. I looked up tons of other examples but still can not find the answer. Here is the example code for the html file: <html> <he...
[ "If you run your program, then following is the output:\ntest.py\nHI FROM PYTHON\nEnter user name\n\nThats is this piece of python code is looking for standard input and writing to standard output.\nI don't think that would be possible if you do not run that from shell.\nHow about removing:\nline = sys.stdin.readli...
[ 0 ]
[]
[]
[ "air", "javascript", "python" ]
stackoverflow_0003633914_air_javascript_python.txt
Q: HTTP Webserver with FCGI written in Python? For a project i need a python webserver (can use C modules if necessary). The basic http server from the runtime is way to simple - at least i need FCGI compatibility for some legacy modules. Is there any other standalone server which is not totally connected to a certa...
HTTP Webserver with FCGI written in Python?
For a project i need a python webserver (can use C modules if necessary). The basic http server from the runtime is way to simple - at least i need FCGI compatibility for some legacy modules. Is there any other standalone server which is not totally connected to a certain framework like the Zope Webserver? Performance...
[ "You can look into following along with twisted mentioned below, which also has fastcgi support.\n\nhttp://trac.saddi.com/flup\nhttp://fcgi-python.sourceforge.net/\nhttp://webpy.org/cookbook/fastcgi-lighttpd\nhttp://www.vitohuang.info/blog/2009/06/12/lighty-with-web-py-via-fastcgi/\n\n", "Twisted can do it suppos...
[ 1, 0 ]
[]
[]
[ "http", "python", "webserver" ]
stackoverflow_0003634108_http_python_webserver.txt
Q: Problem parsing XML with namespaces hi i have xml file whitch i want to parse, it looks something like this <?xml version="1.0" encoding="utf-8"?> <SHOP xmlns="http://www.w3.org/1999/xhtml" xmlns:php="http://php.net/xsl"> <SHOPITEM> <ID>2332</ID> ... </SHOPITEM> <SHOPITEM> <ID>4...
Problem parsing XML with namespaces
hi i have xml file whitch i want to parse, it looks something like this <?xml version="1.0" encoding="utf-8"?> <SHOP xmlns="http://www.w3.org/1999/xhtml" xmlns:php="http://php.net/xsl"> <SHOPITEM> <ID>2332</ID> ... </SHOPITEM> <SHOPITEM> <ID>4433</ID> ... </SHOPITEM> </SH...
[ "See here for an explanation of how lxml.etree handles namespaces. In general, you should work with them rather than try to avoid them. In this case, write:\nfor item in file_data.iter('{http://www.w3.org/1999/xhtml}SHOPITEM'):\n\nIf you need to refer the namespace frequently, setup a local variable:\nxhtml_ns = '{...
[ 3 ]
[]
[]
[ "lxml", "parsing", "python", "xml", "xml_parsing" ]
stackoverflow_0003634420_lxml_parsing_python_xml_xml_parsing.txt
Q: how to render to response? I am sending list to a template using render_to_response. I am using django shortcuts. Hoe to do that? How to set context instance with a variable? A: Like any template value. def some_view(request): # ... my_data_dictionary = { 'somelist': my_list } return render_to_respon...
how to render to response?
I am sending list to a template using render_to_response. I am using django shortcuts. Hoe to do that? How to set context instance with a variable?
[ "Like any template value.\ndef some_view(request):\n # ...\n my_data_dictionary = { 'somelist': my_list }\n return render_to_response('my_template.html',\n my_data_dictionary,\n context_instance=RequestContext(request))\n\nBy the way, there's a nice...
[ 2, 2, 0 ]
[]
[]
[ "django", "python" ]
stackoverflow_0003635073_django_python.txt
Q: SQLAlchemy: writing to database after the response has been sent I have a simple service that does approximately the following: An HTTP client connects to the server The server writes the sessionID of the client and the timestamp to the database, and in most cases just returns an empty response (The cases when i...
SQLAlchemy: writing to database after the response has been sent
I have a simple service that does approximately the following: An HTTP client connects to the server The server writes the sessionID of the client and the timestamp to the database, and in most cases just returns an empty response (The cases when it does do real work and return actual data are irrelevant to this ques...
[ "You could use something like the Celery distributed task queue to offload processing to other machines. It does require setup of a separate infrastructure, but will allow for tasks to be handed off from web requests for processing in the background, while the HTTP repsonse to the request can be returned immediatel...
[ 2 ]
[]
[]
[ "data_storage", "memcached", "optimization", "python" ]
stackoverflow_0003631832_data_storage_memcached_optimization_python.txt
Q: to parse chat conversations stored in a file poem = '''\ me:hello dear me:hyyy asha:edaaaa ''' f=open('poem.txt','r') arr=[] arr1=[] varr=[] darr=[] i=0 j=1 for line in f.read().split('\n'): arr.append(line) i+=1 f.close() #print arr[0] #print arr[1] #print arr[2] text=arr[0].split(':') #print text line=...
to parse chat conversations stored in a file
poem = '''\ me:hello dear me:hyyy asha:edaaaa ''' f=open('poem.txt','r') arr=[] arr1=[] varr=[] darr=[] i=0 j=1 for line in f.read().split('\n'): arr.append(line) i+=1 f.close() #print arr[0] #print arr[1] #print arr[2] text=arr[0].split(':') #print text line=text[0] #print line arr1.append(text[1]) for i in...
[ "CRYSTAL BALL MODE ON\nfrom collections import defaultdict\nresult = defaultdict(list)\n\nwith open('chat.log') as f:\n for line in f:\n nick, msg = line.split(':', 1)\n result[nick].append(msg)\n\nprint result\n\n", "You are attempting to assign to varr[2], but varr is an empty list, so you woul...
[ 5, 0 ]
[]
[]
[ "python" ]
stackoverflow_0003635541_python.txt
Q: Automatic editor of XML (based on XSD scheme) Is there any approach to generate editor of an XML file basing on an XSD scheme? (It should be a Java or Python web based editor). A: ExxEditor is an XML editor based on XML Schema. This is a C++ project, and it's not web based at all. I never used it, but I think th...
Automatic editor of XML (based on XSD scheme)
Is there any approach to generate editor of an XML file basing on an XSD scheme? (It should be a Java or Python web based editor).
[ "ExxEditor is an XML editor based on XML Schema. This is a C++ project, and it's not web based at all.\nI never used it, but I think the XML Schema files can be annotated to \"customize\" the UI.\n", "Funny, I'm concerning myself with something similar. I'm building an editor (not really WYSIWYG, but it abstracts...
[ 2, 1, 1 ]
[]
[]
[ "java", "python", "xml", "xsd" ]
stackoverflow_0003599569_java_python_xml_xsd.txt
Q: Are there conventions for Python module comments? It is my understanding that a module docstring should just provide a general description of what a module does and details such as author and version should only be contained in the module's comments. However, I have seen the following in comments and docstrings: _...
Are there conventions for Python module comments?
It is my understanding that a module docstring should just provide a general description of what a module does and details such as author and version should only be contained in the module's comments. However, I have seen the following in comments and docstrings: __author__ = "..." __version__ = "..." __date__ = "..." ...
[ "They are merely conventions, albeit quite widely-used conventions. See this description of a set of Python metadata requirements.\n__version__ is mentioned in the Python Style Guide.\nRegarding docstrings, there's a PEP just for you!\n\nThe docstring for a module should\n generally list the classes, exceptions\n ...
[ 8, 5, 3 ]
[]
[]
[ "comments", "conventions", "module", "python" ]
stackoverflow_0003635988_comments_conventions_module_python.txt
Q: CookieJarLib wont save cookies back to File? I am working off of the example code given by Anthony Briggs. However it doesn't seem to save the cookies back into the defined cookie file. My modified code. I switched to using LWPCookieJar because its supposedly fully compatible and also removed the login code into a...
CookieJarLib wont save cookies back to File?
I am working off of the example code given by Anthony Briggs. However it doesn't seem to save the cookies back into the defined cookie file. My modified code. I switched to using LWPCookieJar because its supposedly fully compatible and also removed the login code into a separate function so that I can first test if I a...
[ "I just read on another forum that I needed to set ignore_discard=True in all the .save() and .load() methods. \n" ]
[ 2 ]
[]
[]
[ "cookies", "python", "urllib2" ]
stackoverflow_0003630307_cookies_python_urllib2.txt
Q: About IMAP UID with imaplib I try to move email from mailbox's gmail to another one, Just curious that UID of each email will change when move to new mailbox ? A: Yes of course the UID is changed when you do move operation. the new UID for that mail will be the next UID from the destination folder. (i.e if the l...
About IMAP UID with imaplib
I try to move email from mailbox's gmail to another one, Just curious that UID of each email will change when move to new mailbox ?
[ "Yes of course the UID is changed when you do move operation.\nthe new UID for that mail will be the next UID from the destination folder.\n(i.e if the last mail UID of the destination folder is : 9332 , \nthen the UID of the move email will be 9333) \nNote: UID is changed but the Message-Id will not be changed ...
[ 4, 1 ]
[]
[]
[ "imap", "imaplib", "python" ]
stackoverflow_0003615561_imap_imaplib_python.txt
Q: Any good books and/or tutorials on XML-based APIs, REST, SOAP with Python? What are some good books and/or tutorials on XML-based APIs, REST, SOAP with Python? A: Chapters 9, 11, 12 from Dive into Python by Mark Pilgrim deal with these topics. Though the book is outdated, you can give it a try if you are just st...
Any good books and/or tutorials on XML-based APIs, REST, SOAP with Python?
What are some good books and/or tutorials on XML-based APIs, REST, SOAP with Python?
[ "Chapters 9, 11, 12 from Dive into Python by Mark Pilgrim deal with these topics. Though the book is outdated, you can give it a try if you are just starting out. Some of the libraries used in the book haven't been updated in few years.\n" ]
[ 1 ]
[]
[]
[ "python", "rest", "soap", "web_services", "xml" ]
stackoverflow_0003635715_python_rest_soap_web_services_xml.txt
Q: How to install Python 3.1.2 on Mac OS X 10.6.4? Hi there I have downloaded the mac installer here, http://www.python.org/download/releases/3.1.2/ , & installed it. But when I run terminal & type python it says: Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29) [GCC 4.2.1 (Apple Inc. build 5646)] on darwin Type...
How to install Python 3.1.2 on Mac OS X 10.6.4?
Hi there I have downloaded the mac installer here, http://www.python.org/download/releases/3.1.2/ , & installed it. But when I run terminal & type python it says: Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29) [GCC 4.2.1 (Apple Inc. build 5646)] on darwin Type "help", "copyright", "credits" or "license" for more...
[ "Is there another python executable, perhaps python31?\nYou can also install other python versions via MacPorts if you need (although you'll still have to choose the right executable).\nThis should also be relevant: Multiple versions of Python on OS X Leopard\n" ]
[ 1 ]
[]
[]
[ "macos", "python", "python_3.x" ]
stackoverflow_0003636096_macos_python_python_3.x.txt
Q: Check for page loading (Python) In Python, is there any way that I can find out if a browser window that I've opened has loaded completely or not, maybe using a package (for instance, webbrowser)? Once it's loaded completely I want to take a screenshot of it and save it. A: You can do this using e.g. Selenium; I...
Check for page loading (Python)
In Python, is there any way that I can find out if a browser window that I've opened has loaded completely or not, maybe using a package (for instance, webbrowser)? Once it's loaded completely I want to take a screenshot of it and save it.
[ "You can do this using e.g. Selenium; I'm not sure if it's what you want, though. See this short guide.\n#!/usr/bin/env python\n\nfrom selenium import selenium\n\nsel = selenium('localhost', 4444, '*firefox', 'http://www.google.com/')\nsel.start()\nsel.open('/')\nsel.wait_for_page_to_load(10000)\nsel.stop()\n\nYou ...
[ 4, 0 ]
[]
[]
[ "browser", "python" ]
stackoverflow_0003636008_browser_python.txt
Q: Is this a problem with the Django tutorial or a package problem, or is it me? I'm using Ubuntu 10, python 2.6.5 I'm following this tutorial: http://www.djangobook.com/en/2.0/chapter02 I followed all of the steps using cut-and-paste. The following directory structure was automatically created: bill@ed-desktop:~/pro...
Is this a problem with the Django tutorial or a package problem, or is it me?
I'm using Ubuntu 10, python 2.6.5 I'm following this tutorial: http://www.djangobook.com/en/2.0/chapter02 I followed all of the steps using cut-and-paste. The following directory structure was automatically created: bill@ed-desktop:~/projects$ ls -l mysite total 36 -rw-r--r-- 1 bill bill 0 2010-09-01 08:18 __in...
[ "I'm not sure what your actual question is. \nYou've requested the root page, \\, but have only defined a URL for \\hello\\, so obviously Django can't find what you've requested. If you want your hello view to match against the site root, do this:\nurlpatterns = patterns('',\n (r'^$', hello),\n)\n\nI don't under...
[ 1, 1 ]
[]
[]
[ "django", "package", "python" ]
stackoverflow_0003636280_django_package_python.txt
Q: how to do a zoom in/out with wxpython how to do a zoom in/out with wxpython? what are the very basics for this purpose? I googled this, but could not find much, thanks!! A: Instead of zoom, perhaps 'scaling' is what you're looking for: http://www.wxpython.org/docs/api/wx.Size-class.html#Scale A: You should loo...
how to do a zoom in/out with wxpython
how to do a zoom in/out with wxpython? what are the very basics for this purpose? I googled this, but could not find much, thanks!!
[ "Instead of zoom, perhaps 'scaling' is what you're looking for:\nhttp://www.wxpython.org/docs/api/wx.Size-class.html#Scale\n", "You should look at FloatCanvas or FloatCanvas2. I know one of them has a zooming (and maybe panning) feature. You can get ideas about drawing rectangles from Whyteboard. Here's a few lin...
[ 2, 2 ]
[]
[]
[ "python", "user_interface", "wxpython", "zooming" ]
stackoverflow_0003631510_python_user_interface_wxpython_zooming.txt
Q: How to debug "glibc detected *** python: malloc(): memory corruption" I'm using python2.5 with scipy.weave to embed c code. In my c code, there is no malloc() function, but I received error like "glibc detected *** python: malloc(): memory corruption" from time to time.(It's a random algorithm) So how shall I deb...
How to debug "glibc detected *** python: malloc(): memory corruption"
I'm using python2.5 with scipy.weave to embed c code. In my c code, there is no malloc() function, but I received error like "glibc detected *** python: malloc(): memory corruption" from time to time.(It's a random algorithm) So how shall I debug it out? Thanks
[ "I'd hazard a guess that your code is overflowing an array somewhere (or causing Python to do so).\nYou're going to find debugging this to be hard if you can't reliably reproduce it, so you might want to explicitly seed your random number generator and try to find a seed with which you can reproduce the corruption....
[ 7 ]
[]
[]
[ "c", "glibc", "python" ]
stackoverflow_0003636393_c_glibc_python.txt
Q: Getting a listing of Trac projects in Python Is it possible to do something like using the trac module in Python in order to get a listing of all of the projects in a given directory? If possible it would be nice to get things like the description, too. I can't seem to figure out how to do it. Thanks for any help ...
Getting a listing of Trac projects in Python
Is it possible to do something like using the trac module in Python in order to get a listing of all of the projects in a given directory? If possible it would be nice to get things like the description, too. I can't seem to figure out how to do it. Thanks for any help you can provide.
[ "Using the TRAC_ENV_PARENT_DIR environment variable almost certainly does what you need: it will create an index page for you. See the part about \"use multiple projects\" here: http://trac.edgewall.org/wiki/TracCgi#Apacheweb-serverconfiguration\n", "You can script something like this:\nimport trac.admin.console...
[ 1, 1 ]
[]
[]
[ "project_management", "python", "trac" ]
stackoverflow_0003634183_project_management_python_trac.txt