log_score
int64
-1
11
ViewCount
int64
8
6.81M
A_Id
int64
1.99k
72.5M
Available Count
int64
1
18
Question
stringlengths
15
29k
AnswerCount
int64
1
51
Q_Score
int64
0
6.79k
is_accepted
bool
2 classes
Tags
stringlengths
6
94
CreationDate
stringlengths
23
23
Q_Id
int64
1.98k
70M
Title
stringlengths
11
150
Answer
stringlengths
6
11.6k
Score
float64
-1
1.2
Users Score
int64
-36
1.15k
2
13,411
108,649
2
I need to write a module to detect similar documents. I have read many papers of fingerprints of documents techniques and others, but I do not know how to write code or implement such a solution. The algorithm should work for Chinese, Japanese, English and German language or be language independent. How can I accomplish this?
10
10
false
python,algorithm,diff
2008-09-19T12:47:00.000
101,569
Algorithm to detect similar documents in python script
I think Jeremy has hit the nail on the head - if you just want to detect if files are different, a hash algorithm like MD5 or SHA1 is a good way to go. Linus Torvalds' Git source control software uses SHA1 hashing in just this way - to check when files have been modified.
0
0
2
95,625
102,701
1
I'm starting to learn Python and I've come across generator functions, those that have a yield statement in them. I want to know what types of problems that these functions are really good at solving.
16
229
false
python,generator
2008-09-19T14:58:00.000
102,535
What can you use generator functions for?
I use generators when our web server is acting as a proxy: The client requests a proxied url from the server The server begins to load the target url The server yields to return the results to the client as soon as it gets them
0.024995
2
2
68,654
105,058
3
In Python specifically, how do variables get shared between threads? Although I have used threading.Thread before I never really understood or saw examples of how variables got shared. Are they shared between the main thread and the children or only among the children? When would I need to use thread local storage to avoid this sharing? I have seen many warnings about synchronizing access to shared data among threads by using locks but I have yet to see a really good example of the problem. Thanks in advance!
6
123
false
python,multithreading,thread-local
2008-09-19T19:53:00.000
104,983
What is "thread local storage" in Python, and why do I need it?
Just like in every other language, every thread in Python has access to the same variables. There's no distinction between the 'main thread' and child threads. One difference with Python is that the Global Interpreter Lock means that only one thread can be running Python code at a time. This isn't much help when it comes to synchronising access, however, as all the usual pre-emption issues still apply, and you have to use threading primitives just like in other languages. It does mean you need to reconsider if you were using threads for performance, however.
0.099668
3
1
68,654
70,450,414
3
In Python specifically, how do variables get shared between threads? Although I have used threading.Thread before I never really understood or saw examples of how variables got shared. Are they shared between the main thread and the children or only among the children? When would I need to use thread local storage to avoid this sharing? I have seen many warnings about synchronizing access to shared data among threads by using locks but I have yet to see a really good example of the problem. Thanks in advance!
6
123
false
python,multithreading,thread-local
2008-09-19T19:53:00.000
104,983
What is "thread local storage" in Python, and why do I need it?
Worth mentioning threading.local() is not a singleton. You can use more of them per thread. It is not one storage.
0.033321
1
1
68,654
60,241,832
3
In Python specifically, how do variables get shared between threads? Although I have used threading.Thread before I never really understood or saw examples of how variables got shared. Are they shared between the main thread and the children or only among the children? When would I need to use thread local storage to avoid this sharing? I have seen many warnings about synchronizing access to shared data among threads by using locks but I have yet to see a really good example of the problem. Thanks in advance!
6
123
false
python,multithreading,thread-local
2008-09-19T19:53:00.000
104,983
What is "thread local storage" in Python, and why do I need it?
I may be wrong here. If you know otherwise please expound as this would help explain why one would need to use thread local(). This statement seems off, not wrong: "If you want to atomically modify anything that another thread has access to, you have to protect it with a lock." I think this statement is ->effectively<- right but not entirely accurate. I thought the term "atomic" meant that the Python interpreter created a byte-code chunk that left no room for an interrupt signal to the CPU. I thought atomic operations are chunks of Python byte code that does not give access to interrupts. Python statements like "running = True" is atomic. You do not need to lock CPU from interrupts in this case (I believe). The Python byte code breakdown is safe from thread interruption. Python code like "threads_running[5] = True" is not atomic. There are two chunks of Python byte code here; one to de-reference the list() for an object and another byte code chunk to assign a value to an object, in this case a "place" in a list. An interrupt can be raised -->between<- the two byte-code ->chunks<-. That is were bad stuff happens. How does thread local() relate to "atomic"? This is why the statement seems misdirecting to me. If not can you explain?
0.033321
1
1
10,397
105,127
2
If you are relying on an implementation of Python that has a Global Interpreter Lock (i.e. CPython) and writing multithreaded code, do you really need locks at all? If the GIL doesn't allow multiple instructions to be executed in parallel, wouldn't shared data be unnecessary to protect? sorry if this is a dumb question, but it is something I have always wondered about Python on multi-processor/core machines. same thing would apply to any other language implementation that has a GIL.
9
79
false
python,multithreading,locking
2008-09-19T20:07:00.000
105,095
Are locks unnecessary in multi-threaded Python code because of the GIL?
You still need to use locks (your code could be interrupted at any time to execute another thread and this can cause data inconsistencies). The problem with GIL is that it prevents Python code from using more cores at the same time (or multiple processors if they are available).
0.022219
1
5
10,397
105,145
2
If you are relying on an implementation of Python that has a Global Interpreter Lock (i.e. CPython) and writing multithreaded code, do you really need locks at all? If the GIL doesn't allow multiple instructions to be executed in parallel, wouldn't shared data be unnecessary to protect? sorry if this is a dumb question, but it is something I have always wondered about Python on multi-processor/core machines. same thing would apply to any other language implementation that has a GIL.
9
79
false
python,multithreading,locking
2008-09-19T20:07:00.000
105,095
Are locks unnecessary in multi-threaded Python code because of the GIL?
No - the GIL just protects python internals from multiple threads altering their state. This is a very low-level of locking, sufficient only to keep python's own structures in a consistent state. It doesn't cover the application level locking you'll need to do to cover thread safety in your own code. The essence of locking is to ensure that a particular block of code is only executed by one thread. The GIL enforces this for blocks the size of a single bytecode, but usually you want the lock to span a larger block of code than this.
1
25
1
58,009
106,731
2
I need to package my Python application, its dependencies and Python into a single MSI installer. The end result should desirably be: Python is installed in the standard location the package and its dependencies are installed in a separate directory (possibly site-packages) the installation directory should contain the Python uncompressed and a standalone executable is not required
7
61
false
python,tkinter,packaging
2008-09-20T01:39:00.000
106,725
How to bundle a Python application including dependencies?
py2exe is the best way to do this. It's a bit of a PITA to use, but the end result works very well.
0.028564
1
3
58,009
114,717
2
I need to package my Python application, its dependencies and Python into a single MSI installer. The end result should desirably be: Python is installed in the standard location the package and its dependencies are installed in a separate directory (possibly site-packages) the installation directory should contain the Python uncompressed and a standalone executable is not required
7
61
false
python,tkinter,packaging
2008-09-20T01:39:00.000
106,725
How to bundle a Python application including dependencies?
My company uses the free InnoSetup tool. It is a moderately complex program that has tons of flexibility for building installers for windows. I believe that it creates .exe and not .msi files, however. InnoSetup is not python specific but we have created an installer for one of our products that installs python along with dependencies to locations specified by the user at install time.
0.141893
5
3
104,646
106,909
4
I'm used to the Java model where you can have one public class per file. Python doesn't have this restriction, and I'm wondering what's the best practice for organizing classes.
6
294
false
python,class,project-structure
2008-09-20T03:07:00.000
106,896
Possibilities for Python classes organized across files?
Since there is no artificial limit, it really depends on what's comprehensible. If you have a bunch of fairly short, simple classes that are logically grouped together, toss in a bunch of 'em. If you have big, complex classes or classes that don't make sense as a group, go one file per class. Or pick something in between. Refactor as things change.
1
41
5
104,646
106,903
4
I'm used to the Java model where you can have one public class per file. Python doesn't have this restriction, and I'm wondering what's the best practice for organizing classes.
6
294
false
python,class,project-structure
2008-09-20T03:07:00.000
106,896
Possibilities for Python classes organized across files?
I would say to put as many classes as can be logically grouped in that file without making it too big and complex.
1
7
5
104,646
8,098,533
4
I'm used to the Java model where you can have one public class per file. Python doesn't have this restriction, and I'm wondering what's the best practice for organizing classes.
6
294
false
python,class,project-structure
2008-09-20T03:07:00.000
106,896
Possibilities for Python classes organized across files?
I find myself splitting things up when I get annoyed with the bigness of files and when the desirable structure of relatedness starts to emerge naturally. Often these two stages seem to coincide. It can be very annoying if you split things up too early, because you start to realise that a totally different ordering of structure is required. On the other hand, when any .java or .py file is getting to more than about 700 lines I start to get annoyed constantly trying to remember where "that particular bit" is. With Python/Jython circular dependency of import statements also seems to play a role: if you try to split too many cooperating basic building blocks into separate files this "restriction"/"imperfection" of the language seems to force you to group things, perhaps in rather a sensible way. As to splitting into packages, I don't really know, but I'd say probably the same rule of annoyance and emergence of happy structure works at all levels of modularity.
1
10
3
104,646
7,879,007
4
I'm used to the Java model where you can have one public class per file. Python doesn't have this restriction, and I'm wondering what's the best practice for organizing classes.
6
294
false
python,class,project-structure
2008-09-20T03:07:00.000
106,896
Possibilities for Python classes organized across files?
I happen to like the Java model for the following reason. Placing each class in an individual file promotes reuse by making classes easier to see when browsing the source code. If you have a bunch of classes grouped into a single file, it may not be obvious to other developers that there are classes there that can be reused simply by browsing the project's directory structure. Thus, if you think that your class can possibly be reused, I would put it in its own file.
1
29
3
7,082
112,557
4
How would a go about making a program where the user enters a string, and the program generates a list of words beginning with that string? Ex: User: "abd" Program:abdicate, abdomen, abduct... Thanks! Edit: I'm using python, but I assume that this is a fairly language-independent problem.
16
7
false
python,list,dictionary
2008-09-21T23:28:00.000
112,532
List all words in a dictionary that start with
One of the best ways to do this is to use a directed graph to store your dictionary. It takes a little bit of setting up, but once done it is fairly easy to then do the type of searches you are talking about. The nodes in the graph correspond to a letter in your word, so each node will have one incoming link and up to 26 (in English) outgoing links. You could also use a hybrid approach where you maintain a sorted list containing your dictionary and use the directed graph as an index into your dictionary. Then you just look up your prefix in your directed graph and then go to that point in your dictionary and spit out all words matching your search criteria.
1
8
1
7,082
112,541
4
How would a go about making a program where the user enters a string, and the program generates a list of words beginning with that string? Ex: User: "abd" Program:abdicate, abdomen, abduct... Thanks! Edit: I'm using python, but I assume that this is a fairly language-independent problem.
16
7
false
python,list,dictionary
2008-09-21T23:28:00.000
112,532
List all words in a dictionary that start with
Try using regex to search through your list of words, e.g. /^word/ and report all matches.
0.012499
1
1
7,082
112,562
4
How would a go about making a program where the user enters a string, and the program generates a list of words beginning with that string? Ex: User: "abd" Program:abdicate, abdomen, abduct... Thanks! Edit: I'm using python, but I assume that this is a fairly language-independent problem.
16
7
false
python,list,dictionary
2008-09-21T23:28:00.000
112,532
List all words in a dictionary that start with
If you need to be really fast, use a tree: build an array and split the words in 26 sets based on the first letter, then split each item in 26 based on the second letter, then again. So if your user types "abd" you would look for Array[0][1][3] and get a list of all the words starting like that. At that point your list should be small enough to pass over to the client and use javascript to filter.
0.012499
1
0
7,082
112,843
4
How would a go about making a program where the user enters a string, and the program generates a list of words beginning with that string? Ex: User: "abd" Program:abdicate, abdomen, abduct... Thanks! Edit: I'm using python, but I assume that this is a fairly language-independent problem.
16
7
false
python,list,dictionary
2008-09-21T23:28:00.000
112,532
List all words in a dictionary that start with
If your dictionary is really big, i'd suggest indexing with a python text index (PyLucene - note that i've never used the python extension for lucene) The search would be efficient and you could even return a search 'score'. Also, if your dictionary is relatively static you won't even have the overhead of re-indexing very often.
0
0
2
89,995
112,993
3
What's the difference between file and open in Python? When should I use which one? (Say I'm in 2.5)
6
140
false
python,file
2008-09-22T03:04:00.000
112,970
Python - When to use file vs open
According to Mr Van Rossum, although open() is currently an alias for file() you should use open() because this might change in the future.
0.066568
2
2
89,995
112,990
3
What's the difference between file and open in Python? When should I use which one? (Say I'm in 2.5)
6
140
false
python,file
2008-09-22T03:04:00.000
112,970
Python - When to use file vs open
Only ever use open() for opening files. file() is actually being removed in 3.0, and it's deprecated at the moment. They've had a sort of strange relationship, but file() is going now, so there's no need to worry anymore. The following is from the Python 2.6 docs. [bracket stuff] added by me. When opening a file, it’s preferable to use open() instead of invoking this [file()] constructor directly. file is more suited to type testing (for example, writing isinstance(f, file)
0.132549
4
5
89,995
112,989
3
What's the difference between file and open in Python? When should I use which one? (Say I'm in 2.5)
6
140
false
python,file
2008-09-22T03:04:00.000
112,970
Python - When to use file vs open
Two reasons: The python philosophy of "There ought to be one way to do it" and file is going away. file is the actual type (using e.g. file('myfile.txt') is calling its constructor). open is a factory function that will return a file object. In python 3.0 file is going to move from being a built-in to being implemented by multiple classes in the io library (somewhat similar to Java with buffered readers, etc.)
1
33
0
47,992
116,197
4
I'd like to search a Word 2007 file (.docx) for a text string, e.g., "some special phrase" that could/would be found from a search within Word. Is there a way from Python to see the text? I have no interest in formatting - I just want to classify documents as having or not having "some special phrase".
10
51
false
python,ms-word,openxml,docx
2008-09-22T17:08:00.000
116,139
How can I search a word in a Word 2007 .docx file?
a docx file is essentially a zip file with an xml inside it. the xml contains the formatting but it also contains the text.
0.039979
2
5
47,992
116,199
4
I'd like to search a Word 2007 file (.docx) for a text string, e.g., "some special phrase" that could/would be found from a search within Word. Is there a way from Python to see the text? I have no interest in formatting - I just want to classify documents as having or not having "some special phrase".
10
51
false
python,ms-word,openxml,docx
2008-09-22T17:08:00.000
116,139
How can I search a word in a Word 2007 .docx file?
You should be able to use the MSWord ActiveX interface to extract the text to search (or, possibly, do the search). I have no idea how you access ActiveX from Python though.
0
0
3
47,992
116,217
4
I'd like to search a Word 2007 file (.docx) for a text string, e.g., "some special phrase" that could/would be found from a search within Word. Is there a way from Python to see the text? I have no interest in formatting - I just want to classify documents as having or not having "some special phrase".
10
51
true
python,ms-word,openxml,docx
2008-09-22T17:08:00.000
116,139
How can I search a word in a Word 2007 .docx file?
More exactly, a .docx document is a Zip archive in OpenXML format: you have first to uncompress it. I downloaded a sample (Google: some search term filetype:docx) and after unzipping I found some folders. The word folder contains the document itself, in file document.xml.
1.2
35
2
47,992
116,194
4
I'd like to search a Word 2007 file (.docx) for a text string, e.g., "some special phrase" that could/would be found from a search within Word. Is there a way from Python to see the text? I have no interest in formatting - I just want to classify documents as having or not having "some special phrase".
10
51
false
python,ms-word,openxml,docx
2008-09-22T17:08:00.000
116,139
How can I search a word in a Word 2007 .docx file?
A docx is just a zip archive with lots of files inside. Maybe you can look at some of the contents of those files? Other than that you probably have to find a lib that understands the word format so that you can filter out things you're not interested in. A second choice would be to interop with word and do the search through it.
0.07983
4
3
16,311
116,901
1
I want to create a mac osx application from python package and then put it in a disk image. Because I load some resources out of the package, the package should not reside in a zip file. The resulting disk image should display the background picture to "drag here -> applications" for installation.
1
25
false
python,macos,packaging
2008-09-22T18:35:00.000
116,657
How do you create an osx application/dmg from a python package?
I don't know the correct way to do it, but this manual method is the approach I've used for simple scripts which seems to have preformed suitably. I'll assume that whatever directory I'm in, the Python files for my program are in the relative src/ directory, and that the file I want to execute (which has the proper shebang and execute permissions) is named main.py. $ mkdir -p MyApplication.app/Contents/MacOS $ mv src/* MyApplication.app/Contents/MacOS $ cd MyApplication.app/Contents/MacOS $ mv main.py MyApplication At this point we have an application bundle which, as far as I know, should work on any Mac OS system with Python installed (which I think it has by default). It doesn't have an icon or anything, that requires adding some more metadata to the package which is unnecessary for my purposes and I'm not familiar with. To create the drag-and-drop installer is quite simple. Use Disk Utility to create a New Disk Image of approximately the size you require to store your application. Open it up, copy your application and an alias of /Applications to the drive, then use View Options to position them as you want. The drag-and-drop message is just a background of the disk image, which you can also specify in View Options. I haven't done it before, but I'd assume that after you whip up an image in your editor of choice you could copy it over, set it as the background and then use chflags hidden to prevent it from cluttering up your nice window. I know these aren't the clearest, simplest or most detailed instructions out there, but I hope somebody may find them useful.
1
7
0
1,912
1,140,282
2
I need to allow other Python applications to register callback functions for events in my application. These need to have priorities associated with them (so a callback with a priority of 10 runs before a callback with a priority of 1) and callback functions need to be able to signal errors to the dispatcher. These are all lightweight callbacks running in the same process, so I don't need to send signals across process boundaries. Is there a good Python library to handle this, or do I need to write my own?
4
2
false
python
2008-09-22T23:28:00.000
118,221
What's the best dispatcher/callback library in Python?
Try Twisted for anything network-related. Its perspective broker is quite nice to use.
0
0
0
1,912
118,228
2
I need to allow other Python applications to register callback functions for events in my application. These need to have priorities associated with them (so a callback with a priority of 10 runs before a callback with a priority of 1) and callback functions need to be able to signal errors to the dispatcher. These are all lightweight callbacks running in the same process, so I don't need to send signals across process boundaries. Is there a good Python library to handle this, or do I need to write my own?
4
2
false
python
2008-09-22T23:28:00.000
118,221
What's the best dispatcher/callback library in Python?
What platform are you running under? GObject is the basis of the GTK GUI that's widely-used under Linux, and it supports event loops with prioritizable events like this.
0
0
2
11,197
11,996,920
3
I am a totally blind programmer who would like to learn Python. Unfortunately the fact that code blocks are represented with different levels of indentation is a major stumbling block. I was wondering if there were any tools available that would allow me to write code using braces or some other code block delimiter and then convert that format into a properly indented representation that the Python interpreter could use?
11
83
false
python,accessibility
2008-09-23T01:33:00.000
118,643
Is there a way to convert indentation in Python code to braces?
Searching an accessible Python IDE, found this and decided to answer. Under Windows with JAWS: Go to Settings Center by pressing JawsKey+6 (on the number row above the letters) in your favorite text editor. If JAWS prompts to create a new configuration file, agree. In the search field, type "indent" There will be only one result: "Say indent characters". Turn this on. Enjoy! The only thing that is frustrating for us is that we can't enjoy code examples on websites (since indent speaking in browsers is not too comfortable — it generates superfluous speech). Happy coding from another Python beginner).
0.072599
4
2
11,197
453,806
3
I am a totally blind programmer who would like to learn Python. Unfortunately the fact that code blocks are represented with different levels of indentation is a major stumbling block. I was wondering if there were any tools available that would allow me to write code using braces or some other code block delimiter and then convert that format into a properly indented representation that the Python interpreter could use?
11
83
false
python,accessibility
2008-09-23T01:33:00.000
118,643
Is there a way to convert indentation in Python code to braces?
There are various answers explaining how to do this. But I would recommend not taking this route. While you could use a script to do the conversion, it would make it hard to work on a team project. My recommendation would be to configure your screen reader to announce the tabs. This isn't as annoying as it sounds, since it would only say "indent 5" rather than "tab tab tab tab tab". Furthermore, the indentation would only be read whenever it changed, so you could go through an entire block of code without hearing the indentation level. In this way hearing the indentation is no more verbose than hearing the braces. As I don't know which operating system or screen reader you use I unfortunately can't give the exact steps for achieving this.
0.01818
1
1
11,197
236,957
3
I am a totally blind programmer who would like to learn Python. Unfortunately the fact that code blocks are represented with different levels of indentation is a major stumbling block. I was wondering if there were any tools available that would allow me to write code using braces or some other code block delimiter and then convert that format into a properly indented representation that the Python interpreter could use?
11
83
false
python,accessibility
2008-09-23T01:33:00.000
118,643
Is there a way to convert indentation in Python code to braces?
I use eclipse with the pydev extensions since it's an IDE I have a lot of experience with. I also appreciate the smart indentation it offers for coding if statements, loops, etc. I have configured the pindent.py script as an external tool that I can run on the currently focused python module which makes my life easier so I can see what is closed where with out having to constantly check indentation.
0.054491
3
2
22,721
118,821
3
I want to use the macports version of python instead of the one that comes with Leopard.
7
19
false
python,macos,osx-leopard,macports
2008-09-23T02:38:00.000
118,813
How do I uninstall python from OSX Leopard so that I can use the MacPorts version?
Instead of uninstalling the built-in Python, install the MacPorts version and then modify your $PATH to have the MacPorts version first. For example, if MacPorts installs /usr/local/bin/python, then modify your .bashrc to include PATH=/usr/local/bin:$PATH at the end.
0.113791
4
5
22,721
2,621,262
3
I want to use the macports version of python instead of the one that comes with Leopard.
7
19
false
python,macos,osx-leopard,macports
2008-09-23T02:38:00.000
118,813
How do I uninstall python from OSX Leopard so that I can use the MacPorts version?
The current Macports installer does the .profile PATH modification automatically.
0.085505
3
2
22,721
118,824
3
I want to use the macports version of python instead of the one that comes with Leopard.
7
19
false
python,macos,osx-leopard,macports
2008-09-23T02:38:00.000
118,813
How do I uninstall python from OSX Leopard so that I can use the MacPorts version?
Don't. Apple ships various system utilities that rely on the system Python (and particularly the Python "framework" build); removing it will cause you problems. Instead, modify your PATH environ variable in your ~/.bash_profile to put /opt/local/bin first.
1
29
2
5,513
119,386
6
Currently I am developing in the .Net environment using C# but I want to know whether it is worth learning python. I'm thinking of learning the Django framework. What is better?
8
3
false
c#,python
2008-09-23T04:53:00.000
119,198
Is it good to switch from c# to python?
Never stop learning! That said, how can you compare the two? How good is Python support in .Net? Is there C# support in Google App Engine? It really depends what your target system is. Therefore, the more languages you have the better equipped you will be to tackle different challenges.
0.049958
2
1
5,513
119,208
6
Currently I am developing in the .Net environment using C# but I want to know whether it is worth learning python. I'm thinking of learning the Django framework. What is better?
8
3
false
c#,python
2008-09-23T04:53:00.000
119,198
Is it good to switch from c# to python?
Both are useful for different purposes. C# is a pretty good all-rounder, python's dynamic nature makes it more suitable for RAD experiences such as site building. I don't think your career will suffer if you were competant in both. To get going with Python consider an IDE with Python support such as Eclipse+PyDev or ActiveIDE's Komodo. (I found a subscription to Safari Bookshelf online really invaluable too!)
0.024995
1
1
5,513
119,215
6
Currently I am developing in the .Net environment using C# but I want to know whether it is worth learning python. I'm thinking of learning the Django framework. What is better?
8
3
false
c#,python
2008-09-23T04:53:00.000
119,198
Is it good to switch from c# to python?
What's better is inherently subjective. If you like Python's syntax - learn it. It will probably be harder to find a Python job, C# and .NET in general seem to be more popular, but this may change. I also think it's worth to know at least one scripting language, even if your main job doesn't require it. Python is not a bad candidate.
0.024995
1
2
5,513
119,224
6
Currently I am developing in the .Net environment using C# but I want to know whether it is worth learning python. I'm thinking of learning the Django framework. What is better?
8
3
false
c#,python
2008-09-23T04:53:00.000
119,198
Is it good to switch from c# to python?
It can't hurt to learn Python, especially considering some of the heavy weights (Google) are really getting behind it. As for the actual use, it all depends on the application. Use the best tool for the job.
0.07486
3
0
5,513
30,671,567
6
Currently I am developing in the .Net environment using C# but I want to know whether it is worth learning python. I'm thinking of learning the Django framework. What is better?
8
3
false
c#,python
2008-09-23T04:53:00.000
119,198
Is it good to switch from c# to python?
I have been thinking about this same question myself. I believe however there is still a lot of stuff C# can offer that I want to get good at before I job into Python. Because Python is easier to learn it. One advantage I have found in languages is not the language itself but the materials available to learning them. For example let's say you could make a 3D game in JavaScript, but you would be more likely to find resources to do so in C++. Or you could make phone apps in PHP but C# or Java would have more material out there to help you with the phone apps. For me personally I know when I become good at programming in C# I will be able to branch off into other languages. This is the main reason I have chosen to devote most of my time to that one language. I also am learning a little bit of Java and C++ just practice thinking in other languages. I think in the future however Python will become more popular because coding is becoming more popular and Python is the easiest of mainstream languages right now.
0
0
1
5,513
119,205
6
Currently I am developing in the .Net environment using C# but I want to know whether it is worth learning python. I'm thinking of learning the Django framework. What is better?
8
3
false
c#,python
2008-09-23T04:53:00.000
119,198
Is it good to switch from c# to python?
Depends on what you will use it for. If you're making enterprise Windows forms applications, I don't think switching to Python would be a good idea. Also, it is possible to still use Python on the .NET CLR with IronPython.
0.024995
1
2
53,804
120,454
2
Python allocates integers automatically based on the underlying system architecture. Unfortunately I have a huge dataset which needs to be fully loaded into memory. So, is there a way to force Python to use only 2 bytes for some integers (equivalent of C++ 'short')?
6
27
false
python,memory-management,short
2008-09-23T10:35:00.000
120,250
Short Integers in Python
Armin's suggestion of the array module is probably best. Two possible alternatives: You can create an extension module yourself that provides the data structure that you're after. If it's really just something like a collection of shorts, then that's pretty simple to do. You can cheat and manipulate bits, so that you're storing one number in the lower half of the Python int, and another one in the upper half. You'd write some utility functions to convert to/from these within your data structure. Ugly, but it can be made to work. It's also worth realising that a Python integer object is not 4 bytes - there is additional overhead. So if you have a really large number of shorts, then you can save more than two bytes per number by using a C short in some way (e.g. the array module). I had to keep a large set of integers in memory a while ago, and a dictionary with integer keys and values was too large (I had 1GB available for the data structure IIRC). I switched to using a IIBTree (from ZODB) and managed to fit it. (The ints in a IIBTree are real C ints, not Python integers, and I hacked up an automatic switch to a IOBTree when the number was larger than 32 bits).
0.099668
3
2
53,804
60,190,871
2
Python allocates integers automatically based on the underlying system architecture. Unfortunately I have a huge dataset which needs to be fully loaded into memory. So, is there a way to force Python to use only 2 bytes for some integers (equivalent of C++ 'short')?
6
27
false
python,memory-management,short
2008-09-23T10:35:00.000
120,250
Short Integers in Python
You can use NumyPy's int as np.int8 or np.int16.
0.099668
3
4
1,306,364
122,387
1
How do I find the location of my site-packages directory?
22
1,238
false
python,installation
2008-09-23T17:04:00.000
122,327
How do I find the location of my Python site-packages directory?
An additional note to the get_python_lib function mentioned already: on some platforms different directories are used for platform specific modules (eg: modules that require compilation). If you pass plat_specific=True to the function you get the site packages for platform specific packages.
1
13
-1
2,844,364
69,868,767
1
How do I copy a file in Python?
21
3,318
false
python,file,copy,filesystems,file-copying
2008-09-23T19:23:00.000
123,198
How to copy files?
shutil.copy(src, dst, *, follow_symlinks=True)
-1
-4
4
3,114
4,294,670
4
Coming from a Perl 5 background, what are the advantages of moving to Perl 6 or Python?
8
26
false
python,perl,raku
2008-09-23T23:50:00.000
124,604
I know Perl 5. What are the advantages of learning Perl 6, rather than moving to Python?
IMO python's regexing, esp. when you try to represent something like perl's /e operator as in s/whatever/somethingelse/e, becomes quite slow. So in doubt, you may need to stay with Perl5 :-)
0.099668
4
5
3,114
127,627
4
Coming from a Perl 5 background, what are the advantages of moving to Perl 6 or Python?
8
26
false
python,perl,raku
2008-09-23T23:50:00.000
124,604
I know Perl 5. What are the advantages of learning Perl 6, rather than moving to Python?
You have not said why you want to move away from Perl*. If my crystal ball is functioning today then it is because you do not fully know the language and so it frustrates you. Stick with Perl and study the language well. If you do then one day you will be a guru and know why your question is irrelevant. Enlightment comes to those to seek it. You called it "Perl5" but there is no such language. :P
0.099668
4
2
3,114
124,797
4
Coming from a Perl 5 background, what are the advantages of moving to Perl 6 or Python?
8
26
false
python,perl,raku
2008-09-23T23:50:00.000
124,604
I know Perl 5. What are the advantages of learning Perl 6, rather than moving to Python?
There is no advantage to be gained by switching from Perl to Python. There is also no advantage to be gained by switching from Python to Perl. They are both equally capable. Choose your tools based on what you know and the problem you are trying to solve rather than on some sort of notion that one is somehow inherently better than the other. The only real advantage is if you are switching from a language you don't know to a language you do know, in which case your productivity will likely go up.
1
25
2
3,114
124,804
4
Coming from a Perl 5 background, what are the advantages of moving to Perl 6 or Python?
8
26
false
python,perl,raku
2008-09-23T23:50:00.000
124,604
I know Perl 5. What are the advantages of learning Perl 6, rather than moving to Python?
In my opinion, Python's syntax is much cleaner, simpler, and consistent. You can define nested data structures the same everywhere, whether you plan to pass them to a function (or return them from one) or use them directly. I like Perl a lot, but as soon as I learned enough Python to "get" it, I never turned back. In my experience, random snippets of Python tend to be more readable than random snippets of Perl. The difference really comes down to the culture around each language, where Perl users often appreciate cleverness while Python users more often prefer clarity. That's not to say you can't have clear Perl or devious Python, but those are much less common. Both are fine languages and solve many of the same problems. I personally lean toward Python, if for no other reason in that it seems to be gaining momentum while Perl seems to be losing users to Python and Ruby. Note the abundance of weasel words in the above. Honestly, it's really going to come down to personal preference.
1
11
1
395
125,053
1
In Python, I want to make selected instance attributes of a class be readonly to code outside of the class. I want there to be no way outside code can alter the attribute, except indirectly by invoking methods on the instance. I want the syntax to be concise. What is the best way? (I give my current best answer below...)
6
8
false
python,attributes,readonly
2008-09-24T02:15:00.000
125,034
What is the easiest, most concise way to make selected attributes in an instance be readonly?
There is no real way to do this. There are ways to make it more 'difficult', but there's no concept of completely hidden, inaccessible class attributes. If the person using your class can't be trusted to follow the API docs, then that's their own problem. Protecting people from doing stupid stuff just means that they will do far more elaborate, complicated, and damaging stupid stuff to try to do whatever they shouldn't have been doing in the first place.
0.033321
1
2
64,780
125,235
1
for working with MS word files in python, there is python win32 extensions, which can be used in windows. How do I do the same in linux? Is there any library?
15
28
false
python,linux,ms-word
2008-09-24T03:15:00.000
125,222
extracting text from MS word files in python
I'm not sure if you're going to have much luck without using COM. The .doc format is ridiculously complex, and is often called a "memory dump" of Word at the time of saving! At Swati, that's in HTML, which is fine and dandy, but most word documents aren't so nice!
0.039979
3
7
481,640
125,759
1
I'm using Python, and would like to insert a string into a text file without deleting or copying the file. How can I do that?
8
209
false
python,file,text
2008-09-24T06:30:00.000
125,703
How to modify a text file?
Unfortunately there is no way to insert into the middle of a file without re-writing it. As previous posters have indicated, you can append to a file or overwrite part of it using seek but if you want to add stuff at the beginning or the middle, you'll have to rewrite it. This is an operating system thing, not a Python thing. It is the same in all languages. What I usually do is read from the file, make the modifications and write it out to a new file called myfile.txt.tmp or something like that. This is better than reading the whole file into memory because the file may be too large for that. Once the temporary file is completed, I rename it the same as the original file. This is a good, safe way to do it because if the file write crashes or aborts for any reason, you still have your untouched original file.
1
148
2
1,114
127,651
5
I'm a pretty inexperienced programmer (can make tk apps, text processing, sort of understand oop), but Python is so awesome that I would like to help the community. What's the best way for a beginner to contribute?
7
13
false
python
2008-09-24T14:20:00.000
127,454
Contributing to Python
Build something cool in Python and share it with others. Small values of cool are still cool. Not everyone gets to write epic, world-changing software. Every problem solved well using Python is a way of showing how cool Python is.
0.113791
4
0
1,114
127,787
5
I'm a pretty inexperienced programmer (can make tk apps, text processing, sort of understand oop), but Python is so awesome that I would like to help the community. What's the best way for a beginner to contribute?
7
13
false
python
2008-09-24T14:20:00.000
127,454
Contributing to Python
Start by contributing to a Python project that you use and enjoy. This can be as simple as answering questions on the mailing list or IRC channel, offering to help with documentation and test writing or fixing bugs.
0
0
1
1,114
127,501
5
I'm a pretty inexperienced programmer (can make tk apps, text processing, sort of understand oop), but Python is so awesome that I would like to help the community. What's the best way for a beginner to contribute?
7
13
false
python
2008-09-24T14:20:00.000
127,454
Contributing to Python
If you aren't up to actually working on the Python core, there are still many ways to contribute.. 2 that immediately come to mind is: work on documentation.. it can ALWAYS be improved. Take your favorite modules and check out the documentation and add where you can. Reporting descriptive bugs is very helpful to the development process.
0.028564
1
4
1,114
127,601
5
I'm a pretty inexperienced programmer (can make tk apps, text processing, sort of understand oop), but Python is so awesome that I would like to help the community. What's the best way for a beginner to contribute?
7
13
true
python
2008-09-24T14:20:00.000
127,454
Contributing to Python
Add to the docs. it is downright crappy Help out other users on the dev and user mailing lists. TEST PYTHON. bugs in programming languages are real bad. And I have seen someone discover atleast 1 bug in python Frequent the #python channel on irc.freenode.net
1.2
7
2
1,114
127,493
5
I'm a pretty inexperienced programmer (can make tk apps, text processing, sort of understand oop), but Python is so awesome that I would like to help the community. What's the best way for a beginner to contribute?
7
13
false
python
2008-09-24T14:20:00.000
127,454
Contributing to Python
I guess one way would be to help with documentation (translation, updating), until you are aware enough about the language. Also following the devs and users mail groups would give you a pretty good idea of what is being done and needs to be done by the community.
0.085505
3
0
350
134,329
1
Does anyone have some numbers on this? I am just looking for a percentage, a summary will be better. Standards compliance: How does the implementation stack up to the standard language specification? For those still unclear: I place emphasis on current. The IronPython link provided below has info that was last edited more than 2 years back.
4
4
false
ironpython,ironruby
2008-09-25T16:18:00.000
134,314
Current standard compliance level of IronPython & IronRuby
We don't actively track these kinds of numbers, but you could download them and run them against the respective test suites for the languages if you wanted to boil it down to a single numeric value.
0
0
2
213,342
135,074
4
Why or why not?
12
462
false
python,range,xrange
2008-09-25T18:24:00.000
135,041
Should you always favor xrange() over range()?
You should favour range() over xrange() only when you need an actual list. For instance, when you want to modify the list returned by range(), or when you wish to slice it. For iteration or even just normal indexing, xrange() will work fine (and usually much more efficiently). There is a point where range() is a bit faster than xrange() for very small lists, but depending on your hardware and various other details, the break-even can be at a result of length 1 or 2; not something to worry about. Prefer xrange().
1
42
2
213,342
135,070
4
Why or why not?
12
462
false
python,range,xrange
2008-09-25T18:24:00.000
135,041
Should you always favor xrange() over range()?
xrange() is more efficient because instead of generating a list of objects, it just generates one object at a time. Instead of 100 integers, and all of their overhead, and the list to put them in, you just have one integer at a time. Faster generation, better memory use, more efficient code. Unless I specifically need a list for something, I always favor xrange()
1
13
4
213,342
135,531
4
Why or why not?
12
462
false
python,range,xrange
2008-09-25T18:24:00.000
135,041
Should you always favor xrange() over range()?
Okay, everyone here as a different opinion as to the tradeoffs and advantages of xrange versus range. They're mostly correct, xrange is an iterator, and range fleshes out and creates an actual list. For the majority of cases, you won't really notice a difference between the two. (You can use map with range but not with xrange, but it uses up more memory.) What I think you rally want to hear, however, is that the preferred choice is xrange. Since range in Python 3 is an iterator, the code conversion tool 2to3 will correctly convert all uses of xrange to range, and will throw out an error or warning for uses of range. If you want to be sure to easily convert your code in the future, you'll use xrange only, and list(xrange) when you're sure that you want a list. I learned this during the CPython sprint at PyCon this year (2008) in Chicago.
0.033321
2
5
213,342
135,081
4
Why or why not?
12
462
false
python,range,xrange
2008-09-25T18:24:00.000
135,041
Should you always favor xrange() over range()?
Go with range for these reasons: 1) xrange will be going away in newer Python versions. This gives you easy future compatibility. 2) range will take on the efficiencies associated with xrange.
0.066568
4
0
344
48,569,865
2
I write tons of python scripts, and I find myself reusing lots code that I've written for other projects. My solution has been to make sure the code is separated into logical modules/packages (this one's a given). I then make them setuptools-aware and publish them on PyPI. This allows my other scripts to always have the most up-to-date code, I get a warm fuzzy feeling because I'm not repeating myself, and my development, in general, is made less complicated. I also feel good that there MAY be someone out there that finds my code handy for something they're working on, but it's mainly for selfish reasons :) To all the pythonistas, how do you handle this? Do you use PyPI or setuptools (easy_install)? or something else?
3
9
false
python,code-reuse
2008-09-25T21:18:00.000
136,207
How do you manage your custom modules?
I store it all offline in a logical directory structure, with commonly used modules grouped as utilities. This means it's easier to control which versions I publish, and manage. I also automate the build process to interpret the logical directory structure.
0
0
1
344
137,291
2
I write tons of python scripts, and I find myself reusing lots code that I've written for other projects. My solution has been to make sure the code is separated into logical modules/packages (this one's a given). I then make them setuptools-aware and publish them on PyPI. This allows my other scripts to always have the most up-to-date code, I get a warm fuzzy feeling because I'm not repeating myself, and my development, in general, is made less complicated. I also feel good that there MAY be someone out there that finds my code handy for something they're working on, but it's mainly for selfish reasons :) To all the pythonistas, how do you handle this? Do you use PyPI or setuptools (easy_install)? or something else?
3
9
false
python,code-reuse
2008-09-25T21:18:00.000
136,207
How do you manage your custom modules?
What kind of modules are we talking about here? If you're planning on distributing your projects to other python developers, setuptools is great. But it's usually not a very good way to distribute apps to end users. Your best bet in the latter case is to tailor your packaging to the platforms you're distributing it for. Sure, it's a pain, but it makes life for end users far easier. For example, in my Debian system, I usually don't use easy_install because it is a little bit more difficult to get eggs to work well with the package manager. In OS X and windows, you'd probably want to package everything up using py2app and py2exe respectively. This makes life for the end user better. After all, they shouldn't know or care what language your scripts are written in. They just need them to install.
0.066568
1
2
102,301
138,554
2
How feasible would it be to compile Python (possibly via an intermediate C representation) into machine code? Presumably it would need to link to a Python runtime library, and any parts of the Python standard library which were Python themselves would need to be compiled (and linked in) too. Also, you would need to bundle the Python interpreter if you wanted to do dynamic evaluation of expressions, but perhaps a subset of Python that didn't allow this would still be useful. Would it provide any speed and/or memory usage advantages? Presumably the startup time of the Python interpreter would be eliminated (although shared libraries would still need loading at startup).
10
147
false
python,c,linker,compilation
2008-09-26T09:51:00.000
138,521
Is it feasible to compile Python to machine code?
Jython has a compiler targeting JVM bytecode. The bytecode is fully dynamic, just like the Python language itself! Very cool. (Yes, as Greg Hewgill's answer alludes, the bytecode does use the Jython runtime, and so the Jython jar file must be distributed with your app.)
0.059928
3
2
102,301
138,605
2
How feasible would it be to compile Python (possibly via an intermediate C representation) into machine code? Presumably it would need to link to a Python runtime library, and any parts of the Python standard library which were Python themselves would need to be compiled (and linked in) too. Also, you would need to bundle the Python interpreter if you wanted to do dynamic evaluation of expressions, but perhaps a subset of Python that didn't allow this would still be useful. Would it provide any speed and/or memory usage advantages? Presumably the startup time of the Python interpreter would be eliminated (although shared libraries would still need loading at startup).
10
147
false
python,c,linker,compilation
2008-09-26T09:51:00.000
138,521
Is it feasible to compile Python to machine code?
The answer is "Yes, it is possible". You could take Python code and attempt to compile it into the equivalent C code using the CPython API. In fact, there used to be a Python2C project that did just that, but I haven't heard about it in many years (back in the Python 1.5 days is when I last saw it.) You could attempt to translate the Python code into native C as much as possible, and fall back to the CPython API when you need actual Python features. I've been toying with that idea myself the last month or two. It is, however, an awful lot of work, and an enormous amount of Python features are very hard to translate into C: nested functions, generators, anything but simple classes with simple methods, anything involving modifying module globals from outside the module, etc, etc.
0.039979
2
2
9,026
140,822
2
In Java you can do File.listFiles() and receive all of the files in a directory. You can then easily recurse through directory trees. Is there an analogous way to do this in Python?
9
10
false
java,python,file-traversal
2008-09-26T17:20:00.000
140,758
Looking for File Traversal Functions in Python that are Like Java's
Use os.path.walk if you want subdirectories as well. walk(top, func, arg) Directory tree walk with callback function. For each directory in the directory tree rooted at top (including top itself, but excluding '.' and '..'), call func(arg, dirname, fnames). dirname is the name of the directory, and fnames a list of the names of the files and subdirectories in dirname (excluding '.' and '..'). func may modify the fnames list in-place (e.g. via del or slice assignment), and walk will only recurse into the subdirectories whose names remain in fnames; this can be used to implement a filter, or to impose a specific order of visiting. No semantics are defined for, or required of, arg, beyond that arg is always passed to func. It can be used, e.g., to pass a filename pattern, or a mutable object designed to accumulate statistics. Passing None for arg is common.
0.044415
2
2
9,026
141,277
2
In Java you can do File.listFiles() and receive all of the files in a directory. You can then easily recurse through directory trees. Is there an analogous way to do this in Python?
9
10
false
java,python,file-traversal
2008-09-26T17:20:00.000
140,758
Looking for File Traversal Functions in Python that are Like Java's
I'd recommend against os.path.walk as it is being removed in Python 3.0. os.walk is simpler, anyway, or at least I find it simpler.
0.044415
2
5
177,508
15,035,172
2
The __debug__ variable is handy in part because it affects every module. If I want to create another variable that works the same way, how would I do it? The variable (let's be original and call it 'foo') doesn't have to be truly global, in the sense that if I change foo in one module, it is updated in others. I'd be fine if I could set foo before importing other modules and then they would see the same value for it.
12
127
false
python,module,global
2008-09-26T23:59:00.000
142,545
How to make a cross-module variable?
I believe that there are plenty of circumstances in which it does make sense and it simplifies programming to have some globals that are known across several (tightly coupled) modules. In this spirit, I would like to elaborate a bit on the idea of having a module of globals which is imported by those modules which need to reference them. When there is only one such module, I name it "g". In it, I assign default values for every variable I intend to treat as global. In each module that uses any of them, I do not use "from g import var", as this only results in a local variable which is initialized from g only at the time of the import. I make most references in the form g.var, and the "g." serves as a constant reminder that I am dealing with a variable that is potentially accessible to other modules. If the value of such a global variable is to be used frequently in some function in a module, then that function can make a local copy: var = g.var. However, it is important to realize that assignments to var are local, and global g.var cannot be updated without referencing g.var explicitly in an assignment. Note that you can also have multiple such globals modules shared by different subsets of your modules to keep things a little more tightly controlled. The reason I use short names for my globals modules is to avoid cluttering up the code too much with occurrences of them. With only a little experience, they become mnemonic enough with only 1 or 2 characters. It is still possible to make an assignment to, say, g.x when x was not already defined in g, and a different module can then access g.x. However, even though the interpreter permits it, this approach is not so transparent, and I do avoid it. There is still the possibility of accidentally creating a new variable in g as a result of a typo in the variable name for an assignment. Sometimes an examination of dir(g) is useful to discover any surprise names that may have arisen by such accident.
1
28
3
177,508
3,911,089
2
The __debug__ variable is handy in part because it affects every module. If I want to create another variable that works the same way, how would I do it? The variable (let's be original and call it 'foo') doesn't have to be truly global, in the sense that if I change foo in one module, it is updated in others. I'd be fine if I could set foo before importing other modules and then they would see the same value for it.
12
127
false
python,module,global
2008-09-26T23:59:00.000
142,545
How to make a cross-module variable?
You can already do this with module-level variables. Modules are the same no matter what module they're being imported from. So you can make the variable a module-level variable in whatever module it makes sense to put it in, and access it or assign to it from other modules. It would be better to call a function to set the variable's value, or to make it a property of some singleton object. That way if you end up needing to run some code when the variable's changed, you can do so without breaking your module's external interface. It's not usually a great way to do things — using globals seldom is — but I think this is the cleanest way to do it.
0.083141
5
3
62,846
143,643
1
I need a compact representation of an array of booleans, does Python have a builtin bitfield type or will I need to find an alternate solution?
12
54
false
python,bit-fields,bitarray
2008-09-27T02:47:00.000
142,812
Does Python have a bitfield type?
I use the binary bit-wise operators !, &, |, ^, >>, and <<. They work really well and are implemented directly in the underlying C, which is usually directly on the underlying hardware.
1
7
1
66,616
143,726
1
In PHP, a string enclosed in "double quotes" will be parsed for variables to replace whereas a string enclosed in 'single quotes' will not. In Python, does this also apply?
9
71
false
python,string,quotes,double-quotes
2008-09-27T14:39:00.000
143,714
Is there any difference between "string" and 'string' in Python?
There are 3 ways you can qoute strings in python: "string" 'string' """ string string """ they all produce the same result.
0.022219
1
2
1,684
145,195
3
I understand that IronPython is an implementation of Python on the .NET platform just like IronRuby is an implementation of Ruby and F# is more or less OCaml. What I can't seem to grasp is whether these languages perform closer to their "ancestors" or closer to something like C# in terms of speed. For example, is IronPython somehow "compiled" down to the same bytecode used by C# and, therefore, will run just as fast?
4
8
true
.net,performance,ironpython
2008-09-28T04:06:00.000
145,191
Dynamic .NET language performance?
IronPython and IronRuby are built on top of the DLR -- dynamic language runtime -- and are compiled to CIL (the bytecode used by .NET) on the fly. They're slower than C# but faaaaaaar faster than their non-.NET counterparts. There aren't any decent benchmarks out there, to my knowledge, but you'll see the difference.
1.2
9
3
1,684
145,300
3
I understand that IronPython is an implementation of Python on the .NET platform just like IronRuby is an implementation of Ruby and F# is more or less OCaml. What I can't seem to grasp is whether these languages perform closer to their "ancestors" or closer to something like C# in terms of speed. For example, is IronPython somehow "compiled" down to the same bytecode used by C# and, therefore, will run just as fast?
4
8
false
.net,performance,ironpython
2008-09-28T04:06:00.000
145,191
Dynamic .NET language performance?
IronPython is actually the fastest Python implementation out there. For some definition of "fastest", at least: the startup overhead of the CLR, for example, is huge compared to CPython. Also, the optimizing compiler IronPython has, really only makes sense, when code is executed multiple times. IronRuby has the potential to be as fast IronPython, since many of the interesting features that make IronPython fast, have been extracted into the Dynamic Language Runtime, on which both IronPython and IronRuby (and Managed JavaScript, Dynamic VB, IronScheme, VistaSmalltalk and others) are built. In general, the speed of a language implementation is pretty much independent of the actual language features, and more dependent on the number of engineering man-years that go into it. IOW: dynamic vs. static doesn't matter, money does. E.g., Common Lisp is a language that is even more dynamic than Ruby or Python, and yet there are Common Lisp compilers out there that can even give C a run for its money. Good Smalltalk implementations run as fast as Java (which is no surprise, since both major JVMs, Sun HotSpot and IBM J9, are actually just slightly modified Smalltalk VMs) or C++. In just the past 6 months, the major JavaScript implementations (Mozilla TraceMonkey, Apple SquirrelFish Extreme and the new kid on the block, Google V8) have made ginormous performance improvements, 10x and more, to bring JavaScript head-to-head with un-optimized C.
1
7
3
1,684
145,200
3
I understand that IronPython is an implementation of Python on the .NET platform just like IronRuby is an implementation of Ruby and F# is more or less OCaml. What I can't seem to grasp is whether these languages perform closer to their "ancestors" or closer to something like C# in terms of speed. For example, is IronPython somehow "compiled" down to the same bytecode used by C# and, therefore, will run just as fast?
4
8
false
.net,performance,ironpython
2008-09-28T04:06:00.000
145,191
Dynamic .NET language performance?
Currently IronRuby is pretty slow in most regards. It's definitely slower than MRI (Matz' Ruby Implementation) overall, though in some places they're faster. IronRuby does have the potential to be much faster, though I doubt they'll ever get near C# in terms of speed. In most cases it just doesn't matter. A database call will probably make up 90% of the overall duration of a web request, for example. I suspect the team will go for language-completeness rather than performance first. This will allow you to run IronRuby & run most ruby programs when 1.0 ships, then they can improve perf as they go. I suspect IronPython has a similar story.
0.049958
1
0
19,086
1,937,776
1
I need an algorithm that can compare two text files and highlight their difference and ( even better!) can compute their difference in a meaningful way (like two similar files should have a similarity score higher than two dissimilar files, with the word "similar" defined in the normal terms). It sounds easy to implement, but it's not. The implementation can be in c# or python. Thanks.
11
43
false
c#,python,diff
2008-09-28T10:12:00.000
145,607
Text difference algorithm
One method I've employed for a different functionality, to calculate how much data was new in a modified file, could perhaps work for you as well. I have a diff/patch implementation C# that allows me to take two files, presumably old and new version of the same file, and calculate the "difference", but not in the usual sense of the word. Basically I calculate a set of operations that I can perform on the old version to update it to have the same contents as the new version. To use this for the functionality initially described, to see how much data was new, I simple ran through the operations, and for every operation that copied from the old file verbatim, that had a 0-factor, and every operation that inserted new text (distributed as part of the patch, since it didn't occur in the old file) had a 1-factor. All characters was given this factory, which gave me basically a long list of 0's and 1's. All I then had to do was to tally up the 0's and 1's. In your case, with my implementation, a low number of 1's compared to 0's would mean the files are very similar. This implementation would also handle cases where the modified file had inserted copies from the old file out of order, or even duplicates (ie. you copy a part from the start of the file and paste it near the bottom), since they would both be copies of the same original part from the old file. I experimented with weighing copies, so that the first copy counted as 0, and subsequent copies of the same characters had progressively higher factors, in order to give a copy/paste operation some "new-factor", but I never finished it as the project was scrapped. If you're interested, my diff/patch code is available from my Subversion repository.
0
0
3
9,908
150,318
1
I understand that these methods are for pickling/unpickling and have no relation to the reduce built-in function, but what's the difference between the 2 and why do we need both?
2
19
false
python,pickle
2008-09-29T19:31:00.000
150,284
What is the difference between __reduce__ and __reduce_ex__?
__reduce_ex__ is what __reduce__ should have been but never became. __reduce_ex__ works like __reduce__ but the pickle protocol is passed.
1
9
6
1,190,669
152,592
2
How do I check if an object is of a given type, or if it inherits from a given type? How do I check if the object o is of type str?
14
1,624
false
python,types
2008-09-30T11:00:00.000
152,580
What's the canonical way to check for type in Python?
isinstance(o, str) will return True if o is an str or is of a type that inherits from str. type(o) is str will return True if and only if o is a str. It will return False if o is of a type that inherits from str.
1
70
3
1,190,669
153,032
2
How do I check if an object is of a given type, or if it inherits from a given type? How do I check if the object o is of type str?
14
1,624
false
python,types
2008-09-30T11:00:00.000
152,580
What's the canonical way to check for type in Python?
I think the cool thing about using a dynamic language like Python is you really shouldn't have to check something like that. I would just call the required methods on your object and catch an AttributeError. Later on this will allow you to call your methods with other (seemingly unrelated) objects to accomplish different tasks, such as mocking an object for testing. I've used this a lot when getting data off the web with urllib2.urlopen() which returns a file like object. This can in turn can be passed to almost any method that reads from a file, because it implements the same read() method as a real file. But I'm sure there is a time and place for using isinstance(), otherwise it probably wouldn't be there :)
1
7
4
134,803
154,566
2
Can I run the python interpreter without generating the compiled .pyc files?
10
286
false
python
2008-09-30T18:55:00.000
154,443
How to avoid .pyc files?
In 2.5, theres no way to suppress it, other than measures like not giving users write access to the directory. In python 2.6 and 3.0 however, there may be a setting in the sys module called "dont_write_bytecode" that can be set to suppress this. This can also be set by passing the "-B" option, or setting the environment variable "PYTHONDONTWRITEBYTECODE"
1
11
0
134,803
154,467
2
Can I run the python interpreter without generating the compiled .pyc files?
10
286
false
python
2008-09-30T18:55:00.000
154,443
How to avoid .pyc files?
As far as I know python will compile all modules you "import". However python will NOT compile a python script run using: "python script.py" (it will however compile any modules that the script imports). The real questions is why you don't want python to compile the modules? You could probably automate a way of cleaning these up if they are getting in the way.
0
0
1
2,322
158,622
2
I'm creating a networked server for a boggle-clone I wrote in python, which accepts users, solves the boards, and scores the player input. The dictionary file I'm using is 1.8MB (the ENABLE2K dictionary), and I need it to be available to several game solver classes. Right now, I have it so that each class iterates through the file line-by-line and generates a hash table(associative array), but the more solver classes I instantiate, the more memory it takes up. What I would like to do is import the dictionary file once and pass it to each solver instance as they need it. But what is the best way to do this? Should I import the dictionary in the global space, then access it in the solver class as globals()['dictionary']? Or should I import the dictionary then pass it as an argument to the class constructor? Is one of these better than the other? Is there a third option?
4
5
false
python,boggle
2008-10-01T16:37:00.000
158,546
Best way to store and use a large text-file in python
Even though it is essentially a singleton at this point, the usual arguments against globals apply. For a pythonic singleton-substitute, look up the "borg" object. That's really the only difference. Once the dictionary object is created, you are only binding new references as you pass it along unless if you explicitly perform a deep copy. It makes sense that it is centrally constructed once and only once so long as each solver instance does not require a private copy for modification.
0.049958
1
0
2,322
159,341
2
I'm creating a networked server for a boggle-clone I wrote in python, which accepts users, solves the boards, and scores the player input. The dictionary file I'm using is 1.8MB (the ENABLE2K dictionary), and I need it to be available to several game solver classes. Right now, I have it so that each class iterates through the file line-by-line and generates a hash table(associative array), but the more solver classes I instantiate, the more memory it takes up. What I would like to do is import the dictionary file once and pass it to each solver instance as they need it. But what is the best way to do this? Should I import the dictionary in the global space, then access it in the solver class as globals()['dictionary']? Or should I import the dictionary then pass it as an argument to the class constructor? Is one of these better than the other? Is there a third option?
4
5
false
python,boggle
2008-10-01T16:37:00.000
158,546
Best way to store and use a large text-file in python
Depending on what your dict contains, you may be interested in the 'shelve' or 'anydbm' modules. They give you dict-like interfaces (just strings as keys and items for 'anydbm', and strings as keys and any python object as item for 'shelve') but the data is actually in a DBM file (gdbm, ndbm, dbhash, bsddb, depending on what's available on the platform.) You probably still want to share the actual database between classes as you are asking for, but it would avoid the parsing-the-textfile step as well as the keeping-it-all-in-memory bit.
0
0
3
181
161,546
1
Just a curiosity: is there an already-coded way to convert a printed traceback back to the exception that generated it? :) Or to a sys.exc_info-like structure?
1
0
true
python
2008-10-02T08:35:00.000
161,367
Library for converting a traceback to its exception?
Converting a traceback to the exception object wouldn't be too hard, given common exception classes (parse the last line for the exception class and the arguments given to it at instantiation.) The traceback object (the third argument returned by sys.exc_info()) is an entirely different matter, though. The traceback object actually contains the chain of frame objects that constituted the stack at the time of the exception. Including local variables, global variables, et cetera. It is impossible to recreate that just from the displayed traceback. The best you could do would be to parse each 'File "X", line N, in Y:' line and create fake frame objects that are almost entirely empty. There would be very little value in it, as basically the only thing you would be able to do with it would be to print it. What are you trying to accomplish?
1.2
2
0
40,229
165,925
1
Suppose I have a class with some attributes. How is it best (in the Pythonic-OOP) sense to access these attributes ? Just like obj.attr ? Or perhaps write get accessors ? What are the accepted naming styles for such things ? Edit: Can you elaborate on the best-practices of naming attributes with a single or double leading underscore ? I see in most modules that a single underscore is used. If this question has already been asked (and I have a hunch it has, though searching didn't bring results), please point to it - and I will close this one.
7
23
false
python,oop,object,attributes
2008-10-03T06:18:00.000
165,883
Python object attributes - methodology for access
There is no real point of doing getter/setters in python, you can't protect stuff anyway and if you need to execute some extra code when getting/setting the property look at the property() builtin (python -c 'help(property)')
0
0
0
4,466
171,470
1
I have a Python web application consisting of several Python packages. What is the best way of building and deploying this to the servers? Currently I'm deploying the packages with Capistrano, installing the packages into a virtualenv with bash, and configuring the servers with puppet, but I would like to go for a more Python based solution. I've been looking a bit into zc.buildout, but it's not clear for me what I can/should use it for.
5
18
false
python,deployment
2008-10-03T10:57:00.000
166,334
How to build and deploy Python web applications
I use Mercurial as my SCM system, and also for deployment too. It's just a matter of cloning the repository from another one, and then a pull/update or a fetch will get it up to date. I use several instances of the repository - one on the development server, one (or more, depending upon circumstance) on my local machine, one on the production server, and one 'Master' repository that is available to the greater internet (although only by SSH). The only thing it doesn't do is automatically update the database if it is changed, but with incoming hooks I could probably do this too.
0
0
-1
249,871
168,430
1
What is the best way to get a list of all files in a directory, sorted by date [created | modified], using python, on a windows machine?
19
174
false
python,windows,directory
2008-10-03T19:10:00.000
168,409
How do you get a directory listing sorted by creation date in python?
Maybe you should use shell commands. In Unix/Linux, find piped with sort will probably be able to do what you want.
-1
-5
0
10,338
170,521
4
On a question of just performance, how does Python 3 compare to Python 2.x?
6
24
false
python,performance,python-3.x,python-2.x
2008-10-04T14:28:00.000
170,426
Performance: Python 3.x vs Python 2.x
I'd say any difference will be below trivial. For example, looping over a list will be the exact same. The idea behind Python 3 is to clean up the language syntax itself - remove ambigious stuff like except Exception1, Exception2, cleanup the standard modules (no urllib, urllib2, httplib etc). There really isn't much you can do to improve it's performance, although I imagine stuff like the garbage collection and memory management code will have had some tweaks, but it's not going to be a "wow, my database statistic generation code completes in half the time!" improvement - that's something you get by improving the code, rather than the language! Really, performance of the language is irrelevant - all interpreted languages basically function at the same speed. Why I find Python "faster" is all the built-in moudles, and the nice-to-write syntax - something that has been improved in Python3, so I guess in those terms, yes, python3's performance is better then python2.x..
1
7
2
10,338
170,805
4
On a question of just performance, how does Python 3 compare to Python 2.x?
6
24
false
python,performance,python-3.x,python-2.x
2008-10-04T14:28:00.000
170,426
Performance: Python 3.x vs Python 2.x
I think ultimately it is too early to make that kind of comparison just yet. Wait until it is out of beta before benchmarking it. The interpreter will probably be polished enormously before the release but overall i think for most uses the performance would be comparable and if you are running a really speed conscious app is python really the right language to be using?
0.132549
4
2
10,338
170,797
4
On a question of just performance, how does Python 3 compare to Python 2.x?
6
24
false
python,performance,python-3.x,python-2.x
2008-10-04T14:28:00.000
170,426
Performance: Python 3.x vs Python 2.x
Unless there are plans for a new VM of some kind (and I haven't heard of any such plans), there is all the reason to believe that in the long run the performance of Py3K will, at least asymptotically, equal that of 2.5 It may take a few months, but will eventually happen, as nothing in the new features of Py3k is inherently less performant. To conclude, I don't think there's place to worry about it. Neither to hope for a major improvement of some kind.
0.099668
3
3
10,338
170,568
4
On a question of just performance, how does Python 3 compare to Python 2.x?
6
24
false
python,performance,python-3.x,python-2.x
2008-10-04T14:28:00.000
170,426
Performance: Python 3.x vs Python 2.x
I don't if it faster now, but I have to expect that it eventually will be because that is where new performance work will happen and not all of that will be backported.
0
0
1
2,267
709,574
6
Does anyone have an idea how long it will take before "almost all" widely used Python libraries work with Python 3.0? I am planning to stay on 2.X for a while because I don't want to start porting stuff over and then find that some library I already rely on or a new library I might start using doesn't work yet with py3k. My understanding is that the py3k beta process was drawn out specifically to give library developers time to move their stuff over. Has this been happening? Examples of the sorts of libraries I am talking about would be PIL, numpy/ scipy, SQLAlchemy, BeautifulSoup, CherryPy...
7
13
false
python,python-3.x
2008-10-04T16:00:00.000
170,563
When will most libraries be Python 3 compliant?
I remember Adrian (BFDL of django) saying that Guido had given them a time frame of 5 years to port.
0.028564
1
1
2,267
172,026
6
Does anyone have an idea how long it will take before "almost all" widely used Python libraries work with Python 3.0? I am planning to stay on 2.X for a while because I don't want to start porting stuff over and then find that some library I already rely on or a new library I might start using doesn't work yet with py3k. My understanding is that the py3k beta process was drawn out specifically to give library developers time to move their stuff over. Has this been happening? Examples of the sorts of libraries I am talking about would be PIL, numpy/ scipy, SQLAlchemy, BeautifulSoup, CherryPy...
7
13
false
python,python-3.x
2008-10-04T16:00:00.000
170,563
When will most libraries be Python 3 compliant?
The general idea in the migration plan is to stay on 2.x and then slowly change the code to 3.x. You will have at least 1.5 years to worry about it in. Of course there's the chicken and egg problem though.
0.028564
1
1
2,267
170,680
6
Does anyone have an idea how long it will take before "almost all" widely used Python libraries work with Python 3.0? I am planning to stay on 2.X for a while because I don't want to start porting stuff over and then find that some library I already rely on or a new library I might start using doesn't work yet with py3k. My understanding is that the py3k beta process was drawn out specifically to give library developers time to move their stuff over. Has this been happening? Examples of the sorts of libraries I am talking about would be PIL, numpy/ scipy, SQLAlchemy, BeautifulSoup, CherryPy...
7
13
false
python,python-3.x
2008-10-04T16:00:00.000
170,563
When will most libraries be Python 3 compliant?
Some comments I saw in the CherryPy repository is that some of the changes to the sockets module are going to require an extensive reworking of the logic. I expect CherryPy will be slower than some of the other projects to get ported to 3.0.
0.028564
1
2
2,267
170,613
6
Does anyone have an idea how long it will take before "almost all" widely used Python libraries work with Python 3.0? I am planning to stay on 2.X for a while because I don't want to start porting stuff over and then find that some library I already rely on or a new library I might start using doesn't work yet with py3k. My understanding is that the py3k beta process was drawn out specifically to give library developers time to move their stuff over. Has this been happening? Examples of the sorts of libraries I am talking about would be PIL, numpy/ scipy, SQLAlchemy, BeautifulSoup, CherryPy...
7
13
false
python,python-3.x
2008-10-04T16:00:00.000
170,563
When will most libraries be Python 3 compliant?
The examples you have listed will probably be ported very quickly, as they are so widely used. I would be surprised if BeautifulSoup takes more than a month (In fact, I'm surprised it hasn't been ported already using the py3k betas), more complex things like numpy may take a big longer, especially because 2to3 only works on python sources, not C modules.. It's hard to generalise - some modules may never be ported, some may take days, others may take years. It could end up being a situation along the lines of "well I'm not porting my library to Python3, no one is using it!"/"Well I'm not porting my project to python3, no libraries have been updated yet!", but I hope not!
0.113791
4
0
2,267
710,561
6
Does anyone have an idea how long it will take before "almost all" widely used Python libraries work with Python 3.0? I am planning to stay on 2.X for a while because I don't want to start porting stuff over and then find that some library I already rely on or a new library I might start using doesn't work yet with py3k. My understanding is that the py3k beta process was drawn out specifically to give library developers time to move their stuff over. Has this been happening? Examples of the sorts of libraries I am talking about would be PIL, numpy/ scipy, SQLAlchemy, BeautifulSoup, CherryPy...
7
13
false
python,python-3.x
2008-10-04T16:00:00.000
170,563
When will most libraries be Python 3 compliant?
The libraries you mention will be ported once someone puts some serious time into porting them. In the specific case of NumPy/SciPy, a large part of the code is written as C extensions. There is no 2to3 tool for C extensions and so it will take a large amount of man hours to port the code over to the format that cPython3 C extensions need to use.
0
0
2
2,267
170,724
6
Does anyone have an idea how long it will take before "almost all" widely used Python libraries work with Python 3.0? I am planning to stay on 2.X for a while because I don't want to start porting stuff over and then find that some library I already rely on or a new library I might start using doesn't work yet with py3k. My understanding is that the py3k beta process was drawn out specifically to give library developers time to move their stuff over. Has this been happening? Examples of the sorts of libraries I am talking about would be PIL, numpy/ scipy, SQLAlchemy, BeautifulSoup, CherryPy...
7
13
false
python,python-3.x
2008-10-04T16:00:00.000
170,563
When will most libraries be Python 3 compliant?
Actually, the reply to your question depends on the actions of so many different people (all the maintainers of libraries outside the Python std lib), that I think that no-one can give you a reliable answer to your question. That said, you've had already some answers, and you will have more. We agree on one thing, though: as a rule of thumb, I typically suggest that important projects (related to work, mainly) should not be ported immediately to new development technologies (Python 3, .Net 3.x, etc) until such answers as yours have already been answered and many of the initial bugs have been solved. For pet or test projects, though, I'm all in for updates and experimentation.
0.113791
4
4
1,595
184,571
1
Many times I will use the same font scheme for static text in a wxPython application. Currently I am making a SetFont() call for each static text object but that seems like a lot of unnecessary work. However, the wxPython demo and wxPython In Action book don't discuss this. Is there a way to easily apply the same SetFont() method to all these text objects without making separate calls each time?
4
3
true
python,fonts,wxpython
2008-10-05T08:27:00.000
171,694
Applying a common font scheme to multiple objects in wxPython
You can do this by calling SetFont on the parent window (Frame, Dialog, etc) before adding any widgets. The child widgets will inherit the font.
1.2
5
3
6,801
172,007
2
When it comes to organizing python modules, my Mac OS X system is a mess. I've packages lying around everywhere on my hdd and no particular system to organize them. How do you keep everything manageable?
8
14
false
python,module
2008-10-05T10:09:00.000
171,785
How do you organize Python modules?
In addition to PEP8 and easy_install, you should check out virtualenv. Virtualenv allows you to have multiple different python library trees. At work, we use virtualenv with a bootstrapping environment to quickly set up a development/production environment where we are all in sync w.r.t library versions etc. We generally coordinate library upgrades.
0.124353
5
3
6,801
172,538
2
When it comes to organizing python modules, my Mac OS X system is a mess. I've packages lying around everywhere on my hdd and no particular system to organize them. How do you keep everything manageable?
8
14
false
python,module
2008-10-05T10:09:00.000
171,785
How do you organize Python modules?
There are several families of Python componentry. The stuff that comes with Python. This takes care of itself. The stuff that you got with easy_install. This, also, takes care of itself. The packages that you had to get some other way, either as TARballs or SVN checkouts. Create a Components folder. Put the downloads or the SVN's in there first. Every Single Time. Do installs from there. The packages that you wrote that are reusable. I have a Projects folder with each project in that folder. If the project is a highly reusable thing, it has a setup.py and I actually run the install as if I downloaded it. I don't have many of these, but a few. Some of them might become open source projects. The final applications you write. I have a folder in Projects with each of these top-level applications. These are usually big, rambling things (like Django sites) and don't have setup.py. Why? They're often pretty complex with only a few server installations to manage, and each of those server installations is unique. These generally rely on PYTHONPATH to identify their parts. Notice the common theme. Either they're Components you downloaded or they're Projects you're working on. Also, I keep this separate (to an extent) from the client. I have a master directory of Client folders, each of which has Projects and each project has Sales and Delivery. Not all projects have both sales and delivery.
0.124353
5
2
10,198
174,305
4
I'm sure this is a subject that's on most python developers' minds considering that Python 3 is coming out soon. Some questions to get us going in the right direction: Will you have a python 2 and python 3 version to be maintained concurrently or will you simply have a python 3 version once it's finished? Have you already started or plan on starting soon? Or do you plan on waiting until the final version comes out to get into full swing?
7
52
false
python,migration,python-3.x,python-2to3
2008-10-05T17:08:00.000
172,306
How are you planning on handling the migration to Python 3?
Some of my more complex 2.x code is going to stay at 2.5 or 2.6. I am moving onto 3.0 for all new development once some of the 3rd party libraries I use often have been updated for 3.
0
0
2
10,198
172,350
4
I'm sure this is a subject that's on most python developers' minds considering that Python 3 is coming out soon. Some questions to get us going in the right direction: Will you have a python 2 and python 3 version to be maintained concurrently or will you simply have a python 3 version once it's finished? Have you already started or plan on starting soon? Or do you plan on waiting until the final version comes out to get into full swing?
7
52
false
python,migration,python-3.x,python-2to3
2008-10-05T17:08:00.000
172,306
How are you planning on handling the migration to Python 3?
The main idea of 2.6 is to provide a migration path to 3.0. So you can use from __future__ import X slowly migrating one feature at a time until you get all of them nailed down and can move to 3.0. Many of the 3.0 features will flow into 2.6 as well, so you can make the language gap smaller gradually rather than having to migrate everything in one go. At work, we plan to upgrade from 2.5 to 2.6 first. Then we begin enabling 3.0 features slowly one module at a time. At some point a whole subpart of the system will probably be ready for 3.x. The only problem are libraries. If a library is never migrated, we are stuck with the old library. But I am pretty confident that we'll get a fine alternative in due time for that part.
0.141893
5