title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags list |
|---|---|---|---|---|---|---|---|---|---|
What is the difference between isinstance('aaa', basestring) and isinstance('aaa', str)? | 1,979,004 | <pre><code>a='aaaa'
print isinstance(a, basestring)#true
print isinstance(a, str)#true
</code></pre>
| 91 | 2009-12-30T08:02:53Z | 1,979,023 | <p>Really what you're asking is the difference between the basestring and str class.</p>
<p>Str is a class that inherits from basestr. But unicode strings also exist, as could other ones, if you wanted to make one.</p>
<pre><code>>>> a = u'aaaa'
>>> isinstance(a, str)
False
>>> isinstance(... | 4 | 2009-12-30T08:07:13Z | [
"python",
"built-in-types"
] |
What is the difference between isinstance('aaa', basestring) and isinstance('aaa', str)? | 1,979,004 | <pre><code>a='aaaa'
print isinstance(a, basestring)#true
print isinstance(a, str)#true
</code></pre>
| 91 | 2009-12-30T08:02:53Z | 1,979,107 | <p>In Python versions prior to 3.0 there are two kinds of strings "plain strings" and "unicode strings". Plain strings (<code>str</code>) cannot represent characters outside of the Latin alphabet (ignoring details of code pages for simplicity). Unicode strings (<code>unicode</code>) can represent characters from any al... | 239 | 2009-12-30T08:42:08Z | [
"python",
"built-in-types"
] |
how can i escape '\xff\xfe' to a readable string | 1,979,171 | <p>i see a string in this code:</p>
<pre><code>data[:2] == '\xff\xfe'
</code></pre>
<p>i don't know what '\xff\xfe' is,</p>
<p>so i want to escape it ,but not successful</p>
<pre><code>import cgi
print cgi.escape('\xff\xfe')#print \xff\xfe
</code></pre>
<p>how can i get it.</p>
<p>thanks</p>
| 2 | 2009-12-30T09:03:36Z | 1,979,195 | <p>'\xFF' means the byte with the hex value FF. '\xff\xfe' is a byte-order mark: <a href="http://en.wikipedia.org/wiki/Byte%5Forder%5Fmark">http://en.wikipedia.org/wiki/Byte%5Forder%5Fmark</a></p>
<p>You could also represent it as two separate characters but that probably won't tell you anything useful.</p>
| 11 | 2009-12-30T09:10:36Z | [
"python",
"unicode",
"encoding",
"escaping"
] |
how can i escape '\xff\xfe' to a readable string | 1,979,171 | <p>i see a string in this code:</p>
<pre><code>data[:2] == '\xff\xfe'
</code></pre>
<p>i don't know what '\xff\xfe' is,</p>
<p>so i want to escape it ,but not successful</p>
<pre><code>import cgi
print cgi.escape('\xff\xfe')#print \xff\xfe
</code></pre>
<p>how can i get it.</p>
<p>thanks</p>
| 2 | 2009-12-30T09:03:36Z | 1,979,221 | <pre><code>>>> print '\xff\xfe'.encode('string-escape')
\xff\xfe
</code></pre>
| 1 | 2009-12-30T09:17:54Z | [
"python",
"unicode",
"encoding",
"escaping"
] |
how can i escape '\xff\xfe' to a readable string | 1,979,171 | <p>i see a string in this code:</p>
<pre><code>data[:2] == '\xff\xfe'
</code></pre>
<p>i don't know what '\xff\xfe' is,</p>
<p>so i want to escape it ,but not successful</p>
<pre><code>import cgi
print cgi.escape('\xff\xfe')#print \xff\xfe
</code></pre>
<p>how can i get it.</p>
<p>thanks</p>
| 2 | 2009-12-30T09:03:36Z | 1,986,014 | <p>You cannot escape or encode an invalid string.</p>
<p>You should understand that you are working with <strong>strings</strong> and <strong>not byte streams</strong> and there are some characters you cannot accept in them, first of them being <code>0x00</code> - and also your example that is happening to be a <a hre... | -2 | 2009-12-31T16:27:41Z | [
"python",
"unicode",
"encoding",
"escaping"
] |
how can i escape '\xff\xfe' to a readable string | 1,979,171 | <p>i see a string in this code:</p>
<pre><code>data[:2] == '\xff\xfe'
</code></pre>
<p>i don't know what '\xff\xfe' is,</p>
<p>so i want to escape it ,but not successful</p>
<pre><code>import cgi
print cgi.escape('\xff\xfe')#print \xff\xfe
</code></pre>
<p>how can i get it.</p>
<p>thanks</p>
| 2 | 2009-12-30T09:03:36Z | 1,993,047 | <p>What is the connection between "i don't know what '\xff\xfe' is" and "so i want to escape it"? What is the purpose of "escaping" it?</p>
<p>It would help enormously if you gave a little more context than <code>data[:2] == '\xff\xfe'</code> (say a few line before and after) ... however it looks like it is testing wh... | 2 | 2010-01-02T22:11:12Z | [
"python",
"unicode",
"encoding",
"escaping"
] |
What does python print() function actually do? | 1,979,234 | <p>I was looking at this <a href="http://stackoverflow.com/questions/1979171/how-can-i-escape-xff-xfe-to-a-readable-string">question</a> and started wondering what does the <code>print</code> actually do.</p>
<p>I have never found out how to use <code>string.decode()</code> and <code>string.encode()</code> to get an u... | 8 | 2009-12-30T09:20:43Z | 1,979,304 | <p><strong>EDIT:</strong> (Major changes between this edit and the previous one... Note: I'm using Python 2.6.4 on an Ubuntu box.)</p>
<p>Firstly, in my first attempt at an answer, I provided some general information on <code>print</code> and <code>str</code> which I'm going to leave below for the benefit of anybody h... | 8 | 2009-12-30T09:40:57Z | [
"python",
"unicode",
"printing",
"python-2.x"
] |
What does python print() function actually do? | 1,979,234 | <p>I was looking at this <a href="http://stackoverflow.com/questions/1979171/how-can-i-escape-xff-xfe-to-a-readable-string">question</a> and started wondering what does the <code>print</code> actually do.</p>
<p>I have never found out how to use <code>string.decode()</code> and <code>string.encode()</code> to get an u... | 8 | 2009-12-30T09:20:43Z | 1,979,337 | <p><code>print()</code> uses <code>sys.stdout.encoding</code> to determine what the output console can understand and then uses this encoding in the call to <code>str.encode()</code>.</p>
<p>[EDIT] If you <a href="http://svn.python.org/projects/python/branches/release31-maint/Python/bltinmodule.c" rel="nofollow">look ... | 5 | 2009-12-30T09:49:49Z | [
"python",
"unicode",
"printing",
"python-2.x"
] |
What does python print() function actually do? | 1,979,234 | <p>I was looking at this <a href="http://stackoverflow.com/questions/1979171/how-can-i-escape-xff-xfe-to-a-readable-string">question</a> and started wondering what does the <code>print</code> actually do.</p>
<p>I have never found out how to use <code>string.decode()</code> and <code>string.encode()</code> to get an u... | 8 | 2009-12-30T09:20:43Z | 1,981,155 | <pre><code>>>> import sys
>>> a = '\xAA\xBB\xCC'
>>> print(a)
ª»Ã
</code></pre>
<p>All <code>print</code> is doing here is writing raw <strong>bytes</strong> to <code>sys.stdout</code>. The string <code>a</code> is a string of bytes, not Unicode characters.</p>
<blockquote>
<p>Why am I... | 2 | 2009-12-30T16:48:37Z | [
"python",
"unicode",
"printing",
"python-2.x"
] |
What does python print() function actually do? | 1,979,234 | <p>I was looking at this <a href="http://stackoverflow.com/questions/1979171/how-can-i-escape-xff-xfe-to-a-readable-string">question</a> and started wondering what does the <code>print</code> actually do.</p>
<p>I have never found out how to use <code>string.decode()</code> and <code>string.encode()</code> to get an u... | 8 | 2009-12-30T09:20:43Z | 1,982,415 | <pre><code>import sys
source_file_encoding = 'latin-1' # if there is no -*- coding: ... -*- line
a = '\xaa\xbb\xcc' # raw bytes that represent string in source_file_encoding
# print bytes, my terminal tries to interpret it as 'utf-8'
sys.stdout.write(a+'\n')
# -> ��
ua = a.decode(source_file_encoding)
sys.s... | 0 | 2009-12-30T20:49:16Z | [
"python",
"unicode",
"printing",
"python-2.x"
] |
A multi-part/threaded downloader via python? | 1,979,435 | <p>I've seen a few threaded <a href="http://www.artfulcode.net/articles/multi-threading-python/" rel="nofollow">downloaders</a> online, and even a few <a href="http://code.activestate.com/recipes/114217/" rel="nofollow">multi-part downloaders</a> (HTTP).</p>
<p>I haven't seen them together as a class/function.</p>
<p... | 0 | 2009-12-30T10:21:04Z | 1,979,646 | <p><a href="http://www.chrisarndt.de/projects/threadpool/" rel="nofollow">Threadpool</a> by Christopher Arndt may be what you're looking for. I've used <a href="http://chrisarndt.de/projects/threadpool/threadpool.py.html" rel="nofollow">this</a> "easy to use object-oriented thread pool framework" for the exact purpose ... | 1 | 2009-12-30T11:15:08Z | [
"python",
"multithreading",
"download",
"urllib",
"multipart"
] |
Py2exe - win32api.pyc ImportError DLL load failed | 1,979,486 | <p>I am trying to use py2exe to distribute a python application I have written. Everything seems to go OK, but when I run it on another machine it fails with the following error:</p>
<pre><code>Traceback (most recent call last):
File "application.py", line 12, in <module>
File "win32api.pyc", line 12, in &l... | 7 | 2009-12-30T10:32:30Z | 1,980,371 | <p>Try adding win32api to your packages, in the options dictionary.</p>
<p>Here's an example:</p>
<pre><code>excludes = ["pywin", "pywin.debugger"] # there will be more in real life...
options = dict(optimize=2,
dist_dir="build",
excludes=excludes,
packages=["win32api"])
setup(
n... | 0 | 2009-12-30T14:06:25Z | [
"python",
"py2exe"
] |
Py2exe - win32api.pyc ImportError DLL load failed | 1,979,486 | <p>I am trying to use py2exe to distribute a python application I have written. Everything seems to go OK, but when I run it on another machine it fails with the following error:</p>
<pre><code>Traceback (most recent call last):
File "application.py", line 12, in <module>
File "win32api.pyc", line 12, in &l... | 7 | 2009-12-30T10:32:30Z | 1,980,464 | <p>I've seen this problem when the package was built on Vista but executed on XP. The problem turned out to be that py2exe mistakenly added <code>powrprof.dll</code> and <code>mswsock.dll</code> to the package. Windows XP contains its own copies of these files though, and can't load the Vista ones which got installed w... | 29 | 2009-12-30T14:28:00Z | [
"python",
"py2exe"
] |
Py2exe - win32api.pyc ImportError DLL load failed | 1,979,486 | <p>I am trying to use py2exe to distribute a python application I have written. Everything seems to go OK, but when I run it on another machine it fails with the following error:</p>
<pre><code>Traceback (most recent call last):
File "application.py", line 12, in <module>
File "win32api.pyc", line 12, in &l... | 7 | 2009-12-30T10:32:30Z | 3,995,398 | <p>@Wim, I found the bit about "adding this to the options dict in setup.py" a bit confusing. If like me you did not have an options arg in your existing call to setup this might make things clearer:</p>
<pre><code>setup(name='myprog',
...
options={"py2exe":{"dll_excludes":[ "mswsock.dll", "powrprof.d... | 2 | 2010-10-22T09:13:06Z | [
"python",
"py2exe"
] |
Py2exe - win32api.pyc ImportError DLL load failed | 1,979,486 | <p>I am trying to use py2exe to distribute a python application I have written. Everything seems to go OK, but when I run it on another machine it fails with the following error:</p>
<pre><code>Traceback (most recent call last):
File "application.py", line 12, in <module>
File "win32api.pyc", line 12, in &l... | 7 | 2009-12-30T10:32:30Z | 9,599,672 | <p>Just as an added comment. When rebuilding your program with Py2exe be sure to delete the old "dist" directory. I was sitting for over 3 hours not understanding why my app was working on my dev envirnoment and not in production. deleted dist and rebuild with py2exe and it worked.</p>
| 0 | 2012-03-07T10:25:24Z | [
"python",
"py2exe"
] |
Split a database of mol2 molecules into N smaller sets | 1,979,497 | <p>I got a big set of molecules from the zinc database (http://zinc.docking.org/), in mol2 (http://tripos.com/index.php?family=modules,SimplePage,,,&page=sup_mol2&s=0) format. I would like to be able to split this database into an arbitrary set of N smaller databases. What is the best scripting approach in eith... | 3 | 2009-12-30T10:35:56Z | 1,979,639 | <p><code>csplit</code> can separate the file into individual molecules:</p>
<pre><code>csplit ~/Download/zinc.mol2 '/@<TRIPOS>MOLECULE/' '{*}'
</code></pre>
<p>If you want something more clever then you can read each molecule into a list or array as a string and then spit out as many as you like into each file.... | 2 | 2009-12-30T11:12:37Z | [
"python",
"bash"
] |
Split a database of mol2 molecules into N smaller sets | 1,979,497 | <p>I got a big set of molecules from the zinc database (http://zinc.docking.org/), in mol2 (http://tripos.com/index.php?family=modules,SimplePage,,,&page=sup_mol2&s=0) format. I would like to be able to split this database into an arbitrary set of N smaller databases. What is the best scripting approach in eith... | 3 | 2009-12-30T10:35:56Z | 12,115,538 | <p>Here's a way to do this in linux:</p>
<pre><code>gawk -v RS="@<TRIPOS>MOLECULE" 'NF{ print RS$0 > "zinc"++n".mol2" }' zinc.mol2
</code></pre>
| 0 | 2012-08-24T19:31:46Z | [
"python",
"bash"
] |
Python Observer Design Pattern | 1,979,620 | <p>I have two questions:</p>
<ol>
<li><p>I'm trying to implement an Observer design pattern in Python. What is the easiest implementation for that?</p>
<p>I need it to observe the status of machines in a render farm that I'm currently building.</p></li>
<li><p>Are there any good Python design pattern books out there?... | 1 | 2009-12-30T11:05:25Z | 1,979,673 | <p>You can find a discussion on python design patterns in this previous <a href="http://stackoverflow.com/questions/606448/python-design-patterns">question</a>.</p>
<p>An implementation of an observer pattern is given <a href="http://www.suttoncourtenay.org.uk/duncan/accu/pythonpatterns.html#observer" rel="nofollow">h... | 2 | 2009-12-30T11:22:58Z | [
"python",
"design-patterns"
] |
Python Observer Design Pattern | 1,979,620 | <p>I have two questions:</p>
<ol>
<li><p>I'm trying to implement an Observer design pattern in Python. What is the easiest implementation for that?</p>
<p>I need it to observe the status of machines in a render farm that I'm currently building.</p></li>
<li><p>Are there any good Python design pattern books out there?... | 1 | 2009-12-30T11:05:25Z | 1,979,678 | <p>There are already some nice sources of information about <a href="http://www.python.org/workshops/1997-10/proceedings/savikko.html" rel="nofollow">design patterns in Python</a>.</p>
<p><a href="http://rads.stackoverflow.com/amzn/click/0130409561" rel="nofollow">Here's an interesting book</a> on Python design patter... | 7 | 2009-12-30T11:23:48Z | [
"python",
"design-patterns"
] |
Python Observer Design Pattern | 1,979,620 | <p>I have two questions:</p>
<ol>
<li><p>I'm trying to implement an Observer design pattern in Python. What is the easiest implementation for that?</p>
<p>I need it to observe the status of machines in a render farm that I'm currently building.</p></li>
<li><p>Are there any good Python design pattern books out there?... | 1 | 2009-12-30T11:05:25Z | 33,201,367 | <p>Examples of Python implementations of the observer design pattern can be found in the following books:</p>
<ul>
<li>Data formatter: "Every time the value of the default formatter is updated, the registered formatters are notified and take action." [Mastering Python Design Patterns, section "The Observer Pattern" su... | 0 | 2015-10-18T18:01:36Z | [
"python",
"design-patterns"
] |
Loading SQL dump before running Django tests | 1,979,692 | <p>I have a fairly complex Django project which makes it hard/impossible to use fixtures for loading data.</p>
<p>What I would like to do is to load a database dump from the production database server after all tables has bene created by the testrunner and before the actual tests start running.</p>
<p>I've tried vari... | 7 | 2009-12-30T11:27:58Z | 1,980,406 | <p>Fixtures are the best option. Have you tried using ./manage.py dumpdata to create a fixture from your current database? I have not seen that fail on complex models, but I guess it's possible.</p>
<p>Assuming you're using mysql, you should be able to script this by using <a href="http://dev.mysql.com/doc/refman/5.1/... | -1 | 2009-12-30T14:14:04Z | [
"python",
"django",
"django-testing"
] |
Loading SQL dump before running Django tests | 1,979,692 | <p>I have a fairly complex Django project which makes it hard/impossible to use fixtures for loading data.</p>
<p>What I would like to do is to load a database dump from the production database server after all tables has bene created by the testrunner and before the actual tests start running.</p>
<p>I've tried vari... | 7 | 2009-12-30T11:27:58Z | 1,983,339 | <p>You may need to look into defining a custom test runner. There's some info here: <a href="http://docs.djangoproject.com/en/dev/topics/testing/#using-different-testing-frameworks" rel="nofollow">http://docs.djangoproject.com/en/dev/topics/testing/#using-different-testing-frameworks</a></p>
<p>Basically I think you c... | 0 | 2009-12-31T00:37:39Z | [
"python",
"django",
"django-testing"
] |
Loading SQL dump before running Django tests | 1,979,692 | <p>I have a fairly complex Django project which makes it hard/impossible to use fixtures for loading data.</p>
<p>What I would like to do is to load a database dump from the production database server after all tables has bene created by the testrunner and before the actual tests start running.</p>
<p>I've tried vari... | 7 | 2009-12-30T11:27:58Z | 2,589,487 | <p>Django supports loading SQL files when doing syncdb, reset, or starting a test runner -- this does exactly what you describe: </p>
<p><a href="http://docs.djangoproject.com/en/dev/howto/initial-data/#providing-initial-sql-data">http://docs.djangoproject.com/en/dev/howto/initial-data/#providing-initial-sql-data</a><... | 7 | 2010-04-07T01:39:22Z | [
"python",
"django",
"django-testing"
] |
Python dll Extension Import | 1,979,793 | <p>I created extensions for my Python and created a <code>abcPython.dll</code>. How can I import this dll into my Python scripts?</p>
<p>I get an error message when I try to import it usin the following command</p>
<pre class="lang-none prettyprint-override"><code>>>>import abcPython
>>>Traceback (m... | 3 | 2009-12-30T11:51:49Z | 1,979,911 | <p>Follow <a href="http://docs.python.org/extending/windows.html#a-cookbook-approach">Building C and C++ Extensions on Windows</a> carefully - in sub-section 7, it says:</p>
<blockquote>
<p>The output file should be called spam.pyd (in Release mode) or spam_d.pyd (in Debug mode). The <strong>extension .pyd</strong> ... | 10 | 2009-12-30T12:18:52Z | [
"python",
"dll"
] |
Python dll Extension Import | 1,979,793 | <p>I created extensions for my Python and created a <code>abcPython.dll</code>. How can I import this dll into my Python scripts?</p>
<p>I get an error message when I try to import it usin the following command</p>
<pre class="lang-none prettyprint-override"><code>>>>import abcPython
>>>Traceback (m... | 3 | 2009-12-30T11:51:49Z | 2,027,922 | <p>Aarrgghh! Yet another 2.X/3.X gotcha. RTFErrorMessage:</p>
<p><code>ImportError: dynamic module does not define init function (PyInit_abcPython)</code></p>
<p>Note the prefix: it's not <strong>init</strong>, it's <strong>PyInit_</strong></p>
<p>See the <a href="http://docs.python.org/3.1/extending/extending.html#... | 1 | 2010-01-08T13:46:59Z | [
"python",
"dll"
] |
Python dll Extension Import | 1,979,793 | <p>I created extensions for my Python and created a <code>abcPython.dll</code>. How can I import this dll into my Python scripts?</p>
<p>I get an error message when I try to import it usin the following command</p>
<pre class="lang-none prettyprint-override"><code>>>>import abcPython
>>>Traceback (m... | 3 | 2009-12-30T11:51:49Z | 2,271,920 | <p>Simple renaming of .dll to .pyd did not help. I was using SWIG to create the extension module. I created a .pyd instead of creating a .dll module and that solved the issue.</p>
| 1 | 2010-02-16T09:55:06Z | [
"python",
"dll"
] |
Python dll Extension Import | 1,979,793 | <p>I created extensions for my Python and created a <code>abcPython.dll</code>. How can I import this dll into my Python scripts?</p>
<p>I get an error message when I try to import it usin the following command</p>
<pre class="lang-none prettyprint-override"><code>>>>import abcPython
>>>Traceback (m... | 3 | 2009-12-30T11:51:49Z | 24,802,812 | <p>As an example: Imagine you have compiled OpenCV and have several *.dll and the cv2.pyd file.</p>
<p>You need to copy those files to 'DLLs' folder within the python directory.</p>
<p>Then import the module to check wether it is ok.</p>
| 0 | 2014-07-17T11:53:28Z | [
"python",
"dll"
] |
Using Urlllib2.urlopen fails for binary data? | 1,979,934 | <p>I'm using python to programatically download a zip file from a web server. Using a web browser, it's fine. I've written this (partial) script;</p>
<pre><code>response = urllib2.urlopen(url, data, 10)
the_page = response.read()
f = open(filename, 'w')
f.write(the_page)
f.close()
</code></pre>
<p>The request succeed... | 1 | 2009-12-30T12:24:55Z | 1,979,953 | <p>Try opening the file in binary mode:</p>
<pre><code> f = open(filename, 'wb')
</code></pre>
| 8 | 2009-12-30T12:29:03Z | [
"python",
"download",
"urllib2"
] |
Using Urlllib2.urlopen fails for binary data? | 1,979,934 | <p>I'm using python to programatically download a zip file from a web server. Using a web browser, it's fine. I've written this (partial) script;</p>
<pre><code>response = urllib2.urlopen(url, data, 10)
the_page = response.read()
f = open(filename, 'w')
f.write(the_page)
f.close()
</code></pre>
<p>The request succeed... | 1 | 2009-12-30T12:24:55Z | 1,979,956 | <p>You could use the <a href="http://docs.python.org/library/urllib.html#urllib.urlretrieve" rel="nofollow">urlretrieve function</a> for downloading raw binary files.</p>
| 1 | 2009-12-30T12:29:38Z | [
"python",
"download",
"urllib2"
] |
Using Urlllib2.urlopen fails for binary data? | 1,979,934 | <p>I'm using python to programatically download a zip file from a web server. Using a web browser, it's fine. I've written this (partial) script;</p>
<pre><code>response = urllib2.urlopen(url, data, 10)
the_page = response.read()
f = open(filename, 'w')
f.write(the_page)
f.close()
</code></pre>
<p>The request succeed... | 1 | 2009-12-30T12:24:55Z | 10,177,796 | <p>If anyone is running into the same error even with the write-mode set to "wb" make sure you call either "f.flush()" or "f.close()" before attempting to work with the file, otherwise it may not be completely written.</p>
| 0 | 2012-04-16T16:14:25Z | [
"python",
"download",
"urllib2"
] |
django query question | 1,979,951 | <p>Assume I have such simple model:</p>
<pre><code>class Foo(models.Model):
name = models.CharField(max_length=25)
b_date = models.DateField()
</code></pre>
<p>Now assume that my query result from <code>Foo.objects.all()</code> , I retrieve something like this:</p>
<pre><code>[
{'name': 'zed', 'b_date': ... | 1 | 2009-12-30T12:27:47Z | 1,979,964 | <pre><code>Foo.objects.order_by('b_date').values_list('b_date', flat=True)
</code></pre>
| 7 | 2009-12-30T12:30:59Z | [
"python",
"django",
"django-templates",
"django-views"
] |
Python - reading checkboxes | 1,979,986 | <p>I have a few checkboxes with common name and individual variables (ID).
How can I in python read them as list?
Now I'm using </p>
<blockquote>
<p>checkbox= request.POST["common_name"]</p>
</blockquote>
<p>It isn't work properly, checkbox variable store only the last checked box instead of any list or something.<... | 2 | 2009-12-30T12:35:52Z | 1,980,018 | <p>If you were using WebOB, request.POST.getall('common_name') would give you a list of all the POST variables with the name 'common_name'. See the <a href="http://pythonpaste.org/webob/reference.html#query-post-variables" rel="nofollow">WebOB</a> docs for more.</p>
<p>But you aren't - you're using Django. See the <a ... | 6 | 2009-12-30T12:41:28Z | [
"python",
"html",
"django"
] |
Python - reading checkboxes | 1,979,986 | <p>I have a few checkboxes with common name and individual variables (ID).
How can I in python read them as list?
Now I'm using </p>
<blockquote>
<p>checkbox= request.POST["common_name"]</p>
</blockquote>
<p>It isn't work properly, checkbox variable store only the last checked box instead of any list or something.<... | 2 | 2009-12-30T12:35:52Z | 1,980,865 | <pre><code>checkbox = request.POST.getlist("common_name")
</code></pre>
| 2 | 2009-12-30T15:53:23Z | [
"python",
"html",
"django"
] |
Python - reading checkboxes | 1,979,986 | <p>I have a few checkboxes with common name and individual variables (ID).
How can I in python read them as list?
Now I'm using </p>
<blockquote>
<p>checkbox= request.POST["common_name"]</p>
</blockquote>
<p>It isn't work properly, checkbox variable store only the last checked box instead of any list or something.<... | 2 | 2009-12-30T12:35:52Z | 1,989,550 | <p>And if you want to select objects (say Contact objects) based upon the getlist list, you can do this:</p>
<pre><code>selected_ids = request.POST.getlist('_selected_for_action')
object_list = Contact.objects.filter(pk__in=selected_ids)
</code></pre>
| 0 | 2010-01-01T20:32:56Z | [
"python",
"html",
"django"
] |
How to render a doctype with Python's xml.dom.minidom? | 1,980,380 | <p>I tried:</p>
<pre><code>document.doctype = xml.dom.minidom.DocumentType('html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd"')
</code></pre>
<p>There is no doctype in the output. How to fix without inserting it by hand?</p>
| 6 | 2009-12-30T14:08:28Z | 1,980,552 | <p>You shouldn't instantiate classes from <code>minidom</code> directly. It's not a supported part of the API, the <code>ownerDocument</code>âs won't tie up and you can get some strange misbehaviours. Instead use the proper DOM Level 2 Core methods:</p>
<pre><code>>>> imp= minidom.getDOMImplementation('')
&... | 10 | 2009-12-30T14:51:09Z | [
"python",
"xml",
"doctype"
] |
Problem installing MySQLdb on windows - Can't find python | 1,980,454 | <p>I'm trying to install the module mySQLdb on a windows vista 64 (amd) machine.
I've installed python on a different folder other than suggested by Python installer.
When I try to install the .exe mySQLdb installer, it can't find python 2.5 and it halts the installation.</p>
<p>Is there anyway to supply the installer... | 0 | 2009-12-30T14:24:50Z | 2,179,175 | <p>did you use an egg?</p>
<p>if so, python might not be able to find it.</p>
<p>import os,sys
os.environ['PYTHON_EGG_CACHE'] = 'C:/temp'
sys.path.append('C:/path/to/MySQLdb.egg')</p>
| 0 | 2010-02-01T18:46:27Z | [
"python",
"windows-installer",
"mysql"
] |
Is there any reason to use threading.Lock over multiprocessing.Lock? | 1,980,479 | <p>If a software project supports a version of Python that multiprocessing has been backported to, is there any reason to use <code>threading.Lock</code> over <code>multiprocessing.Lock</code>? Would a <code>multiprocessing</code> lock not be thread safe as well?</p>
<p>For that matter, is there a reason to use <em>a... | 7 | 2009-12-30T14:33:21Z | 1,980,503 | <p>I would expect the multi-threading synchronization primitives to be quite faster as they can use shared memory area easily. But I suppose you will have to perform speed test to be sure of it. Also, you might have side-effects that are quite unwanted (and unspecified in the doc).</p>
<p>For example, a process-wise l... | 3 | 2009-12-30T14:39:03Z | [
"python",
"multithreading",
"process",
"locking",
"multiprocessing"
] |
Is there any reason to use threading.Lock over multiprocessing.Lock? | 1,980,479 | <p>If a software project supports a version of Python that multiprocessing has been backported to, is there any reason to use <code>threading.Lock</code> over <code>multiprocessing.Lock</code>? Would a <code>multiprocessing</code> lock not be thread safe as well?</p>
<p>For that matter, is there a reason to use <em>a... | 7 | 2009-12-30T14:33:21Z | 1,980,508 | <p><code>multiprocessing</code> and <code>threading</code> packages have slightly different aims, though both are concurrency related. <code>threading</code> coordinates threads within one process, while <code>multiprocessing</code> provide thread-like interface for coordinating multiple processes.</p>
<p>If your app... | 0 | 2009-12-30T14:39:50Z | [
"python",
"multithreading",
"process",
"locking",
"multiprocessing"
] |
Is there any reason to use threading.Lock over multiprocessing.Lock? | 1,980,479 | <p>If a software project supports a version of Python that multiprocessing has been backported to, is there any reason to use <code>threading.Lock</code> over <code>multiprocessing.Lock</code>? Would a <code>multiprocessing</code> lock not be thread safe as well?</p>
<p>For that matter, is there a reason to use <em>a... | 7 | 2009-12-30T14:33:21Z | 1,980,929 | <p>The threading module's synchronization primitive are lighter and faster than multiprocessing, due to the lack of dealing with shared semaphores, etc. If you are using threads; use threading's locks. Processes should use multiprocessing's locks.</p>
| 11 | 2009-12-30T16:03:58Z | [
"python",
"multithreading",
"process",
"locking",
"multiprocessing"
] |
Django template question | 1,980,600 | <p>How can I achieve this using the Django template system:</p>
<p>Say I have 2 variable passed to the template system:</p>
<pre><code>days=[1,2,3,4,5]
items=[ {name:"apple,day:3},{name:"orange,day:5} ]
</code></pre>
<p>I want to have such output as a table:</p>
<pre><code> 1 2 3 4 5
apple n n... | 1 | 2009-12-30T15:03:10Z | 1,980,658 | <p>Two loops. The outer loop is through <code>items</code>, the inner through <code>days</code>. Test if <code>outer[day]</code> is equal to <code>inner</code>, and output <code>y</code> if so and <code>n</code> if not.</p>
| 2 | 2009-12-30T15:14:10Z | [
"python",
"django",
"django-templates"
] |
Django template question | 1,980,600 | <p>How can I achieve this using the Django template system:</p>
<p>Say I have 2 variable passed to the template system:</p>
<pre><code>days=[1,2,3,4,5]
items=[ {name:"apple,day:3},{name:"orange,day:5} ]
</code></pre>
<p>I want to have such output as a table:</p>
<pre><code> 1 2 3 4 5
apple n n... | 1 | 2009-12-30T15:03:10Z | 1,980,680 | <p>Why don't you define this logic in the django view, and then simply pass arrays of Ys and Ns to the template?</p>
| 6 | 2009-12-30T15:17:13Z | [
"python",
"django",
"django-templates"
] |
Django template question | 1,980,600 | <p>How can I achieve this using the Django template system:</p>
<p>Say I have 2 variable passed to the template system:</p>
<pre><code>days=[1,2,3,4,5]
items=[ {name:"apple,day:3},{name:"orange,day:5} ]
</code></pre>
<p>I want to have such output as a table:</p>
<pre><code> 1 2 3 4 5
apple n n... | 1 | 2009-12-30T15:03:10Z | 1,980,799 | <p>Here's what Ignacio meant. That said, I probably agree with Daniel that you should do this in the view.</p>
<pre><code><table>
{% for item in items %}
<tr>
<td>{% item.name %}</td>
{% for dday in days %}
<td>
{% ifequal dday item.day %}y{% else %}n{% endifequal %}
... | 6 | 2009-12-30T15:39:17Z | [
"python",
"django",
"django-templates"
] |
Loading an image in Python (Error) | 1,981,138 | <p>I want to load an image but I get an error-message.</p>
<p>My code:</p>
<pre><code>from PIL import Image
im = Image.open("D:\Python26\PYTHON-PROGRAMME\bild.jpg")
im.show()
</code></pre>
<p>I get this error:</p>
<pre><code>Traceback (most recent call last):
File "D:\Python26\PYTHON-PROGRAMME\00000000000000000",... | 3 | 2009-12-30T16:44:29Z | 1,981,148 | <p>You need to escape the backslashes:</p>
<pre><code>im = Image.open("D:\\Python26\\PYTHON-PROGRAMME\\bild.jpg")
</code></pre>
| 9 | 2009-12-30T16:46:28Z | [
"python",
"image"
] |
Protection from accidentally misnaming object attributes in Python? | 1,981,208 | <p>A friend was "burned" when starting to learn Python, and now sees the language as <strike>perhaps fatally</strike> flawed.</p>
<p>He was using a library and changed the value of an object's attribute (the class being in the library), but he used the wrong abbreviation for the attribute name. It took him "forever" ... | 4 | 2009-12-30T16:59:16Z | 1,981,231 | <p>A tool like <a href="http://www.logilab.org/857" rel="nofollow" title="pylint">pylint</a> or <a href="http://pychecker.sourceforge.net/" rel="nofollow">pychecker</a> may be able to detect this.</p>
| 2 | 2009-12-30T17:04:05Z | [
"python",
"attributes"
] |
Protection from accidentally misnaming object attributes in Python? | 1,981,208 | <p>A friend was "burned" when starting to learn Python, and now sees the language as <strike>perhaps fatally</strike> flawed.</p>
<p>He was using a library and changed the value of an object's attribute (the class being in the library), but he used the wrong abbreviation for the attribute name. It took him "forever" ... | 4 | 2009-12-30T16:59:16Z | 1,981,235 | <p>There are code analyzers like <a href="http://www.logilab.org/857" rel="nofollow">pylint</a> that will warn you if you add a attribute outside of <code>__init__</code>. PyDev has nice support for it. Such errors are very easy to find with a debugger too.</p>
| 7 | 2009-12-30T17:04:20Z | [
"python",
"attributes"
] |
Protection from accidentally misnaming object attributes in Python? | 1,981,208 | <p>A friend was "burned" when starting to learn Python, and now sees the language as <strike>perhaps fatally</strike> flawed.</p>
<p>He was using a library and changed the value of an object's attribute (the class being in the library), but he used the wrong abbreviation for the attribute name. It took him "forever" ... | 4 | 2009-12-30T16:59:16Z | 1,981,255 | <p>If the possibility to make mistakes is enough for him to consider a language "fatally flawed", I don't think you can convince him otherwise. The more you can do with a language, the more you can do <em>wrong</em> with the language. It's a caveat of flexibility—but that's true for any language.</p>
| 5 | 2009-12-30T17:10:34Z | [
"python",
"attributes"
] |
Protection from accidentally misnaming object attributes in Python? | 1,981,208 | <p>A friend was "burned" when starting to learn Python, and now sees the language as <strike>perhaps fatally</strike> flawed.</p>
<p>He was using a library and changed the value of an object's attribute (the class being in the library), but he used the wrong abbreviation for the attribute name. It took him "forever" ... | 4 | 2009-12-30T16:59:16Z | 1,981,269 | <p>I had a similar bad experience with Python when I first started ... took me 3 months to get over it. Having a tool which warns would be nice back then ...</p>
| 0 | 2009-12-30T17:13:38Z | [
"python",
"attributes"
] |
Protection from accidentally misnaming object attributes in Python? | 1,981,208 | <p>A friend was "burned" when starting to learn Python, and now sees the language as <strike>perhaps fatally</strike> flawed.</p>
<p>He was using a library and changed the value of an object's attribute (the class being in the library), but he used the wrong abbreviation for the attribute name. It took him "forever" ... | 4 | 2009-12-30T16:59:16Z | 1,981,279 | <p>"changed the value of an object's attribute" Can lead to problems. This is pretty well known. You know it, now, also. That doesn't indict the language. It simply says that you've learned an important lesson in dynamic language programming.</p>
<ol>
<li><p>Unit testing absolutely discovers this. You are not fo... | 11 | 2009-12-30T17:14:56Z | [
"python",
"attributes"
] |
Protection from accidentally misnaming object attributes in Python? | 1,981,208 | <p>A friend was "burned" when starting to learn Python, and now sees the language as <strike>perhaps fatally</strike> flawed.</p>
<p>He was using a library and changed the value of an object's attribute (the class being in the library), but he used the wrong abbreviation for the attribute name. It took him "forever" ... | 4 | 2009-12-30T16:59:16Z | 1,981,288 | <p>He's effectively ruling out an entire class of programming languages -- dynamically-typed languages -- because of one hard lesson learned. He can use only statically-typed languages if he wishes and still have a very productive career as a programmer, but he is certainly going to have deep frustrations with them as ... | 1 | 2009-12-30T17:16:09Z | [
"python",
"attributes"
] |
Protection from accidentally misnaming object attributes in Python? | 1,981,208 | <p>A friend was "burned" when starting to learn Python, and now sees the language as <strike>perhaps fatally</strike> flawed.</p>
<p>He was using a library and changed the value of an object's attribute (the class being in the library), but he used the wrong abbreviation for the attribute name. It took him "forever" ... | 4 | 2009-12-30T16:59:16Z | 1,981,378 | <p>I think your friend has misplaced his frustration in the language. His real problem is lack of debugging techniques. teach him how to break down a program into small pieces to examine the output. like a manual unit test, this way any inconsistency is found and any assumptions are proven or discarded.</p>
| 1 | 2009-12-30T17:33:26Z | [
"python",
"attributes"
] |
Protection from accidentally misnaming object attributes in Python? | 1,981,208 | <p>A friend was "burned" when starting to learn Python, and now sees the language as <strike>perhaps fatally</strike> flawed.</p>
<p>He was using a library and changed the value of an object's attribute (the class being in the library), but he used the wrong abbreviation for the attribute name. It took him "forever" ... | 4 | 2009-12-30T16:59:16Z | 1,981,553 | <p>You can use the <code>__slots__</code> class attribute to limit the attributes that instances have. Attempting to set an attribute that's not expliticly listed will raise an <code>AttributeError</code>. There are some complications that arise with subclassing. See the <a href="http://docs.python.org/reference/datamo... | 5 | 2009-12-30T18:06:49Z | [
"python",
"attributes"
] |
Loading an image in Python (Error) part_2 | 1,981,335 | <p>This code didn't show my picture. The picture really exists :)
Does anybody know why this doesnt work?
Thanks in advance!</p>
<pre><code>from PIL import Image
im = Image.open("D:\\Python26\\PYTHON-PROGRAMME\\bild.jpg")
im.show()
</code></pre>
| 0 | 2009-12-30T17:26:07Z | 1,981,360 | <p>You probably need to call the load() method to force the open() method to do its work. open is lazy.</p>
<p>Try:</p>
<pre><code>from PIL import Image
im = Image.open("D:\\Python26\\PYTHON-PROGRAMME\\bild.jpg")
im.load()
im.show()
</code></pre>
<p>Idea #2:
Patch PIL's file Image.py to have a potentially more robus... | 1 | 2009-12-30T17:30:38Z | [
"python",
"image"
] |
How to tell if Python SQLite database connection or cursor is closed? | 1,981,392 | <p>Let's say that you have the following code:</p>
<pre><code>import sqlite3
conn = sqlite3.connect('mydb')
cur = conn.cursor()
# some database actions
cur.close()
conn.close()
# more code below
</code></pre>
<p>If I try to use the <code>conn</code> or <code>cur</code> objects later on, how could I tell that they ar... | 7 | 2009-12-30T17:36:54Z | 1,981,584 | <p>You could wrap in a <code>try, except</code> statement:</p>
<pre><code>>>> conn = sqlite3.connect('mydb')
>>> conn.close()
>>> try:
... resultset = conn.execute("SELECT 1 FROM my_table LIMIT 1;")
... except sqlite3.ProgrammingError as e:
... print e
Cannot operate on a closed database... | 8 | 2009-12-30T18:10:26Z | [
"python",
"sqlite",
"sqlite3",
"database-connection"
] |
How to tell if Python SQLite database connection or cursor is closed? | 1,981,392 | <p>Let's say that you have the following code:</p>
<pre><code>import sqlite3
conn = sqlite3.connect('mydb')
cur = conn.cursor()
# some database actions
cur.close()
conn.close()
# more code below
</code></pre>
<p>If I try to use the <code>conn</code> or <code>cur</code> objects later on, how could I tell that they ar... | 7 | 2009-12-30T17:36:54Z | 1,981,802 | <p>How about making sure that the connection and cursor are never closed?</p>
<p>You could have a state based program that you can guarantee only calls close() at the right time.</p>
<p>Or wrap them in other objects that have a pass implementation of <code>close()</code>. Or add an <code>_isclosed</code> member set ... | 0 | 2009-12-30T18:54:28Z | [
"python",
"sqlite",
"sqlite3",
"database-connection"
] |
Errors accessing .NET class method overloads in IronPython | 1,981,566 | <p>I have a class I've written in C#. The class has two methods, the signatures being:</p>
<pre><code>bool Navigate(string url)
bool Navigate(Uri url)
</code></pre>
<p>From what I gather, the IronPython runtime is supposed to try and select the best overload based on the passed-in argument. In my case, I'm passing in... | 18 | 2009-12-30T18:08:12Z | 13,215,013 | <p>It sounds like somehow IronPython is deciding that it can convert strings to <code>Uri</code>s. Perhaps this is a "feature", I don't know. You could do something like the following (<a href="http://ironpython.net/documentation/dotnet/dotnet.html#method-overloads" rel="nofollow">source</a>):</p>
<pre><code>navigate_... | 3 | 2012-11-04T00:46:54Z | [
"python",
"ironpython"
] |
Django, grouping query items | 1,981,718 | <p>say I have such model:</p>
<pre><code>class Foo(models.Model):
name = models.CharField("name",max_length=25)
type = models.IntegerField("type number")
</code></pre>
<p>after doing some query like Foo.objects.filter(), I want to group the query result as such:</p>
<pre><code>[ [{"name":"jb","type:"whiskey"},{"n... | 1 | 2009-12-30T18:38:10Z | 1,981,813 | <p>You can do this with the <code>values</code> method of a queryset:</p>
<p><a href="http://docs.djangoproject.com/en/1.1/ref/models/querysets/#values-fields" rel="nofollow">http://docs.djangoproject.com/en/1.1/ref/models/querysets/#values-fields</a></p>
<blockquote>
<p>values(*fields)</p>
<p>Returns a Values... | 3 | 2009-12-30T18:56:43Z | [
"python",
"django",
"django-models",
"django-views"
] |
Django, grouping query items | 1,981,718 | <p>say I have such model:</p>
<pre><code>class Foo(models.Model):
name = models.CharField("name",max_length=25)
type = models.IntegerField("type number")
</code></pre>
<p>after doing some query like Foo.objects.filter(), I want to group the query result as such:</p>
<pre><code>[ [{"name":"jb","type:"whiskey"},{"n... | 1 | 2009-12-30T18:38:10Z | 1,981,823 | <p>You can sort of do this by using order_by:</p>
<pre><code>Foo.objects.order_by( "type" );
drinks = Foo.objects.all( )
</code></pre>
<p>Now you have an array of drinks ordered by type. You could use this or write a function to create the structure you want without having to sort it with a linear scan.</p>
| 1 | 2009-12-30T18:59:28Z | [
"python",
"django",
"django-models",
"django-views"
] |
Django, grouping query items | 1,981,718 | <p>say I have such model:</p>
<pre><code>class Foo(models.Model):
name = models.CharField("name",max_length=25)
type = models.IntegerField("type number")
</code></pre>
<p>after doing some query like Foo.objects.filter(), I want to group the query result as such:</p>
<pre><code>[ [{"name":"jb","type:"whiskey"},{"n... | 1 | 2009-12-30T18:38:10Z | 1,981,889 | <p>Check out the <a href="http://docs.djangoproject.com/en/1.1/ref/templates/builtins/#regroup" rel="nofollow">regroup</a> template tag. If you want to do the grouping for display in your template then this should be what you need. Otherwise you can read the source to see how they accomplish the grouping.</p>
| 2 | 2009-12-30T19:12:18Z | [
"python",
"django",
"django-models",
"django-views"
] |
Django, grouping query items | 1,981,718 | <p>say I have such model:</p>
<pre><code>class Foo(models.Model):
name = models.CharField("name",max_length=25)
type = models.IntegerField("type number")
</code></pre>
<p>after doing some query like Foo.objects.filter(), I want to group the query result as such:</p>
<pre><code>[ [{"name":"jb","type:"whiskey"},{"n... | 1 | 2009-12-30T18:38:10Z | 1,982,864 | <p>You can do the grouping in your view by using <code>itertools.groupby()</code>.</p>
| 2 | 2009-12-30T22:25:56Z | [
"python",
"django",
"django-models",
"django-views"
] |
What makes pylint think my class is abstract? | 1,981,978 | <p>As I understand it, Python (2.5.2) does not have real support for abstract classes. Why is pylint complaining about this class being an "Abstract class not reference?" Will it do this for any class that has <code>NotImplementedError</code> thrown?</p>
<p>I have each class in its own file so if this is the case I gu... | 5 | 2009-12-30T19:31:38Z | 1,982,269 | <p>In my experience, pylint is a bit over-zealous, and isn't useful until you've turned off a number of the warnings.</p>
| 1 | 2009-12-30T20:23:09Z | [
"python",
"pylint"
] |
What makes pylint think my class is abstract? | 1,981,978 | <p>As I understand it, Python (2.5.2) does not have real support for abstract classes. Why is pylint complaining about this class being an "Abstract class not reference?" Will it do this for any class that has <code>NotImplementedError</code> thrown?</p>
<p>I have each class in its own file so if this is the case I gu... | 5 | 2009-12-30T19:31:38Z | 1,982,807 | <p>FWIW, raising NotImplementedError is enough to make pylint think this is an abstract class (which is absolutely correct). from logilab.org/card/pylintfeatures: W0223: Method %r is abstract in class %r but is not overridden Used when an abstract method (ie raise NotImplementedError) is not overridden in concrete cla... | 11 | 2009-12-30T22:10:12Z | [
"python",
"pylint"
] |
nesting python list comprehensions to construct a list of lists | 1,982,134 | <p>I'm a python newb and am having trouble groking nested list comprehensions. I'm trying to write some code to read in a file and construct a list for each character for each line.</p>
<p>so if the file contains</p>
<pre><code>xxxcd
cdcdjkhjasld
asdasdxasda
</code></pre>
<p>The resulting list would be:</p>
<p>[<... | 1 | 2009-12-30T20:00:16Z | 1,982,162 | <pre><code>data = [list(line.strip().upper()) for line in open(file,'r')]
</code></pre>
| 1 | 2009-12-30T20:05:38Z | [
"python",
"list-comprehension"
] |
nesting python list comprehensions to construct a list of lists | 1,982,134 | <p>I'm a python newb and am having trouble groking nested list comprehensions. I'm trying to write some code to read in a file and construct a list for each character for each line.</p>
<p>so if the file contains</p>
<pre><code>xxxcd
cdcdjkhjasld
asdasdxasda
</code></pre>
<p>The resulting list would be:</p>
<p>[<... | 1 | 2009-12-30T20:00:16Z | 1,982,165 | <p>Here is one level of list comprehension.</p>
<pre><code>data = []
f = open(file,'r')
for line in f:
data.append([ch for ch in line.strip().upper()])
</code></pre>
<p>But we can do the whole thing on one go:</p>
<pre><code>f = open(file, 'rt')
data = [list(line.strip().upper()) for line in f]
</code></pre>
<... | 1 | 2009-12-30T20:05:54Z | [
"python",
"list-comprehension"
] |
nesting python list comprehensions to construct a list of lists | 1,982,134 | <p>I'm a python newb and am having trouble groking nested list comprehensions. I'm trying to write some code to read in a file and construct a list for each character for each line.</p>
<p>so if the file contains</p>
<pre><code>xxxcd
cdcdjkhjasld
asdasdxasda
</code></pre>
<p>The resulting list would be:</p>
<p>[<... | 1 | 2009-12-30T20:00:16Z | 1,982,169 | <p>This should help (you'll probably have to play around with it to strip the newlines or format it however you want, but the basic idea should work):</p>
<pre><code>f = open(r"temp.txt")
[[c for c in line] for line in f]
</code></pre>
| 12 | 2009-12-30T20:06:25Z | [
"python",
"list-comprehension"
] |
nesting python list comprehensions to construct a list of lists | 1,982,134 | <p>I'm a python newb and am having trouble groking nested list comprehensions. I'm trying to write some code to read in a file and construct a list for each character for each line.</p>
<p>so if the file contains</p>
<pre><code>xxxcd
cdcdjkhjasld
asdasdxasda
</code></pre>
<p>The resulting list would be:</p>
<p>[<... | 1 | 2009-12-30T20:00:16Z | 1,982,171 | <p>First off you could combine the line.strip().upper() part with your outer for-loop, like this:</p>
<pre><code>for line in [l.strip().upper() for l in f]:
# do stuff
</code></pre>
<p>Then you could make the iteration over the characters into a list comprehension, but it wouldn't be shorter or clearer. The neate... | 0 | 2009-12-30T20:06:33Z | [
"python",
"list-comprehension"
] |
nesting python list comprehensions to construct a list of lists | 1,982,134 | <p>I'm a python newb and am having trouble groking nested list comprehensions. I'm trying to write some code to read in a file and construct a list for each character for each line.</p>
<p>so if the file contains</p>
<pre><code>xxxcd
cdcdjkhjasld
asdasdxasda
</code></pre>
<p>The resulting list would be:</p>
<p>[<... | 1 | 2009-12-30T20:00:16Z | 1,982,175 | <pre><code>>>> f = file('teste.txt')
>>> print map(lambda x: [c for c in x][:-1], f)
[['x', 'x', 'x', 'c', 'd'], ['c', 'd', 'c', 'd', 'j', 'k', 'h', 'j', 'a', 's', 'l', 'd'], ['a', 's', 'd', 'a', 's', 'd', 'x', 'a', 's', 'd']]
</code></pre>
| 0 | 2009-12-30T20:07:33Z | [
"python",
"list-comprehension"
] |
nesting python list comprehensions to construct a list of lists | 1,982,134 | <p>I'm a python newb and am having trouble groking nested list comprehensions. I'm trying to write some code to read in a file and construct a list for each character for each line.</p>
<p>so if the file contains</p>
<pre><code>xxxcd
cdcdjkhjasld
asdasdxasda
</code></pre>
<p>The resulting list would be:</p>
<p>[<... | 1 | 2009-12-30T20:00:16Z | 1,982,177 | <p>In your case, you can use the <code>list</code> constructor to handle the inner loop and use list comprehension for the outer loop. Something like:</p>
<pre><code>f = open(file)
data = [list(line.strip().upper()) for line in f]
</code></pre>
<p>Given a string as input, the list constructor will create a list where... | 3 | 2009-12-30T20:07:41Z | [
"python",
"list-comprehension"
] |
nesting python list comprehensions to construct a list of lists | 1,982,134 | <p>I'm a python newb and am having trouble groking nested list comprehensions. I'm trying to write some code to read in a file and construct a list for each character for each line.</p>
<p>so if the file contains</p>
<pre><code>xxxcd
cdcdjkhjasld
asdasdxasda
</code></pre>
<p>The resulting list would be:</p>
<p>[<... | 1 | 2009-12-30T20:00:16Z | 1,982,315 | <p>The only really significant difference between strings and lists of characters is that strings are immutable. You can iterate over and slice strings just as you would lists. And it's much more convenient to handle strings as strings, since they support string methods and lists don't.</p>
<p>So for most applicatio... | 1 | 2009-12-30T20:29:54Z | [
"python",
"list-comprehension"
] |
What's the best way to set up symbolic links to current installs, e.g python -> python2.6 | 1,982,176 | <p>What's the best way to set up symbolic links to current installs, e.g python -> python2.6?</p>
<p>I've just installed python2.6 through Macports at /opt/local/bin/python2.6, I'd now like to set up a symbolic link called python here /usr/local/bin/. I then want to be able to add this line at the beginning of my pyt... | 3 | 2009-12-30T20:07:38Z | 1,982,413 | <p>Symlink the version you use most.</p>
<p>When you need another version, run it by specifying the version number, e.g.:</p>
<pre><code>$ python2.5 dev_appserver.py myapp
</code></pre>
| 1 | 2009-12-30T20:49:01Z | [
"python",
"osx",
"macports"
] |
What's the best way to set up symbolic links to current installs, e.g python -> python2.6 | 1,982,176 | <p>What's the best way to set up symbolic links to current installs, e.g python -> python2.6?</p>
<p>I've just installed python2.6 through Macports at /opt/local/bin/python2.6, I'd now like to set up a symbolic link called python here /usr/local/bin/. I then want to be able to add this line at the beginning of my pyt... | 3 | 2009-12-30T20:07:38Z | 1,982,421 | <p>Not sure about OSX, here is what I do on Ubuntu 9.04:</p>
<pre><code>>which python
#/usr/bin/python
</code></pre>
<p>Just replace that file with a sym link to the version of Python you actually want to use:</p>
<pre><code>>sudo ln -s /usr/bin/python2.6/python /usr/bin/python
</code></pre>
| -3 | 2009-12-30T20:50:44Z | [
"python",
"osx",
"macports"
] |
What's the best way to set up symbolic links to current installs, e.g python -> python2.6 | 1,982,176 | <p>What's the best way to set up symbolic links to current installs, e.g python -> python2.6?</p>
<p>I've just installed python2.6 through Macports at /opt/local/bin/python2.6, I'd now like to set up a symbolic link called python here /usr/local/bin/. I then want to be able to add this line at the beginning of my pyt... | 3 | 2009-12-30T20:07:38Z | 1,982,729 | <p>By default, MacPorts deliberately and carefully installs everything into a separate directory space: <code>/opt/local</code>. This ensures it does not conflict with anything installed as part of OS X or third-parties. To ensure that MacPorts-installed executables are found first, the recommended solution is to mod... | 4 | 2009-12-30T21:55:36Z | [
"python",
"osx",
"macports"
] |
Spam Filtering Forms Without Akismet | 1,982,277 | <p>I'm curious if anyone out there knows of something perhaps like Akismet, but where content doesn't have to go off to a 3rd party server. In a situation with critically sensitive data (patient records for instance) I wouldn't necessarily want that information sent off to another server I don't have control over. I re... | 4 | 2009-12-30T20:24:59Z | 1,982,325 | <p>Have you looked at <a href="http://www.projecthoneypot.org/home.php" rel="nofollow">Project Honey Pot</a>? I think they have some public querying services that you can use.</p>
<p>I think Project Honey Pot aims is to stop spam before it evens gets to your content processing routine (IP checking/headers analyzing/bo... | 4 | 2009-12-30T20:32:03Z | [
"python",
"django",
"spam-prevention"
] |
Spam Filtering Forms Without Akismet | 1,982,277 | <p>I'm curious if anyone out there knows of something perhaps like Akismet, but where content doesn't have to go off to a 3rd party server. In a situation with critically sensitive data (patient records for instance) I wouldn't necessarily want that information sent off to another server I don't have control over. I re... | 4 | 2009-12-30T20:24:59Z | 1,983,179 | <p>I can't think of any <strong>critically sensitive</strong> data that could be submitted by anonymous users. If the data is really sensitive (like you mentioned patient records), it is probably submitted by known and registered user so you should do manual approval of new users and protect the registration part from ... | 1 | 2009-12-30T23:56:26Z | [
"python",
"django",
"spam-prevention"
] |
iPhone client with a python socket | 1,982,375 | <p>i am creating a python server socket that sends data to the client reguarding files status... what i have is a list containing dictionaries:</p>
<pre><code>[{'Status': '[2,5%]', 'File': 'SlackwareDVD.iso'},
{'Status': '[21,8%]', 'File': 'Ubuntu_x86.iso'}]
</code></pre>
<p>the socket, when asked, sends this data, ... | 1 | 2009-12-30T20:41:00Z | 1,982,424 | <p>Convert it to an XML property list and Cocoa will do the rest. </p>
| 1 | 2009-12-30T20:51:15Z | [
"iphone",
"python",
"objective-c",
"sockets",
"string"
] |
iPhone client with a python socket | 1,982,375 | <p>i am creating a python server socket that sends data to the client reguarding files status... what i have is a list containing dictionaries:</p>
<pre><code>[{'Status': '[2,5%]', 'File': 'SlackwareDVD.iso'},
{'Status': '[21,8%]', 'File': 'Ubuntu_x86.iso'}]
</code></pre>
<p>the socket, when asked, sends this data, ... | 1 | 2009-12-30T20:41:00Z | 1,982,437 | <p>Assuming you have access to the python codebase, generating an XML Property List is trivial from Python.</p>
<p>See Understanding <a href="http://developer.apple.com/mac/library/documentation/cocoa/Conceptual/PropertyLists/UnderstandXMLPlist/UnderstandXMLPlist.html#//apple%5Fref/doc/uid/10000048i-CH6-SW1" rel="nofo... | 0 | 2009-12-30T20:55:05Z | [
"iphone",
"python",
"objective-c",
"sockets",
"string"
] |
iPhone client with a python socket | 1,982,375 | <p>i am creating a python server socket that sends data to the client reguarding files status... what i have is a list containing dictionaries:</p>
<pre><code>[{'Status': '[2,5%]', 'File': 'SlackwareDVD.iso'},
{'Status': '[21,8%]', 'File': 'Ubuntu_x86.iso'}]
</code></pre>
<p>the socket, when asked, sends this data, ... | 1 | 2009-12-30T20:41:00Z | 1,982,534 | <p>A binary way to transport common types is using the <a href="http://hessian.caucho.com/" rel="nofollow">Hessian</a> protocol which is available for the iPhone <a href="http://sourceforge.net/projects/hessiankit/" rel="nofollow">here</a>. I'm not sure what the status of the python implementations are, I can find two ... | 1 | 2009-12-30T21:14:06Z | [
"iphone",
"python",
"objective-c",
"sockets",
"string"
] |
iPhone client with a python socket | 1,982,375 | <p>i am creating a python server socket that sends data to the client reguarding files status... what i have is a list containing dictionaries:</p>
<pre><code>[{'Status': '[2,5%]', 'File': 'SlackwareDVD.iso'},
{'Status': '[21,8%]', 'File': 'Ubuntu_x86.iso'}]
</code></pre>
<p>the socket, when asked, sends this data, ... | 1 | 2009-12-30T20:41:00Z | 1,984,300 | <p>Seems perfectly suited for <a href="http://json.org/" rel="nofollow">JSON</a>. On the python side use any of the popular json libraries - for example, <a href="http://www.undefined.org/python/" rel="nofollow">simplejson</a> - to convert your python data to json, and on the iPhone side use an iPhone json library to c... | 3 | 2009-12-31T06:59:32Z | [
"iphone",
"python",
"objective-c",
"sockets",
"string"
] |
Does Python 3 have LDAP module? | 1,982,442 | <p>I am porting some Java code to Python and we would like to use Python 3 but I can't find LDAP module for Python 3 in Windows.</p>
<p>This is forcing us to use 2.6 version and it is bothersome as rest of the code is already in 3.0 format.</p>
| 8 | 2009-12-30T20:56:47Z | 1,982,479 | <p>Sorry to break this on you, but I don't think there is a <code>python-ldap</code> for Python 3 (yet)...</p>
<p>That's the reason why we should keep active development at Python 2.6 for now (as long as most crucial dependencies (libs) are not ported to 3.0).</p>
| 0 | 2009-12-30T21:02:51Z | [
"python",
"ldap",
"python-3.x"
] |
Does Python 3 have LDAP module? | 1,982,442 | <p>I am porting some Java code to Python and we would like to use Python 3 but I can't find LDAP module for Python 3 in Windows.</p>
<p>This is forcing us to use 2.6 version and it is bothersome as rest of the code is already in 3.0 format.</p>
| 8 | 2009-12-30T20:56:47Z | 1,986,019 | <p>If you're running this on Windows, you can get LDAP to work in Python 3.1 by using the ADO access method via Mark Hammond's PyWin32.</p>
<p>To test this, I installed ActiveState Python 3.1, then installed PyWin32 for Python 3.1</p>
<p><a href="http://sourceforge.net/projects/pywin32/files/" rel="nofollow">http://s... | 1 | 2009-12-31T16:28:13Z | [
"python",
"ldap",
"python-3.x"
] |
Does Python 3 have LDAP module? | 1,982,442 | <p>I am porting some Java code to Python and we would like to use Python 3 but I can't find LDAP module for Python 3 in Windows.</p>
<p>This is forcing us to use 2.6 version and it is bothersome as rest of the code is already in 3.0 format.</p>
| 8 | 2009-12-30T20:56:47Z | 1,986,136 | <p>There is a Pure Python implementation of an LDAP client called <a href="http://webmail.inoi.fi/open/trac/ldaptor" rel="nofollow">Ldaptor</a>. I don't think it's maintained though. If you really need it, you might be able to run 2to3 on this and port it.</p>
| 0 | 2009-12-31T16:52:53Z | [
"python",
"ldap",
"python-3.x"
] |
Does Python 3 have LDAP module? | 1,982,442 | <p>I am porting some Java code to Python and we would like to use Python 3 but I can't find LDAP module for Python 3 in Windows.</p>
<p>This is forcing us to use 2.6 version and it is bothersome as rest of the code is already in 3.0 format.</p>
| 8 | 2009-12-30T20:56:47Z | 17,780,873 | <p>You may use <strong><a href="https://pypi.python.org/pypi/ldap3">ldap3</a></strong> module (formerly known as <strong>python3-ldap</strong>), it runs on python3 really well and requires no external C dependances. Also it can correctly handle both unicode and byte data in ldap records (in early versions there was a t... | 26 | 2013-07-22T06:00:48Z | [
"python",
"ldap",
"python-3.x"
] |
python skipping inner loop in nested for loop | 1,982,506 | <p>I am using some python to do some variable name generation. For some reason I am only getting part of what I need.</p>
<pre><code>import sys
import csv
params = csv.reader(open('params.csv'), delimiter=',', skipinitialspace=True)
flags_r = []
flags_w = []
numbers_r = []
numbers_w = []
station = ['AC1','DC1','DC1'... | 0 | 2009-12-30T21:08:40Z | 1,982,518 | <p>Make sure params is a list and not an iterator.</p>
<pre><code>>>> s = (i for i in range(10))
>>> for ss in s: print(ss)
0
...
9
>>> for ss in s: print(ss)
# Nothing!
</code></pre>
| 1 | 2009-12-30T21:11:55Z | [
"python",
"nested-loops"
] |
python skipping inner loop in nested for loop | 1,982,506 | <p>I am using some python to do some variable name generation. For some reason I am only getting part of what I need.</p>
<pre><code>import sys
import csv
params = csv.reader(open('params.csv'), delimiter=',', skipinitialspace=True)
flags_r = []
flags_w = []
numbers_r = []
numbers_w = []
station = ['AC1','DC1','DC1'... | 0 | 2009-12-30T21:08:40Z | 1,982,525 | <p>In the first iteration of the outer loop you read all lines from <code>params</code>. In the second iteration all the lines from <code>params</code> are already read, so there is nothing left to iterate over in the inner loop.</p>
<p>To work around this, you could load all the data sets into a list and then iterate... | 6 | 2009-12-30T21:12:44Z | [
"python",
"nested-loops"
] |
python skipping inner loop in nested for loop | 1,982,506 | <p>I am using some python to do some variable name generation. For some reason I am only getting part of what I need.</p>
<pre><code>import sys
import csv
params = csv.reader(open('params.csv'), delimiter=',', skipinitialspace=True)
flags_r = []
flags_w = []
numbers_r = []
numbers_w = []
station = ['AC1','DC1','DC1'... | 0 | 2009-12-30T21:08:40Z | 1,982,527 | <p>on the first pass the reader buffer gets exhausted, so there is nothing else to read since you reached end of file.</p>
<p>You need to read your file in before the loops</p>
| 0 | 2009-12-30T21:12:51Z | [
"python",
"nested-loops"
] |
registering python com server | 1,982,540 | <p>I have a problem when registering a Python com server, I got a message box that says : </p>
<blockquote>
<p>Invalid command line argument. This
programs provides LocalServer com
support for Python COM objects. It is
typically run automatically by COM,
passing passing as arguments The
ProgID or CLSID of... | 0 | 2009-12-30T21:16:03Z | 1,985,772 | <p>Just an idea but have you checked the value of the LocalServer32 registry key of your COM server. see <a href="http://msdn.microsoft.com/en-us/library/ms683844%28VS.85%29.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms683844%28VS.85%29.aspx</a></p>
<p>Any difference in the ways you've installed it o... | 0 | 2009-12-31T15:11:18Z | [
"python",
"com",
"pywin32"
] |
custom prompt in python | 1,982,601 | <p>I have a script which when first run creates a new thread which logs certain events. After the thread has been created, I ask for some input on user with the following code:</p>
<pre><code>user_input = raw_input('>> ')
</code></pre>
<p>So when the script it run the user receives the '>>' prompt, but when the... | 1 | 2009-12-30T21:31:42Z | 1,982,659 | <p>The problem is that your <code>raw_input()</code> is running on a completely different thread, and has no idea that the logger just spewed out some log messages. So there is no way for <code>raw_input()</code> to know that it should re-draw the prompt.</p>
<p>I don't have any simple solution for you. All I can th... | 2 | 2009-12-30T21:42:08Z | [
"python",
"command-line"
] |
custom prompt in python | 1,982,601 | <p>I have a script which when first run creates a new thread which logs certain events. After the thread has been created, I ask for some input on user with the following code:</p>
<pre><code>user_input = raw_input('>> ')
</code></pre>
<p>So when the script it run the user receives the '>>' prompt, but when the... | 1 | 2009-12-30T21:31:42Z | 1,982,727 | <p>The obvious (and probably the only correct) solution is to log into a separate file, rather than on standard output.
If you still want to observe the logging output in real time, you can use a command such as <code>tail -f</code> on the logging file.</p>
| 1 | 2009-12-30T21:54:48Z | [
"python",
"command-line"
] |
Having trouble understanding CherryPy | 1,982,721 | <p>I read through the tutorial on the cherrypy website, and I'm still having some trouble understanding how it can be implemented in a modular, scalable way. </p>
<p>Could someone show me an example of how to have cherrypy receive a simple http post to its root, process the variable in some way, and respond dynamicall... | 0 | 2009-12-30T21:53:50Z | 1,982,747 | <p>Are you asking for an example like this?</p>
<p><a href="http://www.cherrypy.org/wiki/CherryPyTutorial#ReceivingdatafromHTMLforms" rel="nofollow">http://www.cherrypy.org/wiki/CherryPyTutorial#ReceivingdatafromHTMLforms</a></p>
<p>It receives input from forms.</p>
<p>You can return any text you want from a CherryP... | 1 | 2009-12-30T21:58:37Z | [
"python",
"cherrypy"
] |
Having trouble understanding CherryPy | 1,982,721 | <p>I read through the tutorial on the cherrypy website, and I'm still having some trouble understanding how it can be implemented in a modular, scalable way. </p>
<p>Could someone show me an example of how to have cherrypy receive a simple http post to its root, process the variable in some way, and respond dynamicall... | 0 | 2009-12-30T21:53:50Z | 1,984,200 | <pre><code>from cherrypy import expose
class Adder:
@expose
def index(self):
return '''<html>
<body>
<form action="add">
<input name="a" /> + <input name="b"> =
<input type="submit" />
... | 3 | 2009-12-31T06:21:20Z | [
"python",
"cherrypy"
] |
writing pexpect like program in c++ on Linux | 1,982,788 | <p>Is there any way of writing pexpect like small program which can launch a process and pass the password to that process?
I don't want to install and use pexpect python library but want to know the logic behind it so that using linux system apis I can build something similar.</p>
| 0 | 2009-12-30T22:06:54Z | 1,982,873 | <p>You could just use "expect". It is very light weight and is made to do what youre describing.</p>
| 2 | 2009-12-30T22:28:31Z | [
"c++",
"python",
"linux",
"pexpect"
] |
writing pexpect like program in c++ on Linux | 1,982,788 | <p>Is there any way of writing pexpect like small program which can launch a process and pass the password to that process?
I don't want to install and use pexpect python library but want to know the logic behind it so that using linux system apis I can build something similar.</p>
| 0 | 2009-12-30T22:06:54Z | 2,814,911 | <p>For very simple cases, <a href="http://empty.sourceforge.net/" rel="nofollow" title="empty">empty</a> is one option. It's a lightweight C program, and it can be used straight from a shell script and doesn't require Tcl.</p>
<p>For Debian/Ubuntu, the package is <code>empty-expect</code>.</p>
| 0 | 2010-05-11T22:35:39Z | [
"c++",
"python",
"linux",
"pexpect"
] |
Regex for getting content between $ chars from a text | 1,983,126 | <p>The problem:<br>
I need to extract strings that are between <code>$</code> characters from a block of text, but i'm a total n00b when it comes to regular expressions.</p>
<p>For instance from this text:<br>
<code>Li Europan lingues $es membres$ del sam familie. Lor $separat existentie es un$ myth.</code></p>
<p>i ... | 1 | 2009-12-30T23:42:57Z | 1,983,142 | <p>The regex below captures everything between the $ characters non-greedily </p>
<p>\$(.*?)\$</p>
| 1 | 2009-12-30T23:46:56Z | [
"python",
"regex"
] |
Regex for getting content between $ chars from a text | 1,983,126 | <p>The problem:<br>
I need to extract strings that are between <code>$</code> characters from a block of text, but i'm a total n00b when it comes to regular expressions.</p>
<p>For instance from this text:<br>
<code>Li Europan lingues $es membres$ del sam familie. Lor $separat existentie es un$ myth.</code></p>
<p>i ... | 1 | 2009-12-30T23:42:57Z | 1,983,143 | <p>You can use re.findall:</p>
<pre><code>>>> re.findall(r'\$(.*?)\$', s)
['es membres', 'separat existentie es un']
</code></pre>
| 3 | 2009-12-30T23:47:05Z | [
"python",
"regex"
] |
Regex for getting content between $ chars from a text | 1,983,126 | <p>The problem:<br>
I need to extract strings that are between <code>$</code> characters from a block of text, but i'm a total n00b when it comes to regular expressions.</p>
<p>For instance from this text:<br>
<code>Li Europan lingues $es membres$ del sam familie. Lor $separat existentie es un$ myth.</code></p>
<p>i ... | 1 | 2009-12-30T23:42:57Z | 1,983,144 | <pre><code>import re;
m = re.findall('\$([^$]*)\$','Li Europan lingues $es membres$ del sam familie. Lor $separat existentie es un$ myth');
</code></pre>
| 1 | 2009-12-30T23:47:12Z | [
"python",
"regex"
] |
Regex for getting content between $ chars from a text | 1,983,126 | <p>The problem:<br>
I need to extract strings that are between <code>$</code> characters from a block of text, but i'm a total n00b when it comes to regular expressions.</p>
<p>For instance from this text:<br>
<code>Li Europan lingues $es membres$ del sam familie. Lor $separat existentie es un$ myth.</code></p>
<p>i ... | 1 | 2009-12-30T23:42:57Z | 1,983,145 | <p>Valid regex demo in Perl:</p>
<pre><code>my $a = 'Li Europan lingues $es membres$ del sam familie. Lor $separat existentie es un$ myth.';
my @res;
while ($a =~ /\$([^\$]+)\$/gos)
{
push(@res, $1);
}
foreach my $item (@res)
{
print "item: $item\n";
}
</code></pre>
<p>flags: s - treat all input text as single lin... | -1 | 2009-12-30T23:47:18Z | [
"python",
"regex"
] |
Regex for getting content between $ chars from a text | 1,983,126 | <p>The problem:<br>
I need to extract strings that are between <code>$</code> characters from a block of text, but i'm a total n00b when it comes to regular expressions.</p>
<p>For instance from this text:<br>
<code>Li Europan lingues $es membres$ del sam familie. Lor $separat existentie es un$ myth.</code></p>
<p>i ... | 1 | 2009-12-30T23:42:57Z | 1,983,146 | <p>Alternative without regexes which works for this simple case:</p>
<pre><code>>>> s="Li Europan lingues $es membres$ del sam familie. Lor $separat existentie es un$"
>>> s.split("$")[1::2]
['es membres', 'separat existentie es un']
</code></pre>
<p>Just split the string on '$' (this gives you a py... | 0 | 2009-12-30T23:47:31Z | [
"python",
"regex"
] |
Regex for getting content between $ chars from a text | 1,983,126 | <p>The problem:<br>
I need to extract strings that are between <code>$</code> characters from a block of text, but i'm a total n00b when it comes to regular expressions.</p>
<p>For instance from this text:<br>
<code>Li Europan lingues $es membres$ del sam familie. Lor $separat existentie es un$ myth.</code></p>
<p>i ... | 1 | 2009-12-30T23:42:57Z | 1,983,157 | <p>Import the <strong><a href="http://docs.python.org/library/re.html" rel="nofollow"><code>re</code></a></strong> module, and use <code>findall()</code>:</p>
<pre><code>>>> import re
>>> p = re.compile('\$(.*?)\$')
>>> s = "apple $banana$ coconut $delicious ethereal$ funkytown"
>>>... | 4 | 2009-12-30T23:50:47Z | [
"python",
"regex"
] |
Are Python docstrings and comments stored in memory when module is loaded? | 1,983,177 | <blockquote>
<p>Are Python docstrings and comments stored in memory when module is loaded?</p>
</blockquote>
<p>I've wondered if this is true, because I usually document my code well; may this affect memory usage?</p>
<p><strong>Usually every Python object has a <code>__doc__</code> method. Are those docstrings rea... | 6 | 2009-12-30T23:55:57Z | 1,983,193 | <p>They <strong>are</strong> getting read from the file (when the file is compiled to pyc or when the pyc is loaded -- they must be available under <code>object.__doc__</code>) but <strong>no</strong> --> this will not significantly impact performance under any reasonable circumstances, or are you really writing multi-... | 3 | 2009-12-30T23:59:41Z | [
"python",
"comments",
"memory-management",
"docstring"
] |
Are Python docstrings and comments stored in memory when module is loaded? | 1,983,177 | <blockquote>
<p>Are Python docstrings and comments stored in memory when module is loaded?</p>
</blockquote>
<p>I've wondered if this is true, because I usually document my code well; may this affect memory usage?</p>
<p><strong>Usually every Python object has a <code>__doc__</code> method. Are those docstrings rea... | 6 | 2009-12-30T23:55:57Z | 1,983,203 | <p>Yes the docstrings are read from the file, but that shouldn't stop you writing them. Never <em>ever</em> compromise readability of code for performance until you have done a performance test and found that the thing you are worried about is in fact the bottleneck in your program that is causing a problem. I would th... | 6 | 2009-12-31T00:01:59Z | [
"python",
"comments",
"memory-management",
"docstring"
] |
Are Python docstrings and comments stored in memory when module is loaded? | 1,983,177 | <blockquote>
<p>Are Python docstrings and comments stored in memory when module is loaded?</p>
</blockquote>
<p>I've wondered if this is true, because I usually document my code well; may this affect memory usage?</p>
<p><strong>Usually every Python object has a <code>__doc__</code> method. Are those docstrings rea... | 6 | 2009-12-30T23:55:57Z | 1,983,281 | <p>By default, docstrings are present in the <code>.pyc</code> bytecode file, and are loaded from them (comments are not). If you use <code>python -OO</code> (the <code>-OO</code> flag stands for "optimize intensely", as opposed to <code>-O</code> which stands for "optimize mildly), you get and use <code>.pyo</code> f... | 17 | 2009-12-31T00:21:29Z | [
"python",
"comments",
"memory-management",
"docstring"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.