Q_Id
int64
337
49.3M
CreationDate
stringlengths
23
23
Users Score
int64
-42
1.15k
Other
int64
0
1
Python Basics and Environment
int64
0
1
System Administration and DevOps
int64
0
1
Tags
stringlengths
6
105
A_Id
int64
518
72.5M
AnswerCount
int64
1
64
is_accepted
bool
2 classes
Web Development
int64
0
1
GUI and Desktop Applications
int64
0
1
Answer
stringlengths
6
11.6k
Available Count
int64
1
31
Q_Score
int64
0
6.79k
Data Science and Machine Learning
int64
0
1
Question
stringlengths
15
29k
Title
stringlengths
11
150
Score
float64
-1
1.2
Database and SQL
int64
0
1
Networking and APIs
int64
0
1
ViewCount
int64
8
6.81M
1,108,918
2009-07-10T10:58:00.000
3
0
0
0
python,mysql,perl,ip-address
1,109,278
7
false
0
0
Having seperate fields doesn't sound particularly sensible to me - much like splitting a zipcode into sections or a phone number. Might be useful if you wanted specific info on the sections, but I see no real reason to not use a 32 bit int.
3
25
0
We've got a healthy debate going on in the office this week. We're creating a Db to store proxy information, for the most part we have the schema worked out except for how we should store IPs. One camp wants to use 4 smallints, one for each octet and the other wants to use a 1 big int,INET_ATON. These tables are going ...
How to store an IP in mySQL
0.085505
1
0
14,213
1,108,967
2009-07-10T11:09:00.000
0
0
0
0
python,django,validation,architecture,django-models
1,108,987
5
false
1
0
I am not sure if this is best practise but what I do is that I tend to validate both client side and server side before pushing the data to the database. I know it requires a lot more effort but this can be done by setting some values before use and then maintaining them. You could also try push in size contraints with...
4
0
0
I use django and I wonder in what cases where model validation should go. There are at least two variants: Validate in the model's save method and to raise IntegrityError or another exception if business rules were violated Validate data using forms and built-in clean_* facilities From one point of view, answer is ob...
Separation of ORM and validation
0
0
0
585
1,108,967
2009-07-10T11:09:00.000
0
0
0
0
python,django,validation,architecture,django-models
1,109,190
5
false
1
0
Your two options are two different things. Form-based validation can be regarded as syntactic validation + convert HTTP request parameters from text to Python types. Model-based validation can be regarded as semantic validation, sometimes using context not available at the HTTP/form layer. And of course there is a th...
4
0
0
I use django and I wonder in what cases where model validation should go. There are at least two variants: Validate in the model's save method and to raise IntegrityError or another exception if business rules were violated Validate data using forms and built-in clean_* facilities From one point of view, answer is ob...
Separation of ORM and validation
0
0
0
585
1,108,967
2009-07-10T11:09:00.000
0
0
0
0
python,django,validation,architecture,django-models
1,109,327
5
false
1
0
"but what the hell all that validation features are doing in django.db.models? " One word: Legacy. Early versions of Django had less robust forms and the validation was scattered. "So should I check such conditions in save method?" No, you should use a form for all validation. "What are the best practices of model val...
4
0
0
I use django and I wonder in what cases where model validation should go. There are at least two variants: Validate in the model's save method and to raise IntegrityError or another exception if business rules were violated Validate data using forms and built-in clean_* facilities From one point of view, answer is ob...
Separation of ORM and validation
0
0
0
585
1,108,967
2009-07-10T11:09:00.000
0
0
0
0
python,django,validation,architecture,django-models
1,111,592
5
false
1
0
DB/Model validation The data store in database must always be in a certain form/state. For example: required first name, last name, foreign key, unique constraint. This is where the logic of you app resides. No matter where you think the data comes from - it should be "validated" here and an exception raised if the re...
4
0
0
I use django and I wonder in what cases where model validation should go. There are at least two variants: Validate in the model's save method and to raise IntegrityError or another exception if business rules were violated Validate data using forms and built-in clean_* facilities From one point of view, answer is ob...
Separation of ORM and validation
0
0
0
585
1,108,974
2009-07-10T11:12:00.000
1
0
1
0
python,development-environment,ubuntu-9.04
1,109,305
7
false
1
0
"Question1: How will i tell any framework that go and use version so and so pf python like day django to use 2.6 and say mjango to use 2.4?" You simply run them with the specific python version they need. Run mjango with /usr/bin/python2.4 and django with /usr/bin/python2.6. As easy as that. "Question2: Is there more e...
2
16
0
Story: One of the app that i have works on python 2.4 and other on 2.6. I tried to do a sym link of python2.4 to python and things started to break loose on ubuntu jaunty. Now i am downloading every dependency of 2.4 and installing it using python2.4 setup.py install. The dependencies seem to be endless. Question1: Ho...
switch versions of python
0.028564
0
0
26,273
1,108,974
2009-07-10T11:12:00.000
0
0
1
0
python,development-environment,ubuntu-9.04
35,381,570
7
false
1
0
Move to the project directory : Create an environment : virtualenv -p python2.7 --no-site-packages ~/env/twoseven Then activate your source : source ~/env/twoseven/bin/activate
2
16
0
Story: One of the app that i have works on python 2.4 and other on 2.6. I tried to do a sym link of python2.4 to python and things started to break loose on ubuntu jaunty. Now i am downloading every dependency of 2.4 and installing it using python2.4 setup.py install. The dependencies seem to be endless. Question1: Ho...
switch versions of python
0
0
0
26,273
1,109,422
2009-07-10T13:08:00.000
1
0
1
0
python,image,python-imaging-library
22,503,379
9
false
0
0
As I commented above, problem seems to be the conversion from PIL internal list format to a standard python list type. I've found that Image.tostring() is much faster, and depending on your needs it might be enough. In my case, I needed to calculate the CRC32 digest of image data, and it suited fine. If you need to per...
1
47
0
Guys, I'm looking for a bit of assistance. I'm a newbie programmer and one of the problems I'm having at the minute is trying to convert a black & white .jpg image into a list which I can then modulate into an audio signal. This is part of a lager project to create a python SSTV program. I have imported the PIL module ...
Getting list of pixel values from PIL
0.022219
0
0
170,867
1,109,498
2009-07-10T13:24:00.000
4
0
0
0
python,fonts,pygame
1,109,553
2
false
0
1
A quick and dirty way would be to render your text multiple times with the outline color, shifted by small amounts on a circle around the text position: 1 8 | 2 \ | / \|/ 7----*----3 /|\ / | \ 6 | 4 5 Edit: Doh you've been faster ! I wont d...
1
7
0
I'm writing a game in python with pygame and need to render text onto the screen. I want to render this text in one colour with an outline, so that I don't have to worry about what sort of background the the text is being displayed over. pygame.font doesn't seem to offer support for doing this sort of thing directly, a...
What's a good way to render outlined fonts?
0.379949
0
0
2,637
1,109,870
2009-07-10T14:27:00.000
7
0
1
0
python,multiprocessing
1,109,930
5
true
0
0
Best is to designate one specific process as owning that instance and dedicated to it; any other process requiring access to that instance obtains it by sending messages to the owning process via a Queue (as supplied by the multiprocessing module) or other IPC mechanisms for message passing, and gets answers back via s...
1
6
0
How can I code to share the same instance of a "singletonic" class among processes?
python singleton into multiprocessing
1.2
0
0
7,503
1,110,804
2009-07-10T17:16:00.000
0
0
0
1
python,subprocess
1,110,847
4
false
0
0
The short answer is that there is no such thing as a good cross platform system for process management, without designing that concept into your system. This is especially in the standar libraries. Even the various unix versions have their own compatibility issues. Your best bet is to instrument all the processes with ...
1
4
0
I would like to be able to spawn a process in python and have two way communication. Of course, Pexpect does this and is indeed a way I might go. However, it is not quite ideal. My ideal situation would be to have a cross platform generic technique that involved only the standard python libraries. Subprocess gets prett...
Python subprocess question
0
0
0
1,227
1,110,805
2009-07-10T17:16:00.000
1
0
0
0
python,sqlalchemy
1,110,990
3
true
0
0
I had some issues with sqlalchemy's performance as well - I think you should first figure out in which ways you are using it ... they recommend that for big data sets is better to use the sql expression language. Either ways try and optimize the sqlalchemy code and have the Oracle database optimized as well, so you can...
2
1
0
HI , I made a ICAPServer (similar with httpserver) for which the performance is very important. The DB module is sqlalchemy. I then made a test about the performance of sqlalchemy, as a result, i found that it takes about 30ms for sqlalchemy to write <50kb data to DB (Oracle), i don`t know if the result is normal, or i...
python sqlalchemy performance?
1.2
1
0
4,462
1,110,805
2009-07-10T17:16:00.000
1
0
0
0
python,sqlalchemy
1,110,888
3
false
0
0
You can only push SQLAlchemy so far as a programmer. I would agree with you that the rest of the performance is up to your DBA, including creating proper indexes on tables, etc.
2
1
0
HI , I made a ICAPServer (similar with httpserver) for which the performance is very important. The DB module is sqlalchemy. I then made a test about the performance of sqlalchemy, as a result, i found that it takes about 30ms for sqlalchemy to write <50kb data to DB (Oracle), i don`t know if the result is normal, or i...
python sqlalchemy performance?
0.066568
1
0
4,462
1,111,173
2009-07-10T18:22:00.000
3
0
0
0
python,django,shopping-cart
1,111,510
3
false
1
0
Ingredients: one cup PayPal (or subsitute with other equivalent payment system) few cups html add css to taste add django if desired Cooking: Mix well. Bake for 1-2 month. Release as open source :-)
1
1
0
Is there a book or a tutorial which teaches how to build a shopping cart with django or any other python framework ?
How to build an Ecommerce Shopping Cart in Django?
0.197375
0
0
10,724
1,111,869
2009-07-10T20:39:00.000
2
0
1
0
python,quine
1,112,795
10
false
0
0
What are quines used for? Programming exercises and viruses. A virus needs to replicate somehow -- and one way is to make it a quine. Let's say that a hypothetical antivirus program would flag any process that read its own binary into memory (to pass it to the intended victim); the way to get around that would to have ...
2
18
0
I came across this term - Quine (also called self-reproducing programs). Just wanted to know more on it. How does one write a quine and are they used anywhere or they are just an exercise for fun? I've started with Python, and I might try writing one in Python. Any suggestions?
What are quines? Any specific purpose to have them?
0.039979
0
0
4,308
1,111,869
2009-07-10T20:39:00.000
9
0
1
0
python,quine
1,764,933
10
false
0
0
As others explained, quines are programs that reproduce exact copies of themselves. With regards to applications, if you think that the DNA encodes logic to interpret itself and reproduce itself - the answer is pretty straightforward, without the concept of quines we wouldn't be here and we would never be able to creat...
2
18
0
I came across this term - Quine (also called self-reproducing programs). Just wanted to know more on it. How does one write a quine and are they used anywhere or they are just an exercise for fun? I've started with Python, and I might try writing one in Python. Any suggestions?
What are quines? Any specific purpose to have them?
1
0
0
4,308
1,112,198
2009-07-10T21:59:00.000
6
0
1
0
python
1,112,223
2
false
1
0
__name__ is usually the module name, but it's changed to '__main__' when the module in question is executed directly instead of being imported by another one. I understand that other values can only be set directly by the code you're running.
1
9
0
Checking to see if __name__ == '__main__' is a common idiom to run some code when the file is being called directly, rather than through a module. In the process of writing a custom command for Django's manage.py, I found myself needing to use code.InteractiveConsole, which gives the effect to the user of a standard py...
What are the different possible values for __name__ in a Python script, and what do they mean?
1
0
0
1,833
1,113,040
2009-07-11T05:45:00.000
1
1
0
1
python,c,macos,fonts
1,113,055
5
false
0
0
Do you want to write a program to do it, or do you want to use a program to do it? There are many programs that list fonts, xlsfonts comes to mind.
1
5
0
I'm trying to programatically get a list of installed fonts in C or Python. I need to be able to do this on OS X, does anyone know how?
List of installed fonts OS X / C
0.039979
0
0
5,834
1,113,066
2009-07-11T06:02:00.000
1
0
0
1
java,python,google-app-engine,httpwebrequest,keep-alive
4,707,002
4
false
1
0
App engine also has a new PAY feature where you can have it "always-on". Costs about $0.30 USD cents a day. Just go into your billing settings and enable it if you don't mind paying for the feature. I believe it guarantees you at least 3 instances always running. (I didn't realize hitting a /ping url which caused an...
1
3
0
App Engine allows you 30 seconds to load your application My application takes around 30 seconds - sometimes more, sometimes less. I don't know how to fix this. If the app is idle (does not receive a request for a while), it needs to be re-loaded. So, to avoid the app needing to be reloaded, I want to simulate user a...
How to keep an App Engine/Java app running with deaf requests from a Java/Python web cron?
0.049958
0
0
1,731
1,113,479
2009-07-11T10:57:00.000
3
1
1
0
python,configuration,google-maps
1,113,496
3
true
0
0
No, there's no standard location - on Windows, it's usually in the directory os.path.join(os.environ['APPDATA'], 'appname') and on Unix it's usually os.path.join(os.environ['HOME'], '.appname').
1
3
0
I have a small Python program, which uses a Google Maps API secret key. I'm getting ready to check-in my code, and I don't want to include the secret key in SVN. In the canonical PHP app you put secret keys, database passwords, and other app specific config in LocalSettings.php. Is there a similar file/location whi...
Where to store secret keys and password in Python
1.2
0
0
3,025
1,114,312
2009-07-11T18:11:00.000
14
0
1
1
python,process
1,114,435
3
false
0
0
os.kill does not kill processes, it sends them signals (it's poorly named). If you send signal 0, you can determine whether you are allowed to send other signals. An error code will indicate whether it's a permission problem or a missing process. See man 2 kill for more info. Also, if the process is your child, you ca...
1
3
0
I have a process id in Python. I know I can kill it with os.kill(), but how do I check if it is alive ? Is there a built-in function or do I have to go to the shell?
How do I check if a process is alive in Python on Linux?
1
0
0
15,728
1,115,238
2009-07-12T03:21:00.000
0
0
0
0
python,database,django,django-models,synchronization
1,117,089
5
false
1
0
Just to throw in an extra opinion - dmigrations is pretty nice and clear to use, but I'd say South is your best bet. Again, it's easy to get into, but it's more powerful and also has support for more database backends than just MySQL. It even handles MSSQL, if that's your thing
2
4
0
If I change a field in a Django model, how can I synchronize it with the database tables? Do I need to do it manually on the database or is there a tool that does helps with the process?
Django Model Sync Table
0
0
0
6,973
1,115,238
2009-07-12T03:21:00.000
4
0
0
0
python,database,django,django-models,synchronization
1,232,838
5
false
1
0
Can't seem to be able to add a comment to the marked answer, probably because I haven't got enough rep (be nice if SO told me so though). Anyway, just wanted to add that in the answered post, I believe it is wrong about syncdb - syncdb does not touch tables once they have been created and have data in them. You should ...
2
4
0
If I change a field in a Django model, how can I synchronize it with the database tables? Do I need to do it manually on the database or is there a tool that does helps with the process?
Django Model Sync Table
0.158649
0
0
6,973
1,115,420
2009-07-12T06:32:00.000
8
0
1
0
python,django,thread-safety
1,115,427
2
false
1
0
Functions in a module are equivalent to static methods in a class. The issue of thread safety arises when multiple threads may be modifying shared data, or even one thread may be modifying such data while others are reading it; it's best avoided by making data be owned by ONE module (accessed via Queue.Queue from other...
1
3
0
In python with all this idea of "Everything is an object" where is thread-safety? I am developing django website with wsgi. Also it would work in linux, and as I know they use effective process management, so we could not think about thread-safety alot. I am not doubt in how module loads, and there functions are static...
Static methods and thread safety
1
0
0
3,314
1,116,163
2009-07-12T14:54:00.000
0
0
1
0
python,sqlalchemy,twisted
1,116,170
3
false
0
0
Put an upper limit on the amount of data in the queue?
2
0
0
My program is ICAPServer (similar with httpserver), it's main job is to receive data from clients and save the data to DB. There are two main steps and two threads: ICAPServer receives data from clients, puts the data in a queue (50kb <1ms); another thread pops data from the queue, and writes them to DB SO, if 2nd ste...
python program choice
0
0
0
232
1,116,163
2009-07-12T14:54:00.000
2
0
1
0
python,sqlalchemy,twisted
1,116,224
3
false
0
0
It is hard to say for sure, but perhaps using two processes instead of threads will help in this situation. Since Python has the Global Interpreter Lock (GIL), it has the effect of only allowing any one thread to execute Python instructions at any time. Having a system designed around processes might have the followin...
2
0
0
My program is ICAPServer (similar with httpserver), it's main job is to receive data from clients and save the data to DB. There are two main steps and two threads: ICAPServer receives data from clients, puts the data in a queue (50kb <1ms); another thread pops data from the queue, and writes them to DB SO, if 2nd ste...
python program choice
0.132549
0
0
232
1,116,362
2009-07-12T16:25:00.000
3
0
0
0
python,cookies,urllib2,cookiejar
1,116,535
4
true
1
0
If all pages have the same JavaScript then maybe you could parse the HTML to find that piece of code, and from that get the value the cookie would be set to? That would make your scraping quite vulnerable to changes in the third party website, but that's most often the case while scraping. (Please bear in mind that th...
1
2
0
I've had a look at many tutorials regarding cookiejar, but my problem is that the webpage that i want to scape creates the cookie using javascript and I can't seem to retrieve the cookie. Does anybody have a solution to this problem?
Retrieve cookie created using javascript in python
1.2
0
0
2,627
1,116,449
2009-07-12T17:13:00.000
4
1
1
0
python,unicode
1,116,549
6
false
0
0
Additional to Mihails comment I would say: Use Unicode, since it is the future. In Python 3.0, Non-Unicode will be gone, and as much I know, all the "U"-Prefixes will make trouble, since they are also gone.
5
20
0
Is it considered as a good practice to pick Unicode string over regular string when coding in Python? I mainly work on the Windows platform, where most of the string types are Unicode these days (i.e. .NET String, '_UNICODE' turned on by default on a new c++ project, etc ). Therefore, I tend to think that the case wher...
Should I use Unicode string by default?
0.132549
0
0
3,614
1,116,449
2009-07-12T17:13:00.000
19
1
1
0
python,unicode
1,116,476
6
true
0
0
From my practice -- use unicode. At beginning of one project we used usuall strings, however our project was growing, we were implementing new features and using new third-party libraries. In that mess with non-unicode/unicode string some functions started failing. We started spending time localizing this problems and...
5
20
0
Is it considered as a good practice to pick Unicode string over regular string when coding in Python? I mainly work on the Windows platform, where most of the string types are Unicode these days (i.e. .NET String, '_UNICODE' turned on by default on a new c++ project, etc ). Therefore, I tend to think that the case wher...
Should I use Unicode string by default?
1.2
0
0
3,614
1,116,449
2009-07-12T17:13:00.000
2
1
1
0
python,unicode
1,116,487
6
false
0
0
If you are dealing with severely constrained memory or disk space, use ASCII strings. In this case, you should additionally write your software in C or something even more compact :)
5
20
0
Is it considered as a good practice to pick Unicode string over regular string when coding in Python? I mainly work on the Windows platform, where most of the string types are Unicode these days (i.e. .NET String, '_UNICODE' turned on by default on a new c++ project, etc ). Therefore, I tend to think that the case wher...
Should I use Unicode string by default?
0.066568
0
0
3,614
1,116,449
2009-07-12T17:13:00.000
13
1
1
0
python,unicode
1,116,660
6
false
0
0
Yes, use unicode. Some hints: When doing input output in any sort of binary format, decode directly after reading and encode directly before writing, so that you never need to mix strings and unicode. Because mixing that tends to lead to UnicodeEncodeDecodeErrors sooner or later. [Forget about this one, my explanatio...
5
20
0
Is it considered as a good practice to pick Unicode string over regular string when coding in Python? I mainly work on the Windows platform, where most of the string types are Unicode these days (i.e. .NET String, '_UNICODE' turned on by default on a new c++ project, etc ). Therefore, I tend to think that the case wher...
Should I use Unicode string by default?
1
0
0
3,614
1,116,449
2009-07-12T17:13:00.000
6
1
1
0
python,unicode
1,116,581
6
false
0
0
It can be tricky to consistently use unicode strings in Python 2.x - be it because somebody inadvertently uses the more natural str(blah) where they meant unicode(blah), forgetting the u prefix on string literals, third-party module incompatibilities - whatever. So in Python 2.x, use unicode only if you have to, and ar...
5
20
0
Is it considered as a good practice to pick Unicode string over regular string when coding in Python? I mainly work on the Windows platform, where most of the string types are Unicode these days (i.e. .NET String, '_UNICODE' turned on by default on a new c++ project, etc ). Therefore, I tend to think that the case wher...
Should I use Unicode string by default?
1
0
0
3,614
1,116,725
2009-07-12T19:36:00.000
0
0
0
0
python,excel,formula
1,116,782
6
false
0
0
If you are using COM bindings, then you can simply record a macro in Excel, then translate it into Python code. If you are using xlwt, you have to resort to normal loops in python..
1
1
0
I would like to insert a calculation in Excel using Python. Generally it can be done by inserting a formula string into the relevant cell. However, if i need to calculate a formula multiple times for the whole column the formula must be updated for each individual cell. For example, if i need to calculate the sum of t...
Calculating formulae in Excel with Python
0
1
0
12,592
1,116,948
2009-07-12T21:19:00.000
19
0
1
0
python,django
1,117,692
2
false
1
0
settings.py is for Django settings; it's fine to put your own settings in there, but using it for arbitrary non-configuration data structures isn't good practice. Just put it in the module it logically belongs to, and it'll be run just once per instance. If you want to guarantee that the module is loaded on startup an...
2
10
0
I have a big array, that I would like to load into memory only once when django starts up and then treat it as a read only global variable. What is the best place to put the code for the initialization of that array? If I put it in settings.py it will be reinitialized every time the settings module is imported, correct...
Django Initialization
1
0
0
6,064
1,116,948
2009-07-12T21:19:00.000
9
0
1
0
python,django
1,117,100
2
true
1
0
settings.py is the right place for that. Settings.py is, like any other module, loaded once. There is still the problem of the fact that a module must be imported once for each process, so a respawning style of web server (like apache) will reload it once for each instance in question. For mod_python this will be on...
2
10
0
I have a big array, that I would like to load into memory only once when django starts up and then treat it as a read only global variable. What is the best place to put the code for the initialization of that array? If I put it in settings.py it will be reinitialized every time the settings module is imported, correct...
Django Initialization
1.2
0
0
6,064
1,116,990
2009-07-12T21:35:00.000
2
0
1
0
python,decimal,precision
20,875,524
3
false
0
0
I know this question was a long time ago, but I figured people probably still search something like this so I figured I'd mention some things to keep in mind when doing it since I tried coding and eventually changed my mind to using long division and finding where repetition occurs when you get a remainder after dividi...
2
9
0
I'm working with fractions using Python's decimal module and I'd like to get just the repeating part of a certain fraction. For example: if I had 1/3 I'd like to get 3, if I had 1/7 I'd like to get 142857. Is there any standard function to do this?
Is there any way to get the repeating decimal section of a fraction in Python?
0.132549
0
0
17,332
1,116,990
2009-07-12T21:35:00.000
2
0
1
0
python,decimal,precision
1,117,033
3
false
0
0
Find the first number of the form 10**k - 1 that divides exactly by the denominator of the fraction, divide it by the denominator and multiply by the numerator and you get your repeating part.
2
9
0
I'm working with fractions using Python's decimal module and I'd like to get just the repeating part of a certain fraction. For example: if I had 1/3 I'd like to get 3, if I had 1/7 I'd like to get 142857. Is there any standard function to do this?
Is there any way to get the repeating decimal section of a fraction in Python?
0.132549
0
0
17,332
1,117,414
2009-07-13T01:29:00.000
0
0
0
1
python,filesystems,cygwin,path,utilities
1,117,427
3
false
0
0
What happens when you type "ls"? Do you see "infile.txt" listed there?
1
1
0
I have lots of directories with text files written using (g)vim, and I have written a handful of utilities that I find useful in Python. I start off the utilities with a pound-bang-/usr/bin/env python line in order to use the Python that is installed under cygwin. I would like to type commands like this: %cd ~/SomeBo...
How do I tell a Python script (cygwin) to work in current (or relative) directories?
0
0
0
2,062
1,117,538
2009-07-13T02:44:00.000
1
0
0
0
python,sqlalchemy
1,117,592
2
false
0
0
As long as each concurrent thread has it's own session you should be fine. Trying to use one shared session is where you'll get into trouble.
1
0
0
HI,i got a multi-threading program which all threads will operate on oracle DB. So, can sqlalchemy support parallel operation on oracle? tks!
python sqlalchemy parallel operation
0.099668
1
0
2,195
1,117,828
2009-07-13T05:31:00.000
1
0
0
0
python,mysql,exception
1,117,841
2
false
0
0
I think that the connections and the query can raised errors so you should have try/excepy for both of them.
2
9
0
Just starting to get to grips with python and MySQLdb and was wondering Where is the best play to put a try/catch block for the connection to MySQL. At the MySQLdb.connect point? Also should there be one when ever i query? What exceptions should i be catching on any of these blocks? thanks for any help Cheers Mark
Python MySQLdb exceptions
0.099668
1
0
5,063
1,117,828
2009-07-13T05:31:00.000
16
0
0
0
python,mysql,exception
1,118,129
2
true
0
0
Catch the MySQLdb.Error, while connecting and while executing query
2
9
0
Just starting to get to grips with python and MySQLdb and was wondering Where is the best play to put a try/catch block for the connection to MySQL. At the MySQLdb.connect point? Also should there be one when ever i query? What exceptions should i be catching on any of these blocks? thanks for any help Cheers Mark
Python MySQLdb exceptions
1.2
1
0
5,063
1,117,958
2009-07-13T06:36:00.000
2
0
0
1
python,sockets,raw-sockets
1,186,810
8
false
0
0
Eventually the best solution for this case was to write the entire thing in C, because it's not a big application, so it would've incurred greater penalty to write such a small thing in more than 1 language. After much toying with both the C and python RAW sockets, I eventually preferred the C RAW sockets. RAW sockets ...
1
46
0
I am writing an application to test a network driver for handling corrupted data. And I thought of sending this data using raw socket, so it will not be corrected by the sending machine's TCP-IP stack. I am writing this application solely on Linux. I have code examples of using raw sockets in system-calls, but I would ...
How Do I Use Raw Socket in Python?
0.049958
0
1
109,072
1,118,163
2009-07-13T07:49:00.000
-1
0
0
0
python,django,google-app-engine,turbogears,turbogears2
51,161,118
7
false
1
0
Django ORM uses the active record implementation – you’ll see this implementation in most ORMs. Basically what it means is that each row in the database is directly mapped to an object in the code and vice versa. ORM frameworks such as Django won’t require predefining the schema to use the properties in the code. You j...
4
12
0
I have been using Turbogears 1 for prototyping small sites for the last couple of years and it is getting a little long in the tooth. Any suggestions on making the call between upgrading to Turbogears 2 or switching to something like Django? I'm torn between the familiarity of the TG community who are pretty responsive...
Turbogears 2 vs Django - any advice on choosing replacement for Turbogears 1?
-0.028564
0
0
20,511
1,118,163
2009-07-13T07:49:00.000
-1
0
0
0
python,django,google-app-engine,turbogears,turbogears2
1,584,576
7
false
1
0
Ive only got one question...is the app you are developing directed towards social networking or customized business logic? I personally find Django is good for social networking and pylons/turbogears if you really want the flexibility and no boundaries... just my 2c
4
12
0
I have been using Turbogears 1 for prototyping small sites for the last couple of years and it is getting a little long in the tooth. Any suggestions on making the call between upgrading to Turbogears 2 or switching to something like Django? I'm torn between the familiarity of the TG community who are pretty responsive...
Turbogears 2 vs Django - any advice on choosing replacement for Turbogears 1?
-0.028564
0
0
20,511
1,118,163
2009-07-13T07:49:00.000
4
0
0
0
python,django,google-app-engine,turbogears,turbogears2
1,118,237
7
false
1
0
I have been using Django for a year now and when I started I had no experience of Python or Django and found it very intuitive to use. I have created a number of hobbyist Google App Engine apps using Django with the latest one being a CMS for my site. Using Django has meant that I have been able to code a lot quicker a...
4
12
0
I have been using Turbogears 1 for prototyping small sites for the last couple of years and it is getting a little long in the tooth. Any suggestions on making the call between upgrading to Turbogears 2 or switching to something like Django? I'm torn between the familiarity of the TG community who are pretty responsive...
Turbogears 2 vs Django - any advice on choosing replacement for Turbogears 1?
0.113791
0
0
20,511
1,118,163
2009-07-13T07:49:00.000
11
0
0
0
python,django,google-app-engine,turbogears,turbogears2
1,118,670
7
true
1
0
I have experience with both Django and TG1.1. IMO, TurboGears strong point is it's ORM: SQLAlchemy. I prefer TurboGears when the database side of things is non-trivial. Django's ORM is just not that flexible and powerful. That being said, I prefer Django. If the database schema is a good fit with Django's ORM I would g...
4
12
0
I have been using Turbogears 1 for prototyping small sites for the last couple of years and it is getting a little long in the tooth. Any suggestions on making the call between upgrading to Turbogears 2 or switching to something like Django? I'm torn between the familiarity of the TG community who are pretty responsive...
Turbogears 2 vs Django - any advice on choosing replacement for Turbogears 1?
1.2
0
0
20,511
1,118,266
2009-07-13T08:27:00.000
0
0
0
0
python,audio
1,120,253
3
false
0
0
All you need to do is just append the new data on the end of your wav file. So if you haven't closed your file, just keep writing to it, or if you have, reopen it in append mode (w = open(myfile, 'ba')) and write the new data. For this to sound reasonable without clicks and such, the trick will be to make the waveform...
1
0
0
Im trying to engineer in python a way of transforming a list of integer values between 0-255 into representative equivalent tones from 1500-2200Hz. Timing information (at 1200Hz) is given by the (-1),(-2) and (-3) values. I have created a function that generates a .wav file and then call this function with the paramete...
List of values to a sound file
0
0
0
1,399
1,118,761
2009-07-13T10:40:00.000
1
0
0
1
python,django,google-app-engine
1,118,790
4
false
1
0
There are a few things that you can't do on the App Engine that you can do on your own server like uploading of files. On the App Engine you kinda have to upload it and store the datastore which can cause a few problems. Other than that it should be fine from the Presentation part. There are a number of other little th...
2
9
0
I'm developing a web application and considering Django, Google App Engine, and several other options. I wondered what kind of "penalty" I will incur if I develop a complete Django application assuming it runs on a dedicated server, and then later want to migrate it to Google App Engine. I have a basic understanding of...
Migrating Django Application to Google App Engine?
0.049958
1
0
1,845
1,118,761
2009-07-13T10:40:00.000
8
0
0
1
python,django,google-app-engine
1,119,377
4
true
1
0
Most (all?) of Django is available in GAE, so your main task is to avoid basing your designs around a reliance on anything from Django or the Python standard libraries which is not available on GAE. You've identified the glaring difference, which is the database, so I'll assume you're on top of that. Another difference...
2
9
0
I'm developing a web application and considering Django, Google App Engine, and several other options. I wondered what kind of "penalty" I will incur if I develop a complete Django application assuming it runs on a dedicated server, and then later want to migrate it to Google App Engine. I have a basic understanding of...
Migrating Django Application to Google App Engine?
1.2
1
0
1,845
1,119,696
2009-07-13T14:15:00.000
7
0
1
0
java,python,integration
58,624,426
12
false
1
0
The best solutions, is to use Python programs throw REST API. You define your services and call them. You perhaps need to learn some new modules. But you will be more flexible for futures changes. Here a small list of use full modules for this purpose: Python modules Flask Flask-SQLAlchemy Flask-Restful SQlite3 Jsonif...
1
57
0
I have a Java app that needs to integrate with a 3rd party library. The library is written in Python, and I don't have any say over that. I'm trying to figure out the best way to integrate with it. I'm trying out JEPP (Java Embedded Python) - has anyone used that before? My other thought is to use JNI to communicate wi...
Java Python Integration
1
0
0
81,995
1,119,722
2009-07-13T14:19:00.000
3
1
1
0
python,math,base62
1,119,762
22
false
0
0
You probably want base64, not base62. There's an URL-compatible version of it floating around, so the extra two filler characters shouldn't be a problem. The process is fairly simple; consider that base64 represents 6 bits and a regular byte represents 8. Assign a value from 000000 to 111111 to each of the 64 character...
1
103
0
How would you convert an integer to base 62 (like hexadecimal, but with these digits: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'). I have been trying to find a good Python library for it, but they all seems to be occupied with converting strings. The Python base64 module only accepts strings and t...
Base 62 conversion
0.027266
0
0
83,868
1,120,297
2009-07-13T15:48:00.000
0
0
0
1
java,python,android,platform
1,121,377
3
false
1
0
I'd throw down another vote for Eclipse. I've been using it on the mac and I find it to be very buggy. Not sure if that's just the nature of the beast... My experiences with it on XP have been more stable. Haven't had time to check it out on Ubuntu.
2
4
0
I am interested in developing things for google apps and android using python and java. I am new to both and was wondering if a environment set in windows or linux would be more productive for these tasks?
Platform for developing all things google?
0
0
0
263
1,120,297
2009-07-13T15:48:00.000
0
0
0
1
java,python,android,platform
1,122,211
3
false
1
0
Internally, I believe Google uses Eclipse running on Ubuntu for Android development, so that'd be your best bet if you're completely paranoid about avoiding all potential issues. Of course, this is impossible, and really you should just use whatever you're comfortable in.
2
4
0
I am interested in developing things for google apps and android using python and java. I am new to both and was wondering if a environment set in windows or linux would be more productive for these tasks?
Platform for developing all things google?
0
0
0
263
1,120,914
2009-07-13T17:31:00.000
1
0
0
0
python,django,django-templates
1,120,987
2
false
1
0
The answer to this depends a lot on how you've structured your data, which you don't say - are the extra bits of information in separate related tables, subclassed models, individual fields on the same model...? In general, this sounds like a job for a template tag. I would probably write a custom tag that took your pa...
1
0
0
I just started using django for development. At the moment, I have the following issue: I have to write a page template able to represent different categories of data. For example, suppose I have a medical record of a patient. The represented information about this patient are, for example: name, surname and similar d...
Django templates: adding sections conditionally
0.099668
0
0
235
1,121,299
2009-07-13T18:40:00.000
1
0
0
0
python,django,session
1,121,363
1
true
1
0
Sessions are lazily loaded: if you don't use the session during a request, Django won't load it. This includes request.user: if you access it, it accesses the session to find the user. (It loads lazily, too--if you don't access request.user, it won't access the session, either.) So, figure out what's accessing the ses...
1
0
0
I was wondering if I could eliminate django session calls for specific views. For example, if I have a password reset form I don't want a call to the DB to check for a session or not. Thanks!
Eliminating certain Django Session Calls
1.2
0
0
208
1,121,951
2009-07-13T20:48:00.000
3
0
0
0
python
1,122,107
2
false
0
0
AFAIK, the numbers of internet sockets (necessary to make TCP/IP connections) is naturally limited on every machine, but it's pretty high. 1000 simulatneous connections shouldn't be a problem for the client machine, as each socket uses only little memory. If you start receiving data through all these channels, this mig...
1
4
0
To be more specific, I'm using python and making a pool of HTTPConnection (httplib) and was wondering if there is an limit on the number of concurrent HTTP connections on a windows server.
What is the maximum simultaneous HTTP connections allowed on one machine (windows server 2008) using python
0.291313
0
1
4,587
1,122,537
2009-07-13T22:53:00.000
0
0
0
0
python,thread-safety,pylons
1,128,979
2
false
0
0
Whatever you were to set on the request will only survive for the duration of the request. the problem you are describing is more appropriately handled with a Session as TCH4k has said. It's already enabled in the middleware, so go ahead.
1
2
0
I want keep track of a unique identifier for each browser that connects to my web application (that is written in Pylons.) I keep a cookie on the client to keep track of this, but if the cookie isn't present, then I want to generate a new unique identifier that will be sent back to the client with the response, but I ...
What can I attach to pylons.request in Pylons?
0
0
0
470
1,122,924
2009-07-14T00:45:00.000
1
0
1
1
python,bash,path,cygwin,reboot
1,123,139
4
false
0
0
A couple of things to try and rule out at least: Do you get the same behavior as the following from the shell? (Pasted from my cygwin, which works as expected.) $ echo $PATH /usr/local/bin:/usr/bin:/bin $ export PATH=$PATH:/cygdrive/c/python/bin $ echo $PATH /usr/local/bin:/usr/bin:/bin:/cygdrive/c/python/bin Is y...
2
5
0
I wanted to use the Python installed under cygwin rather than one installed under WinXP directly, so I edited ~/.bashrc and sourced it. Nothing changed. I tried other things, but nothing I did changed $PATH in any way. So I rebooted. Aha; now $PATH has changed to what I wanted. But, can anyone explain WHY this happ...
bash/cygwin/$PATH: Do I really have to reboot to alter $PATH?
0.049958
0
0
9,783
1,122,924
2009-07-14T00:45:00.000
2
0
1
1
python,bash,path,cygwin,reboot
1,123,086
4
false
0
0
If you want your changes to be permanent, you should modify the proper file (.bashrc in this case) and perform ONE of the following actions: Restart the cygwin window source .bashrc (This should work, even if is not working for you) . .bashrc (that is dot <space> <filename>) However, .bashrc is used by default when u...
2
5
0
I wanted to use the Python installed under cygwin rather than one installed under WinXP directly, so I edited ~/.bashrc and sourced it. Nothing changed. I tried other things, but nothing I did changed $PATH in any way. So I rebooted. Aha; now $PATH has changed to what I wanted. But, can anyone explain WHY this happ...
bash/cygwin/$PATH: Do I really have to reboot to alter $PATH?
0.099668
0
0
9,783
1,124,810
2009-07-14T11:30:00.000
0
0
1
1
python
1,124,862
6
false
0
0
Uh... This question is a bit unclear. What do you mean "have"? Do you have the name of the file? Have you opened it? Is it a file object? Is it a file descriptor? What??? If it's a name, what do you mean with "find"? Do you want to search for the file in a bunch of directories? Or do you know which directory it's in? I...
1
11
0
I have a file, for example "something.exe" and I want to find path to this file How can I do this in python?
How can I find path to given file?
0
0
0
91,787
1,126,116
2009-07-14T15:19:00.000
13
0
0
1
python,shell,variables,subprocess,persistent
1,126,137
2
true
0
0
subprocess.Popen takes an optional named argument env that's a dictionary to use as the subprocess's environment (what you're describing as "shell variables"). Prepare a dict as you need it (you may start with a copy of os.environ and alter that as you need) and pass it to all the subprocess.Popen calls you perform.
1
8
0
I'm trying to execute a series of commands using Pythons subprocess module, however I need to set shell variables with export before running them. Of course the shell doesn't seem to be persistent so when I run a command later those shell variables are lost. Is there any way to go about this? I could create a /bin/sh p...
Python: Persistent shell variables in subprocess
1.2
0
0
3,185
1,126,173
2009-07-14T15:28:00.000
0
1
1
0
python,unit-testing,testing,tdd
8,462,601
7
false
0
0
I started unit testing a handful of years ago, and I've read quite a few on it since my initial book. However, my initial was "Test Driven" by Lasse. For me, the author made it simple to understand. Perhaps you could pull some info from it for your teaching. And btw, I've taught TDD as well. I have found that ensuring ...
1
17
0
I'm working with a Python development team who is experienced with programming in Python, but is just now trying to pick up TDD. Since I have some experience working with TDD myself, I've been asked to give a presentation on it. Mainly, I'm just wanting to see articles on this so that I can see how other people are t...
Are there any good online tutorials to TDD for an experienced programmer who is new to testing?
0
0
0
6,164
1,126,842
2009-07-14T17:28:00.000
0
0
1
0
python,windows-xp,cygwin
1,128,193
5
false
0
0
This probably has little value, but... I found myself in this exact situation -- we use ActivePython2.5 in production (pure windows environment) and I was trying to do my development within cygwin and cygwin's Python... After ripping out half of my hair, I have now switched over to Console2, gvim, iPython and ActivePy...
4
3
0
Pythons installed under WinXP have dirs like DLLs, DOC, include, etc. but python (2.5) installed with cygwin is a bare python.exe. My motivation for asking is that 'things' under XP don't seem to be finding 'other things' under cygwin and vice versa, I want to start developing with Qt, I like shells, and I do not like...
Best way to have full Python install under cygwin/XP?
0
0
0
2,747
1,126,842
2009-07-14T17:28:00.000
2
0
1
0
python,windows-xp,cygwin
1,126,885
5
true
0
0
I use Python from within cygwin, but I don't use the version that cygwin gives you the option of installing as I don't have the control over version number used that I need (we use an older version at work). I have my python version installed via the windows installer (the xp version as you put it) and add the /cygdri...
4
3
0
Pythons installed under WinXP have dirs like DLLs, DOC, include, etc. but python (2.5) installed with cygwin is a bare python.exe. My motivation for asking is that 'things' under XP don't seem to be finding 'other things' under cygwin and vice versa, I want to start developing with Qt, I like shells, and I do not like...
Best way to have full Python install under cygwin/XP?
1.2
0
0
2,747
1,126,842
2009-07-14T17:28:00.000
0
0
1
0
python,windows-xp,cygwin
1,126,874
5
false
0
0
Just a little off the question, but... Have you considered running Sun's VirtualBox with Fedora or Ubuntu inside of it? I'm assuming you have to / need to use windows because you still are, but don't like it. Then you would have python running inside a native linux desktop without any of the troubles you mentioned. A...
4
3
0
Pythons installed under WinXP have dirs like DLLs, DOC, include, etc. but python (2.5) installed with cygwin is a bare python.exe. My motivation for asking is that 'things' under XP don't seem to be finding 'other things' under cygwin and vice versa, I want to start developing with Qt, I like shells, and I do not like...
Best way to have full Python install under cygwin/XP?
0
0
0
2,747
1,126,842
2009-07-14T17:28:00.000
0
0
1
0
python,windows-xp,cygwin
11,792,553
5
false
0
0
I accidentally stumbled on this - If I launch Cygwin from the Cygwin.bat file (which is present directly under the main folder), I get access to the Python version installed under Cygwin (i.e 2.6.8) If I instead launch the Cygwin from bash.exe under bin directory (C:\Cygwin\bin\bash.exe for me), running "Python -V" sho...
4
3
0
Pythons installed under WinXP have dirs like DLLs, DOC, include, etc. but python (2.5) installed with cygwin is a bare python.exe. My motivation for asking is that 'things' under XP don't seem to be finding 'other things' under cygwin and vice versa, I want to start developing with Qt, I like shells, and I do not like...
Best way to have full Python install under cygwin/XP?
0
0
0
2,747
1,126,930
2009-07-14T17:45:00.000
0
0
1
0
python,shell,debugging,ipython,pdb
51,654,762
13
false
0
0
This is pretty simple: ipython some_script.py --pdb It needs iPython installing, usually this works: pip install ipython I use ipython3 instead of ipython, so I know it's a recent version of Python. This is simple to remember because you just use iPython instead of python, and add --pdb to the end.
2
84
0
For my debugging needs, pdb is pretty good. However, it would be much cooler (and helpful) if I could go into ipython. Is this thing possible?
Is it possible to go into ipython from code?
0
0
0
23,603
1,126,930
2009-07-14T17:45:00.000
8
0
1
0
python,shell,debugging,ipython,pdb
1,127,042
13
false
0
0
Normally, when I use ipython, I turn automatic debugging on with the "pdb" command inside it. I then run my script with the "run myscript.py" command in the directory where my script is located. If I get an exception, ipython stops the program inside the debugger. Check out the help command for the magic ipython comma...
2
84
0
For my debugging needs, pdb is pretty good. However, it would be much cooler (and helpful) if I could go into ipython. Is this thing possible?
Is it possible to go into ipython from code?
1
0
0
23,603
1,127,836
2009-07-14T20:29:00.000
1
0
1
0
python,garbage-collection,cpython
1,128,216
5
false
0
0
It might also be the case that a reference was leaked by a buggy C extension, IMHO you will not see the referer, yet still the refcount does not go down to 0. You might want to check the return value of sys.getrefcount.
2
4
0
Should it be possible for gc.get_referrers(obj) to return an empty list for an object, but the object still be accessible through a weak reference? If so how would I start trying to identify the cause for this object not being garbage collected? Edit: I'm not sure exactly how a code sample would help in this case - the...
Python object has no referrers but still accessible via a weakref?
0.039979
0
0
2,129
1,127,836
2009-07-14T20:29:00.000
1
0
1
0
python,garbage-collection,cpython
4,093,658
5
false
0
0
I am glad you have found your problem, unrelated to the initial question. Nonetheless, I have a different take on the answer for posterity, in case others have the problem. It IS legal for the object to have no referrers and yet not be garbage collected. From the Python 2.7 manual: "An implementation is allowed to post...
2
4
0
Should it be possible for gc.get_referrers(obj) to return an empty list for an object, but the object still be accessible through a weak reference? If so how would I start trying to identify the cause for this object not being garbage collected? Edit: I'm not sure exactly how a code sample would help in this case - the...
Python object has no referrers but still accessible via a weakref?
0.039979
0
0
2,129
1,129,210
2009-07-15T03:15:00.000
1
0
0
0
python,ajax,django
1,129,395
4
false
1
0
Maybe a few iFrames and some Comet/long-polling? Have the comment submission in an iFrame (so the whole page doesn't reload), and then show the result in the long-polled iFrame... Having said that, it's a pretty bad design idea, and you probably don't want to be doing this. AJAX/JavaScript is pretty much the way to go ...
2
0
0
As far as I know, for a new request coming from a webapp, you need to reload the page to process and respond to that request. For example, if you want to show a comment on a post, you need to reload the page, process the comment, and then show it. What I want, however, is I want to be able to add comments (something...
creating non-reloading dynamic webapps using Django
0.049958
0
0
823
1,129,210
2009-07-15T03:15:00.000
8
0
0
0
python,ajax,django
1,129,222
4
true
1
0
You want to do that with out any client side code (javascript and ajax are just examples) and with out reloading your page (or at least part of it)? If that is your question, then the answer unfortunately is you can't. You need to either have client side code or reload your page. Think about it, once the client get's t...
2
0
0
As far as I know, for a new request coming from a webapp, you need to reload the page to process and respond to that request. For example, if you want to show a comment on a post, you need to reload the page, process the comment, and then show it. What I want, however, is I want to be able to add comments (something...
creating non-reloading dynamic webapps using Django
1.2
0
0
823
1,130,697
2009-07-15T10:50:00.000
1
1
0
0
python,ruby,jruby,jython
1,130,727
5
false
1
0
The compatibility in either case is at the source-code level; with necessary changes where the Python or Ruby code invokes packages that involve native code (especially, standard Python packages like ctypes are not present in Jython).
3
4
0
It's a high level conceptual question. I have two separate code bases that serve the same purpose, one built in Python and the other in Ruby. I need to develop something that will run on JVM. So I have two choices: convert the Python code to Jython or convert the Ruby to JRuby. Since I don't know any of them, I was won...
Jython or JRuby?
0.039979
0
0
5,421
1,130,697
2009-07-15T10:50:00.000
1
1
0
0
python,ruby,jruby,jython
1,140,847
5
false
1
0
Anything you can do in one, you can do in the other. Learn enough of both to realise which one appeals to your coding sensibilities. There is no right or wrong answer here.
3
4
0
It's a high level conceptual question. I have two separate code bases that serve the same purpose, one built in Python and the other in Ruby. I need to develop something that will run on JVM. So I have two choices: convert the Python code to Jython or convert the Ruby to JRuby. Since I don't know any of them, I was won...
Jython or JRuby?
0.039979
0
0
5,421
1,130,697
2009-07-15T10:50:00.000
5
1
0
0
python,ruby,jruby,jython
1,130,722
5
false
1
0
In both cases, most of the code should Just Work™. I don't know of a really compelling reason to choose Jython over JRuby or vice versa if you'll be learning either from scratch. Python places a heavy emphasis on readability and not using "magic", but Ruby tends to give you a little more rope to do fancy things, e.g., ...
3
4
0
It's a high level conceptual question. I have two separate code bases that serve the same purpose, one built in Python and the other in Ruby. I need to develop something that will run on JVM. So I have two choices: convert the Python code to Jython or convert the Ruby to JRuby. Since I don't know any of them, I was won...
Jython or JRuby?
0.197375
0
0
5,421
1,130,992
2009-07-15T12:04:00.000
-1
1
1
0
python,data-structures,dictionary,lookup
1,131,017
4
false
0
0
string array. then binary search through it to search the first match then step one by one through it for all subsequent matches (i originally had linked list here too... but of course this doesn't have random access so this was 'bs' (which probably explains why I was downvoted). My binary search algorithm still is the...
1
6
0
I'm writing an application that needs to read a list of strings from a file, save them in a data structure, and then look up those strings by prefixes. The list of strings is simply a list of words in a given language. For example, if the search function gets "stup" as a parameter, it should return ["stupid", "stupidit...
most efficient data structure for a read-only list of strings (about 100,000) with fast prefix search
-0.049958
0
0
3,095
1,131,430
2009-07-15T13:32:00.000
63
0
1
0
python,multithreading,thread-safety,generator
1,131,458
6
true
0
0
It's not thread-safe; simultaneous calls may interleave, and mess with the local variables. The common approach is to use the master-slave pattern (now called farmer-worker pattern in PC). Make a third thread which generates data, and add a Queue between the master and the slaves, where slaves will read from the queue,...
1
49
0
I have a multithreaded program where I create a generator function and then pass it to new threads. I want it to be shared/global in nature so each thread can get the next value from the generator. Is it safe to use a generator like this, or will I run into problems/conditions accessing the shared generator from multi...
Are Generators Threadsafe?
1.2
0
0
18,065
1,131,599
2009-07-15T14:01:00.000
2
0
1
0
python,oop,multiple-inheritance
1,131,636
8
false
0
0
It doesn't sound like you really need multiple inheritance. In fact, you don't ever really need multiple inheritance. It's just a question of whether multiple inheritance simplifies things (which I couldn't see as being the case here). I would create a Person class that has all the code that the adult and student wou...
4
9
0
I have the following problem and I'm wondering if there's a nice way to model these objects without using multiple inheritance. If it makes any difference, I am using Python. Students need contact information plus student information. Adults need contact information plus billing information. Students can be adult stud...
Eliminating multiple inheritance
0.049958
0
0
681
1,131,599
2009-07-15T14:01:00.000
8
0
1
0
python,oop,multiple-inheritance
1,131,655
8
true
0
0
What you have is an example of Role -- it's a common trap to model Role by inheritance, but Roles can change, and changing an object's inheritance structure (even in languages where it's possible, like Python) is not recommended. Children grow and become adults, and some adults will also be parents of children students...
4
9
0
I have the following problem and I'm wondering if there's a nice way to model these objects without using multiple inheritance. If it makes any difference, I am using Python. Students need contact information plus student information. Adults need contact information plus billing information. Students can be adult stud...
Eliminating multiple inheritance
1.2
0
0
681
1,131,599
2009-07-15T14:01:00.000
2
0
1
0
python,oop,multiple-inheritance
1,131,633
8
false
0
0
Very simple solution: Use composition rather than inheritance. Rather than having Student inherit from Contact and Billing, make Contact a field/attribute of Person and inherit from that. Make Billing a field of Student. Make Parent a self-reference field of Person.
4
9
0
I have the following problem and I'm wondering if there's a nice way to model these objects without using multiple inheritance. If it makes any difference, I am using Python. Students need contact information plus student information. Adults need contact information plus billing information. Students can be adult stud...
Eliminating multiple inheritance
0.049958
0
0
681
1,131,599
2009-07-15T14:01:00.000
0
0
1
0
python,oop,multiple-inheritance
1,131,714
8
false
0
0
One solution is to create a base Info class/interface that the classes ContactInfo, StudentInfo, and BillingInfo inherit from. Have some sort of Person object that contains a list of Info objects, and then you can populate the list of Info objects with ContactInfo, StudentInfo, etc.
4
9
0
I have the following problem and I'm wondering if there's a nice way to model these objects without using multiple inheritance. If it makes any difference, I am using Python. Students need contact information plus student information. Adults need contact information plus billing information. Students can be adult stud...
Eliminating multiple inheritance
0
0
0
681
1,132,766
2009-07-15T17:25:00.000
5
1
1
0
python,file,cryptography,digital-signature
1,132,796
2
true
0
0
The digital signature from C alone should be enough for both A and B to confirm that their file is not corrupted, without ever communicating with eachother. If A and B did not receive a signature from C, they could each create a cryptographic hash of the file and compare the hash, but that does not require any digital...
1
1
0
I'm programming a pet project in Python, and it involves users A & B interacting over network, attempting to insure that each has a local copy of the same file from user C. The idea is that C gives each a file that has been digitally signed. A & B trade the digital signatures they have, and check it out on their own co...
Must a secure cryptographic signature reside outside of the file it refers to?
1.2
0
0
187
1,133,391
2009-07-15T19:17:00.000
1
0
0
0
python,django
1,133,417
5
false
1
0
Check out the wc command on unix.
1
11
0
Is there an easy way to count the lines of code you have written for your django project? Edit: The shell stuff is cool, but how about on Windows?
Count lines of code in a Django Project
0.039979
0
0
6,904
1,134,071
2009-07-15T21:03:00.000
-1
0
1
0
python,configuration,configparser
1,134,323
4
false
1
0
ConfigParser is based on the ini file format, who in it's design is supposed to NOT be sensitive to order. If your config file format is sensitive to order, you can't use ConfigParser. It may also confuse people if you have an ini-type format that is sensitive to the order of the statements...
1
7
0
I've noticed with my source control that the content of the output files generated with ConfigParser is never in the same order. Sometimes sections will change place or options inside sections even without any modifications to the values. Is there a way to keep things sorted in the configuration file so that I don't ha...
Keep ConfigParser output files sorted
-0.049958
0
0
6,931
1,136,676
2009-07-16T10:20:00.000
0
0
0
0
python,mysql
1,136,692
3
false
0
0
How did you install MySQLdb? This sounds like your MySQLdb module is not within your PYTHONPATH which indicates some inconsistancy between how you installed Python itself and how you installed MySQLdb. Or did you perhaps install a MySQLdb binary that was not targeted for your version of Python? Modules are normally put...
1
1
0
I am using Python 2.6.1, MySQL4.0 in Windows platform and I have successfully installed MySQLdb. Do we need to set any path for my python code and MySQLdb to successful run my application? Without any setting paths (in my code I am importing MySQLdb) I am getting No module named MySQLdb error is coming and I am not abl...
is it required to give path after installation MySQL db for Python 2.6
0
1
0
770
1,138,024
2009-07-16T14:30:00.000
6
0
1
0
python,string,list
1,138,036
6
false
0
0
To remove all empty strings, [s for s in list_of_strings if s] To get the first non-empty string, simply create this list and get the first element, or use the lazy method as suggested by wuub.
1
15
0
In Python I have a list of strings, some of which may be the empty string. What's the best way to get the first non-empty string?
Get first non-empty string from a list in python
1
0
0
19,680
1,139,151
2009-07-16T17:40:00.000
2
0
0
1
python,django,google-app-engine,unicode
1,140,751
3
false
1
0
Are you using Django 0.96 or Django 1.0? You can check by looking at your main.py and seeing if it contains the following: from google.appengine.dist import use_library use_library('django', '1.0') If you're using Django 1.0, both FILE_CHARSET and DEFAULT_CHARSET should default to 'utf-8'. If your template is saved u...
3
2
0
When trying to render a Django template file in Google App Engine from google.appengine.ext.webapp import template templatepath = os.path.join(os.path.dirname(file), 'template.html') self.response.out.write (template.render( templatepath , template_values)) I come across the following error: <type 'exceptions.Unico...
Google App engine template unicode decoding problem
0.132549
0
0
2,383
1,139,151
2009-07-16T17:40:00.000
1
0
0
1
python,django,google-app-engine,unicode
1,139,534
3
false
1
0
Did you check in your text editor that the template is encoded in utf-8?
3
2
0
When trying to render a Django template file in Google App Engine from google.appengine.ext.webapp import template templatepath = os.path.join(os.path.dirname(file), 'template.html') self.response.out.write (template.render( templatepath , template_values)) I come across the following error: <type 'exceptions.Unico...
Google App engine template unicode decoding problem
0.066568
0
0
2,383
1,139,151
2009-07-16T17:40:00.000
6
0
0
1
python,django,google-app-engine,unicode
1,141,420
3
true
1
0
Well, turns out the rendered results returned by the template needs to be decoded first: self.response.out.write (template.render( templatepath , template_values).decode('utf-8') ) A silly mistake, but thanks for everyone's answers anyway. :)
3
2
0
When trying to render a Django template file in Google App Engine from google.appengine.ext.webapp import template templatepath = os.path.join(os.path.dirname(file), 'template.html') self.response.out.write (template.render( templatepath , template_values)) I come across the following error: <type 'exceptions.Unico...
Google App engine template unicode decoding problem
1.2
0
0
2,383
1,139,835
2009-07-16T19:38:00.000
1
0
0
1
python,browser,debian,uid
1,140,199
1
true
0
0
This could be your environment. Changing the permissions will still leave environment variables like $HOME pointing at the root user's directory, which will be inaccessible. It may be worth trying altering these variables by changing os.environ before launching the browser. There may also be other variables worth ch...
1
0
0
I can't run firefox from a sudoed python script that drops privileges to normal user. If i write $ sudo python >>> import os >>> import pwd, grp >>> uid = pwd.getpwnam('norby')[2] >>> gid = grp.getgrnam('norby')[2] >>> os.setegid(gid) >>> os.seteuid(uid) >>> import webbrowser >>> webbrowser.get('firefox').open('www.go...
Python fails to execute firefox webbrowser from a root executed script with privileges drop
1.2
0
1
903
1,140,661
2009-07-16T22:27:00.000
3
0
0
0
python
1,491,225
8
false
0
0
The urllib2.HTTPError exception does not contain a getcode() method. Use the code attribute instead.
1
90
0
I’m looking for a quick way to get an HTTP response code from a URL (i.e. 200, 404, etc). I’m not sure which library to use.
What’s the best way to get an HTTP response code from a URL?
0.07486
0
1
153,420
1,140,958
2009-07-17T00:21:00.000
1
0
1
0
python,string,line-endings
67,993,293
13
false
0
0
using regex re.sub(r'^$\n', '', somestring, flags=re.MULTILINE)
2
78
0
I have some code in a python string that contains extraneous empty lines. I would like to remove all empty lines from the string. What's the most pythonic way to do this? Note: I'm not looking for a general code re-formatter, just a quick one or two-liner. Thanks!
What's a quick one-liner to remove empty lines from a python string?
0.015383
0
0
89,033
1,140,958
2009-07-17T00:21:00.000
1
0
1
0
python,string,line-endings
1,141,067
13
false
0
0
This one will remove lines of spaces too. re.replace(u'(?imu)^\s*\n', u'', code)
2
78
0
I have some code in a python string that contains extraneous empty lines. I would like to remove all empty lines from the string. What's the most pythonic way to do this? Note: I'm not looking for a general code re-formatter, just a quick one or two-liner. Thanks!
What's a quick one-liner to remove empty lines from a python string?
0.015383
0
0
89,033
1,141,047
2009-07-17T01:04:00.000
10
0
1
0
python,multithreading,python-3.x
1,141,115
3
false
0
0
It's been quite a long time since the low-level thread module was informally deprecated, with all users heartily encouraged to use the higher-level threading module instead; now with the ability to introduce backwards incompatibilities in Python 3, we've made that deprecation rather more than just "informal", that's al...
1
10
0
Python 3.x renamed the low-level module 'thread' to '_thread' -- I don't see why in the documentation. Does anyone know?
Why was the 'thread' module renamed to '_thread' in Python 3.x?
1
0
0
5,673
1,145,286
2009-07-17T19:41:00.000
-1
0
0
0
python,file
1,148,604
7
false
0
0
Its a time to buy a new hard drive! You can make backup before trying all other answers and don't get data lost :)
3
8
0
I have a large xml file (40 Gb) that I need to split into smaller chunks. I am working with limited space, so is there a way to delete lines from the original file as I write them to new files? Thanks!
Change python file in place
-0.028564
0
1
1,833
1,145,286
2009-07-17T19:41:00.000
1
0
0
0
python,file
1,145,329
7
false
0
0
I'm pretty sure there is, as I've even been able to edit/read from the source files of scripts I've run, but the biggest problem would probably be all the shifting that would be done if you started at the beginning of the file. On the other hand, if you go through the file and record all the starting positions of the l...
3
8
0
I have a large xml file (40 Gb) that I need to split into smaller chunks. I am working with limited space, so is there a way to delete lines from the original file as I write them to new files? Thanks!
Change python file in place
0.028564
0
1
1,833
1,145,286
2009-07-17T19:41:00.000
0
0
0
0
python,file
1,145,341
7
false
0
0
If time is not a major factor (or wear and tear on your disk drive): Open handle to file Read up to the size of your partition / logical break point (due to the xml) Save the rest of your file to disk (not sure how python handles this as far as directly overwriting file or memory usage) Write the partition to disk got...
3
8
0
I have a large xml file (40 Gb) that I need to split into smaller chunks. I am working with limited space, so is there a way to delete lines from the original file as I write them to new files? Thanks!
Change python file in place
0
0
1
1,833
1,145,414
2009-07-17T20:06:00.000
2
0
0
0
python,django,apache
1,152,601
8
false
1
0
Found Python Web Development with Django by Forcier, Bissex and Chun a great start. 50 pages on python to get you going and all the basics of Django.
1
15
0
I'm a newbie on the Django scene coming from an ASP.NET C# background. I'm looking for some good resources to help me learn the ins and outs of Django/Python. Any recommendations?
What are the best books and resources for learning to develop, deploy and/or host Django?
0.049958
0
0
2,869
1,145,524
2009-07-17T20:29:00.000
5
0
1
0
python,django,setuptools,easy-install,egg
1,145,611
1
true
1
0
You add zip_safe = False as an option to setup(). I don't think it has to do with directories. Setuptools will happily eggify packages with loads of directories in it. Then of course it's another problem that this part of Django doesn't find the package even though it's zipped. It should.
1
3
0
How exactly do I configure my setup.py file so that when someone runs easy_install the package gets expanded into \site-packages\ as a directory, rather than remaining inside an egg. The issue I'm encountering is that one of the django apps I've created won't auto-detect if it resides inside an egg. EDIT: For example, ...
How to make easy_install expand a package into directories rather than a single egg file?
1.2
0
0
1,188
1,145,741
2009-07-17T21:18:00.000
1
1
0
1
python,signals,mpi
1,149,142
3
false
0
0
If you use mpirun --nw, then mpirun itself should terminate as soon as it's started the subprocesses, instead of waiting for their termination; if that's acceptable then I believe your processes would be able to catch their own signals.
1
5
0
When using mpirun, is it possible to catch signals (for example, the SIGINT generated by ^C) in the code being run? For example, I'm running a parallelized python code. I can except KeyboardInterrupt to catch those errors when running python blah.py by itself, but I can't when doing mpirun -np 1 python blah.py. Does an...
MPI signal handling
0.066568
0
0
2,988