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
Understanding while loop
1,999,026
<p>I am a newbie in Python. I can understand what a for loop does, but can't really understand what a while loop does. I knew it does repeat something while the condition is true, easy to say, but it's really hard to use it as far as I think.</p> <p>Say, an example here:</p> <pre><code>while 1: rate(100) #what doe...
0
2010-01-04T11:42:30Z
1,999,194
<p>The example code you have provided is equivalent to this:</p> <pre><code>while True: rate(100) #what does this rate(100) do? try: 'something' except: 'something else' </code></pre> <p>In Python many expressions can be tested for truth (that is evaluate to <code>True</code> or <code>Fals...
3
2010-01-04T12:16:11Z
[ "python", "while-loop" ]
Create single python executable module
1,999,129
<p>Guys, I have much python code in modules which are resides in several python packages and now I need to create single python executable module or file which will include all these files, so it will be working on windows and on linux servers. What are possible solutions and how this can be done?</p>
6
2010-01-04T12:02:23Z
1,999,142
<p>Maybe <a href="http://www.py2exe.org/" rel="nofollow">py2exe</a> can help you ..</p> <blockquote> <p>py2exe is a Python Distutils extension which converts Python scripts into executable Windows programs, able to run without requiring a Python installation.</p> </blockquote> <p>Tutorial > <a href="http://www.py2e...
2
2010-01-04T12:04:58Z
[ "python", "linux", "winapi", "executable" ]
Create single python executable module
1,999,129
<p>Guys, I have much python code in modules which are resides in several python packages and now I need to create single python executable module or file which will include all these files, so it will be working on windows and on linux servers. What are possible solutions and how this can be done?</p>
6
2010-01-04T12:02:23Z
1,999,148
<p>That's what egg files are for. Read this: <a href="http://stackoverflow.com/questions/47953/what-are-the-advantages-of-packaging-your-python-library-application-as-an-egg-f">http://stackoverflow.com/questions/47953/what-are-the-advantages-of-packaging-your-python-library-application-as-an-egg-f</a></p>
3
2010-01-04T12:06:38Z
[ "python", "linux", "winapi", "executable" ]
Create single python executable module
1,999,129
<p>Guys, I have much python code in modules which are resides in several python packages and now I need to create single python executable module or file which will include all these files, so it will be working on windows and on linux servers. What are possible solutions and how this can be done?</p>
6
2010-01-04T12:02:23Z
1,999,402
<p>For windows use <a href="http://www.py2exe.org/">py2exe</a> , for linux use <a href="http://www.pyinstaller.org/">pyinstaller</a> and for Mac use <a href="http://svn.pythonmac.org/py2app/py2app/trunk/doc/index.html">py2app</a></p> <p>Using these tools you can have a <code>setup.py</code> which based on os will buil...
10
2010-01-04T13:02:00Z
[ "python", "linux", "winapi", "executable" ]
Create single python executable module
1,999,129
<p>Guys, I have much python code in modules which are resides in several python packages and now I need to create single python executable module or file which will include all these files, so it will be working on windows and on linux servers. What are possible solutions and how this can be done?</p>
6
2010-01-04T12:02:23Z
33,851,952
<p>You can <a href="http://kivy.org/" rel="nofollow">kivy</a> for python cross plat form application .</p> <blockquote> <p>Kivy - Open source Python library for rapid development of applications that make use of innovative user interfaces, such as multi-touch apps</p> </blockquote>
1
2015-11-22T05:32:24Z
[ "python", "linux", "winapi", "executable" ]
Calling a variable from another function Python
1,999,144
<p>I am trying to call a variable for use in another function. The variable is only in the other function and not declared as a global variable. Does anyone know how to call the other variable. The code below shows the 'retval' variable being used but it is declared in the other function.</p> <pre><code>def email_resu...
-6
2010-01-04T12:05:33Z
1,999,165
<p>Your <code>make.retval</code> is (I'm guessing from your vague question) the result of another function, <code>make</code>, which for some reason doesn't return <code>retval</code>.</p> <p>Do this</p> <pre><code>def make( ): etc. return retval def email_results( retval ): etc. if __name__ == "__main...
7
2010-01-04T12:10:37Z
[ "python" ]
Calling a variable from another function Python
1,999,144
<p>I am trying to call a variable for use in another function. The variable is only in the other function and not declared as a global variable. Does anyone know how to call the other variable. The code below shows the 'retval' variable being used but it is declared in the other function.</p> <pre><code>def email_resu...
-6
2010-01-04T12:05:33Z
1,999,238
<p>It should be make() not make.retval; the first is a function call, the second is an object member (sometimes called an attribute) reference. Since you defined make as a function, it is callable but does not have a member called retval.</p>
1
2010-01-04T12:24:18Z
[ "python" ]
How do I add content before </body> in extended page? (KID templates)
1,999,300
<p>I've got master.kid (simplified):</p> <pre><code>&lt;html&gt; &lt;head py:match="item.tag == 'head'"&gt; &lt;title&gt;My Site&lt;/title&gt; &lt;/head&gt; &lt;body py:match="item.tag == 'body'"&gt; &lt;h1&gt;My Site&lt;/h1&gt; &lt;div py:replace="item[:]"&gt;&lt;/div&gt; &lt;p id="footer"&gt;Copyright Blixt ...
1
2010-01-04T12:37:12Z
2,044,804
<p>The best solution I've found is the following:</p> <p>master.kid:</p> <pre><code>&lt;html&gt; &lt;head py:match="item.tag == 'head'"&gt; &lt;title&gt;My Site&lt;/title&gt; &lt;/head&gt; &lt;body py:match="item.tag == 'body'"&gt; &lt;h1&gt;My Site&lt;/h1&gt; &lt;div py:replace="item[:]"&gt;&lt;/div&gt; &lt;...
1
2010-01-11T20:47:22Z
[ "python", "turbogears" ]
How to move my cursor to the last record in MySQL using Python?
1,999,412
<p>I'm using MySQLdb library to connect to MySQL within my Python script.</p> <p>(Ref: <a href="http://mysql-python.sourceforge.net/MySQLdb.html" rel="nofollow">http://mysql-python.sourceforge.net/MySQLdb.html</a> ).</p> <p>I would like to learn if there is a way to jump to the last record in a resultset using Python...
1
2010-01-04T13:03:12Z
1,999,492
<p>Well, your question is weird. Why would you want to do that?</p> <p>You could keep reading records from the cursor until it is the last. But you'd have to try reading past it to know it is the last one, you can't know before reading it.</p> <p>Another idea is to make a reversed query. Use <code>ORDER BY</code> to ...
1
2010-01-04T13:20:20Z
[ "python", "mysql" ]
How to move my cursor to the last record in MySQL using Python?
1,999,412
<p>I'm using MySQLdb library to connect to MySQL within my Python script.</p> <p>(Ref: <a href="http://mysql-python.sourceforge.net/MySQLdb.html" rel="nofollow">http://mysql-python.sourceforge.net/MySQLdb.html</a> ).</p> <p>I would like to learn if there is a way to jump to the last record in a resultset using Python...
1
2010-01-04T13:03:12Z
9,919,388
<p>If you feel the query is not too hard on the db, and there is enough memory on the machine, you could store the result set in a list, and just grab the last object from the list:</p> <pre><code>import MySQLdb conn = MySQLdb.connect(host='',user='',passwd='') curs = conn.cursor() curs.execute('show databases') # or ...
0
2012-03-29T05:09:09Z
[ "python", "mysql" ]
Creating equivalent classes in Python?
1,999,551
<p>I played around with overloading or masking classes in Python. Do the following code examples create equivalent classes? </p> <pre><code>class CustASample(object): def __init__(self): self.__class__.__name__ = "Sample" def doSomething(self): dummy = 1 </code></pre> <p>and </p> <pre><code>...
3
2010-01-04T13:30:43Z
1,999,575
<p>No, they are still different.</p> <pre><code>a = CustASample() b = Sample() a.__class__ is b.__class__ -&gt; False </code></pre> <p>Here's how you could do it:</p> <pre><code>class A(object): def __init__(self): self.__class__ = B class B(object): def bark(self): print "Wuff!" a = A() b =...
10
2010-01-04T13:36:47Z
[ "python" ]
Creating equivalent classes in Python?
1,999,551
<p>I played around with overloading or masking classes in Python. Do the following code examples create equivalent classes? </p> <pre><code>class CustASample(object): def __init__(self): self.__class__.__name__ = "Sample" def doSomething(self): dummy = 1 </code></pre> <p>and </p> <pre><code>...
3
2010-01-04T13:30:43Z
2,000,774
<p>Classes also, not only instances, are objects. For example, you can get id(Sample). Try it and see that these two numbers differ, as differ the classes' memory locations. They are not the same object. It's like asking whether <code>[] is []</code>.</p> <p>EDIT: Too late and the explanation by gs is better.</p>
0
2010-01-04T17:03:33Z
[ "python" ]
media conversion library
1,999,641
<p>I am building a mobile website were users can upload/download videos, and I need a library that can convert the media files from mpeg, 3gp, mov depending on what the user wants to download.</p> <p>Do you happen to know a a library that can do this?</p>
0
2010-01-04T13:50:35Z
1,999,657
<p><a href="http://sourceforge.net/projects/ffdshow/" rel="nofollow">ffdshow</a> is a great lib for that. </p> <p><a href="http://www.afterdawn.com/glossary/terms/libavcodec.cfm" rel="nofollow">libavcodec</a> to be more precise.</p>
1
2010-01-04T13:53:43Z
[ "java", ".net", "php", "python", "ruby" ]
media conversion library
1,999,641
<p>I am building a mobile website were users can upload/download videos, and I need a library that can convert the media files from mpeg, 3gp, mov depending on what the user wants to download.</p> <p>Do you happen to know a a library that can do this?</p>
0
2010-01-04T13:50:35Z
1,999,677
<p>You should not <strong>only</strong> search for Library to do this, if you are using linux you can find an <strong>application</strong> that do this for you with <strong>CLI</strong> support,then using that application cli you can change your format;</p> <pre><code>$result=shell_exec('application_name [parameters] ...
2
2010-01-04T13:56:39Z
[ "java", ".net", "php", "python", "ruby" ]
media conversion library
1,999,641
<p>I am building a mobile website were users can upload/download videos, and I need a library that can convert the media files from mpeg, 3gp, mov depending on what the user wants to download.</p> <p>Do you happen to know a a library that can do this?</p>
0
2010-01-04T13:50:35Z
1,999,684
<p>Take a look at <a href="http://ffmpeg.org/" rel="nofollow">FFmpeg</a>. You could use as a command line tool.</p>
-1
2010-01-04T13:57:57Z
[ "java", ".net", "php", "python", "ruby" ]
media conversion library
1,999,641
<p>I am building a mobile website were users can upload/download videos, and I need a library that can convert the media files from mpeg, 3gp, mov depending on what the user wants to download.</p> <p>Do you happen to know a a library that can do this?</p>
0
2010-01-04T13:50:35Z
2,000,123
<p>Use <a href="http://github.com/polly/ffmpeg/" rel="nofollow">FFmpeg</a> gem in Ruby, it's really cool and easy to use.</p>
1
2010-01-04T15:13:30Z
[ "java", ".net", "php", "python", "ruby" ]
media conversion library
1,999,641
<p>I am building a mobile website were users can upload/download videos, and I need a library that can convert the media files from mpeg, 3gp, mov depending on what the user wants to download.</p> <p>Do you happen to know a a library that can do this?</p>
0
2010-01-04T13:50:35Z
2,008,227
<p>In the past, I ran <a href="http://www.videolan.org/" rel="nofollow">VLC</a> from the command-line and used it to do my conversions (it's free, supports nearly all audio and video formats, and works on many different platforms). If you have VLC installed on the server, you can access it this way using any language ...
-1
2010-01-05T18:35:30Z
[ "java", ".net", "php", "python", "ruby" ]
media conversion library
1,999,641
<p>I am building a mobile website were users can upload/download videos, and I need a library that can convert the media files from mpeg, 3gp, mov depending on what the user wants to download.</p> <p>Do you happen to know a a library that can do this?</p>
0
2010-01-04T13:50:35Z
2,039,812
<p>Or if you want something to use directly from Java, try <a href="http://www.xuggle.com/xuggler" rel="nofollow">Xuggler</a>, a Java-based interface to <a href="http://ffmpeg.org/" rel="nofollow">FFmpeg</a>.</p>
0
2010-01-11T03:52:20Z
[ "java", ".net", "php", "python", "ruby" ]
Find the type of an attribute in a class
1,999,727
<p>I want determine the type of an attribute in a class. I am using <code>setattr</code> to set the value, and I would like to check the type that is expected, so that I can properly convert a string value before calling <code>setattr</code>.</p> <p>How do you do this in python?</p> <p>EDIT 1- Some additional inform...
0
2010-01-04T14:09:04Z
1,999,738
<p>Check a.<code>__class__</code> , or maybe isinstance(obj, class) if you want to check if the type is as expected.</p> <pre><code>&gt;&gt;&gt; a = 1 &gt;&gt;&gt; a.__class__ &lt;type 'int'&gt; &gt;&gt;&gt; isinstance(a, int) True </code></pre> <p>more to the point for you is probably:</p> <pre><code>&gt;&gt;&gt; b...
0
2010-01-04T14:11:11Z
[ "python", "google-app-engine" ]
Find the type of an attribute in a class
1,999,727
<p>I want determine the type of an attribute in a class. I am using <code>setattr</code> to set the value, and I would like to check the type that is expected, so that I can properly convert a string value before calling <code>setattr</code>.</p> <p>How do you do this in python?</p> <p>EDIT 1- Some additional inform...
0
2010-01-04T14:09:04Z
1,999,751
<p>you can use <code>type(a.v)</code> to check it, but if it doesn't have a default value, it could as well be None or undefined.</p> <pre><code>&gt;&gt; class A: &gt;&gt; v=10 &gt;&gt; u=None &gt;&gt; a=A() &gt;&gt; print type(a.v) &lt;type 'int'&gt; &gt;&gt; print type(a.u) &lt;type 'NoneType'&gt; &gt;&gt; pri...
0
2010-01-04T14:14:16Z
[ "python", "google-app-engine" ]
Find the type of an attribute in a class
1,999,727
<p>I want determine the type of an attribute in a class. I am using <code>setattr</code> to set the value, and I would like to check the type that is expected, so that I can properly convert a string value before calling <code>setattr</code>.</p> <p>How do you do this in python?</p> <p>EDIT 1- Some additional inform...
0
2010-01-04T14:09:04Z
2,000,143
<p>Since python does not do type checking in this case you have to implement this feature by hand (or use existing libraries; see Alex Martellis answer).</p> <p>One approach: Check if the value is an instance of the desired type, via <code>isinstance</code>.</p> <p>Here is a modified version of your code, I'd start w...
0
2010-01-04T15:18:49Z
[ "python", "google-app-engine" ]
Find the type of an attribute in a class
1,999,727
<p>I want determine the type of an attribute in a class. I am using <code>setattr</code> to set the value, and I would like to check the type that is expected, so that I can properly convert a string value before calling <code>setattr</code>.</p> <p>How do you do this in python?</p> <p>EDIT 1- Some additional inform...
0
2010-01-04T14:09:04Z
2,000,227
<p>You seem to misunderstand how Python (the language) is designed. Attributes have no a-priori type (the language is dynamically typed), and therefore it makes, most of the time, little sense to try to coerce attributes explicitly when setting them.</p>
1
2010-01-04T15:34:46Z
[ "python", "google-app-engine" ]
Find the type of an attribute in a class
1,999,727
<p>I want determine the type of an attribute in a class. I am using <code>setattr</code> to set the value, and I would like to check the type that is expected, so that I can properly convert a string value before calling <code>setattr</code>.</p> <p>How do you do this in python?</p> <p>EDIT 1- Some additional inform...
0
2010-01-04T14:09:04Z
2,000,241
<p>Normally, a Python class (or instance thereof) carries no information regarding what types it "expects" any given attribute to have, because it has no such "expectation".</p> <p>When you need to encode such metadata, rather than "rolling your own", you can use existing third party extensions like Enthought's <a hre...
0
2010-01-04T15:36:38Z
[ "python", "google-app-engine" ]
Find the type of an attribute in a class
1,999,727
<p>I want determine the type of an attribute in a class. I am using <code>setattr</code> to set the value, and I would like to check the type that is expected, so that I can properly convert a string value before calling <code>setattr</code>.</p> <p>How do you do this in python?</p> <p>EDIT 1- Some additional inform...
0
2010-01-04T14:09:04Z
2,000,683
<p>Since explicit type-checking is so un-pythonic, consider just wrapping the value in <code>int()</code>. Then, if the value (whatever it is) can be coerced into an <code>int</code>, it will be. If it cannot be coerced into an <code>int</code>, then you need to throw an error anyway (which it will do automatically)....
0
2010-01-04T16:47:59Z
[ "python", "google-app-engine" ]
Find the type of an attribute in a class
1,999,727
<p>I want determine the type of an attribute in a class. I am using <code>setattr</code> to set the value, and I would like to check the type that is expected, so that I can properly convert a string value before calling <code>setattr</code>.</p> <p>How do you do this in python?</p> <p>EDIT 1- Some additional inform...
0
2010-01-04T14:09:04Z
2,000,783
<p>In AppEngine, each model has a <code>properties()</code> class method, which returns the dict of properties you declared in your model. You can use it to check the types your model expects for each attribute:</p> <pre><code>def populate_object_properties(values_as_strings, object_to_...
6
2010-01-04T17:05:24Z
[ "python", "google-app-engine" ]
How to print context content in the template?
1,999,811
<p>How can I print or iterate over all the variables available in the context from the template code?</p> <p>I know about <code>{% debug %}</code> but it contains too much information. I'd just like to print variable names available in the current context.</p> <p>Is there a way to do this without writing custom tag?<...
3
2010-01-04T14:22:58Z
1,999,998
<p>Use the <a href="https://github.com/django-debug-toolbar/django-debug-toolbar" rel="nofollow">Django debug toolbar</a> - gives you this on the Templates tab, along a whole range of other useful debugging information.</p>
7
2010-01-04T14:53:08Z
[ "python", "django" ]
How to print context content in the template?
1,999,811
<p>How can I print or iterate over all the variables available in the context from the template code?</p> <p>I know about <code>{% debug %}</code> but it contains too much information. I'd just like to print variable names available in the current context.</p> <p>Is there a way to do this without writing custom tag?<...
3
2010-01-04T14:22:58Z
23,781,108
<p>If you use class-based views you can just give the current context like a variable to context:</p> <pre><code>class MainView(TemplateView): template_name = 'base.html' def get_context_data(self, **kwargs): ctx = super(MainView, self).get_context_data(**kwargs) ctx['ctx'] = ctx retur...
1
2014-05-21T10:52:03Z
[ "python", "django" ]
"download link " fails in IE
1,999,950
<p>I was trying to implement a "download link" and put it beside one of my report table so that users can download a csv file and open it with applications like Excel.</p> <p>The records are generated dynamically based on the query made by users.</p> <p>So somewhere in my controller there's something like:</p> <pre>...
6
2010-01-04T14:45:18Z
2,000,015
<p>This doesn't answer your question, but solves, I hope, original problem.</p> <p>I would just add timestamp (something unique enough) to query string of link to CSV file. It helped for me.</p>
0
2010-01-04T14:56:07Z
[ "python", "internet-explorer", "web2py" ]
"download link " fails in IE
1,999,950
<p>I was trying to implement a "download link" and put it beside one of my report table so that users can download a csv file and open it with applications like Excel.</p> <p>The records are generated dynamically based on the query made by users.</p> <p>So somewhere in my controller there's something like:</p> <pre>...
6
2010-01-04T14:45:18Z
2,000,069
<p>Is the download link using https (ssl)? If so, then IE can't handle the downloading if it's set to be cached. This is a known problem with IE.</p>
2
2010-01-04T15:04:32Z
[ "python", "internet-explorer", "web2py" ]
"download link " fails in IE
1,999,950
<p>I was trying to implement a "download link" and put it beside one of my report table so that users can download a csv file and open it with applications like Excel.</p> <p>The records are generated dynamically based on the query made by users.</p> <p>So somewhere in my controller there's something like:</p> <pre>...
6
2010-01-04T14:45:18Z
2,000,104
<p>I'm not sure what Cache control headers are/were being sent but IE has a bug with downloaded files like you are experiencing.</p> <p><strong>For IE, you MUST enable caching</strong>. When IE loads files (e.g. Excel files), in Excel, it loads them from the cache directory, thus if you don't cache it, Excel (or your...
5
2010-01-04T15:10:03Z
[ "python", "internet-explorer", "web2py" ]
Python string splitting
2,000,202
<p>If I have a string <code>'x=10'</code>, how can I extract the 10 as an integer using one line of code?</p>
0
2010-01-04T15:29:52Z
2,000,212
<p>Check this one:</p> <pre><code>answer = int("x=10".partition("=")[2]) </code></pre>
0
2010-01-04T15:32:26Z
[ "python", "string", "split" ]
Python string splitting
2,000,202
<p>If I have a string <code>'x=10'</code>, how can I extract the 10 as an integer using one line of code?</p>
0
2010-01-04T15:29:52Z
2,000,213
<pre><code>&gt;&gt;&gt; s = "x=10" &gt;&gt;&gt; int(s.split('=')[-1]) 10 </code></pre>
7
2010-01-04T15:32:37Z
[ "python", "string", "split" ]
Python string splitting
2,000,202
<p>If I have a string <code>'x=10'</code>, how can I extract the 10 as an integer using one line of code?</p>
0
2010-01-04T15:29:52Z
2,000,217
<pre><code>s = 'x=10' i = int(s[2:]) </code></pre>
3
2010-01-04T15:33:19Z
[ "python", "string", "split" ]
Python string splitting
2,000,202
<p>If I have a string <code>'x=10'</code>, how can I extract the 10 as an integer using one line of code?</p>
0
2010-01-04T15:29:52Z
2,000,222
<p>Sure:</p> <pre><code>a = "x=10" b = int(a.split('=')[1]) </code></pre>
4
2010-01-04T15:33:51Z
[ "python", "string", "split" ]
Python string splitting
2,000,202
<p>If I have a string <code>'x=10'</code>, how can I extract the 10 as an integer using one line of code?</p>
0
2010-01-04T15:29:52Z
2,000,251
<pre><code>result = int(my_string.rpartition("=")[-1]) </code></pre> <p>Note, however, that if there is anything else after the <code>=</code> sign the function will break.</p> <p>So <code>x=10</code>, <code>x=560</code>, and <code>x=1010001003010</code> will all work. However, <code>y=1,341</code> will break with a...
3
2010-01-04T15:38:34Z
[ "python", "string", "split" ]
is there a way to append the etag at the end of the static resources in django
2,000,306
<p>if I import a css file or javascript file, the url will be like this</p> <pre><code>&lt;script type="text/javascript" src="some.js?&lt;ETag here&gt;"&gt;&lt;/script&gt; </code></pre> <p>if I upgrade the some.js the etag will be changed, so my browser can cache the static resource smartly and update the cache when ...
1
2010-01-04T15:45:59Z
2,000,326
<p>Maybe <a href="http://github.com/peterbe/django-static" rel="nofollow">django-static</a> can help you on this ..</p> <blockquote> <p><code>django_static</code> is a Django app that enables as various template tags for better serving your static content. It basically rewrites references to static files and where a...
1
2010-01-04T15:51:10Z
[ "python", "django" ]
is there a way to append the etag at the end of the static resources in django
2,000,306
<p>if I import a css file or javascript file, the url will be like this</p> <pre><code>&lt;script type="text/javascript" src="some.js?&lt;ETag here&gt;"&gt;&lt;/script&gt; </code></pre> <p>if I upgrade the some.js the etag will be changed, so my browser can cache the static resource smartly and update the cache when ...
1
2010-01-04T15:45:59Z
2,000,934
<p>Besides django-static mentioned by The MYYN, these projects will do what you need and also contain other highly useful features like compression and concatenation:</p> <p><a href="http://github.com/pelme/django-compress" rel="nofollow">django-compress</a></p> <p><a href="http://github.com/mintchaos/django_compress...
0
2010-01-04T17:34:11Z
[ "python", "django" ]
Problem allocating heap space over 4 GB when calling java "from Python"
2,000,331
<p>I am using using os.system call from python to run jar file. The jar file requires large heap space and thus i am allocating 4 Gb heap space using Xmx. When i execute the command "java -Xms4096m -Xmx4096m -jar camXnet.jar net.txt" from command line it executes properly, however when i call it from a python program...
1
2010-01-04T15:52:28Z
2,000,424
<p>It's hard to be sure without knowing more detail - like which OS you're on - but my guess is that you're using a 32-bit version of Python which means that when you launch Java, you're also getting the 32-bit version which has a heap size limit of 4GB.</p> <p>To test if this is the case, compare the output of <code>...
2
2010-01-04T16:05:01Z
[ "java", "python", "ram" ]
Problem allocating heap space over 4 GB when calling java "from Python"
2,000,331
<p>I am using using os.system call from python to run jar file. The jar file requires large heap space and thus i am allocating 4 Gb heap space using Xmx. When i execute the command "java -Xms4096m -Xmx4096m -jar camXnet.jar net.txt" from command line it executes properly, however when i call it from a python program...
1
2010-01-04T15:52:28Z
2,000,528
<p>Just a suggestion, but try using <a href="http://docs.python.org/library/subprocess#subprocess.call" rel="nofollow">subprocess.call()</a> instead of os.system(), <a href="http://docs.python.org/library/os.html#os.system" rel="nofollow">it is preferred</a> and may handle the issue you are experiencing. I'm curious to...
0
2010-01-04T16:21:39Z
[ "java", "python", "ram" ]
Problem allocating heap space over 4 GB when calling java "from Python"
2,000,331
<p>I am using using os.system call from python to run jar file. The jar file requires large heap space and thus i am allocating 4 Gb heap space using Xmx. When i execute the command "java -Xms4096m -Xmx4096m -jar camXnet.jar net.txt" from command line it executes properly, however when i call it from a python program...
1
2010-01-04T15:52:28Z
2,122,159
<p>I was having the same problem launching 64bit Java from 32bit python. I solved the problem using Dave Webb's suggestiong of putting the full path to 64bit Java.exe in the python script. This worked fine so it is not necessary to use 64 bit Python</p>
1
2010-01-23T04:43:41Z
[ "java", "python", "ram" ]
PyQt, widget do not shown
2,000,466
<p>Hi I've this hort program in Python ad Qt4</p> <pre><code>#!/usr/bin/python # -*- coding: utf-8 -*- import sys from PyQt4 import QtGui from PyQt4 import QtCore color = QtGui.QColor(99, 0, 0) class colorButton(QtGui.QWidget): def __init__(self, args): QtGui.QWidget.__init__(self,args) self.se...
1
2010-01-04T16:11:04Z
2,000,492
<p>Try setting autoFillBackground to True before you change the color (before setStylesheet call). AND I think you need to set the pallete. This comment assumes that you meant "the color of the widget is not shown". Please review the syntax as the one illustrated below is for Qt4.3 and I didn't check the latest one. A...
0
2010-01-04T16:15:18Z
[ "python", "pyqt", "qwidget" ]
PyQt, widget do not shown
2,000,466
<p>Hi I've this hort program in Python ad Qt4</p> <pre><code>#!/usr/bin/python # -*- coding: utf-8 -*- import sys from PyQt4 import QtGui from PyQt4 import QtCore color = QtGui.QColor(99, 0, 0) class colorButton(QtGui.QWidget): def __init__(self, args): QtGui.QWidget.__init__(self,args) self.se...
1
2010-01-04T16:11:04Z
2,000,531
<p>Your class <code>colorButton</code> inherits from <code>QWidget</code>, yet you are calling <code>QPushButton.__init__()</code> in the constructor. Maybe you want it to inherit from <code>QPushButton</code>?</p> <p>By using the following class definition, your code works for me:</p> <pre><code>class colorButton(Qt...
4
2010-01-04T16:22:19Z
[ "python", "pyqt", "qwidget" ]
PyQt, widget do not shown
2,000,466
<p>Hi I've this hort program in Python ad Qt4</p> <pre><code>#!/usr/bin/python # -*- coding: utf-8 -*- import sys from PyQt4 import QtGui from PyQt4 import QtCore color = QtGui.QColor(99, 0, 0) class colorButton(QtGui.QWidget): def __init__(self, args): QtGui.QWidget.__init__(self,args) self.se...
1
2010-01-04T16:11:04Z
2,000,769
<p>I think you need to give your ColorDialog a Layout using </p> <pre><code>self.setLayout(SOME_LAYOUT) </code></pre> <p>then add your button to the layout with something like </p> <pre><code>self.layout().addItem(button) </code></pre> <p>Otherwise I am not sure if simply giving your button the ColorDialog as paren...
0
2010-01-04T17:02:28Z
[ "python", "pyqt", "qwidget" ]
PyQt, widget do not shown
2,000,466
<p>Hi I've this hort program in Python ad Qt4</p> <pre><code>#!/usr/bin/python # -*- coding: utf-8 -*- import sys from PyQt4 import QtGui from PyQt4 import QtCore color = QtGui.QColor(99, 0, 0) class colorButton(QtGui.QWidget): def __init__(self, args): QtGui.QWidget.__init__(self,args) self.se...
1
2010-01-04T16:11:04Z
2,002,750
<p>You need to give the widget a paintEvent.</p> <pre><code>#!/usr/bin/python # -*- coding: utf-8 -*- import sys from PyQt4 import QtGui from PyQt4 import QtCore color = QtGui.QColor(99, 0, 0) class colorButton(QtGui.QWidget): def __init__(self, args): QtGui.QWidget.__init__(self,args) self.set...
1
2010-01-04T22:31:17Z
[ "python", "pyqt", "qwidget" ]
Does Django need an IDE?
2,000,631
<p>My company is evaluating the possibility of developing a specialized IDE for Django. </p> <p>So we would like to ask Django users: </p> <ul> <li><p>Do you feel the need for a specialized IDE for Django?</p></li> <li><p>Would you be willing to pay for it, or would you only consider free a open-source product? </p><...
9
2010-01-04T16:39:16Z
2,000,647
<p>You'll likely want an IDE that will provide you with the ability to do source-level debugging of your accompanying Python code. Without it, your productivity will really be below what it could be.</p> <p>I use <a href="http://www.wingware.com/" rel="nofollow">Wing IDE</a>, and I find it to be worth every penny.</p>...
2
2010-01-04T16:43:04Z
[ "python", "django" ]
Does Django need an IDE?
2,000,631
<p>My company is evaluating the possibility of developing a specialized IDE for Django. </p> <p>So we would like to ask Django users: </p> <ul> <li><p>Do you feel the need for a specialized IDE for Django?</p></li> <li><p>Would you be willing to pay for it, or would you only consider free a open-source product? </p><...
9
2010-01-04T16:39:16Z
2,000,657
<ol> <li>I use NotePad++, and have yet to need a fully-fledged IDE specifically for Django (though I do wish NotePad++ would stop periodically crashing).</li> <li>I wouldn't, unless it was really really good (and I have no idea what features it'd need to make me enthusiastic enough to pay for it).</li> <li>Maybe a neat...
2
2010-01-04T16:44:53Z
[ "python", "django" ]
Does Django need an IDE?
2,000,631
<p>My company is evaluating the possibility of developing a specialized IDE for Django. </p> <p>So we would like to ask Django users: </p> <ul> <li><p>Do you feel the need for a specialized IDE for Django?</p></li> <li><p>Would you be willing to pay for it, or would you only consider free a open-source product? </p><...
9
2010-01-04T16:39:16Z
2,000,679
<p>I am using Komodo Edit and it's very good. There is a lot of good open-sources product so i don't think that I would buy a commercial product. </p> <p>Maybe a very good and easy-to-use debugger would make me change my mind. </p> <p>I hope it helps. </p>
4
2010-01-04T16:47:17Z
[ "python", "django" ]
Does Django need an IDE?
2,000,631
<p>My company is evaluating the possibility of developing a specialized IDE for Django. </p> <p>So we would like to ask Django users: </p> <ul> <li><p>Do you feel the need for a specialized IDE for Django?</p></li> <li><p>Would you be willing to pay for it, or would you only consider free a open-source product? </p><...
9
2010-01-04T16:39:16Z
2,001,403
<p>I am currently using aptana studio (basically eclipse with aptana's pydev plugin) and find it useful.</p> <p>I would be willing to pay for a really good IDE though.</p> <p>5 features I would like to see:</p> <ol> <li>Full support for Django templates, including code completion and syntax highlighting</li> <li>Goo...
3
2010-01-04T18:56:37Z
[ "python", "django" ]
Does Django need an IDE?
2,000,631
<p>My company is evaluating the possibility of developing a specialized IDE for Django. </p> <p>So we would like to ask Django users: </p> <ul> <li><p>Do you feel the need for a specialized IDE for Django?</p></li> <li><p>Would you be willing to pay for it, or would you only consider free a open-source product? </p><...
9
2010-01-04T16:39:16Z
2,001,415
<p>It's great that your company wants to contribute to the community, but I have to say that I don't see what a 'Django IDE' would achieve. There are already plugins for all the main editors and IDEs to support Django - from Vim to TextMate to NetBeans - and these provide syntax highlighting, indentation, shortcuts and...
1
2010-01-04T18:57:49Z
[ "python", "django" ]
Does Django need an IDE?
2,000,631
<p>My company is evaluating the possibility of developing a specialized IDE for Django. </p> <p>So we would like to ask Django users: </p> <ul> <li><p>Do you feel the need for a specialized IDE for Django?</p></li> <li><p>Would you be willing to pay for it, or would you only consider free a open-source product? </p><...
9
2010-01-04T16:39:16Z
2,001,956
<p>I would pay a reasonable amount for a Django-tailored IDE or plug-in. I don't know what I mean by reasonable, but maye it helps to know that I would not pay more than $75, and I would only pay the $75 if the tool was really awesome.</p> <p>Now, Django specific features:</p> <ul> <li>Seamless integration with Googl...
8
2010-01-04T20:21:12Z
[ "python", "django" ]
Does Django need an IDE?
2,000,631
<p>My company is evaluating the possibility of developing a specialized IDE for Django. </p> <p>So we would like to ask Django users: </p> <ul> <li><p>Do you feel the need for a specialized IDE for Django?</p></li> <li><p>Would you be willing to pay for it, or would you only consider free a open-source product? </p><...
9
2010-01-04T16:39:16Z
2,002,543
<p>graphic models builder to models.py :), I mean <a href="http://code.google.com/p/django-command-extensions/wiki/GraphModels" rel="nofollow">this</a> but vice-versa.</p> <p>yes I will donate.</p>
0
2010-01-04T21:56:21Z
[ "python", "django" ]
Does Django need an IDE?
2,000,631
<p>My company is evaluating the possibility of developing a specialized IDE for Django. </p> <p>So we would like to ask Django users: </p> <ul> <li><p>Do you feel the need for a specialized IDE for Django?</p></li> <li><p>Would you be willing to pay for it, or would you only consider free a open-source product? </p><...
9
2010-01-04T16:39:16Z
2,002,644
<p>This question comes up a lot in various forms. I suspect it's because there just isn't a Python IDE which is universally accepted to be awesome. </p> <p>If I could have:</p> <ul> <li>some of the features of PyDev, like like real code completion, module navigation, live syntax checking and pylint</li> <li>a fantast...
2
2010-01-04T22:10:52Z
[ "python", "django" ]
Does Django need an IDE?
2,000,631
<p>My company is evaluating the possibility of developing a specialized IDE for Django. </p> <p>So we would like to ask Django users: </p> <ul> <li><p>Do you feel the need for a specialized IDE for Django?</p></li> <li><p>Would you be willing to pay for it, or would you only consider free a open-source product? </p><...
9
2010-01-04T16:39:16Z
2,012,679
<p>I would definitely pay or donate for a pure Django IDE, even tho there are already some existing plugins, I feel something is always "floating". </p>
0
2010-01-06T11:49:24Z
[ "python", "django" ]
Does Django need an IDE?
2,000,631
<p>My company is evaluating the possibility of developing a specialized IDE for Django. </p> <p>So we would like to ask Django users: </p> <ul> <li><p>Do you feel the need for a specialized IDE for Django?</p></li> <li><p>Would you be willing to pay for it, or would you only consider free a open-source product? </p><...
9
2010-01-04T16:39:16Z
11,179,066
<p>There are some Django aware IDEs already. <a href="http://www.jetbrains.com/pycharm/" rel="nofollow">PyCharm</a> is excelent for Django development. It even allows to debug Django Templates visually. </p>
1
2012-06-24T16:20:37Z
[ "python", "django" ]
Retrieve module object from stack frame
2,000,861
<p>Given a frame object, I need to get the corresponding module object. In other words, implement callers_module so this works:</p> <pre><code>import sys from some_other_module import callers_module assert sys.modules[__name__] is callers_module() </code></pre> <p>(That would be equivalent because I can generate a s...
6
2010-01-04T17:18:00Z
2,001,032
<pre><code>import inspect def callers_module(): module = inspect.getmodule(inspect.currentframe().f_back) return module </code></pre>
1
2010-01-04T17:50:39Z
[ "python", "introspection" ]
Retrieve module object from stack frame
2,000,861
<p>Given a frame object, I need to get the corresponding module object. In other words, implement callers_module so this works:</p> <pre><code>import sys from some_other_module import callers_module assert sys.modules[__name__] is callers_module() </code></pre> <p>(That would be equivalent because I can generate a s...
6
2010-01-04T17:18:00Z
2,011,168
<p>While inspect.getmodule works great, and I was indeed looking in the wrong place to find it, I found a slightly better solution for me:</p> <pre><code>def callers_module(): module_name = inspect.currentframe().f_back.f_globals["__name__"] return sys.modules[module_name] </code></pre> <p>It still uses inspect.c...
3
2010-01-06T05:44:56Z
[ "python", "introspection" ]
Class or Metaclass Design for Astrodynamics Engine
2,000,979
<p>Gurus out there:</p> <p>The differential equations for modeling spacecraft motion can be described in terms of a collection of acceleration terms:</p> <pre><code>d2r/dt2 = a0 + a1 + a2 + ... + an </code></pre> <p>Normally a0 is the point mass acceleration due to a body (a0 = -mu * r/r^3); the "higher order" term...
2
2010-01-04T17:42:37Z
2,001,031
<p>I would use instead some library which can work with vectors (in python, try numpy) and represent the acceleration as vector. Then, you are not reinventing the wheel, the + operator works like you wanted. Please correct me if I misunderstood your problem.</p>
0
2010-01-04T17:50:39Z
[ "python", "math", "oop", "simulation", "physics" ]
Class or Metaclass Design for Astrodynamics Engine
2,000,979
<p>Gurus out there:</p> <p>The differential equations for modeling spacecraft motion can be described in terms of a collection of acceleration terms:</p> <pre><code>d2r/dt2 = a0 + a1 + a2 + ... + an </code></pre> <p>Normally a0 is the point mass acceleration due to a body (a0 = -mu * r/r^3); the "higher order" term...
2
2010-01-04T17:42:37Z
2,001,257
<p>For those who would like to avoid numpy and do this in pure python, this may give you a few good ideas. I'm sure there are disadvantages and flaws to this little skit also. The "operator" module speeds up your math calculations as they are done with c functions:</p> <pre><code>from operator import sub, add, iadd,...
1
2010-01-04T18:28:40Z
[ "python", "math", "oop", "simulation", "physics" ]
Class or Metaclass Design for Astrodynamics Engine
2,000,979
<p>Gurus out there:</p> <p>The differential equations for modeling spacecraft motion can be described in terms of a collection of acceleration terms:</p> <pre><code>d2r/dt2 = a0 + a1 + a2 + ... + an </code></pre> <p>Normally a0 is the point mass acceleration due to a body (a0 = -mu * r/r^3); the "higher order" term...
2
2010-01-04T17:42:37Z
2,106,539
<p>Are you asking how to store an arbitrary number of acceleration sources for a spacecraft class?</p> <p>Can't you just use an array of functions? (Function pointers when you get to c++)</p> <p>i.e:</p> <pre><code>#pseudo Python class Spacecraft terms = [] def accelerate(t): a = (0,0,0) for f...
1
2010-01-21T02:35:56Z
[ "python", "math", "oop", "simulation", "physics" ]
Class or Metaclass Design for Astrodynamics Engine
2,000,979
<p>Gurus out there:</p> <p>The differential equations for modeling spacecraft motion can be described in terms of a collection of acceleration terms:</p> <pre><code>d2r/dt2 = a0 + a1 + a2 + ... + an </code></pre> <p>Normally a0 is the point mass acceleration due to a body (a0 = -mu * r/r^3); the "higher order" term...
2
2010-01-04T17:42:37Z
6,886,052
<p><a href="http://pydstool.sourceforge.net" rel="nofollow" title="PyDSTool">PyDSTool</a> lets you build up "components" that have spatial or physical meaning, and have mathematical expressions associated with them, into bigger components that know how to sum things up etc. The result is a way to specify differential e...
2
2011-07-30T21:25:50Z
[ "python", "math", "oop", "simulation", "physics" ]
Is it a good idea to use undocumented public code from the Python standard library?
2,001,052
<p>For instance, in <code>multiprocessing.managers</code> there is a function called <code>MakeProxyType</code>. This function isn't in the multiprocessing documentation at all, but its name doesn't begin with an underscore either. Disregarding the subject of whether or not it's actually <em>useful</em> to use <code>...
8
2010-01-04T17:53:24Z
2,001,079
<p>You should clarify with the authors whether the omission of MakeProxyType from the documentation is deliberate or accidental. If it's deliberate, then it can disappear from the API without notice and would be dangerous to use.</p>
4
2010-01-04T17:58:00Z
[ "python", "api", "documentation", "standard-library" ]
Is it a good idea to use undocumented public code from the Python standard library?
2,001,052
<p>For instance, in <code>multiprocessing.managers</code> there is a function called <code>MakeProxyType</code>. This function isn't in the multiprocessing documentation at all, but its name doesn't begin with an underscore either. Disregarding the subject of whether or not it's actually <em>useful</em> to use <code>...
8
2010-01-04T17:53:24Z
2,001,128
<p>It's going to be safe if, and only if, you can check that the implementation does not depend on other, "private" parts of the package (so that you'll just be able to copy and paste it into your own module if and when it should get removed from the standard library), or else you see how to reimplement the same interf...
2
2010-01-04T18:08:00Z
[ "python", "api", "documentation", "standard-library" ]
Is it a good idea to use undocumented public code from the Python standard library?
2,001,052
<p>For instance, in <code>multiprocessing.managers</code> there is a function called <code>MakeProxyType</code>. This function isn't in the multiprocessing documentation at all, but its name doesn't begin with an underscore either. Disregarding the subject of whether or not it's actually <em>useful</em> to use <code>...
8
2010-01-04T17:53:24Z
2,001,407
<p>If you really need to use the function in your code then you could do this:</p> <pre><code>try: from multiprocessing.managers import MakeProxyType except ImportError: def MakeProxyType(...): &lt;copy the code from source&gt; </code></pre> <p>that way if the function disappears from new versions it will f...
3
2010-01-04T18:56:55Z
[ "python", "api", "documentation", "standard-library" ]
Is it a good idea to use undocumented public code from the Python standard library?
2,001,052
<p>For instance, in <code>multiprocessing.managers</code> there is a function called <code>MakeProxyType</code>. This function isn't in the multiprocessing documentation at all, but its name doesn't begin with an underscore either. Disregarding the subject of whether or not it's actually <em>useful</em> to use <code>...
8
2010-01-04T17:53:24Z
2,001,537
<p>Usually names which don't start with an underscore are considered part of the public API and we try to maintain compatibility accross versions. You might want to wait for Jesse Noller's answer, though, he's the multiprocessing maintainer and I hear he has an account here ;)</p>
2
2010-01-04T19:20:21Z
[ "python", "api", "documentation", "standard-library" ]
How to create dynamical scoped variables in Python?
2,001,138
<p>I am translating some code from lisp to Python.</p> <p>In lisp, you can have a let construct with the variables introduced declared as special and thus having dynamic scope. (See <a href="http://en.wikipedia.org/wiki/Dynamic_scope#Dynamic_scoping">http://en.wikipedia.org/wiki/Dynamic_scope#Dynamic_scoping</a>)</p>...
10
2010-01-04T18:09:52Z
2,001,245
<p>Dynamic Scoping Considered Harmful.</p> <p>Don't use it; don't emulate it.</p> <p>If you need to emulate it, define a <code>dynamic_scope</code> module to emulate this behavior and import the module in all source files. This module should have methods <code>begin</code> which is called in the first line of your fu...
-3
2010-01-04T18:26:20Z
[ "python", "variables", "lisp", "scope", "dynamic-scope" ]
How to create dynamical scoped variables in Python?
2,001,138
<p>I am translating some code from lisp to Python.</p> <p>In lisp, you can have a let construct with the variables introduced declared as special and thus having dynamic scope. (See <a href="http://en.wikipedia.org/wiki/Dynamic_scope#Dynamic_scoping">http://en.wikipedia.org/wiki/Dynamic_scope#Dynamic_scoping</a>)</p>...
10
2010-01-04T18:09:52Z
2,001,797
<p>I feel Justice is plain right in his reasoning here.</p> <p>On the other hand -- I can't resist implementing proof of concept for still another programing paradigm "unnatural" to Python -- I simply love doing this. :-)</p> <p>So, I created a class whose objects'attributes are scopped just like you require (and c...
10
2010-01-04T19:57:32Z
[ "python", "variables", "lisp", "scope", "dynamic-scope" ]
How to create dynamical scoped variables in Python?
2,001,138
<p>I am translating some code from lisp to Python.</p> <p>In lisp, you can have a let construct with the variables introduced declared as special and thus having dynamic scope. (See <a href="http://en.wikipedia.org/wiki/Dynamic_scope#Dynamic_scoping">http://en.wikipedia.org/wiki/Dynamic_scope#Dynamic_scoping</a>)</p>...
10
2010-01-04T18:09:52Z
2,002,140
<p>Here's something that works a bit like Lisp's special variables, but fits a little better into Python.</p> <pre><code>_stack = [] class _EnvBlock(object): def __init__(self, kwargs): self.kwargs = kwargs def __enter__(self): _stack.append(self.kwargs) def __exit__(self, t, v, tb): ...
9
2010-01-04T20:49:34Z
[ "python", "variables", "lisp", "scope", "dynamic-scope" ]
How to create dynamical scoped variables in Python?
2,001,138
<p>I am translating some code from lisp to Python.</p> <p>In lisp, you can have a let construct with the variables introduced declared as special and thus having dynamic scope. (See <a href="http://en.wikipedia.org/wiki/Dynamic_scope#Dynamic_scoping">http://en.wikipedia.org/wiki/Dynamic_scope#Dynamic_scoping</a>)</p>...
10
2010-01-04T18:09:52Z
8,135,949
<p>The Python idiom corresponding to Lisp "special" or dynamically-scoped variables is "thread local storage".</p> <p>Here is a good discussion: <a href="http://stackoverflow.com/questions/104983/what-is-thread-local-storage-in-python-and-why-do-i-need-it">What is &quot;thread local storage&quot; in Python, and why do...
3
2011-11-15T11:53:58Z
[ "python", "variables", "lisp", "scope", "dynamic-scope" ]
Launch script on any network connection
2,001,174
<p>On linux (ubuntu), is it possible to execute a script upon any incoming network connection? </p> <p>During long periods inactivity on my home server, I plan on stopping the software raid, parking the data disks and restarting the raid array upon encountering an incoming network connection.</p> <p>I've been researc...
3
2010-01-04T18:16:00Z
2,001,957
<p>Take a look at netfilter/iptables. You may be able to write code to use the userspace API libraries to detect incoming packet events.</p>
1
2010-01-04T20:21:13Z
[ "python", "linux", "ubuntu" ]
Using Python csv module on updating file
2,001,201
<p>I am using python's csv module to extract data from a csv that is constantly being updated by an external tool. I have run into a problem where when I reach the end of the file I get a StopIteration error, however, I would like the script to continue to loop waiting for more lines to be added by the external tool.<...
4
2010-01-04T18:19:42Z
2,001,246
<p>You rarely need to catch <code>StopIteration</code> explicitly. Do this:</p> <pre><code>for row in csvReader: doStuff(row) </code></pre> <p>As for detecting when new lines are written to the file, you can <s>either popen a <code>tail -f</code> process or</s> write out the Python code for what <code>tail -f</co...
0
2010-01-04T18:26:34Z
[ "python", "file", "csv" ]
Using Python csv module on updating file
2,001,201
<p>I am using python's csv module to extract data from a csv that is constantly being updated by an external tool. I have run into a problem where when I reach the end of the file I get a StopIteration error, however, I would like the script to continue to loop waiting for more lines to be added by the external tool.<...
4
2010-01-04T18:19:42Z
2,001,252
<p>Producer-consumer stuff can get a bit tricky. How about using seek and reading bytes instead? What about using a named pipe?</p> <p>Heck, why not communicate over a local socket?</p>
2
2010-01-04T18:27:48Z
[ "python", "file", "csv" ]
Using Python csv module on updating file
2,001,201
<p>I am using python's csv module to extract data from a csv that is constantly being updated by an external tool. I have run into a problem where when I reach the end of the file I get a StopIteration error, however, I would like the script to continue to loop waiting for more lines to be added by the external tool.<...
4
2010-01-04T18:19:42Z
2,001,315
<p>Your problem is not with the CSV reader, but with the file object itself. You may still have to do the crazy gyrations you're doing in your snippet above, but it would be better to create a file object wrapper or subclass that does it for you, and use that with your CSV reader. That keeps the complexity isolated f...
4
2010-01-04T18:36:58Z
[ "python", "file", "csv" ]
Should I use Lex or a home-brewed solution to parse a formula?
2,001,504
<p>I'm in the process of writing a small, rule-based 'math' engine. I realize this is unclear, so I'll provide a small example.</p> <p>Let's say you have some variable a, that holds an integer. You also have some functions you can apply to the number, i.e.</p> <ul> <li><code>sqr</code> - square the number</li> <li><c...
4
2010-01-04T19:13:38Z
2,001,535
<p>Yes, seems like an overkill in this case. Just split the string on '=", and then apply the operations one after another. Thank god for dictionaries and functions as first-class citizen your engine can be written in 0.5 - 1 pages of code.</p> <pre><code>dct = {'sqr' : lambda a: a * a, ...} ntimes, op = token[:-3], ...
1
2010-01-04T19:19:46Z
[ "python", "lex", "ply" ]
Should I use Lex or a home-brewed solution to parse a formula?
2,001,504
<p>I'm in the process of writing a small, rule-based 'math' engine. I realize this is unclear, so I'll provide a small example.</p> <p>Let's say you have some variable a, that holds an integer. You also have some functions you can apply to the number, i.e.</p> <ul> <li><code>sqr</code> - square the number</li> <li><c...
4
2010-01-04T19:13:38Z
2,001,553
<p>It really depends on how big your project is going to end up being: If you're looking at creating a new language or something that's parsing more interesting grammars than just + then I'd say lex would be a fun and entertaining way to spend an afternoon. </p> <p>On the other hand, writing your own parser is extreme...
0
2010-01-04T19:22:49Z
[ "python", "lex", "ply" ]
Should I use Lex or a home-brewed solution to parse a formula?
2,001,504
<p>I'm in the process of writing a small, rule-based 'math' engine. I realize this is unclear, so I'll provide a small example.</p> <p>Let's say you have some variable a, that holds an integer. You also have some functions you can apply to the number, i.e.</p> <ul> <li><code>sqr</code> - square the number</li> <li><c...
4
2010-01-04T19:13:38Z
2,001,562
<p>If you have some free time and want to learn a new programming paradigm, give Prolog a spin!</p>
-1
2010-01-04T19:24:24Z
[ "python", "lex", "ply" ]
Should I use Lex or a home-brewed solution to parse a formula?
2,001,504
<p>I'm in the process of writing a small, rule-based 'math' engine. I realize this is unclear, so I'll provide a small example.</p> <p>Let's say you have some variable a, that holds an integer. You also have some functions you can apply to the number, i.e.</p> <ul> <li><code>sqr</code> - square the number</li> <li><c...
4
2010-01-04T19:13:38Z
2,003,457
<p>If your grammar isn't super-complex and you don't mind doing it in Python, <a href="http://pyparsing.wikispaces.com/" rel="nofollow">pyparsing</a> could be just what the doctor ordered. I implemented something fairly similar for parsing chemical equations and it took me an hour or so to do it. I'd add the code here,...
3
2010-01-05T00:56:12Z
[ "python", "lex", "ply" ]
Should I use Lex or a home-brewed solution to parse a formula?
2,001,504
<p>I'm in the process of writing a small, rule-based 'math' engine. I realize this is unclear, so I'll provide a small example.</p> <p>Let's say you have some variable a, that holds an integer. You also have some functions you can apply to the number, i.e.</p> <ul> <li><code>sqr</code> - square the number</li> <li><c...
4
2010-01-04T19:13:38Z
2,003,464
<p>What's your host language? For Ruby, I really like <a href="http://treetop.rubyforge.org/" rel="nofollow">treetop</a>. It's a bit hard to get started, but I've used it with success for parsing more complicated math expressions.</p>
0
2010-01-05T00:59:48Z
[ "python", "lex", "ply" ]
How do I update attachment content with the google sites python API?
2,001,664
<p>I'm trying to write a script that will automatically update some attachments on a website created and managed through Google Sites. This should be possible as Google released the <a href="http://code.google.com/apis/sites/" rel="nofollow">Sites API</a> in September and the <a href="http://code.google.com/p/gdata-py...
2
2010-01-04T19:39:09Z
2,001,746
<p>There is an <a href="http://gdata-python-client.googlecode.com/svn/trunk/pydocs/gdata.sites.client.html#SitesClient-upload_attachment" rel="nofollow">upload_attachment</a> method, that should work. You may also want to check out the <a href="http://code.google.com/p/gdata-python-client/source/browse/trunk/samples/si...
0
2010-01-04T19:50:53Z
[ "python", "gdata-api", "google-sites" ]
How do I update attachment content with the google sites python API?
2,001,664
<p>I'm trying to write a script that will automatically update some attachments on a website created and managed through Google Sites. This should be possible as Google released the <a href="http://code.google.com/apis/sites/" rel="nofollow">Sites API</a> in September and the <a href="http://code.google.com/p/gdata-py...
2
2010-01-04T19:39:09Z
2,152,775
<p>sites api has been updated to v1.1; this is probably a new addition</p> <p><a href="http://code.google.com/apis/sites/docs/1.0/developers_guide_python.html#UpdatingContent" rel="nofollow">http://code.google.com/apis/sites/docs/1.0/developers_guide_python.html#UpdatingContent</a></p>
2
2010-01-28T06:41:35Z
[ "python", "gdata-api", "google-sites" ]
How do I update attachment content with the google sites python API?
2,001,664
<p>I'm trying to write a script that will automatically update some attachments on a website created and managed through Google Sites. This should be possible as Google released the <a href="http://code.google.com/apis/sites/" rel="nofollow">Sites API</a> in September and the <a href="http://code.google.com/p/gdata-py...
2
2010-01-04T19:39:09Z
2,424,730
<p>Ok, the API there is weird, and the documentation is not very clear. Here is what I have figured out. First time you upload an attachment, you do it through UploadAttachment method, but on the follow-up attempts, you need to call Update. Here's the code that does it:</p> <pre><code>class AttachmentUploader(object):...
1
2010-03-11T12:08:03Z
[ "python", "gdata-api", "google-sites" ]
How do I update attachment content with the google sites python API?
2,001,664
<p>I'm trying to write a script that will automatically update some attachments on a website created and managed through Google Sites. This should be possible as Google released the <a href="http://code.google.com/apis/sites/" rel="nofollow">Sites API</a> in September and the <a href="http://code.google.com/p/gdata-py...
2
2010-01-04T19:39:09Z
13,261,396
<p>The documentation <a href="https://developers.google.com/google-apps/sites/docs/1.0/developers_guide_python#UpdatingContent" rel="nofollow">here</a> provides an example on how to update an attachment's content and metadata (subsection Replacing an attachment's content and metadata)</p> <p>The only thing left out is...
4
2012-11-07T00:09:43Z
[ "python", "gdata-api", "google-sites" ]
Cannot understand how to get data from checklistbox in wxpython
2,001,703
<p>I am trying to get either the strings checked or the integers from a check list. I cannot seem to get it anywhere. In the code below, you'll see a bunch of un-commented code, those are just different ways I've tried. I thought I would leave them in case any one's suggestions have to do with it. I am very new to GUI-...
1
2010-01-04T19:45:42Z
2,001,751
<pre><code>checkedItems = [i for i in range(citList.GetCount()) if citList.IsChecked(i)] </code></pre> <p><code>citList.GetChecked()</code> should have also completed the task for you. <strong>May the problem be that you are trying to get selected items in <code>__init__</code>?</strong></p> <p><strong>Upd.:</strong>...
3
2010-01-04T19:51:40Z
[ "python", "user-interface", "wxpython" ]
Javascript lexer / tokenizer (in Python?)
2,001,796
<p>Does anyone know of a Javascript lexical analyzer or tokenizer (preferably in Python?)</p> <p>Basically, given an arbitrary Javascript file, I want to grab the tokens.</p> <p>e.g.</p> <p>foo = 1</p> <p>becomes something like:</p> <ol> <li>variable name : "foo"</li> <li>whitespace</li> <li>operator : equals</li>...
1
2010-01-04T19:57:30Z
2,003,418
<p><a href="http://code.google.com/p/pynarcissus/" rel="nofollow">http://code.google.com/p/pynarcissus/</a> has one.</p> <p>Also I made one but it doesn't support automatic semicolon insertion so it is pretty useless for javascript that you have no control over (as almost all real life javascript programs lack at leas...
2
2010-01-05T00:45:18Z
[ "javascript", "python", "yacc", "lex", "tokenize" ]
How to load modules dynamically on package import?
2,001,940
<p>Given the following example layout:</p> <pre><code>test/ test.py formats/ __init__.py format_a.py format_b.py </code></pre> <p>What I try to archive is, that whenever I <code>import formats</code>, the <code>__init__.py</code> looks for all available modules in the <code>formats</code> subdir, load...
3
2010-01-04T20:18:42Z
2,002,063
<p>A module is searched in sys.path. You should be able to extend sys.path with the path to your module. I'm also not really sure whether you can load a module on sys.path with a 'module.py' convention, I would think without '.py' is preferred.</p> <p>This is obviously not a solution, but may be handy nonetheless.</p>...
0
2010-01-04T20:34:40Z
[ "python", "dynamic", "import", "packaging" ]
How to load modules dynamically on package import?
2,001,940
<p>Given the following example layout:</p> <pre><code>test/ test.py formats/ __init__.py format_a.py format_b.py </code></pre> <p>What I try to archive is, that whenever I <code>import formats</code>, the <code>__init__.py</code> looks for all available modules in the <code>formats</code> subdir, load...
3
2010-01-04T20:18:42Z
2,002,079
<p>I thought if you did something that, 'formats' would be your package, so when you tell it <code>import formats</code> you should be able to access the rest of the modules inside that package, so, you would have something like <code>formats.format_a.your_method</code></p> <p>Not sure though, I'm just a n00b.</p>
0
2010-01-04T20:36:59Z
[ "python", "dynamic", "import", "packaging" ]
How to load modules dynamically on package import?
2,001,940
<p>Given the following example layout:</p> <pre><code>test/ test.py formats/ __init__.py format_a.py format_b.py </code></pre> <p>What I try to archive is, that whenever I <code>import formats</code>, the <code>__init__.py</code> looks for all available modules in the <code>formats</code> subdir, load...
3
2010-01-04T20:18:42Z
2,002,082
<p>There are two fixes you need to make to your code:</p> <ol> <li><p>You should call <code>__import__(m, globals(), locals())</code> instead of <code>__import__(m)</code>. This is needed for Python to locate the modules within the package.</p></li> <li><p>Your code doesn't remove the .py extension properly since you ...
1
2010-01-04T20:37:28Z
[ "python", "dynamic", "import", "packaging" ]
How to load modules dynamically on package import?
2,001,940
<p>Given the following example layout:</p> <pre><code>test/ test.py formats/ __init__.py format_a.py format_b.py </code></pre> <p>What I try to archive is, that whenever I <code>import formats</code>, the <code>__init__.py</code> looks for all available modules in the <code>formats</code> subdir, load...
3
2010-01-04T20:18:42Z
2,002,556
<p>First you must make it so that your code works regardless of the current working directory. For that you use the <code>__file__</code> variable. You should also use absolute imports.</p> <p>So something like (untested):</p> <pre><code>supported_formats = {} for fn in os.listdir(os.path.dirname(__file__)): if f...
1
2010-01-04T21:58:28Z
[ "python", "dynamic", "import", "packaging" ]
How to load modules dynamically on package import?
2,001,940
<p>Given the following example layout:</p> <pre><code>test/ test.py formats/ __init__.py format_a.py format_b.py </code></pre> <p>What I try to archive is, that whenever I <code>import formats</code>, the <code>__init__.py</code> looks for all available modules in the <code>formats</code> subdir, load...
3
2010-01-04T20:18:42Z
2,010,296
<p>Here's the code I came up with after the corrections from interjay. Still not sure if this is good style.</p> <pre><code>def load_modules(filemask='*.py', ignore_list=('__init__.py', )): modules = {} dirname = os.path.dirname(__file__) if dirname: filemask = os.path.join(dirname, filemask) for fn in glo...
0
2010-01-06T00:58:46Z
[ "python", "dynamic", "import", "packaging" ]
How to Use Mathematic Equations as Filters in SQLAlchemy
2,002,024
<p>I'm using the SQLAlchemy ORM to construct the MySQL queries in my application, and am perfectly able to add basic filters to the query, like so:</p> <pre><code>query = meta.Session.query(User).filter(User.user_id==1) </code></pre> <p>Which gives me something basically equivalent to this:</p> <pre><code>SELECT * F...
2
2010-01-04T20:29:17Z
2,002,448
<p>You can use literal SQL in your filter, see here: <a href="http://www.sqlalchemy.org/docs/05/ormtutorial.html?highlight=text#using-literal-sql" rel="nofollow">http://www.sqlalchemy.org/docs/05/ormtutorial.html?highlight=text#using-literal-sql</a></p> <p>For example:</p> <pre><code>clause = "SQRT(POW(69.1 * (latitu...
4
2010-01-04T21:44:26Z
[ "python", "mysql", "orm", "sqlalchemy" ]
How to Use Mathematic Equations as Filters in SQLAlchemy
2,002,024
<p>I'm using the SQLAlchemy ORM to construct the MySQL queries in my application, and am perfectly able to add basic filters to the query, like so:</p> <pre><code>query = meta.Session.query(User).filter(User.user_id==1) </code></pre> <p>Which gives me something basically equivalent to this:</p> <pre><code>SELECT * F...
2
2010-01-04T20:29:17Z
2,007,176
<p>I'd use the query builder interface and the <code>func</code> SQL function constructor to abstract the calculation as a function. This way you can use it freely with aliases or joins.</p> <pre><code>User.coords = classmethod(lambda s: (s.latitude, s.longitude)) def calc_distance(latlong1, latlong2): return fun...
2
2010-01-05T15:54:26Z
[ "python", "mysql", "orm", "sqlalchemy" ]
Converting PDF to images automatically
2,002,055
<p>So the state I'm in released a bunch of data in PDF form, but to make matters worse, most (all?) of the PDFs appear to be letters typed in Office, printed/fax, and then scanned (our government at its best eh?). At first I thought I was crazy, but then I started seeing numerous pdfs that are 'tilted', like someone di...
19
2010-01-04T20:33:43Z
2,002,424
<p>Ghostscript is ideal for converting PDF files to images. It is reliable and has many configurable options. Its also available under the GPL license or commercial license. You can call it from the command line or use its native API. For more information:</p> <ul> <li><a href="http://pages.cs.wisc.edu/~ghost/" rel="n...
3
2010-01-04T21:39:53Z
[ "python", "pdf", "image" ]
Converting PDF to images automatically
2,002,055
<p>So the state I'm in released a bunch of data in PDF form, but to make matters worse, most (all?) of the PDFs appear to be letters typed in Office, printed/fax, and then scanned (our government at its best eh?). At first I thought I was crazy, but then I started seeing numerous pdfs that are 'tilted', like someone di...
19
2010-01-04T20:33:43Z
2,002,436
<p>You could call e.g. <code>pdftoppm</code> from the command-line (or using Python's <code>subprocess</code> module) and then convert the resulting PPM files to the desired format using e.g. ImageMagick (again, using <code>subprocess</code> or some bindings if they exist).</p>
4
2010-01-04T21:42:12Z
[ "python", "pdf", "image" ]
Converting PDF to images automatically
2,002,055
<p>So the state I'm in released a bunch of data in PDF form, but to make matters worse, most (all?) of the PDFs appear to be letters typed in Office, printed/fax, and then scanned (our government at its best eh?). At first I thought I was crazy, but then I started seeing numerous pdfs that are 'tilted', like someone di...
19
2010-01-04T20:33:43Z
2,002,785
<p>If the PDFs are truly scanned images, then you shouldn't convert the PDF to an image, you should extract the image from the PDF. Most likely, all of the data in the PDF is essentially one giant image, wrapped in PDF verbosity to make it readable in Acrobat.</p> <p>You should try the simple expedient of simply find...
7
2010-01-04T22:37:48Z
[ "python", "pdf", "image" ]
Alternative to PyGObject?
2,002,119
<p>Does anyone have an alternative to using PyGObject? I can't seem to get it to run at all in Mac OS X. I'm trying to use papyon, which fails amazingly well if GObject isn't around.</p>
1
2010-01-04T20:45:00Z
2,003,383
<p>You can instally PyGobject on Mac OS X with Darwinports, instructions <a href="http://py-gobject.darwinports.com/" rel="nofollow">here</a> .</p>
0
2010-01-05T00:34:19Z
[ "python", "gobject", "pygobject" ]
Alternative to PyGObject?
2,002,119
<p>Does anyone have an alternative to using PyGObject? I can't seem to get it to run at all in Mac OS X. I'm trying to use papyon, which fails amazingly well if GObject isn't around.</p>
1
2010-01-04T20:45:00Z
2,003,385
<p>By <a href="http://telepathy.freedesktop.org/wiki/Papyon" rel="nofollow">its description</a>, it is used for async I/O only. You can try to rework the library to use any of the other Python async libraries, like asyncore, Twisted, or any other.</p> <p>Also, getting PyGObject on Mac OS X is hard, but you can try to ...
2
2010-01-05T00:34:44Z
[ "python", "gobject", "pygobject" ]
Python CGI transaction
2,002,180
<p>I have a Python CGI handling a payment transaction. When the user submits the form, the CGI is called. After submission, the CGI takes a while to perform the credit card transaction. During that time, a user might hit the ESC or refresh button. Doing that will not "kill" the CGI, meaning, the script will keep runnin...
1
2010-01-04T20:57:30Z
2,002,206
<p>Same as you should do with every POST: don't send output, but put the output in a session variable and redirect to a pure-GET request. This one looks in the session for messages, and clears+displays those.</p>
3
2010-01-04T21:02:00Z
[ "python", "cgi" ]
How to debug Jinja2 template?
2,002,357
<p>I am using jinja2 template system into django. It is really fast and I like it a lot. Nevertheless, I have some problem to debug templates : If I make some errors into a template (bad tag, bad filtername, bad end of block...), I do not have at all information about this error.</p> <p>For example, In a django view, ...
17
2010-01-04T21:27:36Z
2,003,029
<p>From the Jinja2 Documentation:</p> <blockquote> <p><strong>My tracebacks look weird. What’s happening?</strong></p> <p>If the speedups module is not compiled and you are using a Python installation without ctypes (Python 2.4 without ctypes, Jython or Google’s AppEngine) Jinja2 is unable to provide correc...
6
2010-01-04T23:21:51Z
[ "python", "django", "jinja2" ]
How to debug Jinja2 template?
2,002,357
<p>I am using jinja2 template system into django. It is really fast and I like it a lot. Nevertheless, I have some problem to debug templates : If I make some errors into a template (bad tag, bad filtername, bad end of block...), I do not have at all information about this error.</p> <p>For example, In a django view, ...
17
2010-01-04T21:27:36Z
2,005,000
<p>After doing some more test, I found the answer :</p> <p>By doing the same template test, directly under python, without using django, debug messages are present. So it comes from django.</p> <p>The fix is in settings.py : One have to set DEBUG to True AND set TEMPLATE_DEBUG to False.</p>
14
2010-01-05T09:12:00Z
[ "python", "django", "jinja2" ]
How can I add an additional row and column to an array?
2,002,415
<p>I need to add a column and and a row to an existing numpy array at a position defined as I can. forgiveness for my regular English.</p>
5
2010-01-04T21:37:45Z
2,002,432
<p>I assume your column and rows are just a list of lists?</p> <p>That is, you have the following?</p> <pre><code>L = [[1,2,3], [4,5,6]] </code></pre> <p>To add another row, use the append method of a list.</p> <pre><code>L.append([7,8,9]) </code></pre> <p>giving</p> <pre><code>L = [[1,2,3], [4,5,6], ...
15
2010-01-04T21:41:51Z
[ "python" ]
How can I add an additional row and column to an array?
2,002,415
<p>I need to add a column and and a row to an existing numpy array at a position defined as I can. forgiveness for my regular English.</p>
5
2010-01-04T21:37:45Z
2,002,587
<p>There are many ways to do this in numpy, but not all of them let you add the row/column to the target array at <em>any</em> location (e.g., append only allows addition after the last row/column). If you want a single method/function to append either a row or column at any position in a target array, i would go with ...
4
2010-01-04T22:03:06Z
[ "python" ]