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
3,440,016
2010-08-09T12:35:00.000
0
0
0
1
python,bytecode,distutils
39,629,278
4
false
0
0
"the standard commands don't have such an option"? Do you have the latest version of setuptools installed? And did you write a setup.py file? If so, this should work: python setup.py bdist_egg --exclude-source-files.
1
8
0
I want to create a bytecode-only distribution from distutils (no really, I do; I know what I'm doing). Using setuptools and the bdist_egg command, you can simply provide the --exclude-source parameter. Unfortunately the standard commands don't have such an option. Is there an easy way to strip the source files just before the tar.gz, zip, rpm or deb is created. Is there a relatively clean per-command way to do this (eg just for tar.gz or zip).
How to strip source from distutils binary distributions?
0
0
0
2,952
3,441,057
2010-08-09T14:33:00.000
0
0
1
0
python,json,couchdb
3,451,512
3
false
0
0
CouchDB will accept any valid JSON Object as a document.
2
0
0
I'm a Python programmer with experience using the json module. I've just meet CouchDB and seems very interesting. I wonder know if JSON data structures can be directly saved as a CouchDB document. Thanks,
Can a JSON data structure be directly saved as a CouchDB document?
0
0
0
761
3,441,057
2010-08-09T14:33:00.000
3
0
1
0
python,json,couchdb
3,451,530
3
true
0
0
You only need to provide an unique ID that will be used as part of the resource name (URI) when PUTting it or you use POST and take an auto-generated ID. You can use any JSON, that does not contain _id and _rev, because these fields are reserved for CouchDB itself.
2
0
0
I'm a Python programmer with experience using the json module. I've just meet CouchDB and seems very interesting. I wonder know if JSON data structures can be directly saved as a CouchDB document. Thanks,
Can a JSON data structure be directly saved as a CouchDB document?
1.2
0
0
761
3,441,358
2010-08-09T15:04:00.000
2
0
1
0
python,types,numbers
3,441,446
15
false
0
0
Probably it's better to just do it the other way around: You check if it's a vector. If it is, you do a dot product and in all other cases you attempt scalar multiplication. Checking for the vector is easy, since it should of your vector class type (or inherited from it). You could also just try first to do a dot-product, and if that fails (= it wasn't really a vector), then fall back to scalar multiplication.
3
133
0
Given an arbitrary python object, what's the best way to determine whether it is a number? Here is is defined as acts like a number in certain circumstances. For example, say you are writing a vector class. If given another vector, you want to find the dot product. If given a scalar, you want to scale the whole vector. Checking if something is int, float, long, bool is annoying and doesn't cover user-defined objects that might act like numbers. But, checking for __mul__, for example, isn't good enough because the vector class I just described would define __mul__, but it wouldn't be the kind of number I want.
What is the most pythonic way to check if an object is a number?
0.02666
0
0
38,514
3,441,358
2010-08-09T15:04:00.000
1
0
1
0
python,types,numbers
25,140,088
15
false
0
0
Just to add upon. Perhaps we can use a combination of isinstance and isdigit as follows to find whether a value is a number (int, float, etc) if isinstance(num1, int) or isinstance(num1 , float) or num1.isdigit():
3
133
0
Given an arbitrary python object, what's the best way to determine whether it is a number? Here is is defined as acts like a number in certain circumstances. For example, say you are writing a vector class. If given another vector, you want to find the dot product. If given a scalar, you want to scale the whole vector. Checking if something is int, float, long, bool is annoying and doesn't cover user-defined objects that might act like numbers. But, checking for __mul__, for example, isn't good enough because the vector class I just described would define __mul__, but it wouldn't be the kind of number I want.
What is the most pythonic way to check if an object is a number?
0.013333
0
0
38,514
3,441,358
2010-08-09T15:04:00.000
17
0
1
0
python,types,numbers
3,441,388
15
false
0
0
This is a good example where exceptions really shine. Just do what you would do with the numeric types and catch the TypeError from everything else. But obviously, this only checks if a operation works, not whether it makes sense! The only real solution for that is to never mix types and always know exactly what typeclass your values belong to.
3
133
0
Given an arbitrary python object, what's the best way to determine whether it is a number? Here is is defined as acts like a number in certain circumstances. For example, say you are writing a vector class. If given another vector, you want to find the dot product. If given a scalar, you want to scale the whole vector. Checking if something is int, float, long, bool is annoying and doesn't cover user-defined objects that might act like numbers. But, checking for __mul__, for example, isn't good enough because the vector class I just described would define __mul__, but it wouldn't be the kind of number I want.
What is the most pythonic way to check if an object is a number?
1
0
0
38,514
3,441,436
2010-08-09T15:12:00.000
0
0
0
0
python,django,django-forms
3,441,476
6
false
1
0
create your own view for logging in, with it's own url, don't use the admin's one. you can store the next page in the session, or pass it as a GET parameter to the login view (i.e. /login?next=gallery) just don't forget to sanitize and validate that value before redirecting to it.
3
29
0
I'm trying to redirect users to custom url "/gallery/(username)/" after successfully logging in. It currently redirects to the default "/account/profile/" url While I know what I can override the redirect url in my settings.py, my url is dynamic thus it will not work. Documentation states that I need to use the "next" parameter and context processors. I have the {{next}} in my template, but I'm confused on how to actually pass the "/gallery/(username)". Any help would be greatly appreciated. p.s: I'm trying to steer away from writing my own login view.
The "next" parameter, redirect, django.contrib.auth.login
0
0
0
42,969
3,441,436
2010-08-09T15:12:00.000
43
0
0
0
python,django,django-forms
5,787,355
6
false
1
0
Django's login view django.contrib.auth.views.login accepts a dictionary named extra_context. The values in the dictionary are directly passed to the template. So you can use that to set the next parameter. Once that is done, you can set a hidden field with name next and value {{ next }} so that it gets rendered in the template.
3
29
0
I'm trying to redirect users to custom url "/gallery/(username)/" after successfully logging in. It currently redirects to the default "/account/profile/" url While I know what I can override the redirect url in my settings.py, my url is dynamic thus it will not work. Documentation states that I need to use the "next" parameter and context processors. I have the {{next}} in my template, but I'm confused on how to actually pass the "/gallery/(username)". Any help would be greatly appreciated. p.s: I'm trying to steer away from writing my own login view.
The "next" parameter, redirect, django.contrib.auth.login
1
0
0
42,969
3,441,436
2010-08-09T15:12:00.000
2
0
0
0
python,django,django-forms
3,442,128
6
false
1
0
You can use a static redirect to /loggedin/ and then associate the url to a view that makes the correct redirect. Login takes an extra step but if you want to use django's view it does the job.
3
29
0
I'm trying to redirect users to custom url "/gallery/(username)/" after successfully logging in. It currently redirects to the default "/account/profile/" url While I know what I can override the redirect url in my settings.py, my url is dynamic thus it will not work. Documentation states that I need to use the "next" parameter and context processors. I have the {{next}} in my template, but I'm confused on how to actually pass the "/gallery/(username)". Any help would be greatly appreciated. p.s: I'm trying to steer away from writing my own login view.
The "next" parameter, redirect, django.contrib.auth.login
0.066568
0
0
42,969
3,441,766
2010-08-09T15:50:00.000
9
1
0
1
python,perl,interop
3,446,205
3
false
0
0
In the short run the easiest solution is to use Inline::Python. Closely followed by calling a command-line script. In the long run, using a server to provide RPC functionality or simply calling a command-line script will give you the most future proof solution. Why? Becuase that way you aren't tied to Perl or Python as the language used to build the systems that consume the services provided by your library. Either method creates a clear, language independent interface that you can use with whatever development environment you adopt. Depending on your needs any of the presented options may be the "best choice". Depending on how your needs evolve over time, a different choice may be revealed as "best". My approach to this would be to ask a couple of questions: How often do you change development tools. You've switched to Python from Perl. Did you start with Tcl and go to Perl? Are you going to switch to the exciting new language X in 1, 5 or 10 years? If you change tools 'often' (whatever that means) emphasize cross tool compatibility. How fast is fast enough? Is the start up time for command line solutions ok? Does Inline::Python slow things down too much (you are still initializing a Python interpreter, it's just embedded in your Perl interpreter)? Based on the answers to these questions, I would do the simplest thing that is likely to work. My guess is that means in order: Inline::Python Command line scripts Build an RPC server
2
9
0
I created a module in Python which provides about a dozen functionalities. While it will be mostly used from within Python, there is a good fraction of legacy users which will be calling it from Perl. What is the best way to make a plug in to this module? My thoughts are: Provide the functionalities as command line utilities and make system calls Create some sort of server and handle RPC calls (say, via JSON RPC) Any advise?
Calling a Python module from Perl
1
0
0
9,275
3,441,766
2010-08-09T15:50:00.000
3
1
0
1
python,perl,interop
3,441,920
3
false
0
0
Provide the functionalities as command line utilities and make system calls Works really nicely. This is the way programs like Python (and Perl) are meant to use used.
2
9
0
I created a module in Python which provides about a dozen functionalities. While it will be mostly used from within Python, there is a good fraction of legacy users which will be calling it from Perl. What is the best way to make a plug in to this module? My thoughts are: Provide the functionalities as command line utilities and make system calls Create some sort of server and handle RPC calls (say, via JSON RPC) Any advise?
Calling a Python module from Perl
0.197375
0
0
9,275
3,441,991
2010-08-09T16:12:00.000
0
0
0
0
python,wxpython,listctrl
3,442,559
3
false
0
1
You can try EVT_LIST_ITEM_RIGHT_CLICK. That should work. Otherwise you'd want to use a flag and check said flag every time the selection event fires to see if it needs to query the database or not. There's also the UltimateListCtrl, a pure python widget, that you can probably hack to do this too.
1
3
0
I'm working on a form using wxPython where I want want listctrl's list of values to change based on the selection of another listctrl. To do this, I'm using methods linked to the controlling object's EVT_LIST_ITEM_SELECTED and EVT_LIST_ITEM_DESELECTED events to call Publisher.sendMessage. The control to be changed has a method that is a subscriber to that publisher. This works: when the first listctrl is clicked, the second is refreshed. The problem is that the data must be refreshed from the database and a message is sent for every selection and deselection. This means that even if I simply click on one item, the database gets queried twice (once for the deselection, then again for the selection). If I shift-click to multi-select 5 items, then 5 calls get made. Is there any way to have the listctrl respond to the set, rather than the individual selections?
Respond to Listctrl change exactly once
0
0
0
940
3,442,477
2010-08-09T17:19:00.000
4
0
1
0
python,google-app-engine
3,442,523
1
true
0
0
Yes. An entity is uniquely identified by its path, which is the kind & name or ID of the entity and all of its ancestors. If two entities have the same name, but different kinds and/or ancestries, they will have distinct paths.
1
1
0
I wonder if 2 objects can have the same key name? They wouldn't be the same class. Thanks!
Can 2 objects have the same key name?
1.2
0
0
157
3,443,547
2010-08-09T19:39:00.000
1
0
1
0
python
3,443,624
3
false
0
0
Isn't Django all about web-based CRUD applications for Python?
1
1
0
i'm looking for a basic CRUD (create-read-update-delete) app in Python, with some line-by-line display grid to browse through a file's records and select individual records from there. It probably already exists but i couldn't find anything yet. Thanks
GUI for the Linux and Windows platforms - Python CRUD app
0.066568
0
0
1,876
3,443,607
2010-08-09T19:46:00.000
24
0
1
1
python,debugging
3,443,835
14
false
0
0
Wow! 5 answers already and nobody has suggested the most obvious and simple: Try to find a reproducible test case that causes the hanging behavior. Add logging to your code. This can be as basic as print "**010", print "**020", etc. peppered through major areas. Run code. See where it hangs. Can't understand why? Add more logging. (I.e. if between **020 and **030, go and add **023, **025, **027, etc.) Goto 3.
2
80
0
So I'm debugging my python program and have encountered a bug that makes the program hang, as if in an infinite loop. Now, I had a problem with an infinite loop before, but when it hung up I could kill the program and python spat out a helpful exception that told me where the program terminated when I sent it the kill command. Now, however, when the program hangs up and I ctrl-c it, it does not abort but continues running. Is there any tool I can use to locate the hang up? I'm new to profiling but from what I know a profiler can only provide you with information about a program that has successfully completed. Or can you use a profiler to debug such hang ups?
How can I tell where my python script is hanging?
1
0
0
82,971
3,443,607
2010-08-09T19:46:00.000
2
0
1
1
python,debugging
3,443,669
14
false
0
0
It's easier to prevent these hang-ups than it is to debug them. First: for loops are very, very hard to get stuck in a situation where the loop won't terminate. Very hard. Second: while loops are relatively easy to get stuck in a loop. The first pass is to check every while loop to see if it must be a while loop. Often you can replace while constructs with for, and you'll correct your problem by rethinking your loop. If you cannot replace a while loop with for, then you simply have to prove that the expression in the while statement must change every time through the loop. This isn't that hard to prove. Look at all the condition in the loop. Call this T. Look at all the logic branches in the body of the loop. Is there any way to get through the loop without making a change to the condition, T? Yes? That's your bug. That logic path is wrong. No? Excellent, that loop must terminate.
2
80
0
So I'm debugging my python program and have encountered a bug that makes the program hang, as if in an infinite loop. Now, I had a problem with an infinite loop before, but when it hung up I could kill the program and python spat out a helpful exception that told me where the program terminated when I sent it the kill command. Now, however, when the program hangs up and I ctrl-c it, it does not abort but continues running. Is there any tool I can use to locate the hang up? I'm new to profiling but from what I know a profiler can only provide you with information about a program that has successfully completed. Or can you use a profiler to debug such hang ups?
How can I tell where my python script is hanging?
0.028564
0
0
82,971
3,444,436
2010-08-09T21:41:00.000
5
0
1
0
python,settings,configuration-files,yaml,configparser
3,444,666
3
false
0
0
ConfigParser has a really bad API, ConfigObj is supposed to be good but I have never used it, for ini files I usually implement my own parser. However ini-like formats don't handle different types, sequences or recursive mappings well anyway so I would just use yaml. It's easy to read and edit with an editor, there is a standard for parsing those files and you have none of the mentioned downsides ini-like formats have.
1
31
0
Which is better for creating a settings file for Python programs, the built-in module (ConfigParser) or the independent project (ConfigObj), or using the YAML data serialization format? I have heard that ConfigObj is easier to use than ConfigParser, even though it is not a built-in library. I have also read that PyYAML is easy to use, though YAML takes a bit of time to use. Ease of implementation aside, which is the best option for creating a settings/configuration file?
ConfigObj/ConfigParser vs. using YAML for Python settings file
0.321513
0
0
15,649
3,444,504
2010-08-09T21:53:00.000
5
0
1
0
django,python-imaging-library,imagekit,django-imagekit,photologue
3,444,601
1
true
1
0
Photologue is a Django application to manage photos. It uses PIL for the image processing. ImageKit is a Django Application for image processing. It is meant for adding images to existing models. PIL is the underlying library for both of these (and actually, most if not all image processing scripts in Python).
1
1
0
I'm trying to figure out which image management library to use on django. What is the difference between photologue, image-kit, and pil(python imaging library)?
Image management on Django
1.2
0
0
462
3,444,611
2010-08-09T22:17:00.000
2
0
1
0
python
3,444,653
4
false
0
0
If you "absolutely must" call it as a method (rather than a function) then the double underscores are needed. But the only motivation I can think for the code you show of is that somebody's gone so OO-happy that they don't understand the key Python principle that you don't directly call special methods (except you may need to call your superclass's version if you're overriding it, of course) -- you use the appropriate builtin or operator, and it calls (internally) whatever special methods are needed. Actually, in the code you show the only sensible thing is to just use the constant 3, so maybe you've oversimplified your example a little...?-)
1
1
0
why would anyone use double underscores why not just do len([1,2,3])? my question is specifically What do the underscores mean?
python: what is this funny notation? [0,1,3].__len__()
0.099668
0
0
303
3,444,804
2010-08-09T22:56:00.000
1
0
0
0
python
3,444,821
4
false
1
0
I think you can build it however you like, as long as you can make it an asynchronous service so that the users don't have to wait. Unless, of course, the users don't mind waiting in this context.
1
9
0
I need to build a webservice that is very computationally intensive, and I'm trying to get my bearings on how best to proceed. I expect users to connect to my service, at which point some computation is done for some amount of time, typically less than 60s. The user knows that they need to wait, so this is not really a problem. My question is, what's the best way to structure a service like this and leave me with the least amount of headache? Can I use Node.js, web.py, CherryPy, etc.? Do I need a load balancer sitting in front of these pieces if used? I don't expect huge numbers of users, perhaps hundreds or into the thousands. I'll need a number of machines to host this number of users, of course, but this is uncharted territory for me, and if someone can give me a few pointers or things to read, that would be great. Thanks.
How to build a computationally intensive webservice?
0.049958
0
0
1,140
3,444,827
2010-08-09T22:59:00.000
0
1
1
0
python,unit-testing
3,444,963
5
false
0
0
Yes to both: setUp will be called between each test test2 will be called twice. If you would like to call a function inside a test, then omit the test prefix.
3
7
0
Can I call a test method from within the test class in python? For example: class Test(unittest.TestCase): def setUp(self): #do stuff def test1(self): self.test2() def test2(self): #do stuff update: I forgot the other half of my question. Will setup or teardown be called only after the method that the tester calls? Or will it get called between test1 entering and after calling test2 from test1?
python unittest methods
0
0
0
3,578
3,444,827
2010-08-09T22:59:00.000
1
1
1
0
python,unit-testing
3,444,872
5
false
0
0
All methods whose name begins with the string 'test' are considered unit tests (i.e. they get run when you call unittest.main()). So you can call methods from within the Test class, but you should name it something that does not start with the string 'test' unless you want it to be also run as a unit test.
3
7
0
Can I call a test method from within the test class in python? For example: class Test(unittest.TestCase): def setUp(self): #do stuff def test1(self): self.test2() def test2(self): #do stuff update: I forgot the other half of my question. Will setup or teardown be called only after the method that the tester calls? Or will it get called between test1 entering and after calling test2 from test1?
python unittest methods
0.039979
0
0
3,578
3,444,827
2010-08-09T22:59:00.000
0
1
1
0
python,unit-testing
3,444,874
5
false
0
0
sure, why not -- however that means test2 will be called twice -- once by test1 and then again as its own test, since all functions named test will be called.
3
7
0
Can I call a test method from within the test class in python? For example: class Test(unittest.TestCase): def setUp(self): #do stuff def test1(self): self.test2() def test2(self): #do stuff update: I forgot the other half of my question. Will setup or teardown be called only after the method that the tester calls? Or will it get called between test1 entering and after calling test2 from test1?
python unittest methods
0
0
0
3,578
3,445,429
2010-08-10T01:37:00.000
6
0
1
0
python,debugging,code-snippets
3,445,509
3
true
0
0
Not sure how to scout "intentionally" for source code with bugs but you can look into the bug trackers of the main Python projects (and the less widespread ones, too), look for the bugs the reports refer to and debug them. It's a win-win situation. You win the skill to debug and they (hopefully) win a patch for the bug :-)
2
5
0
This is a strange request but I'm looking for buggy Python code. I want to learn more about bugs and debuggers and I need some buggy code to work with. Unfortunately, all the code I've written is short and bug-free (so far). Preferably it's not GUI stuff (b/c I'm just starting to learn it) but anything's good. Thanks in advance
Intentionally Buggy Code (Python)
1.2
0
0
1,741
3,445,429
2010-08-10T01:37:00.000
0
0
1
0
python,debugging,code-snippets
3,445,548
3
false
0
0
Debugging is 70% about finding and figuring out the bug from reports of anomalies before you can do anything about it, and 30% about figuring out how not to take the castle of cards down when fixing it. If you have it pointed out in the code for you, or are just given code and you're told it's buggy, you're in a worse place than where you started. Lawrence's comment is spot on IMO, go hunt down something that's been tracked and logged and you have rero steps for in a project where you have realistic constraints and enough codebase to work with if you want this exercise to have any meaning. Will double as good exercise in learning to read too when you have to puzzle out an alien code base too.
2
5
0
This is a strange request but I'm looking for buggy Python code. I want to learn more about bugs and debuggers and I need some buggy code to work with. Unfortunately, all the code I've written is short and bug-free (so far). Preferably it's not GUI stuff (b/c I'm just starting to learn it) but anything's good. Thanks in advance
Intentionally Buggy Code (Python)
0
0
0
1,741
3,445,867
2010-08-10T03:43:00.000
2
0
0
0
python,binding,tkinter
3,445,919
1
false
0
1
Tkinter, on its own, cannot grab keystrokes that (from the OS's/WM's viewpoint) were directed to other, unrelated windows -- you'll need to instruct your window manager, desktop manager, or "operating system", to direct certain keystrokes differently than it usually does. So, what platform do you need to support for this functionality? Each platform has different ways to perform this kind of functionality, of course.
1
1
0
I made a GUI with Tkinter, now how do I make it so when a key command will execute a command even if the Tkinter window is not in focus? Basically I want it so everything is bound to that key command. Example: Say I was browsing the internet and the focus was on my browser, I then type Ctrl + U. An event would then run on my program.
Key commands in Tkinter
0.379949
0
0
515
3,446,087
2010-08-10T04:41:00.000
0
0
0
1
c++,python,c,linux,snmp
3,447,496
4
false
0
0
I am still searching for that easy to use suite of SNMP tools/API myself. I build OA&M and I've tried NET-SNMP, Windows SNMP and lately agentpp (www.agentpp.com). Personally, I preferred the agentpp. Good luck to you.
2
3
0
Well, altough the S of the SNMP stands for Simple, yet, so far I haven't experienced it that way. And now that I am about to deploy my software on around around 180 remote Linux servers and wants to monitor the servers and configure my daemons all from a centralized point. I simply want you to recommend me the library which you'll confidently describe as "SNMP Made Easy". I am looking for a suite of software which not standing in the developer's way, easy to work with (install, configure). Speaking from the NOC perspective, the ideal would be such one which requires no maintenance once installed. Note: Open Source is mandatory.
As a software developer what is your SNMP suite that easy to integrate into your software
0
0
0
597
3,446,087
2010-08-10T04:41:00.000
0
0
0
1
c++,python,c,linux,snmp
3,918,718
4
false
0
0
The "S" in SNMP is actually for "simple" not because using it is simple, but rather because the protocol (on the wire) is designed to be simple and easy to implement. And it is. Now... actually implementing it and then using it is where the S completely drops away.
2
3
0
Well, altough the S of the SNMP stands for Simple, yet, so far I haven't experienced it that way. And now that I am about to deploy my software on around around 180 remote Linux servers and wants to monitor the servers and configure my daemons all from a centralized point. I simply want you to recommend me the library which you'll confidently describe as "SNMP Made Easy". I am looking for a suite of software which not standing in the developer's way, easy to work with (install, configure). Speaking from the NOC perspective, the ideal would be such one which requires no maintenance once installed. Note: Open Source is mandatory.
As a software developer what is your SNMP suite that easy to integrate into your software
0
0
0
597
3,446,457
2010-08-10T06:07:00.000
4
0
1
0
python,file,handles
3,446,508
2
false
0
0
Some systems may limit the number of file descriptors that a single process can have open simultaneously. 1024 is a common default, so if you need "thousands" open at once, you might want to err on the side of portability and design your application to use a smaller pool of open file descriptors.
2
2
0
I'm reading from certain offsets in several hundred and possibly thousands files. Because I need only certain data from certain offsets at that particular time, I must either keep the file handle open for later use OR I can write the parts I need into seperate files. I figured keeping all these file handles open rather than doing a significant amount of writing to the disk of new temporary files is the lesser of two evils. I was just worried about the efficiency of having so many file handles open. Typically, I'll open a file, seek to an offset, read some data, then 5 seconds later do the same thing but at another offset, and do all this on thousand of files within a 2 minute timeframe. Is that going to be a problem? A followup: Really, I"m asking which is better to leave these thousands file handles open, or to constantly close them and re-open them just when I instantaneously need them.
Having several file pointers open simultaneaously alright?
0.379949
0
0
181
3,446,457
2010-08-10T06:07:00.000
3
0
1
0
python,file,handles
3,447,418
2
false
0
0
I recommend that you take a look at Storage.py in BitTorrent. It includes an implementation of a pool of file handles.
2
2
0
I'm reading from certain offsets in several hundred and possibly thousands files. Because I need only certain data from certain offsets at that particular time, I must either keep the file handle open for later use OR I can write the parts I need into seperate files. I figured keeping all these file handles open rather than doing a significant amount of writing to the disk of new temporary files is the lesser of two evils. I was just worried about the efficiency of having so many file handles open. Typically, I'll open a file, seek to an offset, read some data, then 5 seconds later do the same thing but at another offset, and do all this on thousand of files within a 2 minute timeframe. Is that going to be a problem? A followup: Really, I"m asking which is better to leave these thousands file handles open, or to constantly close them and re-open them just when I instantaneously need them.
Having several file pointers open simultaneaously alright?
0.291313
0
0
181
3,448,365
2010-08-10T11:23:00.000
-5
0
0
0
python,image,pdf,reportlab
4,092,003
4
false
0
0
Use from reportlab.graphics import renderPDF
1
12
1
I saved some plots from matplotlib into a pdf format because it seems to offer a better quality. How do I include the PDF image into a PDF document using ReportLab? The convenience method Image(filepath) does not work for this format. Thank you.
PDF image in PDF document using ReportLab (Python)
-1
0
0
7,751
3,449,673
2010-08-10T13:54:00.000
0
0
0
1
python,web-services,reverse-proxy,cherokee
3,452,793
1
true
1
0
You could set a custom 504 error page.
1
0
0
I have a Cherokee installation that I'm using to serve a few web applications - one blog/calendar/etc. and two CPU-intensive web applications (1 stable version and 1 development version). All of them are Django or Pylons webservices served with CherryPy. I'm using the reverse-proxy handler in Cherokee to handle the mappings. Occasionally I have to take the development version down to make changes. Is there a way to set up Cherokee so that it will automatically serve (or redirect to) another page (e.g. indicating an under-construction status) when the reverse-proxy target is unfindable or unresponsive? I'd prefer an automated solution in Cherokee but if someone knows a simple point-and-click method I'll take that too.
Can Cherokee serve a fallback/default page when a reverse proxy is unavailable?
1.2
0
0
218
3,449,968
2010-08-10T14:22:00.000
1
0
1
0
python,spell-checking,pyenchant
3,450,281
3
false
0
0
Perhaps a better way of doing this would be to compress the document, as this would remove any repeating instances of words, which you actually only need to spell check once. I only suggest this as it would probably perform faster than writing your own unique word finder. The compressed version should have references to the unique words, somewhere within its file, you might have to look up how they are structured. You can then spell check all the unique words. I hope you are not checking them with individual SQL queries or something like that, you should load a dictionary in the form of a tree into your memory and then check words against that. Once this is done, simply uncompress it and hey presto it's all spell checked. This should be a fairly fast solution. Or perhaps you don't need to go through the whole zipping process if spell checking really is as fast as the comments suggest, which would indicate a wrong implementation.
1
6
0
Surprisingly I've been unable to find anyone else really doing this, but surely someone has. I'm working on a python project currently that involves spell checking some 16 thousand words. That number of words is only going to grow unfortunately. Right now I'm pulling words from Mongo, iterating through them, and then spell checking them with pyenchant. I've removed mongo as the potential bottleneck by grabbing all my items from there first. That leaves me with around 20 minutes to process through 16k words, which is obviously longer than I want to spend. This leaves me with a couple ideas/questions: Obviously I could leverage threading or some form of parallelism. Even if I chop this into 4 pieces, I'm still looking at roughly 5 minutes assuming peak performance. Is there a way to tell what spelling library Enchant is using underneath pyenchant? Enchant's website seems to imply it'll use all available spelling libraries/dictionaries when spell checking. If so, then I'm potentially running each word through three-four spelling dicts. This could be my issue right here, but I'm having a hard time proving that's the case. Even if it is, is my option really to uninstall other libraries? Sounds unfortunate. So, any ideas on how I can squeeze at least a bit more performance out of this? I'm fine with chopping this into parallel tasks, but I'd still like to get the core piece of it to be a bit faster before I do. Edit: Sorry, posting before morning coffee... Enchant generates a list of suggestions for me if a word is incorrectly spelled. That would appear to be where I spend most of my time in this processing portion.
"Large" scale spell checking in Python
0.066568
0
0
4,945
3,450,525
2010-08-10T15:19:00.000
0
0
0
0
python,event-handling,wxpython
3,451,727
3
false
0
1
In your init or OnInit method, do some kind of check to see if the program should run the startup process on startup (i.e. check a config file or some such). If yes, call the "scan" method using wx.CallAfter or wx.CallLater or call it after you Show() the frame.
2
0
0
OK, I'm trying to explain what I want to achieve in another way. Here's an example: Say if it's an anti virus program, and user can choose between two ways to run the program, choice one, automatically start to scan disks for virus when the program starts up, choice two, hit the start button to make the program scan disks for virus after the program starts up any time the user wants. So, as a wxpython beginner, I know how to bind wx.EVT_BUTTON to let scanning start after the user hit the start button, but I don't know how to make the scanning start once the program starts up. I wonder if there's a program_start event I can bind? Hope you guys can help me out. Thanks!
Is there a wxpython event like program_start?
0
0
0
372
3,450,525
2010-08-10T15:19:00.000
1
0
0
0
python,event-handling,wxpython
3,450,557
3
false
0
1
Why don't you run it just in module code? This way it will be run only once, because code in module is run only once per program instance.
2
0
0
OK, I'm trying to explain what I want to achieve in another way. Here's an example: Say if it's an anti virus program, and user can choose between two ways to run the program, choice one, automatically start to scan disks for virus when the program starts up, choice two, hit the start button to make the program scan disks for virus after the program starts up any time the user wants. So, as a wxpython beginner, I know how to bind wx.EVT_BUTTON to let scanning start after the user hit the start button, but I don't know how to make the scanning start once the program starts up. I wonder if there's a program_start event I can bind? Hope you guys can help me out. Thanks!
Is there a wxpython event like program_start?
0.066568
0
0
372
3,451,149
2010-08-10T16:23:00.000
0
0
1
0
python,performance
3,451,777
3
false
0
0
Python 3 does introduce some new language features too. One of my favorite is the new nonlocal keyword, which finally lets you write certain closures nicely, such as: def getter_setter(): x = 0 def getter(): return x def setter(val): nonlocal x x = val return (getter, setter)
3
1
0
After reading some benchmarks, I noticed that python 3.1 is slower than python 2.6, especially with I/Os. So I wonder what could be the good reasons to switch to Python 3.x ?
Why should I use python 3.1 instead of python 2.6?
0
0
0
583
3,451,149
2010-08-10T16:23:00.000
0
0
1
0
python,performance
3,451,561
3
false
0
0
Go to 3.1. Unless your code is run-once (which at almost never is). 2.6 has no future, and version 3 is the future, unless you are into time travel. They are working on 3.1 and I can assure you the speeds will soon be up to par, and then exceed 2.6 speeds.
3
1
0
After reading some benchmarks, I noticed that python 3.1 is slower than python 2.6, especially with I/Os. So I wonder what could be the good reasons to switch to Python 3.x ?
Why should I use python 3.1 instead of python 2.6?
0
0
0
583
3,451,149
2010-08-10T16:23:00.000
0
0
1
0
python,performance
3,451,250
3
false
0
0
Largely because of the new I/O library. This, however, has been completely rewritten to C in Python 3.2 and 2.7. I think the performance numbers are pretty close right now if you compare it to 3.2. edit: I confused the version numbers. Nevermind.
3
1
0
After reading some benchmarks, I noticed that python 3.1 is slower than python 2.6, especially with I/Os. So I wonder what could be the good reasons to switch to Python 3.x ?
Why should I use python 3.1 instead of python 2.6?
0
0
0
583
3,451,708
2010-08-10T17:29:00.000
3
0
0
0
python,sqlite,embedded,binary-data
3,451,733
1
true
0
0
Use the copy command in your OS. No reason to overthink this.
1
0
0
I have an sqlite database whose data I need to transfer over the network, the server needs to modify the data, and then I need to get the db back and either update my local version or overwrite it with the new db. How should I do this? My coworker at first wanted to scrap the db and just use an .ini file, but this is going to be data that we have to parse pretty frequently (it's a user defined schedule that can change at the user's will, as well as the server's). I said we should just transfer the entire .db as a binary file and let them do with it what they will and then take it back. Or is there a way in sqlite to dump the db to a .sql file like you can do in MySQL so we can transfer it as text? Any other solutions? This is in python if it makes a difference update: This is on an embedded platform running linux (I'm not sure what version/kernel or what OS commands we have except the basics that are obvious)
Sending sqlite db over network
1.2
1
0
471
3,451,983
2010-08-10T18:03:00.000
0
0
0
0
python,google-app-engine
3,467,698
1
true
1
0
Actually, I made some stupid encoding error when testing yesterday, which made me think the error came from the function. The problem doesnt come from the keys. It is just an error in my algorithm that won't check for keys of 2 characters if there is no object which the 1st character as keyname.
1
0
0
I'm using unicode strings for non latin characters as key names for my models. I can create objects without problems, and the appengine admin shows key name correctly (I'm using chinese characters, and the right characters) However, MyModel.get_by_key_name() returns None if the key_name is made of several characters. For 1 character key name, everything works fine. Does anyone know about that? Thanks!
Get_by_key_name doesn't work with unicode key names of several characters
1.2
0
0
351
3,452,022
2010-08-10T18:09:00.000
10
0
1
0
python,exception,exception-handling,twisted
3,452,525
1
true
0
0
A Failure represents an exception and a traceback (often different from the current stack trace). You should use Failure when you are constructing an asynchronous exception. So, when you're going to fire a Deferred with an error, or when you're going to call a method like IProtocol.connectionLost or ClientFactory.clientConnectionFailed. This is because in such cases, you want the ability to associate a different stack trace with the exception than the current stack trace. You shouldn't use Failure(ConnectionDone) because the correct one-argument invocation of Failure accepts an exception instance, not an exception class. So, instead, use Failure(ConnectionDone()). You can also use the zero-argument form to create a new Failure: Failure(). This only works when there is a "current" exception, eg in the suite of an except statement. It constructs the Failure using that current exception, as well as its traceback. You can also construct a Failure with three-arguments, an exception class, instance, and traceback. This is most commonly done using the return value of sys.exc_info(). When you just want to raise an exception, you don't need to create a Failure. Just do what you'd normally do in a Python program to raise an exception: raise SomeException(...).
1
5
0
When should I use a twisted.python.failure.Failure, and when should I use something like twisted.internet.error.ConnectionDone? Or should I do twisted.python.failure.Failure(twisted.internet.error.ConnectionDone), and if so, in what casese should I do that?
twisted: Failure vs. Error
1.2
0
0
2,191
3,452,381
2010-08-10T18:54:00.000
0
0
0
0
python,django,content-type,mime-types
3,452,438
4
false
1
0
Why we use 2 different naming for (almost the same) thing? Backwards compatibility, based on your quote from the documentation.
2
115
0
As far as I know, they are absolute equal. However, browsing some django docs, I've found this piece of code: HttpResponse.__init__(content='', mimetype=None, status=200, content_type='text/html') which surprise me the two getting along each other. The official docs was able to solve the issue in a pratical manner: content_type is an alias for mimetype. Historically, this parameter was only called mimetype, but since this is actually the value included in the HTTP Content-Type header, it can also include the character set encoding, which makes it more than just a MIME type specification. If mimetype is specified (not None), that value is used. Otherwise, content_type is used. If neither is given, the DEFAULT_CONTENT_TYPE setting is used. However, I don't find it elucidating enough. Why we use 2 different naming for (almost the same) thing? Is "Content-Type" just a name used in browser requests, and with very little use outside it? What's the main difference between the each one, and when is right to call something mimetype as opposed to content-type ? Am I being pitty and grammar nazi?
What's the difference of ContentType and MimeType
0
0
0
40,506
3,452,381
2010-08-10T18:54:00.000
63
0
0
0
python,django,content-type,mime-types
17,949,292
4
false
1
0
I've always viewed contentType to be a superset of mimeType. The only difference being the optional character set encoding. If the contentType does not include an optional character set encoding then it is identical to a mimeType. Otherwise, the mimeType is the data prior to the character set encoding sequence. E.G. text/html; charset=UTF-8 text/html is the mimeType ; is the additional parameters indicator charset=UTF-8 is the character set encoding parameter E.G. application/msword application/msword is the mimeType It cannot have a character set encoding as it describes a well formed octet-stream not comprising characters directly.
2
115
0
As far as I know, they are absolute equal. However, browsing some django docs, I've found this piece of code: HttpResponse.__init__(content='', mimetype=None, status=200, content_type='text/html') which surprise me the two getting along each other. The official docs was able to solve the issue in a pratical manner: content_type is an alias for mimetype. Historically, this parameter was only called mimetype, but since this is actually the value included in the HTTP Content-Type header, it can also include the character set encoding, which makes it more than just a MIME type specification. If mimetype is specified (not None), that value is used. Otherwise, content_type is used. If neither is given, the DEFAULT_CONTENT_TYPE setting is used. However, I don't find it elucidating enough. Why we use 2 different naming for (almost the same) thing? Is "Content-Type" just a name used in browser requests, and with very little use outside it? What's the main difference between the each one, and when is right to call something mimetype as opposed to content-type ? Am I being pitty and grammar nazi?
What's the difference of ContentType and MimeType
1
0
0
40,506
3,452,388
2010-08-10T18:55:00.000
1
1
0
0
python,cgi,cgi-bin
3,452,427
1
true
0
0
Being as how it's nominally just a URL, there aren't any impacts on speed per-se. However, it is standard practice, just like it's standard practice to make the entry page to a website index.html, but it's not required by any stretch (as evidenced by default.aspx, home.php, etc) I would change it as a security through obscurity reference myself, were I inclined to change those things on my system. While you won't incur any Apache security issues, there may be issues with server-side code or hard-coded modules that don't query for path, and assume code is running from cgi-bin ... just something to consider.
1
0
0
I'm considering moving from PHP to Python (for personal projects), and I really don't like seeing /cgi-bin/ in my URL. I got the Python to execute outside of cgi-bin, but I just wanted to make sure there were no possible security issues that could pop up, and that there were no major impacts on the speed. So are there any major issues I need to be aware of? Thanks in advance for any help.
Running CGI outside of cgi-bin. Good idea?
1.2
0
0
313
3,452,729
2010-08-10T19:35:00.000
6
1
1
0
python,ruby,perl,comparison
3,454,618
3
false
0
0
I'm learning Python (and it's my first programming language so don't be too intense with your reasons) and I wanted to know how it stacks up to other scripting languages, like Perl and Ruby. What is Python better in comparison to other scripting languages, and what is it worse for? IMO. I have tried Python 2.x for some time and went back to the Perl and C++. What is good about Python. Python features better portability and has modern GUI libraries. Standard library in some places is also very very nice (I esp. liked random). Execution speed of arithmetic expressions beats that of Perl. What is bad about Python. Poor documentation. No warnings, no typing whatsoever combined with weak typing/language's dynamic nature is a hell. Learning easy - using hard, mainly due to immature optimizer driving the need to think about performance edge cases quite early in the development cycle. (That some times reminded me of the Pascal.) OO is a mess at the moment: distinct features and differences between old-style and new-style classes are not spelled out very well; libraries do not mention what type of classes they do define. Poor documentation probably should be highlighted. There are piles of standard functions but their purpose in life isn't really specified nor decent examples are given. And better half of those standard functions in Perl land would have been sitting somewhere in the perldoc perlguts. Anyhow, looking up stuff is much faster with Google. Lack of warnings and lack of typing (and that compared to the weak Perl's use warnings/use strict and sub prototypes) is what in the end drove me back. Partially it is because that I write code faster than I can read it thus I like to rely on the compiler/interpreter to tell me where I might have wrote something I haven't really meant. Also excuse me, but I would throw that at Python again: using indentation to denote code structure is kind'a kinky. I do not mind it per se and for short functions it is very nice. But after one week I have found that I do read Python code slower (compared to C++ or Perl) in greater part because I have to always extra check whether the statement really closed or it still goes on. If code doesn't fit one screen, it becomes a chore to always press PgDown/PgUp just to check. Never before I were that appreciative of the {}s. All considered, Python is at the moment a mess. Worthy contender I do keep an eye on, but not mature enough for my daily needs. If I were making decision about learning Python now, I would have instead waited for Python 3.x to mature. Many things one would learn now with Python 2.x might be useless in Python 3.x. And Python 3.x is at the moment isn't very useful since many libraries were not yet ported to it. P.S. Most bogus part I have encountered is the function pointers. I have discovered them sooner than I needed them by writing start_time = time.time and time_elapsed = time.time() - start_time. Half hour later when script finished instead of results I was presented with nice interpreter exception telling me that I cannot subtract function object. And the half hour was due to the standard for loop, as tutorials have taught me. Optimizations I have looked up later (range vs. xrange, manual loop unrolling) made the script run in less than one minute.
1
1
0
I'm learning Python (and it's my first programming language so don't be too intense with your reasons) and I wanted to know how it stacks up to other scripting languages, like Perl and Ruby. What is Python better in comparison to other scripting languages, and what is it worse for?
How does Python stack up to other scripting languages?
1
0
0
1,331
3,452,788
2010-08-10T19:43:00.000
0
0
1
0
python,config,configparser
3,453,265
1
true
0
0
No. The builtin ConfigParser stores sections as _sections, which is a dict. Since this is python you could access that variable to do an easy copy. (config._sections[new_name] = config._sections[old_name]; config._sections.pop(old_name) But ConfigParser may change at some later date and this would break your implementation. Therefore I don't recommend doing that, alternatively you could subclass ConfigParser and implement a delete_section or change the way options are stored.
1
1
0
Is there an easy way to rename a section in a config file using ConfigParser in python? I'd prefer not to have to delete the section and recreate it, but that is my only answer right now.
Rename config.ini section using ConfigParser in python
1.2
0
0
867
3,452,986
2010-08-10T20:09:00.000
1
0
0
0
python,wxpython,progress-bar
3,453,038
1
true
0
1
The wx.ProgressDialog isn't customizable its just a wrapper around the native ProgressDialog, the the easiest solution would be to roll your own by extending the wx.Dialog class and using a wx.Gauge
1
0
0
Is it possible to customize ProgressDialog in wxPython? For instance, I would like to make the progressbar slimmer, and the window size wider. SetSize() method doesn't appear to have any effect.
How to customize wx.ProgressDialog?
1.2
0
0
352
3,453,085
2010-08-10T20:21:00.000
6
0
1
0
python,syntax,slice
3,453,105
11
false
0
0
The third parameter is the step. So [::3] would return every 3rd element of the list/string.
3
362
0
I know that I can use something like string[3:4] to get a substring in Python, but what does the 3 mean in somesequence[::3]?
What is :: (double colon) in Python when subscripting sequences?
1
0
0
293,448
3,453,085
2010-08-10T20:21:00.000
4
0
1
0
python,syntax,slice
9,916,132
11
false
0
0
Python uses the :: to separate the End, the Start, and the Step value.
3
362
0
I know that I can use something like string[3:4] to get a substring in Python, but what does the 3 mean in somesequence[::3]?
What is :: (double colon) in Python when subscripting sequences?
0.072599
0
0
293,448
3,453,085
2010-08-10T20:21:00.000
221
0
1
0
python,syntax,slice
3,453,102
11
false
0
0
Python sequence slice addresses can be written as a[start:end:step] and any of start, stop or end can be dropped. a[::3] is every third element of the sequence.
3
362
0
I know that I can use something like string[3:4] to get a substring in Python, but what does the 3 mean in somesequence[::3]?
What is :: (double colon) in Python when subscripting sequences?
1
0
0
293,448
3,453,180
2010-08-10T20:33:00.000
2
0
1
0
python,sqlalchemy
3,453,224
2
true
0
0
no. It'll work just fine.
1
12
0
I want to override __cmp__, __eq__, and __hash__ so I can do set operations on a SQLAlchemy Declarative Base model. Will this cause any conflicts with the Declarative Base Implementation?
Overriding __cmp__, __eq__, and __hash__ for SQLAlchemy Declarative Base
1.2
0
0
2,615
3,453,188
2010-08-10T20:34:00.000
2
0
0
0
python,ssh,matplotlib
56,920,446
10
false
0
0
export MPLBACKEND="agg" this worked for me. obviously you can set it via code as well.
1
75
0
I have a python code doing some calculation on a remote machine, named A. I connect on A via ssh from a machine named B. Is there a way to display the figure on machine B?
Matplotlib: display plot on a remote machine
0.039979
0
0
100,815
3,454,647
2010-08-11T01:17:00.000
0
1
0
1
c#,python,c,dll,import
3,454,709
4
false
0
0
I've done some work with ctypes, and loading dlls in windows, but I don't think DLL have any sort of introspection. This really isn't a big deal, because all of the function calls in DLLs are static. If your trying to use a undocumented DLL, you would not only need to know the names of the functions, but also the parameters of the functions. You would have to reverse engineer the DLL, no small task. So, in my opinion, I would say no.
1
4
0
is this possible to view contents and Functions of a DLL file... few times ago i was playing with OlyDBG then i found there is option for viewing contents of dll... so suggest me any good tool or soft for this... and suppose i have a DLL named "Python27.dll"... now i need to view the content of this DLL so what do i do... thanx...
Viewing Contents Of a DLL File
0
0
0
3,117
3,456,088
2010-08-11T07:10:00.000
9
0
1
0
python
3,456,122
5
true
0
0
It depends what you're going to do with it. Unicode handling has vastly improved in Python 3. So if you intend to use this for building web pages or some such, Python 3 might be the obvious choice. On the other hand, many libraries and frameworks still only support Python 2. For example, the numerical processing library numpy, and the web framework Django both only work on Python 2. So if you intend to use any of those, stick with Python 2. Either way, the differences aren't huge to begin with. I'd say Python 3 is a little easier to pick up (due to its string handling), but that is a good reason to learn Python 2 first. That way, if you run into a piece of Python 2 code (and you will), you'll know what is going on.
4
3
0
What's the ideal Python version for a beginner to start learning Python? I need to recommend some newbies a programming language to learn and I chose Python. I'm still not sure which version.
Python 3.X or Python 2.X
1.2
0
0
316
3,456,088
2010-08-11T07:10:00.000
0
0
1
0
python
3,456,113
5
false
0
0
I would suggest Python 2.6; I know it's old, but it's not only the current standard, and there is way more documentation and libraries available for it.
4
3
0
What's the ideal Python version for a beginner to start learning Python? I need to recommend some newbies a programming language to learn and I chose Python. I'm still not sure which version.
Python 3.X or Python 2.X
0
0
0
316
3,456,088
2010-08-11T07:10:00.000
0
0
1
0
python
3,459,116
5
false
0
0
I'll throw my experience into the works: Right now you should be using 2.6. Switch to 2.7 when 2.7.1 comes out. Switch to 3.1/2 when all the libraries you want are fully supported and stable there.
4
3
0
What's the ideal Python version for a beginner to start learning Python? I need to recommend some newbies a programming language to learn and I chose Python. I'm still not sure which version.
Python 3.X or Python 2.X
0
0
0
316
3,456,088
2010-08-11T07:10:00.000
1
0
1
0
python
3,456,110
5
false
0
0
My vote is for 3.1 My reasoning is simple and selfish. The more new python programmers that only use 3.1 there are, the more likely it is that one of them is going to decide that they need some library from 2.6 and port it to 3.1 (learning 2.6 in the process I might add). After this happens, I can start using 3.1: it looks really cool.
4
3
0
What's the ideal Python version for a beginner to start learning Python? I need to recommend some newbies a programming language to learn and I chose Python. I'm still not sure which version.
Python 3.X or Python 2.X
0.039979
0
0
316
3,456,648
2010-08-11T08:32:00.000
0
0
1
0
python,class,object,arguments
23,485,777
3
false
0
0
If I understand your question, this will help you Assume we have class BankAccount: '''After Constructor, we have another method ''' def transfer(self,amount,object): #object is variable passed for referencing an object BankAccount.credit(self,amount) object.debit(amount) call method bank1=BankAccount() bank1.transfer(2000,objectname)
1
3
0
I have a module including definitions for two different classes in Python. How do I use objects of one class as an argument of the other? Say, I have class definitions for Driver and Car, and tuen want to have a Driver object as an argument for a Car object.
Python: object as an argument of another object
0
0
0
23,405
3,458,249
2010-08-11T12:36:00.000
0
1
1
0
python
3,458,457
3
false
0
0
Assuming general network conditions, as long you have sufficient system resources Python's regular threading module will allow you to simulate concurrent workload at an higher rate than any a real workload.
2
3
0
I have a web service that is required to handle significant concurrent utilization and volume and I need to test it. Since the service is fairly specialized, it does not lend itself well to a typical testing framework. The test would need to simulate multiple clients concurrently posting to a URL, parsing the resulting Http response, checking that a database has been appropriately updated and making sure certain emails have been correctly sent/received. The current opinion at my company is that I should write this framework using Python. I have never used Python with multiple threads before and as I was doing my research I came across the Global Interpreter Lock which seems to be the basis of most of Python's concurrency handling. It seems to me that the GIL would prevent Python from being able to achieve true concurrency even on a multi-processor machine. Is this true? Does this scenario change if I use a compiler to compile Python to native code? Am I just barking up the wrong tree entirely and is Python the wrong tool for this job?
Concurrency Testing For A Web Service Using Python
0
0
0
1,336
3,458,249
2010-08-11T12:36:00.000
3
1
1
0
python
3,458,598
3
false
0
0
The Global Interpreter Lock prevents threads simultaneously executing Python code. This doesn't change when Python is compiled to bytecode, because the bytecode is still run by the Python interpreter, which will enforce the GIL. threading works by switching threads every sys.getcheckinterval() bytecodes. This doesn't apply to multiprocessing, because it creates multiple Python processes instead of threads. You can have as many of those as your system will support, running truly concurrently. So yes, you can do this with Python, either with threading or multiprocessing.
2
3
0
I have a web service that is required to handle significant concurrent utilization and volume and I need to test it. Since the service is fairly specialized, it does not lend itself well to a typical testing framework. The test would need to simulate multiple clients concurrently posting to a URL, parsing the resulting Http response, checking that a database has been appropriately updated and making sure certain emails have been correctly sent/received. The current opinion at my company is that I should write this framework using Python. I have never used Python with multiple threads before and as I was doing my research I came across the Global Interpreter Lock which seems to be the basis of most of Python's concurrency handling. It seems to me that the GIL would prevent Python from being able to achieve true concurrency even on a multi-processor machine. Is this true? Does this scenario change if I use a compiler to compile Python to native code? Am I just barking up the wrong tree entirely and is Python the wrong tool for this job?
Concurrency Testing For A Web Service Using Python
0.197375
0
0
1,336
3,461,549
2010-08-11T18:21:00.000
79
0
1
0
javascript,python,twisted,node.js
3,461,640
2
true
1
0
Twisted is more mature -- it's been around for a long, long time, and has so many bells and whistles as to make your head spin (implementations of the fanciest protocols, integration of the reactor with a large variety of other event loops, and so forth). Node.js is said to be faster (I have not measured it myself) and might perhaps be simpler to use (if you need none of the extra bells and whistles) exactly because those extras aren't there (kind of like Tornado in the Python world -- again, I have never measured relative performance). So, I'd absolutely use Twisted if I needed any of its extra features or wanted to feel on a more solid ground by using a more mature package. If these considerations don't apply, but top performance is a key goal of the project, then I'd write a simple benchmark (but still representative of at least one or two key performance-need situations for my actual project) in Twisted, Node.js, and Tornado, and do a lot of careful measurement before I decide which way to go overall. "Extra features" (third party extensions and standard library) for Python vs server-side Javascript are also much more abundant, and that might be a key factor if any such extras are needed for the project. Finally, if none of these issues matter to a specific application scenario, have the development team vote on relative simplicity of the three candidates (Twisted, Node.js, Tornado) in terms of simplicity and familiarity -- any of them will probably be just fine, might as well pick whatever most of the team is most comfortable with!
1
65
0
Assuming a team of developers are equally comfortable with writing Javascript on the server side as they are with Python & Twisted, when is Node.js going to be more appropriate than Twisted (and vice versa)?
What are the use cases of Node.js vs Twisted?
1.2
0
0
20,135
3,462,951
2010-08-11T21:21:00.000
0
0
0
0
python,django
3,463,019
2
false
1
0
Not all sequences of bytes are valid for ex. UTF-8, maybe you should check this?
1
0
0
The file is uploaded through a Django form. The contents of the file need to be saved into a models.TextField(), for editors to review it before publication. I am already checking UploadedFile.content_type. I have considered using a regular input field, but as the text is going to be quite long, it would be unwieldy for users to cut and paste.
In Python, how do I check that a file is a text file?
0
0
0
114
3,464,996
2010-08-12T05:36:00.000
1
0
0
0
python,dial-up,isdn
3,465,106
1
false
0
0
You should have system hardware and software that handles establishing ISDN links, that's not something you should be trying to reimplement yourself. You need to consult the documentation for that hardware and software, and the documentation for the client software, to determine how that connection can be made available to your application, and what communications protocol the client will be using over the ISDN link. (If you're really lucky, the client actually uses PPP to establish a TCP/IP connection.)
1
0
0
I have a requirement to create a Python application that accepts dial up connections over ISDN from client software and relays messages from this connection to a website application running on a LAMP webserver. Do we have some modules or support for this kind of implementation in python? Please suggest. Thanks in advance.
ISDN dial up connection with python
0.197375
0
1
974
3,465,231
2010-08-12T06:32:00.000
0
0
0
0
python,excel-2003
3,466,751
1
true
0
0
If you do not have sufficient file permissions you will not be able to access the file. In that case you will have to execute your Python program as an user with sufficient permissions. If on the other hand the file is locked using other means specific to Excel then I am not sure what exactly is the solution. You might have to work around the protection using other means which will require a fair amount of understanding of how Excel sheets are "locked". I don't know of any Python libraries that will do this for you.
1
0
0
I'm trying to copy an excel sheet with python, but I keep getting "access denied" error message. The file is closed and is not shared. It has macros though. Is their anyway I can copy the file forcefully with python? thanks.
Copying a file with access locks, forcefully with python
1.2
1
0
94
3,465,295
2010-08-12T06:41:00.000
4
1
0
1
python,command,packaging,distutils
3,466,094
2
true
0
0
I wouldn't have any check at all. Document that your library requires this command, and if the user tries to use whatever part of your library needs it, an exception will be raised by whatever runs the command. It should still be possible to import your library and use it, even if only a subset of functionality is offered. (PS: commands is old and broken and shouldn't be used in new code. subprocess is the hot new stuff.)
1
3
0
I'm looking for the most elegant way to notify users of my library that they need a specific unix command to ensure that it will works... When is the bet time for my lib to raise an error: Installation ? When my app call the command ? At the import of my lib ? both? And also how should you detect that the command is missing (if not commands.getoutput("which CommandIDependsOn"): raise Exception("you need CommandIDependsOn")). I need advices.
How to depends of a system command with python/distutils?
1.2
0
0
629
3,468,028
2010-08-12T13:18:00.000
1
0
0
0
php,python,ruby,web-scraping
3,469,962
4
false
1
0
Short answer is no. The problem is that HTML is a large family of formats - and only the more recent variants are consistent (and XML based). If you're going to use PHP then I would recommend using the DOM parser as this can handle a lot of html which does not qualify as well-formed XML. Reading between the lines of your post - you seem to be: 1) capturing content from the web with a requirement for complex interaction management 2) parsing the data into a consistent machine readable format 3) writing the data to a spreadsheet Which is certainly 3 seperate problems - if no one language meets all 3 requirements then why not use the best tool for the job and just worry about an suitable interim format/medium for the data? C.
1
7
0
I have used 3 languages for Web Scraping - Ruby, PHP and Python and honestly none of them seems to perfect for the task. Ruby has an excellent mechanize and XML parsing library but the spreadsheet support is very poor. PHP has excellent spreadsheet and HTML parsing library but it does not have an equivalent of WWW:Mechanize. Python has a very poor Mechanize library. I had many problems with it and still unable to solve them. Its spreadsheet library also is more or less decent since it unable to create XLSX files. Is there anything which is just perfect for webscraping. PS: I am working on windows platform.
Is there any language which is just "perfect" for web scraping?
0.049958
0
1
2,443
3,468,101
2010-08-12T13:25:00.000
0
1
1
0
java,javascript,python,programming-languages,classloader
3,469,617
8
false
0
0
In Python, you should use the traceback or inspect modules. These will modules will shield you from the implementation details of the interpreter, which can differ even today (e.g. IronPython, Jython) and may change even more in the future. The way these modules do it under the standard Python interpreter today, however, is with sys._getframe(). In particular, sys._getframe(1).f_code.co_name provides the information you want.
1
12
0
I would like to write a code internal to my method that print which method/class has invoked it. (My assumption is that I can't change anything but my method..) How about other programming languages? EDIT: Thanks guys, how about JavaScript? python? C++?
Java or any other language: Which method/class invoked mine?
0
0
0
754
3,468,227
2010-08-12T13:37:00.000
2
1
0
0
php,asp.net,python,frameworks,benchmarking
3,468,630
4
true
1
0
What I have done is to write many unit tests so you can test the layers. For example, write a SOAP web service in PHP, Python and C#. Write a REST web service in the same languages (same web services, just two ways to get to them). This one should be able to return JSON and XML as a minimum. Write unit tests in C# and Python to serve as clients, and test the REST with the various result types (XML/JSON). This is important as later you may need to test to see which is best end-to-end, and JSON may be faster to parse than XML, for you (it should be). So, the REST/SOAP services should go to the same controller, to simplify your life. This controller needs tests, as you may need to later remove it's impact on your tests, but, you can also write tests to see how fast it goes to the database. I would use one database for this, unless you want to evaluate various databases, but for a web test, just do that for phase 2. :) So, what you end up with is lots of tests, each test needs to be able to determine how long it took for it to actually run. You then have lots of numbers, and you can start to analyze to see what works best for you. For example, I had learned (a couple of years ago when I did this) that JSON was faster than XML, REST was faster than SOAP. You may find that some things are much harder to do in some languages and so drop them from contention as you go through this process. Writing the tests is the easy part, getting meaningful answers from the numbers will be the harder part, as your biases may color your analysis, so be careful of that. I would do this with some real application so that the work isn't wasted, just duplicated.
2
1
0
I'd like to compare the performance of different languages and/or different frameworks within the same language. This is aimed at server-side languages used for web development. I know an apples to apples comparison is not possible, but I'd like it to be as unbiased as possible. Here are some ideas : Simple "Hello World" page Object initialization Function/method calls Method bodies will range from empty to large File access (read and write) Database access They can either be measured by Requests per second or I can use a for loop and loop many times. Some of these benchmarks should measure the overhead the language has (ie: empty function call) rather than how fast they perform a certain task. I'll take some precautions: They'll run on the same machine, on fresh installations with as few processes on the background as possible. I'll try and set up the server as officially recommended; I will not attempt any optimizations. How can I improve on this?
How can I benchmark different languages / frameworks?
1.2
0
0
463
3,468,227
2010-08-12T13:37:00.000
0
1
0
0
php,asp.net,python,frameworks,benchmarking
3,468,464
4
false
1
0
You will spend a lot of time and come to realization that it was all wasted. After you complete your tests you will learn that loops of 1000000 empty iterations are far from the real life and come to apache benchmark. Then you come no know of opcode cachers which will ruin all your previous results. Then you will learn that single DB query will take 1000 times longer time than API call, so, your comparisons of database access methods are really waste. Then you will learn of memcache which will allow you just jump over some terrible bottlenecks you've discovered already, etc etc etc
2
1
0
I'd like to compare the performance of different languages and/or different frameworks within the same language. This is aimed at server-side languages used for web development. I know an apples to apples comparison is not possible, but I'd like it to be as unbiased as possible. Here are some ideas : Simple "Hello World" page Object initialization Function/method calls Method bodies will range from empty to large File access (read and write) Database access They can either be measured by Requests per second or I can use a for loop and loop many times. Some of these benchmarks should measure the overhead the language has (ie: empty function call) rather than how fast they perform a certain task. I'll take some precautions: They'll run on the same machine, on fresh installations with as few processes on the background as possible. I'll try and set up the server as officially recommended; I will not attempt any optimizations. How can I improve on this?
How can I benchmark different languages / frameworks?
0
0
0
463
3,468,243
2010-08-12T13:40:00.000
9
1
0
0
python,opcode,opcode-cache
3,468,276
3
false
1
0
It's automatic in Python -- a compiled .pyc file will appear magically.
2
2
0
I'm currently using PHP. I plan to start using Django for some of my next project. But I don't have any experience with Python. After some searching, I still can't find a Python opcode cacher. (There are lots of opcode cacher for PHP: APC, eAccelerator, Xcache, ...)
Python doesn't have opcode cacher?
1
0
0
2,395
3,468,243
2010-08-12T13:40:00.000
2
1
0
0
python,opcode,opcode-cache
3,468,296
3
false
1
0
Python doesn't need one the same way PHP needs it. Python doesn't throw the bytecode away after execution, it keeps it around (as .pyc files).
2
2
0
I'm currently using PHP. I plan to start using Django for some of my next project. But I don't have any experience with Python. After some searching, I still can't find a Python opcode cacher. (There are lots of opcode cacher for PHP: APC, eAccelerator, Xcache, ...)
Python doesn't have opcode cacher?
0.132549
0
0
2,395
3,468,248
2010-08-12T13:40:00.000
0
1
0
0
python,sql,caching,urlopen
3,468,315
5
false
0
0
How often do the price(s) change? If they're pretty constant (say once a day, or every hour or so), just go ahead and write a cron script (or equivalent) that retrieves the values and stores it in a database or text file or whatever it is you need. I don't know if you can check the timestamp data from the Amazon API - if they report that sort of thing.
1
3
0
Hey all, I have a site that looks up info for the end user, is written in Python, and requires several urlopen commands. As a result it takes a bit for a page to load. I was wondering if there was a way to make it faster? Is there an easy Python way to cache or a way to make the urlopen scripts fun last? The urlopens access the Amazon API to get prices, so the site needs to be somewhat up to date. The only option I can think of is to make a script to make a mySQL db and run it ever now and then, but that would be a nuisance. Thanks!
Caching options in Python or speeding up urlopen
0
0
1
805
3,468,500
2010-08-12T14:02:00.000
1
1
0
0
php,javascript,python,image-processing
17,615,110
7
false
0
0
A shorter solution for true color image would be to scale it down to 1x1 pixel size and sample the color at that pixel: $scaled = imagescale($img, 1, 1, IMG_BICUBIC); $meanColor = imagecolorat($img, 0, 0); ...but I haven't tested this myself.
1
49
0
I have a jpg image. I need to know "overall average" the color of the image. At first glance there can use the histogram of the image (channel RGB). At work I use mostly JavaScript and PHP (a little Python) therefore welcomed the decision in these languages. Maybe ther are library for working with images that address similar problems. I do not need to dynamically determine the color of the picture. I need just once go through the entire array of images and determine the color of each separately (this information I will remember for future use).
Detect "overall average" color of the picture
0.028564
0
0
37,896
3,469,551
2010-08-12T15:52:00.000
1
0
1
0
python,django,virtualenv,pip
3,470,317
1
true
1
0
it seems that the pip process quit prematurely due to a package in requirements that could not be found. this left things in limbo, stuck in the temp-like "build" folder before having a chance to complete the process which gets them into the proper "site-packages" location.
1
4
0
i am setting up a virtualenv for django deployment. i want an isolated env without access to the global site-packages. i used the option --no-site-packages, then installed a local pip instance for that env. after using pip and a requirements.txt file i noticed that most packages were installed in a "build" folder that is not in sys.path so i am getting an error such as "no module named django.conf" i also installed virtualenvwrapper after the base virtualenv package. as far i as i can recall i have not seen a "build" folder before, and am curious why these packages weren't simply installed in my local env's site-packages folder. how should i go about pointing to that build folder and why does it exist? thanks
virtualenv, sys.path and site-packages
1.2
0
0
1,443
3,470,989
2010-08-12T18:54:00.000
12
1
0
0
python,django,email-headers
3,471,052
2
true
1
0
Ok, I see I was browsing tragically old code. I should be able to call django.core.mail.message.make_msgid() and populate the header myself before calling send.
1
7
0
I want to save the MessageID of a sent email, so I can later use it in a References: header to facilitate threading. I see in root/django/trunk/django/core/mail.py (line ~55) where the MessageID is created. I'm trying to think of the best way to collect this value, other than just copy/pasting into a new backend module and returning it. Maybe that is the best way?
What's the easiest/cleanest way to get the MessageID of a sent email?
1.2
0
0
2,548
3,472,349
2010-08-12T21:52:00.000
0
0
1
1
python,installation,diskimage
3,472,387
4
false
0
0
Looks like all the other versions only have a 32 bit port? So a "new feature" of 2.7 is a 64 bit port. If you aren't running a 64 bit OS and don't need programs that can use > 4 GB of ram, you can stick with the 32 bit.
3
3
0
Python 2.7 has two different disk image installers for Mac OS X. My questions are: What are the differences between the two Python 2.7 disk image installers? Python 2.7 32-bit Mac OS X Installer Disk Image for Mac OS X 10.3 through 10.6 Python 2.7 PPC/i386/x86-64 Mac OS X Installer Disk Image for Mac OS X 10.5 or later If running Mac OS X 10.6 Snow Leopard without the 64-bit kernel and extensions, which is the more appropriate version of Python 2.7 to install? Why are there two different Mac OS X disk image installers for Python 2.7 when Python 2.6.5 and Python 3.2 each only have one? Does the first listed installer support PPC? Strange that it wouldn't if it support back to Mac OS X 10.3, but unlike the second installer PPC isn't listed.
What are the differences between the two Python 2.7 Mac OS X disk image installers?
0
0
0
2,127
3,472,349
2010-08-12T21:52:00.000
0
0
1
1
python,installation,diskimage
3,472,470
4
false
0
0
1) You almost certainly want "Python 2.7 PPC/i386/x86-64 Mac OS X Installer Disk Image". It's also a close analogue of the 2.6.x version that comes with 10.6 by default. 2) Unless you know you need 32-bit versions for some reason, default to 64-bit for everything on Snow Leopard. It's what will most closely match the rest of the the apps/libraries/userland. The kernel is irrelevant in this regard. The 32-bit OS X kernel can and will still run 64-bit userland. 3) 64-bit versions weren't available before 10.6.
3
3
0
Python 2.7 has two different disk image installers for Mac OS X. My questions are: What are the differences between the two Python 2.7 disk image installers? Python 2.7 32-bit Mac OS X Installer Disk Image for Mac OS X 10.3 through 10.6 Python 2.7 PPC/i386/x86-64 Mac OS X Installer Disk Image for Mac OS X 10.5 or later If running Mac OS X 10.6 Snow Leopard without the 64-bit kernel and extensions, which is the more appropriate version of Python 2.7 to install? Why are there two different Mac OS X disk image installers for Python 2.7 when Python 2.6.5 and Python 3.2 each only have one? Does the first listed installer support PPC? Strange that it wouldn't if it support back to Mac OS X 10.3, but unlike the second installer PPC isn't listed.
What are the differences between the two Python 2.7 Mac OS X disk image installers?
0
0
0
2,127
3,472,349
2010-08-12T21:52:00.000
3
0
1
1
python,installation,diskimage
3,472,625
4
true
0
0
As others have pointed out, the second (64-bit) installer variant is new on python.org starting with 2.7 and future releases of 2.7 and 3.2 will have both 32-bit-only and a 32-/64-bit variants. The newer variant is an attempt to add out-of-the-box support from python.org for Intel 64-bit (x86_64) processes which is the default for new applications in OS X 10.6. However, the python.org installer goes a bit further and tries to support x86_64 on OS X 10.5 as well and that has caused some serious problems. In particular, the installer was linked with Tk 8.4 for which Apple does not supply a native 64-bit version on either 10.5 or 10.6. This means that IDLE and any other Python program that uses Tkinter fails on 10.6 in the default 64-bit mode (and for various reasons it is not straightforward to run IDLE in 32-bit mode on 10.6). And, of course, they will fail on 10.5 if 64-bit mode is forced. Apple does supply a 64-bit version of Tk 8.5 but only on OS X 10.6. For this and other reasons, the current plan is to change the 32-bit/64-bit variant in future releases to only support 10.6 or higher and only include 32-bit (i386) and 64-bit (x86_64) support, no PPC. So if you anticipate needing IDLE or Tkinter on 10.6, you should consider sticking to the traditional 32-bit-only 2.7 installer for now until a newer 10.6-only installer is available (which might not be until the next maintenance release of 2.7). As to question 4, at the moment, both installers support PPC 32-bit: the first on 10.3 through 10.6, the second on 10.5 & 10.6. But the second will disappear in the future. And, although OS X 10.6 will not boot on PPC machines, it is possible to run Python (and most other programs) in PPC mode if the Rosetta emulation package is installed in OS X.
3
3
0
Python 2.7 has two different disk image installers for Mac OS X. My questions are: What are the differences between the two Python 2.7 disk image installers? Python 2.7 32-bit Mac OS X Installer Disk Image for Mac OS X 10.3 through 10.6 Python 2.7 PPC/i386/x86-64 Mac OS X Installer Disk Image for Mac OS X 10.5 or later If running Mac OS X 10.6 Snow Leopard without the 64-bit kernel and extensions, which is the more appropriate version of Python 2.7 to install? Why are there two different Mac OS X disk image installers for Python 2.7 when Python 2.6.5 and Python 3.2 each only have one? Does the first listed installer support PPC? Strange that it wouldn't if it support back to Mac OS X 10.3, but unlike the second installer PPC isn't listed.
What are the differences between the two Python 2.7 Mac OS X disk image installers?
1.2
0
0
2,127
3,472,493
2010-08-12T22:23:00.000
4
0
0
0
java,python,gwt,pyjamas
4,886,045
2
false
1
0
I've managed to deploy a couple of medium sized webapps using pyjamas and believe me, it was very smooth sailing. It's a slimmed-down version of GWT too so it is easier to learn. Most of the UI widgets are 100 lines ish! Also the pythonic use of OO is pretty exemplary.
2
6
0
I love both, python and Java and I have this first 'serious' web application project that I would like to carry out. I find it hard to choose between pyjamas + django and GWT + Hibernate. In fact, from my beginner point of view, it seems like the python world is more suitable for a quickly-developed and fun web application. And, on the other hand, the java world is useful for performance-oriented, scalable solutions and for 'serious' projects with big money involved... My requirements are quite simple: this application has to replace a desktop application. So, the performance factor is there. But my deadlines are pretty short. Is pyjamas mature enough to replace GWT on a performance and functionality point of view?
About pyjamas maturity vs GWT maturity (with short dead lines) for a web application
0.379949
0
0
1,811
3,472,493
2010-08-12T22:23:00.000
7
0
0
0
java,python,gwt,pyjamas
3,473,114
2
true
1
0
In fact, from my beginner point of view, it seems like the python world is more suitable for a quickly-developed and fun web application. And, on the other hand, the java world is useful for performance-oriented, scalable solutions and for 'serious' projects with big money involved... Naah. For example, YouTube is in Python -- where do you see that affecting its performance, scalability, or "big money" characteristics? Is pyjamas mature enough to replace GWT on a performance and functionality point of view? Completely different question from the previous, silly observation. GWT has been around for longer, and has more users and contributors. Perhaps pyjamas is "good enough" for many uses -- nevertheless, it is at release 0.7, with GWT at release 2.0, which can be taken as an indication that GWT is better, more developed and mature. Most real-world, highly-scalable web apps use "real" Javascript (typically with some supporting framework, such as the very popular jQuery or any of its many "competitors"); if, for whatever reason, you can't (or, more likely, don't want to), then GWT is probably a less risky choice than pyjamas, in my opinion.
2
6
0
I love both, python and Java and I have this first 'serious' web application project that I would like to carry out. I find it hard to choose between pyjamas + django and GWT + Hibernate. In fact, from my beginner point of view, it seems like the python world is more suitable for a quickly-developed and fun web application. And, on the other hand, the java world is useful for performance-oriented, scalable solutions and for 'serious' projects with big money involved... My requirements are quite simple: this application has to replace a desktop application. So, the performance factor is there. But my deadlines are pretty short. Is pyjamas mature enough to replace GWT on a performance and functionality point of view?
About pyjamas maturity vs GWT maturity (with short dead lines) for a web application
1.2
0
0
1,811
3,472,515
2010-08-12T22:26:00.000
0
0
0
0
python,http,concurrency,urllib2
3,472,568
9
false
0
0
How about using pycurl? You can apt-get it by $ sudo apt-get python-pycurl
1
15
0
As the title suggests, I'm working on a site written in python and it makes several calls to the urllib2 module to read websites. I then parse them with BeautifulSoup. As I have to read 5-10 sites, the page takes a while to load. I'm just wondering if there's a way to read the sites all at once? Or anytricks to make it faster, like should I close the urllib2.urlopen after each read, or keep it open? Added: also, if I were to just switch over to php, would that be faster for fetching and Parsi g HTML and XML files from other sites? I just want it to load faster, as opposed to the ~20 seconds it currently takes
Python urllib2.urlopen() is slow, need a better way to read several urls
0
0
1
32,925
3,472,634
2010-08-12T22:50:00.000
8
0
1
0
java,python
3,472,642
7
false
1
0
Head First Java is a great book for any new Java programmer. It has lots of pictures, fun quips and puzzles to solve. Definitely worth the buy.
3
10
0
My 12 year old brother has recently expressed an interest in learning to program. I of course think this is a great idea, why not start him early? I'm wondering what you guys think with regards a book? I was thinking I should start him off on Java but I'm unsure what book would be best? Any suggestions with regards a book or even another language would be much appreciated. UPDATE: I've went with Python and I'm starting him off with "Snake wrangling for kids".
Good learner book for a 12 year old?
1
0
0
2,051
3,472,634
2010-08-12T22:50:00.000
2
0
1
0
java,python
3,472,998
7
false
1
0
If your brother plays any PC games, you might check to see if any of them are moddable. Many games these days come with scripted campaign editors or have python scripts underlying them that you can modify. They are a great way to get involved with the basic concepts behind programming, as your brother can get pretty immediate feedback in an environment that's already very interesting to him. It may not be 'programming' per se, but it's an exercise in instructing the computer to do what you want, which requires a clear intention and some work and investigation to actually achieve what you've intended. If he develops that mindset, then more general programming in a more complex environment follows naturally.
3
10
0
My 12 year old brother has recently expressed an interest in learning to program. I of course think this is a great idea, why not start him early? I'm wondering what you guys think with regards a book? I was thinking I should start him off on Java but I'm unsure what book would be best? Any suggestions with regards a book or even another language would be much appreciated. UPDATE: I've went with Python and I'm starting him off with "Snake wrangling for kids".
Good learner book for a 12 year old?
0.057081
0
0
2,051
3,472,634
2010-08-12T22:50:00.000
0
0
1
0
java,python
3,472,658
7
false
1
0
I too can recommend the Head First series. You could try "Head First Programming". It uses some python though.
3
10
0
My 12 year old brother has recently expressed an interest in learning to program. I of course think this is a great idea, why not start him early? I'm wondering what you guys think with regards a book? I was thinking I should start him off on Java but I'm unsure what book would be best? Any suggestions with regards a book or even another language would be much appreciated. UPDATE: I've went with Python and I'm starting him off with "Snake wrangling for kids".
Good learner book for a 12 year old?
0
0
0
2,051
3,472,862
2010-08-12T23:40:00.000
4
0
1
1
python,windows,popen
3,472,949
2
true
0
0
Instead ofD:\Program Files\Steam\steamapps\terabytest\sourcesdk\bin\orangebox\bin\vbsp.exe, useD:/Program Files/Steam/steamapps/terabytest/sourcesdk/bin/orangebox/bin/vbsp.exe This eliminates any complications with backslashes inside quotes.
2
2
0
I'm trying to run console commands via subprocess.Popen, and whenever I run it I get the windows "File not found" error, even when running the echo command. I am also using Popen inside a thread made with the thread module. Is that the problem?
Popen gives "File not found" Error (windows/python)
1.2
0
0
4,657
3,472,862
2010-08-12T23:40:00.000
3
0
1
1
python,windows,popen
3,472,903
2
false
0
0
echo is not an executable, it's an internal command inside cmd.exe. If you want to use Popen with internal commands, add a keyword parameter shell=True
2
2
0
I'm trying to run console commands via subprocess.Popen, and whenever I run it I get the windows "File not found" error, even when running the echo command. I am also using Popen inside a thread made with the thread module. Is that the problem?
Popen gives "File not found" Error (windows/python)
0.291313
0
0
4,657
3,476,152
2010-08-13T10:55:00.000
5
0
0
0
python,google-app-engine
3,476,378
1
true
1
0
save() is a (deprecated) alias for put(). They work exactly equivalently - in fact, they're the same function!
1
0
0
What is the difference between Mymodel.save() and Mymodel.put() in appengine with python? I know that save is used in django but does is work with appengine models too?
Difference between save() and put()?
1.2
0
0
205
3,476,183
2010-08-13T11:02:00.000
2
0
1
0
python,events,windows-7,event-handling
3,477,229
1
true
0
0
Ok, I got pyHook working after installing the 32bit version of python 2.7 and compiling pyHook from the source with MinGW. Thanks for the pointers everyone.
1
3
0
Is there any way to monitor keyboard events in windows 7 with python without the python program having focus? I would like to run the python script as a background process that monitors certain keyboard events and does certain things on various keyboard input combinations.
monitor keyboard events with python in windows 7
1.2
0
0
1,581
3,476,387
2010-08-13T11:35:00.000
3
0
1
0
c++,python,constructor,overloading
3,476,486
4
false
0
1
Usually, you're fine with any combination of slightly altered design default arguments (def __init__(self, x = 0.0, y = 0.0, z = 0.0)) use of polymorphism (in a duck-typed language, you don't need an overload for SomeThing vs SomeSlightlyDifferentThing if neither inherits from the other one, as long as their interfaces are similar enough). If that doesn't seem feasible, try harder ;) If it still doesn't seem feasible, look at David's link.
1
1
0
suppose a C++ class has several constructors which are overloaded according the number and type and sequences of their respective parameters, for example, constructor(int x, int y) and constructor(float x, float y, float z), I think these two are overloaded methods, which one to use depends on the parameters, right? So then in python, how could I create a constructor that can work like this? I notice that python has the def method(self, *args, **kwargs):, so can I use it like: def __init__(self, *args), then I check the length of *args, like if len(args) == 2:, then construct according to the 2-parameters constructor, if len(args) == 3, then use the 3-parameters constructor, etc. So, does that work? Or is there any better way to do it with python? Or should I think in other ways that could take the advantage of python feature itself? thanks~
C++ methods overload in python
0.148885
0
0
251
3,476,509
2010-08-13T11:51:00.000
1
0
1
0
python,module,import
3,477,426
4
false
0
0
let me add that i consider not only from math import * a case of namespace pollution, but also from math import cos. this is because when you do this on top of module foo, and you then look at the namespace of that module with import foo; print( dir( foo ) ), you will have an item cos in that list. usually, this is not what you want. so most of the time all my imports look like from math import cos as _cos, the leading underscore being the conventional sigil to indicate a private name. the idea is that an import from another module and a printout, import foo; print( name for name in dir( foo ) if not name.startswith( '_' ) ) will give you exactly those names that were defined in that module as public. there is one thing to be aware of: from math import cos as _cos; f = lambda x: _cos( x ) is functionally not 100% identical to import math; g = lambda x: math.cos( x ). the difference is that in python, name resolution happens at run time, each time the code is called. with the first import, the name cos is only resolved once; any subsequent changes to the math module will not affect f(). with the second import, cos will be resolved against math each time it is called, so changes to the math module's cos method will propagate into g(). of course, the math module is neither expected to change during runtime, nor is changing a module's method at runtime a particularly recommendable programming technique. on the other hand, a module is just an object like everything else in python, so it pays off to always be aware what happens under the hood. normally, from math import cos as _cos; f = lambda x: _cos( x ) is what you want, and it is also a bit faster than the second form.
1
7
0
I use the math module a lot lately. I don't want to write math.sqrt(x) and math.sin(x) all the time. I would like to shorten it and write sqrt(x) and sin(x). How?
How to avoid writing the name of the module all the time when importing a module in python?
0.049958
0
0
3,120
3,477,283
2010-08-13T13:34:00.000
17
0
1
0
python,int,long-integer,max
3,477,336
4
false
0
0
sys.maxint is not the largest integer supported by python. It's the largest integer supported by python's regular integer type.
1
211
0
I think the maximum integer in python is available by calling sys.maxint. What is the maximum float or long in Python?
What is the maximum float in Python?
1
0
0
281,654
3,477,502
2010-08-13T13:56:00.000
9
0
1
0
python
3,477,530
3
false
0
0
While a custom solution will teach you about Python, for production code using the csv module is the best idea. Comma-separated data can become more complex than initially appears.
1
18
0
I am reading in a string of integers such as "3 ,2 ,6 " and want them in the list [3,2,6] as integers. This is easy to hack about, but what is the "pythonic" way of doing it?
"pythonic" method to parse a string of comma-separated integers into a list of integers?
1
0
0
26,335
3,478,001
2010-08-13T14:48:00.000
0
0
1
0
python,vbscript,exchange-server
3,550,966
1
true
0
0
Going to just install powershell on the machine and use that.
1
0
0
Is there a way to create a recovery group in exchange 2003 with python? Maybe CDOEXM or VBScript? But I have been unsuccessful in finding any sample code. Any ideas?
Recovery Group with Exchange 2003 and Python
1.2
0
0
64
3,478,780
2010-08-13T16:18:00.000
3
0
0
0
python,orm,code-generation
3,481,115
3
false
0
0
You do not need to produce a source code representation of your classes to be able to expand them. The only trick is that you need the ORM to generate the classes BEFORE importing the module that defines the derived classes. Even better, don't use derivation, but use __getattr__ and __setattr__ to implement transparent delegation to the ORM classes.
1
2
0
is there a python ORM (object relational mapper) that has a tool for automatically creating python classes (as code so I can expand them) from a given database schema? I'm frequently faced with small tasks involving different databases (like importing/exporting from various sources etc.) and I thought python together with the abovementioned tool would be perfect for that. It should work like Visual Studios ADO.NET/Linq for SQL designer, where I can just drop DB tables and VS creates classes for me ... Thanks in advance.
Python ORM that automatically creates classes from DB schema
0.197375
1
0
1,411
3,479,569
2010-08-13T18:09:00.000
3
1
0
0
python,alignment,blast
5,816,012
2
false
0
0
In fact a complete implementation of the BLAST algorithm is a quite hard. It has a lot of steps and optimizations. What could you do is: take a look of the BLAST Book from O'Reilly, for a very good explanation, take a look of the NCBI Blast code base, that it is big and hard to understand at the first glace, or, I sugest you to take a look at other BLAST implementation or may be, others algorithms like BLAT and Genoogle (http://genoogle.pih.bio.br/)
1
7
0
Is anyone aware of a pure python implementation of BLAST alignment? I am trying to study this algorithm...
Python implementation of BLAST alignment algorithm?
0.291313
0
0
3,698
3,479,728
2010-08-13T18:35:00.000
3
0
0
1
python,security,bash,scripting,embedding
3,479,760
7
false
0
0
It always better and better style to use Python functions to do this kind of stuff. With Python it's not that hard to write a script in an OS-independent way instead of using bash.
3
8
0
I was wondering whether or not it is considered a good style to call bash commands within a Python script using os.system(). I was also wondering whether or not it is safe to do so as well. I know how to implement some of the functionality I need in Bash and in Python, but it is much simpler and more intuitive to implement it in Bash. However, I feel like it is very hackish to write os.system("bash code"). Specifically, I want to move all files that end with a certain extension to a directory. In bash: *mv .ext /path/to/destination In Python (Pseudocode): for file in directory: if file.endswith("ext"): move file to destination In this case, what should I do?
Is it good style to call bash commands within a Python script using os.system("bash code")?
0.085505
0
0
3,091
3,479,728
2010-08-13T18:35:00.000
1
0
0
1
python,security,bash,scripting,embedding
3,479,763
7
false
0
0
It's not idea, since it makes your script a lot less portable. A native python script can run on any unix or windows machine that has the proper python libraries installed. When you add shell commands into the mix, you break that, and suddenly are locked down to a much narrower subset. Sometimes you don't have a choice, but if it's something as simple as that, writing the code natively in python would make a lot more sense, and also be faster to boot (since the python process won't have to spawn a new shell just to execute the one command).
3
8
0
I was wondering whether or not it is considered a good style to call bash commands within a Python script using os.system(). I was also wondering whether or not it is safe to do so as well. I know how to implement some of the functionality I need in Bash and in Python, but it is much simpler and more intuitive to implement it in Bash. However, I feel like it is very hackish to write os.system("bash code"). Specifically, I want to move all files that end with a certain extension to a directory. In bash: *mv .ext /path/to/destination In Python (Pseudocode): for file in directory: if file.endswith("ext"): move file to destination In this case, what should I do?
Is it good style to call bash commands within a Python script using os.system("bash code")?
0.028564
0
0
3,091
3,479,728
2010-08-13T18:35:00.000
1
0
0
1
python,security,bash,scripting,embedding
3,479,838
7
false
0
0
The quoting issues alone suggest that a pure Python solution is preferable.
3
8
0
I was wondering whether or not it is considered a good style to call bash commands within a Python script using os.system(). I was also wondering whether or not it is safe to do so as well. I know how to implement some of the functionality I need in Bash and in Python, but it is much simpler and more intuitive to implement it in Bash. However, I feel like it is very hackish to write os.system("bash code"). Specifically, I want to move all files that end with a certain extension to a directory. In bash: *mv .ext /path/to/destination In Python (Pseudocode): for file in directory: if file.endswith("ext"): move file to destination In this case, what should I do?
Is it good style to call bash commands within a Python script using os.system("bash code")?
0.028564
0
0
3,091
3,480,371
2010-08-13T20:14:00.000
0
0
1
0
python,printing,window
3,480,555
2
false
0
0
If you mean the prompt window that opens when you run a Python script on MS Windows, try specifying the executable pythonw instead of python, on the first line of your script.
1
1
0
In my python app, I print some stuff during a cycle. After the cycle, I want to close the stdout/stderr window that the prints produced using python code.
How to close stdout/stderr window in python?
0
0
0
3,603
3,480,524
2010-08-13T20:41:00.000
6
0
0
1
python,google-app-engine,twisted
3,480,585
1
true
1
0
Certainly. App Engine will scale your application up as the load increases automatically and will be spread over many machines. The web api they have is pretty nice too. You don't have to worry about deferreds either because it scales by bringing more instances up instead of making things asynchronous. BTW: I have web services hosted on app engine that are consumed by iPhone.
1
1
0
So far I have been using Twisted to simultaneously serve a lot of mobile clients (Android, iPhone) with their HTTP requests exchanging JSON messages. For my next project I'd like to try out Google App Engine, but I'm wondering if it is capable of doing the same or if I should rather go with a custom built solution again.
Twisted vs Google App Engine in serving mobile clients
1.2
0
0
617