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
Cannot prettify scraped html in BeautifulSoup
2,022,014
<p>I have a small script that use <code>urllib2</code> to get contents of a site, find all the link tags, appends a small piece of HTML in on the top and bottom, and then I try to prettify it. It keeps returning TypeError: sequence item 1: expected string, Tag found. I have looked around,i can't really find the issue. ...
2
2010-01-07T16:53:48Z
6,281,375
<p>A bit of a syntax error on Jonathans answer, here's the correct one:</p> <pre><code> soup1 = BeautifulSoup(''.join([unicode(tag) for tag in tags])) </code></pre>
0
2011-06-08T15:32:06Z
[ "python", "html", "parsing", "beautifulsoup" ]
Python append() vs. + operator on lists, why do these give different results?
2,022,031
<p>Why do these two operations (<code>append()</code> resp. <code>+</code>) give different results?</p> <pre><code>&gt;&gt;&gt; c = [1, 2, 3] &gt;&gt;&gt; c [1, 2, 3] &gt;&gt;&gt; c += c &gt;&gt;&gt; c [1, 2, 3, 1, 2, 3] &gt;&gt;&gt; c = [1, 2, 3] &gt;&gt;&gt; c.append(c) &gt;&gt;&gt; c [1, 2, 3, [...]] &gt;&gt;&gt; ...
48
2010-01-07T16:56:58Z
2,022,044
<h3>To explain "why":</h3> <p>The <a href="http://docs.python.org/reference/datamodel.html#object.__add__"><code>+</code> operation</a> adds the <a href="http://docs.python.org/library/array.html">array</a> elements to the original array. The <a href="http://docs.python.org/library/array.html?highlight=append#array.ar...
84
2010-01-07T16:58:39Z
[ "python", "list", "append", "nested-lists" ]
Python append() vs. + operator on lists, why do these give different results?
2,022,031
<p>Why do these two operations (<code>append()</code> resp. <code>+</code>) give different results?</p> <pre><code>&gt;&gt;&gt; c = [1, 2, 3] &gt;&gt;&gt; c [1, 2, 3] &gt;&gt;&gt; c += c &gt;&gt;&gt; c [1, 2, 3, 1, 2, 3] &gt;&gt;&gt; c = [1, 2, 3] &gt;&gt;&gt; c.append(c) &gt;&gt;&gt; c [1, 2, 3, [...]] &gt;&gt;&gt; ...
48
2010-01-07T16:56:58Z
2,022,052
<p><code>append</code> is appending an element to a list. if you want to extend the list with the new list you need to use <code>extend</code>.</p> <pre><code>&gt;&gt;&gt; c = [1, 2, 3] &gt;&gt;&gt; c.extend(c) &gt;&gt;&gt; c [1, 2, 3, 1, 2, 3] </code></pre>
12
2010-01-07T16:59:50Z
[ "python", "list", "append", "nested-lists" ]
Python append() vs. + operator on lists, why do these give different results?
2,022,031
<p>Why do these two operations (<code>append()</code> resp. <code>+</code>) give different results?</p> <pre><code>&gt;&gt;&gt; c = [1, 2, 3] &gt;&gt;&gt; c [1, 2, 3] &gt;&gt;&gt; c += c &gt;&gt;&gt; c [1, 2, 3, 1, 2, 3] &gt;&gt;&gt; c = [1, 2, 3] &gt;&gt;&gt; c.append(c) &gt;&gt;&gt; c [1, 2, 3, [...]] &gt;&gt;&gt; ...
48
2010-01-07T16:56:58Z
2,022,059
<p>Python lists are heterogeneous that is the elements in the same list can be any type of object. The expression: <code>c.append(c)</code> appends the object <code>c</code> what ever it may be to the list. In the case it makes the list itself a member of the list.</p> <p>The expression <code>c += c</code> adds two li...
7
2010-01-07T17:00:49Z
[ "python", "list", "append", "nested-lists" ]
Python append() vs. + operator on lists, why do these give different results?
2,022,031
<p>Why do these two operations (<code>append()</code> resp. <code>+</code>) give different results?</p> <pre><code>&gt;&gt;&gt; c = [1, 2, 3] &gt;&gt;&gt; c [1, 2, 3] &gt;&gt;&gt; c += c &gt;&gt;&gt; c [1, 2, 3, 1, 2, 3] &gt;&gt;&gt; c = [1, 2, 3] &gt;&gt;&gt; c.append(c) &gt;&gt;&gt; c [1, 2, 3, [...]] &gt;&gt;&gt; ...
48
2010-01-07T16:56:58Z
2,022,072
<p>you should use extend()</p> <pre><code>&gt;&gt;&gt; c=[1,2,3] &gt;&gt;&gt; c.extend(c) &gt;&gt;&gt; c [1, 2, 3, 1, 2, 3] </code></pre> <p>other info: <a href="http://stackoverflow.com/questions/252703/python-append-vs-extend">http://stackoverflow.com/questions/252703/python-append-vs-extend</a></p>
1
2010-01-07T17:02:07Z
[ "python", "list", "append", "nested-lists" ]
Python append() vs. + operator on lists, why do these give different results?
2,022,031
<p>Why do these two operations (<code>append()</code> resp. <code>+</code>) give different results?</p> <pre><code>&gt;&gt;&gt; c = [1, 2, 3] &gt;&gt;&gt; c [1, 2, 3] &gt;&gt;&gt; c += c &gt;&gt;&gt; c [1, 2, 3, 1, 2, 3] &gt;&gt;&gt; c = [1, 2, 3] &gt;&gt;&gt; c.append(c) &gt;&gt;&gt; c [1, 2, 3, [...]] &gt;&gt;&gt; ...
48
2010-01-07T16:56:58Z
2,022,092
<p>The method you're looking for is <code>extend()</code>. From the Python <a href="http://docs.python.org/tutorial/datastructures.html">documentation</a>:</p> <pre><code>list.append(x) Add an item to the end of the list; equivalent to a[len(a):] = [x]. list.extend(L) Extend the list by appending all the item...
5
2010-01-07T17:03:59Z
[ "python", "list", "append", "nested-lists" ]
Python append() vs. + operator on lists, why do these give different results?
2,022,031
<p>Why do these two operations (<code>append()</code> resp. <code>+</code>) give different results?</p> <pre><code>&gt;&gt;&gt; c = [1, 2, 3] &gt;&gt;&gt; c [1, 2, 3] &gt;&gt;&gt; c += c &gt;&gt;&gt; c [1, 2, 3, 1, 2, 3] &gt;&gt;&gt; c = [1, 2, 3] &gt;&gt;&gt; c.append(c) &gt;&gt;&gt; c [1, 2, 3, [...]] &gt;&gt;&gt; ...
48
2010-01-07T16:56:58Z
2,022,135
<p>See <a href="http://docs.python.org/tutorial/datastructures.html#more-on-lists" rel="nofollow">the documentation</a>:</p> <blockquote> <p>list.append(x)</p> <ul> <li>Add an item to the end of the list; equivalent to a[len(a):] = [x].</li> </ul> <p>list.extend(L) - Extend the list by appending all...
1
2010-01-07T17:10:03Z
[ "python", "list", "append", "nested-lists" ]
Python append() vs. + operator on lists, why do these give different results?
2,022,031
<p>Why do these two operations (<code>append()</code> resp. <code>+</code>) give different results?</p> <pre><code>&gt;&gt;&gt; c = [1, 2, 3] &gt;&gt;&gt; c [1, 2, 3] &gt;&gt;&gt; c += c &gt;&gt;&gt; c [1, 2, 3, 1, 2, 3] &gt;&gt;&gt; c = [1, 2, 3] &gt;&gt;&gt; c.append(c) &gt;&gt;&gt; c [1, 2, 3, [...]] &gt;&gt;&gt; ...
48
2010-01-07T16:56:58Z
17,439,223
<p>The concatenation operator <a href="http://docs.python.org/reference/datamodel.html#object.__add__"><code>+</code></a> is a binary infix operator which, when applied to lists, returns a new list containing all the elements of each of its two operands. The <a href="http://docs.python.org/tutorial/datastructures.html#...
6
2013-07-03T03:35:40Z
[ "python", "list", "append", "nested-lists" ]
Running Different Django Versions But Sharing Authentication
2,022,178
<p>Brand new to django. We have a legacy django project using django 0.96x that does authentication, ldap, etc., and it's pretty involved so we don't want to rewrite that code.</p> <p>We want to add a forum solution (off the shelf) but all of the ones I've seen so far require django 1.x </p> <p>I'm trying to figure o...
0
2010-01-07T17:18:28Z
2,022,368
<p>A user's login status is stored using sessions. As far as I can tell from comparing trunk to the 0.96 source, the sessions are committed to a cookie the same way, and auth stores the user ID and backend the same way, so as long as the two apps use the same session storage and are on the same domain, it should work. ...
0
2010-01-07T17:47:06Z
[ "python", "django", "mod-python" ]
Running Different Django Versions But Sharing Authentication
2,022,178
<p>Brand new to django. We have a legacy django project using django 0.96x that does authentication, ldap, etc., and it's pretty involved so we don't want to rewrite that code.</p> <p>We want to add a forum solution (off the shelf) but all of the ones I've seen so far require django 1.x </p> <p>I'm trying to figure o...
0
2010-01-07T17:18:28Z
2,022,407
<p>It's possible, but it may be pretty painful to do option #3.</p> <p>How about Option 4: bite the bullet and upgrade to Django 1.1.1. I did this with a couple of 0.97pre sites and it took less time than I thought it would. The biggest pain was dealing with admin stuff. Instead of going with separate <code>admin.py</...
1
2010-01-07T17:53:18Z
[ "python", "django", "mod-python" ]
Running Different Django Versions But Sharing Authentication
2,022,178
<p>Brand new to django. We have a legacy django project using django 0.96x that does authentication, ldap, etc., and it's pretty involved so we don't want to rewrite that code.</p> <p>We want to add a forum solution (off the shelf) but all of the ones I've seen so far require django 1.x </p> <p>I'm trying to figure o...
0
2010-01-07T17:18:28Z
2,029,226
<p>It's possible to expose Django 0.96 tables to 1.1 - you can use unmanaged models wrapped around database VIEWs. In other words you issue:</p> <p>CREATE VIEW auth_user AS SELECT * from django096db.auth_user; (and similar cmd for other tables)</p> <p>and then you have Django 1.1 synchronized with 0.96 (assuming 0.96...
0
2010-01-08T17:03:51Z
[ "python", "django", "mod-python" ]
Python asyncore vs plain old C
2,022,211
<p>i'm stress testing 2 different projects: one is proxsmtpd - smtp proxy written in C And the other one, smtp_proxy.py, which i developed under 1 hour, with use of asyncore and smtpd python modules.</p> <p>I stressed both projects under heavy load, and found out that proxsmtpd is able to hold 400 smtp sessions / sec,...
2
2010-01-07T17:25:38Z
2,022,273
<p>I think it's a fair assumption that given a <em>good</em> C version and a <em>good</em> Python version, the C version will be faster and more scalable but in your case, you might want to run a profiler and see why and where your program is not scaling up as much as the C version. Perhaps you can uncover the tight sp...
2
2010-01-07T17:35:29Z
[ "python", "proxy", "smtp", "asyncore", "smtpd" ]
what does yield as assignment do? myVar = (yield)
2,022,218
<p>I'm familiar with yield to return a value thanks mostly to <a href="http://stackoverflow.com/questions/231767/can-somebody-explain-me-the-python-yield-statement">this question</a> </p> <p>but what does yield do when it is on the right side of an assignment?</p> <pre><code>@coroutine def protocol(target=None): w...
27
2010-01-07T17:26:26Z
2,022,300
<p>You can send values to the generator using the <code>send</code> function.</p> <p>If you execute:</p> <pre><code>p = protocol() p.next() # advance to the yield statement, otherwise I can't call send p.send(5) </code></pre> <p>then <code>yield</code> will return 5, so inside the generator <code>c</code> will be 5....
11
2010-01-07T17:38:22Z
[ "python", "yield" ]
what does yield as assignment do? myVar = (yield)
2,022,218
<p>I'm familiar with yield to return a value thanks mostly to <a href="http://stackoverflow.com/questions/231767/can-somebody-explain-me-the-python-yield-statement">this question</a> </p> <p>but what does yield do when it is on the right side of an assignment?</p> <pre><code>@coroutine def protocol(target=None): w...
27
2010-01-07T17:26:26Z
2,022,303
<p>The <code>yield</code> statement used in a function turns that function into a "generator" (a function that creates an iterator). The resulting iterator is normally resumed by calling <code>next()</code>. However it is possible to send values to the function by calling the method <code>send()</code> instead of <code...
30
2010-01-07T17:38:57Z
[ "python", "yield" ]
Get list of open windows in Python
2,022,219
<p>I'm writing and app in Python that must be able to send keys or text to other app. For example, If I have Firefox open, I should be able to send it an URL to open it. I've already have the SendKeys module, and I read about the win32 module too, but I don't know if there's a way to filter out process without open win...
2
2010-01-07T17:26:32Z
2,022,242
<p>Usually, for this sort of "GUI automation" <a href="http://code.google.com/p/pywinauto/" rel="nofollow">pyWinAuto</a> is a good way to go. We use it to allow automated testing of GUI applications, and it ought to let you "type" URLs into Firefox (not to mention finding its window) as well.</p>
3
2010-01-07T17:30:51Z
[ "python", "windows", "pywin32" ]
Get list of open windows in Python
2,022,219
<p>I'm writing and app in Python that must be able to send keys or text to other app. For example, If I have Firefox open, I should be able to send it an URL to open it. I've already have the SendKeys module, and I read about the win32 module too, but I don't know if there's a way to filter out process without open win...
2
2010-01-07T17:26:32Z
2,022,294
<p>Even if you need to use automation for everything else your app is going to do, it would probably be a lot easier to use the <a href="http://docs.python.org/library/webbrowser.html" rel="nofollow"><code>webbrowser</code></a> module for opening urls in the user's browser.</p>
2
2010-01-07T17:37:53Z
[ "python", "windows", "pywin32" ]
Get list of open windows in Python
2,022,219
<p>I'm writing and app in Python that must be able to send keys or text to other app. For example, If I have Firefox open, I should be able to send it an URL to open it. I've already have the SendKeys module, and I read about the win32 module too, but I don't know if there's a way to filter out process without open win...
2
2010-01-07T17:26:32Z
2,023,404
<p>try using <a href="http://code.google.com/p/dragonfly/" rel="nofollow">dragonfly</a>. It has a whole lot of automation stuff built into it. You don't need the speech recognition part in order to use the automation stuff. For example:</p> <pre><code>from dragonfly import Window Window.get_all_windows() </code></pre>...
2
2010-01-07T20:27:20Z
[ "python", "windows", "pywin32" ]
cherrypy and wxpython
2,022,376
<p>I'm trying to make a cherrypy application with a wxpython ui. The problem is both libraries use closed loop event handlers. Is there a way for this to work? If I have the wx ui start cherrypy is that going to lock up the ui?</p>
7
2010-01-07T17:48:08Z
2,022,434
<p>If you use threading, you should be able to start up the CherryPy server in one thread and run wxPython in the other. This article (<a href="http://wiki.wxpython.org/LongRunningTasks" rel="nofollow">http://wiki.wxpython.org/LongRunningTasks</a>) on the wxPython wiki has some info on threading, and the CherryPy serve...
1
2010-01-07T17:58:00Z
[ "python", "wxpython", "cherrypy" ]
cherrypy and wxpython
2,022,376
<p>I'm trying to make a cherrypy application with a wxpython ui. The problem is both libraries use closed loop event handlers. Is there a way for this to work? If I have the wx ui start cherrypy is that going to lock up the ui?</p>
7
2010-01-07T17:48:08Z
2,022,467
<p>One way to decouple them would be to start them up as two separate processes and have them communicate via some kind of IPC mechanism. You might have to write a small adaptor to have them speak a common protocol.</p> <p>Since you're doing CherryPy, you might also be able to expose a control interface via HTTP which...
1
2010-01-07T18:04:48Z
[ "python", "wxpython", "cherrypy" ]
cherrypy and wxpython
2,022,376
<p>I'm trying to make a cherrypy application with a wxpython ui. The problem is both libraries use closed loop event handlers. Is there a way for this to work? If I have the wx ui start cherrypy is that going to lock up the ui?</p>
7
2010-01-07T17:48:08Z
2,022,784
<p>I would encourage you to take a look at the Calibre (e-book manager) <a href="https://launchpad.net/calibre" rel="nofollow">source</a>. It is written in PyQT, but uses CherryPy to allow people to view their library from outside their LAN.</p>
1
2010-01-07T18:49:58Z
[ "python", "wxpython", "cherrypy" ]
cherrypy and wxpython
2,022,376
<p>I'm trying to make a cherrypy application with a wxpython ui. The problem is both libraries use closed loop event handlers. Is there a way for this to work? If I have the wx ui start cherrypy is that going to lock up the ui?</p>
7
2010-01-07T17:48:08Z
2,023,352
<p>See my answer at <a href="http://stackoverflow.com/questions/1075351/cherrypy-interferes-with-twisted-shutting-down-on-windows">http://stackoverflow.com/questions/1075351/cherrypy-interferes-with-twisted-shutting-down-on-windows</a></p> <p>In short, CherryPy handles the main loop by default, but it definitely doesn...
5
2010-01-07T20:16:58Z
[ "python", "wxpython", "cherrypy" ]
How do I deal with multiple common user interfaces?
2,022,448
<p>I'm working on a python application that runs on 2 different platforms, namely regular desktop linux and Maemo 4. We use PyGTK on both platforms but on Maemo there are a bunch of little tweaks to make it look nice which are implemented as follows:</p> <pre><code>if util.platform.MAEMO: # do something fancy for ...
7
2010-01-07T18:00:15Z
2,022,495
<p>You could isolate the platform specific stuff you need to do into small consistently named functions inside a <code>platform</code> module, create the right function name using the platform you're running on and then <code>getattr</code> the right one and call it. The if/else boilerplate would disappear then.</p>
0
2010-01-07T18:07:37Z
[ "python", "user-interface", "pygtk", "code-reuse", "maemo" ]
How do I deal with multiple common user interfaces?
2,022,448
<p>I'm working on a python application that runs on 2 different platforms, namely regular desktop linux and Maemo 4. We use PyGTK on both platforms but on Maemo there are a bunch of little tweaks to make it look nice which are implemented as follows:</p> <pre><code>if util.platform.MAEMO: # do something fancy for ...
7
2010-01-07T18:00:15Z
2,022,503
<p>You could wind up much of this in a factory:</p> <pre><code>def createSpec(): if util.platform.MAEMO: return Maemo4Spec() elif util.platform.MAEMO5: return Maemo5Spec() return StandardPyGTKSpec() </code></pre> <p>Then, somewhere early in your code, you just call that factory:</p> <pre><code> spec = createSp...
10
2010-01-07T18:09:02Z
[ "python", "user-interface", "pygtk", "code-reuse", "maemo" ]
How do I deal with multiple common user interfaces?
2,022,448
<p>I'm working on a python application that runs on 2 different platforms, namely regular desktop linux and Maemo 4. We use PyGTK on both platforms but on Maemo there are a bunch of little tweaks to make it look nice which are implemented as follows:</p> <pre><code>if util.platform.MAEMO: # do something fancy for ...
7
2010-01-07T18:00:15Z
2,246,419
<p>I've made a separate module to handle all of my specializing between normal Linux, Maemo 4.1, and Maemo 5. It detects what features are available and allows the program to gracefully degrade.</p> <p>For example</p> <pre><code> def _fremantle_hildonize_window(app, window): oldWindow = window newW...
0
2010-02-11T17:51:29Z
[ "python", "user-interface", "pygtk", "code-reuse", "maemo" ]
How to diff file and output stream "on-the-fly"?
2,022,492
<p>I need to create a diff file using standard UNIX <strong>diff</strong> command with python <strong>subprocess</strong> module. The problem is that I must compare file and stream without creating tempopary file. I thought about using named pipes via <strong>os.mkfifo</strong> method, but didn't reach any good result....
25
2010-01-07T18:07:32Z
2,022,512
<p>You can use "-" as an argument to <code>diff</code> to mean <code>stdin</code>.</p>
35
2010-01-07T18:10:25Z
[ "python", "diff", "subprocess", "pipe" ]
How to diff file and output stream "on-the-fly"?
2,022,492
<p>I need to create a diff file using standard UNIX <strong>diff</strong> command with python <strong>subprocess</strong> module. The problem is that I must compare file and stream without creating tempopary file. I thought about using named pipes via <strong>os.mkfifo</strong> method, but didn't reach any good result....
25
2010-01-07T18:07:32Z
2,022,556
<p>You could perhaps consider using the <a href="http://docs.python.org/library/difflib.html#difflib-interface">difflib</a> python module (I've linked to an example here) and create something that generates and prints the diff directly rather than relying on <code>diff</code>. The various function methods inside diffli...
8
2010-01-07T18:16:04Z
[ "python", "diff", "subprocess", "pipe" ]
Handling spreadsheet data through the clipboard in GTK
2,022,594
<p>I'm using a <a href="http://vhernandez.github.com/gtksheet/" rel="nofollow"><code>GtkSheet</code></a> widget in PyGTK to power my application's spreadsheet, and it gives me an API to pull and push data out of cells. (I looked at using GtkTreeView, but it seemed to be too much work)</p> <p>What I don't understand is...
3
2010-01-07T18:21:17Z
2,056,084
<p>To catch the paste event, you need to first create a custom entry class (<code>PastableEntry</code> in this example) that inherits from <code>gtksheet.ItemEntry</code>. During its initialisation, we connect to the <code>paste-clipboard</code> signal to trap paste events:</p> <pre><code>class PastableEntry(gtksheet....
6
2010-01-13T11:00:16Z
[ "python", "linux", "gtk", "clipboard", "pygtk" ]
How to handle new files to process in cron job
2,022,775
<p>How can I check files that I already processed in a script so I don't process those again? and/or What is wrong with the way I am doing this now?</p> <p>Hello, I am running <a href="http://www.wireshark.org/docs/man-pages/tshark.html" rel="nofollow">tshark</a> with the ring buffer option to dump to files after 5MB...
2
2010-01-07T18:48:36Z
2,022,926
<p>I see several issues.</p> <p>If you have overlapping cron jobs you need to have a locking mechanism to control access. Only allow one process at a time to eliminate the overlap problem. You might setup a shell script to do that. Create a 'lock' by making a directory (mkdir is atomic), process the data, then delete ...
0
2010-01-07T19:11:53Z
[ "python", "mysql", "file-io", "sysadmin", "hash" ]
How to handle new files to process in cron job
2,022,775
<p>How can I check files that I already processed in a script so I don't process those again? and/or What is wrong with the way I am doing this now?</p> <p>Hello, I am running <a href="http://www.wireshark.org/docs/man-pages/tshark.html" rel="nofollow">tshark</a> with the ring buffer option to dump to files after 5MB...
2
2010-01-07T18:48:36Z
2,023,020
<p>I don't know enough about what is in these files, so this may not work for you, but if you have only one intended consumer, I would recommend using directories and moving the files to reflect their state. Specifically, you could have a dir structure like</p> <pre><code>/waiting /progress /done </code></pre> <p>and...
2
2010-01-07T19:25:55Z
[ "python", "mysql", "file-io", "sysadmin", "hash" ]
How to handle new files to process in cron job
2,022,775
<p>How can I check files that I already processed in a script so I don't process those again? and/or What is wrong with the way I am doing this now?</p> <p>Hello, I am running <a href="http://www.wireshark.org/docs/man-pages/tshark.html" rel="nofollow">tshark</a> with the ring buffer option to dump to files after 5MB...
2
2010-01-07T18:48:36Z
2,023,065
<p>Why not just move a processed file to a different directory?</p> <p>You mentioned overlapping cron jobs. Does this mean one conversion process can start before the previous one finished? That means you would perform the move at the beginning of the conversion. If you are worries about an interrupted conversion, ...
0
2010-01-07T19:33:08Z
[ "python", "mysql", "file-io", "sysadmin", "hash" ]
How to handle new files to process in cron job
2,022,775
<p>How can I check files that I already processed in a script so I don't process those again? and/or What is wrong with the way I am doing this now?</p> <p>Hello, I am running <a href="http://www.wireshark.org/docs/man-pages/tshark.html" rel="nofollow">tshark</a> with the ring buffer option to dump to files after 5MB...
2
2010-01-07T18:48:36Z
2,023,436
<p>If I'm reading the code correctly, you're updating the database (by which I mean the log of files processed) at the very end. So when you have a huge file that's being processed and not yet complete, another cron job will 'legally' start working on it. - both completing succesfully resulting in two entries in the da...
0
2010-01-07T20:34:06Z
[ "python", "mysql", "file-io", "sysadmin", "hash" ]
How to handle new files to process in cron job
2,022,775
<p>How can I check files that I already processed in a script so I don't process those again? and/or What is wrong with the way I am doing this now?</p> <p>Hello, I am running <a href="http://www.wireshark.org/docs/man-pages/tshark.html" rel="nofollow">tshark</a> with the ring buffer option to dump to files after 5MB...
2
2010-01-07T18:48:36Z
2,023,720
<p>A good way to handle/process files that are created at random times is to use <code>incron</code> rather than <code>cron</code>. (Note: since incron uses the Linux kernel's <a href="http://inotify.aiken.cz/?section=inotify&amp;page=why&amp;lang=en" rel="nofollow">inotify</a> syscalls, this solution only works with L...
4
2010-01-07T21:13:17Z
[ "python", "mysql", "file-io", "sysadmin", "hash" ]
Getting started w/ Python on the desktop
2,022,967
<p>I'm interested in getting started w/ developing Python based applications for a desktop environment and have a few (seemingly simple) questions:</p> <ol> <li>What is the best method for developing GUI applications? I've seen several frameworks but the indexes I've found are a bit convoluted and mix (what seem to be...
2
2010-01-07T19:17:21Z
2,022,977
<p>Have you considered <a href="http://ironpython.net/" rel="nofollow">Iron Python</a> as an option? It's basically the Python language on top of the .NET Framework. Having been fortunate enough to work with the .NET Framework in the past on desktop-applications, I can attest to its depth of excellent.</p>
1
2010-01-07T19:19:11Z
[ "python", "desktop-application" ]
Getting started w/ Python on the desktop
2,022,967
<p>I'm interested in getting started w/ developing Python based applications for a desktop environment and have a few (seemingly simple) questions:</p> <ol> <li>What is the best method for developing GUI applications? I've seen several frameworks but the indexes I've found are a bit convoluted and mix (what seem to be...
2
2010-01-07T19:17:21Z
2,022,996
<p>wxPython is a phenomenal GUI toolkit for developing native applications. I highly recommend it. Also, if you combine it with py2exe you can create .exe files for running on Windows.</p>
1
2010-01-07T19:21:53Z
[ "python", "desktop-application" ]
Getting started w/ Python on the desktop
2,022,967
<p>I'm interested in getting started w/ developing Python based applications for a desktop environment and have a few (seemingly simple) questions:</p> <ol> <li>What is the best method for developing GUI applications? I've seen several frameworks but the indexes I've found are a bit convoluted and mix (what seem to be...
2
2010-01-07T19:17:21Z
2,023,140
<ol> <li><a href="http://wxpython.org" rel="nofollow">wxPython</a> is the best GUI framework.</li> <li>The official <a href="http://python.org/doc/" rel="nofollow">docs</a> are the best resource. They helped me quite a bit.</li> </ol>
3
2010-01-07T19:44:06Z
[ "python", "desktop-application" ]
Getting started w/ Python on the desktop
2,022,967
<p>I'm interested in getting started w/ developing Python based applications for a desktop environment and have a few (seemingly simple) questions:</p> <ol> <li>What is the best method for developing GUI applications? I've seen several frameworks but the indexes I've found are a bit convoluted and mix (what seem to be...
2
2010-01-07T19:17:21Z
2,023,368
<p><a href="http://www.easygui.com/" rel="nofollow">easyGUI</a> and <a href="http://wiki.python.org/moin/TkInter" rel="nofollow">Tkinter</a> are VERY easy libraries that can be used with Python to make GUIs. Further, as stealthdragon has suggested, you can use <a href="http://www.py2exe.org" rel="nofollow">py2exe</a> t...
1
2010-01-07T20:20:10Z
[ "python", "desktop-application" ]
Choosing a web application framework in python
2,023,111
<p>I am python newbie from the <a href="http://www.asp.net/%28S%28d35rmemuuono1wvm1gsp2n45%29%29/mvc/">asp.net MVC</a> world, looking to start a new web application project in python. </p> <p>How do I go about <strong>choosing a web application framework</strong> in python? <a href="http://wiki.python.org/moin/WebFra...
10
2010-01-07T19:40:46Z
2,023,133
<p>I would recommend <a href="http://www.pylonsproject.org/" rel="nofollow">Pylons</a>, it's more customizable and intuitive personally than Django, and instead of proprietary components for say, an ORM, the ideal setup is using best of breed components, so you can use say, Mako for templating.. SQLAlchemy for ORM, you...
8
2010-01-07T19:43:41Z
[ "python", "web-applications", "frameworks" ]
Choosing a web application framework in python
2,023,111
<p>I am python newbie from the <a href="http://www.asp.net/%28S%28d35rmemuuono1wvm1gsp2n45%29%29/mvc/">asp.net MVC</a> world, looking to start a new web application project in python. </p> <p>How do I go about <strong>choosing a web application framework</strong> in python? <a href="http://wiki.python.org/moin/WebFra...
10
2010-01-07T19:40:46Z
2,023,146
<p>I'm in exactly the same boat, and I found that the Pylons approach is the most similar to .NET MVC. It has good support, though arguably not as comprehensive as the .NET world.</p> <p>Even if you choose Pylons, you still have a lot of choices to make, but they recommend using Mako as the template engine (which wil...
3
2010-01-07T19:44:48Z
[ "python", "web-applications", "frameworks" ]
Choosing a web application framework in python
2,023,111
<p>I am python newbie from the <a href="http://www.asp.net/%28S%28d35rmemuuono1wvm1gsp2n45%29%29/mvc/">asp.net MVC</a> world, looking to start a new web application project in python. </p> <p>How do I go about <strong>choosing a web application framework</strong> in python? <a href="http://wiki.python.org/moin/WebFra...
10
2010-01-07T19:40:46Z
2,023,241
<p>If you're just getting started with Python and want to get a working site with the minimum LOC, I would highly recommend Django.</p> <p>One of the biggest advantages of Django for someone new to python is the excellent documentation. The <a href="http://djangobook.com/en/2.0/">Django Book</a> is a great way to dive...
11
2010-01-07T19:59:43Z
[ "python", "web-applications", "frameworks" ]
Choosing a web application framework in python
2,023,111
<p>I am python newbie from the <a href="http://www.asp.net/%28S%28d35rmemuuono1wvm1gsp2n45%29%29/mvc/">asp.net MVC</a> world, looking to start a new web application project in python. </p> <p>How do I go about <strong>choosing a web application framework</strong> in python? <a href="http://wiki.python.org/moin/WebFra...
10
2010-01-07T19:40:46Z
2,023,486
<p>I don't think Django is nearly as restrictive as some folks make it out to be. Any framework you select will be a trade off between your ability to forge your own path and the need to reinvent the wheel. For the purposes you describe, Django certainly seems like the right approach.</p> <p>It might be worth your wh...
2
2010-01-07T20:41:28Z
[ "python", "web-applications", "frameworks" ]
Choosing a web application framework in python
2,023,111
<p>I am python newbie from the <a href="http://www.asp.net/%28S%28d35rmemuuono1wvm1gsp2n45%29%29/mvc/">asp.net MVC</a> world, looking to start a new web application project in python. </p> <p>How do I go about <strong>choosing a web application framework</strong> in python? <a href="http://wiki.python.org/moin/WebFra...
10
2010-01-07T19:40:46Z
30,136,429
<p>I thinks <strong>best</strong> and <strong>powerfull</strong> and <strong>light</strong> python framework is <a href="http://www.tornadoweb.org" rel="nofollow">tornado</a>!! developemented by Facebook.</p>
1
2015-05-09T05:36:11Z
[ "python", "web-applications", "frameworks" ]
Trying to get HTTP code. Can someone try this code for me in their Python interpretor and see why it doesn't work?
2,023,312
<pre><code>import httplib def httpCode(theurl): if theurl.startswith("http://"): theurl = theurl[7:] head = theurl[:theurl.find('/')] tail = theurl[theurl.find('/'):] response_code = 0 conn = httplib.HTTPConnection(head) conn.request("HEAD",tail) res = conn.getresponse() response_code = ...
1
2010-01-07T20:10:17Z
2,023,389
<p>Your code worked for me, and for one other person who commented. This implies that the URL you're using is causing a problem with your parsing somehow. <code>head</code> and <code>tail</code> should both be examined in order to determine what it thinks the host is. For example:</p> <pre><code>head = theurl[:theu...
2
2010-01-07T20:24:05Z
[ "python", "http", "exception", "url" ]
Trying to get HTTP code. Can someone try this code for me in their Python interpretor and see why it doesn't work?
2,023,312
<pre><code>import httplib def httpCode(theurl): if theurl.startswith("http://"): theurl = theurl[7:] head = theurl[:theurl.find('/')] tail = theurl[theurl.find('/'):] response_code = 0 conn = httplib.HTTPConnection(head) conn.request("HEAD",tail) res = conn.getresponse() response_code = ...
1
2010-01-07T20:10:17Z
2,023,433
<p>As suggested in comment by Adam Crossland, you should be checking your head and tail values. In your case, without a trailing slash you end up with</p> <pre><code>head = "youtube.co" tail = "m" </code></pre> <p>string.find returns -1 if it is not found, hence you are grabbing all but last character for head and o...
2
2010-01-07T20:33:04Z
[ "python", "http", "exception", "url" ]
Socket module does not work in my Python
2,023,429
<p>Very simple.</p> <pre><code>&gt;&gt;&gt; import socket &gt;&gt;&gt; socket.gethostbyname('http://yahoo.com') Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; socket.gaierror: [Errno -2] Name or service not known </code></pre>
0
2010-01-07T20:31:39Z
2,023,435
<p>Very simple.</p> <p>"http://yahoo.com" is not a host name. Try <code>socket.gethostbyname('yahoo.com')</code> :)</p>
12
2010-01-07T20:33:49Z
[ "python", "http", "sockets" ]
Socket module does not work in my Python
2,023,429
<p>Very simple.</p> <pre><code>&gt;&gt;&gt; import socket &gt;&gt;&gt; socket.gethostbyname('http://yahoo.com') Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; socket.gaierror: [Errno -2] Name or service not known </code></pre>
0
2010-01-07T20:31:39Z
2,023,447
<p>It is because, quite frankly, <code>http://yahoo.com</code> is in no way a <em>domain name</em>, which <code>gethostbyname</code> expects from you. <code>http://yahoo.com</code> is an URL.</p> <pre><code>&gt;&gt;&gt; import socket &gt;&gt;&gt; socket.gethostbyname("yahoo.com") '69.147.114.224' </code></pre>
2
2010-01-07T20:35:45Z
[ "python", "http", "sockets" ]
dumb question alert: use *both* ruby on rails and python possible?
2,023,458
<p>the front end and end-user data-collection we want to build in RoR since it's just some simple forms connected to a database.</p> <p>The integration with other external api's such as twitter and facebook and parsing of the data entered by the users we want to do in python, mostly because the developer for that part...
0
2010-01-07T20:37:33Z
2,023,546
<p>Yes, it is possible at some degree using Java. You may use JRuby and Jython in the same app.</p>
0
2010-01-07T20:49:46Z
[ "python", "ruby-on-rails", "ruby" ]
dumb question alert: use *both* ruby on rails and python possible?
2,023,458
<p>the front end and end-user data-collection we want to build in RoR since it's just some simple forms connected to a database.</p> <p>The integration with other external api's such as twitter and facebook and parsing of the data entered by the users we want to do in python, mostly because the developer for that part...
0
2010-01-07T20:37:33Z
2,023,703
<p>It sounds like the only place the two parts will interact is the database: the RoR parts collect data from the user, the python parts collect data from Twitter and elsewhere.</p> <p>As long as your database is supported by both languages, there's no a priori reason why this wouldn't work.</p> <p>Even if you end up...
3
2010-01-07T21:10:58Z
[ "python", "ruby-on-rails", "ruby" ]
dumb question alert: use *both* ruby on rails and python possible?
2,023,458
<p>the front end and end-user data-collection we want to build in RoR since it's just some simple forms connected to a database.</p> <p>The integration with other external api's such as twitter and facebook and parsing of the data entered by the users we want to do in python, mostly because the developer for that part...
0
2010-01-07T20:37:33Z
2,023,828
<p>If you're parsing data with python, presumably it's going be put into a database. As long as this is the case you can just run two apps standalone. Saying that, using one language and framework is a better solution, especially when you think that you won't be able reuse any code between the two applications if they ...
0
2010-01-07T21:31:25Z
[ "python", "ruby-on-rails", "ruby" ]
C#, Pass Array As Function Parameters
2,023,528
<p>In python the * allows me to pass a list as function parameters:</p> <pre><code>def add(a,b): return a+b x = [1,2] add(*x) </code></pre> <p>Can I replicate this behavior in C# with an array?</p> <p>Thanks.</p>
5
2010-01-07T20:48:00Z
2,023,540
<p>The <a href="http://msdn.microsoft.com/en-us/library/w5zay9db.aspx" rel="nofollow">params</a> keyword allows something similar</p> <pre><code>public int Add(params int[] numbers) { int result = 0; foreach (int i in numbers) { result += i; } return result; } // to call: int result = Add(1,...
12
2010-01-07T20:49:26Z
[ "c#", "python" ]
C#, Pass Array As Function Parameters
2,023,528
<p>In python the * allows me to pass a list as function parameters:</p> <pre><code>def add(a,b): return a+b x = [1,2] add(*x) </code></pre> <p>Can I replicate this behavior in C# with an array?</p> <p>Thanks.</p>
5
2010-01-07T20:48:00Z
2,023,565
<p>Except for:</p> <ol> <li>Changing the method signature to accept an array</li> <li>Adding an overload that accepts an array, extracts the values and calls the original overload</li> <li>Using reflection to call the method</li> </ol> <p>then unfortunately, no, you cannot do that.</p> <p>Keyword-based and positiona...
9
2010-01-07T20:51:38Z
[ "c#", "python" ]
C#, Pass Array As Function Parameters
2,023,528
<p>In python the * allows me to pass a list as function parameters:</p> <pre><code>def add(a,b): return a+b x = [1,2] add(*x) </code></pre> <p>Can I replicate this behavior in C# with an array?</p> <p>Thanks.</p>
5
2010-01-07T20:48:00Z
2,023,573
<p>You could using reflection. However if it's a variable length all the time you might be better off using an array as your method defenition however you would still need to parse the list unless it's a basic need that can be handled by collection methods / array methods.</p>
2
2010-01-07T20:52:24Z
[ "c#", "python" ]
C#, Pass Array As Function Parameters
2,023,528
<p>In python the * allows me to pass a list as function parameters:</p> <pre><code>def add(a,b): return a+b x = [1,2] add(*x) </code></pre> <p>Can I replicate this behavior in C# with an array?</p> <p>Thanks.</p>
5
2010-01-07T20:48:00Z
2,023,584
<p>I'm fairly sure you could use reflection to access your method, and then use <a href="http://msdn.microsoft.com/en-us/library/system.reflection.methodinfo.invoke.aspx" rel="nofollow">Invoke</a>, using your array as the parameter list. Kind of round-about, though.</p>
1
2010-01-07T20:53:42Z
[ "c#", "python" ]
How do I send/get a JSON Object with Django?
2,023,577
<p>I know how to use the JQuery ajax feature to call the "url view" of Django.</p> <pre><code>import simplejson as json def the_view(request): fruits = {'color':5, 'type': 22} jfruit = json.dump(fruits) return render_to_response( THE JSON OBJECT!!! ...how? ) </code></pre>
1
2010-01-07T20:52:46Z
2,023,599
<p>return HttpResponse(simplejson.dumps(mydictionary), mimetype="application/json")</p> <p>see <a href="http://www.b-list.org/weblog/2006/jul/31/django-tips-simple-ajax-example-part-1/" rel="nofollow">b-list</a></p>
5
2010-01-07T20:55:40Z
[ "python", "django", "json" ]
How do I send/get a JSON Object with Django?
2,023,577
<p>I know how to use the JQuery ajax feature to call the "url view" of Django.</p> <pre><code>import simplejson as json def the_view(request): fruits = {'color':5, 'type': 22} jfruit = json.dump(fruits) return render_to_response( THE JSON OBJECT!!! ...how? ) </code></pre>
1
2010-01-07T20:52:46Z
2,029,069
<p>Or shorter: download <a href="http://bitbucket.org/offline/django-annoying/" rel="nofollow">http://bitbucket.org/offline/django-annoying/</a> and write:</p> <pre><code>@ajax_request def the_view(request): return {'color':5, 'type': 22} </code></pre> <p>There are a few such nice tiny things in django-annoying...
3
2010-01-08T16:38:05Z
[ "python", "django", "json" ]
check what files are open in Python
2,023,608
<p>I'm getting an error in a program that is supposed to run for a long time that too many files are open. Is there any way I can keep track of which files are open so I can print that list out occasionally and see where the problem is?</p>
24
2010-01-07T20:57:44Z
2,023,659
<p>I'd guess that you are leaking file descriptors. You probably want to look through your code to make sure that you are closing all of the files that you open.</p>
2
2010-01-07T21:04:16Z
[ "python", "debugging", "exception", "file" ]
check what files are open in Python
2,023,608
<p>I'm getting an error in a program that is supposed to run for a long time that too many files are open. Is there any way I can keep track of which files are open so I can print that list out occasionally and see where the problem is?</p>
24
2010-01-07T20:57:44Z
2,023,679
<p>On Windows, you can use <a href="http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx">Process Explorer</a> to show all file handles owned by a process.</p>
5
2010-01-07T21:07:13Z
[ "python", "debugging", "exception", "file" ]
check what files are open in Python
2,023,608
<p>I'm getting an error in a program that is supposed to run for a long time that too many files are open. Is there any way I can keep track of which files are open so I can print that list out occasionally and see where the problem is?</p>
24
2010-01-07T20:57:44Z
2,023,691
<p>On Linux, you can use <code>lsof</code> to show all files opened by a process.</p>
8
2010-01-07T21:08:48Z
[ "python", "debugging", "exception", "file" ]
check what files are open in Python
2,023,608
<p>I'm getting an error in a program that is supposed to run for a long time that too many files are open. Is there any way I can keep track of which files are open so I can print that list out occasionally and see where the problem is?</p>
24
2010-01-07T20:57:44Z
2,023,709
<p>I ended up wrapping the built-in file object at the entry point of my program. I found out that I wasn't closing my loggers.</p> <pre><code>import __builtin__ openfiles = set() oldfile = __builtin__.file class newfile(oldfile): def __init__(self, *args): self.x = args[0] print "### OPENING %s ##...
26
2010-01-07T21:11:56Z
[ "python", "debugging", "exception", "file" ]
check what files are open in Python
2,023,608
<p>I'm getting an error in a program that is supposed to run for a long time that too many files are open. Is there any way I can keep track of which files are open so I can print that list out occasionally and see where the problem is?</p>
24
2010-01-07T20:57:44Z
2,023,791
<p>On Linux, you can look at the contents of <code>/proc/self/fd</code>:</p> <pre><code>$ ls -l /proc/self/fd/ total 0 lrwx------ 1 foo users 64 Jan 7 15:15 0 -&gt; /dev/pts/3 lrwx------ 1 foo users 64 Jan 7 15:15 1 -&gt; /dev/pts/3 lrwx------ 1 foo users 64 Jan 7 15:15 2 -&gt; /dev/pts/3 lr-x------ 1 foo users 64 ...
17
2010-01-07T21:25:59Z
[ "python", "debugging", "exception", "file" ]
check what files are open in Python
2,023,608
<p>I'm getting an error in a program that is supposed to run for a long time that too many files are open. Is there any way I can keep track of which files are open so I can print that list out occasionally and see where the problem is?</p>
24
2010-01-07T20:57:44Z
7,142,094
<p>Although the solutions above that wrap opens are useful for one's own code, I was debugging my client to a third party library including some c extension code, so I needed a more direct way. The following routine works under darwin, and (I hope) other unix-like environments:</p> <pre><code>def get_open_fds(): '...
10
2011-08-22T00:23:57Z
[ "python", "debugging", "exception", "file" ]
check what files are open in Python
2,023,608
<p>I'm getting an error in a program that is supposed to run for a long time that too many files are open. Is there any way I can keep track of which files are open so I can print that list out occasionally and see where the problem is?</p>
24
2010-01-07T20:57:44Z
16,674,146
<p>There are some limitations to the accepted response, in that it does not seem to count pipes. I had a python script that opened many sub-processes, and was failing to properly close standard input, output, and error pipes, which were used for communication. If I use the accepted response, it will fail to count these...
3
2013-05-21T15:46:27Z
[ "python", "debugging", "exception", "file" ]
check what files are open in Python
2,023,608
<p>I'm getting an error in a program that is supposed to run for a long time that too many files are open. Is there any way I can keep track of which files are open so I can print that list out occasionally and see where the problem is?</p>
24
2010-01-07T20:57:44Z
20,673,733
<p>Get a list of all open files. <code>handle.exe</code> is part of Microsoft's <a href="http://technet.microsoft.com/en-us/sysinternals/bb842062" rel="nofollow">Sysinternals Suite</a>. An alternative is the psutil Python module, but I find 'handle' will print out more files in use.</p> <p>Here is what I made. Kludgy ...
1
2013-12-19T04:56:20Z
[ "python", "debugging", "exception", "file" ]
check what files are open in Python
2,023,608
<p>I'm getting an error in a program that is supposed to run for a long time that too many files are open. Is there any way I can keep track of which files are open so I can print that list out occasionally and see where the problem is?</p>
24
2010-01-07T20:57:44Z
24,803,353
<p>As said earlier, you can list fds on Linux in <em>/proc/self/fd</em>, here is a simple method to list them programmatically:</p> <pre><code>import os import sys import errno def list_fds(): """List process currently open FDs and their target """ if sys.platform != 'linux2': raise NotImplementedErro...
2
2014-07-17T12:17:31Z
[ "python", "debugging", "exception", "file" ]
check what files are open in Python
2,023,608
<p>I'm getting an error in a program that is supposed to run for a long time that too many files are open. Is there any way I can keep track of which files are open so I can print that list out occasionally and see where the problem is?</p>
24
2010-01-07T20:57:44Z
25,069,136
<p>To list all open files in a cross-platform manner, I would recommend <a href="https://pypi.python.org/pypi/psutil">psutil</a>.</p> <pre><code>#!/usr/bin/env python import psutil for proc in psutil.process_iter(): print proc.open_files() </code></pre> <p>The original question implicitly restricts the operation...
14
2014-07-31T21:21:50Z
[ "python", "debugging", "exception", "file" ]
pygtk how to embed external application within my pygtk GUI
2,023,698
<p>I'm desiging a pygtk GUI and want to embed an external application into it.</p> <p>Does anyone have any idea how this can be done?</p>
7
2010-01-07T21:10:04Z
2,025,561
<p>It depends on what application you are trying to embed into yours, but if the other app is a GTK app (or one that supports the XEMBED protocol), you should be able to do this with <a href="http://library.gnome.org/devel/pygtk/stable/class-gtkplug.html" rel="nofollow">gtk.Plug</a> and <a href="http://library.gnome.or...
4
2010-01-08T04:45:04Z
[ "python", "pygtk", "embedding" ]
pygtk how to embed external application within my pygtk GUI
2,023,698
<p>I'm desiging a pygtk GUI and want to embed an external application into it.</p> <p>Does anyone have any idea how this can be done?</p>
7
2010-01-07T21:10:04Z
2,370,766
<p>This one might help. Read the article 19.15. How do I embed something using Plugs and Sockets? (http://faq.pygtk.org/index.py?req=all#19.15) and find out how to embed arbitrary X Window application into (Py)GTK Socket.</p>
3
2010-03-03T11:32:48Z
[ "python", "pygtk", "embedding" ]
pygtk how to embed external application within my pygtk GUI
2,023,698
<p>I'm desiging a pygtk GUI and want to embed an external application into it.</p> <p>Does anyone have any idea how this can be done?</p>
7
2010-01-07T21:10:04Z
2,383,442
<p>You don't use an external program to get the <code>gtk.Plug</code>/<code>gtk.Socket</code> ID, they have their respective functions for that. See this tutorial for examples: <a href="http://www.pygtk.org/pygtk2tutorial/sec-PlugsAndSockets.html" rel="nofollow">link</a>.</p>
1
2010-03-04T23:14:42Z
[ "python", "pygtk", "embedding" ]
pygtk how to embed external application within my pygtk GUI
2,023,698
<p>I'm desiging a pygtk GUI and want to embed an external application into it.</p> <p>Does anyone have any idea how this can be done?</p>
7
2010-01-07T21:10:04Z
7,156,300
<p>If you're trying to reparent an external window (that may not be a gtk window), you can use</p> <pre><code>w = gdk.window_foreign_new(window_id) </code></pre> <p>to get a gdk window object from an operating system window handle, and then use</p> <pre><code>w.reparent(parent_window, x, y) </code></pre> <p>to repa...
0
2011-08-23T04:32:36Z
[ "python", "pygtk", "embedding" ]
Postgis - How do i check the geometry type before i do an insert
2,023,821
<p>i have a postgres database with millions of rows in it it has a column called geom which contains the boundary of a property.</p> <p>using a python script i am extracting the information from this table and re-inserting it into a new table.</p> <p>when i insert in the new table the script bugs out with the followi...
9
2010-01-07T21:30:47Z
2,023,874
<p>Option 1 is to create a savepoint before each insert and roll back to that safepoint if an <code>INSERT</code> fails.</p> <p>Option 2 is to attach the check constraint expression as a <code>WHERE</code> condition on the original query that produced the data to avoid selecting it at all.</p> <p>The best answer depe...
2
2010-01-07T21:39:45Z
[ "python", "postgresql", "postgis" ]
Postgis - How do i check the geometry type before i do an insert
2,023,821
<p>i have a postgres database with millions of rows in it it has a column called geom which contains the boundary of a property.</p> <p>using a python script i am extracting the information from this table and re-inserting it into a new table.</p> <p>when i insert in the new table the script bugs out with the followi...
9
2010-01-07T21:30:47Z
2,024,599
<p>This astonishingly useful bit of PostGIS SQL should help you figure it out... there are many geometry type tests in here:</p> <pre><code>-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- -- $Id: cleanGeometry.sql 2008-04-24 10:30Z Dr. Horst Duester $ -- -- cleanGeometry - remove self- and...
7
2010-01-07T23:58:06Z
[ "python", "postgresql", "postgis" ]
Postgis - How do i check the geometry type before i do an insert
2,023,821
<p>i have a postgres database with millions of rows in it it has a column called geom which contains the boundary of a property.</p> <p>using a python script i am extracting the information from this table and re-inserting it into a new table.</p> <p>when i insert in the new table the script bugs out with the followi...
9
2010-01-07T21:30:47Z
34,356,147
<p>I think you can use <a href="http://postgis.net/docs/manual-2.0/ST_CollectionExtract.html" rel="nofollow">ST_CollectionExtract</a> — Given a (multi)geometry, returns a (multi)geometry consisting only of elements of the specified type.</p> <p>I use it when inserting the results of an ST_Intersection, ST_Dump brea...
0
2015-12-18T12:52:34Z
[ "python", "postgresql", "postgis" ]
Python 3 Get HTTP page
2,023,893
<p>How can I get python to get the contents of an HTTP page? So far all I have is the request and I have imported http.client.</p>
17
2010-01-07T21:43:04Z
2,023,920
<p>Using <a href="http://docs.python.org/3.1/library/urllib.request.html"><code>urllib.request</code></a> is probably the easiest way to do this:</p> <pre><code>import urllib.request f = urllib.request.urlopen("http://stackoverflow.com") print(f.read()) </code></pre>
28
2010-01-07T21:48:08Z
[ "python", "http", "python-3.x" ]
Python 3 Get HTTP page
2,023,893
<p>How can I get python to get the contents of an HTTP page? So far all I have is the request and I have imported http.client.</p>
17
2010-01-07T21:43:04Z
33,142,880
<p>Add this code which can format data for human reading:</p> <pre><code>text = f.read().decode('utf-8') </code></pre>
0
2015-10-15T07:53:13Z
[ "python", "http", "python-3.x" ]
Python 3 Get HTTP page
2,023,893
<p>How can I get python to get the contents of an HTTP page? So far all I have is the request and I have imported http.client.</p>
17
2010-01-07T21:43:04Z
37,291,484
<p>You can also use the requests library. I found this particularly useful because it was easier to retrieve and display the HTTP header.</p> <pre><code>import requests source = 'http://www.pythonlearn.com/code/intro-short.txt' r = requests.get(source) print('Display actual page\n') for line in r: print (line.s...
0
2016-05-18T06:04:34Z
[ "python", "http", "python-3.x" ]
setuptools "at least one of these" dependency specification
2,023,900
<p>In some cases, there are various modules which each implement a common API (in my case, the old pure-python <code>elementtree</code>, <code>cElementTree</code>, <code>lxml.etree</code>, and the built-in <code>xml.etree</code>). I can write the module using <code>ElementTree</code> to try each of these options, and t...
1
2010-01-07T21:44:24Z
2,024,687
<p>I don't think so, but, if you're using a reasonably recent Python, <code>elementtree</code> being part of the standard Python libraries, why do you worry it might be absent? (I do understand this would be a problem for other cases of several possible implementations of an API, I just wonder if you really need it fo...
0
2010-01-08T00:20:56Z
[ "python", "dependencies", "setuptools" ]
setuptools "at least one of these" dependency specification
2,023,900
<p>In some cases, there are various modules which each implement a common API (in my case, the old pure-python <code>elementtree</code>, <code>cElementTree</code>, <code>lxml.etree</code>, and the built-in <code>xml.etree</code>). I can write the module using <code>ElementTree</code> to try each of these options, and t...
1
2010-01-07T21:44:24Z
2,024,784
<p>You might want to try doing something like this in setup.py:</p> <pre><code>install_requires = ["elementree"] try: import cElementTree install_requires = [] except ImportError: try: import lxml install_requires = [] except ImportError: # etc for remaining equivalent modules ...
0
2010-01-08T00:53:08Z
[ "python", "dependencies", "setuptools" ]
Using 'super' when subclassing python class that is not derived from `object`(old-style?)
2,023,940
<p>I'm playing with subclassing <code>OptionParser</code> from the std library module <code>optparser</code>. (Python 2.5.2) When I attempt it I get the exception:</p> <pre><code>TypeError: super() argument 1 must be type, not classobj </code></pre> <p>Looking at <code>OptionParser</code>, it is not derived from <co...
4
2010-01-07T21:52:00Z
2,024,674
<p>Yes I dont see why it would not work. You just need to add couple of spaces right before that super call - as it's written right now, it is not part of your custom <strong>init</strong> method. Also, a shortcut you might want to use is **kwargs - you can do kwargs key check in your method if thats what you desire to...
5
2010-01-08T00:16:34Z
[ "python" ]
Lambda, calling itself into the lambda definition
2,023,992
<p>I'm doing a complicated hack in Python, it's a problem when you mix for+lambda+*args (don't do this at home kids), the boring details can be omited, the unique solution I found to resolve the problem is to pass the lambda object into the self lambda in this way:</p> <pre><code>for ... lambda x=x, *y: foo(x, y, ...
3
2010-01-07T22:01:41Z
2,024,223
<p>If you want to refer to it, you'll have to give it a name</p> <pre><code>bar=lambda x=x, *y: foo(x, y, bar) </code></pre> <p>such is the way of the snake</p>
0
2010-01-07T22:40:37Z
[ "python", "functional-programming", "lambda" ]
Lambda, calling itself into the lambda definition
2,023,992
<p>I'm doing a complicated hack in Python, it's a problem when you mix for+lambda+*args (don't do this at home kids), the boring details can be omited, the unique solution I found to resolve the problem is to pass the lambda object into the self lambda in this way:</p> <pre><code>for ... lambda x=x, *y: foo(x, y, ...
3
2010-01-07T22:01:41Z
2,024,295
<p>While your question is genuinely weird, try something like:</p> <pre><code>&gt;&gt;&gt; import functools &gt;&gt;&gt; f = lambda selflambda, x=x, *y: foo(x, y, selflambda) &gt;&gt;&gt; f = functools.partial(f, f) </code></pre>
4
2010-01-07T22:53:56Z
[ "python", "functional-programming", "lambda" ]
Lambda, calling itself into the lambda definition
2,023,992
<p>I'm doing a complicated hack in Python, it's a problem when you mix for+lambda+*args (don't do this at home kids), the boring details can be omited, the unique solution I found to resolve the problem is to pass the lambda object into the self lambda in this way:</p> <pre><code>for ... lambda x=x, *y: foo(x, y, ...
3
2010-01-07T22:01:41Z
2,024,390
<p>You are looking for a <a href="http://en.wikipedia.org/wiki/Fixed_point_combinator" rel="nofollow">fixed-point combinator</a>, like the Z combinator, for which Wikipedia gives this Python implementation:</p> <pre><code>Z = lambda f: (lambda x: f(lambda *args: x(x)(*args)))(lambda x: f(lambda *args: x(x)(*args))) </...
8
2010-01-07T23:11:14Z
[ "python", "functional-programming", "lambda" ]
Lambda, calling itself into the lambda definition
2,023,992
<p>I'm doing a complicated hack in Python, it's a problem when you mix for+lambda+*args (don't do this at home kids), the boring details can be omited, the unique solution I found to resolve the problem is to pass the lambda object into the self lambda in this way:</p> <pre><code>for ... lambda x=x, *y: foo(x, y, ...
3
2010-01-07T22:01:41Z
2,024,439
<p>The easiest way is to write a separate function to create the lambda.</p> <pre><code>def mkfun(foo, x): f = lambda x=x, *y: foo(x, y, f) return f for ...: ...mkfun(foo, x)... </code></pre> <p>This works just like gnibbler's suggestion but can be used in a for loop.</p> <p><strong>EDIT:</strong> I was...
0
2010-01-07T23:21:19Z
[ "python", "functional-programming", "lambda" ]
Lambda, calling itself into the lambda definition
2,023,992
<p>I'm doing a complicated hack in Python, it's a problem when you mix for+lambda+*args (don't do this at home kids), the boring details can be omited, the unique solution I found to resolve the problem is to pass the lambda object into the self lambda in this way:</p> <pre><code>for ... lambda x=x, *y: foo(x, y, ...
3
2010-01-07T22:01:41Z
2,025,127
<p>I don't understand why you want to do this with <code>lambda</code>.</p> <p><code>lambda</code>: creates a function object that does not have a name</p> <p><code>def</code>: creates a function object that does have a name</p> <p>a name: very useful for calling yourself</p> <pre><code>for ... def selflambda(x...
0
2010-01-08T02:43:47Z
[ "python", "functional-programming", "lambda" ]
How do I get cx_Oracle to work on 64-bit Itanium Windows?
2,024,016
<p>I'm running Windows Server 2003 on a 64-bit Itanium server which is also running 64-bit Oracle 10.2, and I'd like to install cx_Oracle for Python 2.5. I've used cx_Oracle before many times on both Windows and Linux, and I've also compiled it before on 32 bit versions of those platforms, but I've never tried an IA64...
3
2010-01-07T22:04:15Z
2,031,669
<p>I read this yesterday and am not suprised to see that nobody has answered. It is a very specific and complex question. While I do not have direct experience with many of the tools you are dealing with I have delt with the issues surrounding incompatabilities with different compilers and binaries. For what its wort...
0
2010-01-09T00:09:26Z
[ "python", "windows", "64bit", "cx-oracle", "itanium" ]
How do I get cx_Oracle to work on 64-bit Itanium Windows?
2,024,016
<p>I'm running Windows Server 2003 on a 64-bit Itanium server which is also running 64-bit Oracle 10.2, and I'd like to install cx_Oracle for Python 2.5. I've used cx_Oracle before many times on both Windows and Linux, and I've also compiled it before on 32 bit versions of those platforms, but I've never tried an IA64...
3
2010-01-07T22:04:15Z
2,089,401
<p>I ended up going with Option #2: I downloaded the 32-bit Oracle Instant Client, then compiled cx_Oracle for 32-bit Python with the instant client. So everything involved is 32-bit, and I'm just not using any IA64-bit executables, and this works just fine.</p> <p>If I had an IA64 compiler, I'd try Option #3, but it...
1
2010-01-18T21:37:48Z
[ "python", "windows", "64bit", "cx-oracle", "itanium" ]
kwargs sent over pyAMF channel
2,024,024
<p>I'm using cherrypy server to receive requests over a pyAMF channel from a python client. I started with the mock up below and it works fine:</p> <p><b>Server:</b></p> <pre><code>import cherrypy from pyamf.remoting.gateway.wsgi import WSGIGateway def echo(*args, **kwargs): return (args, kwargs) class Root(obj...
1
2010-01-07T22:05:14Z
2,024,251
<p>Notice that with your first echo function, the only way to get the results you do is when it is called this way:</p> <pre><code>echo(u"one=1, two=3") # in words: one unicode string literal, as a positional arg # *very* different from: echo(one=1, two=3) # which seems to be what you expect </code></pre> <p>Because...
2
2010-01-07T22:45:17Z
[ "python", "syntax", "cherrypy", "pyamf" ]
kwargs sent over pyAMF channel
2,024,024
<p>I'm using cherrypy server to receive requests over a pyAMF channel from a python client. I started with the mock up below and it works fine:</p> <p><b>Server:</b></p> <pre><code>import cherrypy from pyamf.remoting.gateway.wsgi import WSGIGateway def echo(*args, **kwargs): return (args, kwargs) class Root(obj...
1
2010-01-07T22:05:14Z
2,025,038
<p>By default, WSGIGateway sets <code>expose_request=True</code> which means that the WSGI environ dict is set as the first argument to any service method in that gateway.</p> <p>This means that echo should be written as:</p> <pre><code>def echo(environ, *args): return args </code></pre> <p>PyAMF provides a deco...
1
2010-01-08T02:16:57Z
[ "python", "syntax", "cherrypy", "pyamf" ]
2-dimensional interpolation
2,024,274
<p>I want to find a value of z at y = 12 and x = 3.5, given the below example data. How can I do this in C++?</p> <pre><code>y = 10 x = [1,2, 3,4, 5,6] z = [2.3, 3.4, 5.6, 7.8, 9.6, 11.2] y = 20 x = [1,2, 3,4, 5,6] z = [4.3, 5.4, 7.6, 9.8, 11.6, 13.2] y = 30 x = [1,2, 3,4, 5,6] z = [6.3, 7.4, 8.6, 10.8, 13.6, 15.2...
0
2010-01-07T22:49:25Z
2,024,318
<p>Just do the interpolation twice. First interpolate with Y to select the two Z tables. Then interpolate with X to pick the Z value.</p>
1
2010-01-07T22:57:42Z
[ "c++", "python", "math" ]
2-dimensional interpolation
2,024,274
<p>I want to find a value of z at y = 12 and x = 3.5, given the below example data. How can I do this in C++?</p> <pre><code>y = 10 x = [1,2, 3,4, 5,6] z = [2.3, 3.4, 5.6, 7.8, 9.6, 11.2] y = 20 x = [1,2, 3,4, 5,6] z = [4.3, 5.4, 7.6, 9.8, 11.6, 13.2] y = 30 x = [1,2, 3,4, 5,6] z = [6.3, 7.4, 8.6, 10.8, 13.6, 15.2...
0
2010-01-07T22:49:25Z
2,024,440
<p>I would use <a href="http://www.recnet.com/fortran/itplbv.for" rel="nofollow">Akima's Spline</a>, which is very well-tested, very fast, and produces extremely good results.</p> <p>Unfortunately, it's in Fortran-66 (and messy at that), so you'll need to either translate it to C or a more modern variant of Fortran. I...
1
2010-01-07T23:21:23Z
[ "c++", "python", "math" ]
View a vmdk file from Python?
2,024,432
<p>Is there any way to view the contents of a vmdk file from Python, and to be able to read files from it? (I have no need to write to it). If not, is there any way to mount a vmdk file on a host machine, or generally any other way to look at a vmdk file without attaching it to a VM and running it?</p>
1
2010-01-07T23:20:27Z
2,024,470
<p>You can mount a VMDK as a local disk with <a href="http://www.petri.co.il/virtual_mount_vmware_virtual_disk_without_vmware.htm" rel="nofollow">Disk Mount Utility</a>.</p>
3
2010-01-07T23:28:19Z
[ "python", "virtualization", "abstraction", "virtualbox", "mount" ]
View a vmdk file from Python?
2,024,432
<p>Is there any way to view the contents of a vmdk file from Python, and to be able to read files from it? (I have no need to write to it). If not, is there any way to mount a vmdk file on a host machine, or generally any other way to look at a vmdk file without attaching it to a VM and running it?</p>
1
2010-01-07T23:20:27Z
20,749,138
<p>You may want to take a look at ctypes-vddk if you are looking to import modules for exfiltration of vmdk data through python. You can find the module here; <a href="http://code.google.com/p/ctypes-vddk/" rel="nofollow">http://code.google.com/p/ctypes-vddk/</a></p> <p>Personally, if you are looking to leverage the ...
1
2013-12-23T18:27:21Z
[ "python", "virtualization", "abstraction", "virtualbox", "mount" ]
Python - automating MySQL query: passing parameter
2,024,535
<p>The code in the sequence is working fine, but looking to improve the MySQL code to a more efficient format.</p> <p>The first case is about a function that received a parameter and returns the customerID from MySQL db:</p> <pre><code>def clean_table(self,customerName): getCustomerIDMySQL="""SELECT customerID ...
2
2010-01-07T23:42:14Z
2,024,555
<p>Unfortunately, you cannot parametrize the name of a table (see <a href="http://stackoverflow.com/questions/474261/python-pysqlite-not-accepting-my-qmark-parameterization">this post</a>). You will have to use Python string operations to do what you are attempting here.</p> <p>Hope this helps, it took me a while to f...
0
2010-01-07T23:47:19Z
[ "python", "mysql", "parameters", "automation" ]
Python - automating MySQL query: passing parameter
2,024,535
<p>The code in the sequence is working fine, but looking to improve the MySQL code to a more efficient format.</p> <p>The first case is about a function that received a parameter and returns the customerID from MySQL db:</p> <pre><code>def clean_table(self,customerName): getCustomerIDMySQL="""SELECT customerID ...
2
2010-01-07T23:42:14Z
2,024,617
<p>For the first case (simple, but easy to get a KeyError when there is no row):</p> <pre><code>customerID = self.cursorMySQL.fetchone()[0] </code></pre> <p>More correct is to implement a new method for the cursor class:</p> <pre><code>def autofetch_value(self, sql, args=None): """ return a single value from a s...
3
2010-01-08T00:01:59Z
[ "python", "mysql", "parameters", "automation" ]
Access outer class from inner class in python
2,024,566
<p>I have a situation like so...</p> <pre><code>class Outer(object): def some_method(self): # do something class Inner(object): def __init__(self): self.Outer.some_method() # &lt;-- this is the line in question </code></pre> <p>How can I access the <code>Outer</code> class's m...
38
2010-01-07T23:49:05Z
2,024,583
<p>The methods of a nested class cannot directly access the instance attributes of the outer class. </p> <p>Note that it is not necessarily the case that an instance of the outer class exists even when you have created an instance of the inner class.</p> <p>In fact, it is often recommended against using nested classe...
27
2010-01-07T23:54:24Z
[ "python" ]
Access outer class from inner class in python
2,024,566
<p>I have a situation like so...</p> <pre><code>class Outer(object): def some_method(self): # do something class Inner(object): def __init__(self): self.Outer.some_method() # &lt;-- this is the line in question </code></pre> <p>How can I access the <code>Outer</code> class's m...
38
2010-01-07T23:49:05Z
2,024,614
<p>Do you mean to use inheritance, rather than nesting classes like this? What you're doing doesn't make a heap of sense in Python.</p> <p>You can access the <code>Outer</code>'s some_method by just referencing <code>Outer.some_method</code> within the inner class's methods, but it's not going to work as you expect it...
5
2010-01-08T00:01:25Z
[ "python" ]
Access outer class from inner class in python
2,024,566
<p>I have a situation like so...</p> <pre><code>class Outer(object): def some_method(self): # do something class Inner(object): def __init__(self): self.Outer.some_method() # &lt;-- this is the line in question </code></pre> <p>How can I access the <code>Outer</code> class's m...
38
2010-01-07T23:49:05Z
6,017,488
<p>i found <a href="http://stackoverflow.com/questions/2278426/inner-classes-how-can-i-get-the-outer-class-object-at-construction-time/2278496#2278496">this</a>.</p> <p>Tweaked to suite your question, it is the answer:</p> <pre><code>class Outer(object): def some_method(self): # do something class _I...
1
2011-05-16T12:37:35Z
[ "python" ]
Access outer class from inner class in python
2,024,566
<p>I have a situation like so...</p> <pre><code>class Outer(object): def some_method(self): # do something class Inner(object): def __init__(self): self.Outer.some_method() # &lt;-- this is the line in question </code></pre> <p>How can I access the <code>Outer</code> class's m...
38
2010-01-07T23:49:05Z
6,876,445
<p>Another possibility:</p> <pre><code>class _Outer (object): # Define your static methods here, e.g. @staticmethod def subclassRef (): return Outer class Outer (_Outer): class Inner (object): def outer (self): return _Outer def doSomething (self): oute...
1
2011-07-29T16:53:47Z
[ "python" ]
Access outer class from inner class in python
2,024,566
<p>I have a situation like so...</p> <pre><code>class Outer(object): def some_method(self): # do something class Inner(object): def __init__(self): self.Outer.some_method() # &lt;-- this is the line in question </code></pre> <p>How can I access the <code>Outer</code> class's m...
38
2010-01-07T23:49:05Z
7,034,206
<p>You're trying to access Outer's class instance, from inner class instance. So just use factory-method to build Inner instance and pass Outer instance to it.</p> <pre><code>class Outer(object): def createInner(self): return Outer.Inner(self) class Inner(object): def __init__(self, outer_ins...
22
2011-08-11T23:44:28Z
[ "python" ]
Access outer class from inner class in python
2,024,566
<p>I have a situation like so...</p> <pre><code>class Outer(object): def some_method(self): # do something class Inner(object): def __init__(self): self.Outer.some_method() # &lt;-- this is the line in question </code></pre> <p>How can I access the <code>Outer</code> class's m...
38
2010-01-07T23:49:05Z
7,152,649
<p>maybe I'm mad but this seems very easy indeed - the thing is to make your inner class inside a method of the outer class... </p> <pre><code>def do_sthg( self ): ... def messAround( self ): outerClassSelf = self class mooble(): def do_sthg_different( self ): ... outerCl...
11
2011-08-22T19:38:17Z
[ "python" ]
Access outer class from inner class in python
2,024,566
<p>I have a situation like so...</p> <pre><code>class Outer(object): def some_method(self): # do something class Inner(object): def __init__(self): self.Outer.some_method() # &lt;-- this is the line in question </code></pre> <p>How can I access the <code>Outer</code> class's m...
38
2010-01-07T23:49:05Z
33,242,490
<p>Expanding on @tsnorri's cogent thinking, that the outer method may be a <a href="https://docs.python.org/2/library/functions.html#staticmethod" rel="nofollow">static method</a>:</p> <pre><code>class Outer(object): @staticmethod def some_static_method(self): # do something class Inner(object): ...
1
2015-10-20T16:57:49Z
[ "python" ]
Access outer class from inner class in python
2,024,566
<p>I have a situation like so...</p> <pre><code>class Outer(object): def some_method(self): # do something class Inner(object): def __init__(self): self.Outer.some_method() # &lt;-- this is the line in question </code></pre> <p>How can I access the <code>Outer</code> class's m...
38
2010-01-07T23:49:05Z
35,118,717
<p>Building on the great idea an answer for the same question my answer is for (at <a href="http://stackoverflow.com/a/7152649/3787376">http://stackoverflow.com/a/7152649/3787376</a>) explained, as I wanted to create my own good quality solution to the question, I came up with a Python answer that should be quite simpl...
2
2016-01-31T19:57:09Z
[ "python" ]