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 |
|---|---|---|---|---|---|---|---|---|---|
Fast string to integer conversion in Python | 1,309,123 | <p>A simple problem, really: you have one billion (1e+9) unsigned 32-bit integers stored as decimal ASCII strings in a TSV (tab-separated values) file. Conversion using <code>int()</code> is horribly slow compared to other tools working on the same dataset. Why? And more importantly: how to make it faster?</p>
<p>Ther... | 3 | 2009-08-20T22:11:33Z | 1,310,928 | <p>The following most simplistic C extension already improves heavily on the builtin, managing to convert over three times as many strings per second (650kcps vs 214kcps):</p>
<pre><code>static PyObject *fastint_int(PyObject *self, PyObject *args) {
char *s; unsigned r = 0;
if (!PyArg_ParseTuple(args, "s", &am... | 3 | 2009-08-21T09:25:53Z | [
"python",
"performance",
"optimization"
] |
Is the implementation of response.info().getencoding() broken in urllib2? | 1,309,233 | <p>I would expect the output of getencoding in the following python session to be "ISO-8859-1":</p>
<pre><code>>>> import urllib2
>>> response = urllib2.urlopen("http://www.google.com/")
>>> response.info().plist
['charset=ISO-8859-1']
>>> response.info().getencoding()
'7bit'
</code... | 2 | 2009-08-20T22:41:40Z | 1,311,332 | <p>Well, what is it you think is broken?</p>
<p>I get ISO-8859-2 for both urllib and wget (I'm currently in Poland). I get UTF-8 with Firefox. This is because my Firefox tells the site it accepts ISO-8859-1 and UTF-8, while wget and urllib2 does not say anything. The relevant request header is:</p>
<pre><code>Accept-... | 0 | 2009-08-21T11:05:34Z | [
"python",
"encoding",
"urllib2"
] |
Is the implementation of response.info().getencoding() broken in urllib2? | 1,309,233 | <p>I would expect the output of getencoding in the following python session to be "ISO-8859-1":</p>
<pre><code>>>> import urllib2
>>> response = urllib2.urlopen("http://www.google.com/")
>>> response.info().plist
['charset=ISO-8859-1']
>>> response.info().getencoding()
'7bit'
</code... | 2 | 2009-08-20T22:41:40Z | 17,150,262 | <p>According to <a href="http://docs.python.org/2/library/mimetools.html#mimetools.Message.getencoding" rel="nofollow">the document</a></p>
<blockquote>
<p>Message.getencoding()</p>
<p>Return the encoding specified in the <strong>Content-Transfer-Encoding</strong> message header. If no such header exists, retur... | 0 | 2013-06-17T14:40:27Z | [
"python",
"encoding",
"urllib2"
] |
Using list_filter with Intermediary Models | 1,309,348 | <p>We have three models, <code>Artist</code>:</p>
<pre><code>class Artist(models.Model):
family_name = models.CharField(max_length=50)
given_name = models.CharField(max_length=50)
</code></pre>
<p><code>Group</code>:</p>
<pre><code>class Group(models.Model):
name = models.CharField(max_length=50)
mem... | 1 | 2009-08-20T23:15:06Z | 1,313,937 | <p>If you define a m2m between artist and group using through=Membership, you can set up a filter directly on group without going through membership. Can't remember if the syntax is </p>
<pre><code>list_filter = ['group']
</code></pre>
<p>or</p>
<pre><code>list_filter = ['group_set']
</code></pre>
<p>or something ... | 1 | 2009-08-21T19:56:00Z | [
"python",
"django",
"django-admin"
] |
How to calculate a date back from another date with a given number of work days | 1,309,355 | <p>I need to calculate date (year, month, day) which is (for example) 18 working days back from another date. It would be enough to eliminate just weekends.</p>
<p>Example: I've got a date 2009-08-21 and a number of 18 workdays as a parameter, and correct answer should be 2009-07-27.</p>
<p>thanks for any help</p>
| 2 | 2009-08-20T23:16:29Z | 1,309,369 | <p>i suggest taking a look at <a href="http://docs.python.org/library/calendar.html" rel="nofollow">http://docs.python.org/library/calendar.html</a>
with it you can easily figure out what day of the week a certain date is, and then you can calculate back - taking into account weekends</p>
| 2 | 2009-08-20T23:21:21Z | [
"python",
"date"
] |
How to calculate a date back from another date with a given number of work days | 1,309,355 | <p>I need to calculate date (year, month, day) which is (for example) 18 working days back from another date. It would be enough to eliminate just weekends.</p>
<p>Example: I've got a date 2009-08-21 and a number of 18 workdays as a parameter, and correct answer should be 2009-07-27.</p>
<p>thanks for any help</p>
| 2 | 2009-08-20T23:16:29Z | 1,309,373 | <p>I would probably just loop over the days checking if the day is mon-fri.<br />
Not as efficent but easier to get right.</p>
| 0 | 2009-08-20T23:22:38Z | [
"python",
"date"
] |
How to calculate a date back from another date with a given number of work days | 1,309,355 | <p>I need to calculate date (year, month, day) which is (for example) 18 working days back from another date. It would be enough to eliminate just weekends.</p>
<p>Example: I've got a date 2009-08-21 and a number of 18 workdays as a parameter, and correct answer should be 2009-07-27.</p>
<p>thanks for any help</p>
| 2 | 2009-08-20T23:16:29Z | 1,309,440 | <p>I recommend using scikits timeseries, with the 'business' frequency. You can download this great python package here:</p>
<p><a href="http://pytseries.sourceforge.net/" rel="nofollow">http://pytseries.sourceforge.net/</a></p>
<p>Then you can write something like</p>
<pre><code>import datetime
import scikits.time... | 1 | 2009-08-20T23:47:32Z | [
"python",
"date"
] |
How to calculate a date back from another date with a given number of work days | 1,309,355 | <p>I need to calculate date (year, month, day) which is (for example) 18 working days back from another date. It would be enough to eliminate just weekends.</p>
<p>Example: I've got a date 2009-08-21 and a number of 18 workdays as a parameter, and correct answer should be 2009-07-27.</p>
<p>thanks for any help</p>
| 2 | 2009-08-20T23:16:29Z | 1,309,446 | <p>I'm assuming you're using datetime, but this should work (date is a datetime, days is an integer):</p>
<pre><code>def goback(date, days):
delta = datetime.timedelta( days=days + 2*(days//5) )
if date.weekday() == 5:
delta += datetime.timedelta(days=1)
elif date.weekday() == 6:
delta += d... | 0 | 2009-08-20T23:49:13Z | [
"python",
"date"
] |
How to calculate a date back from another date with a given number of work days | 1,309,355 | <p>I need to calculate date (year, month, day) which is (for example) 18 working days back from another date. It would be enough to eliminate just weekends.</p>
<p>Example: I've got a date 2009-08-21 and a number of 18 workdays as a parameter, and correct answer should be 2009-07-27.</p>
<p>thanks for any help</p>
| 2 | 2009-08-20T23:16:29Z | 1,309,508 | <p>Here's one way of doing it. Note (1) you don't say what you expect if the start date is NOT a workday. (2) Your example is wrong.</p>
<pre><code>C:\junk\so>type workdays.py
import datetime
def add_workdays(adate, nworkdays):
if nworkdays < 0:
incr = -1
nworkdays = - nworkdays
else:
... | 2 | 2009-08-21T00:13:08Z | [
"python",
"date"
] |
How to calculate a date back from another date with a given number of work days | 1,309,355 | <p>I need to calculate date (year, month, day) which is (for example) 18 working days back from another date. It would be enough to eliminate just weekends.</p>
<p>Example: I've got a date 2009-08-21 and a number of 18 workdays as a parameter, and correct answer should be 2009-07-27.</p>
<p>thanks for any help</p>
| 2 | 2009-08-20T23:16:29Z | 1,309,582 | <p>If you need to count holidays as non-workdays at some point, you'll need to work out Easter/Good Friday, which is best left to a library call:</p>
<p><code>
>>> from dateutil import easter<br/>
>>> easter.easter(2009)<br/>
datetime.date(2009, 4, 12)
</code></p>
<p>The other major holidays are rel... | 0 | 2009-08-21T00:51:45Z | [
"python",
"date"
] |
How to calculate a date back from another date with a given number of work days | 1,309,355 | <p>I need to calculate date (year, month, day) which is (for example) 18 working days back from another date. It would be enough to eliminate just weekends.</p>
<p>Example: I've got a date 2009-08-21 and a number of 18 workdays as a parameter, and correct answer should be 2009-07-27.</p>
<p>thanks for any help</p>
| 2 | 2009-08-20T23:16:29Z | 1,309,683 | <p>My wife Anna has a recipe for this in the 2nd ed. of the Python Cookbook -- you can read it online with this Google Book Search <a href="http://books.google.com/books?id=Q0s6Vgb98CQC&pg=PA123&lpg=PA123&dq=python+cookbook+workdays&source=bl&ots=hc2Wb2UnvE&sig=9LTmmj6W5-5GoIeVe5z3u5YE3Po&hl... | 0 | 2009-08-21T01:32:56Z | [
"python",
"date"
] |
How to calculate a date back from another date with a given number of work days | 1,309,355 | <p>I need to calculate date (year, month, day) which is (for example) 18 working days back from another date. It would be enough to eliminate just weekends.</p>
<p>Example: I've got a date 2009-08-21 and a number of 18 workdays as a parameter, and correct answer should be 2009-07-27.</p>
<p>thanks for any help</p>
| 2 | 2009-08-20T23:16:29Z | 13,673,025 | <p>If you are using <a href="http://pandas.pydata.org" rel="nofollow">pandas</a> you can do that easily:</p>
<pre><code>from pandas.tseries.offsets import BDay
import datetime
datetime.datetime(2009, 8, 21) - 18 * BDay()
</code></pre>
| 1 | 2012-12-02T19:41:55Z | [
"python",
"date"
] |
is there similar syntax to php's $$variable in python | 1,309,366 | <p>is there similar syntax to php's $$variable in python? what I am actually trying is to load a model based on a value.</p>
<p>for example, if the value is Song, I would like to import Song module.
I know I can use if statements or lambada, but something similar to php's $$variable will be much convenient.</p>
<p>wh... | 2 | 2009-08-20T23:20:40Z | 1,309,412 | <pre><code>def load_module_attr (path):
modname, attr = path.rsplit ('.', 1)
mod = __import__ (modname, {}, {}, [attr])
return getattr (mod, attr)
def my_view (request):
model_name = "myapp.models.Song" # Get from command line, user, wherever
model = load_module_attr (model_name)
print model.ob... | 3 | 2009-08-20T23:33:18Z | [
"python",
"django"
] |
is there similar syntax to php's $$variable in python | 1,309,366 | <p>is there similar syntax to php's $$variable in python? what I am actually trying is to load a model based on a value.</p>
<p>for example, if the value is Song, I would like to import Song module.
I know I can use if statements or lambada, but something similar to php's $$variable will be much convenient.</p>
<p>wh... | 2 | 2009-08-20T23:20:40Z | 1,309,916 | <p>So you know the general concept, what you are trying to implement is known as "Reflective Programming". </p>
<p>You can see examples in several languages in the wikipedia entry here </p>
<p><a href="http://en.wikipedia.org/wiki/Reflective%5Fprogramming" rel="nofollow">http://en.wikipedia.org/wiki/Reflective%5Fprog... | 0 | 2009-08-21T03:08:16Z | [
"python",
"django"
] |
is there similar syntax to php's $$variable in python | 1,309,366 | <p>is there similar syntax to php's $$variable in python? what I am actually trying is to load a model based on a value.</p>
<p>for example, if the value is Song, I would like to import Song module.
I know I can use if statements or lambada, but something similar to php's $$variable will be much convenient.</p>
<p>wh... | 2 | 2009-08-20T23:20:40Z | 1,310,355 | <p>I'm pretty sure you want <code>__import__()</code>.</p>
<p>Read this: <a href="http://docs.python.org/library/functions.html?highlight=%5Fimport#%5F%5Fimport%5F%5F" rel="nofollow">docs.python.org: <code>__import__</code></a></p>
<blockquote>
<p>This function is invoked by the import statement. It can be replaced... | 1 | 2009-08-21T06:43:50Z | [
"python",
"django"
] |
is there similar syntax to php's $$variable in python | 1,309,366 | <p>is there similar syntax to php's $$variable in python? what I am actually trying is to load a model based on a value.</p>
<p>for example, if the value is Song, I would like to import Song module.
I know I can use if statements or lambada, but something similar to php's $$variable will be much convenient.</p>
<p>wh... | 2 | 2009-08-20T23:20:40Z | 1,311,263 | <p>It seems that you want to load all the potentially matchable modules/models on hand and according to request choose a particular one to use. You can "globals()" which returns dictionary of global level variables, indexable by string. So if you do something like globals()['Song'], it'd give you Song model. This is mu... | 1 | 2009-08-21T10:49:50Z | [
"python",
"django"
] |
Does a UDP service have to respond from the connected IP address? | 1,309,370 | <p><a href="http://pyzor.org" rel="nofollow">Pyzor</a> uses UDP/IP as the communication protocol. We recently switched the public server to a new machine, and started getting reports of many timeouts. I discovered that I could fix the problem if I changed the IP that was queried from <code>eth0:1</code> to <code>eth0... | 1 | 2009-08-20T23:21:32Z | 1,309,534 | <p>I came across this with a TFTP server. My server had two IP addresses facing the same network. Because UDP is connectionless, there can be issues with IP addresses not being set as expected in that situation. The sequence I had was:</p>
<ol>
<li>Client sends the initial packet to the server at a particular IP addre... | 3 | 2009-08-21T00:31:17Z | [
"python",
"sockets",
"udp",
"ip",
"multihomed"
] |
Does a UDP service have to respond from the connected IP address? | 1,309,370 | <p><a href="http://pyzor.org" rel="nofollow">Pyzor</a> uses UDP/IP as the communication protocol. We recently switched the public server to a new machine, and started getting reports of many timeouts. I discovered that I could fix the problem if I changed the IP that was queried from <code>eth0:1</code> to <code>eth0... | 1 | 2009-08-20T23:21:32Z | 1,309,542 | <blockquote>
<p>Is this just a rule of UDP?</p>
</blockquote>
<p>No.</p>
<blockquote>
<p>Is this a problem/limitation with the
Python UDPServer class?</p>
</blockquote>
<p>Doubtful.</p>
<blockquote>
<p>Is it something I'm doing incorrectly?</p>
</blockquote>
<p>Your program looks correct.</p>
<p>There are... | 1 | 2009-08-21T00:33:44Z | [
"python",
"sockets",
"udp",
"ip",
"multihomed"
] |
How to tame the location of third party contributions in Django | 1,309,606 | <p>I have a django project which is laid out like this...</p>
<ul>
<li>myproject
<ul>
<li>apps</li>
<li>media</li>
<li>templates</li>
<li>django</li>
<li>registration</li>
<li>sorl</li>
<li>typogrify</li>
</ul></li>
</ul>
<p>I'd like to change it to this...</p>
<ul>
<li>myproject
<ul>
<li>apps</li>
<li>media</li>
<l... | 1 | 2009-08-21T00:59:43Z | 1,309,619 | <p>Make sure that site-dependencies, django, registration, sorl, and typogrify all have <code>__init__.py</code> files in them.</p>
| 0 | 2009-08-21T01:03:35Z | [
"python",
"django"
] |
How to tame the location of third party contributions in Django | 1,309,606 | <p>I have a django project which is laid out like this...</p>
<ul>
<li>myproject
<ul>
<li>apps</li>
<li>media</li>
<li>templates</li>
<li>django</li>
<li>registration</li>
<li>sorl</li>
<li>typogrify</li>
</ul></li>
</ul>
<p>I'd like to change it to this...</p>
<ul>
<li>myproject
<ul>
<li>apps</li>
<li>media</li>
<l... | 1 | 2009-08-21T00:59:43Z | 1,309,627 | <p>This looks like a job for <a href="http://pypi.python.org/pypi/virtualenv" rel="nofollow">virtualenv</a>.</p>
<ul>
<li><a href="http://iamzed.com/2009/05/07/a-primer-on-virtualenv/" rel="nofollow">A Primer on virtualenv</a></li>
<li><a href="http://arthurkoziel.com/2008/10/22/working-virtualenv/" rel="nofollow">Wor... | 3 | 2009-08-21T01:08:47Z | [
"python",
"django"
] |
How to tame the location of third party contributions in Django | 1,309,606 | <p>I have a django project which is laid out like this...</p>
<ul>
<li>myproject
<ul>
<li>apps</li>
<li>media</li>
<li>templates</li>
<li>django</li>
<li>registration</li>
<li>sorl</li>
<li>typogrify</li>
</ul></li>
</ul>
<p>I'd like to change it to this...</p>
<ul>
<li>myproject
<ul>
<li>apps</li>
<li>media</li>
<l... | 1 | 2009-08-21T00:59:43Z | 1,309,649 | <p>How are you importing the packages under site-dependencies?</p>
<p>Slightly off topic to your question, but I never liked the "default" project layout for Django so I have a script that lays my projects out like so:</p>
<pre><code>myproject/
apps/
vendor/
vendor/django/
config/__init__.py
con... | 0 | 2009-08-21T01:18:21Z | [
"python",
"django"
] |
How to tame the location of third party contributions in Django | 1,309,606 | <p>I have a django project which is laid out like this...</p>
<ul>
<li>myproject
<ul>
<li>apps</li>
<li>media</li>
<li>templates</li>
<li>django</li>
<li>registration</li>
<li>sorl</li>
<li>typogrify</li>
</ul></li>
</ul>
<p>I'd like to change it to this...</p>
<ul>
<li>myproject
<ul>
<li>apps</li>
<li>media</li>
<l... | 1 | 2009-08-21T00:59:43Z | 1,698,415 | <p>PYTHONPATH searches in the order that the paths are listed</p>
<pre><code>PythonPath "[ '/myproject', '/myproject/site-deps' ] + sys.path"
</code></pre>
<p>is not the same as</p>
<pre><code>PythonPath "[ '/myproject/site-deps', '/myproject' ] + sys.path"
</code></pre>
<p>The former order fails; perhaps because i... | 1 | 2009-11-08T23:56:07Z | [
"python",
"django"
] |
Python String Formatting And String Multiplication Oddity | 1,309,737 | <p>Python is doing string multiplication where I would expect it to do numeric multiplication, and I don't know why.</p>
<pre><code>>>> print('%d' % 2 * 4)
2222
>>> print('%d' % (2 * 4))
8
</code></pre>
<p>Even forcing the type to integer does nothing. (I realize this is redundant, but it's an idiot... | 4 | 2009-08-21T01:55:41Z | 1,309,747 | <p>Ah, I think I figured it out. Just after I posted the message, of course. It's an order-of-operations thing. The string formatting is being calculated, and the resulting string is being string multiplied against the last operand.</p>
<p>When I type:</p>
<pre><code>>>> print '%d' % 2 * 4
2222
</code></pre>... | 2 | 2009-08-21T01:57:54Z | [
"python",
"string",
"formatting",
"order-of-operations"
] |
Python String Formatting And String Multiplication Oddity | 1,309,737 | <p>Python is doing string multiplication where I would expect it to do numeric multiplication, and I don't know why.</p>
<pre><code>>>> print('%d' % 2 * 4)
2222
>>> print('%d' % (2 * 4))
8
</code></pre>
<p>Even forcing the type to integer does nothing. (I realize this is redundant, but it's an idiot... | 4 | 2009-08-21T01:55:41Z | 1,309,759 | <p>You are experiencing <em>operator precedence</em>.</p>
<p>In python <code>%</code> has the same precedence as <code>*</code> so they group left to right.</p>
<p>So,</p>
<pre><code>print('%d' % 2 * 4)
</code></pre>
<p>is the same as,</p>
<pre><code>print( ('%d' % 2) * 4)
</code></pre>
<p>Here is the python <a h... | 12 | 2009-08-21T02:02:41Z | [
"python",
"string",
"formatting",
"order-of-operations"
] |
How do I read CalDAV objects from Google using python/django? | 1,309,941 | <p>I've looked at vObject, iCalendar and the official list of CalDAV libraries, including <a href="http://caldav.calconnect.org/implementations/librariestools.html" rel="nofollow">3 in python</a>. However, I can't find any code that can get me an event object from a given CalDAV (i.e. google, exchange, etc.) server usi... | 3 | 2009-08-21T03:16:48Z | 1,634,405 | <p>For google you should use the <a href="http://code.google.com/intl/fr/apis/calendar/data/1.0/developers%5Fguide%5Fpython.html" rel="nofollow">Google python data API</a></p>
| 0 | 2009-10-27T23:55:43Z | [
"python",
"django",
"icalendar"
] |
How do I read CalDAV objects from Google using python/django? | 1,309,941 | <p>I've looked at vObject, iCalendar and the official list of CalDAV libraries, including <a href="http://caldav.calconnect.org/implementations/librariestools.html" rel="nofollow">3 in python</a>. However, I can't find any code that can get me an event object from a given CalDAV (i.e. google, exchange, etc.) server usi... | 3 | 2009-08-21T03:16:48Z | 2,978,151 | <p>Check this project : <a href="http://pypi.python.org/pypi/caldav" rel="nofollow">http://pypi.python.org/pypi/caldav</a></p>
<p>Recent but promising.</p>
| 2 | 2010-06-04T22:15:54Z | [
"python",
"django",
"icalendar"
] |
Parameter substitution for a SQLite "IN" clause | 1,309,989 | <p>I am trying to use parameter substitution with <a href="http://docs.python.org/library/sqlite3.html">SQLite within Python</a> for an IN clause. Here is a complete running example that demonstrates:</p>
<pre><code>import sqlite3
c = sqlite3.connect(":memory:")
c.execute('CREATE TABLE distro (id INTEGER PRIMARY KEY... | 26 | 2009-08-21T03:41:15Z | 1,309,993 | <p>Update: this works:</p>
<pre><code>import sqlite3
c = sqlite3.connect(":memory:")
c.execute('CREATE TABLE distro (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)')
for name in 'Ubuntu Fedora Puppy DSL SuSE'.split():
c.execute('INSERT INTO distro (name) VALUES (?)', ( name,) )
desired_ids = ["1", "2", "5", "4... | 8 | 2009-08-21T03:45:41Z | [
"python",
"sqlite"
] |
Parameter substitution for a SQLite "IN" clause | 1,309,989 | <p>I am trying to use parameter substitution with <a href="http://docs.python.org/library/sqlite3.html">SQLite within Python</a> for an IN clause. Here is a complete running example that demonstrates:</p>
<pre><code>import sqlite3
c = sqlite3.connect(":memory:")
c.execute('CREATE TABLE distro (id INTEGER PRIMARY KEY... | 26 | 2009-08-21T03:41:15Z | 1,310,001 | <p>You do need the right number of <code>?</code>s, but that doesn't pose a sql injection risk:</p>
<pre><code>>>> result_set = c.execute('SELECT * FROM distro WHERE id IN (%s)' %
','.join('?'*len(desired_ids)), desired_ids)
>>> print result_set.fetchall()
[(1, u'Ubuntu'), ... | 40 | 2009-08-21T03:52:20Z | [
"python",
"sqlite"
] |
Parameter substitution for a SQLite "IN" clause | 1,309,989 | <p>I am trying to use parameter substitution with <a href="http://docs.python.org/library/sqlite3.html">SQLite within Python</a> for an IN clause. Here is a complete running example that demonstrates:</p>
<pre><code>import sqlite3
c = sqlite3.connect(":memory:")
c.execute('CREATE TABLE distro (id INTEGER PRIMARY KEY... | 26 | 2009-08-21T03:41:15Z | 1,310,005 | <p>I always end up doing something like this:</p>
<pre><code>query = 'SELECT * FROM distro WHERE id IN (%s)' % ','.join('?' for i in desired_ids)
c.execute(query, desired_ids)
</code></pre>
<p>There's no injection risk because you're not putting strings from desired_ids into the query directly.</p>
| 2 | 2009-08-21T03:53:26Z | [
"python",
"sqlite"
] |
Parameter substitution for a SQLite "IN" clause | 1,309,989 | <p>I am trying to use parameter substitution with <a href="http://docs.python.org/library/sqlite3.html">SQLite within Python</a> for an IN clause. Here is a complete running example that demonstrates:</p>
<pre><code>import sqlite3
c = sqlite3.connect(":memory:")
c.execute('CREATE TABLE distro (id INTEGER PRIMARY KEY... | 26 | 2009-08-21T03:41:15Z | 1,344,866 | <p>In case sqlite has problem with the length of sql request the indefinite number of question marks can be some kind of way to beak things.</p>
| 0 | 2009-08-28T03:20:28Z | [
"python",
"sqlite"
] |
Parameter substitution for a SQLite "IN" clause | 1,309,989 | <p>I am trying to use parameter substitution with <a href="http://docs.python.org/library/sqlite3.html">SQLite within Python</a> for an IN clause. Here is a complete running example that demonstrates:</p>
<pre><code>import sqlite3
c = sqlite3.connect(":memory:")
c.execute('CREATE TABLE distro (id INTEGER PRIMARY KEY... | 26 | 2009-08-21T03:41:15Z | 3,498,634 | <p>According to <a href="http://www.sqlite.org/limits.html">http://www.sqlite.org/limits.html</a> (item 9), SQLite can't (by default) handle more than 999 parameters to a query, so the solutions here (generating the required list of placeholders) will fail if you have thousands of items that you're looking <code>IN</co... | 13 | 2010-08-17T01:18:51Z | [
"python",
"sqlite"
] |
How to set smtplib sending timeout in python 2.4? | 1,309,991 | <p>I'm having problems with smtplib tying up my program when email sending fails, because a timeout is never raised. The server I'm using does not and will never have python greater than 2.4, so I can't make use of the timeout argument to the SMTP constructor in later versions of python.</p>
<p><a href="http://www.pyt... | 3 | 2009-08-21T03:43:37Z | 1,310,008 | <pre><code>import socket
socket.setdefaulttimeout(120)
</code></pre>
<p>will make any socket time out after 2 minutes, unless the specific socket's timeout is changed (and I believe SMTP in Python 2.4 doesn't do the latter).</p>
<p><strong>Edit</strong>: apparently per OP's comment this breaks TLS, so, plan B...:</p>... | 6 | 2009-08-21T03:55:40Z | [
"python",
"python-2.4",
"smtplib"
] |
Refresh QTextEdit in PyQt | 1,310,142 | <p>Im writing a PyQt app that takes some input in one widget, and then processes some text files.</p>
<p>What ive got at the moment is when the user clicks the "process" button a seperate window with a QTextEdit in it pops up, and ouputs some logging messages.</p>
<p>On Mac OS X this window is refreshed automatically... | 2 | 2009-08-21T04:55:24Z | 1,310,231 | <p>It looks like your are running an external program, capturing its output into a QTextEdit. I didn't see the code of <code>Form.process</code>, but I am guessing on windows your function waits for the external program to finish, then quickly dumps everything to the <code>QTextEdit</code>. </p>
<p>If your interface r... | 1 | 2009-08-21T05:36:12Z | [
"python",
"pyqt"
] |
oop instantiation pythonic practices | 1,310,158 | <p>I've got the code below, and I was planning on making several classes all within the same "import". I was hoping to instantiate each class and get a return value with the widgets I'm making. </p>
<p>This isn't really a PyQt question at all, more of a "good practices" question, as I'll have a class for each widget. ... | 1 | 2009-08-21T05:03:37Z | 1,310,207 | <p>The answer will be decided if the list of tabs can be changed at runtime. If this widget really only supports adding a set of tabs, but never changing or appending new ones, the list of tabs should come from the initializer. Otherwise you should also add a method to do the job. Consider the <code>QLabel</code> widge... | 4 | 2009-08-21T05:24:50Z | [
"oop",
"pyqt",
"python"
] |
What does "built-in method decode" mean in Python when profiling? | 1,310,201 | <p>I'm trying to make my program faster, so I'm profiling it. Right now the top reason is:</p>
<pre><code>566 1.780 0.003 1.780 0.003 (built-in method decode)
</code></pre>
<p>What is this exactly? I never call 'decode' anywhere in my code. It reads text files, but I don't believe they are unicode-encoded... | 0 | 2009-08-21T05:22:32Z | 1,310,218 | <p>Most likely, this is the <a href="http://docs.python.org/library/stdtypes.html#str.decode" rel="nofollow">decode method of string objects</a>.</p>
| 2 | 2009-08-21T05:29:40Z | [
"python",
"string",
"optimization",
"performance",
"pickle"
] |
What does "built-in method decode" mean in Python when profiling? | 1,310,201 | <p>I'm trying to make my program faster, so I'm profiling it. Right now the top reason is:</p>
<pre><code>566 1.780 0.003 1.780 0.003 (built-in method decode)
</code></pre>
<p>What is this exactly? I never call 'decode' anywhere in my code. It reads text files, but I don't believe they are unicode-encoded... | 0 | 2009-08-21T05:22:32Z | 1,310,224 | <p>Presumably this is str.decode ... search your source for "decode". If it's not in your code, look at Python library routines that show up in the profile results. It's highly unlikely to be to be anything to do with cPickle. Care to show us a few more "reasons", preferably with the column headings, to give us a wider... | 1 | 2009-08-21T05:34:20Z | [
"python",
"string",
"optimization",
"performance",
"pickle"
] |
What does "built-in method decode" mean in Python when profiling? | 1,310,201 | <p>I'm trying to make my program faster, so I'm profiling it. Right now the top reason is:</p>
<pre><code>566 1.780 0.003 1.780 0.003 (built-in method decode)
</code></pre>
<p>What is this exactly? I never call 'decode' anywhere in my code. It reads text files, but I don't believe they are unicode-encoded... | 0 | 2009-08-21T05:22:32Z | 1,310,237 | <p>I believe <code>decode</code> is called anytime you are converting unicode strings into ascii strings. I am guessing you have a large amount of unicode data. I'm not sure how the internals of pickle work, but it sounds like that unicode data gets converted to ascii when pickled?</p>
| 0 | 2009-08-21T05:40:02Z | [
"python",
"string",
"optimization",
"performance",
"pickle"
] |
What does "built-in method decode" mean in Python when profiling? | 1,310,201 | <p>I'm trying to make my program faster, so I'm profiling it. Right now the top reason is:</p>
<pre><code>566 1.780 0.003 1.780 0.003 (built-in method decode)
</code></pre>
<p>What is this exactly? I never call 'decode' anywhere in my code. It reads text files, but I don't believe they are unicode-encoded... | 0 | 2009-08-21T05:22:32Z | 1,310,307 | <p>(Answering @Claudiu's latest question, weirdly hidden in a commennt...?!-)... To really speed up pickling, try <a href="http://code.google.com/p/unladen-swallow/" rel="nofollow">unladen swallow</a> -- most of its ambitious targets are still to come, but it DOES already give at least 20-25% speedup in pickling and un... | 1 | 2009-08-21T06:15:47Z | [
"python",
"string",
"optimization",
"performance",
"pickle"
] |
What is the best way to create a Python object when you have the class implementaion stored in a string? | 1,310,254 | <p>What is the best way to dynamically create a Python object instance when all you have is the Python class saved as a string? </p>
<p>For background, I am working in the Google Application Engine environment and I want to be able to load classes dynamically from a string version of the class. </p>
<pre><code>proble... | 2 | 2009-08-21T05:50:00Z | 1,310,271 | <p>Use <a href="http://docs.python.org/reference/simple%5Fstmts.html#the-exec-statement" rel="nofollow">the exec statement</a> to define your class and then instantiate it:</p>
<pre><code>exec solvertext1
s = solver()
answer = s.solve(problem)
</code></pre>
| 0 | 2009-08-21T05:58:07Z | [
"python"
] |
What is the best way to create a Python object when you have the class implementaion stored in a string? | 1,310,254 | <p>What is the best way to dynamically create a Python object instance when all you have is the Python class saved as a string? </p>
<p>For background, I am working in the Google Application Engine environment and I want to be able to load classes dynamically from a string version of the class. </p>
<pre><code>proble... | 2 | 2009-08-21T05:50:00Z | 1,310,297 | <p>Alas, <code>exec</code> is your only choice, but at least do it right to avert disaster: pass an explicit dictionary (with an <code>in</code> clause, of course)! E.g.:</p>
<pre><code>>>> class X(object): pass
...
>>> x=X()
>>> exec 'a=23' in vars(x)
>>> x.a
23
</code></pre>
<p... | 9 | 2009-08-21T06:11:48Z | [
"python"
] |
What is the best way to create a Python object when you have the class implementaion stored in a string? | 1,310,254 | <p>What is the best way to dynamically create a Python object instance when all you have is the Python class saved as a string? </p>
<p>For background, I am working in the Google Application Engine environment and I want to be able to load classes dynamically from a string version of the class. </p>
<pre><code>proble... | 2 | 2009-08-21T05:50:00Z | 1,310,468 | <p>Simple example:</p>
<pre><code>>>> solvertext1 = "def f(problem):\n\treturn len(problem)\n"
>>> ex_string = solvertext1 + "\nanswer = f(%s)"%('\"Hello World\"')
>>> exec ex_string
>>> answer
11
</code></pre>
| 0 | 2009-08-21T07:26:26Z | [
"python"
] |
HTML forms not working with python | 1,310,443 | <p>I've created a HTML page with forms, which takes a name and password and passes it to a Python Script which is supposed to print the persons name with a welcome message. However, after i POST the values, i'm just getting the Python code displayed in the browser and not the welcome message. I have stored the html fil... | 0 | 2009-08-21T07:19:03Z | 1,310,474 | <p>This</p>
<blockquote>
<p>i'm just getting the Python code
displayed in the browser</p>
</blockquote>
<p>sounds like CGI handling with Apache and Python is not configured correctly.</p>
<p>You can narrow the test case by passing UserName and PassWord as GET parameters:</p>
<pre><code>http://example.com/cgi-bi... | 1 | 2009-08-21T07:28:03Z | [
"python"
] |
HTML forms not working with python | 1,310,443 | <p>I've created a HTML page with forms, which takes a name and password and passes it to a Python Script which is supposed to print the persons name with a welcome message. However, after i POST the values, i'm just getting the Python code displayed in the browser and not the welcome message. I have stored the html fil... | 0 | 2009-08-21T07:19:03Z | 1,310,554 | <p>You may have to extract the field values like this</p>
<pre><code>User = form.getfirst('UserName')
Pass = form.getfirst('PassWord')
</code></pre>
<p>I know, it's strange.</p>
| 0 | 2009-08-21T07:46:15Z | [
"python"
] |
Running a Python script outside of Django | 1,310,495 | <p>I have a script which uses the Django ORM features, amongst other external libraries, that I want to run outside of Django (that is, executed from the command-line).</p>
<p>Edit: At the moment, I can launch it by navigating to a URL...</p>
<p>How do I setup the environment for this?</p>
| 33 | 2009-08-21T07:33:37Z | 1,310,547 | <pre><code>from <Project path> import settings #your project settings file
from django.core.management import setup_environ #environment setup function
setup_environ(settings)
#Rest of your django imports and code go here
</code></pre>
| 20 | 2009-08-21T07:44:19Z | [
"python",
"django"
] |
Running a Python script outside of Django | 1,310,495 | <p>I have a script which uses the Django ORM features, amongst other external libraries, that I want to run outside of Django (that is, executed from the command-line).</p>
<p>Edit: At the moment, I can launch it by navigating to a URL...</p>
<p>How do I setup the environment for this?</p>
| 33 | 2009-08-21T07:33:37Z | 1,310,607 | <p>All you need is importable settings and properly set python path. In the most raw form this can be done by setting up appropriate environment variables, like:</p>
<pre><code>$ DJANGO_SETTINGS_MODULE=myproject.settings PYTHONPATH=$HOME/djangoprojects python myscript.py
</code></pre>
<p>There are other ways, like ca... | 12 | 2009-08-21T08:00:02Z | [
"python",
"django"
] |
Running a Python script outside of Django | 1,310,495 | <p>I have a script which uses the Django ORM features, amongst other external libraries, that I want to run outside of Django (that is, executed from the command-line).</p>
<p>Edit: At the moment, I can launch it by navigating to a URL...</p>
<p>How do I setup the environment for this?</p>
| 33 | 2009-08-21T07:33:37Z | 1,310,642 | <p>The easiest way to do this is to set up your script as a <code>manage.py</code> subcommand. It's quite easy to do:</p>
<pre><code>from django.core.management.base import NoArgsCommand, make_option
class Command(NoArgsCommand):
help = "Whatever you want to print here"
option_list = NoArgsCommand.option_li... | 37 | 2009-08-21T08:11:29Z | [
"python",
"django"
] |
Running a Python script outside of Django | 1,310,495 | <p>I have a script which uses the Django ORM features, amongst other external libraries, that I want to run outside of Django (that is, executed from the command-line).</p>
<p>Edit: At the moment, I can launch it by navigating to a URL...</p>
<p>How do I setup the environment for this?</p>
| 33 | 2009-08-21T07:33:37Z | 12,130,739 | <p><strong>Note</strong> that the suggestions around importing settings and using setup_environ have been deprecated with Django 1.4. </p>
<p>There's a thread on the Django Github describing <a href="https://github.com/django/django/commit/38f1fe3b35">why this was done</a>.</p>
<p>There are still some other options ... | 10 | 2012-08-26T14:02:29Z | [
"python",
"django"
] |
Running a Python script outside of Django | 1,310,495 | <p>I have a script which uses the Django ORM features, amongst other external libraries, that I want to run outside of Django (that is, executed from the command-line).</p>
<p>Edit: At the moment, I can launch it by navigating to a URL...</p>
<p>How do I setup the environment for this?</p>
| 33 | 2009-08-21T07:33:37Z | 17,980,230 | <p>Use <code>runscript</code> from <a href="http://django-extensions.readthedocs.org/en/latest/runscript.html">django-extensions</a>: <code>python manage.py runscript <my_script></code></p>
<p>In order to do this, you need to:</p>
<ol>
<li><code>pip install django-extensions</code></li>
<li>Create a directory c... | 9 | 2013-07-31T20:23:04Z | [
"python",
"django"
] |
Running a Python script outside of Django | 1,310,495 | <p>I have a script which uses the Django ORM features, amongst other external libraries, that I want to run outside of Django (that is, executed from the command-line).</p>
<p>Edit: At the moment, I can launch it by navigating to a URL...</p>
<p>How do I setup the environment for this?</p>
| 33 | 2009-08-21T07:33:37Z | 32,052,644 | <p>I like to add the following command to my projects:</p>
<p><code>myproject/management/commands/run-script.py</code>:</p>
<pre><code>from django.core.management.base import BaseCommand, CommandError
import imp
import sys
class Command(BaseCommand):
help = """Run a non-django script with django settings."""
... | 1 | 2015-08-17T14:12:53Z | [
"python",
"django"
] |
What is the oldest time that can be represented in python? | 1,310,740 | <p>I have written a function comp(time1, time2) which will return true when time1 is lesser than time2. I have a scenario where time1 should always be lesser than time2. I need time1 to have the least possible value(date). How to find this time and how to form the corresponding object.</p>
| 10 | 2009-08-21T08:37:28Z | 1,310,772 | <p>In python, the datetime object exports the following constants</p>
<pre><code>datetime.MINYEAR
The smallest year number allowed in a date or datetime object. MINYEAR is 1.
datetime.MAXYEAR
The largest year number allowed in a date or datetime object. MAXYEAR is 9999.
</code></pre>
<p><a href="http://docs.python.o... | 11 | 2009-08-21T08:43:53Z | [
"python",
"python-3.x"
] |
What is the oldest time that can be represented in python? | 1,310,740 | <p>I have written a function comp(time1, time2) which will return true when time1 is lesser than time2. I have a scenario where time1 should always be lesser than time2. I need time1 to have the least possible value(date). How to find this time and how to form the corresponding object.</p>
| 10 | 2009-08-21T08:37:28Z | 1,310,787 | <p>If you're using standard issue unix timestamp values then the earliest representable moment of time is back in 1970:</p>
<pre><code>>>> import time
>>> time.gmtime(0)
(1970, 1, 1, 0, 0, 0, 3, 1, 0)
</code></pre>
| 6 | 2009-08-21T08:47:40Z | [
"python",
"python-3.x"
] |
What is the oldest time that can be represented in python? | 1,310,740 | <p>I have written a function comp(time1, time2) which will return true when time1 is lesser than time2. I have a scenario where time1 should always be lesser than time2. I need time1 to have the least possible value(date). How to find this time and how to form the corresponding object.</p>
| 10 | 2009-08-21T08:37:28Z | 1,313,488 | <p>Certain functions in the <code>datetime</code> module obey <code>datetime.MINYEAR</code> and <code>datetime.MAXYEAR</code> and will raise a <code>ValueException</code> for dates outside that range. These are assigned to 1 and 9999, respectively. </p>
<p>The <code>calender</code> module relies heavily on the <code>... | 5 | 2009-08-21T18:15:25Z | [
"python",
"python-3.x"
] |
What is the oldest time that can be represented in python? | 1,310,740 | <p>I have written a function comp(time1, time2) which will return true when time1 is lesser than time2. I have a scenario where time1 should always be lesser than time2. I need time1 to have the least possible value(date). How to find this time and how to form the corresponding object.</p>
| 10 | 2009-08-21T08:37:28Z | 31,972,447 | <p>If using the <a href="https://docs.python.org/2/library/datetime.html">datetime</a> module, <a href="https://docs.python.org/2/library/datetime.html#date-objects">date</a>, <a href="https://docs.python.org/2/library/datetime.html#time-objects">time</a>, and <a href="https://docs.python.org/2/library/datetime.html#da... | 13 | 2015-08-12T18:09:56Z | [
"python",
"python-3.x"
] |
How to get the diff of two PDF files in python? | 1,310,836 | <p>I need to find the difference between two pdf files. Does any any python related tool have a feature which directly gives the diff of the 2 PDFs?</p>
| 5 | 2009-08-21T09:01:37Z | 1,310,916 | <p>What do you mean by "difference"? A difference in the text of the PDF or some layout change (e.g. an embedded graphic was resized). The first is easy to detect, the second is almost impossible to get (PDF is an VERY complicated file format, that offers endless file formatting capabilities).</p>
<p>If you want to ge... | 5 | 2009-08-21T09:23:16Z | [
"python",
"pdf"
] |
How to get the diff of two PDF files in python? | 1,310,836 | <p>I need to find the difference between two pdf files. Does any any python related tool have a feature which directly gives the diff of the 2 PDFs?</p>
| 5 | 2009-08-21T09:01:37Z | 1,310,920 | <p>Check this out, it can be useful: <a href="http://pybrary.net/pyPdf/" rel="nofollow">http://pybrary.net/pyPdf/</a></p>
| 0 | 2009-08-21T09:24:05Z | [
"python",
"pdf"
] |
How to get the diff of two PDF files in python? | 1,310,836 | <p>I need to find the difference between two pdf files. Does any any python related tool have a feature which directly gives the diff of the 2 PDFs?</p>
| 5 | 2009-08-21T09:01:37Z | 1,311,122 | <p>I do not know your use case, but for regression tests of script which generates pdf using reportlab, I do diff pdfs by</p>
<ol>
<li>Converting each page to an image using ghostsript </li>
<li>Diffing each page against page image of standard pdf, using PIL</li>
</ol>
<p>e.g</p>
<pre><code>im1 = Image.open(imagePat... | 3 | 2009-08-21T10:17:24Z | [
"python",
"pdf"
] |
How to get the diff of two PDF files in python? | 1,310,836 | <p>I need to find the difference between two pdf files. Does any any python related tool have a feature which directly gives the diff of the 2 PDFs?</p>
| 5 | 2009-08-21T09:01:37Z | 21,692,319 | <p>Met the same question on my encrypted pdf unittest, neither pdfminer nor pyPdf works well for me.</p>
<p>Here are two commands (pdftocairo, pdftotext) work perfect on my test. (Ubuntu Install: apt-get install poppler-utils)</p>
<p>You can get pdf content by:</p>
<pre><code>from subprocess import Popen, PIPE
def ... | 1 | 2014-02-11T03:14:26Z | [
"python",
"pdf"
] |
XPath Query in XML using Python | 1,310,904 | <p>Is it possible to use XPath Query in Python while processing XML. I am using minidom which doesn't support that. Is there any other module for that?</p>
| 5 | 2009-08-21T09:18:45Z | 1,311,159 | <p>My favorite XML processing library for Python is <a href="http://lxml.de" rel="nofollow">lxml</a> which, because it is a wrapper around libxml2, also supports full XPath.</p>
<p>There is also <a href="http://4suite.org/index.xhtml" rel="nofollow">4Suite</a> which is more of a pure Python solution.</p>
| 2 | 2009-08-21T10:26:54Z | [
"python",
"python-3.x"
] |
XPath Query in XML using Python | 1,310,904 | <p>Is it possible to use XPath Query in Python while processing XML. I am using minidom which doesn't support that. Is there any other module for that?</p>
| 5 | 2009-08-21T09:18:45Z | 1,311,580 | <p><a href="http://docs.python.org/library/xml.etree.elementtree.html">http://docs.python.org/library/xml.etree.elementtree.html</a></p>
<p>etree supports XPath queries, just like lxml.</p>
<p>etree is included in the standard library, but lxml is faster.</p>
| 6 | 2009-08-21T12:10:13Z | [
"python",
"python-3.x"
] |
XPath Query in XML using Python | 1,310,904 | <p>Is it possible to use XPath Query in Python while processing XML. I am using minidom which doesn't support that. Is there any other module for that?</p>
| 5 | 2009-08-21T09:18:45Z | 13,504,484 | <p>ElementTree is included. Under 2.6 and below its xpath is pretty weak, but in <a href="http://docs.python.org/2/library/xml.etree.elementtree.html#xpath-support" rel="nofollow">2.7 much improved</a>:</p>
<pre><code>import xml.etree.ElementTree as et
root = et.parse(filename)
result = ''
# How to make decisions ba... | 1 | 2012-11-22T01:02:03Z | [
"python",
"python-3.x"
] |
How to execute asynchronous post-processing in CherryPy? | 1,310,959 | <p><strong>Context:</strong>
Imagine that you have a standard CherryPy hello word app:</p>
<pre><code> def index(self):
return "Hello world!"
index.exposed = True
</code></pre>
<p>and you would like to do some post-processing, i.e. record request processing or just log the fact that we were called from spe... | 4 | 2009-08-21T09:33:12Z | 1,311,104 | <p>An <a href="http://web.archive.org/web/20070328175337/http://www.cherrypy.org/wiki/CustomTools" rel="nofollow">on_end_request custom tool</a> may be what you want.</p>
| 2 | 2009-08-21T10:13:37Z | [
"python",
"asynchronous",
"cherrypy"
] |
How to execute asynchronous post-processing in CherryPy? | 1,310,959 | <p><strong>Context:</strong>
Imagine that you have a standard CherryPy hello word app:</p>
<pre><code> def index(self):
return "Hello world!"
index.exposed = True
</code></pre>
<p>and you would like to do some post-processing, i.e. record request processing or just log the fact that we were called from spe... | 4 | 2009-08-21T09:33:12Z | 1,313,032 | <p>The "global threading aware queue" is called Queue.Queue. I just added a recipe for this at <a href="http://tools.cherrypy.org/wiki/BackgroundTaskQueue" rel="nofollow">http://tools.cherrypy.org/wiki/BackgroundTaskQueue</a></p>
| 7 | 2009-08-21T16:48:03Z | [
"python",
"asynchronous",
"cherrypy"
] |
How to execute asynchronous post-processing in CherryPy? | 1,310,959 | <p><strong>Context:</strong>
Imagine that you have a standard CherryPy hello word app:</p>
<pre><code> def index(self):
return "Hello world!"
index.exposed = True
</code></pre>
<p>and you would like to do some post-processing, i.e. record request processing or just log the fact that we were called from spe... | 4 | 2009-08-21T09:33:12Z | 13,547,382 | <p>As i was looking for this and it's now outdated, i found it useful to provide the correct (2012ish) answer. Simply add this at the beginning of the function that handles your url :</p>
<pre><code>cherrypy.request.hooks.attach('on_end_request', mycallbackfunction)
</code></pre>
<p>There's more infos on hooks in the... | 1 | 2012-11-25T01:14:19Z | [
"python",
"asynchronous",
"cherrypy"
] |
Python ConfigParser - values between quotes | 1,311,367 | <p>When using <code>ConfigParser</code> module I would like to use values containing of multiple words set in cfg file. In this case seems trivial for me to surround the string with quotes like (<code>example.cfg</code>):</p>
<pre><code>[GENERAL]
onekey = "value in some words"
</code></pre>
<p>My problem is that in t... | 5 | 2009-08-21T11:12:50Z | 1,311,381 | <p>I didn't see anything in <a href="http://docs.python.org/library/configparser.html">the configparser manual</a>, but you could just use the <code>.strip</code> method of strings to get rid of the leading and trailing double quotes.</p>
<pre><code>>>> s = '"hello world"'
>>> s
'"hello world"'
>&... | 6 | 2009-08-21T11:17:38Z | [
"python",
"configparser"
] |
Python ConfigParser - values between quotes | 1,311,367 | <p>When using <code>ConfigParser</code> module I would like to use values containing of multiple words set in cfg file. In this case seems trivial for me to surround the string with quotes like (<code>example.cfg</code>):</p>
<pre><code>[GENERAL]
onekey = "value in some words"
</code></pre>
<p>My problem is that in t... | 5 | 2009-08-21T11:12:50Z | 1,311,396 | <p>Sorry, the solution was trivial as well - I can simply leave the quotes, it looks python simply takes the right side of equal sign.</p>
| 1 | 2009-08-21T11:21:07Z | [
"python",
"configparser"
] |
Python ConfigParser - values between quotes | 1,311,367 | <p>When using <code>ConfigParser</code> module I would like to use values containing of multiple words set in cfg file. In this case seems trivial for me to surround the string with quotes like (<code>example.cfg</code>):</p>
<pre><code>[GENERAL]
onekey = "value in some words"
</code></pre>
<p>My problem is that in t... | 5 | 2009-08-21T11:12:50Z | 1,314,476 | <p>Davey,</p>
<p>As you say you can just leave the quotes off your string.</p>
<p>For a project I'm working on I wanted to be able to represent almost any Python string literal as a value for some of my config options and more to the point I wanted to be able to handle some of them as raw string literals. (I want th... | 0 | 2009-08-21T22:27:41Z | [
"python",
"configparser"
] |
Python ConfigParser - values between quotes | 1,311,367 | <p>When using <code>ConfigParser</code> module I would like to use values containing of multiple words set in cfg file. In this case seems trivial for me to surround the string with quotes like (<code>example.cfg</code>):</p>
<pre><code>[GENERAL]
onekey = "value in some words"
</code></pre>
<p>My problem is that in t... | 5 | 2009-08-21T11:12:50Z | 2,176,542 | <pre><code>import ConfigParser
class MyConfigParser(ConfigParser.RawConfigParser):
def get(self, section, option):
val = ConfigParser.RawConfigParser.get(self, section, option)
return val.lstrip('"').rstrip('"')
if __name__ == "__main__":
#config = ConfigParser.RawConfigParser()
config = M... | 2 | 2010-02-01T12:23:03Z | [
"python",
"configparser"
] |
Python ConfigParser - values between quotes | 1,311,367 | <p>When using <code>ConfigParser</code> module I would like to use values containing of multiple words set in cfg file. In this case seems trivial for me to surround the string with quotes like (<code>example.cfg</code>):</p>
<pre><code>[GENERAL]
onekey = "value in some words"
</code></pre>
<p>My problem is that in t... | 5 | 2009-08-21T11:12:50Z | 13,760,716 | <p>The question is quite old already, but in 2.6 at least you don't need to use quotes as spaces are retained. </p>
<pre><code>from ConfigParser import RawConfigParser
from StringIO import StringIO
s = RawConfigParser()
s.readfp(StringIO('[t]\na= 1 2 3'))
s.get('t','a')
> '1 2 3'
</code></pre>
<p>That doesn't app... | 2 | 2012-12-07T09:54:48Z | [
"python",
"configparser"
] |
Python ConfigParser - values between quotes | 1,311,367 | <p>When using <code>ConfigParser</code> module I would like to use values containing of multiple words set in cfg file. In this case seems trivial for me to surround the string with quotes like (<code>example.cfg</code>):</p>
<pre><code>[GENERAL]
onekey = "value in some words"
</code></pre>
<p>My problem is that in t... | 5 | 2009-08-21T11:12:50Z | 33,730,075 | <p>At this situation, the most simple solution is "eval()".</p>
<p>However, you may worry about the security stuff.But you could still do this by:</p>
<pre><code>def literal_eval(node_or_string):
"""
Safely evaluate an expression node or a string containing a Python
expression. The string or node provide... | -2 | 2015-11-16T07:11:07Z | [
"python",
"configparser"
] |
Problem while running python script in java code | 1,311,513 | <p>When i run a python script from the below java code, where an input file is given as an argument to the python script as well as an "-v" option, i get a IOException</p>
<pre><code>String pythonScriptPath="\"C:\\Program Files\\bin\\CsvFile.py\"";
String Filepath="C:\\Documents and Settings\\user\\Desktop\\arbit.csv"... | 0 | 2009-08-21T11:52:17Z | 1,311,605 | <p>You don't need all the extra quotes.</p>
<pre><code>String pythonScriptPath="C:\\Program Files\\bin\\CsvFile.py";
</code></pre>
<p>This should work fine.</p>
| 0 | 2009-08-21T12:16:25Z | [
"java",
"python"
] |
Problem while running python script in java code | 1,311,513 | <p>When i run a python script from the below java code, where an input file is given as an argument to the python script as well as an "-v" option, i get a IOException</p>
<pre><code>String pythonScriptPath="\"C:\\Program Files\\bin\\CsvFile.py\"";
String Filepath="C:\\Documents and Settings\\user\\Desktop\\arbit.csv"... | 0 | 2009-08-21T11:52:17Z | 1,311,611 | <ol>
<li>Is Python in your path ? I would most likely qualify it with a path to determine precisely which python you're picking up (if any)</li>
<li>You don't need the quotes around the Python script argument</li>
</ol>
| 0 | 2009-08-21T12:17:22Z | [
"java",
"python"
] |
Problem while running python script in java code | 1,311,513 | <p>When i run a python script from the below java code, where an input file is given as an argument to the python script as well as an "-v" option, i get a IOException</p>
<pre><code>String pythonScriptPath="\"C:\\Program Files\\bin\\CsvFile.py\"";
String Filepath="C:\\Documents and Settings\\user\\Desktop\\arbit.csv"... | 0 | 2009-08-21T11:52:17Z | 1,311,617 | <p><code>error=2</code> means the Win32 <code>CreateProcess</code> function is returning an error code of 2, or <code>ERROR_FILE_NOT_FOUND</code>. Either it can't find your script, or (more likely, IMO) it can't find <code>python.exe</code>. If it's the latter, make sure your Python installation (possibly <code>C:\Prog... | 2 | 2009-08-21T12:19:22Z | [
"java",
"python"
] |
Problem while running python script in java code | 1,311,513 | <p>When i run a python script from the below java code, where an input file is given as an argument to the python script as well as an "-v" option, i get a IOException</p>
<pre><code>String pythonScriptPath="\"C:\\Program Files\\bin\\CsvFile.py\"";
String Filepath="C:\\Documents and Settings\\user\\Desktop\\arbit.csv"... | 0 | 2009-08-21T11:52:17Z | 1,312,264 | <p>Your variable Filepath does not match what you actually sent it according to your program output. The error lists it as "C:\Documents and Settings\user \Desktop\arbit.csv" with an extraneous space after the user profile name which is the most likely cause for a File Not Found error.</p>
| 0 | 2009-08-21T14:23:13Z | [
"java",
"python"
] |
how to get console output from a remote computer (ssh + python) | 1,311,697 | <p>I have googled "python ssh". There is a wonderful module <a href="http://www.noah.org/wiki/Pexpect" rel="nofollow"><code>pexpect</code></a>, which can access a remote computer using ssh (with password). </p>
<p>After the remote computer is connected, I can execute other commands. However I cannot get the result in ... | 5 | 2009-08-21T12:40:13Z | 1,312,752 | <p>Try to send</p>
<pre><code>p.sendline("ps -ef\n")
</code></pre>
<p>IIRC, the text you send is interpreted verbatim, so the other computer is probably waiting for you to complete the command.</p>
| 0 | 2009-08-21T15:43:45Z | [
"python",
"linux",
"login",
"ssh",
"pexpect"
] |
how to get console output from a remote computer (ssh + python) | 1,311,697 | <p>I have googled "python ssh". There is a wonderful module <a href="http://www.noah.org/wiki/Pexpect" rel="nofollow"><code>pexpect</code></a>, which can access a remote computer using ssh (with password). </p>
<p>After the remote computer is connected, I can execute other commands. However I cannot get the result in ... | 5 | 2009-08-21T12:40:13Z | 1,313,728 | <p>You might also want to investigate <a href="http://www.lag.net/paramiko/" rel="nofollow">paramiko</a> which is another SSH library for Python.</p>
| 1 | 2009-08-21T19:08:36Z | [
"python",
"linux",
"login",
"ssh",
"pexpect"
] |
how to get console output from a remote computer (ssh + python) | 1,311,697 | <p>I have googled "python ssh". There is a wonderful module <a href="http://www.noah.org/wiki/Pexpect" rel="nofollow"><code>pexpect</code></a>, which can access a remote computer using ssh (with password). </p>
<p>After the remote computer is connected, I can execute other commands. However I cannot get the result in ... | 5 | 2009-08-21T12:40:13Z | 1,314,571 | <p>Have you tried an even simpler approach?</p>
<pre><code>>>> from subprocess import Popen, PIPE
>>> stdout, stderr = Popen(['ssh', 'user@remote_computer', 'ps -ef'],
... stdout=PIPE).communicate()
>>> print(stdout)
</code></pre>
<p>Granted, this only works because I... | 6 | 2009-08-21T23:07:00Z | [
"python",
"linux",
"login",
"ssh",
"pexpect"
] |
how to get console output from a remote computer (ssh + python) | 1,311,697 | <p>I have googled "python ssh". There is a wonderful module <a href="http://www.noah.org/wiki/Pexpect" rel="nofollow"><code>pexpect</code></a>, which can access a remote computer using ssh (with password). </p>
<p>After the remote computer is connected, I can execute other commands. However I cannot get the result in ... | 5 | 2009-08-21T12:40:13Z | 7,186,014 | <pre><code>child = pexpect.spawn("ssh user@remote_computer ps -ef")
print "connecting..."
i = child.expect(['user@remote_computer\'s password:'])
child.sendline(user_password)
i = child.expect([' .*']) #or use i = child.expect([pexpect.EOF])
if i == 0:
print child.after # uncomment when using [' .*'] pattern
#p... | 3 | 2011-08-25T06:32:20Z | [
"python",
"linux",
"login",
"ssh",
"pexpect"
] |
How nicely does Python 'flow' with HTML as compared to PHP? | 1,311,789 | <p>I'm thinking of switching from using PHP to Python for web applications, but I was wondering if Python is as adept as weaving in and out of HTML as PHP is. Essentially, I find it very easy/intuitive to use <code><? and ?></code> to put PHP where I want, and am then free to arrange/organize my HTML however I wa... | 11 | 2009-08-21T13:00:30Z | 1,311,828 | <p>Well. First of all, you must know that mixing code with presentation is considered bad practice. Although you can use template engines that let you mix any python code inside the html, like <a href="http://www.makotemplates.org/" rel="nofollow">Mako</a>, usually python web libraries and frameworks tend to favor writ... | 2 | 2009-08-21T13:07:50Z | [
"php",
"python",
"html"
] |
How nicely does Python 'flow' with HTML as compared to PHP? | 1,311,789 | <p>I'm thinking of switching from using PHP to Python for web applications, but I was wondering if Python is as adept as weaving in and out of HTML as PHP is. Essentially, I find it very easy/intuitive to use <code><? and ?></code> to put PHP where I want, and am then free to arrange/organize my HTML however I wa... | 11 | 2009-08-21T13:00:30Z | 1,311,902 | <p>Yes, PHP is easy to use in that way. But that's not the recommended way! It's better you use templates. In fact, you can use the same with PHP too.</p>
| 0 | 2009-08-21T13:19:28Z | [
"php",
"python",
"html"
] |
How nicely does Python 'flow' with HTML as compared to PHP? | 1,311,789 | <p>I'm thinking of switching from using PHP to Python for web applications, but I was wondering if Python is as adept as weaving in and out of HTML as PHP is. Essentially, I find it very easy/intuitive to use <code><? and ?></code> to put PHP where I want, and am then free to arrange/organize my HTML however I wa... | 11 | 2009-08-21T13:00:30Z | 1,311,904 | <p>First of all: Escaping out into a programming language from HTML is nice when you do small hacks. For an actual production web application I would never to that.</p>
<p>Mixing in HTML into the programming language is unpractical. It's better to use some sort of templating language. Indentation is not an issue there... | 1 | 2009-08-21T13:19:35Z | [
"php",
"python",
"html"
] |
How nicely does Python 'flow' with HTML as compared to PHP? | 1,311,789 | <p>I'm thinking of switching from using PHP to Python for web applications, but I was wondering if Python is as adept as weaving in and out of HTML as PHP is. Essentially, I find it very easy/intuitive to use <code><? and ?></code> to put PHP where I want, and am then free to arrange/organize my HTML however I wa... | 11 | 2009-08-21T13:00:30Z | 1,311,908 | <p>If you were to progress onto a MVC web framework, you would find that actually both PHP and Python use HTML in a similar way.</p>
<p>The work around the request is done in the controllers, using the model for grabbing data. The results are then posted to a view, which is in effect a template of HTML.</p>
<p>You ca... | 2 | 2009-08-21T13:20:53Z | [
"php",
"python",
"html"
] |
How nicely does Python 'flow' with HTML as compared to PHP? | 1,311,789 | <p>I'm thinking of switching from using PHP to Python for web applications, but I was wondering if Python is as adept as weaving in and out of HTML as PHP is. Essentially, I find it very easy/intuitive to use <code><? and ?></code> to put PHP where I want, and am then free to arrange/organize my HTML however I wa... | 11 | 2009-08-21T13:00:30Z | 1,311,980 | <p>You can't easily compare PHP and Python.</p>
<p>PHP is a web processing framework that is designed specifically as an Apache plug-in. It includes HTTP protocol handling as well as a programming language.</p>
<p>Python is "just" a programming language. There are many Python web frameworks to plug Python into Apac... | 23 | 2009-08-21T13:34:14Z | [
"php",
"python",
"html"
] |
Using a global dictionary with threads in Python | 1,312,331 | <p>Is accessing/changing dictionary values thread-safe?</p>
<p>I have a global dictionary <code>foo</code> and multiple threads with ids <code>id1</code>, <code>id2</code>, ... , <code>idn</code>. Is it OK to access and change <code>foo</code>'s values without allocating a lock for it if it's known that each thread wi... | 13 | 2009-08-21T14:33:32Z | 1,312,384 | <p>The <a href="http://docs.python.org/glossary.html?highlight=gil#term-global-interpreter-lock" rel="nofollow">GIL</a> takes care of that, if you happen to be using <code>CPython</code>.</p>
<blockquote>
<p><strong>global interpreter lock</strong></p>
<p>The lock used by Python threads to assure that only one ... | 3 | 2009-08-21T14:43:28Z | [
"python",
"multithreading"
] |
Using a global dictionary with threads in Python | 1,312,331 | <p>Is accessing/changing dictionary values thread-safe?</p>
<p>I have a global dictionary <code>foo</code> and multiple threads with ids <code>id1</code>, <code>id2</code>, ... , <code>idn</code>. Is it OK to access and change <code>foo</code>'s values without allocating a lock for it if it's known that each thread wi... | 13 | 2009-08-21T14:33:32Z | 1,312,389 | <p>Assuming CPython: Yes and no. It is actually safe to fetch/store values from a shared dictionary in the sense that multiple concurrent read/write requests won't corrupt the dictionary. This is due to the global interpreter lock ("GIL") maintained by the implementation. That is:</p>
<p>Thread A running:</p>
<pre><c... | 19 | 2009-08-21T14:44:38Z | [
"python",
"multithreading"
] |
Using a global dictionary with threads in Python | 1,312,331 | <p>Is accessing/changing dictionary values thread-safe?</p>
<p>I have a global dictionary <code>foo</code> and multiple threads with ids <code>id1</code>, <code>id2</code>, ... , <code>idn</code>. Is it OK to access and change <code>foo</code>'s values without allocating a lock for it if it's known that each thread wi... | 13 | 2009-08-21T14:33:32Z | 1,312,704 | <p>The best, safest, portable way to have each thread work with independent data is:</p>
<pre><code>import threading
tloc = threading.local()
</code></pre>
<p>Now each thread works with a totally independent <code>tloc</code> object even though it's a global name. The thread can get and set attributes on <code>tloc</... | 16 | 2009-08-21T15:36:10Z | [
"python",
"multithreading"
] |
Using a global dictionary with threads in Python | 1,312,331 | <p>Is accessing/changing dictionary values thread-safe?</p>
<p>I have a global dictionary <code>foo</code> and multiple threads with ids <code>id1</code>, <code>id2</code>, ... , <code>idn</code>. Is it OK to access and change <code>foo</code>'s values without allocating a lock for it if it's known that each thread wi... | 13 | 2009-08-21T14:33:32Z | 29,532,297 | <p>Since I needed something similar, I landed here. I sum up your answers in this short snippet :</p>
<pre><code>#!/usr/bin/env python3
import threading
class ThreadSafeDict(dict) :
def __init__(self, * p_arg, ** n_arg) :
dict.__init__(self, * p_arg, ** n_arg)
self._lock = threading.Lock()
d... | 7 | 2015-04-09T07:24:00Z | [
"python",
"multithreading"
] |
Using a global dictionary with threads in Python | 1,312,331 | <p>Is accessing/changing dictionary values thread-safe?</p>
<p>I have a global dictionary <code>foo</code> and multiple threads with ids <code>id1</code>, <code>id2</code>, ... , <code>idn</code>. Is it OK to access and change <code>foo</code>'s values without allocating a lock for it if it's known that each thread wi... | 13 | 2009-08-21T14:33:32Z | 32,303,835 | <p>How it works?:</p>
<pre><code>>>> import dis
>>> demo = {}
>>> def set_dict():
... demo['name'] = 'Jatin Kumar'
...
>>> dis.dis(set_dict)
2 0 LOAD_CONST 1 ('Jatin Kumar')
3 LOAD_GLOBAL 0 (demo)
6 LOAD_CONST ... | 0 | 2015-08-31T04:06:05Z | [
"python",
"multithreading"
] |
Help with Python while loop behaviour | 1,312,421 | <p>I have a script that uses a simple while loop to display a progress bar but it doesn't seem to be working as I expected:</p>
<pre><code>count = 1
maxrecords = len(international)
p = ProgressBar("Blue")
t = time
while count < maxrecords:
print 'Processing %d of %d' % (count, maxrecords)
percent = float(co... | 1 | 2009-08-21T14:50:12Z | 1,312,496 | <p>That's not the way to write a loop in Python.</p>
<pre><code>maxrecords = len(international)
p = ProgressBar("Blue")
for count in range(1, maxrecords):
print 'Processing %d of %d' % (count, maxrecords)
percent = float(count) / float(maxrecords) * 100
p.render(int(percent))
time.sleep(0.5)
</code></p... | 3 | 2009-08-21T15:01:58Z | [
"python",
"while-loop"
] |
Help with Python while loop behaviour | 1,312,421 | <p>I have a script that uses a simple while loop to display a progress bar but it doesn't seem to be working as I expected:</p>
<pre><code>count = 1
maxrecords = len(international)
p = ProgressBar("Blue")
t = time
while count < maxrecords:
print 'Processing %d of %d' % (count, maxrecords)
percent = float(co... | 1 | 2009-08-21T14:50:12Z | 1,312,542 | <p>What is the implementation for <code>ProgressBar.render()</code>? I assume that it is outputting terminal control characters that move the cursor so that previous output is overwritten. This can create the false impression that the control flow isn't working as it should be.</p>
| 2 | 2009-08-21T15:08:47Z | [
"python",
"while-loop"
] |
Help with Python while loop behaviour | 1,312,421 | <p>I have a script that uses a simple while loop to display a progress bar but it doesn't seem to be working as I expected:</p>
<pre><code>count = 1
maxrecords = len(international)
p = ProgressBar("Blue")
t = time
while count < maxrecords:
print 'Processing %d of %d' % (count, maxrecords)
percent = float(co... | 1 | 2009-08-21T14:50:12Z | 1,312,657 | <p>I see you are using the ProgressBar implementation on my website. If you want to print a message you can use the message argument in render</p>
<pre><code>p.render(percent, message='Processing %d of %d' % (count, maxrecords))
</code></pre>
| 5 | 2009-08-21T15:28:32Z | [
"python",
"while-loop"
] |
Help with Python while loop behaviour | 1,312,421 | <p>I have a script that uses a simple while loop to display a progress bar but it doesn't seem to be working as I expected:</p>
<pre><code>count = 1
maxrecords = len(international)
p = ProgressBar("Blue")
t = time
while count < maxrecords:
print 'Processing %d of %d' % (count, maxrecords)
percent = float(co... | 1 | 2009-08-21T14:50:12Z | 1,312,659 | <p>(1) [not part of the problem, but ...] <code>t = time</code> followed much later by <code>t.sleep(0.5)</code> would be a source of annoyance to anyone seeing the bare <code>t</code> and having to read backwards to find what it is.</p>
<p>(2) [not part of the problem, but ...] <code>count</code> can never enter the ... | 1 | 2009-08-21T15:28:48Z | [
"python",
"while-loop"
] |
display a QMessageBox PyQT when a different combobox /list box item is selected | 1,312,598 | <p>I have a combo box <code>cbLayer</code> and a function <code>do_stuff</code> of the following form:</p>
<pre><code>def do_stuff(item_selected_from_cbLayer):
new_list = []
# do stuff based on item_selected_from_combobox and put the items in new_list
return new_list
</code></pre>
<p>How can I get a <code... | 0 | 2009-08-21T15:17:51Z | 1,312,800 | <p>Write a method or function that contains this code and attach it to the combo boxes signal <a href="http://doc.trolltech.com/4.5/qcombobox.html#currentIndexChanged" rel="nofollow"><code>currentIndexChanged</code></a>:</p>
<pre><code>def __init__(self):
...
QObject.connect(self.cbLayer, SIGNAL("currentIndexC... | 1 | 2009-08-21T15:50:35Z | [
"python",
"pyqt"
] |
Python - ambiguity with decorators receiving a single arg | 1,312,785 | <p>I am trying to write a decorator that gets a single arg, i.e</p>
<pre><code>@Printer(1)
def f():
print 3
</code></pre>
<p>So, naively, I tried:</p>
<pre><code>class Printer:
def __init__(self,num):
self.__num=num
def __call__(self,func):
def wrapped(*args,**kargs):
prin... | 1 | 2009-08-21T15:48:51Z | 1,312,866 | <p>Are you sure it works without arguments? If I leave them out I get this error message:</p>
<pre>
Traceback (most recent call last):
File "/tmp/blah.py", line 28, in ?
a()
TypeError: __call__() takes exactly 2 arguments (1 given)
</pre>
<p>You could try this alternative definition, though, if the class-based ... | 1 | 2009-08-21T16:06:57Z | [
"python",
"arguments",
"decorator"
] |
Python - ambiguity with decorators receiving a single arg | 1,312,785 | <p>I am trying to write a decorator that gets a single arg, i.e</p>
<pre><code>@Printer(1)
def f():
print 3
</code></pre>
<p>So, naively, I tried:</p>
<pre><code>class Printer:
def __init__(self,num):
self.__num=num
def __call__(self,func):
def wrapped(*args,**kargs):
prin... | 1 | 2009-08-21T15:48:51Z | 1,312,870 | <p>Well, it's already effectively prevented, in the sense that calling <code>a()</code> doesn't work.</p>
<p>But to stop it as the function is defined, I suppose you'd have to change <code>__init__</code> to check the type of <code>num</code>:</p>
<pre><code>def __init__(self,num):
if callable(num):
raise... | 4 | 2009-08-21T16:07:49Z | [
"python",
"arguments",
"decorator"
] |
Python - ambiguity with decorators receiving a single arg | 1,312,785 | <p>I am trying to write a decorator that gets a single arg, i.e</p>
<pre><code>@Printer(1)
def f():
print 3
</code></pre>
<p>So, naively, I tried:</p>
<pre><code>class Printer:
def __init__(self,num):
self.__num=num
def __call__(self,func):
def wrapped(*args,**kargs):
prin... | 1 | 2009-08-21T15:48:51Z | 1,312,873 | <p>The decorator is whatever the expression after <code>@</code> evaluates to. In the first case, that's an instance of <code>Printer</code>, so what happens is (pretty much) equivalent to</p>
<pre><code>decorator = Printer(1) # an instance of Printer, the "1" is given to __init__
def f():
print 3
f = decorator(f... | 1 | 2009-08-21T16:08:20Z | [
"python",
"arguments",
"decorator"
] |
Python - ambiguity with decorators receiving a single arg | 1,312,785 | <p>I am trying to write a decorator that gets a single arg, i.e</p>
<pre><code>@Printer(1)
def f():
print 3
</code></pre>
<p>So, naively, I tried:</p>
<pre><code>class Printer:
def __init__(self,num):
self.__num=num
def __call__(self,func):
def wrapped(*args,**kargs):
prin... | 1 | 2009-08-21T15:48:51Z | 1,312,965 | <p>I can't think of an ideal answer, but if you force the Printer class to be instantiated with a keyword argument, it can never try to instantiate via the decorator itself, since that only deals with non-keyword arguments:</p>
<pre><code>def __init__(self,**kwargs):
self.__num=kwargs["num"]
</code></pre>
<p>...... | 1 | 2009-08-21T16:30:59Z | [
"python",
"arguments",
"decorator"
] |
Python: what kind of literal delimiter is "better" to use? | 1,312,940 | <p>What is the best literal delimiter in Python and why? Single ' or double "? And most important, why?</p>
<p>I'm a beginner in Python and I'm trying to stick with just one. I know that in PHP, for example " is preferred, because PHP does not try to search for the 'string' variable. Is the same case in Python?</p>
| 2 | 2009-08-21T16:26:42Z | 1,312,949 | <p>' because it's one keystroke less than ". Save your wrists!</p>
<p>They're otherwise identical (except you have to escape whichever you choose to use, if they appear inside the string).</p>
| 9 | 2009-08-21T16:28:53Z | [
"python",
"string"
] |
Python: what kind of literal delimiter is "better" to use? | 1,312,940 | <p>What is the best literal delimiter in Python and why? Single ' or double "? And most important, why?</p>
<p>I'm a beginner in Python and I'm trying to stick with just one. I know that in PHP, for example " is preferred, because PHP does not try to search for the 'string' variable. Is the same case in Python?</p>
| 2 | 2009-08-21T16:26:42Z | 1,312,956 | <p>For string constants containing a <code>single quote</code> use the <code>double quote</code> as delimiter.</p>
<p>The other way around, if you need a <code>double quote</code> inside.</p>
<p>Quick, shiftless typing leads to <code>single quote</code> delimiters.</p>
<pre><code>>>> "it's very simple"
>... | 1 | 2009-08-21T16:29:39Z | [
"python",
"string"
] |
Python: what kind of literal delimiter is "better" to use? | 1,312,940 | <p>What is the best literal delimiter in Python and why? Single ' or double "? And most important, why?</p>
<p>I'm a beginner in Python and I'm trying to stick with just one. I know that in PHP, for example " is preferred, because PHP does not try to search for the 'string' variable. Is the same case in Python?</p>
| 2 | 2009-08-21T16:26:42Z | 1,312,959 | <p>Consider these strings:</p>
<pre><code>"Don't do that."
'I said, "okay".'
"""She said, "That won't work"."""
</code></pre>
<p>Which quote is "best"?</p>
| 9 | 2009-08-21T16:30:11Z | [
"python",
"string"
] |
Python: what kind of literal delimiter is "better" to use? | 1,312,940 | <p>What is the best literal delimiter in Python and why? Single ' or double "? And most important, why?</p>
<p>I'm a beginner in Python and I'm trying to stick with just one. I know that in PHP, for example " is preferred, because PHP does not try to search for the 'string' variable. Is the same case in Python?</p>
| 2 | 2009-08-21T16:26:42Z | 1,312,960 | <p>Single and double quotes act identically in Python. Escapes (<code>\n</code>) always work, and there is no variable interpolation. (If you don't want escapes, you can use the <code>r</code> flag, as in <code>r"\n"</code>.)</p>
<p>Since I'm coming from a Perl background, I have a habit of using single quotes for p... | 0 | 2009-08-21T16:30:15Z | [
"python",
"string"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.