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
How do I prevent execution of arbitrary commands from a Django app making system calls?
768,677
<p>I have a Django application I'm developing that must make a system call to an external program on the server. In creating the command for the system call, the application takes values from a form and uses them as parameters for the call. I suppose this means that one can essentially use bogus parameters and write ar...
5
2009-04-20T15:03:41Z
768,881
<p>To do this, you must do the following. If you don't know what "options" and "arguments" are, read the <a href="http://docs.python.org/library/optparse.html#background" rel="nofollow">optparse background</a>.</p> <p>Each "Command" or "Request" is actually an instance of a model. Define your Request model with all ...
4
2009-04-20T15:52:19Z
[ "python", "django", "security" ]
How to use a python api on iPhone?
768,941
<p>There is an "<a href="http://code.google.com/p/plurkapipy/" rel="nofollow">Unofficial Plurk API in Python</a>". <a href="http://www.plurk.com/" rel="nofollow">Plurk</a> is a twitter-like website.</p> <p>Can I use the API(python) from Objective-C? Or i have to port them?</p>
1
2009-04-20T16:07:44Z
768,956
<p>The iPhone SDK will not allow you to run any Python code. You need to convert it to C, C++, Objective-C or ObjectiveC++.</p>
2
2009-04-20T16:10:18Z
[ "iphone", "python", "objective-c" ]
How to use a python api on iPhone?
768,941
<p>There is an "<a href="http://code.google.com/p/plurkapipy/" rel="nofollow">Unofficial Plurk API in Python</a>". <a href="http://www.plurk.com/" rel="nofollow">Plurk</a> is a twitter-like website.</p> <p>Can I use the API(python) from Objective-C? Or i have to port them?</p>
1
2009-04-20T16:07:44Z
768,957
<p>Apple's iPhone developer license prohibits applications that use interpreted code. So, python is out, unfortunately.</p>
4
2009-04-20T16:10:23Z
[ "iphone", "python", "objective-c" ]
How to use a python api on iPhone?
768,941
<p>There is an "<a href="http://code.google.com/p/plurkapipy/" rel="nofollow">Unofficial Plurk API in Python</a>". <a href="http://www.plurk.com/" rel="nofollow">Plurk</a> is a twitter-like website.</p> <p>Can I use the API(python) from Objective-C? Or i have to port them?</p>
1
2009-04-20T16:07:44Z
768,984
<p>The way I see it, one option is to try this <a href="http://www.saurik.com/id/5" rel="nofollow">this</a>.</p> <p>Alternatively, <a href="http://code.google.com/p/plurkapipy/source/browse/trunk/plurkapi.py" rel="nofollow">ths plurk api</a> (which is really more of a python-automated abstraction than an API) isn't ve...
3
2009-04-20T16:16:28Z
[ "iphone", "python", "objective-c" ]
How to use a python api on iPhone?
768,941
<p>There is an "<a href="http://code.google.com/p/plurkapipy/" rel="nofollow">Unofficial Plurk API in Python</a>". <a href="http://www.plurk.com/" rel="nofollow">Plurk</a> is a twitter-like website.</p> <p>Can I use the API(python) from Objective-C? Or i have to port them?</p>
1
2009-04-20T16:07:44Z
769,048
<p>Check these links :</p> <p>iPhone Applications in Python: <a href="http://www.saurik.com/id/5" rel="nofollow">http://www.saurik.com/id/5</a></p> <p>PyObjC: <a href="http://pyobjc.sourceforge.net/" rel="nofollow">http://pyobjc.sourceforge.net/</a></p>
4
2009-04-20T16:31:33Z
[ "iphone", "python", "objective-c" ]
How to use a python api on iPhone?
768,941
<p>There is an "<a href="http://code.google.com/p/plurkapipy/" rel="nofollow">Unofficial Plurk API in Python</a>". <a href="http://www.plurk.com/" rel="nofollow">Plurk</a> is a twitter-like website.</p> <p>Can I use the API(python) from Objective-C? Or i have to port them?</p>
1
2009-04-20T16:07:44Z
769,150
<p>Unfortunately, you can only do what Apple allows you to do (they are VERY controlling). However, if you jail break your device (this violates your usage agreement with Apple) you can do many, many things with what I consider to be an amazing device (unfortunatly, Apple limits it's true possibilities). </p>
-6
2009-04-20T16:52:32Z
[ "iphone", "python", "objective-c" ]
How to use a python api on iPhone?
768,941
<p>There is an "<a href="http://code.google.com/p/plurkapipy/" rel="nofollow">Unofficial Plurk API in Python</a>". <a href="http://www.plurk.com/" rel="nofollow">Plurk</a> is a twitter-like website.</p> <p>Can I use the API(python) from Objective-C? Or i have to port them?</p>
1
2009-04-20T16:07:44Z
2,533,724
<p>Well, Plurk has an official API now, and I wrote an Objective-C library to connect to Plurk. Maybe you are interested to give it a try.</p> <p><a href="http://github.com/zonble/ObjectivePlurk" rel="nofollow">http://github.com/zonble/ObjectivePlurk</a></p>
1
2010-03-28T17:04:01Z
[ "iphone", "python", "objective-c" ]
Persistent Windows in PyGTK
769,175
<p>Is there a way to force a gtk.Window object to ignore the Window Manager's show/hide commands, such as "iconify" and "show desktop?"</p> <p>I'm trying to create a persistent window, stuck to the desktop, that will not disappear with all other windows when the desktop is exposed.</p> <p><strong>EDIT:</strong> I gue...
1
2009-04-20T16:57:57Z
771,431
<p>You've got it backwards; it's not the window manager telling the window to minimize, by sending it a command. The window manager <strong>owns</strong> the window, if it wants to stop mapping a window, it will just do it, without asking the window for permission.</p> <p>So I would think that the answer is "no".</p>
2
2009-04-21T07:21:36Z
[ "python", "gtk", "pygtk", "x11" ]
Persistent Windows in PyGTK
769,175
<p>Is there a way to force a gtk.Window object to ignore the Window Manager's show/hide commands, such as "iconify" and "show desktop?"</p> <p>I'm trying to create a persistent window, stuck to the desktop, that will not disappear with all other windows when the desktop is exposed.</p> <p><strong>EDIT:</strong> I gue...
1
2009-04-20T16:57:57Z
783,713
<p>Try setting the <a href="http://library.gnome.org/devel/gdk/unstable/gdk-Windows.html#GdkWindowTypeHint" rel="nofollow"><code>GdkWindowTypeHint</code></a> on the <code>GtkWindow</code>:</p> <pre><code>gtk_window_set_type_hint(the_window, GDK_WINDOW_TYPE_HINT_UTILITY); </code></pre> <p>There's also various methods ...
1
2009-04-23T22:03:24Z
[ "python", "gtk", "pygtk", "x11" ]
Persistent Windows in PyGTK
769,175
<p>Is there a way to force a gtk.Window object to ignore the Window Manager's show/hide commands, such as "iconify" and "show desktop?"</p> <p>I'm trying to create a persistent window, stuck to the desktop, that will not disappear with all other windows when the desktop is exposed.</p> <p><strong>EDIT:</strong> I gue...
1
2009-04-20T16:57:57Z
1,030,408
<p>Not having received a "this is how to do this" answer and having done a bit more research I can say that -- as far as I know -- there is no easy way to achieve this sort of functionality with PyGTK. The best options are to set window manager hints and leave it up to the WM to do what you want (hopefully).</p>
0
2009-06-23T02:40:24Z
[ "python", "gtk", "pygtk", "x11" ]
Persistent Windows in PyGTK
769,175
<p>Is there a way to force a gtk.Window object to ignore the Window Manager's show/hide commands, such as "iconify" and "show desktop?"</p> <p>I'm trying to create a persistent window, stuck to the desktop, that will not disappear with all other windows when the desktop is exposed.</p> <p><strong>EDIT:</strong> I gue...
1
2009-04-20T16:57:57Z
5,474,070
<p>I think <code>gtk_window_set_type_hint(window, GDK_WINDOW_TYPE_HINT_SPLASHSCREEN)</code> is what you want. It is also <code>GDK_WINDOW_TYPE_HINT_DOCK</code>, but then the window stay on top of all, and you can't send it back.</p>
0
2011-03-29T14:23:44Z
[ "python", "gtk", "pygtk", "x11" ]
Persistent Windows in PyGTK
769,175
<p>Is there a way to force a gtk.Window object to ignore the Window Manager's show/hide commands, such as "iconify" and "show desktop?"</p> <p>I'm trying to create a persistent window, stuck to the desktop, that will not disappear with all other windows when the desktop is exposed.</p> <p><strong>EDIT:</strong> I gue...
1
2009-04-20T16:57:57Z
19,255,102
<p>From the <a href="http://www.pygtk.org/docs/pygtk/gdk-constants.html#gdk-window-type-hint-constants" rel="nofollow">list of window type hints</a>, only a two are still shown when you click the show desktop button:</p> <ul> <li>gtk.gdk.WINDOW_TYPE_HINT_DESKTOP</li> <li>gtk.gdk.WINDOW_TYPE_HINT_DOCK</li> </ul> <p>Bo...
1
2013-10-08T18:07:54Z
[ "python", "gtk", "pygtk", "x11" ]
Dynamic Loading of Python Modules
769,534
<p>I'm trying to dynamically load modules I've created.</p> <p>Right now this works properly:</p> <pre><code>import structures.index </code></pre> <p>But if I try the same thing by importing it dynamically, it fails.</p> <pre><code>struct = __import__("structures.index") </code></pre> <p>Error supplied is:</p> <p...
3
2009-04-20T18:34:04Z
769,565
<p>Java programmer here, but I think you need the <a href="http://docs.python.org/library/imp.html" rel="nofollow">imp module</a></p>
1
2009-04-20T18:41:13Z
[ "python", "dynamic", "module", "loading" ]
Dynamic Loading of Python Modules
769,534
<p>I'm trying to dynamically load modules I've created.</p> <p>Right now this works properly:</p> <pre><code>import structures.index </code></pre> <p>But if I try the same thing by importing it dynamically, it fails.</p> <pre><code>struct = __import__("structures.index") </code></pre> <p>Error supplied is:</p> <p...
3
2009-04-20T18:34:04Z
769,610
<p>I'm not sure what "it fails" means, so I'll just mention that <code>__import__('structures.index')</code> should, in fact, work, but it doesn't assign the module name in the current scope. To do that (and then use a class in the dynamically imported module), you'll have to use:</p> <pre><code>structures = __import...
10
2009-04-20T18:50:01Z
[ "python", "dynamic", "module", "loading" ]
Dynamic Loading of Python Modules
769,534
<p>I'm trying to dynamically load modules I've created.</p> <p>Right now this works properly:</p> <pre><code>import structures.index </code></pre> <p>But if I try the same thing by importing it dynamically, it fails.</p> <pre><code>struct = __import__("structures.index") </code></pre> <p>Error supplied is:</p> <p...
3
2009-04-20T18:34:04Z
769,622
<p>To import sub-modules, you need to specify them in the <code>fromlist</code> arg of <code>__import__()</code> <br>Fo example, the equivalent of:</p> <pre><code>import structures.index </code></pre> <p>is:</p> <pre><code>structures = __import__('structures', fromlist=['index']) </code></pre> <p>To do this in a ma...
4
2009-04-20T18:52:45Z
[ "python", "dynamic", "module", "loading" ]
Dynamic Loading of Python Modules
769,534
<p>I'm trying to dynamically load modules I've created.</p> <p>Right now this works properly:</p> <pre><code>import structures.index </code></pre> <p>But if I try the same thing by importing it dynamically, it fails.</p> <pre><code>struct = __import__("structures.index") </code></pre> <p>Error supplied is:</p> <p...
3
2009-04-20T18:34:04Z
769,748
<p>Why on earth would you replace</p> <pre><code>import structures.index </code></pre> <p>with</p> <pre><code>map(__import__, ["structures.index"]) </code></pre> <p>The first one (a) works, (b) <em>is</em> dynamic and (c) is directly supported. What possible use case is there for replacing easy-to-change, plain-te...
0
2009-04-20T19:23:19Z
[ "python", "dynamic", "module", "loading" ]
Dynamic Loading of Python Modules
769,534
<p>I'm trying to dynamically load modules I've created.</p> <p>Right now this works properly:</p> <pre><code>import structures.index </code></pre> <p>But if I try the same thing by importing it dynamically, it fails.</p> <pre><code>struct = __import__("structures.index") </code></pre> <p>Error supplied is:</p> <p...
3
2009-04-20T18:34:04Z
770,159
<p>Use full scope ("neoform.structures.index") with this helper method.</p> <pre><code>def import_module(name): mod = __import__(name) components = name.split('.') for comp in components[1:]: mod = getattr(mod, comp) return mod module = import_module("neoform.structures.index") # do stuff with...
3
2009-04-20T21:23:16Z
[ "python", "dynamic", "module", "loading" ]
Dynamic Loading of Python Modules
769,534
<p>I'm trying to dynamically load modules I've created.</p> <p>Right now this works properly:</p> <pre><code>import structures.index </code></pre> <p>But if I try the same thing by importing it dynamically, it fails.</p> <pre><code>struct = __import__("structures.index") </code></pre> <p>Error supplied is:</p> <p...
3
2009-04-20T18:34:04Z
2,492,480
<pre><code>&gt;&gt;&gt; import imp &gt;&gt;&gt; fm = imp.find_module('index', ['./structures']) # for submodule &gt;&gt;&gt; mymod = imp.load_module('structures.index', *fm) &gt;&gt;&gt; mymod &lt;module 'structures.index' from './structures/index.pyc'&gt; &gt;&gt;&gt; x = mymod.insideIndex() Initialising index class.....
1
2010-03-22T13:21:44Z
[ "python", "dynamic", "module", "loading" ]
Dynamic Loading of Python Modules
769,534
<p>I'm trying to dynamically load modules I've created.</p> <p>Right now this works properly:</p> <pre><code>import structures.index </code></pre> <p>But if I try the same thing by importing it dynamically, it fails.</p> <pre><code>struct = __import__("structures.index") </code></pre> <p>Error supplied is:</p> <p...
3
2009-04-20T18:34:04Z
15,423,470
<p>Really late post here. But I was searching for this question on google. I did some trial and error. Not sure if this snippet will help but here it is. Using it for Flask site. </p> <pre><code>modules = ['frontend', 'admin'] for module in modules: mod = __init__('controllers.%s' % module, fromlist=[module]) ...
0
2013-03-15T02:00:00Z
[ "python", "dynamic", "module", "loading" ]
How do I load entry-points for a defined set of eggs with Python setuptools?
769,766
<p>I would like to use the entry point functionality in setuptools.</p> <p>There are a number of occasions where I would like to tightly control the list of eggs that are run, and thence the extensions that contribute to a set of entry points:</p> <ul> <li>egg integration testing, where I want to run multiple test su...
0
2009-04-20T19:27:37Z
1,000,651
<p>We're solving something similar, ability to use setup.py develop if You're mere user without access to global site-packages. So far, we solved it with virtualenv.</p> <p>I'd say it will help for your case too: have minimal system-wide install (or explicitly exclude it), create virtual environment with eggs you want...
0
2009-06-16T10:20:14Z
[ "python", "setuptools", "distutils", "egg" ]
The lines that stand out in a file, but aren't exact duplicates
769,775
<p>I'm combing a webapp's log file for statements that stand out.</p> <p>Most of the lines are similar and uninteresting. I'd pass them through Unix <code>uniq</code>, however that filters nothing, as all the lines are slightly different: they all have a different timestamp, similar statements might print a different ...
3
2009-04-20T19:30:37Z
769,790
<p>Define "notably different". Then have a look at <a href="http://en.wikipedia.org/wiki/Edit%5Fdistance" rel="nofollow">"edit distance" measures</a>.</p>
3
2009-04-20T19:35:08Z
[ "python", "algorithm", "unix", "grep", "nlp" ]
The lines that stand out in a file, but aren't exact duplicates
769,775
<p>I'm combing a webapp's log file for statements that stand out.</p> <p>Most of the lines are similar and uninteresting. I'd pass them through Unix <code>uniq</code>, however that filters nothing, as all the lines are slightly different: they all have a different timestamp, similar statements might print a different ...
3
2009-04-20T19:30:37Z
769,791
<p>You could try a bit of code that counts words, and then sorts lines by those having the least common words. </p> <p>If that doesn't do the trick, you can add in some smarts to filter out time stamps and numbers. </p> <p>Your problem is similar to an earlier question on <a href="http://stackoverflow.com/questions/7...
2
2009-04-20T19:35:15Z
[ "python", "algorithm", "unix", "grep", "nlp" ]
The lines that stand out in a file, but aren't exact duplicates
769,775
<p>I'm combing a webapp's log file for statements that stand out.</p> <p>Most of the lines are similar and uninteresting. I'd pass them through Unix <code>uniq</code>, however that filters nothing, as all the lines are slightly different: they all have a different timestamp, similar statements might print a different ...
3
2009-04-20T19:30:37Z
769,799
<p>I don't know a tool for you but if <em>I</em> were going to roll my own, I'd approach it like this:</p> <p>Presumably the log lines have a well defined structure, no? So</p> <ul> <li>parse the lines on that structure</li> <li>write a number of very basic relevance filters (functions that just return a simple numbe...
2
2009-04-20T19:37:47Z
[ "python", "algorithm", "unix", "grep", "nlp" ]
The lines that stand out in a file, but aren't exact duplicates
769,775
<p>I'm combing a webapp's log file for statements that stand out.</p> <p>Most of the lines are similar and uninteresting. I'd pass them through Unix <code>uniq</code>, however that filters nothing, as all the lines are slightly different: they all have a different timestamp, similar statements might print a different ...
3
2009-04-20T19:30:37Z
770,603
<p>I wonder if you could just focus on the part that defines uniqueness for you. In this case, it seems that the part defining uniqueness is just the middle part:</p> <pre> 2009-04-20 00:03:57 INFO com.foo.Bar - URL:/graph?id=1234 ^---------------------^ 2009-04-20 00:05:59 INFO com.baz.abc.Ac...
0
2009-04-21T00:26:14Z
[ "python", "algorithm", "unix", "grep", "nlp" ]
The lines that stand out in a file, but aren't exact duplicates
769,775
<p>I'm combing a webapp's log file for statements that stand out.</p> <p>Most of the lines are similar and uninteresting. I'd pass them through Unix <code>uniq</code>, however that filters nothing, as all the lines are slightly different: they all have a different timestamp, similar statements might print a different ...
3
2009-04-20T19:30:37Z
770,695
<p>I think you want to break this into fields, sort by the "severity level" field and the next field (looks like "class"). I'd use Haskell:</p> <pre> module Main where import Data.List (nubBy, sortBy) sortAndNub s = nubBy fields2and3 $ sortBy fields2and3comp $ map words $ lines s fields2and3 a b = fi...
0
2009-04-21T01:16:32Z
[ "python", "algorithm", "unix", "grep", "nlp" ]
The lines that stand out in a file, but aren't exact duplicates
769,775
<p>I'm combing a webapp's log file for statements that stand out.</p> <p>Most of the lines are similar and uninteresting. I'd pass them through Unix <code>uniq</code>, however that filters nothing, as all the lines are slightly different: they all have a different timestamp, similar statements might print a different ...
3
2009-04-20T19:30:37Z
770,822
<p>Perhaps you could do a basic calculation of "words the same"/"all words"?</p> <p>e.g. (including an offset to allow you to ignore the timestamp and the word 'INFO', if that's always the same):</p> <pre><code>def score(s1, s2, offset=26): words1 = re.findall('\w+', s1[offset:]) words2 = re.findall('\w+', s2...
1
2009-04-21T02:21:56Z
[ "python", "algorithm", "unix", "grep", "nlp" ]
Multiple projects from one setup.py?
769,793
<p>My current <a href="http://github.com/dbr/tvdb%5Fapi/blob/fa55575e26b188de9b9b9f0c41d52c2a45400796/setup.py">setup.py</a> (using setuptools) installs two things, one is <code>tvdb_api</code> (an API wrapper), the other is <code>tvnamer</code> (a command line script)</p> <p>I wish to make the two available separatel...
6
2009-04-20T19:35:26Z
770,247
<p><code>setup.py</code> is just a regular Python file, which by convention sets up packages. By convention, <code>setup.py</code> contains a call to the setuptools or distutils <code>setup()</code> function. If you want to use one <code>setup.py</code> for two packages, you can call a different <code>setup()</code> f...
7
2009-04-20T21:45:32Z
[ "python", "setuptools" ]
How do I use AND in a Django filter?
769,843
<p>How do I create an "AND" filter to retrieve objects in Django? e.g I would like to retrieve a row which has a combination of two words in a single field.</p> <p>For example the following SQL query does exactly that when I run it on mysql database:</p> <pre><code>select * from myapp_question where ((question like '...
16
2009-04-20T19:55:11Z
769,849
<pre><code>mymodel.objects.filter(first_name__icontains="Foo", first_name__icontains="Bar") </code></pre>
34
2009-04-20T19:57:38Z
[ "python", "django" ]
How do I use AND in a Django filter?
769,843
<p>How do I create an "AND" filter to retrieve objects in Django? e.g I would like to retrieve a row which has a combination of two words in a single field.</p> <p>For example the following SQL query does exactly that when I run it on mysql database:</p> <pre><code>select * from myapp_question where ((question like '...
16
2009-04-20T19:55:11Z
769,862
<p>You can chain filter expressions in Django:</p> <pre><code>q = Question.objects.filter(question__contains='software').filter(question__contains='java') </code></pre> <p>You can find more info in the Django docs at "<a href="http://docs.djangoproject.com/en/dev/topics/db/queries/#id1">Chaining Filters</a>".</p>
8
2009-04-20T20:01:38Z
[ "python", "django" ]
How do I use AND in a Django filter?
769,843
<p>How do I create an "AND" filter to retrieve objects in Django? e.g I would like to retrieve a row which has a combination of two words in a single field.</p> <p>For example the following SQL query does exactly that when I run it on mysql database:</p> <pre><code>select * from myapp_question where ((question like '...
16
2009-04-20T19:55:11Z
770,078
<p>For thoroughness sake, let's just mention the <a href="http://docs.djangoproject.com/en/dev/topics/db/queries/#complex-lookups-with-q-objects"><code>Q</code></a> object method:</p> <pre><code>from django.db.models import Q criterion1 = Q(question__contains="software") criterion2 = Q(question__contains="java") q = Q...
37
2009-04-20T21:04:52Z
[ "python", "django" ]
Python selecting a value in a combo box and HTTP POST
769,948
<p>In Python, I'm trying to read the values on <a href="http://utahcritseries.com/RawResults.aspx" rel="nofollow">http://utahcritseries.com/RawResults.aspx</a>. How can I read years other than the default of 2002?</p> <p>So far, using mechanize, I've been able to reference the SELECT and list all of its available opt...
1
2009-04-20T20:29:50Z
769,966
<p>With problems relating to AJAX-loading of pages, use <a href="http://getfirebug.com/" rel="nofollow">Firebug!</a></p> <p>Install and open Firebug (it's a Firefox plugin), go to the Net page, and make sure "All" is selected. Open the URL and change the select box, and see what is sent to the server, and what is rece...
0
2009-04-20T20:35:14Z
[ "asp.net", "python", "http", "web-scraping" ]
Python selecting a value in a combo box and HTTP POST
769,948
<p>In Python, I'm trying to read the values on <a href="http://utahcritseries.com/RawResults.aspx" rel="nofollow">http://utahcritseries.com/RawResults.aspx</a>. How can I read years other than the default of 2002?</p> <p>So far, using mechanize, I've been able to reference the SELECT and list all of its available opt...
1
2009-04-20T20:29:50Z
801,934
<p>So how about this:</p> <pre><code>from mechanize import Browser year="2005" br=Browser() br.open("http://utahcritseries.com/RawResults.aspx") br.select_form(name="aspnetForm") control=br.form.find_control("ctl00$ContentPlaceHolder1$ddlSeries") control.set_value_by_label((year,)) response2=br.submit() print respon...
1
2009-04-29T11:32:11Z
[ "asp.net", "python", "http", "web-scraping" ]
Global HotKeys in Win&X11
770,049
<p>I need to make a global hotkey for my application, and it should work under X11 and Windows.</p>
3
2009-04-20T20:55:11Z
770,077
<p>What GUI toolkit are you using? Generally, global hot keys are handled by the Desktop environment or Window Manager - I dont believe that Python's builtin toolkit (tkinter) can make global hotkeys. You might look at <a href="http://python-xlib.sourceforge.net/" rel="nofollow">xlib</a> for Unix and a win lib for wind...
4
2009-04-20T21:03:24Z
[ "python", "hotkeys" ]
Global HotKeys in Win&X11
770,049
<p>I need to make a global hotkey for my application, and it should work under X11 and Windows.</p>
3
2009-04-20T20:55:11Z
8,340,605
<p>Just an addition - on windows, if you are using wxpython in your application, you can register your <a href="http://wxpython.org/docs/api/wx.Window-class.html#RegisterHotKey" rel="nofollow">hotkey</a>. Example is <a href="http://wiki.wxpython.org/RegisterHotKey" rel="nofollow">here</a></p>
0
2011-12-01T11:26:36Z
[ "python", "hotkeys" ]
Python Cmd module, subclassing issue
770,134
<p>I'm trying to work out what's not working in this code:</p> <pre><code>#!/usr/bin/python import cmd class My_class (cmd.Cmd): """docstring for Twitter_handler""" def __init__(self): super(My_class, self).__init__() if __name__ == '__main__': my_handler = My_class() </code></pre> <p>Here's the e...
5
2009-04-20T21:18:36Z
770,183
<p><a href="http://docs.python.org/library/functions.html#super">super()</a> only works for <a href="http://docs.python.org/reference/datamodel.html#newstyle">new-style classes</a></p>
9
2009-04-20T21:30:39Z
[ "python" ]
Python Cmd module, subclassing issue
770,134
<p>I'm trying to work out what's not working in this code:</p> <pre><code>#!/usr/bin/python import cmd class My_class (cmd.Cmd): """docstring for Twitter_handler""" def __init__(self): super(My_class, self).__init__() if __name__ == '__main__': my_handler = My_class() </code></pre> <p>Here's the e...
5
2009-04-20T21:18:36Z
770,189
<p>cmd.Cmd is not a new style class in Python 2.5, 2.6, 2.7.</p> <p>Note that your code does <em>not</em> raise an exception in Python 3.0.</p>
7
2009-04-20T21:32:19Z
[ "python" ]
Python Cmd module, subclassing issue
770,134
<p>I'm trying to work out what's not working in this code:</p> <pre><code>#!/usr/bin/python import cmd class My_class (cmd.Cmd): """docstring for Twitter_handler""" def __init__(self): super(My_class, self).__init__() if __name__ == '__main__': my_handler = My_class() </code></pre> <p>Here's the e...
5
2009-04-20T21:18:36Z
34,025,770
<p>So if <a href="http://docs.python.org/library/functions.html#super" rel="nofollow">super()</a> doesn't work use :</p> <pre><code>import cmd class My_class(cmd.Cmd): def __init__(self): cmd.Cmd.__init__(self) </code></pre>
2
2015-12-01T16:57:43Z
[ "python" ]
Python Cmd module, subclassing issue
770,134
<p>I'm trying to work out what's not working in this code:</p> <pre><code>#!/usr/bin/python import cmd class My_class (cmd.Cmd): """docstring for Twitter_handler""" def __init__(self): super(My_class, self).__init__() if __name__ == '__main__': my_handler = My_class() </code></pre> <p>Here's the e...
5
2009-04-20T21:18:36Z
36,985,714
<p>You can still use <code>super()</code> if your <code>MyClass</code> extends <code>object</code>. This works even though the <code>cmd.Cmd</code> module is <em>not</em> a new-style class. Like this:</p> <pre><code>#!/usr/bin/python import cmd class My_class (cmd.Cmd, object): """docstring for Twitter_handler""...
1
2016-05-02T15:08:36Z
[ "python" ]
How do I structure Python code into modules/packages?
770,320
<p>Assume I have this barebones structure:</p> <pre><code>project/ main.py providers/ __init.py__ acme1.py acme2.py acme3.py acme4.py acme5.py acme6.py </code></pre> <p>Assume that <code>main.py</code> contains (partial):</p> <pre><code>if complexcondition(): print providers.acme5.g...
3
2009-04-20T22:10:08Z
770,359
<p>This question asked today, <a href="http://stackoverflow.com/questions/769534/dynamic-loading-of-python-modules">Dynamic Loading of Python Modules</a>, should have your answer.</p>
3
2009-04-20T22:28:51Z
[ "python", "module", "package" ]
How do I structure Python code into modules/packages?
770,320
<p>Assume I have this barebones structure:</p> <pre><code>project/ main.py providers/ __init.py__ acme1.py acme2.py acme3.py acme4.py acme5.py acme6.py </code></pre> <p>Assume that <code>main.py</code> contains (partial):</p> <pre><code>if complexcondition(): print providers.acme5.g...
3
2009-04-20T22:10:08Z
770,787
<p>If I'm reading your question correctly, it looks like you're not trying to do any dynamic importing (like in the question that Van Gale mentioned) but are actually trying to just import all of the modules in the providers package. If that's the case, in <code>__init__.py</code> you would want to have this statement:...
5
2009-04-21T02:06:01Z
[ "python", "module", "package" ]
How do I structure Python code into modules/packages?
770,320
<p>Assume I have this barebones structure:</p> <pre><code>project/ main.py providers/ __init.py__ acme1.py acme2.py acme3.py acme4.py acme5.py acme6.py </code></pre> <p>Assume that <code>main.py</code> contains (partial):</p> <pre><code>if complexcondition(): print providers.acme5.g...
3
2009-04-20T22:10:08Z
4,943,557
<p>hey! two years later but... maybe could be helpfull to some one</p> <p>make your <strong>providers/__init__.py</strong> like that:</p> <pre><code>import os import glob module_path = os.path.dirname(__file__) files = glob.glob(os.path.join(module_path, 'acme*.py')) __all__ = [os.path.basename(f)[:-3] for f in file...
6
2011-02-09T10:25:23Z
[ "python", "module", "package" ]
importing gaeutilities or any other module by dev_appserver
770,385
<p>I'm developing a gae application on a windows machine. to have session handling I downloaded gaeutilities and added its path (C:\Python25\Lib\site-packages\gaeutilities-1.2.1) to the registry ("PythonPath" item under python25).</p> <p>in my code this is how I import the gaeutilities Session class:</p> <p>from appe...
0
2009-04-20T22:39:05Z
771,165
<p>Strange.</p> <p>I would start troubleshooting by making 100% sure that the <code>sys.path</code> that <code>dev_appserver.py</code> uses does include <code>C:\Python25\Lib\site-packages\gaeutilities-1.2.1</code>.</p> <p>I suggest you display <code>sys.path</code> in a HTML view served by <code>dev_appserver.py</co...
1
2009-04-21T05:33:16Z
[ "python", "google-app-engine", "import" ]
What is the best secure way to allow a user to delete a model instance that they added to the db?
770,427
<p>I would like to give users access to delete a model instance that they added to the db. In the django docs it says allowing someone to delete from the template is not a good practice. Is there a secure way to let a user click a "delete this" link from the template and remove that model instance? How should I go abou...
0
2009-04-20T23:00:29Z
770,451
<p><a href="http://stackoverflow.com/questions/679013/get-vs-post-best-practices/679042">Check out this question</a> for discussion related to what you are asking about.</p> <p>Essentially, when you normally click on a link on the page the browser makes a <code>GET</code> request to the server to get the next page's c...
7
2009-04-20T23:13:38Z
[ "python", "django" ]
What is the best secure way to allow a user to delete a model instance that they added to the db?
770,427
<p>I would like to give users access to delete a model instance that they added to the db. In the django docs it says allowing someone to delete from the template is not a good practice. Is there a secure way to let a user click a "delete this" link from the template and remove that model instance? How should I go abou...
0
2009-04-20T23:00:29Z
771,066
<p>Have the user submit a POST request to delete that model instance. These kinds of changes should never be possible via GET requests, so that people can't link each other to unwittingly performing changes on the site.</p> <p>In your view, check that request.user is the same as the author of that particular model ins...
0
2009-04-21T04:42:18Z
[ "python", "django" ]
Python - Overridding print()
770,657
<p>I'm using mod_wsgi and was wondering if it's possible to over-write the print() command (since it's useless).</p> <p>Doing this doesn't work:</p> <pre><code>print = myPrintFunction </code></pre> <p>Since it's a syntax error. :(</p>
4
2009-04-21T00:53:23Z
770,664
<p>Would</p> <pre><code>import sys sys.stdout = MyFileWrapper() </code></pre> <p>or something similar work?</p>
5
2009-04-21T00:56:06Z
[ "python", "python-3.x", "mod-wsgi", "wsgi" ]
Python - Overridding print()
770,657
<p>I'm using mod_wsgi and was wondering if it's possible to over-write the print() command (since it's useless).</p> <p>Doing this doesn't work:</p> <pre><code>print = myPrintFunction </code></pre> <p>Since it's a syntax error. :(</p>
4
2009-04-21T00:53:23Z
770,665
<p>Print is not a function in Python 2.x, so this is not directly possible.</p> <p>You can, however, <a href="http://code.activestate.com/recipes/119404/" rel="nofollow">override sys.stdout</a>.</p> <p>If you are on Python 3.0 in which <a href="http://docs.python.org/3.0/whatsnew/3.0.html#print-is-a-function" rel="no...
13
2009-04-21T00:56:16Z
[ "python", "python-3.x", "mod-wsgi", "wsgi" ]
Python - Overridding print()
770,657
<p>I'm using mod_wsgi and was wondering if it's possible to over-write the print() command (since it's useless).</p> <p>Doing this doesn't work:</p> <pre><code>print = myPrintFunction </code></pre> <p>Since it's a syntax error. :(</p>
4
2009-04-21T00:53:23Z
773,242
<p>If you are using 3.0, print is a function. If you are using 2.6, you can <code>from __future__ import print_function</code> and continue with a print function.</p> <p>If &lt;= 2.5, you can replace stdout like others have suggested, but be very careful if your wsgi server will call your app in multiple threads simul...
1
2009-04-21T15:40:05Z
[ "python", "python-3.x", "mod-wsgi", "wsgi" ]
Python - Overridding print()
770,657
<p>I'm using mod_wsgi and was wondering if it's possible to over-write the print() command (since it's useless).</p> <p>Doing this doesn't work:</p> <pre><code>print = myPrintFunction </code></pre> <p>Since it's a syntax error. :(</p>
4
2009-04-21T00:53:23Z
1,037,841
<p>It is worth noting that use of 'print' to sys.stdout in Apache/mod_wsgi was deliberately restricted. This is because a portable WSGI application should not use either sys.stdin or sys.stdout as some WSGI implementations use them to communicate to the server.</p> <p>Apache/mod_wsgi is therefore trying to force you t...
1
2009-06-24T11:43:58Z
[ "python", "python-3.x", "mod-wsgi", "wsgi" ]
Python - Overridding print()
770,657
<p>I'm using mod_wsgi and was wondering if it's possible to over-write the print() command (since it's useless).</p> <p>Doing this doesn't work:</p> <pre><code>print = myPrintFunction </code></pre> <p>Since it's a syntax error. :(</p>
4
2009-04-21T00:53:23Z
1,818,572
<p>While you can redirect stdout to different sources like file for logging, as Paolo mentions, you probably wouldn't need it. I didn't need it. If you really needed to log stuff, you would be using logging itself in the first place, wouldn't you? Also, even when <strong>you</strong> don't print a thing, the third part...
0
2009-11-30T08:49:04Z
[ "python", "python-3.x", "mod-wsgi", "wsgi" ]
What does python3 do with the methods passed to the "key" argument of sorted()?
770,845
<p>I have a question about how python treats the methods passed to sorted(). Consider the following small script:</p> <pre><code>#!/usr/bin/env python3 import random class SortClass: def __init__(self): self.x = random.choice(range(10)) self.y = random.choice(range(10)) def getX(self): ...
4
2009-04-21T02:37:47Z
770,875
<p>Methods on classes are just functions.</p> <pre><code>class MyClass(object): ... def my_method(self): pass ... &gt;&gt;&gt; MyClass.my_method &lt;function my_method at 0x661c38&gt; </code></pre> <p>When you fetch a method from an instance of a class, Python uses some magic (called descriptors) to return a boun...
8
2009-04-21T02:55:17Z
[ "python", "python-3.x", "sorted" ]
What does python3 do with the methods passed to the "key" argument of sorted()?
770,845
<p>I have a question about how python treats the methods passed to sorted(). Consider the following small script:</p> <pre><code>#!/usr/bin/env python3 import random class SortClass: def __init__(self): self.x = random.choice(range(10)) self.y = random.choice(range(10)) def getX(self): ...
4
2009-04-21T02:37:47Z
7,810,979
<p>+1 for Benjamin's answer.</p> <p>Also, read the Sorting HowTo if you want to master sorting in Python: <a href="http://docs.python.org/howto/sorting.html" rel="nofollow">http://docs.python.org/howto/sorting.html</a></p>
0
2011-10-18T17:02:04Z
[ "python", "python-3.x", "sorted" ]
Django Custom Template Tags In Google App Engine
770,854
<p>I am trying to include the following Tag In Google App Engine Web Application:</p> <p><a href="http://www.djangosnippets.org/snippets/1357/">http://www.djangosnippets.org/snippets/1357/</a></p> <p>Is there any configuration of this file to make it work with Google App Engine?</p> <p>Cause I followed the Django Te...
10
2009-04-21T02:39:47Z
770,898
<p>try doing the following:</p> <pre><code>$ python ./manage.py startapp foo </code></pre> <p>Add foo to installed apps:</p> <pre><code>INSTALLED_APPS += ('foo',) </code></pre> <p>And move your templatetags directory into your foo app. Something like:</p> <pre><code>./djangoproject __init__.py settings.py ...
4
2009-04-21T03:09:52Z
[ "python", "django", "google-app-engine" ]
Django Custom Template Tags In Google App Engine
770,854
<p>I am trying to include the following Tag In Google App Engine Web Application:</p> <p><a href="http://www.djangosnippets.org/snippets/1357/">http://www.djangosnippets.org/snippets/1357/</a></p> <p>Is there any configuration of this file to make it work with Google App Engine?</p> <p>Cause I followed the Django Te...
10
2009-04-21T02:39:47Z
1,812,439
<p>In case someone searches for this, I wrote a small article in 2008 about this: <a href="http://daily.profeth.de/2008/04/using-custom-django-template-helpers.html" rel="nofollow">http://daily.profeth.de/2008/04/using-custom-django-template-helpers.html</a></p>
4
2009-11-28T12:36:51Z
[ "python", "django", "google-app-engine" ]
Django Custom Template Tags In Google App Engine
770,854
<p>I am trying to include the following Tag In Google App Engine Web Application:</p> <p><a href="http://www.djangosnippets.org/snippets/1357/">http://www.djangosnippets.org/snippets/1357/</a></p> <p>Is there any configuration of this file to make it work with Google App Engine?</p> <p>Cause I followed the Django Te...
10
2009-04-21T02:39:47Z
3,168,700
<p>Please make sure to restart the development server after following the above step</p>
1
2010-07-02T19:46:58Z
[ "python", "django", "google-app-engine" ]
Installing Django on Shared Server: No module named MySQLdb?
770,904
<p>I'm getting this error</p> <pre><code>Traceback (most recent call last): File "/home/&lt;username&gt;/flup/server/fcgi_base.py", line 558, in run File "/home/&lt;username&gt;/flup/server/fcgi_base.py", line 1116, in handler File "/home/&lt;username&gt;/python/django/django/core/handlers/wsgi.py", line 241, in...
1
2009-04-21T03:13:44Z
770,936
<p>Is it possible that you have the wrong DATABASE_ENGINE setting in your settings.py? It should be mysql and not mysqldb there.</p>
1
2009-04-21T03:28:56Z
[ "python", "django", "mysql" ]
Installing Django on Shared Server: No module named MySQLdb?
770,904
<p>I'm getting this error</p> <pre><code>Traceback (most recent call last): File "/home/&lt;username&gt;/flup/server/fcgi_base.py", line 558, in run File "/home/&lt;username&gt;/flup/server/fcgi_base.py", line 1116, in handler File "/home/&lt;username&gt;/python/django/django/core/handlers/wsgi.py", line 241, in...
1
2009-04-21T03:13:44Z
771,002
<p>You are missing the python-mysql db driver on your python path. see if you can figure out the pythonpath WSGI is seeing... which can be different from what you are experiencing in shell</p>
2
2009-04-21T04:05:10Z
[ "python", "django", "mysql" ]
Python $OUTPUT_RECORD_SEPARATOR and $INPUT_RECORD_SEPARATOR equivalent
770,925
<p>Does Python have an equivalent to the $OUTPUT_RECORD_SEPARATOR or $\ in Perl?</p> <p><strong>UPDATE:</strong> I totally had this wrong... I was looking for a Python equivalent to a $INPUT_RECORD_SEPARATOR if there is such a thing? Something that you can override so that when you do a readline() type call its lookin...
0
2009-04-21T03:23:33Z
771,086
<p>You could use the ''.join method. e.g.</p> <pre><code># print 'foo', 'bar', 'baz' separated by spaces print 'foo', 'bar', 'baz' # print separated by commas print ', '.join(['foo', 'bar', 'baz']) </code></pre> <p>EDIT:</p> <p>Ok, I misunderstood the purpose of <code>OUTPUT_RECORD_SEPARATOR</code>, so ''.join is n...
1
2009-04-21T04:53:20Z
[ "python", "file-io" ]
Python $OUTPUT_RECORD_SEPARATOR and $INPUT_RECORD_SEPARATOR equivalent
770,925
<p>Does Python have an equivalent to the $OUTPUT_RECORD_SEPARATOR or $\ in Perl?</p> <p><strong>UPDATE:</strong> I totally had this wrong... I was looking for a Python equivalent to a $INPUT_RECORD_SEPARATOR if there is such a thing? Something that you can override so that when you do a readline() type call its lookin...
0
2009-04-21T03:23:33Z
771,101
<p>Python 3's print function has <code>sep</code> and <code>end</code> arguments.</p> <pre><code>print('foo', 'bar', 'baz', sep='|', end='#') </code></pre> <p>Note that in Python 3, <code>print</code> is no longer a statement, it is a function.</p>
1
2009-04-21T04:58:48Z
[ "python", "file-io" ]
Python $OUTPUT_RECORD_SEPARATOR and $INPUT_RECORD_SEPARATOR equivalent
770,925
<p>Does Python have an equivalent to the $OUTPUT_RECORD_SEPARATOR or $\ in Perl?</p> <p><strong>UPDATE:</strong> I totally had this wrong... I was looking for a Python equivalent to a $INPUT_RECORD_SEPARATOR if there is such a thing? Something that you can override so that when you do a readline() type call its lookin...
0
2009-04-21T03:23:33Z
771,585
<p>In Python pre-3, you can suppress standard separator appending ',' at end of line:</p> <pre><code>print yourVar, #these 3 lines print without any newline separator print yourVar, print yourVar, </code></pre> <p>if you want to use non-standard separator, suppress normal one and print yours:</p> <pre><code>print ...
0
2009-04-21T08:20:06Z
[ "python", "file-io" ]
Python $OUTPUT_RECORD_SEPARATOR and $INPUT_RECORD_SEPARATOR equivalent
770,925
<p>Does Python have an equivalent to the $OUTPUT_RECORD_SEPARATOR or $\ in Perl?</p> <p><strong>UPDATE:</strong> I totally had this wrong... I was looking for a Python equivalent to a $INPUT_RECORD_SEPARATOR if there is such a thing? Something that you can override so that when you do a readline() type call its lookin...
0
2009-04-21T03:23:33Z
804,825
<p>If what you want is to have any of <code>\r</code>, <code>\n</code>, or <code>\r\n</code> in the input to be seen as a newline, then you can use “universal newline support” in your ‘open()’ call.</p> <p>In <a href="http://docs.python.org/2.6/library/functions.html#open" rel="nofollow">Python 2.6 open()</a>,...
1
2009-04-29T23:53:13Z
[ "python", "file-io" ]
Python $OUTPUT_RECORD_SEPARATOR and $INPUT_RECORD_SEPARATOR equivalent
770,925
<p>Does Python have an equivalent to the $OUTPUT_RECORD_SEPARATOR or $\ in Perl?</p> <p><strong>UPDATE:</strong> I totally had this wrong... I was looking for a Python equivalent to a $INPUT_RECORD_SEPARATOR if there is such a thing? Something that you can override so that when you do a readline() type call its lookin...
0
2009-04-21T03:23:33Z
816,648
<pre><code>open('file').read().split(your_separator_of_choice) </code></pre> <p>the only difference with <code>readlines()</code> here is that resulting list items won't have separator preserved at the end.</p>
0
2009-05-03T09:13:07Z
[ "python", "file-io" ]
(Python) socket.gaierror: [Errno 11001] getaddrinfo failed
771,247
<p>I'm not sure whats wrong with this code I keep getting that socket.gaierror error ;\ .</p> <pre><code>import sys import socket import random filename = "whoiservers.txt" server_name = random.choice(list(open(filename))) print "connecting to %s..." % server_name s = socket.socket(socket.AF_INET, socket.SOCK_STRE...
3
2009-04-21T06:18:24Z
771,311
<p>I think the problem is a newline at the end of <code>server_name</code>.</p> <p>If the format of your file <code>whoiservers.txt</code> is one hostname on each line then you need to strip the newline at the end of the hostname before passing it to <code>s.connect()</code></p> <p>So, for example, change the open li...
5
2009-04-21T06:41:13Z
[ "python", "sockets" ]
(Python) socket.gaierror: [Errno 11001] getaddrinfo failed
771,247
<p>I'm not sure whats wrong with this code I keep getting that socket.gaierror error ;\ .</p> <pre><code>import sys import socket import random filename = "whoiservers.txt" server_name = random.choice(list(open(filename))) print "connecting to %s..." % server_name s = socket.socket(socket.AF_INET, socket.SOCK_STRE...
3
2009-04-21T06:18:24Z
774,040
<p>Perhaps you have a firewall in between you and these servers that is blocking the request? The last error you posted leads one to believe that it cannot connect to the server at all...</p>
0
2009-04-21T18:49:49Z
[ "python", "sockets" ]
GStrings in Python
771,312
<p>Groovy has a concept of GStrings. I can write code like this:</p> <pre><code>def greeting = 'Hello World' println """This is my first program ${greeting}""" </code></pre> <p>I can access the value of a variable from within the String. </p> <p>How can I do this in Python?</p> <p>-- Thanks</p>
2
2009-04-21T06:41:27Z
771,323
<pre><code>d = {'greeting': 'Hello World'} print "This is my first program %(greeting)s" % d </code></pre>
3
2009-04-21T06:45:23Z
[ "python", "gstring" ]
GStrings in Python
771,312
<p>Groovy has a concept of GStrings. I can write code like this:</p> <pre><code>def greeting = 'Hello World' println """This is my first program ${greeting}""" </code></pre> <p>I can access the value of a variable from within the String. </p> <p>How can I do this in Python?</p> <p>-- Thanks</p>
2
2009-04-21T06:41:27Z
771,326
<p>You can't exactly...</p> <p>I think the closest you can really get is using standard %-based substitution, e.g:</p> <pre><code>greeting = "Hello World" print "This is my first program %s" % greeting </code></pre> <p>Having said that, there are some fancy new classes as of Python 2.6 which can do this in different...
1
2009-04-21T06:47:02Z
[ "python", "gstring" ]
GStrings in Python
771,312
<p>Groovy has a concept of GStrings. I can write code like this:</p> <pre><code>def greeting = 'Hello World' println """This is my first program ${greeting}""" </code></pre> <p>I can access the value of a variable from within the String. </p> <p>How can I do this in Python?</p> <p>-- Thanks</p>
2
2009-04-21T06:41:27Z
771,343
<p>If your trying to do templating you might want to look into Cheetah. It lets you do exactly what your talking about, same syntax and all.</p> <p><a href="http://www.cheetahtemplate.org/" rel="nofollow">http://www.cheetahtemplate.org/</a></p>
1
2009-04-21T06:51:06Z
[ "python", "gstring" ]
GStrings in Python
771,312
<p>Groovy has a concept of GStrings. I can write code like this:</p> <pre><code>def greeting = 'Hello World' println """This is my first program ${greeting}""" </code></pre> <p>I can access the value of a variable from within the String. </p> <p>How can I do this in Python?</p> <p>-- Thanks</p>
2
2009-04-21T06:41:27Z
771,344
<p>In Python 2.6+ you can do:</p> <pre><code>"My name is {0}".format('Fred') </code></pre> <p>Check out <a href="http://www.python.org/dev/peps/pep-3101/" rel="nofollow">PEP 3101</a>.</p>
1
2009-04-21T06:51:11Z
[ "python", "gstring" ]
GStrings in Python
771,312
<p>Groovy has a concept of GStrings. I can write code like this:</p> <pre><code>def greeting = 'Hello World' println """This is my first program ${greeting}""" </code></pre> <p>I can access the value of a variable from within the String. </p> <p>How can I do this in Python?</p> <p>-- Thanks</p>
2
2009-04-21T06:41:27Z
771,371
<p>In Python, you have to explicitely pass a dictionary of possible variables, you cannot access arbitrary "outside" variables from within a string. But, you can use the <code>locals()</code> function that returns a dictionary with all variables of the local scope.</p> <p>For the actual replacement, there are many way...
5
2009-04-21T07:00:49Z
[ "python", "gstring" ]
Python + PHP + Lighttpd?
771,341
<p>I've set up a few web servers in my day, but I'm not sure how they work internally. I'm setting up a new environment for myself and I'm interested in configuring my lighttpd server to support both PHP and Python. Is this possible?</p>
3
2009-04-21T06:49:38Z
771,356
<p>Yes, this is possible. <a href="http://sam.bluwiki.com/blog/2008/04/django-python-phpoptional-lighttpd-on.php" rel="nofollow">Here</a> you can find a sample configuration.</p> <pre><code>fastcgi.server = ( ".php" =&gt; (( "bin-path" =&gt; "/usr/bin/php5-cgi", "socket" =&gt; "/tmp/php.socket" )), "django.fcgi" =&gt;...
3
2009-04-21T06:55:45Z
[ "php", "python", "lighttpd", "configure" ]
Python + PHP + Lighttpd?
771,341
<p>I've set up a few web servers in my day, but I'm not sure how they work internally. I'm setting up a new environment for myself and I'm interested in configuring my lighttpd server to support both PHP and Python. Is this possible?</p>
3
2009-04-21T06:49:38Z
771,528
<p>You can also enable Lighty to use .pl, .py and .php as 'cgi' by enabling mod_cgi and setting it up. The default configs are on the Lighty website. However, this will have the benefits and problems of running an independent cgi process. If you are only experiencing light traffic, performance shouldn't be an issue.</p...
1
2009-04-21T08:01:35Z
[ "php", "python", "lighttpd", "configure" ]
Monitoring a tcp port
771,399
<p>For fun, I've been toying around with writing a load balancer in python and have been trying to figure the best (correct?) way to test if a port is available and the remote host is still there.</p> <p>I'm finding that, once connected, it becomes difficult to tell when the remote host goes down. I've turned keep al...
2
2009-04-21T07:11:13Z
771,415
<p>ping was invented for that purpose</p> <p>also you might be able to send malformed TCP packets to your destination. For example, in the TCP headers there is a flag for acknowleging end of transmission, its the FIN message. If you send a message with ACK and FIN the remote host should complain with a return packet a...
0
2009-04-21T07:16:34Z
[ "python", "tcp", "monitoring", "port" ]
Monitoring a tcp port
771,399
<p>For fun, I've been toying around with writing a load balancer in python and have been trying to figure the best (correct?) way to test if a port is available and the remote host is still there.</p> <p>I'm finding that, once connected, it becomes difficult to tell when the remote host goes down. I've turned keep al...
2
2009-04-21T07:11:13Z
771,422
<p>I'd recommend not leaving your (single) test socket connected - make a new connection each time you need to poll. Every load balancer / server availability system I've ever seen uses this method instead of a persistent connection.</p> <p>If the remote server hasn't responded within a reasonable amount of time (e.g...
2
2009-04-21T07:20:07Z
[ "python", "tcp", "monitoring", "port" ]
Monitoring a tcp port
771,399
<p>For fun, I've been toying around with writing a load balancer in python and have been trying to figure the best (correct?) way to test if a port is available and the remote host is still there.</p> <p>I'm finding that, once connected, it becomes difficult to tell when the remote host goes down. I've turned keep al...
2
2009-04-21T07:11:13Z
771,438
<p>It is theoretically possible to spam a keepalive packet. But to set it to very low intervals, you may need to dig into raw sockets. Also, your host may ignore it if its coming in too fast.</p> <p>The best way to check if a host is alive in a TCP connection is to send data, and wait for an ACK packet. If the ACK pac...
0
2009-04-21T07:24:03Z
[ "python", "tcp", "monitoring", "port" ]
Monitoring a tcp port
771,399
<p>For fun, I've been toying around with writing a load balancer in python and have been trying to figure the best (correct?) way to test if a port is available and the remote host is still there.</p> <p>I'm finding that, once connected, it becomes difficult to tell when the remote host goes down. I've turned keep al...
2
2009-04-21T07:11:13Z
773,207
<p>"it becomes difficult to tell when the remote host goes down"</p> <p>Correct. This is a feature of TCP. The whole point of TCP is to have an enduring connection between ports. Theoretically an application can drop and reconnect to the port through TCP (the socket libraries don't provide a lot of support for this...
1
2009-04-21T15:33:33Z
[ "python", "tcp", "monitoring", "port" ]
Monitoring a tcp port
771,399
<p>For fun, I've been toying around with writing a load balancer in python and have been trying to figure the best (correct?) way to test if a port is available and the remote host is still there.</p> <p>I'm finding that, once connected, it becomes difficult to tell when the remote host goes down. I've turned keep al...
2
2009-04-21T07:11:13Z
35,338,445
<p>You can use <a href="http://www.tldp.org/LDP/abs/html/devref1.html" rel="nofollow">Bash pseudo-device files</a> for TCP/UDP connection with a specific I/O port, for example:</p> <pre><code>printf "" &gt; /dev/tcp/example.com/80 &amp;&amp; echo Works </code></pre> <p>This would open the connection, but won't send a...
0
2016-02-11T11:43:34Z
[ "python", "tcp", "monitoring", "port" ]
Call python script from AIR application?
771,738
<p>How can we invoke a python script using AIR 1.5?</p>
1
2009-04-21T09:09:18Z
771,745
<p>You cannot directly invoke system commands or run an executable (the python interpreter) from within an AIR application. If it's possible to share what exactly you want to do, maybe we can suggest alternatives. </p> <p>If it's really really (that's two reallys) important to run an executable from AIR lookup the Com...
1
2009-04-21T09:12:14Z
[ "python", "flex3", "air" ]
Call python script from AIR application?
771,738
<p>How can we invoke a python script using AIR 1.5?</p>
1
2009-04-21T09:09:18Z
771,752
<p>For example through AMF: <a href="http://pyamf.org/" rel="nofollow">http://pyamf.org/</a></p>
0
2009-04-21T09:14:42Z
[ "python", "flex3", "air" ]
Call python script from AIR application?
771,738
<p>How can we invoke a python script using AIR 1.5?</p>
1
2009-04-21T09:09:18Z
771,836
<p>Hypothetically, Adobe Alchemy technology may allow you to port Python interpreter to Flash.</p> <p>Though I seriously doubt that's the approach you want to use. Depending on task there should be easier solutions.</p>
-1
2009-04-21T09:38:38Z
[ "python", "flex3", "air" ]
Call python script from AIR application?
771,738
<p>How can we invoke a python script using AIR 1.5?</p>
1
2009-04-21T09:09:18Z
3,895,749
<p>Air 2.0 has a native process API.</p>
0
2010-10-09T04:54:56Z
[ "python", "flex3", "air" ]
What does the 'shell' argument in subprocess mean on Windows?
771,816
<p>The docs for the subprocess module state that 'If <em>shell</em> is True, the specified command will be executed through the shell'. What does this mean in practice, on a Windows OS?</p>
1
2009-04-21T09:35:09Z
771,839
<p>It means that the command will be executed using the program specified in the <code>COMSPEC</code> environment variable. Usually <code>cmd.exe</code>.</p> <p>To be exact, subprocess calls the <a href="http://msdn.microsoft.com/en-us/library/ms682425.aspx" rel="nofollow"><code>CreateProcess</code></a> windows api fu...
3
2009-04-21T09:39:22Z
[ "python", "subprocess" ]
What does the 'shell' argument in subprocess mean on Windows?
771,816
<p>The docs for the subprocess module state that 'If <em>shell</em> is True, the specified command will be executed through the shell'. What does this mean in practice, on a Windows OS?</p>
1
2009-04-21T09:35:09Z
771,852
<p>In <a href="http://docs.python.org/library/subprocess.html#using-the-subprocess-module" rel="nofollow">using-the-subprocess-module</a>, there is an explicit paragraph:</p> <blockquote> <p>The executable argument specifies the program to execute. It is very seldom needed: Usually, the program to execute is defined...
0
2009-04-21T09:43:28Z
[ "python", "subprocess" ]
What does the 'shell' argument in subprocess mean on Windows?
771,816
<p>The docs for the subprocess module state that 'If <em>shell</em> is True, the specified command will be executed through the shell'. What does this mean in practice, on a Windows OS?</p>
1
2009-04-21T09:35:09Z
772,687
<p>In addition to what was said in other answers, it is useful in practice if you want to open a file in the default viewer for that file type. For instance, if you want to open an HTML or PDF file, but will not know which browser or viewer is installed on the systems it will be run on, or have no guarantees as to the...
0
2009-04-21T13:51:24Z
[ "python", "subprocess" ]
What does the 'shell' argument in subprocess mean on Windows?
771,816
<p>The docs for the subprocess module state that 'If <em>shell</em> is True, the specified command will be executed through the shell'. What does this mean in practice, on a Windows OS?</p>
1
2009-04-21T09:35:09Z
772,743
<p>When you execute an external process, the command you want may look something like "foo arg1 arg2 arg3". If "foo" is an executable, that is what gets executed and given the arguments. </p> <p>However, often it is the case that "foo" is actually a script of some sort, or maybe a command that is built-in to the shell...
1
2009-04-21T14:04:08Z
[ "python", "subprocess" ]
Python: how to store a draft email with BCC recipients to Exchange Server via IMAP?
771,907
<p>I try to store a draft e-mail via IMAP to a folder running on MS Exchange. Everything ok, except that Bcc recipients don't get shown in the draft message stored on the server. Bcc recipients also don't receive the email if I send it with MS Outlook. If I read the message back with Python after I have stored it on th...
5
2009-04-21T10:03:09Z
772,233
<p>It could be that way by design. After all, the whole point of bcc is that the recipients are hidden from each other.</p> <p>I understand that you are not sending the e-mail, just storing it. But my guess is that Exchange's internal rules kick in when the message is IMAP.appended to the folder, causing the bcc field...
1
2009-04-21T12:02:01Z
[ "python", "email", "exchange-server", "imap", "bcc" ]
Python: how to store a draft email with BCC recipients to Exchange Server via IMAP?
771,907
<p>I try to store a draft e-mail via IMAP to a folder running on MS Exchange. Everything ok, except that Bcc recipients don't get shown in the draft message stored on the server. Bcc recipients also don't receive the email if I send it with MS Outlook. If I read the message back with Python after I have stored it on th...
5
2009-04-21T10:03:09Z
772,496
<p>Try setting this alternate version of the BCC header:</p> <pre><code>X-Receiver: someguy@gmail.com </code></pre> <p>Exchange in particular will treat this like a BCC when you send it. But I bet it will not strip it when you write via IMAP. You can include more than one BCC recipient by duplicating this line.</p> ...
1
2009-04-21T13:07:21Z
[ "python", "email", "exchange-server", "imap", "bcc" ]
Python: how to store a draft email with BCC recipients to Exchange Server via IMAP?
771,907
<p>I try to store a draft e-mail via IMAP to a folder running on MS Exchange. Everything ok, except that Bcc recipients don't get shown in the draft message stored on the server. Bcc recipients also don't receive the email if I send it with MS Outlook. If I read the message back with Python after I have stored it on th...
5
2009-04-21T10:03:09Z
920,817
<p>Actually, the code works just fine. It creates the proper mail with all the right headers including bcc.</p> <p><strong>How does the mail client display bcc?</strong></p> <p>The <a href="http://en.wikipedia.org/wiki/E-mail_client" rel="nofollow">mail client</a> (e.g. Python or MS Outlook via IMAP or MAPI in my cas...
5
2009-05-28T13:22:51Z
[ "python", "email", "exchange-server", "imap", "bcc" ]
pyqt4 and pyserial
771,988
<p>I want to do an app constantly watching the serial port and changing the user interface according to the input received from the port. I've managed to read lines from the port with pyserial under Linux, but I'm not sure how to do this in a regular fashion: create a separate thread and check for input on a timer even...
4
2009-04-21T10:37:15Z
772,091
<p>You won't miss any bytes, any pending input is buffered.</p> <p>You have several options:</p> <ol> <li><p>use a thread that polls the serial port with PySerial/inWaiting() </p></li> <li><p>Use a timer in the main thread that polls the serial port with PySerial/inWaiting.</p></li> <li><p>find the handle of the port...
4
2009-04-21T11:12:42Z
[ "python", "linux", "qt", "serial-port", "pyserial" ]
How to add a second bouncing ball to the window?
771,992
<p>I have coded an animation (in python) for a beach ball to bounce around a screen. I now wish to add a second ball to the window, and when the two collide for them to bounce off each other. </p> <p>So far, my attempts at this have been unsuccessful. Any ideas how to do this? The code I have so far is below.</p> <p...
1
2009-04-21T10:38:19Z
772,015
<p>You should probably create a class to represent your beachball. Then you'd instance as many as you like, and put the instances in a Python list.</p> <p>You'd then go through that list on each frame, updating and rendering each.</p> <p>You would need to include a method to test for collision against another ball (t...
3
2009-04-21T10:46:51Z
[ "python", "animation", "pygame" ]
How to add a second bouncing ball to the window?
771,992
<p>I have coded an animation (in python) for a beach ball to bounce around a screen. I now wish to add a second ball to the window, and when the two collide for them to bounce off each other. </p> <p>So far, my attempts at this have been unsuccessful. Any ideas how to do this? The code I have so far is below.</p> <p...
1
2009-04-21T10:38:19Z
772,180
<p>Here's a very basic restructure of your code. It could still be tidied up a lot, but it should show you how you can use instances of the class.</p> <pre><code>import pygame import random import sys class Ball: def __init__(self,X,Y): self.velocity = [1,1] self.ball_image = pygame.image.load ('Beachba...
7
2009-04-21T11:42:49Z
[ "python", "animation", "pygame" ]
Running python code from standard Cocoa application
772,112
<p>I have an XCode project built as a Cocoa single document application (it's not a Python-Cocoa application, that is not what I want).</p> <p>All the documentation I found assumes I want to create a Cocoa application with code written in Python and this is not the case - I want a standard Cocoa application that calls...
8
2009-04-21T11:18:44Z
772,220
<p>A google search for <a href="http://www.google.com/search?q=embed%2Bpython%2Bobjective%2BC">embed python objective C</a>, returns a few links that might be of interest, in particular:</p> <ul> <li><a href="http://blog.alienoverlord.com/?p=14">http://blog.alienoverlord.com/?p=14</a></li> <li><a href="http://blog.tle...
7
2009-04-21T11:57:55Z
[ "python", "cocoa", "osx", "pyobjc" ]
What does the Python Ellipsis object do?
772,124
<p>While idly surfing the namespace I noticed an odd looking object called "<strong>Ellipsis</strong>", it does not seem to be or do anything special, but it's a globally available builtin. </p> <p>After a search I found that it is used in some obscure variant of the slicing syntax by Numpy and Scipy... but almost not...
196
2009-04-21T11:21:12Z
772,134
<p>You can use Ellipsis yourself, in custom slicing situations like numpy has done, but it has no usage in any builtin class.</p> <p>I don't know if it was added specifically for use in numpy, but I certainly haven't seen it used elsewhere.</p> <p>See also: <a href="http://stackoverflow.com/questions/118370/how-do-yo...
8
2009-04-21T11:24:33Z
[ "python", "ellipsis" ]
What does the Python Ellipsis object do?
772,124
<p>While idly surfing the namespace I noticed an odd looking object called "<strong>Ellipsis</strong>", it does not seem to be or do anything special, but it's a globally available builtin. </p> <p>After a search I found that it is used in some obscure variant of the slicing syntax by Numpy and Scipy... but almost not...
196
2009-04-21T11:21:12Z
772,148
<p>From the <a href="http://www.python.org/doc/2.5.2/lib/bltin-ellipsis-object.html">Python documentation</a>:</p> <blockquote> <p>This object is used by extended slice notation (see the <em><a href="http://www.python.org/doc/2.5.2/ref/ref.html">Python Reference Manual</a></em>). It supports no special operati...
27
2009-04-21T11:30:30Z
[ "python", "ellipsis" ]
What does the Python Ellipsis object do?
772,124
<p>While idly surfing the namespace I noticed an odd looking object called "<strong>Ellipsis</strong>", it does not seem to be or do anything special, but it's a globally available builtin. </p> <p>After a search I found that it is used in some obscure variant of the slicing syntax by Numpy and Scipy... but almost not...
196
2009-04-21T11:21:12Z
773,472
<p>This came up in another <a href="http://stackoverflow.com/questions/752602/slicing-in-python-expressions-documentation">question</a> recently. I'll elaborate on my <a href="http://stackoverflow.com/questions/752602/slicing-in-python-expressions-documentation/753260#753260">answer</a> from there:</p> <p><a href="ht...
242
2009-04-21T16:26:07Z
[ "python", "ellipsis" ]
What does the Python Ellipsis object do?
772,124
<p>While idly surfing the namespace I noticed an odd looking object called "<strong>Ellipsis</strong>", it does not seem to be or do anything special, but it's a globally available builtin. </p> <p>After a search I found that it is used in some obscure variant of the slicing syntax by Numpy and Scipy... but almost not...
196
2009-04-21T11:21:12Z
6,189,281
<p>In Python 3, you can use the Ellipsis literal <code>...</code> as a “nop” placeholder for code:</p> <pre><code>def will_do_something(): ... </code></pre> <p>This is <strong>not</strong> magic; any expression can be used instead of <code>...</code>, e.g.:</p> <pre><code>def will_do_something(): 1 </cod...
73
2011-05-31T14:39:41Z
[ "python", "ellipsis" ]
What does the Python Ellipsis object do?
772,124
<p>While idly surfing the namespace I noticed an odd looking object called "<strong>Ellipsis</strong>", it does not seem to be or do anything special, but it's a globally available builtin. </p> <p>After a search I found that it is used in some obscure variant of the slicing syntax by Numpy and Scipy... but almost not...
196
2009-04-21T11:21:12Z
6,189,379
<p>You can also use the Ellipsis when specifying expected <a href="http://docs.python.org/library/doctest.html#doctest.ELLIPSIS">doctest</a> output:</p> <pre><code>class MyClass(object): """Example of a doctest Ellipsis &gt;&gt;&gt; thing = MyClass() &gt;&gt;&gt; # Match &lt;class '__main__.MyClass'&gt; a...
33
2011-05-31T14:47:58Z
[ "python", "ellipsis" ]
What does the Python Ellipsis object do?
772,124
<p>While idly surfing the namespace I noticed an odd looking object called "<strong>Ellipsis</strong>", it does not seem to be or do anything special, but it's a globally available builtin. </p> <p>After a search I found that it is used in some obscure variant of the slicing syntax by Numpy and Scipy... but almost not...
196
2009-04-21T11:21:12Z
17,763,893
<p>Its intended use shouldn't be only for these 3rd party modules. It isn't mentioned properly in the Python documentation (or maybe I just couldn't find that) but the <strong>ellipsis <code>...</code> is actually used in CPython</strong> in at least one place. </p> <p>It is used for representing infinite data structu...
0
2013-07-20T15:42:41Z
[ "python", "ellipsis" ]
What does the Python Ellipsis object do?
772,124
<p>While idly surfing the namespace I noticed an odd looking object called "<strong>Ellipsis</strong>", it does not seem to be or do anything special, but it's a globally available builtin. </p> <p>After a search I found that it is used in some obscure variant of the slicing syntax by Numpy and Scipy... but almost not...
196
2009-04-21T11:21:12Z
33,087,462
<blockquote> <p>What does the Python Ellipsis object do?</p> </blockquote> <p>Serves as a singleton class magic value that gets passed to <code>__getitem__</code> when you use the "magic-looking" <code>...</code> syntax.</p> <p>The class can then do whatever it wants with it.</p> <p>Example:</p> <pre><code>class ...
2
2015-10-12T18:03:20Z
[ "python", "ellipsis" ]
What does the Python Ellipsis object do?
772,124
<p>While idly surfing the namespace I noticed an odd looking object called "<strong>Ellipsis</strong>", it does not seem to be or do anything special, but it's a globally available builtin. </p> <p>After a search I found that it is used in some obscure variant of the slicing syntax by Numpy and Scipy... but almost not...
196
2009-04-21T11:21:12Z
37,499,388
<p>As of Python 3.5 and <a href="https://www.python.org/dev/peps/pep-0484/#callable">PEP484</a>, the literal ellipsis is used to denote certain types to a static type checker when using the <a href="https://docs.python.org/3/library/typing.html">typing</a> module.</p> <p>Example 1:</p> <blockquote> <p>Arbitrary-len...
5
2016-05-28T13:08:47Z
[ "python", "ellipsis" ]
Django payment proccessing
772,240
<p>Can anyone suggest any good payment processing libraries for python/django?</p>
22
2009-04-21T12:05:31Z
772,311
<p>Perhaps you can find some usefull code hints/modules looking at Satchmo: <a href="http://www.satchmoproject.com/" rel="nofollow">Satchmo Homepage</a></p>
2
2009-04-21T12:26:33Z
[ "python", "django" ]
Django payment proccessing
772,240
<p>Can anyone suggest any good payment processing libraries for python/django?</p>
22
2009-04-21T12:05:31Z
772,320
<p>The most developed Django solution is <a href="http://www.satchmoproject.com/docs/svn/">Satchmo</a> with support for Authorize.Net, TrustCommerce, CyberSource, PayPal, Google Checkout, and Protx.</p> <p>The new kid on the Django block is <a href="http://code.google.com/p/django-lfs/">django-lfs</a> which looks like...
18
2009-04-21T12:28:12Z
[ "python", "django" ]