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 |
|---|---|---|---|---|---|---|---|---|---|
getting an attachment from a Outlook mail in linux | 2,230,958 | <p>I would like to get a file attached to an email I receive using Outlook.</p>
<p>I need to run this python script in a Linux Box.</p>
<p>I read about the win32com.client library.</p>
<p>Do you know if it works also for Linux?</p>
<p>If not do you know any alternative if there are?</p>
| 0 | 2010-02-09T17:10:33Z | 2,231,098 | <p>Coincidentally, today I posted an example of retrieving attachments over IMAP <a href="http://stackoverflow.com/questions/2230037/how-to-fetch-an-email-body-using-imaplib-in-python/2230571#2230571">here</a>, it may be of some use to you.</p>
<p>Outlook is an email client, it may use one or more of a variety of prot... | 1 | 2010-02-09T17:35:00Z | [
"python"
] |
Are there any downsides to upgrading Python on Snow Leopard? | 2,230,968 | <p>I want to use the newest version of Python on Snow Leopard using the installer package, but I've read some confusing articles about conflicts when upgrading. I plan on using PyDev in Eclipse, will there be any conflicts with Snow Leopard if I upgrade?</p>
| 2 | 2010-02-09T17:12:24Z | 2,231,020 | <p>To answer your question explicitly: Are there any downsides to upgrading Python on SL? Only if you upgrade the system installation. It can have strange repercussions on any system/CLI tools that use Python, and on any bundled applications (.app) that are utilizing <a href="http://pyobjc.sourceforge.net/" rel="nofol... | 3 | 2010-02-09T17:21:50Z | [
"python",
"osx",
"osx-snow-leopard"
] |
Unexpected object assignment | 2,230,993 | <pre><code>class TrafficData(object):
def __init__(self):
self.__data = {}
def __getitem__(self, epoch):
if not isinstance(epoch, int):
raise TypeError()
return self.__data.setdefault(epoch, ProcessTraffic())
def __iadd__(self, other):
for epoch, traffic in other.... | 0 | 2010-02-09T17:16:49Z | 2,231,014 | <p>What you are exactly doing in:</p>
<pre><code>self[epoch] += traffic
</code></pre>
<p>is:</p>
<pre><code>self[epoch] = self[epoch] + traffic
</code></pre>
<p>But you haven't defined <code>__setitem__</code> method, so you can do that on self.</p>
<p>You also need:</p>
<pre><code>def __setitem__(self, epoch, va... | 6 | 2010-02-09T17:20:52Z | [
"python",
"variable-assignment",
"dictionary"
] |
Unexpected object assignment | 2,230,993 | <pre><code>class TrafficData(object):
def __init__(self):
self.__data = {}
def __getitem__(self, epoch):
if not isinstance(epoch, int):
raise TypeError()
return self.__data.setdefault(epoch, ProcessTraffic())
def __iadd__(self, other):
for epoch, traffic in other.... | 0 | 2010-02-09T17:16:49Z | 2,231,051 | <p>The code:</p>
<pre><code>self[epoch] += traffic
</code></pre>
<p>Is syntactic sugar for:</p>
<pre><code>self[epoch] = self[epoch] + traffic
</code></pre>
<p>So <strong>the assignment is not unexpected it is the assignment in <code>+=</code></strong>. So you also need to override the <code>__setitem__()</code> me... | 0 | 2010-02-09T17:28:33Z | [
"python",
"variable-assignment",
"dictionary"
] |
Unexpected object assignment | 2,230,993 | <pre><code>class TrafficData(object):
def __init__(self):
self.__data = {}
def __getitem__(self, epoch):
if not isinstance(epoch, int):
raise TypeError()
return self.__data.setdefault(epoch, ProcessTraffic())
def __iadd__(self, other):
for epoch, traffic in other.... | 0 | 2010-02-09T17:16:49Z | 2,231,649 | <blockquote>
<p>It's probably worth pointing out that
the values in <code>self.__data</code> have
<code>__iadd__</code> defined, but not <code>__add__</code>, and I'd much prefer to modify the value in
place if possible.</p>
</blockquote>
<p>To add some precision to previous answers, under the circumstances yo... | 1 | 2010-02-09T18:59:31Z | [
"python",
"variable-assignment",
"dictionary"
] |
Python comparison evaluation | 2,231,220 | <p>As per the python documentation,<code>x<y<z</code> comparison is translated to <code>x<y and y<z</code> and expression <code>y</code> is evaluated only once at most.<br>
Now my question is , does an expression <code>y</code> ( look at the code below) is evaluated only once here?</p>
<pre><code>if(x<... | 1 | 2010-02-09T17:54:28Z | 2,231,248 | <p>No:</p>
<pre><code>>>> dis.dis(lambda x, y, z: x < y() < z)
1 0 LOAD_FAST 0 (x)
3 LOAD_FAST 1 (y)
6 CALL_FUNCTION 0
9 DUP_TOP
10 ROT_THREE
11 COMPARE_OP ... | 3 | 2010-02-09T17:57:42Z | [
"python",
"syntax",
"comparison"
] |
Python comparison evaluation | 2,231,220 | <p>As per the python documentation,<code>x<y<z</code> comparison is translated to <code>x<y and y<z</code> and expression <code>y</code> is evaluated only once at most.<br>
Now my question is , does an expression <code>y</code> ( look at the code below) is evaluated only once here?</p>
<pre><code>if(x<... | 1 | 2010-02-09T17:54:28Z | 2,231,252 | <p>Twice:</p>
<pre><code>>>> def f():
... print "F called"
... return 1
...
>>> 0 < f() < 100
F called
True
>>> 0 < f() and f() < 100
F called
F called
True
>>> if (0 < f() and f() < 100):
... print True
...
F called
F called
True
>>>
</code></pre>
| 9 | 2010-02-09T17:57:50Z | [
"python",
"syntax",
"comparison"
] |
Python subprocess/Popen with a modified environment | 2,231,227 | <p>I believe that running an external command with a slightly modified environment is a very common case. That's how I tend to do it:</p>
<pre><code>import subprocess, os
my_env = os.environ
my_env["PATH"] = "/usr/sbin:/sbin:" + my_env["PATH"]
subprocess.Popen(my_command, env=my_env)
</code></pre>
<p>I've got a gut f... | 128 | 2010-02-09T17:55:16Z | 2,231,315 | <p>In certain circumstances you may want to only pass down the environment variables your subprocess needs, but I think you've got the right idea in general (that's how I do it too).</p>
| 0 | 2010-02-09T18:08:43Z | [
"python",
"subprocess",
"popen"
] |
Python subprocess/Popen with a modified environment | 2,231,227 | <p>I believe that running an external command with a slightly modified environment is a very common case. That's how I tend to do it:</p>
<pre><code>import subprocess, os
my_env = os.environ
my_env["PATH"] = "/usr/sbin:/sbin:" + my_env["PATH"]
subprocess.Popen(my_command, env=my_env)
</code></pre>
<p>I've got a gut f... | 128 | 2010-02-09T17:55:16Z | 2,231,325 | <p>you might use <code>my_env.get("PATH", '')</code> instead of <code>my_env["PATH"]</code> in case <code>PATH</code> somehow not defined in the original environment, but other than that it looks fine.</p>
| 20 | 2010-02-09T18:09:53Z | [
"python",
"subprocess",
"popen"
] |
Python subprocess/Popen with a modified environment | 2,231,227 | <p>I believe that running an external command with a slightly modified environment is a very common case. That's how I tend to do it:</p>
<pre><code>import subprocess, os
my_env = os.environ
my_env["PATH"] = "/usr/sbin:/sbin:" + my_env["PATH"]
subprocess.Popen(my_command, env=my_env)
</code></pre>
<p>I've got a gut f... | 128 | 2010-02-09T17:55:16Z | 2,231,339 | <p>The env parameter accepts a dictionary. You can simply take os.environ, add a key (your desired variable) (to a copy of the dict if you must) to that and use it as a parameter to <code>Popen</code>. </p>
| 0 | 2010-02-09T18:13:28Z | [
"python",
"subprocess",
"popen"
] |
Python subprocess/Popen with a modified environment | 2,231,227 | <p>I believe that running an external command with a slightly modified environment is a very common case. That's how I tend to do it:</p>
<pre><code>import subprocess, os
my_env = os.environ
my_env["PATH"] = "/usr/sbin:/sbin:" + my_env["PATH"]
subprocess.Popen(my_command, env=my_env)
</code></pre>
<p>I've got a gut f... | 128 | 2010-02-09T17:55:16Z | 4,453,495 | <p>I think <code>os.environ.copy()</code> is better if you don't intend to modify the os.environ for the current process:</p>
<pre><code>import subprocess, os
my_env = os.environ.copy()
my_env["PATH"] = "/usr/sbin:/sbin:" + my_env["PATH"]
subprocess.Popen(my_command, env=my_env)
</code></pre>
| 161 | 2010-12-15T18:28:23Z | [
"python",
"subprocess",
"popen"
] |
Python subprocess/Popen with a modified environment | 2,231,227 | <p>I believe that running an external command with a slightly modified environment is a very common case. That's how I tend to do it:</p>
<pre><code>import subprocess, os
my_env = os.environ
my_env["PATH"] = "/usr/sbin:/sbin:" + my_env["PATH"]
subprocess.Popen(my_command, env=my_env)
</code></pre>
<p>I've got a gut f... | 128 | 2010-02-09T17:55:16Z | 17,687,991 | <p>I know this has been answered for some time, but there are some points that some may want to know about using PYTHONPATH instead of PATH in their environment variable. I have outlined an explanation of running python scripts with cronjobs that deals with the modified environment in a different way (<a href="http://s... | 1 | 2013-07-16T22:21:44Z | [
"python",
"subprocess",
"popen"
] |
Python subprocess/Popen with a modified environment | 2,231,227 | <p>I believe that running an external command with a slightly modified environment is a very common case. That's how I tend to do it:</p>
<pre><code>import subprocess, os
my_env = os.environ
my_env["PATH"] = "/usr/sbin:/sbin:" + my_env["PATH"]
subprocess.Popen(my_command, env=my_env)
</code></pre>
<p>I've got a gut f... | 128 | 2010-02-09T17:55:16Z | 28,989,538 | <p>That depends on what the issue is. If it's to clone and modify the environment one solution could be:</p>
<pre><code>subprocess.Popen(my_command, env=dict(os.environ, PATH="path"))
</code></pre>
<p>But that somewhat depends on that the replaced variables are valid python identifiers, which they most often are (how... | 28 | 2015-03-11T14:38:32Z | [
"python",
"subprocess",
"popen"
] |
Python subprocess/Popen with a modified environment | 2,231,227 | <p>I believe that running an external command with a slightly modified environment is a very common case. That's how I tend to do it:</p>
<pre><code>import subprocess, os
my_env = os.environ
my_env["PATH"] = "/usr/sbin:/sbin:" + my_env["PATH"]
subprocess.Popen(my_command, env=my_env)
</code></pre>
<p>I've got a gut f... | 128 | 2010-02-09T17:55:16Z | 32,470,245 | <p>If you are using a Unix, there is other way to put the environment variable that might be more flexible for some use cases, using as command for open <code>["/bin/bash", "-c", "MY_ENVIRONMENT=1 my_command"]</code></p>
<p>Example:</p>
<pre><code>cmd_parts = ["/bin/bash", "-c", "MY_ENV=1 env | grep MY_ENV"]
process ... | 0 | 2015-09-09T03:00:24Z | [
"python",
"subprocess",
"popen"
] |
Python subprocess/Popen with a modified environment | 2,231,227 | <p>I believe that running an external command with a slightly modified environment is a very common case. That's how I tend to do it:</p>
<pre><code>import subprocess, os
my_env = os.environ
my_env["PATH"] = "/usr/sbin:/sbin:" + my_env["PATH"]
subprocess.Popen(my_command, env=my_env)
</code></pre>
<p>I've got a gut f... | 128 | 2010-02-09T17:55:16Z | 37,417,961 | <p>With Python 3.5 you could do it this way:</p>
<pre><code>import os
import subprocess
my_env = {**os.environ, 'PATH': '/usr/sbin:/sbin:' + os.environ['PATH']}
subprocess.Popen(my_command, env=my_env)
</code></pre>
<p>Here we end up with a copy of <code>os.environ</code> and overridden <code>PATH</code> value.</p>... | 1 | 2016-05-24T15:30:59Z | [
"python",
"subprocess",
"popen"
] |
Python subprocess/Popen with a modified environment | 2,231,227 | <p>I believe that running an external command with a slightly modified environment is a very common case. That's how I tend to do it:</p>
<pre><code>import subprocess, os
my_env = os.environ
my_env["PATH"] = "/usr/sbin:/sbin:" + my_env["PATH"]
subprocess.Popen(my_command, env=my_env)
</code></pre>
<p>I've got a gut f... | 128 | 2010-02-09T17:55:16Z | 38,616,763 | <p>If you're working in aws the rpm for their RDS version isn't commonly available.</p>
<pre><code>sudo rpm -Uvh https://download.postgresql.org/pub/repos/yum/9.5/redhat/rhel-6-x86_64/pgdg-ami201503-95-9.5-2.noarch.rpm
sudo yum install postgresql95
</code></pre>
<p>Stole that from this answer;
<a href="http://stackov... | 0 | 2016-07-27T15:04:10Z | [
"python",
"subprocess",
"popen"
] |
Python subprocess/Popen with a modified environment | 2,231,227 | <p>I believe that running an external command with a slightly modified environment is a very common case. That's how I tend to do it:</p>
<pre><code>import subprocess, os
my_env = os.environ
my_env["PATH"] = "/usr/sbin:/sbin:" + my_env["PATH"]
subprocess.Popen(my_command, env=my_env)
</code></pre>
<p>I've got a gut f... | 128 | 2010-02-09T17:55:16Z | 39,362,418 | <p>To temporarily set an environment variable without having to copy the os.envrion object etc, I do this:</p>
<pre><code>process = subprocess.Popen(['env', 'RSYNC_PASSWORD=foobar', 'rsync', \
'rsync://username@foobar.com::'], stdout=subprocess.PIPE)
</code></pre>
| 0 | 2016-09-07T06:16:14Z | [
"python",
"subprocess",
"popen"
] |
pyserial- sending in parameters at runtime- input vs. raw_input - security flaw? | 2,231,249 | <p>I am writing a program that opens and records data sent through a serial port into a text file. I am currently adding functionality to allow reconfiguring the serial port during run-time. I prompt the user to choose which variable to change one at a time, so as to keep it simple for myself (i would appreciate elegan... | 0 | 2010-02-09T17:57:45Z | 2,231,310 | <p>The safest way is just to accept the user's input as a string and then parse it. I.e. let the user enter key=value pairs:</p>
<pre><code>baudrate = 9600
parity = N
</code></pre>
<p>Then parse these pairs, by splitting on '=' and stripping both sides. Assign the variables with a string lookup table (the <code>baudr... | 0 | 2010-02-09T18:08:13Z | [
"python",
"security",
"user-input",
"pyserial"
] |
Updating python variable from c | 2,231,287 | <p>I am having an intermittent error causing my Python module to crash, and I'm assuming it's because of a memory error occurring by not getting the refcounts correct in the c code. I have a bit of code that gets a response at a random time from a remote location. Based on the data received, it needs to update a data v... | 0 | 2010-02-09T18:04:13Z | 2,231,307 | <p><a href="http://docs.python.org/c-api/module.html#PyModule_AddObject" rel="nofollow"><code>PyModule_AddObject()</code></a> <em>steals</em> a reference. As such, you should not be decrefing list after.</p>
| 1 | 2010-02-09T18:07:29Z | [
"python",
"c"
] |
Updating python variable from c | 2,231,287 | <p>I am having an intermittent error causing my Python module to crash, and I'm assuming it's because of a memory error occurring by not getting the refcounts correct in the c code. I have a bit of code that gets a response at a random time from a remote location. Based on the data received, it needs to update a data v... | 0 | 2010-02-09T18:04:13Z | 2,232,491 | <p><code>PyList_New()</code> can return <code>NULL</code> to indicate an error, which you aren't checking for. <code>Py_BuildValue()</code> can return <code>NULL</code> to indicate an error, which you aren't checking for. <code>PyList_Append()</code> can return <code>-1</code> to indicate an error, which you're also no... | 1 | 2010-02-09T21:02:22Z | [
"python",
"c"
] |
sqlalchemy backref slow | 2,231,324 | <p>Hi have have the following tables </p>
<pre><code>nfiletable = Table(
'NFILE', base.metadata,
Column('fileid', Integer, primary_key=True),
Column('path', String(300)),
Column('filename', String(50)),
Column('filesize', Integer),
schema='NATIVEFILES')#,autoload=True,autoload_with=engine)
she... | 1 | 2010-02-09T18:09:51Z | 2,259,952 | <p>if NFile.sheets references a huge collection, put "lazy='dynamic'" on the backref:</p>
<pre><code>mapper(Sheet, sheetnames_table, properties={
'files': relation(
Nfile, secondary=nfile_sheet_table,
backref=backref('sheets', lazy='dynamic'))
})
</code></pre>
<p>All the primaryjoin/secondaryjoin/... | 1 | 2010-02-14T02:40:06Z | [
"python",
"sqlalchemy"
] |
Error when calling the metaclass bases: function() argument 1 must be code, not str | 2,231,427 | <p>I tried to subclass threading.Condition earlier today but it didn't work out. Here is the output of the Python interpreter when I try to subclass the threading.Condition class:</p>
<pre><code>>>> import threading
>>> class ThisWontWork(threading.Condition):
... pass
...
Traceback (most recent... | 30 | 2010-02-09T18:24:16Z | 2,231,478 | <p>You're getting that exception because, despite its class-like name, <code>threading.Condition</code> is a function, and you cannot subclass functions.</p>
<pre><code>>>> type(threading.Condition)
<type 'function'>
</code></pre>
<p>This not-very-helpful error message has been <a href="http://bugs.pyt... | 46 | 2010-02-09T18:31:36Z | [
"python",
"class",
"inheritance",
"metaclass"
] |
Error when calling the metaclass bases: function() argument 1 must be code, not str | 2,231,427 | <p>I tried to subclass threading.Condition earlier today but it didn't work out. Here is the output of the Python interpreter when I try to subclass the threading.Condition class:</p>
<pre><code>>>> import threading
>>> class ThisWontWork(threading.Condition):
... pass
...
Traceback (most recent... | 30 | 2010-02-09T18:24:16Z | 3,507,510 | <p>Different problem than OP had, but you can also get this error if you try to subclass from a module instead of a class (e.g. you try to inherit My.Module instead of My.Module.Class). Kudos to <a href="http://andre.stechert.org/urwhatu/2005/03/typeerror_error.html" rel="nofollow">this post</a> for helping me figure t... | 19 | 2010-08-17T22:32:50Z | [
"python",
"class",
"inheritance",
"metaclass"
] |
Error when calling the metaclass bases: function() argument 1 must be code, not str | 2,231,427 | <p>I tried to subclass threading.Condition earlier today but it didn't work out. Here is the output of the Python interpreter when I try to subclass the threading.Condition class:</p>
<pre><code>>>> import threading
>>> class ThisWontWork(threading.Condition):
... pass
...
Traceback (most recent... | 30 | 2010-02-09T18:24:16Z | 17,067,556 | <p>With respect to subclassing a module, this is a really easy mistake to make if you have,
for example, class Foo defined in a file Foo.py.
When you create a subclass of Foo in a different file, you might accidentally do the following (this is an attempt to subclass a module and will result in an error):</p>
<pre><co... | 12 | 2013-06-12T14:02:15Z | [
"python",
"class",
"inheritance",
"metaclass"
] |
Assign a value equal only to itself | 2,231,781 | <p>I wish to assign to a variable (a "constant"), a value that will allow that variable to only ever return <code>True</code> in <code>is</code> and <code>==</code> comparisons against itself.</p>
<p>I want to avoid assigning an arbitary value such as an <code>int</code> or some other type on the off chance that the v... | 1 | 2010-02-09T19:16:56Z | 2,231,806 | <p>Yes. This is a good way to define unique constants. There is of course, the minimal risk of whatever object you are comparing it to being defined as equal to everything, but if everyone is playing reasonably nicely, this should work. Also, the garbage collection issue won't be a problem, because if that should ev... | 1 | 2010-02-09T19:20:26Z | [
"python",
"comparison",
"unique",
"constants",
"cpython"
] |
Assign a value equal only to itself | 2,231,781 | <p>I wish to assign to a variable (a "constant"), a value that will allow that variable to only ever return <code>True</code> in <code>is</code> and <code>==</code> comparisons against itself.</p>
<p>I want to avoid assigning an arbitary value such as an <code>int</code> or some other type on the off chance that the v... | 1 | 2010-02-09T19:16:56Z | 2,232,073 | <p>As long as <code>MY_CONSTANT</code> stays in scope the object it references can not be garbage collected.
You really should <em>always</em> use <code>is</code> for comparison, as the behaviour of <code>==</code> can be overridden</p>
| 0 | 2010-02-09T19:50:45Z | [
"python",
"comparison",
"unique",
"constants",
"cpython"
] |
Numpy with python 3.0 | 2,231,842 | <p>NumPy installer can't find python path in the registry.</p>
<blockquote>
<p>Cannot install Python version 2.6 required, which was not found in the
registry.</p>
</blockquote>
<p>Is there a numpy build which can be used with python 3.0?</p>
| 21 | 2010-02-09T19:25:26Z | 2,232,131 | <p>there is not [yet] a version of numpy that has been ported to Python 3. </p>
<p>the last update I heard from the people on the project was this:
<a href="http://blog.jarrodmillman.com/2009/01/when-will-numpy-and-scipy-migrate-to.html">http://blog.jarrodmillman.com/2009/01/when-will-numpy-and-scipy-migrate-to.html<... | 11 | 2010-02-09T19:59:17Z | [
"python",
"numpy",
"python-3.x"
] |
Numpy with python 3.0 | 2,231,842 | <p>NumPy installer can't find python path in the registry.</p>
<blockquote>
<p>Cannot install Python version 2.6 required, which was not found in the
registry.</p>
</blockquote>
<p>Is there a numpy build which can be used with python 3.0?</p>
| 21 | 2010-02-09T19:25:26Z | 2,269,785 | <p>Guido van Rossum (creator of Python) says he is <a href="http://neopythonic.blogspot.com/2009/11/python-in-scientific-world.html">keen to see NumPy work in Python 3.x</a>, because it would enable many dependent libraries to move to 3.x.</p>
<p><strong>Update 2010-08-05:</strong> <a href="http://www.mail-archive.com... | 46 | 2010-02-15T23:57:23Z | [
"python",
"numpy",
"python-3.x"
] |
Numpy with python 3.0 | 2,231,842 | <p>NumPy installer can't find python path in the registry.</p>
<blockquote>
<p>Cannot install Python version 2.6 required, which was not found in the
registry.</p>
</blockquote>
<p>Is there a numpy build which can be used with python 3.0?</p>
| 21 | 2010-02-09T19:25:26Z | 2,737,113 | <p>The current development verson of Numpy is compatible with Python 3 -- you can get it from Numpy's SVN and build it yourself. It will probably be released later this year (probably in the summer) as Numpy 2.0.</p>
| 7 | 2010-04-29T12:09:07Z | [
"python",
"numpy",
"python-3.x"
] |
Numpy with python 3.0 | 2,231,842 | <p>NumPy installer can't find python path in the registry.</p>
<blockquote>
<p>Cannot install Python version 2.6 required, which was not found in the
registry.</p>
</blockquote>
<p>Is there a numpy build which can be used with python 3.0?</p>
| 21 | 2010-02-09T19:25:26Z | 8,421,835 | <p>Scipy now also supports Python 3 (<a href="http://sourceforge.net/projects/scipy/files/scipy/0.10.0/" rel="nofollow">http://sourceforge.net/projects/scipy/files/scipy/0.10.0/</a>).</p>
| 7 | 2011-12-07T20:08:59Z | [
"python",
"numpy",
"python-3.x"
] |
check that a script is actually using a proxy from a ip list | 2,231,887 | <p>I have a list of proxy ip's that I want to use in one of my python scripts, but how do I verify that I am using one of the ip addresses from the list and not my own? I'm using mechanize, but any general explanation of how to do this would be helpful. </p>
<p>This is the first time I have worked with proxies, so a... | 0 | 2010-02-09T19:30:30Z | 2,232,325 | <p>Running wireshark / tshark would be one way.</p>
<p>Many proxies run on port 3128, but substitute this for the proxy you're using. Make you request and if you get traffic to the host and port of your configured proxy, it's probably
working. If it goes to the host for the website, then it's not.</p>
<p>E.g. First ... | 1 | 2010-02-09T20:31:38Z | [
"python",
"proxy"
] |
What's python complaining about here? | 2,231,954 | <p>I'm trying to run Adobe's sample python policy server script, linked to here: <a href="http://www.adobe.com/devnet/flashplayer/articles/socket_policy_files.html" rel="nofollow">http://www.adobe.com/devnet/flashplayer/articles/socket_policy_files.html</a></p>
<p>I'm getting the following error:</p>
<pre><code> # py... | 0 | 2010-02-09T19:37:51Z | 2,231,979 | <p>The <code>with</code> statement is new in Python 2.5. Perhaps you are using an older version?</p>
| 1 | 2010-02-09T19:39:44Z | [
"python",
"flash",
"sockets",
"policyfiles"
] |
What's python complaining about here? | 2,231,954 | <p>I'm trying to run Adobe's sample python policy server script, linked to here: <a href="http://www.adobe.com/devnet/flashplayer/articles/socket_policy_files.html" rel="nofollow">http://www.adobe.com/devnet/flashplayer/articles/socket_policy_files.html</a></p>
<p>I'm getting the following error:</p>
<pre><code> # py... | 0 | 2010-02-09T19:37:51Z | 2,231,982 | <p><code>with</code> is only available in 2.6+, or in 2.5+ with <code>from __future__ import with_statement</code>.</p>
| 6 | 2010-02-09T19:40:06Z | [
"python",
"flash",
"sockets",
"policyfiles"
] |
Correct way to emulate single precision floating point in python? | 2,232,362 | <p>What's the best way to emulate single-precision floating point in python? (Or other floating point formats for that matter?) Just use ctypes?</p>
| 15 | 2010-02-09T20:37:10Z | 2,232,382 | <p><a href="http://numpy.scipy.org/"><code>numpy</code></a> has a <a href="http://docs.scipy.org/doc/numpy/user/basics.types.html?highlight=float32#array-types-and-conversions-between-types"><code>float32</code></a> type.</p>
| 17 | 2010-02-09T20:41:24Z | [
"python",
"floating-point"
] |
Correct way to emulate single precision floating point in python? | 2,232,362 | <p>What's the best way to emulate single-precision floating point in python? (Or other floating point formats for that matter?) Just use ctypes?</p>
| 15 | 2010-02-09T20:37:10Z | 2,232,387 | <p>If your application suits arrays/matrices, you can use numpy with <code>float32</code></p>
| 2 | 2010-02-09T20:42:23Z | [
"python",
"floating-point"
] |
Correct way to emulate single precision floating point in python? | 2,232,362 | <p>What's the best way to emulate single-precision floating point in python? (Or other floating point formats for that matter?) Just use ctypes?</p>
| 15 | 2010-02-09T20:37:10Z | 2,232,650 | <p>If <code>numpy</code> (the excellent suggestion of other answers) is inapplicable for you (e.g. because you're in an environment that doesn't allow arbitrary third-party extensions), the <a href="http://docs.python.org/library/array.html?highlight=array#module-array">array</a> module in Python standard library is fi... | 6 | 2010-02-09T21:25:26Z | [
"python",
"floating-point"
] |
Correct way to emulate single precision floating point in python? | 2,232,362 | <p>What's the best way to emulate single-precision floating point in python? (Or other floating point formats for that matter?) Just use ctypes?</p>
| 15 | 2010-02-09T20:37:10Z | 2,232,830 | <p>how about ctypes.c_float from standard library?</p>
| 4 | 2010-02-09T21:56:59Z | [
"python",
"floating-point"
] |
How to mount a network directory using python? | 2,232,420 | <p>I need to mount a directory "dir" on a network machine "data" using python on a linux machine</p>
<p>I know that I can send the command via command line:</p>
<pre><code>mkdir ~/mnt/data_dir
mount -t data:/dir/ ~/mnt/data_dir
</code></pre>
<p>but how would I send those commands from a python script?</p>
| 7 | 2010-02-09T20:47:49Z | 2,232,463 | <p>Here is one way:</p>
<pre><code>import os
os.cmd ("mkdir ~/mnt/data_dir mount -t data:/dir/ /mnt/data_dir")
</code></pre>
<p>You can also use "popen" if you want to read the output of the command in your script.</p>
<p>HIH</p>
<p>...richie</p>
| 1 | 2010-02-09T20:56:20Z | [
"python",
"linux",
"scripting",
"mount"
] |
How to mount a network directory using python? | 2,232,420 | <p>I need to mount a directory "dir" on a network machine "data" using python on a linux machine</p>
<p>I know that I can send the command via command line:</p>
<pre><code>mkdir ~/mnt/data_dir
mount -t data:/dir/ ~/mnt/data_dir
</code></pre>
<p>but how would I send those commands from a python script?</p>
| 7 | 2010-02-09T20:47:49Z | 2,232,697 | <p>Example using the <code>subprocess</code> module:</p>
<pre><code>import subprocess
subprocess.Popen(["mkdir", "~/mnt/data_dir", "mount", "-t", "data:/dir/", "/mnt/data_dir"])
</code></pre>
<p>OR</p>
<pre><code>import subprocess
subprocess.Popen("mkdir ~/mnt/data_dir mount -t data:/dir/ /mnt/data_dir", shell=Tru... | 2 | 2010-02-09T21:34:15Z | [
"python",
"linux",
"scripting",
"mount"
] |
How to mount a network directory using python? | 2,232,420 | <p>I need to mount a directory "dir" on a network machine "data" using python on a linux machine</p>
<p>I know that I can send the command via command line:</p>
<pre><code>mkdir ~/mnt/data_dir
mount -t data:/dir/ ~/mnt/data_dir
</code></pre>
<p>but how would I send those commands from a python script?</p>
| 7 | 2010-02-09T20:47:49Z | 5,185,074 | <p>I'd recommend you use <code>subprocess.checkcall</code>.</p>
<pre><code>from subprocess import *
#most simply
check_call( 'mkdir ~/mnt/data_dir', shell=True )
check_call( 'mount -t whatever data:/dir/ ~/mnt/data_dir', shell=True )
#more securely
from os.path import expanduser
check_call( [ 'mkdir', expanduser( '... | 8 | 2011-03-03T18:46:06Z | [
"python",
"linux",
"scripting",
"mount"
] |
How to mount a network directory using python? | 2,232,420 | <p>I need to mount a directory "dir" on a network machine "data" using python on a linux machine</p>
<p>I know that I can send the command via command line:</p>
<pre><code>mkdir ~/mnt/data_dir
mount -t data:/dir/ ~/mnt/data_dir
</code></pre>
<p>but how would I send those commands from a python script?</p>
| 7 | 2010-02-09T20:47:49Z | 5,751,550 | <p>I tried this in a chroot without proc mounted</p>
<pre><code>/ # python
Python 2.7.1 (r271:86832, Feb 26 2011, 00:09:03)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> from ctypes import *
>>> libc = cdll.LoadLibrary("libc.s... | 6 | 2011-04-22T01:47:48Z | [
"python",
"linux",
"scripting",
"mount"
] |
Python import MySQLdb, Apache Internal Server Error | 2,232,542 | <p>I'm having a similar problem to that described in "<a href="http://stackoverflow.com/questions/621874/cgi-problem-with-web-server">.cgi problem with web server</a>", although I reviewed and tested the previously suggested solutions without success.</p>
<p>I'm running the same program on Mac OS X 10.5.8, Apache 2.2.... | 3 | 2010-02-09T21:09:02Z | 2,232,564 | <p>Make sure the python binary that Apache is using has <code>MySQLdb</code> in its <code>PYTHONPATH</code>. </p>
<p>Confirm it by checking the location of MySQLdb in the working script:</p>
<pre><code>import os
print os.path.dirname(MySQLdb.__file__)
</code></pre>
<p>And comparing that to the output of <code>sys.p... | 2 | 2010-02-09T21:12:56Z | [
"python",
"cgi"
] |
Python import MySQLdb, Apache Internal Server Error | 2,232,542 | <p>I'm having a similar problem to that described in "<a href="http://stackoverflow.com/questions/621874/cgi-problem-with-web-server">.cgi problem with web server</a>", although I reviewed and tested the previously suggested solutions without success.</p>
<p>I'm running the same program on Mac OS X 10.5.8, Apache 2.2.... | 3 | 2010-02-09T21:09:02Z | 12,632,782 | <p>I have this problem too, but I figured it out after several hours trying.</p>
<p><strong>Here is my scenario:</strong> I need to <code>import MySQLdb</code> in a Python cgi file, but it failed, and raised the <code>ImportError</code>.</p>
<p>Then I print out the Web server path and local python path, they were:</p... | 1 | 2012-09-28T02:25:35Z | [
"python",
"cgi"
] |
I've got Python built using VS2008, how do I install it? | 2,232,579 | <p>I'm working with boost::python and wanted to build the whole thing to make sure I can pull it off. However, I don't see any install script or way to build the MSI so I can install it.</p>
<p>Anyone know where the directions are? Or the projects I could use to make an MSI file?</p>
<p>Doing this on linux seems tr... | 0 | 2010-02-09T21:14:36Z | 2,233,535 | <p>All of this is much easier with <a href="http://www.mingw.org/" rel="nofollow">MinGW</a>, plus there's the fact that it's likely to be compatible with the ABI of the official package so that you can just install that instead and only build extensions with MinGW.</p>
| 0 | 2010-02-10T00:19:12Z | [
"python",
"boost",
"windows-installer"
] |
I've got Python built using VS2008, how do I install it? | 2,232,579 | <p>I'm working with boost::python and wanted to build the whole thing to make sure I can pull it off. However, I don't see any install script or way to build the MSI so I can install it.</p>
<p>Anyone know where the directions are? Or the projects I could use to make an MSI file?</p>
<p>Doing this on linux seems tr... | 0 | 2010-02-09T21:14:36Z | 2,242,444 | <p>Well, the python mailing list was some help.</p>
<p>Turns out there is an tools/msi directory and in there is python code to help build the MSI from the tree you built. Only problem is you can't use it without having python and PythonWin installed. So I grabbed 2.6.4 python and pythonwin and installed them.</p>
... | 0 | 2010-02-11T05:17:45Z | [
"python",
"boost",
"windows-installer"
] |
Python newbie having a problem using classes | 2,232,740 | <p>Im just beginning to mess around a bit with classes; however, I am running across a problem.</p>
<pre><code>class MyClass(object):
def f(self):
return 'hello world'
print MyClass.f
</code></pre>
<p>The previous script is returning <code><unbound method MyClass.f></code> instead of the intended va... | 6 | 2010-02-09T21:43:23Z | 2,232,753 | <p>Create an instance of your class: <code>m = MyClass()</code></p>
<p>then use <code>m.f()</code> to call the function</p>
<p>Now you may wonder why you don't have to pass a parameter to the function (the 'self' param). It is because the instance on which you call the function is actually passed as the first paramet... | 7 | 2010-02-09T21:44:55Z | [
"python",
"class"
] |
Python newbie having a problem using classes | 2,232,740 | <p>Im just beginning to mess around a bit with classes; however, I am running across a problem.</p>
<pre><code>class MyClass(object):
def f(self):
return 'hello world'
print MyClass.f
</code></pre>
<p>The previous script is returning <code><unbound method MyClass.f></code> instead of the intended va... | 6 | 2010-02-09T21:43:23Z | 2,232,772 | <p><code>MyClass.f</code> refers to the function object f which is a property of MyClass. In your case, f is an instance method (has a self parameter) so its called on a particular instance. Its "unbound" because you're referring to f without specifying a specific class, kind of like referring to a steering wheel witho... | 14 | 2010-02-09T21:47:12Z | [
"python",
"class"
] |
Does Python PIL resize maintain the aspect ratio? | 2,232,742 | <p>Does PIL resize to the exact dimensions I give it no matter what? Or will it try to keep the aspect ratio if I give it something like the <code>Image.ANTIALIAS</code> argument?</p>
| 2 | 2010-02-09T21:43:27Z | 2,232,815 | <p><a href="http://stackoverflow.com/questions/273946/how-do-i-resize-an-image-using-pil-and-maintain-its-aspect-ratio">How do I resize an image using PIL and maintain its aspect ratio?</a></p>
<p>Image.resize from PIL will do exactly as told. No behind scenes aspect ratio stuff.</p>
| 4 | 2010-02-09T21:54:31Z | [
"python",
"resize",
"python-imaging-library"
] |
Does Python PIL resize maintain the aspect ratio? | 2,232,742 | <p>Does PIL resize to the exact dimensions I give it no matter what? Or will it try to keep the aspect ratio if I give it something like the <code>Image.ANTIALIAS</code> argument?</p>
| 2 | 2010-02-09T21:43:27Z | 4,271,003 | <p>Yes it will keep aspect ratio using <strong>thumbnail</strong> method:</p>
<pre><code>image = Image.open(source_path)
image.thumbnail(size, Image.ANTIALIAS)
image.save(dest_path, "JPEG")
</code></pre>
| 7 | 2010-11-24T20:04:17Z | [
"python",
"resize",
"python-imaging-library"
] |
Does Python PIL resize maintain the aspect ratio? | 2,232,742 | <p>Does PIL resize to the exact dimensions I give it no matter what? Or will it try to keep the aspect ratio if I give it something like the <code>Image.ANTIALIAS</code> argument?</p>
| 2 | 2010-02-09T21:43:27Z | 7,461,971 | <p>Yes. the thumbnail() method is what is needed here... One thing that hasn't been mentioned in this or other posts on the topic is that 'size' must be either a list or tuple. So, to resize to a maximum dimension of 500 pixels, you would call:
image.thumbnail((500,500), Image.ANTIALIAS)</p>
<p>See also this post ... | 1 | 2011-09-18T14:06:18Z | [
"python",
"resize",
"python-imaging-library"
] |
How to include in code an unique ID related to a mercurial commit? | 2,232,852 | <p>I'd like to do the same thing that they're doing here in stackoverflow.</p>
<pre><code><link rel="stylesheet" href="http://sstatic.net/so/all.css?v=6274">
<script type="text/javascript" src="http://sstatic.net/so/js/master.js?v=6180"></script>
<script src="http://sstatic.net/so/js/question.js... | 2 | 2010-02-09T22:02:01Z | 2,232,919 | <p><a href="http://mercurial.selenic.com/wiki/KeywordExtension" rel="nofollow">KeywordExtension</a> will let you put a keyword in a file whose results you can tear apart in order to get the hash.</p>
| 4 | 2010-02-09T22:13:13Z | [
"python",
"django",
"caching",
"mercurial"
] |
Where do stdout and stderr go when in curses mode? | 2,233,006 | <p>Where do stdout and stderr go when curses is active?</p>
<pre><code>import curses, sys
def test_streams():
print "stdout"
print >>sys.stderr, "stderr"
def curses_mode(stdscr):
test_streams()
test_streams()
curses.wrapper(curses_mode)
</code></pre>
<p>Actual output is</p>
<pre><code>stdout
std... | 6 | 2010-02-09T22:33:12Z | 2,234,410 | <p>Activating curses saves the terminal text screen's current contents and clears said screen; exiting curses restores the screen's contents (tossing away whatever's been put on screen during the reign of curses itself). Try with this variant of your code and you'll see better what's happening:</p>
<pre><code>import ... | 4 | 2010-02-10T04:26:35Z | [
"python",
"ncurses",
"curses"
] |
How does zip(*[iter(s)]*n) work in Python? | 2,233,204 | <pre><code>s = [1,2,3,4,5,6,7,8,9]
n = 3
zip(*[iter(s)]*n) # returns [(1,2,3),(4,5,6),(7,8,9)]
</code></pre>
<p>How does <code>zip(*[iter(s)]*n)</code> work? What would it look like if it was written with more verbose code?</p>
| 65 | 2010-02-09T23:07:21Z | 2,233,247 | <p><a href="https://docs.python.org/2/library/functions.html#iter"><code>iter()</code></a> is an iterator over a sequence. <code>[x] * n</code> produces a list containing <code>n</code> quantity of <code>x</code>, i.e. a list of length <code>n</code>, where each element is <code>x</code>. <code>*arg</code> unpacks a se... | 68 | 2010-02-09T23:15:10Z | [
"python",
"iterator"
] |
How does zip(*[iter(s)]*n) work in Python? | 2,233,204 | <pre><code>s = [1,2,3,4,5,6,7,8,9]
n = 3
zip(*[iter(s)]*n) # returns [(1,2,3),(4,5,6),(7,8,9)]
</code></pre>
<p>How does <code>zip(*[iter(s)]*n)</code> work? What would it look like if it was written with more verbose code?</p>
| 65 | 2010-02-09T23:07:21Z | 2,233,289 | <p><code>iter(s)</code> returns an iterator for s.</p>
<p><code>[iter(s)]*n</code> makes a list of n times the same iterator for s.</p>
<p>So, when doing <code>zip(*[iter(s)]*n)</code>, it extracts an item from all the three iterators from the list in order. Since all the iterators are the same object, it just groups... | 6 | 2010-02-09T23:23:28Z | [
"python",
"iterator"
] |
How does zip(*[iter(s)]*n) work in Python? | 2,233,204 | <pre><code>s = [1,2,3,4,5,6,7,8,9]
n = 3
zip(*[iter(s)]*n) # returns [(1,2,3),(4,5,6),(7,8,9)]
</code></pre>
<p>How does <code>zip(*[iter(s)]*n)</code> work? What would it look like if it was written with more verbose code?</p>
| 65 | 2010-02-09T23:07:21Z | 2,233,827 | <p>The other great answers and comments explain well the roles of <a href="http://docs.python.org/tutorial/controlflow.html#unpacking-argument-lists"><strong>argument unpacking</strong></a> and <a href="http://docs.python.org/library/functions.html#zip"><strong>zip()</strong></a>.</p>
<p>As <a href="http://stackoverfl... | 33 | 2010-02-10T01:32:39Z | [
"python",
"iterator"
] |
How does zip(*[iter(s)]*n) work in Python? | 2,233,204 | <pre><code>s = [1,2,3,4,5,6,7,8,9]
n = 3
zip(*[iter(s)]*n) # returns [(1,2,3),(4,5,6),(7,8,9)]
</code></pre>
<p>How does <code>zip(*[iter(s)]*n)</code> work? What would it look like if it was written with more verbose code?</p>
| 65 | 2010-02-09T23:07:21Z | 14,630,643 | <p>One word of advice for using zip this way. It will truncate your list if it's length is not evenly divisible. To work around this you could either use <a href="http://docs.python.org/2/library/itertools.html#itertools.izip_longest" rel="nofollow">itertools.izip_longest</a> if you can accept fill values. Or you could... | 4 | 2013-01-31T16:34:53Z | [
"python",
"iterator"
] |
How does zip(*[iter(s)]*n) work in Python? | 2,233,204 | <pre><code>s = [1,2,3,4,5,6,7,8,9]
n = 3
zip(*[iter(s)]*n) # returns [(1,2,3),(4,5,6),(7,8,9)]
</code></pre>
<p>How does <code>zip(*[iter(s)]*n)</code> work? What would it look like if it was written with more verbose code?</p>
| 65 | 2010-02-09T23:07:21Z | 30,380,585 | <p>I think one thing that's missed in all the answers (probably obvious to those familiar with iterators) but not so obvious to others is - </p>
<p>Since we have the same iterator, it gets consumed and the remaining elements are used by the zip. So if we simply used the list and not the iter
eg.</p>
<pre><code>l = r... | 6 | 2015-05-21T17:29:40Z | [
"python",
"iterator"
] |
Python - letter frequency count and translation | 2,233,355 | <p>I am using Python 3.1, but I can downgrade if needed.</p>
<p>I have an ASCII file containing a short story written in one of the languages the alphabet of which can be represented with upper and or lower ASCII. I wish to:</p>
<p>1) Detect an encoding to the best of my abilities, get some sort of confidence metric ... | 6 | 2010-02-09T23:37:45Z | 2,233,383 | <p>If you have an ASCII file then I can tell you with 100% confidence that it is encoded in ASCII. Beyond that try <a href="http://chardet.feedparser.org/" rel="nofollow"><code>chardet</code></a>. But knowing the encoding isn't necessarily enough to determine what language it's in.</p>
<p>As for multibyte encodings, T... | 1 | 2010-02-09T23:42:50Z | [
"python",
"character-encoding",
"translation",
"nlp"
] |
Python - letter frequency count and translation | 2,233,355 | <p>I am using Python 3.1, but I can downgrade if needed.</p>
<p>I have an ASCII file containing a short story written in one of the languages the alphabet of which can be represented with upper and or lower ASCII. I wish to:</p>
<p>1) Detect an encoding to the best of my abilities, get some sort of confidence metric ... | 6 | 2010-02-09T23:37:45Z | 2,233,403 | <p>Essentially there are three main tasks to implement the described application:</p>
<ul>
<li>1a) Identify the character encoding of the input text</li>
<li>1b) Identify the language of the input text</li>
<li>2) Get the text translated the text, by way of one of the online services' API</li>
</ul>
<p>For 1a, you ma... | 2 | 2010-02-09T23:47:24Z | [
"python",
"character-encoding",
"translation",
"nlp"
] |
Python - letter frequency count and translation | 2,233,355 | <p>I am using Python 3.1, but I can downgrade if needed.</p>
<p>I have an ASCII file containing a short story written in one of the languages the alphabet of which can be represented with upper and or lower ASCII. I wish to:</p>
<p>1) Detect an encoding to the best of my abilities, get some sort of confidence metric ... | 6 | 2010-02-09T23:37:45Z | 2,233,406 | <p>Character frequency is pretty straight forward</p>
<p>I just noticed that you are using Python3.1 so this is even easier</p>
<pre><code>>>> from collections import Counter
>>> Counter("ÎεÏαλλικα")
Counter({'α': 2, 'λ': 2, 'Ï': 1, 'ε': 1, 'ι': 1, 'κ': 1, 'Î': 1})
</code></pre>
<p>... | 2 | 2010-02-09T23:48:19Z | [
"python",
"character-encoding",
"translation",
"nlp"
] |
Python - letter frequency count and translation | 2,233,355 | <p>I am using Python 3.1, but I can downgrade if needed.</p>
<p>I have an ASCII file containing a short story written in one of the languages the alphabet of which can be represented with upper and or lower ASCII. I wish to:</p>
<p>1) Detect an encoding to the best of my abilities, get some sort of confidence metric ... | 6 | 2010-02-09T23:37:45Z | 2,233,649 | <p>I have provided some conditional answers however your question is a little vague and inconsistent. Please edit your question to provide answers to my questions below. </p>
<p>(1) You say that the file is ASCII but you want to detect an encoding? Huh? Isn't the answer "ascii"?? If you really need to detect an encodi... | 1 | 2010-02-10T00:46:48Z | [
"python",
"character-encoding",
"translation",
"nlp"
] |
How to delete list elements while cycling the list itself without duplicate it | 2,233,388 | <p>I lost a little bit of time in this Python for statement:</p>
<pre><code>class MyListContainer:
def __init__(self):
self.list = []
def purge(self):
for object in self.list:
if (object.my_cond()):
self.list.remove(object)
return self.list
container = MyLi... | 1 | 2010-02-09T23:43:25Z | 2,233,396 | <p>Don't try. Just don't. Make a copy or generate a new list.</p>
| 4 | 2010-02-09T23:45:03Z | [
"python",
"list",
"cycle"
] |
How to delete list elements while cycling the list itself without duplicate it | 2,233,388 | <p>I lost a little bit of time in this Python for statement:</p>
<pre><code>class MyListContainer:
def __init__(self):
self.list = []
def purge(self):
for object in self.list:
if (object.my_cond()):
self.list.remove(object)
return self.list
container = MyLi... | 1 | 2010-02-09T23:43:25Z | 2,233,399 | <p>Just make yourself a new list:</p>
<pre><code>def purge(self):
self.list = [object for object in self.list if not object.my_cond()]
return self.list
</code></pre>
<p>Reserve any optimization until you've profiled and found that this method really is the bottleneck of your application. (I bet it won't be.)<... | 3 | 2010-02-09T23:45:41Z | [
"python",
"list",
"cycle"
] |
How to delete list elements while cycling the list itself without duplicate it | 2,233,388 | <p>I lost a little bit of time in this Python for statement:</p>
<pre><code>class MyListContainer:
def __init__(self):
self.list = []
def purge(self):
for object in self.list:
if (object.my_cond()):
self.list.remove(object)
return self.list
container = MyLi... | 1 | 2010-02-09T23:43:25Z | 2,233,410 | <p>Your second solution in which you duplicate the list is the right way to go. Afterward you can just replace the old list with the duplicate if need be.</p>
| 0 | 2010-02-09T23:48:57Z | [
"python",
"list",
"cycle"
] |
How to delete list elements while cycling the list itself without duplicate it | 2,233,388 | <p>I lost a little bit of time in this Python for statement:</p>
<pre><code>class MyListContainer:
def __init__(self):
self.list = []
def purge(self):
for object in self.list:
if (object.my_cond()):
self.list.remove(object)
return self.list
container = MyLi... | 1 | 2010-02-09T23:43:25Z | 2,233,428 | <p>In python variables are actually labels to data. Duplicating a list is, for the most part, making a new set of pointers to the data from the first list. Don't feel too bad about it.</p>
<p>List comprehensions are your friend.</p>
<p>e.g.</p>
<pre><code>>>> a = range(20)
>>> a
[0, 1, 2, 3, 4, 5, ... | 2 | 2010-02-09T23:53:06Z | [
"python",
"list",
"cycle"
] |
How to delete list elements while cycling the list itself without duplicate it | 2,233,388 | <p>I lost a little bit of time in this Python for statement:</p>
<pre><code>class MyListContainer:
def __init__(self):
self.list = []
def purge(self):
for object in self.list:
if (object.my_cond()):
self.list.remove(object)
return self.list
container = MyLi... | 1 | 2010-02-09T23:43:25Z | 2,233,436 | <p>Filter (or list comprehension) IS the way to go. If you want to do it inplace, something like this would work:</p>
<pre><code>purge = []
for i,object in enumerate(self.list):
if object.mycond()
purge.append(i)
for i in reversed(purge):
del self.list[i]
</code></pre>
<p>Or alternatively, the purge l... | 2 | 2010-02-09T23:54:11Z | [
"python",
"list",
"cycle"
] |
How to delete list elements while cycling the list itself without duplicate it | 2,233,388 | <p>I lost a little bit of time in this Python for statement:</p>
<pre><code>class MyListContainer:
def __init__(self):
self.list = []
def purge(self):
for object in self.list:
if (object.my_cond()):
self.list.remove(object)
return self.list
container = MyLi... | 1 | 2010-02-09T23:43:25Z | 2,233,513 | <p>It's perfectly safe to shorten the list in place if you do it in reverse!</p>
<pre><code>>>> a=range(20)
>>> for i in reversed(range(len(a))):
... if a[i]%2: del a[i]
...
>>> a
[0, 2, 4, 6, 8, 10, 12, 14, 16, 18]
</code></pre>
<p>Another way is to reassign the whole slice</p>
<pre>... | 0 | 2010-02-10T00:13:18Z | [
"python",
"list",
"cycle"
] |
How to delete list elements while cycling the list itself without duplicate it | 2,233,388 | <p>I lost a little bit of time in this Python for statement:</p>
<pre><code>class MyListContainer:
def __init__(self):
self.list = []
def purge(self):
for object in self.list:
if (object.my_cond()):
self.list.remove(object)
return self.list
container = MyLi... | 1 | 2010-02-09T23:43:25Z | 2,233,823 | <pre><code>indeces = []
minus = 0
for i in range(self.list):
if cond(self.list[i]):
indeces.append(i)
for i in indeces:
self.list = self.list[:(i-minus)].extend(self.list[i-minus+1:])
</code></pre>
| -1 | 2010-02-10T01:31:16Z | [
"python",
"list",
"cycle"
] |
Compiling Mysqldb for jython 2.5 on Solaris | 2,233,422 | <p>I have used python2.6 + MySQL on Windows and there are binaries available.</p>
<p>I wanted to get the whole thing working on <code>Solaris</code></p>
<p>Hence got the Mysql-Python package from <a href="http://sourceforge.net/projects/mysql-python/" rel="nofollow">here</a></p>
<p>I had to get the setuptools instal... | 0 | 2010-02-09T23:51:29Z | 2,233,441 | <p>You should be using <a href="http://www.jython.org/archive/21/docs/zxjdbc.html" rel="nofollow"><code>zxJDBC</code></a> and JDBC instead of an external DB-API adapter.</p>
| 1 | 2010-02-09T23:55:40Z | [
"python",
"mysql",
"solaris",
"driver",
"jython"
] |
Can I port my existing python apps on ASE? | 2,233,631 | <p>I learned that the Android Scripting Environment (ASE) supports python code. Can I take my existing python programs and run them on android?</p>
<p>Apart from the GUI, what else will I need to adapt? How can I find the list of supported python libraries for ASE? </p>
| 7 | 2010-02-10T00:44:23Z | 2,233,946 | <p>As of yet, there is no support for a gui on ASE apart from some simple input and display dialogs. Look at /sdcard/ase/extras/python to find libraries already available. You can add new libraries by copying them there.</p>
| 4 | 2010-02-10T02:07:17Z | [
"python",
"android",
"ase",
"android-scripting"
] |
Overriding urllib2.HTTPError or urllib.error.HTTPError and reading response HTML anyway | 2,233,687 | <p>I receive a 'HTTP Error 500: Internal Server Error' response, but I still want to read the data inside the error HTML.</p>
<p>With Python 2.6, I normally fetch a page using:</p>
<pre><code>import urllib2
url = "http://google.com"
data = urllib2.urlopen(url)
data = data.read()
</code></pre>
<p>When attempting to u... | 68 | 2010-02-10T00:55:01Z | 2,233,704 | <p>If you mean you want to read the body of the 500:</p>
<pre><code>request = urllib2.Request(url, data, headers)
try:
resp = urllib2.urlopen(request)
print resp.read()
except urllib2.HTTPError, error:
print "ERROR: ", error.read()
</code></pre>
<p>In your case, you don't need to build up the ... | 8 | 2010-02-10T00:59:42Z | [
"python",
"urllib2",
"urllib",
"http-error"
] |
Overriding urllib2.HTTPError or urllib.error.HTTPError and reading response HTML anyway | 2,233,687 | <p>I receive a 'HTTP Error 500: Internal Server Error' response, but I still want to read the data inside the error HTML.</p>
<p>With Python 2.6, I normally fetch a page using:</p>
<pre><code>import urllib2
url = "http://google.com"
data = urllib2.urlopen(url)
data = data.read()
</code></pre>
<p>When attempting to u... | 68 | 2010-02-10T00:55:01Z | 2,233,778 | <p>The <code>HTTPError</code> <a href="http://docs.python.org/library/urllib2.html#urllib2.HTTPError">is a file-like object</a>. You can catch it and then <code>read</code> its contents.</p>
<pre><code>try:
resp = urllib2.urlopen(url)
contents = resp.read()
except urllib2.HTTPError, error:
contents = erro... | 131 | 2010-02-10T01:18:53Z | [
"python",
"urllib2",
"urllib",
"http-error"
] |
Overriding urllib2.HTTPError or urllib.error.HTTPError and reading response HTML anyway | 2,233,687 | <p>I receive a 'HTTP Error 500: Internal Server Error' response, but I still want to read the data inside the error HTML.</p>
<p>With Python 2.6, I normally fetch a page using:</p>
<pre><code>import urllib2
url = "http://google.com"
data = urllib2.urlopen(url)
data = data.read()
</code></pre>
<p>When attempting to u... | 68 | 2010-02-10T00:55:01Z | 36,529,230 | <pre><code>alist=['http://someurl.com']
def testUrl():
errList=[]
for URL in alist:
try:
urllib2.urlopen(URL)
except urllib2.URLError, err:
(err.reason != 200)
errList.append(URL+" "+str(err.reason))
return URL+" "+str(err.reason)
return "".jo... | -1 | 2016-04-10T11:40:07Z | [
"python",
"urllib2",
"urllib",
"http-error"
] |
overriding bool() for custom class | 2,233,786 | <p>All I want is for bool(myInstance) to return False (and for myInstance to evaluate to False when in a conditional like if/or/and. I know how to override >, <, =)</p>
<p>I've tried this:</p>
<pre><code>class test:
def __bool__(self):
return False
myInst = test()
print bool(myInst) #prints "True"
pri... | 29 | 2010-02-10T01:20:47Z | 2,233,796 | <p><a href="http://docs.python.org/reference/datamodel.html#object.__nonzero__" rel="nofollow"><code>test.__nonzero__()</code></a></p>
| 4 | 2010-02-10T01:23:55Z | [
"python",
"class",
"casting",
"boolean",
"python-2.x"
] |
overriding bool() for custom class | 2,233,786 | <p>All I want is for bool(myInstance) to return False (and for myInstance to evaluate to False when in a conditional like if/or/and. I know how to override >, <, =)</p>
<p>I've tried this:</p>
<pre><code>class test:
def __bool__(self):
return False
myInst = test()
print bool(myInst) #prints "True"
pri... | 29 | 2010-02-10T01:20:47Z | 2,233,801 | <p>Is this Python 2.x or Python 3.x? For Python 2.x you are looking to override <code>__nonzero__</code> instead.</p>
<pre><code>class test:
def __nonzero__(self):
return False
</code></pre>
| 38 | 2010-02-10T01:24:23Z | [
"python",
"class",
"casting",
"boolean",
"python-2.x"
] |
overriding bool() for custom class | 2,233,786 | <p>All I want is for bool(myInstance) to return False (and for myInstance to evaluate to False when in a conditional like if/or/and. I know how to override >, <, =)</p>
<p>I've tried this:</p>
<pre><code>class test:
def __bool__(self):
return False
myInst = test()
print bool(myInst) #prints "True"
pri... | 29 | 2010-02-10T01:20:47Z | 2,233,850 | <p>If you want to keep your code forward compatible with python3 you could do something like this</p>
<pre><code>class test:
def __bool__(self):
return False
__nonzero__=__bool__
</code></pre>
| 38 | 2010-02-10T01:37:04Z | [
"python",
"class",
"casting",
"boolean",
"python-2.x"
] |
overriding bool() for custom class | 2,233,786 | <p>All I want is for bool(myInstance) to return False (and for myInstance to evaluate to False when in a conditional like if/or/and. I know how to override >, <, =)</p>
<p>I've tried this:</p>
<pre><code>class test:
def __bool__(self):
return False
myInst = test()
print bool(myInst) #prints "True"
pri... | 29 | 2010-02-10T01:20:47Z | 20,061,009 | <p>if test is list-like, define <strong>len</strong> and bool(myInstanceOfTest) will return True/False if there are 1+ or 0 items. This worked for me.</p>
<pre><code>class MinPriorityQueue(object):
def __init__(self, iterable):
self.priorityQueue = heapq.heapify(iterable)
def __len__(self):
ret... | 5 | 2013-11-19T00:46:08Z | [
"python",
"class",
"casting",
"boolean",
"python-2.x"
] |
overriding bool() for custom class | 2,233,786 | <p>All I want is for bool(myInstance) to return False (and for myInstance to evaluate to False when in a conditional like if/or/and. I know how to override >, <, =)</p>
<p>I've tried this:</p>
<pre><code>class test:
def __bool__(self):
return False
myInst = test()
print bool(myInst) #prints "True"
pri... | 29 | 2010-02-10T01:20:47Z | 39,132,242 | <p>Similar to John La Rooy, I use:</p>
<pre><code>class Test(object):
def __bool__(self):
return False
def __nonzero__(self):
return self.__bool__()
</code></pre>
| 1 | 2016-08-24T20:09:22Z | [
"python",
"class",
"casting",
"boolean",
"python-2.x"
] |
Get all related Django model objects | 2,233,883 | <p>How can I get a list of all the model objects that have a ForeignKey pointing to an object? (Something like the delete confirmation page in the Django admin before DELETE CASCADE).</p>
<p>I'm trying to come up with a generic way of merging duplicate objects in the database. Basically I want all of the objects tha... | 55 | 2010-02-10T01:46:12Z | 2,234,067 | <p>Give this a try.</p>
<pre><code>class A(models.Model):
def get_foreign_fields(self):
return [getattr(self, f.name) for f in self._meta.fields if type(f) == models.fields.related.ForeignKey]
</code></pre>
| 6 | 2010-02-10T02:42:06Z | [
"python",
"django",
"django-models",
"merge"
] |
Get all related Django model objects | 2,233,883 | <p>How can I get a list of all the model objects that have a ForeignKey pointing to an object? (Something like the delete confirmation page in the Django admin before DELETE CASCADE).</p>
<p>I'm trying to come up with a generic way of merging duplicate objects in the database. Basically I want all of the objects tha... | 55 | 2010-02-10T01:46:12Z | 2,315,053 | <p>This gives you the property names for all related objects:</p>
<pre><code>links = [rel.get_accessor_name() for rel in a._meta.get_all_related_objects()]
</code></pre>
<p>You can then use something like this to get all related objects:</p>
<pre><code>for link in links:
objects = getattr(a, link).all()
for ... | 72 | 2010-02-22T23:23:06Z | [
"python",
"django",
"django-models",
"merge"
] |
Get all related Django model objects | 2,233,883 | <p>How can I get a list of all the model objects that have a ForeignKey pointing to an object? (Something like the delete confirmation page in the Django admin before DELETE CASCADE).</p>
<p>I'm trying to come up with a generic way of merging duplicate objects in the database. Basically I want all of the objects tha... | 55 | 2010-02-10T01:46:12Z | 13,651,180 | <pre><code>for link in links:
objects = getattr(a, link).all()
</code></pre>
<p>Works for related sets, but not for ForeignKeys. Since RelatedManagers are created dynamically, looking at the class name is easier than doing an isinstance()</p>
<pre><code>objOrMgr = getattr(a, link)
if objOrMgr.__class__.__name__ ... | 5 | 2012-11-30T18:43:40Z | [
"python",
"django",
"django-models",
"merge"
] |
Get all related Django model objects | 2,233,883 | <p>How can I get a list of all the model objects that have a ForeignKey pointing to an object? (Something like the delete confirmation page in the Django admin before DELETE CASCADE).</p>
<p>I'm trying to come up with a generic way of merging duplicate objects in the database. Basically I want all of the objects tha... | 55 | 2010-02-10T01:46:12Z | 17,105,956 | <p>The following is what django uses to get all related objects</p>
<pre><code>from django.db.models.deletion import Collector
collector = Collector(using="default")
collector.collect([a])
print collector.data
</code></pre>
| 3 | 2013-06-14T10:02:19Z | [
"python",
"django",
"django-models",
"merge"
] |
Get all related Django model objects | 2,233,883 | <p>How can I get a list of all the model objects that have a ForeignKey pointing to an object? (Something like the delete confirmation page in the Django admin before DELETE CASCADE).</p>
<p>I'm trying to come up with a generic way of merging duplicate objects in the database. Basically I want all of the objects tha... | 55 | 2010-02-10T01:46:12Z | 19,389,817 | <p>@digitalPBK was close... here is probably what you are looking for using Django's built in stuff</p>
<pre><code>from django.db.models.deletion import Collector
from django.contrib.admin.util import NestedObjects
collector = NestedObjects(using="default") #database name
collector.collect([objective]) #list of object... | 15 | 2013-10-15T19:50:56Z | [
"python",
"django",
"django-models",
"merge"
] |
Get all related Django model objects | 2,233,883 | <p>How can I get a list of all the model objects that have a ForeignKey pointing to an object? (Something like the delete confirmation page in the Django admin before DELETE CASCADE).</p>
<p>I'm trying to come up with a generic way of merging duplicate objects in the database. Basically I want all of the objects tha... | 55 | 2010-02-10T01:46:12Z | 32,744,063 | <p>Here is another way to get a list of fields (names only) in related models.</p>
<pre><code>def get_related_model_fields(model):
fields=[]
related_models = model._meta.get_all_related_objects()
for r in related_models:
fields.extend(r.opts.get_all_field_names())
return fields
</code></pre>
| 1 | 2015-09-23T15:48:30Z | [
"python",
"django",
"django-models",
"merge"
] |
Get all related Django model objects | 2,233,883 | <p>How can I get a list of all the model objects that have a ForeignKey pointing to an object? (Something like the delete confirmation page in the Django admin before DELETE CASCADE).</p>
<p>I'm trying to come up with a generic way of merging duplicate objects in the database. Basically I want all of the objects tha... | 55 | 2010-02-10T01:46:12Z | 37,617,189 | <p><strong>Django 1.9</strong><br>
<strong>get_all_related_objects() has been deprecated</strong></p>
<pre><code>#Example:
user = User.objects.get(id=1)
print(user._meta.get_fields())
</code></pre>
<p>Note:
<em>RemovedInDjango110Warning: 'get_all_related_objects is an unofficial API that has been deprecated. You may... | 2 | 2016-06-03T14:36:27Z | [
"python",
"django",
"django-models",
"merge"
] |
How to input an integer tuple from user? | 2,233,917 | <p>Presently I am doing this</p>
<pre><code>print 'Enter source'
source = tuple(sys.stdin.readline())
print 'Enter target'
target = tuple(sys.stdin.readline())
</code></pre>
<p>but source and target become string tuples in this case with a \n at the end</p>
| 4 | 2010-02-10T01:57:53Z | 2,233,923 | <pre><code>tuple(int(x.strip()) for x in raw_input().split(','))
</code></pre>
| 10 | 2010-02-10T01:59:15Z | [
"python"
] |
How to input an integer tuple from user? | 2,233,917 | <p>Presently I am doing this</p>
<pre><code>print 'Enter source'
source = tuple(sys.stdin.readline())
print 'Enter target'
target = tuple(sys.stdin.readline())
</code></pre>
<p>but source and target become string tuples in this case with a \n at the end</p>
| 4 | 2010-02-10T01:57:53Z | 2,233,945 | <p>If you still want the user to be prompted twice etc.</p>
<pre><code>print 'Enter source'
source = sys.stdin.readline().strip() #strip removes the \n
print 'Enter target'
target = sys.stdin.readline().strip()
myTuple = tuple([int(source), int(target)])
</code></pre>
<p>This is probably less pythonic, but more di... | 1 | 2010-02-10T02:06:55Z | [
"python"
] |
How to input an integer tuple from user? | 2,233,917 | <p>Presently I am doing this</p>
<pre><code>print 'Enter source'
source = tuple(sys.stdin.readline())
print 'Enter target'
target = tuple(sys.stdin.readline())
</code></pre>
<p>but source and target become string tuples in this case with a \n at the end</p>
| 4 | 2010-02-10T01:57:53Z | 2,234,199 | <p>Turns out that <code>int</code> does a pretty good job of stripping whitespace, so there is no need to use <code>strip</code></p>
<pre><code>tuple(map(int,raw_input().split(',')))
</code></pre>
<p>For example:</p>
<pre><code>>>> tuple(map(int,"3,4".split(',')))
(3, 4)
>>> tuple(map(int," 1 , 2 "... | 4 | 2010-02-10T03:19:25Z | [
"python"
] |
Can I catch error in a list comprehensions to be sure to loop all the list items | 2,233,975 | <p>I've got a list comprehensions which filter a list:</p>
<pre><code>l = [obj for obj in objlist if not obj.mycond()]
</code></pre>
<p>but the object method mycond() can raise an Exception I must intercept. I need to collect all the errors at the end of the loop to show which object has created any problems and at t... | 1 | 2010-02-10T02:14:07Z | 2,234,013 | <p>Instead of copying the list and removing elements, start with a blank list and add members as necessary. Something like this:</p>
<pre><code>errors = []
newlist = []
for obj in objlist:
try:
if not obj.mycond():
newlist.append(obj)
except MyException as err:
errors.append(err)
... | 0 | 2010-02-10T02:22:50Z | [
"python",
"exception",
"list",
"cycle"
] |
Can I catch error in a list comprehensions to be sure to loop all the list items | 2,233,975 | <p>I've got a list comprehensions which filter a list:</p>
<pre><code>l = [obj for obj in objlist if not obj.mycond()]
</code></pre>
<p>but the object method mycond() can raise an Exception I must intercept. I need to collect all the errors at the end of the loop to show which object has created any problems and at t... | 1 | 2010-02-10T02:14:07Z | 2,234,027 | <p>you could define a method of obj that calls obj.mycond() but also catches the exception</p>
<pre><code>class obj:
def __init__(self):
self.errors = []
def mycond(self):
#whatever you have here
def errorcatcher():
try:
return self.mycond()
except MyException... | 0 | 2010-02-10T02:29:17Z | [
"python",
"exception",
"list",
"cycle"
] |
Can I catch error in a list comprehensions to be sure to loop all the list items | 2,233,975 | <p>I've got a list comprehensions which filter a list:</p>
<pre><code>l = [obj for obj in objlist if not obj.mycond()]
</code></pre>
<p>but the object method mycond() can raise an Exception I must intercept. I need to collect all the errors at the end of the loop to show which object has created any problems and at t... | 1 | 2010-02-10T02:14:07Z | 2,234,028 | <p>A couple of comments:</p>
<p>First of all, the list comprehension syntax <code>[expression for var in iterable]</code> DOES create a copy. If you do not want to create a copy of the list, then use the generator expression <code>(expression for var in iterable)</code>.</p>
<p>How do generators work? Essentially b... | 1 | 2010-02-10T02:29:25Z | [
"python",
"exception",
"list",
"cycle"
] |
Can I catch error in a list comprehensions to be sure to loop all the list items | 2,233,975 | <p>I've got a list comprehensions which filter a list:</p>
<pre><code>l = [obj for obj in objlist if not obj.mycond()]
</code></pre>
<p>but the object method mycond() can raise an Exception I must intercept. I need to collect all the errors at the end of the loop to show which object has created any problems and at t... | 1 | 2010-02-10T02:14:07Z | 2,234,342 | <p>I would use a little auxiliary function:</p>
<pre><code>def f(obj, errs):
try: return not obj.mycond()
except MyException as err: errs.append((obj, err))
errs = []
l = [obj for obj in objlist if f(obj, errs)]
if errs:
emiterrorinfo(errs)
</code></pre>
<p>Note that this way you have in <code>errs</code> all ... | 9 | 2010-02-10T04:08:08Z | [
"python",
"exception",
"list",
"cycle"
] |
SQLAlchemy ForeignKey relation via an intermediate table | 2,234,030 | <p>Suppose that I have a table <code>Articles</code>, which has fields <code>article_id</code>, <code>content</code> and it contains one article with id <code>1</code>.</p>
<p>I also have a table <code>Categories</code>, which has fields <code>category_id</code> (primary key), <code>category_name</code>, and it contai... | 0 | 2010-02-10T02:30:16Z | 2,248,806 | <p>Assuming I understand you question correctly, then No, you can't model that relationship as you have suggested. (It would help if you described your desired result, rather than your perceived solution)</p>
<p>What I think you may want is a many-to-many mapping table called ArticleCategories, consisting of 2 int co... | 1 | 2010-02-12T00:23:18Z | [
"python",
"sqlalchemy"
] |
how do I iterate over a "gslist" in Python? | 2,234,056 | <p>Let's say I get a glib <code>gpointer</code> to a glib <code>gslist</code> and would like to iterate over the latter, how would I do it?</p>
<p>I don't even know how to get to the <code>gslist</code> with the <code>gpointer</code> for starters!</p>
<p><strong>Update</strong>: I found a workaround - the python bind... | 0 | 2010-02-10T02:38:08Z | 2,234,282 | <p>How is <code>glib</code> exposed to Python in your application? Via SWIG, ctypes or something else? </p>
<p>You should basically use <code>glib</code>'s own functions to iterate over a list. Something like <code>g_slist_foreach</code>. Just pass it the pointer and its other parameters to do the job. Again, this hea... | 0 | 2010-02-10T03:50:13Z | [
"python",
"glib"
] |
building dynamic forms in django | 2,234,117 | <p>I'm trying to build a form dynamically based on the field and its definitions stored in a database. In my db, I have defined 1 checkbox with some label and 1 textfield with some label. </p>
<p>How do I build a form dynamically in my view from the data in the db?</p>
<p>Thanks</p>
| 2 | 2010-02-10T02:55:01Z | 2,234,212 | <p>Django does a great job auto-generating forms from your <a href="http://docs.djangoproject.com/en/1.1/topics/forms/modelforms/#topics-forms-modelforms" rel="nofollow">model definitions.</a></p>
<p>The first step might be to create a Django model that mirrors your existing database.</p>
<p>Regarding the checkbox/te... | 4 | 2010-02-10T03:25:27Z | [
"python",
"django",
"django-forms"
] |
building dynamic forms in django | 2,234,117 | <p>I'm trying to build a form dynamically based on the field and its definitions stored in a database. In my db, I have defined 1 checkbox with some label and 1 textfield with some label. </p>
<p>How do I build a form dynamically in my view from the data in the db?</p>
<p>Thanks</p>
| 2 | 2010-02-10T02:55:01Z | 2,234,306 | <p>Here are the slides from a talk I gave at EuroDjangoCon about doing precisely this: <a href="http://www.slideshare.net/kingkilr/forms-getting-your-moneys-worth">http://www.slideshare.net/kingkilr/forms-getting-your-moneys-worth</a></p>
| 10 | 2010-02-10T03:56:34Z | [
"python",
"django",
"django-forms"
] |
How do I prevent duplicating code with pylons html table updated via ajax? | 2,234,153 | <p>I have a pylons web-page with a table. I have created python functions in the template which help with the construction of the table html. One of these functions takes an 'item' and generates an html row while also adding css zebra striping. The other def generates the header row's html. </p>
<p>This works perfe... | 0 | 2010-02-10T03:06:37Z | 2,234,168 | <p>One possibility would be to actually generate the AJAX HTML server-side (instead of generating JSON), and insert it right into the DOM tree (instead of parsing the JSON and generating the HTML on the client). Then you could use the same functions on the server side to generate the AJAX rows before they are shipped o... | 1 | 2010-02-10T03:10:57Z | [
"python",
"ajax",
"table",
"pylons"
] |
Django Group By relation's data | 2,234,181 | <p>In Django,</p>
<p>I can do value(), and then distinct() to group by.</p>
<pre><code>A
{
Foreign Key B
}
B
{
String name
}
</code></pre>
<p>However, is it possible to group using a related object's data? I.e. In the above relation, can I group A by B's name?</p>
| 0 | 2010-02-10T03:15:13Z | 2,234,489 | <p>I think you can order_by on the FKey model.</p>
<pre><code>A.objects.order_by('B__name')
</code></pre>
<p>Iff you can't, You need to use the Django ORM's Annotation API, to make a new field and you will be able to order it accordingly:</p>
<pre><code>A.objects.annotate(bname='B__name').order_by('bname')
</code></... | 0 | 2010-02-10T04:51:46Z | [
"python",
"django",
"django-models",
"group-by"
] |
Parsing unicode input using python json.loads | 2,234,228 | <p>What is the best way to load JSON Strings in Python?</p>
<p>I want to use json.loads to process unicode like this:</p>
<pre><code>import json
json.loads(unicode_string_to_load)
</code></pre>
<p>I also tried supplying 'encoding' parameter with value 'utf-16', but the error did not go away.</p>
<p>Full SSCCE with ... | 10 | 2010-02-10T03:32:17Z | 2,234,277 | <p>The OP clarifies (in a comment!)...:</p>
<blockquote>
<p>Source data is huge unicode encoded
string</p>
</blockquote>
<p>Then you have to know <strong>which</strong> of the many unicode encodings it uses -- clearly not 'utf-16', since that failed, but there are so many others -- 'utf-8', 'iso-8859-15', and so ... | 5 | 2010-02-10T03:48:58Z | [
"python",
"django",
"json",
"unicode"
] |
Parsing unicode input using python json.loads | 2,234,228 | <p>What is the best way to load JSON Strings in Python?</p>
<p>I want to use json.loads to process unicode like this:</p>
<pre><code>import json
json.loads(unicode_string_to_load)
</code></pre>
<p>I also tried supplying 'encoding' parameter with value 'utf-16', but the error did not go away.</p>
<p>Full SSCCE with ... | 10 | 2010-02-10T03:32:17Z | 2,235,005 | <p>I typecasting the string into unicode string using 'latin-1' fixed the error: </p>
<pre><code>UnicodeDecodeError: 'utf16' codec can't decode byte 0x38 in
position 6: truncated data
</code></pre>
<p>Fixed code:</p>
<pre><code>import json
ustr_to_load = unicode(str_to_load, 'latin-1')
json.loads(ustr_to_load)
</... | 7 | 2010-02-10T07:01:52Z | [
"python",
"django",
"json",
"unicode"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.