title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
list
What is the best project structure for a Python application?
193,161
<p>Imagine that you want to develop a non-trivial end-user desktop (not web) application in Python. What is the best way to structure the project's folder hierarchy?</p> <p>Desirable features are ease of maintenance, IDE-friendliness, suitability for source control branching/merging, and easy generation of install pac...
405
2008-10-10T21:50:34Z
193,256
<p>Non-python data is best bundled inside your Python modules using the <code>package_data</code> support in <A HREF="http://peak.telecommunity.com/DevCenter/setuptools">setuptools</A>. One thing I strongly recommend is using namespace packages to create shared namespaces which multiple projects can use -- much like th...
6
2008-10-10T22:39:22Z
[ "python", "directory-structure", "project-structure" ]
What is the best project structure for a Python application?
193,161
<p>Imagine that you want to develop a non-trivial end-user desktop (not web) application in Python. What is the best way to structure the project's folder hierarchy?</p> <p>Desirable features are ease of maintenance, IDE-friendliness, suitability for source control branching/merging, and easy generation of install pac...
405
2008-10-10T21:50:34Z
193,280
<p>In my experience, it's just a matter of iteration. Put your data and code wherever you think they go. Chances are, you'll be wrong anyway. But once you get a better idea of exactly how things are going to shape up, you're in a much better position to make these kinds of guesses.</p> <p>As far as extension source...
12
2008-10-10T22:57:39Z
[ "python", "directory-structure", "project-structure" ]
What is the best project structure for a Python application?
193,161
<p>Imagine that you want to develop a non-trivial end-user desktop (not web) application in Python. What is the best way to structure the project's folder hierarchy?</p> <p>Desirable features are ease of maintenance, IDE-friendliness, suitability for source control branching/merging, and easy generation of install pac...
405
2008-10-10T21:50:34Z
3,419,951
<p>This <a href="http://as.ynchrono.us/2007/12/filesystem-structure-of-python-project_21.html">blog post by Jean-Paul Calderone</a> is commonly given as an answer in #python on Freenode.</p> <blockquote> <h2>Filesystem structure of a Python project</h2> <p>Do:</p> <ul> <li>name the directory something re...
126
2010-08-05T23:29:58Z
[ "python", "directory-structure", "project-structure" ]
What is the best project structure for a Python application?
193,161
<p>Imagine that you want to develop a non-trivial end-user desktop (not web) application in Python. What is the best way to structure the project's folder hierarchy?</p> <p>Desirable features are ease of maintenance, IDE-friendliness, suitability for source control branching/merging, and easy generation of install pac...
405
2008-10-10T21:50:34Z
5,169,006
<p>It's worth reading through Python's documentation on packaging, too.</p> <p><a href="http://docs.python.org/tutorial/modules.html#packages">http://docs.python.org/tutorial/modules.html#packages</a></p> <p>Also make sure you're familiar with the rest of the information on that page.</p>
18
2011-03-02T14:37:19Z
[ "python", "directory-structure", "project-structure" ]
What is the best project structure for a Python application?
193,161
<p>Imagine that you want to develop a non-trivial end-user desktop (not web) application in Python. What is the best way to structure the project's folder hierarchy?</p> <p>Desirable features are ease of maintenance, IDE-friendliness, suitability for source control branching/merging, and easy generation of install pac...
405
2008-10-10T21:50:34Z
5,998,845
<p>According to Jean-Paul Calderone's <a href="http://as.ynchrono.us/2007/12/filesystem-structure-of-python-project_21.html">Filesystem structure of a Python project</a>:</p> <pre><code>Project/ |-- bin/ | |-- project | |-- project/ | |-- test/ | | |-- __init__.py | | |-- test_main.py | | | |-- __in...
146
2011-05-13T23:49:13Z
[ "python", "directory-structure", "project-structure" ]
What is the best project structure for a Python application?
193,161
<p>Imagine that you want to develop a non-trivial end-user desktop (not web) application in Python. What is the best way to structure the project's folder hierarchy?</p> <p>Desirable features are ease of maintenance, IDE-friendliness, suitability for source control branching/merging, and easy generation of install pac...
405
2008-10-10T21:50:34Z
19,871,661
<p>Check out <a href="http://www.jeffknupp.com/blog/2013/08/16/open-sourcing-a-python-project-the-right-way/">Open Sourcing a Python Project the Right Way</a>.</p> <p>Let me excerpt the <em>project layout</em> part of that excellent article:</p> <blockquote> <p>When setting up a project, the layout (or directory st...
69
2013-11-09T02:22:39Z
[ "python", "directory-structure", "project-structure" ]
What is the best project structure for a Python application?
193,161
<p>Imagine that you want to develop a non-trivial end-user desktop (not web) application in Python. What is the best way to structure the project's folder hierarchy?</p> <p>Desirable features are ease of maintenance, IDE-friendliness, suitability for source control branching/merging, and easy generation of install pac...
405
2008-10-10T21:50:34Z
22,554,594
<p>Try starting the project using the <a href="https://pypi.python.org/pypi/python_boilerplate_template">python_boilerplate</a> template. It largely follows the best practices (e.g. <a href="http://www.jeffknupp.com/blog/2013/08/16/open-sourcing-a-python-project-the-right-way/">those here</a>), but is better suited in ...
11
2014-03-21T09:17:46Z
[ "python", "directory-structure", "project-structure" ]
What is the best project structure for a Python application?
193,161
<p>Imagine that you want to develop a non-trivial end-user desktop (not web) application in Python. What is the best way to structure the project's folder hierarchy?</p> <p>Desirable features are ease of maintenance, IDE-friendliness, suitability for source control branching/merging, and easy generation of install pac...
405
2008-10-10T21:50:34Z
30,799,616
<p>The "Python Packaging Authority" has a sampleproject:</p> <p><a href="https://github.com/pypa/sampleproject" rel="nofollow">https://github.com/pypa/sampleproject</a></p> <p>IT is a sample project that exists as an aid to the Python Packaging User Guide's Tutorial on Packaging and Distributing Projects.</p>
3
2015-06-12T09:23:59Z
[ "python", "directory-structure", "project-structure" ]
What are best practices for developing consistent libraries?
193,701
<p>I am working on developing a pair of libraries to work with a REST API. Because I need to be able to use the API in very different settings I'm currently planning to have a version in PHP (for web applications) and a second version in Python (for desktop applications, and long running processes). Are there any bes...
3
2008-10-11T05:34:54Z
193,709
<p>Well, the obvious one would be to keep your naming consistent. Functions and classes should be named similarly (if not identically) in both implementations. This usually happens naturally whenever you implement an API separately in two different languages. The big ticket item though (at least in my book) is to fo...
0
2008-10-11T05:42:41Z
[ "php", "python", "api", "rest" ]
What are best practices for developing consistent libraries?
193,701
<p>I am working on developing a pair of libraries to work with a REST API. Because I need to be able to use the API in very different settings I'm currently planning to have a version in PHP (for web applications) and a second version in Python (for desktop applications, and long running processes). Are there any bes...
3
2008-10-11T05:34:54Z
193,713
<p>So, the problem with developing parallel libraries in different languages is that often times different languages will have different idioms for the same task. I know this from personal experience, having ported a library from Python to PHP. Idioms aren't just naming: for example, Python has a good deal of magic you...
6
2008-10-11T05:46:00Z
[ "php", "python", "api", "rest" ]
What are best practices for developing consistent libraries?
193,701
<p>I am working on developing a pair of libraries to work with a REST API. Because I need to be able to use the API in very different settings I'm currently planning to have a version in PHP (for web applications) and a second version in Python (for desktop applications, and long running processes). Are there any bes...
3
2008-10-11T05:34:54Z
193,714
<p>'Be your own client' : I've found that the technique of writing tests first is an excellent way of ensuring an API is easy to use. Writing tests first means you will be thinking like a 'consumer' of your API rather than just an implementor. </p>
2
2008-10-11T05:46:18Z
[ "php", "python", "api", "rest" ]
What are best practices for developing consistent libraries?
193,701
<p>I am working on developing a pair of libraries to work with a REST API. Because I need to be able to use the API in very different settings I'm currently planning to have a version in PHP (for web applications) and a second version in Python (for desktop applications, and long running processes). Are there any bes...
3
2008-10-11T05:34:54Z
193,807
<p>Try to write a common unit test suite for both. Maybe by wrapping a class in one language for calling it from the other. If you can't do it, at least make sure the two versions of the tests are equivalent.</p>
2
2008-10-11T07:28:57Z
[ "php", "python", "api", "rest" ]
What are best practices for developing consistent libraries?
193,701
<p>I am working on developing a pair of libraries to work with a REST API. Because I need to be able to use the API in very different settings I'm currently planning to have a version in PHP (for web applications) and a second version in Python (for desktop applications, and long running processes). Are there any bes...
3
2008-10-11T05:34:54Z
389,024
<p>AFAIKT there are a lot of bridges from to scripting languages. Let's take e.g Jruby, it's Ruby + Java, then there are things to embed Ruby in Python (or the other way). Then there are examples like Etoile where the base is Objective-C but also bridges to Python and Smalltalk, another approach on wide use: Wrappin...
0
2008-12-23T14:41:44Z
[ "php", "python", "api", "rest" ]
What are best practices for developing consistent libraries?
193,701
<p>I am working on developing a pair of libraries to work with a REST API. Because I need to be able to use the API in very different settings I'm currently planning to have a version in PHP (for web applications) and a second version in Python (for desktop applications, and long running processes). Are there any bes...
3
2008-10-11T05:34:54Z
959,080
<p>why not use python for web applications too? there are several frameworks available: django, web2py - similar to django but many say it's simpler to use, there is also TurboGears, web.py, Pylons</p> <p>along the lines of bridging - you could use interprocess communication to have PHP and python application (in daem...
0
2009-06-06T05:41:05Z
[ "php", "python", "api", "rest" ]
Microphone access in Python
193,789
<p>Can I access a users microphone in Python?</p> <p>Sorry I forgot not everyone is a mind reader: Windows at minimum XP but Vista support would be VERY good.</p>
10
2008-10-11T07:06:48Z
193,823
<p>Best way to go about it would be to use the ctypes library and use WinMM from that. mixerOpen will open a microphone device and you can read the data easily from there. Should be very straightforward.</p>
3
2008-10-11T07:47:44Z
[ "python", "windows", "microphone" ]
Microphone access in Python
193,789
<p>Can I access a users microphone in Python?</p> <p>Sorry I forgot not everyone is a mind reader: Windows at minimum XP but Vista support would be VERY good.</p>
10
2008-10-11T07:06:48Z
202,421
<p>You might try <a href="http://code.google.com/p/pygalaxy/wiki/SWMixer" rel="nofollow" title="SWMixer">SWMixer</a>.</p>
2
2008-10-14T19:07:36Z
[ "python", "windows", "microphone" ]
Microphone access in Python
193,789
<p>Can I access a users microphone in Python?</p> <p>Sorry I forgot not everyone is a mind reader: Windows at minimum XP but Vista support would be VERY good.</p>
10
2008-10-11T07:06:48Z
247,349
<p>I got the job done with <a href="http://people.csail.mit.edu/hubert/pyaudio/">pyaudio</a></p> <p>It comes with a binary installer for windows and there's even an example on how to record through the microphone and save to a wave file. Nice! I used it on Windows XP, not sure how it will do on Vista though, sorry.</p...
16
2008-10-29T15:53:36Z
[ "python", "windows", "microphone" ]
What are good rules of thumb for Python imports?
193,919
<p>I am a little confused by the multitude of ways in which you can import modules in Python. </p> <pre><code>import X import X as Y from A import B </code></pre> <p>I have been reading up about scoping and namespaces, but I would like some practical advice on what is the best strategy, under which circumstances and...
60
2008-10-11T09:59:35Z
193,927
<p>I would normally use <code>import X</code> on module level. If you only need a single object from a module, use <code>from X import Y</code>. </p> <p>Only use <code>import X as Y</code> in case you're otherwise confronted with a name clash.</p> <p>I only use imports on function level to import stuff I need when th...
9
2008-10-11T10:10:13Z
[ "python", "python-import" ]
What are good rules of thumb for Python imports?
193,919
<p>I am a little confused by the multitude of ways in which you can import modules in Python. </p> <pre><code>import X import X as Y from A import B </code></pre> <p>I have been reading up about scoping and namespaces, but I would like some practical advice on what is the best strategy, under which circumstances and...
60
2008-10-11T09:59:35Z
193,931
<p>In production code in our company, we try to follow the following rules.</p> <p>We place imports at the beginning of the file, right after the main file's docstring, e.g.:</p> <pre><code>""" Registry related functionality. """ import wx # ... </code></pre> <p>Now, if we import a class that is one of few in the im...
52
2008-10-11T10:15:40Z
[ "python", "python-import" ]
What are good rules of thumb for Python imports?
193,919
<p>I am a little confused by the multitude of ways in which you can import modules in Python. </p> <pre><code>import X import X as Y from A import B </code></pre> <p>I have been reading up about scoping and namespaces, but I would like some practical advice on what is the best strategy, under which circumstances and...
60
2008-10-11T09:59:35Z
193,937
<p>The <code>import X as Y</code> is useful if you have different implementations of the same module/class.</p> <p>With some nested <code>try..import..except ImportError..import</code>s you can hide the implementation from your code. See <a href="http://codespeak.net/lxml/tutorial.html" rel="nofollow">lxml etree impor...
0
2008-10-11T10:23:48Z
[ "python", "python-import" ]
What are good rules of thumb for Python imports?
193,919
<p>I am a little confused by the multitude of ways in which you can import modules in Python. </p> <pre><code>import X import X as Y from A import B </code></pre> <p>I have been reading up about scoping and namespaces, but I would like some practical advice on what is the best strategy, under which circumstances and...
60
2008-10-11T09:59:35Z
193,979
<p>I generally try to use the regular <code>import modulename</code>, unless the module name is long, or used often..</p> <p>For example, I would do..</p> <pre><code>from BeautifulSoup import BeautifulStoneSoup as BSS </code></pre> <p>..so I can do <code>soup = BSS(html)</code> instead of <code>BeautifulSoup.Beautif...
2
2008-10-11T11:27:35Z
[ "python", "python-import" ]
What are good rules of thumb for Python imports?
193,919
<p>I am a little confused by the multitude of ways in which you can import modules in Python. </p> <pre><code>import X import X as Y from A import B </code></pre> <p>I have been reading up about scoping and namespaces, but I would like some practical advice on what is the best strategy, under which circumstances and...
60
2008-10-11T09:59:35Z
194,085
<p>Others have covered most of the ground here but I just wanted to add one case where I will use <code>import X as Y</code> (temporarily), when I'm trying out a new version of a class or module.</p> <p>So if we were migrating to a new implementation of a module, but didn't want to cut the code base over all at one ti...
3
2008-10-11T13:49:34Z
[ "python", "python-import" ]
What are good rules of thumb for Python imports?
193,919
<p>I am a little confused by the multitude of ways in which you can import modules in Python. </p> <pre><code>import X import X as Y from A import B </code></pre> <p>I have been reading up about scoping and namespaces, but I would like some practical advice on what is the best strategy, under which circumstances and...
60
2008-10-11T09:59:35Z
194,096
<p>DON'T do this:</p> <pre><code>from X import * </code></pre> <p>unless you are absolutely sure that you will use each and every thing in that module. And even then, you should probably reconsider using a different approach.</p> <p>Other than that, it's just a matter of style.</p> <pre><code>from X import Y </cod...
3
2008-10-11T14:00:13Z
[ "python", "python-import" ]
What are good rules of thumb for Python imports?
193,919
<p>I am a little confused by the multitude of ways in which you can import modules in Python. </p> <pre><code>import X import X as Y from A import B </code></pre> <p>I have been reading up about scoping and namespaces, but I would like some practical advice on what is the best strategy, under which circumstances and...
60
2008-10-11T09:59:35Z
194,422
<p>Let me just paste a part of conversation on django-dev mailing list started by Guido van Rossum:</p> <blockquote> <p>[...] For example, it's part of the Google Python style guides[1] that all imports must import a module, not a class or function from that module. There are way more classes and functions tha...
30
2008-10-11T18:34:42Z
[ "python", "python-import" ]
What are good rules of thumb for Python imports?
193,919
<p>I am a little confused by the multitude of ways in which you can import modules in Python. </p> <pre><code>import X import X as Y from A import B </code></pre> <p>I have been reading up about scoping and namespaces, but I would like some practical advice on what is the best strategy, under which circumstances and...
60
2008-10-11T09:59:35Z
204,340
<p>When you have a well-written library, which is sometimes case in python, you ought just import it and use it as it. Well-written library tends to take life and language of its own, resulting in pleasant-to-read -code, where you rarely reference the library. When a library is well-written, you ought not need renaming...
1
2008-10-15T11:07:41Z
[ "python", "python-import" ]
What are good rules of thumb for Python imports?
193,919
<p>I am a little confused by the multitude of ways in which you can import modules in Python. </p> <pre><code>import X import X as Y from A import B </code></pre> <p>I have been reading up about scoping and namespaces, but I would like some practical advice on what is the best strategy, under which circumstances and...
60
2008-10-11T09:59:35Z
2,236,989
<p>I'm with Jason in the fact of not using</p> <pre><code>from X import * </code></pre> <p>But in my case (i'm not an expert programmer, so my code does not meet the coding style too well) I usually do in my programs a file with all the constants like program version, authors, error messages and all that stuff, so th...
0
2010-02-10T13:13:55Z
[ "python", "python-import" ]
What are good rules of thumb for Python imports?
193,919
<p>I am a little confused by the multitude of ways in which you can import modules in Python. </p> <pre><code>import X import X as Y from A import B </code></pre> <p>I have been reading up about scoping and namespaces, but I would like some practical advice on what is the best strategy, under which circumstances and...
60
2008-10-11T09:59:35Z
16,070,330
<p>Someone above said that</p> <pre><code>from X import A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P </code></pre> <p>is equivalent to</p> <pre><code>import X </code></pre> <p><code>import X</code> allows direct modifications to A-P, while <code>from X import ...</code> creates copies of A-P. For <code>from X import A..P</code>...
4
2013-04-17T21:10:34Z
[ "python", "python-import" ]
Recommended data format for describing the rules of chess
194,289
<p>I'm going to be writing a chess server and one or more clients for chess and I want to describe the rules of chess (e.g. allowable moves based on game state, rules for when a game is complete) in a programming language independant way. This is a bit tricky since some of the chess rules (e.g. King Castling, en passen...
8
2008-10-11T16:34:31Z
194,306
<p>Let's think. We're describing objects (locations and pieces) with states and behaviors. We need to note a current state and an ever-changing set of allowed state changes from a current state.</p> <p>This is programming. You don't want some "meta-language" that you can then parse in a regular programming language...
4
2008-10-11T16:48:28Z
[ "c#", "java", "python", "chess", "dataformat" ]
Recommended data format for describing the rules of chess
194,289
<p>I'm going to be writing a chess server and one or more clients for chess and I want to describe the rules of chess (e.g. allowable moves based on game state, rules for when a game is complete) in a programming language independant way. This is a bit tricky since some of the chess rules (e.g. King Castling, en passen...
8
2008-10-11T16:34:31Z
194,318
<p><strong>Edit:</strong> Overly wordy answer deleted.</p> <p>The short answer is, write the rules in Python. Use Iron Python to interface that to the C# client, and Jython for the Java client.</p>
2
2008-10-11T16:57:04Z
[ "c#", "java", "python", "chess", "dataformat" ]
Recommended data format for describing the rules of chess
194,289
<p>I'm going to be writing a chess server and one or more clients for chess and I want to describe the rules of chess (e.g. allowable moves based on game state, rules for when a game is complete) in a programming language independant way. This is a bit tricky since some of the chess rules (e.g. King Castling, en passen...
8
2008-10-11T16:34:31Z
194,321
<p>This is answering the followup question :-)</p> <p>I can point out that one of the most popular chess servers around documents its protocol <a href="ftp://ftp.chessclub.com/pub/icc/formats/formats.txt" rel="nofollow">here</a> (Warning, FTP link, and does not support passive FTP), but <strong>only to write interface...
2
2008-10-11T17:00:56Z
[ "c#", "java", "python", "chess", "dataformat" ]
Recommended data format for describing the rules of chess
194,289
<p>I'm going to be writing a chess server and one or more clients for chess and I want to describe the rules of chess (e.g. allowable moves based on game state, rules for when a game is complete) in a programming language independant way. This is a bit tricky since some of the chess rules (e.g. King Castling, en passen...
8
2008-10-11T16:34:31Z
194,326
<p>There's already a widely used format specific to chess called <a href="http://en.wikipedia.org/wiki/Portable_Game_Notation" rel="nofollow">Portable Game Notation</a>. There's also <a href="http://www.red-bean.com/sgf/" rel="nofollow">Smart Game Format</a>, which is adaptable to many different games.</p>
2
2008-10-11T17:09:30Z
[ "c#", "java", "python", "chess", "dataformat" ]
Recommended data format for describing the rules of chess
194,289
<p>I'm going to be writing a chess server and one or more clients for chess and I want to describe the rules of chess (e.g. allowable moves based on game state, rules for when a game is complete) in a programming language independant way. This is a bit tricky since some of the chess rules (e.g. King Castling, en passen...
8
2008-10-11T16:34:31Z
194,332
<p>I would suggest Prolog for describing the rules. </p>
2
2008-10-11T17:14:31Z
[ "c#", "java", "python", "chess", "dataformat" ]
Recommended data format for describing the rules of chess
194,289
<p>I'm going to be writing a chess server and one or more clients for chess and I want to describe the rules of chess (e.g. allowable moves based on game state, rules for when a game is complete) in a programming language independant way. This is a bit tricky since some of the chess rules (e.g. King Castling, en passen...
8
2008-10-11T16:34:31Z
194,417
<p>Drools has a modern human readable rules implementation -- https://www.jboss.org/drools/. They have a way users can enter their rules in Excel. A lot more users can understand what is in Excel than in other tools.</p>
0
2008-10-11T18:31:16Z
[ "c#", "java", "python", "chess", "dataformat" ]
Recommended data format for describing the rules of chess
194,289
<p>I'm going to be writing a chess server and one or more clients for chess and I want to describe the rules of chess (e.g. allowable moves based on game state, rules for when a game is complete) in a programming language independant way. This is a bit tricky since some of the chess rules (e.g. King Castling, en passen...
8
2008-10-11T16:34:31Z
199,233
<p>What I've gathered from the responses so far:</p> <p><strong>For chess board data representations:</strong></p> <p>See the Wikipedia article on [chess board representations](http://en.wikipedia.org/wiki/Board_representation_(chess)).</p> <p><strong>For chess move data representations:</strong></p> <p>See the Wik...
2
2008-10-13T22:22:23Z
[ "c#", "java", "python", "chess", "dataformat" ]
Recommended data format for describing the rules of chess
194,289
<p>I'm going to be writing a chess server and one or more clients for chess and I want to describe the rules of chess (e.g. allowable moves based on game state, rules for when a game is complete) in a programming language independant way. This is a bit tricky since some of the chess rules (e.g. King Castling, en passen...
8
2008-10-11T16:34:31Z
217,035
<p>To represent the current state of a board (including castling possibilities etc) you can use <a href="http://en.wikipedia.org/wiki/Forsyth-Edwards_Notation" rel="nofollow">Forsyth-Edwards Notation</a>, which will give you a short ascii representation. e.g.:</p> <pre> rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w K...
0
2008-10-19T21:53:34Z
[ "c#", "java", "python", "chess", "dataformat" ]
Recommended data format for describing the rules of chess
194,289
<p>I'm going to be writing a chess server and one or more clients for chess and I want to describe the rules of chess (e.g. allowable moves based on game state, rules for when a game is complete) in a programming language independant way. This is a bit tricky since some of the chess rules (e.g. King Castling, en passen...
8
2008-10-11T16:34:31Z
297,803
<p>I would agree with the comment left by ΤΖΩΤΖΙΟΥ, viz. just let the server do the validation and let the clients submit a potential move. If that's not the way you want to take the design, then just write the rules in Python as suggested by S. Lott and others.</p> <p>It really shouldn't be that hard. You can...
0
2008-11-18T03:48:18Z
[ "c#", "java", "python", "chess", "dataformat" ]
Python Code Organization Question : Eggs + Packages + Buildout + Unit Tests + SVN
194,339
<p>I have several python projects that share common modules. Until now, I've been ... ahem ... keeping multiple copies of the common code and synchronizing by hand. But I'd clearly prefer to do something else.</p> <p>It looks to me now, as if zc.Buildout maybe what I need. I guess that what I should be doing is puttin...
8
2008-10-11T17:21:05Z
194,472
<p>This is why you have the <a href="http://www.python.org/doc/2.5.2/lib/module-site.html" rel="nofollow">site</a> module. It sets the internal <code>sys.path</code> to include all packages and modules from</p> <ul> <li><code>lib/site-packages</code> -- including directories, eggs and <code>.pth</code> files.</li> <l...
2
2008-10-11T19:22:32Z
[ "python", "svn", "code-organization", "buildout", "egg" ]
Python Code Organization Question : Eggs + Packages + Buildout + Unit Tests + SVN
194,339
<p>I have several python projects that share common modules. Until now, I've been ... ahem ... keeping multiple copies of the common code and synchronizing by hand. But I'd clearly prefer to do something else.</p> <p>It looks to me now, as if zc.Buildout maybe what I need. I guess that what I should be doing is puttin...
8
2008-10-11T17:21:05Z
195,102
<p>I've use the following structure quite effectively. in SVN.</p> <pre><code>Lib1/ branches/ tags/ trunk/ lib1/ tests/ setup.py Lib2 branches/ tags/ trunk/ lib2/ tests/ setup.py App1 branches/ tags/ trunk/ app1/ tests/ setup.py App2 branches/ ...
2
2008-10-12T04:37:08Z
[ "python", "svn", "code-organization", "buildout", "egg" ]
Python Code Organization Question : Eggs + Packages + Buildout + Unit Tests + SVN
194,339
<p>I have several python projects that share common modules. Until now, I've been ... ahem ... keeping multiple copies of the common code and synchronizing by hand. But I'd clearly prefer to do something else.</p> <p>It looks to me now, as if zc.Buildout maybe what I need. I guess that what I should be doing is puttin...
8
2008-10-11T17:21:05Z
421,758
<p>I'd consider each application and library an egg and use one of the examples already given in terms of laying it out in SVN. Really, the VCS end of things should not be an issue. </p> <p>Then, for testing each application/library or combination, I'd set up a virtualenv and install each package either via setup.py d...
1
2009-01-07T19:38:52Z
[ "python", "svn", "code-organization", "buildout", "egg" ]
Python Code Organization Question : Eggs + Packages + Buildout + Unit Tests + SVN
194,339
<p>I have several python projects that share common modules. Until now, I've been ... ahem ... keeping multiple copies of the common code and synchronizing by hand. But I'd clearly prefer to do something else.</p> <p>It looks to me now, as if zc.Buildout maybe what I need. I guess that what I should be doing is puttin...
8
2008-10-11T17:21:05Z
7,620,767
<p>Do not separate the tests from your code, you need to keep the two closely together. It's not as if tests take up that much disk space or any memory! And tests can be extremely instructive to your library users.</p> <p>For library packages, include a <code>buildout.cfg</code> and <code>bootstrap.py</code> file with...
5
2011-10-01T14:15:43Z
[ "python", "svn", "code-organization", "buildout", "egg" ]
Running a web app in Grails vs Django
195,101
<p>I'm currently in the planning stage for a web application and I find myself trying to decide on using Grails or Django. From an operation perspective:</p> <ol> <li><p>Which ecosystem is easier to maintain (migrations, backup, disaster recovery etc.)? If using grails it'll probably be a typical tomcat + mysql on l...
5
2008-10-12T04:36:49Z
195,137
<p>i think python tend to have lower hosting requirements (i.e., grails needs a jvm, and most el-cheapo hosts dont provide one, where as they usually provide python support). Plus google app engine supports django (to some extend). </p> <p>But if you got the dough, grails is so much better imho. </p>
0
2008-10-12T05:46:45Z
[ "python", "django", "grails", "groovy", "web-applications" ]
Running a web app in Grails vs Django
195,101
<p>I'm currently in the planning stage for a web application and I find myself trying to decide on using Grails or Django. From an operation perspective:</p> <ol> <li><p>Which ecosystem is easier to maintain (migrations, backup, disaster recovery etc.)? If using grails it'll probably be a typical tomcat + mysql on l...
5
2008-10-12T04:36:49Z
195,152
<p>You can run grails in 256 megs of ram. Many members of the community are doing so. That being said I would say in either platform you want much more ram than that to make sure your performant. But I might also reccomend checking out www.linode.com. You can get quality hosting for a very reasonable cost and addin...
9
2008-10-12T06:23:56Z
[ "python", "django", "grails", "groovy", "web-applications" ]
Running a web app in Grails vs Django
195,101
<p>I'm currently in the planning stage for a web application and I find myself trying to decide on using Grails or Django. From an operation perspective:</p> <ol> <li><p>Which ecosystem is easier to maintain (migrations, backup, disaster recovery etc.)? If using grails it'll probably be a typical tomcat + mysql on l...
5
2008-10-12T04:36:49Z
197,592
<p>I think from an operations perspective things are going to be close enough that you can base your decision on other criteria. If you can afford a virtual private server with at least 256 MB RAM you will be able to deploy Grails applications. If the cost seems like a lot check out Sun. They are really pushing hosting...
2
2008-10-13T13:34:41Z
[ "python", "django", "grails", "groovy", "web-applications" ]
Running a web app in Grails vs Django
195,101
<p>I'm currently in the planning stage for a web application and I find myself trying to decide on using Grails or Django. From an operation perspective:</p> <ol> <li><p>Which ecosystem is easier to maintain (migrations, backup, disaster recovery etc.)? If using grails it'll probably be a typical tomcat + mysql on l...
5
2008-10-12T04:36:49Z
288,617
<p>With Java hosting you don't need to do all the stupid tricks with apache, or nginx. Jetty itself can host everything you need, that's how the guys at www.mor.ph do it, and they find it to be pretty fast.</p> <p>The memory usage that way is pretty minimal, I host mine on a 256MB Ubuntu server from RapidXen, so it's ...
5
2008-11-13T22:44:52Z
[ "python", "django", "grails", "groovy", "web-applications" ]
Running a web app in Grails vs Django
195,101
<p>I'm currently in the planning stage for a web application and I find myself trying to decide on using Grails or Django. From an operation perspective:</p> <ol> <li><p>Which ecosystem is easier to maintain (migrations, backup, disaster recovery etc.)? If using grails it'll probably be a typical tomcat + mysql on l...
5
2008-10-12T04:36:49Z
4,260,564
<p>You can host Grails apps cheaply on EATJ: <a href="http://smithnicholas.wordpress.com/2010/09/20/deploying-your-grails-application-on-eatj/" rel="nofollow">http://smithnicholas.wordpress.com/2010/09/20/deploying-your-grails-application-on-eatj/</a></p>
1
2010-11-23T20:29:02Z
[ "python", "django", "grails", "groovy", "web-applications" ]
Running compiled python (py2exe) as administrator in Vista
195,109
<p>Is it possible to programaticly run compiled Python (comiled via py2exe) as administrator in Vista?</p> <p>Some more clarification:<br /> I have written a program that modifies the windows hosts file (c:\Windows\system32\drivers\etc\hosts) in Vista the program will not run and will fail with an exception unless you...
7
2008-10-12T04:46:16Z
195,247
<p>Do you mean that you want Windows to prompt for elevation when your program is run? This is controlled by adding a UAC manifest to the EXE's resources. <a href="http://blogs.msdn.com/shawnfa/archive/2006/04/06/568563.aspx">This blog entry</a> explains how to create the manifest and how to compile it into a .RES file...
5
2008-10-12T08:55:22Z
[ "python", "windows-vista", "permissions", "py2exe" ]
Running compiled python (py2exe) as administrator in Vista
195,109
<p>Is it possible to programaticly run compiled Python (comiled via py2exe) as administrator in Vista?</p> <p>Some more clarification:<br /> I have written a program that modifies the windows hosts file (c:\Windows\system32\drivers\etc\hosts) in Vista the program will not run and will fail with an exception unless you...
7
2008-10-12T04:46:16Z
196,208
<p>Following up Roger Lipscombe's comment, I've used a manifest file in py2exe without any real knowledge of what I was doing. So this <em>might</em> work:</p> <pre><code># in setup.py # manifest copied from http://blogs.msdn.com/shawnfa/archive/2006/04/06/568563.aspx manifest = ''' &lt;assembly xmlns="urn:schemas-mi...
3
2008-10-12T22:17:44Z
[ "python", "windows-vista", "permissions", "py2exe" ]
Running compiled python (py2exe) as administrator in Vista
195,109
<p>Is it possible to programaticly run compiled Python (comiled via py2exe) as administrator in Vista?</p> <p>Some more clarification:<br /> I have written a program that modifies the windows hosts file (c:\Windows\system32\drivers\etc\hosts) in Vista the program will not run and will fail with an exception unless you...
7
2008-10-12T04:46:16Z
1,445,547
<p>Following the examples from <code>Python2x\Lib\site-packages\py2exe\samples\user_access_control</code> just add <code>uac_info="requireAdministrator"</code> to console or windows dict:</p> <pre><code>windows = [{ 'script': "admin.py", 'uac_info': "requireAdministrator", },] </code></pre>
34
2009-09-18T16:15:43Z
[ "python", "windows-vista", "permissions", "py2exe" ]
Python Decimal
195,116
<p>Does anyone know of a faster decimal implementation in python. As example below demonstrates, standard python decimal is ~100 times slower than float.</p> <pre><code>from timeit import Timer def run(val, the_class): test = the_class(1) for c in xrange(10000): d = the_class(val) d + test ...
13
2008-10-12T05:03:05Z
195,124
<p>The <a href="http://gmplib.org">GMP</a> library is one of the best arbitrary precision math libraries around, and there is a Python binding available at <a href="http://www.aleax.it/gmpy.html">GMPY</a>. I would try that method.</p>
10
2008-10-12T05:11:37Z
[ "python" ]
Python Decimal
195,116
<p>Does anyone know of a faster decimal implementation in python. As example below demonstrates, standard python decimal is ~100 times slower than float.</p> <pre><code>from timeit import Timer def run(val, the_class): test = the_class(1) for c in xrange(10000): d = the_class(val) d + test ...
13
2008-10-12T05:03:05Z
195,140
<p>You should compare <em>Decimal</em> to <em>Long Integer</em> performance, not floating point. Floating point is mostly hardware these days. <em>Decimal</em> is used for <strong>decimal precision</strong>, while <em>Floating Point</em> is for wider range. Use the <em>decimal</em> package for monetary calculations.</p...
2
2008-10-12T05:55:38Z
[ "python" ]
Python Decimal
195,116
<p>Does anyone know of a faster decimal implementation in python. As example below demonstrates, standard python decimal is ~100 times slower than float.</p> <pre><code>from timeit import Timer def run(val, the_class): test = the_class(1) for c in xrange(10000): d = the_class(val) d + test ...
13
2008-10-12T05:03:05Z
8,192,918
<p>You can try <a href="http://www.bytereef.org/mpdecimal/index.html">cdecimal</a>:</p> <pre><code>from cdecimal import Decimal </code></pre>
20
2011-11-19T08:47:41Z
[ "python" ]
Python Decimal
195,116
<p>Does anyone know of a faster decimal implementation in python. As example below demonstrates, standard python decimal is ~100 times slower than float.</p> <pre><code>from timeit import Timer def run(val, the_class): test = the_class(1) for c in xrange(10000): d = the_class(val) d + test ...
13
2008-10-12T05:03:05Z
13,876,446
<p>python Decimal is very slow, one can use float or a faster implementation of Decimal cDecimal.</p>
0
2012-12-14T10:04:14Z
[ "python" ]
Python Decimal
195,116
<p>Does anyone know of a faster decimal implementation in python. As example below demonstrates, standard python decimal is ~100 times slower than float.</p> <pre><code>from timeit import Timer def run(val, the_class): test = the_class(1) for c in xrange(10000): d = the_class(val) d + test ...
13
2008-10-12T05:03:05Z
24,408,798
<p>Use <a href="http://www.bytereef.org/mpdecimal/index.html" rel="nofollow">cDecimal</a>.</p> <p>Adding the following to your benchmark:</p> <pre><code>a = Timer("run('123.345', Decimal)", "import sys; import cdecimal; sys.modules['decimal'] = cdecimal; from decimal_benchmark import run; from decimal import Decimal"...
0
2014-06-25T12:33:07Z
[ "python" ]
In production, Apache + mod_wsgi or Nginx + mod_wsgi?
195,534
<p>What to use for a medium to large python WSGI application, Apache + mod_wsgi or Nginx + mod_wsgi?<br /><br /> Which combination will need more memory and CPU time?<br /> Which one is faster?<br/> Which is known for being more stable than the other?<br /><br /> I am also thinking to use CherryPy's WSGI server but I h...
56
2008-10-12T14:14:19Z
196,039
<p>One thing that CherryPy's webserver has going for it is that it's a pure python webserver (AFAIK), which may or may not make deployment easier for you. Plus, I could see the benefits of using it if you're just using a server for WSGI and static content.</p> <p>(shameless plug warning: I wrote the WSGI code that I...
7
2008-10-12T20:45:41Z
[ "python", "apache", "nginx", "mod-wsgi" ]
In production, Apache + mod_wsgi or Nginx + mod_wsgi?
195,534
<p>What to use for a medium to large python WSGI application, Apache + mod_wsgi or Nginx + mod_wsgi?<br /><br /> Which combination will need more memory and CPU time?<br /> Which one is faster?<br/> Which is known for being more stable than the other?<br /><br /> I am also thinking to use CherryPy's WSGI server but I h...
56
2008-10-12T14:14:19Z
196,580
<p>The main difference is that nginx is built to handle large numbers of connections in a much smaller memory space. This makes it very well suited for apps that are doing comet like connections that can have many idle open connections. This also gives it quite a smaller memory foot print.</p> <p>From a raw performa...
13
2008-10-13T02:44:24Z
[ "python", "apache", "nginx", "mod-wsgi" ]
In production, Apache + mod_wsgi or Nginx + mod_wsgi?
195,534
<p>What to use for a medium to large python WSGI application, Apache + mod_wsgi or Nginx + mod_wsgi?<br /><br /> Which combination will need more memory and CPU time?<br /> Which one is faster?<br/> Which is known for being more stable than the other?<br /><br /> I am also thinking to use CherryPy's WSGI server but I h...
56
2008-10-12T14:14:19Z
409,017
<p>The author of nginx mod_wsgi explains some differences to Apache mod_wsgi <a href="http://osdir.com/ml/web.nginx.english/2008-05/msg00451.html">in this mailing list message</a>.</p>
16
2009-01-03T13:04:18Z
[ "python", "apache", "nginx", "mod-wsgi" ]
In production, Apache + mod_wsgi or Nginx + mod_wsgi?
195,534
<p>What to use for a medium to large python WSGI application, Apache + mod_wsgi or Nginx + mod_wsgi?<br /><br /> Which combination will need more memory and CPU time?<br /> Which one is faster?<br/> Which is known for being more stable than the other?<br /><br /> I am also thinking to use CherryPy's WSGI server but I h...
56
2008-10-12T14:14:19Z
1,038,043
<p>For nginx/mod_wsgi, ensure you read:</p> <p><a href="http://blog.dscpl.com.au/2009/05/blocking-requests-and-nginx-version-of.html">http://blog.dscpl.com.au/2009/05/blocking-requests-and-nginx-version-of.html</a></p> <p>Because of how nginx is an event driven system underneath, it has behavioural characteristics wh...
67
2009-06-24T12:26:01Z
[ "python", "apache", "nginx", "mod-wsgi" ]
What is the time complexity of popping elements from list in Python?
195,625
<p>I wonder what is the time complexity of pop method of list objects in Python (in CPython particulary). Also does the value of N for list.pop(N) affects the complexity? </p>
16
2008-10-12T15:58:59Z
195,647
<p>Pop() for the last element ought to be O(1) since you only need to return the element referred to by the last element in the array and update the index of the last element. I would expect pop(N) to be O(N) and require on average N/2 operations since you would need to move any elements beyond the Nth one, one positi...
13
2008-10-12T16:15:39Z
[ "python" ]
What is the time complexity of popping elements from list in Python?
195,625
<p>I wonder what is the time complexity of pop method of list objects in Python (in CPython particulary). Also does the value of N for list.pop(N) affects the complexity? </p>
16
2008-10-12T15:58:59Z
195,839
<p>Yes, it is O(1) to pop the last element of a Python list, and O(N) to pop an arbitrary element (since the whole rest of the list has to be shifted).</p> <p>Here's a great article on how Python lists are stored and manipulated: <a href="http://effbot.org/zone/python-list.htm">http://effbot.org/zone/python-list.htm</...
23
2008-10-12T18:47:42Z
[ "python" ]
How to avoid computation every time a python module is reloaded
195,626
<p>I have a python module that makes use of a huge dictionary global variable, currently I put the computation code in the top section, every first time import or reload of the module takes more then one minute which is totally unacceptable. How can I save the computation result somewhere so that the next import/reload...
6
2008-10-12T15:59:48Z
195,645
<p>I assume you've pasted the dict literal into the source, and that's what's taking a minute? I don't know how to get around that, but you could probably avoid instantiating this dict upon <em>import</em>... You could lazily-instantiate it the first time it's actually used.</p>
2
2008-10-12T16:14:43Z
[ "python", "nltk" ]
How to avoid computation every time a python module is reloaded
195,626
<p>I have a python module that makes use of a huge dictionary global variable, currently I put the computation code in the top section, every first time import or reload of the module takes more then one minute which is totally unacceptable. How can I save the computation result somewhere so that the next import/reload...
6
2008-10-12T15:59:48Z
195,702
<p>You can use a <a href="http://www.python.org/doc/2.5.2/lib/module-shelve.html" rel="nofollow">shelve</a> to store your data on disc instead of loading the whole data into memory. So startup time will be very fast, but the trade-off will be slower access time. </p> <p>Shelve will pickle the dict values too, but will...
1
2008-10-12T17:04:20Z
[ "python", "nltk" ]
How to avoid computation every time a python module is reloaded
195,626
<p>I have a python module that makes use of a huge dictionary global variable, currently I put the computation code in the top section, every first time import or reload of the module takes more then one minute which is totally unacceptable. How can I save the computation result somewhere so that the next import/reload...
6
2008-10-12T15:59:48Z
195,739
<p>Calculate your global var on the first use.</p> <pre><code>class Proxy: @property def global_name(self): # calculate your global var here, enable cache if needed ... _proxy_object = Proxy() GLOBAL_NAME = _proxy_object.global_name </code></pre> <p>Or better yet, access necessery data via sp...
3
2008-10-12T17:29:46Z
[ "python", "nltk" ]
How to avoid computation every time a python module is reloaded
195,626
<p>I have a python module that makes use of a huge dictionary global variable, currently I put the computation code in the top section, every first time import or reload of the module takes more then one minute which is totally unacceptable. How can I save the computation result somewhere so that the next import/reload...
6
2008-10-12T15:59:48Z
195,758
<p>You could try using the <a href="http://en.wikipedia.org/wiki/All_You_Zombies%E2%80%94" rel="nofollow">marshal</a> module instead of the c?Pickle one; it could be faster. This module is used by python to store values in a binary format. Note especially the following paragraph, to see if marshal fits your needs:</p> ...
2
2008-10-12T17:38:20Z
[ "python", "nltk" ]
How to avoid computation every time a python module is reloaded
195,626
<p>I have a python module that makes use of a huge dictionary global variable, currently I put the computation code in the top section, every first time import or reload of the module takes more then one minute which is totally unacceptable. How can I save the computation result somewhere so that the next import/reload...
6
2008-10-12T15:59:48Z
195,776
<p>Expanding on the delayed-calculation idea, why not turn the dict into a class that supplies (and caches) elements as necessary?</p> <p>You might also use psyco to speed up overall execution...</p>
0
2008-10-12T17:54:36Z
[ "python", "nltk" ]
How to avoid computation every time a python module is reloaded
195,626
<p>I have a python module that makes use of a huge dictionary global variable, currently I put the computation code in the top section, every first time import or reload of the module takes more then one minute which is totally unacceptable. How can I save the computation result somewhere so that the next import/reload...
6
2008-10-12T15:59:48Z
195,792
<p><em>OR</em> you could just use a database for storing the values in? Check out SQLObject, which makes it very easy to store stuff to a database.</p>
0
2008-10-12T18:08:54Z
[ "python", "nltk" ]
How to avoid computation every time a python module is reloaded
195,626
<p>I have a python module that makes use of a huge dictionary global variable, currently I put the computation code in the top section, every first time import or reload of the module takes more then one minute which is totally unacceptable. How can I save the computation result somewhere so that the next import/reload...
6
2008-10-12T15:59:48Z
195,962
<p>Just to clarify: the code in the body of a module is <em>not</em> executed every time the module is imported - it is run only once, after which future imports find the already created module, rather than recreating it. Take a look at sys.modules to see the list of cached modules.</p> <p>However, if your problem is...
17
2008-10-12T20:12:25Z
[ "python", "nltk" ]
How to avoid computation every time a python module is reloaded
195,626
<p>I have a python module that makes use of a huge dictionary global variable, currently I put the computation code in the top section, every first time import or reload of the module takes more then one minute which is totally unacceptable. How can I save the computation result somewhere so that the next import/reload...
6
2008-10-12T15:59:48Z
196,218
<p>A couple of things that will help speed up imports:</p> <ol> <li>You might try running python using the -OO flag when running python. This will do some optimizations that will reduce import time of modules.</li> <li>Is there any reason why you couldn't break the dictionary up into smaller dictionaries in separate ...
1
2008-10-12T22:31:37Z
[ "python", "nltk" ]
How to avoid computation every time a python module is reloaded
195,626
<p>I have a python module that makes use of a huge dictionary global variable, currently I put the computation code in the top section, every first time import or reload of the module takes more then one minute which is totally unacceptable. How can I save the computation result somewhere so that the next import/reload...
6
2008-10-12T15:59:48Z
201,077
<ol> <li><p>Factor the computationally intensive part into a separate module. Then at least on reload, you won't have to wait. </p></li> <li><p>Try dumping the data structure using protocol 2. The command to try would be <code>cPickle.dump(FD, protocol=2)</code>. From the docstring for <code>cPickle.Pickler</code>:<...
1
2008-10-14T13:07:08Z
[ "python", "nltk" ]
How to avoid computation every time a python module is reloaded
195,626
<p>I have a python module that makes use of a huge dictionary global variable, currently I put the computation code in the top section, every first time import or reload of the module takes more then one minute which is totally unacceptable. How can I save the computation result somewhere so that the next import/reload...
6
2008-10-12T15:59:48Z
345,744
<p>If the 'shelve' solution turns out to be too slow or fiddly, there are other possibilities:</p> <ul> <li><a href="http://pypi.python.org/pypi/shove" rel="nofollow">shove</a></li> <li><a href="http://www.mems-exchange.org/software/durus/" rel="nofollow">Durus</a></li> <li><a href="http://www.zope.org" rel="nofollow"...
2
2008-12-06T01:56:12Z
[ "python", "nltk" ]
How to avoid computation every time a python module is reloaded
195,626
<p>I have a python module that makes use of a huge dictionary global variable, currently I put the computation code in the top section, every first time import or reload of the module takes more then one minute which is totally unacceptable. How can I save the computation result somewhere so that the next import/reload...
6
2008-10-12T15:59:48Z
431,452
<p>There's another pretty obvious solution for this problem. When code is reloaded the original scope is still available.</p> <p>So... doing something like this will make sure this code is executed only once.</p> <pre><code>try: FD except NameError: FD = FreqDist(word for word in brown.words()) </code></pre>
0
2009-01-10T18:06:13Z
[ "python", "nltk" ]
How to avoid computation every time a python module is reloaded
195,626
<p>I have a python module that makes use of a huge dictionary global variable, currently I put the computation code in the top section, every first time import or reload of the module takes more then one minute which is totally unacceptable. How can I save the computation result somewhere so that the next import/reload...
6
2008-10-12T15:59:48Z
1,184,838
<p><code>shelve</code> gets really slow with large data sets. I've been using <a href="http://streamhacker.com/2009/05/20/building-a-nltk-freqdist-on-redis/" rel="nofollow">redis</a> quite successfully, and wrote a <a href="http://bitbucket.org/japerk/nltk-extras/src/tip/probability.py" rel="nofollow">FreqDist wrapper<...
2
2009-07-26T15:28:23Z
[ "python", "nltk" ]
How to avoid computation every time a python module is reloaded
195,626
<p>I have a python module that makes use of a huge dictionary global variable, currently I put the computation code in the top section, every first time import or reload of the module takes more then one minute which is totally unacceptable. How can I save the computation result somewhere so that the next import/reload...
6
2008-10-12T15:59:48Z
2,213,775
<p>I'm going through this same issue... shelve, databases, etc... are all too slow for this type of problem. You'll need to take the hit once, insert it into an inmemory key/val store like Redis. It will just live there in memory (warning it could use up a good amount of memory so you may want a dedicated box). You'll...
1
2010-02-06T16:28:31Z
[ "python", "nltk" ]
What's the easiest way/best tutorials to get familiar with SQLAlchemy?
195,771
<p>What are best resources/tutorials for starting up with SQLAlchemy? Maybe some simple step by step stuff like creating a simple table and using it and going up from there.</p>
3
2008-10-12T17:49:09Z
195,784
<p>Personally, I'd buy <a href="http://oreilly.com/catalog/9780596516147/">this book</a> and cram it into the noggin over the course of a week or so.</p> <p>I've tried tackling SQLAlchemy on the job without learning the details first. I had a hard time with it, because I found the online documentation to be sparse and...
5
2008-10-12T18:00:02Z
[ "python", "sqlalchemy" ]
What's the easiest way/best tutorials to get familiar with SQLAlchemy?
195,771
<p>What are best resources/tutorials for starting up with SQLAlchemy? Maybe some simple step by step stuff like creating a simple table and using it and going up from there.</p>
3
2008-10-12T17:49:09Z
196,072
<p>Probably the <a href="http://www.sqlalchemy.org/docs/04/ormtutorial.html" rel="nofollow" title="SQLAlchemy ORM Tutorial">SQLAlchemy ORM Tutorial</a>? I started with it.</p>
3
2008-10-12T21:00:05Z
[ "python", "sqlalchemy" ]
What's the easiest way/best tutorials to get familiar with SQLAlchemy?
195,771
<p>What are best resources/tutorials for starting up with SQLAlchemy? Maybe some simple step by step stuff like creating a simple table and using it and going up from there.</p>
3
2008-10-12T17:49:09Z
720,386
<p><a href="http://www.ibm.com/developerworks/aix/library/au-sqlalchemy/" rel="nofollow">Using SQLAlchemy</a> (IBM developerWorks)</p>
1
2009-04-06T06:32:56Z
[ "python", "sqlalchemy" ]
MySQLdb execute timeout
196,217
<p>Sometimes in our production environment occurs situation when connection between service (which is python program that uses MySQLdb) and mysql server is flacky, some packages are lost, some black magic happens and .execute() of MySQLdb.Cursor object never ends (or take great amount of time to end). </p> <p>This is ...
2
2008-10-12T22:27:58Z
196,308
<p>if the communication is such a problem, consider writing a 'proxy' that receives your SQL commands over the flaky connection and relays them to the MySQL server on a reliable channel (maybe running on the same box as the MySQL server). This way you have total control over failure detection and retrying.</p>
2
2008-10-12T23:45:47Z
[ "python", "mysql", "timeout" ]
MySQLdb execute timeout
196,217
<p>Sometimes in our production environment occurs situation when connection between service (which is python program that uses MySQLdb) and mysql server is flacky, some packages are lost, some black magic happens and .execute() of MySQLdb.Cursor object never ends (or take great amount of time to end). </p> <p>This is ...
2
2008-10-12T22:27:58Z
196,891
<p>You need to analyse exactly what the problem is. MySQL connections should eventually timeout if the server is gone; TCP keepalives are generally enabled. You may be able to tune the OS-level TCP timeouts.</p> <p>If the database is "flaky", then you definitely need to investigate how. It seems unlikely that the data...
1
2008-10-13T06:57:13Z
[ "python", "mysql", "timeout" ]
How to check if a string in Python is in ASCII?
196,345
<p>I want to I check whether a string is in ASCII or not.</p> <p>I am aware of <code>ord()</code>, however when I try <code>ord('é')</code>, I have <code>TypeError: ord() expected a character, but string of length 2 found</code>. I understood it is caused by the way I built Python (as explained in <a href="http://doc...
120
2008-10-13T00:13:40Z
196,360
<p>You could use the regular expression library which accepts the Posix standard [[:ASCII:]] definition.</p>
2
2008-10-13T00:18:25Z
[ "python", "string", "unicode", "ascii" ]
How to check if a string in Python is in ASCII?
196,345
<p>I want to I check whether a string is in ASCII or not.</p> <p>I am aware of <code>ord()</code>, however when I try <code>ord('é')</code>, I have <code>TypeError: ord() expected a character, but string of length 2 found</code>. I understood it is caused by the way I built Python (as explained in <a href="http://doc...
120
2008-10-13T00:13:40Z
196,391
<p>I think you are not asking the right question--</p> <p>A string in python has no property corresponding to 'ascii', utf-8, or any other encoding. The source of your string (whether you read it from a file, input from a keyboard, etc.) may have encoded a unicode string in ascii to produce your string, but that's wh...
189
2008-10-13T00:30:32Z
[ "python", "string", "unicode", "ascii" ]
How to check if a string in Python is in ASCII?
196,345
<p>I want to I check whether a string is in ASCII or not.</p> <p>I am aware of <code>ord()</code>, however when I try <code>ord('é')</code>, I have <code>TypeError: ord() expected a character, but string of length 2 found</code>. I understood it is caused by the way I built Python (as explained in <a href="http://doc...
120
2008-10-13T00:13:40Z
196,392
<pre><code>def is_ascii(s): return all(ord(c) &lt; 128 for c in s) </code></pre>
78
2008-10-13T00:30:43Z
[ "python", "string", "unicode", "ascii" ]
How to check if a string in Python is in ASCII?
196,345
<p>I want to I check whether a string is in ASCII or not.</p> <p>I am aware of <code>ord()</code>, however when I try <code>ord('é')</code>, I have <code>TypeError: ord() expected a character, but string of length 2 found</code>. I understood it is caused by the way I built Python (as explained in <a href="http://doc...
120
2008-10-13T00:13:40Z
198,205
<p>How about doing this?</p> <pre><code>import string def isAscii(s): for c in s: if c not in string.ascii_letters: return False return True </code></pre>
10
2008-10-13T16:38:25Z
[ "python", "string", "unicode", "ascii" ]
How to check if a string in Python is in ASCII?
196,345
<p>I want to I check whether a string is in ASCII or not.</p> <p>I am aware of <code>ord()</code>, however when I try <code>ord('é')</code>, I have <code>TypeError: ord() expected a character, but string of length 2 found</code>. I understood it is caused by the way I built Python (as explained in <a href="http://doc...
120
2008-10-13T00:13:40Z
200,267
<p>Your question is incorrect; the error you see is not a result of how you built python, but of a confusion between byte strings and unicode strings.</p> <p>Byte strings (e.g. "foo", or 'bar', in python syntax) are sequences of octets; numbers from 0-255. Unicode strings (e.g. u"foo" or u'bar') are sequences of unic...
16
2008-10-14T07:36:59Z
[ "python", "string", "unicode", "ascii" ]
How to check if a string in Python is in ASCII?
196,345
<p>I want to I check whether a string is in ASCII or not.</p> <p>I am aware of <code>ord()</code>, however when I try <code>ord('é')</code>, I have <code>TypeError: ord() expected a character, but string of length 2 found</code>. I understood it is caused by the way I built Python (as explained in <a href="http://doc...
120
2008-10-13T00:13:40Z
200,311
<p>A sting (<code>str</code>-type) in Python is a series of bytes. There is <strong>no way</strong> of telling just from looking at the string whether this series of bytes represent an ascii string, a string in a 8-bit charset like ISO-8859-1 or a string encoded with UTF-8 or UTF-16 or whatever.</p> <p>However if you ...
2
2008-10-14T07:58:08Z
[ "python", "string", "unicode", "ascii" ]
How to check if a string in Python is in ASCII?
196,345
<p>I want to I check whether a string is in ASCII or not.</p> <p>I am aware of <code>ord()</code>, however when I try <code>ord('é')</code>, I have <code>TypeError: ord() expected a character, but string of length 2 found</code>. I understood it is caused by the way I built Python (as explained in <a href="http://doc...
120
2008-10-13T00:13:40Z
3,296,808
<p>I use the following to determine if the string is ascii or unicode:</p> <pre><code>&gt;&gt; print 'test string'.__class__.__name__ str &gt;&gt;&gt; print u'test string'.__class__.__name__ unicode &gt;&gt;&gt; </code></pre> <p>Then just use a conditional block to define the function:</p> <pre><code>def is_ascii(i...
-2
2010-07-21T06:34:56Z
[ "python", "string", "unicode", "ascii" ]
How to check if a string in Python is in ASCII?
196,345
<p>I want to I check whether a string is in ASCII or not.</p> <p>I am aware of <code>ord()</code>, however when I try <code>ord('é')</code>, I have <code>TypeError: ord() expected a character, but string of length 2 found</code>. I understood it is caused by the way I built Python (as explained in <a href="http://doc...
120
2008-10-13T00:13:40Z
6,988,354
<p>Ran into something like this recently - for future reference</p> <pre><code>import chardet encoding = chardet.detect(string) if encoding['encoding'] == 'ascii': print 'string is in ascii' </code></pre> <p>which you could use with:</p> <pre><code>string_ascii = string.decode(encoding['encoding']).encode('asci...
16
2011-08-08T20:47:22Z
[ "python", "string", "unicode", "ascii" ]
How to check if a string in Python is in ASCII?
196,345
<p>I want to I check whether a string is in ASCII or not.</p> <p>I am aware of <code>ord()</code>, however when I try <code>ord('é')</code>, I have <code>TypeError: ord() expected a character, but string of length 2 found</code>. I understood it is caused by the way I built Python (as explained in <a href="http://doc...
120
2008-10-13T00:13:40Z
12,064,457
<p>I found this question while trying determine how to use/encode/decode a string whose encoding I wasn't sure of (and how to escape/convert special characters in that string).</p> <p>My first step should have been to check the type of the string- I didn't realize there I could get good data about its formatting from ...
7
2012-08-21T23:24:35Z
[ "python", "string", "unicode", "ascii" ]
How to check if a string in Python is in ASCII?
196,345
<p>I want to I check whether a string is in ASCII or not.</p> <p>I am aware of <code>ord()</code>, however when I try <code>ord('é')</code>, I have <code>TypeError: ord() expected a character, but string of length 2 found</code>. I understood it is caused by the way I built Python (as explained in <a href="http://doc...
120
2008-10-13T00:13:40Z
17,516,466
<p>To prevent your code from crashes, you maybe want to use a <code>try-except</code> to catch <code>TypeErrors</code></p> <pre><code>&gt;&gt;&gt; ord("¶") Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; TypeError: ord() expected a character, but string of length 2 found </code></...
0
2013-07-07T21:16:00Z
[ "python", "string", "unicode", "ascii" ]
How to check if a string in Python is in ASCII?
196,345
<p>I want to I check whether a string is in ASCII or not.</p> <p>I am aware of <code>ord()</code>, however when I try <code>ord('é')</code>, I have <code>TypeError: ord() expected a character, but string of length 2 found</code>. I understood it is caused by the way I built Python (as explained in <a href="http://doc...
120
2008-10-13T00:13:40Z
18,403,812
<p>Python 3 way:</p> <pre><code>isascii = lambda s: len(s) == len(s.encode()) </code></pre>
31
2013-08-23T13:14:49Z
[ "python", "string", "unicode", "ascii" ]
How to check if a string in Python is in ASCII?
196,345
<p>I want to I check whether a string is in ASCII or not.</p> <p>I am aware of <code>ord()</code>, however when I try <code>ord('é')</code>, I have <code>TypeError: ord() expected a character, but string of length 2 found</code>. I understood it is caused by the way I built Python (as explained in <a href="http://doc...
120
2008-10-13T00:13:40Z
30,392,263
<p>To improve Alexander's solution from the Python 2.6 (and in Python 3.x) you can use helper module curses.ascii and use curses.ascii.isascii() function or various other: <a href="https://docs.python.org/2.6/library/curses.ascii.html" rel="nofollow">https://docs.python.org/2.6/library/curses.ascii.html</a></p> <pre><...
2
2015-05-22T08:48:46Z
[ "python", "string", "unicode", "ascii" ]
How to check if a string in Python is in ASCII?
196,345
<p>I want to I check whether a string is in ASCII or not.</p> <p>I am aware of <code>ord()</code>, however when I try <code>ord('é')</code>, I have <code>TypeError: ord() expected a character, but string of length 2 found</code>. I understood it is caused by the way I built Python (as explained in <a href="http://doc...
120
2008-10-13T00:13:40Z
32,357,552
<p>Vincent Marchetti has the right idea, but <code>str.decode</code> has been deprecated in Python 3. In Python 3 you can make the same test with <code>str.encode</code>:</p> <pre><code>try: mystring.encode('ascii') except UnicodeEncodeError: pass # string is not ascii else: pass # string is ascii </cod...
3
2015-09-02T15:45:04Z
[ "python", "string", "unicode", "ascii" ]
How to check if a string in Python is in ASCII?
196,345
<p>I want to I check whether a string is in ASCII or not.</p> <p>I am aware of <code>ord()</code>, however when I try <code>ord('é')</code>, I have <code>TypeError: ord() expected a character, but string of length 2 found</code>. I understood it is caused by the way I built Python (as explained in <a href="http://doc...
120
2008-10-13T00:13:40Z
32,869,248
<pre><code>import re def is_ascii(s): return bool(re.match(r'[\x00-\x7F]+$', s)) </code></pre> <p>To include an empty string as ASCII, change the <code>+</code> to <code>*</code>.</p>
0
2015-09-30T14:51:52Z
[ "python", "string", "unicode", "ascii" ]
How can I search through Stack Overflow questions from a script?
196,755
<p>Given a string of keywords, such as "Python best practices", I would like to obtain the first 10 Stack Overflow questions that contain that keywords, sorted by relevance (?), say from a Python script. My goal is to end up with a list of tuples (title, URL).</p> <p>How can I accomplish this? Would you consider query...
3
2008-10-13T05:03:47Z
196,758
<p>You could screen scrape the returned HTML from a valid HTTP request. But that would result in bad karma, and the loss of the ability to enjoy a good night's sleep.</p>
1
2008-10-13T05:09:04Z
[ "python", "search", "scripting", "stackexchange-api" ]
How can I search through Stack Overflow questions from a script?
196,755
<p>Given a string of keywords, such as "Python best practices", I would like to obtain the first 10 Stack Overflow questions that contain that keywords, sorted by relevance (?), say from a Python script. My goal is to end up with a list of tuples (title, URL).</p> <p>How can I accomplish this? Would you consider query...
3
2008-10-13T05:03:47Z
196,763
<p>Since Stackoverflow already has this feature you just need to get the contents of the search results page and scrape the information you need. Here is the URL for a search by relevance:</p> <blockquote> <p><a href="http://stackoverflow.com/search?q=python+best+practices&amp;sort=relevance">http://stackoverflow.co...
5
2008-10-13T05:11:39Z
[ "python", "search", "scripting", "stackexchange-api" ]
How can I search through Stack Overflow questions from a script?
196,755
<p>Given a string of keywords, such as "Python best practices", I would like to obtain the first 10 Stack Overflow questions that contain that keywords, sorted by relevance (?), say from a Python script. My goal is to end up with a list of tuples (title, URL).</p> <p>How can I accomplish this? Would you consider query...
3
2008-10-13T05:03:47Z
196,780
<p>Suggest that a REST API be added to SO. <a href="http://stackoverflow.uservoice.com" rel="nofollow">http://stackoverflow.uservoice.com/</a></p>
1
2008-10-13T05:28:47Z
[ "python", "search", "scripting", "stackexchange-api" ]
How can I search through Stack Overflow questions from a script?
196,755
<p>Given a string of keywords, such as "Python best practices", I would like to obtain the first 10 Stack Overflow questions that contain that keywords, sorted by relevance (?), say from a Python script. My goal is to end up with a list of tuples (title, URL).</p> <p>How can I accomplish this? Would you consider query...
3
2008-10-13T05:03:47Z
196,800
<p>I would just use Pycurl to concatenate the search terms onto the query uri.</p>
0
2008-10-13T05:46:01Z
[ "python", "search", "scripting", "stackexchange-api" ]
How can I search through Stack Overflow questions from a script?
196,755
<p>Given a string of keywords, such as "Python best practices", I would like to obtain the first 10 Stack Overflow questions that contain that keywords, sorted by relevance (?), say from a Python script. My goal is to end up with a list of tuples (title, URL).</p> <p>How can I accomplish this? Would you consider query...
3
2008-10-13T05:03:47Z
196,851
<pre><code>&gt;&gt;&gt; from urllib import urlencode &gt;&gt;&gt; params = urlencode({'q': 'python best practices', 'sort': 'relevance'}) &gt;&gt;&gt; params 'q=python+best+practices&amp;sort=relevance' &gt;&gt;&gt; from urllib2 import urlopen &gt;&gt;&gt; html = urlopen("http://stackoverflow.com/search?%s" % params).r...
5
2008-10-13T06:33:02Z
[ "python", "search", "scripting", "stackexchange-api" ]
What is the best way to escape Python strings in PHP?
196,771
<p>I have a PHP application which needs to output a python script, more specifically a bunch of variable assignment statements, eg.</p> <pre><code>subject_prefix = 'This String From User Input' msg_footer = """This one too.""" </code></pre> <p>The contents of subject_prefix et al need to be written to take user input...
2
2008-10-13T05:20:56Z
196,783
<p>I suggest writing a function that will take two arguments: the text to be escaped and the type of quotes the string is in. Then, for example, if the type of quotes are single quotes, the function will escape the single quotes in the string and any other characters that need to be escaped (backslash?).</p> <pre><cod...
-2
2008-10-13T05:30:00Z
[ "php", "python", "user-input" ]
What is the best way to escape Python strings in PHP?
196,771
<p>I have a PHP application which needs to output a python script, more specifically a bunch of variable assignment statements, eg.</p> <pre><code>subject_prefix = 'This String From User Input' msg_footer = """This one too.""" </code></pre> <p>The contents of subject_prefix et al need to be written to take user input...
2
2008-10-13T05:20:56Z
196,790
<p>I'd start by standardizing the string type I was using in python, to use triple-quoted strings ("""). This should reduce the incidents of problems from stray quotes in the input. You'll still need to escape it of course, but it should reduce the number of issues that are a concern.</p> <p>What I did to escape the...
0
2008-10-13T05:34:47Z
[ "php", "python", "user-input" ]
What is the best way to escape Python strings in PHP?
196,771
<p>I have a PHP application which needs to output a python script, more specifically a bunch of variable assignment statements, eg.</p> <pre><code>subject_prefix = 'This String From User Input' msg_footer = """This one too.""" </code></pre> <p>The contents of subject_prefix et al need to be written to take user input...
2
2008-10-13T05:20:56Z
196,964
<p>Another option may be to export the data as array or object as JSON string and modify the python code slightly to handle the new input. While the escaping via JSON is not 100% bulletproof it will be still better than own escaping routines.</p> <p>And you'll be able to handle errors if the JSON string is malformatte...
0
2008-10-13T07:57:21Z
[ "php", "python", "user-input" ]
What is the best way to escape Python strings in PHP?
196,771
<p>I have a PHP application which needs to output a python script, more specifically a bunch of variable assignment statements, eg.</p> <pre><code>subject_prefix = 'This String From User Input' msg_footer = """This one too.""" </code></pre> <p>The contents of subject_prefix et al need to be written to take user input...
2
2008-10-13T05:20:56Z
200,315
<p><strong>Do not</strong> try write this function in PHP. You will inevitably get it wrong and your application will inevitably have an arbitrary remote execution exploit.</p> <p>First, consider what problem you are actually solving. I presume you are just trying to get data from PHP to Python. You might try to wr...
2
2008-10-14T07:58:38Z
[ "php", "python", "user-input" ]