title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
list
List of specific class names in Python
1,770,701
<p>Is there a way to flag class declarations so that later you can get a list of them flagged?</p> <p>Or a way to get all classes starting with a certain string ?</p> <p>Or all classes that are a subclass of a specific class?</p>
1
2009-11-20T14:17:20Z
1,771,799
<p>To get a list of subclasses of your class from within itself, use the __subclasses__ method from the parent class.</p> <pre><code>&gt;&gt;&gt;class Parent(object): ... pass ... &gt;&gt;&gt;class Child(Parent): ... pass ... &gt;&gt;&gt;Parent.__subclasses__() &gt;&gt;&gt;[&lt;class '__main__.Child'&gt;] </code...
1
2009-11-20T16:56:01Z
[ "python" ]
Metaclass not being called in subclasses
1,770,712
<p>Here is a python session.</p> <pre><code>&gt;&gt;&gt; class Z(type): def __new__(cls, name, bases, attrs): print cls print name return type(name, bases, attrs) ... &gt;&gt;&gt; class Y(object): __metaclass__ = Z ... &lt;class '__main__.Z'&gt; Y &gt;&gt;&gt; class X(Y): ... ...
9
2009-11-20T14:18:55Z
1,770,823
<p>The problem is that the <code>cls</code> argument (which is the metaclass object) is not passed on when you call <code>type</code>, therefore the class object <code>Y</code> that is created and returned does not have any reference to the metaclass <code>Z</code>.</p> <p>If you replace the last line in <code>__new__...
12
2009-11-20T14:35:24Z
[ "python", "metaclass" ]
Pointers to members in swig (or Boost::Python)
1,770,725
<p>I made some bindings from my C++ app for python.</p> <p>The problem is that I use pointers to members (It's for computing shortest path and giving the property to minimize as parameter).</p> <p>This is the C++ signature:</p> <pre><code>std::vector&lt;Path&gt; martins(int start, int dest, MultimodalGraph &amp; g, ...
1
2009-11-20T14:20:52Z
2,186,475
<p>Don't know about SWIG, but in boost::python you can write a wrapper:</p> <pre><code>bool foo(int x, float* result); boost::python::tuple foo_wrapper(int x) { float v; bool result = foo(x, &amp;v); return boost::python::make_tuple(result, v); } BOOST_PYTHON_MODULE(foomodule) { def("foo", &amp;foo_w...
2
2010-02-02T18:12:53Z
[ "c++", "python", "swig", "boost-python" ]
reactor.iterate seems to block a program with Py2exe
1,770,754
<p>I'm currently using an application in python which works quite well but when I'm converting it with py2exe, the application seems to be suspended at the first "reactor.iterate"</p> <p>Each time I press Ctrl+C to stop the application, the error is always the same and the application seems to be bloqued on a "reactor...
1
2009-11-20T14:25:33Z
1,770,870
<p>The typical use of the reactor is <em>not</em> to call <code>reactor.iterate</code>. It's hard to say why exactly you're getting the behavior you are without seeing your program, but for a wild guess, I'd say switching to <code>reactor.run</code> might help.</p>
1
2009-11-20T14:42:53Z
[ "python", "twisted", "py2exe" ]
Fixtures for Google App Engine
1,770,755
<p>Are there any Python tools to create fixtures on Google App Engine? I tried Fixture(<a href="http://farmdev.com/projects/fixture/" rel="nofollow">http://farmdev.com/projects/fixture/</a>). It is the most awesome tool I have come across. I love the clean approach and the consistency of the APIs. But it is LGPL licens...
4
2009-11-20T14:25:41Z
1,774,583
<p>Are you using the fixtures just for testing your app? If so, I don't think the license of your app matters at all. It would only be important if you were redistributing the fixtures functionality.</p>
1
2009-11-21T05:11:51Z
[ "python", "google-app-engine", "testing", "fixture" ]
Fixing a type-error in Python's Pg
1,770,786
<p>Thank you for bobince in solving the first bugs!</p> <p><strong>How can you use *pg.escape_bytea* or *pg.escape_string* in the following?</strong></p> <h1>#1 With both pg.escape_string and pg.escape_bytea</h1> <pre><code> con1.query( "INSERT INTO files (file, file_name) VALUES ('%s', '%s')" % ...
0
2009-11-20T14:29:53Z
1,771,240
<blockquote> <p>INSERT INTO files('binf','file_name') VALUES(file,file_name)</p> </blockquote> <p>You've got the <code>(...)</code> sections the wrong way round, you're trying to insert the columns <code>(file, filename)</code> into the string literals <code>('binf', 'file_name')</code>. You're also not actually ins...
4
2009-11-20T15:30:16Z
[ "python", "postgresql", "types" ]
Is there a more pythonic way to open a file if given one as an argument or stdin if not?
1,770,789
<p>I'm trying to write a python script which follows the common unix command line pattern of accepting input from stdin if no file name is given. This is what I've been using:</p> <pre><code>if __name__ == "__main__": if len(sys.argv) &gt; 1: stream = open(sys.argv[1]) else: stream = sys.stdin...
4
2009-11-20T14:30:16Z
1,770,811
<p>similar but one-line solution</p> <pre><code>stream = sys.argv[1] if len(sys.argv)&gt;1 else sys.stdin </code></pre>
5
2009-11-20T14:33:27Z
[ "python", "unix", "command-line" ]
Is there a more pythonic way to open a file if given one as an argument or stdin if not?
1,770,789
<p>I'm trying to write a python script which follows the common unix command line pattern of accepting input from stdin if no file name is given. This is what I've been using:</p> <pre><code>if __name__ == "__main__": if len(sys.argv) &gt; 1: stream = open(sys.argv[1]) else: stream = sys.stdin...
4
2009-11-20T14:30:16Z
1,770,821
<p>The <a href="http://docs.python.org/library/fileinput.html" rel="nofollow">fileinput</a> module is perfect for this.</p>
10
2009-11-20T14:35:11Z
[ "python", "unix", "command-line" ]
Is there a more pythonic way to open a file if given one as an argument or stdin if not?
1,770,789
<p>I'm trying to write a python script which follows the common unix command line pattern of accepting input from stdin if no file name is given. This is what I've been using:</p> <pre><code>if __name__ == "__main__": if len(sys.argv) &gt; 1: stream = open(sys.argv[1]) else: stream = sys.stdin...
4
2009-11-20T14:30:16Z
1,770,864
<p>I would suggest you make it more unixy instead:</p> <pre><code>if len(sys.argv) &gt; 1: sys.stdin = open(sys.argv[1]) </code></pre>
0
2009-11-20T14:41:23Z
[ "python", "unix", "command-line" ]
Is there a more pythonic way to open a file if given one as an argument or stdin if not?
1,770,789
<p>I'm trying to write a python script which follows the common unix command line pattern of accepting input from stdin if no file name is given. This is what I've been using:</p> <pre><code>if __name__ == "__main__": if len(sys.argv) &gt; 1: stream = open(sys.argv[1]) else: stream = sys.stdin...
4
2009-11-20T14:30:16Z
1,770,933
<p>how about this one?</p> <pre><code>stream=sys.argv[1:] and open(sys.argv[1]) or sys.stdin </code></pre>
2
2009-11-20T14:51:31Z
[ "python", "unix", "command-line" ]
Reading a csv file in Python with different line terminator
1,770,934
<p>I have a file in CSV format where the delimiter is the ASCII unit separator <code>^_</code> and the line terminator is the ASCII record separator <code>^^</code> (obviously, since these are nonprinting characters, I've just used one of the standard ways of writing them here). I've written plenty of code that reads ...
3
2009-11-20T14:51:41Z
1,770,985
<p>Why not supply a custom iterable to the <code>csv.reader</code> function? Here is a naive implementation which reads the entire contents of the CSV file into memory at once (which may or may not be desirable, depending on the size of the file):</p> <pre><code>def records(path): with open(path) as f: co...
3
2009-11-20T14:58:59Z
[ "python", "csv", "delimiter" ]
py2exe and email libs again
1,770,986
<p>Following imports:</p> <pre><code>import pyodbc, sys, smtplib, os from datetime import date from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from email.mime.base import MIMEBase import email.iterators import email.generator from email import Encoders </code></pre> <p>Works ok whe...
2
2009-11-20T14:58:59Z
1,772,145
<p>Py2Exe has a lot of bugs when compiling various modules inside the exe. I had this kind of problem myself. My suggestion is to use pyInstaller which in my opinion is a lot better and easier to use.</p>
2
2009-11-20T17:43:38Z
[ "python", "py2exe" ]
py2exe and email libs again
1,770,986
<p>Following imports:</p> <pre><code>import pyodbc, sys, smtplib, os from datetime import date from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from email.mime.base import MIMEBase import email.iterators import email.generator from email import Encoders </code></pre> <p>Works ok whe...
2
2009-11-20T14:58:59Z
31,599,039
<p>Had same issue with email module. Even though it gives warning that lot of modules are missing but when I run, I face only two issues: one with multipart and other with text. I got it working by explicitly including these 2 modules in setup.py: </p> <p><strong>OLD setup.py contained:</strong></p> <pre><code>setup(...
0
2015-07-23T22:18:49Z
[ "python", "py2exe" ]
"No such file or directory" error with Boost Python
1,771,063
<p>I've installed boost python from ubuntu 9.04 repositories. I've successfully run <a href="http://www.boost.org/doc/libs/1_41_0/more/getting_started/unix-variants.html#build-a-simple-program-using-boost" rel="nofollow">Build a Simple Program Using Boost</a> from the tutorial, so I know that boost python is installed ...
17
2009-11-20T15:08:22Z
1,771,089
<p>It looks like you are missing the Python headers (Python.h etc.). Make sure you insteall the -devel or -dev package for your version of Python through the operating system package manager. This should provide the header files...</p> <p>[Edit: noticed you are on ubuntu so try <code>sudo aptitude install python-dev</...
9
2009-11-20T15:13:19Z
[ "python", "boost" ]
"No such file or directory" error with Boost Python
1,771,063
<p>I've installed boost python from ubuntu 9.04 repositories. I've successfully run <a href="http://www.boost.org/doc/libs/1_41_0/more/getting_started/unix-variants.html#build-a-simple-program-using-boost" rel="nofollow">Build a Simple Program Using Boost</a> from the tutorial, so I know that boost python is installed ...
17
2009-11-20T15:08:22Z
1,771,148
<p>add <code>#include &lt;Python.h&gt;</code> and compile with <code>-I/usr/include/python2.6</code> or whatever your Python version is.</p> <p>Do not forget to link it with <code>-lpython2.6 -lboost_python</code></p>
29
2009-11-20T15:19:13Z
[ "python", "boost" ]
"No such file or directory" error with Boost Python
1,771,063
<p>I've installed boost python from ubuntu 9.04 repositories. I've successfully run <a href="http://www.boost.org/doc/libs/1_41_0/more/getting_started/unix-variants.html#build-a-simple-program-using-boost" rel="nofollow">Build a Simple Program Using Boost</a> from the tutorial, so I know that boost python is installed ...
17
2009-11-20T15:08:22Z
8,952,954
<p>Building a big program by executing individual commands like that can quickly get very complicated. You can use a build system like <a href="http://www.cmake.org/cmake/help/cmake_tutorial.html" rel="nofollow">CMake</a> to find the dependencies and sort out the compiler commands for you.</p> <p>The minimal <code>CMa...
3
2012-01-21T12:26:57Z
[ "python", "boost" ]
"No such file or directory" error with Boost Python
1,771,063
<p>I've installed boost python from ubuntu 9.04 repositories. I've successfully run <a href="http://www.boost.org/doc/libs/1_41_0/more/getting_started/unix-variants.html#build-a-simple-program-using-boost" rel="nofollow">Build a Simple Program Using Boost</a> from the tutorial, so I know that boost python is installed ...
17
2009-11-20T15:08:22Z
25,054,651
<p>Although it's quite late, but still, here's my answer:</p> <p>Make sure you have the libboost-python-dev libraries installed:</p> <pre><code>sudo apt-get install libboost-python-dev </code></pre> <p>This did the trick for me. </p>
6
2014-07-31T08:53:10Z
[ "python", "boost" ]
Choosing a Path for Python File Access
1,771,099
<p>One of the features of my project is to allow users to create their own little <code>.txt</code> file, put it somewhere on their HDD, which can then be used as criteria for a part of my application.</p> <p>Is there a Fixed, 'generic'(?) path for <em>most</em> OSs that I could use? Or does anyone have any kind of ad...
4
2009-11-20T15:14:22Z
1,771,178
<p><a href="http://docs.python.org/library/os.path.html?highlight=home#os.path.expanduser" rel="nofollow">os.path.expanduser</a> is a good start -- a leading <code>~/</code> expands to "the user's home directory", which is computer by reasonable heuristics on both Unix-y and Windows systems. Of course, you don't want ...
7
2009-11-20T15:23:24Z
[ "python", "path" ]
Choosing a Path for Python File Access
1,771,099
<p>One of the features of my project is to allow users to create their own little <code>.txt</code> file, put it somewhere on their HDD, which can then be used as criteria for a part of my application.</p> <p>Is there a Fixed, 'generic'(?) path for <em>most</em> OSs that I could use? Or does anyone have any kind of ad...
4
2009-11-20T15:14:22Z
1,771,190
<p>The <a href="http://wxpython.org/docs/api/wx.StandardPaths-class.html" rel="nofollow"><code>wx.StandardPaths</code></a> module contains methods that return various standard locations in the file system and transparently tries to do "the right thing" under Unix, Mac OS X, and Windows.</p>
3
2009-11-20T15:25:20Z
[ "python", "path" ]
Choosing a Path for Python File Access
1,771,099
<p>One of the features of my project is to allow users to create their own little <code>.txt</code> file, put it somewhere on their HDD, which can then be used as criteria for a part of my application.</p> <p>Is there a Fixed, 'generic'(?) path for <em>most</em> OSs that I could use? Or does anyone have any kind of ad...
4
2009-11-20T15:14:22Z
1,771,578
<p>For the copy/paste crowd out there...</p> <pre><code>import os file_obj = open(os.path.expanduser('~/yourapp/file.txt'), 'w') </code></pre> <p>Good luck.</p>
0
2009-11-20T16:18:20Z
[ "python", "path" ]
Newbie Q about Scrapy pipeline.py
1,771,151
<p>I am studying the Scrapy tutorial. To test the process I created a new project with these files:</p> <p><a href="http://groups.google.com/group/scrapy-users/browse%5Ffrm/thread/4d52fa8c589a412a" rel="nofollow">See my post in Scrapy group for links to scripts, I cannot post more than 1 link here.</a></p> <p>The spi...
2
2009-11-20T15:19:33Z
1,771,199
<p>Open file and write to it.</p> <pre><code>f = open('my.cvs','w') f.write('h1\th2\th3\n') f.write(my_class.v1+'\t'+my_class.v2+'\t'+my_class.v3+'\n') f.close() </code></pre> <p>Or output your results on stdout and then redirect stdout to file <code>./my_script.py &gt;&gt; res.txt</code></p>
-1
2009-11-20T15:25:54Z
[ "python", "web-crawler", "scrapy" ]
Newbie Q about Scrapy pipeline.py
1,771,151
<p>I am studying the Scrapy tutorial. To test the process I created a new project with these files:</p> <p><a href="http://groups.google.com/group/scrapy-users/browse%5Ffrm/thread/4d52fa8c589a412a" rel="nofollow">See my post in Scrapy group for links to scripts, I cannot post more than 1 link here.</a></p> <p>The spi...
2
2009-11-20T15:19:33Z
1,771,209
<p>Python has a <a href="http://www.python.org/doc/2.6/library/csv.html" rel="nofollow">module for reading/writing CSV files</a>, this is safer than writing the output yourself (and getting all quoting/escaping right...)</p> <pre><code>import csv csvfile = csv.writer(open('items.csv', 'w')) csvfile.writerow([ firmitem...
0
2009-11-20T15:27:55Z
[ "python", "web-crawler", "scrapy" ]
Newbie Q about Scrapy pipeline.py
1,771,151
<p>I am studying the Scrapy tutorial. To test the process I created a new project with these files:</p> <p><a href="http://groups.google.com/group/scrapy-users/browse%5Ffrm/thread/4d52fa8c589a412a" rel="nofollow">See my post in Scrapy group for links to scripts, I cannot post more than 1 link here.</a></p> <p>The spi...
2
2009-11-20T15:19:33Z
1,774,708
<p>I think they address your specific question in the <a href="http://doc.scrapy.org/intro/tutorial.html#storing-the-data-using-an-item-pipeline" title="Storing the data (using an Item Pipeline)">Scrapy Tutorial</a>.</p> <p>It suggest, as others have here using the CSV module. Place the following in your <code>pipelin...
9
2009-11-21T06:24:05Z
[ "python", "web-crawler", "scrapy" ]
Newbie Q about Scrapy pipeline.py
1,771,151
<p>I am studying the Scrapy tutorial. To test the process I created a new project with these files:</p> <p><a href="http://groups.google.com/group/scrapy-users/browse%5Ffrm/thread/4d52fa8c589a412a" rel="nofollow">See my post in Scrapy group for links to scripts, I cannot post more than 1 link here.</a></p> <p>The spi...
2
2009-11-20T15:19:33Z
12,141,064
<p>Use the built-in <a href="http://scrapy.readthedocs.org/en/latest/topics/feed-exports.html" rel="nofollow">CSV feed export</a> (available in v0.10) together with the <a href="http://scrapy.readthedocs.org/en/latest/topics/exporters.html#scrapy.contrib.exporter.CsvItemExporter" rel="nofollow">CsvItemExporter</a>.</p>...
1
2012-08-27T11:26:06Z
[ "python", "web-crawler", "scrapy" ]
Python detect USB drive then assign drive letter?
1,771,200
<p>Here is the problem. We have 100s of external 500gb USB drives. Each drive will travel to a new location through the year. What is the best way to automatically detect that a USB drive has been plugged into a Windows system, then assign a Z:\ drive letter? These USB drives will be plugged into lots of different comp...
3
2009-11-20T15:26:03Z
1,772,125
<p>You could try compiling that script to an exe and make an autorun file in the USB key which runs the script. Then the script does its things. For the assigning the Z:\ letter thing, I'd suggest using Win32Com (even though I don't know if it can handle this) or use ctypes which will give you control on the windows dl...
1
2009-11-20T17:39:58Z
[ "python", "windows" ]
Python detect USB drive then assign drive letter?
1,771,200
<p>Here is the problem. We have 100s of external 500gb USB drives. Each drive will travel to a new location through the year. What is the best way to automatically detect that a USB drive has been plugged into a Windows system, then assign a Z:\ drive letter? These USB drives will be plugged into lots of different comp...
3
2009-11-20T15:26:03Z
1,775,387
<p>as terabytest said, you may run a script from an autorun.inf in the root of the drive. personally, i would do with a batch script:</p> <pre><code>(echo select volume %~d0 &amp;&amp; echo assign letter=Z) | diskpart </code></pre> <p>the <code>%~d0</code> retrieves the drive letter of the currently executing batch f...
2
2009-11-21T12:43:36Z
[ "python", "windows" ]
Compare string and floats in python
1,771,374
<p>I have a two lists with values that I want to compare. If the value can be converted to a float, I want to compare the floats else I just want to compare the values as strings. How can I make that distinction to check whether a value can be converted to float or not?</p>
0
2009-11-20T15:49:21Z
1,771,420
<p>The easiest way should be to just try to convert them to floats, and if that fails, fall back to a compare on strings:</p> <pre><code>def floatstrcmp(left, right): try: return cmp(float(left), float(right)) except ValueError: return cmp(left, right) </code></pre>
4
2009-11-20T15:56:26Z
[ "python" ]
Invoking context menu in QTreeWidget
1,771,657
<p>I would like to popup a menu, when user clicks on an object in QTreeWidgetItem. I though about catching signal contextMenuRequested from QWidget and then retrieving index from the view using itemAt. But this doesn't seem very pretty. Is there any easier way to be able to call a menu on an item inside a view?</p>
4
2009-11-20T16:30:20Z
1,772,958
<p>I'm using something like this:</p> <pre><code>self.widget_layers.setContextMenuPolicy(Qt.ActionsContextMenu) removeLayerAction = QAction("Remove selected layer", self) self.connect(removeLayerAction, SIGNAL('triggered()'), self.layers_widget_controller.remove_selected_layer) </code></pre> <p>and check which item t...
0
2009-11-20T20:10:52Z
[ "python", "qt", "pyqt", "qtreewidget" ]
Invoking context menu in QTreeWidget
1,771,657
<p>I would like to popup a menu, when user clicks on an object in QTreeWidgetItem. I though about catching signal contextMenuRequested from QWidget and then retrieving index from the view using itemAt. But this doesn't seem very pretty. Is there any easier way to be able to call a menu on an item inside a view?</p>
4
2009-11-20T16:30:20Z
1,775,282
<p>Write your own custom ItemDelegate and handle the click event in <code>QAbstractItemDelegate::editorEvent</code>. You can retreive the data in the cell from the QModelIndex. In C++ it would look like this:</p> <pre><code>class ItemDelegate: public QItemDelegate { public: ItemDelegate(ContextMenuHandler *const ...
4
2009-11-21T11:50:48Z
[ "python", "qt", "pyqt", "qtreewidget" ]
Invoking context menu in QTreeWidget
1,771,657
<p>I would like to popup a menu, when user clicks on an object in QTreeWidgetItem. I though about catching signal contextMenuRequested from QWidget and then retrieving index from the view using itemAt. But this doesn't seem very pretty. Is there any easier way to be able to call a menu on an item inside a view?</p>
4
2009-11-20T16:30:20Z
29,938,527
<p>What I did with the new signal/slot style:</p> <pre><code>self.treeMenu = QMenu() self.treeAction = QAction('print', self.treeMenu) self.treeAction.triggered.connect(self.printTreeItem) self.treeWidget.addAction(self.treeAction) @pyqtSlot() def printTreeItem(self): print self.treeWidget.currentItem().text(...
0
2015-04-29T08:40:37Z
[ "python", "qt", "pyqt", "qtreewidget" ]
Collecting usage data for a desktop application
1,771,765
<p>I'm going to be running some large scale usability tests of my software for a science project. We have a lab of about 30 computers running Windows XP. Our application is written in <a href="http://python.org" rel="nofollow">Python</a> and <a href="http://pygtk.org" rel="nofollow">PyGTK</a>. </p> <p>We want to be ab...
2
2009-11-20T16:50:47Z
1,771,876
<p>For your first point, I believe you can drive <a href="http://recordmydesktop.sourceforge.net/about.php" rel="nofollow">recordMyDesktop</a> directly from your Python code pretty easily -- I haven't done so, myself, but the docs make it look easy (and both existing frontends to it are in Python).</p> <p>For your sec...
2
2009-11-20T17:03:47Z
[ "python", "windows", "usability", "analytics", "metrics" ]
What is the best browser automation tool for Python?
1,771,898
<p>I want to write a following script: given a text file with the list of actions to be executed on a certain site it would use some browser's (IE probably, because I don't know anything about other drive-able ones) CSS rendering and JS executing capabilities to imitate a user doing those actions on a site. </p> <p>So...
2
2009-11-20T17:06:41Z
1,772,096
<p>You should try <a href="http://python.net/crew/skippy/win32/Downloads.html" rel="nofollow">Win32Com</a> as it gives you the possibility to drive programs using their COM server, and if they don't have one you can make it execute simple actions like emulate the pression of a key or move a window from foreground to ba...
1
2009-11-20T17:34:46Z
[ "python", "browser-automation" ]
What is the best browser automation tool for Python?
1,771,898
<p>I want to write a following script: given a text file with the list of actions to be executed on a certain site it would use some browser's (IE probably, because I don't know anything about other drive-able ones) CSS rendering and JS executing capabilities to imitate a user doing those actions on a site. </p> <p>So...
2
2009-11-20T17:06:41Z
1,772,479
<p>Check out <a href="https://addons.mozilla.org/en-US/firefox/addon/9018" rel="nofollow">MozMill</a>, it's for Firefox. Uses JavaScript, should be easier than COM.</p>
1
2009-11-20T18:43:09Z
[ "python", "browser-automation" ]
What is the best browser automation tool for Python?
1,771,898
<p>I want to write a following script: given a text file with the list of actions to be executed on a certain site it would use some browser's (IE probably, because I don't know anything about other drive-able ones) CSS rendering and JS executing capabilities to imitate a user doing those actions on a site. </p> <p>So...
2
2009-11-20T17:06:41Z
1,772,951
<p>I'm not sure if Qt's Webkit through PyQt can solve your issue but I can usually control a simple browser with Python in that way, for instance:</p> <pre><code>import sys import time from PyQt4.QtCore import * from PyQt4.QtGui import * from PyQt4.QtWebKit import * app = QApplication(sys.argv) web = QWebView() se...
2
2009-11-20T20:09:47Z
[ "python", "browser-automation" ]
What is the best browser automation tool for Python?
1,771,898
<p>I want to write a following script: given a text file with the list of actions to be executed on a certain site it would use some browser's (IE probably, because I don't know anything about other drive-able ones) CSS rendering and JS executing capabilities to imitate a user doing those actions on a site. </p> <p>So...
2
2009-11-20T17:06:41Z
1,773,551
<p>You can use autoit COM object using pywin32.</p> <p>Another option is to use selenium 2 (aka webdriver) python bindings.</p>
1
2009-11-20T22:07:15Z
[ "python", "browser-automation" ]
What is the best browser automation tool for Python?
1,771,898
<p>I want to write a following script: given a text file with the list of actions to be executed on a certain site it would use some browser's (IE probably, because I don't know anything about other drive-able ones) CSS rendering and JS executing capabilities to imitate a user doing those actions on a site. </p> <p>So...
2
2009-11-20T17:06:41Z
1,773,641
<p>I'd encourage you to look again at Selenium...that's really what you want to do. Do you need to actually render the page in a browser, or just emulate navigation and clicking? </p> <p><a href="http://wwwsearch.sourceforge.net/mechanize/" rel="nofollow">Mechanize</a> gives you stateful programmatic web browsing, a...
3
2009-11-20T22:29:56Z
[ "python", "browser-automation" ]
Python/MySQL fails under Windows
1,772,001
<p>I'm trying to get Python 2.6 to communicate with MySQL Server 5.1, under Windows XP, but I keep getting a strange error, "SystemError: NULL object passed to Py_BuildValue":</p> <pre><code>&gt;&gt;&gt; import MySQLdb as mysql &gt;&gt;&gt; db = mysql.connect(user = "root", passwd="whatever", db="mysql", host="localh ...
1
2009-11-20T17:21:25Z
1,772,642
<p>Something wrong with MySQLdb part written in C. According to errors message it tries to pass NULL where pointer to object is expected. It's probably a bug in MySQLdb, unless you are using some broken build. What version are you using? Try to download latest stable version of MySQLdb for exactly your python version a...
1
2009-11-20T19:11:35Z
[ "python", "mysql" ]
Is there a way to parse html with lxml, but manipulate it with minidom?
1,772,031
<p>I have an application where I've been using html5lib to liberally parse html. I use the minidom interface, because I need a real DOM API and ElementTree is not appropriate for what I'm doing.</p> <p>Here's how I do this:</p> <pre><code>parser = html5lib.XHTMLParser(tree=html5lib.treebuilders.getTreeBuilder('dom'))...
2
2009-11-20T17:25:15Z
1,772,108
<p>Think I found a solution:</p> <pre><code>from xml.dom.pulldom import SAX2DOM import lxml.sax def parse_lxml_dom(html): tree = lxml.html.document_fromstring(html) handler = SAX2DOM() lxml.sax.saxify(tree, handler) return handler.document </code></pre> <p>However, this is only about 7 times faster th...
4
2009-11-20T17:36:50Z
[ "python", "html", "dom", "parsing", "lxml" ]
List in a dictionary, looping in Python
1,772,068
<p>I have the following code:</p> <pre><code> TYPES = {'hotmail':{'type':'hotmail', 'lookup':'mixed', 'dkim': 'no', 'signatures':['|S|Return-Path: postmaster@hotmail.com','|R|^Return-Path:\s*[^@]+@(?:hot|msn)','^Received: from .*hotmail.com$']}, 'gmail':{'type':'gmail', 'lookup':'mixed', 'dkim': 'yes',...
3
2009-11-20T17:30:41Z
1,772,095
<pre><code>for type_key, type in TYPES.iteritems(): for sub_type_key, sub_type in type.iteritems(): for sig in sub_type['signatures']: </code></pre> <p>should be:</p> <pre><code>for type_key, type in TYPES.iteritems(): for sig in type['signatures']: </code></pre> <p>But 'type' is a poor name choi...
7
2009-11-20T17:34:18Z
[ "python", "list", "dictionary" ]
List in a dictionary, looping in Python
1,772,068
<p>I have the following code:</p> <pre><code> TYPES = {'hotmail':{'type':'hotmail', 'lookup':'mixed', 'dkim': 'no', 'signatures':['|S|Return-Path: postmaster@hotmail.com','|R|^Return-Path:\s*[^@]+@(?:hot|msn)','^Received: from .*hotmail.com$']}, 'gmail':{'type':'gmail', 'lookup':'mixed', 'dkim': 'yes',...
3
2009-11-20T17:30:41Z
1,772,114
<p>[Posted as an answer instead of a comment because retracile beat me to the <a href="#1772095" rel="nofollow">answer</a>, but the formatting is still a point worth making.]</p> <p>Laying out the data helps to visualize it:</p> <pre><code>TYPES = { 'hotmail': { 'type': 'hotmail', 'lookup': 'mixed', 'dk...
3
2009-11-20T17:38:12Z
[ "python", "list", "dictionary" ]
Python equivalent of ruby's __method__?
1,772,070
<p>I want to be able to do this:</p> <pre><code>def asdf(): print __method__ "asdf" </code></pre> <p>Thanks, Noah</p>
1
2009-11-20T17:30:55Z
1,772,087
<p>Use the traceback module:</p> <pre><code>#!/usr/bin/env python import traceback def asdf(): (filename,line_number,function_name,text)=traceback.extract_stack()[-1] print function_name asdf() </code></pre>
4
2009-11-20T17:33:21Z
[ "python", "ruby" ]
Python equivalent of ruby's __method__?
1,772,070
<p>I want to be able to do this:</p> <pre><code>def asdf(): print __method__ "asdf" </code></pre> <p>Thanks, Noah</p>
1
2009-11-20T17:30:55Z
1,772,149
<p>You need to specify your usecase in order for us to give you a better answer. Why do you want to do this?</p> <p>You can get a string with the name of a function by using <code>__name__</code>:</p> <pre><code>def asdf(): print asdf.__name__ "asdf" </code></pre> <p>But, what would be the point? You might aswel...
8
2009-11-20T17:44:04Z
[ "python", "ruby" ]
IOError with Python and OpenCV
1,772,103
<p>I want to do some OpenCV Basic Operations using Python. My Problem is that the Pythoninterpreter says that the file I want to open with cv.LoadImage() dont exists. But as you can see in my code and the and the Interpreter Output this file exists and the Program should be able to read it.</p> <p>Likly the answer is ...
3
2009-11-20T17:35:40Z
1,772,162
<p>Try giving it the whole path instead of the name only, or maybe using .\google-de02.jpg.</p>
1
2009-11-20T17:46:51Z
[ "python", "opencv" ]
IOError with Python and OpenCV
1,772,103
<p>I want to do some OpenCV Basic Operations using Python. My Problem is that the Pythoninterpreter says that the file I want to open with cv.LoadImage() dont exists. But as you can see in my code and the and the Interpreter Output this file exists and the Program should be able to read it.</p> <p>Likly the answer is ...
3
2009-11-20T17:35:40Z
1,772,272
<p>I've tried both suggestions, but its the same like before. the os.access returns a TRUE but the function cv.LoadImage produce the same error.</p> <p>Any other solutions?</p> <p>anyhow thanks fpr answer...</p>
2
2009-11-20T18:02:36Z
[ "python", "opencv" ]
IOError with Python and OpenCV
1,772,103
<p>I want to do some OpenCV Basic Operations using Python. My Problem is that the Pythoninterpreter says that the file I want to open with cv.LoadImage() dont exists. But as you can see in my code and the and the Interpreter Output this file exists and the Program should be able to read it.</p> <p>Likly the answer is ...
3
2009-11-20T17:35:40Z
1,772,383
<p>Try using the repr function when the exception happens.</p>
0
2009-11-20T18:26:47Z
[ "python", "opencv" ]
pysvn with svn+ssh
1,772,133
<p>I'm working with pysvn, and I'm trying to find a decent way to handle repositories that are only accessible via svn+ssh. Obviously SSH keys make this all incredibly easy, but I can't guarantee the end user will be using an SSH key. This also has to be able to run without user interaction, because it's going to be do...
4
2009-11-20T17:41:19Z
1,773,231
<p>Check out ssh configuration option PasswordAuthentication.</p> <p>I'm not sure how pysvn interacts with ssh, but if you set this to no in your ~/.ssh/config (or maybe global config?) then it shouldn't prompt for a password.</p>
2
2009-11-20T21:04:51Z
[ "python", "svn", "ssh", "pysvn" ]
return a FaultObject on purpose from pyamf
1,772,226
<p>I am currently migrating from RubyAMF to PyAMF. In RubyAMF you can return a FaultObject deliberately like so:</p> <pre><code>render :amf =&gt; FaultObject.new("Thats not your pie!") </code></pre> <p>Is there comparable functionality in PyAMF? I've searched the docs and can't find any mention of it.</p>
2
2009-11-20T17:54:49Z
1,815,801
<p>raise Exception, "ur message" can do.</p>
0
2009-11-29T15:25:53Z
[ "python", "django", "flex", "actionscript-3", "pyamf" ]
return a FaultObject on purpose from pyamf
1,772,226
<p>I am currently migrating from RubyAMF to PyAMF. In RubyAMF you can return a FaultObject deliberately like so:</p> <pre><code>render :amf =&gt; FaultObject.new("Thats not your pie!") </code></pre> <p>Is there comparable functionality in PyAMF? I've searched the docs and can't find any mention of it.</p>
2
2009-11-20T17:54:49Z
1,829,649
<p>coulix is right (but due to reputation restrictions I cannot upvote! :)</p> <p>From within your service method, raise an exception as you would normally and PyAMF will trap that and convert it to an appropriate fault object for consumption by the requestor (e.g. using Flex Messaging this will be an ErrorMessage ins...
1
2009-12-01T23:21:18Z
[ "python", "django", "flex", "actionscript-3", "pyamf" ]
Call from Objective-C into Python
1,772,491
<p>bbum <a href="http://stackoverflow.com/questions/1308079/calling-python-from-objective-c/1308469#1308469">posted</a> an outline of how to do this, but I'm unable to complete the details. Where does the Python code go, and how will my Objective-C code know about it? How would I do it compiling on the command line?<...
4
2009-11-20T18:45:36Z
1,772,809
<p>Google is your friend. Performing a search on the string "Cocoa Python" quickly turned up <a href="http://pyobjc.sourceforge.net/" rel="nofollow">PyObjc</a>.</p>
1
2009-11-20T19:45:05Z
[ "python", "objective-c" ]
Call from Objective-C into Python
1,772,491
<p>bbum <a href="http://stackoverflow.com/questions/1308079/calling-python-from-objective-c/1308469#1308469">posted</a> an outline of how to do this, but I'm unable to complete the details. Where does the Python code go, and how will my Objective-C code know about it? How would I do it compiling on the command line?<...
4
2009-11-20T18:45:36Z
1,773,580
<p>Unfortunately the story for using Python via PyObjC from within an Objective-C app is not very good at the moment. <code>py2app</code> which ships with PyObjC can compile loadable bundles (i.e. can be loaded via <code>NSBundle</code>), which seems like the best approach: define an <code>NSObject</code> subclass in p...
3
2009-11-20T22:13:43Z
[ "python", "objective-c" ]
Call from Objective-C into Python
1,772,491
<p>bbum <a href="http://stackoverflow.com/questions/1308079/calling-python-from-objective-c/1308469#1308469">posted</a> an outline of how to do this, but I'm unable to complete the details. Where does the Python code go, and how will my Objective-C code know about it? How would I do it compiling on the command line?<...
4
2009-11-20T18:45:36Z
1,774,565
<p>Source here:</p> <p><a href="http://svn.red-bean.com/bbum/trunk/PyObjC/CallPythonFromObjectiveC/">Calling Python From Objective-C</a></p> <p>I have posted a <a href="http://www.friday.com/bbum/2009/11/21/calling-python-from-objective-c/">full explanation of how to do this to my weblog</a> as it is quite a bit long...
12
2009-11-21T04:59:29Z
[ "python", "objective-c" ]
Creating thumbnails from video files with Python
1,772,599
<p>I need to create thumbnails for a video file once I've uploaded to a webapp running python.</p> <p>How would I go about this... I need a library that can basically either do this for me, or that can read the image frames out of video files (of several formats) automatically.</p>
14
2009-11-20T19:02:27Z
1,772,713
<p>Look into <a href="http://www.imagemagick.org/download/python/" rel="nofollow">PythonMagick</a>, a Python interface to ImageMagick. That should have what you need. (Disclaimer: I haven't used the Python interface before, but I know ImageMagick is good mojo.)</p>
1
2009-11-20T19:24:13Z
[ "python", "video", "thumbnails" ]
Creating thumbnails from video files with Python
1,772,599
<p>I need to create thumbnails for a video file once I've uploaded to a webapp running python.</p> <p>How would I go about this... I need a library that can basically either do this for me, or that can read the image frames out of video files (of several formats) automatically.</p>
14
2009-11-20T19:02:27Z
1,843,043
<p>A simple combination of <a href="http://www.google.ca/url?sa=t&amp;source=web&amp;ct=res&amp;cd=1&amp;ved=0CAcQFjAA&amp;url=http%3A%2F%2Fpymedia.org%2F&amp;ei=YCwYS-GpFtCWlAecr7DsAg&amp;usg=AFQjCNHPaiXIpSAm1EGRtH3lmGGWE6MLEA">PyMedia</a> and <a href="http://www.pythonware.com/products/pil/">PIL</a> would do the tric...
6
2009-12-03T21:27:34Z
[ "python", "video", "thumbnails" ]
Creating thumbnails from video files with Python
1,772,599
<p>I need to create thumbnails for a video file once I've uploaded to a webapp running python.</p> <p>How would I go about this... I need a library that can basically either do this for me, or that can read the image frames out of video files (of several formats) automatically.</p>
14
2009-11-20T19:02:27Z
1,844,330
<p>You could use the Youtube API for storage and transcoding and grab the feed thumbnails for free. Honestly, that's the easiest way to handle online video and I'm not just shilling a 3rd party service, I'm a very happy user of that API and the internal video paths I was able to delete thanks to it.</p>
3
2009-12-04T01:33:09Z
[ "python", "video", "thumbnails" ]
Creating thumbnails from video files with Python
1,772,599
<p>I need to create thumbnails for a video file once I've uploaded to a webapp running python.</p> <p>How would I go about this... I need a library that can basically either do this for me, or that can read the image frames out of video files (of several formats) automatically.</p>
14
2009-11-20T19:02:27Z
15,130,746
<p>You can use <a href="https://bitbucket.org/zakhar/ffvideo/wiki/Home">ffvideo</a></p> <pre class="lang-py prettyprint-override"><code>from ffvideo import VideoStream pil_image = VideoStream('0.flv').get_frame_at_sec(5).image() pil_image.save('frame5sec.jpeg') </code></pre>
6
2013-02-28T08:26:19Z
[ "python", "video", "thumbnails" ]
Creating thumbnails from video files with Python
1,772,599
<p>I need to create thumbnails for a video file once I've uploaded to a webapp running python.</p> <p>How would I go about this... I need a library that can basically either do this for me, or that can read the image frames out of video files (of several formats) automatically.</p>
14
2009-11-20T19:02:27Z
38,669,959
<pre><code>import cv2 vcap = cv2.VideoCapture(filename) res, im_ar = vcap.read() while im_ar.mean() &lt; threshold and res: res, im_ar = vcap.read() im_ar = cv2.resize(im_ar, (thumb_widht, thumb_height), 0, 0, cv2.INTER_LINEAR) #to save we have two options #1) save on a file cv2.imwrite(save_on_filename) #2)save ...
0
2016-07-30T02:59:16Z
[ "python", "video", "thumbnails" ]
What Python features will excite the interest of a C# developer?
1,773,063
<p>For someone who’s been happily programming in C# for quite some time now and planning to learn a new language I find the Python community more closely knit than many others. </p> <p>Personally dynamic typing puts me off, but I am fascinated by the way the Python community rallies around it. There are a lot of ot...
20
2009-11-20T20:30:24Z
1,773,082
<p>Being able to type in some code and get the result back <em>immediately</em>.</p> <p>(Disclaimer: I use both C# and Python regularly, and I think both have their good and bad points.)</p>
14
2009-11-20T20:33:41Z
[ "c#", "python", "programming-languages" ]
What Python features will excite the interest of a C# developer?
1,773,063
<p>For someone who’s been happily programming in C# for quite some time now and planning to learn a new language I find the Python community more closely knit than many others. </p> <p>Personally dynamic typing puts me off, but I am fascinated by the way the Python community rallies around it. There are a lot of ot...
20
2009-11-20T20:30:24Z
1,773,087
<p>For me its the flexibility and elegance, but there are a handful of things I wish could be pulled in from other languages though (better threading, more robust expressions).</p> <p>In typical I can write a little bit of code in python and do a lot more than the same amount of lines in many other languages. Also, i...
18
2009-11-20T20:34:22Z
[ "c#", "python", "programming-languages" ]
What Python features will excite the interest of a C# developer?
1,773,063
<p>For someone who’s been happily programming in C# for quite some time now and planning to learn a new language I find the Python community more closely knit than many others. </p> <p>Personally dynamic typing puts me off, but I am fascinated by the way the Python community rallies around it. There are a lot of ot...
20
2009-11-20T20:30:24Z
1,773,215
<p>I like all stuff with [] and {}. Selectors like this [-1:1]. Possibility to write less code, but more something meaningfull, that gives to write Models and other declarative things very DRY.</p>
1
2009-11-20T21:01:57Z
[ "c#", "python", "programming-languages" ]
What Python features will excite the interest of a C# developer?
1,773,063
<p>For someone who’s been happily programming in C# for quite some time now and planning to learn a new language I find the Python community more closely knit than many others. </p> <p>Personally dynamic typing puts me off, but I am fascinated by the way the Python community rallies around it. There are a lot of ot...
20
2009-11-20T20:30:24Z
1,773,224
<p>I'm primarily .NET developer and using Python for me personal projects.</p> <blockquote> <p>What are the good things about python that developers love?</p> </blockquote> <p>I can say for myself - Python is like a breath of fresh air. </p> <p>1) It's simple to learn, took about a week for me in the evenings. I'm...
10
2009-11-20T21:03:31Z
[ "c#", "python", "programming-languages" ]
What Python features will excite the interest of a C# developer?
1,773,063
<p>For someone who’s been happily programming in C# for quite some time now and planning to learn a new language I find the Python community more closely knit than many others. </p> <p>Personally dynamic typing puts me off, but I am fascinated by the way the Python community rallies around it. There are a lot of ot...
20
2009-11-20T20:30:24Z
1,773,278
<p>Your question is kind of like a plumber asking why carpenters are always going on and on about hammers. After all the plumber doesn't have a hammer and has never missed it. Python (even IronPython) and C# target different types of developers and different types of programs. I am very comfortable in Python and enj...
9
2009-11-20T21:13:58Z
[ "c#", "python", "programming-languages" ]
What Python features will excite the interest of a C# developer?
1,773,063
<p>For someone who’s been happily programming in C# for quite some time now and planning to learn a new language I find the Python community more closely knit than many others. </p> <p>Personally dynamic typing puts me off, but I am fascinated by the way the Python community rallies around it. There are a lot of ot...
20
2009-11-20T20:30:24Z
1,773,305
<p>My language of choice is C#, and I didn't quite see the point for me to learn Python so far. <a href="http://ecn.channel9.msdn.com/o9/pdc09/wmv/FT30.wmv" rel="nofollow">This talk from PDC09</a> really piqued my interest: the guy demonstrates how you can use IronPython (or IronRuby) to make a C# app scriptable (in hi...
4
2009-11-20T21:20:50Z
[ "c#", "python", "programming-languages" ]
What Python features will excite the interest of a C# developer?
1,773,063
<p>For someone who’s been happily programming in C# for quite some time now and planning to learn a new language I find the Python community more closely knit than many others. </p> <p>Personally dynamic typing puts me off, but I am fascinated by the way the Python community rallies around it. There are a lot of ot...
20
2009-11-20T20:30:24Z
1,773,312
<p>The main thing I like about Python is its very concise, readable syntax. Though using indentation as a block delimiter can seem strange at first, once you begin to code a lot in the language I find it begins to make sense. Though the core language is quite simple, its more advanced features, e.g. list comprehension,...
0
2009-11-20T21:22:09Z
[ "c#", "python", "programming-languages" ]
What Python features will excite the interest of a C# developer?
1,773,063
<p>For someone who’s been happily programming in C# for quite some time now and planning to learn a new language I find the Python community more closely knit than many others. </p> <p>Personally dynamic typing puts me off, but I am fascinated by the way the Python community rallies around it. There are a lot of ot...
20
2009-11-20T20:30:24Z
1,773,315
<p>I'm an <em>asymmetrical</em> user of both languages, in a sense that I use C# mostly professionally and Python for all my "fun" projects (not that work is never fun, but... you know...)</p> <p>This difference of context may skew my perspective, including my opinion that they are two distinct types (pun intended) of...
2
2009-11-20T21:22:22Z
[ "c#", "python", "programming-languages" ]
What Python features will excite the interest of a C# developer?
1,773,063
<p>For someone who’s been happily programming in C# for quite some time now and planning to learn a new language I find the Python community more closely knit than many others. </p> <p>Personally dynamic typing puts me off, but I am fascinated by the way the Python community rallies around it. There are a lot of ot...
20
2009-11-20T20:30:24Z
1,773,317
<p>Like any programming language, it is just a tool in the box or a brush by which you may paint your creation. Any creative endeavour requires that the artist loves the tools he uses; otherwise, the outcome suffers. Some people like Python for the same reason others love Perl. Incidentally, I have found that most Py...
1
2009-11-20T21:22:54Z
[ "c#", "python", "programming-languages" ]
What Python features will excite the interest of a C# developer?
1,773,063
<p>For someone who’s been happily programming in C# for quite some time now and planning to learn a new language I find the Python community more closely knit than many others. </p> <p>Personally dynamic typing puts me off, but I am fascinated by the way the Python community rallies around it. There are a lot of ot...
20
2009-11-20T20:30:24Z
1,773,322
<p>Don't get me wrong, I am and will always be a devoted fan of C#.</p> <p>But sometimes there are things I can't do in C#. lthough C# keeps reducing those gaps, Python is still the language I go to to fill them.</p> <p>It's dynamic, flexible, powerful, and clean. Lovely language. Whenever I need to script or build d...
0
2009-11-20T21:23:56Z
[ "c#", "python", "programming-languages" ]
What Python features will excite the interest of a C# developer?
1,773,063
<p>For someone who’s been happily programming in C# for quite some time now and planning to learn a new language I find the Python community more closely knit than many others. </p> <p>Personally dynamic typing puts me off, but I am fascinated by the way the Python community rallies around it. There are a lot of ot...
20
2009-11-20T20:30:24Z
1,773,421
<p>For me Python is the most elegant language I've used. The syntax is minimalist (significantly less punctuation than most) and intentionally modeled after the psuedo-code conventions which are ubiquitously used by programmer to outline their intentions.</p> <p>Python's <code>if __name__ == '__main__':</code> suite ...
0
2009-11-20T21:42:56Z
[ "c#", "python", "programming-languages" ]
What Python features will excite the interest of a C# developer?
1,773,063
<p>For someone who’s been happily programming in C# for quite some time now and planning to learn a new language I find the Python community more closely knit than many others. </p> <p>Personally dynamic typing puts me off, but I am fascinated by the way the Python community rallies around it. There are a lot of ot...
20
2009-11-20T20:30:24Z
1,773,523
<p>If you are familiar with the .NET CLR and prefer a statically-typed language, but you like Python's lightweight syntax, then perhaps <a href="http://boo.codehaus.org/" rel="nofollow">Boo</a> is the language for you.</p>
1
2009-11-20T22:00:40Z
[ "c#", "python", "programming-languages" ]
What Python features will excite the interest of a C# developer?
1,773,063
<p>For someone who’s been happily programming in C# for quite some time now and planning to learn a new language I find the Python community more closely knit than many others. </p> <p>Personally dynamic typing puts me off, but I am fascinated by the way the Python community rallies around it. There are a lot of ot...
20
2009-11-20T20:30:24Z
1,773,987
<p>I'm a very heavy user of both C# and Python; I've built very complicated applications in both languages, and I've also embedded Python scripting in my major C# application. I'm not using either to do much in the way of web work right now, but other than that I feel like I'm pretty qualified to answer the question.<...
9
2009-11-21T00:07:22Z
[ "c#", "python", "programming-languages" ]
posix_ipc python package equivalent for Windows?
1,773,078
<p>Inter process communication primitives (Semaphores, Shared Memory) in python on windows? posix_ipc works great on linux, anything similar for windows?</p>
1
2009-11-20T20:33:11Z
1,773,536
<p>You can use most (all) of the <a href="http://msdn.microsoft.com/en-us/library/aa365574%28VS.85%29.aspx" rel="nofollow">win32 ipc</a> when you install <a href="http://sourceforge.net/projects/pywin32/" rel="nofollow">pywin32</a></p>
1
2009-11-20T22:03:47Z
[ "python", "ipc" ]
Linking Tcl/Tk to Python 2.5
1,773,222
<p>I have an existing Python 2.4 and it is working properly with tkinter as I tested it using </p> <p>python</p> <p>import _tkinter</p> <blockquote> <blockquote> <blockquote> <p>import Tkinter Tkinter._test() </p> </blockquote> </blockquote> </blockquote> <p>Now, I have installed python 2.5....
0
2009-11-20T21:02:50Z
1,773,435
<p>The files you found are for linking directly to tcl/tk. Python depends on another library as well: _tkinter.so. It should be in /usr/lib/python2.5/lib-dynload/_tkinter.so.<br> How did you install python2.5? If you are using Debian or Ubuntu you need to install the python-tk package to get Tkinter support.</p> <p>If...
3
2009-11-20T21:46:00Z
[ "python", "tcl", "tkinter", "tk" ]
How to count and display objects in relation ManyToMany in Django
1,773,504
<p>I have a simple model with news and categories:</p> <pre><code>class Category(models.Model): name = models.CharField() slug = models.SlugField() class News(models.Model): category = models.ManyToManyField(Category) title = models.CharField() slug = models.SlugField() text = models.TextField...
3
2009-11-20T21:57:48Z
1,773,532
<p>Check out annotate() function from Django 1.1.</p> <p><a href="http://docs.djangoproject.com/en/dev/topics/db/aggregation/#topics-db-aggregation">http://docs.djangoproject.com/en/dev/topics/db/aggregation/#topics-db-aggregation</a></p> <p>Example (from that URL above):</p> <pre><code>&gt;&gt;&gt; q = Book.objects...
6
2009-11-20T22:03:22Z
[ "python", "django", "django-models", "many-to-many" ]
How to count and display objects in relation ManyToMany in Django
1,773,504
<p>I have a simple model with news and categories:</p> <pre><code>class Category(models.Model): name = models.CharField() slug = models.SlugField() class News(models.Model): category = models.ManyToManyField(Category) title = models.CharField() slug = models.SlugField() text = models.TextField...
3
2009-11-20T21:57:48Z
18,515,417
<p>Very simple:</p> <pre><code>&gt;&gt;&gt; for category in Category.objects.all(): ... print category.name, category.news_set.count() </code></pre>
1
2013-08-29T15:44:10Z
[ "python", "django", "django-models", "many-to-many" ]
Class attribute evaluation and generators
1,773,636
<p>How exactly does Python evaluate class attributes? I've stumbled across an interesting quirk (in Python 2.5.2) that I'd like explained.</p> <p>I have a class with some attributes that are defined in terms of other, previously defined attributes. When I try using a generator object, Python throws an error, but if ...
15
2009-11-20T22:29:02Z
1,773,697
<p>Yeah, it's a bit dodgy, this. A class doesn't really introduce a new scope, it just sort of looks a little bit like it does; constructs like this expose the difference.</p> <p>The idea is that when you're using a generator expression it's equivalent to doing it with a lambda:</p> <pre><code>class Brie(object): ...
14
2009-11-20T22:46:45Z
[ "python", "class", "attributes", "class-attributes" ]
Class attribute evaluation and generators
1,773,636
<p>How exactly does Python evaluate class attributes? I've stumbled across an interesting quirk (in Python 2.5.2) that I'd like explained.</p> <p>I have a class with some attributes that are defined in terms of other, previously defined attributes. When I try using a generator object, Python throws an error, but if ...
15
2009-11-20T22:29:02Z
1,773,713
<p>From <a href="http://www.python.org/dev/peps/pep-0289/#id12" rel="nofollow">PEP 289</a>:</p> <blockquote> <p>After exploring many possibilities, a consensus emerged that binding issues were hard to understand and that users should be strongly encouraged to use generator expressions inside functions that...
1
2009-11-20T22:49:50Z
[ "python", "class", "attributes", "class-attributes" ]
PyQt4, QThread and opening big files without freezing the GUI
1,773,716
<p>I would like to ask how to read a big file from disk and maintain the PyQt4 UI responsive (not blocked). I had moved the load of the file to a QThread subclass but my GUI thread get freezed. Any suggestions? I think it must be something with the GIL but I don't know how to sort it?</p> <p>EDIT: I am using vtkGDCMIm...
1
2009-11-20T22:51:02Z
1,773,835
<p>Take a look at <a href="http://stackoverflow.com/questions/1595649/threading-in-a-pyqt-application-use-qt-threads-or-python-threads">threading-in-a-pyqt-application-use-qt-threads-or-python-threads</a></p>
1
2009-11-20T23:21:39Z
[ "python", "pyqt" ]
PyQt4, QThread and opening big files without freezing the GUI
1,773,716
<p>I would like to ask how to read a big file from disk and maintain the PyQt4 UI responsive (not blocked). I had moved the load of the file to a QThread subclass but my GUI thread get freezed. Any suggestions? I think it must be something with the GIL but I don't know how to sort it?</p> <p>EDIT: I am using vtkGDCMIm...
1
2009-11-20T22:51:02Z
2,067,912
<p>Maybe create your reader object in the tread:</p> <pre><code>class ReadThread(QThread): def __init__(self, file_name): super(ReadThread, self).__init__(self) self.file_name = file_name - self.reader = vtkgdcm.vtkGDCMImageReader() def run(self): + self.reader = vtkgdcm.vtkGD...
0
2010-01-14T22:04:43Z
[ "python", "pyqt" ]
PyQt4, QThread and opening big files without freezing the GUI
1,773,716
<p>I would like to ask how to read a big file from disk and maintain the PyQt4 UI responsive (not blocked). I had moved the load of the file to a QThread subclass but my GUI thread get freezed. Any suggestions? I think it must be something with the GIL but I don't know how to sort it?</p> <p>EDIT: I am using vtkGDCMIm...
1
2009-11-20T22:51:02Z
2,762,239
<p>I'm guessing you're directly calling the <code>run</code> to begin the thread. That would make the GUI freeze because you're not activating the thread.</p> <p>So you'd be missing the <code>start</code> there, which would indirectly and properly call the <code>run</code>:</p> <pre><code>thread = ReadThread() thread...
3
2010-05-04T01:22:53Z
[ "python", "pyqt" ]
PyQt4, QThread and opening big files without freezing the GUI
1,773,716
<p>I would like to ask how to read a big file from disk and maintain the PyQt4 UI responsive (not blocked). I had moved the load of the file to a QThread subclass but my GUI thread get freezed. Any suggestions? I think it must be something with the GIL but I don't know how to sort it?</p> <p>EDIT: I am using vtkGDCMIm...
1
2009-11-20T22:51:02Z
4,986,552
<p>A bit late, but I think I can pinpoint the problem you face. </p> <p>The image is large, and the unpacking is probably a CPU intensive task. This means that your GUI thread goes to sleep and the loading thread is CPU bound. At that point the loading thread has the GIL, and the GUI cannot start. </p> <p>Even if you...
1
2011-02-13T20:10:02Z
[ "python", "pyqt" ]
mingw + python eagerly translating path
1,773,763
<p>I am using:</p> <ul> <li>Windows XP</li> <li>Python 2.6.2 (standard install from python.org)</li> <li>git version 1.6.5.1-preview20091022 (installed from <a href="http://code.google.com/p/msysgit/" rel="nofollow">http://code.google.com/p/msysgit/</a>)</li> </ul> <p>I have an environment variable looking like an ab...
2
2009-11-20T23:04:04Z
1,773,862
<p>My guess would be that this is not python at fault, but the git bash shell.<br> Maybe the git bash shell is lying to you when you look at the variable.<br> Or, try to not put the first / and add it again later (if translation does not occurs).</p> <p>If I try with cygwin, it works:</p> <pre><code>$ export test="/b...
1
2009-11-20T23:27:34Z
[ "python", "bash", "mingw", "msysgit" ]
mingw + python eagerly translating path
1,773,763
<p>I am using:</p> <ul> <li>Windows XP</li> <li>Python 2.6.2 (standard install from python.org)</li> <li>git version 1.6.5.1-preview20091022 (installed from <a href="http://code.google.com/p/msysgit/" rel="nofollow">http://code.google.com/p/msysgit/</a>)</li> </ul> <p>I have an environment variable looking like an ab...
2
2009-11-20T23:04:04Z
1,951,056
<p>The console you get from msysgit is probably modified for git user's needs, from my POV, it is only useful for simple tasks and to access git command line not to develop and run python scripts (you are using a Python installation for Windows in a shell installed for a specific application, that doesn't sound good).<...
1
2009-12-23T06:44:51Z
[ "python", "bash", "mingw", "msysgit" ]
mingw + python eagerly translating path
1,773,763
<p>I am using:</p> <ul> <li>Windows XP</li> <li>Python 2.6.2 (standard install from python.org)</li> <li>git version 1.6.5.1-preview20091022 (installed from <a href="http://code.google.com/p/msysgit/" rel="nofollow">http://code.google.com/p/msysgit/</a>)</li> </ul> <p>I have an environment variable looking like an ab...
2
2009-11-20T23:04:04Z
5,260,252
<p>The problem definitely sounds like it's caused by MSYS. When an MSYS process execs a non-MSYS process (e.g. your msysgit bash shell calling native Windows Python), the arguments are checked for anything that looks like an absolute POSIX path (e.g. things that start with a single '/') and these are translated to the...
2
2011-03-10T13:28:54Z
[ "python", "bash", "mingw", "msysgit" ]
Convert ConfigParser.items('') to dictionary
1,773,793
<p>How can I convert the result of a ConfigParser.items('section') to a dictionary to format a string like here:</p> <pre><code>import ConfigParser config = ConfigParser.ConfigParser() config.read('conf.ini') connection_string = ("dbname='%(dbname)s' user='%(dbuser)s' host='%(host)s' " "password...
35
2009-11-20T23:11:28Z
1,773,820
<p>Have you tried</p> <pre><code>print connection_string % dict(config.items('db')) </code></pre> <p>?</p>
58
2009-11-20T23:19:00Z
[ "python" ]
Convert ConfigParser.items('') to dictionary
1,773,793
<p>How can I convert the result of a ConfigParser.items('section') to a dictionary to format a string like here:</p> <pre><code>import ConfigParser config = ConfigParser.ConfigParser() config.read('conf.ini') connection_string = ("dbname='%(dbname)s' user='%(dbuser)s' host='%(host)s' " "password...
35
2009-11-20T23:11:28Z
1,773,851
<p>This is actually already done for you in <code>config._sections</code>. Example:</p> <pre><code>$ cat test.ini [First Section] var = value key = item [Second Section] othervar = othervalue otherkey = otheritem </code></pre> <p>And then:</p> <pre><code>&gt;&gt;&gt; from ConfigParser import ConfigParser &gt;&gt;&...
38
2009-11-20T23:24:57Z
[ "python" ]
Convert ConfigParser.items('') to dictionary
1,773,793
<p>How can I convert the result of a ConfigParser.items('section') to a dictionary to format a string like here:</p> <pre><code>import ConfigParser config = ConfigParser.ConfigParser() config.read('conf.ini') connection_string = ("dbname='%(dbname)s' user='%(dbuser)s' host='%(host)s' " "password...
35
2009-11-20T23:11:28Z
23,944,270
<p>I know this was asked a long time ago and a solution chosen, but the solution selected does not take into account defaults and variable substitution. Since it's the first hit when searching for creating dicts from parsers, thought I'd post my solution which does include default and variable substitutions by using Co...
8
2014-05-29T22:48:25Z
[ "python" ]
Convert ConfigParser.items('') to dictionary
1,773,793
<p>How can I convert the result of a ConfigParser.items('section') to a dictionary to format a string like here:</p> <pre><code>import ConfigParser config = ConfigParser.ConfigParser() config.read('conf.ini') connection_string = ("dbname='%(dbname)s' user='%(dbuser)s' host='%(host)s' " "password...
35
2009-11-20T23:11:28Z
28,721,671
<p>For an individual section, e.g. "general", you can do:</p> <pre><code>dict(parser['general']) </code></pre>
1
2015-02-25T14:32:42Z
[ "python" ]
Convert ConfigParser.items('') to dictionary
1,773,793
<p>How can I convert the result of a ConfigParser.items('section') to a dictionary to format a string like here:</p> <pre><code>import ConfigParser config = ConfigParser.ConfigParser() config.read('conf.ini') connection_string = ("dbname='%(dbname)s' user='%(dbuser)s' host='%(host)s' " "password...
35
2009-11-20T23:11:28Z
28,990,982
<p>How I did it in just one line.</p> <pre><code>my_config_parser_dict = {s:dict(config.items(s)) for s in config.sections()} </code></pre> <p>No more than other answers but when it is not the real businesses of your method and you need it just in one place use less lines and take the power of dict compression could ...
11
2015-03-11T15:37:26Z
[ "python" ]
How can I parse a YAML file in Python
1,773,805
<p>How can I parse a YAML file in Python?</p>
204
2009-11-20T23:16:16Z
1,774,043
<p>The easiest and pureist method without relying on C headers is PyYaml:</p> <pre><code>#!/usr/bin/env python import yaml with open("example.yaml", 'r') as stream: try: print(yaml.load(stream)) except yaml.YAMLError as exc: print(exc) </code></pre> <p>Err.. that's it... how many lines of co...
273
2009-11-21T00:23:34Z
[ "python", "yaml" ]
How can I parse a YAML file in Python
1,773,805
<p>How can I parse a YAML file in Python?</p>
204
2009-11-20T23:16:16Z
38,922,434
<p>If you have YAML that conforms to the YAML 1.2 specification (released 2009) then you should use <a href="https://pypi.python.org/pypi/ruamel.yaml/">ruamel.yaml</a> (disclaimer: I am the author of that package). It is essentially a superset of PyYAML, which supports a most of YAML 1.1 (from 2005).</p> <p>If you wan...
6
2016-08-12T16:15:46Z
[ "python", "yaml" ]
Sort a CSV by date in Python
1,773,909
<p>I'm trying to sort a CSV file and I want the items sorted by date in reverse order: newest first.</p> <pre><code>def SortCsvByField( filename, fieldNo, sep = ',' ): records = [line.split(sep) for line in file(filename)] </code></pre> <p>As far as that it's pretty easy, but how do I compare dates?</p>
3
2009-11-20T23:44:36Z
1,773,915
<p>What you show is pretty easy but also pretty fragile. </p> <p>It is best to use Python's CSV library: <a href="http://docs.python.org/library/csv.html" rel="nofollow">http://docs.python.org/library/csv.html</a></p> <p>About comparing dates (I'm assuming some dates are in a specific column on each row) you can use ...
2
2009-11-20T23:48:36Z
[ "python", "sorting", "csv" ]
Sort a CSV by date in Python
1,773,909
<p>I'm trying to sort a CSV file and I want the items sorted by date in reverse order: newest first.</p> <pre><code>def SortCsvByField( filename, fieldNo, sep = ',' ): records = [line.split(sep) for line in file(filename)] </code></pre> <p>As far as that it's pretty easy, but how do I compare dates?</p>
3
2009-11-20T23:44:36Z
1,773,923
<p>If your dates are in ISO-8601 format (YYYY-MM-DD) then you can sort them as strings, otherwise you will have to parse them first (datetime.strptime).</p> <p>Then you can sort using for example <code>sorted(records, key=lambda a:a[1])</code>, if the date is the second field.</p>
2
2009-11-20T23:50:31Z
[ "python", "sorting", "csv" ]
Sort a CSV by date in Python
1,773,909
<p>I'm trying to sort a CSV file and I want the items sorted by date in reverse order: newest first.</p> <pre><code>def SortCsvByField( filename, fieldNo, sep = ',' ): records = [line.split(sep) for line in file(filename)] </code></pre> <p>As far as that it's pretty easy, but how do I compare dates?</p>
3
2009-11-20T23:44:36Z
1,774,046
<p>I'd recommend installing the excellent <a href="http://labix.org/python-dateutil">dateutil</a> module. (In Ubuntu/Debian, it is provided by the python-dateutil package).</p> <p>dateutil can parse date strings into datetime objects: It can handle many different date formats without you having to lift a finger(*):</p...
5
2009-11-21T00:24:25Z
[ "python", "sorting", "csv" ]
Sort a CSV by date in Python
1,773,909
<p>I'm trying to sort a CSV file and I want the items sorted by date in reverse order: newest first.</p> <pre><code>def SortCsvByField( filename, fieldNo, sep = ',' ): records = [line.split(sep) for line in file(filename)] </code></pre> <p>As far as that it's pretty easy, but how do I compare dates?</p>
3
2009-11-20T23:44:36Z
1,774,069
<p>Assuming that you know the format of the dates, and that they're in column 1 of your CSV file:</p> <pre><code>&gt;&gt;&gt; import csv &gt;&gt;&gt; from datetime import datetime &gt;&gt;&gt; def date_key(row): return datetime.strptime(row[1].strip(), "%m/%d/%Y") &gt;&gt;&gt; with open('c:\\temp\\test\\date_...
2
2009-11-21T00:33:00Z
[ "python", "sorting", "csv" ]
Listing blog entries by year,month
1,774,011
<p>I want to do something like this:</p> <pre><code>Entries.objects.values('date.year','date.month') </code></pre> <p>but this line is not valid. How can I list blog entries by year,month and display them in template?</p> <p>Thanks!</p>
1
2009-11-21T00:14:42Z
1,774,075
<p>Here is some code snipped from my blog where I list all of the blog entries within a certain year:</p> <pre><code>Entries.objects.filter(draft=drafts).filter(posted_date__year=year).order_by(order_by) </code></pre> <p>In the above:</p> <ul> <li><code>drafts</code> is a boolean which specifies whether to show comp...
1
2009-11-21T00:34:10Z
[ "python", "django", "date" ]
Listing blog entries by year,month
1,774,011
<p>I want to do something like this:</p> <pre><code>Entries.objects.values('date.year','date.month') </code></pre> <p>but this line is not valid. How can I list blog entries by year,month and display them in template?</p> <p>Thanks!</p>
1
2009-11-21T00:14:42Z
1,774,405
<p>If you set</p> <pre><code>entry_list = Entry.objects.order_by('pub_date') </code></pre> <p>in your view, you can display the months and years in the template using the <a href="http://docs.djangoproject.com/en/dev/ref/templates/builtins/#ifchanged">ifchanged</a> template tag.</p> <pre><code>{% for entry in entry_...
8
2009-11-21T03:29:31Z
[ "python", "django", "date" ]
Listing blog entries by year,month
1,774,011
<p>I want to do something like this:</p> <pre><code>Entries.objects.values('date.year','date.month') </code></pre> <p>but this line is not valid. How can I list blog entries by year,month and display them in template?</p> <p>Thanks!</p>
1
2009-11-21T00:14:42Z
1,776,283
<p>You can try with the built-in regroup tag.</p> <p>In your view:</p> <pre><code>archives = Entries.objects.all() </code></pre> <p>In your template:</p> <pre><code>{% regroup archives by date.month as entries_by_month %} {% for entries in entries_by_month %} &lt;h1&gt;{{ entries.list.0.date|date:"F Y" }}&lt;/h...
4
2009-11-21T18:22:23Z
[ "python", "django", "date" ]
Listing blog entries by year,month
1,774,011
<p>I want to do something like this:</p> <pre><code>Entries.objects.values('date.year','date.month') </code></pre> <p>but this line is not valid. How can I list blog entries by year,month and display them in template?</p> <p>Thanks!</p>
1
2009-11-21T00:14:42Z
17,708,706
<p>Ok, let's try to do heavy lifting in data structure, instead of templates.</p> <p>Let's create a utility.</p> <pre><code>import itertools def group_by_values(posts, key): groups = {} for k, g in itertools.groupby(posts, key): if groups.get(k) is not None: groups[k].extend(list(g)) ...
0
2013-07-17T19:35:18Z
[ "python", "django", "date" ]
Emacs customization
1,774,320
<p>I'm new to the whole Emacs thing, and one of the things that gets me is that out-of-the-box Emacs doesn't keep you within blocks when programming. I program in mostly Python and C++ and hitting enter sends the cursor back to column 1 on a new line rather than keeping you in the block you're working in. I managed to ...
1
2009-11-21T02:31:44Z
1,774,335
<p>The following is from my init.el for xemacs, it might or might not work for emacs:</p> <pre><code>(add-hook 'c-mode-common-hook '(lambda () (define-key c-mode-base-map (kbd "RET") 'newline-and-indent))) </code></pre>
5
2009-11-21T02:39:42Z
[ "c++", "python", "emacs", "customization" ]
Python ctypes & libspeex.dll/libspeex.so; what are the equivilents to #define, typedef, and structs?
1,774,383
<p>I have a reference of the dll file here: <a href="http://speex.org/docs/api/speex-api-reference/group%5F%5FCodec.html" rel="nofollow">http://speex.org/docs/api/speex-api-reference/group__Codec.html</a></p> <p>What I'm wondering is, in that list, there are a lot of defines. What is the python equivalent, same for ...
1
2009-11-21T03:20:01Z
1,774,548
<p>I figured out structs at least, and how to basically convert them.</p> <p>Basically you just make a class, pass it ctypes.Structure, then make your array of fields.</p> <p>like so:</p> <pre><code>class PASSWD(ctypes.Structure): _fields_ = [("name", ctypes.c_char_p), ("passwd", ctypes.c_char_p), ...
0
2009-11-21T04:48:59Z
[ "python", "c", "api", "ctypes", "speex" ]
Python ctypes & libspeex.dll/libspeex.so; what are the equivilents to #define, typedef, and structs?
1,774,383
<p>I have a reference of the dll file here: <a href="http://speex.org/docs/api/speex-api-reference/group%5F%5FCodec.html" rel="nofollow">http://speex.org/docs/api/speex-api-reference/group__Codec.html</a></p> <p>What I'm wondering is, in that list, there are a lot of defines. What is the python equivalent, same for ...
1
2009-11-21T03:20:01Z
1,774,725
<p>To use structs, you indeed should declare them with <code>ctypes.Structure</code> to let Python know about them. </p> <pre><code>&gt;&gt;&gt; from ctypes import * &gt;&gt;&gt; class POINT(Structure): ... _fields_ = [("x", c_int), ... ("y", c_int)] ... &gt;&gt;&gt; point = POINT(10, 20) &gt;&gt;&...
2
2009-11-21T06:31:24Z
[ "python", "c", "api", "ctypes", "speex" ]