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 are the benefits of using Python for web programming? | 452,305 | <p>What makes Python stand out for use in web development? What are some examples of highly successful uses of Python on the web?</p>
| 9 | 2009-01-16T22:38:56Z | 27,014,289 | <p>Furthermore, </p>
<p>Python is both strong in web and in data analytics and machine learning. For example scikit, sci-py and numpy are very strong. In some cases, it can be very interesting to have the both elements on the same server.</p>
<p>For example <a href="http://rankmytweet.com" rel="nofollow">http://rankm... | 2 | 2014-11-19T10:18:39Z | [
"python",
"programming-languages"
] |
How can I test that I have a Python module successfully installed? | 452,430 | <p>I tried to install beautifulsoup. I get such an error:<br>
<-- snip --></p>
<pre><code>raise MissingSectionHeaderError(fpname, lineno, line)
ConfigParser.MissingSectionHeaderError: File contains no section headers.
file: /Users/Sam/.pydistutils.cfg, line: 1
'install_lib = ~/Library/Python/$py_version_short/site-... | 2 | 2009-01-16T23:36:04Z | 452,438 | <p>You can test if a module is installed like so:</p>
<pre><code>$ python
>>> import modulename
</code></pre>
| 6 | 2009-01-16T23:40:46Z | [
"python",
"installation",
"module"
] |
How can I test that I have a Python module successfully installed? | 452,430 | <p>I tried to install beautifulsoup. I get such an error:<br>
<-- snip --></p>
<pre><code>raise MissingSectionHeaderError(fpname, lineno, line)
ConfigParser.MissingSectionHeaderError: File contains no section headers.
file: /Users/Sam/.pydistutils.cfg, line: 1
'install_lib = ~/Library/Python/$py_version_short/site-... | 2 | 2009-01-16T23:36:04Z | 452,441 | <p>I'd try the following: </p>
<ol>
<li>Open Python shell </li>
<li>Type <code>import <moduleName></code></li>
<li>Parse the results (no error, ImportError or some module loading error) </li>
<li>Try to invoke any function from imported module (to see if module is correctly initialized).</li>
</ol>
<p>Do you... | 1 | 2009-01-16T23:41:29Z | [
"python",
"installation",
"module"
] |
How can I test that I have a Python module successfully installed? | 452,430 | <p>I tried to install beautifulsoup. I get such an error:<br>
<-- snip --></p>
<pre><code>raise MissingSectionHeaderError(fpname, lineno, line)
ConfigParser.MissingSectionHeaderError: File contains no section headers.
file: /Users/Sam/.pydistutils.cfg, line: 1
'install_lib = ~/Library/Python/$py_version_short/site-... | 2 | 2009-01-16T23:36:04Z | 18,761,681 | <p>try:
from prettytable import <strong>PrettyTable</strong>
except:
try:
print "\033[31mPython-prettytable Module [Not Available]\033[0m"
os.system('sudo apt-get install python-setuptools')
os.system('sudo easy_install prettyTable')
print "\033[33mPython-prettytable Module ... | 0 | 2013-09-12T10:24:02Z | [
"python",
"installation",
"module"
] |
A SuggestBox for wxPython? | 452,520 | <p>Is there a widget for wxPython like the <a href="http://google-web-toolkit.googlecode.com/svn/javadoc/1.5/index.html" rel="nofollow">SuggestBox</a> in Google Web Toolkit? It is basically a magic text box that can invoke some code to come up with suggestions relevant to whatever the user has entered so far. Like the ... | 4 | 2009-01-17T00:14:24Z | 455,144 | <p>You might want to look at <a href="http://wiki.wxpython.org/Combo%20Box%20that%20Suggests%20Options" rel="nofollow">Combo Box that Suggests Options</a>.</p>
<p>I hope this is what you were thinking of.</p>
| 4 | 2009-01-18T13:42:08Z | [
"python",
"search",
"wxpython",
"suggestbox"
] |
A SuggestBox for wxPython? | 452,520 | <p>Is there a widget for wxPython like the <a href="http://google-web-toolkit.googlecode.com/svn/javadoc/1.5/index.html" rel="nofollow">SuggestBox</a> in Google Web Toolkit? It is basically a magic text box that can invoke some code to come up with suggestions relevant to whatever the user has entered so far. Like the ... | 4 | 2009-01-17T00:14:24Z | 4,052,860 | <p>Few years ago I made a control like this by subclassing TextCtrl. It supports HTML formating for suggestions. <a href="http://bitbucket.org/raz/wxautocompletectrl" rel="nofollow">Here you go.</a></p>
| 1 | 2010-10-29T14:38:40Z | [
"python",
"search",
"wxpython",
"suggestbox"
] |
What does this Python message mean? | 452,532 | <pre><code>ho-fe3fdd00-12:~ Sam$ easy_install BeautifulSoup
Traceback (most recent call last):
File "/usr/bin/easy_install", line 8, in <module>
load_entry_point('setuptools==0.6c7', 'console_scripts', 'easy_install')()
File "/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/setup... | -1 | 2009-01-17T00:22:25Z | 452,536 | <p>The configuration file .pydstutils.cfg has a syntax error.</p>
| 2 | 2009-01-17T00:26:07Z | [
"python",
"osx",
"installation",
"beautifulsoup",
"easy-install"
] |
What does this Python message mean? | 452,532 | <pre><code>ho-fe3fdd00-12:~ Sam$ easy_install BeautifulSoup
Traceback (most recent call last):
File "/usr/bin/easy_install", line 8, in <module>
load_entry_point('setuptools==0.6c7', 'console_scripts', 'easy_install')()
File "/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/setup... | -1 | 2009-01-17T00:22:25Z | 452,597 | <p>Try to add the line at the top of <code>~/.pydistutils.cfg</code>:</p>
<pre><code>[easy_install]
</code></pre>
| 2 | 2009-01-17T01:10:25Z | [
"python",
"osx",
"installation",
"beautifulsoup",
"easy-install"
] |
What does this Python message mean? | 452,532 | <pre><code>ho-fe3fdd00-12:~ Sam$ easy_install BeautifulSoup
Traceback (most recent call last):
File "/usr/bin/easy_install", line 8, in <module>
load_entry_point('setuptools==0.6c7', 'console_scripts', 'easy_install')()
File "/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/setup... | -1 | 2009-01-17T00:22:25Z | 452,606 | <p>BeautifulSoup is a pure Python module which you can install by grabbing the BeautifulSoup.py file (eg. from inside the standard .tar.gz distribution) and putting it somewhere on your PythonPath - eg. inside /Users/Sam/Library/Python/2.5/site-packages, if the paths mentioned in the error message are accurate.</p>
<p... | 3 | 2009-01-17T01:17:03Z | [
"python",
"osx",
"installation",
"beautifulsoup",
"easy-install"
] |
How do I create a list of Python lambdas (in a list comprehension/for loop)? | 452,610 | <p>I want to create a list of lambda objects from a list of constants in Python; for instance:</p>
<pre><code>listOfNumbers = [1,2,3,4,5]
square = lambda x: x * x
listOfLambdas = [lambda: square(i) for i in listOfNumbers]
</code></pre>
<p>This will create a list of lambda objects, however, when I run them:</p>
<pre>... | 16 | 2009-01-17T01:19:13Z | 452,639 | <p>I'm guessing that the lambda you're creating in the list comprehension is bound to the variable i which eventually ends up at 5. Thus, when you evaluate the lambdas after the fact, they're all bound to 5 and end up calculating 25. The same thing is happening with num in your second example. When you evaluate the lam... | 11 | 2009-01-17T01:37:51Z | [
"python",
"lambda",
"scope",
"closures",
"list-comprehension"
] |
How do I create a list of Python lambdas (in a list comprehension/for loop)? | 452,610 | <p>I want to create a list of lambda objects from a list of constants in Python; for instance:</p>
<pre><code>listOfNumbers = [1,2,3,4,5]
square = lambda x: x * x
listOfLambdas = [lambda: square(i) for i in listOfNumbers]
</code></pre>
<p>This will create a list of lambda objects, however, when I run them:</p>
<pre>... | 16 | 2009-01-17T01:19:13Z | 452,653 | <p>I sometimes find that defining actual classes for function objects makes it easier to understand what's going on:</p>
<pre><code>>>> class square(object):
... def __init__(self, val):
... self.val = val
... def __call__(self):
... return self.val * self.val
...
>>> l = [1,2,3,4,5]
>... | 0 | 2009-01-17T01:46:37Z | [
"python",
"lambda",
"scope",
"closures",
"list-comprehension"
] |
How do I create a list of Python lambdas (in a list comprehension/for loop)? | 452,610 | <p>I want to create a list of lambda objects from a list of constants in Python; for instance:</p>
<pre><code>listOfNumbers = [1,2,3,4,5]
square = lambda x: x * x
listOfLambdas = [lambda: square(i) for i in listOfNumbers]
</code></pre>
<p>This will create a list of lambda objects, however, when I run them:</p>
<pre>... | 16 | 2009-01-17T01:19:13Z | 452,659 | <p>You have:</p>
<pre><code>listOfLambdas = [lambda: i*i for i in range(6)]
for f in listOfLambdas:
print f()
</code></pre>
<p>Output:</p>
<pre><code>25
25
25
25
25
25
</code></pre>
<p>You need currying! Aside from being delicious, use this default value "hack".</p>
<pre><code>listOfLambdas = [lambda i=i: i*... | 17 | 2009-01-17T01:51:59Z | [
"python",
"lambda",
"scope",
"closures",
"list-comprehension"
] |
How do I create a list of Python lambdas (in a list comprehension/for loop)? | 452,610 | <p>I want to create a list of lambda objects from a list of constants in Python; for instance:</p>
<pre><code>listOfNumbers = [1,2,3,4,5]
square = lambda x: x * x
listOfLambdas = [lambda: square(i) for i in listOfNumbers]
</code></pre>
<p>This will create a list of lambda objects, however, when I run them:</p>
<pre>... | 16 | 2009-01-17T01:19:13Z | 452,660 | <pre><code>listOfLambdas = [lambda i=i: square(i) for i in listOfNumbers]
</code></pre>
<p>Or</p>
<pre><code>listOfLambdas = map(lambda i: lambda: square(i), listOfNumbers)
</code></pre>
| 2 | 2009-01-17T01:52:49Z | [
"python",
"lambda",
"scope",
"closures",
"list-comprehension"
] |
How do I create a list of Python lambdas (in a list comprehension/for loop)? | 452,610 | <p>I want to create a list of lambda objects from a list of constants in Python; for instance:</p>
<pre><code>listOfNumbers = [1,2,3,4,5]
square = lambda x: x * x
listOfLambdas = [lambda: square(i) for i in listOfNumbers]
</code></pre>
<p>This will create a list of lambda objects, however, when I run them:</p>
<pre>... | 16 | 2009-01-17T01:19:13Z | 453,152 | <p>When function statements are executed they are bound to their (lexically) enclosing scope.</p>
<p>In your snippet, the lambdas are bound to the global scope, because <code>for</code> suites are not executed as an independently scoped unit in Python. At the end of the <code>for</code> loop, the <code>num</code> is b... | 3 | 2009-01-17T11:13:42Z | [
"python",
"lambda",
"scope",
"closures",
"list-comprehension"
] |
How do I create a list of Python lambdas (in a list comprehension/for loop)? | 452,610 | <p>I want to create a list of lambda objects from a list of constants in Python; for instance:</p>
<pre><code>listOfNumbers = [1,2,3,4,5]
square = lambda x: x * x
listOfLambdas = [lambda: square(i) for i in listOfNumbers]
</code></pre>
<p>This will create a list of lambda objects, however, when I run them:</p>
<pre>... | 16 | 2009-01-17T01:19:13Z | 23,686,541 | <p>Try to use () instead of []:</p>
<pre><code>listOfLambdas = (lambda: square(i) for i in listOfNumbers)
</code></pre>
<p>And you will get:</p>
<pre><code>1
4
9
16
25
</code></pre>
| 1 | 2014-05-15T18:58:02Z | [
"python",
"lambda",
"scope",
"closures",
"list-comprehension"
] |
How do I create a list of Python lambdas (in a list comprehension/for loop)? | 452,610 | <p>I want to create a list of lambda objects from a list of constants in Python; for instance:</p>
<pre><code>listOfNumbers = [1,2,3,4,5]
square = lambda x: x * x
listOfLambdas = [lambda: square(i) for i in listOfNumbers]
</code></pre>
<p>This will create a list of lambda objects, however, when I run them:</p>
<pre>... | 16 | 2009-01-17T01:19:13Z | 31,397,531 | <p>You could also do:</p>
<pre><code>>>> def squares():
... for i in [1,2,3,4,5]:
... yield lambda:i*i
...
>>> print [square() for square in squares()]
[1, 4, 9, 16, 25]
</code></pre>
| 0 | 2015-07-14T04:15:05Z | [
"python",
"lambda",
"scope",
"closures",
"list-comprehension"
] |
What is the best way to handle a bad link given to BeautifulSoup? | 452,884 | <p>I'm working on something that pulls in urls from delicious and then uses those urls to discover associated feeds. </p>
<p>However, some of the bookmarks in delicious are not html links and cause BS to barf. Basically, I want to throw away a link if BS fetches it and it does not look like html.</p>
<p>Right now, th... | 1 | 2009-01-17T06:10:41Z | 452,896 | <p>I simply wrap my BeautifulSoup processing and look for the <code>HTMLParser.HTMLParseError</code> exception</p>
<pre><code>import HTMLParser,BeautifulSoup
try:
soup = BeautifulSoup.BeautifulSoup(raw_html)
for a in soup.findAll('a'):
href = a.['href']
....
except HTMLParser.HTMLParseError:
... | 3 | 2009-01-17T06:20:54Z | [
"python",
"parsing",
"beautifulsoup"
] |
Does python have an equivalent to Java Class.forName()? | 452,969 | <p>I have the need to take a string argument and create an object of the class named in that string in Python. In Java, I would use <code>Class.forName().newInstance()</code>. Is there an equivalent in Python?</p>
<hr>
<p>Thanks for the responses. To answer those who want to know what I'm doing: I want to use a co... | 76 | 2009-01-17T08:10:48Z | 452,971 | <p>Assuming the class is in your scope:</p>
<pre><code>globals()['classname'](args, to, constructor)
</code></pre>
<p>Otherwise:</p>
<pre><code>getattr(someModule, 'classname')(args, to, constructor)
</code></pre>
<p>Edit: Note, you can't give a name like 'foo.bar' to getattr. You'll need to split it by . and cal... | 20 | 2009-01-17T08:13:05Z | [
"java",
"python",
"class",
"instantiation"
] |
Does python have an equivalent to Java Class.forName()? | 452,969 | <p>I have the need to take a string argument and create an object of the class named in that string in Python. In Java, I would use <code>Class.forName().newInstance()</code>. Is there an equivalent in Python?</p>
<hr>
<p>Thanks for the responses. To answer those who want to know what I'm doing: I want to use a co... | 76 | 2009-01-17T08:10:48Z | 452,981 | <p>Reflection in python is a lot easier and far more flexible than it is in Java.</p>
<p>I recommend reading this <a href="http://www.diveintopython.net/power_of_introspection/index.html">tutorial</a></p>
<p>There's no direct function (that I know of) which takes a fully qualified class name and returns the class, ho... | 135 | 2009-01-17T08:25:39Z | [
"java",
"python",
"class",
"instantiation"
] |
Does python have an equivalent to Java Class.forName()? | 452,969 | <p>I have the need to take a string argument and create an object of the class named in that string in Python. In Java, I would use <code>Class.forName().newInstance()</code>. Is there an equivalent in Python?</p>
<hr>
<p>Thanks for the responses. To answer those who want to know what I'm doing: I want to use a co... | 76 | 2009-01-17T08:10:48Z | 453,459 | <p>It seems you're approaching this from the middle instead of the beginning. What are you really trying to do? Finding the class associated with a given string is a means to an end.</p>
<p>If you clarify your problem, which might require your own mental refactoring, a better solution may present itself.</p>
<p>For i... | 3 | 2009-01-17T15:37:40Z | [
"java",
"python",
"class",
"instantiation"
] |
Does python have an equivalent to Java Class.forName()? | 452,969 | <p>I have the need to take a string argument and create an object of the class named in that string in Python. In Java, I would use <code>Class.forName().newInstance()</code>. Is there an equivalent in Python?</p>
<hr>
<p>Thanks for the responses. To answer those who want to know what I'm doing: I want to use a co... | 76 | 2009-01-17T08:10:48Z | 3,610,097 | <p>Yet another implementation.</p>
<pre><code>def import_class(class_string):
"""Returns class object specified by a string.
Args:
class_string: The string representing a class.
Raises:
ValueError if module part of the class is not specified.
"""
module_name, _, class_name = class... | 4 | 2010-08-31T14:41:58Z | [
"java",
"python",
"class",
"instantiation"
] |
Does python have an equivalent to Java Class.forName()? | 452,969 | <p>I have the need to take a string argument and create an object of the class named in that string in Python. In Java, I would use <code>Class.forName().newInstance()</code>. Is there an equivalent in Python?</p>
<hr>
<p>Thanks for the responses. To answer those who want to know what I'm doing: I want to use a co... | 76 | 2009-01-17T08:10:48Z | 20,507,847 | <p>This is found in the python standard library, as unittest.TestLoader.loadTestsFromName. Unfortunately the method goes on to do additional test-related activities, but this first ha looks re-usable. I've edited it to remove the test-related functionality:</p>
<pre><code>def get_object(name):
"""Retrieve a python... | 1 | 2013-12-10T23:54:55Z | [
"java",
"python",
"class",
"instantiation"
] |
Does python have an equivalent to Java Class.forName()? | 452,969 | <p>I have the need to take a string argument and create an object of the class named in that string in Python. In Java, I would use <code>Class.forName().newInstance()</code>. Is there an equivalent in Python?</p>
<hr>
<p>Thanks for the responses. To answer those who want to know what I'm doing: I want to use a co... | 76 | 2009-01-17T08:10:48Z | 30,042,585 | <pre><code>def import_class_from_string(path):
from importlib import import_module
module_path, _, class_name = path.rpartition('.')
mod = import_module(module_path)
klass = getattr(mod, class_name)
return klass
</code></pre>
<h2>Usage</h2>
<pre><code>In [59]: raise import_class_from_string('googl... | 2 | 2015-05-05T01:00:38Z | [
"java",
"python",
"class",
"instantiation"
] |
What is the practical difference between xml, json, rss and atom when interfacing with Twitter? | 453,158 | <p>I'm new to web services and as an introduction I'm playing around with the Twitter API using the Twisted framework in python. I've read up on the different formats they offer, but it's still not clear to me which one I should use in my fairly simple project.
Specifically the practical difference between using JSON o... | 5 | 2009-01-17T11:19:36Z | 453,160 | <p>RSS and Atom are XML formats.</p>
<p>JSON is a string which can be evaluated as Javascript code.</p>
| 4 | 2009-01-17T11:21:38Z | [
"python",
"xml",
"json",
"twitter",
"twisted"
] |
What is the practical difference between xml, json, rss and atom when interfacing with Twitter? | 453,158 | <p>I'm new to web services and as an introduction I'm playing around with the Twitter API using the Twisted framework in python. I've read up on the different formats they offer, but it's still not clear to me which one I should use in my fairly simple project.
Specifically the practical difference between using JSON o... | 5 | 2009-01-17T11:19:36Z | 453,164 | <p>I would say the amount of data being sent over the wire is one factor. XML datastream will be bigger than JSON for the same data. But you can use whatever you know more/have more experiance.
I would reccoment JSON, as it's more "pythonic" than XML.</p>
| 1 | 2009-01-17T11:24:46Z | [
"python",
"xml",
"json",
"twitter",
"twisted"
] |
What is the practical difference between xml, json, rss and atom when interfacing with Twitter? | 453,158 | <p>I'm new to web services and as an introduction I'm playing around with the Twitter API using the Twisted framework in python. I've read up on the different formats they offer, but it's still not clear to me which one I should use in my fairly simple project.
Specifically the practical difference between using JSON o... | 5 | 2009-01-17T11:19:36Z | 453,389 | <p>For me it boils down to convenience. Using XML, I have to parse the response in to a DOM (or more usually an ElementTree). Using JSON, one call to simplejson.loads(json_string) and I have a native Python data structure (lists, dictionaries, strings etc) which I can start iterating over and processing. Anything that ... | 7 | 2009-01-17T14:45:23Z | [
"python",
"xml",
"json",
"twitter",
"twisted"
] |
Advice regarding IPython + MacVim Workflow | 453,329 | <p>I've just found <a href="http://ipython.scipy.org/">IPython</a> and I can report that I'm in deep love. And the affection was immediate. I think this affair will turn into something lasting, like <a href="http://stackoverflow.com/questions/431521/run-a-command-in-a-shell-and-keep-running-the-command-when-you-close-t... | 18 | 2009-01-17T13:46:27Z | 453,378 | <p>In the ipythonrc.ini file in you home directory change the editor to MacVim.</p>
| 1 | 2009-01-17T14:38:20Z | [
"python",
"vim",
"ipython"
] |
Advice regarding IPython + MacVim Workflow | 453,329 | <p>I've just found <a href="http://ipython.scipy.org/">IPython</a> and I can report that I'm in deep love. And the affection was immediate. I think this affair will turn into something lasting, like <a href="http://stackoverflow.com/questions/431521/run-a-command-in-a-shell-and-keep-running-the-command-when-you-close-t... | 18 | 2009-01-17T13:46:27Z | 453,837 | <p>I use Linux, but I believe this tip can be used in OS X too. I use <a href="http://www.gnu.org/software/screen/">GNU Screen</a> to send IPython commands from Vim as recommended by <a href="http://vim.wikia.com/wiki/IPython_integration">this tip</a>. This is how I do it:</p>
<p>First, you should open a terminal and ... | 14 | 2009-01-17T19:13:43Z | [
"python",
"vim",
"ipython"
] |
Advice regarding IPython + MacVim Workflow | 453,329 | <p>I've just found <a href="http://ipython.scipy.org/">IPython</a> and I can report that I'm in deep love. And the affection was immediate. I think this affair will turn into something lasting, like <a href="http://stackoverflow.com/questions/431521/run-a-command-in-a-shell-and-keep-running-the-command-when-you-close-t... | 18 | 2009-01-17T13:46:27Z | 478,897 | <p>I've had the same issue. After experimenting this is my solution: if you placed MacVim.app in /Applications and mvim is in your path, in ~/.ipython/ipythonrc change the line</p>
<pre><code>editor 0
</code></pre>
<p>to</p>
<pre><code>editor mvim --remote-tab-wait-silent
</code></pre>
<p>I think you need to keep ... | 1 | 2009-01-26T05:10:40Z | [
"python",
"vim",
"ipython"
] |
Advice regarding IPython + MacVim Workflow | 453,329 | <p>I've just found <a href="http://ipython.scipy.org/">IPython</a> and I can report that I'm in deep love. And the affection was immediate. I think this affair will turn into something lasting, like <a href="http://stackoverflow.com/questions/431521/run-a-command-in-a-shell-and-keep-running-the-command-when-you-close-t... | 18 | 2009-01-17T13:46:27Z | 8,077,462 | <p>This questions is stale now, but just for reference - if you're using IPython 0.11 with ZeroMQ enabled, take a look at <a href="https://github.com/ivanov/vim-ipython">vim-ipython</a> (an older version of which shipped with 0.11).</p>
<p>Using this plugin, you can send lines or whole files for IPython to execute, an... | 5 | 2011-11-10T09:35:52Z | [
"python",
"vim",
"ipython"
] |
Writing a simple "Rock Paper Scissors" game bot | 453,396 | <p>I need help with a python game im working on (I just started learning Python about 3 days ago, so I'm still a nOob =)</p>
<p>This is what I came up with:</p>
<pre><code>import random
from time import sleep
print "Please select: "
print "1 Rock"
print "2 Paper"
print "3 Scissors"
player = input ("Choose... | 7 | 2009-01-17T14:50:12Z | 453,400 | <p>Well, you've already imported the random module, that's a start.</p>
<p>Try the random.choice function.</p>
<pre><code>>>> from random import choice
>>> cpu_choice = choice(('rock', 'paper', 'scissors'))
</code></pre>
| 29 | 2009-01-17T14:53:03Z | [
"python"
] |
Writing a simple "Rock Paper Scissors" game bot | 453,396 | <p>I need help with a python game im working on (I just started learning Python about 3 days ago, so I'm still a nOob =)</p>
<p>This is what I came up with:</p>
<pre><code>import random
from time import sleep
print "Please select: "
print "1 Rock"
print "2 Paper"
print "3 Scissors"
player = input ("Choose... | 7 | 2009-01-17T14:50:12Z | 453,502 | <pre><code>import random
ROCK, PAPER, SCISSORS = 1, 2, 3
names = 'ROCK', 'PAPER', 'SCISSORS'
def beats(a, b):
if (a,b) in ((ROCK, PAPER), (PAPER, SCISSORS), (SCISSORS, ROCK)):
return False
return True
print "Please select: "
print "1 Rock"
print "2 Paper"
print "3 Scissors"
player = int(in... | 7 | 2009-01-17T16:05:47Z | [
"python"
] |
Writing a simple "Rock Paper Scissors" game bot | 453,396 | <p>I need help with a python game im working on (I just started learning Python about 3 days ago, so I'm still a nOob =)</p>
<p>This is what I came up with:</p>
<pre><code>import random
from time import sleep
print "Please select: "
print "1 Rock"
print "2 Paper"
print "3 Scissors"
player = input ("Choose... | 7 | 2009-01-17T14:50:12Z | 453,804 | <p>Inspired by gumuz:</p>
<pre><code>import random
WEAPONS = 'Rock', 'Paper', 'Scissors'
for i in range(0, 3):
print "%d %s" % (i + 1, WEAPONS[i])
player = int(input ("Choose from 1-3: ")) - 1
cpu = random.choice(range(0, 3))
print "%s vs %s" % (WEAPONS[player], WEAPONS[cpu])
if cpu != player:
if (player - cpu... | 4 | 2009-01-17T18:48:38Z | [
"python"
] |
Writing a simple "Rock Paper Scissors" game bot | 453,396 | <p>I need help with a python game im working on (I just started learning Python about 3 days ago, so I'm still a nOob =)</p>
<p>This is what I came up with:</p>
<pre><code>import random
from time import sleep
print "Please select: "
print "1 Rock"
print "2 Paper"
print "3 Scissors"
player = input ("Choose... | 7 | 2009-01-17T14:50:12Z | 7,410,938 | <p>use dictionaries</p>
<pre><code>loseDic = { 'rock' : 'paper',
'paper' : 'scissors',
'scissors' : 'rock',
}
## Get the human move, chose a random move, bla bla bla...
if robotMove == humanMove:
tie()
elif humanMove == loseDic[robotMove]:
lose()
else:
win()
</code></pre>
| 4 | 2011-09-14T03:28:11Z | [
"python"
] |
Writing a simple "Rock Paper Scissors" game bot | 453,396 | <p>I need help with a python game im working on (I just started learning Python about 3 days ago, so I'm still a nOob =)</p>
<p>This is what I came up with:</p>
<pre><code>import random
from time import sleep
print "Please select: "
print "1 Rock"
print "2 Paper"
print "3 Scissors"
player = input ("Choose... | 7 | 2009-01-17T14:50:12Z | 9,917,204 | <p>Not an expert, but here is what I have thus far, using a <code>__name__ == '__main__'</code> statement may be helpful if you need the computer to generate an answer and keep it clean and concise.</p>
<p>No solution given.</p>
<pre><code>import random
def is_tie(move1, move2):
'''FIX! (parameter types) -> retu... | 1 | 2012-03-28T23:39:33Z | [
"python"
] |
Queryset API distinct() does not work? | 453,477 | <pre><code>class Message(models.Model):
subject = models.CharField(max_length=100)
pub_date = models.DateTimeField(default=datetime.now())
class Topic(models.Model):
title = models.CharField(max_length=100)
message = models.ManyToManyField(Message, verbose_name='Discussion')
</code></pre>
<p>I want to... | 5 | 2009-01-17T15:49:11Z | 460,702 | <p>You'll find the explanation in the <a href="http://docs.djangoproject.com/en/dev/ref/models/querysets/#distinct" rel="nofollow">documentation for <code>.distinct()</code></a>.</p>
<p>I would de-normalize by adding a <code>modified_date</code> field to the <code>Topic</code> model and updating it whenever a Message ... | 3 | 2009-01-20T10:14:16Z | [
"python",
"django"
] |
Queryset API distinct() does not work? | 453,477 | <pre><code>class Message(models.Model):
subject = models.CharField(max_length=100)
pub_date = models.DateTimeField(default=datetime.now())
class Topic(models.Model):
title = models.CharField(max_length=100)
message = models.ManyToManyField(Message, verbose_name='Discussion')
</code></pre>
<p>I want to... | 5 | 2009-01-17T15:49:11Z | 476,232 | <p>You don't need distinct() here, what you need is <a href="http://docs.djangoproject.com/en/dev/topics/db/aggregation/#topics-db-aggregation">aggregation</a>. This query will do what you want:</p>
<pre><code>from django.db.models import Max
Topic.objects.annotate(Max('message__pub_date')).order_by('-message__pub_da... | 7 | 2009-01-24T16:16:07Z | [
"python",
"django"
] |
Is there a fast way to generate a dict of the alphabet in Python? | 453,576 | <p>I want to generate a dict with the letters of the alphabet as the keys, something like </p>
<pre><code>letter_count = {'a': 0, 'b': 0, 'c': 0}
</code></pre>
<p>what would be a fast way of generating that dict, rather than me having to type it in?</p>
<p>Thanks for your help.</p>
<p><b>EDIT</b><br>
Thanks everyon... | 24 | 2009-01-17T16:51:34Z | 453,592 | <p>There's this too:</p>
<pre><code>import string
letter_count = dict((letter, 0) for letter in string.ascii_lowercase)
</code></pre>
| 3 | 2009-01-17T16:59:54Z | [
"python",
"dictionary",
"alphabet"
] |
Is there a fast way to generate a dict of the alphabet in Python? | 453,576 | <p>I want to generate a dict with the letters of the alphabet as the keys, something like </p>
<pre><code>letter_count = {'a': 0, 'b': 0, 'c': 0}
</code></pre>
<p>what would be a fast way of generating that dict, rather than me having to type it in?</p>
<p>Thanks for your help.</p>
<p><b>EDIT</b><br>
Thanks everyon... | 24 | 2009-01-17T16:51:34Z | 453,596 | <p>Here's a compact version, using a <a href="http://docs.python.org/tutorial/datastructures.html#list-comprehensions" rel="nofollow">list comprehension</a>:</p>
<pre><code>>>> import string
>>> letter_count = dict( (key, 0) for key in string.ascii_lowercase )
>>> letter_count
{'a': 0, 'c': ... | 7 | 2009-01-17T17:01:01Z | [
"python",
"dictionary",
"alphabet"
] |
Is there a fast way to generate a dict of the alphabet in Python? | 453,576 | <p>I want to generate a dict with the letters of the alphabet as the keys, something like </p>
<pre><code>letter_count = {'a': 0, 'b': 0, 'c': 0}
</code></pre>
<p>what would be a fast way of generating that dict, rather than me having to type it in?</p>
<p>Thanks for your help.</p>
<p><b>EDIT</b><br>
Thanks everyon... | 24 | 2009-01-17T16:51:34Z | 453,603 | <pre><code>import string
letter_count = dict(zip(string.ascii_lowercase, [0]*26))
</code></pre>
<p>or maybe:</p>
<pre><code>import string
import itertools
letter_count = dict(zip(string.lowercase, itertools.repeat(0)))
</code></pre>
<p>or even:</p>
<pre><code>import string
letter_count = dict.fromkeys(string.ascii_... | 10 | 2009-01-17T17:03:27Z | [
"python",
"dictionary",
"alphabet"
] |
Is there a fast way to generate a dict of the alphabet in Python? | 453,576 | <p>I want to generate a dict with the letters of the alphabet as the keys, something like </p>
<pre><code>letter_count = {'a': 0, 'b': 0, 'c': 0}
</code></pre>
<p>what would be a fast way of generating that dict, rather than me having to type it in?</p>
<p>Thanks for your help.</p>
<p><b>EDIT</b><br>
Thanks everyon... | 24 | 2009-01-17T16:51:34Z | 453,605 | <pre><code>import string
letters = string.ascii_lowercase
d = dict(zip(letters, [0]*len(letters))
</code></pre>
| 2 | 2009-01-17T17:05:46Z | [
"python",
"dictionary",
"alphabet"
] |
Is there a fast way to generate a dict of the alphabet in Python? | 453,576 | <p>I want to generate a dict with the letters of the alphabet as the keys, something like </p>
<pre><code>letter_count = {'a': 0, 'b': 0, 'c': 0}
</code></pre>
<p>what would be a fast way of generating that dict, rather than me having to type it in?</p>
<p>Thanks for your help.</p>
<p><b>EDIT</b><br>
Thanks everyon... | 24 | 2009-01-17T16:51:34Z | 453,761 | <p>Yet another 1-liner Python hack:</p>
<pre><code>letter_count = dict([(chr(i),0) for i in range(97,123)])
</code></pre>
| 4 | 2009-01-17T18:17:54Z | [
"python",
"dictionary",
"alphabet"
] |
Is there a fast way to generate a dict of the alphabet in Python? | 453,576 | <p>I want to generate a dict with the letters of the alphabet as the keys, something like </p>
<pre><code>letter_count = {'a': 0, 'b': 0, 'c': 0}
</code></pre>
<p>what would be a fast way of generating that dict, rather than me having to type it in?</p>
<p>Thanks for your help.</p>
<p><b>EDIT</b><br>
Thanks everyon... | 24 | 2009-01-17T16:51:34Z | 453,766 | <p>If you plan to use it for counting, I suggest the following:</p>
<pre><code>import collections
d = collections.defaultdict(int)
</code></pre>
| 8 | 2009-01-17T18:19:27Z | [
"python",
"dictionary",
"alphabet"
] |
Is there a fast way to generate a dict of the alphabet in Python? | 453,576 | <p>I want to generate a dict with the letters of the alphabet as the keys, something like </p>
<pre><code>letter_count = {'a': 0, 'b': 0, 'c': 0}
</code></pre>
<p>what would be a fast way of generating that dict, rather than me having to type it in?</p>
<p>Thanks for your help.</p>
<p><b>EDIT</b><br>
Thanks everyon... | 24 | 2009-01-17T16:51:34Z | 453,785 | <p>I find this solution more elegant:</p>
<pre><code>import string
d = dict.fromkeys(string.ascii_lowercase, 0)
</code></pre>
| 43 | 2009-01-17T18:36:15Z | [
"python",
"dictionary",
"alphabet"
] |
Is there a Python news site that's the near equivalent of RubyFlow? | 453,673 | <p>I really like the format and type of links from <a href="http://rubyflow.com">RubyFlow</a> for Ruby related topics. Is there an equivalent for Python that's active? There is a <a href="http://pythonflow.com">PythonFlow</a>, but I think it's pretty much dead.</p>
<p>I don't really like <a href="http://planet.python.... | 5 | 2009-01-17T17:41:14Z | 453,680 | <p>Possibly <a href="http://www.planetpython.org/" rel="nofollow">http://www.planetpython.org/</a> or <a href="http://planet.python.org/" rel="nofollow">http://planet.python.org/</a>.</p>
| 1 | 2009-01-17T17:44:13Z | [
"python",
"news"
] |
Is there a Python news site that's the near equivalent of RubyFlow? | 453,673 | <p>I really like the format and type of links from <a href="http://rubyflow.com">RubyFlow</a> for Ruby related topics. Is there an equivalent for Python that's active? There is a <a href="http://pythonflow.com">PythonFlow</a>, but I think it's pretty much dead.</p>
<p>I don't really like <a href="http://planet.python.... | 5 | 2009-01-17T17:41:14Z | 453,704 | <p><a href="http://www.reddit.com/r/Python">http://www.reddit.com/r/Python</a> is my favorite source for Python news.</p>
| 5 | 2009-01-17T17:54:20Z | [
"python",
"news"
] |
Is there a Python news site that's the near equivalent of RubyFlow? | 453,673 | <p>I really like the format and type of links from <a href="http://rubyflow.com">RubyFlow</a> for Ruby related topics. Is there an equivalent for Python that's active? There is a <a href="http://pythonflow.com">PythonFlow</a>, but I think it's pretty much dead.</p>
<p>I don't really like <a href="http://planet.python.... | 5 | 2009-01-17T17:41:14Z | 453,705 | <p><a href="http://planetpython.org/" rel="nofollow">http://planetpython.org/</a> (the unofficial planet) is generally better than <a href="http://planet.python.org/" rel="nofollow">http://planet.python.org/</a> (the official one) - I think the maintainers of the unofficial one are a bit more active in trimming feeds a... | 1 | 2009-01-17T17:54:29Z | [
"python",
"news"
] |
PYTHONSTARTUP doesn't seem to work | 453,808 | <p>I'm trying to use the PYTHONSTARTUP environmental variable. I set it to be "c:\python25\pythonstartup.py" in My Computer --> Advanced etc., and it doesn't seem to work.</p>
<p>Opening IDLE doesn't run the script, although it recognized the variable:</p>
<pre><code>>>> import os
>>> os.environ['PY... | 5 | 2009-01-17T18:51:06Z | 453,819 | <p><a href="http://docs.python.org/using/cmdline.html">The documentation</a> says that PYTHONSTARTUP is only run for interactive sessions. I'm not sure how IDLE runs the Python interpreter, but it could be interfering.</p>
<p>Instead, try running <code>python</code> directly from a command prompt, rather than from cli... | 5 | 2009-01-17T18:56:11Z | [
"python",
"startup"
] |
PYTHONSTARTUP doesn't seem to work | 453,808 | <p>I'm trying to use the PYTHONSTARTUP environmental variable. I set it to be "c:\python25\pythonstartup.py" in My Computer --> Advanced etc., and it doesn't seem to work.</p>
<p>Opening IDLE doesn't run the script, although it recognized the variable:</p>
<pre><code>>>> import os
>>> os.environ['PY... | 5 | 2009-01-17T18:51:06Z | 454,217 | <p>To add to Greg Hewgill's correct answer: If IDLE doesn't have a startup file of its own, you can put a file called <a href="http://docs.python.org/dev/library/site.html" rel="nofollow"><code>sitecustomize.py</code></a> in your path which will be executed for both command prompt and scripts / IDLE sessions.</p>
| 2 | 2009-01-17T22:39:05Z | [
"python",
"startup"
] |
Invoke Python modules from Java | 454,182 | <p>I have a Python interface of a graph library written in C - igraph (the name of library). My need is to invoke the python modules pertaining to this graph library from Java code. It goes like this, the core of library is in c. This core has been imported into Python and interfaces to the functions embedded in core a... | 4 | 2009-01-17T22:22:30Z | 454,211 | <p>Never tried it. But I recently <a href="http://www.miketec.org/serendipity/index.php?/archives/9-Sure,-Change-Jobs!.html" rel="nofollow">stumbled</a> on a <a href="http://jepp.sourceforge.net/" rel="nofollow">project named Jepp</a> that may be of interest to you.</p>
<blockquote>
<p>Jepp embeds CPython in Java. I... | 3 | 2009-01-17T22:36:17Z | [
"java",
"python",
"ipc"
] |
Invoke Python modules from Java | 454,182 | <p>I have a Python interface of a graph library written in C - igraph (the name of library). My need is to invoke the python modules pertaining to this graph library from Java code. It goes like this, the core of library is in c. This core has been imported into Python and interfaces to the functions embedded in core a... | 4 | 2009-01-17T22:22:30Z | 2,512,480 | <p>If you want to call C functions from Java, <a href="https://github.com/twall/jna/" rel="nofollow">JNA</a> (Java Native Access) is probably the way to go. JNA allows you to call functions in native libraries without having to write the C glue code (as you would have to when using JNI), and automatically maps between ... | 2 | 2010-03-25T00:54:15Z | [
"java",
"python",
"ipc"
] |
Invoke Python modules from Java | 454,182 | <p>I have a Python interface of a graph library written in C - igraph (the name of library). My need is to invoke the python modules pertaining to this graph library from Java code. It goes like this, the core of library is in c. This core has been imported into Python and interfaces to the functions embedded in core a... | 4 | 2009-01-17T22:22:30Z | 12,167,871 | <p>You can use jep.getValue() to retrieve a value from script's global dictionary.</p>
<p>There are caveats to that concerning scope levels in Python, so most people find it clearer to pass a Java class to python and set the return value in that instance in Python. After the script completes, the Java code will then h... | 0 | 2012-08-28T21:37:21Z | [
"java",
"python",
"ipc"
] |
How to create a controller method in Turbogears that can be called from within the controller, or rendered with a template | 454,223 | <p>If you have a controller method like so:</p>
<pre><code>@expose("json")
def artists(self, action="view",artist_id=None):
artists=session.query(model.Artist).all()
return dict(artists=artists)
</code></pre>
<p>How can you call that method from within your controller class, and get the python dict back - rat... | 1 | 2009-01-17T22:43:53Z | 454,380 | <p>I normally approach this by having a 'worker' method, which queries the database, transforms results, etc., and a separate exposing method, with all the required decorators. E.g.:</p>
<pre><code># The _artists method can be used from any other method
def _artists(self, action, artist_id):
artists = session.quer... | 1 | 2009-01-18T00:28:06Z | [
"python",
"json",
"turbogears"
] |
How do cursors work in Python's DB-API? | 454,337 | <p>I have been using python with RDBMS' (MySQL and PostgreSQL), and I have noticed that I really do not understand how to use a cursor.</p>
<p>Usually, one have his script connect to the DB via a client DB-API (like psycopg2 or MySQLdb):</p>
<pre><code>connection = psycopg2.connect(host='otherhost', etc)
</code></pre... | 13 | 2009-01-17T23:58:21Z | 454,350 | <p>Assuming you're using PostgreSQL, the cursors probably are just implemented using the database's native cursor API. You may want to look at the source code for <a href="http://pybrary.net/pg8000/" rel="nofollow">pg8000</a>, a pure Python PostgreSQL DB-API module, to see how it handles cursors. You might also like to... | 1 | 2009-01-18T00:09:48Z | [
"python",
"performance",
"rdbms",
"cursors",
"psycopg2"
] |
How do cursors work in Python's DB-API? | 454,337 | <p>I have been using python with RDBMS' (MySQL and PostgreSQL), and I have noticed that I really do not understand how to use a cursor.</p>
<p>Usually, one have his script connect to the DB via a client DB-API (like psycopg2 or MySQLdb):</p>
<pre><code>connection = psycopg2.connect(host='otherhost', etc)
</code></pre... | 13 | 2009-01-17T23:58:21Z | 454,825 | <p>When you look here at the <a href="http://mysql-python.sourceforge.net/MySQLdb.html#cursor-objects" rel="nofollow">mysqldb documentation</a> you can see that they implemented different strategies for cursors. So the general answer is: it depends.</p>
<p>Edit: Here is the <a href="http://mysql-python.sourceforge.net... | 1 | 2009-01-18T08:38:08Z | [
"python",
"performance",
"rdbms",
"cursors",
"psycopg2"
] |
How do cursors work in Python's DB-API? | 454,337 | <p>I have been using python with RDBMS' (MySQL and PostgreSQL), and I have noticed that I really do not understand how to use a cursor.</p>
<p>Usually, one have his script connect to the DB via a client DB-API (like psycopg2 or MySQLdb):</p>
<pre><code>connection = psycopg2.connect(host='otherhost', etc)
</code></pre... | 13 | 2009-01-17T23:58:21Z | 967,713 | <p>ya, i know it's months old :P</p>
<p>DB-API's cursor appears to be closely modeled after SQL cursors. AFA resource(rows) management is concerned, <em>DB-API does not specify whether the client must retrieve all the rows or DECLARE an actual SQL cursor</em>. As long as the fetchXXX interfaces do what they're suppose... | 3 | 2009-06-09T00:57:50Z | [
"python",
"performance",
"rdbms",
"cursors",
"psycopg2"
] |
Does Django development provide a truly flexible 3 layer architecture? | 454,443 | <p>A few weeks ago I asked the question <em>"Is a PHP, Python, PostgreSQL design suitable for a non-web business application?"</em> <a href="http://stackoverflow.com/questions/439759/is-a-php-python-postgresql-design-suitable-for-a-business-application">http://stackoverflow.com/questions/439759/is-a-php-python-postgres... | 3 | 2009-01-18T01:20:33Z | 454,458 | <p>You've effectively got a 3 layer architecture whether you use Django's ORM or SQLAlchemy, though your forgo some of the Django's benefits if you choose the latter.</p>
| 3 | 2009-01-18T01:29:36Z | [
"python",
"django",
"model-view-controller",
"orm"
] |
Does Django development provide a truly flexible 3 layer architecture? | 454,443 | <p>A few weeks ago I asked the question <em>"Is a PHP, Python, PostgreSQL design suitable for a non-web business application?"</em> <a href="http://stackoverflow.com/questions/439759/is-a-php-python-postgresql-design-suitable-for-a-business-application">http://stackoverflow.com/questions/439759/is-a-php-python-postgres... | 3 | 2009-01-18T01:20:33Z | 454,539 | <p>You seem to be saying that choosing Django would prevent you from using a more heterogenous solution later. This isn't the case. Django provides a number of interesting connections between the layers, and using Django for all the layers lets you take advantage of those connections. For example, using the Django O... | 9 | 2009-01-18T02:41:38Z | [
"python",
"django",
"model-view-controller",
"orm"
] |
Does Django development provide a truly flexible 3 layer architecture? | 454,443 | <p>A few weeks ago I asked the question <em>"Is a PHP, Python, PostgreSQL design suitable for a non-web business application?"</em> <a href="http://stackoverflow.com/questions/439759/is-a-php-python-postgresql-design-suitable-for-a-business-application">http://stackoverflow.com/questions/439759/is-a-php-python-postgres... | 3 | 2009-01-18T01:20:33Z | 454,551 | <blockquote>
<p>Based on my understanding, Django would manage both the view and controller pieces and PostgreSQL or MySQL would handle the data.</p>
</blockquote>
<p>Not really, Django has its own ORM, so it does separate data from view/controller.</p>
<p>here's an <a href="http://docs.djangoproject.com/en/dev/faq... | 3 | 2009-01-18T02:52:58Z | [
"python",
"django",
"model-view-controller",
"orm"
] |
Does Django development provide a truly flexible 3 layer architecture? | 454,443 | <p>A few weeks ago I asked the question <em>"Is a PHP, Python, PostgreSQL design suitable for a non-web business application?"</em> <a href="http://stackoverflow.com/questions/439759/is-a-php-python-postgresql-design-suitable-for-a-business-application">http://stackoverflow.com/questions/439759/is-a-php-python-postgres... | 3 | 2009-01-18T01:20:33Z | 454,608 | <p>Django will happily let you use whatever libraries you want for whatever you want to use them for -- you want a different ORM, use it, you want a different template engine, use it, and so on -- but is designed to provide a common default stack used by many interoperable applications. In other words, if you swap out ... | 7 | 2009-01-18T03:48:18Z | [
"python",
"django",
"model-view-controller",
"orm"
] |
Does Django development provide a truly flexible 3 layer architecture? | 454,443 | <p>A few weeks ago I asked the question <em>"Is a PHP, Python, PostgreSQL design suitable for a non-web business application?"</em> <a href="http://stackoverflow.com/questions/439759/is-a-php-python-postgresql-design-suitable-for-a-business-application">http://stackoverflow.com/questions/439759/is-a-php-python-postgres... | 3 | 2009-01-18T01:20:33Z | 455,086 | <p>There's change and there's change. Django utterly seperates domain model, business rules and presentation. You can change (almost) anything with near zero breakage. And by change I am talking about meaningful end-user focused business change.</p>
<p>The technology mix-n-match in this (and the previous) question is... | -1 | 2009-01-18T12:58:43Z | [
"python",
"django",
"model-view-controller",
"orm"
] |
Does Django development provide a truly flexible 3 layer architecture? | 454,443 | <p>A few weeks ago I asked the question <em>"Is a PHP, Python, PostgreSQL design suitable for a non-web business application?"</em> <a href="http://stackoverflow.com/questions/439759/is-a-php-python-postgresql-design-suitable-for-a-business-application">http://stackoverflow.com/questions/439759/is-a-php-python-postgres... | 3 | 2009-01-18T01:20:33Z | 456,085 | <p>You seem to be confusing "separate layers" with "separate languages/technologies." There is no reason you can't separate your concerns appropriately within a single programming language, or within an appropriately modular framework (such as Django). Needlessly multiplying programming languages / frameworks is just... | 4 | 2009-01-18T23:06:07Z | [
"python",
"django",
"model-view-controller",
"orm"
] |
How do I re.search or re.match on a whole file without reading it all into memory? | 454,456 | <p>I want to be able to run a regular expression on an entire file, but I'd like to be able to not have to read the whole file into memory at once as I may be working with rather large files in the future. Is there a way to do this? Thanks!</p>
<p><strong>Clarification:</strong> I cannot read line-by-line because it c... | 19 | 2009-01-18T01:27:16Z | 454,468 | <p>This depends on the file and the regex. The best thing you could do would be to read the file in line by line but if that does not work for your situation then might get stuck with pulling the whole file into memory.</p>
<p>Lets say for example that this is your file:</p>
<pre><code>Lorem ipsum dolor sit amet, co... | 4 | 2009-01-18T01:42:26Z | [
"python",
"regex",
"performance",
"file"
] |
How do I re.search or re.match on a whole file without reading it all into memory? | 454,456 | <p>I want to be able to run a regular expression on an entire file, but I'd like to be able to not have to read the whole file into memory at once as I may be working with rather large files in the future. Is there a way to do this? Thanks!</p>
<p><strong>Clarification:</strong> I cannot read line-by-line because it c... | 19 | 2009-01-18T01:27:16Z | 454,471 | <p>For single line patterns you can iterate over the lines of the file, but for multi-line patterns, You will have to read all (or part, but that'll be hard to keep track of) of the file into memory.</p>
| 0 | 2009-01-18T01:44:49Z | [
"python",
"regex",
"performance",
"file"
] |
How do I re.search or re.match on a whole file without reading it all into memory? | 454,456 | <p>I want to be able to run a regular expression on an entire file, but I'd like to be able to not have to read the whole file into memory at once as I may be working with rather large files in the future. Is there a way to do this? Thanks!</p>
<p><strong>Clarification:</strong> I cannot read line-by-line because it c... | 19 | 2009-01-18T01:27:16Z | 454,474 | <p>Open the file and iterate over the lines.</p>
<pre><code>fd = open('myfile')
for line in fd:
if re.match(...,line)
print line
</code></pre>
| 0 | 2009-01-18T01:46:43Z | [
"python",
"regex",
"performance",
"file"
] |
How do I re.search or re.match on a whole file without reading it all into memory? | 454,456 | <p>I want to be able to run a regular expression on an entire file, but I'd like to be able to not have to read the whole file into memory at once as I may be working with rather large files in the future. Is there a way to do this? Thanks!</p>
<p><strong>Clarification:</strong> I cannot read line-by-line because it c... | 19 | 2009-01-18T01:27:16Z | 454,490 | <p>This is one way:</p>
<pre><code>import re
REGEX = '\d+'
with open('/tmp/workfile', 'r') as f:
for line in f:
print re.match(REGEX,line)
</code></pre>
<ol>
<li>with operator in python 2.5 takes of automatic file closure. Hence you need not worry about it.</li>
<li>iterator over the file object is ... | 0 | 2009-01-18T02:00:41Z | [
"python",
"regex",
"performance",
"file"
] |
How do I re.search or re.match on a whole file without reading it all into memory? | 454,456 | <p>I want to be able to run a regular expression on an entire file, but I'd like to be able to not have to read the whole file into memory at once as I may be working with rather large files in the future. Is there a way to do this? Thanks!</p>
<p><strong>Clarification:</strong> I cannot read line-by-line because it c... | 19 | 2009-01-18T01:27:16Z | 454,535 | <p>If this is a big deal and worth some effort, you can convert the regular expression into a finite state machine which reads the file. The FSM can be of O(n) complexity which means it will be a lot faster as the file size gets big.</p>
<p>You will be able to efficiently match patterns that span lines in files too ... | 1 | 2009-01-18T02:39:06Z | [
"python",
"regex",
"performance",
"file"
] |
How do I re.search or re.match on a whole file without reading it all into memory? | 454,456 | <p>I want to be able to run a regular expression on an entire file, but I'd like to be able to not have to read the whole file into memory at once as I may be working with rather large files in the future. Is there a way to do this? Thanks!</p>
<p><strong>Clarification:</strong> I cannot read line-by-line because it c... | 19 | 2009-01-18T01:27:16Z | 454,589 | <p>You can use mmap to map the file to memory. The file contents can then be accessed like a normal string:</p>
<pre><code>import re, mmap
with open('/var/log/error.log', 'r+') as f:
data = mmap.mmap(f.fileno(), 0)
mo = re.search('error: (.*)', data)
if mo:
print "found error", mo.group(1)
</code></pre>
<p... | 39 | 2009-01-18T03:24:46Z | [
"python",
"regex",
"performance",
"file"
] |
How do I re.search or re.match on a whole file without reading it all into memory? | 454,456 | <p>I want to be able to run a regular expression on an entire file, but I'd like to be able to not have to read the whole file into memory at once as I may be working with rather large files in the future. Is there a way to do this? Thanks!</p>
<p><strong>Clarification:</strong> I cannot read line-by-line because it c... | 19 | 2009-01-18T01:27:16Z | 28,010,463 | <pre><code>f = open(filename,'r')
for eachline in f:
string=re.search("(<tr align=\"right\"><td>)([0-9]*)(</td><td>)([a-zA-Z]*)(</td><td>)([a-zA-Z]*)(</td>)",eachline)
if string:
for i in range (2,8,2):
add = string.group(i)
l.append(add)
</code>... | 0 | 2015-01-18T13:56:39Z | [
"python",
"regex",
"performance",
"file"
] |
Find an Image within an Image | 454,498 | <p>I am looking for the best way to detect an image within another image. I have a small image and would like to find the location that it appears within a larger image - which will actually be screen captures. Conceptually, it is like a 'Where's Waldo?' sort of search in the larger image. </p>
<p>Are there any effi... | 4 | 2009-01-18T02:07:16Z | 454,505 | <p>You can treat this as a substring problem, where characters in the alphabet are pixels and your string is the image. You would need also to use a special character in a similar vein to a linebreak, to denote the image boundary.</p>
<p>The algorithm you want is on wikipedia: <a href="http://en.wikipedia.org/wiki/Knu... | 0 | 2009-01-18T02:11:56Z | [
"java",
"python",
"image"
] |
Find an Image within an Image | 454,498 | <p>I am looking for the best way to detect an image within another image. I have a small image and would like to find the location that it appears within a larger image - which will actually be screen captures. Conceptually, it is like a 'Where's Waldo?' sort of search in the larger image. </p>
<p>Are there any effi... | 4 | 2009-01-18T02:07:16Z | 454,536 | <p>Wikipedia has an article on <a href="http://en.wikipedia.org/wiki/Template_matching">Template Matching</a>, with sample code.</p>
<p>(While that page doesn't handle changed scales, it has links to other styles of matching, for example <a href="http://en.wikipedia.org/wiki/Scale-invariant_feature_transform">Scale in... | 7 | 2009-01-18T02:40:21Z | [
"java",
"python",
"image"
] |
Find an Image within an Image | 454,498 | <p>I am looking for the best way to detect an image within another image. I have a small image and would like to find the location that it appears within a larger image - which will actually be screen captures. Conceptually, it is like a 'Where's Waldo?' sort of search in the larger image. </p>
<p>Are there any effi... | 4 | 2009-01-18T02:07:16Z | 454,548 | <p>If rotation also had to be catered for, the <a href="http://homepages.inf.ed.ac.uk/rbf/HIPR2/hough.htm" rel="nofollow">Generalised Hough Transform</a> can be used.</p>
| 1 | 2009-01-18T02:50:12Z | [
"java",
"python",
"image"
] |
How can I make a list in Python like (0,6,12, .. 144)? | 454,566 | <p>I am not sure, whether I should use for -loop. Perhaps, like </p>
<pre><code>for i in range(145):
by 6: //mistake here?
print i
</code></pre>
| 3 | 2009-01-18T03:04:43Z | 454,569 | <p>I would prefer:</p>
<pre><code>for i in xrange(25): # from 0 to 24
print 6*i
</code></pre>
<p>You can easily build a list containing the same numbers with a similar construct named <em>list comprehension</em>:</p>
<pre><code>numbers = [6*i for i in xrange(25)]
print numbers
</code></pre>
<p>If you already... | 6 | 2009-01-18T03:06:20Z | [
"python",
"list"
] |
How can I make a list in Python like (0,6,12, .. 144)? | 454,566 | <p>I am not sure, whether I should use for -loop. Perhaps, like </p>
<pre><code>for i in range(145):
by 6: //mistake here?
print i
</code></pre>
| 3 | 2009-01-18T03:04:43Z | 454,578 | <pre><code>for i in range(0,150,6):
print i
</code></pre>
<p>if you are stepping by a constant</p>
| 20 | 2009-01-18T03:11:14Z | [
"python",
"list"
] |
How can I make a list in Python like (0,6,12, .. 144)? | 454,566 | <p>I am not sure, whether I should use for -loop. Perhaps, like </p>
<pre><code>for i in range(145):
by 6: //mistake here?
print i
</code></pre>
| 3 | 2009-01-18T03:04:43Z | 454,580 | <pre><code>i = 1
while i * 6 < 144:
i = i + 1
print i * 6
</code></pre>
<p>There are plenty of ways to do this</p>
| -5 | 2009-01-18T03:12:32Z | [
"python",
"list"
] |
How can I make a list in Python like (0,6,12, .. 144)? | 454,566 | <p>I am not sure, whether I should use for -loop. Perhaps, like </p>
<pre><code>for i in range(145):
by 6: //mistake here?
print i
</code></pre>
| 3 | 2009-01-18T03:04:43Z | 454,584 | <p>reqlist = [i for i in range(0,150,6)]</p>
| -2 | 2009-01-18T03:16:11Z | [
"python",
"list"
] |
Pythonic macro syntax | 454,648 | <p>I've been working on an alternative compiler front-end for Python where all syntax is parsed via macros. I'm finally to the point with its development that I can start work on a superset of the Python language where macros are an integral component.</p>
<p>My problem is that I can't come up with a pythonic macro d... | 18 | 2009-01-18T04:22:27Z | 460,594 | <p>This is the current mechanism for defining syntax by use of a standard Python class.</p>
<p>Print macro:</p>
<pre><code>class PrintMacro(Macro):
syntax = 'print', Var
def handle(self, stmts):
if not isinstance(stmts, list):
stmts = [stmts]
return Printnl(stmts, None)
</code></pre>
<p>If/elif/els... | 0 | 2009-01-20T09:37:13Z | [
"python",
"syntax",
"macros"
] |
Pythonic macro syntax | 454,648 | <p>I've been working on an alternative compiler front-end for Python where all syntax is parsed via macros. I'm finally to the point with its development that I can start work on a superset of the Python language where macros are an integral component.</p>
<p>My problem is that I can't come up with a pythonic macro d... | 18 | 2009-01-18T04:22:27Z | 460,598 | <p>This is the macro syntax I've come up with for my Python superset.</p>
<p>Print macro:</p>
<pre><code>macro PrintMacro:
syntax:
stmts = 'print', Var
if not isinstance(stmts, list):
stmts = [stmts]
return Printnl(stmts, None)
</code></pre>
<p>If macro:</p>
<pre><code>@MultiLine
macro IfMacro:
... | 0 | 2009-01-20T09:38:34Z | [
"python",
"syntax",
"macros"
] |
Pythonic macro syntax | 454,648 | <p>I've been working on an alternative compiler front-end for Python where all syntax is parsed via macros. I'm finally to the point with its development that I can start work on a superset of the Python language where macros are an integral component.</p>
<p>My problem is that I can't come up with a pythonic macro d... | 18 | 2009-01-18T04:22:27Z | 460,670 | <p>I'm posting a bit of floating ideas to see if it inspires.
I don't know much python, and I'm not using real python syntax, but it beats nothing :p</p>
<pre><code>macro PrintMacro:
syntax:
print $a
rules:
a: list(String), as vars
handle:
# do something with 'vars'
macro IfMacro... | 1 | 2009-01-20T10:05:14Z | [
"python",
"syntax",
"macros"
] |
Pythonic macro syntax | 454,648 | <p>I've been working on an alternative compiler front-end for Python where all syntax is parsed via macros. I'm finally to the point with its development that I can start work on a superset of the Python language where macros are an integral component.</p>
<p>My problem is that I can't come up with a pythonic macro d... | 18 | 2009-01-18T04:22:27Z | 460,728 | <p>This is a new macro syntax I've come up with based on Kent Fredric's ideas. It parses the syntax into a list just like the code is parsed.</p>
<p>Print macro:</p>
<pre><code>macro PrintMacro:
syntax:
print $stmts
if not isinstance(stmts, list):
stmts = [stmts]
return Printnl(stmts, None)
</code... | 1 | 2009-01-20T10:24:32Z | [
"python",
"syntax",
"macros"
] |
Pythonic macro syntax | 454,648 | <p>I've been working on an alternative compiler front-end for Python where all syntax is parsed via macros. I'm finally to the point with its development that I can start work on a superset of the Python language where macros are an integral component.</p>
<p>My problem is that I can't come up with a pythonic macro d... | 18 | 2009-01-18T04:22:27Z | 483,447 | <p>After thinking about it a while a few days ago, and coming up with nothing worth posting, I came back to it now and came up with some syntax I rather like, because it nearly looks like python:</p>
<pre><code>macro PrintMacro:
syntax:
"print", OneOrMore(Var(), name='vars')
return Printnl(vars, None)
</code>... | 10 | 2009-01-27T13:48:47Z | [
"python",
"syntax",
"macros"
] |
Pythonic macro syntax | 454,648 | <p>I've been working on an alternative compiler front-end for Python where all syntax is parsed via macros. I'm finally to the point with its development that I can start work on a superset of the Python language where macros are an integral component.</p>
<p>My problem is that I can't come up with a pythonic macro d... | 18 | 2009-01-18T04:22:27Z | 484,884 | <p>Incorporating <a href="http://en.wikipedia.org/wiki/Backus-Naur_form" rel="nofollow">BNF</a></p>
<pre><code>class IfMacro(Macro):
syntax: "if" expression ":" suite ("elif" expression ":" suite )* ["else" ":" suite]
def handle(self, if_, elifs, elseBody):
return If(
[(expression, Stmt(s... | 2 | 2009-01-27T19:33:49Z | [
"python",
"syntax",
"macros"
] |
Pythonic macro syntax | 454,648 | <p>I've been working on an alternative compiler front-end for Python where all syntax is parsed via macros. I'm finally to the point with its development that I can start work on a superset of the Python language where macros are an integral component.</p>
<p>My problem is that I can't come up with a pythonic macro d... | 18 | 2009-01-18T04:22:27Z | 494,478 | <p>If you're only asking about the syntax (not implementation) of macros within Python, then I believe the answer is obvious. The syntax should closely match what Python already has (i.e., the "<code>def</code>" keyword).</p>
<p>Whether you implement this as one of the following is up to you:</p>
<pre><code>def macro... | 1 | 2009-01-30T04:18:19Z | [
"python",
"syntax",
"macros"
] |
Pythonic macro syntax | 454,648 | <p>I've been working on an alternative compiler front-end for Python where all syntax is parsed via macros. I'm finally to the point with its development that I can start work on a superset of the Python language where macros are an integral component.</p>
<p>My problem is that I can't come up with a pythonic macro d... | 18 | 2009-01-18T04:22:27Z | 494,516 | <p>You might consider looking at how Boo (a .NET-based language with a syntax largely inspired by Python) implements macros, as described at <A HREF="http://boo.codehaus.org/Syntactic+Macros" rel="nofollow">http://boo.codehaus.org/Syntactic+Macros</A>.</p>
| 3 | 2009-01-30T04:55:21Z | [
"python",
"syntax",
"macros"
] |
Pythonic macro syntax | 454,648 | <p>I've been working on an alternative compiler front-end for Python where all syntax is parsed via macros. I'm finally to the point with its development that I can start work on a superset of the Python language where macros are an integral component.</p>
<p>My problem is that I can't come up with a pythonic macro d... | 18 | 2009-01-18T04:22:27Z | 764,479 | <p>You should take a look at <a href="https://code.google.com/p/metapython/" rel="nofollow">MetaPython</a> to see if it accomplishes what you're looking for.</p>
| 3 | 2009-04-18T23:30:26Z | [
"python",
"syntax",
"macros"
] |
Putting separate python packages into same namespace? | 454,691 | <p>I'm developing a python framework that would have "addons" written as separate packages. I.e.:</p>
<pre><code>import myframework
from myframework.addons import foo, bar
</code></pre>
<p>Now, what I'm trying to arrange is so that these addons can be distributed separately from core framework and injected into <code... | 12 | 2009-01-18T05:17:19Z | 455,033 | <p>It sounds like what you're after can be accomplished quite neatly with import hooks.</p>
<p>This is a way of writing custom loading code, which can be associated with a package (or in your case a framework), to perform the loading of all sub-packages and modules, rather than using python's default loading mechanism... | 0 | 2009-01-18T12:06:18Z | [
"python",
"namespaces",
"distribution",
"extend"
] |
Putting separate python packages into same namespace? | 454,691 | <p>I'm developing a python framework that would have "addons" written as separate packages. I.e.:</p>
<pre><code>import myframework
from myframework.addons import foo, bar
</code></pre>
<p>Now, what I'm trying to arrange is so that these addons can be distributed separately from core framework and injected into <code... | 12 | 2009-01-18T05:17:19Z | 455,267 | <blockquote>
<p>Is there a better way to accomplish this or perhaps a different approach to the above distribution problem altogether?</p>
</blockquote>
<p>Possibly. Python's module/package setup is generally tricky to tamper with dynamically like this, but its object/class system is open and extensible in a well-de... | 4 | 2009-01-18T15:01:30Z | [
"python",
"namespaces",
"distribution",
"extend"
] |
Putting separate python packages into same namespace? | 454,691 | <p>I'm developing a python framework that would have "addons" written as separate packages. I.e.:</p>
<pre><code>import myframework
from myframework.addons import foo, bar
</code></pre>
<p>Now, what I'm trying to arrange is so that these addons can be distributed separately from core framework and injected into <code... | 12 | 2009-01-18T05:17:19Z | 456,621 | <p>Setuptools has the ability to lookup package "entry points" (functions, objects, whatever) by name. Trac uses this mechanism to <a href="http://trac.edgewall.org/browser/trunk/trac/loader.py#L33" rel="nofollow">load its plugins</a>, and it works well.</p>
| 3 | 2009-01-19T05:35:28Z | [
"python",
"namespaces",
"distribution",
"extend"
] |
Putting separate python packages into same namespace? | 454,691 | <p>I'm developing a python framework that would have "addons" written as separate packages. I.e.:</p>
<pre><code>import myframework
from myframework.addons import foo, bar
</code></pre>
<p>Now, what I'm trying to arrange is so that these addons can be distributed separately from core framework and injected into <code... | 12 | 2009-01-18T05:17:19Z | 1,719,512 | <p>See namespace packages:</p>
<p><a href="http://www.python.org/dev/peps/pep-0382/">http://www.python.org/dev/peps/pep-0382/</a></p>
<p>or in setuptools:</p>
<p><a href="http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages">http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages</a></... | 6 | 2009-11-12T02:27:51Z | [
"python",
"namespaces",
"distribution",
"extend"
] |
Python get proper line ending | 454,725 | <p>Is there an easy way to get the type of line ending that the current operating system uses?</p>
| 38 | 2009-01-18T06:01:14Z | 454,731 | <p>Oh, I figured it out. Apparently, <a href="http://www.python.org/dev/peps/pep-0278/">PEP-278</a> states the following: </p>
<blockquote>
<p>Any line ending in the input file will be seen as a '\n' in Python, so little other code has to change to handle universal newlines.</p>
</blockquote>
| 13 | 2009-01-18T06:07:20Z | [
"python",
"line-endings"
] |
Python get proper line ending | 454,725 | <p>Is there an easy way to get the type of line ending that the current operating system uses?</p>
| 38 | 2009-01-18T06:01:14Z | 454,809 | <p>If you are operating on a file that you opened in text mode, then you are correct that line breaks all show up as '<code>\n</code>'. Otherwise, you are looking for <a href="http://docs.python.org/library/os.html"><code>os.linesep</code></a> .</p>
<p>From <a href="http://docs.python.org/library/os.html">http://docs.... | 61 | 2009-01-18T08:21:16Z | [
"python",
"line-endings"
] |
Python get proper line ending | 454,725 | <p>Is there an easy way to get the type of line ending that the current operating system uses?</p>
| 38 | 2009-01-18T06:01:14Z | 454,810 | <p>If specify test resp. binary properly when opening files, and use universal newlines, you shouldn't have to worry about different newlines most of the time.</p>
<p>But if you have to, use <a href="http://docs.python.org/library/os.html#os.linesep" rel="nofollow">os.linesep</a></p>
| 3 | 2009-01-18T08:21:36Z | [
"python",
"line-endings"
] |
No module named MySQLdb | 454,854 | <p>I am using Python version 2.5.4 and install MySQL version 5.0 and Django. Django is working fine with Python, but not MySQL. Can anyone help me to solve this issue? I am using it in Vista.</p>
| 211 | 2009-01-18T09:13:38Z | 454,871 | <p><code>mysqldb</code> is a module for Python that doesn't come pre-installed or with Django. You can download <code>mysqldb</code> <a href="http://sourceforge.net/projects/mysql-python">here</a>.</p>
| 39 | 2009-01-18T09:25:58Z | [
"python",
"django"
] |
No module named MySQLdb | 454,854 | <p>I am using Python version 2.5.4 and install MySQL version 5.0 and Django. Django is working fine with Python, but not MySQL. Can anyone help me to solve this issue? I am using it in Vista.</p>
| 211 | 2009-01-18T09:13:38Z | 455,041 | <p>If you are running on Vista, you may want to check out the <a href="http://bitnami.org/stack/djangostack" rel="nofollow">Bitnami Django stack.</a> It is an all-in-one stack of Apache, Python, MySQL, etc. packaged with <a href="http://bitrock.com" rel="nofollow">Bitrock</a> crossplatform installers to make it really ... | 2 | 2009-01-18T12:18:07Z | [
"python",
"django"
] |
No module named MySQLdb | 454,854 | <p>I am using Python version 2.5.4 and install MySQL version 5.0 and Django. Django is working fine with Python, but not MySQL. Can anyone help me to solve this issue? I am using it in Vista.</p>
| 211 | 2009-01-18T09:13:38Z | 5,873,259 | <p>You need to use one of the following commands. Which one depends on what OS and software you have and use.</p>
<ol>
<li><strong>easy_install mysql-python</strong> (mix os)</li>
<li><strong>pip install mysql-python</strong> (mix os)</li>
<li><stron... | 395 | 2011-05-03T17:23:47Z | [
"python",
"django"
] |
No module named MySQLdb | 454,854 | <p>I am using Python version 2.5.4 and install MySQL version 5.0 and Django. Django is working fine with Python, but not MySQL. Can anyone help me to solve this issue? I am using it in Vista.</p>
| 211 | 2009-01-18T09:13:38Z | 5,999,414 | <p>Ubuntu: </p>
<pre><code>sudo apt-get install python-mysqldb
</code></pre>
| 24 | 2011-05-14T02:17:49Z | [
"python",
"django"
] |
No module named MySQLdb | 454,854 | <p>I am using Python version 2.5.4 and install MySQL version 5.0 and Django. Django is working fine with Python, but not MySQL. Can anyone help me to solve this issue? I am using it in Vista.</p>
| 211 | 2009-01-18T09:13:38Z | 12,726,435 | <p>Thanks to derevo but I think there's another good way for doing this:</p>
<ol>
<li>Download and install <a href="http://www.activestate.com/activepython/downloads#" rel="nofollow">ActivePython</a></li>
<li>Open Command Prompt</li>
<li>Type <code>pypm install mysql-python</code></li>
<li>Read the notes specific to t... | 2 | 2012-10-04T11:38:40Z | [
"python",
"django"
] |
No module named MySQLdb | 454,854 | <p>I am using Python version 2.5.4 and install MySQL version 5.0 and Django. Django is working fine with Python, but not MySQL. Can anyone help me to solve this issue? I am using it in Vista.</p>
| 211 | 2009-01-18T09:13:38Z | 25,475,877 | <p>...and remember there is <strong>no MySQLdb for python3.x</strong></p>
<p>(I know the question is about python2.x but google rates this post quite high)</p>
<hr>
<p><strong>EDIT:</strong> As stated in the comments, there's a MySQLdb's fork that adds Python 3 support: <a href="http://github.com/PyMySQL/mysqlclient... | 40 | 2014-08-24T20:11:47Z | [
"python",
"django"
] |
No module named MySQLdb | 454,854 | <p>I am using Python version 2.5.4 and install MySQL version 5.0 and Django. Django is working fine with Python, but not MySQL. Can anyone help me to solve this issue? I am using it in Vista.</p>
| 211 | 2009-01-18T09:13:38Z | 28,278,997 | <ul>
<li>Go to your project directory with <code>cd</code>.</li>
<li>source/bin/activate (activate your env. if not previously).</li>
<li>Run the command <code>easy_install MySQL-python</code></li>
</ul>
| 4 | 2015-02-02T13:36:45Z | [
"python",
"django"
] |
No module named MySQLdb | 454,854 | <p>I am using Python version 2.5.4 and install MySQL version 5.0 and Django. Django is working fine with Python, but not MySQL. Can anyone help me to solve this issue? I am using it in Vista.</p>
| 211 | 2009-01-18T09:13:38Z | 31,104,707 | <p>If you are on a virtual environment then</p>
<pre><code>pip install MySQL-python
</code></pre>
| 3 | 2015-06-28T21:01:10Z | [
"python",
"django"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.