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:
Creating modelformset from a modelform
I have a model MyModel which contains a PK - locid, that is an AutoField.
I want to construct a model formset from this, with some caveats:
The queryset for the formset should be a custom one (say, order_by('field')) rather than all()
Since locid for MyModel is an AutoField ... | Creating modelformset from a modelform | I have a model MyModel which contains a PK - locid, that is an AutoField.
I want to construct a model formset from this, with some caveats:
The queryset for the formset should be a custom one (say, order_by('field')) rather than all()
Since locid for MyModel is an AutoField and thus hidden by default, I want to be abl... | [
"It makes no sense to show an autofield to the user, as it's an autoincremented primary key -- the user can not change it and it will not be available before saving the record to the database (where the DBMS selectes the next available id).\nThis is how you set a custom queryset for a formset:\nfrom django.forms.mo... | [
2,
1,
0
] | [] | [] | [
"django",
"formset",
"modelform",
"python"
] | stackoverflow_0000896848_django_formset_modelform_python.txt |
Q:
mod_wsgi 2.5 on Ubuntu 9.04 with Python 2.6.2 installation
Has anybody succeeded with mod_wsgi 2.5 on Ubuntu 9.04 with default Python installation (2.6.2)?
I got compilation errors:
mod_wsgi.c:119:2: error: #error Sorry, mod_wsgi requires at least Python 2.3.0.
mod_wsgi.c:123:2: error: #error Sorry, mod_wsgi requi... | mod_wsgi 2.5 on Ubuntu 9.04 with Python 2.6.2 installation | Has anybody succeeded with mod_wsgi 2.5 on Ubuntu 9.04 with default Python installation (2.6.2)?
I got compilation errors:
mod_wsgi.c:119:2: error: #error Sorry, mod_wsgi requires at least Python 2.3.0.
mod_wsgi.c:123:2: error: #error Sorry, mod_wsgi requires that Python supporting thread.
which Python gives /usr/bin/... | [
"From your errors I see that you're having to compile python extensions. If you haven't already, I suggest you install the python-dev package because it's usually required for compiling python extensions and it's not part of the default installation.\nInstalling the package is as easy as running:\n\nsudo apt-get i... | [
5,
2
] | [] | [] | [
"compiler_construction",
"mod_wsgi",
"python",
"ubuntu",
"wsgi"
] | stackoverflow_0000913232_compiler_construction_mod_wsgi_python_ubuntu_wsgi.txt |
Q:
Is it possible to install python 3 and 2.6 on same PC?
How would I do this? The reason being I wanted to try some pygame out, but I have python 3 installed currently and have been learning with that. I'm also interested in trying out wxpython or something like that, but I haven't looked at their compatibilities ye... | Is it possible to install python 3 and 2.6 on same PC? | How would I do this? The reason being I wanted to try some pygame out, but I have python 3 installed currently and have been learning with that. I'm also interested in trying out wxpython or something like that, but I haven't looked at their compatibilities yet.
EDIT:: im on a windows vista 64-bit
| [
"If you are on Windows, then just install another version of Python using the installer. It would be installed into another directory.\nThen if you install other packages using the installer, it would ask you for which python installation to apply. If you use installation from source or easy_install, then just make... | [
9,
3,
3,
2,
1,
1,
0
] | [] | [] | [
"python",
"python_3.x"
] | stackoverflow_0000913204_python_python_3.x.txt |
Q:
Python3.0: tokenize & BytesIO
When attempting to tokenize a string in python3.0, why do I get a leading 'utf-8' before the tokens start?
From the python3 docs, tokenize should now be used as follows:
g = tokenize(BytesIO(s.encode('utf-8')).readline)
However, when attempting this at the terminal, the following hap... | Python3.0: tokenize & BytesIO | When attempting to tokenize a string in python3.0, why do I get a leading 'utf-8' before the tokens start?
From the python3 docs, tokenize should now be used as follows:
g = tokenize(BytesIO(s.encode('utf-8')).readline)
However, when attempting this at the terminal, the following happens:
>>> from tokenize import toke... | [
"That's the coding cookie of the source. You can specify one explicitly:\n# -*- coding: utf-8 -*-\ndo_it()\n\nOtherwise Python assumes the default encoding, utf-8 in Python 3.\n"
] | [
2
] | [] | [] | [
"bytesio",
"io",
"python",
"tokenize"
] | stackoverflow_0000913409_bytesio_io_python_tokenize.txt |
Q:
How do I pass lots of variables to and from a function in Python?
I do scientific programming, and often want to show users prompts and variable pairs, let them edit the variables, and then do the calulations with the new variables. I do this so often, that I wrote a wxPython class to move this code out of the ma... | How do I pass lots of variables to and from a function in Python? | I do scientific programming, and often want to show users prompts and variable pairs, let them edit the variables, and then do the calulations with the new variables. I do this so often, that I wrote a wxPython class to move this code out of the main program. You set up a list for each variable with the type of the v... | [
"The simplest thing to do would be to create a class. Instead of dealing with a list of variables, the class will have attributes. Then you just use a single instance of the class.\n",
"There are two decent options that come to mind.\nThe first is to use a dictionary to gather all the variables in one place:\nd... | [
16,
9,
3,
1,
0,
0
] | [] | [] | [
"pass_by_reference",
"pass_by_value",
"python"
] | stackoverflow_0000912526_pass_by_reference_pass_by_value_python.txt |
Q:
Decoding html encoded strings in python
I have the following string...
"Scam, hoax, or the real deal, he’s gonna work his way to the bottom of the sordid tale, and hopefully end up with an arcade game in the process."
I need to turn it into this string...
Scam, hoax, or the real deal,
he’s gonna work his... | Decoding html encoded strings in python | I have the following string...
"Scam, hoax, or the real deal, he’s gonna work his way to the bottom of the sordid tale, and hopefully end up with an arcade game in the process."
I need to turn it into this string...
Scam, hoax, or the real deal,
he’s gonna work his way to the
bottom of the sordid tale, and
... | [
"What's you're trying to do is called \"HTML entity decoding\" and it's covered in a number of past Stack Overflow questions, for example:\n\nHow to unescape apostrophes and such in Python?\nDecoding HTML Entities With Python\n\nHere's a code snippet using the Beautiful Soup HTML parsing library to decode your exam... | [
4
] | [] | [] | [
"html",
"python",
"xml"
] | stackoverflow_0000913933_html_python_xml.txt |
Q:
on my local Windows machine, how do i write a script to download a comic strip every day and email it to myself?
on my local Windows machine, how do i write a script to download a comic strip every day and email it to myself?
such as
http://comics.com/peanuts/
Update: i know how to download the image as a file. t... | on my local Windows machine, how do i write a script to download a comic strip every day and email it to myself? | on my local Windows machine, how do i write a script to download a comic strip every day and email it to myself?
such as
http://comics.com/peanuts/
Update: i know how to download the image as a file. the hard part is how to email it from my local Windows machine.
| [
"This depends how precise you want to be. Downloading the entire web page wouldn't be too challenging - using wget, as Earwicker mentions above.\nIf you want the actual image file of the comic downloaded, you would need a bit more in your arsenal. In Python - because that's what I know best - I would imagine you'd ... | [
8,
3,
2,
1,
1,
1
] | [] | [] | [
"php",
"python",
"ruby",
"scheduled_tasks"
] | stackoverflow_0000909618_php_python_ruby_scheduled_tasks.txt |
Q:
Using poll on file-like object returned by urllib2.urlopen()?
I've run into the bug described at http://bugs.python.org/issue1327971 while trying to poll a file-like object returned by urllib2.urlopen().
Unfortunately, being relatively new to Python, I can't actually determine from the responses how to get around... | Using poll on file-like object returned by urllib2.urlopen()? | I've run into the bug described at http://bugs.python.org/issue1327971 while trying to poll a file-like object returned by urllib2.urlopen().
Unfortunately, being relatively new to Python, I can't actually determine from the responses how to get around the issue as they seem mostly geared towards fixing the bug, rathe... | [
"If you don't want to modify you system libraries you also can patch httplib on the fly to match the patch in the bug report:\nimport httplib\n\n@property\ndef http_fileno(self):\n return self.fp.fileno\n\n@http_fileno.setter\ndef http_fileno(self, value):\n self.fp.fileno = value\n\nhttplib.HTTPResponse.fileno... | [
1,
0
] | [] | [] | [
"python",
"python_2.6"
] | stackoverflow_0000913913_python_python_2.6.txt |
Q:
Python script embedded in Windows Registry
We all know that windows has the feature that you can right click on a file and numerous options are shown. Well you can add a value to this menu. I followed this guide : jfitz.com/tips/rclick_custom.html
Basically I have a script that runs when I right click on a certain... | Python script embedded in Windows Registry | We all know that windows has the feature that you can right click on a file and numerous options are shown. Well you can add a value to this menu. I followed this guide : jfitz.com/tips/rclick_custom.html
Basically I have a script that runs when I right click on a certain file type.
Alright, so everything is going fla... | [
"yes, call pythonw.exe and pass the script path as a parameter\n\"C:\\Python26\\pythonw.exe\" \"C:\\Users\\daved\\Documents\\Python\\backup.py\" \"%1\"\n\nIt's also recommended (but not required) to use the extension .pyw when your script doesn't run in a console.\n"
] | [
1
] | [] | [] | [
"python",
"winapi"
] | stackoverflow_0000914106_python_winapi.txt |
Q:
Class attributes with a "calculated" name
When defining class attributes through "calculated" names, as in:
class C(object):
for name in (....):
exec("%s = ..." % (name,...))
is there a different way of handling the numerous attribute definitions than by using an exec? getattr(C, name) does not work ... | Class attributes with a "calculated" name | When defining class attributes through "calculated" names, as in:
class C(object):
for name in (....):
exec("%s = ..." % (name,...))
is there a different way of handling the numerous attribute definitions than by using an exec? getattr(C, name) does not work because C is not defined, during class construc... | [
"How about:\nclass C(object):\n blah blah\n\nfor name in (...):\n setattr(C, name, \"....\")\n\nThat is, do the attribute setting after the definition.\n",
"class C (object):\n pass\n\nc = C()\nc.__dict__['foo'] = 42\nc.foo # returns 42\n\n",
"If your entire class is \"calculated\", then may I suggest ... | [
11,
3,
2,
0
] | [] | [] | [
"class_attributes",
"exec",
"python"
] | stackoverflow_0000912412_class_attributes_exec_python.txt |
Q:
Python metaclasses
I've been hacking classes in Python like this:
def hack(f,aClass) :
class MyClass(aClass) :
def f(self) :
f()
return MyClass
A = hack(afunc,A)
Which looks pretty clean to me. It takes a class, A, creates a new class derived from it that has an extra method, calling f, and then ... | Python metaclasses | I've been hacking classes in Python like this:
def hack(f,aClass) :
class MyClass(aClass) :
def f(self) :
f()
return MyClass
A = hack(afunc,A)
Which looks pretty clean to me. It takes a class, A, creates a new class derived from it that has an extra method, calling f, and then reassigns the new class ... | [
"The definition of a class in Python is an instance of type (or an instance of a subclass of type). In other words, the class definition itself is an object. With metaclasses, you have the ability to control the type instance that becomes the class definition.\nWhen a metaclass is invoked, you have the ability to c... | [
5,
1,
1
] | [] | [] | [
"metaclass",
"python"
] | stackoverflow_0000618960_metaclass_python.txt |
Q:
How to save indention format of file in Python
I am saving all the words from a file like so:
sentence = " "
fileName = sys.argv[1]
fileIn = open(sys.argv[1],"r")
for line in open(sys.argv[1]):
for word in line.split(" "):
sentence += word
Everything works okay when outputting it exce... | How to save indention format of file in Python | I am saving all the words from a file like so:
sentence = " "
fileName = sys.argv[1]
fileIn = open(sys.argv[1],"r")
for line in open(sys.argv[1]):
for word in line.split(" "):
sentence += word
Everything works okay when outputting it except the formatting.
I am moving source code, is there... | [
"Since you state, that you want to move source code files, why not just copy/move them?\nimport shutil\nshutil.move(src, dest)\n\nIf you read source file, \nfh = open(\"yourfilename\", \"r\")\ncontent = fh.read()\n\nshould load your file as it is (with indention), or not? \n",
"When you invoke line.split(), you r... | [
3,
2,
1
] | [] | [] | [
"python"
] | stackoverflow_0000914626_python.txt |
Q:
best practice for user preferences in $HOME in Python
For some small programs in Python, I would like to set, store and retrieve user preferences in a file in a portable (multi-platform) way.
I am thinking about a very simple ConfigParser file like "~/.program" or "~/.program/program.cfg".
Is os.path.expanduser() ... | best practice for user preferences in $HOME in Python | For some small programs in Python, I would like to set, store and retrieve user preferences in a file in a portable (multi-platform) way.
I am thinking about a very simple ConfigParser file like "~/.program" or "~/.program/program.cfg".
Is os.path.expanduser() the best way for achieving this or is there something more ... | [
"os.path.expanduser(\"~\")\n\nis more portable than \nos.environ['HOME']\n\nso it should be ok to use the first.\n",
"You can use os.environ:\nimport os\nprint os.environ[\"HOME\"]\n\n"
] | [
8,
0
] | [] | [] | [
"preferences",
"python"
] | stackoverflow_0000914675_preferences_python.txt |
Q:
Does PyS60 has a reliable garbage collection?
I have heard it many times that garbage collection in PyS60 is not up to to the mark. This imposes a lot of limits on writing cleaner code. Can I at least rely that the non cyclic references are cleaned up after a function exists.
A:
PyS60 as of version 1.9.0 uses Py... | Does PyS60 has a reliable garbage collection? | I have heard it many times that garbage collection in PyS60 is not up to to the mark. This imposes a lot of limits on writing cleaner code. Can I at least rely that the non cyclic references are cleaned up after a function exists.
| [
"PyS60 as of version 1.9.0 uses Python 2.5.1 core and has no problems with garbage collection.\n",
"Mostly you can, but occasionally PyS60 needs a little \"help\". Unbind keys, always cancel timers, might have to manually delete some classes etc. Nothing too bad.\nBtw current 1.9.x branch uses python core 2.5.4. ... | [
3,
0
] | [] | [] | [
"nokia",
"pys60",
"python",
"s60",
"symbian"
] | stackoverflow_0000595290_nokia_pys60_python_s60_symbian.txt |
Q:
Does the stack limit of Symbian also apply to PyS60?
Symbian has a stack limit of 8kB. Does this also apply to the function calling in PyS60 apps?
A:
Yes, PyS60 is based on CPython, thus uses the C stack.
A:
Increasing the Symbian stack size is done through a parameter in the mmp file.
This is valid when you c... | Does the stack limit of Symbian also apply to PyS60? | Symbian has a stack limit of 8kB. Does this also apply to the function calling in PyS60 apps?
| [
"Yes, PyS60 is based on CPython, thus uses the C stack.\n",
"Increasing the Symbian stack size is done through a parameter in the mmp file.\nThis is valid when you create a native application that the toolchain will turn into an exe file.\nIf you were to upgrade the Python runtime on your phone, with a version yo... | [
3,
1,
1,
0
] | [] | [] | [
"nokia",
"pys60",
"python",
"symbian"
] | stackoverflow_0000595296_nokia_pys60_python_symbian.txt |
Q:
About the optional argument in Canvas in PyS60
In Python for Symbian60 blit() is defined as:
blit(image [,target=(0,0), source=((0,0),image.size), mask=None, scale=0 ])
In the optional parameter source what is the significance of image.size?
A:
My guess is that blit() will automatically use the result of image.s... | About the optional argument in Canvas in PyS60 | In Python for Symbian60 blit() is defined as:
blit(image [,target=(0,0), source=((0,0),image.size), mask=None, scale=0 ])
In the optional parameter source what is the significance of image.size?
| [
"My guess is that blit() will automatically use the result of image.size when you don't specify anything else (and thus blitting the whole image from (0,0) to (width,height)).\nIf you want only a smaller part of the image copied, you can use the source parameter to define a different rectangle to copy.\n",
"Think... | [
0,
0
] | [] | [] | [
"nokia",
"pys60",
"python"
] | stackoverflow_0000585957_nokia_pys60_python.txt |
Q:
Migrating from python 2.4 to python 2.6
I'm migrating a legacy codebase at work from python 2.4 to python 2.6. This is being done as part of a push to remove the 'legacy' tag and make a maintainable, extensible foundation for active development, so I'm getting a chance to "do things right", including refactoring t... | Migrating from python 2.4 to python 2.6 | I'm migrating a legacy codebase at work from python 2.4 to python 2.6. This is being done as part of a push to remove the 'legacy' tag and make a maintainable, extensible foundation for active development, so I'm getting a chance to "do things right", including refactoring to use new 2.6 features if that leads to clean... | [
"Read the Python 3.0 changes. The point of 2.6 is to aim for 3.0.\nFrom 2.4 to 2.6 you gained a lot of things. These are the the most important. I'm making this answer community wiki so other folks can edit it.\n\nGenerator functions and the yield statement.\nMore consistent use of various types like list and dic... | [
5,
2
] | [] | [] | [
"python"
] | stackoverflow_0000915135_python.txt |
Q:
Clashing guidelines
While coding in Python it's better to code by following the guidelines of PEP8.
And while coding for Symbian it's better to follow its coding standards.
But when I code for PyS60 which guidelines should I follow? Till now I have been following PEP8, but this code shows the opposite. Do I need t... | Clashing guidelines | While coding in Python it's better to code by following the guidelines of PEP8.
And while coding for Symbian it's better to follow its coding standards.
But when I code for PyS60 which guidelines should I follow? Till now I have been following PEP8, but this code shows the opposite. Do I need to rework my code?
| [
"\"Do I need to rework my code?\"\nDoes it add value to rework you code?\nHow many folks will help you develop code who \nA) don't know PEP 8\nB) only know PyS60 coding standards because that's the only code they've ever seen.\nand\nC) cannot be taught anything different than the PyS60 coding standards?\nList all t... | [
2,
2,
1,
0,
0
] | [] | [] | [
"coding_style",
"pep8",
"pys60",
"python",
"symbian"
] | stackoverflow_0000648299_coding_style_pep8_pys60_python_symbian.txt |
Q:
How to convert specific character sequences in a string to upper case using Python?
I am looking to accomplish the following and am wondering if anyone has a suggestion as to how best go about it.
I have a string, say 'this-is,-toronto.-and-this-is,-boston', and I would like to convert all occurrences of ',-[a-z]'... | How to convert specific character sequences in a string to upper case using Python? | I am looking to accomplish the following and am wondering if anyone has a suggestion as to how best go about it.
I have a string, say 'this-is,-toronto.-and-this-is,-boston', and I would like to convert all occurrences of ',-[a-z]' to ',-[A-Z]'. In this case the result of the conversion would be 'this-is,-Toronto.-and... | [
"re.sub can take a function which returns the replacement string:\nimport re\n\ns = 'this-is,-toronto.-and-this-is,-boston'\nt = re.sub(',-[a-z]', lambda x: x.group(0).upper(), s)\nprint t\n\nprints\nthis-is,-Toronto.-and-this-is,-Boston\n\n"
] | [
11
] | [] | [] | [
"python"
] | stackoverflow_0000915391_python.txt |
Q:
Regular Expression for Stripping Strings from Source Code
I'm looking for a regular expression that will replace strings in an input source code with some constant string value such as "string", and that will also take into account escaping the string-start character that is denoted by a double string-start charac... | Regular Expression for Stripping Strings from Source Code | I'm looking for a regular expression that will replace strings in an input source code with some constant string value such as "string", and that will also take into account escaping the string-start character that is denoted by a double string-start character (e.g. "he said ""hello""").
To clarify, I will provide som... | [
"If you're parsing Python code, save yourself the hassle and let the standard library's parser module do the heavy lifting.\nIf you're writing your own parser for some custom language, it's awfully tempting to start out by just hacking together a bunch of regexes, but don't do it. You'll dig yourself into an unmai... | [
3,
0,
0
] | [] | [] | [
"python",
"regex",
"string"
] | stackoverflow_0000914913_python_regex_string.txt |
Q:
Project Euler Problem 245
I'm onto problem 245 now but have hit some problems. I've done some work on it already but don't feel I've made any real steps towards solving it. Here's what I've got so far:
We need to find n=ab with a and b positive integers. We can also assume gcd(a, b) = 1 without loss of generality ... | Project Euler Problem 245 | I'm onto problem 245 now but have hit some problems. I've done some work on it already but don't feel I've made any real steps towards solving it. Here's what I've got so far:
We need to find n=ab with a and b positive integers. We can also assume gcd(a, b) = 1 without loss of generality and thus phi(n) = phi(ab) = phi... | [
"Project Euler isn't fond of discussing problems on public forums like StackOverflow. All tasks are made to be done solo, if you encounter problems you may ask help for a specific mathematical or programming concept, but you can't just decide to ask how to solve the problem at hand - takes away the point of project... | [
9,
4,
3,
1,
1,
0
] | [] | [] | [
"algorithm",
"math",
"python"
] | stackoverflow_0000875027_algorithm_math_python.txt |
Q:
Python Best Practices: Abstract Syntax Trees
Modifying Abstract Syntax Trees
I would like to be able to build and modify an ast and then optionally write it out as python byte code for execution later without overhead.
I have been hacking around with the ast docs for python3.0 and python2.6, but I can't seem to fi... | Python Best Practices: Abstract Syntax Trees | Modifying Abstract Syntax Trees
I would like to be able to build and modify an ast and then optionally write it out as python byte code for execution later without overhead.
I have been hacking around with the ast docs for python3.0 and python2.6, but I can't seem to find any good sources on best practices for this typ... | [
"Other than the manual and the source code, you are on your own. This subject and python bytecode are very undocumented.\nAlternatively you could try using this python bytecode library which I have heard good thing about but haven't tried it yet:\nhttp://code.google.com/p/byteplay/\n",
"I think geniusql is doing ... | [
6,
2
] | [] | [] | [
"abstract_syntax_tree",
"python"
] | stackoverflow_0000911930_abstract_syntax_tree_python.txt |
Q:
How to debug PYGTK program
When python raise an exception in the middle of a pygtk signal handling callback, the exception is catched by the gtk main loop, its value printed and the main loop just continue, ignoring it.
If you want to debug, with something like pdb (python -m pdb myscript.py), you want that when t... | How to debug PYGTK program | When python raise an exception in the middle of a pygtk signal handling callback, the exception is catched by the gtk main loop, its value printed and the main loop just continue, ignoring it.
If you want to debug, with something like pdb (python -m pdb myscript.py), you want that when the exception occure PDB jump on ... | [
"You can't make pdb jump to the exception, since the exception is caught and silenced by gtk's main loop.\nOne of the alternatives is using pdb.set_trace():\nimport pdb\npdb.set_trace()\n\nSee pdb documentation.\nAlternatively you can just use Winpdb:\nIt is a platform independent graphical GPL Python debugger with... | [
5
] | [] | [] | [
"debugging",
"gtk",
"pygtk",
"python"
] | stackoverflow_0000916674_debugging_gtk_pygtk_python.txt |
Q:
Set up svnperms pre-commit hook
I'm trying to implement svnperms into a repository, but am having difficulty with a few things:
pre-commit has the execute permissions:
-rwxrwxr-x 1 svnadm svn 3018 May 27 10:11 pre-commit
This is my call to svnperms within pre-commit:
# Check that the author of thi... | Set up svnperms pre-commit hook | I'm trying to implement svnperms into a repository, but am having difficulty with a few things:
pre-commit has the execute permissions:
-rwxrwxr-x 1 svnadm svn 3018 May 27 10:11 pre-commit
This is my call to svnperms within pre-commit:
# Check that the author of this commit has the rights to perform
# ... | [
"My guess is that the location of the python binary is not in $PATH for the svn server. The shabang line of svnperms.py reads:\n#!/usr/bin/env python\n\nBut that assumes that the executable lies in the $PATH of the caller. If you don't have permissions to modify the runtime environment of your subversion server, t... | [
6
] | [] | [] | [
"pre_commit",
"python",
"svn",
"unix"
] | stackoverflow_0000916758_pre_commit_python_svn_unix.txt |
Q:
Is there a list of Python packages that are not 64 bit compatible somewhere?
I am going to move to a 64 bit machine and a 64 bit OS (Windows) and am trying to figure out if any of the extensions/packages I am using are going to be lost when I make the move. I can't seem to find whether someone has built a list of... | Is there a list of Python packages that are not 64 bit compatible somewhere? | I am going to move to a 64 bit machine and a 64 bit OS (Windows) and am trying to figure out if any of the extensions/packages I am using are going to be lost when I make the move. I can't seem to find whether someone has built a list of known issues as flagged on the Python 2.5 release page. I have been using 2.5 b... | [
"We're running 2.5 on a 64-bit Red Hat Enterprise Linux server.\nEverything appears to be working.\nI would suggest you do what we did. \n\nGet a VM.\nLoad up the app.\nTest it.\n\nIt was easier than trying to do research.\n",
"Perhaps you should figure out what \"make a meaningful move up the memory ladder\" me... | [
4,
3,
1,
1
] | [] | [] | [
"64_bit",
"package",
"python"
] | stackoverflow_0000916952_64_bit_package_python.txt |
Q:
How does Python OOP compare to PHP OOP?
I'm basically wondering if Python has any OOP shortcomings like PHP does. PHP has been developing their OOP practices for the last few versions. It's getting better in PHP but it's still not perfect. I'm new to Python and I'm just wondering if Python's OOP support is better... | How does Python OOP compare to PHP OOP? | I'm basically wondering if Python has any OOP shortcomings like PHP does. PHP has been developing their OOP practices for the last few versions. It's getting better in PHP but it's still not perfect. I'm new to Python and I'm just wondering if Python's OOP support is better or just comparable.
If there are some issue... | [
"I would say that Python's OOP support is much better given the fact that it was introduced into the language in its infancy as opposed to PHP which bolted OOP onto an existing procedural model.\n",
"Python's OOP support is very strong; it does allow multiple inheritance, and everything is manipulable as a first-... | [
20,
8,
8,
3,
3,
1
] | [] | [] | [
"comparison",
"oop",
"php",
"python"
] | stackoverflow_0000916962_comparison_oop_php_python.txt |
Q:
Does Ruby have an equivalent of Python's twisted framework as a networking abstraction layer?
From my understanding, Python's twisted framework provides a higher-level abstraction for networking communications (?).
I am looking for a Ruby equivalent of twisted to use in a Rails application.
A:
Take a look at Ev... | Does Ruby have an equivalent of Python's twisted framework as a networking abstraction layer? | From my understanding, Python's twisted framework provides a higher-level abstraction for networking communications (?).
I am looking for a Ruby equivalent of twisted to use in a Rails application.
| [
"Take a look at EventMachine. It's not as extensive as Twisted but it's built around the same concepts of event-driven network programming.\n"
] | [
7
] | [] | [] | [
"python",
"ruby",
"ruby_on_rails",
"twisted"
] | stackoverflow_0000917369_python_ruby_ruby_on_rails_twisted.txt |
Q:
Sorting a tuple that contains lists
I have a similar question to this one but instead my tuple contains lists, as follows:
mytuple = (
["tomato", 3],
["say", 2],
["say", 5],
["I", 4],
["you", 1],
["tomato", 6],
)
What's the most efficient way of sorting this?
A:
You can get a sorted tuple easy enough:
>>>... | Sorting a tuple that contains lists | I have a similar question to this one but instead my tuple contains lists, as follows:
mytuple = (
["tomato", 3],
["say", 2],
["say", 5],
["I", 4],
["you", 1],
["tomato", 6],
)
What's the most efficient way of sorting this?
| [
"You can get a sorted tuple easy enough:\n>>> sorted(mytuple)\n[['I', 4], ['say', 2], ['say', 5], ['tomato', 3], ['tomato', 6], ['you', 1]]\n\nThis will sort based on the items in the list. If the first two match, it compares the second, etc.\nIf you have a different criteria, you can provide a comparison function.... | [
7,
5,
1,
1
] | [] | [] | [
"list",
"python",
"sorting",
"tuples"
] | stackoverflow_0000917202_list_python_sorting_tuples.txt |
Q:
How can I handle a mouseMiddleDrag event in PythonCard?
I would like to use the middle mouse button to drag an image in an application written in Python and using PythonCard/wxPython for the GUI.
The latest version of PythonCard only implements a "left mouse button drag" event and I am trying to modify PythonCard ... | How can I handle a mouseMiddleDrag event in PythonCard? | I would like to use the middle mouse button to drag an image in an application written in Python and using PythonCard/wxPython for the GUI.
The latest version of PythonCard only implements a "left mouse button drag" event and I am trying to modify PythonCard to handle a "middle mouse button drag" as well.
Here is the r... | [
"It turns out the the mouseDrag event is active regardless of which button on the mouse is pressed. To filter the middle mouse button, you need to call the MiddleIsDown() method from the MouseEvent.\ndef on_mouseDrag( self, event ): \n do_stuff()\n\n if event.MiddleIsDown():\n do_other_stuff()\n\... | [
1
] | [] | [] | [
"mouse",
"python",
"pythoncard",
"user_interface",
"wxpython"
] | stackoverflow_0000916435_mouse_python_pythoncard_user_interface_wxpython.txt |
Q:
Reinstall /Library/Python on OS X Leopard
I accidentally removed /Library/Python on OS X Leopard. How can I reinstall that?
A:
If you'd like, I'll create a tarball from a pristine installation. I'm using MacOSX 10.5.7, and only 12K.
A:
I'm using 10.4, but unless the installation changed dramatically in 10.5, ... | Reinstall /Library/Python on OS X Leopard | I accidentally removed /Library/Python on OS X Leopard. How can I reinstall that?
| [
"If you'd like, I'll create a tarball from a pristine installation. I'm using MacOSX 10.5.7, and only 12K.\n",
"I'm using 10.4, but unless the installation changed dramatically in 10.5, /Library/Python is just a place to install local (user-installed) packages; the actual Python install is under /System. On 10.4... | [
1,
1,
1
] | [] | [] | [
"macos",
"osx_leopard",
"python",
"reinstall"
] | stackoverflow_0000917876_macos_osx_leopard_python_reinstall.txt |
Q:
When Should I Start Thinking About Moving to Python 3?
Possible Duplicate:
Why won't you switch to Python 3.x?
I see there are already a lot of duplicate questions asking whether or not new Python programmers should learn 2 or 3. I am not asking that question.
I am already a Python 2 programmer. I started tinke... | When Should I Start Thinking About Moving to Python 3? |
Possible Duplicate:
Why won't you switch to Python 3.x?
I see there are already a lot of duplicate questions asking whether or not new Python programmers should learn 2 or 3. I am not asking that question.
I am already a Python 2 programmer. I started tinkering with it some years ago. I started using it almost excl... | [
"The best answer I can give you is change when you need to. If you have no need for Python 3, then don't switch. If you aren't sure if you need to switch, chances are that you don't.\nThat said, once Python 3 becomes the more widely used version (in a few years, not anytime soon), you'll probably want to switch jus... | [
3,
0
] | [] | [] | [
"python",
"python_3.x"
] | stackoverflow_0000917987_python_python_3.x.txt |
Q:
Is there a way in Python to index a list of containers (tuples, lists, dictionaries) by an element of a container?
I have been poking around for a recipe / example to index a list of tuples without taking a modification of the decorate, sort, undecorate approach.
For example:
l=[(a,b,c),(x,c,b),(z,c,b),(z,c,d),(... | Is there a way in Python to index a list of containers (tuples, lists, dictionaries) by an element of a container? | I have been poking around for a recipe / example to index a list of tuples without taking a modification of the decorate, sort, undecorate approach.
For example:
l=[(a,b,c),(x,c,b),(z,c,b),(z,c,d),(a,d,d),(x,d,c) . . .]
The approach I have been using is to build a dictionary using defaultdict of the second element
f... | [
"This will generate the result you want\ndict((myTuple[1], index) for index, myTuple in enumerate(l))\n\n>>> l = [(1, 2, 3), (4, 5, 6), (1, 4, 6)]\n>>> dict((myTuple[1], index) for index, myTuple in enumerate(l))\n{2: 0, 4: 2, 5: 1}\n\nAnd if you insist on using a dictionary to represent the index:\ndict((myTuple[1... | [
5,
0
] | [] | [] | [
"containers",
"indexing",
"list",
"python"
] | stackoverflow_0000918076_containers_indexing_list_python.txt |
Q:
Python: Getting an IPv6 socket to receive packets destined for the Subnet-Routers Anycast address
How do you get a socket to receive packets destined for the IPv6 Subnet-Routers Anycast address?
I haven't been able to find any informationn on how to do this.
In a fit of desparation, I've tried using socket.setsock... | Python: Getting an IPv6 socket to receive packets destined for the Subnet-Routers Anycast address | How do you get a socket to receive packets destined for the IPv6 Subnet-Routers Anycast address?
I haven't been able to find any informationn on how to do this.
In a fit of desparation, I've tried using socket.setsockopt as you would to join a multicast group:
# 7 is the interface number
s = socket(AF_INET6, SOCK_DGRA... | [
"Instead of IPV6_JOIN_GROUP, try passing IPV6_JOIN_ANYCAST to your s.setsockopt() code. Unfortunately the Python socket module doesn't define it but you should be able to pass the integer equivalent instead. In Linux IPV6_JOIN_ANYCAST is 27 and IPV6_LEAVE_ANYCAST is 28. (defined in /usr/include/linux/in6.h)\nThe be... | [
2,
0
] | [] | [] | [
"ipv6",
"networking",
"python"
] | stackoverflow_0000597225_ipv6_networking_python.txt |
Q:
Are asynchronous Django model queries possible?
I'm new to Django, but the application that I have in mind might end up having URLs that look like this:
http://mysite/compare/id_1/id_2
Where "id_1" and "id_2" are identifiers of two distinct Model objects. In the handler for "compare" I'd like to asynchronously, ... | Are asynchronous Django model queries possible? | I'm new to Django, but the application that I have in mind might end up having URLs that look like this:
http://mysite/compare/id_1/id_2
Where "id_1" and "id_2" are identifiers of two distinct Model objects. In the handler for "compare" I'd like to asynchronously, and in parallel, query and retrieve objects id_1 and ... | [
"There aren't strictly asynchronous operations as you've described, but I think you can achieve the same effect by using django's in_bulk query operator, which takes a list of ids to query.\nSomething like this for the urls.py:\nurlpatterns = patterns('',\n (r'^compare/(\\d+)/(\\d+)/$', 'my.compareview'),\n)\n\n... | [
11
] | [] | [] | [
"django",
"django_models",
"multithreading",
"mysql",
"python"
] | stackoverflow_0000918298_django_django_models_multithreading_mysql_python.txt |
Q:
Using mocking to test derived classes in Python
I have code that looks like this:
import xmlrpclib
class Base(object):
def __init__(self, server):
self.conn = xmlrpclib.ServerProxy(server)
def foo(self):
return self.conn.do_something()
class Derived(Base):
def foo(self):
if B... | Using mocking to test derived classes in Python | I have code that looks like this:
import xmlrpclib
class Base(object):
def __init__(self, server):
self.conn = xmlrpclib.ServerProxy(server)
def foo(self):
return self.conn.do_something()
class Derived(Base):
def foo(self):
if Base.foo():
return self.conn.do_something_... | [
"You could create a fake ServerProxy class, and substitute that for testing.\nSomething like this:\nclass FakeServerProxy(object):\n def __init__(self, server):\n self.server = server\n def do_something(self):\n pass\n def do_something_else(self):\n pass\n\ndef test_derived():\n xml... | [
4,
3
] | [] | [] | [
"mocking",
"python"
] | stackoverflow_0000412472_mocking_python.txt |
Q:
Appengine - Possible to get an entity using only key string without model name?
I want to be able to have a view that will act upon a number of different types of objects
all the view will get is the key string eg:
agpwb2xsdGhyZWFkchULEg9wb2xsY29yZV9hbnN3ZXIYAww
without knowing the model type, is it possible to re... | Appengine - Possible to get an entity using only key string without model name? | I want to be able to have a view that will act upon a number of different types of objects
all the view will get is the key string eg:
agpwb2xsdGhyZWFkchULEg9wb2xsY29yZV9hbnN3ZXIYAww
without knowing the model type, is it possible to retrieve the entity from just that key string?
thanks
| [
"No superclassing required, just use db.get():\nfrom google.appengine.ext import db\nkey_str = 'agpwb2xsdGhyZWFkchULEg9wb2xsY29yZV9hbnN3ZXIYAww'\nentity = db.get(key_str)\n\n",
"If you design your models so they all use a common superclass it should be possible to retrieve your objects by using something like:\ne... | [
11,
1
] | [] | [] | [
"google_app_engine",
"python"
] | stackoverflow_0000776324_google_app_engine_python.txt |
Q:
How do I make a command line text editor?
I have gotten to know my way around a few programming languages, and I'd like to try my hand at making a command-line text editor -- something that runs in the terminal, like vim/emacs/nano, but is pure text (no guis, please). Preferably, I'd like to do this in python. Whe... | How do I make a command line text editor? | I have gotten to know my way around a few programming languages, and I'd like to try my hand at making a command-line text editor -- something that runs in the terminal, like vim/emacs/nano, but is pure text (no guis, please). Preferably, I'd like to do this in python. Where do I start? Are there any (python) libraries... | [
"try python curses module , it is a command-line graphic operation library.\n",
"Take a look at Curses Programming in Python and this as well. \n",
"Another option if you want to write a TUI (Text User Interface) without having to descend to curses is Snack, which comes with Newt.\n",
"Kids today! Sheesh! W... | [
25,
10,
8,
7,
5,
3,
2,
2,
2,
0
] | [] | [] | [
"python",
"text_editor",
"tui"
] | stackoverflow_0000688302_python_text_editor_tui.txt |
Q:
Is something like ConfigParser appropriate for saving state (key, value) between runs?
I want to save a set of key, value pairs (string, int) between runs of a Python program, reload them on subsequent runs and write the changes to be available on the next run.
I don't think of this data as a configuration file, b... | Is something like ConfigParser appropriate for saving state (key, value) between runs? | I want to save a set of key, value pairs (string, int) between runs of a Python program, reload them on subsequent runs and write the changes to be available on the next run.
I don't think of this data as a configuration file, but it would fit the ConfigParser capabilities quite well. I would only need two [sections]. ... | [
"Well, you have better options. You can for example use pickle or json format.\nPickle serializing module is very easy to use.\nimport cPickle\ncPickle.dump(obj, open('save.p', 'wb')) \nobj = cPickle.load(open('save.p', 'rb'))\n\nThe format is not human readable and unpickling is not secure against erroneous or mal... | [
16,
8,
2,
2,
0,
0
] | [] | [] | [
"configparser",
"perl",
"python",
"xml"
] | stackoverflow_0000916779_configparser_perl_python_xml.txt |
Q:
Resize ctypes array
I'd like to resize a ctypes array. As you can see, ctypes.resize doesn't work like it could. I can write a function to resize an array, but I wanted to know some other solutions to this. Maybe I'm missing some ctypes trick or maybe I simply used resize wrong. The name c_long_Array_0 seems to te... | Resize ctypes array | I'd like to resize a ctypes array. As you can see, ctypes.resize doesn't work like it could. I can write a function to resize an array, but I wanted to know some other solutions to this. Maybe I'm missing some ctypes trick or maybe I simply used resize wrong. The name c_long_Array_0 seems to tell me this may not work w... | [
"from ctypes import *\n\nlist = (c_int*1)()\n\ndef customresize(array, new_size):\n resize(array, sizeof(array._type_)*new_size)\n return (array._type_*new_size).from_address(addressof(array))\n\nlist[0] = 123\nlist = customresize(list, 5)\n\n>>> list[0]\n123\n>>> list[4]\n0\n\n"
] | [
10
] | [] | [] | [
"ctypes",
"python"
] | stackoverflow_0000919369_ctypes_python.txt |
Q:
What is a cyclic data structure good for?
I was just reading through "Learning Python" by Mark Lutz and came across this code sample:
>>> L = ['grail']
>>> L.append(L)
>>> L
['grail', [...]]
It was identified as a cyclic data structure.
So I was wondering, and here is my question:
What is a 'cyclic data structur... | What is a cyclic data structure good for? | I was just reading through "Learning Python" by Mark Lutz and came across this code sample:
>>> L = ['grail']
>>> L.append(L)
>>> L
['grail', [...]]
It was identified as a cyclic data structure.
So I was wondering, and here is my question:
What is a 'cyclic data structure' used for in real life programming?
There se... | [
"Lots of things. Circular buffer, for example: you have some collection of data with a front and a back, but an arbitrary number of nodes, and the \"next\" item from the last should take you back to the first.\nGraph structures are often cyclic; acyclicity is a special case. Consider, for example, a graph contai... | [
18,
6,
1,
1,
1,
1,
0,
0,
0,
0,
0,
0
] | [] | [] | [
"cyclic_reference",
"data_structures",
"python",
"recursion"
] | stackoverflow_0000405540_cyclic_reference_data_structures_python_recursion.txt |
Q:
python monitoring over serial port
Good afternoon,
I would ask some suggestion about the best way to monitor events over the serial port.
I'm using PySerial to write "commands" over the serial port towards some devices and
I would like to receive feedback about the status of this devices.
Wich is the best way: 1) ... | python monitoring over serial port | Good afternoon,
I would ask some suggestion about the best way to monitor events over the serial port.
I'm using PySerial to write "commands" over the serial port towards some devices and
I would like to receive feedback about the status of this devices.
Wich is the best way: 1) fullfill a pipe and read into, 2) a new ... | [
"For general tips on working with pyserial, look at the search S.Lott suggested in the comment.\nRegarding the best strategy to implement your application - it all depends on how your protocols are defined. Do the devices immediately respond to queries? Or do they continually send data that must be monitored? This ... | [
3,
1
] | [] | [] | [
"pyserial",
"python"
] | stackoverflow_0000911089_pyserial_python.txt |
Q:
Stuck on official Django Tutorial
I am just started out learning Python and also started looking into Django a little bit. So I copied this piece of code from the tutorial:
# Create your models here.
class Poll(models.Model):
question = models.CharField(max_length=200)
pub_date = models.DateTimeField('... | Stuck on official Django Tutorial | I am just started out learning Python and also started looking into Django a little bit. So I copied this piece of code from the tutorial:
# Create your models here.
class Poll(models.Model):
question = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
def __unicode__(se... | [
"You have three underscores before \"unicode__\" on the Choice class, it should be only two like in your Poll class, like this:\ndef __unicode__(self):\n return u'%s' % self.choice\n\n",
"Your Unicode method has too many underscores. It should read:\ndef __unicode__(self):\n return u'%s' % self.choice\n\n",... | [
7,
4,
3,
2
] | [] | [] | [
"django",
"python"
] | stackoverflow_0000919927_django_python.txt |
Q:
In python, how can you unload generated classes
I am working on a library that loads files (hfd5 - pytables) into an object structure. The actual classes being used for the structure is loaded as a string from the hdf5 file, and then
loaded in this fashion:
class NamespaceHolder(dict):
# stmt is the source cod... | In python, how can you unload generated classes | I am working on a library that loads files (hfd5 - pytables) into an object structure. The actual classes being used for the structure is loaded as a string from the hdf5 file, and then
loaded in this fashion:
class NamespaceHolder(dict):
# stmt is the source code holding all the class defs
def execute(self, st... | [
"I think the GC can cope with circular references, however you'll need to do is remove the reference from the globals() dict:\ntry:\n del globals()['DummyA']\nexcept KeyError:\n pass\n\notherwise there will be a non-circular reference to the class object that will stop it being cleaned up.\n",
"The gc.set_d... | [
1,
1
] | [] | [] | [
"classloader",
"dynamic",
"garbage_collection",
"python"
] | stackoverflow_0000919924_classloader_dynamic_garbage_collection_python.txt |
Q:
I need a sample of python unit testing sqlalchemy model with nose
Can someone show me how to write unit tests for sqlalchemy model I created using nose.
I just need one simple example.
Thanks.
A:
You can simply create an in-memory SQLite database and bind your session to that.
Example:
from db import session # ... | I need a sample of python unit testing sqlalchemy model with nose | Can someone show me how to write unit tests for sqlalchemy model I created using nose.
I just need one simple example.
Thanks.
| [
"You can simply create an in-memory SQLite database and bind your session to that.\nExample:\n\nfrom db import session # probably a contextbound sessionmaker\nfrom db import model\n\nfrom sqlalchemy import create_engine\n\ndef setup():\n engine = create_engine('sqlite:///:memory:')\n session.configure(bind=en... | [
38,
2
] | [] | [] | [
"nose",
"python",
"sqlalchemy",
"testing",
"unit_testing"
] | stackoverflow_0000833626_nose_python_sqlalchemy_testing_unit_testing.txt |
Q:
Python Cookies question
import cgitb
import Cookie, urllib2
from cookielib import FileCookieJar
cgitb.enable()
c = Cookie.SmartCookie()
c['ini'] = 1
savedc = FileCookieJar()
savedc.add_cookie_header(c.output())
savedc.save()
shoulden't this save the cookie?...
i've been reading over the python documentation like ... | Python Cookies question | import cgitb
import Cookie, urllib2
from cookielib import FileCookieJar
cgitb.enable()
c = Cookie.SmartCookie()
c['ini'] = 1
savedc = FileCookieJar()
savedc.add_cookie_header(c.output())
savedc.save()
shoulden't this save the cookie?...
i've been reading over the python documentation like 1 million times, i just don't... | [
"Raf, all I can say is, Egads! The documentation certainly is not clear! I have used Python for years and this simple Stack Overflow question that I thought I'd quickly nab before getting started on real work for the day has taken me more than twenty minutes to answer. :-)\nFirst: it turns out that the \"Cookie\"... | [
5,
0
] | [] | [] | [
"cgi",
"cookies",
"python"
] | stackoverflow_0000920472_cgi_cookies_python.txt |
Q:
Python: how to store a draft email with BCC recipients to Exchange Server via IMAP?
I try to store a draft e-mail via IMAP to a folder running on MS Exchange. Everything ok, except that Bcc recipients don't get shown in the draft message stored on the server. Bcc recipients also don't receive the email if I send i... | Python: how to store a draft email with BCC recipients to Exchange Server via IMAP? | I try to store a draft e-mail via IMAP to a folder running on MS Exchange. Everything ok, except that Bcc recipients don't get shown in the draft message stored on the server. Bcc recipients also don't receive the email if I send it with MS Outlook. If I read the message back with Python after I have stored it on the s... | [
"Actually, the code works just fine. It creates the proper mail with all the right headers including bcc.\nHow does the mail client display bcc?\nThe mail client (e.g. Python or MS Outlook via IMAP or MAPI in my case) decides whether and how to display bcc-headers. Outlook for example doesn't display bcc headers fr... | [
6,
1,
1
] | [] | [] | [
"bcc",
"email",
"exchange_server",
"imap",
"python"
] | stackoverflow_0000771907_bcc_email_exchange_server_imap_python.txt |
Q:
Swig / Python memory leak detected
I have a very complicated class for which I'm attempting to make Python wrappers in SWIG. When I create an instance of the item in Python, however, I'm unable to initialize certain data members without receiving the message:
>>> myVar = myModule.myDataType()
swig/python detected ... | Swig / Python memory leak detected | I have a very complicated class for which I'm attempting to make Python wrappers in SWIG. When I create an instance of the item in Python, however, I'm unable to initialize certain data members without receiving the message:
>>> myVar = myModule.myDataType()
swig/python detected a memory leak of type 'MyDataType *', no... | [
"SWIG always generates destructor wrappers (unless %nodefaultdtor directive is used). However, in case where it doesn't know anything about a type, it will generate an opaque pointer wrapper, which will cause leaks (and the above message).\nPlease check that myDataType is a type that is known by SWIG. Re-run SWIG w... | [
12
] | [
"The error message is pretty clear to me, you need to define a destructor for this type. \n"
] | [
-13
] | [
"memory_leaks",
"python",
"swig"
] | stackoverflow_0000918180_memory_leaks_python_swig.txt |
Q:
What if I want to store a None value in the memcache?
This is specifically related to the Google App Engine Memcache API, but I'm sure it also applies to other Memcache tools.
The dictionary .get() method allows you to specify a default value, such as dict.get('key', 'defaultval')
This can be useful if it's possib... | What if I want to store a None value in the memcache? | This is specifically related to the Google App Engine Memcache API, but I'm sure it also applies to other Memcache tools.
The dictionary .get() method allows you to specify a default value, such as dict.get('key', 'defaultval')
This can be useful if it's possible you might want to store None as a value in a dictionary.... | [
"A possible way to do this is to create new class that defines None for this purpose, and assign instances of this to the cache (unfortunately you cannot extend None). Alternatively, you could use the empty string \"\", or avoid storing None/null values altogether (absence of the key implies None).\nThen check for ... | [
7,
4,
0
] | [] | [] | [
"google_app_engine",
"memcached",
"python"
] | stackoverflow_0000895386_google_app_engine_memcached_python.txt |
Q:
Reporting charts and data for MS-Office users
We have lots of data and some charts repesenting one logical item. Charts and data is stored in various files. As a result, most users can easily access and re-use the information in their applications.
However, this not exactly a good way of storing data. Amongst othe... | Reporting charts and data for MS-Office users | We have lots of data and some charts repesenting one logical item. Charts and data is stored in various files. As a result, most users can easily access and re-use the information in their applications.
However, this not exactly a good way of storing data. Amongst other reasons, charts belong to some data, the charts a... | [
"I can only agree with Reef on the general concepts he presented:\n\nYou will almost certainly prefer the data in a database than in a single large file\nYou should not worry that the data is not directly manipulated by users because as Reef mentioned, it can only go wrong. And you would be suprised at how ugly it ... | [
2,
1
] | [] | [] | [
"ms_office",
"python",
"reporting",
"scripting",
"web_services"
] | stackoverflow_0000915726_ms_office_python_reporting_scripting_web_services.txt |
Q:
Progress bar with long web requests
In a django application I am working on, I have just added the ability to archive a number of files (starting 50mb in total) to a zip file. Currently, i am doing it something like this:
get files to zip
zip all files
send HTML response
Obviously, this causes a big wait on line ... | Progress bar with long web requests | In a django application I am working on, I have just added the ability to archive a number of files (starting 50mb in total) to a zip file. Currently, i am doing it something like this:
get files to zip
zip all files
send HTML response
Obviously, this causes a big wait on line two where the files are being compressed.... | [
"You should keep in mind showing the progress bar may not be a good idea, since you can get timeouts or get your server suffer from submitting lot of simultaneous requests.\nPut the zipping task in the queue and have it callback to notify the user somehow - by e-mail for instance - that the process has finished.\nT... | [
4,
1,
0
] | [
"Better than a static page, show a Javascript dialog (using Shadowbox, JQuery UI or some custom method) with a throbber ( you can get some at hxxp://www.ajaxload.info/ ). You can also show the throbber in your page, without dialogs. Most users only want to know their action is being handled, and can live without re... | [
-1
] | [
"django",
"python"
] | stackoverflow_0000919816_django_python.txt |
Q:
How to use classes derived from Python's list class
This is a followup to question 912526 - How do I pass lots of variables to and from a function in Python?.
There are lots of variables that need to get passed around in the program I'm writing, and from my previous question I understand that I should put these va... | How to use classes derived from Python's list class | This is a followup to question 912526 - How do I pass lots of variables to and from a function in Python?.
There are lots of variables that need to get passed around in the program I'm writing, and from my previous question I understand that I should put these variables into classes, and then pass around the classes.
S... | [
"There are several issues in your code:\n1.If you make any list operation the result will be a native list:\nlayers1 = Layers()\nlayers2 = Layers()\nlayers1 + layers2 -> the result will be a native list\n\n2.Why define input_string when you can override __repr__ or __str__\n3.Why do you even have to derive from lis... | [
9
] | [] | [] | [
"class",
"python"
] | stackoverflow_0000921334_class_python.txt |
Q:
Using cookies with python to store searches
Hey i have a webpage for searching a database. i would like to be able to implement cookies using python to store what a user searches for and provide them with a recently searched field when they return. is there a way to implement this using the python Cookie library??... | Using cookies with python to store searches | Hey i have a webpage for searching a database. i would like to be able to implement cookies using python to store what a user searches for and provide them with a recently searched field when they return. is there a way to implement this using the python Cookie library??
| [
"Usually, we do the following.\n\nUse a framework.\nEstablish a session. Ideally, ask for a username of some kind. If you don't want to ask for names or anything, you can try to the browser's IP address as the key for the session (this can turn into a nightmare, but you can try it.)\nUsing the session identifica... | [
1,
0
] | [] | [] | [
"cookies",
"python"
] | stackoverflow_0000920278_cookies_python.txt |
Q:
Python and Qt - function reloading
i have an application class inherited from QtGui.QDialog.
I have to reload show-function but save functionality. I take this idea from C#.
There i could do something like this:
static void show()
{
// My code...
base.show();
}
I want to do something like that but with python... | Python and Qt - function reloading | i have an application class inherited from QtGui.QDialog.
I have to reload show-function but save functionality. I take this idea from C#.
There i could do something like this:
static void show()
{
// My code...
base.show();
}
I want to do something like that but with python and qt (PyQt). Can i do that?
| [
"Checkout the super() function but note some pitfalls.\n"
] | [
1
] | [] | [] | [
"function",
"python",
"reloading"
] | stackoverflow_0000921929_function_python_reloading.txt |
Q:
How do I deactivate an egg?
I've installed cx_Oracle (repeatedly) and I just can't get it to work on my Intel Mac. How do I deactivate/uninstall it?
A:
You simply delete the .egg file
On OS X they are installed into /Library/Python/2.5/site-packages/ - in that folder you should find a file named cx_Oracle.egg or... | How do I deactivate an egg? | I've installed cx_Oracle (repeatedly) and I just can't get it to work on my Intel Mac. How do I deactivate/uninstall it?
| [
"You simply delete the .egg file\nOn OS X they are installed into /Library/Python/2.5/site-packages/ - in that folder you should find a file named cx_Oracle.egg or similar. You can simple delete this file and it will be gone.\nOne way of finding the file is, if you can import the module, simply displaying the repr(... | [
3
] | [] | [] | [
"egg",
"python",
"uninstallation"
] | stackoverflow_0000922323_egg_python_uninstallation.txt |
Q:
Learning parser in python
I recall I have read about a parser which you just have to feed some sample lines, for it to know how to parse some text.
It just determines the difference between two lines to know what the variable parts are. I thought it was written in python, but i'm not sure. Does anyone know what li... | Learning parser in python | I recall I have read about a parser which you just have to feed some sample lines, for it to know how to parse some text.
It just determines the difference between two lines to know what the variable parts are. I thought it was written in python, but i'm not sure. Does anyone know what library that was?
| [
"Probably you mean TemplateMaker, I haven't tried it yet, but it builds on well-researched longest-common-substring algorithms and thus should work reasonably... If you are interested in different (more complex) approaches, you can easily find a lot of material on Google Scholar using the query \"wrapper induction\... | [
10,
2
] | [] | [] | [
"parsing",
"python"
] | stackoverflow_0000921792_parsing_python.txt |
Q:
Is there a better way than int( byte_buffer.encode('hex'), 16 )
In Python, I'm constantly using the following sequence to get an integer value from a byte buffer (in python this is a str).
I'm getting the buffer from the struct.unpack() routine. When I unpack a 'char' using
byte_buffer, = struct.unpack('c', raw_b... | Is there a better way than int( byte_buffer.encode('hex'), 16 ) | In Python, I'm constantly using the following sequence to get an integer value from a byte buffer (in python this is a str).
I'm getting the buffer from the struct.unpack() routine. When I unpack a 'char' using
byte_buffer, = struct.unpack('c', raw_buffer)
int_value = int( byte_buffer.encode('hex'), 16 )
Is there a b... | [
"The struct module is good at unpacking binary data.\nint_value = struct.unpack('>I', byte_buffer)[0]\n\n",
"\nBounded to 1 byte – Noah Campbell 18 mins ago\n\nThe best way to do this then is to instantiate a struct unpacker.\nfrom struct import Struct\n\nunpacker = Struct(\"b\")\nunpacker.unpack(\"z\")[0]\n\nNot... | [
6,
2,
1
] | [] | [] | [
"byte",
"integer",
"python",
"types"
] | stackoverflow_0000918754_byte_integer_python_types.txt |
Q:
Python, SimPy: How to generate a value from a triangular probability distribution?
I want to run a simulation that uses as parameter a value generated from a triangular probability distribution with lower limit A, mode B and and upper limit C. How can I generate this value in Python? Is there something as simple a... | Python, SimPy: How to generate a value from a triangular probability distribution? | I want to run a simulation that uses as parameter a value generated from a triangular probability distribution with lower limit A, mode B and and upper limit C. How can I generate this value in Python? Is there something as simple as expovariate(lambda) (from random) for this distribution or do I have to code this thin... | [
"If you download the NumPy package, it has a function numpy.random.triangular(left, mode, right[, size]) that does exactly what you are looking for.\n",
"Since, I was checking random's documentation from Python 2.4 I missed this:\nrandom.triangular(low, high, mode)¶\n Return a random floating point number N su... | [
9,
6,
3
] | [] | [] | [
"distribution",
"probability",
"python",
"simpy"
] | stackoverflow_0000815969_distribution_probability_python_simpy.txt |
Q:
How can I capture the stdout output of a child process?
I'm trying to write a program in Python and I'm told to run an .exe file. When this .exe file is run it spits out a lot of data and I need a certain line printed out to the screen. I'm pretty sure I need to use subprocess.popen or something similar but I'm ne... | How can I capture the stdout output of a child process? | I'm trying to write a program in Python and I'm told to run an .exe file. When this .exe file is run it spits out a lot of data and I need a certain line printed out to the screen. I'm pretty sure I need to use subprocess.popen or something similar but I'm new to subprocess and have no clue. Anyone have an easy way for... | [
"@Paolo's solution is perfect if you are interested in printing output after the process has finished executing. In case you want to poll output while the process is running you have to do it this way:\nprocess = subprocess.Popen(cmd, stdout=subprocess.PIPE)\n\nwhile True:\n out = process.stdout.readline(1)\n ... | [
28,
21
] | [] | [] | [
"python",
"stdout",
"subprocess"
] | stackoverflow_0000923079_python_stdout_subprocess.txt |
Q:
Writing a kernel mode profiler for processes in python
I would like seek some guidance in writing a "process profiler" which runs in kernel mode. I am asking for a kernel mode profiler is because I run loads of applications and I do not want my profiler to be swapped out.
When I said "process profiler" I mean to s... | Writing a kernel mode profiler for processes in python | I would like seek some guidance in writing a "process profiler" which runs in kernel mode. I am asking for a kernel mode profiler is because I run loads of applications and I do not want my profiler to be swapped out.
When I said "process profiler" I mean to something that would monitor resource usage by the process. i... | [
"It's going to be very difficult to do the process monitoring part in Python, since the python interpreter doesn't run in the kernel.\nI suspect there are two easy approaches to this:\n\nuse the /proc filesystem if you have one (you don't mention your OS)\nUse dtrace if you have dtrace (again, without the OS, who k... | [
7,
3,
0,
0
] | [] | [] | [
"kernel",
"python"
] | stackoverflow_0000922788_kernel_python.txt |
Q:
Scraping Multiple html files to CSV
I am trying to scrape rows off of over 1200 .htm files that are on my hard drive. On my computer they are here 'file:///home/phi/Data/NHL/pl07-08/PL020001.HTM'. These .htm files are sequential from *20001.htm until *21230.htm. My plan is to eventually toss my data in MySQL or SQ... | Scraping Multiple html files to CSV | I am trying to scrape rows off of over 1200 .htm files that are on my hard drive. On my computer they are here 'file:///home/phi/Data/NHL/pl07-08/PL020001.HTM'. These .htm files are sequential from *20001.htm until *21230.htm. My plan is to eventually toss my data in MySQL or SQLite via a spreadsheet app or just straig... | [
"You won't need mechanize. Since I do not exactly know the HTML content, I'd try to see what matches, first. Like this: \nimport glob\nfrom BeautifulSoup import BeautifulSoup\n\nfor filename in glob.glob('/home/phi/Data/*.htm'):\n soup = BeautifulSoup(open(filename, \"r\").read()) # assuming some HTML\n for a... | [
1,
0
] | [] | [] | [
"beautifulsoup",
"mechanize",
"python",
"screen_scraping",
"sqlite"
] | stackoverflow_0000923318_beautifulsoup_mechanize_python_screen_scraping_sqlite.txt |
Q:
Matching text within P tags in HTML
I'd like to match the contents within each paragraph in html using a python regular expression. These paragraphs always have BR tags inside them like so:
<p class="thisClass">this is nice <br /><br /> isn't it?</p>
I'm currently using this pattern:
pattern = re.compile('<p clas... | Matching text within P tags in HTML | I'd like to match the contents within each paragraph in html using a python regular expression. These paragraphs always have BR tags inside them like so:
<p class="thisClass">this is nice <br /><br /> isn't it?</p>
I'm currently using this pattern:
pattern = re.compile('<p class=\"thisClass\">(.*?)<\/p>')
Then I'm us... | [
"I don't think it is failing because of the <br/> but rather because the paragraph is spread across multiple lines. Use the DOTALL mode to fix this:\npattern = re.compile('<p class=\\\"thisClass\\\">(.*?)<\\/p>', re.DOTALL)\n\n",
"It turns out the answer was to include re.S as a flag which allows the \".\" charac... | [
5,
3
] | [] | [] | [
"html",
"python",
"regex"
] | stackoverflow_0000923472_html_python_regex.txt |
Q:
Python RegEx - Getting multiple pieces of information out of a string
I'm trying to use python to parse a log file and match 4 pieces of information in one regex. (epoch time, SERVICE NOTIFICATION, hostname and CRITICAL) I can't seem to get this to work. So Far I've been able to only match two of the four. Is it p... | Python RegEx - Getting multiple pieces of information out of a string | I'm trying to use python to parse a log file and match 4 pieces of information in one regex. (epoch time, SERVICE NOTIFICATION, hostname and CRITICAL) I can't seem to get this to work. So Far I've been able to only match two of the four. Is it possible to do this? Below is an example of a string from the log file and t... | [
"You can use | to match any one of various possible things, and re.findall to get all non-overlapping matches to some RE.\n",
"The question is a bit confusing. But you don't need to do everything with regular expressions, there are some good plain old string functions you might want to try, like 'split'.\nThis v... | [
6,
2,
2,
1,
0
] | [] | [] | [
"python",
"regex"
] | stackoverflow_0000924127_python_regex.txt |
Q:
Unicode problems in PyObjC
I am trying to figure out PyObjC on Mac OS X, and I have written a simple program to print out the names in my Address Book. However, I am having some trouble with the encoding of the output.
#! /usr/bin/env python
# -*- coding: UTF-8 -*-
from AddressBook import *
ab = ABAddressBook.sh... | Unicode problems in PyObjC | I am trying to figure out PyObjC on Mac OS X, and I have written a simple program to print out the names in my Address Book. However, I am having some trouble with the encoding of the output.
#! /usr/bin/env python
# -*- coding: UTF-8 -*-
from AddressBook import *
ab = ABAddressBook.sharedAddressBook()
people = ab.pe... | [
"# -*- coding: UTF-8 -*-\n\nonly affects the way Python decodes comments and string literals in your source, not the way standard output is configured, etc, etc. If you set your Mac's Terminal to UTF-8 (Terminal, Preferences, Settings, Advanced, International dropdown) and emit Unicode text to it after encoding it... | [
3,
1,
0,
0
] | [] | [] | [
"macos",
"pyobjc",
"python",
"unicode"
] | stackoverflow_0000922562_macos_pyobjc_python_unicode.txt |
Q:
Python taskbar applet
I want to code up a panel that will be used both in Linux and Windows. Ideally it will be written in Python using PyQT.
What I've found so far is the QSystemTrayIcon widget, and while that is quite useful, that's not quite what I'm looking for. That widget lets you attach a menu to the left a... | Python taskbar applet | I want to code up a panel that will be used both in Linux and Windows. Ideally it will be written in Python using PyQT.
What I've found so far is the QSystemTrayIcon widget, and while that is quite useful, that's not quite what I'm looking for. That widget lets you attach a menu to the left and right clicks of an icon ... | [
"Widgets inside the GNOME panel are called applets, and to my knowledge it's not possible to write them with anything but Gtk, since you have to use the respective GNOME library libpanel-applet (in either C, C++ or Python). \nSystem tray icons are different, because they only allow icons to be displayed inside the ... | [
5
] | [
"Sounds like you are looking for Plasmoids, which can be integrated into the task bar. There are a Plasmoid tutorials in C++ and Python.\nI can't say, however, whether it will work with KDE on Windows.\n"
] | [
-1
] | [
"pyqt",
"python",
"qt4"
] | stackoverflow_0000923701_pyqt_python_qt4.txt |
Q:
Capturing Implicit Signals of Interest in Django
To set the background: I'm interested in:
Capturing implicit signals of interest in books as users browse around a site. The site is written in django (python) using mysql, memcached, ngnix, and apache
Let's say, for instance, my site sells books. As a user browse... | Capturing Implicit Signals of Interest in Django | To set the background: I'm interested in:
Capturing implicit signals of interest in books as users browse around a site. The site is written in django (python) using mysql, memcached, ngnix, and apache
Let's say, for instance, my site sells books. As a user browses around my site I'd like to keep track of which books... | [
"If this data is not an unimportant statistic that might or might not be available I'd suggest taking the simple approach and using a model. It will surely hit the database everytime. \nUnless you are absolutely positively sure these queries are actually degrading overall experience there is no need to worry about ... | [
3,
1,
1,
0
] | [] | [] | [
"collaborative_filtering",
"django",
"mysql",
"python"
] | stackoverflow_0000924530_collaborative_filtering_django_mysql_python.txt |
Q:
The right way to auto filter SQLAlchemy queries?
I've just introspected a pretty nasty schema from a CRM app with sqlalchemy. All of the tables have a deleted column on them and I wanted to auto filter all those entities and relations flagged as deleted. Here's what I came up with:
class CustomizableQuery(Query):... | The right way to auto filter SQLAlchemy queries? | I've just introspected a pretty nasty schema from a CRM app with sqlalchemy. All of the tables have a deleted column on them and I wanted to auto filter all those entities and relations flagged as deleted. Here's what I came up with:
class CustomizableQuery(Query):
"""An overridden sqlalchemy.orm.query.Query to fi... | [
"You can map to a select. Like this:\nmapper(EmailInfo, select([email_join], email_join.c.deleted == False))\n\n",
"I'd consider seeing if it was possible to create views for these tables that filter out the deleted elements, and then you might be able to map directly to that view instead of the underlying table,... | [
7,
0
] | [] | [] | [
"python",
"sqlalchemy",
"sugarcrm"
] | stackoverflow_0000920724_python_sqlalchemy_sugarcrm.txt |
Q:
Uploading multiple images in Django admin
I'm currently building a portfolio site for a client, and I'm having trouble with one small area. I want to be able to upload multiple images (varying number) inline for each portfolio item, and I can't see an obvious way to do it.
The most user-friendly way I can see woul... | Uploading multiple images in Django admin | I'm currently building a portfolio site for a client, and I'm having trouble with one small area. I want to be able to upload multiple images (varying number) inline for each portfolio item, and I can't see an obvious way to do it.
The most user-friendly way I can see would be a file upload form with a JavaScript contr... | [
"photologue is a feature-rich photo app for django. it e.g. lets you upload galleries as zip files (which in a sense means uploading multiple files at once), automatically creates thumbnails of different custom sizes and can apply effects to images. I used it once on one project and the integration wasn't too hard.... | [
9,
9
] | [] | [] | [
"django",
"image_uploading",
"python"
] | stackoverflow_0000925305_django_image_uploading_python.txt |
Q:
parsing in python
I have following string
adId:4028cb901dd9720a011e1160afbc01a3;siteId:8a8ee4f720e6beb70120e6d8e08b0002;userId:5082a05c-015e-4266-9874-5dc6262da3e0
I need only the value of adId,siteId and userId.
means
4028cb901dd9720a011e1160afbc01a3
8a8ee4f720e6beb70120e6d8e08b0002
5082a05c-015e-4266-9874-5dc62... | parsing in python | I have following string
adId:4028cb901dd9720a011e1160afbc01a3;siteId:8a8ee4f720e6beb70120e6d8e08b0002;userId:5082a05c-015e-4266-9874-5dc6262da3e0
I need only the value of adId,siteId and userId.
means
4028cb901dd9720a011e1160afbc01a3
8a8ee4f720e6beb70120e6d8e08b0002
5082a05c-015e-4266-9874-5dc6262da3e0
all the 3 in di... | [
"You can split them to a dictionary if you don't need any fancy parsing:\nIn [2]: dict(kvpair.split(':') for kvpair in s.split(';'))\nOut[2]:\n{'adId': '4028cb901dd9720a011e1160afbc01a3',\n 'siteId': '8a8ee4f720e6beb70120e6d8e08b0002',\n 'userId': '5082a05c-015e-4266-9874-5dc6262da3e0'}\n\n",
"matches = re.findal... | [
18,
1,
1,
0
] | [] | [] | [
"python"
] | stackoverflow_0000925839_python.txt |
Q:
When calling a Python script from a PHP script, temporary file that is created on a console run, is not created via the PHP invocation
Scenario:
I have a php page in which I call a python script.
Python script when run on the command line (Linux) shows output on the command line, as well as writes the output to a... | When calling a Python script from a PHP script, temporary file that is created on a console run, is not created via the PHP invocation | Scenario:
I have a php page in which I call a python script.
Python script when run on the command line (Linux) shows output on the command line, as well as writes the output to a file.
Python script when run through php, doesn't do either.
Elaboration:
I use a simple system command in PHP to run the python script as:... | [
"I bet your py script has some bug which couses it to break when called from inside PHP.\nTry\npassthru('/usr/python/bin/python3 ../cgi-bin/tabular.py 1 2>&1');\n\nto investigate (notice 2>&1 which causess stderr to be written to stdout).\n",
"A permission problem is most likely the case.\nIf apache is running as... | [
2,
1,
0
] | [] | [] | [
"linux",
"php",
"python"
] | stackoverflow_0000923680_linux_php_python.txt |
Q:
Are inner-classes unpythonic?
My colleague just pointed out that my use of inner-classes seemed to be "unpythonic". I guess it violates the "flat is better than nested" heuristic.
What do people here think? Are inner-classes something which are more appropriate to Java etc than Python?
NB : I don't think this is a... | Are inner-classes unpythonic? | My colleague just pointed out that my use of inner-classes seemed to be "unpythonic". I guess it violates the "flat is better than nested" heuristic.
What do people here think? Are inner-classes something which are more appropriate to Java etc than Python?
NB : I don't think this is a "subjective" question. Surely styl... | [
"This may not deserve a [subjective] tag on StackOverflow, but it's subjective on the larger stage: some language communities encourage nesting and others discourage it. So why would the Python community discourage nesting? Because Tim Peters put it in The Zen of Python? Does it apply to every scenario, always, wit... | [
10,
9,
2
] | [] | [] | [
"python"
] | stackoverflow_0000926327_python.txt |
Q:
Why does defining __getitem__ on a class make it iterable in python?
Why does defining __getitem__ on a class make it iterable?
For instance if I write:
class b:
def __getitem__(self, k):
return k
cb = b()
for k in cb:
print k
I get the output:
0
1
2
3
4
5
6
7
8
...
I would really expect to see an err... | Why does defining __getitem__ on a class make it iterable in python? | Why does defining __getitem__ on a class make it iterable?
For instance if I write:
class b:
def __getitem__(self, k):
return k
cb = b()
for k in cb:
print k
I get the output:
0
1
2
3
4
5
6
7
8
...
I would really expect to see an error returned from "for k in cb:"
| [
"Iteration's support for __getitem__ can be seen as a \"legacy feature\" which allowed smoother transition when PEP234 introduced iterability as a primary concept. It only applies to classes without __iter__ whose __getitem__ accepts integers 0, 1, &c, and raises IndexError once the index gets too high (if ever), t... | [
77,
55,
40,
8,
5,
2
] | [] | [] | [
"iterator",
"overloading",
"python"
] | stackoverflow_0000926574_iterator_overloading_python.txt |
Q:
How can I make a class in python support __getitem__, but not allow iteration?
I want to define a class that supports __getitem__, but does not allow iteration.
for example:
class B:
def __getitem__(self, k):
return k
cb = B()
for x in cb:
print x
What could I add to the class B to force the for x i... | How can I make a class in python support __getitem__, but not allow iteration? | I want to define a class that supports __getitem__, but does not allow iteration.
for example:
class B:
def __getitem__(self, k):
return k
cb = B()
for x in cb:
print x
What could I add to the class B to force the for x in cb: to fail?
| [
"I think a slightly better solution would be to raise a TypeError rather than a plain exception (this is what normally happens with a non-iterable class:\nclass A(object):\n # show what happens with a non-iterable class with no __getitem__\n pass\n\nclass B(object):\n def __getitem__(self, k):\n ret... | [
14,
2
] | [] | [] | [
"iteration",
"operator_overloading",
"python"
] | stackoverflow_0000926688_iteration_operator_overloading_python.txt |
Q:
Checking to See if a List Exists Within Another Lists?
Okay I'm trying to go for a more pythonic method of doing things.
How can i do the following:
required_values = ['A','B','C']
some_map = {'A' : 1, 'B' : 2, 'C' : 3, 'D' : 4}
for required_value in required_values:
if not required_value in some_map:
... | Checking to See if a List Exists Within Another Lists? | Okay I'm trying to go for a more pythonic method of doing things.
How can i do the following:
required_values = ['A','B','C']
some_map = {'A' : 1, 'B' : 2, 'C' : 3, 'D' : 4}
for required_value in required_values:
if not required_value in some_map:
print 'It Doesnt Exists'
return False
return True
... | [
"all(value in some_map for value in required_values)\n\n",
"return set(required_values).issubset(set(some_map.keys()))\n\n",
"try a list comprehension:\nreturn not bool([x for x in required_values if x not in some_map.keys()]) (bool conversion for clarity)\nor return not [x for x in required_values if x not in... | [
11,
3,
0
] | [] | [] | [
"list",
"python"
] | stackoverflow_0000926946_list_python.txt |
Q:
Do I need PyISAPIe to run Django on IIS6?
It seems that all roads lead to having to use PyISAPIe to get Django running on IIS6. This becomes a problem for us because it appears you need separate application pools per PyISAPIe/Django instance which is something we'd prefer not to do.
Does anyone have any advice/gui... | Do I need PyISAPIe to run Django on IIS6? | It seems that all roads lead to having to use PyISAPIe to get Django running on IIS6. This becomes a problem for us because it appears you need separate application pools per PyISAPIe/Django instance which is something we'd prefer not to do.
Does anyone have any advice/guidance, or can share their experiences (particul... | [
"You need separate application pools no matter what extension you use. This is because application pools split the handler DLLs into different w3wp.exe process instances. You might wonder why this is necessary:\nLook at Django's module setting: os.environ[\"DJANGO_SETTINGS_MODULE\"]. That's the environment of the p... | [
3,
1
] | [] | [] | [
"django",
"iis_6",
"pyisapie",
"python"
] | stackoverflow_0000853755_django_iis_6_pyisapie_python.txt |
Q:
Giving anonymous users the same functionality as registered ones
I'm working on an online store in Django (just a basic shopping cart right now), and I'm planning to add functionality for users to mark items as favorite (just like in stackoverflow). Models for the cart look something like this:
class Cart(models.M... | Giving anonymous users the same functionality as registered ones | I'm working on an online store in Django (just a basic shopping cart right now), and I'm planning to add functionality for users to mark items as favorite (just like in stackoverflow). Models for the cart look something like this:
class Cart(models.Model):
user = models.OneToOneField(User)
class CartItem(models.Mo... | [
"I haven't done this before but from reading your description I would simply create a user object when someone needs to do something that requires it. You then send the user a cookie which links to this user object, so if someone comes back (without clearing their cookies) they get the same skeleton user object.\n... | [
12,
5,
2,
0
] | [] | [] | [
"django",
"python",
"session"
] | stackoverflow_0000925456_django_python_session.txt |
Q:
FIFO (named pipe) messaging obstacles
I plan to use Unix named pipes (mkfifo) for simple multi-process messaging.
A message would be just a single line of text.
Would you discourage me from that? What obstacles should I expect?
I have noticed these limitations:
A sender cannot continue until the message is receiv... | FIFO (named pipe) messaging obstacles | I plan to use Unix named pipes (mkfifo) for simple multi-process messaging.
A message would be just a single line of text.
Would you discourage me from that? What obstacles should I expect?
I have noticed these limitations:
A sender cannot continue until the message is received.
A receiver is blocked until there are s... | [
"\nLack of portability - they are mainly a Unix thing. Sockets are more portable.\nHarder to scale out to multiple systems (another sockets+)\nOn the other hand, I believe pipes are faster than sockets for processes on the same machine (less communication overhead).\n\nAs to your limitations,\n\nYou can \"select\" ... | [
5,
3
] | [] | [] | [
"linux",
"named_pipes",
"pipe",
"python",
"unix"
] | stackoverflow_0000927233_linux_named_pipes_pipe_python_unix.txt |
Q:
Render PyCairo onto PyOpenGL surface?
I've recently started playing with pycairo - is it easy enough to render this to an pyopengl surface (e.g. on the side of a cube?)... my opengl is really non-existant so I'm not sure the best way to go about this.
A:
This procedure might work:
Do your drawing in pycairo lik... | Render PyCairo onto PyOpenGL surface? | I've recently started playing with pycairo - is it easy enough to render this to an pyopengl surface (e.g. on the side of a cube?)... my opengl is really non-existant so I'm not sure the best way to go about this.
| [
"This procedure might work:\n\nDo your drawing in pycairo like normal.\nExport the image to a file (or get a handle to it in memory).\nLoad the image into opengl texture memory.\nDraw your cube in opengl using the texture.\n\nSteps 1&2 are in cairo, which I'm not familiar with. Steps 3&4 would be done in opengl. ... | [
0
] | [] | [] | [
"cairo",
"opengl",
"python"
] | stackoverflow_0000820221_cairo_opengl_python.txt |
Q:
Does python-memcache use consistent hashing?
I'm using the python-memcache library, and I'm wondering if anyone knows if consistent hashing is used by that client as of 1.44.
A:
If you need something like that you might be interested in hash_ring
A:
From a quick view into the source code: No it does not. It us... | Does python-memcache use consistent hashing? | I'm using the python-memcache library, and I'm wondering if anyone knows if consistent hashing is used by that client as of 1.44.
| [
"If you need something like that you might be interested in hash_ring\n",
"From a quick view into the source code: No it does not. It uses server = hash_key % len(servers) and round-robin if offline/full servers are encountered.\n"
] | [
3,
2
] | [] | [] | [
"memcached",
"python"
] | stackoverflow_0000926814_memcached_python.txt |
Q:
Is there a uniform python library to transfer files using different protocols
I know there is ftplib for ftp, shutil for local files, what about NFS? I know urllib2 can get files via HTTP/HTTPS/FTP/FTPS, but it can't put files.
If there is a uniform library that automatically detects the protocol (FTP/NFS/LOCAL) w... | Is there a uniform python library to transfer files using different protocols | I know there is ftplib for ftp, shutil for local files, what about NFS? I know urllib2 can get files via HTTP/HTTPS/FTP/FTPS, but it can't put files.
If there is a uniform library that automatically detects the protocol (FTP/NFS/LOCAL) with URI and deals with file transfer (get/put) transparently, it's even better, doe... | [
"You want to look up and use pycurl/libcurl. Libcurl: http://curl.haxx.se/ PyCurl: http://pycurl.sourceforge.net/ - curl supports the http://, file://, and ftp:// uris. I have used it with much success.\n",
"Have a look at KDE IOSlaves. They can manage all the protocol you describe, plus a few others (samba, ssh,... | [
2,
1
] | [] | [] | [
"file",
"ftp",
"networking",
"nfs",
"python"
] | stackoverflow_0000925716_file_ftp_networking_nfs_python.txt |
Q:
Really odd (mod)_python problem
this one is hard to explain!
I am writing a python application to be ran through mod_python. At each request, the returned output differs, even though the logic is 'fixed'.
I have two classes, classA and classB. Such that:
class ClassA:
def page(self, req):
req.write("In... | Really odd (mod)_python problem | this one is hard to explain!
I am writing a python application to be ran through mod_python. At each request, the returned output differs, even though the logic is 'fixed'.
I have two classes, classA and classB. Such that:
class ClassA:
def page(self, req):
req.write("In classA page")
objB = ClassB(... | [
"I've seen similar behaviour with mod_python before. Usually it is because apache is running multiple threads and one of them is running an older version of the code. When you refresh the page chances are the thread with the older code is serving the page. I usually fix this by stoping apache and then restarting it... | [
4,
1
] | [] | [] | [
"debugging",
"mod_python",
"python"
] | stackoverflow_0000927759_debugging_mod_python_python.txt |
Q:
str.startswith() not working as I intended
I'm trying to test for a /t or a space character and I can't understand why this bit of code won't work. What I am doing is reading in a file, counting the loc for the file, and then recording the names of each function present within the file along with their individual ... | str.startswith() not working as I intended | I'm trying to test for a /t or a space character and I can't understand why this bit of code won't work. What I am doing is reading in a file, counting the loc for the file, and then recording the names of each function present within the file along with their individual lines of code. The bit of code below is where I ... | [
"\\s is only whitespace to the re package when doing pattern matching.\nFor startswith, an ordinary method of ordinary strings, \\s is nothing special. Not a pattern, just characters.\n",
"Your question has already been answered and this is slightly off-topic, but...\nIf you want to parse code, it is often easie... | [
8,
3,
2
] | [] | [] | [
"python",
"python_3.x",
"string"
] | stackoverflow_0000927584_python_python_3.x_string.txt |
Q:
Formatting the output of a key from a dictionary
I have a dictionary which store a string as the key, and an integer as the value. In my output I would like to have the key displayed as a string without parenthesis or commas. How would I do this?
for f_name,f_loc in dict_func.items():
print ('Function name... | Formatting the output of a key from a dictionary | I have a dictionary which store a string as the key, and an integer as the value. In my output I would like to have the key displayed as a string without parenthesis or commas. How would I do this?
for f_name,f_loc in dict_func.items():
print ('Function names:\n\n\t{0} -- {1} lines of code\n'.format(f_name, f_l... | [
"I don't have Python 3 so I can't test this, but the output of f_name makes it look like it is a tuple with one element in it. So you would change .format(f_name, f_loc) to .format(f_name[0], f_loc)\nEDIT:\nIn response to your edit, try using .group() instead of .groups()\n",
"To elaborate on Peter's answer, It l... | [
4,
3,
2,
1
] | [] | [] | [
"dictionary",
"python",
"python_3.x",
"string"
] | stackoverflow_0000928330_dictionary_python_python_3.x_string.txt |
Q:
Fedora Python Upgrade broke easy_install
Fedora Core 9 includes Python 2.5.1. I can use YUM to get latest and greatest releases.
To get ready for 2.6 official testing, I wanted to start with 2.5.4. It appears that there's no Fedora 9 YUM package, because 2.5.4 isn't an official part of FC9.
I downloaded 2.5.4, d... | Fedora Python Upgrade broke easy_install | Fedora Core 9 includes Python 2.5.1. I can use YUM to get latest and greatest releases.
To get ready for 2.6 official testing, I wanted to start with 2.5.4. It appears that there's no Fedora 9 YUM package, because 2.5.4 isn't an official part of FC9.
I downloaded 2.5.4, did ./configure; make; make install and wound u... | [
"Normally, you would only have one version of a python release installed. Since 2.5.1 and 2.5.4 are from the same release, copying your libraries should work fine. What you would need to watch out for, is that you now have /usr/bin/python, and /usr/local/bin/python in your path, and some utilities may get confused.... | [
4,
2,
2
] | [] | [] | [
"easy_install",
"fedora",
"python"
] | stackoverflow_0000925965_easy_install_fedora_python.txt |
Q:
Configure Apache to recover from mod_python errors
I am hosting a Django app on Apache using mod_python. Occasionally, I get some cryptic mod_python errors, usually of the ImportError variety, although not usually referring to the same module. The thing is, these seem to come up for a single forked subprocess, w... | Configure Apache to recover from mod_python errors | I am hosting a Django app on Apache using mod_python. Occasionally, I get some cryptic mod_python errors, usually of the ImportError variety, although not usually referring to the same module. The thing is, these seem to come up for a single forked subprocess, while the others operate fine, even when I force behavior... | [
"As a workaround, and assuming you are free to install new Apache modules on the server, you might try one of\n\nmod_scgi\nmod_fastcgi\nmod_wsgi \n\ninstead. I use SCGI to connect an nginx frontend webserver to my Django apps, which highlights a major benefit (decoupling from the webserver). All of these packages a... | [
1
] | [] | [] | [
"apache",
"django",
"mod_python",
"python"
] | stackoverflow_0000926579_apache_django_mod_python_python.txt |
Q:
How do I access the name of the class of an Object in Python?
The title says it mostly.
If I have an object in Python and want to access the name of the class it is instantiated from is there a standard way to do this?
A:
obj.__class__.__name__
| How do I access the name of the class of an Object in Python? | The title says it mostly.
If I have an object in Python and want to access the name of the class it is instantiated from is there a standard way to do this?
| [
"obj.__class__.__name__\n\n"
] | [
19
] | [] | [] | [
"python"
] | stackoverflow_0000928806_python.txt |
Q:
Python File Read + Write
I am working on porting over a database from a custom MSSQL CMS to MYSQL - Wordpress. I am using Python to read a txt file with \t delineated columns and one row per line.
I am trying to write a Python script that will read this file (fread) and [eventually] create a MYSSQL ready .sql file... | Python File Read + Write | I am working on porting over a database from a custom MSSQL CMS to MYSQL - Wordpress. I am using Python to read a txt file with \t delineated columns and one row per line.
I am trying to write a Python script that will read this file (fread) and [eventually] create a MYSSQL ready .sql file with insert statements.
A lin... | [
"Although this is easily doable, it does become easier with the csv module.\n>>> import csv\n>>> reader = csv.reader(open('C:/www/stackoverflow.txt'), delimiter='\\t')\n>>> for row in reader:\n... print row\n...\n['1', 'John Smith', 'Developer', 'http://twiiter.com/johns', 'Chicago, IL']\n['2', 'John Doe', 'Dev... | [
10,
1,
0,
0,
0
] | [] | [] | [
"file",
"python"
] | stackoverflow_0000928918_file_python.txt |
Q:
Tkinter: Changing a variable within a function
I know this kind of question gets asked all the time but either i've been unable to come across the answer i need, or i've been unable to understand it when i did.
I want to be able to do something like:
spam = StringVar()
spam.set(aValue)
class MyScale(Scale):
de... | Tkinter: Changing a variable within a function | I know this kind of question gets asked all the time but either i've been unable to come across the answer i need, or i've been unable to understand it when i did.
I want to be able to do something like:
spam = StringVar()
spam.set(aValue)
class MyScale(Scale):
def __init__(self,var,*args,**kwargs):
Scale._... | [
"Please give this a shot.\nLots of example code out there generously uses globals, like your \"var\" variable.\nI have used your var argument to act as a pointer back to the original spam object; assigned to self.var_pointer within the MyScale class.\nThe code below will change the value of 'spam' (and 'eggs') on t... | [
2,
1
] | [] | [] | [
"python",
"tkinter"
] | stackoverflow_0000928520_python_tkinter.txt |
Q:
str.startswith() not working as I intended
I can't see why this won't work. I am performing lstrip() on the string being passed to the function, and trying to see if it starts with """. For some reason, it gets caught in an infinite loop
def find_comment(infile, line):
line_t = line.lstrip()
if not line_t... | str.startswith() not working as I intended | I can't see why this won't work. I am performing lstrip() on the string being passed to the function, and trying to see if it starts with """. For some reason, it gets caught in an infinite loop
def find_comment(infile, line):
line_t = line.lstrip()
if not line_t.startswith('"""') and not line_t.startswith('#'... | [
"You haven't provided and exit path from the recursive loop. A return statement should do the trick.\n (...)\n while True:\n if line.rstrip().endswith('\"\"\"'):\n line = infile.readline()\n return find_comment(infile, line)\n else:\n line = infile.readline()\n\n... | [
4,
2,
1,
1,
1
] | [] | [] | [
"python",
"python_3.x",
"string"
] | stackoverflow_0000929169_python_python_3.x_string.txt |
Q:
Why doesn't inspect.getsource return the whole class source?
I have this code in my forms.py:
from django import forms
from formfieldset.forms import FieldsetMixin
class ContactForm(forms.Form, FieldsetMixin):
full_name = forms.CharField(max_length=120)
email = forms.EmailField()
website = forms.URLFi... | Why doesn't inspect.getsource return the whole class source? | I have this code in my forms.py:
from django import forms
from formfieldset.forms import FieldsetMixin
class ContactForm(forms.Form, FieldsetMixin):
full_name = forms.CharField(max_length=120)
email = forms.EmailField()
website = forms.URLField()
message = forms.CharField(max_length=500, widget=forms.... | [
"edit: revised based on comments:\nInside inspect.getsource(forms.ContactForm) the method BlockFinder.tokeneater() is used to determine where the ContactForm block stops. Besides others, it checks for tokenize.DEDENT, which it finds right before fieldsets in your version stored at github. The line contains only a l... | [
1,
0
] | [] | [] | [
"code_inspection",
"inspect",
"python"
] | stackoverflow_0000929472_code_inspection_inspect_python.txt |
Q:
Django ORM Query to limit for the specific key instance
Projectfundingdetail has a foreign key to project.
The following query gives me the list of all projects that have any projectfundingdetail under 1000. How do I limit it to latest projectfundingdetail only.
projects_list.filter(projectfundingdetail__budget__l... | Django ORM Query to limit for the specific key instance | Projectfundingdetail has a foreign key to project.
The following query gives me the list of all projects that have any projectfundingdetail under 1000. How do I limit it to latest projectfundingdetail only.
projects_list.filter(projectfundingdetail__budget__lte=1000).distinct()
I have defined the following function,
d... | [
"This query is harder than it looks at first glance. AFAIK the Django ORM does not provide any way to generate efficient SQL for this query, because the efficient SQL requires a correlated subquery. (I'd love to be corrected on this!) You can generate some ugly SQL with this query:\nProjectfundingdetail.objects.a... | [
3
] | [] | [] | [
"django",
"django_models",
"django_orm",
"orm",
"python"
] | stackoverflow_0000929468_django_django_models_django_orm_orm_python.txt |
Q:
How can I count unique terms in a plaintext file case-insensitively?
This can be in any high-level language that is likely to be available on a typical unix-like system (Python, Perl, awk, standard unix utils {sort, uniq}, etc). Hopefully it's fast enough to report the total number of unique terms for a 2MB text f... | How can I count unique terms in a plaintext file case-insensitively? | This can be in any high-level language that is likely to be available on a typical unix-like system (Python, Perl, awk, standard unix utils {sort, uniq}, etc). Hopefully it's fast enough to report the total number of unique terms for a 2MB text file.
I only need this for quick sanity-checking, so it doesn't need to be ... | [
"In Perl:\nmy %words; \nwhile (<>) { \n map { $words{lc $_} = 1 } split /\\s/); \n} \nprint scalar keys %words, \"\\n\";\n\n",
"Using bash/UNIX commands:\nsed -e 's/[[:space:]]\\+/\\n/g' $FILE | sort -fu | wc -l\n\n",
"In Python 2.4 (possibly it works on earlier systems as well):\n#! /usr/bin/python2.4\nimpo... | [
6,
5,
4,
4,
4,
3,
3,
0
] | [] | [] | [
"awk",
"count",
"perl",
"python",
"unix"
] | stackoverflow_0000914382_awk_count_perl_python_unix.txt |
Q:
How do I call template defs with names only known at runtime in the Python template language Mako?
I am trying to find a way of calling def templates determined by the data available in the context.
Edit: A simpler instance of the same question.
It is possible to emit the value of an object in the context:
# in p... | How do I call template defs with names only known at runtime in the Python template language Mako? | I am trying to find a way of calling def templates determined by the data available in the context.
Edit: A simpler instance of the same question.
It is possible to emit the value of an object in the context:
# in python
ctx = Context(buffer, website='stackoverflow.com')
# in mako
<%def name="body()">
I visit ${websi... | [
"Takes some playing with mako's local namespace, but here's a working example:\nfrom mako.template import Template\nfrom mako.runtime import Context\nfrom StringIO import StringIO\n\nmytemplate = Template(\"\"\"\n<%def name='html_link(w)'>\n<a href='http://${w}'>${w}</a>\n</%def>\n<%def name='text_link(w)'>\n${w}\n... | [
1,
0
] | [] | [] | [
"mako",
"python",
"templates"
] | stackoverflow_0000923837_mako_python_templates.txt |
Q:
SDL or PyGame international input
So basically, how is non-western input handled in SDL or OpenGL games or applications? Googling for it reveals http://sdl-im.csie.net/ but that doesn't seem to be maintained or available anymore. Just to view the page I had to use the Google cache.
To clarify, I'm not having a... | SDL or PyGame international input | So basically, how is non-western input handled in SDL or OpenGL games or applications? Googling for it reveals http://sdl-im.csie.net/ but that doesn't seem to be maintained or available anymore. Just to view the page I had to use the Google cache.
To clarify, I'm not having any kind of issue in terms of the applic... | [
"You are interested in SDL_EnableUNICODE(). When you enable unicode translation, you can use the unicode field of SDL_keysym structure to get the unicode character based on the key user typed.\nGenerally I think whenever you do text input (e.g. user focuses on a textbox) you should use the unicode field and not att... | [
3,
1,
0
] | [] | [] | [
"internationalization",
"python",
"sdl"
] | stackoverflow_0000394618_internationalization_python_sdl.txt |
Q:
Python regex - conditional matching?
I don't know if that's the right word for it, but I am trying to come up with some regex's that can extract coefficients and exponents from a mathematical expression. The expression will come in the form 'axB+cxD+exF' where the lower case letters are the coefficients and the u... | Python regex - conditional matching? | I don't know if that's the right word for it, but I am trying to come up with some regex's that can extract coefficients and exponents from a mathematical expression. The expression will come in the form 'axB+cxD+exF' where the lower case letters are the coefficients and the uppercase letters are the exponents. I hav... | [
"You can use positive look-ahead to match something that is followed by something else. To match the coefficients, you can use:\n>>> s = '3x3+6x2+2x1+8x0'\n>>> re.findall(r'\\d+(?=x)', s)\n['3', '6', '2', '8']\n\nFrom the documentation of the re module:\n\n(?=...)\n Matches if ... matches next, but doesn’t con... | [
4,
1,
1
] | [] | [] | [
"python",
"regex"
] | stackoverflow_0000930834_python_regex.txt |
Q:
Django Shell shortcut in Windows
I'm trying to write a bat file so I can quickly launch into the Interactive Shell for one of my Django projects.
Basically I need to write a python script that can launch "manage.py shell" and then be able to print from mysite.myapp.models import *
The problem is manage.py shell ca... | Django Shell shortcut in Windows | I'm trying to write a bat file so I can quickly launch into the Interactive Shell for one of my Django projects.
Basically I need to write a python script that can launch "manage.py shell" and then be able to print from mysite.myapp.models import *
The problem is manage.py shell cannot take additional arguments and lau... | [
"First download django-extensions from google code. search for \"django command-extensions\"\nDownload and install it by running setup.py install from within the folder (it has a file called \"setup.py\")\nYou will then be able to run manage.py shell_plus instead of manage.py shell, giving you an enhanced version o... | [
2
] | [] | [] | [
"batch_file",
"command_line",
"django",
"python",
"windows_xp"
] | stackoverflow_0000930641_batch_file_command_line_django_python_windows_xp.txt |
Q:
Python AppEngine; get user info and post parameters?
Im checking the examples google gives on how to start using python; especifically the code posted here; http://code.google.com/appengine/docs/python/gettingstarted/usingdatastore.html
The thing that i want to lean is that, here:
class Guestbook(webapp.RequestHan... | Python AppEngine; get user info and post parameters? | Im checking the examples google gives on how to start using python; especifically the code posted here; http://code.google.com/appengine/docs/python/gettingstarted/usingdatastore.html
The thing that i want to lean is that, here:
class Guestbook(webapp.RequestHandler):
def post(self):
greeting = Greeting()
if... | [
"The problem is, self.redirect cannot \"carry along\" the payload of a POST HTTP request, so (from a post method) the redirection to the login-url &c is going to misbehave (in fact I believe the login URL will use get to continue when it's done, and that there's no way to ask it to do a post instead).\nIf you don't... | [
3
] | [] | [] | [
"google_app_engine",
"python"
] | stackoverflow_0000930578_google_app_engine_python.txt |
Q:
Scalable web application with lot of image servings
I started working on a web application. This application needs lot of image handling. I started off with PHP as it was the easiest and cheapest to host. I have used the .NET framework for some of my previous applications and I'm very comfortable with Python.
But... | Scalable web application with lot of image servings | I started working on a web application. This application needs lot of image handling. I started off with PHP as it was the easiest and cheapest to host. I have used the .NET framework for some of my previous applications and I'm very comfortable with Python.
But I'm not at all comfortable using PHP now, so I have deci... | [
"Please buy Schlossnagle's book, Scalable Internet Architectures.\nYou should not be serving the images from Python (or PHP or .Net) but from Apache and Squid. Same is true for Javascript and CSS files -- they're static media, and Python should never touch them. \nYou should only be processing the HTML portion of... | [
1,
1,
0,
0,
0,
0
] | [] | [] | [
".net",
"python",
"scalability"
] | stackoverflow_0000919248_.net_python_scalability.txt |
Q:
How do I inspect the scope of a function where Python raises an exception?
I've recently discovered the very useful '-i' flag to Python
-i : inspect interactively after running script, (also PYTHONINSPECT=x)
and force prompts, even if stdin does not appear to be a terminal
this is great for inspecti... | How do I inspect the scope of a function where Python raises an exception? | I've recently discovered the very useful '-i' flag to Python
-i : inspect interactively after running script, (also PYTHONINSPECT=x)
and force prompts, even if stdin does not appear to be a terminal
this is great for inspecting objects in the global scope, but what happens if the exception was raised in ... | [
"At the interactive prompt, immediately type\n>>> import pdb\n>>> pdb.pm()\n\npdb.pm() is the \"post-mortem\" debugger. It will put you at the scope where the exception was raised, and then you can use the usual pdb commands.\nI use this all the time. It's part of the standard library (no ipython necessary) and doe... | [
7,
5,
4
] | [] | [] | [
"debugging",
"python"
] | stackoverflow_0000906649_debugging_python.txt |
Q:
Debug some Python code
Edit: You can get the full source here: http://pastebin.com/m26693
Edit again: I added some highlights to the pastebin page. http://pastebin.com/m10f8d239
I'm probably going to regret asking such a long question, but I'm stumped with this bug and I could use some guidance. You're going to ha... | Debug some Python code | Edit: You can get the full source here: http://pastebin.com/m26693
Edit again: I added some highlights to the pastebin page. http://pastebin.com/m10f8d239
I'm probably going to regret asking such a long question, but I'm stumped with this bug and I could use some guidance. You're going to have to run this code (edit: n... | [
"It appears that your code was truncated, so I can't look through it.\nGiven that you only get the extra argument on methods defined in a class, though, might it be the self variable? Every method on a Python class receives self as the first parameter, and if you don't account for it, you'll get things wrong.\nIn ... | [
2,
1
] | [] | [] | [
"debugging",
"python"
] | stackoverflow_0000931211_debugging_python.txt |
Q:
Getting friends within a specified degree of separation
all. I'm a very, very new programmer. My language of choice at the moment is Python, and I feel like I have a decent feel for it. I'm just now starting to learn about recursion. (By the way, if anyone could recommend a good guide on this, please let me kno... | Getting friends within a specified degree of separation | all. I'm a very, very new programmer. My language of choice at the moment is Python, and I feel like I have a decent feel for it. I'm just now starting to learn about recursion. (By the way, if anyone could recommend a good guide on this, please let me know!) Just so you all know, this question is very elementary, a... | [
"friendList = friendList.append(self)\n\nThis sets friendList to None, unconditionally, as that's the invariable return value of any list's append method -- so, fix that weirdness first...!-)\nOnce you've fixed that, you still need to fix the function so that it always ends with return of something -- \"falling off... | [
14,
1,
1,
1,
1
] | [] | [] | [
"python",
"recursion"
] | stackoverflow_0000931323_python_recursion.txt |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.