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
listlengths
1
5
Calculating formulae in Excel with Python
1,116,725
<p>I would like to insert a calculation in Excel using Python. Generally it can be done by inserting a formula string into the relevant cell. However, if i need to calculate a formula multiple times for the whole column the formula must be updated for each individual cell. For example, if i need to calculate the sum o...
1
2009-07-12T19:36:54Z
5,479,903
<p>If you want to iterate in the horizontal direction, here is a function I use. 0 -> a, 26 -> aa, 723 -> aav </p> <pre><code>def _num_to_let(num): if num &gt; 25: return _num_to_let(num/26-1) + chr(97+ num % 26) return chr(97+num) </code></pre>
0
2011-03-29T22:57:54Z
[ "python", "excel", "formula" ]
Calculating formulae in Excel with Python
1,116,725
<p>I would like to insert a calculation in Excel using Python. Generally it can be done by inserting a formula string into the relevant cell. However, if i need to calculate a formula multiple times for the whole column the formula must be updated for each individual cell. For example, if i need to calculate the sum o...
1
2009-07-12T19:36:54Z
36,379,409
<p>If you want to iterate in xlwt for columns (in formulas) you can use Utils module from xlwt like this:</p> <pre><code>from xlwt import Utils print Utils.rowcol_pair_to_cellrange(2,2,12,2) print Utils.rowcol_to_cell(13,2) &gt;&gt;&gt; C3:C13 C14 </code></pre>
0
2016-04-02T22:24:16Z
[ "python", "excel", "formula" ]
html form submission in python and php is simple, can a novice do it in java?
1,116,921
<p>I've made two versions of a script that submits a (https) web page form and collects the results. One version uses Snoopy.class in php, and the other uses urllib and urllib2 in python. Now I would like to make a java version.</p> <p>Snoopy makes the php version exceedingly easy to write, and it runs fine on my own ...
2
2009-07-12T21:07:58Z
1,116,934
<p>Use HttpComponents <a href="http://hc.apache.org/" rel="nofollow">http://hc.apache.org/</a>. You need:</p> <ul> <li>HttpComponents Core, <a href="http://mirrors.hostingromania.ro/apache.org/httpcomponents/httpcore/binary/httpcomponents-core-4.0.1-bin.zip" rel="nofollow">direct download</a></li> <li>HttpComponents C...
3
2009-07-12T21:13:15Z
[ "java", "php", "python", "http" ]
html form submission in python and php is simple, can a novice do it in java?
1,116,921
<p>I've made two versions of a script that submits a (https) web page form and collects the results. One version uses Snoopy.class in php, and the other uses urllib and urllib2 in python. Now I would like to make a java version.</p> <p>Snoopy makes the php version exceedingly easy to write, and it runs fine on my own ...
2
2009-07-12T21:07:58Z
1,116,949
<p>What would be so wrong with Apache HttpClient?</p> <p>Just make sure you add the dependencies also to classpath, that is <a href="http://hc.apache.org/downloads.cgi" rel="nofollow">HttpComponents</a>.</p> <pre><code>PostMethod post = new PostMethod("https URL of form action goes here"); NameValuePair[] data = { ...
2
2009-07-12T21:20:03Z
[ "java", "php", "python", "http" ]
html form submission in python and php is simple, can a novice do it in java?
1,116,921
<p>I've made two versions of a script that submits a (https) web page form and collects the results. One version uses Snoopy.class in php, and the other uses urllib and urllib2 in python. Now I would like to make a java version.</p> <p>Snoopy makes the php version exceedingly easy to write, and it runs fine on my own ...
2
2009-07-12T21:07:58Z
1,117,351
<p>Using HttpClient is certainly the more robust solution, but this can be done without an external library dependency. See <a href="http://www.xyzws.com/javafaq/how-to-use-httpurlconnection-post-data-to-web-server/139" rel="nofollow" title="How to use HttpURLConnection POST data to web server?">here</a> for an example...
2
2009-07-13T00:51:08Z
[ "java", "php", "python", "http" ]
html form submission in python and php is simple, can a novice do it in java?
1,116,921
<p>I've made two versions of a script that submits a (https) web page form and collects the results. One version uses Snoopy.class in php, and the other uses urllib and urllib2 in python. Now I would like to make a java version.</p> <p>Snoopy makes the php version exceedingly easy to write, and it runs fine on my own ...
2
2009-07-12T21:07:58Z
1,150,746
<p>MercerTraieste and Tarnschaf kindly offered partial solutions to the problem. It took me a few more days, and untold hours of brain-splitting nightmare, before I gave up trying to figure out how to add a referer to the http post, and sent a new question to stackoverflow.</p> <p>Jon Skeet answered instantly that I o...
2
2009-07-19T20:04:43Z
[ "java", "php", "python", "http" ]
Django Initialization
1,116,948
<p>I have a big array, that I would like to load into memory only once when django starts up and then treat it as a read only global variable. What is the best place to put the code for the initialization of that array?</p> <p>If I put it in settings.py it will be reinitialized every time the settings module is import...
9
2009-07-12T21:19:42Z
1,117,100
<p>settings.py is the right place for that. Settings.py is, like any other module, loaded once. There is still the problem of the fact that a module must be imported once for each process, so a respawning style of web server (like apache) will reload it once for each instance in question. For mod_python this will be...
9
2009-07-12T22:35:25Z
[ "python", "django" ]
Django Initialization
1,116,948
<p>I have a big array, that I would like to load into memory only once when django starts up and then treat it as a read only global variable. What is the best place to put the code for the initialization of that array?</p> <p>If I put it in settings.py it will be reinitialized every time the settings module is import...
9
2009-07-12T21:19:42Z
1,117,692
<p>settings.py is for Django settings; it's fine to put your own settings in there, but using it for arbitrary non-configuration data structures isn't good practice.</p> <p>Just put it in the module it logically belongs to, and it'll be run just once per instance. If you want to guarantee that the module is loaded on...
14
2009-07-13T04:23:30Z
[ "python", "django" ]
lucene / python
1,116,967
<p>Can I use lucene directly from python, preferably without using a binary module?</p> <p>I am interested mainly in read access -- being able to perform queries from python over existing lucene indexes.</p>
5
2009-07-12T21:29:23Z
1,116,984
<p>You can't use Lucene itself from CPython without using a binary module, no.</p> <p>You could use it directly from <a href="http://jython.org/">Jython</a>, or you could use a Python port of Lucene, eg. <a href="http://pypi.python.org/pypi/Lupy/0.2.1">Lupy</a> (though Lupy is no longer under development).</p> <p>If ...
8
2009-07-12T21:33:35Z
[ "python", "lucene" ]
lucene / python
1,116,967
<p>Can I use lucene directly from python, preferably without using a binary module?</p> <p>I am interested mainly in read access -- being able to perform queries from python over existing lucene indexes.</p>
5
2009-07-12T21:29:23Z
1,116,989
<p><a href="http://lucene.apache.org/pylucene/">PyLucene</a> is a Python wrapper around Lucene. Therefore, you have to install Lucene as well, and its installation may be a bit complex (especially on Windows!)</p>
7
2009-07-12T21:34:49Z
[ "python", "lucene" ]
Is there any way to get the repeating decimal section of a fraction in Python?
1,116,990
<p>I'm working with fractions using Python's decimal module and I'd like to get just the repeating part of a certain fraction. For example: if I had 1/3 I'd like to get 3, if I had 1/7 I'd like to get 142857. Is there any standard function to do this?</p>
3
2009-07-12T21:35:10Z
1,117,033
<p>Find the first number of the form 10**k - 1 that divides exactly by the denominator of the fraction, divide it by the denominator and multiply by the numerator and you get your repeating part.</p>
0
2009-07-12T21:51:17Z
[ "python", "decimal", "precision" ]
Is there any way to get the repeating decimal section of a fraction in Python?
1,116,990
<p>I'm working with fractions using Python's decimal module and I'd like to get just the repeating part of a certain fraction. For example: if I had 1/3 I'd like to get 3, if I had 1/7 I'd like to get 142857. Is there any standard function to do this?</p>
3
2009-07-12T21:35:10Z
1,117,059
<p>Since giving the answer could be a spoiler for project euler (which is generally not done here at stackoverflow), I'd like to give this hint: read <a href="http://en.wikipedia.org/wiki/Repeating%5Fdecimal">this</a> (section 1.2 should ring a bell).</p>
5
2009-07-12T22:07:56Z
[ "python", "decimal", "precision" ]
Is there any way to get the repeating decimal section of a fraction in Python?
1,116,990
<p>I'm working with fractions using Python's decimal module and I'd like to get just the repeating part of a certain fraction. For example: if I had 1/3 I'd like to get 3, if I had 1/7 I'd like to get 142857. Is there any standard function to do this?</p>
3
2009-07-12T21:35:10Z
20,875,524
<p>I know this question was a long time ago, but I figured people probably still search something like this so I figured I'd mention some things to keep in mind when doing it since I tried coding and eventually changed my mind to using long division and finding where repetition occurs when you get a remainder after div...
0
2014-01-02T02:39:37Z
[ "python", "decimal", "precision" ]
How to package a command line Python script
1,117,041
<p>I've created a python script that's intended to be used from the command line. How do I go about packaging it? This is my first python package and I've read a bit about setuptools, but I'm still not sure the best way to do this.</p> <p><hr /></p> <h1>Solution</h1> <p>I ended up using <a href="http://peak.telecomm...
25
2009-07-12T21:55:09Z
1,117,081
<p>What do you mean by packaging? If it is a single script to be run on a box that already has python installed, you just need to put a <a href="http://en.wikipedia.org/wiki/Shebang%5F%28Unix%29" rel="nofollow">shebang</a> into the first line of the file and that's it.</p> <p>If you want it to be executed under Window...
2
2009-07-12T22:19:30Z
[ "python", "command-line", "packaging" ]
How to package a command line Python script
1,117,041
<p>I've created a python script that's intended to be used from the command line. How do I go about packaging it? This is my first python package and I've read a bit about setuptools, but I'm still not sure the best way to do this.</p> <p><hr /></p> <h1>Solution</h1> <p>I ended up using <a href="http://peak.telecomm...
25
2009-07-12T21:55:09Z
1,117,528
<p>@Zach, given your clarification in your comment to @soulmerge's answer, it looks like what you need is to write a setup.py as per the instructions regarding the <a href="http://docs.python.org/distutils/index.html#distutils-index" rel="nofollow">distutils</a> -- <a href="http://docs.python.org/distutils/packageindex...
3
2009-07-13T02:38:15Z
[ "python", "command-line", "packaging" ]
How to package a command line Python script
1,117,041
<p>I've created a python script that's intended to be used from the command line. How do I go about packaging it? This is my first python package and I've read a bit about setuptools, but I'm still not sure the best way to do this.</p> <p><hr /></p> <h1>Solution</h1> <p>I ended up using <a href="http://peak.telecomm...
25
2009-07-12T21:55:09Z
7,065,072
<p>Rather than using setuptools non standard way of proceeding, it is possible to directly rely on <code>distutils</code> setup's function, using the <code>scripts</code> argument, as stated here: <a href="http://docs.python.org/distutils/setupscript.html#installing-scripts" rel="nofollow">http://docs.python.org/distut...
3
2011-08-15T12:46:26Z
[ "python", "command-line", "packaging" ]
How to package a command line Python script
1,117,041
<p>I've created a python script that's intended to be used from the command line. How do I go about packaging it? This is my first python package and I've read a bit about setuptools, but I'm still not sure the best way to do this.</p> <p><hr /></p> <h1>Solution</h1> <p>I ended up using <a href="http://peak.telecomm...
25
2009-07-12T21:55:09Z
22,440,072
<p>Last month, I have written an article answering exactly your question. You can find it here: <a href="http://gehrcke.de/2014/02/distributing-a-python-command-line-application/" rel="nofollow">http://gehrcke.de/2014/02/distributing-a-python-command-line-application/</a></p> <p>There, I am using only currently recomm...
1
2014-03-16T17:12:51Z
[ "python", "command-line", "packaging" ]
How to package a command line Python script
1,117,041
<p>I've created a python script that's intended to be used from the command line. How do I go about packaging it? This is my first python package and I've read a bit about setuptools, but I'm still not sure the best way to do this.</p> <p><hr /></p> <h1>Solution</h1> <p>I ended up using <a href="http://peak.telecomm...
25
2009-07-12T21:55:09Z
32,006,336
<p>For those who are beginners in Python Packaging, I suggest going through this <a href="http://www.scotttorborg.com/python-packaging/index.html" rel="nofollow">Python Packaging Tutorial</a>.</p> <p>Note about the tutorial:</p> <blockquote> <p>At this time, this documentation focuses on Python 2.x only, and may no...
0
2015-08-14T09:07:31Z
[ "python", "command-line", "packaging" ]
Error running twisted application
1,117,072
<p>I am trying to run a simple twisted application echo bot that metajack blogged about, everything looks like it is going to load fine, but at the very end I get an error:</p> <pre><code>2009/07/12 15:46 -0600 [-] ImportError: cannot import name toResponse 2009/07/12 15:46 -0600 [-] Failed to load application: cannot...
1
2009-07-12T22:12:55Z
1,117,077
<p>There's not really enough information to go on, but if I had to guess, I'd say that you've given your program the same name as one of the modules that it relies on. Try renaming it to <code>anthonys_echo_bot.py</code> and re-running it. Do this:</p> <pre><code>rm *.pyc </code></pre> <p>in the directory in which ...
1
2009-07-12T22:15:59Z
[ "python", "twisted" ]
Error running twisted application
1,117,072
<p>I am trying to run a simple twisted application echo bot that metajack blogged about, everything looks like it is going to load fine, but at the very end I get an error:</p> <pre><code>2009/07/12 15:46 -0600 [-] ImportError: cannot import name toResponse 2009/07/12 15:46 -0600 [-] Failed to load application: cannot...
1
2009-07-12T22:12:55Z
1,117,217
<p>This error is caused because I have an outdated version of Twisted. Off to find a way to update twisted itself as the installer doesnt seem to be doing the trick.</p>
2
2009-07-12T23:42:05Z
[ "python", "twisted" ]
does python have conversion operators?
1,117,149
<p>I don't think so, but I thought I'd ask just in case. For example, for use in a class that encapsulates an int:</p> <pre><code>i = IntContainer(3) i + 5 </code></pre> <p>And I'm not just interested in this int example, I was looking for something clean and general, not overriding every int and string method.</p> ...
5
2009-07-12T22:59:00Z
1,117,157
<p>Is this what you need?</p> <pre><code>In [1]: class IntContainer(object): ...: def __init__(self, val): ...: self.val = val ...: def __add__(self, val): ...: return self.val + val ...: def __radd__(self, val): ...: return self.val + val ...: ...: In [2]: ...
3
2009-07-12T23:03:49Z
[ "python", "operators" ]
does python have conversion operators?
1,117,149
<p>I don't think so, but I thought I'd ask just in case. For example, for use in a class that encapsulates an int:</p> <pre><code>i = IntContainer(3) i + 5 </code></pre> <p>And I'm not just interested in this int example, I was looking for something clean and general, not overriding every int and string method.</p> ...
5
2009-07-12T22:59:00Z
1,117,163
<p>This should do what you need:</p> <pre><code>class IntContainer(object): def __init__(self, x): self.x = x def __add__(self, other): # do some type checking on other return self.x + other def __radd__(self, other): # do some type checking on other return self.x ...
10
2009-07-12T23:09:13Z
[ "python", "operators" ]
does python have conversion operators?
1,117,149
<p>I don't think so, but I thought I'd ask just in case. For example, for use in a class that encapsulates an int:</p> <pre><code>i = IntContainer(3) i + 5 </code></pre> <p>And I'm not just interested in this int example, I was looking for something clean and general, not overriding every int and string method.</p> ...
5
2009-07-12T22:59:00Z
1,117,174
<p>You won't get conversion operators like in C++ because Python does not have this kind of strong static type system. The only automatic conversion operators are those which handle default numeric values (int/float); they are predefined in the language and cannot be changed.</p> <p>Type "conversion" is usually done b...
3
2009-07-12T23:13:43Z
[ "python", "operators" ]
does python have conversion operators?
1,117,149
<p>I don't think so, but I thought I'd ask just in case. For example, for use in a class that encapsulates an int:</p> <pre><code>i = IntContainer(3) i + 5 </code></pre> <p>And I'm not just interested in this int example, I was looking for something clean and general, not overriding every int and string method.</p> ...
5
2009-07-12T22:59:00Z
1,117,456
<p>sometimes maybe just subclass from int directly is enough. then <code>__add__</code> and <code>__radd__</code> need not costuming.</p> <pre><code>class IntContainer(int): pass i = IntContainer(3) print i + 5 # 8 print 4 + i # 7 class StrContainer(str): pass s = StrContainer(3) print s + '5' # 35 print '4'...
2
2009-07-13T01:50:25Z
[ "python", "operators" ]
How to find the number of parameters to a Python function from C?
1,117,164
<p>I'm using the Python C API to call Python functions from my application. I'd like to present a list of functions that could be called and would like to be able to limit this list to just the ones with the expected number of parameters.</p> <p>I'm happy that I can walk the dictionary to extract a list of functions a...
3
2009-07-12T23:09:18Z
1,117,179
<p><a href="http://mail.python.org/pipermail/cplusplus-sig/2008-February/013027.html" rel="nofollow">Maybe this is helpful?</a> (not tested, there could be relevant pieces of information along this thread)...</p>
1
2009-07-12T23:18:43Z
[ "python", "c" ]
How to find the number of parameters to a Python function from C?
1,117,164
<p>I'm using the Python C API to call Python functions from my application. I'd like to present a list of functions that could be called and would like to be able to limit this list to just the ones with the expected number of parameters.</p> <p>I'm happy that I can walk the dictionary to extract a list of functions a...
3
2009-07-12T23:09:18Z
1,117,518
<p>Your C code can call <a href="http://docs.python.org/library/inspect.html?highlight=getargspec#inspect.getargspec" rel="nofollow">inspect.getargspec</a> just like any Python code would (e.g. via <a href="http://docs.python.org/c-api/object.html?highlight=pyobject%5Fcallmethod#PyObject%5FCallMethod" rel="nofollow">Py...
0
2009-07-13T02:30:21Z
[ "python", "c" ]
How to find the number of parameters to a Python function from C?
1,117,164
<p>I'm using the Python C API to call Python functions from my application. I'd like to present a list of functions that could be called and would like to be able to limit this list to just the ones with the expected number of parameters.</p> <p>I'm happy that I can walk the dictionary to extract a list of functions a...
3
2009-07-12T23:09:18Z
1,117,735
<p>Okay, so in the end I've discovered how to do it. User-defined Python functions have a member called <code>func_code</code> (in Python 3.0+ it's <code>__code__</code>), which itself has a member <code>co_argcount</code>, which is presumably what Boost::Python extracts in the example given by Christophe.</p> <p>The ...
3
2009-07-13T04:48:57Z
[ "python", "c" ]
How to update the twisted framework
1,117,255
<p>I can see from the latest 8.2 (almost 1200 lines of code) twisted that I am missing something: <a href="http://twistedmatrix.com/trac/browser/trunk/twisted/words/protocols/jabber/xmlstream.py" rel="nofollow">http://twistedmatrix.com/trac/browser/trunk/twisted/words/protocols/jabber/xmlstream.py</a></p> <p>My copy (...
3
2009-07-12T23:59:35Z
1,117,318
<p>You can download that file you mentioned by scrolling to the bottom and click "Download in other formats"</p> <p>Otherwise just do svn update.</p>
1
2009-07-13T00:35:53Z
[ "python", "twisted" ]
How to update the twisted framework
1,117,255
<p>I can see from the latest 8.2 (almost 1200 lines of code) twisted that I am missing something: <a href="http://twistedmatrix.com/trac/browser/trunk/twisted/words/protocols/jabber/xmlstream.py" rel="nofollow">http://twistedmatrix.com/trac/browser/trunk/twisted/words/protocols/jabber/xmlstream.py</a></p> <p>My copy (...
3
2009-07-12T23:59:35Z
1,124,217
<p>The answer was hidden away here: <a href="http://twistedmatrix.com/trac/wiki/FrequentlyAskedQuestions#WhyamIgettingImportErrorsforTwistedsubpackagesonOSX10.5" rel="nofollow">http://twistedmatrix.com/trac/wiki/FrequentlyAskedQuestions#WhyamIgettingImportErrorsforTwistedsubpackagesonOSX10.5</a></p> <p>Not really clea...
1
2009-07-14T08:47:21Z
[ "python", "twisted" ]
How to update the twisted framework
1,117,255
<p>I can see from the latest 8.2 (almost 1200 lines of code) twisted that I am missing something: <a href="http://twistedmatrix.com/trac/browser/trunk/twisted/words/protocols/jabber/xmlstream.py" rel="nofollow">http://twistedmatrix.com/trac/browser/trunk/twisted/words/protocols/jabber/xmlstream.py</a></p> <p>My copy (...
3
2009-07-12T23:59:35Z
1,257,261
<p>Try using <code>virtualenv</code> and <code>pip</code> (<code>sudo easy_install virtualenv pip</code>), which are great ways to avoid the dependency hell that you are experiencing.</p> <p>With <code>virtualenv</code> you can create isolated Python environments, and then using <code>pip</code> you can directly insta...
16
2009-08-10T21:15:38Z
[ "python", "twisted" ]
How do I tell a Python script (cygwin) to work in current (or relative) directories?
1,117,414
<p>I have lots of directories with text files written using (g)vim, and I have written a handful of utilities that I find useful in Python. I start off the utilities with a pound-bang-/usr/bin/env python line in order to use the Python that is installed under cygwin. I would like to type commands like this:</p> <p>%...
1
2009-07-13T01:29:44Z
1,117,425
<p>Look at os.getcwd:</p> <ul> <li><a href="http://docs.python.org/library/os.html#os-file-dir" rel="nofollow">http://docs.python.org/library/os.html#os-file-dir</a></li> </ul> <p>Edit: For relative paths, please take a look at the os.path module:</p> <ul> <li><a href="http://docs.python.org/library/os.path.html" r...
4
2009-07-13T01:35:42Z
[ "python", "filesystems", "cygwin", "path", "utilities" ]
How do I tell a Python script (cygwin) to work in current (or relative) directories?
1,117,414
<p>I have lots of directories with text files written using (g)vim, and I have written a handful of utilities that I find useful in Python. I start off the utilities with a pound-bang-/usr/bin/env python line in order to use the Python that is installed under cygwin. I would like to type commands like this:</p> <p>%...
1
2009-07-13T01:29:44Z
1,117,427
<p>What happens when you type "ls"? Do you see "infile.txt" listed there?</p>
0
2009-07-13T01:36:45Z
[ "python", "filesystems", "cygwin", "path", "utilities" ]
How do I tell a Python script (cygwin) to work in current (or relative) directories?
1,117,414
<p>I have lots of directories with text files written using (g)vim, and I have written a handful of utilities that I find useful in Python. I start off the utilities with a pound-bang-/usr/bin/env python line in order to use the Python that is installed under cygwin. I would like to type commands like this:</p> <p>%...
1
2009-07-13T01:29:44Z
1,117,450
<pre><code>os.chdir(my_dir) </code></pre> <p>or</p> <pre><code>os.chdir(os.getcwd()) </code></pre>
0
2009-07-13T01:46:58Z
[ "python", "filesystems", "cygwin", "path", "utilities" ]
Efficiently importing modules in Django views
1,117,451
<p>I was wondering - how do people handle importing large numbers of commonly used modules within django views? And whats the best method to do this efficiently?</p> <p>For instance, I've got some views like,</p> <pre><code>admin_views.py search_views.py . . </code></pre> <p>and from what I've seen, every one of the...
3
2009-07-13T01:46:59Z
1,117,496
<p>Python itself guarantees that a module is loaded just once (unless <code>reload</code> is explicitly called, which is not the case here): after the first time, <code>import</code> of that module just binds its name directly from <code>sys.modules[themodulename]</code>, an extremely fast operation. So Django does not...
6
2009-07-13T02:14:18Z
[ "python", "django", "performance", "import", "python-module" ]
Efficiently importing modules in Django views
1,117,451
<p>I was wondering - how do people handle importing large numbers of commonly used modules within django views? And whats the best method to do this efficiently?</p> <p>For instance, I've got some views like,</p> <pre><code>admin_views.py search_views.py . . </code></pre> <p>and from what I've seen, every one of the...
3
2009-07-13T01:46:59Z
1,117,498
<p>I guess you could slap your frequently used imports into your __init__.py file.</p>
0
2009-07-13T02:14:45Z
[ "python", "django", "performance", "import", "python-module" ]
Efficiently importing modules in Django views
1,117,451
<p>I was wondering - how do people handle importing large numbers of commonly used modules within django views? And whats the best method to do this efficiently?</p> <p>For instance, I've got some views like,</p> <pre><code>admin_views.py search_views.py . . </code></pre> <p>and from what I've seen, every one of the...
3
2009-07-13T01:46:59Z
1,117,556
<p>Django isn't CGI (or PHP). Your app is a single (or a few) long-running Python process. It doesn't matter how long it takes to start, each HTTP request will simply call your (already loaded) view functions.</p>
0
2009-07-13T03:01:43Z
[ "python", "django", "performance", "import", "python-module" ]
Cleaning up nested Try/Excepts
1,117,460
<p>I've just written a chunk of code that strikes me as being far more nested than is optimal. I'd like advice on how to improve the style of this, particularly so that it conforms more with "Flat is better than nested."</p> <pre><code>for app in apps: if app.split('.', 1)[0] == 'zc': #only look for cron in zc app...
4
2009-07-13T01:51:59Z
1,117,473
<p>You can create a function that performs the main logic, and another function which invokes that function, wrapping it with the try...except statements. Then, in the main application, you can just invoke those function which already handle the exceptions. (Based on the recommendations of the "Clean Code" book).</p>
0
2009-07-13T02:00:51Z
[ "python" ]
Cleaning up nested Try/Excepts
1,117,460
<p>I've just written a chunk of code that strikes me as being far more nested than is optimal. I'd like advice on how to improve the style of this, particularly so that it conforms more with "Flat is better than nested."</p> <pre><code>for app in apps: if app.split('.', 1)[0] == 'zc': #only look for cron in zc app...
4
2009-07-13T01:51:59Z
1,117,477
<p>Well, the trick here is to figure out if they are broken. That is the <strong><em>handling</em></strong> part of <strong>exception <em>handling</em></strong>. I mean, at least print a warning that states the comment's assumption. Worrying about excessive nesting before the actual handling seems like you are getting ...
0
2009-07-13T02:01:38Z
[ "python" ]
Cleaning up nested Try/Excepts
1,117,460
<p>I've just written a chunk of code that strikes me as being far more nested than is optimal. I'd like advice on how to improve the style of this, particularly so that it conforms more with "Flat is better than nested."</p> <pre><code>for app in apps: if app.split('.', 1)[0] == 'zc': #only look for cron in zc app...
4
2009-07-13T01:51:59Z
1,117,507
<p>The main problem is that your try clauses are too broad, particularly the outermost one: with that kind of habit, you WILL sooner or later run into a mysterious bug because one of your try/except has accidentally hidden an unexpected exception "bubbling up" from some other function you're calling.</p> <p>So I'd sug...
9
2009-07-13T02:25:23Z
[ "python" ]
Cleaning up nested Try/Excepts
1,117,460
<p>I've just written a chunk of code that strikes me as being far more nested than is optimal. I'd like advice on how to improve the style of this, particularly so that it conforms more with "Flat is better than nested."</p> <pre><code>for app in apps: if app.split('.', 1)[0] == 'zc': #only look for cron in zc app...
4
2009-07-13T01:51:59Z
1,117,531
<p>I wonder, if the jobs for each time unit is actually broken, would they raise an AttibuteError, or some other exception? In particular, if there's something about a job that is really busted, you probably aught not to catch them. </p> <p>Another option that can help is to wrap only the offending code with a try-c...
1
2009-07-13T02:41:18Z
[ "python" ]
Fake a cookie to scrape a site in python
1,117,491
<p>The site that I'm trying to scrape uses js to create a cookie. What I was thinking was that I can create a cookie in python and then use that cookie to scrape the site. However, I don't know any way of doing that. Does anybody have any ideas?</p>
2
2009-07-13T02:11:20Z
1,117,495
<p>Please see <a href="http://www.testingreflections.com/node/view/5919" rel="nofollow">Python httplib2 - Handling Cookies in HTTP Form Posts</a> for an example of adding a cookie to a request.</p> <blockquote> <p>I often need to automate tasks in web based applications. I like to do this at the protocol level ...
2
2009-07-13T02:13:49Z
[ "python", "cookies", "cookiejar" ]
Fake a cookie to scrape a site in python
1,117,491
<p>The site that I'm trying to scrape uses js to create a cookie. What I was thinking was that I can create a cookie in python and then use that cookie to scrape the site. However, I don't know any way of doing that. Does anybody have any ideas?</p>
2
2009-07-13T02:11:20Z
1,118,060
<p>If you want to do more involved browser emulation (including setting cookies) take a look at <a href="http://wwwsearch.sourceforge.net/mechanize/" rel="nofollow">mechanize</a>. It's simulation capabilities are almost complete (no Javascript support unfortunately): I've used it to build several scrapers with much su...
2
2009-07-13T07:14:21Z
[ "python", "cookies", "cookiejar" ]
python sqlalchemy parallel operation
1,117,538
<p>HI,i got a multi-threading program which all threads will operate on oracle DB. So, can sqlalchemy support parallel operation on oracle?</p> <p>tks!</p>
0
2009-07-13T02:44:56Z
1,117,592
<p>As long as each concurrent thread has it's own session you should be fine. Trying to use one shared session is where you'll get into trouble.</p>
1
2009-07-13T03:29:59Z
[ "python", "sqlalchemy" ]
python sqlalchemy parallel operation
1,117,538
<p>HI,i got a multi-threading program which all threads will operate on oracle DB. So, can sqlalchemy support parallel operation on oracle?</p> <p>tks!</p>
0
2009-07-13T02:44:56Z
1,175,578
<p>OCI (oracle client interface) has a parameter OCI_THREADED which has the effect of connections being mutexed, such that concurrent access via multiple threads is safe. This is likely the setting the document you saw was referring to.</p> <p><code>cx_oracle</code>, which is essentially a Python->OCI bridge, provide...
3
2009-07-24T03:09:36Z
[ "python", "sqlalchemy" ]
Set Django IntegerField by choices=... name
1,117,564
<p>When you have a model field with a choices option you tend to have some magic values associated with human readable names. Is there in Django a convenient way to set these fields by the human readable name instead of the value?</p> <p>Consider this model:</p> <pre><code>class Thing(models.Model): PRIORITIES = ( ...
62
2009-07-13T03:05:15Z
1,117,581
<p>Simply replace your numbers with the human readable values you would like. As such:</p> <pre><code>PRIORITIES = ( ('LOW', 'Low'), ('NORMAL', 'Normal'), ('HIGH', 'High'), ) </code></pre> <p>This makes it human readable, however, you'd have to define your own ordering.</p>
1
2009-07-13T03:19:16Z
[ "python", "django", "django-models" ]
Set Django IntegerField by choices=... name
1,117,564
<p>When you have a model field with a choices option you tend to have some magic values associated with human readable names. Is there in Django a convenient way to set these fields by the human readable name instead of the value?</p> <p>Consider this model:</p> <pre><code>class Thing(models.Model): PRIORITIES = ( ...
62
2009-07-13T03:05:15Z
1,117,586
<p>I'd probably set up the reverse-lookup dict once and for all, but if I hadn't I'd just use:</p> <pre><code>thing.priority = next(value for value, name in Thing.PRIORITIES if name=='Normal') </code></pre> <p>which seems simpler than building the dict on the fly just to toss it away again;-).</...
7
2009-07-13T03:23:26Z
[ "python", "django", "django-models" ]
Set Django IntegerField by choices=... name
1,117,564
<p>When you have a model field with a choices option you tend to have some magic values associated with human readable names. Is there in Django a convenient way to set these fields by the human readable name instead of the value?</p> <p>Consider this model:</p> <pre><code>class Thing(models.Model): PRIORITIES = ( ...
62
2009-07-13T03:05:15Z
1,117,587
<p>Do as <a href="http://www.b-list.org/weblog/2007/nov/02/handle-choices-right-way/">seen here</a>. Then you can use a word that represents the proper integer.</p> <p>Like so:</p> <pre><code>LOW = 0 NORMAL = 1 HIGH = 2 STATUS_CHOICES = ( (LOW, 'Low'), (NORMAL, 'Normal'), (HIGH, 'High'), ) </code></pre> ...
103
2009-07-13T03:23:48Z
[ "python", "django", "django-models" ]
Set Django IntegerField by choices=... name
1,117,564
<p>When you have a model field with a choices option you tend to have some magic values associated with human readable names. Is there in Django a convenient way to set these fields by the human readable name instead of the value?</p> <p>Consider this model:</p> <pre><code>class Thing(models.Model): PRIORITIES = ( ...
62
2009-07-13T03:05:15Z
1,490,069
<p>Here's a field type I wrote a few minutes ago that I think does what you want. Its constructor requires an argument 'choices', which may be either a tuple of 2-tuples in the same format as the choices option to IntegerField, or instead a simple list of names (ie ChoiceField(('Low', 'Normal', 'High'), default='Low') ...
4
2009-09-29T00:56:05Z
[ "python", "django", "django-models" ]
Set Django IntegerField by choices=... name
1,117,564
<p>When you have a model field with a choices option you tend to have some magic values associated with human readable names. Is there in Django a convenient way to set these fields by the human readable name instead of the value?</p> <p>Consider this model:</p> <pre><code>class Thing(models.Model): PRIORITIES = ( ...
62
2009-07-13T03:05:15Z
4,846,507
<pre><code>class Sequence(object): def __init__(self, func, *opts): keys = func(len(opts)) self.attrs = dict(zip([t[0] for t in opts], keys)) self.choices = zip(keys, [t[1] for t in opts]) self.labels = dict(self.choices) def __getattr__(self, a): return self.attrs[a] ...
2
2011-01-31T00:07:59Z
[ "python", "django", "django-models" ]
Set Django IntegerField by choices=... name
1,117,564
<p>When you have a model field with a choices option you tend to have some magic values associated with human readable names. Is there in Django a convenient way to set these fields by the human readable name instead of the value?</p> <p>Consider this model:</p> <pre><code>class Thing(models.Model): PRIORITIES = ( ...
62
2009-07-13T03:05:15Z
35,026,629
<p>I appreciate the constant defining way but I believe <a href="https://www.python.org/dev/peps/pep-0435/" rel="nofollow">Enum</a> type is far best for this task. They can represent integer and a string for an item in the same time, while keeping your code more readable.</p> <p>Enums were introduced to Python in vers...
1
2016-01-27T00:25:36Z
[ "python", "django", "django-models" ]
In Python, is there a way to detect the use of incorrect variable names; something like VB's "Option Explicit"?
1,117,661
<p>I do most of my development in Java and C++ but recently had to write various scripts and picked up Python. I run python from the command line on scripts; not in interactive mode. I'm wondering if </p> <p>I like a lot of things about the language, but one thing that keeps reducing my productivity is the fact that I...
3
2009-07-13T04:09:46Z
1,117,676
<p>there are some tools like <a href="http://www.logilab.org/project/pylint" rel="nofollow">pylint</a> or <a href="http://www.divmod.org/trac/wiki/DivmodPyflakes" rel="nofollow">pyflakes</a> which may catch some of those. pyflakes is quite fast, and usable on many projects for this reason</p> <p>As reported on pyflake...
2
2009-07-13T04:14:44Z
[ "python" ]
In Python, is there a way to detect the use of incorrect variable names; something like VB's "Option Explicit"?
1,117,661
<p>I do most of my development in Java and C++ but recently had to write various scripts and picked up Python. I run python from the command line on scripts; not in interactive mode. I'm wondering if </p> <p>I like a lot of things about the language, but one thing that keeps reducing my productivity is the fact that I...
3
2009-07-13T04:09:46Z
1,117,736
<p>Pydev is pretty well integrated with Pylint, see <a href="http://pydev.sourceforge.net/pylint.html" rel="nofollow">here</a> -- and pylint is a much more powerful checker than pyflakes (beyond the minor issue of misspelled variables, it will catch style violations, etc, etc -- it's <em>highly</em> customizable for wh...
2
2009-07-13T04:48:57Z
[ "python" ]
Python MySQLdb exceptions
1,117,828
<p>Just starting to get to grips with python and MySQLdb and was wondering</p> <ol> <li><p>Where is the best play to put a try/catch block for the connection to MySQL. At the MySQLdb.connect point? Also should there be one when ever i query?</p></li> <li><p>What exceptions should i be catching on any of these blocks?<...
7
2009-07-13T05:31:22Z
1,117,841
<p>I think that the connections and the query can raised errors so you should have try/excepy for both of them. </p>
1
2009-07-13T05:37:08Z
[ "python", "mysql", "exception" ]
Python MySQLdb exceptions
1,117,828
<p>Just starting to get to grips with python and MySQLdb and was wondering</p> <ol> <li><p>Where is the best play to put a try/catch block for the connection to MySQL. At the MySQLdb.connect point? Also should there be one when ever i query?</p></li> <li><p>What exceptions should i be catching on any of these blocks?<...
7
2009-07-13T05:31:22Z
1,118,129
<p>Catch the MySQLdb.Error, while connecting and while executing query</p>
13
2009-07-13T07:38:08Z
[ "python", "mysql", "exception" ]
Caching PHP script outputs on the client side
1,117,890
<p>I have a php script that outputs a random image each time it's called. So when I open the script in a web browser, it shows one image and if I refresh, another image shows up.</p> <p>I'm trying to capture the correct image from visiting the web site through a command line (via mechanize). I used urllib2.urlopen(......
0
2009-07-13T06:03:22Z
1,117,912
<p>Most likely your image is cached by browser set this:</p> <pre><code>&lt;?php header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past ?&gt; </code></pre> <p>and each time you generating the image use another name for it (can ...
1
2009-07-13T06:17:21Z
[ "php", "python", "caching", "mechanize" ]
Caching PHP script outputs on the client side
1,117,890
<p>I have a php script that outputs a random image each time it's called. So when I open the script in a web browser, it shows one image and if I refresh, another image shows up.</p> <p>I'm trying to capture the correct image from visiting the web site through a command line (via mechanize). I used urllib2.urlopen(......
0
2009-07-13T06:03:22Z
1,117,926
<p>You can try caching the image generated to disk and make it available to the user via a different link.</p> <p>After the image is generated, move it to a temp folder, where the user can download the generated static image. After it is downloaded, delete to make space.</p>
1
2009-07-13T06:22:39Z
[ "php", "python", "caching", "mechanize" ]
Caching PHP script outputs on the client side
1,117,890
<p>I have a php script that outputs a random image each time it's called. So when I open the script in a web browser, it shows one image and if I refresh, another image shows up.</p> <p>I'm trying to capture the correct image from visiting the web site through a command line (via mechanize). I used urllib2.urlopen(......
0
2009-07-13T06:03:22Z
1,125,281
<p>Grab it once and cache it on your side.</p>
0
2009-07-14T13:12:10Z
[ "php", "python", "caching", "mechanize" ]
Caching PHP script outputs on the client side
1,117,890
<p>I have a php script that outputs a random image each time it's called. So when I open the script in a web browser, it shows one image and if I refresh, another image shows up.</p> <p>I'm trying to capture the correct image from visiting the web site through a command line (via mechanize). I used urllib2.urlopen(......
0
2009-07-13T06:03:22Z
1,125,316
<p>When you save it from the browser, it is not going back to the server to re-request the image, it is serving the one that it is displaying from its cache.</p> <p>Your command line client needs to do the same thing. You need to save the image every time you request it. Then when you find the one you want to keep y...
1
2009-07-14T13:17:10Z
[ "php", "python", "caching", "mechanize" ]
How Do I Use Raw Socket in Python?
1,117,958
<p>I am writing an application to test a network driver for handling corrupted data. And I thought of sending this data using raw socket, so it will not be corrected by the sending machine's TCP-IP stack.</p> <p>I am writing this application solely on Linux. I have code examples of using raw sockets in system-calls, b...
30
2009-07-13T06:36:13Z
1,117,995
<p>The socket class should help. If not you'll need to either write a Python module in C or just use C. See <a href="http://mail.python.org/pipermail/python-list/2001-April/077454.html" rel="nofollow">http://mail.python.org/pipermail/python-list/2001-April/077454.html</a>.</p> <p>Basic Googling found that.</p> <p>I a...
0
2009-07-13T06:49:05Z
[ "python", "sockets", "raw-sockets" ]
How Do I Use Raw Socket in Python?
1,117,958
<p>I am writing an application to test a network driver for handling corrupted data. And I thought of sending this data using raw socket, so it will not be corrected by the sending machine's TCP-IP stack.</p> <p>I am writing this application solely on Linux. I have code examples of using raw sockets in system-calls, b...
30
2009-07-13T06:36:13Z
1,118,001
<p>Is <a href="ftp://ftp.visi.com/users/grante/python/rawDemo.py" rel="nofollow">this</a> the old code you mentioned finding? It looks sensible to me, but I haven't tested it myself (or used raw sockets much). <a href="http://docs.python.org/library/socket.html" rel="nofollow">This example</a> from the documentation sh...
2
2009-07-13T06:50:15Z
[ "python", "sockets", "raw-sockets" ]
How Do I Use Raw Socket in Python?
1,117,958
<p>I am writing an application to test a network driver for handling corrupted data. And I thought of sending this data using raw socket, so it will not be corrected by the sending machine's TCP-IP stack.</p> <p>I am writing this application solely on Linux. I have code examples of using raw sockets in system-calls, b...
30
2009-07-13T06:36:13Z
1,118,003
<p>Sockets system calls (or Winsocks, on Windows), are already wrapped in the standard module <code>socket</code>: <a href="http://docs.python.org/howto/sockets.html">intro</a>, <a href="http://docs.python.org/library/socket.html">reference</a>.</p> <p>I've never used raw sockets but it looks like they can be used wit...
8
2009-07-13T06:52:13Z
[ "python", "sockets", "raw-sockets" ]
How Do I Use Raw Socket in Python?
1,117,958
<p>I am writing an application to test a network driver for handling corrupted data. And I thought of sending this data using raw socket, so it will not be corrected by the sending machine's TCP-IP stack.</p> <p>I am writing this application solely on Linux. I have code examples of using raw sockets in system-calls, b...
30
2009-07-13T06:36:13Z
1,186,810
<p>Eventually the best solution for this case was to write the entire thing in C, because it's not a big application, so it would've incurred greater penalty to write such a small thing in more than 1 language.</p> <p>After much toying with both the C and python RAW sockets, I eventually preferred the C RAW sockets. R...
4
2009-07-27T06:58:51Z
[ "python", "sockets", "raw-sockets" ]
How Do I Use Raw Socket in Python?
1,117,958
<p>I am writing an application to test a network driver for handling corrupted data. And I thought of sending this data using raw socket, so it will not be corrected by the sending machine's TCP-IP stack.</p> <p>I am writing this application solely on Linux. I have code examples of using raw sockets in system-calls, b...
30
2009-07-13T06:36:13Z
6,374,862
<p>You do it like this:</p> <p>First you disable your network card's automatic checksumming:</p> <pre><code>sudo ethtool -K eth1 tx off </code></pre> <p>And then send your dodgy frame from python:</p> <pre><code>#!/usr/bin/env python from socket import socket, AF_PACKET, SOCK_RAW s = socket(AF_PACKET, SOCK_RAW) s.b...
35
2011-06-16T15:57:17Z
[ "python", "sockets", "raw-sockets" ]
How Do I Use Raw Socket in Python?
1,117,958
<p>I am writing an application to test a network driver for handling corrupted data. And I thought of sending this data using raw socket, so it will not be corrected by the sending machine's TCP-IP stack.</p> <p>I am writing this application solely on Linux. I have code examples of using raw sockets in system-calls, b...
30
2009-07-13T06:36:13Z
12,633,135
<pre><code>s = socket(AF_PACKET, SOCK_RAW) s = socket(PF_PACKET, SOCK_RAW) </code></pre> <p>result:</p> <pre><code>[root@localhost python]# tcpdump -i eth0 capture size 96 bytes 11:01:46.850438 01:02:03:04:05:06 (oui Unknown) &gt; 01:02:03:04:05:06 (oui Unknown), ethertype Unknown (0x0801), length 85: 0...
1
2012-09-28T03:15:43Z
[ "python", "sockets", "raw-sockets" ]
Most "pythonic" way of organising class attributes, constructor arguments and subclass constructor defaults?
1,118,006
<p>Being relatively new to Python 2, I'm uncertain how best to organise my class files in the most 'pythonic' way. I wouldn't be asking this but for the fact that Python seems to have quite a few ways of doing things that are very different to what I have come to expect from the languages I am used to.</p> <p>Initiall...
12
2009-07-13T06:54:28Z
1,118,035
<ul> <li><p>If attributes will vary from instance to instance make them instance attribute i.e. create them inside<code>__init__</code> using <strong>self</strong> else if they need to be shared between class instances like a constant, put them at class level.</p></li> <li><p>If your class really need to pass, so many ...
4
2009-07-13T07:05:47Z
[ "python", "python-2.6" ]
Most "pythonic" way of organising class attributes, constructor arguments and subclass constructor defaults?
1,118,006
<p>Being relatively new to Python 2, I'm uncertain how best to organise my class files in the most 'pythonic' way. I wouldn't be asking this but for the fact that Python seems to have quite a few ways of doing things that are very different to what I have come to expect from the languages I am used to.</p> <p>Initiall...
12
2009-07-13T06:54:28Z
1,118,076
<p>It is possible that you can break your massive classes down into classes that each only perform one simple task. Usually classes don't need this many attributes.</p> <p>If you really need to have that many attributes, I think you'll have to live with assigning them all too, especially since you need default values ...
-1
2009-07-13T07:19:25Z
[ "python", "python-2.6" ]
Turbogears 2 vs Django - any advice on choosing replacement for Turbogears 1?
1,118,163
<p>I have been using Turbogears 1 for prototyping small sites for the last couple of years and it is getting a little long in the tooth. Any suggestions on making the call between upgrading to Turbogears 2 or switching to something like Django? I'm torn between the familiarity of the TG community who are pretty respons...
10
2009-07-13T07:49:39Z
1,118,228
<p>Am sure you would have read from plenty of comparison between TurboGears and DJango on web.</p> <p>But as for your temptation on CMS and GAE, i can really think you got to go DJango way. Check these out, and decide youself.</p> <p><a href="http://stackoverflow.com/questions/526256/best-django-features-that-do-wor...
1
2009-07-13T08:13:20Z
[ "python", "django", "google-app-engine", "turbogears", "turbogears2" ]
Turbogears 2 vs Django - any advice on choosing replacement for Turbogears 1?
1,118,163
<p>I have been using Turbogears 1 for prototyping small sites for the last couple of years and it is getting a little long in the tooth. Any suggestions on making the call between upgrading to Turbogears 2 or switching to something like Django? I'm torn between the familiarity of the TG community who are pretty respons...
10
2009-07-13T07:49:39Z
1,118,237
<p>I have been using Django for a year now and when I started I had no experience of Python or Django and found it very intuitive to use.</p> <p>I have created a number of hobbyist Google App Engine apps using Django with the latest one being a CMS for my site. Using Django has meant that I have been able to code a lo...
5
2009-07-13T08:15:27Z
[ "python", "django", "google-app-engine", "turbogears", "turbogears2" ]
Turbogears 2 vs Django - any advice on choosing replacement for Turbogears 1?
1,118,163
<p>I have been using Turbogears 1 for prototyping small sites for the last couple of years and it is getting a little long in the tooth. Any suggestions on making the call between upgrading to Turbogears 2 or switching to something like Django? I'm torn between the familiarity of the TG community who are pretty respons...
10
2009-07-13T07:49:39Z
1,118,670
<p>I have experience with both Django and TG1.1.</p> <p>IMO, TurboGears strong point is it's ORM: SQLAlchemy. I prefer TurboGears when the database side of things is non-trivial.</p> <p>Django's ORM is just not that flexible and powerful.</p> <p>That being said, I prefer Django. If the database schema is a good fit ...
9
2009-07-13T10:18:12Z
[ "python", "django", "google-app-engine", "turbogears", "turbogears2" ]
Turbogears 2 vs Django - any advice on choosing replacement for Turbogears 1?
1,118,163
<p>I have been using Turbogears 1 for prototyping small sites for the last couple of years and it is getting a little long in the tooth. Any suggestions on making the call between upgrading to Turbogears 2 or switching to something like Django? I'm torn between the familiarity of the TG community who are pretty respons...
10
2009-07-13T07:49:39Z
1,118,673
<p>TG2 is built on top of Pylons which has a fairly large community as well. TG got faster compared to TG1 and it includes a per-method (not just web pages) caching engine. I think it's more AJAX-friendly than Django by the way pages can be easly published in HTML or JSON .</p> <p>2011 update: after 3 years of bloated...
13
2009-07-13T10:19:12Z
[ "python", "django", "google-app-engine", "turbogears", "turbogears2" ]
Turbogears 2 vs Django - any advice on choosing replacement for Turbogears 1?
1,118,163
<p>I have been using Turbogears 1 for prototyping small sites for the last couple of years and it is getting a little long in the tooth. Any suggestions on making the call between upgrading to Turbogears 2 or switching to something like Django? I'm torn between the familiarity of the TG community who are pretty respons...
10
2009-07-13T07:49:39Z
1,584,576
<p>Ive only got one question...is the app you are developing directed towards social networking or customized business logic?</p> <p>I personally find Django is good for social networking and pylons/turbogears if you really want the flexibility and no boundaries...</p> <p>just my 2c</p>
-1
2009-10-18T10:44:30Z
[ "python", "django", "google-app-engine", "turbogears", "turbogears2" ]
Turbogears 2 vs Django - any advice on choosing replacement for Turbogears 1?
1,118,163
<p>I have been using Turbogears 1 for prototyping small sites for the last couple of years and it is getting a little long in the tooth. Any suggestions on making the call between upgrading to Turbogears 2 or switching to something like Django? I'm torn between the familiarity of the TG community who are pretty respons...
10
2009-07-13T07:49:39Z
4,919,043
<p>TG2 seem much complicated and confusing, even for doing somewhat simple like a login page with multimple error messages <a href="http://stackoverflow.com/questions/1960747/how-to-extend-the-turbogears-2-1-login-functionality">How to extend the Turbogears 2.1 login functionality</a> I think thats because of intempera...
0
2011-02-07T07:49:15Z
[ "python", "django", "google-app-engine", "turbogears", "turbogears2" ]
How to debug in Django, the good way?
1,118,183
<p>So, I started learning to code in <a href="http://en.wikipedia.org/wiki/Python%5F%28programming%5Flanguage%29">Python</a> and later <a href="http://en.wikipedia.org/wiki/Django%5F%28web%5Fframework%29">Django</a>. The first times it was hard looking at tracebacks and actually figure out what I did wrong and where th...
378
2009-07-13T07:57:02Z
1,118,271
<p>There are a bunch of ways to do it, but the most straightforward is to simply use the <a href="https://docs.python.org/2/library/pdb.html">Python debugger</a>. Just add following line in to a Django view function:</p> <pre><code>import pdb; pdb.set_trace() </code></pre> <p>If you try to load that page in your bro...
345
2009-07-13T08:29:24Z
[ "python", "django", "debugging" ]
How to debug in Django, the good way?
1,118,183
<p>So, I started learning to code in <a href="http://en.wikipedia.org/wiki/Python%5F%28programming%5Flanguage%29">Python</a> and later <a href="http://en.wikipedia.org/wiki/Django%5F%28web%5Fframework%29">Django</a>. The first times it was hard looking at tracebacks and actually figure out what I did wrong and where th...
378
2009-07-13T07:57:02Z
1,118,273
<p>There are a few tools that cooperate well and can make your debugging task easier.</p> <p>Most important is the <a href="https://github.com/django-debug-toolbar/django-debug-toolbar">Django debug toolbar</a>.</p> <p>Then you need good logging using the Python <a href="http://docs.python.org/library/logging.html#mo...
64
2009-07-13T08:30:07Z
[ "python", "django", "debugging" ]
How to debug in Django, the good way?
1,118,183
<p>So, I started learning to code in <a href="http://en.wikipedia.org/wiki/Python%5F%28programming%5Flanguage%29">Python</a> and later <a href="http://en.wikipedia.org/wiki/Django%5F%28web%5Fframework%29">Django</a>. The first times it was hard looking at tracebacks and actually figure out what I did wrong and where th...
378
2009-07-13T07:57:02Z
1,118,314
<p>I use <a href="http://www.pydev.sourceforge.net/">pyDev</a> with Eclipse really good, set break points, step into code, view values on any objects and variables, try it.</p>
13
2009-07-13T08:40:54Z
[ "python", "django", "debugging" ]
How to debug in Django, the good way?
1,118,183
<p>So, I started learning to code in <a href="http://en.wikipedia.org/wiki/Python%5F%28programming%5Flanguage%29">Python</a> and later <a href="http://en.wikipedia.org/wiki/Django%5F%28web%5Fframework%29">Django</a>. The first times it was hard looking at tracebacks and actually figure out what I did wrong and where th...
378
2009-07-13T07:57:02Z
1,118,360
<p>I really like <a href="http://werkzeug.pocoo.org/">Werkzeug</a>'s interactive debugger. It's similar to Django's debug page, except that you get an interactive shell on every level of the traceback. If you use the <a href="https://github.com/django-extensions/django-extensions">django-extensions</a>, you get a <code...
181
2009-07-13T08:54:44Z
[ "python", "django", "debugging" ]
How to debug in Django, the good way?
1,118,183
<p>So, I started learning to code in <a href="http://en.wikipedia.org/wiki/Python%5F%28programming%5Flanguage%29">Python</a> and later <a href="http://en.wikipedia.org/wiki/Django%5F%28web%5Fframework%29">Django</a>. The first times it was hard looking at tracebacks and actually figure out what I did wrong and where th...
378
2009-07-13T07:57:02Z
2,324,210
<p>A little quickie for template tags:</p> <pre><code>@register.filter def pdb(element): import pdb; pdb.set_trace() return element </code></pre> <p>Now, inside a template you can do <code>{{ template_var|pdb }}</code> and enter a pdb session (given you're running the local devel server) where you can inspec...
138
2010-02-24T06:52:09Z
[ "python", "django", "debugging" ]
How to debug in Django, the good way?
1,118,183
<p>So, I started learning to code in <a href="http://en.wikipedia.org/wiki/Python%5F%28programming%5Flanguage%29">Python</a> and later <a href="http://en.wikipedia.org/wiki/Django%5F%28web%5Fframework%29">Django</a>. The first times it was hard looking at tracebacks and actually figure out what I did wrong and where th...
378
2009-07-13T07:57:02Z
2,324,303
<p>Almost everything has been mentioned so far, so I'll only add that instead of <code>pdb.set_trace()</code> one can use <strong>ipdb.set_trace()</strong> which uses iPython and therefore is more powerful (autocomplete and other goodies). This requires ipdb package, so you only need to <code>pip install ipdb</code></p...
33
2010-02-24T07:25:16Z
[ "python", "django", "debugging" ]
How to debug in Django, the good way?
1,118,183
<p>So, I started learning to code in <a href="http://en.wikipedia.org/wiki/Python%5F%28programming%5Flanguage%29">Python</a> and later <a href="http://en.wikipedia.org/wiki/Django%5F%28web%5Fframework%29">Django</a>. The first times it was hard looking at tracebacks and actually figure out what I did wrong and where th...
378
2009-07-13T07:57:02Z
3,466,951
<p>I use <a href="http://www.jetbrains.com/pycharm/">PyCharm</a> (same pydev engine as eclipse). Really helps me to visually be able to step through my code and see what is happening.</p>
34
2010-08-12T11:07:32Z
[ "python", "django", "debugging" ]
How to debug in Django, the good way?
1,118,183
<p>So, I started learning to code in <a href="http://en.wikipedia.org/wiki/Python%5F%28programming%5Flanguage%29">Python</a> and later <a href="http://en.wikipedia.org/wiki/Django%5F%28web%5Fframework%29">Django</a>. The first times it was hard looking at tracebacks and actually figure out what I did wrong and where th...
378
2009-07-13T07:57:02Z
6,880,214
<p>I've pushed <code>django-pdb</code> to <a href="http://pypi.python.org/pypi/django-pdb">PyPI</a>. It's a simple app that means you don't need to edit your source code every time you want to break into pdb.</p> <p>Installation is just...</p> <ol> <li><code>pip install django-pdb</code></li> <li>Add <code>'django_pd...
21
2011-07-30T00:11:18Z
[ "python", "django", "debugging" ]
How to debug in Django, the good way?
1,118,183
<p>So, I started learning to code in <a href="http://en.wikipedia.org/wiki/Python%5F%28programming%5Flanguage%29">Python</a> and later <a href="http://en.wikipedia.org/wiki/Django%5F%28web%5Fframework%29">Django</a>. The first times it was hard looking at tracebacks and actually figure out what I did wrong and where th...
378
2009-07-13T07:57:02Z
9,154,880
<p>If using Aptana for django development, watch this: <a href="http://www.youtube.com/watch?v=qQh-UQFltJQ" rel="nofollow">http://www.youtube.com/watch?v=qQh-UQFltJQ</a></p> <p>If not, consider using it.</p>
2
2012-02-06T02:05:13Z
[ "python", "django", "debugging" ]
How to debug in Django, the good way?
1,118,183
<p>So, I started learning to code in <a href="http://en.wikipedia.org/wiki/Python%5F%28programming%5Flanguage%29">Python</a> and later <a href="http://en.wikipedia.org/wiki/Django%5F%28web%5Fframework%29">Django</a>. The first times it was hard looking at tracebacks and actually figure out what I did wrong and where th...
378
2009-07-13T07:57:02Z
10,039,794
<p>The easiest way to debug python - especially for programmers that are used to Visual Studio - is using PTVS (Python Tools for Visual Studio). The steps are simple: </p> <ol> <li>Download and install it from <a href="http://pytools.codeplex.com/">http://pytools.codeplex.com/</a> </li> <li>Set breakpoints and press ...
17
2012-04-06T06:09:44Z
[ "python", "django", "debugging" ]
How to debug in Django, the good way?
1,118,183
<p>So, I started learning to code in <a href="http://en.wikipedia.org/wiki/Python%5F%28programming%5Flanguage%29">Python</a> and later <a href="http://en.wikipedia.org/wiki/Django%5F%28web%5Fframework%29">Django</a>. The first times it was hard looking at tracebacks and actually figure out what I did wrong and where th...
378
2009-07-13T07:57:02Z
11,884,452
<p>Most options are alredy mentioned. To print template context, I've created a simple library for that. See <a href="https://github.com/edoburu/django-debugtools" rel="nofollow">https://github.com/edoburu/django-debugtools</a></p> <p>You can use it to print template context without any <code>{% load %}</code> constru...
2
2012-08-09T13:22:54Z
[ "python", "django", "debugging" ]
How to debug in Django, the good way?
1,118,183
<p>So, I started learning to code in <a href="http://en.wikipedia.org/wiki/Python%5F%28programming%5Flanguage%29">Python</a> and later <a href="http://en.wikipedia.org/wiki/Django%5F%28web%5Fframework%29">Django</a>. The first times it was hard looking at tracebacks and actually figure out what I did wrong and where th...
378
2009-07-13T07:57:02Z
15,304,395
<p>I highly recommend epdb (Extended Python Debugger). </p> <p><a href="https://bitbucket.org/dugan/epdb">https://bitbucket.org/dugan/epdb</a></p> <p>One thing I love about epdb for debugging Django or other Python webservers is the epdb.serve() command. This sets a trace and serves this on a local port that you ca...
6
2013-03-08T22:26:24Z
[ "python", "django", "debugging" ]
How to debug in Django, the good way?
1,118,183
<p>So, I started learning to code in <a href="http://en.wikipedia.org/wiki/Python%5F%28programming%5Flanguage%29">Python</a> and later <a href="http://en.wikipedia.org/wiki/Django%5F%28web%5Fframework%29">Django</a>. The first times it was hard looking at tracebacks and actually figure out what I did wrong and where th...
378
2009-07-13T07:57:02Z
17,351,366
<p>I use <a href="http://www.jetbrains.com/pycharm/" rel="nofollow">PyCharm</a> and different debug tools. Also have a nice articles set about easy set up those things for novices. <a href="http://garmoncheg.blogspot.com/2013/06/django-how-to-debug-django.html" rel="nofollow">You may start here.</a> It tells about PDB ...
3
2013-06-27T19:12:02Z
[ "python", "django", "debugging" ]
How to debug in Django, the good way?
1,118,183
<p>So, I started learning to code in <a href="http://en.wikipedia.org/wiki/Python%5F%28programming%5Flanguage%29">Python</a> and later <a href="http://en.wikipedia.org/wiki/Django%5F%28web%5Fframework%29">Django</a>. The first times it was hard looking at tracebacks and actually figure out what I did wrong and where th...
378
2009-07-13T07:57:02Z
17,560,099
<p>I just found wdb (<a href="http://www.rkblog.rk.edu.pl/w/p/debugging-python-code-browser-wdb-debugger/?goback=%2Egde_25827_member_255996401">http://www.rkblog.rk.edu.pl/w/p/debugging-python-code-browser-wdb-debugger/?goback=%2Egde_25827_member_255996401</a>). It has a pretty nice user interface / GUI with all the b...
6
2013-07-09T23:38:42Z
[ "python", "django", "debugging" ]
How to debug in Django, the good way?
1,118,183
<p>So, I started learning to code in <a href="http://en.wikipedia.org/wiki/Python%5F%28programming%5Flanguage%29">Python</a> and later <a href="http://en.wikipedia.org/wiki/Django%5F%28web%5Fframework%29">Django</a>. The first times it was hard looking at tracebacks and actually figure out what I did wrong and where th...
378
2009-07-13T07:57:02Z
17,892,930
<p>Sometimes when I wan to explore around in a particular method and summoning pdb is just too cumbersome, I would add:</p> <pre><code>import IPython; IPython.embed() </code></pre> <p><code>IPython.embed()</code> starts an IPython shell which have access to the local variables from the point where you call it. </p>
6
2013-07-27T00:15:25Z
[ "python", "django", "debugging" ]
How to debug in Django, the good way?
1,118,183
<p>So, I started learning to code in <a href="http://en.wikipedia.org/wiki/Python%5F%28programming%5Flanguage%29">Python</a> and later <a href="http://en.wikipedia.org/wiki/Django%5F%28web%5Fframework%29">Django</a>. The first times it was hard looking at tracebacks and actually figure out what I did wrong and where th...
378
2009-07-13T07:57:02Z
19,250,270
<p>I use <a href="http://www.jetbrains.com/pycharm/">PyCharm</a> and stand by it all the way. It cost me a little but I have to say the advantage that I get out of it is priceless. I tried debugging from console and I do give people a lot of credit who can do that, but for me being able to visually debug my application...
6
2013-10-08T14:18:43Z
[ "python", "django", "debugging" ]
How to debug in Django, the good way?
1,118,183
<p>So, I started learning to code in <a href="http://en.wikipedia.org/wiki/Python%5F%28programming%5Flanguage%29">Python</a> and later <a href="http://en.wikipedia.org/wiki/Django%5F%28web%5Fframework%29">Django</a>. The first times it was hard looking at tracebacks and actually figure out what I did wrong and where th...
378
2009-07-13T07:57:02Z
26,323,570
<p>i highly suggest to use PDB.</p> <pre><code>import pdb pdb.set_trace() </code></pre> <p>You can inspect all the variables values, step in to the function and much more. <a href="https://docs.python.org/2/library/pdb.html" rel="nofollow">https://docs.python.org/2/library/pdb.html</a></p> <p>for checking out the al...
1
2014-10-12T09:14:05Z
[ "python", "django", "debugging" ]
How to debug in Django, the good way?
1,118,183
<p>So, I started learning to code in <a href="http://en.wikipedia.org/wiki/Python%5F%28programming%5Flanguage%29">Python</a> and later <a href="http://en.wikipedia.org/wiki/Django%5F%28web%5Fframework%29">Django</a>. The first times it was hard looking at tracebacks and actually figure out what I did wrong and where th...
378
2009-07-13T07:57:02Z
33,038,237
<p>As mentioned in other posts here - setting breakpoints in your code and walking thru the code to see if it behaves as you expected is a great way to learn something like Django until you have a good sense of how it all behaves - and what your code is doing.</p> <p>To do this I would recommend using WingIde. Just li...
1
2015-10-09T12:24:44Z
[ "python", "django", "debugging" ]
How to debug in Django, the good way?
1,118,183
<p>So, I started learning to code in <a href="http://en.wikipedia.org/wiki/Python%5F%28programming%5Flanguage%29">Python</a> and later <a href="http://en.wikipedia.org/wiki/Django%5F%28web%5Fframework%29">Django</a>. The first times it was hard looking at tracebacks and actually figure out what I did wrong and where th...
378
2009-07-13T07:57:02Z
34,699,590
<p>From my perspective, we could break down common <em>code debugging</em> tasks into three distinct usage patterns:</p> <ol> <li>Something has <strong>raised an exception</strong>: <a href="https://github.com/django-extensions/django-extensions">runserver_plus</a>' Werkzeug debugger to the rescue. The ability to run ...
6
2016-01-09T22:17:57Z
[ "python", "django", "debugging" ]
How to debug in Django, the good way?
1,118,183
<p>So, I started learning to code in <a href="http://en.wikipedia.org/wiki/Python%5F%28programming%5Flanguage%29">Python</a> and later <a href="http://en.wikipedia.org/wiki/Django%5F%28web%5Fframework%29">Django</a>. The first times it was hard looking at tracebacks and actually figure out what I did wrong and where th...
378
2009-07-13T07:57:02Z
38,065,474
<p>An additional suggestion. </p> <p>You can leverage <strong>nosetests</strong> and <strong>pdb</strong> together, rather injecting <code>pdb.set_trace()</code> in your views manually. The advantage is that you can observe error conditions when they first start, potentially in 3rd party code.</p> <p>Here's an erro...
0
2016-06-28T01:01:29Z
[ "python", "django", "debugging" ]
How to debug in Django, the good way?
1,118,183
<p>So, I started learning to code in <a href="http://en.wikipedia.org/wiki/Python%5F%28programming%5Flanguage%29">Python</a> and later <a href="http://en.wikipedia.org/wiki/Django%5F%28web%5Fframework%29">Django</a>. The first times it was hard looking at tracebacks and actually figure out what I did wrong and where th...
378
2009-07-13T07:57:02Z
38,287,020
<p>I like answers I can copy directly. And I like IPython:</p> <pre><code>pip install ipdb </code></pre> <p>In your code:</p> <pre><code>import ipdb; ipdb.set_trace() </code></pre>
1
2016-07-09T22:52:30Z
[ "python", "django", "debugging" ]
How to debug in Django, the good way?
1,118,183
<p>So, I started learning to code in <a href="http://en.wikipedia.org/wiki/Python%5F%28programming%5Flanguage%29">Python</a> and later <a href="http://en.wikipedia.org/wiki/Django%5F%28web%5Fframework%29">Django</a>. The first times it was hard looking at tracebacks and actually figure out what I did wrong and where th...
378
2009-07-13T07:57:02Z
39,866,246
<p>use <code>pdb</code> or <code>ipdb</code>. Diffrence between these two is ipdb supports auto complete.</p> <p>for pdb</p> <pre><code>import pdb pdb.set_trace() </code></pre> <p>for ipdb</p> <pre><code>import ipdb ipdb.set_trace() </code></pre> <p>For executing new line hit <code>n</code> key, for continue hit <...
0
2016-10-05T05:45:53Z
[ "python", "django", "debugging" ]
Is there a way to know which versions of python are supported by my code?
1,118,208
<p>You may know the Windows compliance tool that helps people to know if their code is supported by any version of the MS OS.</p> <p>I am looking something similar for Python. </p> <p>I am writing a lib with Python 2.6 and I realized that it was not compatible with Python 2.5 due to the use of the with keyword. </p> ...
3
2009-07-13T08:05:03Z
1,118,220
<p>In response to <a href="http://stackoverflow.com/questions/804538/tool-to-determine-what-lowest-version-of-python-required">a previous question about this</a>, I wrote <a href="http://github.com/ghewgill/pyqver/tree/master" rel="nofollow">pyqver</a>. If you have any improvements, please feel free to fork and contrib...
7
2009-07-13T08:09:04Z
[ "python", "dependencies", "versioning" ]
Is there a way to know which versions of python are supported by my code?
1,118,208
<p>You may know the Windows compliance tool that helps people to know if their code is supported by any version of the MS OS.</p> <p>I am looking something similar for Python. </p> <p>I am writing a lib with Python 2.6 and I realized that it was not compatible with Python 2.5 due to the use of the with keyword. </p> ...
3
2009-07-13T08:05:03Z
1,118,459
<p>I recommend you rather use automated tests than a code analysis tool.</p> <p>Be aware that there are subtle behaviour changes in the Python standard library that your code may or may not depend upon. For example <code>httplib</code>: When uploading files, it is normal to give the data as a <code>str</code>. In P...
6
2009-07-13T09:24:52Z
[ "python", "dependencies", "versioning" ]
Is there a way to know which versions of python are supported by my code?
1,118,208
<p>You may know the Windows compliance tool that helps people to know if their code is supported by any version of the MS OS.</p> <p>I am looking something similar for Python. </p> <p>I am writing a lib with Python 2.6 and I realized that it was not compatible with Python 2.5 due to the use of the with keyword. </p> ...
3
2009-07-13T08:05:03Z
1,118,558
<p>Python 2.5 can still be saved, since it can use the with keyword:</p> <pre><code>from __future__ import with_statement </code></pre>
0
2009-07-13T09:51:55Z
[ "python", "dependencies", "versioning" ]
List of values to a sound file
1,118,266
<p>Guys, Im trying to engineer in python a way of transforming a list of integer values between 0-255 into representative equivalent tones from 1500-2200Hz. Timing information (at 1200Hz) is given by the (-1),(-2) and (-3) values. I have created a function that generates a .wav file and then call this function with the...
0
2009-07-13T08:27:25Z
1,118,303
<p>Looks like you're trying to reinvent the wheel, be careful... If you want to generate music from arrays then you can have a look at pyaudiere, a simple wrapper upon the audiere library. See the docs for how to open an array but it looks should like this : </p> <pre><code>import audiere d = audiere.open_device() s =...
2
2009-07-13T08:38:44Z
[ "python", "audio" ]
List of values to a sound file
1,118,266
<p>Guys, Im trying to engineer in python a way of transforming a list of integer values between 0-255 into representative equivalent tones from 1500-2200Hz. Timing information (at 1200Hz) is given by the (-1),(-2) and (-3) values. I have created a function that generates a .wav file and then call this function with the...
0
2009-07-13T08:27:25Z
1,120,253
<p>All you need to do is just append the new data on the end of your wav file. So if you haven't closed your file, just keep writing to it, or if you have, reopen it in append mode (<code>w = open(myfile, 'ba')</code>) and write the new data.</p> <p>For this to sound reasonable without clicks and such, the trick will...
0
2009-07-13T15:41:32Z
[ "python", "audio" ]
List of values to a sound file
1,118,266
<p>Guys, Im trying to engineer in python a way of transforming a list of integer values between 0-255 into representative equivalent tones from 1500-2200Hz. Timing information (at 1200Hz) is given by the (-1),(-2) and (-3) values. I have created a function that generates a .wav file and then call this function with the...
0
2009-07-13T08:27:25Z
1,705,021
<p>I'm not sure I understand exactly what you're asking, but I'll try to answer.</p> <p>I wouldn't mess around with the low-level WAV format if I didn't have to. Just use <a href="http://cournape.github.com/audiolab/" rel="nofollow">Audiolab</a> for this.</p> <ol> <li>Initialize an empty <code>song</code> NumPy 1-D ...
0
2009-11-10T00:58:52Z
[ "python", "audio" ]