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:
How to count possibilities in python lists
Given a list like this:
num = [1, 2, 3, 4, 5]
There are 10 three-element combinations:
[123, 124, 125, 134, 135, 145, 234, 235, 245, 345]
How can I generate this list?
A:
Use itertools.combinations:
import itertools
num = [1, 2, 3, 4, 5]
combinations = []
for combina... | How to count possibilities in python lists | Given a list like this:
num = [1, 2, 3, 4, 5]
There are 10 three-element combinations:
[123, 124, 125, 134, 135, 145, 234, 235, 245, 345]
How can I generate this list?
| [
"Use itertools.combinations:\nimport itertools\n\nnum = [1, 2, 3, 4, 5]\ncombinations = []\nfor combination in itertools.combinations(num, 3):\n combinations.append(int(\"\".join(str(i) for i in combination)))\n# => [123, 124, 125, 134, 135, 145, 234, 235, 245, 345]\nprint len(combinations)\n# => 10\n\nEdit\nYou... | [
10,
5,
2,
2
] | [] | [] | [
"python"
] | stackoverflow_0001367550_python.txt |
Q:
How can I update an attribute created by a base class' mutable default argument, without modifying that argument?
I've found a strange issue with subclassing and dictionary updates in new-style classes:
Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)] on
win32
>>> class a(object):
... ... | How can I update an attribute created by a base class' mutable default argument, without modifying that argument? | I've found a strange issue with subclassing and dictionary updates in new-style classes:
Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)] on
win32
>>> class a(object):
... def __init__(self, props={}):
... self.props = props
...
>>> class b(a):
... def __init__(self, val ... | [
"props should not have a default value like that. Do this instead:\nclass a(object):\n def __init__(self, props=None):\n if props is None:\n props = {}\n self.props = props\n\nThis is a common python \"gotcha\".\n",
"Your problem is in this line:\ndef __init__(self, props={}):\n\n{} is... | [
19,
8,
3
] | [] | [] | [
"dictionary",
"python",
"super"
] | stackoverflow_0001367883_dictionary_python_super.txt |
Q:
simplifying data structures and condition statements in python code
I was wondering if there are any ways to simplify the following piece of Code. As you can see, there are numerous dicts being used as well as condition statements to weed out bad input data. Note that the trip rate values are not all inputed yet, ... | simplifying data structures and condition statements in python code | I was wondering if there are any ways to simplify the following piece of Code. As you can see, there are numerous dicts being used as well as condition statements to weed out bad input data. Note that the trip rate values are not all inputed yet, the dicts are just copied and pasted for now
EDIT
In any of the rates, (x... | [
"Well, where to start? Here is just a first observation:\nYou have a lot of data there, and it seems code and data are mixed into each other.\nData and Code should be separate. Data is an external source, something you modify or read in. You could probably adapt your code to quickly parse Data from a good editable ... | [
5,
2
] | [] | [] | [
"conditional",
"data_structures",
"python"
] | stackoverflow_0001367913_conditional_data_structures_python.txt |
Q:
How to create objects dynamically in an elegant way in python?
I have two classes that I would like to merge into a composite. These two classes will continue to be used standalone and I don't want to modify them.
For some reasons, I want to let my composite class creating the objects. I am thinking about somethi... | How to create objects dynamically in an elegant way in python? | I have two classes that I would like to merge into a composite. These two classes will continue to be used standalone and I don't want to modify them.
For some reasons, I want to let my composite class creating the objects. I am thinking about something like the code below (it is just an example) but I think it is com... | [
"You could shorten it by removing type-checking _make_object, and letting class constructors take care of the default arguments, e.g.\nclass Composite(Parent):\n def __init__(self, x, list_of_classes, list_of_args):\n Parent.__init__(self, x)\n self._objs = [\n the_class(self.x, *the_arg... | [
2
] | [] | [] | [
"python"
] | stackoverflow_0001367819_python.txt |
Q:
Java equivalent of a Python functionality -> set(string)
I want to mimic a Python functionality in Java.
In Python if I want unique characters in a string I can do just,
text = "i am a string"
print set(text) # o/p is set(['a', ' ', 'g', 'i', 'm', 'n', 's', 'r', 't'])
How can I do this in Java trivially or direc... | Java equivalent of a Python functionality -> set(string) | I want to mimic a Python functionality in Java.
In Python if I want unique characters in a string I can do just,
text = "i am a string"
print set(text) # o/p is set(['a', ' ', 'g', 'i', 'm', 'n', 's', 'r', 't'])
How can I do this in Java trivially or directly?
| [
"String str = \"i am a string\";\nSystem.out.println(new HashSet<String>(Arrays.asList(str.split(\"\"))));\n\nEDIT: For those who object that they aren't exactly equivalent because str.split will include an empty string in the set, we can do it even more verbose:\nString str = \"i am a string\";\nSet<String> set = ... | [
10
] | [] | [] | [
"java",
"python",
"set"
] | stackoverflow_0001368181_java_python_set.txt |
Q:
python file-like buffer object
I've written a buffer class that provides a File-like interface with read, write, seek, tell, flush methods to a simple string in memory. Of course it is incomplete (e.g. I didn't write readline). It's purpose is to be filled by a background thread from some external data source, but... | python file-like buffer object | I've written a buffer class that provides a File-like interface with read, write, seek, tell, flush methods to a simple string in memory. Of course it is incomplete (e.g. I didn't write readline). It's purpose is to be filled by a background thread from some external data source, but let a user treat it like a file. I'... | [
"You can use the standard Python modules StringIO or cStringIO to obtain an in-memory buffer which implements the file interface.\ncStringIO is implemented in C, and will be faster, so you should use that version if possible.\nIf you're using Python 3 you should use the io.StringIO instead of StringIO and io.BytesI... | [
27,
7
] | [] | [] | [
"buffer",
"io",
"python"
] | stackoverflow_0001368261_buffer_io_python.txt |
Q:
How do I unit test Django Views?
I want to begin integrating unit tests into my Django projects and I've discovered unit testing a view to be tricky because of the way Django implements views with functions.
For example, each function is a view/page in Django if the function has a URL.
How do I unit test Django v... | How do I unit test Django Views? | I want to begin integrating unit tests into my Django projects and I've discovered unit testing a view to be tricky because of the way Django implements views with functions.
For example, each function is a view/page in Django if the function has a URL.
How do I unit test Django views?
| [
"I'm not sure how testing a view is tricky.\nYou just use the test client.\nCode coverage is easy. You reason how how a URL request maps to a code path and make the appropriate URL requests.\nYou can, if you want, call the view functions \"manually\" by creating a Request object and examining the Response object, ... | [
11,
2,
0
] | [] | [] | [
"django",
"python",
"unit_testing",
"views"
] | stackoverflow_0001368255_django_python_unit_testing_views.txt |
Q:
Default encoding of exception messages
The following code examines the behaviour of the float() method when fed a non-ascii symbol:
import sys
try:
float(u'\xbd')
except ValueError as e:
print sys.getdefaultencoding() # in my system, this is 'ascii'
print e[0].decode('latin-1') # u'invalid literal for float... | Default encoding of exception messages | The following code examines the behaviour of the float() method when fed a non-ascii symbol:
import sys
try:
float(u'\xbd')
except ValueError as e:
print sys.getdefaultencoding() # in my system, this is 'ascii'
print e[0].decode('latin-1') # u'invalid literal for float(): ' followed by the 1/2 (one half) charact... | [
"e[0] isn't encoded with latin-1; it just so happens that the byte \\xbd, when decoded as latin-1, is the character U+00BD.\nThe conversion occurs in Objects/floatobject.c.\nFirst, the unicode string must be converted to a byte string. This is performed using PyUnicode_EncodeDecimal():\nif (PyUnicode_EncodeDecimal(... | [
9,
5,
2,
0
] | [] | [] | [
"encoding",
"exception",
"python",
"python_2.x"
] | stackoverflow_0001369089_encoding_exception_python_python_2.x.txt |
Q:
Managing Python Path When Moving Code from Development Computer to Target
I have a python project with this directory structure and these files:
/home/project_root
|---__init__.py
|---setup
|---__init__.py
|---configs.py
|---test_code
|---__init__.py
|---tester.py
The tester script imp... | Managing Python Path When Moving Code from Development Computer to Target | I have a python project with this directory structure and these files:
/home/project_root
|---__init__.py
|---setup
|---__init__.py
|---configs.py
|---test_code
|---__init__.py
|---tester.py
The tester script imports from setup/configs.py with the reference "setup.configs". It runs fine on... | [
"Stick this in the tester script right before the import setup.configs\nimport sys\nimport os\nsys.path.insert(0, os.path.join(os.path.dirname(__file__), os.path.pardir))\n\nsys.path is a list of all the directories the python interpreter looks for when importing a python module.\nThis will add the parent directory... | [
4,
0,
0
] | [] | [] | [
"path",
"python",
"pythonpath"
] | stackoverflow_0001369159_path_python_pythonpath.txt |
Q:
Split a list of dates by another list of dates
I have a number of nodes in a network. The nodes send status information every hour to indicate that they are alive. So i have a list of Nodes and the time when they were last alive. I want to graph the number of alive nodes over the time.
The list of nodes is sorted ... | Split a list of dates by another list of dates | I have a number of nodes in a network. The nodes send status information every hour to indicate that they are alive. So i have a list of Nodes and the time when they were last alive. I want to graph the number of alive nodes over the time.
The list of nodes is sorted by the time they were last alive but i cant figure o... | [
"this generator traverses the list only once:\ndef get_alive(seen, dates):\n c = len(seen)\n for date in dates:\n for s in seen[-c:]:\n if s >= date: # replaced your > for >= as it seems to make more sense\n yield c\n break\n else:\n ... | [
2,
1,
1
] | [] | [] | [
"performance",
"python"
] | stackoverflow_0001368802_performance_python.txt |
Q:
referencing class methods in class lists in Python
I am writing a class in Python 2.6.2 that contains a lookup table. Most cases are simple enough that the table contains data. Some of the cases are more complex and I want to be able call a function. However, I'm running into some trouble referencing the funct... | referencing class methods in class lists in Python | I am writing a class in Python 2.6.2 that contains a lookup table. Most cases are simple enough that the table contains data. Some of the cases are more complex and I want to be able call a function. However, I'm running into some trouble referencing the function.
Here's some sample code:
class a:
lut = [1,
... | [
"In the clas body, you're creating the class; there is no self, so you obviously cannot yet refer to self.anything. But also within that body there is as yet no a: name a gets bound AFTER the class body is done. So, although that's a tad less obvious, in the body of class a you cannot refer to a.anything either, ye... | [
4,
3,
1,
0,
0,
0
] | [
"You're going to need to move the definition of a.lut outside of the definition of a. \nclass a():\n def spam():pass\n\na.lut = [1,2,3,a.spam]\n\nIf you think about it, this makes perfect sense. Using self wouldn't work because self is actually only defined for class methods for which you use the parameter \"s... | [
-1
] | [
"class",
"python",
"reference"
] | stackoverflow_0001351669_class_python_reference.txt |
Q:
How does Django determine if an uploaded image is valid?
I'm trying to add images to my models in my Django app.
models.py
class ImageMain(models.Model):
"""This is the Main Image of the product"""
product = models.ForeignKey(Product)
photo = models.ImageField(upload_to='products')
In development mode, ev... | How does Django determine if an uploaded image is valid? | I'm trying to add images to my models in my Django app.
models.py
class ImageMain(models.Model):
"""This is the Main Image of the product"""
product = models.ForeignKey(Product)
photo = models.ImageField(upload_to='products')
In development mode, every time I try to upload the image via Django admin, I keep ge... | [
"According to Django's source code. Those three lines are responsible for verifying images:\nfrom PIL import Image\ntrial_image = Image.open(file)\ntrial_image.verify()\n\nThe image type could be unsupported by PIL. Check the list of supported formats here\n",
"Did you try uploading image format like gif or png? ... | [
12,
2,
0
] | [] | [] | [
"django",
"python",
"python_imaging_library"
] | stackoverflow_0001368724_django_python_python_imaging_library.txt |
Q:
How would you query Picasa from a Google App Engine app? Data API or Url Fetch?
How would you query Picasa from a Google App Engine app? Data API or Url Fetch? What are the pros and cons of using either method?
[Edit]
I would like to be able to query a specific album in Picasa and list all the photos in it.
Code e... | How would you query Picasa from a Google App Engine app? Data API or Url Fetch? | How would you query Picasa from a Google App Engine app? Data API or Url Fetch? What are the pros and cons of using either method?
[Edit]
I would like to be able to query a specific album in Picasa and list all the photos in it.
Code examples to do this in python are much appreciated.
| [
"Your question is a little off, since the Data API is exposed through RESTful URLs, so both methods are ultimately a \"URL Fetch\".\nThe Data API works quite well, though. It gives you access to nearly all the functionality of Picasa, and responses are sent back and forth in well-formed, well-documented XML. Google... | [
2
] | [] | [] | [
"api",
"google_app_engine",
"picasa",
"python",
"urlfetch"
] | stackoverflow_0001369861_api_google_app_engine_picasa_python_urlfetch.txt |
Q:
Python .pth Files Aren't Working
Directories listed in my .pth configuration file aren't appearing in sys.path.
The contents of configuration file, named some_code_dirs.pth:
/home/project
Paths to the file:
/usr/lib/python2.6/site-packages/some_code_dirs.pth
/usr/lib/python2.6/some_code_dirs.pth
Check on sys var... | Python .pth Files Aren't Working | Directories listed in my .pth configuration file aren't appearing in sys.path.
The contents of configuration file, named some_code_dirs.pth:
/home/project
Paths to the file:
/usr/lib/python2.6/site-packages/some_code_dirs.pth
/usr/lib/python2.6/some_code_dirs.pth
Check on sys variables in the python interpreter:
>>> ... | [
"What OS are you using? On my Ubuntu 9.04 system that directory is not in sys.path.\nTry putting it into /usr/lib/python2.6/dist-packages. Notice that it is dist instead of site.\n",
"I had a similar problem a while ago. Check the encoding of your pth-file. It seems that pth-files are silently ignored if encoded ... | [
4,
0
] | [] | [] | [
"python",
"pythonpath"
] | stackoverflow_0001369947_python_pythonpath.txt |
Q:
Why is my "exploded" Python code actually running faster?
I'm in an introductory comp-sci class (after doing web programming for years) and became curious about how much speed I was gaining, if any, with my one-liners.
for line in lines:
numbers.append(eval(line.strip().split()[0]))
So I wrote the same thing wi... | Why is my "exploded" Python code actually running faster? | I'm in an introductory comp-sci class (after doing web programming for years) and became curious about how much speed I was gaining, if any, with my one-liners.
for line in lines:
numbers.append(eval(line.strip().split()[0]))
So I wrote the same thing with painfully explicit assignments and ran them against each oth... | [
"Your code isn't exploded in the same order. The compact version goes:\nA > B > C > D > E \n\nwhile your exploded version goes \nB > C > A > D > E\n\nThe effect is that strip() is being deferred 2 steps down, which may affect performance depending on what the input is.\n",
"Frankly speaking, the first version, w... | [
15,
7,
4,
3,
3,
3,
2,
2
] | [] | [] | [
"optimization",
"python"
] | stackoverflow_0001369697_optimization_python.txt |
Q:
random.choice not random
I'm using Python 2.5 on Linux, in multiple parallel FCGI processes. I use
chars = string.ascii_letters + string.digits
cookie = ''.join([random.choice(chars) for x in range(32)])
to generate distinct cookies. Assuming that the RNG is seeded from /dev/urandom, and that the sequence... | random.choice not random | I'm using Python 2.5 on Linux, in multiple parallel FCGI processes. I use
chars = string.ascii_letters + string.digits
cookie = ''.join([random.choice(chars) for x in range(32)])
to generate distinct cookies. Assuming that the RNG is seeded from /dev/urandom, and that the sequence of random numbers comes from ... | [
"It shouldn't be generating duplicates.\nimport random\nchars = \"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\"\ndef gen():\n return ''.join([random.choice(chars) for x in range(32)])\n\ntest = [gen() for i in range(100000)]\nprint len(test), len(set(test)) # 100000 100000\n\nThe chances of du... | [
13,
4,
1,
0
] | [
"To avoid the problem, you can use a sequence of cookies, that are guaranteed to be different (you can e.g. use a set). Each time you give a cookie to someone, you take it from the sequence and you add another to it. Another option is to generate a UUID and use that as a cookie.\nAnother way to avoid the problem co... | [
-4
] | [
"python",
"random"
] | stackoverflow_0001366047_python_random.txt |
Q:
Django - flush response?
I am sending an AJAX request to a Django view that can potentially take a lot of time. It goes through some well-defined steps, however, so I would like to print status indicators to the user letting it know when it is finished doing a certain thing and has moved on to the next.
If I was u... | Django - flush response? | I am sending an AJAX request to a Django view that can potentially take a lot of time. It goes through some well-defined steps, however, so I would like to print status indicators to the user letting it know when it is finished doing a certain thing and has moved on to the next.
If I was using PHP it might look like th... | [
"Most webservers (eg. FCGI/SCGI) do their own buffering, HTTP clients do their own, and so on. It's very difficult to actually get data flushed out in this way and for the client to actually receive it, because it's not a typical operation.\nThe closest to what you're trying to do would be to pass an iterator to H... | [
9,
4
] | [] | [] | [
"django",
"python"
] | stackoverflow_0001371020_django_python.txt |
Q:
Limit choices to
I have a model named Project which has a m2m field users. I have a task model with a FK project. And it has a field assigned_to. How can i limit the choices of assigned_to to only the users of the current project?
A:
You could do this another way, using this nifty form factory trick.
def make_ta... | Limit choices to | I have a model named Project which has a m2m field users. I have a task model with a FK project. And it has a field assigned_to. How can i limit the choices of assigned_to to only the users of the current project?
| [
"You could do this another way, using this nifty form factory trick.\ndef make_task_form(project):\n class _TaskForm(forms.Form):\n assigned_to = forms.ModelChoiceField(\n queryset=User.objects.filter(user__project=project))\n\n class Meta:\n model = Task\n return _TaskFo... | [
1,
0
] | [] | [] | [
"django_models",
"python"
] | stackoverflow_0001239433_django_models_python.txt |
Q:
REST / JSON / XML-RPC / SOAP
Sorry for being the 100000th person to ask the same question. But I guess my case is slightly distinctive.
The application is that we'd like to have an Android phone client on 3g and a light python web service server.
The phone would do most of the work and do a lot of uploading, pictu... | REST / JSON / XML-RPC / SOAP | Sorry for being the 100000th person to ask the same question. But I guess my case is slightly distinctive.
The application is that we'd like to have an Android phone client on 3g and a light python web service server.
The phone would do most of the work and do a lot of uploading, pictures, GPS, etc etc. The server just... | [
"REST mandates the general semantics and concepts. The transport and encodings are up to you. They were originally formulated on XML, but JSON is totally applicable.\nXML-RPC / SOAP are different mechanisms, but mostly the same ideas: how to map OO APIs on top of XML and HTTP. IMHO, they're disgusting from a des... | [
7
] | [] | [] | [
"android",
"python",
"service"
] | stackoverflow_0001371312_android_python_service.txt |
Q:
How to distribute and execute platform-specific unit tests?
We have a python project that we want to start testing using buildbot. Its unit tests include tests that should only work on some platforms. So, we've got tests that should pass on all platforms, tests that should only run on 1 specific platform, tests th... | How to distribute and execute platform-specific unit tests? | We have a python project that we want to start testing using buildbot. Its unit tests include tests that should only work on some platforms. So, we've got tests that should pass on all platforms, tests that should only run on 1 specific platform, tests that should pass on platforms A, B, C and tests that pass on B and ... | [
"On a couple of occasions I have used this very simple approach in test modules:\nimport sys\nimport unittest\n\nif 'win' in sys.platform:\n class TestIt(unittest.TestCase):\n ...\n\nif 'linux' in sys.platform:\n class TestIt(unittest.TestCase):\n ...\n\n",
"Sounds like a handy place for a te... | [
2,
0,
0
] | [] | [] | [
"buildbot",
"python",
"unit_testing"
] | stackoverflow_0001199493_buildbot_python_unit_testing.txt |
Q:
Django: retrieve all galleries containing one public photo at least
excuse me for my ugly english) !
Imagine these very simple models :
class Photo(models.Model):
is_public = models.BooleanField('Public', default=False)
class Gallery(models.Model):
photos = models.ManyToManyField('Photos', related_name='g... | Django: retrieve all galleries containing one public photo at least | excuse me for my ugly english) !
Imagine these very simple models :
class Photo(models.Model):
is_public = models.BooleanField('Public', default=False)
class Gallery(models.Model):
photos = models.ManyToManyField('Photos', related_name='galleries', null=True, blank=True)
I need to select all Gallery instances... | [
"This should do it:\nEdit, updated to add count:\nSELECT `gallery`.*, 'a'.'count' \nFROM `gallery` \ninner join (\n select `gallery`.`id`, count(*) as count\n from `gallery_photos` \n INNER JOIN `photo` ON (`gallery_photos`.`photo_id` = `photo`.`id`) \n where `photo`.`is_public` = True\n group by `ga... | [
0,
0,
0,
0
] | [] | [] | [
"count",
"django",
"django_models",
"python",
"sql"
] | stackoverflow_0001366943_count_django_django_models_python_sql.txt |
Q:
query for values based on date w/ Django ORM
I have a bunch of objects that have a value and a date field:
obj1 = Obj(date='2009-8-20', value=10)
obj2 = Obj(date='2009-8-21', value=15)
obj3 = Obj(date='2009-8-23', value=8)
I want this returned:
[10, 15, 0, 8]
or better yet, an aggregate of the total up to that ... | query for values based on date w/ Django ORM | I have a bunch of objects that have a value and a date field:
obj1 = Obj(date='2009-8-20', value=10)
obj2 = Obj(date='2009-8-21', value=15)
obj3 = Obj(date='2009-8-23', value=8)
I want this returned:
[10, 15, 0, 8]
or better yet, an aggregate of the total up to that point:
[10, 25, 25, 33]
I would be best to get th... | [
"This one isn't tested, since it's a bit too much of a pain to set up a Django table to test with:\nfrom datetime import date, timedelta\n# http://www.ianlewis.org/en/python-date-range-iterator\ndef datetimeRange(from_date, to_date=None):\n while to_date is None or from_date <= to_date:\n yield from_date\... | [
4,
0,
0
] | [] | [] | [
"django",
"django_orm",
"python"
] | stackoverflow_0001371280_django_django_orm_python.txt |
Q:
Python Changing module variables in another module
Say I am importing the module 'foo' into the module 'bar'.
Is it possible for me to change a global variable in foo inside bar?
Let the global variable in foo be 'arbit'.
Change arbit so that if bar were to call a function of foo that uses this variable, the upda... | Python Changing module variables in another module | Say I am importing the module 'foo' into the module 'bar'.
Is it possible for me to change a global variable in foo inside bar?
Let the global variable in foo be 'arbit'.
Change arbit so that if bar were to call a function of foo that uses this variable, the updated variable is used rather than the one before that.
| [
"You should be able to do:\nimport foo\nfoo.arbit = 'new value'\n\n"
] | [
9
] | [] | [] | [
"module",
"python"
] | stackoverflow_0001372486_module_python.txt |
Q:
What non web-oriented Python frameworks exist?
I'm looking for a good framework on which to base my applications development.
In PHP I use Symfony, in ActionScript PureMVC, they are all MVC frameworks.
I'm looking for a Python framework being oriented towards general purpose application development, not web applic... | What non web-oriented Python frameworks exist? | I'm looking for a good framework on which to base my applications development.
In PHP I use Symfony, in ActionScript PureMVC, they are all MVC frameworks.
I'm looking for a Python framework being oriented towards general purpose application development, not web application. I mean, just applications, services, daemons ... | [
"For network services needing to handle numerous connections asynchronously, a great many people favor Twisted.\nOutside of that (and web applications), however, there's simply less need for overarching frameworks in Python than with many other languages -- the core language itself is expressive, powerful, and come... | [
9,
6,
6,
3,
3,
1,
0,
0
] | [] | [] | [
"frameworks",
"python"
] | stackoverflow_0001368364_frameworks_python.txt |
Q:
Aliasing a class in Python
I am writing a class to implement an algorithm. This algorithm has three levels of complexity. It makes sense to me to implement the classes like this:
class level0:
def calc_algorithm(self):
# level 0 algorithm
pass
# more level0 stuff
class level1(level0):
... | Aliasing a class in Python | I am writing a class to implement an algorithm. This algorithm has three levels of complexity. It makes sense to me to implement the classes like this:
class level0:
def calc_algorithm(self):
# level 0 algorithm
pass
# more level0 stuff
class level1(level0):
def calc_algorithm(self):
... | [
"Are you looking for something along these lines?\ndispatch = {0: level0, 1: level1, 2:level2}\ndispatch[offset].calc_algorithm\n\nKeys (and offset), obviously, could come from command line.\n",
"dispatch = {0:level0, 1:level1, 2:level2}\nalgo = dispatch[offset]() # \"calling\" a class constructs an instance.\n... | [
11,
4,
3,
2
] | [] | [] | [
"class",
"python"
] | stackoverflow_0001369534_class_python.txt |
Q:
Algorithm to filter a set of all phrases containing in other phrase
Given a set of phrases, i would like to filter the set of all phrases that contain any of the other phrases. Contained here means that if a phrase contains all the words of another phrase it should be filtered out. Order of the words within the ph... | Algorithm to filter a set of all phrases containing in other phrase | Given a set of phrases, i would like to filter the set of all phrases that contain any of the other phrases. Contained here means that if a phrase contains all the words of another phrase it should be filtered out. Order of the words within the phrase does not matter.
What i have so far is this:
Sort the set by the nu... | [
"You could build an index which maps words to phrases and do something like:\n\nlet matched = set of all phrases\nfor each word in the searched phrase\n let wordMatch = all phrases containing the current word\n let matched = intersection of matched and wordMatch\n\nAfter this, matched would contain all phrase... | [
1,
1,
1,
0
] | [] | [] | [
"algorithm",
"c#",
"c++",
"java",
"python"
] | stackoverflow_0001372531_algorithm_c#_c++_java_python.txt |
Q:
Is there a python library/module for creating a multi ssh connection?
I've been searching for a library that can access multiple ssh connections at once, Ruby has a Net::SSH::Multi module that allows multiple ssh connections at once. However I rather prefer coding this in Python, are there any similar SSH module f... | Is there a python library/module for creating a multi ssh connection? | I've been searching for a library that can access multiple ssh connections at once, Ruby has a Net::SSH::Multi module that allows multiple ssh connections at once. However I rather prefer coding this in Python, are there any similar SSH module for python?
| [
"Paramiko is Python's SSH library.\nI've never tried concurrent connections with Paramiko, but this answer says it's possible, and this little script seems to make multiple connections in different threads.\nThe Paramiko mailing list also confirms it's possible to make multiple connections by forking -- there was a... | [
2
] | [] | [] | [
"python",
"ruby",
"ssh"
] | stackoverflow_0001372657_python_ruby_ssh.txt |
Q:
How to insert a row with autoincrement id in a multi-primary-key table?
I am writing a turbogears2 application. I have a table like this:
class Order(DeclarativeBase):
__tablename__ = 'order'
# id of order
id = Column(Integer, autoincrement=True, primary_key=True)
# buyer's id
buyer_id = Colu... | How to insert a row with autoincrement id in a multi-primary-key table? | I am writing a turbogears2 application. I have a table like this:
class Order(DeclarativeBase):
__tablename__ = 'order'
# id of order
id = Column(Integer, autoincrement=True, primary_key=True)
# buyer's id
buyer_id = Column(Integer, ForeignKey('user.user_id',
onupdate="CASCADE", ondelete="... | [
"If you want sequential numbers per buyer for your orders then you'll have to serialize the transactions inserting to one buyer. You can do that by acquiring exclusive lock on the buyer row:\nsess.query(Buyer.id).with_lockmode('update').get(xxx)\norder_id = sess.query(func.max(Order.id)+1).filter_by(buyer_id=xxx).s... | [
1,
1
] | [] | [] | [
"database",
"python",
"sql",
"sqlalchemy"
] | stackoverflow_0001372525_database_python_sql_sqlalchemy.txt |
Q:
Reading a Django model's field options
Is it possible to read a Django model's fields' options? For example, with the model:
class MyModel(models.Model):
source_url = models.URLField(max_length=500)
...
i.e. how would I programmatically read the 'max_length' option from, say, within a view or form.
My cur... | Reading a Django model's field options | Is it possible to read a Django model's fields' options? For example, with the model:
class MyModel(models.Model):
source_url = models.URLField(max_length=500)
...
i.e. how would I programmatically read the 'max_length' option from, say, within a view or form.
My current workaround is to define a separate clas... | [
"Do it this way.\nfrom models import MyModel\ntry:\n max_length = MyModel._meta.get_field('source_url').max_length\nexcept:\n max_length = None\n\n"
] | [
5
] | [] | [] | [
"django",
"python"
] | stackoverflow_0001372706_django_python.txt |
Q:
How to convert tab separated, pipe separated to CSV file format in Python
I have a text file (.txt) which could be in tab separated format or pipe separated format, and I need to convert it into CSV file format. I am using python 2.6. Can any one suggest me how to identify the delimiter in a text file, read the da... | How to convert tab separated, pipe separated to CSV file format in Python | I have a text file (.txt) which could be in tab separated format or pipe separated format, and I need to convert it into CSV file format. I am using python 2.6. Can any one suggest me how to identify the delimiter in a text file, read the data and then convert that into comma separated file.
Thanks in advance
| [
"I fear that you can't identify the delimiter without knowing what it is. The problem with CSV is, that, quoting ESR:\n\nthe Microsoft version of CSV is a textbook example of how not to design a textual file format.\n\nThe delimiter needs to be escaped in some way if it can appear in fields. Without knowing, how th... | [
6,
1,
0,
0,
0
] | [] | [] | [
"csv",
"python"
] | stackoverflow_0001366775_csv_python.txt |
Q:
Weird python behaviour on machine with ARM CPU
What could possibly cause this weird python behaviour?
Python 2.6.2 (r262:71600, May 31 2009, 03:55:41)
[GCC 3.3.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> .1
1251938906.2350719
>>> .1
0.23507189750671387
>>> .1
0.0
>>> .1
... | Weird python behaviour on machine with ARM CPU | What could possibly cause this weird python behaviour?
Python 2.6.2 (r262:71600, May 31 2009, 03:55:41)
[GCC 3.3.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> .1
1251938906.2350719
>>> .1
0.23507189750671387
>>> .1
0.0
>>> .1
-1073741823.0
>>> .1
-1073741823.0
>>> .1
-107374182... | [
"Maybe it's compiled for the wrong VFP version.\nOr your ARM has no VFP and needs to use software emulation instead, but the python binary tries to use hardware.\n\nEDIT\nYour DS-101j build on FW IXP420 BB cpu, which is Intel XScale (armv5b) (link). It has no hardware floating-point support. And \"b\" in armv5b sta... | [
8,
0
] | [] | [] | [
"arm",
"floating_point",
"python"
] | stackoverflow_0001371228_arm_floating_point_python.txt |
Q:
Looking for the "Hello World" of ctypes unicode processing (including both Python and C code)
Can someone show me a really simple Python ctypes example involving Unicode strings including the C code?
Say, a way to take a Python Unicode string and pass it to a C function which catenates it with itself and returns t... | Looking for the "Hello World" of ctypes unicode processing (including both Python and C code) | Can someone show me a really simple Python ctypes example involving Unicode strings including the C code?
Say, a way to take a Python Unicode string and pass it to a C function which catenates it with itself and returns that to Python, which prints it.
| [
"This program uses ctypes to call wcsncat from Python. It concatenates a and b into a buffer that is not quite long enough for a + b + (null terminator) to demonstrate the safer n version of concatenation.\nYou must pass create_unicode_buffer() instead of passing a regular immutable u\"unicode string\" for non-cons... | [
6
] | [
"Untested, but I think this should work.\ns = \"inputstring\"\nmydll.my_c_fcn.restype = c_char_p\nresult = mydll.my_c_fcn(s)\nprint result\n\nAs for memory management, my understanding is that your c code needs to manage the memory it creates. That is, it should not free the input string, but eventually needs to f... | [
-1,
-1
] | [
"c",
"ctypes",
"python"
] | stackoverflow_0000890793_c_ctypes_python.txt |
Q:
How to get/set local variables of a function (from outside) in Python?
If I have a function (in Python 2.5.2) like:
def sample_func():
a = 78
b = range(5)
#c = a + b[2] - x
My questions are:
How to get the local variables (a,b) of the function from outside without using locals() inside the function? ... | How to get/set local variables of a function (from outside) in Python? | If I have a function (in Python 2.5.2) like:
def sample_func():
a = 78
b = range(5)
#c = a + b[2] - x
My questions are:
How to get the local variables (a,b) of the function from outside without using locals() inside the function? (kind of reflection)
Is it possible to set a local variable (say x) from out... | [
"No. A function that isn't being run doesn't have locals; it's just a function. Asking how to modify a function's locals when it's not running is like asking how to modify a program's heap when it's not running.\nYou can modify constants, though, if you really want to.\ndef func():\n a = 10\n print a\n\nco ... | [
18,
9,
3,
2,
1
] | [] | [] | [
"python"
] | stackoverflow_0001360721_python.txt |
Q:
save python output to log
I have a python script the runs this code:
strpath = "sudo svnadmin create /svn/repos/" + short_name
os.popen (strpath, 'w')
How can I get the output of that command stored in a variable or written to a log file in the current directory?
I know, there may not be an output, but if there i... | save python output to log | I have a python script the runs this code:
strpath = "sudo svnadmin create /svn/repos/" + short_name
os.popen (strpath, 'w')
How can I get the output of that command stored in a variable or written to a log file in the current directory?
I know, there may not be an output, but if there is, I need to know.
| [
"Use the 'r' mode to open the pipe instead:\nf = os.popen (strpath, 'r')\nfor line in f:\n print line\nf.close()\n\nSee the documentation for os.popen() for more information.\nThe subprocess module is a better way to execute external commands like this, because it allows much more control over the process execut... | [
4,
1,
0
] | [] | [] | [
"logging",
"python",
"variables"
] | stackoverflow_0001375283_logging_python_variables.txt |
Q:
What is this piece of Python code doing?
This following is a snippet of Python code I found that solves a mathematical problem. What exactly is it doing? I wasn't too sure what to Google for.
x, y = x + 3 * y, 4 * x + 1 * y
Is this a special Python syntax?
A:
x, y = x + 3 * y, 4 * x + 1 * y
is the equivalent... | What is this piece of Python code doing? | This following is a snippet of Python code I found that solves a mathematical problem. What exactly is it doing? I wasn't too sure what to Google for.
x, y = x + 3 * y, 4 * x + 1 * y
Is this a special Python syntax?
| [
"x, y = x + 3 * y, 4 * x + 1 * y\n\nis the equivalent of:\nx = x + 3 * y\ny = 4 * x + 1 * y\n\nEXCEPT that it uses the original values for x and y in both calculations - because the new values for x and y aren't assigned until both calculations are complete.\nThe generic form is:\nx,y = a,b\n\nwhere a and b are exp... | [
16,
12,
0
] | [] | [] | [
"math",
"python",
"syntax"
] | stackoverflow_0001370604_math_python_syntax.txt |
Q:
How can I call the svn.client.svn_client_list2 with python SVN API SWIG bindings?
The question
How do I call svn_client_list2 C API function from python via SVN API SWIG bindings?
Problem description
I can find that function from the svn.client module, but calling it is the problem, because the callback function i... | How can I call the svn.client.svn_client_list2 with python SVN API SWIG bindings? | The question
How do I call svn_client_list2 C API function from python via SVN API SWIG bindings?
Problem description
I can find that function from the svn.client module, but calling it is the problem, because the callback function it uses is a typedef svn_client_list_func_t and I don't know how to use that typedef in ... | [
"It looks like you can't really do this at the moment. When I dug into bit into the SWIG bindings code and documentation it says that when you're using target language functions as the callback function, you need a typemap for it as it says in the SWIG documentation:\nAlthough SWIG does not normally allow callback... | [
0
] | [] | [] | [
"python"
] | stackoverflow_0001298869_python.txt |
Q:
pywikipedia login.py socket.error: (10060, 'Operation timed out')
I'm totally new to python, so hopefully someone can help if I'm doing something obviously wrong. I'm trying to create and run a simple pywikipedia bot on vocabularies.referata.com, a semantic mediawiki site. I downloaded the pywikipedia distro and c... | pywikipedia login.py socket.error: (10060, 'Operation timed out') | I'm totally new to python, so hopefully someone can help if I'm doing something obviously wrong. I'm trying to create and run a simple pywikipedia bot on vocabularies.referata.com, a semantic mediawiki site. I downloaded the pywikipedia distro and created a family file:
import config, family, urllib # REQUIRED
... | [
"I'm not familiar w/ pywikipedia =p, but the problem is at least about connection rather than python: the socket connection fails to be established at the beginning.\n\nIs the post url, address in the login.py L178 , correct? Any typo or misconfiguration? \nIs the url accessible? You could try to directly visit the... | [
0,
0
] | [] | [] | [
"mediawiki",
"python",
"pywikibot"
] | stackoverflow_0001368266_mediawiki_python_pywikibot.txt |
Q:
XML parsing in Python
I'd like to parse a simple, small XML file using python however work on pyXML seems to have ceased. I'd like to use python 2.6 if possible. Can anyone recommend an XML parser that will work with 2.6?
Thanks
A:
If it's small and simple then just use the standard library:
from xml.dom.minidom... | XML parsing in Python | I'd like to parse a simple, small XML file using python however work on pyXML seems to have ceased. I'd like to use python 2.6 if possible. Can anyone recommend an XML parser that will work with 2.6?
Thanks
| [
"If it's small and simple then just use the standard library:\nfrom xml.dom.minidom import parse\ndoc = parse(\"filename.xml\")\n\nThis will return a DOM tree implementing the standard Document Object Model API\nIf you later need to do complex things like schema validation or XPath querying then I recommend the thi... | [
19,
6,
5,
3,
1
] | [] | [] | [
"parsing",
"python",
"python_2.6",
"xml"
] | stackoverflow_0001373707_parsing_python_python_2.6_xml.txt |
Q:
Error importing a python module in Django
In my Django project, the following line throws an ImportError: "No module named elementtree".
from elementtree import ElementTree
However, the module is installed (ie, I can run an interactive python shell, and type that exact line without any ImportError), and the di... | Error importing a python module in Django | In my Django project, the following line throws an ImportError: "No module named elementtree".
from elementtree import ElementTree
However, the module is installed (ie, I can run an interactive python shell, and type that exact line without any ImportError), and the directory containing the module is on the PYTHONP... | [
"Can you import elementtree within the django shell:\npython manage.py shell\n\nAssuming you have multiple python versions and do not know which one is being used to run your site, add the following to your view and push python_ver to your template, it will show you the Python version you are using:\nimport sys\np... | [
7,
1,
0
] | [] | [] | [
"django",
"elementtree",
"python",
"python_module"
] | stackoverflow_0001375382_django_elementtree_python_python_module.txt |
Q:
Problem with polling sockets in python
After I begin the polling loop, all messages printed after the first iteration require me to press enter in the terminal for it to be displayed.
#!/usr/bin/python
import socket, select, os, pty, sys
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('', 5007))
s.l... | Problem with polling sockets in python | After I begin the polling loop, all messages printed after the first iteration require me to press enter in the terminal for it to be displayed.
#!/usr/bin/python
import socket, select, os, pty, sys
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('', 5007))
s.listen(5)
mypoll = select.poll()
mypoll.regi... | [
"After the first iteration, haven't you registered the pty fd, and are then polling it? And its fd will never be equal to the socket fd, so you will then os.read the pty fd. And isn't that now reading from your terminal? And so won't typing a return cause it to \"print data\"?\n"
] | [
1
] | [] | [] | [
"fork",
"polling",
"python",
"sockets"
] | stackoverflow_0001375772_fork_polling_python_sockets.txt |
Q:
Wrapping Mutually Dependent Structs in Pyrex
I am attempting to wrap some C code in Python using Pyrex. I've run into an issue with defining two structs. In this case, the structures have been defined in terms of one another, and Pyrex cannot seem to handle the conflict. The structures look something like so:
t... | Wrapping Mutually Dependent Structs in Pyrex | I am attempting to wrap some C code in Python using Pyrex. I've run into an issue with defining two structs. In this case, the structures have been defined in terms of one another, and Pyrex cannot seem to handle the conflict. The structures look something like so:
typedef struct a {
b * b_pointer;
} a;
typedef... | [
"You can use an incomplete type (you do need the corresponding C typedefs in to be in a .h file, not just a .c file):\ncdef extern from \"some.h\":\n ctypedef struct b\n ctypedef struct a:\n b * b_pointer\n ctypedef struct b:\n a a_obj\n\n"
] | [
3
] | [] | [] | [
"c",
"python",
"struct",
"wrapper"
] | stackoverflow_0001375293_c_python_struct_wrapper.txt |
Q:
In python, how does one test if a string-like object is mutable?
I have a function that takes a string-like argument.
I want to decide if I can safely store the argument and be sure that it won't change. So I'd like to test if it's mutable, e.g the result of a buffer() built from an array.array(), or not.
Currentl... | In python, how does one test if a string-like object is mutable? | I have a function that takes a string-like argument.
I want to decide if I can safely store the argument and be sure that it won't change. So I'd like to test if it's mutable, e.g the result of a buffer() built from an array.array(), or not.
Currently I use:
type(s) == str
Is there a better way to do it?
(copying the ... | [
"It would be better to use\nisinstance(s, basestring)\n\nIt works for Unicode strings too.\n",
"If it's just a heuristic for your caching, just use whatever works. isinstance(x, str), for example, almost exactly like now. (Given you want to decide whether to cache or not; a False-bearing test just means a cache m... | [
5,
4,
3,
3
] | [] | [] | [
"python"
] | stackoverflow_0001375936_python.txt |
Q:
Web/Screen Scraping with Google App Engine - Code works in python interpreter but not GAE
I want to do some web scraping with GAE. (Infinite Campus Student Information Portal, fyi). This service requires you to login to get in the website.
I had some code that worked using mechanize in normal python. When I learne... | Web/Screen Scraping with Google App Engine - Code works in python interpreter but not GAE | I want to do some web scraping with GAE. (Infinite Campus Student Information Portal, fyi). This service requires you to login to get in the website.
I had some code that worked using mechanize in normal python. When I learned that I couldn't use mechanize in Google App Engine I ended up using urllib2 + ClientForm. I c... | [
"App Engine does not strip out the Host header: it forces it to be an accurate value based on the URI you are requesting. Assuming that URI's absolute, the server isn't even allowed to consider the Host header anyway, per RFC2616:\n\n\nIf Request-URI is an absoluteURI, the host is part of the Request-URI.\n Any H... | [
2
] | [] | [] | [
"google_app_engine",
"python",
"screen_scraping"
] | stackoverflow_0001376377_google_app_engine_python_screen_scraping.txt |
Q:
Django: remove GROUP BY added with extra() method?
Hi (excuse me for my bad english) !
When I make this:
gallery_qs = Gallery.objects.all()\
.annotate(Count('photos'))\
.extra(select={'photo_id': 'photologue_photo.id'})
The sql query is :
SELECT (photologue_photo.id) AS `ph... | Django: remove GROUP BY added with extra() method? | Hi (excuse me for my bad english) !
When I make this:
gallery_qs = Gallery.objects.all()\
.annotate(Count('photos'))\
.extra(select={'photo_id': 'photologue_photo.id'})
The sql query is :
SELECT (photologue_photo.id) AS `photo`, `photologue_gallery`.*
FROM `photologue_gallery`
... | [
"I don't think you really need the extra. From Django's concept, you don't need to cherry pick specific columns while running a Django QuerySet. That logic can be done in the template side.\nI assume you know how to push galley_qs to your template from your view:\n# views.py\ngallery_qs = Gallery.objects.all()\\\... | [
1,
0
] | [] | [] | [
"django",
"django_models",
"photologue",
"python",
"sql"
] | stackoverflow_0001372890_django_django_models_photologue_python_sql.txt |
Q:
How do create a python module for MySQL Workbench?
I am trying to create a simple Python module for MySQL Workbench 5.1.17 SE however I cannot seem to register the module, that is, it is not displaying under the Plugins->Catalog menu.
The documentation appears to be rather weak at this time, the best I have found... | How do create a python module for MySQL Workbench? | I am trying to create a simple Python module for MySQL Workbench 5.1.17 SE however I cannot seem to register the module, that is, it is not displaying under the Plugins->Catalog menu.
The documentation appears to be rather weak at this time, the best I have found is Python Scripting in Workbench. There isn't much in t... | [
"I chatted with one of the developers of MySQL Workbench via IRC and it turns out there were two problems:\n\nI had to make sure my python script ended with *_grt.py so that it was recognized as a module.\nThere is a bug at least in version 5.1.17+ that prevents more than one python script module from being loaded.... | [
1
] | [] | [] | [
"mysql_workbench",
"plugins",
"python"
] | stackoverflow_0001375881_mysql_workbench_plugins_python.txt |
Q:
calculate user inputed time with Python
I need to calculate (using python) how much time a user has inputed, whether they input something like 3:30 or 3.5. I'm not really sure what the best way to go about this is and I thought I'd ask for advice from the experts.
=== Edit ==================
To specify more cle... | calculate user inputed time with Python | I need to calculate (using python) how much time a user has inputed, whether they input something like 3:30 or 3.5. I'm not really sure what the best way to go about this is and I thought I'd ask for advice from the experts.
=== Edit ==================
To specify more clearly, I want the user to input hours and minu... | [
"Can you precisely define the syntax of the strings that the user is allowed to input? Once you do that, if it's simple enough it can be matched by simple Python string expressions, else you may be better off with pyparsing or the like. Also, a precise syntax will make it easier to identify any ambiguities so you... | [
1,
0,
0,
0,
0
] | [] | [] | [
"python",
"regex"
] | stackoverflow_0001376835_python_regex.txt |
Q:
Python: cannot read / write in another commandline application by using subprocess module
I am using Python 3.0 in Windows and trying to automate the testing of a commandline application. The user can type commands in Application Under Test and it returns the output as 2 XML packets. One is a packet and the other... | Python: cannot read / write in another commandline application by using subprocess module | I am using Python 3.0 in Windows and trying to automate the testing of a commandline application. The user can type commands in Application Under Test and it returns the output as 2 XML packets. One is a packet and the other one is an packet. By analyzing these packets I can verifyt he result. I ahev the code as belo... | [
"This is a popular problem, e.g. see:\n\nInteract with a Windows console application via Python\nHow do I get 'real-time' information back from a subprocess.Popen in python (2.5)\nhow do I read everything currently in a subprocess.stdout pipe and then return?\n\n(Actually, you should have seen these during creation... | [
1,
0,
0
] | [] | [] | [
"python",
"readline",
"subprocess"
] | stackoverflow_0001165064_python_readline_subprocess.txt |
Q:
Porting from Python to C#
I´m trying to learn C#, coming from a Python/PHP background, and I´m trying to port a script from Python to getting started.
The script reads a text file line by line (about 150K lines), apply a list of regex until one is matched, get the named groups results and add the values as propert... | Porting from Python to C# | I´m trying to learn C#, coming from a Python/PHP background, and I´m trying to port a script from Python to getting started.
The script reads a text file line by line (about 150K lines), apply a list of regex until one is matched, get the named groups results and add the values as properties of a class.
Here´s how the ... | [
"1., sure\n2., see e.g. here\n3., yep, same basic concept as 2\n4., nah, C# is flexible enough to allow you to port your architecture over\nAlso consider studying this book as the best intro to .NET for Python programmers AND vice versa (I'm biased, having been a tech editor and being a friend of the author, but I ... | [
3,
2,
1,
1,
1,
0
] | [] | [] | [
"c#",
"python"
] | stackoverflow_0001376976_c#_python.txt |
Q:
PyParsing simple language expressions
I'm trying to write something that will parse some code. I'm able to successfully parse foo(spam) and spam+eggs, but foo(spam+eggs) (recursive descent? my terminology from compilers is a bit rusty) fails.
I have the following code:
from pyparsing_py3 import *
myVal = Word(alp... | PyParsing simple language expressions | I'm trying to write something that will parse some code. I'm able to successfully parse foo(spam) and spam+eggs, but foo(spam+eggs) (recursive descent? my terminology from compilers is a bit rusty) fails.
I have the following code:
from pyparsing_py3 import *
myVal = Word(alphas+nums+'_')
myFunction = myVal + '(' ... | [
"Several issues: delimitedList is looking for a comma-delimited list of myVal, i.e. identifiers, as the only acceptable form of argument list, so of course it can't match 'foo+bar' (not a comma-delimited list of myVal!); fixing that reveals another -- myVal and myFunction start the same way so their order in mySubE... | [
4,
4
] | [] | [] | [
"parsing",
"pyparsing",
"python"
] | stackoverflow_0001376716_parsing_pyparsing_python.txt |
Q:
Python dictionary to store socket objects
Can we store socket objects in a Python dictionary.
I want to create a socket, store socket object, do some stuff and then read from the socket(search from dictionary to get socketobject).
A:
Yes:
>>> import socket
>>> s = socket.socket()
>>> d = {"key" : s}
>>> d
{'key... | Python dictionary to store socket objects | Can we store socket objects in a Python dictionary.
I want to create a socket, store socket object, do some stuff and then read from the socket(search from dictionary to get socketobject).
| [
"Yes:\n>>> import socket\n>>> s = socket.socket()\n>>> d = {\"key\" : s}\n>>> d\n{'key': <socket._socketobject object at 0x00CEB5A8>}\n\n"
] | [
10
] | [] | [] | [
"python"
] | stackoverflow_0001378079_python.txt |
Q:
Creating GUI with Python in Linux
Quick question.
I'm using Linux and I want to try making a GUI with Python. I've heard about something like Qt, GTK+ and PyGTK but I don't know what they are exactly and what the difference between them is.
Is there any difference on how they work with different DEs like GNOME, KD... | Creating GUI with Python in Linux | Quick question.
I'm using Linux and I want to try making a GUI with Python. I've heard about something like Qt, GTK+ and PyGTK but I don't know what they are exactly and what the difference between them is.
Is there any difference on how they work with different DEs like GNOME, KDE, XFCE etc.? Is there any IDE that all... | [
"Your first step should be http://wiki.python.org/moin/GuiProgramming\nSome tool-kits integrate better in one environment over the other. For example PyQt, PyKDE (and the brand new PySide) will play nicer in a KDE environment, while the GTK versions (including the WX-widgets) will blend better into a GNOME/XFCE des... | [
14,
4,
2,
1,
0
] | [] | [] | [
"gtk",
"linux",
"pygtk",
"python",
"user_interface"
] | stackoverflow_0001355918_gtk_linux_pygtk_python_user_interface.txt |
Q:
CheckedListBox used from Python(pywin32)
Does anyone know how to get the list of items and check/uncheck items in a CheckedListBox from python?
I've found this to help me partly on the way. I think I've found the handle for the CheckedListBox(listed as a SysTreeView32 by WinGuiAuto.py).
One usage will for my part ... | CheckedListBox used from Python(pywin32) | Does anyone know how to get the list of items and check/uncheck items in a CheckedListBox from python?
I've found this to help me partly on the way. I think I've found the handle for the CheckedListBox(listed as a SysTreeView32 by WinGuiAuto.py).
One usage will for my part be to create an autoinstaller that manages to ... | [
"By using pywinauto I've managed to check items in a checkedlistbox by selecting them twice.\nfrom pywinauto import application\napp = application.Application()\napp.Form1.CheckedListBox1.Select('item1')\napp.Form1.CheckedListBox1.Select('item1')\n\n"
] | [
1
] | [] | [] | [
"checkedlistbox",
"message",
"python",
"pywin32",
"windows"
] | stackoverflow_0001305703_checkedlistbox_message_python_pywin32_windows.txt |
Q:
Python : email sending failing on SSL read
I keep getting this intermittent error when trying to send through 'smtp.gmail.com'.
Traceback (most recent call last):
File "/var/home/ptarjan/django/mysite/django/core/handlers/base.py", line 92, in get_response
response = callback(request, *callback_args, **cal... | Python : email sending failing on SSL read | I keep getting this intermittent error when trying to send through 'smtp.gmail.com'.
Traceback (most recent call last):
File "/var/home/ptarjan/django/mysite/django/core/handlers/base.py", line 92, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "/var/home/ptarjan/django/... | [
"Altho' I don't know why, I have been thro' this, and it works when you have settings variables ordered in a particular order:\n\nEMAIL_HOST\nEMAIL_PORT\nEMAIL_HOST_USER\nEMAIL_HOST_PASSWORD\nEMAIL_USE_TLS\n\n",
"Looks like gmail may simply be occasionally slow to respond, so your operation times out. Perhaps you... | [
3,
0
] | [] | [] | [
"django",
"email",
"python",
"smtp",
"ssl"
] | stackoverflow_0001376450_django_email_python_smtp_ssl.txt |
Q:
How to make this code handle big inputs more efficiently?
Hey. I know this is not a 'refactor my code' site but I made this little piece of code which works perfectly fine with moderately sized input but it's problematic with string of size, say, over 2000.
What it does - it takes a string of numbers as a paramete... | How to make this code handle big inputs more efficiently? | Hey. I know this is not a 'refactor my code' site but I made this little piece of code which works perfectly fine with moderately sized input but it's problematic with string of size, say, over 2000.
What it does - it takes a string of numbers as a parameter, and it returns the number of ways it can be interpreted as a... | [
"Try using a dynamic programming approach instead:\n\nCreate an array (call it 'P') with 1 element per character in the string.\nInitialize P[0] = 1 (unless the first character is 0, in which case just return 0 for the result).\nInitialize P[1] = 2 if the first two characters can be interpreted as a letter as can t... | [
3,
1,
0,
0
] | [] | [] | [
"python",
"recursion"
] | stackoverflow_0001377335_python_recursion.txt |
Q:
How to get/set data of(into) visual components (of windows programs) programmatically?
I am talking about windows GUI programs. Say a program-window has a dialog box (or a confirm button) asking user input. How can I provide input to that program using my program (written in say C#, Java or Python). Or say, a prog... | How to get/set data of(into) visual components (of windows programs) programmatically? | I am talking about windows GUI programs. Say a program-window has a dialog box (or a confirm button) asking user input. How can I provide input to that program using my program (written in say C#, Java or Python). Or say, a program window is showing some image in one of its panels. How can I grab that from other(my) pr... | [
"spy++ is listening for all win32 messages. It is very useful for debugging an application but I don't think that it is a good idea to use it as an inter-process communication mechanism.\nYou can use win32 apis to send input to your program. As an example, You can modify the content of an edit text by using the Set... | [
2,
1,
1
] | [] | [] | [
"c#",
"impersonation",
"java",
"python",
"windows"
] | stackoverflow_0001378803_c#_impersonation_java_python_windows.txt |
Q:
Python multiprocessing with twisted's reactor
I am working on a xmlrpc server which has to perform certain tasks cyclically. I am using twisted as the core of the xmlrpc service but I am running into a little problem:
class cemeteryRPC(xmlrpc.XMLRPC):
def __init__(self, dic):
xmlrpc.XMLRPC.__init__(se... | Python multiprocessing with twisted's reactor | I am working on a xmlrpc server which has to perform certain tasks cyclically. I am using twisted as the core of the xmlrpc service but I am running into a little problem:
class cemeteryRPC(xmlrpc.XMLRPC):
def __init__(self, dic):
xmlrpc.XMLRPC.__init__(self)
def xmlrpc_foo(self):
return 1
... | [
"Do you really need to run Twisted in a separate process? That looks pretty unusual to me.\nTry to think of Twisted's Reactor as your main loop - and hang everything you need off that - rather than trying to run Twisted as a background task.\nThe more normal way of performing this sort of operation would be to use ... | [
11,
3
] | [] | [] | [
"multiprocessing",
"python",
"twisted"
] | stackoverflow_0001377494_multiprocessing_python_twisted.txt |
Q:
Closures in Python
I've been trying to learn Python, and while I'm enthusiastic about using closures in Python, I've been having trouble getting some code to work properly:
def memoize(fn):
def get(key):
return (False,)
def vset(key, value):
global get
oldget = get
def newg... | Closures in Python | I've been trying to learn Python, and while I'm enthusiastic about using closures in Python, I've been having trouble getting some code to work properly:
def memoize(fn):
def get(key):
return (False,)
def vset(key, value):
global get
oldget = get
def newget(ky):
if k... | [
"The problem is in your scoping, not in your closures. If you're up for some heavy reading, then you can try http://www.python.org/dev/peps/pep-3104/.\nIf that's not the case, here's the simple explanation:\nThe problem is in the statement global get . global refers to the outermost scope, and since there isn't any... | [
8,
8,
1,
1,
0,
0
] | [] | [] | [
"closures",
"lexical_scope",
"python"
] | stackoverflow_0000505559_closures_lexical_scope_python.txt |
Q:
What is faster in Python, "while" or "for xrange"
We can do numeric iteration like:
for i in xrange(10):
print i,
and in C-style:
i = 0
while i < 10:
print i,
i = i + 1
Yes, I know, the first one is less error-prone, more pythonic but is it fast enough as C-style version?
PS. I'm from C++ planet and ... | What is faster in Python, "while" or "for xrange" | We can do numeric iteration like:
for i in xrange(10):
print i,
and in C-style:
i = 0
while i < 10:
print i,
i = i + 1
Yes, I know, the first one is less error-prone, more pythonic but is it fast enough as C-style version?
PS. I'm from C++ planet and pretty new on Python one.
| [
"I am sure the while version is slower. Python will have to lookup the add operation for the integer object on each turn of the loop etc, it is not pure C just because it looks like it!\nAnd if you want a pythonic version of exactly the above, use:\nprint \" \".join(str(i) for i in xrange(10))\n\n\nEdit: My timings... | [
16,
15,
3,
1,
1,
0,
0
] | [] | [] | [
"micro_optimization",
"python"
] | stackoverflow_0001377429_micro_optimization_python.txt |
Q:
Where is Python used? I read about it a lot on Reddit
I have downloaded the Pyscripter and learning Python. But I have no Idea if it has any job value , especially in India. I am learning Python as a Hobby. But it would be comforting to know if Python programmers are in demand in India.
A:
Everywhere. It's used ... | Where is Python used? I read about it a lot on Reddit | I have downloaded the Pyscripter and learning Python. But I have no Idea if it has any job value , especially in India. I am learning Python as a Hobby. But it would be comforting to know if Python programmers are in demand in India.
| [
"Everywhere. It's used extensively by google for one.\nSee list of python software for more info, and also who uses python on the web?\n",
"In many large companies it is a primary scripting language.\nGoogle is using it along with Java and C++ and almost nothing else.\nAlso many web pages are built on top of pyth... | [
17,
10,
4,
1,
1,
1,
1,
0
] | [] | [] | [
"python"
] | stackoverflow_0000520210_python.txt |
Q:
Set Snow Leopard to use python 2.5 rather than 2.6
I just upgraded to Snow Leopard and I'm trying to get it to use the old python 2.5 install. I had with all my modules in it. Does anyone know how to set the default python install to 2.5?
A:
I worked this out - if you have this problem open a terminal and type... | Set Snow Leopard to use python 2.5 rather than 2.6 | I just upgraded to Snow Leopard and I'm trying to get it to use the old python 2.5 install. I had with all my modules in it. Does anyone know how to set the default python install to 2.5?
| [
"I worked this out - if you have this problem open a terminal and type:\ndefaults write com.apple.versioner.python Version 2.5\n\n",
"You want python_select.\n\nDescription: Switch the default python interpreter\n\n"
] | [
8,
0
] | [] | [] | [
"macos",
"osx_snow_leopard",
"python"
] | stackoverflow_0001380281_macos_osx_snow_leopard_python.txt |
Q:
pagination with the python cmd module
I'm prototyping a Python app with the cmd module.
Some messages to the user will be quite long and I'd like to paginate them.
The first 10 (or a configurable number) lines of the message would appear, and pressing the SPACE bar would display the next page, until the end of the... | pagination with the python cmd module | I'm prototyping a Python app with the cmd module.
Some messages to the user will be quite long and I'd like to paginate them.
The first 10 (or a configurable number) lines of the message would appear, and pressing the SPACE bar would display the next page, until the end of the message.
I don't want to reinvent somethin... | [
"The simple thing would just be to pipe your script through \"less\" or a similar command at runtime.\nHere's a simple method that does approximately what you want, though:\ndef print_and_wait(some_long_message):\n lines = some_long_message.split('\\n')\n i=0\n while i < len(lines):\n print '\\n'.jo... | [
4,
3,
1,
0
] | [] | [] | [
"cmd",
"pagination",
"python"
] | stackoverflow_0000520963_cmd_pagination_python.txt |
Q:
Is it possible to reference the output of an IronPython project from within a c# project?
I would like to build a code library in IronPython and have another C# project reference it. Can I do this? How?
Is this just as simple as building the project and referencing the dll? Is there any conflict with the dynamic a... | Is it possible to reference the output of an IronPython project from within a c# project? | I would like to build a code library in IronPython and have another C# project reference it. Can I do this? How?
Is this just as simple as building the project and referencing the dll? Is there any conflict with the dynamic aspect of it?
| [
"There is currently no way to build CLS-compliant assemblies from IronPython. The pyc tool will generate a DLL from Python code, but it's really only useful from IronPython.\nIf you want to use IronPython from a C# app, you'll have to use the hosting interfaces (gory details). You could also check out IronPython in... | [
1
] | [] | [] | [
"assemblies",
"c#",
"ironpython",
"python"
] | stackoverflow_0001342645_assemblies_c#_ironpython_python.txt |
Q:
Django and weird legacy database tables
I'm trying to integrate a legacy database in Django.
I'm running into problems with some weird tables that result from horribly bad database design, but I'm not free to change it.
The problem is that there are tables that dont have a primarykey ID, but a product ID and, here... | Django and weird legacy database tables | I'm trying to integrate a legacy database in Django.
I'm running into problems with some weird tables that result from horribly bad database design, but I'm not free to change it.
The problem is that there are tables that dont have a primarykey ID, but a product ID and, here comes the problem, a lot of them are multipl... | [
"Django's ORM will have trouble working with this table unless you add a unique primary key column.\nIf you do add a primary key, then it would be trivial to write a method to query for a given product ID and return a list of the values corresponding to that product ID. Something like:\ndef names_for(product_id):\n... | [
2
] | [] | [] | [
"database",
"django",
"legacy",
"python"
] | stackoverflow_0001379905_database_django_legacy_python.txt |
Q:
Slickest REPL console in any language
Many languages of REPL consoles with additional features like autocomplete and intellisense. For instance, iPython, Mathematica, and PyCrust all make some effort to go beyond a basic read eval loop. REPLs are particularly useful in languages where interactive exploration is ... | Slickest REPL console in any language | Many languages of REPL consoles with additional features like autocomplete and intellisense. For instance, iPython, Mathematica, and PyCrust all make some effort to go beyond a basic read eval loop. REPLs are particularly useful in languages where interactive exploration is very important, such as Matlab or R.
I'm lo... | [
"Common Lisp and emacs with SLIME. All you could really want, think of, dream of, and then some.\n",
"I really like Safari's Web Inspector Javascript console. Specifically:\n\nCollapsible interactive object hierarchies\nsprintf-style logging\nPretty-printing of closures, allowing you to peer into the internals o... | [
5,
4,
3,
0
] | [] | [] | [
"console",
"matlab",
"python"
] | stackoverflow_0001380592_console_matlab_python.txt |
Q:
What lightweight python library for simple scientific visualization in 3D
I am writing a program in python to experiment an academic idea. Look at a resultant image the program generates:
The thick skeleton lines in the middle of the leaf is what need to be visualized. Every segment of the skeleton lines has a ... | What lightweight python library for simple scientific visualization in 3D | I am writing a program in python to experiment an academic idea. Look at a resultant image the program generates:
The thick skeleton lines in the middle of the leaf is what need to be visualized. Every segment of the skeleton lines has a value associated with it, in the above image (drawn by pycairo), different shad... | [
"If you want lightweight, then you can use PyOpenGL to just wrap OpenGL calls in python directly. This is probably the lightest-weight option.\nIf you want lots of features, I'd recommend using VTK. It's a very powerful visualization toolkit with Python wrappers (included). There are other packages built on top ... | [
4,
3
] | [] | [] | [
"3d",
"geometry",
"python",
"visualization"
] | stackoverflow_0001380861_3d_geometry_python_visualization.txt |
Q:
How do I extract a date range from a csv using perl/php/grep/etc?
Is there a way to take text like below (if it was already in an array or a file) and have it strip the lines with a specified date range?
For instance if i wanted every line from 2009-09-04 until 2009-09-09 to be pulled out (maybe this can be done ... | How do I extract a date range from a csv using perl/php/grep/etc? | Is there a way to take text like below (if it was already in an array or a file) and have it strip the lines with a specified date range?
For instance if i wanted every line from 2009-09-04 until 2009-09-09 to be pulled out (maybe this can be done with grep?) how would I go about doing so?
date,test,time,avail
2009-0... | [
"Python\nimport csv\nimport datetime\n\nstart= datetime.datetime(2009,9,4)\nend= datetime.datetime(2009,9,9)\n\nsource= csv.DictReader( open(\"someFile\",\"rb\") )\nfor row in source:\n dt = datetime.datetime.strptime(row['date'],\"%Y-%m-%d\")\n if start <= dt <= end:\n print row # depends on what \"pu... | [
4,
3,
2,
1,
1,
0,
0
] | [] | [] | [
"grep",
"perl",
"php",
"python",
"ruby"
] | stackoverflow_0001369287_grep_perl_php_python_ruby.txt |
Q:
Can I add parameters to a python property to reduce code duplication?
I have a the following class:
class Vector(object):
def __init__(self, x=0, y=0, z=0):
self.x = x
self.y = y
self.z = z
def _getx(self):
return self._x
def _setx(self, value):
self._x = float... | Can I add parameters to a python property to reduce code duplication? | I have a the following class:
class Vector(object):
def __init__(self, x=0, y=0, z=0):
self.x = x
self.y = y
self.z = z
def _getx(self):
return self._x
def _setx(self, value):
self._x = float(value)
x = property(_getx, _setx)
def _gety(self):
return... | [
"Sure, make a custom descriptor as per the concepts clearly explained in this doc:\nclass JonProperty(object):\n def __init__(self, name):\n self.name = name\n\n def __get__(self, obj, objtype):\n return getattr(obj, self.name)\n\n def __set__(self, obj, val):\n setattr(obj, self.name,... | [
16,
2,
0
] | [] | [] | [
"python"
] | stackoverflow_0001380566_python.txt |
Q:
Python list vs. MySQL Select performance
I have a large list with 15k entries in a MySQL table from which I need to select a few items, many times. For example, I might want all entries with a number field between 1 and 10.
In SQL this would be easy:
SELECT text FROM table WHERE number>=1 AND number<10;
If I ext... | Python list vs. MySQL Select performance | I have a large list with 15k entries in a MySQL table from which I need to select a few items, many times. For example, I might want all entries with a number field between 1 and 10.
In SQL this would be easy:
SELECT text FROM table WHERE number>=1 AND number<10;
If I extract the entire table to a Python list:
PyList... | [
"Simply define an index over number in your database, then the database can generate the result sets instantly. Plus it can do some calculations on these sets too, if that is your next step. \nDatabases are actually great at such queries, I'd let it do its job before trying something else.\n",
"It's certainly goi... | [
1,
1,
0,
0
] | [] | [] | [
"mysql",
"python"
] | stackoverflow_0001380917_mysql_python.txt |
Q:
How to aggregate all attributes of a hierarchy of classes?
There is a hierchy of classes. Each class may define a class variable (to be specific, it's a dictionary), all of which have the same variable name. I'd like the very root class to be able to somehow access all of these variables (i.e. all the dictionaries... | How to aggregate all attributes of a hierarchy of classes? | There is a hierchy of classes. Each class may define a class variable (to be specific, it's a dictionary), all of which have the same variable name. I'd like the very root class to be able to somehow access all of these variables (i.e. all the dictionaries joined together), given an instance of a child class. I can't s... | [
"As long as you're using new-style classes (i.e., object or some other built-in type is the \"deepest ancestor\"), __mro__ is what you're looking for. For example, given:\n>>> class Root(object):\n... d = {'za': 23}\n... \n>>> class Trunk(Root):\n... d = {'ki': 45}\n... \n>>> class Branch(Root):\n... d = {'f... | [
1
] | [] | [] | [
"class",
"hierarchy",
"python"
] | stackoverflow_0001381333_class_hierarchy_python.txt |
Q:
Logging multithreaded processes in python
I was thinking of using the logging module to log all events to one file. The number of threads should be constant from start to finish, but if one thread fails, I'd like to just log that and continue on. What's a simple way of accomplishing this? Thanks!
A:
Not entirely... | Logging multithreaded processes in python | I was thinking of using the logging module to log all events to one file. The number of threads should be constant from start to finish, but if one thread fails, I'd like to just log that and continue on. What's a simple way of accomplishing this? Thanks!
| [
"Not entirely sure what you mean by \"one thread fails\", but if by \"fail\" you mean that an exception propagates all the way up to the top function of the thread, then you can wrap every thread's top function (e.g. in a decorator) to catch any exception, log whatever you wish, and re-raise. The logging module sh... | [
7
] | [] | [] | [
"logging",
"multithreading",
"python"
] | stackoverflow_0001380985_logging_multithreading_python.txt |
Q:
How do I wrap this C function, with multiple arguments, with ctypes?
I have the function prototype here:
extern "C" void __stdcall__declspec(dllexport) ReturnPulse(double*,double*,double*,double*,double*);
I need to write some python to access this function that is in a DLL.
I have loaded the DLL, but
each of the... | How do I wrap this C function, with multiple arguments, with ctypes? | I have the function prototype here:
extern "C" void __stdcall__declspec(dllexport) ReturnPulse(double*,double*,double*,double*,double*);
I need to write some python to access this function that is in a DLL.
I have loaded the DLL, but
each of the double* is actually pointing to a variable number of doubles (an array), ... | [
"I haven't looked at ctypes too much, but try using a numpy array of the right type. If that doesn't just automatically work, they also have a ctypes attribute that should contain a pointer to the data.\n",
"To make an array with, say, n doubles:\narr7 = ctypes.c_double * `n` \nx = arr7()\n\nand pass x to your fu... | [
1,
1
] | [] | [] | [
"arrays",
"ctypes",
"pointers",
"python",
"return"
] | stackoverflow_0001381016_arrays_ctypes_pointers_python_return.txt |
Q:
Is packaging scripts as executables a solution for comercial applications?
What happens when you package a script as an executable? Is this a good way to distribute commercial applications? I remember I read something a long time ago that when you package scripts as executables, at runtime the exe decompresses the... | Is packaging scripts as executables a solution for comercial applications? | What happens when you package a script as an executable? Is this a good way to distribute commercial applications? I remember I read something a long time ago that when you package scripts as executables, at runtime the exe decompresses the scripts to a temporary directory where they get ran.
If it's like that, than I ... | [
"With Python (e.g. pyinstaller -- be sure to get the SVN version, the \"released\" one is WAY out of date -- or py2exe) you can package bytecode. Sure, it can be \"reverse compiled\", just like Java bytecode or .NET assemblies (or for that matter, machine code), but I think it's a decent level of \"obscurity\" desp... | [
3,
3,
2,
1
] | [] | [] | [
"executable",
"python",
"ruby"
] | stackoverflow_0001380852_executable_python_ruby.txt |
Q:
Wrong Mac OS X framework gets loaded
I've compiled a Python module using my own Qt4 library located in ~/opt/qt-4.6.0/,
but when I try to import that module, the dynamic libraries that get loaded are from my MacPorts Qt4 installation.
$ /opt/local/bin/python2.6
>>> import vtk
objc[58041]: Class QMacSoundDelegate ... | Wrong Mac OS X framework gets loaded | I've compiled a Python module using my own Qt4 library located in ~/opt/qt-4.6.0/,
but when I try to import that module, the dynamic libraries that get loaded are from my MacPorts Qt4 installation.
$ /opt/local/bin/python2.6
>>> import vtk
objc[58041]: Class QMacSoundDelegate is implemented in both /Users/luis/opt/qt-... | [
"Ok, after Barry Wark pointed me to dyld(1), the man page described a number of variables that I could set.\nThe first hint came from setting the environment variable DYLD_PRINT_LIBRARIES, so I could see what libraries were being loaded.\n$ DYLD_PRINT_LIBRARIES=1 python -c 'import vtk'\n[... snip ...]\ndyld: loaded... | [
3,
2
] | [] | [] | [
"macos",
"macports",
"python",
"qt4",
"vtk"
] | stackoverflow_0001381177_macos_macports_python_qt4_vtk.txt |
Q:
Model inheritance approach with Django's ORM
I want to store events in a web application I am fooling around with and I feel quite unsure about the pros and cons of each respective approach - using inheritance extensively or in a more modest manner.
Example:
class Event(models.Model):
moment = models.DateTimeF... | Model inheritance approach with Django's ORM | I want to store events in a web application I am fooling around with and I feel quite unsure about the pros and cons of each respective approach - using inheritance extensively or in a more modest manner.
Example:
class Event(models.Model):
moment = models.DateTimeField()
class UserEvent(Event):
user = models.... | [
"Flat is better than nested. I don't see that the \"deep inheritance\" is really buying you anything in this case: I'd go for the flatter model as a simpler, plainer design, with likely better performance characteristics and ease of access.\n",
"You might want to try Abstract base models. This implements inherit... | [
6,
2
] | [] | [] | [
"django",
"django_models",
"model_inheritance",
"python"
] | stackoverflow_0001381423_django_django_models_model_inheritance_python.txt |
Q:
MAC OS X Custom Application Keeping Bouncing in the Dock
First of all, thank you for taking the time to read this. I am new to developing applications for the Mac and I am having some problems. My application works fine, and that is not the focus of my question. Rather, I have a python program which essentially do... | MAC OS X Custom Application Keeping Bouncing in the Dock | First of all, thank you for taking the time to read this. I am new to developing applications for the Mac and I am having some problems. My application works fine, and that is not the focus of my question. Rather, I have a python program which essentially does this:
for i in values:
os.system(java program_and_opti... | [
"Does running Java with headless mode = true fix it?\nhttp://zzamboni.org/brt/2007/12/07/disable-dock-icon-for-java-programs-in-mac-osx-howto/\n",
"As far as I am aware there is no way to disable the annoying double Java bounce without making your Java application a first class citizen on Mac OS X (much like NetB... | [
1,
0,
0
] | [] | [] | [
"java",
"macos",
"python"
] | stackoverflow_0001381739_java_macos_python.txt |
Q:
Beginner graphics program in Python giving 'out of stack space' error
I'm currently learning Python using Zelle's Introductory text, and I'm trying to recreate one of the example programs which uses an accompanying file graphics.py. Because I'm using Python 3.1 and the text was written for 2.x though, I'm using t... | Beginner graphics program in Python giving 'out of stack space' error | I'm currently learning Python using Zelle's Introductory text, and I'm trying to recreate one of the example programs which uses an accompanying file graphics.py. Because I'm using Python 3.1 and the text was written for 2.x though, I'm using the GraphicsPy3.py file found at http://mcsp.wartburg.edu/zelle/python and r... | [
"There appears to be a problem with the Python 3 version of graphics.py.\nI downloaded the Python 3 version, renamed it to graphics.py, then ran the following.\nPS C:\\Users\\jaraco\\Desktop> python\nPython 3.1.1 (r311:74483, Aug 17 2009, 17:02:12) [MSC v.1500 32 bit (Intel)] on\nwin32\nType \"help\", \"copyright\"... | [
2,
1,
0
] | [] | [] | [
"python"
] | stackoverflow_0001372949_python.txt |
Q:
inserting a tuple into a mysql db
can anyone show me the syntax for inserting a python tuple/list into a mysql database?
i also need to know if it is possible for user to pass certain rows without inserting anything...
for example: a function is returning this tuple:
return job(jcardnum, jreg, jcarddate, jcardtime... | inserting a tuple into a mysql db | can anyone show me the syntax for inserting a python tuple/list into a mysql database?
i also need to know if it is possible for user to pass certain rows without inserting anything...
for example: a function is returning this tuple:
return job(jcardnum, jreg, jcarddate, jcardtime, jcardserve, jdeliver)
suppose the us... | [
"As a comment says, the job(...) part is a function (or class) call -- whatever is returned from that call also gets returned from this return statement.\nLet's assume it's a tuple. What if \"the user didn't enter anything in jreg\" -- well then, depending on a lot of code you're not showing us, that could be a run... | [
7,
0
] | [] | [] | [
"mysql",
"python"
] | stackoverflow_0001381840_mysql_python.txt |
Q:
You don't have permission to access /index.py on this server
I am setting up a simple test page in Python. I only have two files: .htaccess and index.py. I get a 403 Forbidden error when trying to view the page - how can I fix this?
.htaccess:
RewriteEngine On
AddHandler application/x-httpd-cgi .py
DirectoryIndex ... | You don't have permission to access /index.py on this server | I am setting up a simple test page in Python. I only have two files: .htaccess and index.py. I get a 403 Forbidden error when trying to view the page - how can I fix this?
.htaccess:
RewriteEngine On
AddHandler application/x-httpd-cgi .py
DirectoryIndex index.py
index.py:
#!/usr/bin/python
print "Content-type: text/ht... | [
"What permissions have you set on index.py (e.g. what does ls -l index.py say, if in Linux or other Unix variants)?\n"
] | [
1
] | [] | [] | [
".htaccess",
"python"
] | stackoverflow_0001383632_.htaccess_python.txt |
Q:
Dynamically attaching a method to an existing Python object generated with swig?
I am working with a Python class, and I don't have write access to its declaration.
How can I attach a custom method (such as __str__) to the objects created from that class without modifying the class declaration?
EDIT:
Thank you fo... | Dynamically attaching a method to an existing Python object generated with swig? | I am working with a Python class, and I don't have write access to its declaration.
How can I attach a custom method (such as __str__) to the objects created from that class without modifying the class declaration?
EDIT:
Thank you for all your answers. I tried them all but they haven't resolved my problem. Here is a m... | [
"If you create a wrapper class, this will work with any other class, either built-in or not. This is called \"containment and delegation\", and it is a common alternative to inheritance:\nclass SuperDuperWrapper(object):\n def __init__(self, origobj):\n self.myobj = origobj\n def __str__(self):\n ... | [
24,
3,
3,
2,
1
] | [] | [] | [
"class",
"dynamic",
"methods",
"python"
] | stackoverflow_0001382871_class_dynamic_methods_python.txt |
Q:
Python data structure for a collection of objects with random access based on an attribute
I need a collection of objects which can be looked up by a certain (unique) attribute common to each of the objects. Right now I am using a dicitionary assigning the dictionary key to the attribute.
Here is an example of wha... | Python data structure for a collection of objects with random access based on an attribute | I need a collection of objects which can be looked up by a certain (unique) attribute common to each of the objects. Right now I am using a dicitionary assigning the dictionary key to the attribute.
Here is an example of what I have now:
class Item():
def __init__(self, uniq_key, title=None):
self.key = uni... | [
"There is actually no duplication of information as you fear: the dict's key, and the object's .key attribute, are just two references to exactly the same object.\nThe only real problem is \"what if the .key gets reassigned\". Well then, clearly you must use a property that updates all the relevant dicts as well as... | [
5,
2,
0,
0
] | [] | [] | [
"python"
] | stackoverflow_0001383693_python.txt |
Q:
Framework/CMS suggestions for enterprise website & intranet (I've got to convince the president its solid!)
Dear stack overflow community,
I've been given the task of overhauling a couple of websites for a large corporation I'm working for, as well as developing an internal intranet site for content management and... | Framework/CMS suggestions for enterprise website & intranet (I've got to convince the president its solid!) | Dear stack overflow community,
I've been given the task of overhauling a couple of websites for a large corporation I'm working for, as well as developing an internal intranet site for content management and document storage within the organization.
My "problem" is this: They want me to use a framework/set of languages... | [
"This is a contradictory statement: \"The spec's \"big picture\" really isn't too complicated: Implement an enterprise-class CMS for management of each division's web pages\".\n\"Enterprise Class\" and \"isn't too complicated\" do not belong in the same sentence. Seriously.\n\"Enterprise Class\" stuff is complicate... | [
9,
8,
5,
4,
3,
3,
3,
2,
2,
2,
1,
1,
0,
0
] | [] | [] | [
"content_management_system",
"enterprise",
"frameworks",
"python"
] | stackoverflow_0000241575_content_management_system_enterprise_frameworks_python.txt |
Q:
OS X - multiple python versions, PATH and /usr/local
If you install multiple versions of python (I currently have the default 2.5, installed 3.0.1 and now installed 2.6.2), it automatically puts stuff in /usr/local, and it also adjusts the path to include the /Library/Frameworks/Python/Versions/theVersion/bin, but... | OS X - multiple python versions, PATH and /usr/local | If you install multiple versions of python (I currently have the default 2.5, installed 3.0.1 and now installed 2.6.2), it automatically puts stuff in /usr/local, and it also adjusts the path to include the /Library/Frameworks/Python/Versions/theVersion/bin, but whats the point of that when /usr/local is already on the... | [
"There's no a priori guarantee that /usr/local/bin will stay on the PATH (especially it will not necessarily stay \"in front of\" /usr/bin!-), so it's perfectly reasonable for an installer to ensure the specifically needed /Library/.../bin directory does get on the PATH. Plus, it may be the case that the /Library/... | [
5,
0
] | [] | [] | [
"macos",
"multiple_versions",
"path",
"python"
] | stackoverflow_0001383863_macos_multiple_versions_path_python.txt |
Q:
Locking PC in Python on Ubuntu
i'm doing application that locks the PC using pyGtk, but i have a problem, when i click on the ok button the function of the button should get the time from the textbox, hide the window then sleep for a while, and at last lock the pc using a bash command. but it just don't hide.
and ... | Locking PC in Python on Ubuntu | i'm doing application that locks the PC using pyGtk, but i have a problem, when i click on the ok button the function of the button should get the time from the textbox, hide the window then sleep for a while, and at last lock the pc using a bash command. but it just don't hide.
and here is the complete program
| [
"Provided you are using Gnome on Ubuntu \nimport os\n\nos.system('gnome-screensaver-command –-lock')\n\n",
"Is there any reason for the main class to be a thread? I would make it just a normal class, which would be a lot easier to debug. The reason its not working is that all gtk related stuff must happen in t... | [
3,
1
] | [] | [] | [
"pygtk",
"python"
] | stackoverflow_0001376232_pygtk_python.txt |
Q:
Serving file download with python
Hey gang, I'm trying to convert a legacy php script over to python and not having much luck.
The intent of the script is to serve up a file while concealing it's origin. Here's what's working in php:
<?php
$filepath = "foo.mp3";
$filesize = filesize($filepath);
header("Pragma: ... | Serving file download with python | Hey gang, I'm trying to convert a legacy php script over to python and not having much luck.
The intent of the script is to serve up a file while concealing it's origin. Here's what's working in php:
<?php
$filepath = "foo.mp3";
$filesize = filesize($filepath);
header("Pragma: no-cache");
header("Expires: 0");
heade... | [
"Well, maybe it's just me missing something, but... You are actually not writing the contents of the file to stdout. You are just reading it into memory, so it will never show up on the other side of the TCP connection...\nTry:\nsys.stdout.write(open(filepath,\"rb\").read())\nsys.stdout.flush()\n\nDepending on the ... | [
5,
1
] | [
"You should check out urllib to set and work with headers. Here's a small example that does this.\n"
] | [
-1
] | [
"binary",
"php",
"python"
] | stackoverflow_0001384320_binary_php_python.txt |
Q:
python variable scope issue
i am stuck at scope resolution in python.
let me explain a code first:
class serv_db:
def __init__(self, db):
self.db = db
self.dbc = self.db.cursor()
def menudisp (self):
print"Welcome to Tata Motors"
print"Please select one of the options to continue:"
print"1. I... | python variable scope issue | i am stuck at scope resolution in python.
let me explain a code first:
class serv_db:
def __init__(self, db):
self.db = db
self.dbc = self.db.cursor()
def menudisp (self):
print"Welcome to Tata Motors"
print"Please select one of the options to continue:"
print"1. Insert Car Info"
print"2. Disp... | [
"It's a mistake to explicitly pass self when calling a method on your class. It's another mistake comparing ch to integers, when raw_input returns a string\nTry\nelif ch=='2': self.adnewcar(reg)\n\ninstead\nYou also have a print misindented in adnewcar.\nBut even then, after fixing all this I cannot reproduce your ... | [
2,
0,
0
] | [] | [] | [
"python"
] | stackoverflow_0001384301_python.txt |
Q:
Python : Revert to base __str__ behavior
How can I revert back to the default function that python uses if there is no __str__ method?
class A :
def __str__(self) :
return "Something useless"
class B(A) :
def __str__(self) :
return some_magic_base_function(self)
A:
You can use object.__str__()... | Python : Revert to base __str__ behavior | How can I revert back to the default function that python uses if there is no __str__ method?
class A :
def __str__(self) :
return "Something useless"
class B(A) :
def __str__(self) :
return some_magic_base_function(self)
| [
"You can use object.__str__():\nclass A:\n def __str__(self):\n return \"Something useless\"\n\nclass B(A):\n def __str__(self):\n return object.__str__(self)\n\nThis gives you the default output for instances of B:\n>>> b = B()\n>>> str(b)\n'<__main__.B instance at 0x7fb34c4f09e0>'\n\n",
"\"the def... | [
12,
2
] | [] | [] | [
"python",
"string"
] | stackoverflow_0001384542_python_string.txt |
Q:
Show *only* docstring in Sphinx documentation?
Sphinx has a feature called automethod that extracts the documentation from a method's docstring and embeds that into the documentation. But it not only embeds the docstring, but also the method signature (name + arguments). How do I embed only the docstring (excludin... | Show *only* docstring in Sphinx documentation? | Sphinx has a feature called automethod that extracts the documentation from a method's docstring and embeds that into the documentation. But it not only embeds the docstring, but also the method signature (name + arguments). How do I embed only the docstring (excluding the method signature)?
ref: http://www.sphinx-doc.... | [
"I think what you're looking for is:\nfrom sphinx.ext import autodoc\n\nclass DocsonlyMethodDocumenter(autodoc.MethodDocumenter):\n def format_args(self):\n return None\n\nautodoc.add_documenter(DocsonlyMethodDocumenter)\n\nper the current sources this should allow overriding what class is responsible for docum... | [
17
] | [] | [] | [
"autodoc",
"python",
"python_sphinx"
] | stackoverflow_0001370283_autodoc_python_python_sphinx.txt |
Q:
Is concurrent computing important for web development?
Let's say I have a web application running on S servers with an average of C cores each. My application is processing an average of R requests at any instant. Assuming R is around 10 times larger than S * C, won't benefits from spreading the work of a reques... | Is concurrent computing important for web development? | Let's say I have a web application running on S servers with an average of C cores each. My application is processing an average of R requests at any instant. Assuming R is around 10 times larger than S * C, won't benefits from spreading the work of a request across multiple cores be minimal since each core is proces... | [
"In the hypothetical circumstances you design, with about 10 requests \"in play\" per core, as long as the request-to-core assignment is handled sensibly (probably even the simplest round-robin load balancing will do), it's just fine if each request lives throughout its lifetime on a single core.\nPoint is, that sc... | [
5,
4,
1,
1,
0
] | [] | [] | [
"concurrency",
"python",
"web_applications"
] | stackoverflow_0001384715_concurrency_python_web_applications.txt |
Q:
Unpickling classes from Python 3 in Python 2
If a Python 3 class is pickled using protocol 2, it is supposed to work in Python 2, but unfortunately, this fails because the names of some classes have changed.
Assume we have code called as follows.
Sender
pickle.dumps(obj,2)
Receiver
pickle.loads(atom)
To give a s... | Unpickling classes from Python 3 in Python 2 | If a Python 3 class is pickled using protocol 2, it is supposed to work in Python 2, but unfortunately, this fails because the names of some classes have changed.
Assume we have code called as follows.
Sender
pickle.dumps(obj,2)
Receiver
pickle.loads(atom)
To give a specific case, if obj={}, then the error given is:
... | [
"This problem is Python issue 3675. This bug is actually fixed in Python 3.11.\nIf we import:\nfrom lib2to3.fixes.fix_imports import MAPPING\n\nMAPPING maps Python 2 names to Python 3 names. We want this in reverse.\nREVERSE_MAPPING={}\nfor key,val in MAPPING.items():\n REVERSE_MAPPING[val]=key\n\nWe can overrid... | [
14
] | [] | [] | [
"pickle",
"python",
"python_3.x"
] | stackoverflow_0001385096_pickle_python_python_3.x.txt |
Q:
How to set timeout detection on a RabbitMQ server?
I am trying out RabbitMQ with this python binding.
One thing I noticed is that if I kill a consumer uncleanly (emulating a crashed program), the server will think that this consumer is still there for a long time. The result of this is that every other message wil... | How to set timeout detection on a RabbitMQ server? | I am trying out RabbitMQ with this python binding.
One thing I noticed is that if I kill a consumer uncleanly (emulating a crashed program), the server will think that this consumer is still there for a long time. The result of this is that every other message will be ignored.
For example if you kill a consumer 1 time ... | [
"I don't see amqp_consumer.py or amqp_producer.py in the tarball, so reproducing the fault is tricky.\nRabbitMQ terminates connections, releasing their unacknowledged messages for redelivery to other clients, whenever it is told by the operating system that a socket has closed. Your symptoms are very strange, in th... | [
11,
5,
2
] | [] | [] | [
"amqp",
"message_queue",
"python",
"rabbitmq"
] | stackoverflow_0001345239_amqp_message_queue_python_rabbitmq.txt |
Q:
Calling non-static method from static one in Python
I can't find if it's possible to call a non-static method from a static one in Python.
Thanks
EDIT:
Ok. And what about static from static? Can I do this:
class MyClass(object):
@staticmethod
def static_method_one(cmd):
...
@staticmethod
def ... | Calling non-static method from static one in Python | I can't find if it's possible to call a non-static method from a static one in Python.
Thanks
EDIT:
Ok. And what about static from static? Can I do this:
class MyClass(object):
@staticmethod
def static_method_one(cmd):
...
@staticmethod
def static_method_two(cmd):
static_method_one(cmd)
| [
"It's perfectly possible, but not very meaningful. Ponder the following class:\nclass MyClass:\n # Normal method:\n def normal_method(self, data):\n print \"Normal method called with instance %s and data %s\" % (self, data)\n\n @classmethod\n def class_method(cls, data):\n print \"Class me... | [
15,
7,
4,
2,
0
] | [] | [] | [
"oop",
"python"
] | stackoverflow_0001385546_oop_python.txt |
Q:
Edit python31 file and it opens notepad and starts python26
I am in python31,
then I go to file open i left click to open file
and it opens in notepad(simple text editor)python31
The moment it opens the notepad, it starts python26
I thought it has something to open with, and I have changed that to python31
And it... | Edit python31 file and it opens notepad and starts python26 | I am in python31,
then I go to file open i left click to open file
and it opens in notepad(simple text editor)python31
The moment it opens the notepad, it starts python26
I thought it has something to open with, and I have changed that to python31
And it still opens python26
EDIT:
The file is created by python26, but ... | [
"I am guessing here, the question it not very clear. \nIt sounds like the .py extension in Windows is associated with the Python 2.6 runtime. (This normally get setup this way during installation of Python on Windows). You can change this by updating the associated file extensions and programs in Windows.\nBy doubl... | [
0,
0
] | [] | [] | [
"python",
"python_3.x",
"windows"
] | stackoverflow_0001385280_python_python_3.x_windows.txt |
Q:
How to get 280slides.com functionality?
I have seen 280slides.com and it is really impresive. But its developers had to create their own language.
Which platform or language would you use to have an as similar as possible functionality?
Is it possible to do something similar in python?
Could you give any working e... | How to get 280slides.com functionality? | I have seen 280slides.com and it is really impresive. But its developers had to create their own language.
Which platform or language would you use to have an as similar as possible functionality?
Is it possible to do something similar in python?
Could you give any working examples?
| [
"Inventing our own language was a miniscule part of the problem. What was important was developing the right framework, which is now available as Cappuccino (cappuccino.org). \nYou ask what platform/language you could use to develop something similar? I assume you already know that the answer to what platform is th... | [
8,
0
] | [] | [] | [
"python",
"rich_internet_application"
] | stackoverflow_0001385722_python_rich_internet_application.txt |
Q:
How do you check if a widget has focus in Tkinter?
from Tkinter import *
app = Tk()
text_field = Entry(app)
text_field.pack()
app.mainloop()
I want to be able to check if text_field is currently selected or focused, so that I know whether or not to do something with its contents when the user presses enter.
A:
... | How do you check if a widget has focus in Tkinter? | from Tkinter import *
app = Tk()
text_field = Entry(app)
text_field.pack()
app.mainloop()
I want to be able to check if text_field is currently selected or focused, so that I know whether or not to do something with its contents when the user presses enter.
| [
"If you want to do something when the user presses enter only if the focus is on the entry widget, simply add a binding to the entry widget. It will only fire if that widget has focus. For example:\nimport tkinter as tk\n\nroot = tk.Tk()\ne1 = tk.Entry(root)\ne2 = tk.Entry(root)\ne1.pack()\ne2.pack()\n\ndef handleR... | [
29
] | [] | [] | [
"focus",
"python",
"tkinter",
"tkinter_entry"
] | stackoverflow_0001385921_focus_python_tkinter_tkinter_entry.txt |
Q:
is there a way to start/stop linux processes with python?
I want to be able to start a process and then be able to kill it afterwards
A:
Here's a little python script that starts a process, checks if it is running, waits a while, kills it, waits for it to terminate, then checks again. It uses the 'kill' command.... | is there a way to start/stop linux processes with python? | I want to be able to start a process and then be able to kill it afterwards
| [
"Here's a little python script that starts a process, checks if it is running, waits a while, kills it, waits for it to terminate, then checks again. It uses the 'kill' command. Version 2.6 of python subprocess has a kill function. This was written on 2.5.\nimport subprocess\nimport time\n\nproc = subprocess.Popen(... | [
14,
8,
3,
3,
0,
0
] | [] | [] | [
"linux",
"python"
] | stackoverflow_0001378974_linux_python.txt |
Q:
Add Preprocessor to HTML (Probably in Apache)
I would like to add a preprocessor to HTML pages. Basically, I have a program that takes the name of an HTML file containing preprocessor instructions and outputs the contents of the file after preprocessing to stdout. This mechanism could change if it makes things e... | Add Preprocessor to HTML (Probably in Apache) | I would like to add a preprocessor to HTML pages. Basically, I have a program that takes the name of an HTML file containing preprocessor instructions and outputs the contents of the file after preprocessing to stdout. This mechanism could change if it makes things easier. All I want to do is hook this into Apache s... | [
"If you have Apache and a \"preprocessor\" written in python, why not go for mod_python?\n"
] | [
4
] | [] | [] | [
"apache",
"html",
"php",
"preprocessor",
"python"
] | stackoverflow_0001385965_apache_html_php_preprocessor_python.txt |
Q:
How to avoid html-escaping in evoque
I try to make my evoque templates color-code a bit,
but the html I get is already escaped with lt-gt's
I read there should be something like a quoted-no-more class
but I haven't been able to find the evoque.quoted package
My aim is to not have escaped html coming out of the t... | How to avoid html-escaping in evoque | I try to make my evoque templates color-code a bit,
but the html I get is already escaped with lt-gt's
I read there should be something like a quoted-no-more class
but I haven't been able to find the evoque.quoted package
My aim is to not have escaped html coming out of the template, but 'real'.
from pygments import ... | [
"Have you tried it with raw=True? See:\n\nhttp://evoque.gizmojo.org/howto/source/\n\nI haven't used Qpy before, but perhaps this note will help:\n\nDefining custom quoted-no-more classes\n[...] It is also highly recommended to download and install the Qpy unicode templating utility that provides the qpy.xml Quoted... | [
1,
1,
0
] | [] | [] | [
"python"
] | stackoverflow_0001285134_python.txt |
Q:
maximum number combinations
I am trying to generate a list of all possible number combinations within a set of four numbers using all numbers from 0 through 9.
I'm getting close but the output doesn't show every possible combination starting from 0000 all the way to 9999.
Any clues as to why the following code is... | maximum number combinations | I am trying to generate a list of all possible number combinations within a set of four numbers using all numbers from 0 through 9.
I'm getting close but the output doesn't show every possible combination starting from 0000 all the way to 9999.
Any clues as to why the following code is dropping certain combinations?
... | [
"If you have python 2.6, why not use itertools.combinations?\nfrom itertools import combinations\ncombinations(range(10), 4)\n\n",
"This line:\nfor cc in permgen(items[:i]+items[i+1:],n-1):\n\nYou're basically saying \"get a number, than add another one different from ir, repeat n times, then return a list of the... | [
12,
4,
4,
0
] | [] | [] | [
"combinations",
"python"
] | stackoverflow_0001385929_combinations_python.txt |
Q:
SQLCODE -1829 on connect using informixdb
While trying to connect to the database I get a strange error:
DatabaseError: SQLCODE -1829 in CONNECT:
ì¦à : Cannot open file 'os.iem'
ì¦à : Cannot open file 'os.iem'
I can confirm that the file is present in $INFORMIXDIR/msg/en_us/0333/ directory. The environment ... | SQLCODE -1829 on connect using informixdb | While trying to connect to the database I get a strange error:
DatabaseError: SQLCODE -1829 in CONNECT:
ì¦à : Cannot open file 'os.iem'
ì¦à : Cannot open file 'os.iem'
I can confirm that the file is present in $INFORMIXDIR/msg/en_us/0333/ directory. The environment variables INFORMIXDIR, INFORMIXSERVER and ONCON... | [
"ok figured this one out! It appears only the env values set before the import of the informixdb module affect the way the module works. So the following does not work:\nimport informixdb\nos.environ[\"INFORMIXDIR\"] = \"/opt/informix\"\n\n...\ndef conn(db):\n informixdb.connect(db, self.username, self.passwd)\n... | [
1
] | [] | [] | [
"informix",
"python"
] | stackoverflow_0001385731_informix_python.txt |
Q:
'Query' object has no attribute 'kind' when using appcfg.py download_data
I'm having problems with bulk downloads -- all of my data is not being pulled down.
I'm still debugging, but I see in my console:
Traceback (most recent call last):
File "/Users/matthew/local/opt/google_appengine/google/appengine/tools/adapt... | 'Query' object has no attribute 'kind' when using appcfg.py download_data | I'm having problems with bulk downloads -- all of my data is not being pulled down.
I'm still debugging, but I see in my console:
Traceback (most recent call last):
File "/Users/matthew/local/opt/google_appengine/google/appengine/tools/adaptive_thread_pool.py", line 150, in WorkOnItems
status, instruction = item.Perf... | [
"It looks like you've encountered a bug in the bulk downloader, unfortunately. Can you please file a bug report here? It'd help if you can supply the model definition and bulk loader exporter subclass definition.\n"
] | [
1
] | [] | [] | [
"google_app_engine",
"python"
] | stackoverflow_0001386191_google_app_engine_python.txt |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.