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 |
|---|---|---|---|---|---|---|---|---|---|
Python: Can subclasses overload inherited methods? | 2,398,666 | <p>I'm making a shopping cart app in Google App Engine. I have many classes that derive from a base handler:</p>
<pre><code>class BaseHandler(webapp.RequestHandler):
def get(self, CSIN=None):
self.body(CSIN)
</code></pre>
<p>Does this mean that the <code>body()</code> method of every descendant class need... | 2 | 2010-03-08T00:38:34Z | 2,398,696 | <p>Overridden methods don't have to have the same parameters as each other in principle, but they do have to have the same formal parameters they're called with. So since any handler can have <code>body</code> called on it by <code>get</code>, yes they have to be the same. For that matter, kind of the point of overridi... | 4 | 2010-03-08T00:50:18Z | [
"python",
"oop",
"google-app-engine",
"refactoring",
"method-overloading"
] |
Python: Can subclasses overload inherited methods? | 2,398,666 | <p>I'm making a shopping cart app in Google App Engine. I have many classes that derive from a base handler:</p>
<pre><code>class BaseHandler(webapp.RequestHandler):
def get(self, CSIN=None):
self.body(CSIN)
</code></pre>
<p>Does this mean that the <code>body()</code> method of every descendant class need... | 2 | 2010-03-08T00:38:34Z | 2,398,717 | <p>Python matches methods for overloading based on name only. Which means that</p>
<pre><code>class Base:
def method(self, param2):
print "cheeses"
class NotBase(Base):
def method(self):
print "dill"
obj = NotBase();
obj.method()
</code></pre>
<p>will output dill( while obj.method("stuff") will fail ... | 1 | 2010-03-08T00:58:38Z | [
"python",
"oop",
"google-app-engine",
"refactoring",
"method-overloading"
] |
How to create Python module distribution to gracefully fall-back to pure Python code | 2,398,699 | <p>I have written a Python module, and I have two versions: a pure Python implementation and a C extension. I've written the <code>__init__.py</code> file so that it tries to import the C extension, and if that fails, it imports the pure Python code (is that reasonable?).</p>
<p>Now, I'd like to know what is the best ... | 5 | 2010-03-08T00:50:52Z | 2,398,773 | <blockquote>
<p>(is that reasonable?).</p>
</blockquote>
<p>Yep, perfectly sensible.</p>
<p>To catch the "no suitable C compiler case": the call to <code>setup(...)</code> will do a sys.exit in case of problems. So, first try it with the <code>ext_modules</code> argument set as desired, within a <code>try</code>:<... | 5 | 2010-03-08T01:19:33Z | [
"python",
"software-distribution"
] |
How to create Python module distribution to gracefully fall-back to pure Python code | 2,398,699 | <p>I have written a Python module, and I have two versions: a pure Python implementation and a C extension. I've written the <code>__init__.py</code> file so that it tries to import the C extension, and if that fails, it imports the pure Python code (is that reasonable?).</p>
<p>Now, I'd like to know what is the best ... | 5 | 2010-03-08T00:50:52Z | 2,399,160 | <p>"tries to import the C extension, and if that fails, it imports the pure Python code (is that reasonable?)."</p>
<p>Almost. Read about <code>cStringIO</code> and <code>StringIO</code>. Also read about <code>cPickle</code> and <code>Pickle</code>. Also read about <code>cElementTree</code> and <code>ElementTree</c... | 0 | 2010-03-08T03:41:31Z | [
"python",
"software-distribution"
] |
How to create Python module distribution to gracefully fall-back to pure Python code | 2,398,699 | <p>I have written a Python module, and I have two versions: a pure Python implementation and a C extension. I've written the <code>__init__.py</code> file so that it tries to import the C extension, and if that fails, it imports the pure Python code (is that reasonable?).</p>
<p>Now, I'd like to know what is the best ... | 5 | 2010-03-08T00:50:52Z | 2,721,859 | <p>According to the <a href="http://pygamesf.org/~casey/planar/doc/overview.html" rel="nofollow">documentation for Planar</a>, you can make the <code>setup.py</code> file for building the C extensions as normal, and then:</p>
<blockquote>
<p>To build and install Planar from the source distribution or repository use:... | 0 | 2010-04-27T14:07:00Z | [
"python",
"software-distribution"
] |
Apps not showing in Django admin site | 2,398,721 | <p>I have a Django project with about 10 apps in it. But the admin interface only shows Auth and Site models which are part of Django distribution. Yes, the admin interface is up and working but none of my self-written apps shows there.</p>
<p><strong>INSTALLED_APPS</strong></p>
<pre><code>INSTALLED_APPS = (
'dja... | 2 | 2010-03-08T00:59:48Z | 2,398,851 | <p>Which version of Django are you using? Support for files named admin.py was added in version 1.0 (I think). Before that, you'd have to add <a href="http://www.djangoproject.com/documentation/0.96/tutorial02/" rel="nofollow">extra information to your model</a>.</p>
| 0 | 2010-03-08T01:44:56Z | [
"python",
"django",
"model",
"admin"
] |
Apps not showing in Django admin site | 2,398,721 | <p>I have a Django project with about 10 apps in it. But the admin interface only shows Auth and Site models which are part of Django distribution. Yes, the admin interface is up and working but none of my self-written apps shows there.</p>
<p><strong>INSTALLED_APPS</strong></p>
<pre><code>INSTALLED_APPS = (
'dja... | 2 | 2010-03-08T00:59:48Z | 2,513,581 | <p>If something in your app throws an exception, the app or model may be excluded from the admin on subsequent requests.</p>
<p>If that is the case, you should get an error on the first request.</p>
<p>Also, please make sure your URLCONF has admin.autodiscover()</p>
| 0 | 2010-03-25T06:54:06Z | [
"python",
"django",
"model",
"admin"
] |
Saving Python Complex Data Types to Amazon S3 | 2,398,735 | <p>Can Python class data be saved to S3 without marshalling? I am trying to cut down of I/O operations until necessary.</p>
| 0 | 2010-03-08T01:05:10Z | 2,398,752 | <p>Amazon S3 stores plain data files. Even if there's a library that makes it look like objects are being saved, it's going to do marshalling in the background. Might as well just <a href="http://docs.python.org/library/pickle.html" rel="nofollow">pickle</a> your objects by yourself.</p>
| 1 | 2010-03-08T01:12:46Z | [
"python",
"amazon-s3",
"amazon",
"boto"
] |
Python 3.1.1 Class Question | 2,398,782 | <p>I'm a new Python programmer who is having a little trouble using 'self' in classes. For example:</p>
<pre><code>class data:
def __init__(self):
self.table = []
def add(self, file):
self.table.append(file)
data.add('yes')
</code></pre>
<p>In this function I want to have table be a variable s... | 1 | 2010-03-08T01:23:17Z | 2,398,789 | <p>You first need to make an <strong>instance</strong> of the class:</p>
<pre><code>mydata = data()
</code></pre>
<p><strong>then</strong> you can call the method -- on the <strong>instance</strong>, of course, <strong>not</strong> on the class:</p>
<pre><code>mydata.add('yes')
</code></pre>
| 8 | 2010-03-08T01:25:09Z | [
"python",
"class"
] |
Python 3.1.1 Class Question | 2,398,782 | <p>I'm a new Python programmer who is having a little trouble using 'self' in classes. For example:</p>
<pre><code>class data:
def __init__(self):
self.table = []
def add(self, file):
self.table.append(file)
data.add('yes')
</code></pre>
<p>In this function I want to have table be a variable s... | 1 | 2010-03-08T01:23:17Z | 2,398,790 | <p>You need to instantiate the class before you can call methods on it:</p>
<pre><code>mydata = Data()
mydata.add('yes')
</code></pre>
| 2 | 2010-03-08T01:25:17Z | [
"python",
"class"
] |
Python 3.1.1 Class Question | 2,398,782 | <p>I'm a new Python programmer who is having a little trouble using 'self' in classes. For example:</p>
<pre><code>class data:
def __init__(self):
self.table = []
def add(self, file):
self.table.append(file)
data.add('yes')
</code></pre>
<p>In this function I want to have table be a variable s... | 1 | 2010-03-08T01:23:17Z | 2,398,794 | <p>You are trying to call data.add() somewhat like you would call a static method in Java.
Try doing this instead:</p>
<pre><code>d = data()
d.add('yes')
</code></pre>
<p>The <code>self</code> parameter tells the method that it operates on an object of type <code>data</code>. </p>
| 1 | 2010-03-08T01:26:31Z | [
"python",
"class"
] |
Python 3.1.1 Class Question | 2,398,782 | <p>I'm a new Python programmer who is having a little trouble using 'self' in classes. For example:</p>
<pre><code>class data:
def __init__(self):
self.table = []
def add(self, file):
self.table.append(file)
data.add('yes')
</code></pre>
<p>In this function I want to have table be a variable s... | 1 | 2010-03-08T01:23:17Z | 2,398,797 | <p>you are calling the add method on the class object not an instance of the class.</p>
<p>It looks like what you want to do is:</p>
<p>classInst = data() #make an instance</p>
<p>classInst.add("stuff") #call the method</p>
<p>When add is invoked on an instance object, the instance object is passed as the self argu... | 2 | 2010-03-08T01:27:13Z | [
"python",
"class"
] |
Linking a qtDesigner .ui file to python/pyqt? | 2,398,800 | <p>So if I go into QtDesigner and build a UI, it'll be saved as a .ui file. How can I make this as a python file or use this in python?</p>
| 49 | 2010-03-08T01:27:56Z | 2,399,618 | <p>You need to generate a python file from your ui file with the pyuic tool (site-packages\pyqt4\bin)</p>
<pre><code>pyuic form1.ui > form1.py
</code></pre>
<p>with pyqt4</p>
<pre><code>pyuic4.bat form1.ui > form1.py
</code></pre>
<p>Then you can import the form1 into your script.</p>
| 22 | 2010-03-08T06:19:05Z | [
"python",
"user-interface",
"qt",
"pyqt",
"qt-designer"
] |
Linking a qtDesigner .ui file to python/pyqt? | 2,398,800 | <p>So if I go into QtDesigner and build a UI, it'll be saved as a .ui file. How can I make this as a python file or use this in python?</p>
| 49 | 2010-03-08T01:27:56Z | 2,401,814 | <p>You can convert your .ui files to an executable python file using the below command..</p>
<pre><code>pyuic4 -x form1.ui > form1.py
</code></pre>
<p>Now you can straightaway execute the python file as</p>
<pre><code>python3(whatever version) form1.py
</code></pre>
<p>You can import this file and you can use it... | 6 | 2010-03-08T14:06:50Z | [
"python",
"user-interface",
"qt",
"pyqt",
"qt-designer"
] |
Linking a qtDesigner .ui file to python/pyqt? | 2,398,800 | <p>So if I go into QtDesigner and build a UI, it'll be saved as a .ui file. How can I make this as a python file or use this in python?</p>
| 49 | 2010-03-08T01:27:56Z | 2,500,905 | <p>Another way to use .ui in your code is:</p>
<pre><code>from PyQt4 import QtCore, QtGui, uic
class MyWidget(QtGui.QWidget)
...
#somewhere in constructor:
uic.loadUi('MyWidget.ui', self)
</code></pre>
<p>both approaches are good. Do not forget, that if you use Qt resource files (extremely useful) for ico... | 44 | 2010-03-23T14:59:33Z | [
"python",
"user-interface",
"qt",
"pyqt",
"qt-designer"
] |
Linking a qtDesigner .ui file to python/pyqt? | 2,398,800 | <p>So if I go into QtDesigner and build a UI, it'll be saved as a .ui file. How can I make this as a python file or use this in python?</p>
| 49 | 2010-03-08T01:27:56Z | 9,526,625 | <p>I found this article very helpful. </p>
<p><a href="http://talk.maemo.org/archive/index.php/t-43663.html">http://talk.maemo.org/archive/index.php/t-43663.html</a></p>
<p>I'll briefly describe the actions to create and change .ui file to .py file, taken from that article.</p>
<ol>
<li>Start Qt Designer from your s... | 20 | 2012-03-02T01:05:25Z | [
"python",
"user-interface",
"qt",
"pyqt",
"qt-designer"
] |
Linking a qtDesigner .ui file to python/pyqt? | 2,398,800 | <p>So if I go into QtDesigner and build a UI, it'll be saved as a .ui file. How can I make this as a python file or use this in python?</p>
| 49 | 2010-03-08T01:27:56Z | 17,133,008 | <p>Combining <a href="http://stackoverflow.com/a/2500905/544059">Max's answer</a> and <a href="http://www.riverbankcomputing.com/pipermail/pyqt/2007-April/015902.html">Shriramana Sharma's mailing list post</a>, I built a small working example for loading a <code>mywindow.ui</code> file containing a <code>QMainWindow</c... | 21 | 2013-06-16T11:51:33Z | [
"python",
"user-interface",
"qt",
"pyqt",
"qt-designer"
] |
Linking a qtDesigner .ui file to python/pyqt? | 2,398,800 | <p>So if I go into QtDesigner and build a UI, it'll be saved as a .ui file. How can I make this as a python file or use this in python?</p>
| 49 | 2010-03-08T01:27:56Z | 21,524,726 | <p>you can compile the ui files like this</p>
<pre><code>pyuic4 -x helloworld.ui -o helloworld.py
</code></pre>
| 2 | 2014-02-03T10:22:35Z | [
"python",
"user-interface",
"qt",
"pyqt",
"qt-designer"
] |
Linking a qtDesigner .ui file to python/pyqt? | 2,398,800 | <p>So if I go into QtDesigner and build a UI, it'll be saved as a .ui file. How can I make this as a python file or use this in python?</p>
| 49 | 2010-03-08T01:27:56Z | 26,037,792 | <p>In order to compile .ui files to .py files, I did:</p>
<pre><code>python pyuic.py form1.ui > form1.py
</code></pre>
<p>Att.</p>
| 1 | 2014-09-25T11:44:56Z | [
"python",
"user-interface",
"qt",
"pyqt",
"qt-designer"
] |
Linking a qtDesigner .ui file to python/pyqt? | 2,398,800 | <p>So if I go into QtDesigner and build a UI, it'll be saved as a .ui file. How can I make this as a python file or use this in python?</p>
| 49 | 2010-03-08T01:27:56Z | 31,282,948 | <p>You can also use <code>uic</code> in PyQt5 with the following code.</p>
<pre><code>from PyQt5 import uic, QtWidgets
import sys
class Ui(QtWidgets.QDialog):
def __init__(self):
super(Ui, self).__init__()
uic.loadUi('SomeUi.ui', self)
self.show()
if __name__ == '__main__':
app = QtWi... | 3 | 2015-07-08T03:18:26Z | [
"python",
"user-interface",
"qt",
"pyqt",
"qt-designer"
] |
Linking a qtDesigner .ui file to python/pyqt? | 2,398,800 | <p>So if I go into QtDesigner and build a UI, it'll be saved as a .ui file. How can I make this as a python file or use this in python?</p>
| 49 | 2010-03-08T01:27:56Z | 37,907,101 | <p>The cleaner way in my opinion is to first export to .py as aforementioned: </p>
<pre><code>pyuic4 foo.ui > foo.py
</code></pre>
<p>And then use it inside your code (e.g <code>main.py</code>), like:</p>
<pre><code>from foo import Ui_MyWindow
class MyWindow(QtGui.QDialog):
def __init__(self):
super... | 2 | 2016-06-19T12:12:34Z | [
"python",
"user-interface",
"qt",
"pyqt",
"qt-designer"
] |
Why is my implementation of the Sieve of Atkin overlooking numbers close to the specified limit? | 2,398,894 | <p>My implementation of <a href="http://en.wikipedia.org/wiki/Sieve_of_Atkin" rel="nofollow">Sieve of Atkin</a> either overlooks primes near the limit or composites near the limit. while some limits work and others don't. I'm am completely confused as to what is wrong.</p>
<pre><code>def AtkinSieve (limit):
results = ... | 3 | 2010-03-08T02:00:54Z | 2,399,001 | <p><UL>
<LI> Change <code>lim</code> to <code>limit</code>. Of course you must have known that.
<LI>
Since <code>sieve = [False]*limit</code>,
the largest index allowed is <code>limit-1</code>.</p>
<p>However, on this line</p>
<pre><code>if (n <= limit) and (n % 12 == 1 or n % 12 == 5):
</code></pre>
<p>you are c... | 6 | 2010-03-08T02:43:56Z | [
"python",
"math",
"primes",
"sieve-of-atkin"
] |
Python + QT + Gstreamer | 2,398,958 | <p>I'm working with PyQt and trying to get video from a webcam to play within a QT widget. I've found tutorials for C and Qt, and for python and gtk, but NOTHING for this combo of pyQt and gstreamer. Anybody get this working? </p>
<p>This plays the video fine, but in a separate window:</p>
<pre><code>self.gcam = g... | 6 | 2010-03-08T02:26:26Z | 2,587,432 | <p>Got it! It appears I needed to force the resolution of the pipeline to match the resolution of the widget where I was pumping the video to:</p>
<p>self.fvidscale_cap = gst.element_factory_make("capsfilter", "fvidscale_cap")
self.fvidscale_cap.set_property('caps', gst.caps_from_string('video/x-raw-yuv, width=256, h... | 1 | 2010-04-06T18:50:19Z | [
"python",
"pyqt4",
"gstreamer",
"maemo",
"qt-maemo"
] |
Python + QT + Gstreamer | 2,398,958 | <p>I'm working with PyQt and trying to get video from a webcam to play within a QT widget. I've found tutorials for C and Qt, and for python and gtk, but NOTHING for this combo of pyQt and gstreamer. Anybody get this working? </p>
<p>This plays the video fine, but in a separate window:</p>
<pre><code>self.gcam = g... | 6 | 2010-03-08T02:26:26Z | 2,739,861 | <p>Ptterb can you post your full code please?</p>
<p>I copied your code.<br/>
Added fvidscale_cap to pipeline, with:</p>
<pre><code>self.player.add(self.source, self.scaler, self.fvidscale_cap, self.sink)
gst.element_link_many(self.source,self.scaler, self.fvidscale_cap, self.sink)
</code></pre>
<p>From the main pro... | 1 | 2010-04-29T18:39:33Z | [
"python",
"pyqt4",
"gstreamer",
"maemo",
"qt-maemo"
] |
Python + QT + Gstreamer | 2,398,958 | <p>I'm working with PyQt and trying to get video from a webcam to play within a QT widget. I've found tutorials for C and Qt, and for python and gtk, but NOTHING for this combo of pyQt and gstreamer. Anybody get this working? </p>
<p>This plays the video fine, but in a separate window:</p>
<pre><code>self.gcam = g... | 6 | 2010-03-08T02:26:26Z | 6,903,143 | <p>If you're happening to use PySide instead of PyQt on a platform other than Linux, winId() returns a PyCObject which <a href="http://www.expobrain.net/2011/02/22/handling-win32-windows-handler-in-pyside/" rel="nofollow">can't be used directly with native functions or other modules</a>. In my case this came in handy w... | 3 | 2011-08-01T19:11:02Z | [
"python",
"pyqt4",
"gstreamer",
"maemo",
"qt-maemo"
] |
Python + QT + Gstreamer | 2,398,958 | <p>I'm working with PyQt and trying to get video from a webcam to play within a QT widget. I've found tutorials for C and Qt, and for python and gtk, but NOTHING for this combo of pyQt and gstreamer. Anybody get this working? </p>
<p>This plays the video fine, but in a separate window:</p>
<pre><code>self.gcam = g... | 6 | 2010-03-08T02:26:26Z | 8,920,407 | <p>The pasted code is not showing gobject loading, which cannot be dismissed.
It took me a good while to figure out what was missing. Thanks <a href="http://ooboontoo.blogspot.com/2008/03/gstreamer-with-python-in-qt-learning-by.html" rel="nofollow">Jun</a> for having
a working audio example.</p>
<pre><code>import gobj... | 1 | 2012-01-19T02:41:45Z | [
"python",
"pyqt4",
"gstreamer",
"maemo",
"qt-maemo"
] |
Python, print delimited list | 2,399,112 | <p>Consider this Python code for printing a list of comma separated values</p>
<pre><code>for element in list:
print element + ",",
</code></pre>
<p>What is the preferred method for printing such that a comma does not appear if <code>element</code> is the final element in the list.</p>
<p>ex</p>
<pre><code>a = ... | 25 | 2010-03-08T03:25:03Z | 2,399,120 | <p>That's what <a href="http://docs.python.org/library/stdtypes.html#str.join" rel="nofollow"><code>join</code></a> is for.</p>
<pre><code>','.join([str(elem) for elem in a])
</code></pre>
| 2 | 2010-03-08T03:26:42Z | [
"python",
"string",
"printing"
] |
Python, print delimited list | 2,399,112 | <p>Consider this Python code for printing a list of comma separated values</p>
<pre><code>for element in list:
print element + ",",
</code></pre>
<p>What is the preferred method for printing such that a comma does not appear if <code>element</code> is the final element in the list.</p>
<p>ex</p>
<pre><code>a = ... | 25 | 2010-03-08T03:25:03Z | 2,399,121 | <pre><code>print ','.join(a)
</code></pre>
| 0 | 2010-03-08T03:26:42Z | [
"python",
"string",
"printing"
] |
Python, print delimited list | 2,399,112 | <p>Consider this Python code for printing a list of comma separated values</p>
<pre><code>for element in list:
print element + ",",
</code></pre>
<p>What is the preferred method for printing such that a comma does not appear if <code>element</code> is the final element in the list.</p>
<p>ex</p>
<pre><code>a = ... | 25 | 2010-03-08T03:25:03Z | 2,399,122 | <pre><code>>>> ','.join(map(str,a))
'1,2,3'
</code></pre>
| 60 | 2010-03-08T03:27:18Z | [
"python",
"string",
"printing"
] |
Python, print delimited list | 2,399,112 | <p>Consider this Python code for printing a list of comma separated values</p>
<pre><code>for element in list:
print element + ",",
</code></pre>
<p>What is the preferred method for printing such that a comma does not appear if <code>element</code> is the final element in the list.</p>
<p>ex</p>
<pre><code>a = ... | 25 | 2010-03-08T03:25:03Z | 2,399,163 | <p>A <code>','.join</code> as suggested in other answers is the typical Python solution; the normal approach, which peculiarly I don't see in any of the answers so far, is</p>
<pre><code>print ','.join(str(x) for x in a)
</code></pre>
<p>known as a generator expression or genexp.</p>
<p>If you prefer a loop (or need... | 9 | 2010-03-08T03:42:18Z | [
"python",
"string",
"printing"
] |
Python, print delimited list | 2,399,112 | <p>Consider this Python code for printing a list of comma separated values</p>
<pre><code>for element in list:
print element + ",",
</code></pre>
<p>What is the preferred method for printing such that a comma does not appear if <code>element</code> is the final element in the list.</p>
<p>ex</p>
<pre><code>a = ... | 25 | 2010-03-08T03:25:03Z | 2,399,429 | <pre><code>>>> a=[1,2,3]
>>> a=[str(i) for i in a ]
>>> s=a[0]
>>> for i in a[1:-1]: s="%s,%s"%(s,i)
...
>>> s=s+","+a[-1]
>>> s
'1,2,3'
</code></pre>
| -3 | 2010-03-08T05:15:51Z | [
"python",
"string",
"printing"
] |
Python, print delimited list | 2,399,112 | <p>Consider this Python code for printing a list of comma separated values</p>
<pre><code>for element in list:
print element + ",",
</code></pre>
<p>What is the preferred method for printing such that a comma does not appear if <code>element</code> is the final element in the list.</p>
<p>ex</p>
<pre><code>a = ... | 25 | 2010-03-08T03:25:03Z | 38,953,227 | <pre><code> def stringTokenizer(sentense,delimiters):
list=[]
word=""
isInWord=False
for ch in sentense:
if ch in delimiters:
if isInWord: # start ow word
print(word)
list.append(word)
isInWord=False
else:
... | -1 | 2016-08-15T10:15:32Z | [
"python",
"string",
"printing"
] |
Python, lazy list | 2,399,194 | <p>Is it possible to have a list be evaluated lazily in Python?</p>
<p>For example</p>
<pre><code>a = 1
list = [a]
print list
#[1]
a = 2
print list
#[1]
</code></pre>
<p>If the list was set to evaluate lazily then the final line would be [2]</p>
| 7 | 2010-03-08T03:52:09Z | 2,399,205 | <p>Python is <a href="http://www.pages.drexel.edu/~kmk592/rants/lazy-python/index.html">not really very lazy in general</a>.</p>
<p>You can use generators to emulate lazy data structures (like infinite lists, et cetera), but as far as things like using normal list syntax, et cetera, you're not going to have laziness.<... | 6 | 2010-03-08T03:55:39Z | [
"python",
"lazy-evaluation"
] |
Python, lazy list | 2,399,194 | <p>Is it possible to have a list be evaluated lazily in Python?</p>
<p>For example</p>
<pre><code>a = 1
list = [a]
print list
#[1]
a = 2
print list
#[1]
</code></pre>
<p>If the list was set to evaluate lazily then the final line would be [2]</p>
| 7 | 2010-03-08T03:52:09Z | 2,399,233 | <p>The concept of "lazy" evaluation normally comes with functional languages -- but in those you could not reassign two different values to the same identifier, so, not even there could your example be reproduced.</p>
<p>The point is not about laziness at all -- it is that using an identifier is guaranteed to be ident... | 8 | 2010-03-08T04:06:21Z | [
"python",
"lazy-evaluation"
] |
about the post_save signal and created argument | 2,399,197 | <p>the <a href="http://docs.djangoproject.com/en/dev/ref/signals/#post-save" rel="nofollow">docs</a> says:</p>
<pre><code>post_save
django.db.models.signals.post_save
created
A boolean; True if a -new- record was create.
</code></pre>
<p>and I have this:</p>
<pre><code>from django.db.models.signals import post_save... | 2 | 2010-03-08T03:52:37Z | 2,400,001 | <p>Seems like you have implemented your own User which doesn't have a unique constraint on username?</p>
| 0 | 2010-03-08T08:13:12Z | [
"python",
"django",
"django-signals"
] |
about the post_save signal and created argument | 2,399,197 | <p>the <a href="http://docs.djangoproject.com/en/dev/ref/signals/#post-save" rel="nofollow">docs</a> says:</p>
<pre><code>post_save
django.db.models.signals.post_save
created
A boolean; True if a -new- record was create.
</code></pre>
<p>and I have this:</p>
<pre><code>from django.db.models.signals import post_save... | 2 | 2010-03-08T03:52:37Z | 18,168,020 | <p>I suggest you use <code>User.objects.create_user</code> to avoid bulk operation. </p>
| 0 | 2013-08-11T01:59:57Z | [
"python",
"django",
"django-signals"
] |
replace only one variable in web.py templates | 2,399,289 | <p>I am passing variable to template in web.py and have the same condition in some places. Like this:</p>
<p>$if myvar=="string1":</p>
<pre><code>$passed argument1
</code></pre>
<p>............</p>
<p>$if myvar =="striung2":</p>
<pre><code>$passed argument2
</code></pre>
<p>If say myvar is "string1" and I pass pa... | 0 | 2010-03-08T04:30:25Z | 3,956,023 | <p>Your question is unclear. What are you trying to do? It sounds like you just need to use else:</p>
<pre><code>if myvar == "string1":
print passed
else:
# something
</code></pre>
<p>But it's very hard to understand what you are asking.</p>
| 0 | 2010-10-18T01:05:28Z | [
"python",
"templates",
"web.py"
] |
How to invoke the super constructor in Python? | 2,399,307 | <pre><code>class A:
def __init__(self):
print "world"
class B(A):
def __init__(self):
print "hello"
B()
hello
</code></pre>
<p>In all other languages I've worked with the super constructor is invoked implicitly. How does one invoke it in Python? I would expect <code>super(self)</code> but this doesn't work</... | 127 | 2010-03-08T04:35:17Z | 2,399,332 | <p><code>super()</code> returns a parent-like object <em>in new-style classes</em>:</p>
<pre><code>class A(object):
def __init__(self):
print "world"
class B(A):
def __init__(self):
print "hello"
super(B, self).__init__()
B()
</code></pre>
| 156 | 2010-03-08T04:43:13Z | [
"python",
"class",
"inheritance"
] |
How to invoke the super constructor in Python? | 2,399,307 | <pre><code>class A:
def __init__(self):
print "world"
class B(A):
def __init__(self):
print "hello"
B()
hello
</code></pre>
<p>In all other languages I've worked with the super constructor is invoked implicitly. How does one invoke it in Python? I would expect <code>super(self)</code> but this doesn't work</... | 127 | 2010-03-08T04:35:17Z | 2,399,348 | <p>With Python 2.x old-style classes it would be this:</p>
<pre><code>class A:
def __init__(self):
print "world"
class B(A):
def __init__(self):
print "hello"
A.__init__(self)
</code></pre>
| 37 | 2010-03-08T04:48:00Z | [
"python",
"class",
"inheritance"
] |
How to invoke the super constructor in Python? | 2,399,307 | <pre><code>class A:
def __init__(self):
print "world"
class B(A):
def __init__(self):
print "hello"
B()
hello
</code></pre>
<p>In all other languages I've worked with the super constructor is invoked implicitly. How does one invoke it in Python? I would expect <code>super(self)</code> but this doesn't work</... | 127 | 2010-03-08T04:35:17Z | 2,399,385 | <p>One way is to call A's constructor and pass <code>self</code> as an argument, like so:</p>
<pre><code>class B(A):
def __init__(self):
A.__init__(self)
print "hello"
</code></pre>
<p>The advantage of this style is that it's very clear. It call A's constructor. The downside is that it doesn't h... | 25 | 2010-03-08T05:01:49Z | [
"python",
"class",
"inheritance"
] |
How to invoke the super constructor in Python? | 2,399,307 | <pre><code>class A:
def __init__(self):
print "world"
class B(A):
def __init__(self):
print "hello"
B()
hello
</code></pre>
<p>In all other languages I've worked with the super constructor is invoked implicitly. How does one invoke it in Python? I would expect <code>super(self)</code> but this doesn't work</... | 127 | 2010-03-08T04:35:17Z | 33,191,175 | <p>In line with the other answers, there are multiple ways to call super class methods (including the constructor), however in Python-3.x the process has been simplified:</p>
<p><strong>Python-2.x</strong></p>
<pre><code>class A(object):
def __init__(self):
print "world"
class B(A):
def __init__(self):
print... | 17 | 2015-10-17T20:17:54Z | [
"python",
"class",
"inheritance"
] |
How to invoke the super constructor in Python? | 2,399,307 | <pre><code>class A:
def __init__(self):
print "world"
class B(A):
def __init__(self):
print "hello"
B()
hello
</code></pre>
<p>In all other languages I've worked with the super constructor is invoked implicitly. How does one invoke it in Python? I would expect <code>super(self)</code> but this doesn't work</... | 127 | 2010-03-08T04:35:17Z | 33,824,716 | <p>I use the following formula that extends previous answers:</p>
<pre><code>class A(object):
def __init__(self):
print "world"
class B(A):
def __init__(self):
print "hello"
super(self.__class__, self).__init__()
B()
</code></pre>
<p>This way you don't have to repeat the name of the class in the call to ... | 3 | 2015-11-20T10:46:46Z | [
"python",
"class",
"inheritance"
] |
Generator speed in python 3 | 2,399,308 | <p>I am going through a <a href="http://www.dabeaz.com/generators/Generators.pdf" rel="nofollow">link about generators</a> that someone posted. In the beginning he compares the two functions below. On his setup he showed a speed increase of 5% with the generator. </p>
<p>I'm running windows XP, python 3.1.1, and canno... | 7 | 2010-03-08T04:35:22Z | 2,399,413 | <p>You don't have an answer after almost a half an hour. I'm posting something that makes sense to me, not necessarily the right answer. I figure that this is better than nothing after almost half an hour:</p>
<p>The first algorithm uses a generator. A generator functions by loading the first <a href="http://en.wikipe... | 0 | 2010-03-08T05:11:55Z | [
"python",
"python-3.x"
] |
Generator speed in python 3 | 2,399,308 | <p>I am going through a <a href="http://www.dabeaz.com/generators/Generators.pdf" rel="nofollow">link about generators</a> that someone posted. In the beginning he compares the two functions below. On his setup he showed a speed increase of 5% with the generator. </p>
<p>I'm running windows XP, python 3.1.1, and canno... | 7 | 2010-03-08T04:35:22Z | 2,399,633 | <p>In David Beazley's slides that you linked to, he states that all tests were run with "Python 2.5.1 on OS X 10.4.11," and you say you're running tests with Python 3.1 on Windows XP. So, realize you're doing some apples to oranges comparison. I suspect of the two variables, the Python version matters much more.</p>
<... | 1 | 2010-03-08T06:22:36Z | [
"python",
"python-3.x"
] |
Generator speed in python 3 | 2,399,308 | <p>I am going through a <a href="http://www.dabeaz.com/generators/Generators.pdf" rel="nofollow">link about generators</a> that someone posted. In the beginning he compares the two functions below. On his setup he showed a speed increase of 5% with the generator. </p>
<p>I'm running windows XP, python 3.1.1, and canno... | 7 | 2010-03-08T04:35:22Z | 2,401,657 | <p>For what it's worth, the main purpose of the speed comparison in the presentation was to point out that using generators does not introduce a huge performance overhead. Many programmers, when first seeing generators, might start wondering about the hidden costs. For example, is there all sorts of fancy magic going... | 8 | 2010-03-08T13:44:55Z | [
"python",
"python-3.x"
] |
How to use py2exe icon_resources in wxPython application? | 2,399,424 | <p>I have a wxPython application I'm bundling into an exe using py2exe. I've defined an icon in the <code>setup.py</code> file using the following:</p>
<pre><code>setup(
windows=[
{
'script': 'myapp.py',
'icon_resources': [(1, 'myicon.ico')]
},
],
)
</code></pre>
<p>Th... | 3 | 2010-03-08T05:14:10Z | 2,399,439 | <p>I do this inside the Frame subclass</p>
<pre><code>if os.path.exists("myWxApplication.exe"):
self.SetIcon(wx.Icon("myWxApplication.exe",wx.BITMAP_TYPE_ICO))
</code></pre>
| 4 | 2010-03-08T05:18:49Z | [
"python",
"wxpython",
"icons",
"bundle",
"py2exe"
] |
Python learner needs help spotting an error | 2,399,438 | <p>This piece of code gives a syntax error at the colon of "elif process.loop(i, len(list_i) != 'repeat':" and I can't seem to figure out why.</p>
<pre><code>class process:
def loop(v1, v2):
if v1 < v2 - 1:
return 'repeat'
def isel(chr_i, list_i):
for i in range(len(list_i)):
... | 1 | 2010-03-08T05:18:35Z | 2,399,442 | <pre><code>elif process.loop(i, len(list_i) != 'repeat':
</code></pre>
<p>you forgot a closed-paren, <code>)</code>, just before the <code>!=</code>; so the would-be left-hand side of the comparison opens two parentheses but closes only one -- that's the syntax error: "unbalanced parentheses", if you will.</p>
| 2 | 2010-03-08T05:20:21Z | [
"python"
] |
Python learner needs help spotting an error | 2,399,438 | <p>This piece of code gives a syntax error at the colon of "elif process.loop(i, len(list_i) != 'repeat':" and I can't seem to figure out why.</p>
<pre><code>class process:
def loop(v1, v2):
if v1 < v2 - 1:
return 'repeat'
def isel(chr_i, list_i):
for i in range(len(list_i)):
... | 1 | 2010-03-08T05:18:35Z | 2,399,448 | <p>You're missing a parentheses!</p>
<p>Change</p>
<p><code>
elif process.loop(i, len(list_i) != 'repeat':
</code></p>
<p>to</p>
<p><code>
elif process.loop(i, len(list_i)) != 'repeat':
</code></p>
| 2 | 2010-03-08T05:21:00Z | [
"python"
] |
Cross-site json rpc : Python server side and Mozilla extension using Javascript client side | 2,399,516 | <p>I am building a Mozilla extension that contacts a Python application on a remote server to send and receive data. The Python application can be called using xml-rpc from a Python console. I am attempting to design a JSON-RPC that would contact the same application. Developing the Python server side, which can be acc... | 1 | 2010-03-08T05:44:55Z | 2,409,253 | <p>You can use <a href="http://mimic-xmlrpc.sourceforge.net/" rel="nofollow">http://mimic-xmlrpc.sourceforge.net/</a> js library, or just XMLHttpRequest. I'm just with the same problem, and i'm an absolute newby with js :(</p>
<p>mimic seems grat, even if i'm having problems parsing the data returned.. </p>
| 0 | 2010-03-09T13:21:08Z | [
"javascript",
"python",
"json",
"rpc",
"mozilla"
] |
Expressing multiple columns in berkeley db in python? | 2,399,643 | <p>Say I have a simple table that contains username, firstname, lastname.</p>
<p>How do I express this in berkeley Db?</p>
<p>I'm currently using bsddb as the interface.</p>
<p>Cheers.</p>
| 1 | 2010-03-08T06:25:34Z | 2,399,691 | <p>You have to pick one "column" as the key (must be unique; I imagine that would be "username" in your case) -- the only way searches will ever possibly happen. The other columns can be made to be the single string value of that key by any way you like, from pickling to simple joining with a character that's guarante... | 3 | 2010-03-08T06:39:20Z | [
"python",
"berkeley-db",
"bsddb"
] |
Expressing multiple columns in berkeley db in python? | 2,399,643 | <p>Say I have a simple table that contains username, firstname, lastname.</p>
<p>How do I express this in berkeley Db?</p>
<p>I'm currently using bsddb as the interface.</p>
<p>Cheers.</p>
| 1 | 2010-03-08T06:25:34Z | 32,148,388 | <p>There is several ways to do that using ordered key/value store.</p>
<p>The simplest solution is to <a href="http://stackoverflow.com/questions/21934806/store-dictionary-in-database">store documents as json values with a correct key</a>.</p>
<p>Now you probably want to build index over those columns to retrieve doc... | 0 | 2015-08-21T19:58:28Z | [
"python",
"berkeley-db",
"bsddb"
] |
Kiosk mode in wxpython? | 2,399,812 | <p>Is there a way to create a 'kiosk mode' in wxpython under Windows (98 - 7) where the application disables you from breaking out of the app using Windows keys, alt-tab, alt-f4, and ctrl+alt+delete? </p>
| 0 | 2010-03-08T07:12:34Z | 2,399,844 | <p>If an application could do that it would make a great denial-of-service attack on the machine.</p>
<p>In particular Ctrl+Alt+Delete is the <a href="http://technet.microsoft.com/en-us/library/cc780332(WS.10).aspx" rel="nofollow">Secure Attention Sequence</a>. Microsoft goes to great lengths to insure that when the ... | 1 | 2010-03-08T07:22:17Z | [
"python",
"wxpython",
"mode",
"kiosk"
] |
Kiosk mode in wxpython? | 2,399,812 | <p>Is there a way to create a 'kiosk mode' in wxpython under Windows (98 - 7) where the application disables you from breaking out of the app using Windows keys, alt-tab, alt-f4, and ctrl+alt+delete? </p>
| 0 | 2010-03-08T07:12:34Z | 2,399,853 | <p>wxPython alone cannot be done with that. </p>
<p>You need to do Low Level Keyboard Hook with C/C++ or with equivalent ctypes, for</p>
<p>Windows keys, alt-tab, alt-f4, </p>
<p>but Ctrl-Alt-Del, I don't think so for Windows XP and above.</p>
| 0 | 2010-03-08T07:24:14Z | [
"python",
"wxpython",
"mode",
"kiosk"
] |
In python, what does len(list) do? | 2,399,835 | <p>Does <code>len(list)</code> calculate the length of the list every time it is called, or does it return the value of the built-in counter?<br/>I have a context where I need to check the length of a list every time through a loop, like:</p>
<pre><code>listData = []
for value in ioread():
if len(listData)>=25:... | 11 | 2010-03-08T07:18:36Z | 2,399,839 | <pre><code>Help on built-in function len in module __builtin__:
len(...)
len(object) -> integer
Return the number of items of a sequence or mapping.
</code></pre>
<p>so yes, <code>len(list)</code> returns how many items in the list. You might want to describe in more details, providing necessary input fil... | 1 | 2010-03-08T07:20:17Z | [
"python",
"list"
] |
In python, what does len(list) do? | 2,399,835 | <p>Does <code>len(list)</code> calculate the length of the list every time it is called, or does it return the value of the built-in counter?<br/>I have a context where I need to check the length of a list every time through a loop, like:</p>
<pre><code>listData = []
for value in ioread():
if len(listData)>=25:... | 11 | 2010-03-08T07:18:36Z | 2,399,846 | <p><code>len(list)</code> returns the length of a list. If you change it, you'll have to check it's length every iteration. Or use a counter.</p>
| 0 | 2010-03-08T07:22:30Z | [
"python",
"list"
] |
In python, what does len(list) do? | 2,399,835 | <p>Does <code>len(list)</code> calculate the length of the list every time it is called, or does it return the value of the built-in counter?<br/>I have a context where I need to check the length of a list every time through a loop, like:</p>
<pre><code>listData = []
for value in ioread():
if len(listData)>=25:... | 11 | 2010-03-08T07:18:36Z | 2,399,877 | <p>len(list) returns the length of the list. Everytime you call it, it will return the length of the list as it currently is. You could set up a counter by taking the len of list initially and then adding 1 to the variable each time something is appended to the list.</p>
| 0 | 2010-03-08T07:31:10Z | [
"python",
"list"
] |
In python, what does len(list) do? | 2,399,835 | <p>Does <code>len(list)</code> calculate the length of the list every time it is called, or does it return the value of the built-in counter?<br/>I have a context where I need to check the length of a list every time through a loop, like:</p>
<pre><code>listData = []
for value in ioread():
if len(listData)>=25:... | 11 | 2010-03-08T07:18:36Z | 2,399,932 | <p>You should probably be aware, if you're worried about this operation's performance, that "lists" in Python <a href="http://bytes.com/topic/python/answers/101848-list-implementation">are really</a> dynamic arrays. That is, they're not implemented as linked lists, which you generally have to "walk" to compute a length... | 16 | 2010-03-08T07:52:14Z | [
"python",
"list"
] |
Python: getting \\u00bd correctly in editor | 2,400,088 | <p>I would like to do the following:
1) Serialize my class
2) Also manually edit the serialization dump file to remove certain objects of my class which I find unnecessary.</p>
<p>I am currently using python with simplejson. As you know, simplejson converts all characters to unicde. As a result, when I dump a particul... | 1 | 2010-03-08T08:37:52Z | 2,400,915 | <p>I don't know anything about simplejson or the Serialisation part of the question, but you asked about converting "\u00bd" to 好 in Vim. Here are some vim tips for working with unicode:</p>
<ul>
<li><p>You'll need the correct encoding set up in vim, see:</p>
<pre><code>:help 'encoding'
:help 'fileencoding'
</code... | 1 | 2010-03-08T11:30:05Z | [
"python",
"vim"
] |
Python: getting \\u00bd correctly in editor | 2,400,088 | <p>I would like to do the following:
1) Serialize my class
2) Also manually edit the serialization dump file to remove certain objects of my class which I find unnecessary.</p>
<p>I am currently using python with simplejson. As you know, simplejson converts all characters to unicde. As a result, when I dump a particul... | 1 | 2010-03-08T08:37:52Z | 2,401,864 | <p>If you want <code>json</code>/<code>simplejson</code> to produce unicode output instead of str output with Unicode escapes then you need to pass <code>ensure_ascii=False</code> to <code>dump()</code>/<code>dumps()</code>, then either encode before saving or use a file-like from <code>codecs</code>.</p>
| 0 | 2010-03-08T14:15:58Z | [
"python",
"vim"
] |
__rlshift__, __ror__ in Python | 2,400,171 | <p>I noticed that this <a href="http://code.activestate.com/recipes/384122/#">recipe</a> seems to use <code>__rlshift__</code>, <code>__ror__</code> like operators. But, they aren't in the <a href="http://docs.python.org/3.1/library/operator.html">documentation</a>! Can anyone explain these and perhaps point to some do... | 5 | 2010-03-08T08:56:29Z | 2,400,193 | <p><a href="http://docs.python.org/3.1/reference/datamodel.html?highlight=rlshift" rel="nofollow">http://docs.python.org/3.1/reference/datamodel.html?highlight=rlshift</a></p>
<p><code>__rlshift__</code> is the swapped operands version of <code>__lshift__</code>, used when the right-hand operand supports the operation... | 5 | 2010-03-08T09:01:07Z | [
"python",
"operators"
] |
Python 3.1.1 Problem With Tuples | 2,400,188 | <p>This piece of code is supposed to go through a list and preform some formatting to the items, such as removing quotations, and then saving it to another list.</p>
<pre><code>class process:
def rchr(string_i, asciivalue):
string_o = ()
for i in range(len(string_i)):
if ord(string_i[i]... | 0 | 2010-03-08T09:00:37Z | 2,400,201 | <p>I think you want <code>string_o = ""</code> instead of <code>string_o = ()</code></p>
<p>Your problem is that you want <code>string_o</code> to be a string so you can append other strings onto it. Setting it equal to <code>()</code> makes it a tuple instead, which is a data type incompatible with string.</p>
| 3 | 2010-03-08T09:02:39Z | [
"python",
"class",
"tuples"
] |
Python 3.1.1 Problem With Tuples | 2,400,188 | <p>This piece of code is supposed to go through a list and preform some formatting to the items, such as removing quotations, and then saving it to another list.</p>
<pre><code>class process:
def rchr(string_i, asciivalue):
string_o = ()
for i in range(len(string_i)):
if ord(string_i[i]... | 0 | 2010-03-08T09:00:37Z | 2,400,252 | <p>In addition to the previous answer, a more pythonic way to go would be:</p>
<pre><code>string_o = ''.join(c for c in string_i if ord(c) != asciivalue)
</code></pre>
<p>It is short and readable.</p>
| 3 | 2010-03-08T09:14:02Z | [
"python",
"class",
"tuples"
] |
Python 3.1.1 Problem With Tuples | 2,400,188 | <p>This piece of code is supposed to go through a list and preform some formatting to the items, such as removing quotations, and then saving it to another list.</p>
<pre><code>class process:
def rchr(string_i, asciivalue):
string_o = ()
for i in range(len(string_i)):
if ord(string_i[i]... | 0 | 2010-03-08T09:00:37Z | 2,400,288 | <p>To add to Olivier's answer, I think the whole code could be replaced with:</p>
<pre><code>import itertools
output = [i.replace('"','') for i in list(itertools.chain(*(x.split('\t') for x in input)))]
</code></pre>
<p>Tested with python 2.x only.</p>
| 2 | 2010-03-08T09:24:27Z | [
"python",
"class",
"tuples"
] |
How to create a timer using tkinter? | 2,400,262 | <p>I need to code a program with Python's tkinter library.</p>
<p>My major problem is that I don't know how to create a <em>timer</em> or a <em>clock</em> like
<code>hh:mm:ss</code>. </p>
<p>I need it to update itself (that's what I don't know how to do).</p>
| 37 | 2010-03-08T09:16:34Z | 2,401,181 | <p>Tkinter root windows have a method called <code>after</code> which can be used to schedule a function to be called after a given period of time. If that function itself calls <code>after</code> you've set up an automatically recurring event. </p>
<p>Here is a working example:</p>
<pre><code># for python 3.x use 't... | 60 | 2010-03-08T12:20:02Z | [
"python",
"user-interface",
"tkinter"
] |
How to create a timer using tkinter? | 2,400,262 | <p>I need to code a program with Python's tkinter library.</p>
<p>My major problem is that I don't know how to create a <em>timer</em> or a <em>clock</em> like
<code>hh:mm:ss</code>. </p>
<p>I need it to update itself (that's what I don't know how to do).</p>
| 37 | 2010-03-08T09:16:34Z | 34,022,680 | <p>Python3 clock example using the frame.after() rather than the top level application. Also shows updating the label with a StringVar()</p>
<pre><code>#!/usr/bin/env python3
# Display UTC.
# started with https://docs.python.org/3.4/library/tkinter.html#module-tkinter
import tkinter as tk
import time
def current_is... | 2 | 2015-12-01T14:21:50Z | [
"python",
"user-interface",
"tkinter"
] |
Is closing file descriptor and removing inotify watch really necessary? | 2,400,276 | <p>With python inotifyx, do I have to remove watch and close opened system file descriptor if I need them until program exit? E.g. is there some possible problems if I create one (file descriptor + watch) with each run and don't close it?</p>
| 2 | 2010-03-08T09:22:12Z | 2,400,290 | <p>The kernel stores watches as full paths, so closing the watch is preferable, it also takes unnecessary work off of VFS. As for the file descriptor, that would depend on how many others you had opened.</p>
<p>Kind of like a phone call, its nice to tell the other party that you have stopped listening, hanging up the ... | 0 | 2010-03-08T09:24:45Z | [
"python",
"linux",
"inotify"
] |
Is closing file descriptor and removing inotify watch really necessary? | 2,400,276 | <p>With python inotifyx, do I have to remove watch and close opened system file descriptor if I need them until program exit? E.g. is there some possible problems if I create one (file descriptor + watch) with each run and don't close it?</p>
| 2 | 2010-03-08T09:22:12Z | 2,400,337 | <p>It's always a good idea to release resources (e.g. free memory, close file descriptors, waitpid(2) on child processes, etc) whenever you're done using them. Being lazy and letting the operating system take care of it for you when you exit is a sure way to cause bugs in the future.</p>
| 0 | 2010-03-08T09:33:15Z | [
"python",
"linux",
"inotify"
] |
Ubuntu System Tray in Python | 2,400,432 | <p>How do I put a program in the system tray (I don't think it's called like that in Linux) in python TKINTER for UBUNTU 9.04.</p>
| 11 | 2010-03-08T09:53:47Z | 2,400,511 | <p>I don't believe you can do that using Tkinter. You will have to use the gtk libraries.</p>
<p>An example, found on a Ubuntu forum: <a href="http://ubuntuforums.org/showpost.php?s=bc369fc9343ae728577f1bdcd292caca&p=1053546&postcount=3">http://ubuntuforums.org/showpost.php?s=bc369fc9343ae728577f1bdcd292caca&a... | 7 | 2010-03-08T10:09:37Z | [
"python",
"linux",
"ubuntu",
"tkinter"
] |
Ubuntu System Tray in Python | 2,400,432 | <p>How do I put a program in the system tray (I don't think it's called like that in Linux) in python TKINTER for UBUNTU 9.04.</p>
| 11 | 2010-03-08T09:53:47Z | 2,473,520 | <p>You have to use GTK. Do note that Ubuntu 10.04+ has a new, incompatible system tray. It's called AppIndicator; there's a python example here: <a href="https://wiki.ubuntu.com/DesktopExperienceTeam/ApplicationIndicators#Python%20version" rel="nofollow">https://wiki.ubuntu.com/DesktopExperienceTeam/ApplicationIndicato... | 6 | 2010-03-18T21:42:46Z | [
"python",
"linux",
"ubuntu",
"tkinter"
] |
Ubuntu System Tray in Python | 2,400,432 | <p>How do I put a program in the system tray (I don't think it's called like that in Linux) in python TKINTER for UBUNTU 9.04.</p>
| 11 | 2010-03-08T09:53:47Z | 2,473,991 | <p>There is the <a href="http://standards.freedesktop.org/systemtray-spec/systemtray-spec-latest.html" rel="nofollow">sytem tray protocol</a>, which I believe both gnome and kde use. You might be able to use it straight from python using ctype to call X11 methods. But I would go with the GTK solution.</p>
| 3 | 2010-03-18T23:13:26Z | [
"python",
"linux",
"ubuntu",
"tkinter"
] |
How do I execute SQL_CALC_FOUND_ROWS in python MySQLDB | 2,400,492 | <pre><code>cursor.execute("SELECT SQL_CALC_FOUND_ROWS user_id FROM...limit 5")
rows = cursor.fetchall()
...
total_rows = cursor.execute("SELECT FOUND_ROWS()") #this doesn't work for some reason.
</code></pre>
<p>Edit: I tried SELECT FOUND_ROWS() FROM my_table...and the numbers are funky.</p>
| 1 | 2010-03-08T10:06:50Z | 2,400,933 | <p>Seems to work here by fetching the result for the second cursor:</p>
<pre><code>cursor.execute("SELECT SQL_CALC_FOUND_ROWS user_id FROM...limit 5")
rows = cursor.fetchall()
cursor.execute("SELECT FOUND_ROWS()")
(total_rows,) = cursor.fetchone()
</code></pre>
| 1 | 2010-03-08T11:32:44Z | [
"python",
"mysql",
"database",
"select"
] |
Easiest way to replace a string using a dictionary of replacements? | 2,400,504 | <p>Consider..</p>
<pre><code>dict = {
'СпоÑÑ':'ÐоÑÑг',
'russianA':'englishA'
}
s = 'СпоÑÑ russianA'
</code></pre>
<p>I'd like to replace all dict keys with their respective dict values in <code>s</code>.</p>
| 38 | 2010-03-08T10:08:23Z | 2,400,550 | <p>one way, without re</p>
<pre><code>d = {
'СпоÑÑ':'ÐоÑÑг',
'russianA':'englishA'
}
s = 'СпоÑÑ russianA'.split()
for n,i in enumerate(s):
if i in d:
s[n]=d[i]
print ' '.join(s)
</code></pre>
| 5 | 2010-03-08T10:16:24Z | [
"python",
"regex"
] |
Easiest way to replace a string using a dictionary of replacements? | 2,400,504 | <p>Consider..</p>
<pre><code>dict = {
'СпоÑÑ':'ÐоÑÑг',
'russianA':'englishA'
}
s = 'СпоÑÑ russianA'
</code></pre>
<p>I'd like to replace all dict keys with their respective dict values in <code>s</code>.</p>
| 38 | 2010-03-08T10:08:23Z | 2,400,564 | <p>Almost the same as ghostdog74, though independently created. One difference,
using d.get() in stead of d[] can handle items not in the dict.</p>
<pre><code>>>> d = {'a':'b', 'c':'d'}
>>> s = "a c x"
>>> foo = s.split()
>>> ret = []
>>> for item in foo:
... ret.append(d... | 3 | 2010-03-08T10:18:42Z | [
"python",
"regex"
] |
Easiest way to replace a string using a dictionary of replacements? | 2,400,504 | <p>Consider..</p>
<pre><code>dict = {
'СпоÑÑ':'ÐоÑÑг',
'russianA':'englishA'
}
s = 'СпоÑÑ russianA'
</code></pre>
<p>I'd like to replace all dict keys with their respective dict values in <code>s</code>.</p>
| 38 | 2010-03-08T10:08:23Z | 2,400,569 | <p>You could use the <a href="http://docs.python.org/2.7/library/functions.html#reduce">reduce</a> function:</p>
<pre><code>reduce(lambda x, y: x.replace(y, dict[y]), dict, s)
</code></pre>
| 13 | 2010-03-08T10:19:34Z | [
"python",
"regex"
] |
Easiest way to replace a string using a dictionary of replacements? | 2,400,504 | <p>Consider..</p>
<pre><code>dict = {
'СпоÑÑ':'ÐоÑÑг',
'russianA':'englishA'
}
s = 'СпоÑÑ russianA'
</code></pre>
<p>I'd like to replace all dict keys with their respective dict values in <code>s</code>.</p>
| 38 | 2010-03-08T10:08:23Z | 2,400,577 | <p>Using re:</p>
<pre><code>import re
s = 'СпоÑÑ not russianA'
d = {
'СпоÑÑ':'ÐоÑÑг',
'russianA':'englishA'
}
pattern = re.compile(r'\b(' + '|'.join(d.keys()) + r')\b')
result = pattern.sub(lambda x: d[x.group()], s)
# Output: 'ÐоÑÑг not englishA'
</code></pre>
<p>This will match whole words onl... | 49 | 2010-03-08T10:20:39Z | [
"python",
"regex"
] |
Easiest way to replace a string using a dictionary of replacements? | 2,400,504 | <p>Consider..</p>
<pre><code>dict = {
'СпоÑÑ':'ÐоÑÑг',
'russianA':'englishA'
}
s = 'СпоÑÑ russianA'
</code></pre>
<p>I'd like to replace all dict keys with their respective dict values in <code>s</code>.</p>
| 38 | 2010-03-08T10:08:23Z | 2,401,481 | <p>Solution <a href="http://www.daniweb.com/code/snippet216636.html#">found here</a> (I like its simplicity):</p>
<pre><code>def multipleReplace(text, wordDict):
for key in wordDict:
text = text.replace(key, wordDict[key])
return text
</code></pre>
| 8 | 2010-03-08T13:15:12Z | [
"python",
"regex"
] |
Easiest way to replace a string using a dictionary of replacements? | 2,400,504 | <p>Consider..</p>
<pre><code>dict = {
'СпоÑÑ':'ÐоÑÑг',
'russianA':'englishA'
}
s = 'СпоÑÑ russianA'
</code></pre>
<p>I'd like to replace all dict keys with their respective dict values in <code>s</code>.</p>
| 38 | 2010-03-08T10:08:23Z | 18,748,467 | <p>I used this in a similar situation (my string was all in uppercase):</p>
<pre><code>def translate(string, wdict):
for key in wdict:
string = string.replace(key, wdict[key].lower())
return string.upper()
</code></pre>
<p>hope that helps in some way... :)</p>
| 1 | 2013-09-11T18:19:09Z | [
"python",
"regex"
] |
Validating ModelChoiceField in Django forms | 2,400,548 | <p>I'm trying to validate a form containing a ModelChoiceField:</p>
<p>forms.py:</p>
<pre><code>from django import forms
from modelchoicetest.models import SomeObject
class SomeObjectAddForm(forms.ModelForm):
class Meta:
model = SomeObject
</code></pre>
<p>models.py:</p>
<pre><code>from django.db impo... | 1 | 2010-03-08T10:16:03Z | 2,401,881 | <p>It looks to me like the exception is being raised by the <code>clean</code> method of the actual <code>ModelChoiceField</code> object. Because it's a foreign key, Django is expecting an <code>int</code>, which would be representative of the <code>pk</code> for <code>SomeChoice</code>. How exactly are you passing <co... | 1 | 2010-03-08T14:18:54Z | [
"python",
"django",
"validation",
"forms"
] |
Validating ModelChoiceField in Django forms | 2,400,548 | <p>I'm trying to validate a form containing a ModelChoiceField:</p>
<p>forms.py:</p>
<pre><code>from django import forms
from modelchoicetest.models import SomeObject
class SomeObjectAddForm(forms.ModelForm):
class Meta:
model = SomeObject
</code></pre>
<p>models.py:</p>
<pre><code>from django.db impo... | 1 | 2010-03-08T10:16:03Z | 4,022,511 | <p>This is known Django bug:</p>
<p><a href="http://code.djangoproject.com/ticket/11716" rel="nofollow">http://code.djangoproject.com/ticket/11716</a></p>
<p>And while this bug is not fixed, you can only handle ValueError manually.</p>
| 0 | 2010-10-26T09:51:43Z | [
"python",
"django",
"validation",
"forms"
] |
Implementing __concat__ in Python | 2,400,561 | <p>I tried to implement <code>__concat__</code>, but it didn't work</p>
<pre><code>>>> class lHolder():
... def __init__(self,l):
... self.l=l
... def __concat__(self, l2):
... return self.l+l2
... def __iter__(self):
... return self.l.__iter__()
...
>>&g... | 1 | 2010-03-08T10:17:36Z | 2,400,599 | <p>You want to implement <code>__add__</code>, not <code>__concat__</code>. There's no <code>__concat__</code> special method in Python.</p>
| 2 | 2010-03-08T10:24:51Z | [
"python",
"operator-overloading",
"sequences"
] |
Implementing __concat__ in Python | 2,400,561 | <p>I tried to implement <code>__concat__</code>, but it didn't work</p>
<pre><code>>>> class lHolder():
... def __init__(self,l):
... self.l=l
... def __concat__(self, l2):
... return self.l+l2
... def __iter__(self):
... return self.l.__iter__()
...
>>&g... | 1 | 2010-03-08T10:17:36Z | 2,400,601 | <p><code>__concat__</code> is not a special method (http://docs.python.org/glossary.html#term-special-method). It is part of the operator module.</p>
<p>You will need to implement <code>__add__</code> to get the behaviour you want.</p>
| 5 | 2010-03-08T10:25:28Z | [
"python",
"operator-overloading",
"sequences"
] |
Best web application language for Delphi Developers | 2,400,605 | <p>I'm Delphi developer, and I would like to build few web applications, I know about Intraweb, but I think it's not a real tool for web development, maybe for just intranet applications</p>
<p>so I'm considering PHP, Python or ruby, I prefer python because it's better syntax than other( I feel it closer to Delphi), a... | 5 | 2010-03-08T10:26:18Z | 2,400,637 | <p>PHP is the best to start, but as experienced programmer you may want to look at Python, because PHP is a C style language. Python would be easier after Pascal, I think.</p>
<p>Take a look at examples:</p>
<p>On PHP: <a href="http://en.wikipedia.org/wiki/Php#Syntax" rel="nofollow">http://en.wikipedia.org/wiki/Php#S... | 2 | 2010-03-08T10:33:27Z | [
"php",
"python",
"ruby",
"delphi"
] |
Best web application language for Delphi Developers | 2,400,605 | <p>I'm Delphi developer, and I would like to build few web applications, I know about Intraweb, but I think it's not a real tool for web development, maybe for just intranet applications</p>
<p>so I'm considering PHP, Python or ruby, I prefer python because it's better syntax than other( I feel it closer to Delphi), a... | 5 | 2010-03-08T10:26:18Z | 2,400,693 | <p>If you feel like stretching your muscles, you could try out <a href="http://www.seaside.st/" rel="nofollow">Seaside</a>.</p>
<p>Seaside's a Smalltalk framework (so working with it will feel pretty much like working with Ruby) that lets you write your website just like you'd build a desktop application. You can spli... | 4 | 2010-03-08T10:43:37Z | [
"php",
"python",
"ruby",
"delphi"
] |
Best web application language for Delphi Developers | 2,400,605 | <p>I'm Delphi developer, and I would like to build few web applications, I know about Intraweb, but I think it's not a real tool for web development, maybe for just intranet applications</p>
<p>so I'm considering PHP, Python or ruby, I prefer python because it's better syntax than other( I feel it closer to Delphi), a... | 5 | 2010-03-08T10:26:18Z | 2,400,768 | <p>I agree about Intraweb, but Delphi itself is still a good language to build websites with. You could start a CGI application or an ISAPI-extesion. You could also check out <a href="http://xxm.sf.net" rel="nofollow">http://xxm.sf.net</a> , it's an open-source project I started that offers a few extra's:</p>
<ul>
<li... | 4 | 2010-03-08T10:58:08Z | [
"php",
"python",
"ruby",
"delphi"
] |
Best web application language for Delphi Developers | 2,400,605 | <p>I'm Delphi developer, and I would like to build few web applications, I know about Intraweb, but I think it's not a real tool for web development, maybe for just intranet applications</p>
<p>so I'm considering PHP, Python or ruby, I prefer python because it's better syntax than other( I feel it closer to Delphi), a... | 5 | 2010-03-08T10:26:18Z | 2,400,960 | <p>Try Morfik <a href="http://www.morfik.com/" rel="nofollow">http://www.morfik.com/</a></p>
<p>P.S.
It looked promising a few years ago, but after I digged it deeper I must admit that it's quite limited web development environment for a very basic web development.</p>
| 7 | 2010-03-08T11:37:37Z | [
"php",
"python",
"ruby",
"delphi"
] |
Best web application language for Delphi Developers | 2,400,605 | <p>I'm Delphi developer, and I would like to build few web applications, I know about Intraweb, but I think it's not a real tool for web development, maybe for just intranet applications</p>
<p>so I'm considering PHP, Python or ruby, I prefer python because it's better syntax than other( I feel it closer to Delphi), a... | 5 | 2010-03-08T10:26:18Z | 2,401,092 | <p>Actually, the answer probably is ASP.NET using C#. You'll see (ex-)Borland engineering syntax that looks quite familiar coming from Delphi. To deploy on Linux have a look at the <a href="http://www.mono-project.com/Main_Page" rel="nofollow">Mono project</a>.</p>
| 0 | 2010-03-08T12:03:59Z | [
"php",
"python",
"ruby",
"delphi"
] |
Best web application language for Delphi Developers | 2,400,605 | <p>I'm Delphi developer, and I would like to build few web applications, I know about Intraweb, but I think it's not a real tool for web development, maybe for just intranet applications</p>
<p>so I'm considering PHP, Python or ruby, I prefer python because it's better syntax than other( I feel it closer to Delphi), a... | 5 | 2010-03-08T10:26:18Z | 2,401,097 | <p>Why should an answer be different if the question was asked by a Delphi programmer, than a programmer from any other platform? Any decent language should be fun to learn, regardless of the tool you are using right now.</p>
<p>That said, I myself walked a way from Borland Pascal and Delphi (quite some time ago), ove... | 6 | 2010-03-08T12:04:42Z | [
"php",
"python",
"ruby",
"delphi"
] |
Best web application language for Delphi Developers | 2,400,605 | <p>I'm Delphi developer, and I would like to build few web applications, I know about Intraweb, but I think it's not a real tool for web development, maybe for just intranet applications</p>
<p>so I'm considering PHP, Python or ruby, I prefer python because it's better syntax than other( I feel it closer to Delphi), a... | 5 | 2010-03-08T10:26:18Z | 2,401,270 | <p>Only good answer - C# ;) Seriously ;)</p>
<p>Why? Anders Hejlsberg. He made it. It is the direct continuation of his work that started with Turbo Pascal and went over to Delphi... then Microsoft hired him and he moved from Pascal to C (core langauge) and made C#.</p>
<p>Read it up on <a href="http://en.wikipedia.o... | 2 | 2010-03-08T12:36:07Z | [
"php",
"python",
"ruby",
"delphi"
] |
Best web application language for Delphi Developers | 2,400,605 | <p>I'm Delphi developer, and I would like to build few web applications, I know about Intraweb, but I think it's not a real tool for web development, maybe for just intranet applications</p>
<p>so I'm considering PHP, Python or ruby, I prefer python because it's better syntax than other( I feel it closer to Delphi), a... | 5 | 2010-03-08T10:26:18Z | 2,401,428 | <p>I have done a fairly large (4-5 FTE) project based on webhub (www.href.com). I can certainly advise this if it is a webapp for internal use.</p>
| 0 | 2010-03-08T13:06:57Z | [
"php",
"python",
"ruby",
"delphi"
] |
Best web application language for Delphi Developers | 2,400,605 | <p>I'm Delphi developer, and I would like to build few web applications, I know about Intraweb, but I think it's not a real tool for web development, maybe for just intranet applications</p>
<p>so I'm considering PHP, Python or ruby, I prefer python because it's better syntax than other( I feel it closer to Delphi), a... | 5 | 2010-03-08T10:26:18Z | 2,401,646 | <p>PHP is a pretty simple answer. </p>
<p>One reason is there is both Delphi4PHP (the rather cryptic IDE licensed by Embarcadero which in my estimation is really only for Web Apps (not for doing whole site)s) and PHP4Delphi (the pretty awesome Delphi Component that lets you compile your Delphi code to PHP Extensions).... | 1 | 2010-03-08T13:42:38Z | [
"php",
"python",
"ruby",
"delphi"
] |
Best web application language for Delphi Developers | 2,400,605 | <p>I'm Delphi developer, and I would like to build few web applications, I know about Intraweb, but I think it's not a real tool for web development, maybe for just intranet applications</p>
<p>so I'm considering PHP, Python or ruby, I prefer python because it's better syntax than other( I feel it closer to Delphi), a... | 5 | 2010-03-08T10:26:18Z | 2,404,139 | <p>I'm a long-time Delphi developer myself and had to do some web work recently, I decided to use ASP.Net with <a href="http://www.embarcadero.com/products/delphi-prism" rel="nofollow">Delphi Prism</a> and found myself right at home since I didn't have to learn a new language, just a new framework.</p>
| 1 | 2010-03-08T19:36:41Z | [
"php",
"python",
"ruby",
"delphi"
] |
How can I interact with rather long python scripts? | 2,400,619 | <p>I love the IDLE. However, sometimes I have 100-200 line scripts and I want to sort of interactively debug/play with say, functions defined in <code>foo.py</code> instead of just calling <code>python foo.py</code>. Is there a way I can trigger IDLE in the context of my <code>foo.py</code>?</p>
| 3 | 2010-03-08T10:30:09Z | 2,400,641 | <p>Insert this line into the script:</p>
<pre><code>import pdb; pdb.set_trace()
</code></pre>
<p>Which will start the <a href="http://docs.python.org/library/pdb.html" rel="nofollow">python debugger</a> which lets you step through the script interactively, checking variables and such as you go. </p>
| 5 | 2010-03-08T10:33:57Z | [
"python",
"python-idle"
] |
How can I interact with rather long python scripts? | 2,400,619 | <p>I love the IDLE. However, sometimes I have 100-200 line scripts and I want to sort of interactively debug/play with say, functions defined in <code>foo.py</code> instead of just calling <code>python foo.py</code>. Is there a way I can trigger IDLE in the context of my <code>foo.py</code>?</p>
| 3 | 2010-03-08T10:30:09Z | 2,400,666 | <p>I assume you are asking about how to enable debugging in Idle?</p>
<p>In the <code>Python Shell</code> window, choose <em>Debugger</em> from the <em>Debug</em> menu, then open <code>foo.py</code> and use the <em>Run Model</em> command. A <em>Debug Control</em> window opens, allowing you to step through the executio... | 1 | 2010-03-08T10:38:22Z | [
"python",
"python-idle"
] |
Is there a memory efficient and fast way to load big json files in python? | 2,400,643 | <p>I have some json files with 500MB.
If I use the "trivial" json.load to load its content all at once, it will consume a lot of memory. </p>
<p>Is there a way to read partially the file? If it was a text, line delimited file, I would be able to iterate over the lines. I am looking for analogy to it.</p>
<p>Any sugg... | 33 | 2010-03-08T10:34:15Z | 2,400,780 | <p>Short answer: no.</p>
<p>Properly dividing a json file would take intimate knowledge of the json object graph to get right.</p>
<p>However, if you have this knowledge, then you could implement a file-like object that wraps the json file and spits out proper chunks.</p>
<p>For instance, if you know that your json ... | 2 | 2010-03-08T11:01:05Z | [
"python",
"json",
"large-files"
] |
Is there a memory efficient and fast way to load big json files in python? | 2,400,643 | <p>I have some json files with 500MB.
If I use the "trivial" json.load to load its content all at once, it will consume a lot of memory. </p>
<p>Is there a way to read partially the file? If it was a text, line delimited file, I would be able to iterate over the lines. I am looking for analogy to it.</p>
<p>Any sugg... | 33 | 2010-03-08T10:34:15Z | 2,402,371 | <p>On your mention of running out of memory I must question if you're actually managing memory. Are you using the "del" keyword to remove your old object before trying to read a new one? Python should never silently retain something in memory if you remove it. </p>
| 2 | 2010-03-08T15:27:01Z | [
"python",
"json",
"large-files"
] |
Is there a memory efficient and fast way to load big json files in python? | 2,400,643 | <p>I have some json files with 500MB.
If I use the "trivial" json.load to load its content all at once, it will consume a lot of memory. </p>
<p>Is there a way to read partially the file? If it was a text, line delimited file, I would be able to iterate over the lines. I am looking for analogy to it.</p>
<p>Any sugg... | 33 | 2010-03-08T10:34:15Z | 2,402,407 | <p>in addition to @codeape</p>
<p>I would try writing a custom json parser to help you figure out the structure of the JSON blob you are dealing with. Print out the key names only, etc. Make a hierarchical tree and decide (yourself) how you can chunk it. This way you can do what @codeape suggests - break the file up i... | 1 | 2010-03-08T15:31:44Z | [
"python",
"json",
"large-files"
] |
Is there a memory efficient and fast way to load big json files in python? | 2,400,643 | <p>I have some json files with 500MB.
If I use the "trivial" json.load to load its content all at once, it will consume a lot of memory. </p>
<p>Is there a way to read partially the file? If it was a text, line delimited file, I would be able to iterate over the lines. I am looking for analogy to it.</p>
<p>Any sugg... | 33 | 2010-03-08T10:34:15Z | 2,402,417 | <p>So the problem is not that each file is too big, but that there are too many of them, and they seem to be adding up in memory. Python's garbage collector should be fine, unless you are keeping around references you don't need. It's hard to tell exactly what's happening without any further information, but some thi... | 10 | 2010-03-08T15:33:47Z | [
"python",
"json",
"large-files"
] |
Is there a memory efficient and fast way to load big json files in python? | 2,400,643 | <p>I have some json files with 500MB.
If I use the "trivial" json.load to load its content all at once, it will consume a lot of memory. </p>
<p>Is there a way to read partially the file? If it was a text, line delimited file, I would be able to iterate over the lines. I am looking for analogy to it.</p>
<p>Any sugg... | 33 | 2010-03-08T10:34:15Z | 2,402,423 | <p>Another idea is to try load it into a document-store database like MongoDB.
It deals with large blobs of JSON well. Although you might run into the same problem loading the JSON - avoid the problem by loading the files one at a time.</p>
<p>If path works for you, then you can interact with the JSON data via their ... | 2 | 2010-03-08T15:34:28Z | [
"python",
"json",
"large-files"
] |
Is there a memory efficient and fast way to load big json files in python? | 2,400,643 | <p>I have some json files with 500MB.
If I use the "trivial" json.load to load its content all at once, it will consume a lot of memory. </p>
<p>Is there a way to read partially the file? If it was a text, line delimited file, I would be able to iterate over the lines. I am looking for analogy to it.</p>
<p>Any sugg... | 33 | 2010-03-08T10:34:15Z | 2,406,386 | <p>"the garbage collector should free the memory" </p>
<p>Correct.</p>
<p>Since it doesn't, something else is wrong. Generally, the problem with infinite memory growth is global variables.</p>
<p>Remove all global variables.</p>
<p>Make all module-level code into smaller functions.</p>
| 0 | 2010-03-09T03:10:51Z | [
"python",
"json",
"large-files"
] |
Is there a memory efficient and fast way to load big json files in python? | 2,400,643 | <p>I have some json files with 500MB.
If I use the "trivial" json.load to load its content all at once, it will consume a lot of memory. </p>
<p>Is there a way to read partially the file? If it was a text, line delimited file, I would be able to iterate over the lines. I am looking for analogy to it.</p>
<p>Any sugg... | 33 | 2010-03-08T10:34:15Z | 17,326,199 | <p>There was a duplicate to this question that had a better answer. See <a href="http://stackoverflow.com/a/10382359/1623645">http://stackoverflow.com/a/10382359/1623645</a>, which suggests <a href="https://pypi.python.org/pypi/ijson/">ijson</a>.</p>
<p><strong>Update:</strong></p>
<p>I tried it out, and ijson is to... | 34 | 2013-06-26T17:01:03Z | [
"python",
"json",
"large-files"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.