CreationDate
stringlengths
23
23
Users Score
int64
-36
1.15k
Available Count
int64
1
18
Title
stringlengths
11
150
Tags
stringlengths
6
94
is_accepted
bool
2 classes
Answer
stringlengths
6
11.6k
Q_Score
int64
0
6.79k
Score
float64
-1
1.2
A_Id
int64
1.99k
72.5M
log_score
int64
-1
11
ViewCount
int64
8
6.81M
AnswerCount
int64
1
51
Question
stringlengths
15
29k
Q_Id
int64
1.98k
70M
2008-08-05T07:18:00.000
2
14
Python: what is the difference between (1,2,3) and [1,2,3], and when should I use each?
python,list,tuples
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.
58
0.022219
49,586,164
2
12,477
18
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,983
2008-08-05T07:18:00.000
2
14
Python: what is the difference between (1,2,3) and [1,2,3], and when should I use each?
python,list,tuples
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.
58
0.022219
5,746
2
12,477
18
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,983
2008-08-05T07:18:00.000
4
14
Python: what is the difference between (1,2,3) and [1,2,3], and when should I use each?
python,list,tuples
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.
58
0.044415
12,454
0
12,477
18
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,983
2008-08-05T07:18:00.000
3
14
Python: what is the difference between (1,2,3) and [1,2,3], and when should I use each?
python,list,tuples
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.
58
0.033321
5,719
0
12,477
18
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,983
2008-08-05T07:18:00.000
23
14
Python: what is the difference between (1,2,3) and [1,2,3], and when should I use each?
python,list,tuples
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.
58
1
1,987
0
12,477
18
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,983
2008-08-05T07:18:00.000
5
14
Python: what is the difference between (1,2,3) and [1,2,3], and when should I use each?
python,list,tuples
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.
58
0.055498
6,477,369
0
12,477
18
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,983
2008-08-05T07:18:00.000
0
14
Python: what is the difference between (1,2,3) and [1,2,3], and when should I use each?
python,list,tuples
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.
58
0
54,570,759
0
12,477
18
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,983
2008-08-05T07:18:00.000
2
14
Python: what is the difference between (1,2,3) and [1,2,3], and when should I use each?
python,list,tuples
false
[1,2,3] is a list. (1,2,3) is a tuple and immutable.
58
0.022219
26,250,158
0
12,477
18
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,983
2008-08-05T07:18:00.000
0
14
Python: what is the difference between (1,2,3) and [1,2,3], and when should I use each?
python,list,tuples
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.
58
0
69,499,270
3
12,477
18
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,983
2008-08-05T07:18:00.000
0
14
Python: what is the difference between (1,2,3) and [1,2,3], and when should I use each?
python,list,tuples
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.
58
0
38,062,967
5
12,477
18
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,983
2008-08-05T07:18:00.000
0
14
Python: what is the difference between (1,2,3) and [1,2,3], and when should I use each?
python,list,tuples
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
58
0
63,479,906
2
12,477
18
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,983
2008-08-05T07:18:00.000
0
14
Python: what is the difference between (1,2,3) and [1,2,3], and when should I use each?
python,list,tuples
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.
58
0
62,503,886
2
12,477
18
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,983
2008-08-05T07:18:00.000
3
14
Python: what is the difference between (1,2,3) and [1,2,3], and when should I use each?
python,list,tuples
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.
58
0.033321
44,083,156
2
12,477
18
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,983
2008-08-05T07:18:00.000
0
14
Python: what is the difference between (1,2,3) and [1,2,3], and when should I use each?
python,list,tuples
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.
58
0
35,496,153
2
12,477
18
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,983
2008-08-17T19:14:00.000
3
2
Can you explain closures (as they relate to Python)?
python,functional-programming,closures
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.
95
0.046121
473,491
2
15,413
13
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.
13,857
2008-08-17T19:14:00.000
-2
2
Can you explain closures (as they relate to Python)?
python,functional-programming,closures
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.
95
-0.03076
94,543
-1
15,413
13
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.
13,857
2008-08-18T07:41:00.000
0
2
Is there a python module for regex matching in zip files
python,regex,zip,text-processing
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.
7
0
41,822
0
2,774
4
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,281
2008-08-18T07:41:00.000
0
2
Is there a python module for regex matching in zip files
python,regex,zip,text-processing
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.
7
0
14,304
0
2,774
4
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,281
2008-08-21T11:48:00.000
1
8
Introducing Python
php,python
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.
6
0.024995
19,700
1
651
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,654
2008-08-21T11:48:00.000
14
8
Introducing Python
php,python
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.
6
1.2
19,715
5
651
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,654
2008-08-21T11:48:00.000
0
8
Introducing Python
php,python
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.
6
0
19,943
0
651
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,654
2008-08-21T11:48:00.000
1
8
Introducing Python
php,python
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.
6
0.024995
19,968
1
651
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,654
2008-08-21T11:48:00.000
0
8
Introducing Python
php,python
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.
6
0
19,685
0
651
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,654
2008-08-21T11:48:00.000
2
8
Introducing Python
php,python
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.
6
0.049958
19,692
2
651
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,654
2008-08-21T11:48:00.000
4
8
Introducing Python
php,python
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?
6
0.099668
19,668
2
651
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,654
2008-08-21T11:48:00.000
0
8
Introducing Python
php,python
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 ..
6
0
19,665
0
651
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,654
2008-08-22T07:35:00.000
4
4
Why Java and Python garbage collection methods are different?
java,python,garbage-collection
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.
65
0.088656
46,780
3
20,044
9
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,934
2008-08-22T07:35:00.000
54
4
Why Java and Python garbage collection methods are different?
java,python,garbage-collection
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...
65
1.2
21,964
4
20,044
9
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,934
2008-08-22T07:35:00.000
6
4
Why Java and Python garbage collection methods are different?
java,python,garbage-collection
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.
65
1
74,327
6
20,044
9
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,934
2008-08-22T07:35:00.000
7
4
Why Java and Python garbage collection methods are different?
java,python,garbage-collection
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.
65
1
7,826,363
2
20,044
9
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,934
2008-08-23T12:41:00.000
2
2
Python code generator for Visual Studio?
python,visual-studio-2008,code-generation
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.
4
0.07983
24,199
2
1,825
5
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,193
2008-08-23T12:41:00.000
1
2
Python code generator for Visual Studio?
python,visual-studio-2008,code-generation
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#?
4
0.039979
24,236
1
1,825
5
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,193
2008-08-26T18:26:00.000
-2
3
What refactoring tools do you use for Python?
python,refactoring
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 ;)
74
-0.057081
14,046,877
-1
39,816
7
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.
28,796
2008-08-26T18:26:00.000
4
3
What refactoring tools do you use for Python?
python,refactoring
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.
74
0.113791
1,813,244
2
39,816
7
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.
28,796
2008-08-26T18:26:00.000
5
3
What refactoring tools do you use for Python?
python,refactoring
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.
74
0.141893
4,882,243
3
39,816
7
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.
28,796
2008-08-27T23:44:00.000
2
1
How do threads work in Python, and what are common Python-threading specific pitfalls?
python,multithreading
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).
89
0.057081
1,197,151
2
43,779
7
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.
31,340
2008-08-29T04:59:00.000
2
1
Find out how much memory is being used by an object in Python
python,performance,memory-profiling
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.
267
0.07983
24,495,011
2
222,118
5
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.
33,978
2008-08-29T05:43:00.000
2
3
Are Python threads buggy?
python,multithreading
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.
28
0.066568
576,667
2
12,462
6
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,020
2008-08-29T05:43:00.000
-2
3
Are Python threads buggy?
python,multithreading
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.
28
-0.066568
34,024
-1
12,462
6
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,020
2008-08-29T05:43:00.000
9
3
Are Python threads buggy?
python,multithreading
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!
28
1
34,078
3
12,462
6
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,020
2008-08-29T09:24:00.000
4
1
Python descriptor protocol analog in other languages?
python,language-features,encapsulation
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.
10
1.2
34,266
3
888
2
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,243
2008-08-29T15:05:00.000
132
1
Finding what methods a Python object has
python,introspection
false
The simplest method is to use dir(objectname). It will display all the methods available for that object.
592
1
20,100,900
7
564,030
22
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?
34,439
2008-08-30T03:04:00.000
2
1
Ruby "is" equivalent
python,ruby
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).
9
0.197375
39,062
2
473
2
Is there a Ruby equivalent for Python's "is"? It tests whether two objects are identical (i.e. have the same memory location).
35,634
2008-08-30T07:08:00.000
23
8
Is Python good for big software projects (not web based)?
python,ide
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.
29
1
35,777
5
29,152
13
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,753
2008-08-30T07:08:00.000
0
8
Is Python good for big software projects (not web based)?
python,ide
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.
29
0
277,490
0
29,152
13
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,753
2008-08-30T07:08:00.000
13
8
Is Python good for big software projects (not web based)?
python,ide
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.
29
1
35,759
4
29,152
13
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,753
2008-08-30T07:08:00.000
0
8
Is Python good for big software projects (not web based)?
python,ide
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.
29
0
35,838
0
29,152
13
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,753
2008-08-30T07:08:00.000
1
8
Is Python good for big software projects (not web based)?
python,ide
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.
29
0.015383
286,449
1
29,152
13
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,753
2008-08-30T07:08:00.000
1
8
Is Python good for big software projects (not web based)?
python,ide
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.
29
0.015383
286,491
1
29,152
13
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,753
2008-08-30T07:08:00.000
0
8
Is Python good for big software projects (not web based)?
python,ide
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.
29
0
3,445,481
0
29,152
13
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,753
2008-08-30T07:08:00.000
3
8
Is Python good for big software projects (not web based)?
python,ide
false
Refactoring is inevitable on larger codebases and the lack of static typing makes this much harder in python than in statically typed languages.
29
0.046121
35,841
2
29,152
13
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,753
2008-09-01T05:25:00.000
0
2
Filter out HTML tags and resolve entities in python
python,html
false
Looking at the amount of sense people are demonstrating in other answers here, I'd say that using a regex probably isn't the best idea for your situation. Go for something tried and tested, and treat my previous answer as a demonstration that regexes need not be that scary.
18
0
38,646
0
25,958
8
Because regular expressions scare me, I'm trying to find a way to remove all HTML tags and resolve HTML entities from a string in Python.
37,486
2008-09-01T05:25:00.000
0
2
Filter out HTML tags and resolve entities in python
python,html
false
Regular expressions are not scary, but writing your own regexes to strip HTML is a sure path to madness (and it won't work, either). Follow the path of wisdom, and use one of the many good HTML-parsing libraries. Lucas' example is also broken because "sub" is not a method of a Python string. You'd have to "import re", then call re.sub(pattern, repl, string). But that's neither here nor there, as the correct answer to your question does not involve writing any regexes.
18
0
37,604
0
25,958
8
Because regular expressions scare me, I'm trying to find a way to remove all HTML tags and resolve HTML entities from a string in Python.
37,486
2008-09-01T17:40:00.000
8
2
Why is the subprocess.Popen class not named Subprocess?
python,subprocess
true
Now, I'm not saying that this is the greatest name in the world, but here was the idea as I understand it. Originally, the popen family was in the os module and was an implementation of the venerable posix popen. The movement to the subprocess module would have been an opportune time to rename them, but I guess that keeping Popen makes it easier to find in the docs for those who have a long history with python or even to the venerable posix functions. From its earliest posix incarnation, Popen has always been meant to open a Process and allow you to read and write from its stdio like a file. Thus the mnemonic for Popen is that it is short for ProcessOpen in an attempt to kind of, sorta, look like open.
4
1.2
38,222
4
691
3
The primary class in the subprocess module is name Popen, and represents a subprocess. Popen sounds like someone was trying to force the name to follow some function naming format, rather than chosing a name that actually represents what the object is. Does anyone know why it was chosen over something simple like, say, Subprocess?
38,197
2008-09-01T17:40:00.000
-1
2
Why is the subprocess.Popen class not named Subprocess?
python,subprocess
false
I suppose the name was chosen because the functionality subprocess is replacing was formerly in the os module as the os.popen function. There could be even ways to automate migration between the two.
4
-0.066568
38,202
-1
691
3
The primary class in the subprocess module is name Popen, and represents a subprocess. Popen sounds like someone was trying to force the name to follow some function naming format, rather than chosing a name that actually represents what the object is. Does anyone know why it was chosen over something simple like, say, Subprocess?
38,197
2008-09-02T09:40:00.000
3
2
Finding a file in a Python module distribution
python,distutils
false
That's probably the way to do it, without resorting to something more advanced like using setuptools to install the files where they belong. Notice there's a problem with that approach, because on OSes with real a security framework (UNIXes, etc.) the user running your script might not have the rights to access the DB in the system directory where it gets installed.
32
0.148885
39,295
4
28,993
4
I've written a Python package that includes a bsddb database of pre-computed values for one of the more time-consuming computations. For simplicity, my setup script installs the database file in the same directory as the code which accesses the database (on Unix, something like /usr/lib/python2.5/site-packages/mypackage/). How do I store the final location of the database file so my code can access it? Right now, I'm using a hack based on the __file__ variable in the module which accesses the database: dbname = os.path.join(os.path.dirname(__file__), "database.dat") It works, but it seems... hackish. Is there a better way to do this? I'd like to have the setup script just grab the final installation location from the distutils module and stuff it into a "dbconfig.py" file that gets installed alongside the code that accesses the database.
39,104
2008-09-02T09:40:00.000
19
2
Finding a file in a Python module distribution
python,distutils
false
Use pkgutil.get_data. It’s the cousin of pkg_resources.resource_stream, but in the standard library, and should work with flat filesystem installs as well as zipped packages and other importers.
32
1
9,918,496
2
28,993
4
I've written a Python package that includes a bsddb database of pre-computed values for one of the more time-consuming computations. For simplicity, my setup script installs the database file in the same directory as the code which accesses the database (on Unix, something like /usr/lib/python2.5/site-packages/mypackage/). How do I store the final location of the database file so my code can access it? Right now, I'm using a hack based on the __file__ variable in the module which accesses the database: dbname = os.path.join(os.path.dirname(__file__), "database.dat") It works, but it seems... hackish. Is there a better way to do this? I'd like to have the setup script just grab the final installation location from the distutils module and stuff it into a "dbconfig.py" file that gets installed alongside the code that accesses the database.
39,104
2008-09-02T15:46:00.000
0
4
Using C in a shared multi-platform POSIX environment
python,c,cross-platform,posix,scripting
false
You know, you should look at static linking. These days, we all have HUGE hard drives, and a few extra megabytes (for carrying around libc and what not) is really not that big a deal anymore. You could also try running your applications in chroot() jails and distributing those.
2
0
39,865
0
293
4
I write tools that are used in a shared workspace. Since there are multiple OS's working in this space, we generally use Python and standardize the version that is installed across machines. However, if I wanted to write some things in C, I was wondering if maybe I could have the application wrapped in a Python script, that detected the operating system and fired off the correct version of the C application. Each platform has GCC available and uses the same shell. One idea was to have the C compiled to the users local ~/bin, with timestamp comparison with C code so it is not compiled each run, but only when code is updated. Another was to just compile it for each platform, and have the wrapper script select the proper executable. Is there an accepted/stable process for this? Are there any catches? Are there alternatives (assuming the absolute need to use native C code)? Clarification: Multiple OS's are involved that do not share ABI. Eg. OS X, various Linuxes, BSD etc. I need to be able to update the code in place in shared folders and have the new code working more or less instantaneously. Distributing binary or source packages is less than ideal.
39,847
2008-09-02T15:46:00.000
1
4
Using C in a shared multi-platform POSIX environment
python,c,cross-platform,posix,scripting
false
Also, you could use autoconf and distribute your application in source form only. :)
2
0.049958
39,878
1
293
4
I write tools that are used in a shared workspace. Since there are multiple OS's working in this space, we generally use Python and standardize the version that is installed across machines. However, if I wanted to write some things in C, I was wondering if maybe I could have the application wrapped in a Python script, that detected the operating system and fired off the correct version of the C application. Each platform has GCC available and uses the same shell. One idea was to have the C compiled to the users local ~/bin, with timestamp comparison with C code so it is not compiled each run, but only when code is updated. Another was to just compile it for each platform, and have the wrapper script select the proper executable. Is there an accepted/stable process for this? Are there any catches? Are there alternatives (assuming the absolute need to use native C code)? Clarification: Multiple OS's are involved that do not share ABI. Eg. OS X, various Linuxes, BSD etc. I need to be able to update the code in place in shared folders and have the new code working more or less instantaneously. Distributing binary or source packages is less than ideal.
39,847
2008-09-02T15:46:00.000
2
4
Using C in a shared multi-platform POSIX environment
python,c,cross-platform,posix,scripting
false
Launching a Python interpreter instance just to select the right binary to run would be much heavier than you need. I'd distribute a shell .rc file which provides aliases. In /shared/bin, you put the various binaries: /shared/bin/toolname-mac, /shared/bin/toolname-debian-x86, /shared/bin/toolname-netbsd-dreamcast, etc. Then, in the common shared shell .rc file, you put the logic to set the aliases according to platform, so that on OSX, it gets alias toolname=/shared/bin/toolname-mac, and so forth. This won't work as well if you're adding new tools all the time, because the users will need to reload the aliases. I wouldn't recommend distributing tools this way, though. Testing and qualifying new builds of the tools should be taking up enough time and effort that the extra time required to distribute the tools to the users is trivial. You seem to be optimizing to reduce the distribution time. Replacing tools that quickly in a live environment is all too likely to result in lengthy and confusing downtime if anything goes wrong in writing and building the tools--especially when subtle cross-platform issues creep in.
2
0.099668
40,367
2
293
4
I write tools that are used in a shared workspace. Since there are multiple OS's working in this space, we generally use Python and standardize the version that is installed across machines. However, if I wanted to write some things in C, I was wondering if maybe I could have the application wrapped in a Python script, that detected the operating system and fired off the correct version of the C application. Each platform has GCC available and uses the same shell. One idea was to have the C compiled to the users local ~/bin, with timestamp comparison with C code so it is not compiled each run, but only when code is updated. Another was to just compile it for each platform, and have the wrapper script select the proper executable. Is there an accepted/stable process for this? Are there any catches? Are there alternatives (assuming the absolute need to use native C code)? Clarification: Multiple OS's are involved that do not share ABI. Eg. OS X, various Linuxes, BSD etc. I need to be able to update the code in place in shared folders and have the new code working more or less instantaneously. Distributing binary or source packages is less than ideal.
39,847
2008-09-02T15:46:00.000
0
4
Using C in a shared multi-platform POSIX environment
python,c,cross-platform,posix,scripting
false
Depending on your mix os OSes, you might be better off creating packages for each class of system. Alternatively, if they all share the same ABI and hardware architecture, you could also compile static binaries.
2
0
39,871
0
293
4
I write tools that are used in a shared workspace. Since there are multiple OS's working in this space, we generally use Python and standardize the version that is installed across machines. However, if I wanted to write some things in C, I was wondering if maybe I could have the application wrapped in a Python script, that detected the operating system and fired off the correct version of the C application. Each platform has GCC available and uses the same shell. One idea was to have the C compiled to the users local ~/bin, with timestamp comparison with C code so it is not compiled each run, but only when code is updated. Another was to just compile it for each platform, and have the wrapper script select the proper executable. Is there an accepted/stable process for this? Are there any catches? Are there alternatives (assuming the absolute need to use native C code)? Clarification: Multiple OS's are involved that do not share ABI. Eg. OS X, various Linuxes, BSD etc. I need to be able to update the code in place in shared folders and have the new code working more or less instantaneously. Distributing binary or source packages is less than ideal.
39,847
2008-09-03T13:48:00.000
3
1
Splitting tuples in Python - best practice?
python,tuples
false
Perhaps this is overkill for your case, but I would be tempted to create a "Job" class that takes the tuple as its constructor argument and has respective properties on it. I'd then pass instances of this class around instead.
13
0.066568
41,721
2
9,634
9
I have a method in my Python code that returns a tuple - a row from a SQL query. Let's say it has three fields: (jobId, label, username) For ease of passing it around between functions, I've been passing the entire tuple as a variable called 'job'. Eventually, however, I want to get at the bits, so I've been using code like this: (jobId, label, username) = job I've realised, however, that this is a maintenance nightmare, because now I can never add new fields to the result set without breaking all of my existing code. How should I have written this? Here are my two best guesses: (jobId, label, username) = (job[0], job[1], job[2]) ...but that doesn't scale nicely when you have 15...20 fields or to convert the results from the SQL query to a dictionary straight away and pass that around (I don't have control over the fact that it starts life as a tuple, that's fixed for me)
41,701
2008-09-03T16:13:00.000
65
5
What is a tuple useful for?
python,tuples
true
Tuples are used whenever you want to return multiple results from a function. Since they're immutable, they can be used as keys for a dictionary (lists can't).
56
1.2
42,048
7
46,193
11
I am learning Python for a class now, and we just covered tuples as one of the data types. I read the Wikipedia page on it, but, I could not figure out where such a data type would be useful in practice. Can I have some examples, perhaps in Python, where an immutable set of numbers would be needed? How is this different from a list?
42,034
2008-09-03T16:13:00.000
2
5
What is a tuple useful for?
python,tuples
false
I find them useful when you always deal with two or more objects as a set.
56
0.036348
42,049
2
46,193
11
I am learning Python for a class now, and we just covered tuples as one of the data types. I read the Wikipedia page on it, but, I could not figure out where such a data type would be useful in practice. Can I have some examples, perhaps in Python, where an immutable set of numbers would be needed? How is this different from a list?
42,034
2008-09-03T16:13:00.000
0
5
What is a tuple useful for?
python,tuples
false
In addition to the places where they're syntactically required like the string % operation and for multiple return values, I use tuples as a form of lightweight classes. For example, suppose you have an object that passes out an opaque cookie to a caller from one method which is then passed into another method. A tuple is a good way to pack multiple values into that cookie without having to define a separate class to contain them. I try to be judicious about this particular use, though. If the cookies are used liberally throughout the code, it's better to create a class because it helps document their use. If they are only used in one place (e.g. one pair of methods) then I might use a tuple. In any case, because it's Python you can start with a tuple and then change it to an instance of a custom class without having to change any code in the caller.
56
0
51,200
0
46,193
11
I am learning Python for a class now, and we just covered tuples as one of the data types. I read the Wikipedia page on it, but, I could not figure out where such a data type would be useful in practice. Can I have some examples, perhaps in Python, where an immutable set of numbers would be needed? How is this different from a list?
42,034
2008-09-03T16:13:00.000
4
5
What is a tuple useful for?
python,tuples
false
Tuples and lists have the same uses in general. Immutable data types in general have many benefits, mostly about concurrency issues. So, when you have lists that are not volatile in nature and you need to guarantee that no consumer is altering it, you may use a tuple. Typical examples are fixed data in an application like company divisions, categories, etc. If this data change, typically a single producer rebuilts the tuple.
56
0.072599
42,060
2
46,193
11
I am learning Python for a class now, and we just covered tuples as one of the data types. I read the Wikipedia page on it, but, I could not figure out where such a data type would be useful in practice. Can I have some examples, perhaps in Python, where an immutable set of numbers would be needed? How is this different from a list?
42,034
2008-09-03T16:13:00.000
1
5
What is a tuple useful for?
python,tuples
false
A tuple is useful for storing multiple values.. As you note a tuple is just like a list that is immutable - e.g. once created you cannot add/remove/swap elements. One benefit of being immutable is that because the tuple is fixed size it allows the run-time to perform certain optimizations. This is particularly beneficial when a tupple is used in the context of a return value or a parameter to a function.
56
0.01818
42,055
1
46,193
11
I am learning Python for a class now, and we just covered tuples as one of the data types. I read the Wikipedia page on it, but, I could not figure out where such a data type would be useful in practice. Can I have some examples, perhaps in Python, where an immutable set of numbers would be needed? How is this different from a list?
42,034
2008-09-03T21:52:00.000
4
3
Which Dynamic .NET language makes more sense to learn, Iron Ruby or Iron Python?
.net,ironpython,ironruby,dynamic-language-runtime,dynamic-languages
true
If this is 'Which language runs better on the CLR,' then right now, IronPython wins hands down. For the long term though, 'which language will teach me more, and serve me better in my career as a programmer', I would definitely say IronRuby (this would be true of CPython vs CRuby also) Ruby will expose you to more 'concepts' than python does, due to it being more liberal in how it handles things like lambda functions, code blocks, eval, and so on. Anyway, this is probably going to descend into a flame-war. Sorry
5
1.2
61,734
4
1,222
6
I'd like to take some time to learn more about dynamic languages built on top of the DLR and I'm not sure which language would be better to learn. Having limited time, I really only have time to look learn one of them. Any opinions on which of the two (Iron Ruby or Iron Python) would be more useful in the long run?
42,690
2008-09-03T21:52:00.000
1
3
Which Dynamic .NET language makes more sense to learn, Iron Ruby or Iron Python?
.net,ironpython,ironruby,dynamic-language-runtime,dynamic-languages
false
I just want to mention that there is also a DLR version of Javascript(JScript), which is my personal fav. If you are looking for a new language to learn for dlr use, I'd suggest ironpython as mentioned, it is farther along in terms of the dlr. Python is also fairly popular outside the dlr for gui programming, and offers Django for mvc web apps. This is purely subjective, but I think that ruby popularity is waning a bit. In the long run I feel it will be like perl, used and respected, but a drop in the bucket compared to other options. I happen to really like ruby (and perl), but wouldn't suggest it as a new path for your intended purpose.
5
0.033321
467,185
1
1,222
6
I'd like to take some time to learn more about dynamic languages built on top of the DLR and I'm not sure which language would be better to learn. Having limited time, I really only have time to look learn one of them. Any opinions on which of the two (Iron Ruby or Iron Python) would be more useful in the long run?
42,690
2008-09-03T21:52:00.000
5
3
Which Dynamic .NET language makes more sense to learn, Iron Ruby or Iron Python?
.net,ironpython,ironruby,dynamic-language-runtime,dynamic-languages
false
Without getting into the relative merits of the languages (which would be an entire pissing contest in itself), IronPython (stable 1.1.1, beta 2.0) is further along in development than IronRuby (alpha)
5
0.16514
42,702
2
1,222
6
I'd like to take some time to learn more about dynamic languages built on top of the DLR and I'm not sure which language would be better to learn. Having limited time, I really only have time to look learn one of them. Any opinions on which of the two (Iron Ruby or Iron Python) would be more useful in the long run?
42,690
2008-09-04T13:36:00.000
16
6
Modulus operation with negatives values - weird thing?
python,math,modulo
true
By the way: most programming languages would disagree with Python and give the result -2. Depending on the interpretation of modulus this is correct. However, the most agreed-upon mathematical definition states that the modulus of a and b is the (strictly positive) rest r of the division of a / b. More precisely, 0 <= r < b by definition.
18
1.2
43,794
5
11,706
12
Can you please tell me how much is (-2) % 5? According to my Python interpreter is 3, but do you have a wise explanation for this? I've read that in some languages the result can be machine-dependent, but I'm not sure though.
43,775
2008-09-04T13:36:00.000
14
6
Modulus operation with negatives values - weird thing?
python,math,modulo
false
Your Python interpreter is correct. One (stupid) way of calculating a modulus is to subtract or add the modulus until the resulting value is between 0 and (modulus − 1). e.g.: 13 mod 5 = (13 − 5) mod 5 = (13 − 10) mod 5 = 3 or in your case: −2 mod 5 = (−2 + 5) mod 5 = 3
18
1
43,780
4
11,706
12
Can you please tell me how much is (-2) % 5? According to my Python interpreter is 3, but do you have a wise explanation for this? I've read that in some languages the result can be machine-dependent, but I'm not sure though.
43,775
2008-09-04T13:36:00.000
0
6
Modulus operation with negatives values - weird thing?
python,math,modulo
false
Well, -2 divided by 5 would be 0 with a remainder of 3. I don't believe that should be very platform dependent, but I've seen stranger things.
18
0
43,781
0
11,706
12
Can you please tell me how much is (-2) % 5? According to my Python interpreter is 3, but do you have a wise explanation for this? I've read that in some languages the result can be machine-dependent, but I'm not sure though.
43,775
2008-09-04T13:36:00.000
4
6
Modulus operation with negatives values - weird thing?
python,math,modulo
false
Well, 0 % 5 should be 0, right? -1 % 5 should be 4 because that's the next allowed digit going in the reverse direction (i.e., it can't be 5, since that's out of range). And following along by that logic, -2 must be 3. The easiest way to think of how it will work is that you keep adding or subtracting 5 until the number falls between 0 (inclusive) and 5 (exclusive). I'm not sure about machine dependence - I've never seen an implementation that was, but I can't say it's never done.
18
0.066568
43,785
2
11,706
12
Can you please tell me how much is (-2) % 5? According to my Python interpreter is 3, but do you have a wise explanation for this? I've read that in some languages the result can be machine-dependent, but I'm not sure though.
43,775
2008-09-04T13:36:00.000
0
6
Modulus operation with negatives values - weird thing?
python,math,modulo
false
The result depends on the language. Python returns the sign of the divisor, where for example c# returns the sign of the dividend (ie. -2 % 5 returns -2 in c#).
18
0
43,799
0
11,706
12
Can you please tell me how much is (-2) % 5? According to my Python interpreter is 3, but do you have a wise explanation for this? I've read that in some languages the result can be machine-dependent, but I'm not sure though.
43,775
2008-09-04T13:36:00.000
0
6
Modulus operation with negatives values - weird thing?
python,math,modulo
false
There seems to be a common confusion between the terms "modulo" and "remainder". In math, a remainder should always be defined consistent with the quotient, so that if a / b == c rem d then (c * b) + d == a. Depending on how you round your quotient, you get different remainders. However, modulo should always give a result 0 <= r < divisor, which is only consistent with round-to-minus-infinity division if you allow negative integers. If division rounds towards zero (which is common), modulo and remainder are only equivalent for non-negative values. Some languages (notably C and C++) don't define the required rounding/remainder behaviours and % is ambiguous. Many define rounding as towards zero, yet use the term modulo where remainder would be more correct. Python is relatively unusual in that it rounds to negative infinity, so modulo and remainder are equivalent. Ada rounds towards zero IIRC, but has both mod and rem operators. The C policy is intended to allow compilers to choose the most efficient implementation for the machine, but IMO is a false optimisation, at least these days. A good compiler will probably be able to use the equivalence for optimisation wherever a negative number cannot occur (and almost certainly if you use unsigned types). On the other hand, where negative numbers can occur, you almost certainly care about the details - for portability reasons you have to use very carefully designed overcomplex algorithms and/or checks to ensure that you get the results you want irrespective of the rounding and remainder behaviour. In other words, the gain for this "optimisation" is mostly (if not always) an illusion, whereas there are very real costs in some cases - so it's a false optimisation.
18
0
5,203,460
0
11,706
12
Can you please tell me how much is (-2) % 5? According to my Python interpreter is 3, but do you have a wise explanation for this? I've read that in some languages the result can be machine-dependent, but I'm not sure though.
43,775
2008-09-04T16:15:00.000
1
4
invisible watermarks in images
python,image,watermark
false
What about Exif? It's probably not as secure as what you're thinking, but most users don't even know it exists and if you make it that easy to read the watermark information those who care will still be able to do it anyway.
12
0.01818
44,132
1
13,301
11
How do you insert invisible watermarks in images for copyright purposes? I'm looking for a python library. What algorithm do you use? What about performance and efficiency?
44,101
2008-09-04T16:15:00.000
2
4
invisible watermarks in images
python,image,watermark
false
Well, invisible watermarking is not that easy. Check digimarc, what money did they earn on it. There is no free C/Python code that a lonely genius has written a leave it for free usage. I've implemented my own algorithm and the name of the tool is SignMyImage. Google it if interested ... F>
12
0.036348
541,170
2
13,301
11
How do you insert invisible watermarks in images for copyright purposes? I'm looking for a python library. What algorithm do you use? What about performance and efficiency?
44,101
2008-09-04T16:15:00.000
6
4
invisible watermarks in images
python,image,watermark
false
You might want to look into Steganography; that is hiding data inside of images. There are forms that won't get lost if you convert to a lossier format or even crop parts of the image out.
12
1
44,217
3
13,301
11
How do you insert invisible watermarks in images for copyright purposes? I'm looking for a python library. What algorithm do you use? What about performance and efficiency?
44,101
2008-09-04T16:15:00.000
0
4
invisible watermarks in images
python,image,watermark
false
I was going to post an answer similar to Ugh. I would suggest putting a small TXT file describing the image source (and perhaps a small copyright statement, if one applies) into the image in a manner that is difficult to detect and break.
12
0
44,221
0
13,301
11
How do you insert invisible watermarks in images for copyright purposes? I'm looking for a python library. What algorithm do you use? What about performance and efficiency?
44,101
2008-09-04T21:28:00.000
797
1
What does __all__ mean in Python?
python,syntax,namespaces
true
It's a list of public objects of that module, as interpreted by import *. It overrides the default of hiding everything that begins with an underscore.
1,420
1.2
44,842
11
473,666
11
I see __all__ in __init__.py files. What does it do?
44,834
2008-09-05T10:26:00.000
1
1
Is there a Python library for generating .ico files?
python,favicon
false
I don't know if this applies for all cases, but on WinXP an .ico can be a bmp of size 16x16, 32x32 or 64x64. Just change the extension to ico from bmp and you're ready to go.
32
0.028564
45,520
1
25,030
7
I'm looking to create favicon.ico files programatically from Python, but PIL only has support for reading ico files.
45,507
2008-09-06T02:22:00.000
0
2
Which Version of Python to Use for Maximum Compatibility
python,compatibility
false
If the project is going to be mainstream and will be run on Linux the only sensible choise is 2.4 - just because it is a pain to get anything else installed as default on Enterprise Linuxes. In any case, any modern OS will/can have 2.4 or newer.
15
0
2,036,609
0
3,460
6
If I was going to start an open source project using Python what version should I use to ensure that the vast majority of users can use it on their system? I'm the kind of person who quickly jumps to the next version (which I'll do when Python 3 comes out) but many people may be more conservative if their current version seems to be working fine. What version would hit the sweet spot but still allow me to enjoy the newest and coolest language enhancements?
47,198
2008-09-06T02:22:00.000
1
2
Which Version of Python to Use for Maximum Compatibility
python,compatibility
false
You can use different versions of python on each machine. Coding something new, I would not use anything less than python2.5. You can do apt-get install python2.5 on stock debian stable. For windows, don't really worry about it. It's very easy to install the python2.5 msi. If the users can't be bothered to do that, you can deploy an executable with py2exe (so simple) and build an installer with inno setup (again simple) then it will behave like a standard windows application and will use its own python dlls, so no need to have python installed. Like Peter said: keep in mind the transition to 3.0 but don't build on it yet.
15
0.033321
47,264
1
3,460
6
If I was going to start an open source project using Python what version should I use to ensure that the vast majority of users can use it on their system? I'm the kind of person who quickly jumps to the next version (which I'll do when Python 3 comes out) but many people may be more conservative if their current version seems to be working fine. What version would hit the sweet spot but still allow me to enjoy the newest and coolest language enhancements?
47,198
2008-09-06T18:14:00.000
4
1
Is there a way to attach a debugger to a multi-threaded Python process?
python,debugging
false
My experience debugging multi-threaded programs in PyDev (Eclipse on Windows XP) is, threads created using thread.start_new_thread could not be hooked, but thread created using threading.Thread could be hooked. Hope the information is helpful.
35
0.07983
277,800
2
34,732
10
I'm trying to debug a deadlock in a multi-threaded Python application after it has locked up. Is there a way to attach a debugger to inspect the state of the process? Edit: I'm attempting this on Linux, but it would be great if there were a cross-platform solution. It's Python after all :)
47,701
2008-09-06T23:35:00.000
1
3
What are the advantages of packaging your python library/application as an .egg file?
python,zip,packaging,software-distribution,egg
false
For simple Python programs, you probably don't need to use eggs. Distributing the raw .py files should suffice; it's like distributing source files for GNU/Linux. You can also use the various OS "packagers" (like py2exe or py2app) to create .exe, .dmg, or other files for different operating systems. More complex programs, e.g. Django, pretty much require eggs due to the various modules and dependencies required.
27
0.033321
138,090
1
10,471
6
I've read some about .egg files and I've noticed them in my lib directory but what are the advantages/disadvantages of using then as a developer?
47,953
2008-09-06T23:35:00.000
1
3
What are the advantages of packaging your python library/application as an .egg file?
python,zip,packaging,software-distribution,egg
false
Whatever you do, do not stop distributing your application, also, as a tarball, as that is the easiest packagable format for operating systems with a package sysetem.
27
0.033321
137,903
1
10,471
6
I've read some about .egg files and I've noticed them in my lib directory but what are the advantages/disadvantages of using then as a developer?
47,953
2008-09-06T23:35:00.000
4
3
What are the advantages of packaging your python library/application as an .egg file?
python,zip,packaging,software-distribution,egg
false
Eggs are a pretty good way to distribute python apps. Think of it as a platform independent .deb file that will install all dependencies and whatnot. The advantage is that it's easy to use for the end user. The disadvantage are that it can be cumbersome to package your app up as a .egg file. You should also offer an alternative means of installation in addition to .eggs. There are some people who don't like using eggs because they don't like the idea of a software program installing whatever software it wants. These usually tend to be sysadmin types.
27
0.132549
47,958
2
10,471
6
I've read some about .egg files and I've noticed them in my lib directory but what are the advantages/disadvantages of using then as a developer?
47,953
2008-09-07T04:00:00.000
1
8
Glade or no glade: What is the best way to use PyGtk?
python,gtk,pygtk,glade,gtk2
false
Personally I would recommend coding it out instead of using Glade. I'm still learning python and pyGtk but I will say that writing out the UI by hand gave me a lot of insight on how things work under the hood. Once you have it learned I'd say to give glade, or other UI designers a try but definitely learn how to do it the "hard" way first.
32
0.01818
751,707
1
8,539
11
I've been learning python for a while now with some success. I even managed to create one or two (simple) programs using PyGtk + Glade. The thing is: I am not sure if the best way to use GTK with python is by building the interfaces using Glade. I was wondering if the more experienced ones among us (remember, I'm just a beginner) could point out the benefits and caveats of using Glade as opposed to creating everything in the code itself (assuming that learning the correct gtk bindings wouldn't exactly be a problem).
48,123
2008-09-07T04:00:00.000
1
8
Glade or no glade: What is the best way to use PyGtk?
python,gtk,pygtk,glade,gtk2
false
For quick and simple screens I use Glade. But for anything that needs finer levels of control, I create a custom classes for what I actually need (this is important, because it's too easy to get carried away with generalisations). With a skinny applications specific classes, I can rapidly change the look and feel application wide from a single place. Rather like using CSS to mantain consistency for web sites.
32
0.01818
199,167
1
8,539
11
I've been learning python for a while now with some success. I even managed to create one or two (simple) programs using PyGtk + Glade. The thing is: I am not sure if the best way to use GTK with python is by building the interfaces using Glade. I was wondering if the more experienced ones among us (remember, I'm just a beginner) could point out the benefits and caveats of using Glade as opposed to creating everything in the code itself (assuming that learning the correct gtk bindings wouldn't exactly be a problem).
48,123
2008-09-07T04:00:00.000
5
8
Glade or no glade: What is the best way to use PyGtk?
python,gtk,pygtk,glade,gtk2
false
I started out using glade, but soon moved to just doing everything in code. Glade is nice for simple things, and it's good when you're learning how GTK organizes the widgets (how things are packed, etc). Constructing everything in code, however, you have much more flexibility. Plus, you don't have the glade dependency.
32
0.090659
106,889
3
8,539
11
I've been learning python for a while now with some success. I even managed to create one or two (simple) programs using PyGtk + Glade. The thing is: I am not sure if the best way to use GTK with python is by building the interfaces using Glade. I was wondering if the more experienced ones among us (remember, I'm just a beginner) could point out the benefits and caveats of using Glade as opposed to creating everything in the code itself (assuming that learning the correct gtk bindings wouldn't exactly be a problem).
48,123
2008-09-07T04:00:00.000
2
8
Glade or no glade: What is the best way to use PyGtk?
python,gtk,pygtk,glade,gtk2
false
I recommend using Glade for rapid development, but not for learning. Why? because some times you will need to tune up some widgets in order to work as you want they to work, and if you don't really know/understand the properties attributes of every widget then you will be in troubles.
32
0.036348
305,667
2
8,539
11
I've been learning python for a while now with some success. I even managed to create one or two (simple) programs using PyGtk + Glade. The thing is: I am not sure if the best way to use GTK with python is by building the interfaces using Glade. I was wondering if the more experienced ones among us (remember, I'm just a beginner) could point out the benefits and caveats of using Glade as opposed to creating everything in the code itself (assuming that learning the correct gtk bindings wouldn't exactly be a problem).
48,123
2008-09-07T04:00:00.000
4
8
Glade or no glade: What is the best way to use PyGtk?
python,gtk,pygtk,glade,gtk2
false
I usually start with Glade until I come to a point where it doesn't have the features I need, e.g. creating a wizard. As long as I'm using the standard widgets that Glade provides, there's really no reason to hand-code the GUI. The more comfortable I become with how Glade formats the code, the better my hand-coding becomes. Not to mention, it's real easy to use Glade to make the underlying framework so you don't have to worry about all the initializations.
32
0.072599
107,959
2
8,539
11
I've been learning python for a while now with some success. I even managed to create one or two (simple) programs using PyGtk + Glade. The thing is: I am not sure if the best way to use GTK with python is by building the interfaces using Glade. I was wondering if the more experienced ones among us (remember, I'm just a beginner) could point out the benefits and caveats of using Glade as opposed to creating everything in the code itself (assuming that learning the correct gtk bindings wouldn't exactly be a problem).
48,123
2008-09-07T04:00:00.000
2
8
Glade or no glade: What is the best way to use PyGtk?
python,gtk,pygtk,glade,gtk2
false
First, start to put this in perspective. You will be using GTK. This is a huge C library built in 1993 using the best traditions of 1970s coding style. It was built to help implement the GIMP, a Photoshop competitor wanna-be with user interface blunders of legend. A typical gui field might have forty or more parameters, mostly repetitive, having getters and setters. There will be pain. The GTK itself manages a complete dynamic type system in C using GObject. This makes debugging a special joy that requires manually walking through arrays of pointers to methods full of generic argument lists with implicit inheritance. You will also be jumping through Pango libraries when you least expect it, e.g., using a Pango constant for where in a label the ellipsis go when the page is small. Expect more pain. By now, you are probably vowing to wrap all your GTK interactions in a Model-View-Controller architecture specific to your application. This is good. Using Glade, or gtkBuilder, or Stetic, will help coral the huge coupling problem of forty parameters to a function. Glade provides a basic GUI builder to drag and drop components together. The parameters and inherited parameters are somewhat separated out. The output of Glade is .glade XML file which you will then read in, attach your callbacks ("signal handlers") to identically named functions, and query or update the in-memory version of that XML to get widgets that you then use pyGTK to manipulate. Glade itself is a creaky and not well maintained. Using pyGTK gives you annoyingly fine grained control in order to build your GUI. This will be verbose, copy-and-paste code. Each attribute will be a separate function call. The attribute setter does not return anything, so chaining the calls is out of the question. Usually, your IDE will give only minimal help on what functions mean and you will be constantly referring to DevHelp or some other tool. One would almost expect GTK GUIs were meant to fail.
32
0.036348
2,149,087
2
8,539
11
I've been learning python for a while now with some success. I even managed to create one or two (simple) programs using PyGtk + Glade. The thing is: I am not sure if the best way to use GTK with python is by building the interfaces using Glade. I was wondering if the more experienced ones among us (remember, I'm just a beginner) could point out the benefits and caveats of using Glade as opposed to creating everything in the code itself (assuming that learning the correct gtk bindings wouldn't exactly be a problem).
48,123
2008-09-07T04:00:00.000
5
8
Glade or no glade: What is the best way to use PyGtk?
python,gtk,pygtk,glade,gtk2
false
Glade is very useful for creating interfaces, it means you can easily change the GUI without doing much coding. You'll find that if you want to do anything useful (e.g. build a treeview) you will have to get familiar with various parts of the GTK documentation - in practice finding a good tutorial/examples.
32
0.090659
54,313
3
8,539
11
I've been learning python for a while now with some success. I even managed to create one or two (simple) programs using PyGtk + Glade. The thing is: I am not sure if the best way to use GTK with python is by building the interfaces using Glade. I was wondering if the more experienced ones among us (remember, I'm just a beginner) could point out the benefits and caveats of using Glade as opposed to creating everything in the code itself (assuming that learning the correct gtk bindings wouldn't exactly be a problem).
48,123
2008-09-07T04:00:00.000
12
8
Glade or no glade: What is the best way to use PyGtk?
python,gtk,pygtk,glade,gtk2
false
Use GtkBuilder instead of Glade, it's integrated into Gtk itself instead of a separate library. The main benefit of Glade is that it's much, much easier to create the interface. It's a bit more work to connect signal handlers, but I've never felt that matters much.
32
1
48,136
4
8,539
11
I've been learning python for a while now with some success. I even managed to create one or two (simple) programs using PyGtk + Glade. The thing is: I am not sure if the best way to use GTK with python is by building the interfaces using Glade. I was wondering if the more experienced ones among us (remember, I'm just a beginner) could point out the benefits and caveats of using Glade as opposed to creating everything in the code itself (assuming that learning the correct gtk bindings wouldn't exactly be a problem).
48,123
2008-09-08T03:59:00.000
3
2
How can I make an EXE file from a Python program?
python,exe,executable
false
Use cx_Freeze to make exe your python program
115
0.085505
15,667,090
2
289,620
7
I've used several modules to make EXEs for Python, but I'm not sure if I'm doing it right. How should I go about this, and why? Please base your answers on personal experience, and provide references where necessary.
49,146
2008-09-08T03:59:00.000
4
2
How can I make an EXE file from a Python program?
python,exe,executable
false
Also known as Frozen Binaries but not the same as as the output of a true compiler- they run byte code through a virtual machine (PVM). Run the same as a compiled program just larger because the program is being compiled along with the PVM. Py2exe can freeze standalone programs that use the tkinter, PMW, wxPython, and PyGTK GUI libraties; programs that use the pygame game programming toolkit; win32com client programs; and more. The Stackless Python system is a standard CPython implementation variant that does not save state on the C language call stack. This makes Python more easy to port to small stack architectures, provides efficient multiprocessing options, and fosters novel programming structures such as coroutines. Other systems of study that are working on future development: Pyrex is working on the Cython system, the Parrot project, the PyPy is working on replacing the PVM altogether, and of course the founder of Python is working with Google to get Python to run 5 times faster than C with the Unladen Swallow project. In short, py2exe is the easiest and Cython is more efficient for now until these projects improve the Python Virtual Machine (PVM) for standalone files.
115
0.113791
10,241,354
2
289,620
7
I've used several modules to make EXEs for Python, but I'm not sure if I'm doing it right. How should I go about this, and why? Please base your answers on personal experience, and provide references where necessary.
49,146
2008-09-08T08:25:00.000
-2
1
Can parallel traversals be done in MATLAB just as in Python?
python,arrays,matlab,for-loop
false
for loops in MATLAB used to be slow, but this is not true anymore. So vectorizing is not always the miracle solution. Just use the profiler, and tic and toc functions to help you identify possible bottlenecks.
14
-0.057081
138,886
-1
7,417
7
Using the zip function, Python allows for loops to traverse multiple sequences in parallel. for (x,y) in zip(List1, List2): Does MATLAB have an equivalent syntax? If not, what is the best way to iterate over two parallel arrays at the same time using MATLAB?
49,307
2008-09-08T14:36:00.000
47
2
Java -> Python?
java,python
true
List comprehensions. I often find myself filtering/mapping lists, and being able to say [line.replace("spam","eggs") for line in open("somefile.txt") if line.startswith("nee")] is really nice. Functions are first class objects. They can be passed as parameters to other functions, defined inside other function, and have lexical scope. This makes it really easy to say things like people.sort(key=lambda p: p.age) and thus sort a bunch of people on their age without having to define a custom comparator class or something equally verbose. Everything is an object. Java has basic types which aren't objects, which is why many classes in the standard library define 9 different versions of functions (for boolean, byte, char, double, float, int, long, Object, short). Array.sort is a good example. Autoboxing helps, although it makes things awkward when something turns out to be null. Properties. Python lets you create classes with read-only fields, lazily-generated fields, as well as fields which are checked upon assignment to make sure they're never 0 or null or whatever you want to guard against, etc.' Default and keyword arguments. In Java if you want a constructor that can take up to 5 optional arguments, you must define 6 different versions of that constructor. And there's no way at all to say Student(name="Eli", age=25) Functions can only return 1 thing. In Python you have tuple assignment, so you can say spam, eggs = nee() but in Java you'd need to either resort to mutable out parameters or have a custom class with 2 fields and then have two additional lines of code to extract those fields. Built-in syntax for lists and dictionaries. Operator Overloading. Generally better designed libraries. For example, to parse an XML document in Java, you say Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse("test.xml"); and in Python you say doc = parse("test.xml") Anyway, I could go on and on with further examples, but Python is just overall a much more flexible and expressive language. It's also dynamically typed, which I really like, but which comes with some disadvantages. Java has much better performance than Python and has way better tool support. Sometimes those things matter a lot and Java is the better language than Python for a task; I continue to use Java for some new projects despite liking Python a lot more. But as a language I think Python is superior for most things I find myself needing to accomplish.
29
1.2
49,953
7
11,654
5
Besides the dynamic nature of Python (and the syntax), what are some of the major features of the Python language that Java doesn't have, and vice versa?
49,824

SO dataset of python tag data and "Python basics and Envirinment" subcategory

Question filters:

  • images
  • links
  • code blocks
  • 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
2
Edit dataset card