title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
listlengths
1
5
python line.split semantic error fromtext file
1,634,117
<p>this section of code is supposed to make a list containing the values of the second column in the text file, but it takes the second letter. anyone know what my problem is? </p> <pre><code>TEXTFILE opi 60 kid 60 pou 60 ret 60 kai 60 bob 100 for line in lst: line.split(' ...
0
2009-10-27T22:49:27Z
1,634,137
<p>You probably want to do something like this:</p> <pre><code>mylist = [] for line in file: firstcolval, secondcolval = line.split() mylist.append(int(firstcolval)) </code></pre>
1
2009-10-27T22:53:37Z
[ "python", "string" ]
python line.split semantic error fromtext file
1,634,117
<p>this section of code is supposed to make a list containing the values of the second column in the text file, but it takes the second letter. anyone know what my problem is? </p> <pre><code>TEXTFILE opi 60 kid 60 pou 60 ret 60 kai 60 bob 100 for line in lst: line.split(' ...
0
2009-10-27T22:49:27Z
1,634,361
<p>This should also work</p> <pre><code>import csv for line in csv.reader(open("datafile"), delimiter=" "): fire.append(int(line[1])) print(line[1]) </code></pre> <p>Alternatively</p> <pre><code>from operator import itemgetter import csv f=csv.reader(open("datafile"),delimiter=' ') ...
1
2009-10-27T23:43:28Z
[ "python", "string" ]
python line.split semantic error fromtext file
1,634,117
<p>this section of code is supposed to make a list containing the values of the second column in the text file, but it takes the second letter. anyone know what my problem is? </p> <pre><code>TEXTFILE opi 60 kid 60 pou 60 ret 60 kai 60 bob 100 for line in lst: line.split(' ...
0
2009-10-27T22:49:27Z
1,634,809
<p>You can do it with a simple one liner.</p> <pre><code>fire = [int(b) for a, b in line.split(" ") for line in lst] </code></pre>
0
2009-10-28T02:11:36Z
[ "python", "string" ]
python line.split semantic error fromtext file
1,634,117
<p>this section of code is supposed to make a list containing the values of the second column in the text file, but it takes the second letter. anyone know what my problem is? </p> <pre><code>TEXTFILE opi 60 kid 60 pou 60 ret 60 kai 60 bob 100 for line in lst: line.split(' ...
0
2009-10-27T22:49:27Z
1,639,951
<p>Okay, so since split creates a new object (list containing at least one element), you should do:</p> <pre> for line in lst: lc = line.split(' ') fire.append(int(lc[1])) print lc[1] </pre> <p>But as someone has already suggested, you can do that in one line, with list comprehension:</p> <pre> newlist =...
0
2009-10-28T20:36:03Z
[ "python", "string" ]
__init__.py descends dirtree for python, but not from c++; causes "import matplotlib" error
1,634,147
<p>Why or how does the file <code>__init__.py</code> cause the python interpreter to search subdirectories for a module -- and why does the interpreter not honor this convention when invoked from C++?</p> <p>Here's what I know: </p> <p>Using strace on my program, I can see that the same python2.5 interpreter is bein...
0
2009-10-27T22:55:15Z
1,639,133
<p>Looking at (a different version # of) python, I see that <code>import.c</code> has the <code>find_init_module()</code>, which is a part of the <code>find_module()</code>. Not evident why <code>find_init_module()</code> is not executed or fails. </p>
0
2009-10-28T18:21:04Z
[ "c++", "python", "import", "path", "init" ]
How do I blit a PNG with some transparency onto a surface in Pygame?
1,634,208
<p>I'm trying to blit a PNG image onto a surface, but the transparent part of the image turns black for some reason, here's the simple code:</p> <pre><code>screen = pygame.display.set_mode((800, 600), pygame.DOUBLEBUF, 32) world = pygame.Surface((800, 600), pygame.SRCALPHA, 32) treeImage = pygame.image.load("tree.png...
6
2009-10-27T23:09:30Z
1,634,607
<p><a href="http://www.pygame.org/docs/ref/image.html">http://www.pygame.org/docs/ref/image.html</a> recommends:</p> <blockquote> <p>For alpha transparency, like in .png images use the <code>convert_alpha()</code> method after loading so that the image has per pixel transparency.</p> </blockquote>
15
2009-10-28T00:57:06Z
[ "python", "png", "pygame", "alpha", "blit" ]
How do I blit a PNG with some transparency onto a surface in Pygame?
1,634,208
<p>I'm trying to blit a PNG image onto a surface, but the transparent part of the image turns black for some reason, here's the simple code:</p> <pre><code>screen = pygame.display.set_mode((800, 600), pygame.DOUBLEBUF, 32) world = pygame.Surface((800, 600), pygame.SRCALPHA, 32) treeImage = pygame.image.load("tree.png...
6
2009-10-27T23:09:30Z
1,689,433
<p>Your code looks like it should be correct. The SDL library does not support alpha to alpha blitting like this, but Pygame added support for it awhile ago. In Pygame 1.8 support was added for custom blending modes, and I wonder if that removed Pygame's internal alpha-to-alpha blitter?</p> <p>Alas, further investigat...
0
2009-11-06T18:31:29Z
[ "python", "png", "pygame", "alpha", "blit" ]
How do I blit a PNG with some transparency onto a surface in Pygame?
1,634,208
<p>I'm trying to blit a PNG image onto a surface, but the transparent part of the image turns black for some reason, here's the simple code:</p> <pre><code>screen = pygame.display.set_mode((800, 600), pygame.DOUBLEBUF, 32) world = pygame.Surface((800, 600), pygame.SRCALPHA, 32) treeImage = pygame.image.load("tree.png...
6
2009-10-27T23:09:30Z
13,815,907
<p>You did not flip the doublebuffer.</p> <pre><code>import pygame from pygame.locals import Color screen = pygame.display.set_mode((800, 600)) treeImage = pygame.image.load("tree.png").convert_alpha() white = Color('white') while(True): screen.fill(white) screen.blit(treeImage, pygame.rect.Rect(0,0, 128, ...
6
2012-12-11T07:57:06Z
[ "python", "png", "pygame", "alpha", "blit" ]
Inconsistency in ability to access data member of loaded JSON object
1,634,347
<p>I'm loading a JSON string in Django using <code>simplejson</code>, thus:</p> <pre><code>obj = json.loads('{"name": "joe"}') person = obj.name </code></pre> <p>This throws an error:</p> <pre><code>'dict' object has no attribute 'name' </code></pre> <p>but when I pass <code>obj</code> down to the view template and...
1
2009-10-27T23:39:41Z
1,634,377
<p>I'm not sure how the Django aspect of it works, but the object you get from <code>json.loads</code> is a Python <code>dict</code> object. That means it doesn't have attributes of its keys, but you can access them like you would any other dictionary:</p> <pre><code>obj = json.loads('{"name": "joe"}') person = obj['n...
7
2009-10-27T23:47:38Z
[ "python", "django", "simplejson" ]
Inconsistency in ability to access data member of loaded JSON object
1,634,347
<p>I'm loading a JSON string in Django using <code>simplejson</code>, thus:</p> <pre><code>obj = json.loads('{"name": "joe"}') person = obj.name </code></pre> <p>This throws an error:</p> <pre><code>'dict' object has no attribute 'name' </code></pre> <p>but when I pass <code>obj</code> down to the view template and...
1
2009-10-27T23:39:41Z
1,634,426
<p><code>json.loads</code> loads json into a python dictionary. So you must access it like a dictionary, i.e. <code>data['key']</code>.</p> <p>Now, on the django template side of things, check the official <a href="http://docs.djangoproject.com/en/dev/topics/templates/#variables" rel="nofollow">django templates</a> do...
4
2009-10-28T00:03:21Z
[ "python", "django", "simplejson" ]
Please help me in understanding Class in Python
1,634,502
<p>I am newbie and finding it very hard to grasp the syntax of Class in python. I have a background of C/C++, java and objective C. A very big difference which i am noticing in python is that you don't explicitly declare the "data members" in the class and you just randomly add them? And it leads to quite big confusion...
2
2009-10-28T00:25:54Z
1,634,535
<p>You should really use some <strong>.</strong> in your text :p</p> <p>Could you mean:</p> <pre><code>class MyClass: def __int__(self, a, b, c=None): self.a = a self.b = b self.c = c one = MyClass(1,2) one.c # None two = MyClass(1,2,3) two.c # 3 </code></pre>
2
2009-10-28T00:32:17Z
[ "python" ]
Please help me in understanding Class in Python
1,634,502
<p>I am newbie and finding it very hard to grasp the syntax of Class in python. I have a background of C/C++, java and objective C. A very big difference which i am noticing in python is that you don't explicitly declare the "data members" in the class and you just randomly add them? And it leads to quite big confusion...
2
2009-10-28T00:25:54Z
1,634,537
<p>In short, <strong>Yes</strong>.</p> <p>You're right. Python lets you add (and remove!) members from objects at will, at any time. There's nothing special about a constructor that allows it to do anything that other functions can't.</p> <p>If you want to be sure that all instances of your class have the same memb...
5
2009-10-28T00:32:47Z
[ "python" ]
Please help me in understanding Class in Python
1,634,502
<p>I am newbie and finding it very hard to grasp the syntax of Class in python. I have a background of C/C++, java and objective C. A very big difference which i am noticing in python is that you don't explicitly declare the "data members" in the class and you just randomly add them? And it leads to quite big confusion...
2
2009-10-28T00:25:54Z
1,634,606
<pre><code>class MyClass: def __int__(self, a, b): self.a = a self.b = b self.c = None #This line is optional def set_c(self, c): self.c = c </code></pre> <p>Some people prefer to list all the attributes in the <code>__init__</code>. You don't have to, but there are any number...
0
2009-10-28T00:57:05Z
[ "python" ]
Is there any way to "clear" a surface?
1,634,509
<p>Is there any way to clear a surface from anything that has been blitted to it?</p>
4
2009-10-28T00:27:33Z
1,634,553
<p>I don't know what API you're using, so here's a vague answer:</p> <p>In virtually all cases "clearing" a surface simply blits a coloured quad of the same size as the surface onto it. The colour used is whatever you want your clear colour to be. </p> <p>If you know how do blit, just blit a white quad of the same s...
1
2009-10-28T00:37:20Z
[ "python", "pygame", "geometry-surface", "blit" ]
Is there any way to "clear" a surface?
1,634,509
<p>Is there any way to clear a surface from anything that has been blitted to it?</p>
4
2009-10-28T00:27:33Z
1,634,560
<p>For pygame you can use <a href="http://www.pygame.org/docs/ref/surface.html#Surface.fill" rel="nofollow">Surface.fill</a></p>
0
2009-10-28T00:40:33Z
[ "python", "pygame", "geometry-surface", "blit" ]
Is there any way to "clear" a surface?
1,634,509
<p>Is there any way to clear a surface from anything that has been blitted to it?</p>
4
2009-10-28T00:27:33Z
1,634,912
<p>Fill the surface with fill, then make it transparent with set_alpha</p> <pre><code>surface.fill surface.set_alpha(255) </code></pre>
0
2009-10-28T02:34:59Z
[ "python", "pygame", "geometry-surface", "blit" ]
Is there any way to "clear" a surface?
1,634,509
<p>Is there any way to clear a surface from anything that has been blitted to it?</p>
4
2009-10-28T00:27:33Z
1,637,386
<p>You can't undo one graphic written over the top of another graphic any more than you can undo one chalk illustration drawn over the top of another chalk illustration on the same board.</p> <p>What is typically done in graphics is what you'd do with the chalkboard - clear the whole lot, and next time only redraw wha...
2
2009-10-28T13:51:33Z
[ "python", "pygame", "geometry-surface", "blit" ]
Is there any way to "clear" a surface?
1,634,509
<p>Is there any way to clear a surface from anything that has been blitted to it?</p>
4
2009-10-28T00:27:33Z
1,846,124
<p>When I dont care about performance, I use:</p> <pre><code>mysurface.fill((0,0,0)) </code></pre> <p>Which will draw the specified color (black in this case) across the entire surface. Is that what you meant by "clear"?</p> <p>Oh, and you need, of course, to "flip" the surface after doing this for it to be visible ...
2
2009-12-04T10:30:24Z
[ "python", "pygame", "geometry-surface", "blit" ]
Is there any way to "clear" a surface?
1,634,509
<p>Is there any way to clear a surface from anything that has been blitted to it?</p>
4
2009-10-28T00:27:33Z
6,641,560
<p>I had this problem too</p> <p>To create the surface:</p> <pre><code>mask=pygame.Surface((180,100),pygame.SRCALPHA) </code></pre> <p>To clear the surface:</p> <pre><code>mask.fill mask.set_alpha(255) </code></pre> <p>Draw your lines/images etc</p> <p>Then blit this surface onto your main surface using the Alpha...
2
2011-07-10T14:11:40Z
[ "python", "pygame", "geometry-surface", "blit" ]
Is there any way to "clear" a surface?
1,634,509
<p>Is there any way to clear a surface from anything that has been blitted to it?</p>
4
2009-10-28T00:27:33Z
26,833,607
<p><code>.fill((255,255,255,0))</code> appears to work for me anyway.</p>
0
2014-11-09T21:36:26Z
[ "python", "pygame", "geometry-surface", "blit" ]
Is there any way to "clear" a surface?
1,634,509
<p>Is there any way to clear a surface from anything that has been blitted to it?</p>
4
2009-10-28T00:27:33Z
30,915,179
<p>If what you want is to make a pygame Surface object "clean", that is erase all images blited to it, to blit new images to it every game loop and keep the peer pixel alpha without creating a new surface, you can fill it, but instead of a solid color, use a transparent color</p> <pre><code>from pygame import Color, S...
0
2015-06-18T12:19:50Z
[ "python", "pygame", "geometry-surface", "blit" ]
Is there any way to "clear" a surface?
1,634,509
<p>Is there any way to clear a surface from anything that has been blitted to it?</p>
4
2009-10-28T00:27:33Z
33,120,077
<p>I used the following in a game I made:</p> <pre><code>self.image = 0 #to empty it self.image = pygame.image.load("image") </code></pre>
0
2015-10-14T08:15:53Z
[ "python", "pygame", "geometry-surface", "blit" ]
least square solution to camera matrix [numpy]
1,634,555
<p>I would like to use use numpy's least square algorithm to solve for a camera matrix from 6 known 3D -> 2D point correspondence.</p> <p>I have been using this website as a reference:</p> <p><a href="http://homepages.inf.ed.ac.uk/rbf/CVonline/LOCAL%5FCOPIES/OWENS/LECT9/node4.html" rel="nofollow">http://homepages.inf...
0
2009-10-28T00:37:54Z
1,638,088
<p>I suspect you may need to use the fmin_* routines in scipy.optimize. The <a href="http://docs.scipy.org/doc/scipy/reference/tutorial/optimize.html" rel="nofollow">optimization tutorial</a> covers basic use and scipy.optimize.fmin_slsqp can include constraints. </p>
1
2009-10-28T15:41:19Z
[ "python", "numpy", "computer-vision" ]
least square solution to camera matrix [numpy]
1,634,555
<p>I would like to use use numpy's least square algorithm to solve for a camera matrix from 6 known 3D -> 2D point correspondence.</p> <p>I have been using this website as a reference:</p> <p><a href="http://homepages.inf.ed.ac.uk/rbf/CVonline/LOCAL%5FCOPIES/OWENS/LECT9/node4.html" rel="nofollow">http://homepages.inf...
0
2009-10-28T00:37:54Z
1,638,672
<blockquote> <p>I need to get scipy installed properly</p> </blockquote> <p>Just a note for installing scipy, ubuntu distributions since 8.04 have had a broken scipy build. That has been taken care of in the latest 9.10 beta build. You could build scipy from scratch, but it isn't in general an easy thing to do. Just...
2
2009-10-28T17:08:43Z
[ "python", "numpy", "computer-vision" ]
least square solution to camera matrix [numpy]
1,634,555
<p>I would like to use use numpy's least square algorithm to solve for a camera matrix from 6 known 3D -> 2D point correspondence.</p> <p>I have been using this website as a reference:</p> <p><a href="http://homepages.inf.ed.ac.uk/rbf/CVonline/LOCAL%5FCOPIES/OWENS/LECT9/node4.html" rel="nofollow">http://homepages.inf...
0
2009-10-28T00:37:54Z
1,661,225
<p>Would <a href="http://advice.mechanicalkern.com/question/18/how-to-minimize-ax-b-by-least-squares-staying-near-a-point-x0" rel="nofollow">least squares staying near a point x0</a> be of any use, i.e. is there a camera matrix x0 you want to be near to ?<br /> "Keep away from some x0" is non-convex, nasty; keep near x...
0
2009-11-02T13:08:33Z
[ "python", "numpy", "computer-vision" ]
How to run django development server at startup?
1,634,730
<p>I added following command to Sessions -> Startup program but it didn't work. I'm using Ubuntu.</p> <pre><code>sudo -u www-data python manage.py 192.168.1.2:8001 </code></pre> <p>192.168.1.2 is the ip address on ath0. Is it still not available for binding at the stage when this command is executed?</p> <p>What I c...
3
2009-10-28T01:42:36Z
1,634,744
<p>Hopefully you're not trying to run the server in a production environment (according to the <a href="http://docs.djangoproject.com/en/dev/ref/django-admin/#runserver" rel="nofollow">django docs</a>). Take a look instead at <a href="http://code.djangoproject.com/wiki/django%5Fapache%5Fand%5Fmod%5Fwsgi" rel="nofollow...
4
2009-10-28T01:49:37Z
[ "python", "django" ]
How to run django development server at startup?
1,634,730
<p>I added following command to Sessions -> Startup program but it didn't work. I'm using Ubuntu.</p> <pre><code>sudo -u www-data python manage.py 192.168.1.2:8001 </code></pre> <p>192.168.1.2 is the ip address on ath0. Is it still not available for binding at the stage when this command is executed?</p> <p>What I c...
3
2009-10-28T01:42:36Z
1,634,983
<p>If you want the dev server to always run, you're probably better off setting up a real server on your local machine. It doesn't have to be something fat or big. I use <a href="http://www.cherokee-project.com/doc/cookbook%5Fdjango.html" rel="nofollow">cherokee</a> server. Another options is <a href="http://code.djang...
1
2009-10-28T03:03:25Z
[ "python", "django" ]
How to run django development server at startup?
1,634,730
<p>I added following command to Sessions -> Startup program but it didn't work. I'm using Ubuntu.</p> <pre><code>sudo -u www-data python manage.py 192.168.1.2:8001 </code></pre> <p>192.168.1.2 is the ip address on ath0. Is it still not available for binding at the stage when this command is executed?</p> <p>What I c...
3
2009-10-28T01:42:36Z
1,635,984
<p>Mmmm... shouldn't it be?</p> <blockquote> <p>sudo -u www-data python manage.py <strong>runserver</strong> 192.168.1.2:8001</p> </blockquote>
2
2009-10-28T09:04:14Z
[ "python", "django" ]
ToscaWidgets CalendarDatePicker pylons
1,634,793
<p>How does one set the date on the CalendarDatePicker. i.e. it defaults to current date and I want to display it with another date which I will set from my controller.</p> <p>I am displaying the CalendarDatePicker widget in a TableForm from tw.form. I have looked at this for a few hours and can't work out how to do t...
0
2009-10-28T02:06:09Z
1,634,947
<p>I don't have a copy of twforms laying around, but based on their <a href="http://toscawidgets.org/documentation/tw.forms/modules/calendar.html" rel="nofollow">sample code</a>, it looks like you might want to do something like:</p> <pre><code>from datetime import datetime start = twf.CalendarDatePicker('StartDate',...
0
2009-10-28T02:46:34Z
[ "python", "pylons", "toscawidgets" ]
What's the simplest cross-platform way to pop up graphical dialogs in Python?
1,635,027
<p>I want the simplest possible way to pop up simple dialogs in Python scripts. Ideally, the solution would:</p> <ul> <li>Work on Windows, OS X, Gnome, KDE</li> <li>Look like a native dialog on any OS</li> <li>Require minimal code</li> </ul> <p>To pop up a simple standard dialog should require only minimal code. Es...
26
2009-10-28T03:20:38Z
1,635,040
<p><a href="http://wiki.python.org/moin/TkInter">TkInter</a> is usually supplied with Python</p> <pre><code># File: hello1.py from Tkinter import * root = Tk() w = Label(root, text="Hello, world!") w.pack() root.mainloop() </code></pre> <p>If you want something more native looking, you'll have to install somethin...
11
2009-10-28T03:24:51Z
[ "python", "cross-platform", "dialog", "zenity" ]
What's the simplest cross-platform way to pop up graphical dialogs in Python?
1,635,027
<p>I want the simplest possible way to pop up simple dialogs in Python scripts. Ideally, the solution would:</p> <ul> <li>Work on Windows, OS X, Gnome, KDE</li> <li>Look like a native dialog on any OS</li> <li>Require minimal code</li> </ul> <p>To pop up a simple standard dialog should require only minimal code. Es...
26
2009-10-28T03:20:38Z
1,635,043
<p><a href="http://easygui.sourceforge.net/">EasyGUI</a> is a single file, and provides a simple way to work with Tkinter dialogs, but they're still ugly non-native Tkinter dialogs.</p> <pre><code>from easygui import msgbox msgbox('Stuff') </code></pre> <p><img src="http://farm3.static.flickr.com/2627/4052101866_b9af...
17
2009-10-28T03:25:49Z
[ "python", "cross-platform", "dialog", "zenity" ]
What's the simplest cross-platform way to pop up graphical dialogs in Python?
1,635,027
<p>I want the simplest possible way to pop up simple dialogs in Python scripts. Ideally, the solution would:</p> <ul> <li>Work on Windows, OS X, Gnome, KDE</li> <li>Look like a native dialog on any OS</li> <li>Require minimal code</li> </ul> <p>To pop up a simple standard dialog should require only minimal code. Es...
26
2009-10-28T03:20:38Z
1,635,047
<p><a href="http://en.wikipedia.org/wiki/Zenity">Zenity</a> works under Linux and <a href="http://www.placella.com/software/zenity/">Windows</a>, and can be called from Python directly:</p> <pre><code>import os os.system('zenity --info --text="Stuff"') </code></pre> <p>The return values from question boxes need to be...
8
2009-10-28T03:26:48Z
[ "python", "cross-platform", "dialog", "zenity" ]
What's the simplest cross-platform way to pop up graphical dialogs in Python?
1,635,027
<p>I want the simplest possible way to pop up simple dialogs in Python scripts. Ideally, the solution would:</p> <ul> <li>Work on Windows, OS X, Gnome, KDE</li> <li>Look like a native dialog on any OS</li> <li>Require minimal code</li> </ul> <p>To pop up a simple standard dialog should require only minimal code. Es...
26
2009-10-28T03:20:38Z
1,638,539
<p>pyglet is another alternative, though it may not be the simplest. that being said, it's cross-platform and only depends on python, so there's no external dependencies. that fact alone can be reason enough to use it over others.</p> <p>and all it can handle multimedia pretty easily as well, pretty handy if you want ...
1
2009-10-28T16:48:41Z
[ "python", "cross-platform", "dialog", "zenity" ]
What's the simplest cross-platform way to pop up graphical dialogs in Python?
1,635,027
<p>I want the simplest possible way to pop up simple dialogs in Python scripts. Ideally, the solution would:</p> <ul> <li>Work on Windows, OS X, Gnome, KDE</li> <li>Look like a native dialog on any OS</li> <li>Require minimal code</li> </ul> <p>To pop up a simple standard dialog should require only minimal code. Es...
26
2009-10-28T03:20:38Z
1,652,975
<p>Another possibility is the <a href="http://epydoc.sourceforge.net/stdlib/tkMessageBox-module.html" rel="nofollow">tkMessageBox module</a>, which is apparently built into the standard library and is cross-platform, though this is even more ugly than the rest:</p> <pre><code>import tkMessageBox tkMessageBox.showinfo(...
3
2009-10-31T00:38:56Z
[ "python", "cross-platform", "dialog", "zenity" ]
What's the simplest cross-platform way to pop up graphical dialogs in Python?
1,635,027
<p>I want the simplest possible way to pop up simple dialogs in Python scripts. Ideally, the solution would:</p> <ul> <li>Work on Windows, OS X, Gnome, KDE</li> <li>Look like a native dialog on any OS</li> <li>Require minimal code</li> </ul> <p>To pop up a simple standard dialog should require only minimal code. Es...
26
2009-10-28T03:20:38Z
1,663,944
<p>@ endolith, re: zenity for Windows.</p> <p>Hi,</p> <p>I repackaged "Zenity for Windows" and included the correct GTK-theme file. It looks much better now. :) It is now available for download: <a href="http://www.placella.com/software/zenity/" rel="nofollow">http://www.placella.com/software/zenity/</a></p> <p>Scr...
6
2009-11-02T21:49:33Z
[ "python", "cross-platform", "dialog", "zenity" ]
What's the simplest cross-platform way to pop up graphical dialogs in Python?
1,635,027
<p>I want the simplest possible way to pop up simple dialogs in Python scripts. Ideally, the solution would:</p> <ul> <li>Work on Windows, OS X, Gnome, KDE</li> <li>Look like a native dialog on any OS</li> <li>Require minimal code</li> </ul> <p>To pop up a simple standard dialog should require only minimal code. Es...
26
2009-10-28T03:20:38Z
1,680,954
<p>wxPython is the best Python GUI library (IMO) and uses native widgets.</p> <pre><code>import wx app = wx.PySimpleApp() dialog = wx.MessageDialog(None, 'wxPython is awesome!', 'Dialog Box', wx.OK|wx.ICON_INFORMATION) dialog.ShowModal() dialog.Destroy() app.MainLoop() </code></pre>
4
2009-11-05T14:36:48Z
[ "python", "cross-platform", "dialog", "zenity" ]
What's the simplest cross-platform way to pop up graphical dialogs in Python?
1,635,027
<p>I want the simplest possible way to pop up simple dialogs in Python scripts. Ideally, the solution would:</p> <ul> <li>Work on Windows, OS X, Gnome, KDE</li> <li>Look like a native dialog on any OS</li> <li>Require minimal code</li> </ul> <p>To pop up a simple standard dialog should require only minimal code. Es...
26
2009-10-28T03:20:38Z
1,681,019
<p>This is not possible. If you want simple then you have to use Tkinter because that is what is included. If Tkinter is not good enough then you will have to choose and package a GUI for each platform separately.</p> <p>I suggest that you do use Tkinter and wrap the parts that you need in a class that will be even si...
-3
2009-11-05T14:47:06Z
[ "python", "cross-platform", "dialog", "zenity" ]
What's the simplest cross-platform way to pop up graphical dialogs in Python?
1,635,027
<p>I want the simplest possible way to pop up simple dialogs in Python scripts. Ideally, the solution would:</p> <ul> <li>Work on Windows, OS X, Gnome, KDE</li> <li>Look like a native dialog on any OS</li> <li>Require minimal code</li> </ul> <p>To pop up a simple standard dialog should require only minimal code. Es...
26
2009-10-28T03:20:38Z
5,059,990
<p>To extend on endolith's tkMessageBox answer with the ugly empty window in the background...</p> <p>The code below pops up the box without the background window.</p> <pre><code>import Tkinter, tkMessageBox root = Tkinter.Tk() root.withdraw() tkMessageBox.showinfo("my dialog title", "my dialog message") </code></pre...
8
2011-02-20T21:03:23Z
[ "python", "cross-platform", "dialog", "zenity" ]
What's the simplest cross-platform way to pop up graphical dialogs in Python?
1,635,027
<p>I want the simplest possible way to pop up simple dialogs in Python scripts. Ideally, the solution would:</p> <ul> <li>Work on Windows, OS X, Gnome, KDE</li> <li>Look like a native dialog on any OS</li> <li>Require minimal code</li> </ul> <p>To pop up a simple standard dialog should require only minimal code. Es...
26
2009-10-28T03:20:38Z
25,655,555
<p>The PyMsgBox module does almost exactly this. It uses the built-in tkinter module for its message box functions that follow the naming conventions of JavaScript: alert(), confirm(), prompt() and password() (which is prompt() but uses * when you type). These function calls block until the user clicks an OK/Cancel but...
7
2014-09-04T00:24:43Z
[ "python", "cross-platform", "dialog", "zenity" ]
Terminate a multi-thread python program
1,635,080
<p>How to make a multi-thread python program response to Ctrl+C key event?</p> <p><strong>Edit:</strong> The code is like this:</p> <pre><code>import threading current = 0 class MyThread(threading.Thread): def __init__(self, total): threading.Thread.__init__(self) self.total = total def stop...
52
2009-10-28T03:41:20Z
1,635,084
<p>Make every thread except the main one a daemon (<code>t.daemon = True</code> in 2.6 or better, <code>t.setDaemon(True)</code> in 2.6 or less, for every thread object <code>t</code> before you start it). That way, when the main thread receives the KeyboardInterrupt, if it doesn't catch it or catches it but decided t...
68
2009-10-28T03:47:06Z
[ "python", "multithreading" ]
Terminate a multi-thread python program
1,635,080
<p>How to make a multi-thread python program response to Ctrl+C key event?</p> <p><strong>Edit:</strong> The code is like this:</p> <pre><code>import threading current = 0 class MyThread(threading.Thread): def __init__(self, total): threading.Thread.__init__(self) self.total = total def stop...
52
2009-10-28T03:41:20Z
1,635,089
<p>There're two main ways, one clean and one easy.</p> <p>The clean way is to catch KeyboardInterrupt in your main thread, and set a flag your background threads can check so they know to exit; here's a simple/slightly-messy version using a global:</p> <pre><code>exitapp = False if __name__ == '__main__': try: ...
14
2009-10-28T03:49:05Z
[ "python", "multithreading" ]
Terminate a multi-thread python program
1,635,080
<p>How to make a multi-thread python program response to Ctrl+C key event?</p> <p><strong>Edit:</strong> The code is like this:</p> <pre><code>import threading current = 0 class MyThread(threading.Thread): def __init__(self, total): threading.Thread.__init__(self) self.total = total def stop...
52
2009-10-28T03:41:20Z
8,134,616
<p>A <strong><em>Worker</em></strong> might be helpful for you:</p> <pre><code>#!/usr/bin/env python import sys, time from threading import * from collections import deque class Worker(object): def __init__(self, concurrent=1): self.concurrent = concurrent self.queue = deque([]) self.thre...
5
2011-11-15T10:10:12Z
[ "python", "multithreading" ]
Terminate a multi-thread python program
1,635,080
<p>How to make a multi-thread python program response to Ctrl+C key event?</p> <p><strong>Edit:</strong> The code is like this:</p> <pre><code>import threading current = 0 class MyThread(threading.Thread): def __init__(self, total): threading.Thread.__init__(self) self.total = total def stop...
52
2009-10-28T03:41:20Z
11,148,458
<p>I would rather go with the code proposed in <a href="http://www.regexprn.com/2010/05/killing-multithreaded-python-programs.html" rel="nofollow">this blog post</a>:</p> <pre><code>def main(args): threads = [] for i in range(10): t = Worker() threads.append(t) t.start() while len...
3
2012-06-21T23:51:29Z
[ "python", "multithreading" ]
Terminate a multi-thread python program
1,635,080
<p>How to make a multi-thread python program response to Ctrl+C key event?</p> <p><strong>Edit:</strong> The code is like this:</p> <pre><code>import threading current = 0 class MyThread(threading.Thread): def __init__(self, total): threading.Thread.__init__(self) self.total = total def stop...
52
2009-10-28T03:41:20Z
18,219,792
<p>If you spawn a Thread like so - <code>myThread = Thread(target = function)</code> - and then do <code>myThread.start(); myThread.join()</code>. When CTRL-C is initiated, the main thread doesn't exit because it is waiting on that blocking <code>myThread.join()</code> call. To fix this, simply put in a timeout on the ...
1
2013-08-13T21:47:14Z
[ "python", "multithreading" ]
Terminate a multi-thread python program
1,635,080
<p>How to make a multi-thread python program response to Ctrl+C key event?</p> <p><strong>Edit:</strong> The code is like this:</p> <pre><code>import threading current = 0 class MyThread(threading.Thread): def __init__(self, total): threading.Thread.__init__(self) self.total = total def stop...
52
2009-10-28T03:41:20Z
27,833,178
<p>You can always set your threads to "daemon" threads like:</p> <pre><code>t.daemon = True t.start() </code></pre> <p>And whenever the main thread dies all threads will die with it.</p> <p><a href="http://www.regexprn.com/2010/05/killing-multithreaded-python-programs.html" rel="nofollow">http://www.regexprn.com/201...
0
2015-01-08T04:52:07Z
[ "python", "multithreading" ]
Terminate a multi-thread python program
1,635,080
<p>How to make a multi-thread python program response to Ctrl+C key event?</p> <p><strong>Edit:</strong> The code is like this:</p> <pre><code>import threading current = 0 class MyThread(threading.Thread): def __init__(self, total): threading.Thread.__init__(self) self.total = total def stop...
52
2009-10-28T03:41:20Z
32,540,634
<pre><code>thread1 = threading.Thread(target=your_procedure, args = (arg_1, arg_2)) try: thread1.setDaemon(True) # very important thread1.start() except (KeyboardInterrupt, SystemExit): cleanup_stop_thread(); sys.exit() </code></pre> <p>When you want to kill the thread just use:</p> <pre>...
0
2015-09-12T15:40:34Z
[ "python", "multithreading" ]
pyGTK ComboBox List Height
1,635,161
<p>I'm just getting started with pyGtk programming, so bear with me. I have a dialog with a ComboBox. The list that shows up when I click on the combo box has 70+ times in it. It extends from the top of the screen to the bottom. I can live with it, but I'd rather have the ComboBox perform like an html select elemen...
3
2009-10-28T04:14:36Z
1,651,006
<p>You can use a <a href="http://library.gnome.org/devel/pygtk/stable/class-gtkcomboboxentry.html" rel="nofollow">gtk.ComboBoxEntry</a> instead of <a href="http://library.gnome.org/devel/pygtk/stable/class-gtkcombobox.html" rel="nofollow">gtk.ComboBox</a>. I have tested a ComboBoxEntry with 100 items and it works how y...
1
2009-10-30T16:47:15Z
[ "python", "gtk", "pygtk" ]
What is wrong with my django's model field?
1,635,392
<p>I am trying to do a PhoneField that convert the value as a standardized value.</p> <p>In this case, I want to use this clean method.</p> <pre><code>def clean(self): phone = self.cleaned_data.get('phone') # Is it already standardized ? if phone.startswith('+'): mo = re.search(r'^\+\d{2,3}\.\d{9,1...
2
2009-10-28T05:48:04Z
1,635,519
<p>You are mixing up the model fields and form fields.</p> <p>Form Fields need to be first defined and then corresponding model Fields need to be asked to use those form fields for a model form.</p> <p>See <a href="http://docs.djangoproject.com/en/dev/howto/custom-model-fields/#specifying-the-form-field-for-a-model-f...
6
2009-10-28T06:39:43Z
[ "python", "django", "django-forms" ]
What is wrong with my django's model field?
1,635,392
<p>I am trying to do a PhoneField that convert the value as a standardized value.</p> <p>In this case, I want to use this clean method.</p> <pre><code>def clean(self): phone = self.cleaned_data.get('phone') # Is it already standardized ? if phone.startswith('+'): mo = re.search(r'^\+\d{2,3}\.\d{9,1...
2
2009-10-28T05:48:04Z
1,635,587
<p>Here is how I fixed it using becomingGuru help :)</p> <pre><code> class PhoneFormField(forms.CharField): widget = PhoneInput def clean(self, value): phone = super(PhoneFormField, self).clean(value) # Le numéro contient-il un indicatif ? if phone.startswith('+'): mo...
1
2009-10-28T07:09:57Z
[ "python", "django", "django-forms" ]
Is there any Python module similar to Distributed Ruby
1,635,558
<p>I am new to Python. Just want to know is there any module in python similar to ruby's drb? Like a client can use object provided by the drb server?</p>
1
2009-10-28T06:57:20Z
1,635,580
<p>I have no idea what drb is, but from the little information you have given, it might be something like the <a href="http://twistedmatrix.com/projects/core/documentation/howto/pb-intro.html" rel="nofollow">Perspective Broker in Twisted</a></p> <blockquote> <p><strong>Introduction</strong></p> <p>Suppose you f...
0
2009-10-28T07:05:51Z
[ "python", "ruby", "drb" ]
Is there any Python module similar to Distributed Ruby
1,635,558
<p>I am new to Python. Just want to know is there any module in python similar to ruby's drb? Like a client can use object provided by the drb server?</p>
1
2009-10-28T06:57:20Z
1,635,899
<p>Have you looked at execnet?</p> <p><a href="http://codespeak.net/execnet/" rel="nofollow">http://codespeak.net/execnet/</a></p>
0
2009-10-28T08:43:58Z
[ "python", "ruby", "drb" ]
Is there any Python module similar to Distributed Ruby
1,635,558
<p>I am new to Python. Just want to know is there any module in python similar to ruby's drb? Like a client can use object provided by the drb server?</p>
1
2009-10-28T06:57:20Z
1,635,900
<p>The standard <a href="http://docs.python.org/library/multiprocessing.html" rel="nofollow">multiprocessing</a> module might do what you want.</p>
1
2009-10-28T08:44:02Z
[ "python", "ruby", "drb" ]
Is there any Python module similar to Distributed Ruby
1,635,558
<p>I am new to Python. Just want to know is there any module in python similar to ruby's drb? Like a client can use object provided by the drb server?</p>
1
2009-10-28T06:57:20Z
1,635,938
<p>For parallel processing and distributed computing I use <a href="http://www.parallelpython.com/" rel="nofollow">parallel python</a>.</p>
0
2009-10-28T08:52:08Z
[ "python", "ruby", "drb" ]
Is there any Python module similar to Distributed Ruby
1,635,558
<p>I am new to Python. Just want to know is there any module in python similar to ruby's drb? Like a client can use object provided by the drb server?</p>
1
2009-10-28T06:57:20Z
1,635,982
<p><a href="http://pyro.sourceforge.net/" rel="nofollow">Pyro</a> does what I think you're discribing (although I've not used drb).</p> <p>From the website:</p> <blockquote> <p>Pyro is short for PYthon Remote Objects. It is an advanced and powerful Distributed Object Technology system written entirely in Python, th...
2
2009-10-28T09:02:42Z
[ "python", "ruby", "drb" ]
Is there any Python module similar to Distributed Ruby
1,635,558
<p>I am new to Python. Just want to know is there any module in python similar to ruby's drb? Like a client can use object provided by the drb server?</p>
1
2009-10-28T06:57:20Z
1,635,985
<p>This is generally called "object brokering" and a list of some Python packages in this area can be found by browsing the Object Brokering topic area of the Python Package Index <a href="http://pypi.python.org/pypi?%3Aaction=browse&amp;c=405&amp;c=427" rel="nofollow">here</a>.</p> <p>The oldest and most widely used ...
6
2009-10-28T09:04:21Z
[ "python", "ruby", "drb" ]
How do I make powerpoint play presentations/load up ppts automatically?
1,635,565
<p>I was wondering how I can make a script load powerpoint file, advance slides automatically and put it on full screen. Is there a way to make windows do that? Can I just load powerpoint.exe and maybe use some sort of API/Pipe to give commands from another script.</p> <p>To make a case: I'm making a script that autom...
2
2009-10-28T00:47:25Z
1,635,566
<p>One solution for you would be to use the PowerPoint Viewer program instead. PPT Viewer is set to open a PowerPoint file straight away in Presentation mode.</p> <p>Alternatively, you can use the argument /s to start Powerpoint.</p> <pre><code>"powerpoint.exe /s &lt;filename&gt;.ppt" </code></pre> <p>This will be e...
3
2009-10-28T02:52:40Z
[ "python", "powerpoint" ]
How do I make powerpoint play presentations/load up ppts automatically?
1,635,565
<p>I was wondering how I can make a script load powerpoint file, advance slides automatically and put it on full screen. Is there a way to make windows do that? Can I just load powerpoint.exe and maybe use some sort of API/Pipe to give commands from another script.</p> <p>To make a case: I'm making a script that autom...
2
2009-10-28T00:47:25Z
1,635,567
<p>As previously stated, this is more StackOverflow geared, but this can easily be achieved with Python and <a href="http://autohotkey.com" rel="nofollow">AutoHotkey</a>.</p> <p>On the Python side of things, as a general idea on how to go about this (I'm kind of rusty, beware!):</p> <ul> <li>Find files using <code>os...
1
2009-10-28T03:07:00Z
[ "python", "powerpoint" ]
How do I make powerpoint play presentations/load up ppts automatically?
1,635,565
<p>I was wondering how I can make a script load powerpoint file, advance slides automatically and put it on full screen. Is there a way to make windows do that? Can I just load powerpoint.exe and maybe use some sort of API/Pipe to give commands from another script.</p> <p>To make a case: I'm making a script that autom...
2
2009-10-28T00:47:25Z
1,737,451
<p>If you want more control over the powerpoint slide, you could write something in VB.Net (or other .Net languages) according to <a href="http://support.microsoft.com/kb/303717" rel="nofollow">this MS support article</a>.</p> <p>If you wanted direct control from Python, you could probably use <a href="http://sourcefo...
0
2009-11-15T12:43:56Z
[ "python", "powerpoint" ]
How do I make powerpoint play presentations/load up ppts automatically?
1,635,565
<p>I was wondering how I can make a script load powerpoint file, advance slides automatically and put it on full screen. Is there a way to make windows do that? Can I just load powerpoint.exe and maybe use some sort of API/Pipe to give commands from another script.</p> <p>To make a case: I'm making a script that autom...
2
2009-10-28T00:47:25Z
1,737,489
<p>Save the file with the extension ".pps". That will make powerpoint open the file in presentation mode. The presentaion needs to designed to advance slides, else you will have to script that part.</p>
1
2009-11-15T13:10:01Z
[ "python", "powerpoint" ]
How do we override the choice field display of a reference property in appengine using Django?
1,635,638
<p>The default choice field display of a reference property in appengine returns the choices as the string representation of the entire object. What is the best method to override this behaviour? I tried to override str() in the referenced class. But it does not work.</p>
1
2009-10-28T07:25:16Z
1,636,697
<p>I got it to work by overriding the init method of the modelform to pick up the correct fields as I had to do filtering of the choices as well. </p>
1
2009-10-28T11:33:59Z
[ "python", "django", "google-app-engine", "referenceproperty" ]
How do we override the choice field display of a reference property in appengine using Django?
1,635,638
<p>The default choice field display of a reference property in appengine returns the choices as the string representation of the entire object. What is the best method to override this behaviour? I tried to override str() in the referenced class. But it does not work.</p>
1
2009-10-28T07:25:16Z
2,455,288
<p>The correct way would be to override the <code>__unicode__</code> method of the class, like:</p> <pre><code>def __unicode__(self): return self.name </code></pre> <p>where <code>name</code> is the value that you want to display.</p>
0
2010-03-16T14:44:54Z
[ "python", "django", "google-app-engine", "referenceproperty" ]
How would one implement Lazy Evaluation in C?
1,635,827
<p>Take for example,</p> <p>The follow python code:</p> <pre><code>def multiples_of_2(): i = 0 while True: i = i + 2 yield i </code></pre> <p>How do we translate this into C code?</p> <p>Edit: I am looking to translate this python code into a similar generator in C, with next() function. What I am not l...
17
2009-10-28T08:22:44Z
1,635,838
<p>I found a good article recently on <a href="http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html" rel="nofollow">coroutines in C</a>, which describes one method of doing this. It's certainly not for the faint of heart.</p>
5
2009-10-28T08:26:56Z
[ "python", "c" ]
How would one implement Lazy Evaluation in C?
1,635,827
<p>Take for example,</p> <p>The follow python code:</p> <pre><code>def multiples_of_2(): i = 0 while True: i = i + 2 yield i </code></pre> <p>How do we translate this into C code?</p> <p>Edit: I am looking to translate this python code into a similar generator in C, with next() function. What I am not l...
17
2009-10-28T08:22:44Z
1,635,839
<p>The basic approach is to not do it. In Python (and C#) the 'yield' method stores local state between calls, whereas in C/C++ and most other languages the local state stored on the stack is not preserved between calls and this is a fundemental implementation difference. So in C you'd have to store the state between...
1
2009-10-28T08:27:13Z
[ "python", "c" ]
How would one implement Lazy Evaluation in C?
1,635,827
<p>Take for example,</p> <p>The follow python code:</p> <pre><code>def multiples_of_2(): i = 0 while True: i = i + 2 yield i </code></pre> <p>How do we translate this into C code?</p> <p>Edit: I am looking to translate this python code into a similar generator in C, with next() function. What I am not l...
17
2009-10-28T08:22:44Z
1,635,863
<pre><code>int multiples_of_2() { static int i = 0; i += 2; return i; } </code></pre> <p>The static int i behaves like a global variable but is visible only within the contect of multiples_of_2().</p>
0
2009-10-28T08:34:58Z
[ "python", "c" ]
How would one implement Lazy Evaluation in C?
1,635,827
<p>Take for example,</p> <p>The follow python code:</p> <pre><code>def multiples_of_2(): i = 0 while True: i = i + 2 yield i </code></pre> <p>How do we translate this into C code?</p> <p>Edit: I am looking to translate this python code into a similar generator in C, with next() function. What I am not l...
17
2009-10-28T08:22:44Z
1,635,951
<p>Check out <a href="http://en.wikipedia.org/wiki/Setjmp/longjmp" rel="nofollow">setjmp/longjmp</a></p> <blockquote> <p>setjmp.h is a header defined in the C standard library to provide "non-local jumps," or control flow besides the usual subroutine call and return sequence. The paired functions setjmp an...
1
2009-10-28T08:55:41Z
[ "python", "c" ]
How would one implement Lazy Evaluation in C?
1,635,827
<p>Take for example,</p> <p>The follow python code:</p> <pre><code>def multiples_of_2(): i = 0 while True: i = i + 2 yield i </code></pre> <p>How do we translate this into C code?</p> <p>Edit: I am looking to translate this python code into a similar generator in C, with next() function. What I am not l...
17
2009-10-28T08:22:44Z
1,636,076
<p>You can pass the argument as a pointer to allow the function to modify it without using the return value:</p> <pre><code>void multiples_of_2(int *i) { *i += 2; } </code></pre> <p>And call it:</p> <pre><code>int i = 0; multiples_of_2(&amp;i); </code></pre>
1
2009-10-28T09:25:27Z
[ "python", "c" ]
How would one implement Lazy Evaluation in C?
1,635,827
<p>Take for example,</p> <p>The follow python code:</p> <pre><code>def multiples_of_2(): i = 0 while True: i = i + 2 yield i </code></pre> <p>How do we translate this into C code?</p> <p>Edit: I am looking to translate this python code into a similar generator in C, with next() function. What I am not l...
17
2009-10-28T08:22:44Z
1,636,156
<p>You could try to encapsulate this in a <code>struct</code>:</p> <pre><code>typedef struct s_generator { int current; int (*func)(int); } generator; int next(generator* gen) { int result = gen-&gt;current; gen-&gt;current = (gen-&gt;func)(gen-&gt;current); return result; } </code></pre> <p>Then...
19
2009-10-28T09:44:31Z
[ "python", "c" ]
How would one implement Lazy Evaluation in C?
1,635,827
<p>Take for example,</p> <p>The follow python code:</p> <pre><code>def multiples_of_2(): i = 0 while True: i = i + 2 yield i </code></pre> <p>How do we translate this into C code?</p> <p>Edit: I am looking to translate this python code into a similar generator in C, with next() function. What I am not l...
17
2009-10-28T08:22:44Z
1,636,188
<p>As Will mentioned, languages like python do the job of storing the state of the stack between successive calls of the generator. Since C does not have this mechanism, you'll have to do it yourself. The "generic" way of doing this is not for the faint-hearted, as Greg pointed out. The traditional C way of doing this ...
2
2009-10-28T09:51:07Z
[ "python", "c" ]
How would one implement Lazy Evaluation in C?
1,635,827
<p>Take for example,</p> <p>The follow python code:</p> <pre><code>def multiples_of_2(): i = 0 while True: i = i + 2 yield i </code></pre> <p>How do we translate this into C code?</p> <p>Edit: I am looking to translate this python code into a similar generator in C, with next() function. What I am not l...
17
2009-10-28T08:22:44Z
1,636,199
<p>The key is keeping the state of the function between calls. You have a number of options:</p> <ol> <li><p>Static (or global) state. Means the sequence of calls to the function is not reentrant, i.e. you can't have the function call itself recursively, nor can you have more than one caller running different sequen...
1
2009-10-28T09:53:06Z
[ "python", "c" ]
How would one implement Lazy Evaluation in C?
1,635,827
<p>Take for example,</p> <p>The follow python code:</p> <pre><code>def multiples_of_2(): i = 0 while True: i = i + 2 yield i </code></pre> <p>How do we translate this into C code?</p> <p>Edit: I am looking to translate this python code into a similar generator in C, with next() function. What I am not l...
17
2009-10-28T08:22:44Z
1,640,887
<p>I have implemented my own lazy eval, with respects to solving the hamming's problem.</p> <p>Heres my code for anyone whos interested:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; // Hamming problem in C. typedef struct gen { int tracker; int (*next)(struct gen *g); } generator; int twos...
0
2009-10-28T23:57:23Z
[ "python", "c" ]
Any hints on programming Dia with Python extensions?
1,635,943
<p>I'm searching for documentation on how to do it properly. Any hints?</p>
1
2009-10-28T08:53:34Z
1,635,989
<p>if you google "dia python", you'll find <a href="http://projects.gnome.org/dia/python.html" rel="nofollow">http://projects.gnome.org/dia/python.html</a> which is a good starting point </p>
3
2009-10-28T09:05:11Z
[ "python", "interface", "uml", "visio", "dia" ]
How to execute os.* methods as root?
1,636,136
<p>Is it possible to ask for a root pw without storing in in my script memory and to run some of os.* commands as root?</p> <p>My script</p> <ol> <li>scans some folders and files to check if it can do the job</li> <li>makes some changes in /etc/...</li> <li>creates a folder and files that should be owned by the user ...
3
2009-10-28T09:40:15Z
1,636,248
<p>Maybe you can put (2) in a separate script, say <code>script2.py</code>, and in the main script you call <code>sudo script2.py</code> with a <code>popen</code> ? </p> <p>This way only (2) will be executed as root.</p>
2
2009-10-28T10:02:39Z
[ "python", "root", "sudo" ]
How to execute os.* methods as root?
1,636,136
<p>Is it possible to ask for a root pw without storing in in my script memory and to run some of os.* commands as root?</p> <p>My script</p> <ol> <li>scans some folders and files to check if it can do the job</li> <li>makes some changes in /etc/...</li> <li>creates a folder and files that should be owned by the user ...
3
2009-10-28T09:40:15Z
1,636,251
<p>Would you consider using <a href="http://en.wikipedia.org/wiki/Linux%5FPAM" rel="nofollow">Linux PAM</a>? You might want to take a look at the <a href="http://www.kernel.org/pub/linux/libs/pam/Linux-PAM-html/Linux-PAM%5FADG.html" rel="nofollow">Linux-PAM Application Developers' Guide</a> and <a href="http://ace-host...
1
2009-10-28T10:03:07Z
[ "python", "root", "sudo" ]
How to execute os.* methods as root?
1,636,136
<p>Is it possible to ask for a root pw without storing in in my script memory and to run some of os.* commands as root?</p> <p>My script</p> <ol> <li>scans some folders and files to check if it can do the job</li> <li>makes some changes in /etc/...</li> <li>creates a folder and files that should be owned by the user ...
3
2009-10-28T09:40:15Z
1,636,395
<p><code>yourscript.py</code>:</p> <pre><code>run_part_1() subprocess.call(['sudo', sys.executable, 'part2.py']) run_part_3() </code></pre> <p><code>part2.py</code>:</p> <pre><code>run_part_2() </code></pre>
1
2009-10-28T10:29:24Z
[ "python", "root", "sudo" ]
How to execute os.* methods as root?
1,636,136
<p>Is it possible to ask for a root pw without storing in in my script memory and to run some of os.* commands as root?</p> <p>My script</p> <ol> <li>scans some folders and files to check if it can do the job</li> <li>makes some changes in /etc/...</li> <li>creates a folder and files that should be owned by the user ...
3
2009-10-28T09:40:15Z
1,637,326
<p>You should execute your script as root and do the proper changes to permissions for (3) using os.chmod and os.chown.</p> <p>It would be possible for you to execute another script with root rights through sudo, but that would also require storing your user's password in the script to pass in to sudo, which is a terr...
1
2009-10-28T13:43:48Z
[ "python", "root", "sudo" ]
How to execute os.* methods as root?
1,636,136
<p>Is it possible to ask for a root pw without storing in in my script memory and to run some of os.* commands as root?</p> <p>My script</p> <ol> <li>scans some folders and files to check if it can do the job</li> <li>makes some changes in /etc/...</li> <li>creates a folder and files that should be owned by the user ...
3
2009-10-28T09:40:15Z
1,686,034
<p><a href="http://stackoverflow.com/users/174728/gnibbler">gnibbler</a> gave a hint at <code>os.chown</code>. The problem was then to know the ID of the user behind sudo. That information is stored in environment variables <code>SUDO_*</code>:</p> <pre><code>os.chown, (some_path, int(os.getenv('SUDO_UID')), int(os.ge...
1
2009-11-06T07:40:53Z
[ "python", "root", "sudo" ]
I am downloading a file using Python urllib2. How do I check how large the file size is?
1,636,637
<p>And if it is large...then stop the download? I don't want to download files that are larger than 12MB.</p> <pre><code>request = urllib2.Request(ep_url) request.add_header('User-Agent',random.choice(agents)) thefile = urllib2.urlopen(request).read() </code></pre>
9
2009-10-28T11:19:24Z
1,636,656
<p>you can check the content-length in a HEAD request first, but be warned, this header doesn't have to be set - see <a href="http://stackoverflow.com/questions/107405/how-do-you-send-a-head-http-request-in-python">http://stackoverflow.com/questions/107405/how-do-you-send-a-head-http-request-in-python</a></p>
1
2009-10-28T11:24:05Z
[ "python", "file", "download", "urllib2" ]
I am downloading a file using Python urllib2. How do I check how large the file size is?
1,636,637
<p>And if it is large...then stop the download? I don't want to download files that are larger than 12MB.</p> <pre><code>request = urllib2.Request(ep_url) request.add_header('User-Agent',random.choice(agents)) thefile = urllib2.urlopen(request).read() </code></pre>
9
2009-10-28T11:19:24Z
1,636,707
<p>You could say:</p> <pre><code>maxlength= 12*1024*1024 thefile= urllib2.urlopen(request).read(maxlength+1) if len(thefile)==maxlength+1: raise ThrowToysOutOfPramException() </code></pre> <p>but then of course you've still read 12MB of unwanted data. If you want to minimise the risk of this happening you can che...
7
2009-10-28T11:36:19Z
[ "python", "file", "download", "urllib2" ]
I am downloading a file using Python urllib2. How do I check how large the file size is?
1,636,637
<p>And if it is large...then stop the download? I don't want to download files that are larger than 12MB.</p> <pre><code>request = urllib2.Request(ep_url) request.add_header('User-Agent',random.choice(agents)) thefile = urllib2.urlopen(request).read() </code></pre>
9
2009-10-28T11:19:24Z
1,639,765
<p>There's no need as <a href="http://stackoverflow.com/users/18936/bobince">bobince</a> did and drop to httplib. You can do all that with urllib directly:</p> <pre><code>&gt;&gt;&gt; import urllib2 &gt;&gt;&gt; f = urllib2.urlopen("http://dalkescientific.com") &gt;&gt;&gt; f.headers.items() [('content-length', '7535'...
19
2009-10-28T20:04:35Z
[ "python", "file", "download", "urllib2" ]
I am downloading a file using Python urllib2. How do I check how large the file size is?
1,636,637
<p>And if it is large...then stop the download? I don't want to download files that are larger than 12MB.</p> <pre><code>request = urllib2.Request(ep_url) request.add_header('User-Agent',random.choice(agents)) thefile = urllib2.urlopen(request).read() </code></pre>
9
2009-10-28T11:19:24Z
8,377,730
<p>This will work if the Content-Length header is set</p> <pre><code>import urllib2 req = urllib2.urlopen("http://example.com/file.zip") total_size = int(req.info().getheader('Content-Length')) </code></pre>
1
2011-12-04T18:52:44Z
[ "python", "file", "download", "urllib2" ]
How am I able to assign a value to a literal? ('a' = 10)
1,636,852
<pre><code>def foo(**args): for k, v in args.items(): print type(k), type(v) for k, v in args.items(): k = v print k print type(k) foo(a = 10) foo(**{'a':10}) </code></pre> <p>Gives me</p> <pre><code>&lt;type 'str'&gt; &lt;type 'int'&gt; 10 &lt;type 'int'&gt; &lt;type 'str'&gt; &lt;ty...
2
2009-10-28T12:07:23Z
1,636,912
<p>k is not a string, it is just a loop variable. You've just assigned some new value to it and it lost its relation to the dictionary you are iterating over.</p>
3
2009-10-28T12:20:26Z
[ "python" ]
How am I able to assign a value to a literal? ('a' = 10)
1,636,852
<pre><code>def foo(**args): for k, v in args.items(): print type(k), type(v) for k, v in args.items(): k = v print k print type(k) foo(a = 10) foo(**{'a':10}) </code></pre> <p>Gives me</p> <pre><code>&lt;type 'str'&gt; &lt;type 'int'&gt; 10 &lt;type 'int'&gt; &lt;type 'str'&gt; &lt;ty...
2
2009-10-28T12:07:23Z
1,636,919
<p>Well, when you do <code>for k, v in args.items()</code>, in the first (and the only, in your case) iteration the identifier <code>k</code> starts pointing to a current key of the dictionary "args", which happens to be a string, right?</p> <p>When you do <code>k = v</code>, <code>k</code> starts pointing to whatever...
1
2009-10-28T12:21:07Z
[ "python" ]
How am I able to assign a value to a literal? ('a' = 10)
1,636,852
<pre><code>def foo(**args): for k, v in args.items(): print type(k), type(v) for k, v in args.items(): k = v print k print type(k) foo(a = 10) foo(**{'a':10}) </code></pre> <p>Gives me</p> <pre><code>&lt;type 'str'&gt; &lt;type 'int'&gt; 10 &lt;type 'int'&gt; &lt;type 'str'&gt; &lt;ty...
2
2009-10-28T12:07:23Z
1,636,939
<p><code>k</code> is not a string, it is the name of a variable. You can easily do</p> <pre><code>k = 'a' k = 10 </code></pre> <p>without any problem, since an assignment statement in Python will assign the name to point to whichever value is on the right-hand side.</p> <p>Strings are immutable, as you mentioned, bu...
5
2009-10-28T12:26:37Z
[ "python" ]
Django formsets required
1,636,923
<p>How to make all forms in django formset required? I tried to validate presence of all fields in <code>cleaned_data</code> overriding formset's clean() method but it just fails silently without any error displayed.</p> <p>Thanks!</p> <p>Source code:</p> <pre><code>class BaseScheduleForm(forms.ModelForm): def ...
5
2009-10-28T12:22:23Z
1,637,177
<p>It's a bit hard to understand <strong>where</strong> the errors are not being displayed.</p> <p>If is_valid is False, then good, the validation it self is working. Then the next place to look is for the templating layer. How are you checking for errors? {{form.errors}} or {{somefield.errors}}.</p> <p>The way the c...
0
2009-10-28T13:16:24Z
[ "python", "django", "forms", "formset" ]
Django formsets required
1,636,923
<p>How to make all forms in django formset required? I tried to validate presence of all fields in <code>cleaned_data</code> overriding formset's clean() method but it just fails silently without any error displayed.</p> <p>Thanks!</p> <p>Source code:</p> <pre><code>class BaseScheduleForm(forms.ModelForm): def ...
5
2009-10-28T12:22:23Z
3,158,906
<p>I had this same problem and figured out where these errors were stored by checking the source. When you override the clean method of a formset and raise a validation error the errors are stored in the non_form_errors property.</p> <p>So in your template you would need to add the following assuming the template var...
0
2010-07-01T14:48:15Z
[ "python", "django", "forms", "formset" ]
pythoncomplete in vim - hardcode factory function returns?
1,636,929
<p>I'm using pythoncomplete omnicompletion in vim. It works great when I instantiate classes directly, eg</p> <pre><code>import numpy as np x = np.ndarray(l) </code></pre> <p>then x attributes complete correctly.</p> <p>But I work with numpy and matplotlib so usually use factory functions ie </p> <pre><code>x = np...
7
2009-10-28T12:23:40Z
23,803,756
<p>Try <a href="https://github.com/davidhalter/jedi-vim" rel="nofollow">jedi-vim</a>.</p> <p>There's an open issue for the problem you're facing. I think there's a good chance that it will be fixed in 3-4 months time: <a href="https://github.com/davidhalter/jedi/issues/372" rel="nofollow">https://github.com/davidhalte...
1
2014-05-22T10:07:38Z
[ "python", "vim", "numpy", "omnicomplete" ]
Unable to query from entities loaded onto the app engine datastore
1,636,940
<p>I am a newbie to python. I am not able to query from the entities- UserDetails and PhoneBook I loaded to the app engine datastore. I have written this UI below based on the youtube video by Brett on "Developing and Deploying applications on GAE" -- shoutout application. Well I just tried to do some reverse engineeri...
0
2009-10-28T12:26:44Z
1,637,374
<p>I recommend that you read the Python documentation of GAE found <a href="http://code.google.com/appengine/docs/python/gettingstarted/" rel="nofollow">here</a>.</p> <p>Some comments:</p> <ol> <li><p>To use your models found in <code>models.py</code>, you either need to use the prefix <code>models.</code> (e.g. <cod...
3
2009-10-28T13:50:43Z
[ "python", "google-app-engine" ]
Unable to query from entities loaded onto the app engine datastore
1,636,940
<p>I am a newbie to python. I am not able to query from the entities- UserDetails and PhoneBook I loaded to the app engine datastore. I have written this UI below based on the youtube video by Brett on "Developing and Deploying applications on GAE" -- shoutout application. Well I just tried to do some reverse engineeri...
0
2009-10-28T12:26:44Z
1,637,889
<p>Your "session variable" being stored to the datastore isn't going to follow your redirect; you'd have to fetch it from the datastore in your get() handler, although without setting a session ID in a cookie or something this isn't going to implement sessions at all, but rather allow anyone getting / to use whatever v...
1
2009-10-28T15:08:04Z
[ "python", "google-app-engine" ]
Method to peek at a Python program running right now
1,637,198
<p>Is it possible to find any information about what a Python program <em>running right now</em> is doing without interrupting it? </p> <p>Also, if it isn't possible, is there anyway to crash a running Python program so that I can at least get a stacktrace (using PyDev on Ubuntu)?</p> <p>I know I should have used log...
13
2009-10-28T13:20:36Z
1,637,257
<p>To "crash" a python program with a stacktrace you can send it SIGINT, that is unless you trap it or catch KeyboardInterrupt (python installs a SIGINT handler by default, that raises KeyboardInterrupt).</p> <p>As for debugging, doesn't PyDev have built-in debugging support (through pdb)?</p>
4
2009-10-28T13:32:13Z
[ "python", "debugging" ]
Method to peek at a Python program running right now
1,637,198
<p>Is it possible to find any information about what a Python program <em>running right now</em> is doing without interrupting it? </p> <p>Also, if it isn't possible, is there anyway to crash a running Python program so that I can at least get a stacktrace (using PyDev on Ubuntu)?</p> <p>I know I should have used log...
13
2009-10-28T13:20:36Z
1,637,277
<p>If you place </p> <pre><code>import code code.interact(local=locals()) </code></pre> <p>at any point in your script, python will instantiate a python shell at exactly that point that has access to everything in the state of the script at that point. ^D exits the shell and resumes execution past that point.</p> <p...
26
2009-10-28T13:35:40Z
[ "python", "debugging" ]
Method to peek at a Python program running right now
1,637,198
<p>Is it possible to find any information about what a Python program <em>running right now</em> is doing without interrupting it? </p> <p>Also, if it isn't possible, is there anyway to crash a running Python program so that I can at least get a stacktrace (using PyDev on Ubuntu)?</p> <p>I know I should have used log...
13
2009-10-28T13:20:36Z
1,637,360
<p>Install signal handler that sets a trace function with <code>sys.settrace()</code> that prints traceback and clears clears trace function. This will allow you to see where your program is at any moment without interrupting it. Note, that signal is handled after each <code>sys.getcheckinterval()</code> python instruc...
0
2009-10-28T13:48:53Z
[ "python", "debugging" ]
Method to peek at a Python program running right now
1,637,198
<p>Is it possible to find any information about what a Python program <em>running right now</em> is doing without interrupting it? </p> <p>Also, if it isn't possible, is there anyway to crash a running Python program so that I can at least get a stacktrace (using PyDev on Ubuntu)?</p> <p>I know I should have used log...
13
2009-10-28T13:20:36Z
1,637,543
<p>Personally, I prefer <a href="http://pypi.python.org/pypi/ipdb/0.1dev-r1716" rel="nofollow">ipdb</a>. It's pdb with added <a href="http://ipython.scipy.org/" rel="nofollow">IPython</a> goodness. It seems to be more of an interactive Python interpreter with a few shortcuts for debugging functions.</p>
2
2009-10-28T14:20:24Z
[ "python", "debugging" ]
Method to peek at a Python program running right now
1,637,198
<p>Is it possible to find any information about what a Python program <em>running right now</em> is doing without interrupting it? </p> <p>Also, if it isn't possible, is there anyway to crash a running Python program so that I can at least get a stacktrace (using PyDev on Ubuntu)?</p> <p>I know I should have used log...
13
2009-10-28T13:20:36Z
1,639,943
<p>If you have a running Python, which wasn't built with any sort of trace or logging mechanism, and you want to see what it's doing internally, then two options are:</p> <ul> <li><p>On a Solaris or Mac, if you are using the system-provided Python then use dtrace</p></li> <li><p>use <a href="http://wiki.python.org/moi...
8
2009-10-28T20:33:20Z
[ "python", "debugging" ]
Method to peek at a Python program running right now
1,637,198
<p>Is it possible to find any information about what a Python program <em>running right now</em> is doing without interrupting it? </p> <p>Also, if it isn't possible, is there anyway to crash a running Python program so that I can at least get a stacktrace (using PyDev on Ubuntu)?</p> <p>I know I should have used log...
13
2009-10-28T13:20:36Z
1,640,034
<p>If you're happy with a crash, inserting "1/0" will create a quick and dirty breakpoint, with a complete backtrace!</p>
0
2009-10-28T20:50:16Z
[ "python", "debugging" ]
Is there a way to generate pdf containing non-ascii symbols with pisa from django template?
1,637,229
<p>I'm trying to generate a pdf from template using this snippet:</p> <pre><code>def write_pdf(template_src, context_dict): template = get_template(template_src) context = Context(context_dict) html = template.render(context) result = StringIO.StringIO() pdf = pisa.pisaDocument(StringIO.StringIO(h...
18
2009-10-28T13:26:48Z
1,637,287
<p>Try replacing</p> <pre><code>pdf = pisa.pisaDocument(StringIO.StringIO(html.encode("UTF-8")), result) </code></pre> <p>with</p> <pre><code>pdf = pisa.pisaDocument(StringIO.StringIO(html), result, encoding='UTF-8') </code></pre> <p>Or checkout this answer to <a href="http://stackoverflow.com/questions/1377446/htm...
3
2009-10-28T13:37:25Z
[ "python", "django", "pdf", "pisa" ]
Is there a way to generate pdf containing non-ascii symbols with pisa from django template?
1,637,229
<p>I'm trying to generate a pdf from template using this snippet:</p> <pre><code>def write_pdf(template_src, context_dict): template = get_template(template_src) context = Context(context_dict) html = template.render(context) result = StringIO.StringIO() pdf = pisa.pisaDocument(StringIO.StringIO(h...
18
2009-10-28T13:26:48Z
1,789,319
<p>This does work for me:</p> <pre><code>pdf = pisa.pisaDocument(StringIO.StringIO(html.encode("UTF-8")), result, encoding='UTF-8') </code></pre>
29
2009-11-24T10:57:55Z
[ "python", "django", "pdf", "pisa" ]
Is there a way to generate pdf containing non-ascii symbols with pisa from django template?
1,637,229
<p>I'm trying to generate a pdf from template using this snippet:</p> <pre><code>def write_pdf(template_src, context_dict): template = get_template(template_src) context = Context(context_dict) html = template.render(context) result = StringIO.StringIO() pdf = pisa.pisaDocument(StringIO.StringIO(h...
18
2009-10-28T13:26:48Z
2,147,026
<p>You need to modify your django template. Add a new font face in the stylesheet that will link to a font file with characters used in your document. And that font file must be accessible from your server (under Ubuntu you can find files with fonts in /usr/share/fonts/truetype/ directory). For example:</p> <pre><code...
2
2010-01-27T13:11:06Z
[ "python", "django", "pdf", "pisa" ]
Is there a way to generate pdf containing non-ascii symbols with pisa from django template?
1,637,229
<p>I'm trying to generate a pdf from template using this snippet:</p> <pre><code>def write_pdf(template_src, context_dict): template = get_template(template_src) context = Context(context_dict) html = template.render(context) result = StringIO.StringIO() pdf = pisa.pisaDocument(StringIO.StringIO(h...
18
2009-10-28T13:26:48Z
3,342,559
<p>If you are calling createPDF instead of the pisaDocument method, you can use</p> <pre><code>pisa.CreatePDF(html.encode('UTF-8'), response, link_callback=fetch_resources, encoding='UTF-8') </code></pre>
0
2010-07-27T10:11:51Z
[ "python", "django", "pdf", "pisa" ]
Remove html formating "&gt;" from text file using Python csv.reader
1,637,253
<p>I have a text file with ; used as the delimiter. The problem is that it has some html text formating in it such as <code>&amp;gt;</code> Obviously the ; in this causes problems. The text file is large and I don't have a list of these html strings, that is there are many different examples such as <code>$amp;</code>...
3
2009-10-28T13:30:54Z
1,637,299
<p>Take a look at the code from <a href="http://effbot.org/zone/re-sub.htm#unescape-html" rel="nofollow">here</a>:</p> <pre><code>import re, htmlentitydefs ## # Removes HTML or XML character references and entities from a text string. # # @param text The HTML (or XML) source text. # @return The plain text, as a Unico...
3
2009-10-28T13:39:17Z
[ "python", "html", "regex", "file", "csv" ]
Remove html formating "&gt;" from text file using Python csv.reader
1,637,253
<p>I have a text file with ; used as the delimiter. The problem is that it has some html text formating in it such as <code>&amp;gt;</code> Obviously the ; in this causes problems. The text file is large and I don't have a list of these html strings, that is there are many different examples such as <code>$amp;</code>...
3
2009-10-28T13:30:54Z
1,637,318
<p>The quickest way is probably to use the undocumented but so far stable <code>unescape</code> method in <a href="http://docs.python.org/library/htmlparser.html">HTMLParser</a>:</p> <pre><code>import HTMLParser s= HTMLParser.HTMLParser().unescape(s) </code></pre> <p>Note this will necessarily output a Unicode string...
6
2009-10-28T13:41:44Z
[ "python", "html", "regex", "file", "csv" ]