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 |
|---|---|---|---|---|---|---|---|---|---|
After breaking a python program into functions, how do I make one the main function? | 2,125,825 | <p>This is the biggest newbie question on the planet, but I'm just not sure. I've written a bunch of functions that perform some task, and I want a "main" function that will, for example, when I call "someProgram.py", run function1, function2 and quit. I vaguely remember something about "<strong>main</strong>" but I ... | 10 | 2010-01-24T03:42:27Z | 2,125,833 | <p>It's the following idiom:</p>
<pre><code>if __name__ == "__main__":
yourfoo()
</code></pre>
<p><a href="http://www.artima.com/weblogs/viewpost.jsp?thread=4829" rel="nofollow">Also read this</a>.</p>
| 1 | 2010-01-24T03:44:21Z | [
"python"
] |
After breaking a python program into functions, how do I make one the main function? | 2,125,825 | <p>This is the biggest newbie question on the planet, but I'm just not sure. I've written a bunch of functions that perform some task, and I want a "main" function that will, for example, when I call "someProgram.py", run function1, function2 and quit. I vaguely remember something about "<strong>main</strong>" but I ... | 10 | 2010-01-24T03:42:27Z | 2,125,834 | <pre><code>if __name__ == '__main__':
run_main()
</code></pre>
| 2 | 2010-01-24T03:44:26Z | [
"python"
] |
After breaking a python program into functions, how do I make one the main function? | 2,125,825 | <p>This is the biggest newbie question on the planet, but I'm just not sure. I've written a bunch of functions that perform some task, and I want a "main" function that will, for example, when I call "someProgram.py", run function1, function2 and quit. I vaguely remember something about "<strong>main</strong>" but I ... | 10 | 2010-01-24T03:42:27Z | 2,125,857 | <p>When a python module is being imported for the first time, it's main block is run. You can distinguish between being run by itself and being imported into another program:</p>
<pre><code>if __name__ == "__main__":
function1()
function2()
else:
# loaded from another module
</code></pre>
| 3 | 2010-01-24T03:50:50Z | [
"python"
] |
After breaking a python program into functions, how do I make one the main function? | 2,125,825 | <p>This is the biggest newbie question on the planet, but I'm just not sure. I've written a bunch of functions that perform some task, and I want a "main" function that will, for example, when I call "someProgram.py", run function1, function2 and quit. I vaguely remember something about "<strong>main</strong>" but I ... | 10 | 2010-01-24T03:42:27Z | 2,125,860 | <p>Python scripts are not collections of functions, but rather collections of statements - function and class definitions are just statements that bind names to function or class objects.</p>
<p>If you put a print statement at the top or middle of your program, it will run normally without being in any function. What ... | 12 | 2010-01-24T03:52:13Z | [
"python"
] |
After breaking a python program into functions, how do I make one the main function? | 2,125,825 | <p>This is the biggest newbie question on the planet, but I'm just not sure. I've written a bunch of functions that perform some task, and I want a "main" function that will, for example, when I call "someProgram.py", run function1, function2 and quit. I vaguely remember something about "<strong>main</strong>" but I ... | 10 | 2010-01-24T03:42:27Z | 2,126,059 | <p>As I read your question, you're asking about how to define a main function. That actually would be done with something like:</p>
<pre><code>def main():
function1()
function2()
return 0
</code></pre>
<p>And then you would put code something like this outside all your main file's functions:</p>
<pre><c... | 1 | 2010-01-24T05:18:00Z | [
"python"
] |
How limiting are web frameworks | 2,125,865 | <p>This is a general question about how limiting are web development frameworks such as Django and ruby-on-rails.</p>
<p>I am planning on building a RESTful web service which will have a purely JSON/XML interface, no GUI. The service will rely on a database however for a few of the more important operations there is n... | 7 | 2010-01-24T03:53:02Z | 2,125,958 | <p>You'll be much more limited by the abilities of yourself versus a diverse community of developers working on a large project to share all those common parts.</p>
| 0 | 2010-01-24T04:29:35Z | [
"python",
"ruby-on-rails",
"django",
"rest"
] |
How limiting are web frameworks | 2,125,865 | <p>This is a general question about how limiting are web development frameworks such as Django and ruby-on-rails.</p>
<p>I am planning on building a RESTful web service which will have a purely JSON/XML interface, no GUI. The service will rely on a database however for a few of the more important operations there is n... | 7 | 2010-01-24T03:53:02Z | 2,125,973 | <p>Rails is as helpful or not as you need it to be, overall. If you need to load a collection with straight SQL, it's straightforward. If in the same line you want to use all the built-in ActiveRecord Fu, you can. RESTful routing is extremely simple, but again if the particular Rails flavor of REST doesn't meet your ne... | 1 | 2010-01-24T04:35:09Z | [
"python",
"ruby-on-rails",
"django",
"rest"
] |
How limiting are web frameworks | 2,125,865 | <p>This is a general question about how limiting are web development frameworks such as Django and ruby-on-rails.</p>
<p>I am planning on building a RESTful web service which will have a purely JSON/XML interface, no GUI. The service will rely on a database however for a few of the more important operations there is n... | 7 | 2010-01-24T03:53:02Z | 2,125,979 | <p>You can still use the full potential of the language in question, even if you also use a framework. A framework isn't a limiting factor, it's basically a tool to ease development of certain parts of your application. Django and rails, for instance, abstract away some database functionality, so you'll only have to wo... | 5 | 2010-01-24T04:35:54Z | [
"python",
"ruby-on-rails",
"django",
"rest"
] |
How limiting are web frameworks | 2,125,865 | <p>This is a general question about how limiting are web development frameworks such as Django and ruby-on-rails.</p>
<p>I am planning on building a RESTful web service which will have a purely JSON/XML interface, no GUI. The service will rely on a database however for a few of the more important operations there is n... | 7 | 2010-01-24T03:53:02Z | 2,126,006 | <p>If you're not using the presentation layer of Rails, you're missing out on a huge part of it. The functionality required to dump objects to json/xml is so small the only real remaining advantages you could gain from it would be ActiveRecord and routing, and if you can't imagine your data cleanly fitting a model, the... | 1 | 2010-01-24T04:55:59Z | [
"python",
"ruby-on-rails",
"django",
"rest"
] |
How limiting are web frameworks | 2,125,865 | <p>This is a general question about how limiting are web development frameworks such as Django and ruby-on-rails.</p>
<p>I am planning on building a RESTful web service which will have a purely JSON/XML interface, no GUI. The service will rely on a database however for a few of the more important operations there is n... | 7 | 2010-01-24T03:53:02Z | 2,126,011 | <p>Web frameworks tend to optimize around building websites, making most normal use cases simpler to accomplish. Once you start to do more "out of the box" stuff with a framework, you might find that you spend more time working around it then you save using it in the first place.</p>
<p>It's hard to generalize here (... | 8 | 2010-01-24T04:58:13Z | [
"python",
"ruby-on-rails",
"django",
"rest"
] |
How limiting are web frameworks | 2,125,865 | <p>This is a general question about how limiting are web development frameworks such as Django and ruby-on-rails.</p>
<p>I am planning on building a RESTful web service which will have a purely JSON/XML interface, no GUI. The service will rely on a database however for a few of the more important operations there is n... | 7 | 2010-01-24T03:53:02Z | 2,126,030 | <p>I have used Ruby/Rails for years now, and unlike just about every other language/framework I have used (across nearly 15 years of Java, PHP, ColdFusion, ASP, etc etc) it gets out of the way when you need it to.</p>
<p>It sounds like you might benefit from a "lighter-weight" framework like Sinatra, but with the upco... | 1 | 2010-01-24T05:06:05Z | [
"python",
"ruby-on-rails",
"django",
"rest"
] |
How limiting are web frameworks | 2,125,865 | <p>This is a general question about how limiting are web development frameworks such as Django and ruby-on-rails.</p>
<p>I am planning on building a RESTful web service which will have a purely JSON/XML interface, no GUI. The service will rely on a database however for a few of the more important operations there is n... | 7 | 2010-01-24T03:53:02Z | 2,126,315 | <p>Most web <strong>sites</strong> will be well suited to rich frameworks like Rails or Django -- but you're building a web <strong>service</strong> , and that has very different tradeoffs.</p>
<p>Personally, I prefer to use <em>very</em> light frameworks for web services: in Python, that means relying primarily on <a... | 6 | 2010-01-24T07:35:01Z | [
"python",
"ruby-on-rails",
"django",
"rest"
] |
How limiting are web frameworks | 2,125,865 | <p>This is a general question about how limiting are web development frameworks such as Django and ruby-on-rails.</p>
<p>I am planning on building a RESTful web service which will have a purely JSON/XML interface, no GUI. The service will rely on a database however for a few of the more important operations there is n... | 7 | 2010-01-24T03:53:02Z | 2,126,329 | <p><strong>You have written down no requirements</strong>, you have written down <em>technology decisions</em>. That's something totally different. <strong>What</strong> do you want to achieve? Then we might be able to help you with <strong>how</strong> to achieve them.</p>
| 1 | 2010-01-24T07:42:07Z | [
"python",
"ruby-on-rails",
"django",
"rest"
] |
How limiting are web frameworks | 2,125,865 | <p>This is a general question about how limiting are web development frameworks such as Django and ruby-on-rails.</p>
<p>I am planning on building a RESTful web service which will have a purely JSON/XML interface, no GUI. The service will rely on a database however for a few of the more important operations there is n... | 7 | 2010-01-24T03:53:02Z | 2,126,352 | <p>Give a try to Spring 3.0 : <a href="http://blog.springsource.com/2009/03/08/rest-in-spring-3-mvc/" rel="nofollow">See this post</a></p>
| 0 | 2010-01-24T07:52:22Z | [
"python",
"ruby-on-rails",
"django",
"rest"
] |
How limiting are web frameworks | 2,125,865 | <p>This is a general question about how limiting are web development frameworks such as Django and ruby-on-rails.</p>
<p>I am planning on building a RESTful web service which will have a purely JSON/XML interface, no GUI. The service will rely on a database however for a few of the more important operations there is n... | 7 | 2010-01-24T03:53:02Z | 2,126,628 | <p>In average, the more complete and helpful the web framework is, the more limiting it is when you try to do things another way than the way the web framework thinks is The Right Way. Some web frameworks try to be very helpful and still not restrictive, and some do that better than others.</p>
<p>And the general reco... | 2 | 2010-01-24T10:02:58Z | [
"python",
"ruby-on-rails",
"django",
"rest"
] |
How limiting are web frameworks | 2,125,865 | <p>This is a general question about how limiting are web development frameworks such as Django and ruby-on-rails.</p>
<p>I am planning on building a RESTful web service which will have a purely JSON/XML interface, no GUI. The service will rely on a database however for a few of the more important operations there is n... | 7 | 2010-01-24T03:53:02Z | 2,129,721 | <p>If you know you're not going to use an ORM, or create a user interface, then you've just eliminated about 90% of what you'd use a web application framework for in the first place. If you look at the feature set of Django, for instance: what parts of that would you use to implement a web service that you couldn't g... | 1 | 2010-01-25T01:38:15Z | [
"python",
"ruby-on-rails",
"django",
"rest"
] |
How to organize an app-engine application | 2,125,951 | <p>I want to create a directory structure like the following. How can I get the account.py and game.py to handle the requests that go to \account\ and \game\ respectfully. All the app-engine examples I have seen have all the logic in on main.py that handle all urls.</p>
<pre><code>app\account\
\account.... | 3 | 2010-01-24T04:27:43Z | 2,125,980 | <p>Take a look at <a href="http://code.google.com/p/gae-mvc-engine/" rel="nofollow">MVCEngine</a>, a framework for AppEngine that provides a Ruby on Rails-like structure for building apps. It may or may not be overkill for what you are looking to do, but if you take a look in the main project file, MVCEngine.py, you sh... | 2 | 2010-01-24T04:36:08Z | [
"python",
"google-app-engine"
] |
How to organize an app-engine application | 2,125,951 | <p>I want to create a directory structure like the following. How can I get the account.py and game.py to handle the requests that go to \account\ and \game\ respectfully. All the app-engine examples I have seen have all the logic in on main.py that handle all urls.</p>
<pre><code>app\account\
\account.... | 3 | 2010-01-24T04:27:43Z | 2,126,290 | <p>You need the following in your <code>app.yaml</code>:</p>
<pre><code>- url: /account
script: account/account.py
- url: /game
script: game/game.py
- url: .*
script: main.py
</code></pre>
<p>BTW, I suggest you try to forget backslashes (characters like this: \ ) -- think <em>normal</em> slashes (characters l... | 11 | 2010-01-24T07:21:54Z | [
"python",
"google-app-engine"
] |
Which python installation should I use? | 2,126,001 | <p>I'm about to refresh myself in programming and I have decided on Python 2.6 for that. I have searched the net and it gave me two possible installers for download. One is from the Python site and another is from Activestate. Which one should I install on my Windows computer?</p>
| 8 | 2010-01-24T04:53:42Z | 2,126,014 | <p>I suggest you to download <a href="http://python.org/download/">from python site</a> </p>
| 5 | 2010-01-24T04:59:09Z | [
"python",
"windows",
"installer",
"activepython"
] |
Which python installation should I use? | 2,126,001 | <p>I'm about to refresh myself in programming and I have decided on Python 2.6 for that. I have searched the net and it gave me two possible installers for download. One is from the Python site and another is from Activestate. Which one should I install on my Windows computer?</p>
| 8 | 2010-01-24T04:53:42Z | 2,126,015 | <p><a href="http://www.activestate.com/activepython" rel="nofollow">ActiveState</a> gives you paid support. While this may be very important / critical to some companies, most do just fine with python.org version, particularly those who experiment. </p>
<p>There are other crazy ones like Stackless Python, Google's imp... | 6 | 2010-01-24T04:59:43Z | [
"python",
"windows",
"installer",
"activepython"
] |
Which python installation should I use? | 2,126,001 | <p>I'm about to refresh myself in programming and I have decided on Python 2.6 for that. I have searched the net and it gave me two possible installers for download. One is from the Python site and another is from Activestate. Which one should I install on my Windows computer?</p>
| 8 | 2010-01-24T04:53:42Z | 2,126,114 | <p>If all you want is refresh your programming skill, then installing the version from the <a href="http://python.org/" rel="nofollow">official</a> site should be more than enough</p>
| 1 | 2010-01-24T05:51:00Z | [
"python",
"windows",
"installer",
"activepython"
] |
Which python installation should I use? | 2,126,001 | <p>I'm about to refresh myself in programming and I have decided on Python 2.6 for that. I have searched the net and it gave me two possible installers for download. One is from the Python site and another is from Activestate. Which one should I install on my Windows computer?</p>
| 8 | 2010-01-24T04:53:42Z | 2,126,117 | <p>Download Python 2.6 from the python.org and read its tutorial as a start. </p>
| 1 | 2010-01-24T05:54:20Z | [
"python",
"windows",
"installer",
"activepython"
] |
Which python installation should I use? | 2,126,001 | <p>I'm about to refresh myself in programming and I have decided on Python 2.6 for that. I have searched the net and it gave me two possible installers for download. One is from the Python site and another is from Activestate. Which one should I install on my Windows computer?</p>
| 8 | 2010-01-24T04:53:42Z | 2,126,268 | <p><strong><a href="http://www.activestate.com/activepython/" rel="nofollow">ActivePython</a></strong> is essentially the same as python.org's distro - except you also get the following:</p>
<ul>
<li><a href="http://docs.activestate.com/activepython/2.7/pypm.html" rel="nofollow"><strong>PyPM</strong></a>: a binary pac... | 6 | 2010-01-24T07:12:13Z | [
"python",
"windows",
"installer",
"activepython"
] |
Which python installation should I use? | 2,126,001 | <p>I'm about to refresh myself in programming and I have decided on Python 2.6 for that. I have searched the net and it gave me two possible installers for download. One is from the Python site and another is from Activestate. Which one should I install on my Windows computer?</p>
| 8 | 2010-01-24T04:53:42Z | 2,126,277 | <p>Since you're running Windows you may want to also install (after Python 2.6) <a href="http://sourceforge.net/projects/pywin32/" rel="nofollow">Pywin32 - Python Extensions for Windows: </a>. It also has a very nice IDE (PythonWin) which you may prefer to IDLE. A version of Pywin32 is also available for Python 3.x.</p... | 1 | 2010-01-24T07:14:18Z | [
"python",
"windows",
"installer",
"activepython"
] |
Which python installation should I use? | 2,126,001 | <p>I'm about to refresh myself in programming and I have decided on Python 2.6 for that. I have searched the net and it gave me two possible installers for download. One is from the Python site and another is from Activestate. Which one should I install on my Windows computer?</p>
| 8 | 2010-01-24T04:53:42Z | 3,264,583 | <p>I also do recommend ACTIVESTATE - with the standard python.org package you will have lots of trouble when you want to install packages!</p>
<p><strong>BUT</strong> be prepared to be bitten from time to time by ActiveState:</p>
<pre><code>D:\>pypm search lxml
*** Packages marked [BE] below require a valid
*** Bu... | 0 | 2010-07-16T11:59:48Z | [
"python",
"windows",
"installer",
"activepython"
] |
Python os.path is ntpath, how? | 2,126,301 | <p>Can someone tell me how Python "aliases" <code>os.path</code> to <code>ntpath</code>?</p>
<pre><code>>>> import os.path
>>> os.path
<module 'ntpath' from 'C:\Python26\lib\ntpath.pyc'>
>>>
</code></pre>
| 4 | 2010-01-24T07:28:19Z | 2,126,306 | <pre><code>>>> import os as my_aliased_module
>>> my_aliased_module
<module 'os' from 'C:\Program Files\Python 2.6\lib\os.pyc'>
</code></pre>
<p><strong>EDIT:</strong> And since <code>import</code> is a simple statement in Python, you can do neat stuff like:</p>
<pre><code>import sys
if sys.p... | 6 | 2010-01-24T07:31:28Z | [
"python",
"path",
"module",
"alias"
] |
Python os.path is ntpath, how? | 2,126,301 | <p>Can someone tell me how Python "aliases" <code>os.path</code> to <code>ntpath</code>?</p>
<pre><code>>>> import os.path
>>> os.path
<module 'ntpath' from 'C:\Python26\lib\ntpath.pyc'>
>>>
</code></pre>
| 4 | 2010-01-24T07:28:19Z | 2,126,323 | <p>Look at <a href="http://svn.python.org/view/python/trunk/Lib/os.py?annotate=77218">os.py</a>, lines 55-67:</p>
<pre><code>elif 'nt' in _names:
name = 'nt'
linesep = '\r\n'
from nt import *
try:
from nt import _exit
except ImportError:
pass
import ntpath as path
import nt... | 7 | 2010-01-24T07:39:25Z | [
"python",
"path",
"module",
"alias"
] |
Machine learning issue for negative instances | 2,126,383 | <p>I had to build a concept analyzer for computer science field and I used for this machine learning, the orange library for Python. I have the examples of concepts, where the features are lemma and part of speech, like algorithm|NN|concept. The problem is that any other word, that in fact is not a concept, is classifi... | 2 | 2010-01-24T08:07:08Z | 2,126,656 | <p>The question is very unclear, but assuming what you mean is that your machine learning algorithm is not working without negative examples and you can't give it every possible negative example, then it's perfectly alright to give it <em>some</em> negative examples.</p>
<p>The point of data mining (a.k.a. machine lea... | 2 | 2010-01-24T10:15:23Z | [
"python",
"artificial-intelligence",
"machine-learning",
"data-mining"
] |
Using Django's Model API without having to *include* the full Django stack | 2,126,433 | <p>Currently an application of mine is using <strong>SQLAlchemy</strong>, but I have been considering the possibility of using <strong>Django model API</strong>. </p>
<p>Django 1.1.1 is about 3.6 megabytes in size, whereas SQLAlchemy is about 400 kilobytes (as reported by PyPM - which is essentially the size of the fi... | 1 | 2010-01-24T08:27:23Z | 2,127,512 | <p>The Django ORM is usable on its own - you can use "settings.configure()" to set up the database settings. That said, you'll have to do the stripping down and repackaging yourself, and you'll have to experiment with how much you can actually strip away. I'm sure you can ditch contrib/, forms/, template/, and probably... | 1 | 2010-01-24T15:20:58Z | [
"python",
"django",
"deployment",
"size",
"sqlalchemy"
] |
Using Django's Model API without having to *include* the full Django stack | 2,126,433 | <p>Currently an application of mine is using <strong>SQLAlchemy</strong>, but I have been considering the possibility of using <strong>Django model API</strong>. </p>
<p>Django 1.1.1 is about 3.6 megabytes in size, whereas SQLAlchemy is about 400 kilobytes (as reported by PyPM - which is essentially the size of the fi... | 1 | 2010-01-24T08:27:23Z | 2,130,014 | <p>You may be able to get a good idea of what is safe to strip out by checking which files don't have their access time updated when you run your application.</p>
| 1 | 2010-01-25T03:19:03Z | [
"python",
"django",
"deployment",
"size",
"sqlalchemy"
] |
An equivalent to string.ascii_letters for unicode strings in python 2.x? | 2,126,551 | <p>In the "string" module of the standard library, </p>
<pre><code>string.ascii_letters ## Same as string.ascii_lowercase + string.ascii_uppercase
</code></pre>
<p>is</p>
<pre><code>'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
</code></pre>
<p>Is there a similar constant which would include everything th... | 10 | 2010-01-24T09:26:57Z | 2,126,592 | <p>That would be a pretty massive constant. Unicode currently covers over 100.000 different characters. So the answer is no.</p>
<p>The question is why you would need it? There might be some other way of solving whatever your problem is with the unicodedata module, for example.</p>
<p>Update: You can download files w... | 0 | 2010-01-24T09:44:36Z | [
"python",
"unicode",
"python-2.x"
] |
An equivalent to string.ascii_letters for unicode strings in python 2.x? | 2,126,551 | <p>In the "string" module of the standard library, </p>
<pre><code>string.ascii_letters ## Same as string.ascii_lowercase + string.ascii_uppercase
</code></pre>
<p>is</p>
<pre><code>'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
</code></pre>
<p>Is there a similar constant which would include everything th... | 10 | 2010-01-24T09:26:57Z | 2,126,632 | <p>There's no string, but you can check whether a character is a letter using the <code>unicodedata</code> module, in particular its <code>category()</code> function.</p>
<pre><code>>>> unicodedata.category(u'a')
'Ll'
>>> unicodedata.category(u'A')
'Lu'
>>> unicodedata.category(u'5')
'Nd'
&g... | 6 | 2010-01-24T10:05:15Z | [
"python",
"unicode",
"python-2.x"
] |
An equivalent to string.ascii_letters for unicode strings in python 2.x? | 2,126,551 | <p>In the "string" module of the standard library, </p>
<pre><code>string.ascii_letters ## Same as string.ascii_lowercase + string.ascii_uppercase
</code></pre>
<p>is</p>
<pre><code>'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
</code></pre>
<p>Is there a similar constant which would include everything th... | 10 | 2010-01-24T09:26:57Z | 2,126,775 | <p>As mentioned in previous answers, the string would indeed be <em>way</em> too long. So, you have to target (a) specific language(s).<br>
[EDIT: I realized it was the case for my original intended use, and for most uses, I guess. However, in the meantime, Mark Tolonen gave a good answer to the question as it was aske... | -1 | 2010-01-24T11:08:34Z | [
"python",
"unicode",
"python-2.x"
] |
An equivalent to string.ascii_letters for unicode strings in python 2.x? | 2,126,551 | <p>In the "string" module of the standard library, </p>
<pre><code>string.ascii_letters ## Same as string.ascii_lowercase + string.ascii_uppercase
</code></pre>
<p>is</p>
<pre><code>'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
</code></pre>
<p>Is there a similar constant which would include everything th... | 10 | 2010-01-24T09:26:57Z | 2,127,648 | <p>You can construct your own constant of Unicode upper and lower case letters with:</p>
<pre><code>import unicodedata as ud
all_unicode = ''.join(unichr(i) for i in xrange(65536))
unicode_letters = ''.join(c for c in all_unicode
if ud.category(c)=='Lu' or ud.category(c)=='Ll')
</code></pre>
... | 11 | 2010-01-24T15:58:49Z | [
"python",
"unicode",
"python-2.x"
] |
Processing a simple workflow in Python | 2,126,811 | <p>I am working on a code which takes a dataset and runs some algorithms on it.</p>
<p>User uploads a dataset, and then selects which algorithms will be run on this dataset and creates a workflow like this:</p>
<pre><code>workflow =
{0: {'dataset': 'some dataset'},
1: {'algorithm1': "parameters"},
2: {'algorithm2'... | 9 | 2010-01-24T11:20:47Z | 2,126,837 | <p>The way you want to do it seems sound to me, or you need to post more informations about what you are trying to accomplish.</p>
<p>And advice: I would put the workflow structure in a list with tuples rather than a dictionary</p>
<pre><code>workflow = [ ('dataset', 'some dataset'),
('algorithm1', "para... | 2 | 2010-01-24T11:31:04Z | [
"python",
"workflow"
] |
Processing a simple workflow in Python | 2,126,811 | <p>I am working on a code which takes a dataset and runs some algorithms on it.</p>
<p>User uploads a dataset, and then selects which algorithms will be run on this dataset and creates a workflow like this:</p>
<pre><code>workflow =
{0: {'dataset': 'some dataset'},
1: {'algorithm1': "parameters"},
2: {'algorithm2'... | 9 | 2010-01-24T11:20:47Z | 2,126,839 | <p>If each <code>algorithm</code> works on each element on <code>dataset</code>, <code>map()</code> would be an elegant option:</p>
<pre><code>dataset=workflow[0]
for algorithm in workflow[1:]:
dataset=map(algorithm, dataset)
</code></pre>
<p>e.g. for the square roots of odd numbers only, use,</p>
<pre><code>>... | 4 | 2010-01-24T11:31:13Z | [
"python",
"workflow"
] |
Processing a simple workflow in Python | 2,126,811 | <p>I am working on a code which takes a dataset and runs some algorithms on it.</p>
<p>User uploads a dataset, and then selects which algorithms will be run on this dataset and creates a workflow like this:</p>
<pre><code>workflow =
{0: {'dataset': 'some dataset'},
1: {'algorithm1': "parameters"},
2: {'algorithm2'... | 9 | 2010-01-24T11:20:47Z | 2,126,853 | <p>Define a <code>Dataset</code> class that tracks... data... for your set. Define methods in this class. Something like this:</p>
<pre><code>class Dataset:
# Some member fields here that define your data, and a constructor
def algorithm1(self, param1, param2, param3):
# Update member fields based on ... | 1 | 2010-01-24T11:37:23Z | [
"python",
"workflow"
] |
Processing a simple workflow in Python | 2,126,811 | <p>I am working on a code which takes a dataset and runs some algorithms on it.</p>
<p>User uploads a dataset, and then selects which algorithms will be run on this dataset and creates a workflow like this:</p>
<pre><code>workflow =
{0: {'dataset': 'some dataset'},
1: {'algorithm1': "parameters"},
2: {'algorithm2'... | 9 | 2010-01-24T11:20:47Z | 2,126,863 | <p>You want to run a pipeline on some dataset. That sounds like a reduce operation (fold in some languages). No need for anything complicated:</p>
<pre><code>result = reduce(lambda data, (aname, p): algo_by_name(aname)(p, data), workflow)
</code></pre>
<p>This assumes workflow looks like (text-oriented so you can loa... | 9 | 2010-01-24T11:41:21Z | [
"python",
"workflow"
] |
Processing a simple workflow in Python | 2,126,811 | <p>I am working on a code which takes a dataset and runs some algorithms on it.</p>
<p>User uploads a dataset, and then selects which algorithms will be run on this dataset and creates a workflow like this:</p>
<pre><code>workflow =
{0: {'dataset': 'some dataset'},
1: {'algorithm1': "parameters"},
2: {'algorithm2'... | 9 | 2010-01-24T11:20:47Z | 2,126,983 | <p>Here is how I would do this (all code untested):</p>
<p>Step 1: You need to create the algorithms. The Dataset could look like this:</p>
<pre><code>class Dataset(object):
def __init__(self, dataset):
self.dataset = dataset
def __iter__(self):
for x in self.dataset:
yield x
</co... | 1 | 2010-01-24T12:19:14Z | [
"python",
"workflow"
] |
web2py - my application doesn' login | 2,126,824 | <p>i have a web2py application and am using default/user/login to login to my application but sometimes when i login the application redirect to the login page agin and sometimes the system logged fine and there is no problem i dont know why ?</p>
<p>so please can anyone tell me ?</p>
<p>Thanks in advance</p>
| 2 | 2010-01-24T11:24:44Z | 2,391,381 | <p>I have seen something like this happen with cookie based load balancing. The cookie was being set too late, so the user would switch frontends sometimes when they logged it.</p>
<p>If you have a load balancer over 2 frontends, you might see this happen 50% of the time.</p>
<p>Check the logs and make sure the hits ... | 1 | 2010-03-06T04:47:32Z | [
"python",
"web2py"
] |
Can you really scale up with Django...given that you can only use one database? (In the models.py and settings.py) | 2,127,067 | <p>Django only allows you to use one database in settings.py.
Does that prevent you from scaling up? (millions of users)</p>
| 5 | 2010-01-24T12:46:44Z | 2,127,076 | <p>Django now has <a href="http://code.djangoproject.com/wiki/MultipleDatabaseSupport" rel="nofollow">support for multiple databases</a>.</p>
| 11 | 2010-01-24T12:49:51Z | [
"python",
"django",
"web-services",
"scalability"
] |
Can you really scale up with Django...given that you can only use one database? (In the models.py and settings.py) | 2,127,067 | <p>Django only allows you to use one database in settings.py.
Does that prevent you from scaling up? (millions of users)</p>
| 5 | 2010-01-24T12:46:44Z | 2,127,141 | <p>The database isn't your bottleneck.</p>
<p>Check your browser carefully.</p>
<p>For each page of HTML you're sending (on average) 8 other files, some of which may be quite large. These are your JS, CSS, graphics, etc.</p>
<p>The actual performance bottleneck is the browser requesting those files and accepting th... | 8 | 2010-01-24T13:08:22Z | [
"python",
"django",
"web-services",
"scalability"
] |
Can you really scale up with Django...given that you can only use one database? (In the models.py and settings.py) | 2,127,067 | <p>Django only allows you to use one database in settings.py.
Does that prevent you from scaling up? (millions of users)</p>
| 5 | 2010-01-24T12:46:44Z | 2,127,160 | <p>If you find out that the DB is the bottlenck of your app, and their is now way around it (like using caching) then you should scale your DB as well. Django has nothing to do with this</p>
| 0 | 2010-01-24T13:12:19Z | [
"python",
"django",
"web-services",
"scalability"
] |
Can you really scale up with Django...given that you can only use one database? (In the models.py and settings.py) | 2,127,067 | <p>Django only allows you to use one database in settings.py.
Does that prevent you from scaling up? (millions of users)</p>
| 5 | 2010-01-24T12:46:44Z | 2,127,162 | <p>Read scaling to millions of users is not a database problem, but is fixed with load balancing and caching, etc, see S. Lott above.</p>
<p>Write scaling can indeed be a database problem. "Sharding" and having multiple databases can be one solution, but that's hard with SQL while still retaining the relationality of ... | 3 | 2010-01-24T13:12:50Z | [
"python",
"django",
"web-services",
"scalability"
] |
Can you really scale up with Django...given that you can only use one database? (In the models.py and settings.py) | 2,127,067 | <p>Django only allows you to use one database in settings.py.
Does that prevent you from scaling up? (millions of users)</p>
| 5 | 2010-01-24T12:46:44Z | 2,127,194 | <p>Some great answers already (S. Lott for example), however I thought I should pipe in with some more things:</p>
<p><em>Make sure not to use the database for logical operations</em></p>
<p>I understand the attractiveness of <code>Order By</code> or <code>SQL Procedures</code> however you only have one database but ... | 1 | 2010-01-24T13:27:08Z | [
"python",
"django",
"web-services",
"scalability"
] |
Can you really scale up with Django...given that you can only use one database? (In the models.py and settings.py) | 2,127,067 | <p>Django only allows you to use one database in settings.py.
Does that prevent you from scaling up? (millions of users)</p>
| 5 | 2010-01-24T12:46:44Z | 2,127,238 | <p>A few miscellaneous pieces of advice:</p>
<ul>
<li><p>I'm surprised no one's mentioned this yet. Use memcached. If you're getting a lot of repetitive types of queries (which most webapps do), this can make a huge difference.</p></li>
<li><p>Consider using Oracle's <a href="http://www.orafaq.com/node/1840" rel="no... | 1 | 2010-01-24T13:42:32Z | [
"python",
"django",
"web-services",
"scalability"
] |
Any Python alternatives to Selenium for programmatically logging into websites that require JavaScript for login? | 2,127,181 | <p>Iâm writing a little private app to automatically log into my internet banking every day, and download the latest transactions. Iâm writing it as a Django app, so Iâm working in Python.</p>
<p>My internet banking doesnât seem to work without JavaScript â I think it uses JavaScript to assign a session ID o... | 9 | 2010-01-24T13:22:03Z | 2,127,282 | <p>You can use <a href="http://code.google.com/p/pywebkitgtk/">Pywebkitgtk</a>. There is a <a href="http://blog.motane.lu/2009/06/18/pywebkitgtk-execute-javascript-from-python/">nice tutorial here</a>.</p>
<p>Alternatively, you can use <a href="http://www.crummy.com/software/BeautifulSoup/">Beautiful Soup</a> to get t... | 6 | 2010-01-24T13:59:16Z | [
"javascript",
"python",
"selenium"
] |
Any Python alternatives to Selenium for programmatically logging into websites that require JavaScript for login? | 2,127,181 | <p>Iâm writing a little private app to automatically log into my internet banking every day, and download the latest transactions. Iâm writing it as a Django app, so Iâm working in Python.</p>
<p>My internet banking doesnât seem to work without JavaScript â I think it uses JavaScript to assign a session ID o... | 9 | 2010-01-24T13:22:03Z | 2,128,219 | <p>Looks like <a href="http://blog.motane.lu/2009/07/07/downloading-a-pages-content-with-python-and-webkit/" rel="nofollow">QtWebKit</a> is another option.</p>
| 1 | 2010-01-24T18:37:47Z | [
"javascript",
"python",
"selenium"
] |
Any Python alternatives to Selenium for programmatically logging into websites that require JavaScript for login? | 2,127,181 | <p>Iâm writing a little private app to automatically log into my internet banking every day, and download the latest transactions. Iâm writing it as a Django app, so Iâm working in Python.</p>
<p>My internet banking doesnât seem to work without JavaScript â I think it uses JavaScript to assign a session ID o... | 9 | 2010-01-24T13:22:03Z | 2,128,285 | <p>since you use selenium I think you have already installed firefox. if so get an extension like firebug or tamper data and see what http-requests the javascript code will do while logging in.</p>
<p>if you have the url and the parameters needed you can easily program a python client with httplib or urllib2.</p>
<p>... | 4 | 2010-01-24T18:58:33Z | [
"javascript",
"python",
"selenium"
] |
Any Python alternatives to Selenium for programmatically logging into websites that require JavaScript for login? | 2,127,181 | <p>Iâm writing a little private app to automatically log into my internet banking every day, and download the latest transactions. Iâm writing it as a Django app, so Iâm working in Python.</p>
<p>My internet banking doesnât seem to work without JavaScript â I think it uses JavaScript to assign a session ID o... | 9 | 2010-01-24T13:22:03Z | 2,128,783 | <p>Since BeautifulSoup is no longer being actively developed I would recommend <a href="http://codespeak.net/lxml/" rel="nofollow">lxml</a> since it does all the things that BeautifulSoup can do and a lot more.</p>
| 0 | 2010-01-24T20:53:14Z | [
"javascript",
"python",
"selenium"
] |
Any Python alternatives to Selenium for programmatically logging into websites that require JavaScript for login? | 2,127,181 | <p>Iâm writing a little private app to automatically log into my internet banking every day, and download the latest transactions. Iâm writing it as a Django app, so Iâm working in Python.</p>
<p>My internet banking doesnât seem to work without JavaScript â I think it uses JavaScript to assign a session ID o... | 9 | 2010-01-24T13:22:03Z | 2,129,732 | <p>I think a good match for your problem is <a href="http://twill.idyll.org/" rel="nofollow">Twill</a>: a simple scripting language for Web browsing.</p>
<p>An other one to check is <a href="http://www.getwindmill.com/" rel="nofollow">Windmill</a> (a kind of Selenium but all written in Python).</p>
| 2 | 2010-01-25T01:42:54Z | [
"javascript",
"python",
"selenium"
] |
Any Python alternatives to Selenium for programmatically logging into websites that require JavaScript for login? | 2,127,181 | <p>Iâm writing a little private app to automatically log into my internet banking every day, and download the latest transactions. Iâm writing it as a Django app, so Iâm working in Python.</p>
<p>My internet banking doesnât seem to work without JavaScript â I think it uses JavaScript to assign a session ID o... | 9 | 2010-01-24T13:22:03Z | 7,326,037 | <p>You can also use <a href="http://code.google.com/p/spynner/" rel="nofollow">Spynner</a>, it allows programmatic web browsing.</p>
| 3 | 2011-09-06T20:54:58Z | [
"javascript",
"python",
"selenium"
] |
Matplotlib with dual scale mouse over | 2,127,183 | <p>I try to plot some curves with matplotlib using the default gui component and have some trouble to select which of the two y-axes that the mouse over functionality should select. The default case seems to be that ax2 gets selected but I would like to use ax1 instead. Is this possible to fix in some easy way? </p>
<... | 4 | 2010-01-24T13:23:28Z | 7,196,917 | <p>Add the following after calling twinx</p>
<pre><code>ax3 = ax1.figure.add_axes(ax1.get_position(True), sharex=ax1, sharey=ax1,
frameon=False)
ax3.xaxis.set_visible(False)
ax3.yaxis.set_visible(False)
</code></pre>
<p>You will also need to change plt.grid(True) to ax1.grid(True)</p>
| 2 | 2011-08-25T20:41:48Z | [
"python",
"matplotlib"
] |
tricky string matching | 2,127,188 | <p>I want to find the first index of substrings in a larger string. I only want it to match whole words and I'd like it to be case-insensitive, except that I want it to treat CamelCase as separate words.</p>
<p>The code below does the trick, but it's slow. I'd like to speed it up. Any suggestions? I was trying som... | 4 | 2010-01-24T13:25:36Z | 2,127,237 | <p>If I were doing this with regular expressions I'd probably do it like this:</p>
<pre><code>def word_start_index2(text, seek_word):
camel_case = seek_word[0].upper() + seek_word[1:].lower()
seek_word_i = ''.join('[' + c.lower() + c.upper() + ']'
for c in seek_word)
regex1 = r'(... | 2 | 2010-01-24T13:42:07Z | [
"python",
"regex",
"string",
"find"
] |
tricky string matching | 2,127,188 | <p>I want to find the first index of substrings in a larger string. I only want it to match whole words and I'd like it to be case-insensitive, except that I want it to treat CamelCase as separate words.</p>
<p>The code below does the trick, but it's slow. I'd like to speed it up. Any suggestions? I was trying som... | 4 | 2010-01-24T13:25:36Z | 2,127,343 | <p><code>word_emitter</code> (below) takes a text string and yields lowercase "words" as they are found, one at a time (along with their positions). </p>
<p>It replaces all underscores with spaces. It then splits the text into a list. For example,</p>
<pre><code>"a_foobar_FooBar baz golf_CART Foo"
</code></pre>
<p>b... | 3 | 2010-01-24T14:21:16Z | [
"python",
"regex",
"string",
"find"
] |
tricky string matching | 2,127,188 | <p>I want to find the first index of substrings in a larger string. I only want it to match whole words and I'd like it to be case-insensitive, except that I want it to treat CamelCase as separate words.</p>
<p>The code below does the trick, but it's slow. I'd like to speed it up. Any suggestions? I was trying som... | 4 | 2010-01-24T13:25:36Z | 2,127,430 | <p>With a index to speed up searching :-)</p>
<pre><code>from collections import defaultdict
class IndexedText(object):
""" a indexed text """
def __init__(self, text):
self.text = text
self._index()
def word_start_index(self, word):
l = len(word)
w = word.lower()
... | 1 | 2010-01-24T14:52:05Z | [
"python",
"regex",
"string",
"find"
] |
Finding fast default aliases in Python | 2,127,202 | <p>Is there a faster way to do the following for much larger dicts?</p>
<pre><code>aliases = {
'United States': 'USA',
'United Kingdom': 'UK',
'Russia': 'RUS',
}
if countryname in aliases: countryname = aliases[countryname]
</code></pre>
| 3 | 2010-01-24T13:31:12Z | 2,127,211 | <p>Accessing with .get could be faster than checking and assigning in variable</p>
<pre><code>aliases.get(countryname)
</code></pre>
<p>And if countryname is not exists in aliases it will return None.</p>
| 1 | 2010-01-24T13:33:42Z | [
"python"
] |
Finding fast default aliases in Python | 2,127,202 | <p>Is there a faster way to do the following for much larger dicts?</p>
<pre><code>aliases = {
'United States': 'USA',
'United Kingdom': 'UK',
'Russia': 'RUS',
}
if countryname in aliases: countryname = aliases[countryname]
</code></pre>
| 3 | 2010-01-24T13:31:12Z | 2,127,229 | <p>If your list fits in memory, dicts are the fastest way to go. As S.Mark points out, you are doing two lookups where one will do, either with:</p>
<pre><code>countryname = aliases.get(countryname, countryname)
</code></pre>
<p>(which will leave countryname unchanged if it isn't in the dictionary), or:</p>
<pre><c... | 2 | 2010-01-24T13:39:19Z | [
"python"
] |
Finding fast default aliases in Python | 2,127,202 | <p>Is there a faster way to do the following for much larger dicts?</p>
<pre><code>aliases = {
'United States': 'USA',
'United Kingdom': 'UK',
'Russia': 'RUS',
}
if countryname in aliases: countryname = aliases[countryname]
</code></pre>
| 3 | 2010-01-24T13:31:12Z | 2,127,230 | <p>Your solution is fine, as "in" is 0(1) for dictionaries.</p>
<p>You could do something like this to save some typing:</p>
<pre><code>countryname = aliases.get(countryname, countryname)
</code></pre>
<p>(But I find your code a lot easier to read than that)</p>
<p>When it comes to speed, what solution is best woul... | 6 | 2010-01-24T13:39:24Z | [
"python"
] |
Finding fast default aliases in Python | 2,127,202 | <p>Is there a faster way to do the following for much larger dicts?</p>
<pre><code>aliases = {
'United States': 'USA',
'United Kingdom': 'UK',
'Russia': 'RUS',
}
if countryname in aliases: countryname = aliases[countryname]
</code></pre>
| 3 | 2010-01-24T13:31:12Z | 2,127,713 | <p>If your dictionary is very large and you expect many of your checks not to find a match, then you might want to consider a <a href="http://en.wikipedia.org/wiki/Bloom_filter" rel="nofollow">Bloom filter</a> or one of it's derivatives and allow false positives.</p>
<p>Alternatively, because your keys can be sorted (... | 0 | 2010-01-24T16:14:31Z | [
"python"
] |
Set auto-incrementing attribute in XML node | 2,127,291 | <p>I'm trying to set an attribute in one of the nodes for my XML as below:</p>
<pre><code>rank = 1
for photo in s:
image = feed.createElement('Image')
images.appendChild(image)
image.setAttribute("rank", rank)
p = feed.createTextNode(str(main_url+photo.display.url))
image.appendChild(p)
rank += 1
</code></... | 3 | 2010-01-24T14:02:22Z | 2,127,302 | <p>The <a href="http://docs.python.org/library/xml.dom.html#xml.dom.Element.setAttribute" rel="nofollow"><code>.setAttribute</code> method</a> expects a string, so you will have to convert it:</p>
<pre><code>image.setAttribute("rank", str(rank))
</code></pre>
| 1 | 2010-01-24T14:06:30Z | [
"python",
"xml"
] |
How to resolve case problems for non-english languages in django admin panel? | 2,127,362 | <p>I need to resolve problem with word endings in django admin panel. The language I'm using is russian (using utf-8 charset), so some problems occur, for example, there is a problem with the right endings on the "Add" button for some model names. The simplest thing I found is using jQuery to correct endings "on the fl... | 2 | 2010-01-24T14:28:10Z | 2,127,399 | <p>If I understood the problem correctly, you should just add an appropriate attribute in the meta section of the class.<br>
English example:</p>
<pre><code>class Man(models.Model):
[...your fields...]
class Meta:
verbose_name_plural = "men"
</code></pre>
<p>More info can be found in the <a href="htt... | 1 | 2010-01-24T14:43:40Z | [
"python",
"django",
"internationalization"
] |
Python - Moving entire text between two .doc files | 2,127,410 | <p>I have been having this issue for a while and cannot figure how should I start to do this with python. My OS is windows xp pro. I need the script that moves entire (100% of the text) text from one .doc file to another. But its not so easy as it sounds. The target .doc file is not the only one but can be many of them... | 2 | 2010-01-24T14:46:42Z | 2,127,567 | <p>So you want to take the text from a doc file, and append it to the end of the text in another doc file. And the problem here is that's MS Word files. It's a proprietary format, and as far as I know there is not module to access them from Python.</p>
<p>But if you are on Windows, you can access them via the COM API,... | 1 | 2010-01-24T15:40:13Z | [
"python",
"text",
".doc"
] |
Python - Moving entire text between two .doc files | 2,127,410 | <p>I have been having this issue for a while and cannot figure how should I start to do this with python. My OS is windows xp pro. I need the script that moves entire (100% of the text) text from one .doc file to another. But its not so easy as it sounds. The target .doc file is not the only one but can be many of them... | 2 | 2010-01-24T14:46:42Z | 2,127,977 | <p>Openoffice ships with full python scripting support, have a look: <a href="http://wiki.services.openoffice.org/wiki/Python" rel="nofollow">http://wiki.services.openoffice.org/wiki/Python</a></p>
<p>Might be easier than trying to mess around with MS Word and COM apis.</p>
| 3 | 2010-01-24T17:25:20Z | [
"python",
"text",
".doc"
] |
Easy to use time-stamps in Python | 2,127,447 | <p>I'm working on a journal-type application in Python. The application basically permits the user write entries in the journal and adds a time-stamp for later querying the journal.</p>
<p>As of now, I use the <code>time.ctime()</code> function to generate time-stamps that are visually friendly. The journal entries th... | 3 | 2010-01-24T15:01:42Z | 2,127,476 | <p>Option 1: Don't change anything. Use <a href="http://docs.python.org/library/time.html#time.strptime">time.strptime</a> to parse your timestamps.</p>
<p>Option 2: Change to <code>datetime</code>. You can format the timestamps the same way, and use <a href="http://docs.python.org/library/datetime.html#datetime.dat... | 7 | 2010-01-24T15:11:47Z | [
"python",
"datetime",
"time",
"timestamp"
] |
Easy to use time-stamps in Python | 2,127,447 | <p>I'm working on a journal-type application in Python. The application basically permits the user write entries in the journal and adds a time-stamp for later querying the journal.</p>
<p>As of now, I use the <code>time.ctime()</code> function to generate time-stamps that are visually friendly. The journal entries th... | 3 | 2010-01-24T15:01:42Z | 2,127,501 | <p>You might want to consider changing to <a href="http://en.wikipedia.org/wiki/ISO_8601">ISO 8601</a>. Will help with sorting for example, or transferring data between different systems.</p>
| 9 | 2010-01-24T15:18:19Z | [
"python",
"datetime",
"time",
"timestamp"
] |
Python: Optimizing, or at least getting fresh ideas for a tree generator | 2,127,680 | <p>I have written a program that generates random expressions and then uses genetic techniques to select for fitness.</p>
<p>The following part of the program generates the random expression and stores it in a tree structure.</p>
<p>As this can get called billions of times during a run, I thought it should be optimiz... | 1 | 2010-01-24T16:08:38Z | 2,127,869 | <p>You can omit lots of braces in your code, that's one of Python's benefits. E.g. when putting braces around conditions, like</p>
<pre><code>if (depth <= 0) or ((r > Ratio) and (not (entry))):
</code></pre>
<p>just write</p>
<pre><code>if depth <= 0 or (r > Ratio and not entry):
</code></pre>
<p>And I ... | 2 | 2010-01-24T16:51:19Z | [
"python",
"optimization",
"expression-trees"
] |
Python: Optimizing, or at least getting fresh ideas for a tree generator | 2,127,680 | <p>I have written a program that generates random expressions and then uses genetic techniques to select for fitness.</p>
<p>The following part of the program generates the random expression and stores it in a tree structure.</p>
<p>As this can get called billions of times during a run, I thought it should be optimiz... | 1 | 2010-01-24T16:08:38Z | 2,127,975 | <p>You can replace the KeySeq generator with itertools.count which does exactly the same thing but is implemented in C.</p>
<p>I don't see any way of speeding up the Node constructor. The call to random.choice you could optimise by inlining the code - cut & paste it from the source for the random module. This wi... | 2 | 2010-01-24T17:24:34Z | [
"python",
"optimization",
"expression-trees"
] |
Python: Optimizing, or at least getting fresh ideas for a tree generator | 2,127,680 | <p>I have written a program that generates random expressions and then uses genetic techniques to select for fitness.</p>
<p>The following part of the program generates the random expression and stores it in a tree structure.</p>
<p>As this can get called billions of times during a run, I thought it should be optimiz... | 1 | 2010-01-24T16:08:38Z | 2,128,900 | <p>Below, I've summarized some of the more obvious optimization efforts, without really touching the algorithm much. All timings are done with Python 2.6.4 on a Linux x86-64 system.</p>
<p>Initial time: <strong>8.3s</strong></p>
<h2>Low-Hanging Fruits</h2>
<p><a href="http://stackoverflow.com/questions/2127680/pytho... | 4 | 2010-01-24T21:19:20Z | [
"python",
"optimization",
"expression-trees"
] |
Python Syntax Error but looks fine to me. Help? | 2,127,735 | <p>Right now I'm working on a Tetris Game (sorta, I found a Tetris example for Python on a website, I've been copying it but adding some of my own stuff), and just finished writing all the code but have had a couple syntax errors. I've been able to fix all of them but this last syntax error is confusing to me.</p>
<pr... | 2 | 2010-01-24T16:20:08Z | 2,127,762 | <p>There's an extra whitespace on the last line - just ahead <code>self.removeFullLines()</code>. Its indenting is thus not the same as the <code>for</code> line's indenting. EDIT: Seems to be corrected now.</p>
<p>Always use the same indent sequence - choose either tabs, or n whitespaces. But be consistent. Some edit... | 0 | 2010-01-24T16:25:36Z | [
"python",
"syntax-error"
] |
Python Syntax Error but looks fine to me. Help? | 2,127,735 | <p>Right now I'm working on a Tetris Game (sorta, I found a Tetris example for Python on a website, I've been copying it but adding some of my own stuff), and just finished writing all the code but have had a couple syntax errors. I've been able to fix all of them but this last syntax error is confusing to me.</p>
<pr... | 2 | 2010-01-24T16:20:08Z | 2,127,766 | <p>You didn't close the parenthesis of <code>self.setShapeAt</code>.</p>
| 7 | 2010-01-24T16:26:31Z | [
"python",
"syntax-error"
] |
TextMate and Django Integration - Supporting {% %} markup | 2,127,956 | <p>I have installed a TextMate bundle that I believe enables the ability for automatic closing of the "{{" markup (so that it will automatically close the markup with "}}"), but this does not seem to be possible with the other markup that uses "{%" and "%}".</p>
<p>So, I was wondering if anyone out there knows how to ... | 3 | 2010-01-24T17:17:40Z | 2,128,058 | <p>I don't think that's possible, but the Django bundle for TextMate does allow you to insert the opening and closing tags in one go, placing the cursor in the middle, with ctrl-% (ctrl-shift-5).</p>
<p>Click the Bundles -> Python Django Templates menu to see all the shortcuts that are available.</p>
| 1 | 2010-01-24T17:49:35Z | [
"python",
"django",
"textmate"
] |
TextMate and Django Integration - Supporting {% %} markup | 2,127,956 | <p>I have installed a TextMate bundle that I believe enables the ability for automatic closing of the "{{" markup (so that it will automatically close the markup with "}}"), but this does not seem to be possible with the other markup that uses "{%" and "%}".</p>
<p>So, I was wondering if anyone out there knows how to ... | 3 | 2010-01-24T17:17:40Z | 2,133,642 | <p>It's possible - the Rails bundle does this for ERB (<% automatically gets closing %> tags).</p>
<p>So that's a place you could go look.</p>
| 2 | 2010-01-25T16:14:44Z | [
"python",
"django",
"textmate"
] |
Google App Engine: Add task to queue from a task | 2,127,981 | <p>I need to track data from another website. Since it's spread over 60+ pages, I intend to use a daily cron job to add a task to the queue. This task then should take care of one page and depending on some checks, put another instance of itself on the queue for the next page.</p>
<p>Now a simple</p>
<pre><code>taskq... | 2 | 2010-01-24T17:26:11Z | 2,128,221 | <p>It's possible to add tasks from within tasks. I'm doing it in my application.</p>
<p>It's very useful when you want to migrate a large set of entities : one task processes a small chunk of entities then adds itself to the queue in order to process the rest until the migration is over.</p>
<p>I am not sure what is ... | 6 | 2010-01-24T18:38:15Z | [
"python",
"google-app-engine",
"task",
"task-queue"
] |
Python equivalent of IDL's stop and .reset | 2,127,991 | <p>I'm relatively new to python but have a bit of experience using IDL. I was wondering if anyone knows if there are equivalent commands in python for IDL's stop and .reset commands.</p>
<p>If I'm running some IDL script I wrote that I put a stop command in, essentially what it does is stop the script there and give m... | 7 | 2010-01-24T17:30:24Z | 2,128,011 | <p>You probably just want to use a Python debugger for this.</p>
| 0 | 2010-01-24T17:34:05Z | [
"python",
"reset",
"equivalent",
"idl-programming-language"
] |
Python equivalent of IDL's stop and .reset | 2,127,991 | <p>I'm relatively new to python but have a bit of experience using IDL. I was wondering if anyone knows if there are equivalent commands in python for IDL's stop and .reset commands.</p>
<p>If I'm running some IDL script I wrote that I put a stop command in, essentially what it does is stop the script there and give m... | 7 | 2010-01-24T17:30:24Z | 2,163,054 | <p><code>stop</code> sounds equivalent to use of the <a href="http://docs.python.org/library/code.html" rel="nofollow"><code>code</code></a> module. <code>.reset</code> doesn't have an equivalent in Python short of gratuitous use of <code>del</code>.</p>
| 1 | 2010-01-29T15:46:57Z | [
"python",
"reset",
"equivalent",
"idl-programming-language"
] |
Python equivalent of IDL's stop and .reset | 2,127,991 | <p>I'm relatively new to python but have a bit of experience using IDL. I was wondering if anyone knows if there are equivalent commands in python for IDL's stop and .reset commands.</p>
<p>If I'm running some IDL script I wrote that I put a stop command in, essentially what it does is stop the script there and give m... | 7 | 2010-01-24T17:30:24Z | 2,164,139 | <p>Welcome to the Python community! I'm still learning, but imo Python's nicer than the Interactive Data Language.</p>
<p>Anyway, Ignacio's answer about using the code module looks like it may provide what you want, at least as far as a parallel to IDL's stop.</p>
<p>Another thing you may find useful is to go into P... | 0 | 2010-01-29T18:15:49Z | [
"python",
"reset",
"equivalent",
"idl-programming-language"
] |
Python equivalent of IDL's stop and .reset | 2,127,991 | <p>I'm relatively new to python but have a bit of experience using IDL. I was wondering if anyone knows if there are equivalent commands in python for IDL's stop and .reset commands.</p>
<p>If I'm running some IDL script I wrote that I put a stop command in, essentially what it does is stop the script there and give m... | 7 | 2010-01-24T17:30:24Z | 2,221,432 | <p><a href="http://ipython.scipy.org/moin/" rel="nofollow">IPython</a> (aside from being a far nicer REPL than the standard python interpreter) may do what you want:</p>
<pre><code>from IPython.Shell import IPShellEmbed
start_shell = IPShellEmbed()
def times_2(x):
return 2*x
a = 5
start_shell()
# now in IPyth... | 3 | 2010-02-08T12:12:32Z | [
"python",
"reset",
"equivalent",
"idl-programming-language"
] |
Python equivalent of IDL's stop and .reset | 2,127,991 | <p>I'm relatively new to python but have a bit of experience using IDL. I was wondering if anyone knows if there are equivalent commands in python for IDL's stop and .reset commands.</p>
<p>If I'm running some IDL script I wrote that I put a stop command in, essentially what it does is stop the script there and give m... | 7 | 2010-01-24T17:30:24Z | 2,891,791 | <p>Use pdb, as in this short script. Run it at the command line, and the PDB prompt will magically appear allowing single stepping, evaluation of arbitrary expressions, etc.</p>
<pre><code>#!/usr/bin/env python
import pdb;
print 1
print 2
pdb.set_trace()
print 3
print 4
</code></pre>
| 1 | 2010-05-23T12:54:39Z | [
"python",
"reset",
"equivalent",
"idl-programming-language"
] |
Python equivalent of IDL's stop and .reset | 2,127,991 | <p>I'm relatively new to python but have a bit of experience using IDL. I was wondering if anyone knows if there are equivalent commands in python for IDL's stop and .reset commands.</p>
<p>If I'm running some IDL script I wrote that I put a stop command in, essentially what it does is stop the script there and give m... | 7 | 2010-01-24T17:30:24Z | 25,557,034 | <p>You could do <code>%reset</code> from within an IPython shell.</p>
<p>For stops, just add pydebug breakpoints as mentioned</p>
| 0 | 2014-08-28T20:00:19Z | [
"python",
"reset",
"equivalent",
"idl-programming-language"
] |
Python equivalent of IDL's stop and .reset | 2,127,991 | <p>I'm relatively new to python but have a bit of experience using IDL. I was wondering if anyone knows if there are equivalent commands in python for IDL's stop and .reset commands.</p>
<p>If I'm running some IDL script I wrote that I put a stop command in, essentially what it does is stop the script there and give m... | 7 | 2010-01-24T17:30:24Z | 35,762,023 | <p><code>pdb.set_trace()</code> breaking out of code apparently does not allow you to ".continue" (IDL command) from that point (from <a href="http://pythondammit.blogspot.fr/2012/04/equivalent-of-idls-stop-command.html" rel="nofollow">http://pythondammit.blogspot.fr/2012/04/equivalent-of-idls-stop-command.html</a>)</p... | 1 | 2016-03-03T02:25:23Z | [
"python",
"reset",
"equivalent",
"idl-programming-language"
] |
Django, making a page activate for a fixed time | 2,128,093 | <p>Greetings
I am hacking Django and trying to test something such as:</p>
<p>Like <a href="http://www.woot.com" rel="nofollow">woot.com</a> , I want to sell "an item per day", so only one item will be available for that day (say the default www.mysite.com will be redirected to that item), </p>
<p>Assume my urls for ... | 0 | 2010-01-24T18:03:24Z | 2,128,123 | <p>It seems you've got the basics figured out, so I'm assuming you're asking for polishing suggestions... A few ideas in this vein:</p>
<ol>
<li><p>I think I'd have a separate URL like <code>/items/today/</code> for this, or perhaps just <code>/today/</code>.</p></li>
<li><p>You'll want to use <strong>the date compone... | 2 | 2010-01-24T18:14:37Z | [
"python",
"django",
"django-models",
"django-views"
] |
Django, making a page activate for a fixed time | 2,128,093 | <p>Greetings
I am hacking Django and trying to test something such as:</p>
<p>Like <a href="http://www.woot.com" rel="nofollow">woot.com</a> , I want to sell "an item per day", so only one item will be available for that day (say the default www.mysite.com will be redirected to that item), </p>
<p>Assume my urls for ... | 0 | 2010-01-24T18:03:24Z | 2,128,215 | <p>I have a photo of the day feature on my site. I have a model that represents today's photo, and a cron job runs a custom management command at midnight to update it with the next photo in the sequence (also a model). So all my view has to do is retrieve the current photo from the database.</p>
| 1 | 2010-01-24T18:36:06Z | [
"python",
"django",
"django-models",
"django-views"
] |
Access contents of PyBuffer from C | 2,128,195 | <p>I have created a buffer object in python like so:</p>
<pre><code>f = io.open('some_file', 'rb')
byte_stream = buffer(f.read(4096))
</code></pre>
<p>I'm now passing <code>byte_stream</code> as a parameter to a C function, through SWIG. I have a typemap for converting the data which looks like this:</p>
<pre><code>... | 2 | 2010-01-24T18:30:15Z | 2,128,952 | <p>As soon as you use the <code>read</code> method on your file object, the data will be converted to a <code>str</code> object; calling the <code>buffer</code> method does not convert it into a stream of any kind. If you want to avoid the overhead of creating the string object, you could simply pass the file object to... | 1 | 2010-01-24T21:31:51Z | [
"python",
"swig",
"python-c-api",
"pybuffer"
] |
Access contents of PyBuffer from C | 2,128,195 | <p>I have created a buffer object in python like so:</p>
<pre><code>f = io.open('some_file', 'rb')
byte_stream = buffer(f.read(4096))
</code></pre>
<p>I'm now passing <code>byte_stream</code> as a parameter to a C function, through SWIG. I have a typemap for converting the data which looks like this:</p>
<pre><code>... | 2 | 2010-01-24T18:30:15Z | 2,200,654 | <blockquote>
<p>I'm using buffers because I want to
avoid the overhead of converting the
data to a string when reading it from
the file</p>
</blockquote>
<p>You are not avoiding anything. The string is already built by the <code>read()</code> method. Calling <code>buffer()</code> just builds an additional buff... | 2 | 2010-02-04T15:05:11Z | [
"python",
"swig",
"python-c-api",
"pybuffer"
] |
Network programming in Python | 2,128,266 | <p>What library should I use for network programming? Is <code>sockets</code> the best, or is there a higher level interface, that is standard?</p>
<p>I need something that will be pretty cross platform (ie. Linux, Windows, Mac OS X), and it only needs to be able to connect to other Python programs using the same libr... | 2 | 2010-01-24T18:51:42Z | 2,128,279 | <p>There is a framework that you may be interested in: <a href="http://twistedmatrix.com" rel="nofollow">Twisted</a></p>
| 6 | 2010-01-24T18:55:51Z | [
"python",
"sockets",
"network-programming"
] |
Network programming in Python | 2,128,266 | <p>What library should I use for network programming? Is <code>sockets</code> the best, or is there a higher level interface, that is standard?</p>
<p>I need something that will be pretty cross platform (ie. Linux, Windows, Mac OS X), and it only needs to be able to connect to other Python programs using the same libr... | 2 | 2010-01-24T18:51:42Z | 2,128,325 | <p>A lot of people like <a href="http://twistedmatrix.com/" rel="nofollow">Twisted</a>. I was a huge fan for awhile, but on working with it a bit and thinking about it more I've become disenchanted. It's complex, and last I looked, a lot of it had the assumption that your program would <strong>always</strong> be able... | 4 | 2010-01-24T19:10:34Z | [
"python",
"sockets",
"network-programming"
] |
Network programming in Python | 2,128,266 | <p>What library should I use for network programming? Is <code>sockets</code> the best, or is there a higher level interface, that is standard?</p>
<p>I need something that will be pretty cross platform (ie. Linux, Windows, Mac OS X), and it only needs to be able to connect to other Python programs using the same libr... | 2 | 2010-01-24T18:51:42Z | 2,128,428 | <p>As previously mentioned, Twisted is the most popular (by far). However, there are a lot of other alternative worth exploring. <a href="http://www.tornadoweb.org/" rel="nofollow">Tornado</a> and <a href="http://dieselweb.org/" rel="nofollow">Diesel</a> are probably the top two contenders. A more complete comparison... | 5 | 2010-01-24T19:33:21Z | [
"python",
"sockets",
"network-programming"
] |
Network programming in Python | 2,128,266 | <p>What library should I use for network programming? Is <code>sockets</code> the best, or is there a higher level interface, that is standard?</p>
<p>I need something that will be pretty cross platform (ie. Linux, Windows, Mac OS X), and it only needs to be able to connect to other Python programs using the same libr... | 2 | 2010-01-24T18:51:42Z | 2,128,435 | <p>the answer depends on what you are trying to do.</p>
<p>"What library should I use for network programming?" is pretty vague.</p>
<p>for example, if you want to do HTTP, you might look at such standard libraries as urllib, urllib2, httplib, sockets. It all depends on which protocol you are looking to use, and whi... | 6 | 2010-01-24T19:34:32Z | [
"python",
"sockets",
"network-programming"
] |
Network programming in Python | 2,128,266 | <p>What library should I use for network programming? Is <code>sockets</code> the best, or is there a higher level interface, that is standard?</p>
<p>I need something that will be pretty cross platform (ie. Linux, Windows, Mac OS X), and it only needs to be able to connect to other Python programs using the same libr... | 2 | 2010-01-24T18:51:42Z | 2,128,855 | <p>Personally I just use asyncore from the standard library, which is a bit like a very cut-down version of Twisted, but this is because I prefer a simple and low level interface. If you want a higher level interface, especially just to communicate with another instance of your own program, you don't necessarily have t... | 5 | 2010-01-24T21:09:24Z | [
"python",
"sockets",
"network-programming"
] |
Network programming in Python | 2,128,266 | <p>What library should I use for network programming? Is <code>sockets</code> the best, or is there a higher level interface, that is standard?</p>
<p>I need something that will be pretty cross platform (ie. Linux, Windows, Mac OS X), and it only needs to be able to connect to other Python programs using the same libr... | 2 | 2010-01-24T18:51:42Z | 2,128,966 | <p>The <code>socket</code> module in the standard lib is in my opinion a good choice if you don't need high performance.</p>
<p>It is a very famous API that is known by almost every developpers of almost every languages. It's quite sipmple and there is a lot of information available on the internet. Moreover, it will ... | 1 | 2010-01-24T21:35:59Z | [
"python",
"sockets",
"network-programming"
] |
Network programming in Python | 2,128,266 | <p>What library should I use for network programming? Is <code>sockets</code> the best, or is there a higher level interface, that is standard?</p>
<p>I need something that will be pretty cross platform (ie. Linux, Windows, Mac OS X), and it only needs to be able to connect to other Python programs using the same libr... | 2 | 2010-01-24T18:51:42Z | 2,129,373 | <p>You just want to send python data between nodes (possibly on separate computers)? You might want to look at SimpleXMLRPCServer. It's based on the inbuilt HTTP server, which is based on the inbuilt Socket server, neither of which are the most industrial-strength servers around, but it's easy to set up in a hurry:</p>... | 7 | 2010-01-24T23:27:10Z | [
"python",
"sockets",
"network-programming"
] |
Network programming in Python | 2,128,266 | <p>What library should I use for network programming? Is <code>sockets</code> the best, or is there a higher level interface, that is standard?</p>
<p>I need something that will be pretty cross platform (ie. Linux, Windows, Mac OS X), and it only needs to be able to connect to other Python programs using the same libr... | 2 | 2010-01-24T18:51:42Z | 39,160,652 | <p>Socket is low level api, it is mapped directly to operating system interface.
Twisted, Tornado ... are high level framework (of course they are built on socket because socket is low level).
When it come to TCP/IP programming, you should have some basic knowledge to make a decision about what you shoud use:</p>
<ul>... | 0 | 2016-08-26T07:25:18Z | [
"python",
"sockets",
"network-programming"
] |
Preferred way to store/retrieve python data | 2,128,399 | <p>I would like to include data files with a Python package. Is the best place to put them inside the actual package as suggested <a href="http://docs.python.org/distutils/setupscript.html#installing-package-data" rel="nofollow">here</a>, i.e.</p>
<pre><code>setup.py
src/
mypkg/
__init__.py
module.... | 3 | 2010-01-24T19:24:37Z | 2,128,425 | <p>You should store your data as a Python data structure vÃa the Pickle module. That way, when you call it (load it) the data is ready to be used, and you dont need to process it in every script. </p>
<p>As for the location, it makes sense that you store it in a way that is transparent and clear to the user, the foll... | -2 | 2010-01-24T19:32:39Z | [
"python"
] |
Preferred way to store/retrieve python data | 2,128,399 | <p>I would like to include data files with a Python package. Is the best place to put them inside the actual package as suggested <a href="http://docs.python.org/distutils/setupscript.html#installing-package-data" rel="nofollow">here</a>, i.e.</p>
<pre><code>setup.py
src/
mypkg/
__init__.py
module.... | 3 | 2010-01-24T19:24:37Z | 2,128,455 | <p>pkgutil means you can load the data even if the package is installed in a ZIP file, so it's preferable if you want to support that. Storing it in a data directory like that is fine, I do that all the time. :)</p>
| 3 | 2010-01-24T19:38:17Z | [
"python"
] |
What's the difference between filter and filter_by in SQLAlchemy? | 2,128,505 | <p>Could anyone explain the difference between <code>filter</code> and <code>filter_by</code> functions in SQLAlchemy? I am confused and can't really see the difference. Which one should I be using?</p>
| 144 | 2010-01-24T19:49:46Z | 2,128,558 | <p><code>filter_by</code> is used for simple queries on the column names like</p>
<p><code>db.users.filter_by(name='Joe')</code></p>
<p>The same can be accomplished with <code>filter</code> by writing</p>
<p><code>db.users.filter(db.users.name=='Joe')</code></p>
<p>but you can also write more powerful queries conta... | 160 | 2010-01-24T20:02:56Z | [
"python",
"sqlalchemy"
] |
What's the difference between filter and filter_by in SQLAlchemy? | 2,128,505 | <p>Could anyone explain the difference between <code>filter</code> and <code>filter_by</code> functions in SQLAlchemy? I am confused and can't really see the difference. Which one should I be using?</p>
| 144 | 2010-01-24T19:49:46Z | 2,128,567 | <p><code>filter_by</code> uses keyword arguments, whereas <code>filter</code> allows pythonic filtering arguments like <code>filter(User.name=="john")</code></p>
| 25 | 2010-01-24T20:04:59Z | [
"python",
"sqlalchemy"
] |
What's the difference between filter and filter_by in SQLAlchemy? | 2,128,505 | <p>Could anyone explain the difference between <code>filter</code> and <code>filter_by</code> functions in SQLAlchemy? I am confused and can't really see the difference. Which one should I be using?</p>
| 144 | 2010-01-24T19:49:46Z | 2,157,930 | <p>We actually had these merged together originally, i.e. there was a "filter"-like method that accepted *args and **kwargs, where you could pass a SQL expression or keyword arguments (or both). I actually find that a lot more convenient, but people were always confused by it, since they're usually still getting over ... | 80 | 2010-01-28T21:04:50Z | [
"python",
"sqlalchemy"
] |
What's the difference between filter and filter_by in SQLAlchemy? | 2,128,505 | <p>Could anyone explain the difference between <code>filter</code> and <code>filter_by</code> functions in SQLAlchemy? I am confused and can't really see the difference. Which one should I be using?</p>
| 144 | 2010-01-24T19:49:46Z | 31,560,897 | <p>It is a syntax sugar for faster query writing. Its implementation in pseudocode:</p>
<pre><code>def filter_by(self, **kwargs):
return self.filter(sql.and_(**kwargs))
</code></pre>
<p>For AND you can simply write:</p>
<pre><code>Users.query.filter_by(name='Joe', surname='Dodson')
</code></pre>
<p>btw </p>
<p... | 15 | 2015-07-22T10:45:58Z | [
"python",
"sqlalchemy"
] |
What's the difference between filter and filter_by in SQLAlchemy? | 2,128,505 | <p>Could anyone explain the difference between <code>filter</code> and <code>filter_by</code> functions in SQLAlchemy? I am confused and can't really see the difference. Which one should I be using?</p>
| 144 | 2010-01-24T19:49:46Z | 39,743,480 | <p>the difference between <code>filter()</code> and <code>filter_by()</code> is that the former(<code>filter()</code>) works like an <code>or (||)</code> statement and <code>filter_by()</code> works like an <code>and (&&)</code> statement.
<code>filter()</code> evaluates true if any of the supplied argument is... | 0 | 2016-09-28T09:34:09Z | [
"python",
"sqlalchemy"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.