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 |
|---|---|---|---|---|---|---|---|---|---|
Reverse for '*' with arguments '()' and keyword arguments '{}' not found | 1,842,389 | <p>Caught an exception while rendering: </p>
<blockquote>
<p>Reverse for 'products.views.'filter_by_led' with arguments '()' and
keyword arguments '{}' not found.</p>
</blockquote>
<p>I was able to successfully import <code>products.views.filter_by_led</code> from the shell and it worked so the path should be co... | 44 | 2009-12-03T19:42:13Z | 1,842,830 | <p>I don't think you need the trailing slash in the URL entry. Ie, put this instead:</p>
<pre><code>(r'^led-tv$', filter_by_led ),
</code></pre>
<p>This is assuming you have <a href="http://docs.djangoproject.com/en/dev/ref/settings/#append-slash" rel="nofollow">trailing slashes</a> enabled, which is the default.</p>... | 0 | 2009-12-03T20:50:33Z | [
"python",
"django",
"django-templates"
] |
Reverse for '*' with arguments '()' and keyword arguments '{}' not found | 1,842,389 | <p>Caught an exception while rendering: </p>
<blockquote>
<p>Reverse for 'products.views.'filter_by_led' with arguments '()' and
keyword arguments '{}' not found.</p>
</blockquote>
<p>I was able to successfully import <code>products.views.filter_by_led</code> from the shell and it worked so the path should be co... | 44 | 2009-12-03T19:42:13Z | 14,982,471 | <p>Shell calls to <em>reverse</em> (as mentioned above) are very good to debug these problems, but there are two critical conditions:</p>
<ul>
<li>you <strong>must</strong> supply arguments that matches whatever arguments the view needs,</li>
<li>these <strong>arguments</strong> must match regexp patterns.</li>
</ul>
... | 27 | 2013-02-20T14:37:41Z | [
"python",
"django",
"django-templates"
] |
Reverse for '*' with arguments '()' and keyword arguments '{}' not found | 1,842,389 | <p>Caught an exception while rendering: </p>
<blockquote>
<p>Reverse for 'products.views.'filter_by_led' with arguments '()' and
keyword arguments '{}' not found.</p>
</blockquote>
<p>I was able to successfully import <code>products.views.filter_by_led</code> from the shell and it worked so the path should be co... | 44 | 2009-12-03T19:42:13Z | 27,051,040 | <p>You need single quotes around the view name</p>
<pre><code>{% url 'viewname' %}
</code></pre>
<p>instead of</p>
<pre><code>{% url viewname %}
</code></pre>
| 4 | 2014-11-20T22:45:02Z | [
"python",
"django",
"django-templates"
] |
Reverse for '*' with arguments '()' and keyword arguments '{}' not found | 1,842,389 | <p>Caught an exception while rendering: </p>
<blockquote>
<p>Reverse for 'products.views.'filter_by_led' with arguments '()' and
keyword arguments '{}' not found.</p>
</blockquote>
<p>I was able to successfully import <code>products.views.filter_by_led</code> from the shell and it worked so the path should be co... | 44 | 2009-12-03T19:42:13Z | 33,779,469 | <p>I had a similar problem and the solution was in the right use of the '$' (end-of-string) character:</p>
<p>My main url.py looked like this (notice the $ character):</p>
<pre><code>urlpatterns = [
url(r'^admin/', include(admin.site.urls )),
url(r'^$', include('card_purchase.urls' )),
]
</code></pre>
<p>and my url.... | 3 | 2015-11-18T11:57:32Z | [
"python",
"django",
"django-templates"
] |
Why is 'dir()' named 'dir' in python? | 1,842,414 | <p>In Python there is a built-in function called <code>dir</code>. This is used to get a list of all the attributes for an object.</p>
<p>I understand what it does, but I am confused about why it is called <code>dir</code>. How is this name related to getting the attributes from an object?</p>
| 20 | 2009-12-03T19:47:05Z | 1,842,423 | <p>It gives you a <strong>dir</strong>ectory of all attributes of an object. </p>
<p>This is not a directory as used in file systems, but the standard usage: a listing of names or data.</p>
| 25 | 2009-12-03T19:48:19Z | [
"python",
"built-in",
"dir"
] |
Why is 'dir()' named 'dir' in python? | 1,842,414 | <p>In Python there is a built-in function called <code>dir</code>. This is used to get a list of all the attributes for an object.</p>
<p>I understand what it does, but I am confused about why it is called <code>dir</code>. How is this name related to getting the attributes from an object?</p>
| 20 | 2009-12-03T19:47:05Z | 1,842,428 | <p>You're retrieving a "directory", a list of all of the stuff that's available in some resource.</p>
| 3 | 2009-12-03T19:48:57Z | [
"python",
"built-in",
"dir"
] |
Sending movie stream from client to server. The python server should play the stream on the fly | 1,842,583 | <p>I would like to simulate some kind of camera on a UAV. The camera should provide a live stream, and send the stream over a network connection to a server. The server should be able to play the stream on the fly for me to see.</p>
<p>I was thinking the client(UAV) just read a moviefile and sent it to the server. But... | 0 | 2009-12-03T20:14:28Z | 1,844,006 | <p>try 'webcam'</p>
<pre><code>sudo apt-get install webcam
</code></pre>
<p>on debian.</p>
<p>It will grab images from a USB camera and put them in a jpg file in /var/www/ then you make an html page that auto-refreshes as fast as possible that points to the image file.</p>
<p>I know its not a very elegant solution ... | 0 | 2009-12-04T00:08:51Z | [
"python",
"network-programming",
"streaming",
"movie"
] |
Timer object in Django | 1,842,593 | <p>I'm using Django to create registration/payment application for a limited number of products. I want to create a timer so that when a user chooses to purchase a product, that product will then displayed as "already taken". But, if the user the user does not go through with the purchase and the timer runs out, th... | 0 | 2009-12-03T20:15:22Z | 1,842,622 | <p>You should not use some in-process/memory timer objects since your django app can run in multiple processes...</p>
<p>I suggest create this "timers" in database (like "expire" datetime field for your product model) and use cron job that will mark expired objects to be available </p>
| 1 | 2009-12-03T20:19:07Z | [
"python",
"django",
"timer"
] |
Timer object in Django | 1,842,593 | <p>I'm using Django to create registration/payment application for a limited number of products. I want to create a timer so that when a user chooses to purchase a product, that product will then displayed as "already taken". But, if the user the user does not go through with the purchase and the timer runs out, th... | 0 | 2009-12-03T20:15:22Z | 1,842,666 | <p>Fork it. Have your model use three states for a product: <code>available</code>, <code>taken</code>, and <code>purchased</code>. When a user initiates an action that marks the product as <code>taken</code>, spawn a new process that will mark the product to <code>available</code> in 3 minutes if it is not <code>purch... | -2 | 2009-12-03T20:25:32Z | [
"python",
"django",
"timer"
] |
Timer object in Django | 1,842,593 | <p>I'm using Django to create registration/payment application for a limited number of products. I want to create a timer so that when a user chooses to purchase a product, that product will then displayed as "already taken". But, if the user the user does not go through with the purchase and the timer runs out, th... | 0 | 2009-12-03T20:15:22Z | 1,842,844 | <p>I would not use a timer for such situation because it can give some complexity. What will happen to your timers if the process is restarted. That't the case with some internet providers who restart the process on a regular basis. Maybe you are facing a similar situation.</p>
<p>I would add a 'taken_time' datetimefi... | 6 | 2009-12-03T20:52:34Z | [
"python",
"django",
"timer"
] |
Regular expression to replace with XML node | 1,842,608 | <p>I'm using Python to write a regular expression for replacing parts of the string with a XML node.</p>
<p>The source string looks like:</p>
<pre>
Hello
REPLACE(str1) this is to replace
REPLACE(str2) this is to replace
</pre>
<p>And the result string should be like:</p>
<pre>
Hello
<replace name="str1"> this is... | 1 | 2009-12-03T20:17:01Z | 1,842,631 | <p>Here is an <a href="http://www.amk.ca/python/howto/regex/" rel="nofollow">excellent tutorial</a> on how to write regular expressions in Python.</p>
| 4 | 2009-12-03T20:19:36Z | [
"python",
"regex"
] |
Regular expression to replace with XML node | 1,842,608 | <p>I'm using Python to write a regular expression for replacing parts of the string with a XML node.</p>
<p>The source string looks like:</p>
<pre>
Hello
REPLACE(str1) this is to replace
REPLACE(str2) this is to replace
</pre>
<p>And the result string should be like:</p>
<pre>
Hello
<replace name="str1"> this is... | 1 | 2009-12-03T20:17:01Z | 1,842,688 | <p>Maybe like this ?</p>
<pre><code>import re
mystr = """Hello
REPLACE(str1) this is to replace
REPLACE(str2) this is to replace"""
prog = re.compile(r'REPLACE\((.*?)\)\s(.*)')
for line in mystr.split("\n"):
print prog.sub(r'< replace name="\1" > \2',line)
</code></pre>
| 0 | 2009-12-03T20:29:16Z | [
"python",
"regex"
] |
Regular expression to replace with XML node | 1,842,608 | <p>I'm using Python to write a regular expression for replacing parts of the string with a XML node.</p>
<p>The source string looks like:</p>
<pre>
Hello
REPLACE(str1) this is to replace
REPLACE(str2) this is to replace
</pre>
<p>And the result string should be like:</p>
<pre>
Hello
<replace name="str1"> this is... | 1 | 2009-12-03T20:17:01Z | 1,842,700 | <p>Something like this should work:</p>
<pre><code>import re,sys
f = open( sys.argv[1], 'r' )
for i in f:
g = re.match( r'REPLACE\((.*)\)(.*)', i )
if g is None:
print i
else:
print '<replace name=\"%s\">%s</replace>' % (g.group(1),g.group(2))
f.close()
</code></pre>
| 0 | 2009-12-03T20:30:40Z | [
"python",
"regex"
] |
Regular expression to replace with XML node | 1,842,608 | <p>I'm using Python to write a regular expression for replacing parts of the string with a XML node.</p>
<p>The source string looks like:</p>
<pre>
Hello
REPLACE(str1) this is to replace
REPLACE(str2) this is to replace
</pre>
<p>And the result string should be like:</p>
<pre>
Hello
<replace name="str1"> this is... | 1 | 2009-12-03T20:17:01Z | 1,842,721 | <p>What makes your problem a little bit tricky is that you want to match inside of a multiline string. You need to use the <code>re.MULTILINE</code> flag to make that work.</p>
<p>Then, you need to match some groups inside your source string, and use those groups in the final output. Here is code that works to solve... | 5 | 2009-12-03T20:32:53Z | [
"python",
"regex"
] |
Regular expression to replace with XML node | 1,842,608 | <p>I'm using Python to write a regular expression for replacing parts of the string with a XML node.</p>
<p>The source string looks like:</p>
<pre>
Hello
REPLACE(str1) this is to replace
REPLACE(str2) this is to replace
</pre>
<p>And the result string should be like:</p>
<pre>
Hello
<replace name="str1"> this is... | 1 | 2009-12-03T20:17:01Z | 1,842,727 | <pre><code>import re
a="""Hello
REPLACE(str1) this is to replace
REPLACE(str2) this is to replace"""
regex = re.compile(r"^REPLACE\(([^)]+)\)\s+(.*)$", re.MULTILINE)
b=re.sub(regex, r'< replace name="\1" > \2 < /replace >', a)
print b
</code></pre>
<p>will do the replace in one line.</p>
| 0 | 2009-12-03T20:33:33Z | [
"python",
"regex"
] |
Regular expression to replace with XML node | 1,842,608 | <p>I'm using Python to write a regular expression for replacing parts of the string with a XML node.</p>
<p>The source string looks like:</p>
<pre>
Hello
REPLACE(str1) this is to replace
REPLACE(str2) this is to replace
</pre>
<p>And the result string should be like:</p>
<pre>
Hello
<replace name="str1"> this is... | 1 | 2009-12-03T20:17:01Z | 1,844,810 | <p>Here is a solution using pyparsing. I know you specifically asked about a regex solution, but if your requirements change, you might find it easier to expand a pyparsing parser. Or a pyparsing prototype solution might give you a little more insight into the problem leading toward a regex or other final implementat... | 1 | 2009-12-04T04:15:27Z | [
"python",
"regex"
] |
Python's string.maketrans works at home but fails on Google App Engine | 1,842,692 | <p>I have this code in Google AppEngine (Python SDK):</p>
<pre><code>from string import maketrans
intab = u"ÃÃÃÃÃÃ
à áâãäåÃÃÃÃÃÃòóôõöøÃÃÃÃèéêëÃçÃÃÃÃìÃîïÃÃÃÃùúûüÿÃñ".encode('latin1')
outtab = u"aaaaaaaaaaaaooooooooooooeeeeeeeecciiiiiiiiuuuuuuuuynn".encode('latin1')... | 5 | 2009-12-03T20:29:45Z | 1,842,999 | <p><code>string.maketrans</code> and <code>string.translate</code> do not work for Unicode strings. Your call to <code>string.maketrans</code> will implictly convert the Unicode you gave it to an encoding like <code>utf-8</code>. In <code>utf-8</code> <code>Ã¥</code> takes up more space than ASCII <code>a</code>. <code... | 14 | 2009-12-03T21:21:29Z | [
"python",
"google-app-engine",
"internationalization",
"translation"
] |
Python's string.maketrans works at home but fails on Google App Engine | 1,842,692 | <p>I have this code in Google AppEngine (Python SDK):</p>
<pre><code>from string import maketrans
intab = u"ÃÃÃÃÃÃ
à áâãäåÃÃÃÃÃÃòóôõöøÃÃÃÃèéêëÃçÃÃÃÃìÃîïÃÃÃÃùúûüÿÃñ".encode('latin1')
outtab = u"aaaaaaaaaaaaooooooooooooeeeeeeeecciiiiiiiiuuuuuuuuynn".encode('latin1')... | 5 | 2009-12-03T20:29:45Z | 1,843,042 | <p>Maybe you could use iso-8859-1 encoding for your file instead of utf-8</p>
<pre><code># -*- coding: iso-8859-1 -*-
from string import maketrans
import logging
intab = "ÃÃÃÃÃÃ
à áâãäåÃÃÃÃÃÃòóôõöøÃÃÃÃèéêëÃçÃÃÃÃìÃîïÃÃÃÃùúûüÿÃñ"
outtab = "aaaaaaaaaaaaooooooooooooeee... | 1 | 2009-12-03T21:27:16Z | [
"python",
"google-app-engine",
"internationalization",
"translation"
] |
Hadoop MapReduce job on file containing HTML tags | 1,842,747 | <p>I have a bunch of large HTML files and I want to run a Hadoop MapReduce job on them to find the most frequently used words. I wrote both my mapper and reducer in Python and used Hadoop streaming to run them. </p>
<p>Here is my mapper: </p>
<pre><code>#!/usr/bin/env python
import sys
import re
import string
def r... | 1 | 2009-12-03T20:36:48Z | 1,843,191 | <p>You can reproduce the bug even with just:</p>
<pre><code>echo "hello - world" | ./mapper.py | sort | ./reducer.py
</code></pre>
<p>The issue is here:</p>
<pre><code>if word =='': continue
for c in string.punctuation:
word= word.replace(c,'')
</code></pre>
<p>If <code>word</code> is a single punctuati... | 1 | 2009-12-03T21:53:22Z | [
"python",
"hadoop",
"mapreduce"
] |
Python Performance on Windows | 1,842,798 | <p>Is Python generally slower on Windows vs. a *nix machine? Python seems to blaze on my Mac OS X machine whereas it <em>seems</em> to run slower on my Window's Vista machine. The machines are similar in processing power and the vista machine has 1GBs more memory. </p>
<p>I particularly notice this in Mercurial but I... | 9 | 2009-12-03T20:44:20Z | 1,843,044 | <p>No real numbers here but it certainly feels like the start up time is slower on Windows platforms. I regularly switch between Ubuntu at home and Windows 7 at work and it's an order of magnitude faster starting up on Ubuntu, despite my work machine being at least 4x the speed.</p>
<p>As for runtime performance, it ... | 1 | 2009-12-03T21:27:53Z | [
"python",
"windows",
"performance",
"osx",
"mercurial"
] |
Python Performance on Windows | 1,842,798 | <p>Is Python generally slower on Windows vs. a *nix machine? Python seems to blaze on my Mac OS X machine whereas it <em>seems</em> to run slower on my Window's Vista machine. The machines are similar in processing power and the vista machine has 1GBs more memory. </p>
<p>I particularly notice this in Mercurial but I... | 9 | 2009-12-03T20:44:20Z | 1,845,271 | <p>Maybe the python has more depend on a lot of files open (import different modules).</p>
<p>Windows doesn't handle file open as efficiently as Linux. </p>
<p>Or maybe Linux probably have more utilities depend on python and python scripts/modules are more likely to be buffered in the system cache.</p>
| 1 | 2009-12-04T06:46:29Z | [
"python",
"windows",
"performance",
"osx",
"mercurial"
] |
Python Performance on Windows | 1,842,798 | <p>Is Python generally slower on Windows vs. a *nix machine? Python seems to blaze on my Mac OS X machine whereas it <em>seems</em> to run slower on my Window's Vista machine. The machines are similar in processing power and the vista machine has 1GBs more memory. </p>
<p>I particularly notice this in Mercurial but I... | 9 | 2009-12-03T20:44:20Z | 1,845,290 | <p>I run Python locally on Windows XP and 7 as well as OSX on my Macbook. I've seen no noticable performance differences in the command line interpreter, wx widget apps run the same, and Django apps also perform virtually identically.</p>
<p>One thing I noticed at work was that the Kaspersky virus scanner tended to s... | 1 | 2009-12-04T06:54:07Z | [
"python",
"windows",
"performance",
"osx",
"mercurial"
] |
Python Performance on Windows | 1,842,798 | <p>Is Python generally slower on Windows vs. a *nix machine? Python seems to blaze on my Mac OS X machine whereas it <em>seems</em> to run slower on my Window's Vista machine. The machines are similar in processing power and the vista machine has 1GBs more memory. </p>
<p>I particularly notice this in Mercurial but I... | 9 | 2009-12-03T20:44:20Z | 1,846,141 | <p>With the OS and network libraries, I can confirm slower performance on Windows, at least for versions =< 2.6. </p>
<p>I wrote a CLI podcast-fetcher script which ran great on Ubuntu, but then wouldn't download anything faster than about 80 kB/s (where ~1.6 MB/s is my usual max) on either XP or 7.</p>
<p>I cou... | 0 | 2009-12-04T10:34:41Z | [
"python",
"windows",
"performance",
"osx",
"mercurial"
] |
Python Performance on Windows | 1,842,798 | <p>Is Python generally slower on Windows vs. a *nix machine? Python seems to blaze on my Mac OS X machine whereas it <em>seems</em> to run slower on my Window's Vista machine. The machines are similar in processing power and the vista machine has 1GBs more memory. </p>
<p>I particularly notice this in Mercurial but I... | 9 | 2009-12-03T20:44:20Z | 2,345,328 | <p>I wanted to follow up on this and I found something that I believe is 'my answer'. It appears that Windows (vista, which is what I notice this on) is not as fast in handling files. This was mentioned by tony-p-lee. </p>
<p>I found this comparisons of <a href="http://www.tuxradar.com/content/benchmarked-ubuntu-vs... | 5 | 2010-02-26T22:40:07Z | [
"python",
"windows",
"performance",
"osx",
"mercurial"
] |
Python Performance on Windows | 1,842,798 | <p>Is Python generally slower on Windows vs. a *nix machine? Python seems to blaze on my Mac OS X machine whereas it <em>seems</em> to run slower on my Window's Vista machine. The machines are similar in processing power and the vista machine has 1GBs more memory. </p>
<p>I particularly notice this in Mercurial but I... | 9 | 2009-12-03T20:44:20Z | 37,372,277 | <p>Interestingly I ran a direct comparison of a popular Python app on a Windows 10 x64 Machine (low powered admittedly) and a Ubuntu 14.04 VM running on the same machine.</p>
<p>I have not tested load speeds etc, but am just looking at processor usage between the two. To make the test fair, both were fresh installs an... | 0 | 2016-05-22T08:46:43Z | [
"python",
"windows",
"performance",
"osx",
"mercurial"
] |
Can I CREATE TEMPORARY TABLE in SQLAlchemy without appending to Table._prefixes? | 1,842,902 | <p>I'd like to create a temporary table in SQLAlchemy. I can build a <code>CREATE TABLE</code> statement with a <code>TEMPORARY</code> clause by calling <code>table._prefixes.append('TEMPORARY')</code> against a <code>Table</code> object, but that's less elegant than <code>table.select().prefix_with()</code> used to ad... | 6 | 2009-12-03T21:02:11Z | 1,845,540 | <p>No, <code>prefix_with()</code> is defined for SELECT and INSERT only. But convenient way to add prefix to CREATE TABLE statement is passing it into table definition:</p>
<pre><code>t = Table(
't', metadata,
Column('id', Integer, primary_key=True),
# ...
prefixes=['TEMPORARY'],
)
</code></pre>
| 7 | 2009-12-04T08:08:17Z | [
"python",
"sqlalchemy",
"temp-tables"
] |
Translating python dictionary to C++ | 1,842,941 | <p>I have python code that contains the following code. </p>
<pre><code>d = {}
d[(0,0)] = 0
d[(1,2)] = 1
d[(2,1)] = 2
d[(2,3)] = 3
d[(3,2)] = 4
for (i,j) in d:
print d[(i,j)], d[(j,i)]
</code></pre>
<p>Unfortunately looping over all the keys in python isn't really fast enough for my purpose, and I would like to... | 17 | 2009-12-03T21:10:19Z | 1,842,953 | <p>The type is</p>
<pre><code>std::map< std::pair<int,int>, int>
</code></pre>
<p>The code to add entries to map is like here:</p>
<pre><code>typedef std::map< std::pair<int,int>, int> container;
container m;
m[ make_pair(1,2) ] = 3; //...
for(container::iterator i = m.begin(); i != m.en... | 8 | 2009-12-03T21:12:20Z | [
"c++",
"python",
"dictionary",
"tuples"
] |
Translating python dictionary to C++ | 1,842,941 | <p>I have python code that contains the following code. </p>
<pre><code>d = {}
d[(0,0)] = 0
d[(1,2)] = 1
d[(2,1)] = 2
d[(2,3)] = 3
d[(3,2)] = 4
for (i,j) in d:
print d[(i,j)], d[(j,i)]
</code></pre>
<p>Unfortunately looping over all the keys in python isn't really fast enough for my purpose, and I would like to... | 17 | 2009-12-03T21:10:19Z | 1,842,976 | <p>A dictionary would be a std::map in c++, and a tuple with two elements would be a std::pair.</p>
<p>The python code provided would translate to:</p>
<pre><code>#include <iostream>
#include <map>
typedef std::map<std::pair<int, int>, int> Dict;
typedef Dict::const_iterator It;
int main()
{... | 33 | 2009-12-03T21:17:00Z | [
"c++",
"python",
"dictionary",
"tuples"
] |
Translating python dictionary to C++ | 1,842,941 | <p>I have python code that contains the following code. </p>
<pre><code>d = {}
d[(0,0)] = 0
d[(1,2)] = 1
d[(2,1)] = 2
d[(2,3)] = 3
d[(3,2)] = 4
for (i,j) in d:
print d[(i,j)], d[(j,i)]
</code></pre>
<p>Unfortunately looping over all the keys in python isn't really fast enough for my purpose, and I would like to... | 17 | 2009-12-03T21:10:19Z | 1,843,003 | <p>Have a look at <a href="http://www.boost.org/doc/libs/1%5F41%5F0/libs/python/doc/index.html" rel="nofollow">Boost.python</a>. It's for interaction between python and C++ (basically building python libs using C++, but also for embedding python in C++ programs). Most pythons data structures and their C++ equivalents a... | 3 | 2009-12-03T21:22:25Z | [
"c++",
"python",
"dictionary",
"tuples"
] |
Translating python dictionary to C++ | 1,842,941 | <p>I have python code that contains the following code. </p>
<pre><code>d = {}
d[(0,0)] = 0
d[(1,2)] = 1
d[(2,1)] = 2
d[(2,3)] = 3
d[(3,2)] = 4
for (i,j) in d:
print d[(i,j)], d[(j,i)]
</code></pre>
<p>Unfortunately looping over all the keys in python isn't really fast enough for my purpose, and I would like to... | 17 | 2009-12-03T21:10:19Z | 1,843,038 | <p><code>std::map</code> or more likely <code>std::tr1::unordered_map</code> / <code>boost::unordered_map</code> (aka <code>hash_map</code>) is what you want. </p>
<p>Also, as kriss said, Boost.Python is a good idea to look at here. It provides a C++ version of python's dict class already, so if you're doing cross-lan... | 3 | 2009-12-03T21:26:46Z | [
"c++",
"python",
"dictionary",
"tuples"
] |
Translating python dictionary to C++ | 1,842,941 | <p>I have python code that contains the following code. </p>
<pre><code>d = {}
d[(0,0)] = 0
d[(1,2)] = 1
d[(2,1)] = 2
d[(2,3)] = 3
d[(3,2)] = 4
for (i,j) in d:
print d[(i,j)], d[(j,i)]
</code></pre>
<p>Unfortunately looping over all the keys in python isn't really fast enough for my purpose, and I would like to... | 17 | 2009-12-03T21:10:19Z | 1,843,102 | <p>As a direct answer to your question (for the python part look at my other answer). You can forget the tuple part if you want. You can use any mapping type key/value (hash, etc.) in C++, you just have to find a unique key function. In some cases that can be easy. For instance if you two integers are integers between ... | 0 | 2009-12-03T21:37:56Z | [
"c++",
"python",
"dictionary",
"tuples"
] |
Translating python dictionary to C++ | 1,842,941 | <p>I have python code that contains the following code. </p>
<pre><code>d = {}
d[(0,0)] = 0
d[(1,2)] = 1
d[(2,1)] = 2
d[(2,3)] = 3
d[(3,2)] = 4
for (i,j) in d:
print d[(i,j)], d[(j,i)]
</code></pre>
<p>Unfortunately looping over all the keys in python isn't really fast enough for my purpose, and I would like to... | 17 | 2009-12-03T21:10:19Z | 1,843,316 | <p>Do you want to call an optimized C++ routine via Python? If so, read on:</p>
<p>Often times I use <a href="http://pyyaml.org/" rel="nofollow">PyYaml</a> when dealing with dictionaries in Python. Perhaps you could link in something like <a href="http://pyyaml.org/wiki/LibYAML" rel="nofollow">LibYAML</a> or <a href... | 1 | 2009-12-03T22:10:06Z | [
"c++",
"python",
"dictionary",
"tuples"
] |
Translating python dictionary to C++ | 1,842,941 | <p>I have python code that contains the following code. </p>
<pre><code>d = {}
d[(0,0)] = 0
d[(1,2)] = 1
d[(2,1)] = 2
d[(2,3)] = 3
d[(3,2)] = 4
for (i,j) in d:
print d[(i,j)], d[(j,i)]
</code></pre>
<p>Unfortunately looping over all the keys in python isn't really fast enough for my purpose, and I would like to... | 17 | 2009-12-03T21:10:19Z | 37,355,278 | <p>Map is often implemented as a balanced binary tree not a hash table. This not the case for a Python dict. So you need a C++ O(1) equivalent data structure to use your pairs with.</p>
| 1 | 2016-05-20T20:24:57Z | [
"c++",
"python",
"dictionary",
"tuples"
] |
Kill Windows asynchronous Popen process in 2.4 | 1,842,985 | <p>I have a testing script that needs to open a process (a Pyro server), do some stuff that will call the opened process for information, and when it's all done will need to close the process back down. It's all part of an automated test on a staging server.</p>
<p>In python 2.6 you can do this:</p>
<pre><code>pyro_... | 0 | 2009-12-03T21:19:30Z | 1,844,251 | <ol>
<li><p>Consider copying subprocess.py to your python2.4 dist-packages directory. It should just work as it's a simple wrapper around the old popen library.</p></li>
<li><p>The Popen object terminate function does nothing more than the following:</p>
<p>import os, signal</p>
<p>os.kill(pid, signal.SIGKILL)</p></l... | 1 | 2009-12-04T01:14:30Z | [
"python",
"subprocess",
"popen",
"pyro"
] |
Kill Windows asynchronous Popen process in 2.4 | 1,842,985 | <p>I have a testing script that needs to open a process (a Pyro server), do some stuff that will call the opened process for information, and when it's all done will need to close the process back down. It's all part of an automated test on a staging server.</p>
<p>In python 2.6 you can do this:</p>
<pre><code>pyro_... | 0 | 2009-12-03T21:19:30Z | 19,314,538 | <p>@BrainCore: Note that os.kill is not available on windows in python24, check the docs.</p>
<p>My solution for killing a subprocess.Popen object on windows when using python24 is this:</p>
<pre><code>import os, subprocess
p = subprocess.Popen(...)
res = os.system('taskkill /PID %d /F' % p.pid)
</code></pre>
| 0 | 2013-10-11T09:18:49Z | [
"python",
"subprocess",
"popen",
"pyro"
] |
parsing large compressed xml files, python | 1,843,009 | <pre><code>file = BZ2File(SOME_FILE_PATH)
p = xml.parsers.expat.ParserCreate()
p.Parse(file)
</code></pre>
<p>Here's code that tries to parse xml file compressed with bz2. Unfortunately it fails with a message:</p>
<p><code>TypeError: Parse() argument 1 must be string or read-only buffer, not bz2.BZ2File</code></p>
... | 2 | 2009-12-03T21:23:29Z | 1,843,045 | <p>Use <a href="http://docs.python.org/library/bz2.html#bz2.BZ2File.read" rel="nofollow"><code>.read()</code></a> on the <code>file</code> object to read in the entire file as a string, and then pass that to <code>Parse</code>?</p>
<pre><code>file = BZ2File(SOME_FILE_PATH)
p = xml.parsers.expat.ParserCreate()
p.Parse... | 1 | 2009-12-03T21:28:12Z | [
"python",
"data-compression",
"bzip"
] |
parsing large compressed xml files, python | 1,843,009 | <pre><code>file = BZ2File(SOME_FILE_PATH)
p = xml.parsers.expat.ParserCreate()
p.Parse(file)
</code></pre>
<p>Here's code that tries to parse xml file compressed with bz2. Unfortunately it fails with a message:</p>
<p><code>TypeError: Parse() argument 1 must be string or read-only buffer, not bz2.BZ2File</code></p>
... | 2 | 2009-12-03T21:23:29Z | 1,843,120 | <p>Can you pass in an mmap()'ed file? That should take care of automatically paging the needed parts of the file in, and avoid memory overflow. Of course if <code>expat</code> builts a parse tree, it might still run out of memory.</p>
<p><a href="http://docs.python.org/library/mmap.html" rel="nofollow">http://docs.p... | 0 | 2009-12-03T21:42:42Z | [
"python",
"data-compression",
"bzip"
] |
parsing large compressed xml files, python | 1,843,009 | <pre><code>file = BZ2File(SOME_FILE_PATH)
p = xml.parsers.expat.ParserCreate()
p.Parse(file)
</code></pre>
<p>Here's code that tries to parse xml file compressed with bz2. Unfortunately it fails with a message:</p>
<p><code>TypeError: Parse() argument 1 must be string or read-only buffer, not bz2.BZ2File</code></p>
... | 2 | 2009-12-03T21:23:29Z | 1,843,151 | <p>Just use p.ParseFile(file) instead of p.Parse(file).</p>
<p>Parse() takes a string, ParseFile() takes a file handle, and reads the data in as required.</p>
<p>Ref: <a href="http://docs.python.org/library/pyexpat.html#xml.parsers.expat.xmlparser.ParseFile" rel="nofollow">http://docs.python.org/library/pyexpat.html#... | 5 | 2009-12-03T21:47:38Z | [
"python",
"data-compression",
"bzip"
] |
What modules ought I to consider in Python if I wish to use CGI sessions? | 1,843,022 | <p>Given that I know no web frameworks in Python and would like to keep it Very Simple at the moment (as I am Very Stupid), for what is a prototype of sketchy longevity, are there any streamlined, simple, "batteries-included" modules for this? (It is also too early in my Python career to evaluate frameworks, select on... | 3 | 2009-12-03T21:24:53Z | 1,843,095 | <p>I think the <a href="http://www.web2py.com/" rel="nofollow">web2py</a> (web framework) is easy enough for you. I think it is the simplest approach of making a website or webservice. It will be also <strong>easier</strong>, than to understand Cookie or the other modules of python related to web-things.</p>
<p>You ca... | 3 | 2009-12-03T21:37:12Z | [
"python",
"session"
] |
What modules ought I to consider in Python if I wish to use CGI sessions? | 1,843,022 | <p>Given that I know no web frameworks in Python and would like to keep it Very Simple at the moment (as I am Very Stupid), for what is a prototype of sketchy longevity, are there any streamlined, simple, "batteries-included" modules for this? (It is also too early in my Python career to evaluate frameworks, select on... | 3 | 2009-12-03T21:24:53Z | 1,843,272 | <p><a href="http://cherrypy.org/" rel="nofollow">CherryPy</a> is worth looking into. Yes it is a framework, and yes it requires WSGI, but it is extremely lightweight compared to other more robust alternatives. </p>
<p>There is another question that was answered on SO that gives a <a href="http://stackoverflow.com/qu... | 0 | 2009-12-03T22:04:40Z | [
"python",
"session"
] |
What modules ought I to consider in Python if I wish to use CGI sessions? | 1,843,022 | <p>Given that I know no web frameworks in Python and would like to keep it Very Simple at the moment (as I am Very Stupid), for what is a prototype of sketchy longevity, are there any streamlined, simple, "batteries-included" modules for this? (It is also too early in my Python career to evaluate frameworks, select on... | 3 | 2009-12-03T21:24:53Z | 1,845,073 | <p>WSGI is not a framework, nor does it require that you choose one -- it's THE standard way to run any Python web app framework on any Python-supporting web server, including a CGI one. If you have a WSGI application named <code>app</code>, and want to run it on CGI, see <a href="http://docs.python.org/library/wsgire... | 0 | 2009-12-04T05:40:34Z | [
"python",
"session"
] |
Plotting vector fields in python (matplotlib) | 1,843,194 | <p>I found this code on <a href="http://matplotlib.sourceforge.net/examples/pylab%5Fexamples/quiver%5Fdemo.html">http://matplotlib.sourceforge.net/examples/pylab%5Fexamples/quiver%5Fdemo.html</a></p>
<pre><code>from pylab import *
from numpy import ma
X,Y = meshgrid( arange(0,2*pi,.2),arange(0,2*pi,.2) )
U = cos(X)
V... | 8 | 2009-12-03T21:53:43Z | 1,843,249 | <p>You need to <a href="http://matplotlib.sourceforge.net/faq/howto%5Ffaq.html#generate-images-without-having-a-window-popup" rel="nofollow">call</a> <code>show()</code> or <code>savefig()</code>.</p>
| 3 | 2009-12-03T22:01:08Z | [
"python",
"matplotlib"
] |
Plotting vector fields in python (matplotlib) | 1,843,194 | <p>I found this code on <a href="http://matplotlib.sourceforge.net/examples/pylab%5Fexamples/quiver%5Fdemo.html">http://matplotlib.sourceforge.net/examples/pylab%5Fexamples/quiver%5Fdemo.html</a></p>
<pre><code>from pylab import *
from numpy import ma
X,Y = meshgrid( arange(0,2*pi,.2),arange(0,2*pi,.2) )
U = cos(X)
V... | 8 | 2009-12-03T21:53:43Z | 1,843,255 | <p>Stick <code>show()</code> at the end of the script. Or to save it to a jpg file, put</p>
<pre><code>savefig('output.jpg')
show()
</code></pre>
<p>Be sure to put the <code>savefig()</code> command before the <code>show()</code>.</p>
| 5 | 2009-12-03T22:01:34Z | [
"python",
"matplotlib"
] |
Plotting vector fields in python (matplotlib) | 1,843,194 | <p>I found this code on <a href="http://matplotlib.sourceforge.net/examples/pylab%5Fexamples/quiver%5Fdemo.html">http://matplotlib.sourceforge.net/examples/pylab%5Fexamples/quiver%5Fdemo.html</a></p>
<pre><code>from pylab import *
from numpy import ma
X,Y = meshgrid( arange(0,2*pi,.2),arange(0,2*pi,.2) )
U = cos(X)
V... | 8 | 2009-12-03T21:53:43Z | 13,838,932 | <p>Ideally, you would type this in an interactive shell ( like EPD Python's PyLab ) . Otherwise, you need to explicitly invoke the <code>show()</code> command</p>
| 6 | 2012-12-12T11:38:55Z | [
"python",
"matplotlib"
] |
how to transition from C# to python? | 1,843,219 | <p>i feel like i'm going back to the stone age.</p>
<p>how do i relearn to develop without intellisense (pydev intellisense doesn't count).. in general, how does one successfully leave the comfort of visual studio ?</p>
| 7 | 2009-12-03T21:57:03Z | 1,843,265 | <p>I'm not too familiar with Python so I'll give some general advice. Make sure to print out some reference pages of common functions. Keep them by you(or pinned to a wall or desk) at all times when your programming.. I'm traditionally a "stone age" developer and after developing in VS for a few months I'm finding my h... | 0 | 2009-12-03T22:03:16Z | [
"c#",
"python",
"visual-studio",
"transition"
] |
how to transition from C# to python? | 1,843,219 | <p>i feel like i'm going back to the stone age.</p>
<p>how do i relearn to develop without intellisense (pydev intellisense doesn't count).. in general, how does one successfully leave the comfort of visual studio ?</p>
| 7 | 2009-12-03T21:57:03Z | 1,843,269 | <p>One step at a time?</p>
<p>Start off with simple programs (things you can write with your eyes closed in C#), and keep going... You will end up knowing the API by heart.</p>
| 5 | 2009-12-03T22:04:03Z | [
"c#",
"python",
"visual-studio",
"transition"
] |
how to transition from C# to python? | 1,843,219 | <p>i feel like i'm going back to the stone age.</p>
<p>how do i relearn to develop without intellisense (pydev intellisense doesn't count).. in general, how does one successfully leave the comfort of visual studio ?</p>
| 7 | 2009-12-03T21:57:03Z | 1,843,273 | <p>I've only ever used IDLE for python development and it is not fun in the least. I would recommend getting your favorite text editor, mine is notepad++, and praying for a decent plugin for it. I only ever had to go from Eclipse to Visual Studio so my opinions are generally invalid in these contexts.</p>
| 0 | 2009-12-03T22:04:40Z | [
"c#",
"python",
"visual-studio",
"transition"
] |
how to transition from C# to python? | 1,843,219 | <p>i feel like i'm going back to the stone age.</p>
<p>how do i relearn to develop without intellisense (pydev intellisense doesn't count).. in general, how does one successfully leave the comfort of visual studio ?</p>
| 7 | 2009-12-03T21:57:03Z | 1,843,298 | <p>You could always start with IronPython and continue to develop in Visual Studio. </p>
| 2 | 2009-12-03T22:07:44Z | [
"c#",
"python",
"visual-studio",
"transition"
] |
how to transition from C# to python? | 1,843,219 | <p>i feel like i'm going back to the stone age.</p>
<p>how do i relearn to develop without intellisense (pydev intellisense doesn't count).. in general, how does one successfully leave the comfort of visual studio ?</p>
| 7 | 2009-12-03T21:57:03Z | 1,843,362 | <p>The python ide from wingware is pretty nice. Thats what I ended up using going from visual studio C++/.net to doing python.</p>
| 2 | 2009-12-03T22:17:13Z | [
"c#",
"python",
"visual-studio",
"transition"
] |
how to transition from C# to python? | 1,843,219 | <p>i feel like i'm going back to the stone age.</p>
<p>how do i relearn to develop without intellisense (pydev intellisense doesn't count).. in general, how does one successfully leave the comfort of visual studio ?</p>
| 7 | 2009-12-03T21:57:03Z | 1,843,371 | <p>I recently learned python with a strong C# background. </p>
<p>My advise: Just do it. Sorry, couldn't resist but I'm also serious. Install python and read: <a href="http://docs.python.org/" rel="nofollow">Python.org documentation</a> (v2.6). A book might help too -- I like <a href="http://rads.stackoverflow.com/amz... | 7 | 2009-12-03T22:18:35Z | [
"c#",
"python",
"visual-studio",
"transition"
] |
how to transition from C# to python? | 1,843,219 | <p>i feel like i'm going back to the stone age.</p>
<p>how do i relearn to develop without intellisense (pydev intellisense doesn't count).. in general, how does one successfully leave the comfort of visual studio ?</p>
| 7 | 2009-12-03T21:57:03Z | 1,843,406 | <p>Don't worry about intellisense. Python is really simple and there really isn't that much to know, so after a few projects you'll be conceiving of python code while driving, eating, etc., without really even trying. Plus, python's built in text editor (IDLE) has a wimpy version of intellisense that has always been mo... | 1 | 2009-12-03T22:23:48Z | [
"c#",
"python",
"visual-studio",
"transition"
] |
how to transition from C# to python? | 1,843,219 | <p>i feel like i'm going back to the stone age.</p>
<p>how do i relearn to develop without intellisense (pydev intellisense doesn't count).. in general, how does one successfully leave the comfort of visual studio ?</p>
| 7 | 2009-12-03T21:57:03Z | 1,843,426 | <p>I use <a href="http://www.activestate.com/komodo%5Fedit/" rel="nofollow">Komodo Edit</a> and it does reasonably good guessing at the autocompletion. </p>
| 0 | 2009-12-03T22:26:03Z | [
"c#",
"python",
"visual-studio",
"transition"
] |
how to transition from C# to python? | 1,843,219 | <p>i feel like i'm going back to the stone age.</p>
<p>how do i relearn to develop without intellisense (pydev intellisense doesn't count).. in general, how does one successfully leave the comfort of visual studio ?</p>
| 7 | 2009-12-03T21:57:03Z | 1,843,434 | <p><code><rant></code></p>
<p>This is sort of the reason that I think being a good visual studio user makes you a bad developer. Instead of learning an API, you look in the object browser until you find something that sounds more or less like what you are looking for, instantiate it, then hit . and start looking... | 4 | 2009-12-03T22:26:29Z | [
"c#",
"python",
"visual-studio",
"transition"
] |
how to transition from C# to python? | 1,843,219 | <p>i feel like i'm going back to the stone age.</p>
<p>how do i relearn to develop without intellisense (pydev intellisense doesn't count).. in general, how does one successfully leave the comfort of visual studio ?</p>
| 7 | 2009-12-03T21:57:03Z | 1,844,135 | <p>Python has rich "introspection" features. In particular, you can find out a lot about built-in features using a command called <code>help()</code> from the Python command line.</p>
<p>Suppose you want to use regular expressions, and want to find out how to use them.</p>
<pre><code>>>> import re
>>&... | 6 | 2009-12-04T00:42:02Z | [
"c#",
"python",
"visual-studio",
"transition"
] |
how to transition from C# to python? | 1,843,219 | <p>i feel like i'm going back to the stone age.</p>
<p>how do i relearn to develop without intellisense (pydev intellisense doesn't count).. in general, how does one successfully leave the comfort of visual studio ?</p>
| 7 | 2009-12-03T21:57:03Z | 1,844,168 | <p>Same way you do anything else that doesn't have IntelliStuff.</p>
<p>I'm betting you wrote that question without the aid of an IntelliEnglish computer program that showed you a list of verbs you could use and automatically added punctuation at the end of your sentences, for example. :-)</p>
| 1 | 2009-12-04T00:52:41Z | [
"c#",
"python",
"visual-studio",
"transition"
] |
how to transition from C# to python? | 1,843,219 | <p>i feel like i'm going back to the stone age.</p>
<p>how do i relearn to develop without intellisense (pydev intellisense doesn't count).. in general, how does one successfully leave the comfort of visual studio ?</p>
| 7 | 2009-12-03T21:57:03Z | 1,844,721 | <p>I use Eclipse and PyDev, most of the time, and the limited auto-completion help that it provides is pretty useful.</p>
<p>It's not ever going to come up to the level of VS's IntelliSense, and it can't, because of the dynamic nature of Python. But there are compensations, big ones.</p>
<p>The biggest is the breaki... | 1 | 2009-12-04T03:49:54Z | [
"c#",
"python",
"visual-studio",
"transition"
] |
how to transition from C# to python? | 1,843,219 | <p>i feel like i'm going back to the stone age.</p>
<p>how do i relearn to develop without intellisense (pydev intellisense doesn't count).. in general, how does one successfully leave the comfort of visual studio ?</p>
| 7 | 2009-12-03T21:57:03Z | 1,846,993 | <p>Others have suggested several editors that have intellisense-like capabilities. Try them out.</p>
<p>Also install <a href="http://ipython.scipy.org/moin/" rel="nofollow">ipython</a> and use that to learn the language interactively. It is like a souped up version of the regular python interactive shell with lots a... | 0 | 2009-12-04T13:37:17Z | [
"c#",
"python",
"visual-studio",
"transition"
] |
how to transition from C# to python? | 1,843,219 | <p>i feel like i'm going back to the stone age.</p>
<p>how do i relearn to develop without intellisense (pydev intellisense doesn't count).. in general, how does one successfully leave the comfort of visual studio ?</p>
| 7 | 2009-12-03T21:57:03Z | 1,847,027 | <p><a href="http://code.google.com/p/pyscripter/" rel="nofollow">Pyscripter</a> does a reasonable job at auto-completion/intellisense. I've been using it recently as I started to learn Python/Django, where I've been mainly a C# developer for the last few years.</p>
| 0 | 2009-12-04T13:43:29Z | [
"c#",
"python",
"visual-studio",
"transition"
] |
how to transition from C# to python? | 1,843,219 | <p>i feel like i'm going back to the stone age.</p>
<p>how do i relearn to develop without intellisense (pydev intellisense doesn't count).. in general, how does one successfully leave the comfort of visual studio ?</p>
| 7 | 2009-12-03T21:57:03Z | 1,847,072 | <p>I suggest going cold turkey - languages like Python shine with great text editors. Choose one you want to become amazing at (vim, emacs, etc.) and never look back.</p>
| 0 | 2009-12-04T13:51:20Z | [
"c#",
"python",
"visual-studio",
"transition"
] |
how to transition from C# to python? | 1,843,219 | <p>i feel like i'm going back to the stone age.</p>
<p>how do i relearn to develop without intellisense (pydev intellisense doesn't count).. in general, how does one successfully leave the comfort of visual studio ?</p>
| 7 | 2009-12-03T21:57:03Z | 1,847,933 | <p>Use a good editor like emacs or vim.</p>
| -2 | 2009-12-04T16:04:51Z | [
"c#",
"python",
"visual-studio",
"transition"
] |
how to transition from C# to python? | 1,843,219 | <p>i feel like i'm going back to the stone age.</p>
<p>how do i relearn to develop without intellisense (pydev intellisense doesn't count).. in general, how does one successfully leave the comfort of visual studio ?</p>
| 7 | 2009-12-03T21:57:03Z | 38,883,895 | <p>A mistake people coming from C# or Java make a lot is recreate a large class hierarchy like is common in those languages. With Python this is almost never useful. Instead, learn about duck typing. And don't worry too much about the lack of static typing: in practice, it's almost never an issue.</p>
| 0 | 2016-08-10T21:30:54Z | [
"c#",
"python",
"visual-studio",
"transition"
] |
Get webpage contents with Python? | 1,843,422 | <p>I'm using Python 3.1, if that helps.</p>
<p>Anyways, I'm trying to get the contents of <a href="http://hiscore.runescape.com/index_lite.ws?player=zezima">this</a> webpage. I Googled for a little bit and tried different things, but they didn't work. I'm guessing that this should be an easy task, but...I can't get it... | 18 | 2009-12-03T22:25:35Z | 1,843,458 | <p>You can use urlib2 and parse the HTML yourself.</p>
<p>Or try <strong>Beautiful Soup</strong> to do some of the parsing for you.</p>
| 1 | 2009-12-03T22:29:56Z | [
"python",
"python-3.x"
] |
Get webpage contents with Python? | 1,843,422 | <p>I'm using Python 3.1, if that helps.</p>
<p>Anyways, I'm trying to get the contents of <a href="http://hiscore.runescape.com/index_lite.ws?player=zezima">this</a> webpage. I Googled for a little bit and tried different things, but they didn't work. I'm guessing that this should be an easy task, but...I can't get it... | 18 | 2009-12-03T22:25:35Z | 1,843,511 | <p>Because you're using Python 3.1, you need to use the new <a href="http://www.diveinto.org/python3/porting-code-to-python-3-with-2to3.html#urllib">Python 3.1 APIs</a>.</p>
<p>Try:</p>
<pre><code>urllib.request.urlopen('http://www.python.org/')
</code></pre>
<p>Alternately, it looks like you're working from Python ... | 16 | 2009-12-03T22:38:21Z | [
"python",
"python-3.x"
] |
Get webpage contents with Python? | 1,843,422 | <p>I'm using Python 3.1, if that helps.</p>
<p>Anyways, I'm trying to get the contents of <a href="http://hiscore.runescape.com/index_lite.ws?player=zezima">this</a> webpage. I Googled for a little bit and tried different things, but they didn't work. I'm guessing that this should be an easy task, but...I can't get it... | 18 | 2009-12-03T22:25:35Z | 1,843,635 | <p><a href="http://wwwsearch.sourceforge.net/mechanize/" rel="nofollow">Mechanize</a> is a great package for "acting like a browser", if you want to handle cookie state, etc.</p>
<p><a href="http://wwwsearch.sourceforge.net/mechanize/" rel="nofollow">http://wwwsearch.sourceforge.net/mechanize/</a></p>
| 2 | 2009-12-03T22:56:10Z | [
"python",
"python-3.x"
] |
Get webpage contents with Python? | 1,843,422 | <p>I'm using Python 3.1, if that helps.</p>
<p>Anyways, I'm trying to get the contents of <a href="http://hiscore.runescape.com/index_lite.ws?player=zezima">this</a> webpage. I Googled for a little bit and tried different things, but they didn't work. I'm guessing that this should be an easy task, but...I can't get it... | 18 | 2009-12-03T22:25:35Z | 19,973,400 | <p>If you ask me. try this one</p>
<pre><code>import urllib2
resp = urllib2.urlopen('http://hiscore.runescape.com/index_lite.ws?player=zezima')
</code></pre>
<p>and read the normal way ie</p>
<pre><code>page = resp.read()
</code></pre>
<p>Good luck though</p>
| 4 | 2013-11-14T09:02:17Z | [
"python",
"python-3.x"
] |
Get webpage contents with Python? | 1,843,422 | <p>I'm using Python 3.1, if that helps.</p>
<p>Anyways, I'm trying to get the contents of <a href="http://hiscore.runescape.com/index_lite.ws?player=zezima">this</a> webpage. I Googled for a little bit and tried different things, but they didn't work. I'm guessing that this should be an easy task, but...I can't get it... | 18 | 2009-12-03T22:25:35Z | 23,565,355 | <p>The best way to do this these day is to use the 'requests' library:</p>
<pre><code>import requests
response = requests.get('http://hiscore.runescape.com/index_lite.ws?player=zezima')
print (response.status_code)
print (response.content)
</code></pre>
| 9 | 2014-05-09T13:02:49Z | [
"python",
"python-3.x"
] |
Get webpage contents with Python? | 1,843,422 | <p>I'm using Python 3.1, if that helps.</p>
<p>Anyways, I'm trying to get the contents of <a href="http://hiscore.runescape.com/index_lite.ws?player=zezima">this</a> webpage. I Googled for a little bit and tried different things, but they didn't work. I'm guessing that this should be an easy task, but...I can't get it... | 18 | 2009-12-03T22:25:35Z | 38,428,249 | <p>A solution with works with Python 2.X and Python 3.X:</p>
<pre><code>try:
# For Python 3.0 and later
from urllib.request import urlopen
except ImportError:
# Fall back to Python 2's urllib2
from urllib2 import urlopen
url = 'http://hiscore.runescape.com/index_lite.ws?player=zezima'
response = urlop... | 0 | 2016-07-18T03:38:13Z | [
"python",
"python-3.x"
] |
'setup.py test' egg install location? | 1,843,424 | <p>I have all the eggs my project requires pre-downloaded in a directory, and I would like setuptools to <em>only</em> install packages from that directory.</p>
<p>In my <code>setup.cfg</code> I have:</p>
<pre><code>[easy_install]
allow_hosts = None
find_links = ../../setup
</code></pre>
<p>I run <code>python setup.... | 7 | 2009-12-03T22:25:44Z | 1,845,315 | <p>Just looking at the source code (setuptools/command/tests.py), it doesn't look like setup.py test is not supposed to install anything by design (it is testing, so why put anything in site-packages?). It uses fetch_build_egg (setuptools/dist.py) to get the eggs, which actually does a local easy_install. I suspect y... | 3 | 2009-12-04T07:03:49Z | [
"python",
"setuptools"
] |
User authentication in Django | 1,843,535 | <p>I learned how to authenticate users in Django months ago, but I've since upgraded and am having some problems so it occurred to me this morning that I may not have been doing it correctly from the start so I decided to ask.</p>
<p>In my project's urls.py file I've got ^accounts/login/$ and ^accounts/logout/$ both w... | -1 | 2009-12-03T22:42:30Z | 1,844,023 | <p>Yes the context you pass in render_to_response() is passed to the named templates and ALL the templates it includes or inherits from.</p>
<p>You should look into Using <a href="http://docs.djangoproject.com/en/dev/ref/templates/api/#id1" rel="nofollow">RequestContext</a></p>
<h2>Another thing to check...</h2>
<p>... | 1 | 2009-12-04T00:13:57Z | [
"python",
"django",
"django-templates",
"authentication"
] |
User authentication in Django | 1,843,535 | <p>I learned how to authenticate users in Django months ago, but I've since upgraded and am having some problems so it occurred to me this morning that I may not have been doing it correctly from the start so I decided to ask.</p>
<p>In my project's urls.py file I've got ^accounts/login/$ and ^accounts/logout/$ both w... | -1 | 2009-12-03T22:42:30Z | 1,844,043 | <p>In order to make sure django correctly identifies users, you need to make sure it is properly enabled in your settings module. specifically, you need to make sure that the <code>SessionMiddleware</code> and <code>AuthenticationMiddleware</code> modules are enabled in your <code>settings.MIDDLEWARE_CLASSES</code>. ... | 1 | 2009-12-04T00:19:17Z | [
"python",
"django",
"django-templates",
"authentication"
] |
User authentication in Django | 1,843,535 | <p>I learned how to authenticate users in Django months ago, but I've since upgraded and am having some problems so it occurred to me this morning that I may not have been doing it correctly from the start so I decided to ask.</p>
<p>In my project's urls.py file I've got ^accounts/login/$ and ^accounts/logout/$ both w... | -1 | 2009-12-03T22:42:30Z | 1,844,095 | <p>This answer is tangential, but Jim's suggestion to use RequestContext is so good I want to explicitly explain how to do it.</p>
<p>You can reduce your <code>start_here</code> function to </p>
<pre><code>from django.template import RequestContext
def start_here(request):
return render_to_response("profile.html... | 7 | 2009-12-04T00:31:53Z | [
"python",
"django",
"django-templates",
"authentication"
] |
How to get back to the for loop after exception handling | 1,843,659 | <p>I am ready to run this code but before I want to fix the exception handling:</p>
<pre><code>for l in bios:
OpenThisLink = url + l
try:
response = urllib2.urlopen(OpenThisLink)
except urllib2.HTTPError:
pass
bio = response.read()
item = re.search('(JD)(.*?)(\d+)', bio)
....
</... | 8 | 2009-12-03T22:59:53Z | 1,843,671 | <p>Use <code>continue</code> instead of <code>break</code>.</p>
<p>The statement <code>pass</code> is a no-op (meaning that it doesn't do anything). The program just continues to the next statement, which is why you get an error.</p>
<p><code>break</code> exits the loops and continues running from the next statement ... | 18 | 2009-12-03T23:01:39Z | [
"python",
"exception-handling"
] |
How to get back to the for loop after exception handling | 1,843,659 | <p>I am ready to run this code but before I want to fix the exception handling:</p>
<pre><code>for l in bios:
OpenThisLink = url + l
try:
response = urllib2.urlopen(OpenThisLink)
except urllib2.HTTPError:
pass
bio = response.read()
item = re.search('(JD)(.*?)(\d+)', bio)
....
</... | 8 | 2009-12-03T22:59:53Z | 1,843,864 | <p>Try is actually way more powerful than that. You can use the else block here too:</p>
<pre><code>try:
stuff
except Exception:
print "oh no a exception"
else:
print "oh yay no exception"
finally:
print "leaving the try block"
</code></pre>
| 1 | 2009-12-03T23:34:56Z | [
"python",
"exception-handling"
] |
How to get back to the for loop after exception handling | 1,843,659 | <p>I am ready to run this code but before I want to fix the exception handling:</p>
<pre><code>for l in bios:
OpenThisLink = url + l
try:
response = urllib2.urlopen(OpenThisLink)
except urllib2.HTTPError:
pass
bio = response.read()
item = re.search('(JD)(.*?)(\d+)', bio)
....
</... | 8 | 2009-12-03T22:59:53Z | 1,844,313 | <p>you are getting that error because when the exception is thrown the response variable doesn't exist. If you want to leave the code how you have it you will need to check that response exists before calling read</p>
<pre><code>if response:
bio = response.read()
...
</code></pre>
<p>having said that I agree... | 0 | 2009-12-04T01:27:31Z | [
"python",
"exception-handling"
] |
UnicodeEncodeError with csvwriter | 1,843,999 | <p>I have one more error to fix. </p>
<pre><code>row = OpenThisLink + titleTag + JD
try:
csvwriter.writerow([row])
except (UnicodeEncodeError, UnicodeDecodeError):
pass
</code></pre>
<p>This gives the error (for this character: "Å")</p>
<pre><code>row = OpenThisLink + str(t... | 0 | 2009-12-04T00:07:25Z | 1,844,196 | <pre><code>>>> title = "hello GiliciÅski"
>>> title
'hello Gilici\xc5\x84ski'
>>> u = unicode(title, 'latin')
>>> u
u'hello Gilici\xc5\x84ski'
>>> str(title)
'hello Gilici\xc5\x84ski'
</code></pre>
<p>Works for me. What version of python are you using? I'm using 2.6. If al... | -1 | 2009-12-04T00:59:21Z | [
"python"
] |
UnicodeEncodeError with csvwriter | 1,843,999 | <p>I have one more error to fix. </p>
<pre><code>row = OpenThisLink + titleTag + JD
try:
csvwriter.writerow([row])
except (UnicodeEncodeError, UnicodeDecodeError):
pass
</code></pre>
<p>This gives the error (for this character: "Å")</p>
<pre><code>row = OpenThisLink + str(t... | 0 | 2009-12-04T00:07:25Z | 1,844,441 | <blockquote>
<p>And indeed, my exception doesn't seem
to work. Any suggestions?</p>
</blockquote>
<p><code>row = OpenThisLink + titleTag + JD</code> is outside the try/except block and so any exceptions raised while that statement is running will not be caught. This, however, will catch the exception:</p>
<pre><c... | 5 | 2009-12-04T02:03:35Z | [
"python"
] |
UnicodeEncodeError with csvwriter | 1,843,999 | <p>I have one more error to fix. </p>
<pre><code>row = OpenThisLink + titleTag + JD
try:
csvwriter.writerow([row])
except (UnicodeEncodeError, UnicodeDecodeError):
pass
</code></pre>
<p>This gives the error (for this character: "Å")</p>
<pre><code>row = OpenThisLink + str(t... | 0 | 2009-12-04T00:07:25Z | 5,447,011 | <p>For IDLE, according to the solution here(<a href="http://bytes.com/topic/python/answers/543035-typing-utf-8-characters-idle" rel="nofollow">link</a>), open file $python/Lib/idellib/IOBinding.py, forcefully put </p>
<blockquote>
<p>encoding = "utf-8"</p>
</blockquote>
<p>after the try-except-pass module for setti... | 1 | 2011-03-27T03:29:53Z | [
"python"
] |
Strings are wrapped in b'...' | 1,844,034 | <pre><code>import urllib.request
#name = input("What is your screenname? ");
name = "zezima"
page = urllib.request.urlopen('http://hiscore.runescape.com/index_lite.ws?player=' + name)
page = page.readlines()
skills = []
for line in page:
skills += [line]
print(skills)
</code></pre>
<p>Outputs:</p>
<pre><code>[... | 1 | 2009-12-04T00:16:46Z | 1,844,055 | <p>"b" means byte array.
You can refer to <a href="http://stackoverflow.com/questions/606191/convert-byte-array-to-python-string">this</a> question for a solution.</p>
| 6 | 2009-12-04T00:22:11Z | [
"python",
"python-3.x"
] |
Patterns for dealing with memcache Caching in Django | 1,844,432 | <p>I have a big Django project with several interrelated projects and a lot of caching in use. It currently has a file which stores cache helper functions. So for example, get_object_x(id) would check cache for this object and if it wasn't there, go to the DB and pull it from there and return it, caching it along the w... | 4 | 2009-12-04T02:00:44Z | 1,844,581 | <p>Since you indicated you're caching Django ORM model instances, take a look at <a href="http://github.com/dcramer/django-orm-cache" rel="nofollow">django-orm-cache</a>, which provides automated caching of model instances and is smart about when to invalidate the cache.</p>
<p>Your circular imports won't be an issue ... | 3 | 2009-12-04T02:59:46Z | [
"python",
"django",
"memcached"
] |
Patterns for dealing with memcache Caching in Django | 1,844,432 | <p>I have a big Django project with several interrelated projects and a lot of caching in use. It currently has a file which stores cache helper functions. So for example, get_object_x(id) would check cache for this object and if it wasn't there, go to the DB and pull it from there and return it, caching it along the w... | 4 | 2009-12-04T02:00:44Z | 1,845,729 | <p>A general Python pattern for avoiding circular imports is to put one set of the imports inside the dependent functions:</p>
<pre><code># module_a.py
import module_b
def foo():
return "bar"
def bar():
return module_b.baz()
# module_b.py
def baz():
import module_a
return module_a.foo()
</code></pre... | 7 | 2009-12-04T08:59:17Z | [
"python",
"django",
"memcached"
] |
Using xvkbd to read a barcode. How to disable Enter key? | 1,844,457 | <p>I am using zbarcam to read barcode from a webcam in my webapps.
But, since zbarcam display a \n at the end, my form is submit.</p>
<p>Here is what I use :</p>
<p><strong>read_one.py</strong></p>
<pre><code>#!/usr/bin/python
from sys import argv
import zbar
import webbrowser
# create a Processor
proc = zbar.Proce... | 1 | 2009-12-04T02:09:30Z | 1,844,475 | <p>Try this:</p>
<pre><code>printf "$(python read_one.py)" | xvkbd -file -
</code></pre>
| 1 | 2009-12-04T02:15:14Z | [
"python",
"bash",
"barcode",
"barcode-scanner"
] |
Using xvkbd to read a barcode. How to disable Enter key? | 1,844,457 | <p>I am using zbarcam to read barcode from a webcam in my webapps.
But, since zbarcam display a \n at the end, my form is submit.</p>
<p>Here is what I use :</p>
<p><strong>read_one.py</strong></p>
<pre><code>#!/usr/bin/python
from sys import argv
import zbar
import webbrowser
# create a Processor
proc = zbar.Proce... | 1 | 2009-12-04T02:09:30Z | 15,900,389 | <p>To strip the enter:</p>
<pre><code>print symbol.data.strip()
</code></pre>
<p>But a pipeable program that does that is kind of nasty. You could just send directly to xvkbd from your program (and no need for file if you don't mind passing the string in args):</p>
<pre><code>import subprocess # at appropriate place... | 1 | 2013-04-09T11:15:39Z | [
"python",
"bash",
"barcode",
"barcode-scanner"
] |
Problem with the size of the arrows on a vector field plot | 1,844,467 | <p>I would like to know how can I make it so the arrows have a length of sqrt(2) (as their x and y coordinates have length 1). As you can see for the picture shown bellow, they seem quite small. Thanks!
from pylab import *
from numpy import ma</p>
<pre><code>X = (0, 0, 0)
Y = (0, 1, 2)
quiver(X, Y, (1, 1, 1),... | 0 | 2009-12-04T02:12:41Z | 1,845,000 | <p>This will produce arrows sqrt(2) in proportion to the y axis.</p>
<pre><code>pylab.quiver(X,Y,(1,1,1),(1,1,1), scale=2**.5, units='y')
</code></pre>
<p>It was in the <a href="http://matplotlib.sourceforge.net/api/pyplot%5Fapi.html#matplotlib.pyplot.quiver" rel="nofollow">documentation</a>.</p>
<p>Here is an <a hr... | 1 | 2009-12-04T05:16:27Z | [
"python",
"matplotlib"
] |
Howto Embed , load .swf into Pygame? | 1,844,535 | <p>How to load a .swf(flash) file in Pygame?</p>
<p>THANK YOU. </p>
| 0 | 2009-12-04T02:43:40Z | 1,844,651 | <p>As far as I know, Pygame does not have a browser widget that supports playing flash. To get this working, you'll have to embed a window from a web browser that does (i.e. FireFox, IE, Safari, etc).</p>
<p>Alternatively, you can use Python's C/C++ interface integrate the <a href="http://www.gnu.org/software/gnash/" ... | 0 | 2009-12-04T03:26:53Z | [
"python",
"pygame"
] |
Howto Embed , load .swf into Pygame? | 1,844,535 | <p>How to load a .swf(flash) file in Pygame?</p>
<p>THANK YOU. </p>
| 0 | 2009-12-04T02:43:40Z | 1,846,107 | <p>Take a look at <a href="http://www.gnu.org/software/gnash/" rel="nofollow">Gnash</a>, you might find <a href="http://stackoverflow.com/questions/1685969/embedding-gnash-into-pygame">this question</a> relevant.</p>
| 0 | 2009-12-04T10:25:42Z | [
"python",
"pygame"
] |
Remove a sublayout in qt? | 1,844,630 | <p>In PyQt 4.5, I have a layout inside another layout. I'd like to remove the sublayout from its parent, and hide it. I can say <code>parent_layout.removeItem(child_layout)</code> to remove the layout from its parent, but it still shows on the widget. I can't find any way to hide it in one step, as <code>QLayout</co... | 3 | 2009-12-04T03:19:43Z | 1,844,640 | <p>With some help from flupke on <code>#qt</code>, I came up with:</p>
<pre><code>for i in range(0, child_layout.count()):
child_layout.itemAt(i).widget().hide()
parent_layout.removeItem(child_layout)
</code></pre>
<p>Which assumes all the child layout's children are widgets. Is there a simpler solution?</p>
| 1 | 2009-12-04T03:22:57Z | [
"python",
"qt4",
"pyqt"
] |
Remove a sublayout in qt? | 1,844,630 | <p>In PyQt 4.5, I have a layout inside another layout. I'd like to remove the sublayout from its parent, and hide it. I can say <code>parent_layout.removeItem(child_layout)</code> to remove the layout from its parent, but it still shows on the widget. I can't find any way to hide it in one step, as <code>QLayout</co... | 3 | 2009-12-04T03:19:43Z | 1,844,678 | <p>The easy solution would be to have an interior widget, not an interior layout. You could assign the layout you desire to the widget, then just remove/hide the widget when you want to do so. A good rule of thumb is if you just want to arrange how widgets appear, then use a layout; if you want to hide/show them as a... | 4 | 2009-12-04T03:36:39Z | [
"python",
"qt4",
"pyqt"
] |
Programmatically pass unknown number of parameters in Python | 1,844,705 | <p>I'd like an easy way to plug in a function and arguments to be executed later so I can have a kind of wrapper around it.</p>
<p>In this case, I'd like to use it to benchmark, example:</p>
<pre><code>def timefunc(fn, *args):
start = time.clock()
fn(args)
stop = time.clock()
return stop - start
</code></... | 2 | 2009-12-04T03:44:44Z | 1,844,713 | <p>Just call the function like this:</p>
<pre><code>fn(*args)
</code></pre>
| 7 | 2009-12-04T03:46:52Z | [
"python"
] |
Programmatically pass unknown number of parameters in Python | 1,844,705 | <p>I'd like an easy way to plug in a function and arguments to be executed later so I can have a kind of wrapper around it.</p>
<p>In this case, I'd like to use it to benchmark, example:</p>
<pre><code>def timefunc(fn, *args):
start = time.clock()
fn(args)
stop = time.clock()
return stop - start
</code></... | 2 | 2009-12-04T03:44:44Z | 1,845,205 | <p>MatrixFrog's answer is the correct one, but just to complete the picture. For finding out the number of arguments simply call <code>len</code>, because <code>args</code> is a tuple:</p>
<pre><code>import time
def timefunc(fn, *args):
start = time.clock()
print len(args), type(args)
fn(*args)
stop = tim... | 1 | 2009-12-04T06:19:52Z | [
"python"
] |
How to add a scrollbar to a window with tkinter? | 1,844,995 | <p>I have a tkinter program:</p>
<pre><code>import urllib.request
from tkinter import *
root = Tk()
root.iconbitmap(default='icon.ico')
root.wm_title('Got Skills\' Skill Tracker')
frame = Frame(width="500",height="500")
frame.pack()
def show():
name = "zezima"
page = urllib.request.urlopen('http://hiscore.rune... | 4 | 2009-12-04T05:15:01Z | 1,845,422 | <p>To add the scroll bars, use tkinter.tix.ScrolledWindow.</p>
<p>To remove extra space drop the extra "\n" and display a string, not a tuple. Here is the complete code:</p>
<pre><code>import urllib.request
from tkinter import *
from tkinter.tix import *
root = Tk()
root.iconbitmap(default='icon.ico')
root.wm_title(... | 5 | 2009-12-04T07:33:09Z | [
"python",
"tkinter"
] |
Matrices and inverse Matrices in Python | 1,845,209 | <p>For a project that I am doing, I decompose a graph that I created using NetworkX into an adjacency matrix using the NetworkX adj_matrix() function. However, one of the problems that I have come across is that every single graph that I decompose gives me the following error when I try to find the inverse of the matri... | 2 | 2009-12-04T06:21:00Z | 1,845,311 | <p>are you asking for a method to generate graphs whose adjacency matrices are non-singular? it is no fault of networkx's or numpy's that the graphs you generated have adjacency matrices that do not have inverses.</p>
| 1 | 2009-12-04T07:02:37Z | [
"python",
"matrix",
"networkx",
"matrix-inverse"
] |
Matrices and inverse Matrices in Python | 1,845,209 | <p>For a project that I am doing, I decompose a graph that I created using NetworkX into an adjacency matrix using the NetworkX adj_matrix() function. However, one of the problems that I have come across is that every single graph that I decompose gives me the following error when I try to find the inverse of the matri... | 2 | 2009-12-04T06:21:00Z | 1,845,613 | <p>Adjacency matrices are <a href="http://wiki.canisiusmath.net/index.php?title=Invertible%5Fadjacency%5Fmatrices" rel="nofollow">not always invertible</a>. There are <a href="http://www.emis.de/journals/ELA/ela-articles/abstracts/abs%5Fvol16%5Fpp451-462.ps" rel="nofollow">papers</a> on this subject; I'm not sure whet... | 4 | 2009-12-04T08:25:41Z | [
"python",
"matrix",
"networkx",
"matrix-inverse"
] |
Matrices and inverse Matrices in Python | 1,845,209 | <p>For a project that I am doing, I decompose a graph that I created using NetworkX into an adjacency matrix using the NetworkX adj_matrix() function. However, one of the problems that I have come across is that every single graph that I decompose gives me the following error when I try to find the inverse of the matri... | 2 | 2009-12-04T06:21:00Z | 1,845,644 | <p>I don't know exactly how networkx produces the adjacency matrix, but there is absolutely no reason for it to be inversible. For example, consider the complete graph (all nodes are connected to every each other), its adacency matrix is full of ones, and the matrix has obviously 0 as an eigenvalue (as soon as the numb... | 2 | 2009-12-04T08:33:14Z | [
"python",
"matrix",
"networkx",
"matrix-inverse"
] |
Popularity of path hooks (PEP 302 custom import) | 1,845,251 | <p>My project has the ability to run python functions remotely. Doing so requires transmitting modules a given function utilizes. Determining what to send is conducted via a modified modulefinder.</p>
<p>As I modify the modulefinder to support arbitrary path_hooks, I've started to get the impression that path_hooks... | 1 | 2009-12-04T06:38:36Z | 1,847,726 | <p>Yes, I've coded some path hooks (for one of the obvious purposes: access modules living in other forms of storage besides the filesystem and zipfiles), but never on an open-source project (and actually never needed to support modulefinder in them). What difficulties are you encountering? While I can't share my origi... | 2 | 2009-12-04T15:32:53Z | [
"python",
"path"
] |
Get all table names in a Django app | 1,845,293 | <p>How to get all table names in a Django app?</p>
<p>I use the following code but it doesn't get the tables created by ManyToManyField</p>
<pre><code>from django.db.models import get_app, get_models
app = get_app(app_name)
for model in get_models(app):
print model._meta.db_table
</code></pre>
| 23 | 2009-12-04T06:54:57Z | 1,846,240 | <p>The simplest method should be to use the database reflection APIs in django to go directly to the database. The drawback to this is that it won't give you any tables before you've synced.</p>
| 0 | 2009-12-04T10:58:14Z | [
"python",
"django",
"table",
"model",
"many-to-many"
] |
Get all table names in a Django app | 1,845,293 | <p>How to get all table names in a Django app?</p>
<p>I use the following code but it doesn't get the tables created by ManyToManyField</p>
<pre><code>from django.db.models import get_app, get_models
app = get_app(app_name)
for model in get_models(app):
print model._meta.db_table
</code></pre>
| 23 | 2009-12-04T06:54:57Z | 1,847,330 | <pre><code>from django.db import connection
tables = connection.introspection.table_names()
seen_models = connection.introspection.installed_models(tables)
</code></pre>
<p>As seen in the syncdb command for manage.py.</p>
| 41 | 2009-12-04T14:36:27Z | [
"python",
"django",
"table",
"model",
"many-to-many"
] |
Get all table names in a Django app | 1,845,293 | <p>How to get all table names in a Django app?</p>
<p>I use the following code but it doesn't get the tables created by ManyToManyField</p>
<pre><code>from django.db.models import get_app, get_models
app = get_app(app_name)
for model in get_models(app):
print model._meta.db_table
</code></pre>
| 23 | 2009-12-04T06:54:57Z | 7,513,713 | <p>The simplest answer, that still allows you to pick which app you want, is to modify your code with one extra argument "include_auto_created".</p>
<pre><code>from django.db.models import get_app, get_models
app = get_app(app_name)
for model in get_models(app, include_auto_created=True):
print model._meta.db_tabl... | 9 | 2011-09-22T11:02:35Z | [
"python",
"django",
"table",
"model",
"many-to-many"
] |
How to set shell variables in subprocess.Popen (in a less ugly way...) | 1,845,435 | <p>NOTE: This is <em>not</em> the same question as <a href="http://stackoverflow.com/questions/1126116/python-persistent-shell-variables-in-subprocess">Python: Persistent shell variables in subprocess</a>, as that question is actually about environment variables, not shell variables.</p>
<p>I'm trying to automate a ba... | 0 | 2009-12-04T07:37:40Z | 1,845,473 | <p>You have a limited number of options to communicate to a child process (invocation arguments, environment, and streams). Since setting a shell variable is in a more general sense modifying a child process's internal state, what you call a "kludge" is actually quite reasonable. I don't know of any csh variants that... | 1 | 2009-12-04T07:50:22Z | [
"python",
"unix",
"shell",
"subprocess",
"freebsd"
] |
Python: WindowsError when editing Registry values using _winreg on Windows 7 | 1,845,650 | <p>I am trying to execute <a href="http://nedbatchelder.com/blog/200810/switching%5Fpython%5Fversions%5Fon%5Fwindows.html" rel="nofollow">this script</a> by Ned Batchelder to switch <code>.py</code> file association between my two Python installations on Windows. This Python script uses the <a href="http://docs.python.... | 4 | 2009-12-04T08:35:18Z | 1,845,716 | <p>When I tried that one, I got "Path not found" error on <code>Python.CompiledFile</code>.</p>
<p>I checked it on my registry, it does not exist, not Windows 7 though.</p>
<p>So, I removed those lines of <code>Python.CompiledFile</code> and its running fine here, or</p>
<p>You could put <code>try: except:</code> On... | 0 | 2009-12-04T08:55:34Z | [
"python",
"windows-7",
"registry",
"winreg"
] |
Submenu items in Nautilus right-click menu | 1,845,681 | <p>I am trying to write an extension for nautilus, which add an item to the menu that appears when you right-click a file (as shown in image)</p>
<p><img src="http://img.photobucket.com/albums/v425/play/help/Screenshot-1.png" alt="alt text"></p>
<p>However, I would like to add a submenu to my custom menu item.</p>
<... | 3 | 2009-12-04T08:44:58Z | 1,845,856 | <p>I found the solution.</p>
<ol>
<li>you need a <strong>init</strong> function declared.</li>
<li><p>had to make some variable name change to the example above</p>
<pre><code>import nautilus
class ExampleMenuProvider(nautilus.MenuProvider):
def __init__(self):
pass
def get_file_items(self, window, ... | 3 | 2009-12-04T09:29:07Z | [
"python",
"gtk",
"gnome",
"nautilus"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.