Datasets:
Question
stringlengths 15
29.1k
| A_Id
int64 518
76.6M
| AnswerCount
int64 1
64
| Tags
stringlengths 6
105
| Users Score
int64 -42
1.15k
| CreationDate
stringlengths 19
23
| Score
float64 -1
1.2
| Q_Score
int64 0
6.79k
| Title
stringlengths 11
150
| Q_Id
int64 337
75M
| ViewCount
int64 6
6.81M
| is_accepted
bool 2
classes | Answer
stringlengths 6
11.6k
| Available Count
int64 1
31
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
I am about to build a piece of a project that will need to construct and post an XML document to a web service and I'd like to do it in Python, as a means to expand my skills in it.
Unfortunately, whilst I know the XML model fairly well in .NET, I'm uncertain what the pros and cons are of the XML models in Python.
Anyone have experience doing XML processing in Python? Where would you suggest I start? The XML files I'll be building will be fairly simple. | 635 | 12 | python,xml | 6 | 2008-08-02 03:35:55.697 | 1 | 82 | XML Processing in Python | 337 | 9,979 | false | I write a SOAP server that receives XML requests and creates XML responses. (Unfortunately, it's not my project, so it's closed source, but that's another problem).
It turned out for me that creating (SOAP) XML documents is fairly simple if you have a data structure that "fits" the schema.
I keep the envelope since the response envelope is (almost) the same as the request envelope. Then, since my data structure is a (possibly nested) dictionary, I create a string that turns this dictionary into <key>value</key> items.
This is a task that recursion makes simple, and I end up with the right structure. This is all done in python code and is currently fast enough for production use.
You can also (relatively) easily build lists as well, although depending upon your client, you may hit problems unless you give length hints.
For me, this was much simpler, since a dictionary is a much easier way of working than some custom class. For the books, generating XML is much easier than parsing! | 6 |
I am about to build a piece of a project that will need to construct and post an XML document to a web service and I'd like to do it in Python, as a means to expand my skills in it.
Unfortunately, whilst I know the XML model fairly well in .NET, I'm uncertain what the pros and cons are of the XML models in Python.
Anyone have experience doing XML processing in Python? Where would you suggest I start? The XML files I'll be building will be fairly simple. | 69,772 | 12 | python,xml | 2 | 2008-08-02 03:35:55.697 | 0.033321 | 82 | XML Processing in Python | 337 | 9,979 | false | I assume that the .NET way of processing XML builds on some version of MSXML and in that case I assume that using, for example, minidom would make you feel somewhat at home. However, if it is simple processing you are doing, any library will probably do.
I also prefer working with ElementTree when dealing with XML in Python because it is a very neat library. | 6 |
I am about to build a piece of a project that will need to construct and post an XML document to a web service and I'd like to do it in Python, as a means to expand my skills in it.
Unfortunately, whilst I know the XML model fairly well in .NET, I'm uncertain what the pros and cons are of the XML models in Python.
Anyone have experience doing XML processing in Python? Where would you suggest I start? The XML files I'll be building will be fairly simple. | 202,259 | 12 | python,xml | 8 | 2008-08-02 03:35:55.697 | 1 | 82 | XML Processing in Python | 337 | 9,979 | false | It depends a bit on how complicated the document needs to be.
I've used minidom a lot for writing XML, but that's usually been just reading documents, making some simple transformations, and writing them back out. That worked well enough until I needed the ability to order element attributes (to satisfy an ancient application that doesn't parse XML properly). At that point I gave up and wrote the XML myself.
If you're only working on simple documents, then doing it yourself can be quicker and simpler than learning a framework. If you can conceivably write the XML by hand, then you can probably code it by hand as well (just remember to properly escape special characters, and use str.encode(codec, errors="xmlcharrefreplace")). Apart from these snafus, XML is regular enough that you don't need a special library to write it. If the document is too complicated to write by hand, then you should probably look into one of the frameworks already mentioned. At no point should you need to write a general XML writer. | 6 |
I am about to build a piece of a project that will need to construct and post an XML document to a web service and I'd like to do it in Python, as a means to expand my skills in it.
Unfortunately, whilst I know the XML model fairly well in .NET, I'm uncertain what the pros and cons are of the XML models in Python.
Anyone have experience doing XML processing in Python? Where would you suggest I start? The XML files I'll be building will be fairly simple. | 69,410 | 12 | python,xml | 8 | 2008-08-02 03:35:55.697 | 1 | 82 | XML Processing in Python | 337 | 9,979 | false | There are 3 major ways of dealing with XML, in general: dom, sax, and xpath. The dom model is good if you can afford to load your entire xml file into memory at once, and you don't mind dealing with data structures, and you are looking at much/most of the model. The sax model is great if you only care about a few tags, and/or you are dealing with big files and can process them sequentially. The xpath model is a little bit of each -- you can pick and choose paths to the data elements you need, but it requires more libraries to use.
If you want straightforward and packaged with Python, minidom is your answer, but it's pretty lame, and the documentation is "here's docs on dom, go figure it out". It's really annoying.
Personally, I like cElementTree, which is a faster (c-based) implementation of ElementTree, which is a dom-like model.
I've used sax systems, and in many ways they're more "pythonic" in their feel, but I usually end up creating state-based systems to handle them, and that way lies madness (and bugs).
I say go with minidom if you like research, or ElementTree if you want good code that works well. | 6 |
I am about to build a piece of a project that will need to construct and post an XML document to a web service and I'd like to do it in Python, as a means to expand my skills in it.
Unfortunately, whilst I know the XML model fairly well in .NET, I'm uncertain what the pros and cons are of the XML models in Python.
Anyone have experience doing XML processing in Python? Where would you suggest I start? The XML files I'll be building will be fairly simple. | 13,832,269 | 12 | python,xml | 3 | 2008-08-02 03:35:55.697 | 0.049958 | 82 | XML Processing in Python | 337 | 9,979 | false | I strongly recommend SAX - Simple API for XML - implementation in the Python libraries. They are fairly easy to setup and process large XML by even driven API, as discussed by previous posters here, and have low memory footprint unlike validating DOM style XML parsers. | 6 |
I am about to build a piece of a project that will need to construct and post an XML document to a web service and I'd like to do it in Python, as a means to expand my skills in it.
Unfortunately, whilst I know the XML model fairly well in .NET, I'm uncertain what the pros and cons are of the XML models in Python.
Anyone have experience doing XML processing in Python? Where would you suggest I start? The XML files I'll be building will be fairly simple. | 123,307 | 12 | python,xml | 8 | 2008-08-02 03:35:55.697 | 1 | 82 | XML Processing in Python | 337 | 9,979 | false | I've used ElementTree for several projects and recommend it.
It's pythonic, comes 'in the box' with Python 2.5, including the c version cElementTree (xml.etree.cElementTree) which is 20 times faster than the pure Python version, and is very easy to use.
lxml has some perfomance advantages, but they are uneven and you should check the benchmarks first for your use case.
As I understand it, ElementTree code can easily be ported to lxml. | 6 |
I am using the Photoshop's javascript API to find the fonts in a given PSD.
Given a font name returned by the API, I want to find the actual physical font file that font name corresponds to on the disc.
This is all happening in a python program running on OSX so I guess I'm looking for one of:
Some Photoshop javascript
A Python function
An OSX API that I can call from python | 518 | 4 | python,macos,fonts,photoshop | 6 | 2008-08-02 15:11:16.430 | 1 | 47 | How can I find the full path to a font from its display name on a Mac? | 469 | 4,225 | false | I haven't been able to find anything that does this directly. I think you'll have to iterate through the various font folders on the system: /System/Library/Fonts, /Library/Fonts, and there can probably be a user-level directory as well ~/Library/Fonts. | 2 |
I am using the Photoshop's javascript API to find the fonts in a given PSD.
Given a font name returned by the API, I want to find the actual physical font file that font name corresponds to on the disc.
This is all happening in a python program running on OSX so I guess I'm looking for one of:
Some Photoshop javascript
A Python function
An OSX API that I can call from python | 3,040 | 4 | python,macos,fonts,photoshop | 21 | 2008-08-02 15:11:16.430 | 1.2 | 47 | How can I find the full path to a font from its display name on a Mac? | 469 | 4,225 | true | Unfortunately the only API that isn't deprecated is located in the ApplicationServices framework, which doesn't have a bridge support file, and thus isn't available in the bridge. If you're wanting to use ctypes, you can use ATSFontGetFileReference after looking up the ATSFontRef.
Cocoa doesn't have any native support, at least as of 10.5, for getting the location of a font. | 2 |
What do I need to look at to see whether I'm on Windows or Unix, etc? | 48,244,490 | 26 | python,cross-platform,platform-specific,platform-agnostic | 2 | 2008-08-05 03:23:18.917 | 0.015383 | 838 | Python: What OS am I running on? | 1,854 | 422,064 | false | If you are running macOS X and run platform.system() you get darwin
because macOS X is built on Apple's Darwin OS. Darwin is the kernel of macOS X and is essentially macOS X without the GUI. | 1 |
In many places, (1,2,3) (a tuple) and [1,2,3] (a list) can be used interchangeably.
When should I use one or the other, and why? | 6,477,369 | 18 | python,list,tuples | 5 | 2008-08-05 07:18:55.853 | 0.055498 | 58 | Python: what is the difference between (1,2,3) and [1,2,3], and when should I use each? | 1,983 | 12,477 | false | [1, 2, 3] is a list in which one can add or delete items.
(1, 2, 3) is a tuple in which once defined, modification cannot be done. | 14 |
In many places, (1,2,3) (a tuple) and [1,2,3] (a list) can be used interchangeably.
When should I use one or the other, and why? | 1,987 | 18 | python,list,tuples | 23 | 2008-08-05 07:18:55.853 | 1 | 58 | Python: what is the difference between (1,2,3) and [1,2,3], and when should I use each? | 1,983 | 12,477 | false | The list [1,2,3] is dynamic and flexible but that flexibility comes at a speed cost.
The tuple (1,2,3) is fixed (immutable) and therefore faster. | 14 |
In many places, (1,2,3) (a tuple) and [1,2,3] (a list) can be used interchangeably.
When should I use one or the other, and why? | 54,570,759 | 18 | python,list,tuples | 0 | 2008-08-05 07:18:55.853 | 0 | 58 | Python: what is the difference between (1,2,3) and [1,2,3], and when should I use each? | 1,983 | 12,477 | false | (1,2,3)-tuple
[1,2,3]-list
lists are mutable on which various operations can be performed whereas tuples are immutable which cannot be extended.we cannot add,delete or update any element from a tuple once it is created. | 14 |
In many places, (1,2,3) (a tuple) and [1,2,3] (a list) can be used interchangeably.
When should I use one or the other, and why? | 35,496,153 | 18 | python,list,tuples | 0 | 2008-08-05 07:18:55.853 | 0 | 58 | Python: what is the difference between (1,2,3) and [1,2,3], and when should I use each? | 1,983 | 12,477 | false | (1,2,3) is a tuple while [1,2,3] is a list. A tuple is an immutable object while a list is mutable. | 14 |
In many places, (1,2,3) (a tuple) and [1,2,3] (a list) can be used interchangeably.
When should I use one or the other, and why? | 5,719 | 18 | python,list,tuples | 3 | 2008-08-05 07:18:55.853 | 0.033321 | 58 | Python: what is the difference between (1,2,3) and [1,2,3], and when should I use each? | 1,983 | 12,477 | false | As others have mentioned, Lists and tuples are both containers which can be used to store python objects. Lists are extensible and their contents can change by assignment, on the other hand tuples are immutable.
Also, lists cannot be used as keys in a dictionary whereas tuples can. | 14 |
In many places, (1,2,3) (a tuple) and [1,2,3] (a list) can be used interchangeably.
When should I use one or the other, and why? | 12,454 | 18 | python,list,tuples | 4 | 2008-08-05 07:18:55.853 | 0.044415 | 58 | Python: what is the difference between (1,2,3) and [1,2,3], and when should I use each? | 1,983 | 12,477 | false | Whenever I need to pass in a collection of items to a function, if I want the function to not change the values passed in - I use tuples.
Else if I want to have the function to alter the values, I use list.
Always if you are using external libraries and need to pass in a list of values to a function and are unsure about the integrity of the data, use a tuple. | 14 |
In many places, (1,2,3) (a tuple) and [1,2,3] (a list) can be used interchangeably.
When should I use one or the other, and why? | 49,586,164 | 18 | python,list,tuples | 2 | 2008-08-05 07:18:55.853 | 0.022219 | 58 | Python: what is the difference between (1,2,3) and [1,2,3], and when should I use each? | 1,983 | 12,477 | false | (1,2,3) and [1,2,3] can be used interchangeably in rare conditions.
So (1,2,3) is a tuple and is immutable. Any changes you wish to make need to overwrite the object.
[1,2,3] is a list and elements can be appended and removed.
List has more features than a tuple. | 14 |
In many places, (1,2,3) (a tuple) and [1,2,3] (a list) can be used interchangeably.
When should I use one or the other, and why? | 5,746 | 18 | python,list,tuples | 2 | 2008-08-05 07:18:55.853 | 0.022219 | 58 | Python: what is the difference between (1,2,3) and [1,2,3], and when should I use each? | 1,983 | 12,477 | false | If you can find a solution that works with tuples, use them, as it forces immutability which kind of drives you down a more functional path. You almost never regret going down the functional/immutable path. | 14 |
In many places, (1,2,3) (a tuple) and [1,2,3] (a list) can be used interchangeably.
When should I use one or the other, and why? | 44,083,156 | 18 | python,list,tuples | 3 | 2008-08-05 07:18:55.853 | 0.033321 | 58 | Python: what is the difference between (1,2,3) and [1,2,3], and when should I use each? | 1,983 | 12,477 | false | A tuple might represent a key in dictionary, because it's
immutable.
Use lists if you have a collection of data that doesn't
need random access. | 14 |
In many places, (1,2,3) (a tuple) and [1,2,3] (a list) can be used interchangeably.
When should I use one or the other, and why? | 62,503,886 | 18 | python,list,tuples | 0 | 2008-08-05 07:18:55.853 | 0 | 58 | Python: what is the difference between (1,2,3) and [1,2,3], and when should I use each? | 1,983 | 12,477 | false | a = (1,2,3) is a tuple which is immutable meaning you can't add anything into a
b = [1,2,3] is a list in python which is immutable meaning you can make changes into 'b' either delete or add numbers into it. | 14 |
In many places, (1,2,3) (a tuple) and [1,2,3] (a list) can be used interchangeably.
When should I use one or the other, and why? | 26,250,158 | 18 | python,list,tuples | 2 | 2008-08-05 07:18:55.853 | 0.022219 | 58 | Python: what is the difference between (1,2,3) and [1,2,3], and when should I use each? | 1,983 | 12,477 | false | [1,2,3] is a list.
(1,2,3) is a tuple and immutable. | 14 |
In many places, (1,2,3) (a tuple) and [1,2,3] (a list) can be used interchangeably.
When should I use one or the other, and why? | 38,062,967 | 18 | python,list,tuples | 0 | 2008-08-05 07:18:55.853 | 0 | 58 | Python: what is the difference between (1,2,3) and [1,2,3], and when should I use each? | 1,983 | 12,477 | false | (1,2,3) is a tuple and [1,2,3] is a list. You either of the two represent sequences of numbers but note that tuples are immutable and list are mutable Python objects. | 14 |
In many places, (1,2,3) (a tuple) and [1,2,3] (a list) can be used interchangeably.
When should I use one or the other, and why? | 63,479,906 | 18 | python,list,tuples | 0 | 2008-08-05 07:18:55.853 | 0 | 58 | Python: what is the difference between (1,2,3) and [1,2,3], and when should I use each? | 1,983 | 12,477 | false | In simple words, lists are mutable whereas tuples are not. Hence, if you want to modify the elements in your program i.e., adding, deleting or altering elements, go for a list. But, if you don't want tat to happen i.e., may be for setting sequence in for loop, etc. go for a tuple | 14 |
In many places, (1,2,3) (a tuple) and [1,2,3] (a list) can be used interchangeably.
When should I use one or the other, and why? | 69,499,270 | 18 | python,list,tuples | 0 | 2008-08-05 07:18:55.853 | 0 | 58 | Python: what is the difference between (1,2,3) and [1,2,3], and when should I use each? | 1,983 | 12,477 | false | (1,2,3) is immutable, so you can't add to it or change one of the items. In contrast, [1,2,3] is mutable, so you can add to it or change the items. | 14 |
Python works on multiple platforms and can be used for desktop and web applications, thus I conclude that there is some way to compile it into an executable for Mac, Windows and Linux.
The problem being I have no idea where to start or how to write a GUI with it, can anybody shed some light on this and point me in the right direction please? | 12,167 | 13 | python,user-interface,deployment,tkinter,release-management | 4 | 2008-08-05 22:26:00.797 | 0.061461 | 300 | Create a directly-executable cross-platform GUI app using Python | 2,933 | 199,251 | false | I'm not sure that this is the best way to do it, but when I'm deploying Ruby GUI apps (not Python, but has the same "problem" as far as .exe's are concerned) on Windows, I just write a short launcher in C# that calls on my main script. It compiles to an executable, and I then have an application executable. | 2 |
Python works on multiple platforms and can be used for desktop and web applications, thus I conclude that there is some way to compile it into an executable for Mac, Windows and Linux.
The problem being I have no idea where to start or how to write a GUI with it, can anybody shed some light on this and point me in the right direction please? | 2,980 | 13 | python,user-interface,deployment,tkinter,release-management | 6 | 2008-08-05 22:26:00.797 | 1 | 300 | Create a directly-executable cross-platform GUI app using Python | 2,933 | 199,251 | false | Since python is installed on nearly every non-Windows OS by default now, the only thing you really need to make sure of is that all of the non-standard libraries you use are installed.
Having said that, it is possible to build executables that include the python interpreter, and any libraries you use. This is likely to create a large executable, however.
MacOS X even includes support in the Xcode IDE for creating full standalone GUI apps. These can be run by any user running OS X. | 2 |
When asked to create system XYZ and you ask to do it in Python over PHP or Ruby, what are the main features you can mention when they require you to explain it? | 5,014 | 8 | php,python,ruby-on-rails,ruby | 3 | 2008-08-07 16:43:21.937 | 0.07486 | 14 | How to sell Python to a client/boss/person | 4,942 | 1,421 | false | I would consider that using python on a new project is completely dependent on what problem you are trying to solve with python. If you want someone to agree with you that you should use python, then show them how python's features apply specifically to that problem.
In the case of web development with python, talk about WSGI and other web libraries and frameworks you could use that would make your life easier. One note for python is that most of the frameworks for python web development can be plugged right into any current project. With ruby on rails, you're practically working in a DSL that anyone who uses your project will have to learn. If they know python, then they can figure out what you are doing with django, etc in a day.
I'm only talking about web development because it appears that's what you are going to be working on seeing ruby, python and PHP in the same list. The real message that's important is applying to whatever it is you like about python directly to some problem you are trying to solve. | 6 |
When asked to create system XYZ and you ask to do it in Python over PHP or Ruby, what are the main features you can mention when they require you to explain it? | 15,296 | 8 | php,python,ruby-on-rails,ruby | 5 | 2008-08-07 16:43:21.937 | 0.124353 | 14 | How to sell Python to a client/boss/person | 4,942 | 1,421 | false | It's one of the preferred languages over at Google - It's several years ahead of Ruby in terms of "maturity" (what ever that really means - but managers like that). Since it's prefered by Google you can also run it on the Google App Engine.
Mircosoft is also embracing Python, and will have a v2.0 of IronPython coming out shortly. They are working on a Ruby implementation as well, but the Python version is way ahead, and is actually "ready for primetime". That give you the possibility for easy integration with .NET code, as well as being able to write client side RIAs in Python when Silverlight 2 ships. | 6 |
When asked to create system XYZ and you ask to do it in Python over PHP or Ruby, what are the main features you can mention when they require you to explain it? | 4,978 | 8 | php,python,ruby-on-rails,ruby | 13 | 2008-08-07 16:43:21.937 | 1.2 | 14 | How to sell Python to a client/boss/person | 4,942 | 1,421 | true | This is one of those cases that really boil down to personal preference or situational details. If you're more comfortable and experienced with Python, then say so. Are they asking you to justify it because they're more comfortable with one of the other environments? After you're done, will the system be passed off to someone else for long-term maintenance?
If they ask you to use a technology or language that you're not as familiar with, then make sure they know up-front that it's going to take you longer. | 6 |
When asked to create system XYZ and you ask to do it in Python over PHP or Ruby, what are the main features you can mention when they require you to explain it? | 9,420,311 | 8 | php,python,ruby-on-rails,ruby | 1 | 2008-08-07 16:43:21.937 | 0.024995 | 14 | How to sell Python to a client/boss/person | 4,942 | 1,421 | false | Give them a snippet of code in each (no more than a page) that performs some cool function that they will like. (e.g show outliers in a data set).
Show them each page. One in PHP, Ruby and Python.
Ask them which they find easiest to understand/read.
Tell them thats why you want to use Python. It's easier to read if you've not written it, more manageable, less buggy and quicker to build features because it is the most elegant (pythonic) | 6 |
When asked to create system XYZ and you ask to do it in Python over PHP or Ruby, what are the main features you can mention when they require you to explain it? | 4,958 | 8 | php,python,ruby-on-rails,ruby | 3 | 2008-08-07 16:43:21.937 | 0.07486 | 14 | How to sell Python to a client/boss/person | 4,942 | 1,421 | false | Focus on the shorter time needed for development/prototype and possibly easier maintenance (none of this may apply against Ruby). | 6 |
When asked to create system XYZ and you ask to do it in Python over PHP or Ruby, what are the main features you can mention when they require you to explain it? | 15,291 | 8 | php,python,ruby-on-rails,ruby | 0 | 2008-08-07 16:43:21.937 | 0 | 14 | How to sell Python to a client/boss/person | 4,942 | 1,421 | false | I agree with mreggen. Tell them by working in Python you can get things done faster. Getting things done faster possibly means money saved by the client. In the least it means that you are working with a language you a more comfortable in, meaning faster development, debugging, and refactoring time. There will be less time spent looking up documentation on what function to use to find the length of a string, etc. | 6 |
I tried to follow a couple of googled up tutorials on setting up mod_python, but failed every time. Do you have a good, step-by step, rock-solid howto?
My dev box is OS X, production - Centos. | 14,791,003 | 4 | python,apache,apache2 | 0 | 2008-08-07 18:24:12.013 | 0 | 23 | How do you set up Python scripts to work in Apache 2.0? | 5,102 | 32,774 | false | The problem for me wasn't in Apache set up, but in understanding how mod_apache actually uses the .py files. Module-level statements (including those in a if __name__=='__main__' section) are not executed--I assumed that the stdout from running the script at the commandline would be what the server would output, but that's not how it works.
Instead, I wrote a module-level function called index(), and had it return as a string the HTML of the page. It's also possible to have other module-level functions (e.g., otherFunction()) that can be accessed as further segments in the URI (e.g., testScript/otherFunction for the file testScript.py.)
Obviously, this makes more sense than my original stdout conception. Better capability of actually using Python as a scripting language and not a humongous markup language. | 1 |
A researcher has created a small simulation in MATLAB and we want to make it accessible to others. My plan is to take the simulation, clean up a few things and turn it into a set of functions. Then I plan to compile it into a C library and use SWIG to create a Python wrapper. At that point, I should be able to call the simulation from a small Django app. At least I hope so.
Do I have the right plan? Has anyone else done something similar? Can you let me know if there are any serious pitfalls that I'm not aware of at the moment? | 1,659,332 | 4 | python,c,matlab | 5 | 2008-08-07 18:47:58.487 | 0.244919 | 14 | Does anyone have experience creating a shared library in MATLAB? | 5,136 | 2,313 | false | One thing to remember is that the Matlab compiler does not actually compile the Matlab code into native machine instructions. It simply wraps it into a standalone executable or a library with its own runtime engine that runs it. You would be able to run your code without Matlab installed, and you would be able to interface it with other languages, but it will still be interpreted Matlab code, so there would be no speedup. | 3 |
A researcher has created a small simulation in MATLAB and we want to make it accessible to others. My plan is to take the simulation, clean up a few things and turn it into a set of functions. Then I plan to compile it into a C library and use SWIG to create a Python wrapper. At that point, I should be able to call the simulation from a small Django app. At least I hope so.
Do I have the right plan? Has anyone else done something similar? Can you let me know if there are any serious pitfalls that I'm not aware of at the moment? | 138,534 | 4 | python,c,matlab | 2 | 2008-08-07 18:47:58.487 | 0.099668 | 14 | Does anyone have experience creating a shared library in MATLAB? | 5,136 | 2,313 | false | I'd also try ctypes first.
Use the Matlab compiler to compile the code into C.
Compile the C code into a DLL.
Use ctypes to load and call code from this DLL
The hardest step is probably 1, but if you already know Matlab and have used the Matlab compiler, you should not have serious problems with it. | 3 |
A researcher has created a small simulation in MATLAB and we want to make it accessible to others. My plan is to take the simulation, clean up a few things and turn it into a set of functions. Then I plan to compile it into a C library and use SWIG to create a Python wrapper. At that point, I should be able to call the simulation from a small Django app. At least I hope so.
Do I have the right plan? Has anyone else done something similar? Can you let me know if there are any serious pitfalls that I'm not aware of at the moment? | 5,302 | 4 | python,c,matlab | 3 | 2008-08-07 18:47:58.487 | 1.2 | 14 | Does anyone have experience creating a shared library in MATLAB? | 5,136 | 2,313 | true | I won't help much but I remember that I was able to wrap a MATLAB simulation into DLL and then call it from a Delphi app. It worked really well. | 3 |
What are the libraries that support XPath? Is there a full implementation? How is the library used? Where is its website? | 1,732,475 | 11 | python,xml,dom,xpath,python-2.x | 40 | 2008-08-12 11:28:36.900 | 1 | 245 | How to use XPath in Python? | 8,692 | 338,237 | false | Use LXML. LXML uses the full power of libxml2 and libxslt, but wraps them in more "Pythonic" bindings than the Python bindings that are native to those libraries. As such, it gets the full XPath 1.0 implementation. Native ElemenTree supports a limited subset of XPath, although it may be good enough for your needs. | 1 |
Is there a maintained package I can use to retrieve and set MP3 ID3 metadata using Python? | 31,373,513 | 16 | python,mp3,metadata | 1 | 2008-08-12 15:16:00.637 | 0.012499 | 142 | Accessing MP3 metadata with Python | 8,948 | 140,384 | false | After some initial research I thought songdetails might fit my use case, but it doesn't handle .m4b files. Mutagen does. Note that while some have (reasonably) taken issue with Mutagen's surfacing of format-native keys, that vary from format to format (TIT2 for mp3, title for ogg, \xa9nam for mp4, Title for WMA etc.), mutagen.File() has a (new?) easy=True parameter that provides EasyMP3/EasyID3 tags, which have a consistent, albeit limited, set of keys. I've only done limited testing so far, but the common keys, like album, artist, albumartist, genre, tracknumber, discnumber, etc. are all present and identical for .mb4 and .mp3 files when using easy=True, making it very convenient for my purposes. | 1 |
This is a difficult and open-ended question I know, but I thought I'd throw it to the floor and see if anyone had any interesting suggestions.
I have developed a code-generator that takes our python interface to our C++ code (generated via SWIG) and generates code needed to expose this as WebServices. When I developed this code I did it using TDD, but I've found my tests to be brittle as hell. Because each test essentially wanted to verify that for a given bit of input code (which happens to be a C++ header) I'd get a given bit of outputted code I wrote a small engine that reads test definitions from XML input files and generates test cases from these expectations.
The problem is I dread going in to modify the code at all. That and the fact that the unit tests themselves are a: complex, and b: brittle.
So I'm trying to think of alternative approaches to this problem, and it strikes me I'm perhaps tackling it the wrong way. Maybe I need to focus more on the outcome, IE: does the code I generate actually run and do what I want it to, rather than, does the code look the way I want it to.
Has anyone got any experiences of something similar to this they would care to share? | 11,128 | 8 | c++,python,unit-testing,code-generation,swig | 0 | 2008-08-14 13:59:21.533 | 0 | 29 | How should I unit test a code-generator? | 11,060 | 7,527 | false | Yes, results are the ONLY thing that matters. The real chore is writing a framework that allows your generated code to run independently... spend your time there. | 5 |
This is a difficult and open-ended question I know, but I thought I'd throw it to the floor and see if anyone had any interesting suggestions.
I have developed a code-generator that takes our python interface to our C++ code (generated via SWIG) and generates code needed to expose this as WebServices. When I developed this code I did it using TDD, but I've found my tests to be brittle as hell. Because each test essentially wanted to verify that for a given bit of input code (which happens to be a C++ header) I'd get a given bit of outputted code I wrote a small engine that reads test definitions from XML input files and generates test cases from these expectations.
The problem is I dread going in to modify the code at all. That and the fact that the unit tests themselves are a: complex, and b: brittle.
So I'm trying to think of alternative approaches to this problem, and it strikes me I'm perhaps tackling it the wrong way. Maybe I need to focus more on the outcome, IE: does the code I generate actually run and do what I want it to, rather than, does the code look the way I want it to.
Has anyone got any experiences of something similar to this they would care to share? | 3,331,503 | 8 | c++,python,unit-testing,code-generation,swig | 0 | 2008-08-14 13:59:21.533 | 0 | 29 | How should I unit test a code-generator? | 11,060 | 7,527 | false | My recommendation would be to figure out a set of known input-output results, such as some simpler cases that you already have in place, and unit test the code that is produced. It's entirely possible that as you change the generator that the exact string that is produced may be slightly different... but what you really care is whether it is interpreted in the same way. Thus, if you test the results as you would test that code if it were your feature, you will find out if it succeeds in the ways you want.
Basically, what you really want to know is whether your generator will produce what you expect without physically testing every possible combination (also: impossible). By ensuring that your generator is consistent in the ways you expect, you can feel better that the generator will succeed in ever-more-complex situations.
In this way, you can also build up a suite of regression tests (unit tests that need to keep working correctly). This will help you make sure that changes to your generator aren't breaking other forms of code. When you encounter a bug that your unit tests didn't catch, you may want to include it to prevent similar breakage. | 5 |
This is a difficult and open-ended question I know, but I thought I'd throw it to the floor and see if anyone had any interesting suggestions.
I have developed a code-generator that takes our python interface to our C++ code (generated via SWIG) and generates code needed to expose this as WebServices. When I developed this code I did it using TDD, but I've found my tests to be brittle as hell. Because each test essentially wanted to verify that for a given bit of input code (which happens to be a C++ header) I'd get a given bit of outputted code I wrote a small engine that reads test definitions from XML input files and generates test cases from these expectations.
The problem is I dread going in to modify the code at all. That and the fact that the unit tests themselves are a: complex, and b: brittle.
So I'm trying to think of alternative approaches to this problem, and it strikes me I'm perhaps tackling it the wrong way. Maybe I need to focus more on the outcome, IE: does the code I generate actually run and do what I want it to, rather than, does the code look the way I want it to.
Has anyone got any experiences of something similar to this they would care to share? | 11,074 | 8 | c++,python,unit-testing,code-generation,swig | 14 | 2008-08-14 13:59:21.533 | 1.2 | 29 | How should I unit test a code-generator? | 11,060 | 7,527 | true | I started writing up a summary of my experience with my own code generator, then went back and re-read your question and found you had already touched upon the same issues yourself, focus on the execution results instead of the code layout/look.
Problem is, this is hard to test, the generated code might not be suited to actually run in the environment of the unit test system, and how do you encode the expected results?
I've found that you need to break down the code generator into smaller pieces and unit test those. Unit testing a full code generator is more like integration testing than unit testing if you ask me. | 5 |
This is a difficult and open-ended question I know, but I thought I'd throw it to the floor and see if anyone had any interesting suggestions.
I have developed a code-generator that takes our python interface to our C++ code (generated via SWIG) and generates code needed to expose this as WebServices. When I developed this code I did it using TDD, but I've found my tests to be brittle as hell. Because each test essentially wanted to verify that for a given bit of input code (which happens to be a C++ header) I'd get a given bit of outputted code I wrote a small engine that reads test definitions from XML input files and generates test cases from these expectations.
The problem is I dread going in to modify the code at all. That and the fact that the unit tests themselves are a: complex, and b: brittle.
So I'm trying to think of alternative approaches to this problem, and it strikes me I'm perhaps tackling it the wrong way. Maybe I need to focus more on the outcome, IE: does the code I generate actually run and do what I want it to, rather than, does the code look the way I want it to.
Has anyone got any experiences of something similar to this they would care to share? | 11,235 | 8 | c++,python,unit-testing,code-generation,swig | 0 | 2008-08-14 13:59:21.533 | 0 | 29 | How should I unit test a code-generator? | 11,060 | 7,527 | false | If you are running on *nux you might consider dumping the unittest framework in favor of a bash script or makefile. on windows you might consider building a shell app/function that runs the generator and then uses the code (as another process) and unittest that.
A third option would be to generate the code and then build an app from it that includes nothing but a unittest. Again you would need a shell script or whatnot to run this for each input. As to how to encode the expected behavior, it occurs to me that it could be done in much the same way as you would for the C++ code just using the generated interface rather than the C++ one. | 5 |
This is a difficult and open-ended question I know, but I thought I'd throw it to the floor and see if anyone had any interesting suggestions.
I have developed a code-generator that takes our python interface to our C++ code (generated via SWIG) and generates code needed to expose this as WebServices. When I developed this code I did it using TDD, but I've found my tests to be brittle as hell. Because each test essentially wanted to verify that for a given bit of input code (which happens to be a C++ header) I'd get a given bit of outputted code I wrote a small engine that reads test definitions from XML input files and generates test cases from these expectations.
The problem is I dread going in to modify the code at all. That and the fact that the unit tests themselves are a: complex, and b: brittle.
So I'm trying to think of alternative approaches to this problem, and it strikes me I'm perhaps tackling it the wrong way. Maybe I need to focus more on the outcome, IE: does the code I generate actually run and do what I want it to, rather than, does the code look the way I want it to.
Has anyone got any experiences of something similar to this they would care to share? | 11,443 | 8 | c++,python,unit-testing,code-generation,swig | 5 | 2008-08-14 13:59:21.533 | 0.124353 | 29 | How should I unit test a code-generator? | 11,060 | 7,527 | false | Recall that "unit testing" is only one kind of testing. You should be able to unit test the internal pieces of your code generator. What you're really looking at here is system level testing (a.k.a. regression testing). It's not just semantics... there are different mindsets, approaches, expectations, etc. It's certainly more work, but you probably need to bite the bullet and set up an end-to-end regression test suite: fixed C++ files -> SWIG interfaces -> python modules -> known output. You really want to check the known input (fixed C++ code) against expected output (what comes out of the final Python program). Checking the code generator results directly would be like diffing object files... | 5 |
Has anyone built a website with IronPython and ASP.NET. What were your experiences and is the combination ready for prime-time? | 21,149 | 3 | asp.net,ironpython | 0 | 2008-08-15 20:17:49.450 | 0 | 7 | IronPython and ASP.NET | 12,692 | 634 | false | Keep a look out for ASP.NET MVC
The IronRuby guys have got some internal builds of MVC to work with IronRuby, and IronPython 2 and IronRuby have a lot of code in common with the DLR.
I'm not sure if they'll support IronPython/IronRuby when MVC is released, but it's definitely worth keeping your eye on anyway - The old ASP.NET forms-based development model is old, busted, and the sooner it goes away the better. | 1 |
I've been reading a lot about closures and I think I understand them, but without clouding the picture for myself and others, I am hoping someone can explain closures as succinctly and clearly as possible. I'm looking for a simple explanation that might help me understand where and why I would want to use them. | 94,543 | 13 | python,functional-programming,closures | -2 | 2008-08-17 19:14:30.747 | -0.03076 | 95 | Can you explain closures (as they relate to Python)? | 13,857 | 15,413 | false | The best explanation I ever saw of a closure was to explain the mechanism. It went something like this:
Imagine your program stack as a degenerate tree where each node has only one child and the single leaf node is the context of your currently executing procedure.
Now relax the constraint that each node can have only one child.
If you do this, you can have a construct ('yield') that can return from a procedure without discarding the local context (i.e. it doesn't pop it off the stack when you return). The next time the procedure is invoked, the invocation picks up the old stack (tree) frame and continues executing where it left off. | 2 |
I've been reading a lot about closures and I think I understand them, but without clouding the picture for myself and others, I am hoping someone can explain closures as succinctly and clearly as possible. I'm looking for a simple explanation that might help me understand where and why I would want to use them. | 473,491 | 13 | python,functional-programming,closures | 3 | 2008-08-17 19:14:30.747 | 0.046121 | 95 | Can you explain closures (as they relate to Python)? | 13,857 | 15,413 | false | Here's a typical use case for closures - callbacks for GUI elements (this would be an alternative to subclassing the button class). For example, you can construct a function that will be called in response to a button press, and "close" over the relevant variables in the parent scope that are necessary for processing the click. This way you can wire up pretty complicated interfaces from the same initialization function, building all the dependencies into the closure. | 2 |
I have over a million text files compressed into 40 zip files. I also have a list of about 500 model names of phones. I want to find out the number of times a particular model was mentioned in the text files.
Is there any python module which can do a regex match on the files without unzipping it. Is there a simple way to solve this problem without unzipping? | 14,304 | 4 | python,regex,zip,text-processing | 0 | 2008-08-18 07:41:09.010 | 0 | 7 | Is there a python module for regex matching in zip files | 14,281 | 2,774 | false | You could loop through the zip files, reading individual files using the zipfile module and running your regex on those, eliminating to unzip all the files at once.
I'm fairly certain that you can't run a regex over the zipped data, at least not meaningfully. | 2 |
I have over a million text files compressed into 40 zip files. I also have a list of about 500 model names of phones. I want to find out the number of times a particular model was mentioned in the text files.
Is there any python module which can do a regex match on the files without unzipping it. Is there a simple way to solve this problem without unzipping? | 41,822 | 4 | python,regex,zip,text-processing | 0 | 2008-08-18 07:41:09.010 | 0 | 7 | Is there a python module for regex matching in zip files | 14,281 | 2,774 | false | Isn't it (at least theoretically) possible, to read in the ZIP's Huffman coding and then translate the regexp into the Huffman code? Might this be more efficient than first de-compressing the data, then running the regexp?
(Note: I know it wouldn't be quite that simple: you'd also have to deal with other aspects of the ZIP coding—file layout, block structures, back-references—but one imagines this could be fairly lightweight.)
EDIT: Also note that it's probably much more sensible to just use the zipfile solution. | 2 |
The company I used to work with has two developers working fulltime, and a handful of freelancers. They're in the process of hiring a new lead developer to try to bring order and management to the development.
But, currently, one of the developers has seen the light of Django (the company has only developed in PHP to date) while the other developer is concerned that introducing a new language (Python) is a bad idea right now.
How should they approach introducing this new technology? Obviously with only one of the developers actually knowing Python, there will be no redundancy when that dev is away or leaves the company.
Should they bother to introduce Python, or should they look for PHP-only solutions until such a time when the team actually have more than one Pythonion? Without a team leader, the decisions are having to fall to them. | 19,668 | 8 | php,python | 4 | 2008-08-21 11:48:03.000 | 0.099668 | 6 | Introducing Python | 19,654 | 651 | false | If the mandate of the new lead is to put the house in order, the current situation should likely be simplified as much as possible prior. If I had to bring things to order, I wouldn't want to have to manage an ongoing language conversion project on top of everything else, or at least I'd like some choice when initiating the project. When making your recommendation, did you think about the additional managerial complexity that coming into the middle of a conversion would entail? | 8 |
The company I used to work with has two developers working fulltime, and a handful of freelancers. They're in the process of hiring a new lead developer to try to bring order and management to the development.
But, currently, one of the developers has seen the light of Django (the company has only developed in PHP to date) while the other developer is concerned that introducing a new language (Python) is a bad idea right now.
How should they approach introducing this new technology? Obviously with only one of the developers actually knowing Python, there will be no redundancy when that dev is away or leaves the company.
Should they bother to introduce Python, or should they look for PHP-only solutions until such a time when the team actually have more than one Pythonion? Without a team leader, the decisions are having to fall to them. | 19,665 | 8 | php,python | 0 | 2008-08-21 11:48:03.000 | 0 | 6 | Introducing Python | 19,654 | 651 | false | Well, python is a high level language.. its not hard to learn and if the guys already have programming knowledge it should be much easier to learn.. i like django.. i think it should be a nice try to use django .. | 8 |
The company I used to work with has two developers working fulltime, and a handful of freelancers. They're in the process of hiring a new lead developer to try to bring order and management to the development.
But, currently, one of the developers has seen the light of Django (the company has only developed in PHP to date) while the other developer is concerned that introducing a new language (Python) is a bad idea right now.
How should they approach introducing this new technology? Obviously with only one of the developers actually knowing Python, there will be no redundancy when that dev is away or leaves the company.
Should they bother to introduce Python, or should they look for PHP-only solutions until such a time when the team actually have more than one Pythonion? Without a team leader, the decisions are having to fall to them. | 19,715 | 8 | php,python | 14 | 2008-08-21 11:48:03.000 | 1.2 | 6 | Introducing Python | 19,654 | 651 | true | I recently introduced Python to my company, which does consulting work for the Post Office. I did this by waiting until there was a project for which I would be the only programmer, then getting permission to do this new project in Python. I then did another small project in Python with similarly impressive results. In addition, I used Python for all of my small throwaway assignments ("can you parse the stats in these files into a CSV file organized by date and site?", etc) and had a quick turnaround time on all of them.
I also evangelized Python a bit; I went out of my way to NOT be obnoxious about it, but I'd occasionally describe why I liked it so much, talked about the personal projects I use it for in my free time and why it's awesome for me, etc.
Eventually we started another project and I convinced everyone to use Python for it. I took care to point everyone to a lot of documentation, including the specific webpages relating to what they were working on, and every time they had a question, I'd explain how to do things properly by explaining the Pythonic approach to things, etc.
This has worked really well. However, this might be somewhat different than what you're describing. In my case I started with moderately small projects and Python is only being used for new projects. Also, none of my co-workers were really Perl or PHP gurus; they all knew those languages and had been using them for awhile, but it didn't take much effort for them to become more productive in Python than they'd been before.
So if you're talking about new projects with people who currently use PHP but aren't super-experts and don't love that language, then I think switching to Python is a no-brainer. However, if you're talking about working with a large existing PHP code base with a lot of very experienced PHP programmers who are happy with their current setup, then switching languages is probably not a good idea. You're probably somewhere in between, so you'll have to weigh the tradeoffs; hopefully my answer will help you do that. | 8 |
The company I used to work with has two developers working fulltime, and a handful of freelancers. They're in the process of hiring a new lead developer to try to bring order and management to the development.
But, currently, one of the developers has seen the light of Django (the company has only developed in PHP to date) while the other developer is concerned that introducing a new language (Python) is a bad idea right now.
How should they approach introducing this new technology? Obviously with only one of the developers actually knowing Python, there will be no redundancy when that dev is away or leaves the company.
Should they bother to introduce Python, or should they look for PHP-only solutions until such a time when the team actually have more than one Pythonion? Without a team leader, the decisions are having to fall to them. | 19,943 | 8 | php,python | 0 | 2008-08-21 11:48:03.000 | 0 | 6 | Introducing Python | 19,654 | 651 | false | I love Python and Django, and use both to develop the our core webapps.
That said, it's hard to make a business case for switching at this point. Specifically:
Any new platform is risky compared to staying with the tried and true
You'll have the developer fragmentation you mentioned
It's far easier to find PHP programmers than python programmers
Moreover, as other posters have mention, if the issue is more with spaghetti code than PHP itself, there are plenty of nice PHP frameworks that could be used to refactor the code.
That said, if this developer is excited about python, stopping them outright is probably demoralizing. My suggestion would be to encourage them to develop in python, but not the mission critical parts of the app. Instead they could write some utility scripts, some small internal application that needs doing, etc.
In conclusion: I don't recommend switching from PHP, but I do recommend accommodating the developer's interest in some way at work. | 8 |
The company I used to work with has two developers working fulltime, and a handful of freelancers. They're in the process of hiring a new lead developer to try to bring order and management to the development.
But, currently, one of the developers has seen the light of Django (the company has only developed in PHP to date) while the other developer is concerned that introducing a new language (Python) is a bad idea right now.
How should they approach introducing this new technology? Obviously with only one of the developers actually knowing Python, there will be no redundancy when that dev is away or leaves the company.
Should they bother to introduce Python, or should they look for PHP-only solutions until such a time when the team actually have more than one Pythonion? Without a team leader, the decisions are having to fall to them. | 19,968 | 8 | php,python | 1 | 2008-08-21 11:48:03.000 | 0.024995 | 6 | Introducing Python | 19,654 | 651 | false | It's really all about schedules. To me the break should be with a specific project. If you decide your direction is Django then start new projects with that. Before you start a new project with a new language/framework, either make sure that you have scheduled time to get up to speed in this new direction, or get up to speed before using on new projects.
I would avoid going with a tool of the month. Make sure you want it to be your direction and commit some time/resources to learning enough to make a good decision. | 8 |
The company I used to work with has two developers working fulltime, and a handful of freelancers. They're in the process of hiring a new lead developer to try to bring order and management to the development.
But, currently, one of the developers has seen the light of Django (the company has only developed in PHP to date) while the other developer is concerned that introducing a new language (Python) is a bad idea right now.
How should they approach introducing this new technology? Obviously with only one of the developers actually knowing Python, there will be no redundancy when that dev is away or leaves the company.
Should they bother to introduce Python, or should they look for PHP-only solutions until such a time when the team actually have more than one Pythonion? Without a team leader, the decisions are having to fall to them. | 19,685 | 8 | php,python | 0 | 2008-08-21 11:48:03.000 | 0 | 6 | Introducing Python | 19,654 | 651 | false | I don't think it's a matter of a programming language as such.
What is the proficiency level of PHP in the team you're talking about? Are they doing spaghetti code or using some structured framework like Zend? If this is the first case then I absolutely understand the guy's interest in Python and Django. It this is the latter, it's just a hype. | 8 |
The company I used to work with has two developers working fulltime, and a handful of freelancers. They're in the process of hiring a new lead developer to try to bring order and management to the development.
But, currently, one of the developers has seen the light of Django (the company has only developed in PHP to date) while the other developer is concerned that introducing a new language (Python) is a bad idea right now.
How should they approach introducing this new technology? Obviously with only one of the developers actually knowing Python, there will be no redundancy when that dev is away or leaves the company.
Should they bother to introduce Python, or should they look for PHP-only solutions until such a time when the team actually have more than one Pythonion? Without a team leader, the decisions are having to fall to them. | 19,692 | 8 | php,python | 2 | 2008-08-21 11:48:03.000 | 0.049958 | 6 | Introducing Python | 19,654 | 651 | false | @darkdog:
Using a new language in production code is about more than easy syntax and high-level capability. You want to be familiar with core APIs and feel like you can fix something through logic instead of having to comb through the documentation.
I'm not saying transitioning to Python would be a bad idea for this company, but I'm with John--keep things simple during the transition. The new lead will appreciate having a say in such decisions.
If you'd really, really, really like to introduce Python, consider writing some extensions or utilities in straight-up Python or in the framework. You won't be upsetting your core initiatives, so it will be a low/no-risk opportunity to prove the merits of a switch. | 8 |
The company I used to work with has two developers working fulltime, and a handful of freelancers. They're in the process of hiring a new lead developer to try to bring order and management to the development.
But, currently, one of the developers has seen the light of Django (the company has only developed in PHP to date) while the other developer is concerned that introducing a new language (Python) is a bad idea right now.
How should they approach introducing this new technology? Obviously with only one of the developers actually knowing Python, there will be no redundancy when that dev is away or leaves the company.
Should they bother to introduce Python, or should they look for PHP-only solutions until such a time when the team actually have more than one Pythonion? Without a team leader, the decisions are having to fall to them. | 19,700 | 8 | php,python | 1 | 2008-08-21 11:48:03.000 | 0.024995 | 6 | Introducing Python | 19,654 | 651 | false | I think the language itself is not an issue here, as python is really nice high level language with good and easy to find, thorough documentation.
From what I've seen, the Django framework is also a great tooklit for web development, giving much the same developer performance boost Rails is touted to give.
The real issue is at the maintenance and management level.
How will this move fragment the maintenance between PHP and Python code. Is there a need to migrate existing code from one platform to another? What problems will adopting Python and Django solve that you have in your current development workflow and frameworks, etc. | 8 |
If I call os.stat() on a broken symlink, python throws an OSError exception. This makes it useful for finding them. However, there are a few other reasons that os.stat() might throw a similar exception. Is there a more precise way of detecting broken symlinks with Python under Linux? | 20,843 | 8 | python,linux,symlink | 4 | 2008-08-21 19:00:52.053 | 0.099668 | 30 | Find broken symlinks with Python | 20,794 | 25,846 | false | Can I mention testing for hardlinks without python? /bin/test has the FILE1 -ef FILE2 condition that is true when files share an inode.
Therefore, something like find . -type f -exec test \{} -ef /path/to/file \; -print works for hard link testing to a specific file.
Which brings me to reading man test and the mentions of -L and -h which both work on one file and return true if that file is a symbolic link, however that doesn't tell you if the target is missing.
I did find that head -0 FILE1 would return an exit code of 0 if the file can be opened and a 1 if it cannot, which in the case of a symbolic link to a regular file works as a test for whether it's target can be read. | 1 |
Python uses the reference count method to handle object life time. So an object that has no more use will be immediately destroyed.
But, in Java, the GC(garbage collector) destroys objects which are no longer used at a specific time.
Why does Java choose this strategy and what is the benefit from this?
Is this better than the Python approach? | 46,780 | 9 | java,python,garbage-collection | 4 | 2008-08-22 07:35:26.703 | 0.088656 | 65 | Why Java and Python garbage collection methods are different? | 21,934 | 20,044 | false | Reference counting is particularly difficult to do efficiently in a multi-threaded environment. I don't know how you'd even start to do it without getting into hardware assisted transactions or similar (currently) unusual atomic instructions.
Reference counting is easy to implement. JVMs have had a lot of money sunk into competing implementations, so it shouldn't be surprising that they implement very good solutions to very difficult problems. However, it's becoming increasingly easy to target your favourite language at the JVM. | 4 |
Python uses the reference count method to handle object life time. So an object that has no more use will be immediately destroyed.
But, in Java, the GC(garbage collector) destroys objects which are no longer used at a specific time.
Why does Java choose this strategy and what is the benefit from this?
Is this better than the Python approach? | 21,964 | 9 | java,python,garbage-collection | 54 | 2008-08-22 07:35:26.703 | 1.2 | 65 | Why Java and Python garbage collection methods are different? | 21,934 | 20,044 | true | There are drawbacks of using reference counting. One of the most mentioned is circular references: Suppose A references B, B references C and C references B. If A were to drop its reference to B, both B and C will still have a reference count of 1 and won't be deleted with traditional reference counting. CPython (reference counting is not part of python itself, but part of the C implementation thereof) catches circular references with a separate garbage collection routine that it runs periodically...
Another drawback: Reference counting can make execution slower. Each time an object is referenced and dereferenced, the interpreter/VM must check to see if the count has gone down to 0 (and then deallocate if it did). Garbage Collection does not need to do this.
Also, Garbage Collection can be done in a separate thread (though it can be a bit tricky). On machines with lots of RAM and for processes that use memory only slowly, you might not want to be doing GC at all! Reference counting would be a bit of a drawback there in terms of performance... | 4 |
Python uses the reference count method to handle object life time. So an object that has no more use will be immediately destroyed.
But, in Java, the GC(garbage collector) destroys objects which are no longer used at a specific time.
Why does Java choose this strategy and what is the benefit from this?
Is this better than the Python approach? | 74,327 | 9 | java,python,garbage-collection | 6 | 2008-08-22 07:35:26.703 | 1 | 65 | Why Java and Python garbage collection methods are different? | 21,934 | 20,044 | false | Garbage collection is faster (more time efficient) than reference counting, if you have enough memory. For example, a copying gc traverses the "live" objects and copies them to a new space, and can reclaim all the "dead" objects in one step by marking a whole memory region. This is very efficient, if you have enough memory. Generational collections use the knowledge that "most objects die young"; often only a few percent of objects have to be copied.
[This is also the reason why gc can be faster than malloc/free]
Reference counting is much more space efficient than garbage collection, since it reclaims memory the very moment it gets unreachable. This is nice when you want to attach finalizers to objects (e.g. to close a file once the File object gets unreachable). A reference counting system can work even when only a few percent of the memory is free. But the management cost of having to increment and decrement counters upon each pointer assignment cost a lot of time, and some kind of garbage collection is still needed to reclaim cycles.
So the trade-off is clear: if you have to work in a memory-constrained environment, or if you need precise finalizers, use reference counting. If you have enough memory and need the speed, use garbage collection. | 4 |
Python uses the reference count method to handle object life time. So an object that has no more use will be immediately destroyed.
But, in Java, the GC(garbage collector) destroys objects which are no longer used at a specific time.
Why does Java choose this strategy and what is the benefit from this?
Is this better than the Python approach? | 7,826,363 | 9 | java,python,garbage-collection | 7 | 2008-08-22 07:35:26.703 | 1 | 65 | Why Java and Python garbage collection methods are different? | 21,934 | 20,044 | false | One big disadvantage of Java's tracing GC is that from time to time it will "stop the world" and freeze the application for a relatively long time to do a full GC. If the heap is big and the the object tree complex, it will freeze for a few seconds. Also each full GC visits the whole object tree over and over again, something that is probably quite inefficient. Another drawback of the way Java does GC is that you have to tell the jvm what heap size you want (if the default is not good enough); the JVM derives from that value several thresholds that will trigger the GC process when there is too much garbage stacking up in the heap.
I presume that this is actually the main cause of the jerky feeling of Android (based on Java), even on the most expensive cellphones, in comparison with the smoothness of iOS (based on ObjectiveC, and using RC).
I'd love to see a jvm option to enable RC memory management, and maybe keeping GC only to run as a last resort when there is no more memory left. | 4 |
I was wondering how as semantic service like Open Calais figures out the names of companies, or people, tech concepts, keywords, etc. from a piece of text. Is it because they have a large database that they match the text against?
How would a service like Zemanta know what images to suggest to a piece of text for instance? | 23,041 | 3 | python,ruby,semantics,zemanta | 0 | 2008-08-22 10:51:19.057 | 0 | 5 | How do content discovery engines, like Zemanta and Open Calais work? | 22,059 | 2,346 | false | Open Calais probably use language parsing technology and language statics to guess which words or phrases are Names, Places, Companies, etc. Then, it is just another step to do some kind of search for those entities and return meta data.
Zementa probably does something similar, but matches the phrases against meta-data attached to images in order to acquire related results.
It certainly isn't easy. | 1 |
I have a small utility that I use to download an MP3 file from a website on a schedule and then builds/updates a podcast XML file which I've added to iTunes.
The text processing that creates/updates the XML file is written in Python. However, I use wget inside a Windows .bat file to download the actual MP3 file. I would prefer to have the entire utility written in Python.
I struggled to find a way to actually download the file in Python, thus why I resorted to using wget.
So, how do I download the file using Python? | 39,573,536 | 27 | python,http,urllib | 20 | 2008-08-22 15:34:13.760 | 1 | 1,032 | How to download a file over HTTP? | 22,676 | 1,341,778 | false | Following are the most commonly used calls for downloading files in python:
urllib.urlretrieve ('url_to_file', file_name)
urllib2.urlopen('url_to_file')
requests.get(url)
wget.download('url', file_name)
Note: urlopen and urlretrieve are found to perform relatively bad with downloading large files (size > 500 MB). requests.get stores the file in-memory until download is complete. | 1 |
How do I implement some logic that will allow me to reproduce on Windows the functionality that I have on Linux with the fork() system call, using Python?
I'm specifically trying to execute a method on the SAPI Com component, while continuing the other logic in the main thread without blocking or waiting. | 52,191 | 7 | python,windows,process,subprocess,fork | 3 | 2008-08-22 20:27:46.767 | 0.085505 | 23 | What's the best way to duplicate fork() in windows? | 23,397 | 31,865 | false | The Threading example from Eli will run the thread, but not do any of the work after that line.
I'm going to look into the processing module and the subprocess module. I think the com method I'm running needs to be in another process, not just in another thread. | 1 |
I had an idea, if I add a python .py file to my C# project, and tag the file with a custom generator that would execute the python file, and treat the output as the result of the code generation, ie. put it into a C# file, that would allow me to do quite a lot of code generation as part of the build process.
Does anyone know if such a custom generator for Visual Studio 2008 exists? | 24,199 | 5 | python,visual-studio-2008,code-generation | 2 | 2008-08-23 12:41:43.433 | 0.07983 | 4 | Python code generator for Visual Studio? | 24,193 | 1,825 | false | I recall that in previous versions of VS, there was a way to add custom build steps to the build process. I used that a lot to do exactly the kind of automated code generation you describe.
I imagine the custom build step feature is still there in 2008. | 2 |
I had an idea, if I add a python .py file to my C# project, and tag the file with a custom generator that would execute the python file, and treat the output as the result of the code generation, ie. put it into a C# file, that would allow me to do quite a lot of code generation as part of the build process.
Does anyone know if such a custom generator for Visual Studio 2008 exists? | 24,236 | 5 | python,visual-studio-2008,code-generation | 1 | 2008-08-23 12:41:43.433 | 0.039979 | 4 | Python code generator for Visual Studio? | 24,193 | 1,825 | false | I don't understand what you are trying to do here. Are you trying to execute a Python script that generates a C# file and then compile that with the project? Or are you trying to compile a Python script to C#? | 2 |
What is the best way to use PyGame (SDL) within a PyGTK application?
I'm searching for a method that allows me to have a drawing area in the GTK window and at the same time being able to manage both GTK and SDL events. | 88,457 | 7 | python,gtk,pygtk,sdl,pygame | 0 | 2008-08-25 04:36:48.980 | 0 | 9 | pyGame within a pyGTK application | 25,661 | 4,838 | false | I tried doing this myself a while ago, and I never got it to work perfectly. Actually I never got it to work at all under Windows, as it kept crashing the entire OS and I ran out of patience. I continued to use it though as it was only important it ran on Linux, and was only a small project. I'd strongly recommend you investigate alternatives. It always felt like a nasty hack, and made me feel dirty. | 2 |
What is the best way to use PyGame (SDL) within a PyGTK application?
I'm searching for a method that allows me to have a drawing area in the GTK window and at the same time being able to manage both GTK and SDL events. | 199,288 | 7 | python,gtk,pygtk,sdl,pygame | 0 | 2008-08-25 04:36:48.980 | 0 | 9 | pyGame within a pyGTK application | 25,661 | 4,838 | false | There's a simple solution that might work for you.
Write the PyGTK stuff and PyGame stuff as separate applications. Then from the PyGTK application call the PyGame application, using os.system to call the PyGame application. If you need to share data between the two then either use a database, pipes or IPC. | 2 |
I'm about to deploy a mediumsized site powered by Django. I have a dedicated Ubuntu Server.
I'm really confused over which serversoftware to use. So i thought to myself: why not ask stackoverflow.
What i'm looking for is:
Easy to set up
Fast and easy on resources
Can serve mediafiles
Able to serve multiple djangosites on same server
I would rather not install PHP or anything else that sucks resources, and for which I have no use for.
I have heard of mod_wsgi and mod_python on Apache, nginx and lighty. Which are the pros and cons of these and have i missed someone?
@Barry: Somehow i feel like Apache is to bloated for me. What about the alternatives?
@BrianLy: Ok I'll check out mod_wsgi some more. But why do i need Apache if i serve static files with lighty? I have also managed to serve the django app itself with lighty. Is that bad in anyway? Sorry for beeing so stupid :-)
UPDATE: What about lighty and nginx - which are the uses-cases when these are the perfect choice? | 5,942,466 | 13 | python,django,apache,hosting | 2 | 2008-08-25 13:28:41.150 | 0.03076 | 47 | Cleanest & Fastest server setup for Django | 26,025 | 24,076 | false | In my opinion best/fastest stack is varnish-nginx-uwsgi-django.
And I'm successfully using it. | 3 |
I'm about to deploy a mediumsized site powered by Django. I have a dedicated Ubuntu Server.
I'm really confused over which serversoftware to use. So i thought to myself: why not ask stackoverflow.
What i'm looking for is:
Easy to set up
Fast and easy on resources
Can serve mediafiles
Able to serve multiple djangosites on same server
I would rather not install PHP or anything else that sucks resources, and for which I have no use for.
I have heard of mod_wsgi and mod_python on Apache, nginx and lighty. Which are the pros and cons of these and have i missed someone?
@Barry: Somehow i feel like Apache is to bloated for me. What about the alternatives?
@BrianLy: Ok I'll check out mod_wsgi some more. But why do i need Apache if i serve static files with lighty? I have also managed to serve the django app itself with lighty. Is that bad in anyway? Sorry for beeing so stupid :-)
UPDATE: What about lighty and nginx - which are the uses-cases when these are the perfect choice? | 26,185 | 13 | python,django,apache,hosting | 1 | 2008-08-25 13:28:41.150 | 0.015383 | 47 | Cleanest & Fastest server setup for Django | 26,025 | 24,076 | false | If you're using lighthttpd, you can also use FastCGI for serving Django. I'm not sure how the speed compares to mod_wsgi, but if memory serves correctly, you get a couple of the benefits that you would get with mod_wsgi that you wouldn't get with mod_python. The main one being that you can give each application its own process (which is really helpful for keeping memory of different apps separated as well as for taking advantage of multi-core computers.
Edit: Just to add in regards to your update about nginix, if memory serves correctly again, nginix uses "greenlets" to handle concurrency. This means that you may need to be a little bit more careful to make sure that one app doesn't eat up all the server's time. | 3 |
I'm about to deploy a mediumsized site powered by Django. I have a dedicated Ubuntu Server.
I'm really confused over which serversoftware to use. So i thought to myself: why not ask stackoverflow.
What i'm looking for is:
Easy to set up
Fast and easy on resources
Can serve mediafiles
Able to serve multiple djangosites on same server
I would rather not install PHP or anything else that sucks resources, and for which I have no use for.
I have heard of mod_wsgi and mod_python on Apache, nginx and lighty. Which are the pros and cons of these and have i missed someone?
@Barry: Somehow i feel like Apache is to bloated for me. What about the alternatives?
@BrianLy: Ok I'll check out mod_wsgi some more. But why do i need Apache if i serve static files with lighty? I have also managed to serve the django app itself with lighty. Is that bad in anyway? Sorry for beeing so stupid :-)
UPDATE: What about lighty and nginx - which are the uses-cases when these are the perfect choice? | 29,748 | 13 | python,django,apache,hosting | 27 | 2008-08-25 13:28:41.150 | 1.2 | 47 | Cleanest & Fastest server setup for Django | 26,025 | 24,076 | true | Since I was looking for some more in-depth answers, I decided to research the issue myself in depth. Please let me know if I've misunderstood anything.
Some general recommendation are to use a separate webserver for handling media. By separate, I mean a webserver which is not running Django. This server can be for instance:
Lighttpd (Lighty)
Nginx (EngineX)
Or some other light-weight server
Then, for Django, you can go down different paths. You can either:
Serve Django via Apache and:
mod_python
This is the stable and recommended/well documented way. Cons: uses a lot of memory.
mod_wsgi
From what I understand, mod_wsgi is a newer alternative. It appears to be faster and easier on resources.
mod_fastcgi
When using FastCGI you are delegating the serving of Django to another process. Since mod_python includes a python interpreter in every request it uses a lot of memory. This is a way to bypass that problem. Also there is some security concerns.
What you do is that you start your Django FastCGI server in a separate process and then configures apache via rewrites to call this process when needed.
Or you can:
Serve Django without using Apache but with another server that supports FastCGI natively:
(The documentation mentions that you can do this if you don't have any Apache specific needs. I guess the reason must be to save memory.)
Lighttpd
This is the server that runs Youtube. It seems fast and easy to use, however i've seen reports on memoryleaks.
nginx
I've seen benchmarks claiming that this server is even faster than lighttpd. It's mostly documented in Russian though.
Another thing, due to limitations in Python your server should be running in forked mode, not threaded.
So this is my current research, but I want more opinions and experiences. | 3 |
I'm a bit perplexed by drag and drop in wxPython (but perhaps this questions pertains to drag and drop in other GUI frameworks as well). The frameworks provides a couple of callbacks (OnEnter and OnDragOver) that purportedly allow me to inform the system whether the current mouse position is a valid place to drop whatever it is that is being dragged. From these methods I can return wx.DragNone, wx.DragCopy, etc. What baffles me is that from within these methods I am not allowed to call GetData, which means I am not allowed to examine the data that the user is dragging. If I cannot see the data, how am I supposed to know whether it is OK for the user to drop here? | 26,707 | 2 | python,user-interface,drag-and-drop,wxpython,wxwidgets | 1 | 2008-08-25 19:43:15.960 | 1.2 | 6 | wxpython: How do I examine dragged data in OnDragOver? | 26,706 | 584 | true | One solution, which is a hack of limited usefulness, is when a drag is initiated, store the dragged data in a global or static reference somewhere. This way, in the OnEnter and OnDragOver handlers, it is possible to get a reference to the data being dragged. This is of course only useful for drags within the same application (the same instance of the application, actually). | 2 |
I'm a bit perplexed by drag and drop in wxPython (but perhaps this questions pertains to drag and drop in other GUI frameworks as well). The frameworks provides a couple of callbacks (OnEnter and OnDragOver) that purportedly allow me to inform the system whether the current mouse position is a valid place to drop whatever it is that is being dragged. From these methods I can return wx.DragNone, wx.DragCopy, etc. What baffles me is that from within these methods I am not allowed to call GetData, which means I am not allowed to examine the data that the user is dragging. If I cannot see the data, how am I supposed to know whether it is OK for the user to drop here? | 139,047 | 2 | python,user-interface,drag-and-drop,wxpython,wxwidgets | 1 | 2008-08-25 19:43:15.960 | 0.099668 | 6 | wxpython: How do I examine dragged data in OnDragOver? | 26,706 | 584 | false | There is no way to see dragged data in OnEnter and OnDragOver methods.
The only solution I found is to store the dragged item in some instance variable that is then readable inside these methods. | 2 |
I've been having a hard time trying to understand PyPy's translation. It looks like something absolutely revolutionary from simply reading the description, however I'm hard-pressed to find good documentation on actually translating a real world piece of code to something such as LLVM. Does such a thing exist? The official PyPy documentation on it just skims over the functionality, rather than providing anything I can try out myself. | 1,041,655 | 5 | python,translation,pypy | 3 | 2008-08-26 08:40:28.853 | 0.119427 | 11 | Where can I learn more about PyPy's translation function? | 27,567 | 1,284 | false | PyPy translator is in general, not intended for more public use. We use it for translating
our own python interpreter (including JIT and GCs, both written in RPython, this restricted
subset of Python). The idea is that with good JIT and GC, you'll be able to speedups even
without knowing or using PyPy's translation toolchain (and more importantly, without
restricting yourself to RPython).
Cheers,
fijal | 2 |
I've been having a hard time trying to understand PyPy's translation. It looks like something absolutely revolutionary from simply reading the description, however I'm hard-pressed to find good documentation on actually translating a real world piece of code to something such as LLVM. Does such a thing exist? The official PyPy documentation on it just skims over the functionality, rather than providing anything I can try out myself. | 1,041,857 | 5 | python,translation,pypy | 1 | 2008-08-26 08:40:28.853 | 0.039979 | 11 | Where can I learn more about PyPy's translation function? | 27,567 | 1,284 | false | It looks like something absolutely revolutionary from simply reading the description,
As far as I know, PyPy is novel in the sense that it is the first system expressly designed for implementing languages. Other tools exist to help with much of the very front end, such as parser generators, or for the very back end, such as code generation, but not much existed for connecting the two. | 2 |
I have a bunch of classes I want to rename. Some of them have names that are small and that name is reused in other class names, where I don't want that name changed. Most of this lives in Python code, but we also have some XML code that references class names.
Simple search and replace only gets me so far. In my case, I want to rename AdminAction to AdminActionPlug and AdminActionLogger to AdminActionLoggerPlug, so the first one's search-and-replace would also hit the second, wrongly.
Does anyone have experience with Python refactoring tools ? Bonus points if they can fix class names in the XML documents too. | 4,882,243 | 7 | python,refactoring | 5 | 2008-08-26 18:26:51.517 | 0.141893 | 74 | What refactoring tools do you use for Python? | 28,796 | 39,816 | false | WingIDE 4.0 (WingIDE is my python IDE of choice) will support a few refactorings, but I just tried out the latest beta, beta6, and... there's still work to be done. Retract Method works nicely, but Rename Symbol does not.
Update: The 4.0 release has fixed all of the refactoring tools. They work great now. | 3 |
I have a bunch of classes I want to rename. Some of them have names that are small and that name is reused in other class names, where I don't want that name changed. Most of this lives in Python code, but we also have some XML code that references class names.
Simple search and replace only gets me so far. In my case, I want to rename AdminAction to AdminActionPlug and AdminActionLogger to AdminActionLoggerPlug, so the first one's search-and-replace would also hit the second, wrongly.
Does anyone have experience with Python refactoring tools ? Bonus points if they can fix class names in the XML documents too. | 14,046,877 | 7 | python,refactoring | -2 | 2008-08-26 18:26:51.517 | -0.057081 | 74 | What refactoring tools do you use for Python? | 28,796 | 39,816 | false | You can use sed to perform this. The trick is to recall that regular expressions can recognize word boundaries. This works on all platforms provided you get the tools, which on Windows is Cygwin, Mac OS may require installing the dev tools, I'm not sure, and Linux has this out of the box. So grep, xargs, and sed should do the trick, after 12 hours of reading man pages and trial and error ;) | 3 |
I have a bunch of classes I want to rename. Some of them have names that are small and that name is reused in other class names, where I don't want that name changed. Most of this lives in Python code, but we also have some XML code that references class names.
Simple search and replace only gets me so far. In my case, I want to rename AdminAction to AdminActionPlug and AdminActionLogger to AdminActionLoggerPlug, so the first one's search-and-replace would also hit the second, wrongly.
Does anyone have experience with Python refactoring tools ? Bonus points if they can fix class names in the XML documents too. | 1,813,244 | 7 | python,refactoring | 4 | 2008-08-26 18:26:51.517 | 0.113791 | 74 | What refactoring tools do you use for Python? | 28,796 | 39,816 | false | Your IDE can support refactorings !!
Check it Eric, Eclipse, WingIDE have build in tools for refactorings (Rename including). And that are very safe refactorings - if something can go wrong IDE wont do ref.
Also consider adding few unit test to ensure your code did not suffer during refactorings. | 3 |
I have a medium sized application that runs as a .net web-service which I do not control,
and I want to create a loose pythonic API above it to enable easy scripting.
I wanted to know what is the best/most practical solution for using web-services in python.
Edit:
I need to consume a complex soap WS
and I have no control over it. | 31,926 | 3 | python,web-services,soap | 3 | 2008-08-26 19:49:54.517 | 0.197375 | 8 | What's the best way to use web services in python? | 28,961 | 1,090 | false | If I have to expose APIs, I prefer doing it as JSON. Python has excellent support for JSON objects (JSON Objects are infact python dictionaries) | 1 |
The default Python install on OS X 10.5 is 2.5.1 with a FAT 32 bit (Intel and PPC) client. I want to setup apache and mysql to run django. In the past, I have run Apache and MySQL to match this install in 32 bit mode (even stripping out the 64 bit stuff from Apache to make it work).
I want to upgrade Python to 64 bit. I am completely comfortable with compiling it from source with one caveat. How do I match the way that the default install is laid out? Especially, with regards to site-packages being in /Library/Python/2.5/ and not the one in buried at the top of the framework once I compile it. | 31,425 | 5 | python,macos,64-bit | 0 | 2008-08-27 10:22:09.427 | 0 | 4 | Install Python to match directory layout in OS X 10.5 | 29,856 | 653 | false | The short answer is because I can. The long answer, expanding on what the OP said, is to be more compatible with apache and mysql/postgresql. They are all 64bit (apache is a fat binary with ppc, ppc64 x86 and x86 and x86_64, the others just straight 64bit). Mysqldb and mod_python wont compile unless they are all running the same architecture. Yes I could run them all in 32bit (and have in the past) but this is much more work then compiling one program.
EDIT: You pretty much convinced though to just let the installer do its thing and update the PATH to reflect this. | 4 |
The default Python install on OS X 10.5 is 2.5.1 with a FAT 32 bit (Intel and PPC) client. I want to setup apache and mysql to run django. In the past, I have run Apache and MySQL to match this install in 32 bit mode (even stripping out the 64 bit stuff from Apache to make it work).
I want to upgrade Python to 64 bit. I am completely comfortable with compiling it from source with one caveat. How do I match the way that the default install is laid out? Especially, with regards to site-packages being in /Library/Python/2.5/ and not the one in buried at the top of the framework once I compile it. | 30,591 | 5 | python,macos,64-bit | 1 | 2008-08-27 10:22:09.427 | 0.039979 | 4 | Install Python to match directory layout in OS X 10.5 | 29,856 | 653 | false | Not sure I entirely understand your question, but can't you simply build and install a 64 bit version and then create symbolic links so that /Library/Python/2.5 and below point to your freshly built version of python? | 4 |
The default Python install on OS X 10.5 is 2.5.1 with a FAT 32 bit (Intel and PPC) client. I want to setup apache and mysql to run django. In the past, I have run Apache and MySQL to match this install in 32 bit mode (even stripping out the 64 bit stuff from Apache to make it work).
I want to upgrade Python to 64 bit. I am completely comfortable with compiling it from source with one caveat. How do I match the way that the default install is laid out? Especially, with regards to site-packages being in /Library/Python/2.5/ and not the one in buried at the top of the framework once I compile it. | 31,331 | 5 | python,macos,64-bit | 0 | 2008-08-27 10:22:09.427 | 0 | 4 | Install Python to match directory layout in OS X 10.5 | 29,856 | 653 | false | Essentially, yes. I was not sure you could do it like that (current version does not do it like that). When using the python install script, however, there is no option (that I can find) to specify where to put directories and files (eg --prefix). I was hoping to match the current layout of python related files so as to avoid 'polluting' my machine with redundant files. | 4 |
The default Python install on OS X 10.5 is 2.5.1 with a FAT 32 bit (Intel and PPC) client. I want to setup apache and mysql to run django. In the past, I have run Apache and MySQL to match this install in 32 bit mode (even stripping out the 64 bit stuff from Apache to make it work).
I want to upgrade Python to 64 bit. I am completely comfortable with compiling it from source with one caveat. How do I match the way that the default install is laid out? Especially, with regards to site-packages being in /Library/Python/2.5/ and not the one in buried at the top of the framework once I compile it. | 31,384 | 5 | python,macos,64-bit | 1 | 2008-08-27 10:22:09.427 | 1.2 | 4 | Install Python to match directory layout in OS X 10.5 | 29,856 | 653 | true | Personally, I wouldn't worry about it until you see a problem. Messing with the default python install on a *Nix system can cause more trouble than it's worth. I can say from personal experience that you never truly understand what python has done for the nix world until you have a problem with it.
You can also add a second python installation, but that also causes more problems than it's worth IMO.
So I suppose the best question to start out with would be why exactly do you want to use the 64 bit version of python? | 4 |
I've been trying to wrap my head around how threads work in Python, and it's hard to find good information on how they operate. I may just be missing a link or something, but it seems like the official documentation isn't very thorough on the subject, and I haven't been able to find a good write-up.
From what I can tell, only one thread can be running at once, and the active thread switches every 10 instructions or so?
Where is there a good explanation, or can you provide one? It would also be very nice to be aware of common problems that you run into while using threads with Python. | 1,197,151 | 7 | python,multithreading | 2 | 2008-08-27 23:44:47.843 | 0.057081 | 89 | How do threads work in Python, and what are common Python-threading specific pitfalls? | 31,340 | 43,779 | false | Try to remember that the GIL is set to poll around every so often in order to do show the appearance of multiple tasks. This setting can be fine tuned, but I offer the suggestion that there should be work that the threads are doing or lots of context switches are going to cause problems.
I would go so far as to suggest multiple parents on processors and try to keep like jobs on the same core(s). | 1 |
This is something that I think would be very useful. Basically, I'd like there to be a way to edit Python source programmatically without requiring human intervention. There are a couple of things I would like to do with this:
Edit the configuration of Python apps that use source modules for configuration.
Set up a "template" so that I can customize a Python source file on the fly. This way, I can set up a "project" system on an open source app I'm working on and allow certain files to be customized.
I could probably write something that can do this myself, but I can see that opening up a lot of "devil's in the details" type issues. Are there any ways to do this currently, or am I just going to have to bite the bullet and implement it myself? | 33,325 | 3 | python,file-io | 0 | 2008-08-28 14:23:00.247 | 0 | 9 | Programmatically editing Python source | 32,385 | 1,904 | false | I had the same issue and I simply opened the file and did some replace: then reload the file in the Python interpreter. This works fine and is easy to do.
Otherwise AFAIK you have to use some conf objects. | 1 |
How would you go about finding out how much memory is being used by an object? I know it is possible to find out how much is used by a block of code, but not by an instantiated object (anytime during its life), which is what I want. | 24,495,011 | 5 | python,performance,memory-profiling | 2 | 2008-08-29 04:59:31.200 | 0.07983 | 267 | Find out how much memory is being used by an object in Python | 33,978 | 222,118 | false | For big objects you may use a somewhat crude but effective method:
check how much memory your Python process occupies in the system, then delete the object and compare.
This method has many drawbacks but it will give you a very fast estimate for very big objects. | 1 |
A reliable coder friend told me that Python's current multi-threading implementation is seriously buggy - enough to avoid using altogether. What can said about this rumor? | 34,024 | 6 | python,multithreading | -2 | 2008-08-29 05:43:16.960 | -0.066568 | 28 | Are Python threads buggy? | 34,020 | 12,462 | false | I've used it in several applications and have never had nor heard of threading being anything other than 100% reliable, as long as you know its limits. You can't spawn 1000 threads at the same time and expect your program to run properly on Windows, however you can easily write a worker pool and just feed it 1000 operations, and keep everything nice and under control. | 3 |
A reliable coder friend told me that Python's current multi-threading implementation is seriously buggy - enough to avoid using altogether. What can said about this rumor? | 34,078 | 6 | python,multithreading | 9 | 2008-08-29 05:43:16.960 | 1 | 28 | Are Python threads buggy? | 34,020 | 12,462 | false | The GIL (Global Interpreter Lock) might be a problem, but the API is quite OK. Try out the excellent processing module, which implements the Threading API for separate processes. I am using that right now (albeit on OS X, have yet to do some testing on Windows) and am really impressed. The Queue class is really saving my bacon in terms of managing complexity!
EDIT: it seemes the processing module is being included in the standard library as of version 2.6 (import multiprocessing). Joy! | 3 |
A reliable coder friend told me that Python's current multi-threading implementation is seriously buggy - enough to avoid using altogether. What can said about this rumor? | 576,667 | 6 | python,multithreading | 2 | 2008-08-29 05:43:16.960 | 0.066568 | 28 | Are Python threads buggy? | 34,020 | 12,462 | false | If you want to code in python and get great threading support, you might want to check out IronPython or Jython. Since the python code in IronPython and Jython run on the .NET CLR and Java VM respectively, they enjoy the great threading support built into those libraries. In addition to that, IronPython doesn't have the GIL, an issue that prevents CPython threads from taking full advantage of multi-core architectures. | 3 |
What's the best way to specify a proxy with username and password for an http connection in python? | 3,942,980 | 6 | python,http,proxy | 15 | 2008-08-29 06:55:54.977 | 1 | 58 | How to specify an authenticated proxy for a python http connection? | 34,079 | 95,434 | false | Setting an environment var named http_proxy like this: http://username:password@proxy_url:port | 1 |
Is there something like the Python descriptor protocol implemented in other languages? It seems like a nice way to increase modularity/encapsulation without bloating your containing class' implementation, but I've never heard of a similar thing in any other languages. Is it likely absent from other languages because of the lookup overhead? | 34,266 | 2 | python,language-features,encapsulation | 4 | 2008-08-29 09:24:08.583 | 1.2 | 10 | Python descriptor protocol analog in other languages? | 34,243 | 888 | true | I've not heard of a direct equivalent either. You could probably achieve the same effect with macros, especially in a language like Lisp which has extremely powerful macros.
I wouldn't be at all surprised if other languages start to incorporate something similar because it is so powerful. | 1 |
Given a Python object of any kind, is there an easy way to get the list of all methods that this object has?
Or,
if this is not possible, is there at least an easy way to check if it has a particular method other than simply checking if an error occurs when the method is called? | 20,100,900 | 22 | python,introspection | 132 | 2008-08-29 15:05:17.237 | 1 | 592 | Finding what methods a Python object has | 34,439 | 564,030 | false | The simplest method is to use dir(objectname). It will display all the methods available for that object. | 1 |
Is there a Ruby equivalent for Python's "is"? It tests whether two objects are identical (i.e. have the same memory location). | 39,062 | 2 | python,ruby | 2 | 2008-08-30 03:04:54.527 | 0.197375 | 9 | Ruby "is" equivalent | 35,634 | 473 | false | You could also use __id__. This gives you the objects internal ID number, which is always unique. To check if to objects are the same, try
a.__id__ = b.__id__
This is how Ruby's standard library does it as far as I can tell (see group_by and others). | 1 |
Right now I'm developing mostly in C/C++, but I wrote some small utilities in Python to automatize some tasks and I really love it as language (especially the productivity).
Except for the performances (a problem that could be sometimes solved thanks to the ease of interfacing Python with C modules), do you think it is proper for production use in the development of stand-alone complex applications (think for example to a word processor or a graphic tool)?
What IDE would you suggest? The IDLE provided with Python is not enough even for small projects in my opinion. | 35,838 | 13 | python,ide | 0 | 2008-08-30 07:08:22.587 | 0 | 29 | Is Python good for big software projects (not web based)? | 35,753 | 29,152 | false | I know I'm probably stating the obvious, but don't forget that the quality of the development team and their familiarity with the technology will have a major impact on your ability to deliver.
If you have a strong team, then it's probably not an issue if they're familiar. But if you have people who are more 9 to 5'rs who aren't familiar with the technology, they will need more support and you'd need to make a call if the productivity gains are worth whatever the cost of that support is. | 8 |
Right now I'm developing mostly in C/C++, but I wrote some small utilities in Python to automatize some tasks and I really love it as language (especially the productivity).
Except for the performances (a problem that could be sometimes solved thanks to the ease of interfacing Python with C modules), do you think it is proper for production use in the development of stand-alone complex applications (think for example to a word processor or a graphic tool)?
What IDE would you suggest? The IDLE provided with Python is not enough even for small projects in my opinion. | 286,491 | 13 | python,ide | 1 | 2008-08-30 07:08:22.587 | 0.015383 | 29 | Is Python good for big software projects (not web based)? | 35,753 | 29,152 | false | Python is a delight to use. I use it routinely and also write a lot of code for work in C#. There are two drawbacks to writing UI code in Python. one is that there is not a single ui framework that is accepted by the majority of the community. when you write in c# the .NET runtime and class libraries are all meant to work together. With Python every UI library has at's own semantics which are often at odds with the pythonic mindset in which you are trying to write your program. I am not blaming the library writers. I've tried several libraries (wxwidgets, PythonWin[Wrapper around MFC], Tkinter), When doing so I often felt that I was writing code in a language other than Python (despite the fact that it was python) because the libraries aren't exactly pythonic they are a port from another language be it c, c++, tk.
So for me I will write UI code in .NET (for me C#) because of the IDE & the consistency of the libraries. But when I can I will write business logic in python because it is more clear and more fun. | 8 |
Right now I'm developing mostly in C/C++, but I wrote some small utilities in Python to automatize some tasks and I really love it as language (especially the productivity).
Except for the performances (a problem that could be sometimes solved thanks to the ease of interfacing Python with C modules), do you think it is proper for production use in the development of stand-alone complex applications (think for example to a word processor or a graphic tool)?
What IDE would you suggest? The IDLE provided with Python is not enough even for small projects in my opinion. | 286,449 | 13 | python,ide | 1 | 2008-08-30 07:08:22.587 | 0.015383 | 29 | Is Python good for big software projects (not web based)? | 35,753 | 29,152 | false | And as far as I know they use a lot of python inside google too.
Well i'd hope so, the maker of python still works at google if i'm not mistaken?
As for the use of Python, i think it's a great language for stand-alone apps. It's heavily used in a lot of Linux programs, and there are a few nice widget sets out there to aid in the development of GUI's. | 8 |
Right now I'm developing mostly in C/C++, but I wrote some small utilities in Python to automatize some tasks and I really love it as language (especially the productivity).
Except for the performances (a problem that could be sometimes solved thanks to the ease of interfacing Python with C modules), do you think it is proper for production use in the development of stand-alone complex applications (think for example to a word processor or a graphic tool)?
What IDE would you suggest? The IDLE provided with Python is not enough even for small projects in my opinion. | 35,777 | 13 | python,ide | 23 | 2008-08-30 07:08:22.587 | 1 | 29 | Is Python good for big software projects (not web based)? | 35,753 | 29,152 | false | You'll find mostly two answers to that – the religous one (Yes! Of course! It's the best language ever!) and the other religious one (you gotta be kidding me! Python? No... it's not mature enough). I will maybe skip the last religion (Python?! Use Ruby!). The truth, as always, is far from obvious.
Pros: it's easy, readable, batteries included, has lots of good libraries for pretty much everything. It's expressive and dynamic typing makes it more concise in many cases.
Cons: as a dynamic language, has way worse IDE support (proper syntax completion requires static typing, whether explicit in Java or inferred in SML), its object system is far from perfect (interfaces, anyone?) and it is easy to end up with messy code that has methods returning either int or boolean or object or some sort under unknown circumstances.
My take – I love Python for scripting, automation, tiny webapps and other simple well defined tasks. In my opinion it is by far the best dynamic language on the planet. That said, I would never use it any dynamically typed language to develop an application of substantial size.
Say – it would be fine to use it for Stack Overflow, which has three developers and I guess no more than 30k lines of code. For bigger things – first your development would be super fast, and then once team and codebase grow things are slowing down more than they would with Java or C#. You need to offset lack of compilation time checks by writing more unittests, refactorings get harder cause you never know what your refacoring broke until you run all tests or even the whole big app, etc.
Now – decide on how big your team is going to be and how big the app is supposed to be once it is done. If you have 5 or less people and the target size is roughly Stack Overflow, go ahead, write in Python. You will finish in no time and be happy with good codebase. But if you want to write second Google or Yahoo, you will be much better with C# or Java.
Side-note on C/C++ you have mentioned: if you are not writing performance critical software (say massive parallel raytracer that will run for three months rendering a film) or a very mission critical system (say Mars lander that will fly three years straight and has only one chance to land right or you lose $400mln) do not use it. For web apps, most desktop apps, most apps in general it is not a good choice. You will die debugging pointers and memory allocation in complex business logic. | 8 |
Right now I'm developing mostly in C/C++, but I wrote some small utilities in Python to automatize some tasks and I really love it as language (especially the productivity).
Except for the performances (a problem that could be sometimes solved thanks to the ease of interfacing Python with C modules), do you think it is proper for production use in the development of stand-alone complex applications (think for example to a word processor or a graphic tool)?
What IDE would you suggest? The IDLE provided with Python is not enough even for small projects in my opinion. | 3,445,481 | 13 | python,ide | 0 | 2008-08-30 07:08:22.587 | 0 | 29 | Is Python good for big software projects (not web based)? | 35,753 | 29,152 | false | Try Django or Pylons, write a simple app with both of them and then decide which one suits you best. There are others (like Turbogears or Werkzeug) but those are the most used. | 8 |
Right now I'm developing mostly in C/C++, but I wrote some small utilities in Python to automatize some tasks and I really love it as language (especially the productivity).
Except for the performances (a problem that could be sometimes solved thanks to the ease of interfacing Python with C modules), do you think it is proper for production use in the development of stand-alone complex applications (think for example to a word processor or a graphic tool)?
What IDE would you suggest? The IDLE provided with Python is not enough even for small projects in my opinion. | 35,759 | 13 | python,ide | 13 | 2008-08-30 07:08:22.587 | 1 | 29 | Is Python good for big software projects (not web based)? | 35,753 | 29,152 | false | I really like python, it's usually my language of choice these days for small (non-gui) stuff that I do on my own.
However, for some larger Python projects I've tackled, I'm finding that it's not quite the same as programming in say, C++. I was working on a language parser, and needed to represent an AST in Python. This is certainly within the scope of what Python can do, but I had a bit of trouble with some refactoring. I was changing the representation of my AST and changing methods and classes around a lot, and I found I missed the strong typing that would be available to me in a C++ solution. Python's duck typing was almost too flexible and I found myself adding a lot of assert code to try to check my types as the program ran. And then I couldn't really be sure that everything was properly typed unless I had 100% code coverage testing (which I didn't at the time).
Actually, that's another thing that I miss sometimes. It's possible to write syntactically correct code in Python that simply won't run. The compiler is incapable of telling you about it until it actually executes the code, so in infrequently-used code paths such as error handlers you can easily have unseen bugs lurking around. Even code that's as simple as printing an error message with a % format string can fail at runtime because of mismatched types.
I haven't used Python for any GUI stuff so I can't comment on that aspect. | 8 |
Right now I'm developing mostly in C/C++, but I wrote some small utilities in Python to automatize some tasks and I really love it as language (especially the productivity).
Except for the performances (a problem that could be sometimes solved thanks to the ease of interfacing Python with C modules), do you think it is proper for production use in the development of stand-alone complex applications (think for example to a word processor or a graphic tool)?
What IDE would you suggest? The IDLE provided with Python is not enough even for small projects in my opinion. | 277,490 | 13 | python,ide | 0 | 2008-08-30 07:08:22.587 | 0 | 29 | Is Python good for big software projects (not web based)? | 35,753 | 29,152 | false | I had only one python experience, my trash-cli project.
I know that probably some or all problems depends of my inexperience with python.
I found frustrating these things:
the difficult of finding a good IDE for free
the limited support to automatic refactoring
Moreover:
the need of introduce two level of grouping packages and modules confuses me.
it seems to me that there is not a widely adopted code naming convention
it seems to me that there are some standard library APIs docs that are incomplete
the fact that some standard libraries are not fully object oriented annoys me
Although some python coders tell me that they does not have these problems, or they say these are not problems. | 8 |
Right now I'm developing mostly in C/C++, but I wrote some small utilities in Python to automatize some tasks and I really love it as language (especially the productivity).
Except for the performances (a problem that could be sometimes solved thanks to the ease of interfacing Python with C modules), do you think it is proper for production use in the development of stand-alone complex applications (think for example to a word processor or a graphic tool)?
What IDE would you suggest? The IDLE provided with Python is not enough even for small projects in my opinion. | 35,841 | 13 | python,ide | 3 | 2008-08-30 07:08:22.587 | 0.046121 | 29 | Is Python good for big software projects (not web based)? | 35,753 | 29,152 | false | Refactoring is inevitable on larger codebases and the lack of static typing makes this much harder in python than in statically typed languages. | 8 |
End of preview. Expand
in Dataset Viewer.
SO dataset of python
tag data
Question filters:
- images
- links
- Q_Score > 0
- Answer_count > 0
Answers filters:
- images
- links
- code blocks
Scores are tanh applied to scaled with AbsMaxScaler to IQR range of Original SO Answers' scores
- Downloads last month
- 145