Q_Id
int64
337
49.3M
CreationDate
stringlengths
23
23
Users Score
int64
-42
1.15k
Other
int64
0
1
Python Basics and Environment
int64
0
1
System Administration and DevOps
int64
0
1
Tags
stringlengths
6
105
A_Id
int64
518
72.5M
AnswerCount
int64
1
64
is_accepted
bool
2 classes
Web Development
int64
0
1
GUI and Desktop Applications
int64
0
1
Answer
stringlengths
6
11.6k
Available Count
int64
1
31
Q_Score
int64
0
6.79k
Data Science and Machine Learning
int64
0
1
Question
stringlengths
15
29k
Title
stringlengths
11
150
Score
float64
-1
1.2
Database and SQL
int64
0
1
Networking and APIs
int64
0
1
ViewCount
int64
8
6.81M
35,922
2008-08-30T12:19:00.000
1
0
0
0
python,user-interface
36,761
5
false
0
1
I use pyGtk. I think wxPython is nice but it's too limited, and PyQt is, well, Qt. =)
1
19
0
I've played around with GTK, TK, wxPython, Cocoa, curses and others. They are are fairly horrible to use.. GTK/TK/wx/curses all seem to basically be direct-ports of the appropriate C libraries, and Cocoa basically mandates using both PyObjC and Interface Builder, both of which I dislike.. The Shoes GUI library for Ruby is great.. It's very sensibly designed, and very "rubyish", and borrows some nice-to-use things from web development (like using hex colours codes, or :color => rgb(128,0,0)) As the title says: are there any nice, "Pythonic" GUI toolkits?
Are there any "nice to program" GUI toolkits for Python?
0.039979
0
0
10,824
36,647
2008-08-31T05:07:00.000
1
1
0
0
python,unit-testing
1,310,119
9
false
0
0
I recommend Nose. After the reasonable simple installation, you just have to run "nosetests" in your project folder and Nose will find all your tests and run them. I also like the collection of plugins (coverage, GAE, etc.) and the abilty to call Nose directly from within my Python scripts.
3
20
0
Does Python have a unit testing framework compatible with the standard xUnit style of test framework? If so, what is it, where is it, and is it any good?
Unit tests in Python
0.022219
0
0
8,490
36,647
2008-08-31T05:07:00.000
0
1
0
0
python,unit-testing
2,194,729
9
false
0
0
nose seems to be the best combination of flexibility and convenience. It runs unittests, doctests, coverage (with an extension) and py.test-like tests from one framework and does so admirably. It has enough popularity that it has had some IDE integration done as well for Komodo Edit and I wouldn't be surprised to see it elsewhere as well. I like it for one strong reason: I almost always doctest before writing more extensive tests in another framework. This is because, for basic tests, doctests kill two birds with one stone. You get executable tests (although they are a bit clumsy to write well sometimes) as well as API documentation and interactive documentation at the same time. nose will run these with the bundled doctest extension when you use a command-line option (--with-doctest). I say this having come from py.test as my former favorite. While it is great, nose tests are similar enough to me that I don't miss it, and I like the integration of the various test methodologies under one roof, so to speak. YMMV, but I recommend taking a good look at nose before choosing another. If you aren't familiar with py.test tests, you should look at them as well. I find them terrific because they are usually written in such a way that they can be easily debugged without the testing framework, which makes one less tricky system involved in the debugging session. I find that alone invaluable, while they are also easier to write than unittest tests in my opinion.
3
20
0
Does Python have a unit testing framework compatible with the standard xUnit style of test framework? If so, what is it, where is it, and is it any good?
Unit tests in Python
0
0
0
8,490
36,647
2008-08-31T05:07:00.000
2
1
0
0
python,unit-testing
36,654
9
false
0
0
@Greg: PyUnit is included in the standard library as unittest
3
20
0
Does Python have a unit testing framework compatible with the standard xUnit style of test framework? If so, what is it, where is it, and is it any good?
Unit tests in Python
0.044415
0
0
8,490
37,486
2008-09-01T05:25:00.000
0
0
1
0
python,html
38,646
8
false
1
0
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.
2
18
0
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.
Filter out HTML tags and resolve entities in python
0
0
0
25,958
37,486
2008-09-01T05:25:00.000
0
0
1
0
python,html
37,604
8
false
1
0
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.
2
18
0
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.
Filter out HTML tags and resolve entities in python
0
0
0
25,958
38,197
2008-09-01T17:40:00.000
8
0
1
1
python,subprocess
38,222
3
true
0
0
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.
2
4
0
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?
Why is the subprocess.Popen class not named Subprocess?
1.2
0
0
691
38,197
2008-09-01T17:40:00.000
-1
0
1
1
python,subprocess
38,202
3
false
0
0
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.
2
4
0
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?
Why is the subprocess.Popen class not named Subprocess?
-0.066568
0
0
691
39,104
2008-09-02T09:40:00.000
19
0
1
0
python,distutils
9,918,496
4
false
0
0
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.
2
32
0
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.
Finding a file in a Python module distribution
1
1
0
28,993
39,104
2008-09-02T09:40:00.000
3
0
1
0
python,distutils
39,295
4
false
0
0
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.
2
32
0
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.
Finding a file in a Python module distribution
0.148885
1
0
28,993
39,847
2008-09-02T15:46:00.000
0
0
1
1
python,c,cross-platform,posix,scripting
39,865
4
false
0
0
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.
4
2
0
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.
Using C in a shared multi-platform POSIX environment
0
0
0
293
39,847
2008-09-02T15:46:00.000
1
0
1
1
python,c,cross-platform,posix,scripting
39,878
4
false
0
0
Also, you could use autoconf and distribute your application in source form only. :)
4
2
0
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.
Using C in a shared multi-platform POSIX environment
0.049958
0
0
293
39,847
2008-09-02T15:46:00.000
2
0
1
1
python,c,cross-platform,posix,scripting
40,367
4
false
0
0
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.
4
2
0
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.
Using C in a shared multi-platform POSIX environment
0.099668
0
0
293
39,847
2008-09-02T15:46:00.000
0
0
1
1
python,c,cross-platform,posix,scripting
39,871
4
false
0
0
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.
4
2
0
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.
Using C in a shared multi-platform POSIX environment
0
0
0
293
41,701
2008-09-03T13:48:00.000
3
0
1
0
python,tuples
41,721
9
false
0
0
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.
1
13
0
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)
Splitting tuples in Python - best practice?
0.066568
0
0
9,634
42,034
2008-09-03T16:13:00.000
65
0
1
0
python,tuples
42,048
11
true
0
0
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).
5
56
0
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?
What is a tuple useful for?
1.2
0
0
46,193
42,034
2008-09-03T16:13:00.000
2
0
1
0
python,tuples
42,049
11
false
0
0
I find them useful when you always deal with two or more objects as a set.
5
56
0
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?
What is a tuple useful for?
0.036348
0
0
46,193
42,034
2008-09-03T16:13:00.000
0
0
1
0
python,tuples
51,200
11
false
0
0
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.
5
56
0
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?
What is a tuple useful for?
0
0
0
46,193
42,034
2008-09-03T16:13:00.000
4
0
1
0
python,tuples
42,060
11
false
0
0
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.
5
56
0
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?
What is a tuple useful for?
0.072599
0
0
46,193
42,034
2008-09-03T16:13:00.000
1
0
1
0
python,tuples
42,055
11
false
0
0
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.
5
56
0
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?
What is a tuple useful for?
0.01818
0
0
46,193
42,690
2008-09-03T21:52:00.000
5
1
1
0
.net,ironpython,ironruby,dynamic-language-runtime,dynamic-languages
42,702
6
false
0
0
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)
3
5
0
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?
Which Dynamic .NET language makes more sense to learn, Iron Ruby or Iron Python?
0.16514
0
0
1,222
42,690
2008-09-03T21:52:00.000
1
1
1
0
.net,ironpython,ironruby,dynamic-language-runtime,dynamic-languages
467,185
6
false
0
0
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.
3
5
0
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?
Which Dynamic .NET language makes more sense to learn, Iron Ruby or Iron Python?
0.033321
0
0
1,222
42,690
2008-09-03T21:52:00.000
4
1
1
0
.net,ironpython,ironruby,dynamic-language-runtime,dynamic-languages
61,734
6
true
0
0
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
3
5
0
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?
Which Dynamic .NET language makes more sense to learn, Iron Ruby or Iron Python?
1.2
0
0
1,222
43,290
2008-09-04T07:36:00.000
4
0
0
0
python,django,url,django-urls
72,249
4
false
1
0
Be aware that using reverse() requires that your urlconf module is 100% error free and can be processed - iow no ViewDoesNotExist errors or so, or you get the dreaded NoReverseMatch exception (errors in templates usually fail silently resulting in None).
1
35
0
In Django's template language, you can use {% url [viewname] [args] %} to generate a URL to a specific view with parameters. How can you programatically do the same in Python code? What I need is to create a list of menu items where each item has name, URL, and an active flag (whether it's the current page or not). This is because it will be a lot cleaner to do this in Python than the template language.
How to generate urls in django
0.197375
0
0
37,259
43,368
2008-09-04T08:53:00.000
1
0
0
0
python,sql,metadata,coupling,data-driven
48,479
5
false
1
0
I know that you specificity ask for a framework but I thought I would let you know about what I get up to here. I have just undergone converting my company's web application from a custom in-house ORM layer into sqlAlchemy so I am far from an expert but something that occurred to me was that sqlAlchemy has types for all of the attributes it maps from the database so why not use that to help output the right html onto the page. So we use sqlAlchemy for the back end and Cheetah templates for the front end but everything in between is basically our own still. We have never managed to find a framework that does exactly what we want without compromise and prefer to get all the bits that work right for us and write the glue our selves. Step 1. For each data type sqlAlchemy.types.INTEGER etc. Add an extra function toHtml (or many maybe toHTMLReadOnly, toHTMLAdminEdit whatever) and just have that return the template for the html, now you don't even have to care what data type your displaying if you just want to spit out a whole table you can just do (as a cheetah template or what ever your templating engine is). Step 2 <table> <tr> #for $field in $dbObject.c: <th>$field.name</th> #end for </tr> <tr> #for $field in dbObject.c: <td>$field.type.toHtml($field.name, $field.value)</td> #end for </tr> </table> Using this basic method and stretching pythons introspection to its potential, in an afternoon I managed to make create read update and delete code for our whole admin section of out database, not yet with the polish of django but more then good enough for my needs. Step 3 Discovered the need for a third step just on Friday, wanted to upload files which as you know needs more then just the varchar data types default text box. No sweat, I just overrode the rows class in my table definition from VARCHAR to FilePath(VARCHAR) where the only difference was FilePath had a different toHtml method. Worked flawlessly. All that said, if there is a shrink wrapped one out there that does just what you want, use that. Disclaimer: This code was written from memory after midnight and probably wont produce a functioning web page.
1
11
0
I'm a firm believer of the heretic thought of tight coupling between the backend and frontend: I want existing, implied knowledge about a backend to be automatically made use of when generating user interfaces. E.g., if a VARCHAR column has a maximum with of 20 characters, there GUIs should automatically constrain the user from typing more than 20 characters in a related form field. And I have strong antipathy to ORMs which want to define my database tables, or are based on some hack where every table needs to have extra numeric ID columns because of the ORM. I've looked a bit into Python database frameworks and I think I can conclude the SQLAlchemy fits best to my mentality. Now, I need to find a web application framework which fits naturally with SQLAlchemy (or an equivalent) and perhaps even with my appetite for coupling. With "web application framework", I mean products/project such as Pyhons, Django, TurboGears, web2py, etc. E.g., it should ideally be able to: automatically select a suitable form widget for data entering a given column if told to do so; e.g., if the column has a foreign key to a column with 10 different values, widget should display the 10 possible values as a dropdown auto-generate javascript form validation code which gives the end-user quick error feedback if a string is entered into a field which is about to end up in an INTEGER column, etc auto-generate a calendar widget for data which will end up in a DATE column hint NOT NULL constraints as javascript which complains about empty or whitespace-only data in a related input field generate javascript validation code which matches relevant (simple) CHECK-constraints make it easy to avoid SQL injection, by using prepared statements and/or validation of externally derived data make it easy to avoid cross site scripting by automatically escape outgoing strings when appropriate make use of constraint names to generate somewhat user friendly error messages in case a constrataint is violated All this should happen dynamically, so table adjustments are automatically reflected on the frontend - probably with a caching mechanism, so that all the model introspection wouldn't kill performance. In other words, I don't want to repeat my model definition in an XML file (or alike) when it has already been carefully been defined in my database. Does such a framework exist for Python (or for any language, for that matter)? If not: Which of the several Python web application frameworks will be least in the way if I were to add parts of the above features myself?
A python web application framework for tight DB/GUI coupling?
0.039979
0
0
2,785
43,580
2008-09-04T12:07:00.000
1
1
0
0
python,mime
11,101,343
18
false
0
0
The mimetypes module just recognise an file type based on file extension. If you will try to recover a file type of a file without extension, the mimetypes will not works.
3
242
0
Let's say you want to save a bunch of files somewhere, for instance in BLOBs. Let's say you want to dish these files out via a web page and have the client automatically open the correct application/viewer. Assumption: The browser figures out which application/viewer to use by the mime-type (content-type?) header in the HTTP response. Based on that assumption, in addition to the bytes of the file, you also want to save the MIME type. How would you find the MIME type of a file? I'm currently on a Mac, but this should also work on Windows. Does the browser add this information when posting the file to the web page? Is there a neat python library for finding this information? A WebService or (even better) a downloadable database?
How to find the mime type of a file in python?
0.011111
0
0
233,034
43,580
2008-09-04T12:07:00.000
0
1
0
0
python,mime
51,510,950
18
false
0
0
For byte Array type data you can use magic.from_buffer(_byte_array,mime=True)
3
242
0
Let's say you want to save a bunch of files somewhere, for instance in BLOBs. Let's say you want to dish these files out via a web page and have the client automatically open the correct application/viewer. Assumption: The browser figures out which application/viewer to use by the mime-type (content-type?) header in the HTTP response. Based on that assumption, in addition to the bytes of the file, you also want to save the MIME type. How would you find the MIME type of a file? I'm currently on a Mac, but this should also work on Windows. Does the browser add this information when posting the file to the web page? Is there a neat python library for finding this information? A WebService or (even better) a downloadable database?
How to find the mime type of a file in python?
0
0
0
233,034
43,580
2008-09-04T12:07:00.000
11
1
0
0
python,mime
12,297,929
18
false
0
0
There are 3 different libraries that wraps libmagic. 2 of them are available on pypi (so pip install will work): filemagic python-magic And another, similar to python-magic is available directly in the latest libmagic sources, and it is the one you probably have in your linux distribution. In Debian the package python-magic is about this one and it is used as toivotuo said and it is not obsoleted as Simon Zimmermann said (IMHO). It seems to me another take (by the original author of libmagic). Too bad is not available directly on pypi.
3
242
0
Let's say you want to save a bunch of files somewhere, for instance in BLOBs. Let's say you want to dish these files out via a web page and have the client automatically open the correct application/viewer. Assumption: The browser figures out which application/viewer to use by the mime-type (content-type?) header in the HTTP response. Based on that assumption, in addition to the bytes of the file, you also want to save the MIME type. How would you find the MIME type of a file? I'm currently on a Mac, but this should also work on Windows. Does the browser add this information when posting the file to the web page? Is there a neat python library for finding this information? A WebService or (even better) a downloadable database?
How to find the mime type of a file in python?
1
0
0
233,034
43,775
2008-09-04T13:36:00.000
16
0
1
0
python,math,modulo
43,794
12
true
0
0
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.
6
18
0
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.
Modulus operation with negatives values - weird thing?
1.2
0
0
11,706
43,775
2008-09-04T13:36:00.000
14
0
1
0
python,math,modulo
43,780
12
false
0
0
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
6
18
0
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.
Modulus operation with negatives values - weird thing?
1
0
0
11,706
43,775
2008-09-04T13:36:00.000
0
0
1
0
python,math,modulo
43,781
12
false
0
0
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.
6
18
0
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.
Modulus operation with negatives values - weird thing?
0
0
0
11,706
43,775
2008-09-04T13:36:00.000
4
0
1
0
python,math,modulo
43,785
12
false
0
0
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.
6
18
0
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.
Modulus operation with negatives values - weird thing?
0.066568
0
0
11,706
43,775
2008-09-04T13:36:00.000
0
0
1
0
python,math,modulo
43,799
12
false
0
0
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#).
6
18
0
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.
Modulus operation with negatives values - weird thing?
0
0
0
11,706
43,775
2008-09-04T13:36:00.000
0
0
1
0
python,math,modulo
5,203,460
12
false
0
0
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.
6
18
0
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.
Modulus operation with negatives values - weird thing?
0
0
0
11,706
44,101
2008-09-04T16:15:00.000
1
0
1
0
python,image,watermark
44,132
11
false
0
0
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.
4
12
0
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?
invisible watermarks in images
0.01818
0
0
13,301
44,101
2008-09-04T16:15:00.000
2
0
1
0
python,image,watermark
541,170
11
false
0
0
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>
4
12
0
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?
invisible watermarks in images
0.036348
0
0
13,301
44,101
2008-09-04T16:15:00.000
6
0
1
0
python,image,watermark
44,217
11
false
0
0
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.
4
12
0
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?
invisible watermarks in images
1
0
0
13,301
44,101
2008-09-04T16:15:00.000
0
0
1
0
python,image,watermark
44,221
11
false
0
0
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.
4
12
0
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?
invisible watermarks in images
0
0
0
13,301
44,135
2008-09-04T16:36:00.000
1
0
0
0
python,django
427,643
6
false
1
0
My current layout stems from me wanting to have a test-version of my sites. This means having two projects for every site, since they need different configurations, and forces me to move all the applications out of the projects. I've created two folders: $APP_ROOT/devel and $APP_ROOT/prod. These contain all the apps. Using source control (in my case git) I have the apps in devel at the HEAD revision, while the apps in prod are locked to the PROD tag. The templates also have their own folder with the same layout as the apps. Now I'm able to do all my development in the devel-apps folder and the matching template-folder. When I have something I'm happy with, I tag that revision and update prod.
1
44
0
What is the best way to layout a large django project? The tutorials provide simple instructions for setting up apps, models, and views, but there is less information about how apps and projects should be broken down, how much sharing is allowable/necessary between apps in a typical project (obviously that is largely dependent on the project) and how/where general templates should be kept. Does anyone have examples, suggestions, and explanations as to why a certain project layout is better than another? I am particularly interested in the incorporation of large numbers of unit tests (2-5x the size of the actual code base) and string externalization / templates.
Project design / FS layout for large django projects
0.033321
0
0
7,973
44,834
2008-09-04T21:28:00.000
797
0
1
0
python,syntax,namespaces
44,842
11
true
0
0
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
1,420
0
I see __all__ in __init__.py files. What does it do?
What does __all__ mean in Python?
1.2
0
0
473,666
45,507
2008-09-05T10:26:00.000
1
1
1
0
python,favicon
45,520
7
false
0
0
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.
1
32
0
I'm looking to create favicon.ico files programatically from Python, but PIL only has support for reading ico files.
Is there a Python library for generating .ico files?
0.028564
0
0
25,030
47,198
2008-09-06T02:22:00.000
0
1
1
0
python,compatibility
2,036,609
6
false
0
0
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.
2
15
0
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?
Which Version of Python to Use for Maximum Compatibility
0
0
0
3,460
47,198
2008-09-06T02:22:00.000
1
1
1
0
python,compatibility
47,264
6
false
0
0
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.
2
15
0
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?
Which Version of Python to Use for Maximum Compatibility
0.033321
0
0
3,460
47,701
2008-09-06T18:14:00.000
4
0
1
0
python,debugging
277,800
10
false
0
0
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.
1
35
0
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 :)
Is there a way to attach a debugger to a multi-threaded Python process?
0.07983
0
0
34,732
47,953
2008-09-06T23:35:00.000
1
1
1
1
python,zip,packaging,software-distribution,egg
138,090
6
false
0
0
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.
3
27
0
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?
What are the advantages of packaging your python library/application as an .egg file?
0.033321
0
0
10,471
47,953
2008-09-06T23:35:00.000
1
1
1
1
python,zip,packaging,software-distribution,egg
137,903
6
false
0
0
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.
3
27
0
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?
What are the advantages of packaging your python library/application as an .egg file?
0.033321
0
0
10,471
47,953
2008-09-06T23:35:00.000
4
1
1
1
python,zip,packaging,software-distribution,egg
47,958
6
false
0
0
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.
3
27
0
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?
What are the advantages of packaging your python library/application as an .egg file?
0.132549
0
0
10,471
48,123
2008-09-07T04:00:00.000
1
0
1
0
python,gtk,pygtk,glade,gtk2
751,707
11
false
0
1
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.
8
32
0
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).
Glade or no glade: What is the best way to use PyGtk?
0.01818
0
0
8,539
48,123
2008-09-07T04:00:00.000
1
0
1
0
python,gtk,pygtk,glade,gtk2
199,167
11
false
0
1
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.
8
32
0
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).
Glade or no glade: What is the best way to use PyGtk?
0.01818
0
0
8,539
48,123
2008-09-07T04:00:00.000
5
0
1
0
python,gtk,pygtk,glade,gtk2
106,889
11
false
0
1
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.
8
32
0
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).
Glade or no glade: What is the best way to use PyGtk?
0.090659
0
0
8,539
48,123
2008-09-07T04:00:00.000
2
0
1
0
python,gtk,pygtk,glade,gtk2
305,667
11
false
0
1
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.
8
32
0
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).
Glade or no glade: What is the best way to use PyGtk?
0.036348
0
0
8,539
48,123
2008-09-07T04:00:00.000
4
0
1
0
python,gtk,pygtk,glade,gtk2
107,959
11
false
0
1
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.
8
32
0
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).
Glade or no glade: What is the best way to use PyGtk?
0.072599
0
0
8,539
48,123
2008-09-07T04:00:00.000
2
0
1
0
python,gtk,pygtk,glade,gtk2
2,149,087
11
false
0
1
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.
8
32
0
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).
Glade or no glade: What is the best way to use PyGtk?
0.036348
0
0
8,539
48,123
2008-09-07T04:00:00.000
5
0
1
0
python,gtk,pygtk,glade,gtk2
54,313
11
false
0
1
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.
8
32
0
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).
Glade or no glade: What is the best way to use PyGtk?
0.090659
0
0
8,539
48,123
2008-09-07T04:00:00.000
12
0
1
0
python,gtk,pygtk,glade,gtk2
48,136
11
false
0
1
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.
8
32
0
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).
Glade or no glade: What is the best way to use PyGtk?
1
0
0
8,539
49,137
2008-09-08T03:53:00.000
0
1
0
1
c++,python,embedded-language
69,672,216
7
false
0
0
Using Inter Process Communication (IPC) over socket can be a possible solution. Use a local network socket to listen/trasfer commands between both.
1
65
0
I would like to call python script files from my c++ program. I am not sure that the people I will distribute to will have python installed. Basically I'm looking for a .lib file that I can use that has an Apache like distribution license.
Calling python from a c++ program for distribution
0
0
0
100,997
49,146
2008-09-08T03:59:00.000
4
0
1
0
python,exe,executable
10,241,354
7
false
0
0
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.
2
115
0
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.
How can I make an EXE file from a Python program?
0.113791
0
0
289,620
49,146
2008-09-08T03:59:00.000
3
0
1
0
python,exe,executable
15,667,090
7
false
0
0
Use cx_Freeze to make exe your python program
2
115
0
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.
How can I make an EXE file from a Python program?
0.085505
0
0
289,620
49,195
2008-09-08T05:23:00.000
1
1
0
0
python,c
49,246
14
false
0
0
C is a bridge onto itself. K&R is the only programming language book you can read in one sitting and almost never pick it up again ...
12
4
0
The first language I learnt was PHP, but I have more recently picked up Python. As these are all 'high-level' languages, I have found them a bit difficult to pick up. I also tried to learn Objective-C but I gave up. So, what language should I learn to bridge between Python to C
What language should I learn as a bridge to C (and derivatives)
0.014285
0
0
871
49,195
2008-09-08T05:23:00.000
5
1
0
0
python,c
49,285
14
false
0
0
I generally agree with most of the others - There's not really a good stepping stone language. It is, however, useful to understand what is difficult about learning C, which might help you understand what's making it difficult for you. I'd say the things that would prove difficult in C for someone coming from PHP would be : Pointers and memory management This is pretty much the reason you're learning C I imagine, so there's not really any getting around it. Learning lower level assembly type languages might make this easier, but C is probably a bridge to do that, not the other way around. Lack of built in data structures PHP and co all have native String types, and useful things like hash tables built in, which is not the case in C. In C, a String is just an array of characters, which means you'll need to do a lot more work, or look seriously at libraries which add the features you're used to. Lack of built in libraries Languages like PHP nowadays almost always come with stacks of libraries for things like database connections, image manipulation and stacks of other things. In C, this is not the case other than a very thin standard library which revolves mostly around file reading, writing and basic string manipulation. There are almost always good choices available to fill these needs, but you need to include them yourself. Suitability for high level tasks If you try to implement the same type of application in C as you might in PHP, you'll find it very slow going. Generating a web page, for example, isn't really something plain C is suited for, so if you're trying to do that, you'll find it very slow going. Preprocessor and compilation Most languages these days don't have a preprocessor, and if you're coming from PHP, the compilation cycle will seem painful. Both of these are performance trade offs in a way - Scripting languages make the trade off in terms of developer efficiency, where as C prefers performance. I'm sure there are more that aren't springing to mind for me right now. The moral of the story is that trying to understand what you're finding difficult in C may help you proceed. If you're trying to generate web pages with it, try doing something lower level. If you're missing hash tables, try writing your own, or find a library. If you're struggling with pointers, stick with it :)
12
4
0
The first language I learnt was PHP, but I have more recently picked up Python. As these are all 'high-level' languages, I have found them a bit difficult to pick up. I also tried to learn Objective-C but I gave up. So, what language should I learn to bridge between Python to C
What language should I learn as a bridge to C (and derivatives)
0.071307
0
0
871
49,195
2008-09-08T05:23:00.000
0
1
0
0
python,c
49,237
14
false
0
0
Java might actually be a good option here, believe it or not. It is strongly based on C/C++, so if you can get the syntax and the strong typing, picking up C might be easier. The benefit is you can learn the lower level syntax without having to learn pointers (since memory is managed for you just like in Python and PHP). You will, however, learn a similar concept... references (or objects in general). Also, it is strongly Object Oriented, so it may be difficult to pick up on that if you haven't dealt with OOP yet.... you might be better off just digging in with C like others suggested, but it is an option.
12
4
0
The first language I learnt was PHP, but I have more recently picked up Python. As these are all 'high-level' languages, I have found them a bit difficult to pick up. I also tried to learn Objective-C but I gave up. So, what language should I learn to bridge between Python to C
What language should I learn as a bridge to C (and derivatives)
0
0
0
871
49,195
2008-09-08T05:23:00.000
0
1
0
0
python,c
49,248
14
false
0
0
I think C++ is a good "bridge" to C. I learned C++ first at University, and since it's based on C you'll learn a lot of the same concepts - perhaps most notably pointers - but also Object Oriented Design. OO can be applied to all kinds of modern languages, so it's worth learning. After learning C++, I found it wasn't too hard to pick up the differences between C++ and C as required (for example, when working on devices that didn't support C++).
12
4
0
The first language I learnt was PHP, but I have more recently picked up Python. As these are all 'high-level' languages, I have found them a bit difficult to pick up. I also tried to learn Objective-C but I gave up. So, what language should I learn to bridge between Python to C
What language should I learn as a bridge to C (and derivatives)
0
0
0
871
49,195
2008-09-08T05:23:00.000
1
1
0
0
python,c
49,245
14
false
0
0
Forget Java - it is not going to bring you anywhere closer to C (you have allready proved that you don't have a problem learning new syntax). Either read K&R or go one lower: Learn about the machine itself. The only tricky part in C is pointers and memory management (which is closely related to pointers, but also has a bit to do with how functions are called). Learning a (simple, maybe even "fake" assembly) language should help you out here. Then, start reading up on the standard library provided by C. It will be your daily bread and butter. Oh: another tip! If you really do want to bridge, try FORTH. It helped me get into pointers. Also, using the win32 api from Visual Basic 6.0 can teach you some stuff about pointers ;)
12
4
0
The first language I learnt was PHP, but I have more recently picked up Python. As these are all 'high-level' languages, I have found them a bit difficult to pick up. I also tried to learn Objective-C but I gave up. So, what language should I learn to bridge between Python to C
What language should I learn as a bridge to C (and derivatives)
0.014285
0
0
871
49,195
2008-09-08T05:23:00.000
0
1
0
0
python,c
49,502
14
false
0
0
Languages are easy to learn (especially one like C)... the hard part is learning the libraries and/or coding style of the language. For instance, I know C++ fairly well, but most C/C++ code I see confuses me because the naming conventions are so different from what I work with on a daily basis. Anyway, I guess what I'm trying to say is don't worry too much about the syntax, focus on said language's library. This isn't specific to C, you can say the same about c#, vb.net, java and just about every other language out there.
12
4
0
The first language I learnt was PHP, but I have more recently picked up Python. As these are all 'high-level' languages, I have found them a bit difficult to pick up. I also tried to learn Objective-C but I gave up. So, what language should I learn to bridge between Python to C
What language should I learn as a bridge to C (and derivatives)
0
0
0
871
49,195
2008-09-08T05:23:00.000
0
1
0
0
python,c
49,217
14
false
0
0
I'm feeling your pain, I also learned PHP first and I'm trying to learn C++, it's not easy, and I am really struggling, It's been 2 years since I started on c++ and Still the extent of what I can do is cout, cin, and math. If anyone reads this and wonders where to start, START LOWER.
12
4
0
The first language I learnt was PHP, but I have more recently picked up Python. As these are all 'high-level' languages, I have found them a bit difficult to pick up. I also tried to learn Objective-C but I gave up. So, what language should I learn to bridge between Python to C
What language should I learn as a bridge to C (and derivatives)
0
0
0
871
49,195
2008-09-08T05:23:00.000
0
1
0
0
python,c
50,673
14
false
0
0
Pascal! Close enough syntax, still requires you to do some memory management, but not as rough for beginners.
12
4
0
The first language I learnt was PHP, but I have more recently picked up Python. As these are all 'high-level' languages, I have found them a bit difficult to pick up. I also tried to learn Objective-C but I gave up. So, what language should I learn to bridge between Python to C
What language should I learn as a bridge to C (and derivatives)
0
0
0
871
49,195
2008-09-08T05:23:00.000
0
1
0
0
python,c
49,295
14
false
0
0
try to learn a language which you are comfortable with, try different approach and the basics.
12
4
0
The first language I learnt was PHP, but I have more recently picked up Python. As these are all 'high-level' languages, I have found them a bit difficult to pick up. I also tried to learn Objective-C but I gave up. So, what language should I learn to bridge between Python to C
What language should I learn as a bridge to C (and derivatives)
0
0
0
871
49,195
2008-09-08T05:23:00.000
1
1
0
0
python,c
49,234
14
false
0
0
Learning any language takes time, I always ensure I have a measurable goal; I set myself an objective, then start learning the language to achieve this objective, as opposed to trying to learn every nook and cranny of the language and syntax. C is not easy, pointers can be hard to comprehend if you’re not coming assembler roots. I first learned C++, then retro fit C to my repertoire but I started with x86 and 68000 assembler.
12
4
0
The first language I learnt was PHP, but I have more recently picked up Python. As these are all 'high-level' languages, I have found them a bit difficult to pick up. I also tried to learn Objective-C but I gave up. So, what language should I learn to bridge between Python to C
What language should I learn as a bridge to C (and derivatives)
0.014285
0
0
871
49,195
2008-09-08T05:23:00.000
15
1
0
0
python,c
49,202
14
true
0
0
It's not clear why you need a bridge language. Why don't you start working with C directly? C is a very simple language itself. I think that hardest part for C learner is pointers and everything else related to memory management. Also C lang is oriented on structured programming, so you will need to learn how to implement data structures and algorithms without OOP goodness. Actually, your question is pretty hard, usually people go from low level langs to high level and I can understand frustration of those who goes in other direction.
12
4
0
The first language I learnt was PHP, but I have more recently picked up Python. As these are all 'high-level' languages, I have found them a bit difficult to pick up. I also tried to learn Objective-C but I gave up. So, what language should I learn to bridge between Python to C
What language should I learn as a bridge to C (and derivatives)
1.2
0
0
871
49,195
2008-09-08T05:23:00.000
7
1
0
0
python,c
49,227
14
false
0
0
The best place to start learning C is the book "The C Programming Language" by Kernighan and Ritchie. You will recognise a lot of things from PHP, and you will be surprised how much PHP (and Perl, Python etc) do for you. Oh and you also will need a C compiler, but i guess you knew that.
12
4
0
The first language I learnt was PHP, but I have more recently picked up Python. As these are all 'high-level' languages, I have found them a bit difficult to pick up. I also tried to learn Objective-C but I gave up. So, what language should I learn to bridge between Python to C
What language should I learn as a bridge to C (and derivatives)
1
0
0
871
49,307
2008-09-08T08:25:00.000
-2
0
1
0
python,arrays,matlab,for-loop
138,886
7
false
0
0
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.
1
14
1
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?
Can parallel traversals be done in MATLAB just as in Python?
-0.057081
0
0
7,417
49,824
2008-09-08T14:36:00.000
47
1
1
0
java,python
49,953
5
true
0
0
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.
2
29
0
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?
Java -> Python?
1.2
0
0
11,654
49,824
2008-09-08T14:36:00.000
2
1
1
0
java,python
51,512
5
false
0
0
Apart from what Eli Courtwright said: I find iterators in Python more concise. You can use for i in something, and it works with pretty much everything. Yeah, Java has gotten better since 1.5, but for example you can iterate through a string in python with this same construct. Introspection: In python you can get at runtime information about an object or a module about its symbols, methods, or even its docstrings. You can also instantiate them dynamically. Java has some of this, but usually in Java it takes half a page of code to get an instance of a class, whereas in Python it is about 3 lines. And as far as I know the docstrings thing is not available in Java
2
29
0
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?
Java -> Python?
0.07983
0
0
11,654
50,568
2008-09-08T20:16:00.000
3
0
0
0
python,django,session,caching,mongodb
100,464
5
false
1
0
One thing that has to be considered when choosing session backend is "how often session data is modified"? Even sites with moderate traffic will suffer if session data is modified on each request, making many database trips to store and retrieve data. In my previous work we used memcache as session backend exclusively and it worked really well. Our administrative team put really great effort in making two special memcached instances stable as a rock, but after bit of twiddling with initial setup, we did not have any interrupts of session backends operations.
3
38
0
I'm looking at sessions in Django, and by default they are stored in the database. What are the benefits of filesystem and cache sessions and when should I use them?
Django Sessions
0.119427
0
0
12,358
50,568
2008-09-08T20:16:00.000
1
0
0
0
python,django,session,caching,mongodb
326,046
5
false
1
0
If the database have a DBA that isn't you, you may not be allowed to use a database-backed session (it being a front-end matter only). Until django supports easily merging data from several databases, so that you can have frontend-specific stuff like sessions and user-messages (the messages in django.contrib.auth are also stored in the db) in a separate db, you need to keep this in mind.
3
38
0
I'm looking at sessions in Django, and by default they are stored in the database. What are the benefits of filesystem and cache sessions and when should I use them?
Django Sessions
0.039979
0
0
12,358
50,568
2008-09-08T20:16:00.000
25
0
0
0
python,django,session,caching,mongodb
50,668
5
false
1
0
The filesystem backend is only worth looking at if you're not going to use a database for any other part of your system. If you are using a database then the filesystem backend has nothing to recommend it. The memcache backend is much quicker than the database backend, but you run the risk of a session being purged and some of your session data being lost. If you're a really, really high traffic website and code carefully so you can cope with losing a session then use memcache. If you're not using a database use the file system cache, but the default database backend is the best, safest and simplest option in almost all cases.
3
38
0
I'm looking at sessions in Django, and by default they are stored in the database. What are the benefits of filesystem and cache sessions and when should I use them?
Django Sessions
1
0
0
12,358
51,010
2008-09-09T00:28:00.000
-1
0
1
0
python,datetime,time
108,603
7
false
0
0
Retrieve the times in milliseconds and then do the subtraction.
2
13
0
I have 2 time values which have the type datetime.time. I want to find their difference. The obvious thing to do is t1 - t2, but this doesn't work. It works for objects of type datetime.datetime but not for datetime.time. So what is the best way to do this?
What is the simplest way to find the difference between 2 times in python?
-0.028564
0
0
10,861
51,010
2008-09-09T00:28:00.000
-3
0
1
0
python,datetime,time
263,451
7
false
0
0
Environment.TickCount seems to work well if you need something quick. int start = Environment.TickCount ...DoSomething() int elapsedtime = Environment.TickCount - start Jon
2
13
0
I have 2 time values which have the type datetime.time. I want to find their difference. The obvious thing to do is t1 - t2, but this doesn't work. It works for objects of type datetime.datetime but not for datetime.time. So what is the best way to do this?
What is the simplest way to find the difference between 2 times in python?
-0.085505
0
0
10,861
51,233
2008-09-09T04:38:00.000
2
0
0
0
python,html
17,123,979
12
false
1
0
soup.title.string actually returns a unicode string. To convert that into normal string, you need to do string=string.encode('ascii','ignore')
1
86
0
How can I retrieve the page title of a webpage (title html tag) using Python?
How can I retrieve the page title of a webpage using Python?
0.033321
0
1
103,114
53,428
2008-09-10T04:49:00.000
0
0
0
0
python,orm
4,908,742
12
false
1
0
I used Storm + SQLite for a small project, and was pretty happy with it until I added multiprocessing. Trying to use the database from multiple processes resulted in a "Database is locked" exception. I switched to SQLAlchemy, and the same code worked with no problems.
3
236
0
I'm evaluating and looking at using CherryPy for a project that's basically a JavaScript front-end from the client-side (browser) that talks to a Python web service on the back-end. So, I really need something fast and lightweight on the back-end that I can implement using Python that then speaks to the PostgreSQL DB via an ORM (JSON to the browser). I'm also looking at Django, which I like, since its ORM is built-in. However, I think Django might be a little more than I really need (i.e. more features than I really need == slower?). Anyone have any experience with different Python ORM solutions that can compare and contrast their features and functionality, speed, efficiency, etc.?
What are some good Python ORM solutions?
0
0
0
178,152
53,428
2008-09-10T04:49:00.000
-2
0
0
0
python,orm
2,510,845
12
false
1
0
SQLAlchemy is very, very powerful. However it is not thread safe make sure you keep that in mind when working with cherrypy in thread-pool mode.
3
236
0
I'm evaluating and looking at using CherryPy for a project that's basically a JavaScript front-end from the client-side (browser) that talks to a Python web service on the back-end. So, I really need something fast and lightweight on the back-end that I can implement using Python that then speaks to the PostgreSQL DB via an ORM (JSON to the browser). I'm also looking at Django, which I like, since its ORM is built-in. However, I think Django might be a little more than I really need (i.e. more features than I really need == slower?). Anyone have any experience with different Python ORM solutions that can compare and contrast their features and functionality, speed, efficiency, etc.?
What are some good Python ORM solutions?
-0.033321
0
0
178,152
53,428
2008-09-10T04:49:00.000
1
0
0
0
python,orm
186,179
12
false
1
0
There is no conceivable way that the unused features in Django will give a performance penalty. Might just come in handy if you ever decide to upscale the project.
3
236
0
I'm evaluating and looking at using CherryPy for a project that's basically a JavaScript front-end from the client-side (browser) that talks to a Python web service on the back-end. So, I really need something fast and lightweight on the back-end that I can implement using Python that then speaks to the PostgreSQL DB via an ORM (JSON to the browser). I'm also looking at Django, which I like, since its ORM is built-in. However, I think Django might be a little more than I really need (i.e. more features than I really need == slower?). Anyone have any experience with different Python ORM solutions that can compare and contrast their features and functionality, speed, efficiency, etc.?
What are some good Python ORM solutions?
0.016665
0
0
178,152
53,543
2008-09-10T07:04:00.000
2
0
1
0
python,ironpython,jython,cpython
199,275
6
false
0
0
I write code for CPython and IronPython but tip should work for Jython as well. Basically, I write all the platform specific code in separate modules/packages and then import the appropriate one based on platform I'm running on. (see cdleary's comment above) This is especially important when it comes to the differences between the SQLite implementations and if you are implementing any GUI code.
3
16
0
Having tries to target two of these environments at the same time I can safely say the if you have to use a database etc. you end up having to write unique code for that environment. Have you got a great way to handle this situation?
What are some strategies to write python code that works in CPython, Jython and IronPython
0.066568
0
0
1,296
53,543
2008-09-10T07:04:00.000
0
0
1
0
python,ironpython,jython,cpython
637,549
6
false
0
0
There are two major issues at play here... Firstly, to my knowledge, only CPython has RAII - you have to close your own resources in Jython, Ironpython, etc. And Secondly, as has been mentioned, is thread safety.
3
16
0
Having tries to target two of these environments at the same time I can safely say the if you have to use a database etc. you end up having to write unique code for that environment. Have you got a great way to handle this situation?
What are some strategies to write python code that works in CPython, Jython and IronPython
0
0
0
1,296
53,543
2008-09-10T07:04:00.000
1
0
1
0
python,ironpython,jython,cpython
342,835
6
false
0
0
The #1 thing IMO: Focus on thread safety. CPython's GIL makes writing threadsafe code easy because only one thread can access the interpreter at a time. IronPython and Jython are a little less hand-holding though.
3
16
0
Having tries to target two of these environments at the same time I can safely say the if you have to use a database etc. you end up having to write unique code for that environment. Have you got a great way to handle this situation?
What are some strategies to write python code that works in CPython, Jython and IronPython
0.033321
0
0
1,296
53,997
2008-09-10T13:12:00.000
0
0
0
1
python,ajax,google-app-engine
230,476
11
false
1
0
I'm currently using JQuery for my GAE app and it works beautifully for me. I have a chart (google charts) that is dynamic and uses an Ajax call to grab a JSON string. It really seems to work fine for me.
2
14
0
I am trying to implement AJAX in my Google App Engine application, and so I am looking for a good AJAX framework that will help me. Anyone has any idea? I am thinking about Google Web Toolkit, how good it is in terms of creating AJAX for Google App Engine?
Any good AJAX framework for Google App Engine apps?
0
0
0
11,904
53,997
2008-09-10T13:12:00.000
3
0
0
1
python,ajax,google-app-engine
54,015
11
false
1
0
I'd recommend looking into a pure javascript framework (probably Jquery) for your client-side code, and write JSON services in python- that seems to be the easiest / bestest way to go. Google Web Toolkit lets you write the UI in Java and compile it to javascript. As Dave says, it may be a better choice where the backend is in Java, as it has nice RPC hooks for that case.
2
14
0
I am trying to implement AJAX in my Google App Engine application, and so I am looking for a good AJAX framework that will help me. Anyone has any idea? I am thinking about Google Web Toolkit, how good it is in terms of creating AJAX for Google App Engine?
Any good AJAX framework for Google App Engine apps?
0.054491
0
0
11,904
54,867
2008-09-10T18:01:00.000
8
0
1
0
python,class,oop,types,new-style-class
16,295,402
8
false
0
0
New style classes may use super(Foo, self) where Foo is a class and self is the instance. super(type[, object-or-type]) Return a proxy object that delegates method calls to a parent or sibling class of type. This is useful for accessing inherited methods that have been overridden in a class. The search order is same as that used by getattr() except that the type itself is skipped. And in Python 3.x you can simply use super() inside a class without any parameters.
2
1,091
0
What is the difference between old style and new style classes in Python? When should I use one or the other?
What is the difference between old style and new style classes in Python?
1
0
0
257,866
54,867
2008-09-10T18:01:00.000
41
0
1
0
python,class,oop,types,new-style-class
3,228,045
8
false
0
0
Old style classes are still marginally faster for attribute lookup. This is not usually important, but it may be useful in performance-sensitive Python 2.x code: In [3]: class A: ...: def __init__(self): ...: self.a = 'hi there' ...: In [4]: class B(object): ...: def __init__(self): ...: self.a = 'hi there' ...: In [6]: aobj = A() In [7]: bobj = B() In [8]: %timeit aobj.a 10000000 loops, best of 3: 78.7 ns per loop In [10]: %timeit bobj.a 10000000 loops, best of 3: 86.9 ns per loop
2
1,091
0
What is the difference between old style and new style classes in Python? When should I use one or the other?
What is the difference between old style and new style classes in Python?
1
0
0
257,866
55,365
2008-09-10T21:32:00.000
6
0
1
0
python,emacs,ide,keyboard
56,008
3
true
0
0
IDLE provides Emacs keybindings without having to install other software. Open up the menu item Options -> Configure IDLE... Go to Keys tab In the drop down menu on the right side of the dialog change the select to "IDLE Classic Unix" It's not the true emacs key bindings but you get the basics like movement, saving/opening, ...
1
6
0
I use Emacs primarily for coding Python but sometimes I use IDLE. Is there a way to change the key bindings easily in IDLE to match Emacs?
How can I get Emacs' key bindings in Python's IDLE?
1.2
0
0
1,983
56,011
2008-09-11T08:18:00.000
1
0
1
0
python,coding-style
1,167,795
19
false
0
0
I just use whatever strikes my fancy at the time; it's convenient to be able to switch between the two at a whim! Of course, when quoting quote characetrs, switching between the two might not be so whimsical after all...
12
718
0
According to the documentation, they're pretty much interchangeable. Is there a stylistic reason to use one over the other?
Single quotes vs. double quotes in Python
0.010526
0
0
712,544
56,011
2008-09-11T08:18:00.000
3
0
1
0
python,coding-style
56,047
19
false
0
0
I use double quotes in general, but not for any specific reason - Probably just out of habit from Java. I guess you're also more likely to want apostrophes in an inline literal string than you are to want double quotes.
12
718
0
According to the documentation, they're pretty much interchangeable. Is there a stylistic reason to use one over the other?
Single quotes vs. double quotes in Python
0.031568
0
0
712,544
56,011
2008-09-11T08:18:00.000
0
0
1
0
python,coding-style
56,025
19
false
0
0
Your team's taste or your project's coding guidelines. If you are in a multilanguage environment, you might wish to encourage the use of the same type of quotes for strings that the other language uses, for instance. Else, I personally like best the look of '
12
718
0
According to the documentation, they're pretty much interchangeable. Is there a stylistic reason to use one over the other?
Single quotes vs. double quotes in Python
0
0
0
712,544
56,011
2008-09-11T08:18:00.000
44
0
1
0
python,coding-style
56,210
19
false
0
0
I'm with Will: Double quotes for text Single quotes for anything that behaves like an identifier Double quoted raw string literals for regexps Tripled double quotes for docstrings I'll stick with that even if it means a lot of escaping. I get the most value out of single quoted identifiers standing out because of the quotes. The rest of the practices are there just to give those single quoted identifiers some standing room.
12
718
0
According to the documentation, they're pretty much interchangeable. Is there a stylistic reason to use one over the other?
Single quotes vs. double quotes in Python
1
0
0
712,544
56,011
2008-09-11T08:18:00.000
-1
0
1
0
python,coding-style
3,179,675
19
false
0
0
I use double quotes because I have been doing so for years in most languages (C++, Java, VB…) except Bash, because I also use double quotes in normal text and because I'm using a (modified) non-English keyboard where both characters require the shift key.
12
718
0
According to the documentation, they're pretty much interchangeable. Is there a stylistic reason to use one over the other?
Single quotes vs. double quotes in Python
-0.010526
0
0
712,544
56,011
2008-09-11T08:18:00.000
26
0
1
0
python,coding-style
56,041
19
false
0
0
If the string you have contains one, then you should use the other. For example, "You're able to do this", or 'He said "Hi!"'. Other than that, you should simply be as consistent as you can (within a module, within a package, within a project, within an organisation). If your code is going to be read by people who work with C/C++ (or if you switch between those languages and Python), then using '' for single-character strings, and "" for longer strings might help ease the transition. (Likewise for following other languages where they are not interchangeable). The Python code I've seen in the wild tends to favour " over ', but only slightly. The one exception is that """these""" are much more common than '''these''', from what I have seen.
12
718
0
According to the documentation, they're pretty much interchangeable. Is there a stylistic reason to use one over the other?
Single quotes vs. double quotes in Python
1
0
0
712,544
56,011
2008-09-11T08:18:00.000
0
0
1
0
python,coding-style
56,029
19
false
0
0
None as far as I know. Although if you look at some code, " " is commonly used for strings of text (I guess ' is more common inside text than "), and ' ' appears in hashkeys and things like that.
12
718
0
According to the documentation, they're pretty much interchangeable. Is there a stylistic reason to use one over the other?
Single quotes vs. double quotes in Python
0
0
0
712,544
56,011
2008-09-11T08:18:00.000
3
0
1
0
python,coding-style
145,149
19
false
0
0
Personally I stick with one or the other. It doesn't matter. And providing your own meaning to either quote is just to confuse other people when you collaborate.
12
718
0
According to the documentation, they're pretty much interchangeable. Is there a stylistic reason to use one over the other?
Single quotes vs. double quotes in Python
0.031568
0
0
712,544
56,011
2008-09-11T08:18:00.000
1
0
1
0
python,coding-style
629,106
19
false
0
0
I chose to use double quotes because they are easier to see.
12
718
0
According to the documentation, they're pretty much interchangeable. Is there a stylistic reason to use one over the other?
Single quotes vs. double quotes in Python
0.010526
0
0
712,544
56,011
2008-09-11T08:18:00.000
0
0
1
0
python,coding-style
16,048,319
19
false
0
0
I aim to minimize both pixels and surprise. I typically prefer ' in order to minimize pixels, but " instead if the string has an apostrophe, again to minimize pixels. For a docstring, however, I prefer """ over ''' because the latter is non-standard, uncommon, and therefore surprising. If now I have a bunch of strings where I used " per the above logic, but also one that can get away with a ', I may still use " in it to preserve consistency, only to minimize surprise. Perhaps it helps to think of the pixel minimization philosophy in the following way. Would you rather that English characters looked like A B C or AA BB CC? The latter choice wastes 50% of the non-empty pixels.
12
718
0
According to the documentation, they're pretty much interchangeable. Is there a stylistic reason to use one over the other?
Single quotes vs. double quotes in Python
0
0
0
712,544