A_Id
int64
518
76.6M
AnswerCount
int64
1
64
Question
stringlengths
15
29.1k
Available Count
int64
1
31
Tags
stringlengths
6
105
Q_Id
int64
337
75M
Answer
stringlengths
6
11.6k
is_accepted
bool
2 classes
CreationDate
stringlengths
19
23
ViewCount
int64
6
6.81M
Users Score
int64
-42
1.15k
Score
float64
-1
1.2
Title
stringlengths
11
150
Q_Score
int64
0
6.79k
36,761
5
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?
1
python,user-interface
35,922
I use pyGtk. I think wxPython is nice but it's too limited, and PyQt is, well, Qt. =)
false
2008-08-30 12:19:01.933
10,824
1
0.039979
Are there any "nice to program" GUI toolkits for Python?
19
1,310,119
9
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?
3
python,unit-testing
36,647
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.
false
2008-08-31 05:07:41.603
8,490
1
0.022219
Unit tests in Python
20
2,194,729
9
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?
3
python,unit-testing
36,647
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.
false
2008-08-31 05:07:41.603
8,490
0
0
Unit tests in Python
20
36,654
9
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?
3
python,unit-testing
36,647
@Greg: PyUnit is included in the standard library as unittest
false
2008-08-31 05:07:41.603
8,490
2
0.044415
Unit tests in Python
20
38,646
8
Because regular expressions scare me, I'm trying to find a way to remove all HTML tags and resolve HTML entities from a string in Python.
2
python,html
37,486
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.
false
2008-09-01 05:25:01.990
25,958
0
0
Filter out HTML tags and resolve entities in python
18
37,604
8
Because regular expressions scare me, I'm trying to find a way to remove all HTML tags and resolve HTML entities from a string in Python.
2
python,html
37,486
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.
false
2008-09-01 05:25:01.990
25,958
0
0
Filter out HTML tags and resolve entities in python
18
38,222
3
The primary class in the subprocess module is name Popen, and represents a subprocess. Popen sounds like someone was trying to force the name to follow some function naming format, rather than chosing a name that actually represents what the object is. Does anyone know why it was chosen over something simple like, say, Subprocess?
2
python,subprocess
38,197
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.
true
2008-09-01 17:40:52.220
691
8
1.2
Why is the subprocess.Popen class not named Subprocess?
4
38,202
3
The primary class in the subprocess module is name Popen, and represents a subprocess. Popen sounds like someone was trying to force the name to follow some function naming format, rather than chosing a name that actually represents what the object is. Does anyone know why it was chosen over something simple like, say, Subprocess?
2
python,subprocess
38,197
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.
false
2008-09-01 17:40:52.220
691
-1
-0.066568
Why is the subprocess.Popen class not named Subprocess?
4
9,918,496
4
I've written a Python package that includes a bsddb database of pre-computed values for one of the more time-consuming computations. For simplicity, my setup script installs the database file in the same directory as the code which accesses the database (on Unix, something like /usr/lib/python2.5/site-packages/mypackage/). How do I store the final location of the database file so my code can access it? Right now, I'm using a hack based on the __file__ variable in the module which accesses the database: dbname = os.path.join(os.path.dirname(__file__), "database.dat") It works, but it seems... hackish. Is there a better way to do this? I'd like to have the setup script just grab the final installation location from the distutils module and stuff it into a "dbconfig.py" file that gets installed alongside the code that accesses the database.
2
python,distutils
39,104
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.
false
2008-09-02 09:40:26.580
28,993
19
1
Finding a file in a Python module distribution
32
39,295
4
I've written a Python package that includes a bsddb database of pre-computed values for one of the more time-consuming computations. For simplicity, my setup script installs the database file in the same directory as the code which accesses the database (on Unix, something like /usr/lib/python2.5/site-packages/mypackage/). How do I store the final location of the database file so my code can access it? Right now, I'm using a hack based on the __file__ variable in the module which accesses the database: dbname = os.path.join(os.path.dirname(__file__), "database.dat") It works, but it seems... hackish. Is there a better way to do this? I'd like to have the setup script just grab the final installation location from the distutils module and stuff it into a "dbconfig.py" file that gets installed alongside the code that accesses the database.
2
python,distutils
39,104
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.
false
2008-09-02 09:40:26.580
28,993
3
0.148885
Finding a file in a Python module distribution
32
39,871
4
I write tools that are used in a shared workspace. Since there are multiple OS's working in this space, we generally use Python and standardize the version that is installed across machines. However, if I wanted to write some things in C, I was wondering if maybe I could have the application wrapped in a Python script, that detected the operating system and fired off the correct version of the C application. Each platform has GCC available and uses the same shell. One idea was to have the C compiled to the users local ~/bin, with timestamp comparison with C code so it is not compiled each run, but only when code is updated. Another was to just compile it for each platform, and have the wrapper script select the proper executable. Is there an accepted/stable process for this? Are there any catches? Are there alternatives (assuming the absolute need to use native C code)? Clarification: Multiple OS's are involved that do not share ABI. Eg. OS X, various Linuxes, BSD etc. I need to be able to update the code in place in shared folders and have the new code working more or less instantaneously. Distributing binary or source packages is less than ideal.
4
python,c,cross-platform,posix,scripting
39,847
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.
false
2008-09-02 15:46:39.193
293
0
0
Using C in a shared multi-platform POSIX environment
2
39,878
4
I write tools that are used in a shared workspace. Since there are multiple OS's working in this space, we generally use Python and standardize the version that is installed across machines. However, if I wanted to write some things in C, I was wondering if maybe I could have the application wrapped in a Python script, that detected the operating system and fired off the correct version of the C application. Each platform has GCC available and uses the same shell. One idea was to have the C compiled to the users local ~/bin, with timestamp comparison with C code so it is not compiled each run, but only when code is updated. Another was to just compile it for each platform, and have the wrapper script select the proper executable. Is there an accepted/stable process for this? Are there any catches? Are there alternatives (assuming the absolute need to use native C code)? Clarification: Multiple OS's are involved that do not share ABI. Eg. OS X, various Linuxes, BSD etc. I need to be able to update the code in place in shared folders and have the new code working more or less instantaneously. Distributing binary or source packages is less than ideal.
4
python,c,cross-platform,posix,scripting
39,847
Also, you could use autoconf and distribute your application in source form only. :)
false
2008-09-02 15:46:39.193
293
1
0.049958
Using C in a shared multi-platform POSIX environment
2
40,367
4
I write tools that are used in a shared workspace. Since there are multiple OS's working in this space, we generally use Python and standardize the version that is installed across machines. However, if I wanted to write some things in C, I was wondering if maybe I could have the application wrapped in a Python script, that detected the operating system and fired off the correct version of the C application. Each platform has GCC available and uses the same shell. One idea was to have the C compiled to the users local ~/bin, with timestamp comparison with C code so it is not compiled each run, but only when code is updated. Another was to just compile it for each platform, and have the wrapper script select the proper executable. Is there an accepted/stable process for this? Are there any catches? Are there alternatives (assuming the absolute need to use native C code)? Clarification: Multiple OS's are involved that do not share ABI. Eg. OS X, various Linuxes, BSD etc. I need to be able to update the code in place in shared folders and have the new code working more or less instantaneously. Distributing binary or source packages is less than ideal.
4
python,c,cross-platform,posix,scripting
39,847
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.
false
2008-09-02 15:46:39.193
293
2
0.099668
Using C in a shared multi-platform POSIX environment
2
39,865
4
I write tools that are used in a shared workspace. Since there are multiple OS's working in this space, we generally use Python and standardize the version that is installed across machines. However, if I wanted to write some things in C, I was wondering if maybe I could have the application wrapped in a Python script, that detected the operating system and fired off the correct version of the C application. Each platform has GCC available and uses the same shell. One idea was to have the C compiled to the users local ~/bin, with timestamp comparison with C code so it is not compiled each run, but only when code is updated. Another was to just compile it for each platform, and have the wrapper script select the proper executable. Is there an accepted/stable process for this? Are there any catches? Are there alternatives (assuming the absolute need to use native C code)? Clarification: Multiple OS's are involved that do not share ABI. Eg. OS X, various Linuxes, BSD etc. I need to be able to update the code in place in shared folders and have the new code working more or less instantaneously. Distributing binary or source packages is less than ideal.
4
python,c,cross-platform,posix,scripting
39,847
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.
false
2008-09-02 15:46:39.193
293
0
0
Using C in a shared multi-platform POSIX environment
2
41,721
9
I have a method in my Python code that returns a tuple - a row from a SQL query. Let's say it has three fields: (jobId, label, username) For ease of passing it around between functions, I've been passing the entire tuple as a variable called 'job'. Eventually, however, I want to get at the bits, so I've been using code like this: (jobId, label, username) = job I've realised, however, that this is a maintenance nightmare, because now I can never add new fields to the result set without breaking all of my existing code. How should I have written this? Here are my two best guesses: (jobId, label, username) = (job[0], job[1], job[2]) ...but that doesn't scale nicely when you have 15...20 fields or to convert the results from the SQL query to a dictionary straight away and pass that around (I don't have control over the fact that it starts life as a tuple, that's fixed for me)
1
python,tuples
41,701
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.
false
2008-09-03 13:48:30.657
9,634
3
0.066568
Splitting tuples in Python - best practice?
13
42,048
11
I am learning Python for a class now, and we just covered tuples as one of the data types. I read the Wikipedia page on it, but, I could not figure out where such a data type would be useful in practice. Can I have some examples, perhaps in Python, where an immutable set of numbers would be needed? How is this different from a list?
5
python,tuples
42,034
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).
true
2008-09-03 16:13:06.737
46,193
65
1.2
What is a tuple useful for?
56
42,049
11
I am learning Python for a class now, and we just covered tuples as one of the data types. I read the Wikipedia page on it, but, I could not figure out where such a data type would be useful in practice. Can I have some examples, perhaps in Python, where an immutable set of numbers would be needed? How is this different from a list?
5
python,tuples
42,034
I find them useful when you always deal with two or more objects as a set.
false
2008-09-03 16:13:06.737
46,193
2
0.036348
What is a tuple useful for?
56
51,200
11
I am learning Python for a class now, and we just covered tuples as one of the data types. I read the Wikipedia page on it, but, I could not figure out where such a data type would be useful in practice. Can I have some examples, perhaps in Python, where an immutable set of numbers would be needed? How is this different from a list?
5
python,tuples
42,034
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.
false
2008-09-03 16:13:06.737
46,193
0
0
What is a tuple useful for?
56
42,060
11
I am learning Python for a class now, and we just covered tuples as one of the data types. I read the Wikipedia page on it, but, I could not figure out where such a data type would be useful in practice. Can I have some examples, perhaps in Python, where an immutable set of numbers would be needed? How is this different from a list?
5
python,tuples
42,034
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.
false
2008-09-03 16:13:06.737
46,193
4
0.072599
What is a tuple useful for?
56
42,055
11
I am learning Python for a class now, and we just covered tuples as one of the data types. I read the Wikipedia page on it, but, I could not figure out where such a data type would be useful in practice. Can I have some examples, perhaps in Python, where an immutable set of numbers would be needed? How is this different from a list?
5
python,tuples
42,034
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.
false
2008-09-03 16:13:06.737
46,193
1
0.01818
What is a tuple useful for?
56
467,185
6
I'd like to take some time to learn more about dynamic languages built on top of the DLR and I'm not sure which language would be better to learn. Having limited time, I really only have time to look learn one of them. Any opinions on which of the two (Iron Ruby or Iron Python) would be more useful in the long run?
3
.net,ironpython,ironruby,dynamic-language-runtime,dynamic-languages
42,690
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.
false
2008-09-03 21:52:50.197
1,222
1
0.033321
Which Dynamic .NET language makes more sense to learn, Iron Ruby or Iron Python?
5
61,734
6
I'd like to take some time to learn more about dynamic languages built on top of the DLR and I'm not sure which language would be better to learn. Having limited time, I really only have time to look learn one of them. Any opinions on which of the two (Iron Ruby or Iron Python) would be more useful in the long run?
3
.net,ironpython,ironruby,dynamic-language-runtime,dynamic-languages
42,690
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
true
2008-09-03 21:52:50.197
1,222
4
1.2
Which Dynamic .NET language makes more sense to learn, Iron Ruby or Iron Python?
5
42,702
6
I'd like to take some time to learn more about dynamic languages built on top of the DLR and I'm not sure which language would be better to learn. Having limited time, I really only have time to look learn one of them. Any opinions on which of the two (Iron Ruby or Iron Python) would be more useful in the long run?
3
.net,ironpython,ironruby,dynamic-language-runtime,dynamic-languages
42,690
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)
false
2008-09-03 21:52:50.197
1,222
5
0.16514
Which Dynamic .NET language makes more sense to learn, Iron Ruby or Iron Python?
5
72,249
4
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.
1
python,django,url,django-urls
43,290
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).
false
2008-09-04 07:36:39.277
37,259
4
0.197375
How to generate urls in django
35
48,479
5
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?
1
python,sql,metadata,coupling,data-driven
43,368
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.
false
2008-09-04 08:53:58.140
2,785
1
0.039979
A python web application framework for tight DB/GUI coupling?
11
11,101,343
18
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?
3
python,mime
43,580
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.
false
2008-09-04 12:07:27.037
233,034
1
0.011111
How to find the mime type of a file in python?
242
51,510,950
18
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?
3
python,mime
43,580
For byte Array type data you can use magic.from_buffer(_byte_array,mime=True)
false
2008-09-04 12:07:27.037
233,034
0
0
How to find the mime type of a file in python?
242
12,297,929
18
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?
3
python,mime
43,580
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.
false
2008-09-04 12:07:27.037
233,034
11
1
How to find the mime type of a file in python?
242
43,794
12
Can you please tell me how much is (-2) % 5? According to my Python interpreter is 3, but do you have a wise explanation for this? I've read that in some languages the result can be machine-dependent, but I'm not sure though.
6
python,math,modulo
43,775
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.
true
2008-09-04 13:36:46.917
11,706
16
1.2
Modulus operation with negatives values - weird thing?
18
43,780
12
Can you please tell me how much is (-2) % 5? According to my Python interpreter is 3, but do you have a wise explanation for this? I've read that in some languages the result can be machine-dependent, but I'm not sure though.
6
python,math,modulo
43,775
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
false
2008-09-04 13:36:46.917
11,706
14
1
Modulus operation with negatives values - weird thing?
18
43,781
12
Can you please tell me how much is (-2) % 5? According to my Python interpreter is 3, but do you have a wise explanation for this? I've read that in some languages the result can be machine-dependent, but I'm not sure though.
6
python,math,modulo
43,775
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.
false
2008-09-04 13:36:46.917
11,706
0
0
Modulus operation with negatives values - weird thing?
18
43,785
12
Can you please tell me how much is (-2) % 5? According to my Python interpreter is 3, but do you have a wise explanation for this? I've read that in some languages the result can be machine-dependent, but I'm not sure though.
6
python,math,modulo
43,775
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.
false
2008-09-04 13:36:46.917
11,706
4
0.066568
Modulus operation with negatives values - weird thing?
18
43,799
12
Can you please tell me how much is (-2) % 5? According to my Python interpreter is 3, but do you have a wise explanation for this? I've read that in some languages the result can be machine-dependent, but I'm not sure though.
6
python,math,modulo
43,775
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#).
false
2008-09-04 13:36:46.917
11,706
0
0
Modulus operation with negatives values - weird thing?
18
5,203,460
12
Can you please tell me how much is (-2) % 5? According to my Python interpreter is 3, but do you have a wise explanation for this? I've read that in some languages the result can be machine-dependent, but I'm not sure though.
6
python,math,modulo
43,775
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.
false
2008-09-04 13:36:46.917
11,706
0
0
Modulus operation with negatives values - weird thing?
18
44,221
11
How do you insert invisible watermarks in images for copyright purposes? I'm looking for a python library. What algorithm do you use? What about performance and efficiency?
4
python,image,watermark
44,101
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.
false
2008-09-04 16:15:42.633
13,301
0
0
invisible watermarks in images
12
44,217
11
How do you insert invisible watermarks in images for copyright purposes? I'm looking for a python library. What algorithm do you use? What about performance and efficiency?
4
python,image,watermark
44,101
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.
false
2008-09-04 16:15:42.633
13,301
6
1
invisible watermarks in images
12
541,170
11
How do you insert invisible watermarks in images for copyright purposes? I'm looking for a python library. What algorithm do you use? What about performance and efficiency?
4
python,image,watermark
44,101
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>
false
2008-09-04 16:15:42.633
13,301
2
0.036348
invisible watermarks in images
12
44,132
11
How do you insert invisible watermarks in images for copyright purposes? I'm looking for a python library. What algorithm do you use? What about performance and efficiency?
4
python,image,watermark
44,101
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.
false
2008-09-04 16:15:42.633
13,301
1
0.01818
invisible watermarks in images
12
427,643
6
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.
1
python,django
44,135
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.
false
2008-09-04 16:36:12.180
7,973
1
0.033321
Project design / FS layout for large django projects
44
44,842
11
I see __all__ in __init__.py files. What does it do?
1
python,syntax,namespaces
44,834
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.
true
2008-09-04 21:28:18.547
473,666
797
1.2
What does __all__ mean in Python?
1,420
45,520
7
I'm looking to create favicon.ico files programatically from Python, but PIL only has support for reading ico files.
1
python,favicon
45,507
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.
false
2008-09-05 10:26:47.223
25,030
1
0.028564
Is there a Python library for generating .ico files?
32
2,036,609
6
If I was going to start an open source project using Python what version should I use to ensure that the vast majority of users can use it on their system? I'm the kind of person who quickly jumps to the next version (which I'll do when Python 3 comes out) but many people may be more conservative if their current version seems to be working fine. What version would hit the sweet spot but still allow me to enjoy the newest and coolest language enhancements?
2
python,compatibility
47,198
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.
false
2008-09-06 02:22:50.683
3,460
0
0
Which Version of Python to Use for Maximum Compatibility
15
47,264
6
If I was going to start an open source project using Python what version should I use to ensure that the vast majority of users can use it on their system? I'm the kind of person who quickly jumps to the next version (which I'll do when Python 3 comes out) but many people may be more conservative if their current version seems to be working fine. What version would hit the sweet spot but still allow me to enjoy the newest and coolest language enhancements?
2
python,compatibility
47,198
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.
false
2008-09-06 02:22:50.683
3,460
1
0.033321
Which Version of Python to Use for Maximum Compatibility
15
277,800
10
I'm trying to debug a deadlock in a multi-threaded Python application after it has locked up. Is there a way to attach a debugger to inspect the state of the process? Edit: I'm attempting this on Linux, but it would be great if there were a cross-platform solution. It's Python after all :)
1
python,debugging
47,701
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.
false
2008-09-06 18:14:05.607
34,732
4
0.07983
Is there a way to attach a debugger to a multi-threaded Python process?
35
47,958
6
I've read some about .egg files and I've noticed them in my lib directory but what are the advantages/disadvantages of using then as a developer?
3
python,zip,packaging,software-distribution,egg
47,953
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.
false
2008-09-06 23:35:30.560
10,471
4
0.132549
What are the advantages of packaging your python library/application as an .egg file?
27
137,903
6
I've read some about .egg files and I've noticed them in my lib directory but what are the advantages/disadvantages of using then as a developer?
3
python,zip,packaging,software-distribution,egg
47,953
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.
false
2008-09-06 23:35:30.560
10,471
1
0.033321
What are the advantages of packaging your python library/application as an .egg file?
27
138,090
6
I've read some about .egg files and I've noticed them in my lib directory but what are the advantages/disadvantages of using then as a developer?
3
python,zip,packaging,software-distribution,egg
47,953
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.
false
2008-09-06 23:35:30.560
10,471
1
0.033321
What are the advantages of packaging your python library/application as an .egg file?
27
54,313
11
I've been learning python for a while now with some success. I even managed to create one or two (simple) programs using PyGtk + Glade. The thing is: I am not sure if the best way to use GTK with python is by building the interfaces using Glade. I was wondering if the more experienced ones among us (remember, I'm just a beginner) could point out the benefits and caveats of using Glade as opposed to creating everything in the code itself (assuming that learning the correct gtk bindings wouldn't exactly be a problem).
8
python,gtk,pygtk,glade,gtk2
48,123
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.
false
2008-09-07 04:00:41.437
8,539
5
0.090659
Glade or no glade: What is the best way to use PyGtk?
32
2,149,087
11
I've been learning python for a while now with some success. I even managed to create one or two (simple) programs using PyGtk + Glade. The thing is: I am not sure if the best way to use GTK with python is by building the interfaces using Glade. I was wondering if the more experienced ones among us (remember, I'm just a beginner) could point out the benefits and caveats of using Glade as opposed to creating everything in the code itself (assuming that learning the correct gtk bindings wouldn't exactly be a problem).
8
python,gtk,pygtk,glade,gtk2
48,123
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.
false
2008-09-07 04:00:41.437
8,539
2
0.036348
Glade or no glade: What is the best way to use PyGtk?
32
107,959
11
I've been learning python for a while now with some success. I even managed to create one or two (simple) programs using PyGtk + Glade. The thing is: I am not sure if the best way to use GTK with python is by building the interfaces using Glade. I was wondering if the more experienced ones among us (remember, I'm just a beginner) could point out the benefits and caveats of using Glade as opposed to creating everything in the code itself (assuming that learning the correct gtk bindings wouldn't exactly be a problem).
8
python,gtk,pygtk,glade,gtk2
48,123
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.
false
2008-09-07 04:00:41.437
8,539
4
0.072599
Glade or no glade: What is the best way to use PyGtk?
32
48,136
11
I've been learning python for a while now with some success. I even managed to create one or two (simple) programs using PyGtk + Glade. The thing is: I am not sure if the best way to use GTK with python is by building the interfaces using Glade. I was wondering if the more experienced ones among us (remember, I'm just a beginner) could point out the benefits and caveats of using Glade as opposed to creating everything in the code itself (assuming that learning the correct gtk bindings wouldn't exactly be a problem).
8
python,gtk,pygtk,glade,gtk2
48,123
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.
false
2008-09-07 04:00:41.437
8,539
12
1
Glade or no glade: What is the best way to use PyGtk?
32
106,889
11
I've been learning python for a while now with some success. I even managed to create one or two (simple) programs using PyGtk + Glade. The thing is: I am not sure if the best way to use GTK with python is by building the interfaces using Glade. I was wondering if the more experienced ones among us (remember, I'm just a beginner) could point out the benefits and caveats of using Glade as opposed to creating everything in the code itself (assuming that learning the correct gtk bindings wouldn't exactly be a problem).
8
python,gtk,pygtk,glade,gtk2
48,123
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.
false
2008-09-07 04:00:41.437
8,539
5
0.090659
Glade or no glade: What is the best way to use PyGtk?
32
199,167
11
I've been learning python for a while now with some success. I even managed to create one or two (simple) programs using PyGtk + Glade. The thing is: I am not sure if the best way to use GTK with python is by building the interfaces using Glade. I was wondering if the more experienced ones among us (remember, I'm just a beginner) could point out the benefits and caveats of using Glade as opposed to creating everything in the code itself (assuming that learning the correct gtk bindings wouldn't exactly be a problem).
8
python,gtk,pygtk,glade,gtk2
48,123
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.
false
2008-09-07 04:00:41.437
8,539
1
0.01818
Glade or no glade: What is the best way to use PyGtk?
32
751,707
11
I've been learning python for a while now with some success. I even managed to create one or two (simple) programs using PyGtk + Glade. The thing is: I am not sure if the best way to use GTK with python is by building the interfaces using Glade. I was wondering if the more experienced ones among us (remember, I'm just a beginner) could point out the benefits and caveats of using Glade as opposed to creating everything in the code itself (assuming that learning the correct gtk bindings wouldn't exactly be a problem).
8
python,gtk,pygtk,glade,gtk2
48,123
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.
false
2008-09-07 04:00:41.437
8,539
1
0.01818
Glade or no glade: What is the best way to use PyGtk?
32
305,667
11
I've been learning python for a while now with some success. I even managed to create one or two (simple) programs using PyGtk + Glade. The thing is: I am not sure if the best way to use GTK with python is by building the interfaces using Glade. I was wondering if the more experienced ones among us (remember, I'm just a beginner) could point out the benefits and caveats of using Glade as opposed to creating everything in the code itself (assuming that learning the correct gtk bindings wouldn't exactly be a problem).
8
python,gtk,pygtk,glade,gtk2
48,123
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.
false
2008-09-07 04:00:41.437
8,539
2
0.036348
Glade or no glade: What is the best way to use PyGtk?
32
69,672,216
7
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.
1
c++,python,embedded-language
49,137
Using Inter Process Communication (IPC) over socket can be a possible solution. Use a local network socket to listen/trasfer commands between both.
false
2008-09-08 03:53:39.560
100,997
0
0
Calling python from a c++ program for distribution
65
10,241,354
7
I've used several modules to make EXEs for Python, but I'm not sure if I'm doing it right. How should I go about this, and why? Please base your answers on personal experience, and provide references where necessary.
2
python,exe,executable
49,146
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.
false
2008-09-08 03:59:57.937
289,620
4
0.113791
How can I make an EXE file from a Python program?
115
15,667,090
7
I've used several modules to make EXEs for Python, but I'm not sure if I'm doing it right. How should I go about this, and why? Please base your answers on personal experience, and provide references where necessary.
2
python,exe,executable
49,146
Use cx_Freeze to make exe your python program
false
2008-09-08 03:59:57.937
289,620
3
0.085505
How can I make an EXE file from a Python program?
115
49,248
14
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
12
python,c
49,195
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++).
false
2008-09-08 05:23:35.957
871
0
0
What language should I learn as a bridge to C (and derivatives)
4
49,295
14
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
12
python,c
49,195
try to learn a language which you are comfortable with, try different approach and the basics.
false
2008-09-08 05:23:35.957
871
0
0
What language should I learn as a bridge to C (and derivatives)
4
49,227
14
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
12
python,c
49,195
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.
false
2008-09-08 05:23:35.957
871
7
1
What language should I learn as a bridge to C (and derivatives)
4
49,217
14
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
12
python,c
49,195
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.
false
2008-09-08 05:23:35.957
871
0
0
What language should I learn as a bridge to C (and derivatives)
4
50,673
14
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
12
python,c
49,195
Pascal! Close enough syntax, still requires you to do some memory management, but not as rough for beginners.
false
2008-09-08 05:23:35.957
871
0
0
What language should I learn as a bridge to C (and derivatives)
4
49,285
14
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
12
python,c
49,195
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 :)
false
2008-09-08 05:23:35.957
871
5
0.071307
What language should I learn as a bridge to C (and derivatives)
4
49,502
14
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
12
python,c
49,195
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.
false
2008-09-08 05:23:35.957
871
0
0
What language should I learn as a bridge to C (and derivatives)
4
49,246
14
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
12
python,c
49,195
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 ...
false
2008-09-08 05:23:35.957
871
1
0.014285
What language should I learn as a bridge to C (and derivatives)
4
49,245
14
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
12
python,c
49,195
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 ;)
false
2008-09-08 05:23:35.957
871
1
0.014285
What language should I learn as a bridge to C (and derivatives)
4
49,237
14
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
12
python,c
49,195
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.
false
2008-09-08 05:23:35.957
871
0
0
What language should I learn as a bridge to C (and derivatives)
4
49,234
14
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
12
python,c
49,195
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.
false
2008-09-08 05:23:35.957
871
1
0.014285
What language should I learn as a bridge to C (and derivatives)
4
49,202
14
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
12
python,c
49,195
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.
true
2008-09-08 05:23:35.957
871
15
1.2
What language should I learn as a bridge to C (and derivatives)
4
138,886
7
Using the zip function, Python allows for loops to traverse multiple sequences in parallel. for (x,y) in zip(List1, List2): Does MATLAB have an equivalent syntax? If not, what is the best way to iterate over two parallel arrays at the same time using MATLAB?
1
python,arrays,matlab,for-loop
49,307
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.
false
2008-09-08 08:25:55.037
7,417
-2
-0.057081
Can parallel traversals be done in MATLAB just as in Python?
14
49,953
5
Besides the dynamic nature of Python (and the syntax), what are some of the major features of the Python language that Java doesn't have, and vice versa?
2
java,python
49,824
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.
true
2008-09-08 14:36:24.083
11,654
47
1.2
Java -> Python?
29
51,512
5
Besides the dynamic nature of Python (and the syntax), what are some of the major features of the Python language that Java doesn't have, and vice versa?
2
java,python
49,824
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
false
2008-09-08 14:36:24.083
11,654
2
0.07983
Java -> Python?
29
326,046
5
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?
3
python,django,session,caching,mongodb
50,568
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.
false
2008-09-08 20:16:16.717
12,358
1
0.039979
Django Sessions
38
50,668
5
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?
3
python,django,session,caching,mongodb
50,568
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.
false
2008-09-08 20:16:16.717
12,358
25
1
Django Sessions
38
100,464
5
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?
3
python,django,session,caching,mongodb
50,568
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.
false
2008-09-08 20:16:16.717
12,358
3
0.119427
Django Sessions
38
108,603
7
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?
2
python,datetime,time
51,010
Retrieve the times in milliseconds and then do the subtraction.
false
2008-09-09 00:28:58.420
10,861
-1
-0.028564
What is the simplest way to find the difference between 2 times in python?
13
263,451
7
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?
2
python,datetime,time
51,010
Environment.TickCount seems to work well if you need something quick. int start = Environment.TickCount ...DoSomething() int elapsedtime = Environment.TickCount - start Jon
false
2008-09-09 00:28:58.420
10,861
-3
-0.085505
What is the simplest way to find the difference between 2 times in python?
13
17,123,979
12
How can I retrieve the page title of a webpage (title html tag) using Python?
1
python,html
51,233
soup.title.string actually returns a unicode string. To convert that into normal string, you need to do string=string.encode('ascii','ignore')
false
2008-09-09 04:38:55.527
103,114
2
0.033321
How can I retrieve the page title of a webpage using Python?
86
4,908,742
12
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.?
3
python,orm
53,428
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.
false
2008-09-10 04:49:32.667
178,152
0
0
What are some good Python ORM solutions?
236
186,179
12
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.?
3
python,orm
53,428
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.
false
2008-09-10 04:49:32.667
178,152
1
0.016665
What are some good Python ORM solutions?
236
2,510,845
12
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.?
3
python,orm
53,428
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.
false
2008-09-10 04:49:32.667
178,152
-2
-0.033321
What are some good Python ORM solutions?
236
199,275
6
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?
3
python,ironpython,jython,cpython
53,543
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.
false
2008-09-10 07:04:43.920
1,296
2
0.066568
What are some strategies to write python code that works in CPython, Jython and IronPython
16
637,549
6
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?
3
python,ironpython,jython,cpython
53,543
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.
false
2008-09-10 07:04:43.920
1,296
0
0
What are some strategies to write python code that works in CPython, Jython and IronPython
16
342,835
6
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?
3
python,ironpython,jython,cpython
53,543
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.
false
2008-09-10 07:04:43.920
1,296
1
0.033321
What are some strategies to write python code that works in CPython, Jython and IronPython
16
230,476
11
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?
2
python,ajax,google-app-engine
53,997
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.
false
2008-09-10 13:12:07.267
11,904
0
0
Any good AJAX framework for Google App Engine apps?
14
54,015
11
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?
2
python,ajax,google-app-engine
53,997
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.
false
2008-09-10 13:12:07.267
11,904
3
0.054491
Any good AJAX framework for Google App Engine apps?
14
16,295,402
8
What is the difference between old style and new style classes in Python? When should I use one or the other?
2
python,class,oop,types,new-style-class
54,867
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.
false
2008-09-10 18:01:27.163
257,866
8
1
What is the difference between old style and new style classes in Python?
1,091
3,228,045
8
What is the difference between old style and new style classes in Python? When should I use one or the other?
2
python,class,oop,types,new-style-class
54,867
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
false
2008-09-10 18:01:27.163
257,866
41
1
What is the difference between old style and new style classes in Python?
1,091
56,008
3
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?
1
python,emacs,ide,keyboard
55,365
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, ...
true
2008-09-10 21:32:47.140
1,983
6
1.2
How can I get Emacs' key bindings in Python's IDLE?
6
56,029
19
According to the documentation, they're pretty much interchangeable. Is there a stylistic reason to use one over the other?
12
python,coding-style
56,011
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.
false
2008-09-11 08:18:55.293
712,544
0
0
Single quotes vs. double quotes in Python
718
3,179,568
19
According to the documentation, they're pretty much interchangeable. Is there a stylistic reason to use one over the other?
12
python,coding-style
56,011
In Perl you want to use single quotes when you have a string which doesn't need to interpolate variables or escaped characters like \n, \t, \r, etc. PHP makes the same distinction as Perl: content in single quotes will not be interpreted (not even \n will be converted), as opposed to double quotes which can contain variables to have their value printed out. Python does not, I'm afraid. Technically seen, there is no $ token (or the like) to separate a name/text from a variable in Python. Both features make Python more readable, less confusing, after all. Single and double quotes can be used interchangeably in Python.
false
2008-09-11 08:18:55.293
712,544
2
0.02105
Single quotes vs. double quotes in Python
718
56,025
19
According to the documentation, they're pretty much interchangeable. Is there a stylistic reason to use one over the other?
12
python,coding-style
56,011
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 '
false
2008-09-11 08:18:55.293
712,544
0
0
Single quotes vs. double quotes in Python
718
104,842
19
According to the documentation, they're pretty much interchangeable. Is there a stylistic reason to use one over the other?
12
python,coding-style
56,011
It's probably a stylistic preference more than anything. I just checked PEP 8 and didn't see any mention of single versus double quotes. I prefer single quotes because its only one keystroke instead of two. That is, I don't have to mash the shift key to make single quote.
false
2008-09-11 08:18:55.293
712,544
2
0.02105
Single quotes vs. double quotes in Python
718
629,106
19
According to the documentation, they're pretty much interchangeable. Is there a stylistic reason to use one over the other?
12
python,coding-style
56,011
I chose to use double quotes because they are easier to see.
false
2008-09-11 08:18:55.293
712,544
1
0.010526
Single quotes vs. double quotes in Python
718
56,047
19
According to the documentation, they're pretty much interchangeable. Is there a stylistic reason to use one over the other?
12
python,coding-style
56,011
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.
false
2008-09-11 08:18:55.293
712,544
3
0.031568
Single quotes vs. double quotes in Python
718
16,048,319
19
According to the documentation, they're pretty much interchangeable. Is there a stylistic reason to use one over the other?
12
python,coding-style
56,011
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.
false
2008-09-11 08:18:55.293
712,544
0
0
Single quotes vs. double quotes in Python
718
56,041
19
According to the documentation, they're pretty much interchangeable. Is there a stylistic reason to use one over the other?
12
python,coding-style
56,011
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.
false
2008-09-11 08:18:55.293
712,544
26
1
Single quotes vs. double quotes in Python
718
56,210
19
According to the documentation, they're pretty much interchangeable. Is there a stylistic reason to use one over the other?
12
python,coding-style
56,011
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.
false
2008-09-11 08:18:55.293
712,544
44
1
Single quotes vs. double quotes in Python
718
1,167,795
19
According to the documentation, they're pretty much interchangeable. Is there a stylistic reason to use one over the other?
12
python,coding-style
56,011
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...
false
2008-09-11 08:18:55.293
712,544
1
0.010526
Single quotes vs. double quotes in Python
718