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 |
|---|---|---|---|---|---|---|---|---|---|
With Python, can I keep a persistent dictionary and modify it? | 1,229,068 | <p>So, I want to store a dictionary in a persistent file. Is there a way to use regular dictionary methods to add, print, or delete entries from the dictionary in that file?</p>
<p>It seems that I would be able to use cPickle to store the dictionary and load it, but I'm not sure where to take it from there.</p>
| 5 | 2009-08-04T18:10:52Z | 23,137,456 | <h1>Use JSON</h1>
<p>Similar to Pete's answer, I like using JSON because it maps very well to python data structures and is very readable:</p>
<p>Persisting data is trivial:</p>
<pre><code>>>> import json
>>> db = {'hello': 123, 'foo': [1,2,3,4,5,6], 'bar': {'a': 0, 'b':9}}
>>> fh = open("... | 1 | 2014-04-17T15:38:26Z | [
"python",
"dictionary",
"persistence",
"object-persistence"
] |
Parsing empty options in Python | 1,229,146 | <p>I have an application that allows you to send event data to a custom script. You simply lay out the command line arguments and assign what event data goes with what argument. The problem is that there is no real flexibility here. Every option you map out is going to be used, but not every option will necessarily hav... | 4 | 2009-08-04T18:32:47Z | 1,229,197 | <p>Yes, there is an argument to do so when you add the option:</p>
<pre><code>from optparse import OptionParser
parser = OptionParser()
parser.add_option("--SomeData",action="store", dest="TheData", default='')
</code></pre>
<p>Give the <em>default</em> argument the value you want the option to have it is to be speci... | -1 | 2009-08-04T18:42:03Z | [
"python",
"optparse",
"optionparser"
] |
Parsing empty options in Python | 1,229,146 | <p>I have an application that allows you to send event data to a custom script. You simply lay out the command line arguments and assign what event data goes with what argument. The problem is that there is no real flexibility here. Every option you map out is going to be used, but not every option will necessarily hav... | 4 | 2009-08-04T18:32:47Z | 1,229,387 | <p>I don't think <code>optparse</code> can do this. <a href="http://argparse.googlecode.com/" rel="nofollow"><code>argparse</code></a> is a different (non-standard) module that can <a href="http://argparse.googlecode.com/svn/trunk/doc/argparse-vs-optparse.html#more-nargs-options" rel="nofollow">handle situations like t... | 1 | 2009-08-04T19:17:40Z | [
"python",
"optparse",
"optionparser"
] |
Parsing empty options in Python | 1,229,146 | <p>I have an application that allows you to send event data to a custom script. You simply lay out the command line arguments and assign what event data goes with what argument. The problem is that there is no real flexibility here. Every option you map out is going to be used, but not every option will necessarily hav... | 4 | 2009-08-04T18:32:47Z | 1,229,667 | <p>Sorry, misunderstood the question with my first answer. You can accomplish the ability to have optional arguments to command line flags use the <em>callback</em> action type when you define an option. Use the following function as a call back (you will likely wish to tailor to your needs) and configure it for each... | 8 | 2009-08-04T20:11:30Z | [
"python",
"optparse",
"optionparser"
] |
Parsing empty options in Python | 1,229,146 | <p>I have an application that allows you to send event data to a custom script. You simply lay out the command line arguments and assign what event data goes with what argument. The problem is that there is no real flexibility here. Every option you map out is going to be used, but not every option will necessarily hav... | 4 | 2009-08-04T18:32:47Z | 3,139,732 | <p>Optparse already allows you to pass the empty string as an option argument. So if possible, treat the empty string as "no value". For long options, any of the following work:</p>
<pre><code>my_script --opt= --anotheroption
my_script --opt='' --anotheroption
my_script --opt="" --anotheroption
my_script --opt '' ... | 0 | 2010-06-29T10:17:27Z | [
"python",
"optparse",
"optionparser"
] |
Parsing empty options in Python | 1,229,146 | <p>I have an application that allows you to send event data to a custom script. You simply lay out the command line arguments and assign what event data goes with what argument. The problem is that there is no real flexibility here. Every option you map out is going to be used, but not every option will necessarily hav... | 4 | 2009-08-04T18:32:47Z | 8,081,533 | <p>Mark Roddy's solution would work, but it requires attribute modification of a parser object during runtime, and has no support for alternative option formattings other than - or --.
A slightly less involved solution is to modify the sys.argv array before running optparse and insert an empty string ("") after a switc... | 0 | 2011-11-10T15:01:48Z | [
"python",
"optparse",
"optionparser"
] |
Parsing empty options in Python | 1,229,146 | <p>I have an application that allows you to send event data to a custom script. You simply lay out the command line arguments and assign what event data goes with what argument. The problem is that there is no real flexibility here. Every option you map out is going to be used, but not every option will necessarily hav... | 4 | 2009-08-04T18:32:47Z | 15,986,529 | <p>After checking that the <code>cp</code> command understands e.g. <code>--backup=simple</code> but <em>not</em> <code>--backup simple</code>, I answered the problem like this:</p>
<pre><code>import sys
from optparse import OptionParser
def add_optval_option(pog, *args, **kwargs):
if 'empty' in kwargs:
e... | 0 | 2013-04-13T09:52:52Z | [
"python",
"optparse",
"optionparser"
] |
Convert list of floats into buffer in Python? | 1,229,202 | <p>I am playing around with PortAudio and Python.</p>
<pre><code>data = getData()
stream.write( data )
</code></pre>
<p>I want my stream to play sound data, that is represented in Float32 values. Therefore I use the following function:</p>
<pre><code>def getData():
data = []
for i in range( 0, 1024 ):
... | 5 | 2009-08-04T18:43:04Z | 1,229,232 | <p>Consider perhaps instead:</p>
<pre><code>d = [0.25 * math.sin(math.radians(i)) for i in range(0, 1024)]
</code></pre>
<p>Perhaps you have to use a package like pickle to serialize the data first.</p>
<pre><code>import pickle
f1 = open("test.dat", "wb")
pickle.dump(d, f1)
f1.close()
</code></pre>
<p>Then load it ... | 0 | 2009-08-04T18:49:01Z | [
"python",
"list",
"floating-point",
"buffer"
] |
Convert list of floats into buffer in Python? | 1,229,202 | <p>I am playing around with PortAudio and Python.</p>
<pre><code>data = getData()
stream.write( data )
</code></pre>
<p>I want my stream to play sound data, that is represented in Float32 values. Therefore I use the following function:</p>
<pre><code>def getData():
data = []
for i in range( 0, 1024 ):
... | 5 | 2009-08-04T18:43:04Z | 1,229,237 | <p>Actually, the easiest way is to use the <a href="http://docs.python.org/library/struct.html#module-struct" rel="nofollow">struct module</a>. It is designed to convert from python objects to C-like "native" objects.</p>
| 2 | 2009-08-04T18:49:52Z | [
"python",
"list",
"floating-point",
"buffer"
] |
Convert list of floats into buffer in Python? | 1,229,202 | <p>I am playing around with PortAudio and Python.</p>
<pre><code>data = getData()
stream.write( data )
</code></pre>
<p>I want my stream to play sound data, that is represented in Float32 values. Therefore I use the following function:</p>
<pre><code>def getData():
data = []
for i in range( 0, 1024 ):
... | 5 | 2009-08-04T18:43:04Z | 1,229,314 | <pre><code>import struct
def getData():
data = []
for i in range( 0, 1024 ):
data.append( 0.25 * math.sin( math.radians( i ) ) )
return struct.pack('f'*len(data), *data)
</code></pre>
| 7 | 2009-08-04T19:01:30Z | [
"python",
"list",
"floating-point",
"buffer"
] |
How to read/copy ctype pointers into python class? | 1,229,318 | <p>This is a kind of follow-up from <a href="http://stackoverflow.com/questions/1228158/python-ctype-recursive-structures">my last question</a> if this can help you.</p>
<p>I'm defining a few ctype structures</p>
<pre><code>class EthercatDatagram(Structure):
_fields_ = [("header", EthercatDatagramHeader),
... | 1 | 2009-08-04T19:02:34Z | 1,229,490 | <p>Ok I got it working</p>
<p>correct code was </p>
<pre><code>print packet.data.header[0]
</code></pre>
<p>thanks to the 7 person who dared to look at the question</p>
<p>the google string for the answer was : python ctype dereference pointer
3rd hit</p>
| 0 | 2009-08-04T19:36:36Z | [
"python",
"variables",
"pointers",
"ctypes"
] |
How to read/copy ctype pointers into python class? | 1,229,318 | <p>This is a kind of follow-up from <a href="http://stackoverflow.com/questions/1228158/python-ctype-recursive-structures">my last question</a> if this can help you.</p>
<p>I'm defining a few ctype structures</p>
<pre><code>class EthercatDatagram(Structure):
_fields_ = [("header", EthercatDatagramHeader),
... | 1 | 2009-08-04T19:02:34Z | 1,229,916 | <p>The square-bracket notation is indeed correct. For reference, here's a snippet from some ctypes code I recently made:</p>
<pre><code>class Message(Structure):
_fields_ = [ ("id", BYTE), ("data", POINTER(BYTE)), ("data_length", DWORD) ]
def __repr__(self):
d = ' '.join(["0x%02X" % self.data[i] for i... | 1 | 2009-08-04T20:59:32Z | [
"python",
"variables",
"pointers",
"ctypes"
] |
Unicode utf-8/utf-16 encoding in Python | 1,229,414 | <p>In python:</p>
<pre><code>u'\u3053\n'
</code></pre>
<p>Is it utf-16? </p>
<p>I'm not really aware of all the unicode/encoding stuff, but this type of thing is coming up in my dataset,
like if I have <code>a=u'\u3053\n'</code>.</p>
<p><code>print</code> gives an exception and
decoding gives an exception.</p>
<p... | 4 | 2009-08-04T19:22:40Z | 1,229,467 | <p>Here's the Unicode HowTo Doc for Python 2.6.2:</p>
<p><a href="http://docs.python.org/howto/unicode.html" rel="nofollow">http://docs.python.org/howto/unicode.html</a></p>
<p>Also see the links in the Reference section of that document for other explanations, including one by Joel Spolsky.</p>
| 1 | 2009-08-04T19:33:30Z | [
"python",
"unicode",
"encoding",
"decoding"
] |
Unicode utf-8/utf-16 encoding in Python | 1,229,414 | <p>In python:</p>
<pre><code>u'\u3053\n'
</code></pre>
<p>Is it utf-16? </p>
<p>I'm not really aware of all the unicode/encoding stuff, but this type of thing is coming up in my dataset,
like if I have <code>a=u'\u3053\n'</code>.</p>
<p><code>print</code> gives an exception and
decoding gives an exception.</p>
<p... | 4 | 2009-08-04T19:22:40Z | 1,229,481 | <p>It's a unicode character that doesn't seem to be displayable in your terminals encoding. <code>print</code> tries to encode the unicode object in the encoding of your terminal and if this can't be done you get an exception.</p>
<p>On a terminal that can display utf-8 you get:</p>
<pre><code>>>> print u'\u... | 7 | 2009-08-04T19:35:04Z | [
"python",
"unicode",
"encoding",
"decoding"
] |
Unicode utf-8/utf-16 encoding in Python | 1,229,414 | <p>In python:</p>
<pre><code>u'\u3053\n'
</code></pre>
<p>Is it utf-16? </p>
<p>I'm not really aware of all the unicode/encoding stuff, but this type of thing is coming up in my dataset,
like if I have <code>a=u'\u3053\n'</code>.</p>
<p><code>print</code> gives an exception and
decoding gives an exception.</p>
<p... | 4 | 2009-08-04T19:22:40Z | 1,229,498 | <p>Character U+3053 "HIRAGANA LETTER KO".</p>
<p>The <code>\xff\xfe</code> bit at the start of the UTF-16 binary format is the encoded byte order mark (U+FEFF), then "S0" is <code>\x5e\x30</code>, then there's the <code>\n</code> from the original string. (Each of the characters has its bytes "reversed" as it's using ... | 1 | 2009-08-04T19:37:58Z | [
"python",
"unicode",
"encoding",
"decoding"
] |
Unicode utf-8/utf-16 encoding in Python | 1,229,414 | <p>In python:</p>
<pre><code>u'\u3053\n'
</code></pre>
<p>Is it utf-16? </p>
<p>I'm not really aware of all the unicode/encoding stuff, but this type of thing is coming up in my dataset,
like if I have <code>a=u'\u3053\n'</code>.</p>
<p><code>print</code> gives an exception and
decoding gives an exception.</p>
<p... | 4 | 2009-08-04T19:22:40Z | 1,230,857 | <p>You ask:</p>
<blockquote>
<p>u'\u3053\n'</p>
<p>Is it utf-16?</p>
</blockquote>
<p>The answer is no: it's unicode, not any specific encoding. utf-16 is an encoding.</p>
<p>To print a Unicode string effectively to your terminal, you need to find out what encoding that terminal is willing to accept and able ... | 5 | 2009-08-05T02:15:58Z | [
"python",
"unicode",
"encoding",
"decoding"
] |
XML Parsing in Python using document builder factory | 1,229,507 | <p>I am working in STAF and STAX. Here python is used for coding . I am new to python.
Basically my task is to parse a XML file in python using Document Factory Parser.</p>
<p>The XML file I am trying to parse is :</p>
<pre><code><?xml version="1.0" encoding="utf-8"?>
<operating_system>
<unix_80sp1&g... | 0 | 2009-08-04T19:39:12Z | 1,230,508 | <p>You are need to instantiate vmware_value, vmware_attr and machname as lists not as strings, so instead of this:</p>
<pre><code>vmware_value = None
vmware_attr = None
machname = None
</code></pre>
<p>do this:</p>
<pre><code>vmware_value = []
vmware_attr = []
machname = []
</code></pre>
<p>Then, to add items to th... | 0 | 2009-08-04T23:53:43Z | [
"python",
"xml",
"parsing"
] |
Opening a wx.Frame in Python via a new thread | 1,229,525 | <p>I have a frame that exists as a start up screen for the user to make a selection before the main program starts. After the user makes a selection I need the screen to stay up as a sort of splash screen until the main program finishes loading in back.</p>
<p>I've done this by creating an application and starting a ... | 0 | 2009-08-04T19:42:49Z | 1,229,823 | <p>You don't need threads for this. The drawback is that the splash window will block while loading but that is an issue only if you want to update it's contents (animate it) or if you want to be able to drag it. An issue that can be solved by periodically calling <code>wx.SafeYield</code> for example.</p>
<pre><code>... | 0 | 2009-08-04T20:40:48Z | [
"python",
"multithreading",
"wxpython"
] |
How to make two elements in gtk have the same size? | 1,229,933 | <p>I'm using pyGTK. I want to layout a large element with 2 smaller ones on each side. For aesthetic reasons, I want the 2 smaller ones to be the same size. As it is, they differ by a few pixels, and the middle element is not centered as a result.</p>
<p>I tried using gtk.Table with 3 cells, but having homogeneous=Tru... | 1 | 2009-08-04T21:04:00Z | 1,229,981 | <p>You should use GtkSizeGroup for this. Create a GtkSizeGroup, add both widgets to it. This will ensure that both widgets have the same size. If you want that widget have the same size in only one direction (width or height), set the "mode" property of SizeGroup.</p>
| 5 | 2009-08-04T21:18:35Z | [
"python",
"layout",
"gtk",
"pygtk"
] |
What is the % operator in python for? | 1,230,321 | <p>I've seen the % operator being used in some Python code related to strings, such as:</p>
<pre><code>String = "Value: " % variable
</code></pre>
<p>What does that mean? How is it different from using:</p>
<pre><code>String = "Value: " + variable
</code></pre>
| 1 | 2009-08-04T22:58:56Z | 1,230,332 | <p>its for inserting values into strings containing <a href="http://www.python.org/doc/2.4/lib/typesseq-strings.html">format specifications</a></p>
<pre><code>string = "number is %d" % 1
</code></pre>
<p>or </p>
<pre><code>string = "float is %.3f" % 3.1425
</code></pre>
<p>this works in a similar way as spintf in C... | 11 | 2009-08-04T23:00:49Z | [
"python"
] |
What is the % operator in python for? | 1,230,321 | <p>I've seen the % operator being used in some Python code related to strings, such as:</p>
<pre><code>String = "Value: " % variable
</code></pre>
<p>What does that mean? How is it different from using:</p>
<pre><code>String = "Value: " + variable
</code></pre>
| 1 | 2009-08-04T22:58:56Z | 1,230,346 | <p>The % is the <em>string formatting operator</em> (also known as the <em>interpolation operator</em>), see <a href="http://docs.python.org/library/stdtypes.html#string-formatting" rel="nofollow">http://docs.python.org/library/stdtypes.html#string-formatting</a></p>
| 2 | 2009-08-04T23:04:51Z | [
"python"
] |
What is the % operator in python for? | 1,230,321 | <p>I've seen the % operator being used in some Python code related to strings, such as:</p>
<pre><code>String = "Value: " % variable
</code></pre>
<p>What does that mean? How is it different from using:</p>
<pre><code>String = "Value: " + variable
</code></pre>
| 1 | 2009-08-04T22:58:56Z | 1,230,348 | <p>Read <a href="http://diveintopython.net/native_data_types/formatting_strings.html" rel="nofollow">formatting strings</a></p>
<ul>
<li>'%' is the formatting string operator</li>
<li>'+' would be the concat operator</li>
</ul>
| 0 | 2009-08-04T23:05:07Z | [
"python"
] |
What is the % operator in python for? | 1,230,321 | <p>I've seen the % operator being used in some Python code related to strings, such as:</p>
<pre><code>String = "Value: " % variable
</code></pre>
<p>What does that mean? How is it different from using:</p>
<pre><code>String = "Value: " + variable
</code></pre>
| 1 | 2009-08-04T22:58:56Z | 1,230,353 | <p>For strings % is the <a href="http://docs.python.org/library/stdtypes.html#string-formatting-operations" rel="nofollow">formatting operator</a>. It also marks the start of the format specifier. </p>
<p>The + operator will concat a string at the end of the string with the right hand side of the +. The % operator... | 2 | 2009-08-04T23:06:24Z | [
"python"
] |
What is the % operator in python for? | 1,230,321 | <p>I've seen the % operator being used in some Python code related to strings, such as:</p>
<pre><code>String = "Value: " % variable
</code></pre>
<p>What does that mean? How is it different from using:</p>
<pre><code>String = "Value: " + variable
</code></pre>
| 1 | 2009-08-04T22:58:56Z | 1,231,334 | <p>According to John E. Grayson in his book "Python and Tkinter Programming", using string formatter rather than concatenation could increase the performance for at least 25 percent.</p>
<p>a = x + ' ' + y + ' ' + z</p>
<p>is 25 percent slower than </p>
<p>a = '%s %s %s' % (x, y, z)</p>
<p>In Python 3, you could al... | 0 | 2009-08-05T05:24:27Z | [
"python"
] |
What is the % operator in python for? | 1,230,321 | <p>I've seen the % operator being used in some Python code related to strings, such as:</p>
<pre><code>String = "Value: " % variable
</code></pre>
<p>What does that mean? How is it different from using:</p>
<pre><code>String = "Value: " + variable
</code></pre>
| 1 | 2009-08-04T22:58:56Z | 11,797,624 | <p>(As an aside, in case you didn't know): When not being used on strings, <code>%</code> acts as a modulo function</p>
<pre><code>>>> 5 % 5
0
>>> 1 % 4
1
</code></pre>
| 0 | 2012-08-03T14:23:44Z | [
"python"
] |
Decode complex JSON in Python | 1,230,347 | <p>Hey,
I have a JSON object created in PHP, that JSON object contains another escaped JSON string in one of it's cells:</p>
<pre>
php > $insidejson = array('foo' => 'bar','foo1' => 'bar1');
php > $arr = array('a' => array('a1'=>json_encode($insidejson)));
php > echo json_encode($arr);
{"a":{"a1":"{\"foo\":\"bar\",\"... | 5 | 2009-08-04T23:05:07Z | 1,230,402 | <p>Try </p>
<ul>
<li><a href="http://docs.python.org/library/json.html" rel="nofollow">The Python Standard Library</a></li>
<li><a href="http://opensource.xhaus.com/projects/show/jyson" rel="nofollow">jyson</a></li>
</ul>
<p>Maybe simplejson is too much "simple".</p>
| 1 | 2009-08-04T23:19:57Z | [
"php",
"python",
"json",
"simplejson"
] |
Decode complex JSON in Python | 1,230,347 | <p>Hey,
I have a JSON object created in PHP, that JSON object contains another escaped JSON string in one of it's cells:</p>
<pre>
php > $insidejson = array('foo' => 'bar','foo1' => 'bar1');
php > $arr = array('a' => array('a1'=>json_encode($insidejson)));
php > echo json_encode($arr);
{"a":{"a1":"{\"foo\":\"bar\",\"... | 5 | 2009-08-04T23:05:07Z | 1,230,447 | <p>If you want to insert backslashes into a string they need escaping themselves.</p>
<pre><code>import simplejson as json
json.loads('{"a":{"a1":"{\\"foo\\":\\"bar\\",\\"foo1\\":\\"bar1\\"}"}}')
</code></pre>
<p>I've tested it and Python handles that input just fine - except I used the json module included in the st... | 1 | 2009-08-04T23:35:09Z | [
"php",
"python",
"json",
"simplejson"
] |
Decode complex JSON in Python | 1,230,347 | <p>Hey,
I have a JSON object created in PHP, that JSON object contains another escaped JSON string in one of it's cells:</p>
<pre>
php > $insidejson = array('foo' => 'bar','foo1' => 'bar1');
php > $arr = array('a' => array('a1'=>json_encode($insidejson)));
php > echo json_encode($arr);
{"a":{"a1":"{\"foo\":\"bar\",\"... | 5 | 2009-08-04T23:05:07Z | 1,230,459 | <p>Try prefixing your string with 'r' to make it a raw string:</p>
<pre><code># Python 2.6.2
>>> import json
>>> s = r'{"a":{"a1":"{\"foo\":\"bar\",\"foo1\":\"bar1\"}"}}'
>>> json.loads(s)
{u'a': {u'a1': u'{"foo":"bar","foo1":"bar1"}'}}
</code></pre>
<p>What Alex says below is true: you can... | 9 | 2009-08-04T23:38:45Z | [
"php",
"python",
"json",
"simplejson"
] |
Does using properties on an old-style python class cause problems | 1,230,383 | <p>Pretty simple question. I've seen it mentioned in many places that using properties on an old-style class shouldn't work, but apparently Qt classes (through PyQt4) aren't new-style and there are properties on a few of them in the code I'm working with (and as far as I know the code isn't showing any sorts of proble... | 5 | 2009-08-04T23:14:37Z | 1,230,439 | <p>Properties of the Python sort work, in my experience, just fine on PyQt4 objects. I don't know if they are explicitly supported by PyQt4 or not or if there are some hidden gotchas, but I've never seen them misbehave. Here's an example using PyQt 4.4 and Python 2.5:</p>
<pre><code>from PyQt4.QtCore import QObject
... | 3 | 2009-08-04T23:32:54Z | [
"python",
"class",
"properties",
"pyqt"
] |
Does using properties on an old-style python class cause problems | 1,230,383 | <p>Pretty simple question. I've seen it mentioned in many places that using properties on an old-style class shouldn't work, but apparently Qt classes (through PyQt4) aren't new-style and there are properties on a few of them in the code I'm working with (and as far as I know the code isn't showing any sorts of proble... | 5 | 2009-08-04T23:14:37Z | 1,230,829 | <p>property works because QObject has a metaclass that takes care of them. Witness this small variation on @quark's code...:</p>
<pre><code>from PyQt4.QtCore import QObject
def makec(base):
class X( base ):
def __init__(self):
self.__x = 10
def get_x(self):
print 'getting',
... | 4 | 2009-08-05T02:04:04Z | [
"python",
"class",
"properties",
"pyqt"
] |
Does using properties on an old-style python class cause problems | 1,230,383 | <p>Pretty simple question. I've seen it mentioned in many places that using properties on an old-style class shouldn't work, but apparently Qt classes (through PyQt4) aren't new-style and there are properties on a few of them in the code I'm working with (and as far as I know the code isn't showing any sorts of proble... | 5 | 2009-08-04T23:14:37Z | 1,232,208 | <p>At least in PyQt4.5, Qt classes certainly ARE new style objects, as seen from their method resolution order:</p>
<pre><code>from PyQt4 import QtGui
print QtGui.QWidget.__mro__
(<class 'PyQt4.QtGui.QWidget'>, <class 'PyQt4.QtCore.QObject'>, <type 'sip.wrapper'>, <class 'PyQt4.QtGui.QPaintDevice'... | 1 | 2009-08-05T09:46:37Z | [
"python",
"class",
"properties",
"pyqt"
] |
Does Django have a built in way of getting the last app url the current user visited? | 1,230,392 | <p>I was hoping that Django had a built in way of getting the last url that was visited in the app itself. As I write this I realize that there are some complications in doing something like that (excluding pages that redirect, for example) but i thought I'd give it a shot. </p>
<p>if there isn't a built-in for this... | 0 | 2009-08-04T23:17:36Z | 1,230,419 | <p>you can just write a middleware that does exactly that, no need to repeat logging code on every view function.</p>
| 0 | 2009-08-04T23:23:25Z | [
"python",
"django"
] |
Does Django have a built in way of getting the last app url the current user visited? | 1,230,392 | <p>I was hoping that Django had a built in way of getting the last url that was visited in the app itself. As I write this I realize that there are some complications in doing something like that (excluding pages that redirect, for example) but i thought I'd give it a shot. </p>
<p>if there isn't a built-in for this... | 0 | 2009-08-04T23:17:36Z | 1,230,492 | <p>No, there is nothing like that built in to Django core (and it's not built in because it isn't a common usage pattern).</p>
<p>Like Javier suggested, you could make some middleware which does what you want. Something like this:</p>
<pre><code>class PreviousURLMiddleware(object):
def process_response(request, r... | 5 | 2009-08-04T23:50:52Z | [
"python",
"django"
] |
Do I only need to check the users machine for the version of the MSVCR90.dll that was installed with my python installation? | 1,230,479 | <p>I was working on an update to my application and before I began I migrated to 2.62 because it seemed to be the time to. I walked right into the issue of having problems building my application using py2exe because of the MSVCR90.dlls. There seems to be a fair amount of information on how to solve this issue, inclu... | 0 | 2009-08-04T23:45:58Z | 1,230,912 | <p>Vista 64bit has a 32 bit emulator I believe, so you will not need to worry about this.</p>
<p>However, I would just tell them to install the msvcrt runtime which is supposed to be the correct way to deal with this sxs mess.</p>
| 1 | 2009-08-05T02:37:16Z | [
"python",
"py2exe",
"msvcr90.dll"
] |
Do I only need to check the users machine for the version of the MSVCR90.dll that was installed with my python installation? | 1,230,479 | <p>I was working on an update to my application and before I began I migrated to 2.62 because it seemed to be the time to. I walked right into the issue of having problems building my application using py2exe because of the MSVCR90.dlls. There seems to be a fair amount of information on how to solve this issue, inclu... | 0 | 2009-08-04T23:45:58Z | 1,242,396 | <p>From what I have gathered and learned the correct answer is that I have to worry about the MSCVCR90 dll that is used in the version of Python and mx that the application I am building rely on. This is important because it means that if the user has a different configuration I can't easily fix that problem unless I ... | 0 | 2009-08-07T01:14:07Z | [
"python",
"py2exe",
"msvcr90.dll"
] |
python unittest assertRaises throws exception when assertRaises fails | 1,230,498 | <p>I've got code where assertRaises throws an exception when assertRaises fails. I thought that if assertRaises fails then the test would fail and I'd get a report at the end that says the test failed. I wasn't expecting the exception to be thrown. Below is my code. I'm I doing something wrong? I'm using Python 2.... | 5 | 2009-08-04T23:51:42Z | 1,230,537 | <p>The code as posted is wrong. For a start, <code>class myClass():</code> shoudl be <code>class myClass:</code>. Also <code>if name == "main":</code> should be:</p>
<pre><code>if __name__ == "__main__":
unittest.main()
</code></pre>
<p>Apart from these problems, this fails because <code>getName()</code> is raisi... | 6 | 2009-08-05T00:05:41Z | [
"python",
"unit-testing",
"pyunit"
] |
python unittest assertRaises throws exception when assertRaises fails | 1,230,498 | <p>I've got code where assertRaises throws an exception when assertRaises fails. I thought that if assertRaises fails then the test would fail and I'd get a report at the end that says the test failed. I wasn't expecting the exception to be thrown. Below is my code. I'm I doing something wrong? I'm using Python 2.... | 5 | 2009-08-04T23:51:42Z | 1,230,769 | <p>Starting with an aside, the <code>()</code> after the classname in a <code>class</code> statement is perfectly correct in modern Python -- not an error at all.</p>
<p>On the meat of the issue, <code>assertRaises(MyException, foo)</code> IS documented to propagate exceptions raised by calling <code>foo()</code> whos... | 5 | 2009-08-05T01:40:11Z | [
"python",
"unit-testing",
"pyunit"
] |
How do you force refresh of a wx.Panel? | 1,230,630 | <p>I am trying to modify the controls of a Panel, have it update, then continue on with code execution. The problem seems to be that the Panel is waiting for Idle before it will refresh itself. I've tried refresh of course as well as GetSizer().Layout() and even sent a resize event to the frame using the SendSizeEven... | 7 | 2009-08-05T00:40:39Z | 1,230,736 | <p>You could put the mutable part of your panel on subpanels, e.g. like this:</p>
<pre><code>def MakeButtonPanels(self):
self.buttonPanel1 = wx.Panel(self)
self.Add(self.buttonPanel1, 0, wxALL|wxALIGN_LEFT, 5)
# ... make the three buttons and the button sizer on buttonPanel1
self.buttonPanel2 = wx.Pan... | 1 | 2009-08-05T01:22:19Z | [
"python",
"wxpython",
"refresh",
"panel"
] |
How do you force refresh of a wx.Panel? | 1,230,630 | <p>I am trying to modify the controls of a Panel, have it update, then continue on with code execution. The problem seems to be that the Panel is waiting for Idle before it will refresh itself. I've tried refresh of course as well as GetSizer().Layout() and even sent a resize event to the frame using the SendSizeEven... | 7 | 2009-08-05T00:40:39Z | 1,231,708 | <p>You need to call the <a href="http://www.wxpython.org/docs/api/wx.Window-class.html#Update"><code>Update</code></a> method.</p>
| 10 | 2009-08-05T07:41:06Z | [
"python",
"wxpython",
"refresh",
"panel"
] |
How do you force refresh of a wx.Panel? | 1,230,630 | <p>I am trying to modify the controls of a Panel, have it update, then continue on with code execution. The problem seems to be that the Panel is waiting for Idle before it will refresh itself. I've tried refresh of course as well as GetSizer().Layout() and even sent a resize event to the frame using the SendSizeEven... | 7 | 2009-08-05T00:40:39Z | 17,626,478 | <p>I had a <code>StaticBitmap</code> that, similarly, wouldn't update by any of these techniques (including the <code>Update</code> suggested in the accepted answer). </p>
<p>I found that calling <code>.Hide()</code> and <code>.Show()</code> on the <code>Panel</code> was enough to refresh the image. I suspect that t... | 2 | 2013-07-13T02:43:02Z | [
"python",
"wxpython",
"refresh",
"panel"
] |
subprocess: deleting child processes in Windows | 1,230,669 | <p>On Windows, <code>subprocess.Popen.terminate</code> calls win32's <code>TerminalProcess</code>. However, the behavior I see is that child processes of the process I am trying to terminate are still running. Why is that? How do I ensure all child processes started by the process are killed?</p>
| 25 | 2009-08-05T00:53:49Z | 1,230,853 | <p>This is a hard thing to do. Windows does not actually store a process tree in the process space. Nor is it possible to terminate a process and specify that it's children should also die.</p>
<p>One way around that is to use taskkill and tell it to wack the whole tree.</p>
<p>Another way to do it (assuming that y... | 7 | 2009-08-05T02:12:55Z | [
"python",
"windows",
"process",
"subprocess",
"kill-process"
] |
subprocess: deleting child processes in Windows | 1,230,669 | <p>On Windows, <code>subprocess.Popen.terminate</code> calls win32's <code>TerminalProcess</code>. However, the behavior I see is that child processes of the process I am trying to terminate are still running. Why is that? How do I ensure all child processes started by the process are killed?</p>
| 25 | 2009-08-05T00:53:49Z | 1,231,192 | <p>Put the children in a NT <a href="http://msdn.microsoft.com/en-us/library/ms684161%28VS.85%29.aspx">Job object</a>, then you can kill all children</p>
| 6 | 2009-08-05T04:30:00Z | [
"python",
"windows",
"process",
"subprocess",
"kill-process"
] |
subprocess: deleting child processes in Windows | 1,230,669 | <p>On Windows, <code>subprocess.Popen.terminate</code> calls win32's <code>TerminalProcess</code>. However, the behavior I see is that child processes of the process I am trying to terminate are still running. Why is that? How do I ensure all child processes started by the process are killed?</p>
| 25 | 2009-08-05T00:53:49Z | 4,229,404 | <p>By using <a href="http://code.google.com/p/psutil">psutil</a>:</p>
<pre><code>import psutil, os
def kill_proc_tree(pid, including_parent=True):
parent = psutil.Process(pid)
children = parent.children(recursive=True)
for child in children:
child.kill()
psutil.wait_procs(children, timeout... | 41 | 2010-11-19T21:11:59Z | [
"python",
"windows",
"process",
"subprocess",
"kill-process"
] |
subprocess: deleting child processes in Windows | 1,230,669 | <p>On Windows, <code>subprocess.Popen.terminate</code> calls win32's <code>TerminalProcess</code>. However, the behavior I see is that child processes of the process I am trying to terminate are still running. Why is that? How do I ensure all child processes started by the process are killed?</p>
| 25 | 2009-08-05T00:53:49Z | 10,830,753 | <p>Use <code>taskkill</code> with the <code>/T</code> flag</p>
<pre><code>p = subprocess.Popen(...)
<wait>
subprocess.call(['taskkill', '/F', '/T', '/PID', str(p.pid)])
</code></pre>
<p>The flags to taskkill has the following docs:</p>
<pre><code>TASKKILL [/S system [/U username [/P [password]]]]
{ [/... | 17 | 2012-05-31T09:21:14Z | [
"python",
"windows",
"process",
"subprocess",
"kill-process"
] |
subprocess: deleting child processes in Windows | 1,230,669 | <p>On Windows, <code>subprocess.Popen.terminate</code> calls win32's <code>TerminalProcess</code>. However, the behavior I see is that child processes of the process I am trying to terminate are still running. Why is that? How do I ensure all child processes started by the process are killed?</p>
| 25 | 2009-08-05T00:53:49Z | 12,942,797 | <p>Here's example code for the Job object method, but instead of <code>subprocess</code> it uses <code>win32api.CreateProcess</code></p>
<pre><code>import win32process
import win32job
startup = win32process.STARTUPINFO()
(hProcess, hThread, processId, threadId) = win32process.CreateProcess(None, command, None, None, T... | 6 | 2012-10-17T20:25:37Z | [
"python",
"windows",
"process",
"subprocess",
"kill-process"
] |
How should I close a multi-line variable/comment in Python? | 1,231,333 | <p>I am receiving this error:</p>
<pre><code> File "/DateDbLoop.py", line 33
d.Id""" % (str(day), str(2840))"
^
SyntaxError: EOL while scanning single-quoted string
</code></pre>
<p>Here is the script. There are 4 double quotes to open this, but I am unsure how to correctly close this out?</p>
<p>Fol... | 0 | 2009-08-05T05:23:32Z | 1,231,340 | <p>You use triple quotes for this.</p>
<pre><code>s = """
Python is awesome.
Python is cool.
I use Python.
And so should you.
"""
print s
Python is awesome.
Python is cool.
I use Python.
And so should you.
</code></pre>
| 0 | 2009-08-05T05:27:23Z | [
"python"
] |
How should I close a multi-line variable/comment in Python? | 1,231,333 | <p>I am receiving this error:</p>
<pre><code> File "/DateDbLoop.py", line 33
d.Id""" % (str(day), str(2840))"
^
SyntaxError: EOL while scanning single-quoted string
</code></pre>
<p>Here is the script. There are 4 double quotes to open this, but I am unsure how to correctly close this out?</p>
<p>Fol... | 0 | 2009-08-05T05:23:32Z | 1,231,341 | <p>You have 4 double-quotes at your sql= line, make it 3 instead. Also remove the single quote after your %-substitution value.</p>
<pre><code>#!/usr/bin/python
import datetime
import sys, os, time, string
a = datetime.date(2009, 1, 1)
b = datetime.date(2009, 2, 1)
one_day = datetime.timedelta(1)
day = a
while day... | 5 | 2009-08-05T05:27:40Z | [
"python"
] |
How should I close a multi-line variable/comment in Python? | 1,231,333 | <p>I am receiving this error:</p>
<pre><code> File "/DateDbLoop.py", line 33
d.Id""" % (str(day), str(2840))"
^
SyntaxError: EOL while scanning single-quoted string
</code></pre>
<p>Here is the script. There are 4 double quotes to open this, but I am unsure how to correctly close this out?</p>
<p>Fol... | 0 | 2009-08-05T05:23:32Z | 1,231,356 | <p>Open and close the string with three quotes </p>
<pre><code>sql = """
SELECT d.Date, SUM(d.Revenue),
FROM Table d WHERE d.Date = '%s' AND d.Id = %s
GROUP BY d.Date
""" % (str(day), str(2840))
</code></pre>
<p>You can also break a line in the middle of a string with the \ character. </p>
<... | 1 | 2009-08-05T05:31:44Z | [
"python"
] |
New to Python. Need info on the environment for it | 1,231,397 | <p>I'm a complete newbie to Python. I've worked on PHP/JavaScript earlier but starting today I'm moving onto Python. I have no idea about the environment needed for it. I could use some suggestions on it for me to get started. </p>
| 1 | 2009-08-05T05:47:52Z | 1,231,419 | <p>The <a href="http://wiki.python.org/moin/BeginnersGuide" rel="nofollow">Python Beginner's Guide</a> and the official <a href="http://docs.python.org/tutorial/" rel="nofollow">Python Tutorial</a> both seem like good places to start.</p>
| 0 | 2009-08-05T05:55:57Z | [
"python",
"ide"
] |
New to Python. Need info on the environment for it | 1,231,397 | <p>I'm a complete newbie to Python. I've worked on PHP/JavaScript earlier but starting today I'm moving onto Python. I have no idea about the environment needed for it. I could use some suggestions on it for me to get started. </p>
| 1 | 2009-08-05T05:47:52Z | 1,231,439 | <p>On my mac/Linux machines, python came pre-installed. On windows I use both <a href="http://jython.org" rel="nofollow">jython</a> under the <a href="http://eclipse.org" rel="nofollow">eclipse</a> IDE and <a href="http://ActiveState.com/activepython" rel="nofollow">ActivePython</a> with their IDE/eclipse. Â With <a h... | 1 | 2009-08-05T06:01:31Z | [
"python",
"ide"
] |
New to Python. Need info on the environment for it | 1,231,397 | <p>I'm a complete newbie to Python. I've worked on PHP/JavaScript earlier but starting today I'm moving onto Python. I have no idea about the environment needed for it. I could use some suggestions on it for me to get started. </p>
| 1 | 2009-08-05T05:47:52Z | 1,231,658 | <p>Under Unix, Emacs is a good choice, to which I always come back, because it is convenient to have a single editor for everything, and because it's open source.</p>
<p>What is best for you depends on your past experience with IDEs. I'd say: stick with what you've been using, or take this opportunity to try an even ... | 3 | 2009-08-05T07:25:49Z | [
"python",
"ide"
] |
New to Python. Need info on the environment for it | 1,231,397 | <p>I'm a complete newbie to Python. I've worked on PHP/JavaScript earlier but starting today I'm moving onto Python. I have no idea about the environment needed for it. I could use some suggestions on it for me to get started. </p>
| 1 | 2009-08-05T05:47:52Z | 1,231,739 | <p>Geany is a good option for a Linux setup, it's intellisense isn't that great but syntax highlighting is good and it can compile your code directly from inside the editor, plus it handles other languages such as C/C++, PHP, Java etc... Eric is another popular choice as it's a full IDE and I know some people use Ecli... | 0 | 2009-08-05T07:51:22Z | [
"python",
"ide"
] |
New to Python. Need info on the environment for it | 1,231,397 | <p>I'm a complete newbie to Python. I've worked on PHP/JavaScript earlier but starting today I'm moving onto Python. I have no idea about the environment needed for it. I could use some suggestions on it for me to get started. </p>
| 1 | 2009-08-05T05:47:52Z | 1,231,761 | <p><a href="http://en.wikipedia.org/wiki/IDLE%5F%28Python%29" rel="nofollow">IDLE</a> is nice to try out things. Other tools that people like are <a href="http://www.eclipse.org/" rel="nofollow">Eclipse</a> with the <a href="http://pydev.sourceforge.net/" rel="nofollow">Pydev</a> plugin which seems to work ok, although... | 0 | 2009-08-05T07:57:34Z | [
"python",
"ide"
] |
New to Python. Need info on the environment for it | 1,231,397 | <p>I'm a complete newbie to Python. I've worked on PHP/JavaScript earlier but starting today I'm moving onto Python. I have no idea about the environment needed for it. I could use some suggestions on it for me to get started. </p>
| 1 | 2009-08-05T05:47:52Z | 1,231,790 | <p>It all depends on what you are looking for and what you are already using. </p>
<p>For instance, if you are using a more 'simple' editor at the moment: as long as it's got Python syntax you've got the basics.</p>
<p>If you are used to e.g. <a href="http://eclipse.org/" rel="nofollow">Eclipse</a> you can just conti... | 1 | 2009-08-05T08:06:15Z | [
"python",
"ide"
] |
New to Python. Need info on the environment for it | 1,231,397 | <p>I'm a complete newbie to Python. I've worked on PHP/JavaScript earlier but starting today I'm moving onto Python. I have no idea about the environment needed for it. I could use some suggestions on it for me to get started. </p>
| 1 | 2009-08-05T05:47:52Z | 1,231,813 | <p>I can only help you if you're running a Mac. Download <a href="http://developer.apple.com/technology/xcode.html" rel="nofollow">Xcode</a>. I believe that Python 2.3 comes bundled with these development tools. Luckily enough, this is all you really need to get started, unless you want a newer version of Python.</p>
... | 0 | 2009-08-05T08:11:42Z | [
"python",
"ide"
] |
New to Python. Need info on the environment for it | 1,231,397 | <p>I'm a complete newbie to Python. I've worked on PHP/JavaScript earlier but starting today I'm moving onto Python. I have no idea about the environment needed for it. I could use some suggestions on it for me to get started. </p>
| 1 | 2009-08-05T05:47:52Z | 1,231,819 | <p>Be sure to check out IPython. It's an enhanced interactive python shell with a bunch of useful features such as Tab-Completion using introspection (eg, type "my_object." to see a list of its attributes and methods), logging your interactive session to an executable python-file, defining macros, etc. The <a href="htt... | 2 | 2009-08-05T08:12:34Z | [
"python",
"ide"
] |
New to Python. Need info on the environment for it | 1,231,397 | <p>I'm a complete newbie to Python. I've worked on PHP/JavaScript earlier but starting today I'm moving onto Python. I have no idea about the environment needed for it. I could use some suggestions on it for me to get started. </p>
| 1 | 2009-08-05T05:47:52Z | 1,231,931 | <p>I use gvim with some plugin in order to have better support for python.</p>
<p>If you like IDE, look at <a href="http://www.wingware.com/" rel="nofollow">wing IDE</a> wich is the best I have tested so far. Especially the debuger included is really helpful.</p>
| 1 | 2009-08-05T08:44:06Z | [
"python",
"ide"
] |
Python Multiprocessing Exit Elegantly How? | 1,231,599 | <pre><code>import multiprocessing
import time
class testM(multiprocessing.Process):
def __init__(self):
multiprocessing.Process.__init__(self)
self.exit = False
def run(self):
while not self.exit:
pass
print "You exited!"
return
def shutdown(self):
... | 30 | 2009-08-05T07:07:23Z | 1,231,648 | <p>The reason you are not seeing this happen is because you are not communicating with the subprocess. You are trying to use a local variable (local to the parent process) to signal to the child that it should shutdown.</p>
<p>Take a look at the information on <a href="http://docs.python.org/library/multiprocessing.h... | 34 | 2009-08-05T07:23:47Z | [
"python",
"multiprocessing"
] |
How to get a reference to the module something is implemented in from within that implementation? | 1,231,631 | <p>Say I have the following code:</p>
<pre><code> from foo.bar import Foo
from foo.foo import Bar
__all__ = ["Foo", "Bar"]
def iterate_over_all():
...
</code></pre>
<p>How can I implement code in the function <code>iterate_over_all()</code> that can dynamically obtain references to whatever is referenced in... | 0 | 2009-08-05T07:19:25Z | 1,231,705 | <p><code>eval</code> is one way. e.g. <code>eval("Foo")</code> would give you <code>Foo</code>. However you can also just put Foo and Bar directly in your list e.g. <code>__all__ = [Foo, Bar]</code> </p>
<p>It would depend on where the contents of <code>__all__</code> is coming from in your actual program.</p>
| 0 | 2009-08-05T07:40:21Z | [
"python",
"module"
] |
How to get a reference to the module something is implemented in from within that implementation? | 1,231,631 | <p>Say I have the following code:</p>
<pre><code> from foo.bar import Foo
from foo.foo import Bar
__all__ = ["Foo", "Bar"]
def iterate_over_all():
...
</code></pre>
<p>How can I implement code in the function <code>iterate_over_all()</code> that can dynamically obtain references to whatever is referenced in... | 0 | 2009-08-05T07:19:25Z | 1,232,214 | <p>You can easily index with the strings from <em>__all__</em> into the module's <em>__dict__</em>:</p>
<pre><code>__dict__["Foo"] == foo.bar.Foo # -> True
</code></pre>
| 0 | 2009-08-05T09:48:36Z | [
"python",
"module"
] |
How to get a reference to the module something is implemented in from within that implementation? | 1,231,631 | <p>Say I have the following code:</p>
<pre><code> from foo.bar import Foo
from foo.foo import Bar
__all__ = ["Foo", "Bar"]
def iterate_over_all():
...
</code></pre>
<p>How can I implement code in the function <code>iterate_over_all()</code> that can dynamically obtain references to whatever is referenced in... | 0 | 2009-08-05T07:19:25Z | 1,232,542 | <p>Would this do?</p>
<pre><code>def iterate_over_all():
for name in __all__:
value = globals()[name]
yield value # or do whatever with it
</code></pre>
| 2 | 2009-08-05T11:03:05Z | [
"python",
"module"
] |
How do I remove packages installed with Python's easy_install? | 1,231,688 | <p>Python's <code>easy_install</code> makes installing new packages extremely convenient. However, as far as I can tell, it doesn't implement the other common features of a dependency manager - listing and removing installed packages.</p>
<p>What is the best way of finding out what's installed, and what is the preferr... | 572 | 2009-08-05T07:33:13Z | 1,231,745 | <p>There are <a href="http://thingsilearned.com/2009/04/13/easy_install-uninstalling/">several</a> sources on the net suggesting a hack by reinstalling the package with the -m option and then just removing the .egg file in lib/ and the binaries in bin/. Also, discussion about this setuptools issue can be found on the p... | 27 | 2009-08-05T07:53:43Z | [
"python",
"packages",
"setuptools",
"easy-install"
] |
How do I remove packages installed with Python's easy_install? | 1,231,688 | <p>Python's <code>easy_install</code> makes installing new packages extremely convenient. However, as far as I can tell, it doesn't implement the other common features of a dependency manager - listing and removing installed packages.</p>
<p>What is the best way of finding out what's installed, and what is the preferr... | 572 | 2009-08-05T07:33:13Z | 1,233,261 | <p>If the problem is a serious-enough annoyance to you, you might consider <a href="http://pypi.python.org/pypi/virtualenv">virtualenv</a>. It allows you to create an environment that encapsulates python libraries. You install packages there rather than in the global site-packages directory. Any scripts you run in that... | 23 | 2009-08-05T13:28:37Z | [
"python",
"packages",
"setuptools",
"easy-install"
] |
How do I remove packages installed with Python's easy_install? | 1,231,688 | <p>Python's <code>easy_install</code> makes installing new packages extremely convenient. However, as far as I can tell, it doesn't implement the other common features of a dependency manager - listing and removing installed packages.</p>
<p>What is the best way of finding out what's installed, and what is the preferr... | 572 | 2009-08-05T07:33:13Z | 1,233,282 | <p>To uninstall an <code>.egg</code> you need to <code>rm -rf</code> the egg (it might be a directory) and remove the matching line from <code>site-packages/easy-install.pth</code></p>
| 164 | 2009-08-05T13:31:53Z | [
"python",
"packages",
"setuptools",
"easy-install"
] |
How do I remove packages installed with Python's easy_install? | 1,231,688 | <p>Python's <code>easy_install</code> makes installing new packages extremely convenient. However, as far as I can tell, it doesn't implement the other common features of a dependency manager - listing and removing installed packages.</p>
<p>What is the best way of finding out what's installed, and what is the preferr... | 572 | 2009-08-05T07:33:13Z | 3,297,522 | <p>try</p>
<pre><code>$ easy_install -m [PACKAGE]
</code></pre>
<p>then</p>
<pre><code>$ rm -rf .../python2.X/site-packages/[PACKAGE].egg
</code></pre>
| 14 | 2010-07-21T08:40:36Z | [
"python",
"packages",
"setuptools",
"easy-install"
] |
How do I remove packages installed with Python's easy_install? | 1,231,688 | <p>Python's <code>easy_install</code> makes installing new packages extremely convenient. However, as far as I can tell, it doesn't implement the other common features of a dependency manager - listing and removing installed packages.</p>
<p>What is the best way of finding out what's installed, and what is the preferr... | 572 | 2009-08-05T07:33:13Z | 3,297,564 | <p><a href="http://pypi.python.org/pypi/pip/">pip</a>, an alternative to setuptools/easy_install, provides an "uninstall" command. </p>
<p>Install pip according to the <a href="http://pip.readthedocs.org/en/stable/installing/">installation instructions</a>:</p>
<pre><code>$ wget https://bootstrap.pypa.io/get-pip.py
$... | 536 | 2010-07-21T08:47:21Z | [
"python",
"packages",
"setuptools",
"easy-install"
] |
How do I remove packages installed with Python's easy_install? | 1,231,688 | <p>Python's <code>easy_install</code> makes installing new packages extremely convenient. However, as far as I can tell, it doesn't implement the other common features of a dependency manager - listing and removing installed packages.</p>
<p>What is the best way of finding out what's installed, and what is the preferr... | 572 | 2009-08-05T07:33:13Z | 3,454,856 | <p>Official(?) instructions: <a href="http://peak.telecommunity.com/DevCenter/EasyInstall#uninstalling-packages" rel="nofollow">http://peak.telecommunity.com/DevCenter/EasyInstall#uninstalling-packages</a></p>
<blockquote>
<p>If you have replaced a package with another version, then you can just delete the package(s... | 13 | 2010-08-11T02:28:14Z | [
"python",
"packages",
"setuptools",
"easy-install"
] |
How do I remove packages installed with Python's easy_install? | 1,231,688 | <p>Python's <code>easy_install</code> makes installing new packages extremely convenient. However, as far as I can tell, it doesn't implement the other common features of a dependency manager - listing and removing installed packages.</p>
<p>What is the best way of finding out what's installed, and what is the preferr... | 572 | 2009-08-05T07:33:13Z | 4,320,437 | <p>To list installed Python packages, you can use <code>yolk -l</code>. You'll need to use <code>easy_install yolk</code> first though.</p>
| 6 | 2010-12-01T01:25:11Z | [
"python",
"packages",
"setuptools",
"easy-install"
] |
How do I remove packages installed with Python's easy_install? | 1,231,688 | <p>Python's <code>easy_install</code> makes installing new packages extremely convenient. However, as far as I can tell, it doesn't implement the other common features of a dependency manager - listing and removing installed packages.</p>
<p>What is the best way of finding out what's installed, and what is the preferr... | 572 | 2009-08-05T07:33:13Z | 4,321,319 | <p>Came across this question, while trying to uninstall the many random Python packages installed over time.</p>
<p>Using information from this thread, this is what I came up with:</p>
<pre><code>cat package_list | xargs -n1 sudo pip uninstall -y
</code></pre>
<p>The <code>package_list</code> is cleaned up (awk) fro... | 5 | 2010-12-01T04:56:40Z | [
"python",
"packages",
"setuptools",
"easy-install"
] |
How do I remove packages installed with Python's easy_install? | 1,231,688 | <p>Python's <code>easy_install</code> makes installing new packages extremely convenient. However, as far as I can tell, it doesn't implement the other common features of a dependency manager - listing and removing installed packages.</p>
<p>What is the best way of finding out what's installed, and what is the preferr... | 572 | 2009-08-05T07:33:13Z | 5,677,700 | <p>I ran into the same problem on my MacOS X Leopard 10.6.blah.</p>
<p>Solution is to make sure you're calling the MacPorts Python:</p>
<pre><code>sudo port install python26
sudo port install python_select
sudo python_select python26
sudo port install py26-mysql
</code></pre>
<p>Hope this helps.</p>
| 2 | 2011-04-15T13:45:56Z | [
"python",
"packages",
"setuptools",
"easy-install"
] |
How do I remove packages installed with Python's easy_install? | 1,231,688 | <p>Python's <code>easy_install</code> makes installing new packages extremely convenient. However, as far as I can tell, it doesn't implement the other common features of a dependency manager - listing and removing installed packages.</p>
<p>What is the best way of finding out what's installed, and what is the preferr... | 572 | 2009-08-05T07:33:13Z | 6,263,564 | <p>First you have to run this command:</p>
<pre><code>$ easy_install -m [PACKAGE]
</code></pre>
<p>It removes all dependencies of the package.</p>
<p>Then remove egg file of that package:</p>
<pre><code>$ sudo rm -rf /usr/local/lib/python2.X/site-packages/[PACKAGE].egg
</code></pre>
| 128 | 2011-06-07T09:56:47Z | [
"python",
"packages",
"setuptools",
"easy-install"
] |
How do I remove packages installed with Python's easy_install? | 1,231,688 | <p>Python's <code>easy_install</code> makes installing new packages extremely convenient. However, as far as I can tell, it doesn't implement the other common features of a dependency manager - listing and removing installed packages.</p>
<p>What is the best way of finding out what's installed, and what is the preferr... | 572 | 2009-08-05T07:33:13Z | 8,718,590 | <p>All the info is in the other answers, but none summarizes <em>both</em> your requests or seem to make things needlessly complex:</p>
<ul>
<li><p>For your removal needs use:</p>
<pre><code>pip uninstall <package>
</code></pre>
<p>(install using <code>easy_install pip</code>)</p></li>
<li><p>For your 'list in... | 49 | 2012-01-03T21:04:44Z | [
"python",
"packages",
"setuptools",
"easy-install"
] |
How do I remove packages installed with Python's easy_install? | 1,231,688 | <p>Python's <code>easy_install</code> makes installing new packages extremely convenient. However, as far as I can tell, it doesn't implement the other common features of a dependency manager - listing and removing installed packages.</p>
<p>What is the best way of finding out what's installed, and what is the preferr... | 572 | 2009-08-05T07:33:13Z | 26,481,670 | <p>For me only deleting this file : easy-install.pth
worked, rest pip install django==1.3.7 </p>
| 1 | 2014-10-21T08:00:54Z | [
"python",
"packages",
"setuptools",
"easy-install"
] |
python String Formatting Operations | 1,231,784 | <p>Faulty code:</p>
<pre><code>pos_1 = 234
pos_n = 12890
min_width = len(str(pos_n)) # is there a better way for this?
# How can I use min_width as the minimal width of the two conversion specifiers?
# I don't understand the Python documentation on this :(
raw_str = '... from %(pos1)0*d to %(posn)0*d ...' % {'pos1':p... | 0 | 2009-08-05T08:04:10Z | 1,231,809 | <pre><code>"1234".rjust(13,"0")
</code></pre>
<p>Should do what you need</p>
<p>addition:</p>
<pre><code>a = ["123", "12"]
max_width = sorted([len(i) for i in a])[-1]
</code></pre>
<p>put max_width instead of 13 above and put all your strings in a single array a (which seems to me much more usable than having a... | 1 | 2009-08-05T08:11:14Z | [
"python",
"string",
"formatting"
] |
python String Formatting Operations | 1,231,784 | <p>Faulty code:</p>
<pre><code>pos_1 = 234
pos_n = 12890
min_width = len(str(pos_n)) # is there a better way for this?
# How can I use min_width as the minimal width of the two conversion specifiers?
# I don't understand the Python documentation on this :(
raw_str = '... from %(pos1)0*d to %(posn)0*d ...' % {'pos1':p... | 0 | 2009-08-05T08:04:10Z | 1,231,833 | <pre><code>pos_1 = 234
pos_n = 12890
min_width = len(str(pos_n))
raw_str = '... from %0*d to %0*d ...' % (min_width, pos_1, min_width, pos_n)
</code></pre>
| 2 | 2009-08-05T08:18:58Z | [
"python",
"string",
"formatting"
] |
python String Formatting Operations | 1,231,784 | <p>Faulty code:</p>
<pre><code>pos_1 = 234
pos_n = 12890
min_width = len(str(pos_n)) # is there a better way for this?
# How can I use min_width as the minimal width of the two conversion specifiers?
# I don't understand the Python documentation on this :(
raw_str = '... from %(pos1)0*d to %(posn)0*d ...' % {'pos1':p... | 0 | 2009-08-05T08:04:10Z | 1,232,559 | <p>Concerning using a mapping type as second argument to '%':</p>
<p>I presume you mean something like that <em>'%(mykey)d' % {'mykey': 3}</em>, right?! I think you cannot use this if you use the "%*d" syntax, since there is no way to provide the necessary width arguments with a dict.</p>
<p>But why don't you generat... | 1 | 2009-08-05T11:05:59Z | [
"python",
"string",
"formatting"
] |
Classes nested in functions and attribute lookup | 1,231,814 | <p>The following works Ok, i.e. it doesn't give any errors:</p>
<pre><code>def foo(arg):
class Nested(object):
x = arg
foo('hello')
</code></pre>
<p>But the following throws an exception:</p>
<pre><code>def foo(arg):
class Nested(object):
arg = arg # note that names are the same
foo('hello'... | 3 | 2009-08-05T08:11:48Z | 1,231,888 | <p>The <code>arg</code> property shadows the <code>arg</code> function argument (inner scoping)</p>
<pre><code>def foo(arg):
class Nested(object):
arg = arg # you try to read the `arg` property which isn't initialized
</code></pre>
<p><br>
You get the same error if you type <code>i = i</code> in the inte... | 4 | 2009-08-05T08:32:45Z | [
"python",
"class",
"nested"
] |
Classes nested in functions and attribute lookup | 1,231,814 | <p>The following works Ok, i.e. it doesn't give any errors:</p>
<pre><code>def foo(arg):
class Nested(object):
x = arg
foo('hello')
</code></pre>
<p>But the following throws an exception:</p>
<pre><code>def foo(arg):
class Nested(object):
arg = arg # note that names are the same
foo('hello'... | 3 | 2009-08-05T08:11:48Z | 1,231,892 | <p>If you try and assign to a variable within a function, Python assumes that variable is local to that function. So by trying to assign arg to the value of itself, you are implicitly declaring it as a local variable.</p>
| 3 | 2009-08-05T08:33:46Z | [
"python",
"class",
"nested"
] |
Classes nested in functions and attribute lookup | 1,231,814 | <p>The following works Ok, i.e. it doesn't give any errors:</p>
<pre><code>def foo(arg):
class Nested(object):
x = arg
foo('hello')
</code></pre>
<p>But the following throws an exception:</p>
<pre><code>def foo(arg):
class Nested(object):
arg = arg # note that names are the same
foo('hello'... | 3 | 2009-08-05T08:11:48Z | 1,231,897 | <p>It is due to Python's scoping rules:</p>
<pre><code>def foo(arg): # (1)
class Nested(object):
arg = arg # (2)
</code></pre>
<p>(2) defines a new 'arg' name in the class' namespace, which opaques the value of the other 'arg' in the outer namespace (1).</p>
<p>However, (2) is unnecessary and the followi... | 2 | 2009-08-05T08:35:10Z | [
"python",
"class",
"nested"
] |
How does mercurial work without Python installed? | 1,231,853 | <p>I have Mercurial 1.3 installed on my Windows 7 machine. I don't have python installed, but Mercurial seems to be OK with that.</p>
<p>How does it work?</p>
<p>Also, is it possible to force Mercurial run on IronPython and will it be compatible?</p>
<p>Thank you.</p>
| 8 | 2009-08-05T08:22:55Z | 1,231,883 | <p>Mercurial bundles the necessary python binaries within it, I believe.</p>
| 3 | 2009-08-05T08:31:04Z | [
"python",
"mercurial",
"ironpython"
] |
How does mercurial work without Python installed? | 1,231,853 | <p>I have Mercurial 1.3 installed on my Windows 7 machine. I don't have python installed, but Mercurial seems to be OK with that.</p>
<p>How does it work?</p>
<p>Also, is it possible to force Mercurial run on IronPython and will it be compatible?</p>
<p>Thank you.</p>
| 8 | 2009-08-05T08:22:55Z | 1,232,605 | <p>Since there is a "library.zip"(9MB), Mercurial's Windows binary package maybe made by <a href="http://www.py2exe.org/" rel="nofollow">py2exe</a>, py2exe is a Python Distutils extension which converts Python scripts into executable Windows programs, able to run without requiring a Python installation. </p>
| 7 | 2009-08-05T11:16:36Z | [
"python",
"mercurial",
"ironpython"
] |
How does mercurial work without Python installed? | 1,231,853 | <p>I have Mercurial 1.3 installed on my Windows 7 machine. I don't have python installed, but Mercurial seems to be OK with that.</p>
<p>How does it work?</p>
<p>Also, is it possible to force Mercurial run on IronPython and will it be compatible?</p>
<p>Thank you.</p>
| 8 | 2009-08-05T08:22:55Z | 1,232,767 | <p>The Mercurial windows installer is packaged using <a href="http://www.py2exe.org/">py2exe</a>. This places the python interpreter as a DLL inside of a file called "library.zip". </p>
<p>On my machine, it is placed in "C:\Program Files\TortoiseHg\library.zip"</p>
<p>This zip file also contains the python libraries... | 17 | 2009-08-05T11:52:12Z | [
"python",
"mercurial",
"ironpython"
] |
How does mercurial work without Python installed? | 1,231,853 | <p>I have Mercurial 1.3 installed on my Windows 7 machine. I don't have python installed, but Mercurial seems to be OK with that.</p>
<p>How does it work?</p>
<p>Also, is it possible to force Mercurial run on IronPython and will it be compatible?</p>
<p>Thank you.</p>
| 8 | 2009-08-05T08:22:55Z | 1,283,908 | <p>Others have answered the first question -- let me give a guess about the second part. </p>
<p>Mercurial will normally use some C extensions for speed. You cannot use those with IronPython.</p>
<p>But we also ship pure Python versions of these modules, and depending on how much IronPython implements of a standard P... | 6 | 2009-08-16T09:47:36Z | [
"python",
"mercurial",
"ironpython"
] |
MySQL LOAD DATA LOCAL INFILE example in python? | 1,231,900 | <p>I am looking for a syntax definition, example, sample code, wiki, etc. for
executing a LOAD DATA LOCAL INFILE command from python.</p>
<p>I believe I can use mysqlimport as well if that is available, so any feedback (and code snippet) on which is the better route, is welcome. A Google search is not turning up muc... | 10 | 2009-08-05T08:36:26Z | 1,234,705 | <p>Well, using python's MySQLdb, I use this:</p>
<pre><code>connection = MySQLdb.Connect(host='**', user='**', passwd='**', db='**')
cursor = connection.cursor()
query = "LOAD DATA INFILE '/path/to/my/file' INTO TABLE sometable FIELDS TERMINATED BY ';' ENCLOSED BY '\"' ESCAPED BY '\\\\'"
cursor.execute( query )
connec... | 18 | 2009-08-05T17:46:39Z | [
"python",
"mysql",
"load-data-infile"
] |
MySQL LOAD DATA LOCAL INFILE example in python? | 1,231,900 | <p>I am looking for a syntax definition, example, sample code, wiki, etc. for
executing a LOAD DATA LOCAL INFILE command from python.</p>
<p>I believe I can use mysqlimport as well if that is available, so any feedback (and code snippet) on which is the better route, is welcome. A Google search is not turning up muc... | 10 | 2009-08-05T08:36:26Z | 2,802,111 | <p>You can also get the results for the import by adding the following lines after your query:</p>
<pre><code>results = connection.info()
</code></pre>
| 0 | 2010-05-10T11:09:23Z | [
"python",
"mysql",
"load-data-infile"
] |
how to overwrite User model | 1,231,943 | <p>I don't like models.User, but I like Admin view, and I will keep admin view in my application. </p>
<p>How to overwirte models.User ?
Make it just look like following:</p>
<pre><code>from django.contrib.auth.models import User
class ShugeUser(User)
username = EmailField(uniqute=True, verbose_name='EMail as y... | 0 | 2009-08-05T08:47:59Z | 1,232,099 | <p>That isn't possible right now. If all you want is to use the email address as the username, you could write a <a href="http://docs.djangoproject.com/en/dev/topics/auth/#writing-an-authentication-backend" rel="nofollow">custom auth backend</a> that checks if the email/password combination is correct instead of the us... | 4 | 2009-08-05T09:23:08Z | [
"python",
"django",
"django-models",
"django-admin"
] |
how to overwrite User model | 1,231,943 | <p>I don't like models.User, but I like Admin view, and I will keep admin view in my application. </p>
<p>How to overwirte models.User ?
Make it just look like following:</p>
<pre><code>from django.contrib.auth.models import User
class ShugeUser(User)
username = EmailField(uniqute=True, verbose_name='EMail as y... | 0 | 2009-08-05T08:47:59Z | 1,237,517 | <p>The answer above is good and we use it on several sites successfully. I want to also point out though that many times people want to change the User model they are adding more information fields. This can be accommodated with the built in user profile support in the the contrib admin module.</p>
<p>You access the p... | 0 | 2009-08-06T08:06:24Z | [
"python",
"django",
"django-models",
"django-admin"
] |
How can I use a class instance variable as an argument for a method decorator in Python? | 1,231,950 | <p>How can I use a class instance variable as an argument for a method decorator in Python?
The following is a minimal example shows what I'm trying to do. It obviously fails as the decorator function does not have access to the reference to the instance and I have no idea how to get access to the reference from the de... | 4 | 2009-08-05T08:49:25Z | 1,232,003 | <p>The decorator is executed when the class is defined, so you can't pass an instance variable to it.</p>
| 0 | 2009-08-05T08:59:54Z | [
"python",
"decorator"
] |
How can I use a class instance variable as an argument for a method decorator in Python? | 1,231,950 | <p>How can I use a class instance variable as an argument for a method decorator in Python?
The following is a minimal example shows what I'm trying to do. It obviously fails as the decorator function does not have access to the reference to the instance and I have no idea how to get access to the reference from the de... | 4 | 2009-08-05T08:49:25Z | 1,232,055 | <p>It's not going to work; the decorator is called during <em>class creation</em> time, which is long before an instance is created (<em>if</em> that ever happens). So if your "decorator" needs the instance, you have to do the "decorating" at instantiation time:</p>
<pre><code>def get_decorator(arg1):
def my_decor... | 7 | 2009-08-05T09:11:19Z | [
"python",
"decorator"
] |
How can I use a class instance variable as an argument for a method decorator in Python? | 1,231,950 | <p>How can I use a class instance variable as an argument for a method decorator in Python?
The following is a minimal example shows what I'm trying to do. It obviously fails as the decorator function does not have access to the reference to the instance and I have no idea how to get access to the reference from the de... | 4 | 2009-08-05T08:49:25Z | 1,232,295 | <p>Your âwarperâ function is actually a decorator, rather than a warper. Your âdecorator1â function is a decorator constructor. If you want to have access to self.var1 in runtime you have to make a warper not decorator: </p>
<pre><code>def decorator(function):
def wrapper(self,*args,**kwargs):
print "Doi... | 4 | 2009-08-05T10:06:42Z | [
"python",
"decorator"
] |
How can I use a class instance variable as an argument for a method decorator in Python? | 1,231,950 | <p>How can I use a class instance variable as an argument for a method decorator in Python?
The following is a minimal example shows what I'm trying to do. It obviously fails as the decorator function does not have access to the reference to the instance and I have no idea how to get access to the reference from the de... | 4 | 2009-08-05T08:49:25Z | 1,235,366 | <p>Here's how we used to do this in the olden days.</p>
<pre><code>class Foo(object):
def __init__(self, arg1):
self.var1 = arg1
def method1(self):
self.lock()
try:
self.do_method1()
except Exception:
pass # Might want to log this
finally:
... | 0 | 2009-08-05T19:49:45Z | [
"python",
"decorator"
] |
setuptools / dpkg-buildpackage: Refuse to build if nosetests fail | 1,231,958 | <p>I have a very simple python package that I build into debian packages using setuptools, cdbs and pycentral:</p>
<p>setup.py:</p>
<pre><code>from setuptools import setup
setup(name='PHPSerialize',
version='1.0',
py_modules=['PHPSerialize'],
test_suite = 'nose.collector'
)
</code></pre>
<p>debian/rules:</p>
... | 3 | 2009-08-05T08:50:03Z | 1,420,883 | <p>Try</p>
<pre><code>build/yourpackage::
nosetests
</code></pre>
| 2 | 2009-09-14T10:58:40Z | [
"python",
"debian",
"setuptools",
"nose",
"cdbs"
] |
Django - Following a foreign key relationship (i.e JOIN in SQL) | 1,232,172 | <p>Busy playing with django, but one thing seems to be tripping me up is following a foreign key relationship. Now, I have a ton of experience in writing SQL, so i could prob. return the result if the ORM was not there. </p>
<p>Basically this is the SQL query i want returned</p>
<pre><code>Select
table1.id
table1... | 0 | 2009-08-05T09:40:01Z | 1,232,221 | <p>Something like this should work:</p>
<pre><code>u = Table1.objects.get(id=1)
print u.id
print u.user.user_name
</code></pre>
<p>If you want to follow a foreign key, you must do it explicitly. You don't get an automatic join, when you retrieve an object from Table1. You will only get an object from Table2, when you... | 3 | 2009-08-05T09:49:30Z | [
"python",
"django",
"django-models",
"django-urls"
] |
Django - Following a foreign key relationship (i.e JOIN in SQL) | 1,232,172 | <p>Busy playing with django, but one thing seems to be tripping me up is following a foreign key relationship. Now, I have a ton of experience in writing SQL, so i could prob. return the result if the ORM was not there. </p>
<p>Basically this is the SQL query i want returned</p>
<pre><code>Select
table1.id
table1... | 0 | 2009-08-05T09:40:01Z | 1,232,225 | <p>select_related() do not add second table result directly to the query, it just "Loads" them, insead of giving to you lazily. You should only use it, when you are sure it can boost your site performance. To get second table you need to write</p>
<pre><code>a.user.username
</code></pre>
<p>In Django to get related t... | 2 | 2009-08-05T09:50:13Z | [
"python",
"django",
"django-models",
"django-urls"
] |
How to make server accepting connections from multiple ports? | 1,232,366 | <p>How can I make a simple server(simple as in accepting a connection and print to terminal whatever is received) accept connection from multiple ports or a port range?</p>
<p>Do I have to use multiple threads, one for each bind call. Or is there another solution?</p>
<p>The simple server can look something like this... | 4 | 2009-08-05T10:26:35Z | 1,232,387 | <p>I'm not a python guy, but the function you are interested in is "select". This will allow you to watch multiple sockets and breaks out when activity occurs on any one of them.</p>
<p>Here's a <a href="http://code.activestate.com/recipes/531824/">python example that uses select</a>.</p>
| 6 | 2009-08-05T10:31:47Z | [
"python",
"network-programming"
] |
How to make server accepting connections from multiple ports? | 1,232,366 | <p>How can I make a simple server(simple as in accepting a connection and print to terminal whatever is received) accept connection from multiple ports or a port range?</p>
<p>Do I have to use multiple threads, one for each bind call. Or is there another solution?</p>
<p>The simple server can look something like this... | 4 | 2009-08-05T10:26:35Z | 1,232,676 | <p>If you really wanted to be lazy (from a <em>programmer</em> standpoint, not an evaluation standpoint), you could set a timeout on your blocking read and just loop through all your sockets; if a timeout occurs, there wasn't any data available. Functionally, this is similar to what the <code>select</code> is doing, b... | 1 | 2009-08-05T11:30:38Z | [
"python",
"network-programming"
] |
How to make server accepting connections from multiple ports? | 1,232,366 | <p>How can I make a simple server(simple as in accepting a connection and print to terminal whatever is received) accept connection from multiple ports or a port range?</p>
<p>Do I have to use multiple threads, one for each bind call. Or is there another solution?</p>
<p>The simple server can look something like this... | 4 | 2009-08-05T10:26:35Z | 19,575,664 | <p>Since Python's got so much overhead, multithreaded apps are a big point of debate. Then there's the whole blocking-operation-GIL issue too. Luckily, the Python motto of <em>"If it seems like a big issue, someone's probably already come up with a solution (or several!)"</em> holds true here. My favorite solution tend... | 2 | 2013-10-24T20:10:11Z | [
"python",
"network-programming"
] |
"Upload" a file from django shell | 1,232,434 | <p>I need to import some data from a excel file and a folder with images, every row in the excel describes every entry and have a list of filenames in the folder (photos related to the entry).</p>
<p>I've done a script which creates every entry in the database and saves it trough the django shell, but i have no idea h... | 10 | 2009-08-05T10:41:15Z | 1,232,567 | <p>Finally I found the answer.</p>
<pre><code>from django.core.files import File
f = File(open(os.path.join(IMPORT_DIR, 'fotos', photo), 'r'))
p = Photo(name=f.name, image=f, parent=supply.supply_ptr)
name = str(uuid1()) + os.path.splitext(f.name)[1]
p.image.save(name, f)
p.save()
</code></pre>
| 17 | 2009-08-05T11:07:11Z | [
"python",
"django",
"file",
"import",
"data-importer"
] |
"Upload" a file from django shell | 1,232,434 | <p>I need to import some data from a excel file and a folder with images, every row in the excel describes every entry and have a list of filenames in the folder (photos related to the entry).</p>
<p>I've done a script which creates every entry in the database and saves it trough the django shell, but i have no idea h... | 10 | 2009-08-05T10:41:15Z | 24,699,274 | <p>If using <strong>Python 3</strong> one adjustment is needed - change 'r' to 'rb': </p>
<pre><code>f = File(open(os.path.join(IMPORT_DIR, 'fotos', photo), 'rb'))
</code></pre>
| 2 | 2014-07-11T13:45:43Z | [
"python",
"django",
"file",
"import",
"data-importer"
] |
Concatenating Dictionaries | 1,232,904 | <p>I have three lists, the first is a list of names, the second is a list of dictionaries, and the third is a list of data. Each position in a list corresponds with the same positions in the other lists. List_1[0] has corresponding data in List_2[0] and List_3[0], etc. I would like to turn these three lists into a dict... | 6 | 2009-08-05T12:22:03Z | 1,232,938 | <pre><code>>>> a = [1,2,3]
>>> b = [4,5,6]
>>> c = [7,8,9]
>>> dict(zip(a, zip(b, c)))
{1: (4, 7), 2: (5, 8), 3: (6, 9)}
</code></pre>
<p>See the <a href="http://docs.python.org/library/functions.html#zip" rel="nofollow">documentation</a> for more info on <code>zip</code>.</p>
<p>A... | 13 | 2009-08-05T12:27:35Z | [
"python",
"dictionary",
"merge",
"key"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.