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 |
|---|---|---|---|---|---|---|---|---|---|
python GTK container for mjpeg stream | 1,811,624 | <p>I have an mjpeg stream from a web-cam and would like to display it in an application written in python using pygtk.
The stream is a string of bytes from the driver.
What widget would be best for displaying this and would I need to do some intermediate conversion before putting it in the widget? Should I write my ow... | 0 | 2009-11-28T05:02:15Z | 2,364,164 | <p>This example helped me getting started with gstreamer, it shows how one grabbs the webcam stream and displays it in an widget.</p>
<p><a href="http://pygstdocs.berlios.de/pygst-tutorial/webcam-viewer.html" rel="nofollow">http://pygstdocs.berlios.de/pygst-tutorial/webcam-viewer.html</a></p>
| 1 | 2010-03-02T15:17:06Z | [
"python",
"gtk",
"pygtk",
"mjpeg"
] |
python GTK container for mjpeg stream | 1,811,624 | <p>I have an mjpeg stream from a web-cam and would like to display it in an application written in python using pygtk.
The stream is a string of bytes from the driver.
What widget would be best for displaying this and would I need to do some intermediate conversion before putting it in the widget? Should I write my ow... | 0 | 2009-11-28T05:02:15Z | 28,047,082 | <p>It is possible to use an Image widget to show the MJPEG stream.</p>
<p>Start a background thread, and have it read the stream and update the Image using <code>gtk.gdk.PixbufLoader</code> and <code>image_widget.set_from_pixbuf</code></p>
<p>For example:</p>
<pre><code>for frame in self.get_raw_frame():
loader ... | 0 | 2015-01-20T13:54:59Z | [
"python",
"gtk",
"pygtk",
"mjpeg"
] |
How to pass this command to subprocess.call? | 1,811,683 | <p>Command:</p>
<pre><code>root@host:~#convert source.jpg -resize x500 -resize "500x<" -gravity center +repage target.jpg
</code></pre>
<p>Python code:</p>
<pre><code>>> command_list = ['convert', 'source.jpg', '-resize', 'x500', '-resize', '\'500x<\'', '-gravity', 'center', 'target.jpg']
>> p = su... | 2 | 2009-11-28T05:33:03Z | 1,811,690 | <p>Why the extra quotes on <code>500x<</code>? Subprocess will correctly quote any arguments. </p>
<p>Keep in mind that the shell will NOT pass the outer quotes to the application, just the quoted value, but subprocess will pass the quotes if you force it to.</p>
| 5 | 2009-11-28T05:36:38Z | [
"python",
"subprocess"
] |
How to pass this command to subprocess.call? | 1,811,683 | <p>Command:</p>
<pre><code>root@host:~#convert source.jpg -resize x500 -resize "500x<" -gravity center +repage target.jpg
</code></pre>
<p>Python code:</p>
<pre><code>>> command_list = ['convert', 'source.jpg', '-resize', 'x500', '-resize', '\'500x<\'', '-gravity', 'center', 'target.jpg']
>> p = su... | 2 | 2009-11-28T05:33:03Z | 1,811,693 | <p>Have you tried <code>'"500x<"'</code> instead of <code>'\'500x<\''</code>?</p>
| 0 | 2009-11-28T05:38:28Z | [
"python",
"subprocess"
] |
running an outside program (executable) in python? | 1,811,691 | <p>I just started working on python and I have been trying to run an outside executable form python.
I have an executable for a program written in Fortran. Lets say the name for the executable is flow.exe. And my executable is lacated in C:\Documents and Settings\flow_model
I tried both os.system and popen commands but... | 30 | 2009-11-28T05:36:50Z | 1,811,695 | <p>Is that trying to execute <code>C:\Documents</code> with arguments of <code>"and", "Settings/flow_model/flow.exe"</code> ?</p>
<p>Also, you might consider <code>subprocess.call()</code></p>
| 1 | 2009-11-28T05:39:05Z | [
"python",
"executable"
] |
running an outside program (executable) in python? | 1,811,691 | <p>I just started working on python and I have been trying to run an outside executable form python.
I have an executable for a program written in Fortran. Lets say the name for the executable is flow.exe. And my executable is lacated in C:\Documents and Settings\flow_model
I tried both os.system and popen commands but... | 30 | 2009-11-28T05:36:50Z | 1,811,698 | <p>Try</p>
<pre><code>import subprocess
subprocess.call(["C:/Documents and Settings/flow_model/flow.exe"])
</code></pre>
| 1 | 2009-11-28T05:39:17Z | [
"python",
"executable"
] |
running an outside program (executable) in python? | 1,811,691 | <p>I just started working on python and I have been trying to run an outside executable form python.
I have an executable for a program written in Fortran. Lets say the name for the executable is flow.exe. And my executable is lacated in C:\Documents and Settings\flow_model
I tried both os.system and popen commands but... | 30 | 2009-11-28T05:36:50Z | 1,811,701 | <p>That's the correct usage, but perhaps the spaces in the path name are messing things up for some reason.</p>
<p>You may want to run the program under cmd.exe as well so you can see any output from flow.exe that might be indicating an error.</p>
| 0 | 2009-11-28T05:40:15Z | [
"python",
"executable"
] |
running an outside program (executable) in python? | 1,811,691 | <p>I just started working on python and I have been trying to run an outside executable form python.
I have an executable for a program written in Fortran. Lets say the name for the executable is flow.exe. And my executable is lacated in C:\Documents and Settings\flow_model
I tried both os.system and popen commands but... | 30 | 2009-11-28T05:36:50Z | 1,811,745 | <p>Those whitespaces can really be a bother:-(. Try <code>os.chdir('C:/Documents\ and\ Settings/')</code> followed by relative paths for <code>os.system</code>, <code>subprocess</code> methods, or whatever...</p>
<p>If best-effort attempts to bypass the whitespaces-in-path hurdle keep failing, then my next best sugge... | 18 | 2009-11-28T06:08:35Z | [
"python",
"executable"
] |
running an outside program (executable) in python? | 1,811,691 | <p>I just started working on python and I have been trying to run an outside executable form python.
I have an executable for a program written in Fortran. Lets say the name for the executable is flow.exe. And my executable is lacated in C:\Documents and Settings\flow_model
I tried both os.system and popen commands but... | 30 | 2009-11-28T05:36:50Z | 1,811,902 | <p>I'd try inserting an 'r' in front of your path if I were you, to indicate that its a raw string - and then you won't have to use forward slashes, for example:</p>
<pre><code>os.system(r"C:\Documents and Settings\flow_model\flow.exe")
</code></pre>
| 6 | 2009-11-28T07:42:57Z | [
"python",
"executable"
] |
running an outside program (executable) in python? | 1,811,691 | <p>I just started working on python and I have been trying to run an outside executable form python.
I have an executable for a program written in Fortran. Lets say the name for the executable is flow.exe. And my executable is lacated in C:\Documents and Settings\flow_model
I tried both os.system and popen commands but... | 30 | 2009-11-28T05:36:50Z | 1,812,050 | <p>your usage is correct, i bet that your external program, flow.exe, needs to be executed in its directory because it accesses some external files stored there. </p>
<p>so you might try:</p>
<pre><code>import sys, string, os, arcgisscripting
os.chdir( 'c:\\documents and settings\\flow_model' )
os.system( '"C:\\Docum... | 10 | 2009-11-28T09:08:45Z | [
"python",
"executable"
] |
running an outside program (executable) in python? | 1,811,691 | <p>I just started working on python and I have been trying to run an outside executable form python.
I have an executable for a program written in Fortran. Lets say the name for the executable is flow.exe. And my executable is lacated in C:\Documents and Settings\flow_model
I tried both os.system and popen commands but... | 30 | 2009-11-28T05:36:50Z | 1,812,338 | <p>If it were me, I'd put the exe in the root diretcory (C:) and see if it works like that. If so, it's probably the (already mentioned) spaces in the directory name. If not, it may be some environment variables.</p>
<p>Also, try to check you stderr (using an earlier answer by int3):</p>
<pre><code>import subprocess
... | 1 | 2009-11-28T11:43:01Z | [
"python",
"executable"
] |
running an outside program (executable) in python? | 1,811,691 | <p>I just started working on python and I have been trying to run an outside executable form python.
I have an executable for a program written in Fortran. Lets say the name for the executable is flow.exe. And my executable is lacated in C:\Documents and Settings\flow_model
I tried both os.system and popen commands but... | 30 | 2009-11-28T05:36:50Z | 10,395,222 | <p>The simplest way is :</p>
<pre><code>import os
os.startfile("C:\Documents and Settings\flow_model\flow.exe")
</code></pre>
<p>It works, i tried it.</p>
| 5 | 2012-05-01T08:17:22Z | [
"python",
"executable"
] |
running an outside program (executable) in python? | 1,811,691 | <p>I just started working on python and I have been trying to run an outside executable form python.
I have an executable for a program written in Fortran. Lets say the name for the executable is flow.exe. And my executable is lacated in C:\Documents and Settings\flow_model
I tried both os.system and popen commands but... | 30 | 2009-11-28T05:36:50Z | 13,296,949 | <p>If Using Python 2.7 or higher you can use the following:</p>
<pre><code>import subprocess
</code></pre>
<ul>
<li><code>subprocess.call(args, *, stdin=None, stdout=None, stderr=None, shell=False)</code>
Runs the command described by args. Waits for command to complete, then returns the returncode attribute.</li>
<l... | 15 | 2012-11-08T20:09:48Z | [
"python",
"executable"
] |
running an outside program (executable) in python? | 1,811,691 | <p>I just started working on python and I have been trying to run an outside executable form python.
I have an executable for a program written in Fortran. Lets say the name for the executable is flow.exe. And my executable is lacated in C:\Documents and Settings\flow_model
I tried both os.system and popen commands but... | 30 | 2009-11-28T05:36:50Z | 26,215,800 | <p>Use <strong>subprocess</strong>, it is a smaller module so it runs the <code>.exe</code> quicker.</p>
<pre><code>import subprocess
subprocess.Popen([r"U:\Year 8\kerbal space program\KSP.exe"])
</code></pre>
| 4 | 2014-10-06T12:00:42Z | [
"python",
"executable"
] |
running an outside program (executable) in python? | 1,811,691 | <p>I just started working on python and I have been trying to run an outside executable form python.
I have an executable for a program written in Fortran. Lets say the name for the executable is flow.exe. And my executable is lacated in C:\Documents and Settings\flow_model
I tried both os.system and popen commands but... | 30 | 2009-11-28T05:36:50Z | 26,413,661 | <p>By using <a href="https://docs.python.org/3.4/library/os.html#os.system" rel="nofollow">os.system</a>:</p>
<pre><code>import os
os.system(r'"C:/Documents and Settings/flow_model/flow.exe"')
</code></pre>
| 2 | 2014-10-16T20:51:09Z | [
"python",
"executable"
] |
I want to develop a framework in Python for desktop based applications. How should I go about it? | 1,811,940 | <p>I want to develop a desktop application framework in Python, much like QT, but how to go about it? Any tutorials or links related to it would be helpful!</p>
| 1 | 2009-11-28T08:04:14Z | 1,811,959 | <p>theres WxPython tutorial <a href="http://www.wxpython.org/tutorial.php" rel="nofollow">http://www.wxpython.org/tutorial.php</a></p>
<p>or PyQt <a href="http://zetcode.com/tutorials/pyqt4/" rel="nofollow">http://zetcode.com/tutorials/pyqt4/</a></p>
<p>or the ever stylish Tk <a href="http://www.pythonware.com/librar... | 1 | 2009-11-28T08:14:45Z | [
"python",
"frameworks",
"desktop"
] |
I want to develop a framework in Python for desktop based applications. How should I go about it? | 1,811,940 | <p>I want to develop a desktop application framework in Python, much like QT, but how to go about it? Any tutorials or links related to it would be helpful!</p>
| 1 | 2009-11-28T08:04:14Z | 1,811,965 | <p>There is so many great freameworks like <a href="http://wxpython.org/download.php#binaries" rel="nofollow">wxPython</a> (<a href="http://wiki.wxpython.org/How%20to%20Learn%20wxPython" rel="nofollow">Tutorial</a>), <a href="http://www.riverbankcomputing.co.uk/software/pyqt/download" rel="nofollow">PyQt</a> (<a href="... | 3 | 2009-11-28T08:18:45Z | [
"python",
"frameworks",
"desktop"
] |
I want to develop a framework in Python for desktop based applications. How should I go about it? | 1,811,940 | <p>I want to develop a desktop application framework in Python, much like QT, but how to go about it? Any tutorials or links related to it would be helpful!</p>
| 1 | 2009-11-28T08:04:14Z | 1,812,027 | <p>You can get a pretty comprehensive list of Gui programming frameworks for Python here, <a href="http://wiki.python.org/moin/GuiProgramming" rel="nofollow">http://wiki.python.org/moin/GuiProgramming</a> </p>
| 2 | 2009-11-28T08:58:47Z | [
"python",
"frameworks",
"desktop"
] |
I want to develop a framework in Python for desktop based applications. How should I go about it? | 1,811,940 | <p>I want to develop a desktop application framework in Python, much like QT, but how to go about it? Any tutorials or links related to it would be helpful!</p>
| 1 | 2009-11-28T08:04:14Z | 1,813,171 | <p>Well the best way to start is to look at the source code of the framework the other answers are talking about.</p>
<p>First, try to use them all to build the same application with the functionalities you expect from a framework. Them, look at how it works under the hood.</p>
<p>Secondly, build your framework, star... | 1 | 2009-11-28T17:38:24Z | [
"python",
"frameworks",
"desktop"
] |
Is it possible to unpack a tuple without using variables? | 1,812,020 | <p>I'm using the os.path.split() function on a path in my program to get the filename and pathname of a file then passing them into another method, but my current solution seems rather ugly:</p>
<pre><code>path = os.path.split(somefile)
some_class(path[0], path[1])
</code></pre>
<p>Is it possible to unpack the path t... | 10 | 2009-11-28T08:54:12Z | 1,812,030 | <p>Yes, Python has <a href="http://docs.python.org/tutorial/controlflow.html#unpacking-argument-lists">argument list unpacking</a>. Try this:</p>
<pre><code>some_class(*os.path.split(somefile))
</code></pre>
| 14 | 2009-11-28T09:00:00Z | [
"python",
"tuples",
"iterable-unpacking"
] |
How to safely write to a file? | 1,812,115 | <p>Imagine you have a library for working with some sort of XML file or configuration file. The library reads the whole file into memory and provides methods for editing the content. When you are done manipulating the content you can call a <code>write</code> to save the content back to file. The question is how to do ... | 14 | 2009-11-28T09:46:38Z | 1,812,142 | <p>In Win API I found quite nice function <a href="http://msdn.microsoft.com/en-us/library/aa365512%28VS.85%29.aspx" rel="nofollow">ReplaceFile</a> that does what name suggests even with optional back-up. There is always way with <a href="http://msdn.microsoft.com/en-us/library/aa363915%28VS.85%29.aspx" rel="nofollow">... | 4 | 2009-11-28T09:57:59Z | [
"python",
"windows",
"file"
] |
How to safely write to a file? | 1,812,115 | <p>Imagine you have a library for working with some sort of XML file or configuration file. The library reads the whole file into memory and provides methods for editing the content. When you are done manipulating the content you can call a <code>write</code> to save the content back to file. The question is how to do ... | 14 | 2009-11-28T09:46:38Z | 1,812,155 | <p>A simplistic solution. Use <a href="http://docs.python.org/library/tempfile.html" rel="nofollow"><code>tempfile</code></a> to create a temporary file and if writing succeeds the just rename the file to your original configuration file. </p>
<p>For locking a file, see <a href="http://code.activestate.com/recipes/652... | 3 | 2009-11-28T10:07:09Z | [
"python",
"windows",
"file"
] |
How to safely write to a file? | 1,812,115 | <p>Imagine you have a library for working with some sort of XML file or configuration file. The library reads the whole file into memory and provides methods for editing the content. When you are done manipulating the content you can call a <code>write</code> to save the content back to file. The question is how to do ... | 14 | 2009-11-28T09:46:38Z | 1,812,351 | <p>The standard solution is this.</p>
<ol>
<li><p>Write a new file with a similar name. X.ext# for example.</p></li>
<li><p>When that file has been closed (and perhaps even read and checksummed), then you two two renames.</p>
<ul>
<li><p>X.ext (the original) to X.ext~ </p></li>
<li><p>X.ext# (the new one) to X.ext</... | 3 | 2009-11-28T11:56:57Z | [
"python",
"windows",
"file"
] |
How to safely write to a file? | 1,812,115 | <p>Imagine you have a library for working with some sort of XML file or configuration file. The library reads the whole file into memory and provides methods for editing the content. When you are done manipulating the content you can call a <code>write</code> to save the content back to file. The question is how to do ... | 14 | 2009-11-28T09:46:38Z | 1,812,421 | <p>If you want to be POSIXly correct and save you have to:</p>
<ol>
<li>Write to temporary file</li>
<li>Flush and <a href="http://docs.python.org/library/os.html#os.fsync"><code>fsync</code></a> the file (or <code>fdatasync</code>)</li>
<li>Rename over the original file</li>
</ol>
<p>Note that calling fsync has unp... | 11 | 2009-11-28T12:28:01Z | [
"python",
"windows",
"file"
] |
How to safely write to a file? | 1,812,115 | <p>Imagine you have a library for working with some sort of XML file or configuration file. The library reads the whole file into memory and provides methods for editing the content. When you are done manipulating the content you can call a <code>write</code> to save the content back to file. The question is how to do ... | 14 | 2009-11-28T09:46:38Z | 1,812,604 | <p>If you see Python's documentation, it clearly mentions that os.rename() is an atomic operation. So in your case, writing data to a temporary file and then renaming it to the original file would be quite safe. </p>
<p>Another way could work like this:</p>
<ul>
<li>let original file be abc.xml</li>
<li>create abc.xm... | 13 | 2009-11-28T14:18:28Z | [
"python",
"windows",
"file"
] |
How to safely write to a file? | 1,812,115 | <p>Imagine you have a library for working with some sort of XML file or configuration file. The library reads the whole file into memory and provides methods for editing the content. When you are done manipulating the content you can call a <code>write</code> to save the content back to file. The question is how to do ... | 14 | 2009-11-28T09:46:38Z | 1,812,623 | <p>Per RedGlyph's suggestion, I'm added an implementation of ReplaceFile that uses ctypes to access the Windows APIs. I first added this to jaraco.windows.api.filesystem.</p>
<pre><code>ReplaceFile = windll.kernel32.ReplaceFileW
ReplaceFile.restype = BOOL
ReplaceFile.argtypes = [
LPWSTR,
LPWSTR,
LPWSTR,
DWORD,
LP... | 1 | 2009-11-28T14:27:58Z | [
"python",
"windows",
"file"
] |
How to safely write to a file? | 1,812,115 | <p>Imagine you have a library for working with some sort of XML file or configuration file. The library reads the whole file into memory and provides methods for editing the content. When you are done manipulating the content you can call a <code>write</code> to save the content back to file. The question is how to do ... | 14 | 2009-11-28T09:46:38Z | 1,812,676 | <p>You could use the fileinput module to handle the backing-up and in-place writing for you:</p>
<pre><code>import fileinput
for line in fileinput.input(filename,inplace=True, backup='.bak'):
# inplace=True causes the original file to be moved to a backup
# standard output is redirected to the original file.
... | 0 | 2009-11-28T14:48:15Z | [
"python",
"windows",
"file"
] |
How to safely write to a file? | 1,812,115 | <p>Imagine you have a library for working with some sort of XML file or configuration file. The library reads the whole file into memory and provides methods for editing the content. When you are done manipulating the content you can call a <code>write</code> to save the content back to file. The question is how to do ... | 14 | 2009-11-28T09:46:38Z | 35,240,362 | <p>There's now a codified, pure-Python, and I dare say Pythonic solution to this in the <a href="http://boltons.readthedocs.org" rel="nofollow">boltons utility library</a>: <a href="http://boltons.readthedocs.org/en/latest/fileutils.html#atomic-file-saving" rel="nofollow">boltons.fileutils.atomic_save</a>.</p>
<p>Just... | 2 | 2016-02-06T11:17:00Z | [
"python",
"windows",
"file"
] |
Python MySQL: clean multiple foreign keys table | 1,812,191 | <p>I am working with Python MySQL, and need to clean a table in my database that has 13328 rows.</p>
<p>I can not make a simple drop table, because this table is child and also father of other child foreign-keys linked on it. If I try drop table, the system forbidden me. The table is defined with ON UPDATE CASCADE, ON... | 0 | 2009-11-28T10:26:01Z | 1,812,326 | <p>To remove all records from the table: </p>
<pre><code>truncate table product
</code></pre>
<p>To reset next ID to 1:</p>
<pre><code>ALTER TABLE product AUTO_INCREMENT = 1
</code></pre>
<p>or </p>
<pre><code>SET insert_id;
INSERT INTO product ...;
</code></pre>
<p>(I haven't tested this. But i should work) ... | 2 | 2009-11-28T11:39:23Z | [
"python",
"mysql",
"auto-increment",
"foreign-keys"
] |
Python MySQL: clean multiple foreign keys table | 1,812,191 | <p>I am working with Python MySQL, and need to clean a table in my database that has 13328 rows.</p>
<p>I can not make a simple drop table, because this table is child and also father of other child foreign-keys linked on it. If I try drop table, the system forbidden me. The table is defined with ON UPDATE CASCADE, ON... | 0 | 2009-11-28T10:26:01Z | 1,812,332 | <p>If you clean a table with truncate:</p>
<pre><code>TRUNCATE TABLE product
</code></pre>
<p>As a side effect, that will reset the auto-increment counter. But you can also reset it manually:</p>
<pre><code>ALTER TABLE product AUTO_INCREMENT = 1
</code></pre>
| 2 | 2009-11-28T11:41:37Z | [
"python",
"mysql",
"auto-increment",
"foreign-keys"
] |
Python MySQL: clean multiple foreign keys table | 1,812,191 | <p>I am working with Python MySQL, and need to clean a table in my database that has 13328 rows.</p>
<p>I can not make a simple drop table, because this table is child and also father of other child foreign-keys linked on it. If I try drop table, the system forbidden me. The table is defined with ON UPDATE CASCADE, ON... | 0 | 2009-11-28T10:26:01Z | 1,817,213 | <p>Thanks a lot for all input and quick feedback. It did the trick!</p>
<p>Here is how it looks now:</p>
<pre><code>def clean_tableProduct(self):
cleanTabeMySQLQuery = """TRUNCATE TABLE product;"""
self.cursorMySQL.execute(cleanTabeMySQLQuery)
setIndexMySQLQuery = """ALTER TABLE product AUTO_INCREMENT = ... | 0 | 2009-11-30T00:00:23Z | [
"python",
"mysql",
"auto-increment",
"foreign-keys"
] |
Help ctypes.windll.dnsapi.DnsQuery_A | 1,812,564 | <p>I have trouble with <a href="http://msdn.microsoft.com/en-us/library/ms682016%28VS.85).aspx" rel="nofollow">DnsQuery</a> API, the *ppQueryResultsSet parameter troubles me. Can anyone show me an example of how to make correct DLL calls in python?</p>
<pre><code>import ctypes
from ctypes import wintypes
from windns_t... | 2 | 2009-11-28T13:50:40Z | 1,813,270 | <p>Isn't it a pointer to pointer to <code>DNS_RECORD</code>? This means you have to initialize rr as <code>POINTER(DNS_RECORD)()</code> and pass it by reference: <code>ctypes.byref(rr)</code>.</p>
<p><strong>Update</strong>: But I think the problem you see is from passing <code>server_arr</code>: you pass a structure ... | 2 | 2009-11-28T18:18:59Z | [
"python",
"winapi",
"dns",
"ctypes"
] |
Replacing elements with lxml.html | 1,812,764 | <p>I'm fairly new to lxml and HTML Parsers as a whole.
I was wondering if there is a way to replace an element within a tree with another element...</p>
<p>For example I have:</p>
<pre><code>body = """<code> def function(arg): print arg </code> Blah blah blah <code> int main() { return 0; } </cod... | 6 | 2009-11-28T15:22:58Z | 1,812,809 | <p>If you're new to python HTML parsers, you might try out <a href="http://www.crummy.com/software/BeautifulSoup/" rel="nofollow">BeautifulSoup</a>, a html/xml parser, which lets you <a href="http://www.crummy.com/software/BeautifulSoup/documentation.html#Modifying%20the%20Parse%20Tree" rel="nofollow">modify the parse ... | 0 | 2009-11-28T15:35:05Z | [
"python",
"lxml"
] |
Replacing elements with lxml.html | 1,812,764 | <p>I'm fairly new to lxml and HTML Parsers as a whole.
I was wondering if there is a way to replace an element within a tree with another element...</p>
<p>For example I have:</p>
<pre><code>body = """<code> def function(arg): print arg </code> Blah blah blah <code> int main() { return 0; } </cod... | 6 | 2009-11-28T15:22:58Z | 1,812,918 | <p>Regarding lxml,</p>
<p>In <code>doc.replace(block, hilited)</code></p>
<p><strong>block</strong> is the lxml's Element object, <strong>hilited</strong> is string, you cannot replace that.</p>
<p>There is 2 ways to do that</p>
<pre><code>block.text=hilited
</code></pre>
<p>or</p>
<pre><code>body=body.replace(bl... | 4 | 2009-11-28T16:19:22Z | [
"python",
"lxml"
] |
What should i use for a Remote Desktop Control? | 1,812,890 | <p>Hi everybody i'm new to stackoverflow and to python programming :-)</p>
<p>Can somebody point me in the right direction or suggest me a good way to do this..?</p>
<p>The software I'd like to write is a kind of "multiple remote control", it has:</p>
<ul>
<li><b> One Server </b> ... whose task is to send his screen... | 3 | 2009-11-28T16:11:08Z | 1,812,981 | <p><a href="http://www.teamtalk.im/" rel="nofollow">Teamtalk</a> is a Python IM software that also has Remote Desktop access. You can download the source and look at the implementation.</p>
| 2 | 2009-11-28T16:42:02Z | [
"python",
"twisted",
"python-imaging-library"
] |
What should i use for a Remote Desktop Control? | 1,812,890 | <p>Hi everybody i'm new to stackoverflow and to python programming :-)</p>
<p>Can somebody point me in the right direction or suggest me a good way to do this..?</p>
<p>The software I'd like to write is a kind of "multiple remote control", it has:</p>
<ul>
<li><b> One Server </b> ... whose task is to send his screen... | 3 | 2009-11-28T16:11:08Z | 1,813,096 | <p>Take a look at the <a href="http://homepage.hispeed.ch/py430/python/" rel="nofollow">VNC viewer implemented in Python</a>.</p>
| 3 | 2009-11-28T17:11:43Z | [
"python",
"twisted",
"python-imaging-library"
] |
How to delete Firefox cookies from webdriver in python? | 1,813,044 | <p>when I can't delete FF cookies from webdriver. When I use the <code>.delete_all_cookies</code> method, it returns <code>None</code>. And when I try to <code>get_cookies</code>, I get the following error:</p>
<pre>webdriver_common.exceptions.ErrorInResponseException: Error occurred when processing
packet:Content-Len... | 0 | 2009-11-28T16:59:39Z | 1,814,160 | <p>Hmm, I actually haven't worked with Webdriver so this may be of no help at all... but in your other post you mention that you're experimenting with modifying the delete cookie webdriver js function. Did get_cookies fail before you were modifying the delete function? What happens when you get cookies before deleting ... | 0 | 2009-11-28T23:45:00Z | [
"python",
"firefox",
"webdriver"
] |
Making a Python script Object-Oriented | 1,813,117 | <p>I'm writing an application in Python that is going to have a lot of different functions, so logically I thought it would be best to split up my script into different modules. Currently my script reads in a text file that contains code which has been converted into tokens and spellings. The script then reconstructs t... | 15 | 2009-11-28T17:19:36Z | 1,813,148 | <p>When I do this particular refactoring, I usually start with an initial transformation within the first file. Step 1: move the functionality into a method in a new class. Step 2: add
the magic invocation below to get the file to run like a script again:</p>
<pre><code>class LineCleaner:
def cleanFile(filename)... | 1 | 2009-11-28T17:28:40Z | [
"python",
"oop"
] |
Making a Python script Object-Oriented | 1,813,117 | <p>I'm writing an application in Python that is going to have a lot of different functions, so logically I thought it would be best to split up my script into different modules. Currently my script reads in a text file that contains code which has been converted into tokens and spellings. The script then reconstructs t... | 15 | 2009-11-28T17:19:36Z | 1,813,167 | <p>To speed up your existing code measurably, add <code>def main():</code> before the assignment to <code>tokenList</code>, indent everything after that 4 spaces, and at the end put the usual idiom</p>
<pre><code>if __name__ == '__main__':
main()
</code></pre>
<p>(The guard is not actually necessary, but it's a goo... | 39 | 2009-11-28T17:36:11Z | [
"python",
"oop"
] |
Making a Python script Object-Oriented | 1,813,117 | <p>I'm writing an application in Python that is going to have a lot of different functions, so logically I thought it would be best to split up my script into different modules. Currently my script reads in a text file that contains code which has been converted into tokens and spellings. The script then reconstructs t... | 15 | 2009-11-28T17:19:36Z | 1,813,177 | <p>You can get away with creating a function and putting all your logic in it. For full "object orientedness" though, you can do something like this:</p>
<p>ps - your posted code has a bug on the <code>continue</code> line - it is always executed and the last 2 lines will never execute.</p>
<pre><code>class Cleaner:... | 0 | 2009-11-28T17:39:41Z | [
"python",
"oop"
] |
Making a Python script Object-Oriented | 1,813,117 | <p>I'm writing an application in Python that is going to have a lot of different functions, so logically I thought it would be best to split up my script into different modules. Currently my script reads in a text file that contains code which has been converted into tokens and spellings. The script then reconstructs t... | 15 | 2009-11-28T17:19:36Z | 1,813,199 | <p>If presented code is all code Just don't add any class !!</p>
<p>Your code is too simply for that !!
OOP approach would add unnecessary complexity.</p>
<p>But if still wont.
Put all code into function eg.</p>
<pre><code>def parse_tokenized_input(file):
tokenList = open(file, 'r')
cleanedInput = ''
pre... | 0 | 2009-11-28T17:47:01Z | [
"python",
"oop"
] |
Python: execfile from other file's working directory? | 1,813,282 | <p>I have some code that loads a default configuration file and then allows users to supply their own Python files as additional supplemental configuration or overrides of the defaults:</p>
<pre><code># foo.py
def load(cfg_path=None):
# load default configuration
exec(default_config)
# load user-specific... | 7 | 2009-11-28T18:22:46Z | 1,813,338 | <p><a href="http://docs.python.org/library/os.html?highlight=os#os.chdir">os.chdir</a> lets you change the working directory as you wish (you can extract the working directory of <code>cfg_path</code> with <code>os.path.dirname</code>); be sure to first get the current directory with <a href="http://docs.python.org/lib... | 7 | 2009-11-28T18:40:42Z | [
"python",
"working-directory",
"execfile"
] |
Why should I use WSGI? | 1,813,394 | <p>Been using mod_python for a while, I read more and more articles about how good WSGI is, without really understanding why.</p>
<p>So why should I switch to it? What are the benefits? Is it hard, and is the learning curve worth it?</p>
| 12 | 2009-11-28T18:54:51Z | 1,813,431 | <p>You shouldn't have to relearn much, since the difference from a developer perspective is just a small wrapper and some server configuration.</p>
<p>From a deployment perspective, the difference is that your python code lives in a separate process from the web browser, which means</p>
<p>a) The python process can b... | 1 | 2009-11-28T19:04:52Z | [
"python",
"wsgi"
] |
Why should I use WSGI? | 1,813,394 | <p>Been using mod_python for a while, I read more and more articles about how good WSGI is, without really understanding why.</p>
<p>So why should I switch to it? What are the benefits? Is it hard, and is the learning curve worth it?</p>
| 12 | 2009-11-28T18:54:51Z | 1,813,452 | <p>WSGI is the standard API, which enables you to choose the webserver, and also put A WSGI pipeline such as Repoze in front of it. </p>
<p>See <a href="http://repoze.org/" rel="nofollow">http://repoze.org/</a></p>
| 0 | 2009-11-28T19:09:33Z | [
"python",
"wsgi"
] |
Why should I use WSGI? | 1,813,394 | <p>Been using mod_python for a while, I read more and more articles about how good WSGI is, without really understanding why.</p>
<p>So why should I switch to it? What are the benefits? Is it hard, and is the learning curve worth it?</p>
| 12 | 2009-11-28T18:54:51Z | 1,813,462 | <p>Most Python frameworks implement wsgi. There is mod_wsgi for apache and a SCGI/FastCGI/AJP module + Flup for the others. That way you can have all the advantages of a separate Python process, without being tied to one webserver.</p>
| 2 | 2009-11-28T19:12:26Z | [
"python",
"wsgi"
] |
Why should I use WSGI? | 1,813,394 | <p>Been using mod_python for a while, I read more and more articles about how good WSGI is, without really understanding why.</p>
<p>So why should I switch to it? What are the benefits? Is it hard, and is the learning curve worth it?</p>
| 12 | 2009-11-28T18:54:51Z | 1,813,470 | <p>For developing sophisticated web applications in Python, you would probably use a more comprehensive web development framework like DJango, Zope, Turbogears etc. As an application developer, you don't have to worry about WSGI much. All you have to be aware about is that these frameworks support WSGI. The WSGI allows... | 7 | 2009-11-28T19:15:41Z | [
"python",
"wsgi"
] |
Why should I use WSGI? | 1,813,394 | <p>Been using mod_python for a while, I read more and more articles about how good WSGI is, without really understanding why.</p>
<p>So why should I switch to it? What are the benefits? Is it hard, and is the learning curve worth it?</p>
| 12 | 2009-11-28T18:54:51Z | 1,813,471 | <p>mod_wsgi vs. mod_python:</p>
<ul>
<li>mod_wsgi is a little faster (internally there's more C, less Python)</li>
<li>mod_wsgi processes can be isolated from Apache, which improves security/stability with lower memory use[1]</li>
<li>mod_python gives you access to some of Apache's internals</li>
</ul>
<p>WSGI in gen... | 9 | 2009-11-28T19:16:34Z | [
"python",
"wsgi"
] |
Remove Duplicate Items in Dictionary | 1,813,469 | <p>I'm trying to remove duplicate items in a list through a dictionary:</p>
<pre><code>def RemoveDuplicates(list):
d = dict()
for i in xrange(0, len(list)):
dict[list[i]] = 1 <------- error here
return d.keys()
</code></pre>
<p>But it is raising me the following error:</p>
<pre><code>T... | 1 | 2009-11-28T19:15:25Z | 1,813,476 | <p>You should have written:</p>
<pre><code>d[list[i]] = 1
</code></pre>
<p>But why not do this?</p>
<pre><code>def RemoveDuplicates(l):
return list(set(l))
</code></pre>
<p>Also, don't use built-in function names as variable names. It can lead to confusing bugs.</p>
| 11 | 2009-11-28T19:18:15Z | [
"python",
"duplicate-removal"
] |
Remove Duplicate Items in Dictionary | 1,813,469 | <p>I'm trying to remove duplicate items in a list through a dictionary:</p>
<pre><code>def RemoveDuplicates(list):
d = dict()
for i in xrange(0, len(list)):
dict[list[i]] = 1 <------- error here
return d.keys()
</code></pre>
<p>But it is raising me the following error:</p>
<pre><code>T... | 1 | 2009-11-28T19:15:25Z | 1,813,481 | <p>dict is the type, you mean <code>d[list[i]] = 1</code>.</p>
<p>Addition: This points out the actual error in your code. But the answers provided by others provide better way to achieve what you are aiming at.</p>
| 3 | 2009-11-28T19:19:02Z | [
"python",
"duplicate-removal"
] |
Remove Duplicate Items in Dictionary | 1,813,469 | <p>I'm trying to remove duplicate items in a list through a dictionary:</p>
<pre><code>def RemoveDuplicates(list):
d = dict()
for i in xrange(0, len(list)):
dict[list[i]] = 1 <------- error here
return d.keys()
</code></pre>
<p>But it is raising me the following error:</p>
<pre><code>T... | 1 | 2009-11-28T19:15:25Z | 1,813,489 | <pre><code>def remove_duplicates(myList):
return list (set(myList))
</code></pre>
<p>From looking at your code it seems that you are not bothered about the ordering of elements and concerned only about the uniqueness. In such a case, a set() could be a better data structure. </p>
<p>The problem in your code is ju... | 3 | 2009-11-28T19:20:26Z | [
"python",
"duplicate-removal"
] |
Remove Duplicate Items in Dictionary | 1,813,469 | <p>I'm trying to remove duplicate items in a list through a dictionary:</p>
<pre><code>def RemoveDuplicates(list):
d = dict()
for i in xrange(0, len(list)):
dict[list[i]] = 1 <------- error here
return d.keys()
</code></pre>
<p>But it is raising me the following error:</p>
<pre><code>T... | 1 | 2009-11-28T19:15:25Z | 1,813,519 | <p>In addition to what others have said, it is unpythonic to do this:</p>
<pre><code>for i in xrange(0, len(lst)):
do stuff with lst[i]
</code></pre>
<p>when you can do this instead:</p>
<pre><code>for item in lst:
do stuff with item
</code></pre>
| 4 | 2009-11-28T19:31:17Z | [
"python",
"duplicate-removal"
] |
Remove Duplicate Items in Dictionary | 1,813,469 | <p>I'm trying to remove duplicate items in a list through a dictionary:</p>
<pre><code>def RemoveDuplicates(list):
d = dict()
for i in xrange(0, len(list)):
dict[list[i]] = 1 <------- error here
return d.keys()
</code></pre>
<p>But it is raising me the following error:</p>
<pre><code>T... | 1 | 2009-11-28T19:15:25Z | 1,813,660 | <p>Note that using <code>list(set(seq))</code> will likely change the ordering of the remaining items. If retaining their order is important, you need to make a copy of the list:</p>
<pre><code>items = set()
copy = []
for item in seq:
if not item in items:
copy.add(item)
items.append(item)
seq = c... | 0 | 2009-11-28T20:14:37Z | [
"python",
"duplicate-removal"
] |
Django, how to generate an admin panel without models? | 1,813,637 | <p>I'm building a rather large project, that basically consists of this:</p>
<p>Server 1:
Ice based services.
Glacier2 for session handling.
Firewall allowing access to Glacier2.</p>
<p>Server 2:
Web interface (read, public) for Ice services via Glacier2.
Admin interface for Ice services via Glacier 2.</p>
... | 4 | 2009-11-28T20:08:02Z | 1,813,657 | <p>The django ORM has a pluggable backent, which means that you can write a backend for things that aren't RDBMSes. It's probably a rather large task, but a good place to get started is with Malcolm Tredinnick's talk from DjangoCon 2008, <a href="http://www.youtube.com/watch?v=zlhyp5Ve2qk" rel="nofollow">Inside the OR... | 0 | 2009-11-28T20:13:59Z | [
"python",
"django",
"django-admin",
"ice"
] |
Django, how to generate an admin panel without models? | 1,813,637 | <p>I'm building a rather large project, that basically consists of this:</p>
<p>Server 1:
Ice based services.
Glacier2 for session handling.
Firewall allowing access to Glacier2.</p>
<p>Server 2:
Web interface (read, public) for Ice services via Glacier2.
Admin interface for Ice services via Glacier 2.</p>
... | 4 | 2009-11-28T20:08:02Z | 1,813,666 | <p>The real power of the contrib.admin is <a href="http://docs.djangoproject.com/en/dev/topics/forms/" rel="nofollow">django Forms</a>. In essence, the admin tool is basically auto-generating a Form to match a Model with a little bit of urls.py routing thrown in. In the end it would probably just be easier to use dja... | 3 | 2009-11-28T20:15:47Z | [
"python",
"django",
"django-admin",
"ice"
] |
Django, how to generate an admin panel without models? | 1,813,637 | <p>I'm building a rather large project, that basically consists of this:</p>
<p>Server 1:
Ice based services.
Glacier2 for session handling.
Firewall allowing access to Glacier2.</p>
<p>Server 2:
Web interface (read, public) for Ice services via Glacier2.
Admin interface for Ice services via Glacier 2.</p>
... | 4 | 2009-11-28T20:08:02Z | 1,813,785 | <p>you can "mock" some class so it look like a model but it does proxy to your APIs</p>
<p>f.e.</p>
<pre><code>class QuerysetMock(object):
def all():
return call_to_your_api()
[...]
class MetaMock(object):
def fields():
return fields_mock_objects..
verbose_name = ''
[...]
cl... | 1 | 2009-11-28T21:06:28Z | [
"python",
"django",
"django-admin",
"ice"
] |
Django, how to generate an admin panel without models? | 1,813,637 | <p>I'm building a rather large project, that basically consists of this:</p>
<p>Server 1:
Ice based services.
Glacier2 for session handling.
Firewall allowing access to Glacier2.</p>
<p>Server 2:
Web interface (read, public) for Ice services via Glacier2.
Admin interface for Ice services via Glacier 2.</p>
... | 4 | 2009-11-28T20:08:02Z | 1,813,797 | <p>I think there might be a simpler way than writing custom ORMS to get the admin integration you want. I used it in an app that allows managing Webfaction email accounts via their Control Panel API.</p>
<p>Take a look at models.py, admin.py and urls.py here: <a href="http://code.google.com/p/django-webfaction/">djang... | 7 | 2009-11-28T21:11:35Z | [
"python",
"django",
"django-admin",
"ice"
] |
How to deal with "None" DB values in Django queries | 1,813,653 | <p>I have the following filter query which is doing an SQL OR statement:</p>
<pre><code>results = Stores.objects.filter(Q(title__icontains=prefs.address1) | Q(title__icontains=prefs.address2))
</code></pre>
<p>This works fine but if the prefs.address1 and prefs.address2 values (which come from another model) are blan... | 6 | 2009-11-28T20:13:00Z | 1,813,674 | <p>This?</p>
<pre><code>thefilter = Q(title__icontains=prefs.address1)
if prefs.address2 is not None:
thefilter = thefilter | Q(title__icontains=prefs.address2)
results = Stores.objects.filter( thefilter)
</code></pre>
| 3 | 2009-11-28T20:18:43Z | [
"python",
"django"
] |
How to deal with "None" DB values in Django queries | 1,813,653 | <p>I have the following filter query which is doing an SQL OR statement:</p>
<pre><code>results = Stores.objects.filter(Q(title__icontains=prefs.address1) | Q(title__icontains=prefs.address2))
</code></pre>
<p>This works fine but if the prefs.address1 and prefs.address2 values (which come from another model) are blan... | 6 | 2009-11-28T20:13:00Z | 1,813,768 | <p>You could do this which is easily generalisable to more queries</p>
<pre><code>query = Q()
for search in (prefs.address1, prefs.address2):
if search:
query |= Q(title__icontains=search)
results = Stores.objects.filter(query)
</code></pre>
| 8 | 2009-11-28T20:59:16Z | [
"python",
"django"
] |
Intersection between bezier curve and a line segment | 1,813,719 | <p>I am writing a game in Python (with pygame) that requires me to generate random but nice-looking "sea" for each new game. After a long search I settled on an algorithm that involves Bezier curves as defined in <a href="http://www.pygame.org/project-Pygame+Advance+Graphics+Library-660-.html">padlib.py</a>. I now need... | 13 | 2009-11-28T20:34:11Z | 1,813,744 | <p>As a rough outline, rotate and translate the system so that the line segment lies on the X axis. Now the y coordinate is a cubic function of the parameter t. Find the 'zeros' (the analytic formulae will be found in good math texts or wikipedia). Now evaluate the x coordinates corresponding to those zero points and t... | 7 | 2009-11-28T20:45:51Z | [
"python",
"math",
"geometry",
"pygame",
"spline"
] |
Intersection between bezier curve and a line segment | 1,813,719 | <p>I am writing a game in Python (with pygame) that requires me to generate random but nice-looking "sea" for each new game. After a long search I settled on an algorithm that involves Bezier curves as defined in <a href="http://www.pygame.org/project-Pygame+Advance+Graphics+Library-660-.html">padlib.py</a>. I now need... | 13 | 2009-11-28T20:34:11Z | 2,671,578 | <p>I've finally got to a working code to illustrate the method suggested by Mark Thornton. Below is the Python code for the intersection routine, together with pygame code to test it visually. The cubic roots solution can be written based on <a href="http://stackoverflow.com/questions/1829330/solving-a-cubic-equation">... | 5 | 2010-04-19T23:23:38Z | [
"python",
"math",
"geometry",
"pygame",
"spline"
] |
A puzzle concerning Q objects and Foreign Keys | 1,813,777 | <p>I've got a model like this:</p>
<pre><code>class Thing(models.Model):
property1 = models.IntegerField()
property2 = models.IntegerField()
property3 = models.IntegerField()
class Subthing(models.Model):
subproperty = models.IntegerField()
thing = modelsForeignkey(Thing)
main = models.Boolean... | 4 | 2009-11-28T21:02:02Z | 1,814,155 | <p>Using (instead of <code>final_q=Q()</code> in the beginning)</p>
<pre><code>final_q=Q(subthing_set__main=True)
sub_vals = map(lambda v: v['value'], filters)
if sub_vals:
final_q = final_q & Q(subthing_set__subproperty__in=sub_vals)
</code></pre>
<p>should get you what you want, you can also adjust your loo... | 1 | 2009-11-28T23:42:39Z | [
"python",
"django",
"django-models",
"django-queryset",
"django-q"
] |
A puzzle concerning Q objects and Foreign Keys | 1,813,777 | <p>I've got a model like this:</p>
<pre><code>class Thing(models.Model):
property1 = models.IntegerField()
property2 = models.IntegerField()
property3 = models.IntegerField()
class Subthing(models.Model):
subproperty = models.IntegerField()
thing = modelsForeignkey(Thing)
main = models.Boolean... | 4 | 2009-11-28T21:02:02Z | 1,814,164 | <p>It's a bit easier to understand if you explicitly give your Subthings a "related_name" in their relationship to the Thing</p>
<pre><code>class Subthing(models.Model):
...
thing = models.ForeignKey(Thing, related_name='subthings')
...
</code></pre>
<p>Now, you use <a href="http://docs.djangoproject.com/... | 2 | 2009-11-28T23:46:38Z | [
"python",
"django",
"django-models",
"django-queryset",
"django-q"
] |
How does python webdriver work? | 1,813,824 | <p>I want to add some features to <a href="http://code.google.com/p/webdriver/" rel="nofollow">webdriver</a>, but since I don't know Java at all, I want to understand the way it works first. So as I get it, there is a firefox plugin (javascript) and there is java code that starts firefox with that extension installed, ... | 3 | 2009-11-28T21:25:00Z | 1,813,855 | <p>Yeah you've got it. The Java server controls a browser with a special JavaScript environment that allows the server to control it. The server listens for commands given to it through http, when it receives commands, it pulls the strings on the browser to make it do stuff. The Python API for webdriver is code that co... | 4 | 2009-11-28T21:39:30Z | [
"java",
"javascript",
"python",
"firefox",
"webdriver"
] |
Running a process in pythonw with Popen without a console | 1,813,872 | <p>I have a program with a GUI that runs an external program through a Popen call:</p>
<pre><code>p = subprocess.Popen("<commands>" , stdout=subprocess.PIPE , stderr=subprocess.PIPE , cwd=os.getcwd())
p.communicate()
</code></pre>
<p>But a console pops up, regardless of what I do (I've also tried passing it NUL... | 9 | 2009-11-28T21:50:26Z | 1,813,893 | <p>From <a href="http://code.activestate.com/recipes/409002/">here</a>:</p>
<pre><code>import subprocess
def launchWithoutConsole(command, args):
"""Launches 'command' windowless and waits until finished"""
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
r... | 17 | 2009-11-28T21:58:35Z | [
"python",
"user-interface",
"console",
"popen",
"pythonw"
] |
Running a process in pythonw with Popen without a console | 1,813,872 | <p>I have a program with a GUI that runs an external program through a Popen call:</p>
<pre><code>p = subprocess.Popen("<commands>" , stdout=subprocess.PIPE , stderr=subprocess.PIPE , cwd=os.getcwd())
p.communicate()
</code></pre>
<p>But a console pops up, regardless of what I do (I've also tried passing it NUL... | 9 | 2009-11-28T21:50:26Z | 1,814,119 | <p>You might be able to just do <code>subprocess.Popen([command], shell=False)</code>.</p>
<p>That's what I use anyways. Saves you all the nonsense of setting flags and whatnot.
Once named as a .pyw or run with pythonw it shouldn't open a console.</p>
| 2 | 2009-11-28T23:27:55Z | [
"python",
"user-interface",
"console",
"popen",
"pythonw"
] |
How to search a HTML page for an item in a given list | 1,813,921 | <p>I have a list of schools</p>
<pre><code>schools = ['Harvard Law School', 'Stanford Law School', 'Yale Law School', 'Columbia Law School', 'NYU School of Law', 'University of Chicago Law School']
</code></pre>
<p>and bios of lawyers that contain one of these schools:</p>
<pre><code>html = "page that contains one o... | 0 | 2009-11-28T22:06:47Z | 1,814,011 | <p>I would need to know which school matches.</p>
<p>Now I am extracting the school info with regex (I am still testing):</p>
<pre><code> item = re.search('(JD)(.*?)(\d+)', html)
if item:
JD = item.group()
f = open('test1.txt', 'a')
f.write(JD)
else:
NoJD = ("empty cvs schem... | 0 | 2009-11-28T22:44:55Z | [
"python"
] |
How to search a HTML page for an item in a given list | 1,813,921 | <p>I have a list of schools</p>
<pre><code>schools = ['Harvard Law School', 'Stanford Law School', 'Yale Law School', 'Columbia Law School', 'NYU School of Law', 'University of Chicago Law School']
</code></pre>
<p>and bios of lawyers that contain one of these schools:</p>
<pre><code>html = "page that contains one o... | 0 | 2009-11-28T22:06:47Z | 1,814,026 | <p>I don't know nothing about Python but I often create dynamic regex expressions into a string like:</p>
<p>"(school 1|school 2|school 3|school n)"</p>
<p>Then I instantiate a regex object, passing the string.</p>
<p>You can then match your schools, regardless of the form of the document unless a HTML tag is in th... | 1 | 2009-11-28T22:50:44Z | [
"python"
] |
How to search a HTML page for an item in a given list | 1,813,921 | <p>I have a list of schools</p>
<pre><code>schools = ['Harvard Law School', 'Stanford Law School', 'Yale Law School', 'Columbia Law School', 'NYU School of Law', 'University of Chicago Law School']
</code></pre>
<p>and bios of lawyers that contain one of these schools:</p>
<pre><code>html = "page that contains one o... | 0 | 2009-11-28T22:06:47Z | 1,814,058 | <p>This is a very basic screen scraping way to achieve what you want</p>
<pre><code>import urllib
html = urllib.urlopen(pageToLawyersBio)
htmlstr=''
for line in html.readlines():
htmlstr += line.lower()
for school in listOfSchools:
if school.lower() in htmlstr:
print "This lawyer went to", school
</c... | 1 | 2009-11-28T23:02:35Z | [
"python"
] |
How to search a HTML page for an item in a given list | 1,813,921 | <p>I have a list of schools</p>
<pre><code>schools = ['Harvard Law School', 'Stanford Law School', 'Yale Law School', 'Columbia Law School', 'NYU School of Law', 'University of Chicago Law School']
</code></pre>
<p>and bios of lawyers that contain one of these schools:</p>
<pre><code>html = "page that contains one o... | 0 | 2009-11-28T22:06:47Z | 1,814,523 | <p>I hate to rain on your parade, but building a lookup list of law schools and then doing a set membership type of test in the source code probably will not work. The flawed approach:</p>
<pre><code>schools = []
html = page.read()
for school in list:
if school in html:
schools.append(school)
</code></pre>... | 1 | 2009-11-29T03:12:06Z | [
"python"
] |
How to search a HTML page for an item in a given list | 1,813,921 | <p>I have a list of schools</p>
<pre><code>schools = ['Harvard Law School', 'Stanford Law School', 'Yale Law School', 'Columbia Law School', 'NYU School of Law', 'University of Chicago Law School']
</code></pre>
<p>and bios of lawyers that contain one of these schools:</p>
<pre><code>html = "page that contains one o... | 0 | 2009-11-28T22:06:47Z | 1,814,616 | <p>You should consider using beautifulSoup to parse the HTML. In regards to your question, you might want to try something like:</p>
<pre><code>for line in html.split("<br \>"):
# This gives a lot of crap, filter it with
for values in line.split(", "):
try:
if values[0] in schools:... | 0 | 2009-11-29T04:04:37Z | [
"python"
] |
How to search a HTML page for an item in a given list | 1,813,921 | <p>I have a list of schools</p>
<pre><code>schools = ['Harvard Law School', 'Stanford Law School', 'Yale Law School', 'Columbia Law School', 'NYU School of Law', 'University of Chicago Law School']
</code></pre>
<p>and bios of lawyers that contain one of these schools:</p>
<pre><code>html = "page that contains one o... | 0 | 2009-11-28T22:06:47Z | 1,814,624 | <p>inspectorG4dgt: This is great! thanks. I think this better than using regex. Because in some pages "JD" comes before school name, in others, after the school name. Same with the graduation dates. </p>
<p>I have been trying to get the line where the school names occurs but I couldn't do it. Something like this:</p>
... | 0 | 2009-11-29T04:09:35Z | [
"python"
] |
python and securing pyc files on disk | 1,814,053 | <p>I set django's settings.py file to chmod 600 to keep felonious folks from spying my database connection info, but on import python compiles this file and writes out settings.pyc as mode 644. It doesn't take much sleuthing for the bad guys to get the info they need from this compiled version. I fear my blog entries a... | 1 | 2009-11-28T23:00:48Z | 1,814,092 | <p>To add a little bit to S.Lott's comment: The code portion of your blog should be stored in a location where it can be executed (e.g. via a web request), but not read directly. Any reasonable web server providing CGI support will allow this to be set up.</p>
| 1 | 2009-11-28T23:17:30Z | [
"python",
"security"
] |
python and securing pyc files on disk | 1,814,053 | <p>I set django's settings.py file to chmod 600 to keep felonious folks from spying my database connection info, but on import python compiles this file and writes out settings.pyc as mode 644. It doesn't take much sleuthing for the bad guys to get the info they need from this compiled version. I fear my blog entries a... | 1 | 2009-11-28T23:00:48Z | 1,814,099 | <p>You can set the umask directly in python. The interpreter uses this umask to create the pyc files:</p>
<pre><code>import os
os.umask(077) # Only keep rights for owner
import test
</code></pre>
<p>Verify the test.pyc created:</p>
<pre><code>$> ls -l test.py*
-rw-r--r-- 1 shad users 0 2009-11-29 00:15 test.py
-... | 6 | 2009-11-28T23:20:38Z | [
"python",
"security"
] |
Convert Python to Haskell / Lambda calculus | 1,814,061 | <p><strong>What is the Python code in Haskell and Lambda calculus?</strong></p>
<pre><code>def f1():
x = 77
def f2():
print x
f2
f1
</code></pre>
<p>My attempt in lambda calculus</p>
<pre><code>\x. 77 (\x.x)
</code></pre>
| 1 | 2009-11-28T23:03:06Z | 1,814,070 | <p>Haskell:</p>
<pre><code>f1 :: IO ()
f1 = let x = 77
f2 = print x
in f2
main :: IO ()
main = f1
</code></pre>
<p>Or to be more like your lambda calculus:</p>
<pre><code>f1 :: Int
f1 = let f2 = x
x = 77
in f2
main :: IO ()
main = print f1
</code></pre>
| 3 | 2009-11-28T23:07:59Z | [
"python",
"haskell",
"lambda",
"lambda-calculus"
] |
Convert Python to Haskell / Lambda calculus | 1,814,061 | <p><strong>What is the Python code in Haskell and Lambda calculus?</strong></p>
<pre><code>def f1():
x = 77
def f2():
print x
f2
f1
</code></pre>
<p>My attempt in lambda calculus</p>
<pre><code>\x. 77 (\x.x)
</code></pre>
| 1 | 2009-11-28T23:03:06Z | 1,814,085 | <p>I don't know python, so I could be completely wrong, but this is my Haskell interpretation.</p>
<pre><code>f1 = let x = 77 in show x
</code></pre>
<p>Or, since you've got a constant there</p>
<pre><code>f1 = show 77
</code></pre>
| 1 | 2009-11-28T23:15:27Z | [
"python",
"haskell",
"lambda",
"lambda-calculus"
] |
Convert Python to Haskell / Lambda calculus | 1,814,061 | <p><strong>What is the Python code in Haskell and Lambda calculus?</strong></p>
<pre><code>def f1():
x = 77
def f2():
print x
f2
f1
</code></pre>
<p>My attempt in lambda calculus</p>
<pre><code>\x. 77 (\x.x)
</code></pre>
| 1 | 2009-11-28T23:03:06Z | 1,814,877 | <p>In lambda calculus:</p>
<pre><code>λprint. print 77
</code></pre>
| 1 | 2009-11-29T07:02:10Z | [
"python",
"haskell",
"lambda",
"lambda-calculus"
] |
Convert Python to Haskell / Lambda calculus | 1,814,061 | <p><strong>What is the Python code in Haskell and Lambda calculus?</strong></p>
<pre><code>def f1():
x = 77
def f2():
print x
f2
f1
</code></pre>
<p>My attempt in lambda calculus</p>
<pre><code>\x. 77 (\x.x)
</code></pre>
| 1 | 2009-11-28T23:03:06Z | 3,034,083 | <p>In Haskell:</p>
<pre><code>f1 = f2
where x = 77
f2 = print x
</code></pre>
<p>Refactoring, since IO just confuses the issue:</p>
<pre><code>f1 = f2
where x = 77
f2 = x
</code></pre>
<p>Refactoring:</p>
<pre><code>f1 = x
where x = 77
</code></pre>
<p>Refactoring, since you want... | 8 | 2010-06-13T22:01:05Z | [
"python",
"haskell",
"lambda",
"lambda-calculus"
] |
Django, displaying a view in an another view? | 1,814,255 | <p>I would like to know if I can display a view inside another view with django.</p>
<p>This is what I tried to do:</p>
<pre><code>def displayRow(request, row_id):
row = Event.objects.get(pk=row_id)
return render_to_response('row.html', {'row': row})
def listEventsSummary(request):
listEventsSummary = Ev... | 5 | 2009-11-29T00:27:16Z | 1,814,266 | <p>http response contains headers along with html, or anything else, so you can't just add them up like strings.</p>
<p>if you want to modularize your view function, then have sub-procedure calls return strings and then you can do it the way you propose</p>
<p>Probably in your case it would be better to put a loop sh... | 4 | 2009-11-29T00:33:45Z | [
"python",
"django",
"django-views"
] |
Global disk resource becomes unavailable | 1,814,393 | <p>If I've got a global disk resource (mount point on an isilon file server) that multiple servers use to access a lock file. What is a good way to handle the situation if that global disk becomes unavailable and the servers can't access the global lock file?
Thanks,
Doug</p>
| 0 | 2009-11-29T02:00:48Z | 1,814,406 | <p>If this happens intermittently, you might just want to try waiting a short period and retrying. Other than that... log the error and fail. Maybe throw an exception that someone higher up can catch and deal with more gracefully.</p>
| 1 | 2009-11-29T02:05:35Z | [
"python",
"linux",
"fileserver",
"flock"
] |
Simple way to convert a string to a dictionary | 1,814,400 | <p>What is the simplest way to convert a string of keyword=values to a dictionary, for example the following string:</p>
<pre><code>name="John Smith", age=34, height=173.2, location="US", avatar=":,=)"
</code></pre>
<p>to the following python dictionary:</p>
<pre><code>{'name':'John Smith', 'age':34, 'height':173.2,... | 6 | 2009-11-29T02:03:17Z | 1,814,415 | <p><strong>Edit</strong>: since the <code>csv</code> module doesn't deal as desired with quotes <em>inside</em> fields, it takes a bit more work to implement this functionality:</p>
<pre><code>import re
quoted = re.compile(r'"[^"]*"')
class QuoteSaver(object):
def __init__(self):
self.saver = dict()
self.r... | 4 | 2009-11-29T02:08:31Z | [
"python",
"string",
"dictionary"
] |
Simple way to convert a string to a dictionary | 1,814,400 | <p>What is the simplest way to convert a string of keyword=values to a dictionary, for example the following string:</p>
<pre><code>name="John Smith", age=34, height=173.2, location="US", avatar=":,=)"
</code></pre>
<p>to the following python dictionary:</p>
<pre><code>{'name':'John Smith', 'age':34, 'height':173.2,... | 6 | 2009-11-29T02:03:17Z | 1,814,420 | <p>Always comma separated? Use the CSV module to split the line into parts (not checked):</p>
<pre><code>import csv
import cStringIO
parts=csv.reader(cStringIO.StringIO(<string to parse>)).next()
</code></pre>
| -2 | 2009-11-29T02:10:28Z | [
"python",
"string",
"dictionary"
] |
Simple way to convert a string to a dictionary | 1,814,400 | <p>What is the simplest way to convert a string of keyword=values to a dictionary, for example the following string:</p>
<pre><code>name="John Smith", age=34, height=173.2, location="US", avatar=":,=)"
</code></pre>
<p>to the following python dictionary:</p>
<pre><code>{'name':'John Smith', 'age':34, 'height':173.2,... | 6 | 2009-11-29T02:03:17Z | 1,814,482 | <p>The following code produces the correct behavior, but is just a bit long! I've added a space in the avatar to show that it deals well with commas and spaces and equal signs inside the string. Any suggestions to shorten it?</p>
<pre><code>import hashlib
string = 'name="John Smith", age=34, height=173.2, location="U... | 1 | 2009-11-29T02:43:44Z | [
"python",
"string",
"dictionary"
] |
Simple way to convert a string to a dictionary | 1,814,400 | <p>What is the simplest way to convert a string of keyword=values to a dictionary, for example the following string:</p>
<pre><code>name="John Smith", age=34, height=173.2, location="US", avatar=":,=)"
</code></pre>
<p>to the following python dictionary:</p>
<pre><code>{'name':'John Smith', 'age':34, 'height':173.2,... | 6 | 2009-11-29T02:03:17Z | 1,814,489 | <p>This works for me:</p>
<pre><code># get all the items
matches = re.findall(r'\w+=".+?"', s) + re.findall(r'\w+=[\d.]+',s)
# partition each match at '='
matches = [m.group().split('=', 1) for m in matches]
# use results to make a dict
d = dict(matches)
</code></pre>
| 9 | 2009-11-29T02:49:37Z | [
"python",
"string",
"dictionary"
] |
Simple way to convert a string to a dictionary | 1,814,400 | <p>What is the simplest way to convert a string of keyword=values to a dictionary, for example the following string:</p>
<pre><code>name="John Smith", age=34, height=173.2, location="US", avatar=":,=)"
</code></pre>
<p>to the following python dictionary:</p>
<pre><code>{'name':'John Smith', 'age':34, 'height':173.2,... | 6 | 2009-11-29T02:03:17Z | 1,814,569 | <p>I think you just need to set maxsplit=1, for instance the following should work.</p>
<pre><code>string = 'name="John Smith", age=34, height=173.2, location="US", avatar=":, =)"'
newDict = dict(map( lambda(z): z.split("=",1), string.split(", ") ))
</code></pre>
<p>Edit (see comment): </p>
<p>I didn't notice that "... | 0 | 2009-11-29T03:40:03Z | [
"python",
"string",
"dictionary"
] |
Simple way to convert a string to a dictionary | 1,814,400 | <p>What is the simplest way to convert a string of keyword=values to a dictionary, for example the following string:</p>
<pre><code>name="John Smith", age=34, height=173.2, location="US", avatar=":,=)"
</code></pre>
<p>to the following python dictionary:</p>
<pre><code>{'name':'John Smith', 'age':34, 'height':173.2,... | 6 | 2009-11-29T02:03:17Z | 1,814,714 | <p>Here is a more verbose approach to the problem using pyparsing. Note the parse actions
which do the automatic conversion of types from strings to ints or floats. Also, the
QuotedString class implicitly strips the quotation marks from the quoted value. Finally,
the Dict class takes each 'key = val' group in the co... | 2 | 2009-11-29T05:10:15Z | [
"python",
"string",
"dictionary"
] |
Simple way to convert a string to a dictionary | 1,814,400 | <p>What is the simplest way to convert a string of keyword=values to a dictionary, for example the following string:</p>
<pre><code>name="John Smith", age=34, height=173.2, location="US", avatar=":,=)"
</code></pre>
<p>to the following python dictionary:</p>
<pre><code>{'name':'John Smith', 'age':34, 'height':173.2,... | 6 | 2009-11-29T02:03:17Z | 1,814,733 | <p>do it step by step</p>
<pre><code>d={}
mystring='name="John Smith", age=34, height=173.2, location="US", avatar=":,=)"';
s = mystring.split(", ")
for item in s:
i=item.split("=",1)
d[i[0]]=i[-1]
print d
</code></pre>
| 0 | 2009-11-29T05:23:45Z | [
"python",
"string",
"dictionary"
] |
Simple way to convert a string to a dictionary | 1,814,400 | <p>What is the simplest way to convert a string of keyword=values to a dictionary, for example the following string:</p>
<pre><code>name="John Smith", age=34, height=173.2, location="US", avatar=":,=)"
</code></pre>
<p>to the following python dictionary:</p>
<pre><code>{'name':'John Smith', 'age':34, 'height':173.2,... | 6 | 2009-11-29T02:03:17Z | 1,814,806 | <p>Here is a approach with <code>eval</code>, I considered it is as unreliable though, but its works for your example.</p>
<pre><code>>>> import re
>>>
>>> s='name="John Smith", age=34, height=173.2, location="US", avatar=":,=)"'
>>>
>>> eval("{"+re.sub('(\w+)=("[^"]+"|[\d.... | 1 | 2009-11-29T06:11:56Z | [
"python",
"string",
"dictionary"
] |
Simple way to convert a string to a dictionary | 1,814,400 | <p>What is the simplest way to convert a string of keyword=values to a dictionary, for example the following string:</p>
<pre><code>name="John Smith", age=34, height=173.2, location="US", avatar=":,=)"
</code></pre>
<p>to the following python dictionary:</p>
<pre><code>{'name':'John Smith', 'age':34, 'height':173.2,... | 6 | 2009-11-29T02:03:17Z | 1,828,901 | <p>Here's a somewhat more robust version of the regexp solution:</p>
<pre><code>import re
keyval_re = re.compile(r'''
\s* # Leading whitespace is ok.
(?P<key>\w+)\s*=\s*( # Search for a key followed by..
(?P<str>"[^"]*"|\'[^\']*\')| # a q... | 1 | 2009-12-01T21:02:03Z | [
"python",
"string",
"dictionary"
] |
MySQL driver issues with INFORMATION_SCHEMA? | 1,814,408 | <p>I'm trying out the Concurrence framework for Stackless Python. It includes a MySQL driver and when running some code that previously ran fine with MySQLdb it fails.</p>
<p>What I am doing:</p>
<ol>
<li><p>Connecting to the MySQL database using dbapi with username/password/port/database.</p></li>
<li><p>Executing <... | 0 | 2009-11-29T02:06:11Z | 1,814,456 | <p>It definitely looks like a driver issue. Maybe the python driver don't support the DB prefix.</p>
<p>Just to be sure, try the other way around: first <code>use INFORMATION_SCHEMA</code> and then <code>SELECT * FROM mydatabase.sometable</code></p>
| 1 | 2009-11-29T02:32:15Z | [
"python",
"mysql",
"python-stackless",
"python-db-api"
] |
MySQL driver issues with INFORMATION_SCHEMA? | 1,814,408 | <p>I'm trying out the Concurrence framework for Stackless Python. It includes a MySQL driver and when running some code that previously ran fine with MySQLdb it fails.</p>
<p>What I am doing:</p>
<ol>
<li><p>Connecting to the MySQL database using dbapi with username/password/port/database.</p></li>
<li><p>Executing <... | 0 | 2009-11-29T02:06:11Z | 1,817,178 | <p>I finally found the reason.</p>
<p>The driver just echoed the server capability flags back in the protocol handshake, with the exception of compression:</p>
<pre><code>## concurrence/database/mysql/client.py ##
client_caps = server_caps
#always turn off compression
client_caps &= ~CAPS.COMPRESS
</code></pre... | 1 | 2009-11-29T23:42:21Z | [
"python",
"mysql",
"python-stackless",
"python-db-api"
] |
New transport and reader type in Twisted | 1,814,467 | <p>I'm trying to add a new transport to Twisted, which will read data from a stream - either a file in a <code>tail -f</code> way, or from a pipe, but I have some problems with Twisted architecture.</p>
<p>I've got the transport itself (implements <code>ITransport</code>) ready - it handles all file opening. I've got ... | 2 | 2009-11-29T02:38:02Z | 1,814,658 | <p>It sounds like you've mostly figured out how to do this. You might be interested in <code>twisted.internet.fdesc.readFromFD</code>, but it's only a few lines long and it's not doing anything particularly complicated (it's a few lines you don't have to maintain, though). Aside from that - yes, you have to do the I/... | 5 | 2009-11-29T04:31:31Z | [
"python",
"architecture",
"twisted",
"protocols",
"transport"
] |
Python: How to shutdown a threaded HTTP server with persistent connections (how to kill readline() from another thread)? | 1,814,575 | <p>I'm using python2.6 with <code>HTTPServer</code> and the <code>ThreadingMixIn</code>, which will handle each request in a separate thread. I'm also using HTTP1.1 persistent connections ('Connection: keep-alive'), so neither the server or client will close a connection after a request.</p>
<p>Here's roughly what th... | 2 | 2009-11-29T03:44:04Z | 1,814,588 | <p>You're almost there—the correct approach is to call <code>rfile.close()</code> and to catch the broken pipe errors and exit your loop when that happens.</p>
| 1 | 2009-11-29T03:50:14Z | [
"python",
"multithreading",
"sockets"
] |
Python: How to shutdown a threaded HTTP server with persistent connections (how to kill readline() from another thread)? | 1,814,575 | <p>I'm using python2.6 with <code>HTTPServer</code> and the <code>ThreadingMixIn</code>, which will handle each request in a separate thread. I'm also using HTTP1.1 persistent connections ('Connection: keep-alive'), so neither the server or client will close a connection after a request.</p>
<p>Here's roughly what th... | 2 | 2009-11-29T03:44:04Z | 1,814,591 | <p>If you set <code>daemon_threads</code> to true in your <code>HTTPServer</code> subclass, the activity of the threads will not prevent the server from exiting.</p>
<pre><code>class ThreadedHTTPServer(ThreadingMixIn, HTTPServer):
daemon_threads = True
</code></pre>
| 0 | 2009-11-29T03:51:18Z | [
"python",
"multithreading",
"sockets"
] |
Python: How to shutdown a threaded HTTP server with persistent connections (how to kill readline() from another thread)? | 1,814,575 | <p>I'm using python2.6 with <code>HTTPServer</code> and the <code>ThreadingMixIn</code>, which will handle each request in a separate thread. I'm also using HTTP1.1 persistent connections ('Connection: keep-alive'), so neither the server or client will close a connection after a request.</p>
<p>Here's roughly what th... | 2 | 2009-11-29T03:44:04Z | 1,814,597 | <p>You could work around the Windows problem by making <code>closefile</code> a socket, too -- after all, since it's presumably something that's opened by your main thread, it's up to you to decide whether to open it as a socket or a file;-).</p>
| 0 | 2009-11-29T03:54:02Z | [
"python",
"multithreading",
"sockets"
] |
Display gaps in dates with Python and Django | 1,814,664 | <p>I'm building an application that requires each user to make a post on a daily basis. I'd like to display the gaps in dates where users haven't made posts. Since it doesn't seem like a good idea to insert empty database rows for empty posts, I'm only inserting a record when the user adds a post.</p>
<p>The model con... | 2 | 2009-11-29T04:34:56Z | 1,814,710 | <p>I recommend building a set of dates that a user has posted, then start at the earliest date and iterate until the current day. For each day, print the date and check whether a post exists for that day. By using a set we can do this check in constant time, not that this will likely matter.</p>
<pre><code>days = se... | 4 | 2009-11-29T05:06:56Z | [
"python",
"django"
] |
How can I translate this XPath expression to BeautifulSoup? | 1,814,750 | <p>In answer to a <a href="http://stackoverflow.com/questions/1813921/how-to-search-a-html-page-for-an-item-in-a-given-list/1814616#1814616">previous question</a>, several people suggested that I use <a href="http://www.crummy.com/software/BeautifulSoup/">BeautifulSoup</a> for my project. I've been struggling with thei... | 9 | 2009-11-29T05:36:20Z | 1,814,763 | <p>one option is to use lxml (I'm not familiar with beautifulsoup, so I can't say how to do with it), it defaultly supports <a href="http://lxml.de/xpathxslt.html#xpath" rel="nofollow">XPath</a></p>
<p><strong>Edit:</strong><br>
try <strike>(untested)</strike> tested:</p>
<pre><code>soup.findAll('td', 'altRow')[1].fi... | 6 | 2009-11-29T05:41:58Z | [
"python",
"xpath",
"beautifulsoup"
] |
How can I translate this XPath expression to BeautifulSoup? | 1,814,750 | <p>In answer to a <a href="http://stackoverflow.com/questions/1813921/how-to-search-a-html-page-for-an-item-in-a-given-list/1814616#1814616">previous question</a>, several people suggested that I use <a href="http://www.crummy.com/software/BeautifulSoup/">BeautifulSoup</a> for my project. I've been struggling with thei... | 9 | 2009-11-29T05:36:20Z | 1,816,183 | <p>It seems that you are using BeautifulSoup 3.1</p>
<p>I suggest reverting to BeautifulSoup 3.0.7 (because of <a href="http://www.crummy.com/software/BeautifulSoup/3.1-problems.html" rel="nofollow">this problem</a>)</p>
<p>I just tested with 3.0.7 and got the results you expect:</p>
<pre><code>>>> soup.fin... | 1 | 2009-11-29T17:48:20Z | [
"python",
"xpath",
"beautifulsoup"
] |
How can I translate this XPath expression to BeautifulSoup? | 1,814,750 | <p>In answer to a <a href="http://stackoverflow.com/questions/1813921/how-to-search-a-html-page-for-an-item-in-a-given-list/1814616#1814616">previous question</a>, several people suggested that I use <a href="http://www.crummy.com/software/BeautifulSoup/">BeautifulSoup</a> for my project. I've been struggling with thei... | 9 | 2009-11-29T05:36:20Z | 1,816,635 | <p>I just answered this on the Beautiful Soup mailing list as a response to Zeynel's email to the list. Basically, there is an error in the web page that totally kills Beautiful Soup 3.1 during parsing, but is merely mangled by Beautiful Soup 3.0.</p>
<p>The thread is located at the <a href="http://groups.google.com/g... | 2 | 2009-11-29T20:16:04Z | [
"python",
"xpath",
"beautifulsoup"
] |
How can I translate this XPath expression to BeautifulSoup? | 1,814,750 | <p>In answer to a <a href="http://stackoverflow.com/questions/1813921/how-to-search-a-html-page-for-an-item-in-a-given-list/1814616#1814616">previous question</a>, several people suggested that I use <a href="http://www.crummy.com/software/BeautifulSoup/">BeautifulSoup</a> for my project. I've been struggling with thei... | 9 | 2009-11-29T05:36:20Z | 1,816,821 | <p>I know BeautifulSoup is the canonical HTML parsing module, but sometimes you just want to scrape out some substrings from some HTML, and pyparsing has some useful methods to do this. Using this code:</p>
<pre><code>from pyparsing import makeHTMLTags, withAttribute, SkipTo
import urllib
# get the HTML from your UR... | 3 | 2009-11-29T21:20:40Z | [
"python",
"xpath",
"beautifulsoup"
] |
Python: Extract HTML from an XML file | 1,814,923 | <p>My XML file looks like this:</p>
<pre><code> <strings>
<string>Bla <b>One &amp; Two</b> Foo</string>
</strings>
</code></pre>
<p>I want to extract the content of each <string> while maintaining the inner tags. That is, I would like to see the following Python st... | 0 | 2009-11-29T07:38:31Z | 1,814,928 | <p>try <a href="http://codespeak.net/lxml/api/lxml.etree-module.html#tostring" rel="nofollow">etree.tostring</a></p>
<pre><code>outer = etree.tostring(string_elem, method='html')
inner = re.match("^[^>]+>(.*)<[^<]+$", outer).groups(1)[0]
</code></pre>
| 2 | 2009-11-29T07:42:09Z | [
"python",
"html",
"xml",
"lxml"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.