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 |
|---|---|---|---|---|---|---|---|---|---|
Restarting a self-updating python script | 1,750,757 | <p>I have written a script that will keep itself up to date by downloading the latest version from a website and overwriting the running script.</p>
<p>I am not sure what the best way to restart the script after it has been updated.</p>
<p>Any ideas?</p>
<p>I don't really want to have a separate update script.
oh an... | 24 | 2009-11-17T18:16:55Z | 1,750,798 | <p>The cleanest solution is a separate update script!</p>
<p>Run your program inside it, report back (when exiting) that a new version is available. This allows your program to save all of its data, the updater to apply the update, and run the new version, which then loads the saved data and continues. To the user t... | 2 | 2009-11-17T18:23:32Z | [
"python",
"auto-update"
] |
Restarting a self-updating python script | 1,750,757 | <p>I have written a script that will keep itself up to date by downloading the latest version from a website and overwriting the running script.</p>
<p>I am not sure what the best way to restart the script after it has been updated.</p>
<p>Any ideas?</p>
<p>I don't really want to have a separate update script.
oh an... | 24 | 2009-11-17T18:16:55Z | 1,750,799 | <p>You can use <a href="http://docs.python.org/library/functions.html#reload" rel="nofollow">reload(module)</a> to reload a module.</p>
| 1 | 2009-11-17T18:23:59Z | [
"python",
"auto-update"
] |
Restarting a self-updating python script | 1,750,757 | <p>I have written a script that will keep itself up to date by downloading the latest version from a website and overwriting the running script.</p>
<p>I am not sure what the best way to restart the script after it has been updated.</p>
<p>Any ideas?</p>
<p>I don't really want to have a separate update script.
oh an... | 24 | 2009-11-17T18:16:55Z | 1,751,884 | <p>I think the best solution whould be something like this:</p>
<p>Your normal program:</p>
<pre><code>...
# ... part that downloaded newest files and put it into the "newest" folder
from subprocess import Popen
Popen("/home/code/reloader.py", shell=True) # start reloader
exit("exit for updating all files")
</cod... | 2 | 2009-11-17T21:20:42Z | [
"python",
"auto-update"
] |
Restarting a self-updating python script | 1,750,757 | <p>I have written a script that will keep itself up to date by downloading the latest version from a website and overwriting the running script.</p>
<p>I am not sure what the best way to restart the script after it has been updated.</p>
<p>Any ideas?</p>
<p>I don't really want to have a separate update script.
oh an... | 24 | 2009-11-17T18:16:55Z | 5,758,926 | <p>The CherryPy project has code that restarts itself. Here's <a href="http://www.cherrypy.org/browser/trunk/py2/cherrypy/process/wspbus.py#L345">how they do it</a>:</p>
<pre><code> args = sys.argv[:]
self.log('Re-spawning %s' % ' '.join(args))
args.insert(0, sys.executable)
if sys.platform == 'win32':... | 10 | 2011-04-22T18:54:14Z | [
"python",
"auto-update"
] |
Restarting a self-updating python script | 1,750,757 | <p>I have written a script that will keep itself up to date by downloading the latest version from a website and overwriting the running script.</p>
<p>I am not sure what the best way to restart the script after it has been updated.</p>
<p>Any ideas?</p>
<p>I don't really want to have a separate update script.
oh an... | 24 | 2009-11-17T18:16:55Z | 17,707,568 | <p>Main File:</p>
<pre><code>if __name__ == '__main__':
if os.path.isfile('__config.py'):
print 'Development'
push.update_server()
else:
e = update.check()
if not e: sys.exit()
</code></pre>
<p>Update File:</p>
<pre><code>def check():
e = 1.....perform checks, if something needs updating, e=0;
... | 0 | 2013-07-17T18:33:26Z | [
"python",
"auto-update"
] |
Restarting a self-updating python script | 1,750,757 | <p>I have written a script that will keep itself up to date by downloading the latest version from a website and overwriting the running script.</p>
<p>I am not sure what the best way to restart the script after it has been updated.</p>
<p>Any ideas?</p>
<p>I don't really want to have a separate update script.
oh an... | 24 | 2009-11-17T18:16:55Z | 27,004,102 | <p>To additionally support script calls with Python's "-m" parameter the following can be used (based on the Alex's answer; Windows version):</p>
<pre><code>os.spawnl(os.P_WAIT, sys.executable, *([sys.executable] +
(sys.argv if __package__ is None else ["-m", __loader__.name] + sys.argv[1:])))
sys.exit()
</code></... | 0 | 2014-11-18T21:09:31Z | [
"python",
"auto-update"
] |
Obtain MAC Address from Devices using Python | 1,750,803 | <p>I'm looking for a way (with python) to obtain the layer II address from a device on my local network. Layer III addresses are known.</p>
<p>The goal is to build a script that will poll a databases of IP addresses on regular intervals ensuring that the mac addresses have not changed and if they have, email alerts t... | 12 | 2009-11-17T18:24:09Z | 1,750,818 | <p>Sounds like you want to monitor ARP spoofers? In this case, all you need is <a href="http://en.wikipedia.org/wiki/Arpwatch" rel="nofollow">arpwatch</a>, available in every well-supplied Linux distribution near you. Download sources here: <a href="http://ee.lbl.gov/" rel="nofollow">http://ee.lbl.gov/</a></p>
| 2 | 2009-11-17T18:27:23Z | [
"python",
"ip-address",
"mac-address"
] |
Obtain MAC Address from Devices using Python | 1,750,803 | <p>I'm looking for a way (with python) to obtain the layer II address from a device on my local network. Layer III addresses are known.</p>
<p>The goal is to build a script that will poll a databases of IP addresses on regular intervals ensuring that the mac addresses have not changed and if they have, email alerts t... | 12 | 2009-11-17T18:24:09Z | 1,750,907 | <p>There was a <a href="http://stackoverflow.com/questions/85577/search-for-host-with-mac-address-using-python">similar question</a> answered not too long ago on this site. As mentioned in the answer chosen by the asker of that question, Python doesn't have a built-in way to do it. You must either call a system comman... | 2 | 2009-11-17T18:41:00Z | [
"python",
"ip-address",
"mac-address"
] |
Obtain MAC Address from Devices using Python | 1,750,803 | <p>I'm looking for a way (with python) to obtain the layer II address from a device on my local network. Layer III addresses are known.</p>
<p>The goal is to build a script that will poll a databases of IP addresses on regular intervals ensuring that the mac addresses have not changed and if they have, email alerts t... | 12 | 2009-11-17T18:24:09Z | 1,750,931 | <p>To answer the question with Python depends on your platform. I don't have Windows handy, so the following solution works on the Linux box I wrote it on. A small change to the regular expression will make it work in OS X.</p>
<p>First, you must ping the target. That will place the target -- as long as it's within... | 12 | 2009-11-17T18:44:39Z | [
"python",
"ip-address",
"mac-address"
] |
Obtain MAC Address from Devices using Python | 1,750,803 | <p>I'm looking for a way (with python) to obtain the layer II address from a device on my local network. Layer III addresses are known.</p>
<p>The goal is to build a script that will poll a databases of IP addresses on regular intervals ensuring that the mac addresses have not changed and if they have, email alerts t... | 12 | 2009-11-17T18:24:09Z | 21,259,964 | <p>Try using the netifaces found here. <a href="http://alastairs-place.net/projects/netifaces/" rel="nofollow">netifaces</a></p>
| 0 | 2014-01-21T13:46:35Z | [
"python",
"ip-address",
"mac-address"
] |
Obtain MAC Address from Devices using Python | 1,750,803 | <p>I'm looking for a way (with python) to obtain the layer II address from a device on my local network. Layer III addresses are known.</p>
<p>The goal is to build a script that will poll a databases of IP addresses on regular intervals ensuring that the mac addresses have not changed and if they have, email alerts t... | 12 | 2009-11-17T18:24:09Z | 31,575,892 | <p>for Unix based systems:</p>
<pre><code>#!/usr/bin/env python2.7
import re
import subprocess
arp_out =subprocess.check_output(['arp','-lan'])
re.findall(r"((\w{2,2}\:{0,1}){6})",arp_out)
</code></pre>
<p>will return list of tuples with macs.
scapy is an amazing tool , but seems to be overkill for this case </p>
| 0 | 2015-07-22T23:47:24Z | [
"python",
"ip-address",
"mac-address"
] |
Obtain MAC Address from Devices using Python | 1,750,803 | <p>I'm looking for a way (with python) to obtain the layer II address from a device on my local network. Layer III addresses are known.</p>
<p>The goal is to build a script that will poll a databases of IP addresses on regular intervals ensuring that the mac addresses have not changed and if they have, email alerts t... | 12 | 2009-11-17T18:24:09Z | 37,238,136 | <p>In Linux sometimems you miss the command line util "arp". A base yocto linux embedded environment image for instance. </p>
<p>An alternative way without the "arp" tool would be to read and parse the file /proc/net/arp:</p>
<pre><code>root@raspberrypi:~# cat /proc/net/arp
IP address HW type Flags HW... | 0 | 2016-05-15T12:11:03Z | [
"python",
"ip-address",
"mac-address"
] |
How do I get something like repeat customers in Django | 1,750,806 | <p>My models look something like this:</p>
<pre><code>class Customer(models.Model):
name = models.CharField(max_length=100)
class Order(models.Model):
customer = models.ForeignKey(Customer)
date = models.DateField()
total = models.DecimalField(max_digits=5, decimal_places=2)
</code></pre>
<p>I then have ... | 0 | 2009-11-17T18:24:57Z | 1,750,853 | <p>This would be a good use for Django 1.1's <a href="http://docs.djangoproject.com/en/dev/topics/db/aggregation/#generating-aggregates-for-each-item-in-a-queryset" rel="nofollow"><code>annotate()</code></a> functionality, which is part of <a href="http://docs.djangoproject.com/en/dev/topics/db/aggregation/#aggregation... | 0 | 2009-11-17T18:32:57Z | [
"python",
"django"
] |
How do I get something like repeat customers in Django | 1,750,806 | <p>My models look something like this:</p>
<pre><code>class Customer(models.Model):
name = models.CharField(max_length=100)
class Order(models.Model):
customer = models.ForeignKey(Customer)
date = models.DateField()
total = models.DecimalField(max_digits=5, decimal_places=2)
</code></pre>
<p>I then have ... | 0 | 2009-11-17T18:24:57Z | 1,751,432 | <p>Always base your query around the object in which you are primarily interested in:</p>
<pre><code>repeat_customers = Customer.objects.annotate(order_count=Count('order'))\
.filter(order_count__gt=1)
</code></pre>
<p>Then if you want to annotate with their totals (you could altern... | 1 | 2009-11-17T20:11:47Z | [
"python",
"django"
] |
Peeking in a heap in python | 1,750,991 | <p>What is the official way of peeking in a python heap as created by the heapq libs? Right now I have</p>
<pre><code>def heappeak(heap):
smallest = heappop(heap)
heappush(heap, smallest)
return smallest
</code></pre>
<p>which is arguably, not very nice. Can I always assume that <code>heap[0]</code> is the top ... | 12 | 2009-11-17T18:57:07Z | 1,751,007 | <p>Yes, you can make this assumption, because it is stated in the <a href="http://docs.python.org/3.1/library/heapq.html">documentation</a>:</p>
<blockquote>
<p>Heaps are arrays for which <code>heap[k] <= heap[2*k+1]</code> and <code>heap[k] <=
heap[2*k+2]</code> for all <em>k</em>, counting
elements from ... | 19 | 2009-11-17T19:00:17Z | [
"python",
"heap",
"peek"
] |
Peeking in a heap in python | 1,750,991 | <p>What is the official way of peeking in a python heap as created by the heapq libs? Right now I have</p>
<pre><code>def heappeak(heap):
smallest = heappop(heap)
heappush(heap, smallest)
return smallest
</code></pre>
<p>which is arguably, not very nice. Can I always assume that <code>heap[0]</code> is the top ... | 12 | 2009-11-17T18:57:07Z | 5,870,713 | <p>If you're using Python 2.4 or newer, you can also use heapq.nsmallest().</p>
| 4 | 2011-05-03T14:07:12Z | [
"python",
"heap",
"peek"
] |
Python SOAP server / client | 1,751,027 | <p>I have a problem with Python and SOAP. I need to create a web service based on SOAP in Python. I read that I can use libraries like soaplib, suds and ZSI. I created a Hello World web service with soaplib, like in documentation (<a href="http://trac.optio.webfactional.com/wiki/HelloWorld" rel="nofollow">http://trac.o... | 1 | 2009-11-17T19:03:03Z | 1,751,481 | <p>Are you asking whether it's possible to use (consume) a SOAP web service built with something other than soaplib? That would of course be possible. Suds is good idea for this.</p>
| 1 | 2009-11-17T20:18:36Z | [
"python",
"soap",
"web-services"
] |
Python SOAP server / client | 1,751,027 | <p>I have a problem with Python and SOAP. I need to create a web service based on SOAP in Python. I read that I can use libraries like soaplib, suds and ZSI. I created a Hello World web service with soaplib, like in documentation (<a href="http://trac.optio.webfactional.com/wiki/HelloWorld" rel="nofollow">http://trac.o... | 1 | 2009-11-17T19:03:03Z | 1,751,650 | <p>How are you serving the service? soaplib produces a WSGI object, which needs to be served by a webserver. If you are following the helloworld example you link to then you are using CherryPy (a pure python web server) to host the service on your own machine. In the example the port is 7789 (but you can use anything y... | 2 | 2009-11-17T20:46:19Z | [
"python",
"soap",
"web-services"
] |
Is there any way to read the header codes without downloading the file at all? | 1,751,253 | <pre><code> import httplib
conn = httplib.HTTPConnection(head)
conn.request("HEAD",tail)
res = conn.getresponse()
print res.status
</code></pre>
<p>I am currently using this to get the HTTP header code of a file.
However, it seems like this code DOWNLOADS the file, and then gets the code. </p>
<p>However, some fi... | 0 | 2009-11-17T19:41:24Z | 1,751,326 | <p>The purpose of the HTTP <code>HEAD</code> command is to return the header information, identical to what you would receive with a <code>GET</code> command, but without the response body (e.g. the video itself). If you are issuing the <code>HEAD</code> command and receiving the full body of the response anyway, that... | 1 | 2009-11-17T19:54:32Z | [
"python",
"http",
"header"
] |
Is there any way to read the header codes without downloading the file at all? | 1,751,253 | <pre><code> import httplib
conn = httplib.HTTPConnection(head)
conn.request("HEAD",tail)
res = conn.getresponse()
print res.status
</code></pre>
<p>I am currently using this to get the HTTP header code of a file.
However, it seems like this code DOWNLOADS the file, and then gets the code. </p>
<p>However, some fi... | 0 | 2009-11-17T19:41:24Z | 1,751,379 | <p>Unfortunately the <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html" rel="nofollow">HEAD HTTP Method</a> like all other HTTP method is just a directive to the server. The HTTP spec says that the server must not return the body in case, but if the server is not implemented or configured correctly then it... | 2 | 2009-11-17T20:01:04Z | [
"python",
"http",
"header"
] |
Is there any way to read the header codes without downloading the file at all? | 1,751,253 | <pre><code> import httplib
conn = httplib.HTTPConnection(head)
conn.request("HEAD",tail)
res = conn.getresponse()
print res.status
</code></pre>
<p>I am currently using this to get the HTTP header code of a file.
However, it seems like this code DOWNLOADS the file, and then gets the code. </p>
<p>However, some fi... | 0 | 2009-11-17T19:41:24Z | 1,751,759 | <p>As the others have said, if you're getting more than the headers back with the <code>HEAD</code> command, the target server is misconfigured.</p>
<p>However, a pragmatic solution to your problem is to simply ask for the first N bytes of the file, and then parse those as a header. Alternatively, stream the connectio... | 0 | 2009-11-17T21:03:26Z | [
"python",
"http",
"header"
] |
Is there any way to read the header codes without downloading the file at all? | 1,751,253 | <pre><code> import httplib
conn = httplib.HTTPConnection(head)
conn.request("HEAD",tail)
res = conn.getresponse()
print res.status
</code></pre>
<p>I am currently using this to get the HTTP header code of a file.
However, it seems like this code DOWNLOADS the file, and then gets the code. </p>
<p>However, some fi... | 0 | 2009-11-17T19:41:24Z | 1,752,262 | <p>Use urllib2.open() and get the headers already parsed for you, along with a file-handle ready to read the rest of the data stream. At that point you close the file and don't fetch anything more.</p>
<pre><code>>>> import urllib2
>>> f = urllib2.urlopen("http://stackoverflow.com/")
>>> for... | 0 | 2009-11-17T22:17:30Z | [
"python",
"http",
"header"
] |
Stuck on a loop! | 1,751,359 | <p>I am creating an app which will be used to upload images to a specified server. I have created my GUI in Qt Designer, everything works fine I just am stuck on something that I know is simple. Cant seem to wrap my head around it. </p>
<p>The idea is for the script to go through and see how many text fields are filed... | 0 | 2009-11-17T19:58:59Z | 1,751,454 | <p>Aside from the issue of the range needing to be +1 as so to reach to #3 (cf Remark by Vincent R),</p>
<p>(one of) the problem(s) is that the fullname variable is overwritten with each of the new case of non empty label.</p>
<p>It's hard to comment about the code to just fix it, i.e. I'd like to suggest and reorgan... | 0 | 2009-11-17T20:14:29Z | [
"python",
"image",
"ftp",
"range",
"qt-designer"
] |
Stuck on a loop! | 1,751,359 | <p>I am creating an app which will be used to upload images to a specified server. I have created my GUI in Qt Designer, everything works fine I just am stuck on something that I know is simple. Cant seem to wrap my head around it. </p>
<p>The idea is for the script to go through and see how many text fields are filed... | 0 | 2009-11-17T19:58:59Z | 1,751,456 | <p>The issue you have is that you are assigning to the variable <code>fullname</code> three times overwriting it each time. So by the time you get to the for loop only have the last file name available if the last field has been set otherwise you get nothing at all. Your statement that you need a list of full names ra... | 2 | 2009-11-17T20:14:45Z | [
"python",
"image",
"ftp",
"range",
"qt-designer"
] |
Stuck on a loop! | 1,751,359 | <p>I am creating an app which will be used to upload images to a specified server. I have created my GUI in Qt Designer, everything works fine I just am stuck on something that I know is simple. Cant seem to wrap my head around it. </p>
<p>The idea is for the script to go through and see how many text fields are filed... | 0 | 2009-11-17T19:58:59Z | 1,751,748 | <p>Another issue with your original code is that if labels 1 and 3 are not blank, but label 2 is, <code>totalImages</code> would be set to 3 even though you only have two paths.</p>
<p>Also, a typo in this code ("Two" vs "2"):</p>
<pre><code>if not self.imgTwoPathLabel.text().isEmpty():
image2 = self.img2PathLabe... | 0 | 2009-11-17T21:01:57Z | [
"python",
"image",
"ftp",
"range",
"qt-designer"
] |
Boost.Python + OpenGL segmentation faults | 1,751,408 | <p>I have a (almost) perfectly working C++ code written with Boost.Python. It wraps a shared pointer based structure hierarchy of 3 or 4 classes, nothing terribly complex (i.e. class A has a std::vector of class B instance pointers, etc.), top level package called, say, foo.</p>
<p>Some time ago I decided to add visua... | 1 | 2009-11-17T20:05:13Z | 5,835,733 | <p>If your OS is linux, you might be running into this bug: <a href="https://bugs.launchpad.net/ubuntu/+source/mesa/+bug/259219" rel="nofollow">https://bugs.launchpad.net/ubuntu/+source/mesa/+bug/259219</a>.</p>
<p>If calling</p>
<p><code>export LD_PRELOAD=<path-to-libstdc++></code></p>
<p>before starting your... | 2 | 2011-04-29T18:14:48Z | [
"python",
"memory",
"opengl",
"boost",
"segmentation-fault"
] |
Python equivalent of ruby's StringScanner? | 1,751,949 | <p>Is there a python class equivalent to ruby's <a href="http://ruby-doc.org/core/classes/StringScanner.html" rel="nofollow">StringScanner class</a>? I Could hack something together, but i don't want to reinvent the wheel if this already exists.</p>
| 2 | 2009-11-17T21:31:08Z | 1,751,992 | <p>Are you looking for regular expressions in Python? Check this link from official docs:</p>
<p><a href="http://docs.python.org/library/re.html" rel="nofollow">http://docs.python.org/library/re.html</a></p>
| 0 | 2009-11-17T21:36:06Z | [
"python",
"ruby",
"string"
] |
Python equivalent of ruby's StringScanner? | 1,751,949 | <p>Is there a python class equivalent to ruby's <a href="http://ruby-doc.org/core/classes/StringScanner.html" rel="nofollow">StringScanner class</a>? I Could hack something together, but i don't want to reinvent the wheel if this already exists.</p>
| 2 | 2009-11-17T21:31:08Z | 1,752,010 | <p>Looks like a variant on <code>re.split( pattern, string )</code>.</p>
<p><a href="http://docs.python.org/library/re.html" rel="nofollow">http://docs.python.org/library/re.html</a></p>
<p><a href="http://docs.python.org/library/re.html#re.split" rel="nofollow">http://docs.python.org/library/re.html#re.split</a></p>... | 1 | 2009-11-17T21:37:27Z | [
"python",
"ruby",
"string"
] |
Python equivalent of ruby's StringScanner? | 1,751,949 | <p>Is there a python class equivalent to ruby's <a href="http://ruby-doc.org/core/classes/StringScanner.html" rel="nofollow">StringScanner class</a>? I Could hack something together, but i don't want to reinvent the wheel if this already exists.</p>
| 2 | 2009-11-17T21:31:08Z | 1,752,064 | <p>Maybe look into the built in module <a href="http://docs.python.org/library/tokenize.html" rel="nofollow">tokenize</a>. It looks like you can pass a string into it using the <a href="http://docs.python.org/library/stringio.html" rel="nofollow">StringIO module</a>.</p>
| -1 | 2009-11-17T21:45:12Z | [
"python",
"ruby",
"string"
] |
Python equivalent of ruby's StringScanner? | 1,751,949 | <p>Is there a python class equivalent to ruby's <a href="http://ruby-doc.org/core/classes/StringScanner.html" rel="nofollow">StringScanner class</a>? I Could hack something together, but i don't want to reinvent the wheel if this already exists.</p>
| 2 | 2009-11-17T21:31:08Z | 1,752,076 | <p>Interestingly there's an undocumented <a href="http://code.activestate.com/recipes/457664/">Scanner</a> class in the <a href="http://docs.python.org/library/re.html">re</a> module:</p>
<pre><code>import re
def s_ident(scanner, token): return token
def s_operator(scanner, token): return "op%s" % token
def s_float(s... | 9 | 2009-11-17T21:48:06Z | [
"python",
"ruby",
"string"
] |
Python equivalent of ruby's StringScanner? | 1,751,949 | <p>Is there a python class equivalent to ruby's <a href="http://ruby-doc.org/core/classes/StringScanner.html" rel="nofollow">StringScanner class</a>? I Could hack something together, but i don't want to reinvent the wheel if this already exists.</p>
| 2 | 2009-11-17T21:31:08Z | 1,752,352 | <p>There is nothing exactly like Ruby's StringScanner in Python. It is of course easy to put something together:</p>
<pre><code>import re
class Scanner(object):
def __init__(self, s):
self.s = s
self.offset = 0
def eos(self):
return self.offset == len(self.s)
def scan(self, pattern... | 4 | 2009-11-17T22:33:40Z | [
"python",
"ruby",
"string"
] |
Python equivalent of ruby's StringScanner? | 1,751,949 | <p>Is there a python class equivalent to ruby's <a href="http://ruby-doc.org/core/classes/StringScanner.html" rel="nofollow">StringScanner class</a>? I Could hack something together, but i don't want to reinvent the wheel if this already exists.</p>
| 2 | 2009-11-17T21:31:08Z | 7,753,206 | <p>Today there is a project by Mark Watkinson that implements StringScanner in Python:</p>
<p><a href="http://asgaard.co.uk/p/Python-StringScanner" rel="nofollow">http://asgaard.co.uk/p/Python-StringScanner</a></p>
<p><a href="https://github.com/markwatkinson/python-string-scanner" rel="nofollow">https://github.com/m... | 0 | 2011-10-13T11:09:04Z | [
"python",
"ruby",
"string"
] |
Python equivalent of ruby's StringScanner? | 1,751,949 | <p>Is there a python class equivalent to ruby's <a href="http://ruby-doc.org/core/classes/StringScanner.html" rel="nofollow">StringScanner class</a>? I Could hack something together, but i don't want to reinvent the wheel if this already exists.</p>
| 2 | 2009-11-17T21:31:08Z | 21,358,717 | <p><a href="https://pypi.python.org/pypi/scanner/" rel="nofollow">https://pypi.python.org/pypi/scanner/</a></p>
<p>Seems a more maintained and feature complete solution. But it uses oniguruma directly.</p>
| 1 | 2014-01-26T01:59:43Z | [
"python",
"ruby",
"string"
] |
python paste using global egg instead of local one | 1,751,959 | <p>I'm using Paste to run a Pylons application. Is there a way to specify in my paste config file to use the egg from the current directory (the same dir as the config file) instead of looking in global site-packages?</p>
<p>For example, right now the config file has:</p>
<pre><code>[app:main]
use = egg:example
</co... | 0 | 2009-11-17T21:32:07Z | 1,752,125 | <p>Read this similar question, at least one of the answers should help you: <a href="http://stackoverflow.com/questions/1749452/making-python-use-code-in-my-directory-not-that-in-usr">http://stackoverflow.com/questions/1749452/making-python-use-code-in-my-directory-not-that-in-usr</a></p>
<p><strong>UPDATE:</strong> Y... | 1 | 2009-11-17T21:56:07Z | [
"python",
"pylons",
"paste",
"paster"
] |
python paste using global egg instead of local one | 1,751,959 | <p>I'm using Paste to run a Pylons application. Is there a way to specify in my paste config file to use the egg from the current directory (the same dir as the config file) instead of looking in global site-packages?</p>
<p>For example, right now the config file has:</p>
<pre><code>[app:main]
use = egg:example
</co... | 0 | 2009-11-17T21:32:07Z | 1,752,785 | <p>One way to use several versions of python package on the same system is <a href="http://wiki.pylonshq.com/display/pylonscookbook/Using+a+Virtualenv+Sandbox" rel="nofollow">virtualenv</a>. It works by creating sandboxed environments. All global packages are "visible" from sandboxed environment, but you can install n... | 1 | 2009-11-18T00:13:18Z | [
"python",
"pylons",
"paste",
"paster"
] |
How can I append data to a text file with a line break using Python? | 1,752,019 | <p>I've just been asked to come up with a script to find files with a certain filename length. I've decided to try out Python for the first time for this task as I've always wanted to learn it.</p>
<p>I've got the script to find the files and append them to a text file but it does not write a line break for each new e... | 2 | 2009-11-17T21:39:11Z | 1,752,047 | <p>You just need to explicitly append a <code>'\n'</code> each time you want a line break -- if you're appending to the output file in text mode, this will expand to the proper line separation where needed (e.g. Windows). (You could use <a href="http://docs.python.org/library/os.html?highlight=linesep#os.linesep">os.l... | 10 | 2009-11-17T21:42:41Z | [
"python"
] |
How can I append data to a text file with a line break using Python? | 1,752,019 | <p>I've just been asked to come up with a script to find files with a certain filename length. I've decided to try out Python for the first time for this task as I've always wanted to learn it.</p>
<p>I've got the script to find the files and append them to a text file but it does not write a line break for each new e... | 2 | 2009-11-17T21:39:11Z | 1,753,809 | <p>I am wondering why you don't have a line break when you print. an example.</p>
<pre><code>>>> import os
>>> for files in os.listdir("."):
... if os.path.isfile(files):
... print "file: ",files," length: ",len(files)
...
file: test1 length: 5
file: shell.sh length: 8
file: test.txt lengt... | 0 | 2009-11-18T05:23:04Z | [
"python"
] |
Custom traversal and page templates | 1,752,090 | <p>Using Marius Gedminas's <a href="http://mg.pov.lt/blog/zope3-custom-traversal.html" rel="nofollow">excellent blog post</a>, I have created a custom traverser for a folder in my site.</p>
<p>This allows me to show: <code>http://foo.com/folder/random_id</code></p>
<p>Instead of: <code>http://foo.com/folder/object.ht... | 0 | 2009-11-17T21:50:37Z | 1,754,488 | <p>If you end up at a proper object with your custom traverser, you can just tack on the template name and user "context" in that template. So <code>http://foo.com/folder/random_id/my_template</code> and in the template do the normal <code><h1 tal:content="context/title" /></code> stuff.</p>
| 0 | 2009-11-18T08:38:28Z | [
"python",
"zope",
"zpt"
] |
Custom traversal and page templates | 1,752,090 | <p>Using Marius Gedminas's <a href="http://mg.pov.lt/blog/zope3-custom-traversal.html" rel="nofollow">excellent blog post</a>, I have created a custom traverser for a folder in my site.</p>
<p>This allows me to show: <code>http://foo.com/folder/random_id</code></p>
<p>Instead of: <code>http://foo.com/folder/object.ht... | 0 | 2009-11-17T21:50:37Z | 1,755,710 | <p>IIUC, what you want is to render the 'read' view when somebody requests /folder/random_id. If that's the case, all you need to do is make your traversal return an object (IFolderContent, maybe) representing a random_id and specify the 'view' page as the defaultView for IFolderContent.</p>
<p>The defaultView is ne... | 0 | 2009-11-18T12:43:45Z | [
"python",
"zope",
"zpt"
] |
Custom traversal and page templates | 1,752,090 | <p>Using Marius Gedminas's <a href="http://mg.pov.lt/blog/zope3-custom-traversal.html" rel="nofollow">excellent blog post</a>, I have created a custom traverser for a folder in my site.</p>
<p>This allows me to show: <code>http://foo.com/folder/random_id</code></p>
<p>Instead of: <code>http://foo.com/folder/object.ht... | 0 | 2009-11-17T21:50:37Z | 1,756,577 | <p>It would be easier to answer your question if you showed what your custom traverser is doing.</p>
<p>Essentially, you want something like this:</p>
<pre><code>def publishTraverse(self, request, name):
if name in self.context:
return MyMessageView(self.context[name], request)
# fall back to views s... | 1 | 2009-11-18T14:58:06Z | [
"python",
"zope",
"zpt"
] |
How to loop until EOF in Python? | 1,752,107 | <p>I need to loop until I hit the end of a file-like object, but I'm not finding an "obvious way to do it", which makes me suspect I'm overlooking something, well, obvious. :-)</p>
<p>I have a stream (in this case, it's a StringIO object, but I'm curious about the general case as well) which stores an unknown number ... | 8 | 2009-11-17T21:53:01Z | 1,752,155 | <p>Have you seen how to iterate over lines in a text file?</p>
<pre><code>for line in file_obj:
use(line)
</code></pre>
<p>You can do the same thing with your own generator:</p>
<pre><code>def read_blocks(file_obj, size):
while True:
data = file_obj.read(size)
if not data:
break
yield data
for... | 9 | 2009-11-17T22:00:37Z | [
"python",
"eof",
"stringio"
] |
How to loop until EOF in Python? | 1,752,107 | <p>I need to loop until I hit the end of a file-like object, but I'm not finding an "obvious way to do it", which makes me suspect I'm overlooking something, well, obvious. :-)</p>
<p>I have a stream (in this case, it's a StringIO object, but I'm curious about the general case as well) which stores an unknown number ... | 8 | 2009-11-17T21:53:01Z | 1,752,170 | <p>I see, as predicted, that the typical and most popular answer are using very specialized generators to "read 4 bytes at a time". Sometimes generality isn't any harder (and much more rewarding;-), so, I've suggested instead the following very general solution:</p>
<pre><code>import operator
def funlooper(afun, *a, ... | 3 | 2009-11-17T22:02:49Z | [
"python",
"eof",
"stringio"
] |
How to loop until EOF in Python? | 1,752,107 | <p>I need to loop until I hit the end of a file-like object, but I'm not finding an "obvious way to do it", which makes me suspect I'm overlooking something, well, obvious. :-)</p>
<p>I have a stream (in this case, it's a StringIO object, but I'm curious about the general case as well) which stores an unknown number ... | 8 | 2009-11-17T21:53:01Z | 1,752,182 | <p>The EOF marker in python is an empty string so what you have is pretty close to the best you are going to get without writing a function to wrap this up in an iterator. I could be written in a little more pythonic way by changing the <code>while</code> like:</p>
<pre><code>while len_name:
len_name = struct.unpa... | 1 | 2009-11-17T22:05:15Z | [
"python",
"eof",
"stringio"
] |
How to loop until EOF in Python? | 1,752,107 | <p>I need to loop until I hit the end of a file-like object, but I'm not finding an "obvious way to do it", which makes me suspect I'm overlooking something, well, obvious. :-)</p>
<p>I have a stream (in this case, it's a StringIO object, but I'm curious about the general case as well) which stores an unknown number ... | 8 | 2009-11-17T21:53:01Z | 1,752,187 | <p>I prefer the already mentioned iterator-based solution to turn this into a for-loop. Another solution written directly is Knuth's "loop-and-a-half"</p>
<pre><code>while 1:
len_name = data.read(4)
if not len_name:
break
names.append(data.read(len_name))
</code></pre>
<p>You can see by comparison... | 5 | 2009-11-17T22:06:18Z | [
"python",
"eof",
"stringio"
] |
How to loop until EOF in Python? | 1,752,107 | <p>I need to loop until I hit the end of a file-like object, but I'm not finding an "obvious way to do it", which makes me suspect I'm overlooking something, well, obvious. :-)</p>
<p>I have a stream (in this case, it's a StringIO object, but I'm curious about the general case as well) which stores an unknown number ... | 8 | 2009-11-17T21:53:01Z | 1,752,208 | <p>You can combine iteration through <a href="http://docs.python.org/library/functions.html#iter">iter()</a> with a sentinel:</p>
<pre><code>for block in iter(lambda: file_obj.read(4), ""):
use(block)
</code></pre>
| 22 | 2009-11-17T22:09:52Z | [
"python",
"eof",
"stringio"
] |
How to loop until EOF in Python? | 1,752,107 | <p>I need to loop until I hit the end of a file-like object, but I'm not finding an "obvious way to do it", which makes me suspect I'm overlooking something, well, obvious. :-)</p>
<p>I have a stream (in this case, it's a StringIO object, but I'm curious about the general case as well) which stores an unknown number ... | 8 | 2009-11-17T21:53:01Z | 1,752,281 | <p>I'd go with Tendayi's suggestion re function and iterator for readability:</p>
<pre><code>def read4():
len_name = data.read(4)
if len_name:
len_name = struct.unpack("<I", len_name)[0]
return data.read(len_name)
else:
raise StopIteration
for d in iter(read4, ''):
names.app... | 0 | 2009-11-17T22:20:44Z | [
"python",
"eof",
"stringio"
] |
In Python, what does getresponse() return? | 1,752,283 | <pre><code> import httplib
conn = httplib.HTTPConnection(head)
conn.request("HEAD",tail)
res = conn.getresponse()
</code></pre>
<p>I can get the <strong>res.status</strong> , which is the http status code.</p>
<p>What other elements can I get?
Why is it that when I do print <strong>res</strong>, it won't ... | 8 | 2009-11-17T22:20:45Z | 1,752,295 | <p>You can always inspect an object using <a href="http://docs.python.org/library/functions.html#dir"><code>dir</code></a>; that will show you which attributes it has.</p>
<pre><code>>>> import httplib
>>> conn = httplib.HTTPConnection("www.google.nl")
>>> conn.request("HEAD", "/index.html")... | 21 | 2009-11-17T22:22:59Z | [
"python",
"linux",
"http",
"unix"
] |
How to get the true URL of a file on the web. (Python) | 1,752,317 | <p>I notice that sometimes audio files on the internet have a "fake" URL. </p>
<pre><code>http://garagaeband.com/3252243
</code></pre>
<p>And this will <strong>302</strong> to the real URL:</p>
<pre><code>http://garageband.com/michael_jackson4.mp3
</code></pre>
<p>My question is...when supplied with the fake URL, ... | 6 | 2009-11-17T22:26:55Z | 1,752,344 | <p>You have to read the response, realize that you got a 302 (FOUND), and parse out the real URL from the response headers, then fetch the resource using the new URI.</p>
| 0 | 2009-11-17T22:31:55Z | [
"python",
"linux",
"http",
"unix",
"http-headers"
] |
How to get the true URL of a file on the web. (Python) | 1,752,317 | <p>I notice that sometimes audio files on the internet have a "fake" URL. </p>
<pre><code>http://garagaeband.com/3252243
</code></pre>
<p>And this will <strong>302</strong> to the real URL:</p>
<pre><code>http://garageband.com/michael_jackson4.mp3
</code></pre>
<p>My question is...when supplied with the fake URL, ... | 6 | 2009-11-17T22:26:55Z | 1,752,362 | <p>Use urllib.getUrl()</p>
<p><strong>edit:</strong>
Sorry, I haven't done this in a while: </p>
<pre><code>import urllib
urllib.urlopen(url).geturl()
</code></pre>
<p>For example:</p>
<pre><code>>>> f = urllib2.urlopen("http://tinyurl.com/oex2e")
>>> f.geturl()
'http://www.amazon.com/All-Creatur... | 8 | 2009-11-17T22:35:47Z | [
"python",
"linux",
"http",
"unix",
"http-headers"
] |
How to get the true URL of a file on the web. (Python) | 1,752,317 | <p>I notice that sometimes audio files on the internet have a "fake" URL. </p>
<pre><code>http://garagaeband.com/3252243
</code></pre>
<p>And this will <strong>302</strong> to the real URL:</p>
<pre><code>http://garageband.com/michael_jackson4.mp3
</code></pre>
<p>My question is...when supplied with the fake URL, ... | 6 | 2009-11-17T22:26:55Z | 1,752,420 | <p>Mark Pilgrim advises to use <a href="http://code.google.com/p/httplib2/" rel="nofollow">httplib2</a> in "<a href="http://diveintopython3.org/http-web-services.html#httplib2-redirects" rel="nofollow">Dive Into Python3</a>" as it handles many things (including redirects) in a smarter way.</p>
<pre><code>>>> ... | 2 | 2009-11-17T22:45:51Z | [
"python",
"linux",
"http",
"unix",
"http-headers"
] |
How to get the true URL of a file on the web. (Python) | 1,752,317 | <p>I notice that sometimes audio files on the internet have a "fake" URL. </p>
<pre><code>http://garagaeband.com/3252243
</code></pre>
<p>And this will <strong>302</strong> to the real URL:</p>
<pre><code>http://garageband.com/michael_jackson4.mp3
</code></pre>
<p>My question is...when supplied with the fake URL, ... | 6 | 2009-11-17T22:26:55Z | 1,752,560 | <p>I solved the answer.</p>
<pre><code> import urllib2
req = urllib2.Request('http://' + theurl)
opener = urllib2.build_opener()
f = opener.open(req)
print 'the real url is......' + f .url
</code></pre>
| 0 | 2009-11-17T23:16:34Z | [
"python",
"linux",
"http",
"unix",
"http-headers"
] |
What conditions cause Tokyo Cabinet to block | 1,752,454 | <p>I'm using Tokyo Cabinet with the <code>tc</code> module in python. I store my data in the TDB format. I expected the table to block only for the duration of a write. Unfortunately, I see that when the file is open with in the "writer mode", other processes cannot read from it. Is that a standard behaviour, wrappers ... | 2 | 2009-11-17T22:53:45Z | 1,754,066 | <p>According to <a href="http://1978th.net/tokyocabinet/spex-en.html" rel="nofollow">specification</a>:</p>
<blockquote>
<p>Tokyo Cabinet provides two modes to
connect to a database: "reader" and
"writer". A reader can perform
retrieving but neither storing nor
deleting. A writer can perform all
access met... | 4 | 2009-11-18T06:35:15Z | [
"python",
"blocking",
"tokyo-cabinet"
] |
Python LEPL LineAwareConfiguration trouble | 1,752,645 | <p>I'm new to using python's LEPL, and it looks great. However, I'm trying to use the LineAwareConfiguration to easily handle a grammar in which whitespace matters, and I'm running into some serious issues. Namely, this code works:</p>
<pre><code>from lepl import *
broken = Token(r'.')
parser = broken[:].string_parser... | 1 | 2009-11-17T23:34:47Z | 1,752,744 | <p>Never mind: it looks like this is a known bug and that it's being worked on. Shows me to ask a question before I check the mailing lists...</p>
| 0 | 2009-11-18T00:01:26Z | [
"python"
] |
Python LEPL LineAwareConfiguration trouble | 1,752,645 | <p>I'm new to using python's LEPL, and it looks great. However, I'm trying to use the LineAwareConfiguration to easily handle a grammar in which whitespace matters, and I'm running into some serious issues. Namely, this code works:</p>
<pre><code>from lepl import *
broken = Token(r'.')
parser = broken[:].string_parser... | 1 | 2009-11-17T23:34:47Z | 1,757,401 | <p>yeah, sorry about this. it's at least partly related to the difference between normal (byte) and unicode strings in python 2.6 (the line aware code is new this last release). i will get a fixed release out as soon as i can - hopefully by the weekend. if you keep watching the mailing list there may be a point befo... | 2 | 2009-11-18T16:49:39Z | [
"python"
] |
BeautifulSoup - easy way to to obtain HTML-free contents | 1,752,662 | <p>I'm using this code to find all interesting links in a page:</p>
<pre><code>soup.findAll('a', href=re.compile('^notizia.php\?idn=\d+'))
</code></pre>
<p>And it does its job pretty well. Unfortunately inside that <strong>a</strong> tag there are a lot of nested tags, like <strong>font</strong>, <strong>b</strong> ... | 7 | 2009-11-17T23:38:20Z | 1,752,754 | <p>I've used this:</p>
<pre><code>def textOf(soup):
return u''.join(soup.findAll(text=True))
</code></pre>
<p>So...</p>
<pre><code>texts = [textOf(n) for n in soup.findAll('a', href=re.compile('^notizia.php\?idn=\d+'))]
</code></pre>
| 12 | 2009-11-18T00:04:22Z | [
"python",
"beautifulsoup",
"html-parsing",
"html-content-extraction"
] |
BeautifulSoup - easy way to to obtain HTML-free contents | 1,752,662 | <p>I'm using this code to find all interesting links in a page:</p>
<pre><code>soup.findAll('a', href=re.compile('^notizia.php\?idn=\d+'))
</code></pre>
<p>And it does its job pretty well. Unfortunately inside that <strong>a</strong> tag there are a lot of nested tags, like <strong>font</strong>, <strong>b</strong> ... | 7 | 2009-11-17T23:38:20Z | 1,752,907 | <p>Interested in a pyparsing take on the problem?</p>
<pre><code>from pyparsing import makeHTMLTags, SkipTo, anyOpenTag, anyCloseTag, ParseException
htmlsrc = """<A HREF="notizia.php?idn=1134" OnMouseOver="verde();" OnMouseOut="blu();"><FONT CLASS="v12"><B>03-11-2009:&nbsp;&nbsp;<font col... | 2 | 2009-11-18T00:45:42Z | [
"python",
"beautifulsoup",
"html-parsing",
"html-content-extraction"
] |
A dictionary with values that are dictionaries: trying to sum across those keys in python | 1,752,730 | <p>Data structure is a dictionary, each value is another dictionary, like:</p>
<pre><code>>>> from lib import schedule
>>> schedule = schedule.Schedule()
>>> game = schedule.games[0]
>>> game.home
<lib.schedule.Team instance at 0x9d97c6c>
>>> game.home.lineup
{'guerv0... | 1 | 2009-11-17T23:58:31Z | 1,752,760 | <p>You can use a generator expression:</p>
<pre><code>def total(category):
return sum(value.get(category, 0) for value in game.home.lineup.values())
>>> total('HR')
1104
</code></pre>
<p>I used <a href="http://docs.python.org/library/stdtypes.html#dict.get" rel="nofollow">dict.get</a> to make the defaul... | 4 | 2009-11-18T00:06:46Z | [
"python",
"hash",
"dictionary"
] |
A dictionary with values that are dictionaries: trying to sum across those keys in python | 1,752,730 | <p>Data structure is a dictionary, each value is another dictionary, like:</p>
<pre><code>>>> from lib import schedule
>>> schedule = schedule.Schedule()
>>> game = schedule.games[0]
>>> game.home
<lib.schedule.Team instance at 0x9d97c6c>
>>> game.home.lineup
{'guerv0... | 1 | 2009-11-17T23:58:31Z | 1,752,777 | <pre><code>def total(category):
return sum([ghl[man][category] for man in game.home.lineup.keys()])
</code></pre>
| 1 | 2009-11-18T00:11:00Z | [
"python",
"hash",
"dictionary"
] |
A dictionary with values that are dictionaries: trying to sum across those keys in python | 1,752,730 | <p>Data structure is a dictionary, each value is another dictionary, like:</p>
<pre><code>>>> from lib import schedule
>>> schedule = schedule.Schedule()
>>> game = schedule.games[0]
>>> game.home
<lib.schedule.Team instance at 0x9d97c6c>
>>> game.home.lineup
{'guerv0... | 1 | 2009-11-17T23:58:31Z | 1,752,779 | <pre><code>def myGetTotals(self, team):
count = 0
for aKey in self.lineup:
if team in self.lineup[aKey]:
count = count + self.lineup[aKey][team]
return count
</code></pre>
<p>Kind of verbose, but meh. Do pay attention to the first parameter which is the instance. Now, if you want it to ... | 0 | 2009-11-18T00:11:31Z | [
"python",
"hash",
"dictionary"
] |
How do I make a simple DNS server listening two ports simultaneously in python | 1,752,902 | <p>I'm trying to build a DNS server in python. It must listen two ports (8007 - client, 8008 - admin). The client only send an URL and receives the respective IP. The admin has permissions to change the DNS table (add, remove,.. doesn't matter to this right now).</p>
<p>So my question is: how do I implement the server... | 0 | 2009-11-18T00:44:43Z | 1,753,119 | <p>No need to use threads.</p>
<p>Use twisted.</p>
<p><a href="http://twistedmatrix.com/trac/wiki/TwistedNames">TwistedNames</a> has support out of the box for a dns server. You can customize it as needed or read its source as base when you build yours.</p>
| 5 | 2009-11-18T01:49:06Z | [
"python",
"dns",
"ports",
"listen"
] |
How do I make a simple DNS server listening two ports simultaneously in python | 1,752,902 | <p>I'm trying to build a DNS server in python. It must listen two ports (8007 - client, 8008 - admin). The client only send an URL and receives the respective IP. The admin has permissions to change the DNS table (add, remove,.. doesn't matter to this right now).</p>
<p>So my question is: how do I implement the server... | 0 | 2009-11-18T00:44:43Z | 1,753,268 | <p>You can use non-blocking sockets, and use the select call to read from the socket. This <a href="http://docs.python.org/howto/sockets.html" rel="nofollow">Sockets Programming HOWTO for Python</a> article has a section on <a href="http://docs.python.org/howto/sockets.html#non-blocking-sockets" rel="nofollow">non-bloc... | 0 | 2009-11-18T02:35:29Z | [
"python",
"dns",
"ports",
"listen"
] |
Python functions can be given new attributes from outside the scope? | 1,753,232 | <p>I didn't know you could do this:</p>
<pre><code>def tom():
print "tom's locals: ", locals()
def dick(z):
print "z.__name__ = ", z.__name__
z.guest = "Harry"
print "z.guest = ", z.guest
print "dick's locals: ", locals()
tom() #>>> tom's locals: {}
#print tom.guest #Att... | 2 | 2009-11-18T02:27:05Z | 1,753,261 | <p>In python, a namespace is just a dictionary object, mapping variable name as a string (in this case, 'guest') to a value (in this case, 'Harry'). So as long as you have access to an object, and it's mutable, you can change anything about its namespace.</p>
<p>On small projects, it's not a huge problem, and lets you... | 3 | 2009-11-18T02:34:11Z | [
"python",
"attributes",
"namespaces",
"scope"
] |
Python functions can be given new attributes from outside the scope? | 1,753,232 | <p>I didn't know you could do this:</p>
<pre><code>def tom():
print "tom's locals: ", locals()
def dick(z):
print "z.__name__ = ", z.__name__
z.guest = "Harry"
print "z.guest = ", z.guest
print "dick's locals: ", locals()
tom() #>>> tom's locals: {}
#print tom.guest #Att... | 2 | 2009-11-18T02:27:05Z | 1,753,277 | <p>tom.guest is just a property on the tom function object, it has nothing to do with the scope or locals() inside that function, and nothing to do with that fact that tom is a function, it would work on any object.</p>
| 1 | 2009-11-18T02:38:24Z | [
"python",
"attributes",
"namespaces",
"scope"
] |
Python functions can be given new attributes from outside the scope? | 1,753,232 | <p>I didn't know you could do this:</p>
<pre><code>def tom():
print "tom's locals: ", locals()
def dick(z):
print "z.__name__ = ", z.__name__
z.guest = "Harry"
print "z.guest = ", z.guest
print "dick's locals: ", locals()
tom() #>>> tom's locals: {}
#print tom.guest #Att... | 2 | 2009-11-18T02:27:05Z | 1,753,280 | <p>I think you might be conflating the concepts of <em>local variables</em> and <em>function attributes</em>. For more information on Python function attributes, see the SO question <a href="http://stackoverflow.com/questions/338101/python-function-attributes-uses-and-abuses">Python function attributes - uses and abuse... | 4 | 2009-11-18T02:39:03Z | [
"python",
"attributes",
"namespaces",
"scope"
] |
Python functions can be given new attributes from outside the scope? | 1,753,232 | <p>I didn't know you could do this:</p>
<pre><code>def tom():
print "tom's locals: ", locals()
def dick(z):
print "z.__name__ = ", z.__name__
z.guest = "Harry"
print "z.guest = ", z.guest
print "dick's locals: ", locals()
tom() #>>> tom's locals: {}
#print tom.guest #Att... | 2 | 2009-11-18T02:27:05Z | 1,753,344 | <p>Python functions are lexically scoped so there is no way to add variables to the function outside of its defined scope.</p>
<p>However, the function still will have access to all parent scopes, if you really wanted to design the system like that (generally considered bad practice though):</p>
<pre><code>>>&g... | 0 | 2009-11-18T02:53:20Z | [
"python",
"attributes",
"namespaces",
"scope"
] |
Python functions can be given new attributes from outside the scope? | 1,753,232 | <p>I didn't know you could do this:</p>
<pre><code>def tom():
print "tom's locals: ", locals()
def dick(z):
print "z.__name__ = ", z.__name__
z.guest = "Harry"
print "z.guest = ", z.guest
print "dick's locals: ", locals()
tom() #>>> tom's locals: {}
#print tom.guest #Att... | 2 | 2009-11-18T02:27:05Z | 1,753,421 | <p>I have used this in the past to make a self-contained function with "enums" that go along with it.</p>
<p>Suppose I were implementing a <code>seek()</code> function. The built-in Python one (on file objects) takes an integer to tell it how to operate; yuck, give me an enum please.</p>
<pre><code>def seek(f, offse... | 1 | 2009-11-18T03:18:08Z | [
"python",
"attributes",
"namespaces",
"scope"
] |
Python functions can be given new attributes from outside the scope? | 1,753,232 | <p>I didn't know you could do this:</p>
<pre><code>def tom():
print "tom's locals: ", locals()
def dick(z):
print "z.__name__ = ", z.__name__
z.guest = "Harry"
print "z.guest = ", z.guest
print "dick's locals: ", locals()
tom() #>>> tom's locals: {}
#print tom.guest #Att... | 2 | 2009-11-18T02:27:05Z | 1,753,450 | <p>Python API documentation generation tools, such as <a href="http://docs.python.org/library/pydoc" rel="nofollow">pydoc</a> and <a href="http://epydoc.sourceforge.net/" rel="nofollow">epydoc</a>, use introspection to determine a function's name and docstring (available as the <code>__name__</code> and <code>__doc__</... | 0 | 2009-11-18T03:29:38Z | [
"python",
"attributes",
"namespaces",
"scope"
] |
Python functions can be given new attributes from outside the scope? | 1,753,232 | <p>I didn't know you could do this:</p>
<pre><code>def tom():
print "tom's locals: ", locals()
def dick(z):
print "z.__name__ = ", z.__name__
z.guest = "Harry"
print "z.guest = ", z.guest
print "dick's locals: ", locals()
tom() #>>> tom's locals: {}
#print tom.guest #Att... | 2 | 2009-11-18T02:27:05Z | 1,753,475 | <p>@behindthefall, the motivation to give function objects generic assignable attributes (they didn't use to have them) was that, absent such possibilities, real and popular frameworks were abusing what few assignable attributes <strong>existed</strong> (typically <code>__doc__</code>) to record information about each ... | 4 | 2009-11-18T03:37:04Z | [
"python",
"attributes",
"namespaces",
"scope"
] |
Can this breadth-first search be made faster? | 1,753,257 | <p>I have a data set which is a large unweighted cyclic graph The cycles occur in loops of about 5-6 paths. It consists of about 8000 nodes and each node has from 1-6 (usually about 4-5) connections. I'm doing single pair shortest path calculations and have implemented the following code to do a breadth-first search.</... | 5 | 2009-11-18T02:33:23Z | 1,753,274 | <p>I'll bet that machine has more than one core, doesn't it? Run it in parallel. </p>
<p><a href="http://www.wellho.net/solutions/python-python-threads-a-first-example.html" rel="nofollow">Python Threading</a></p>
| 0 | 2009-11-18T02:37:53Z | [
"python",
"algorithm",
"computer-science",
"breadth-first-search"
] |
Can this breadth-first search be made faster? | 1,753,257 | <p>I have a data set which is a large unweighted cyclic graph The cycles occur in loops of about 5-6 paths. It consists of about 8000 nodes and each node has from 1-6 (usually about 4-5) connections. I'm doing single pair shortest path calculations and have implemented the following code to do a breadth-first search.</... | 5 | 2009-11-18T02:33:23Z | 1,753,276 | <p>Hmm, doesn't BFS involve marking nodes you've already seen so you don't visit them again?</p>
| 0 | 2009-11-18T02:38:13Z | [
"python",
"algorithm",
"computer-science",
"breadth-first-search"
] |
Can this breadth-first search be made faster? | 1,753,257 | <p>I have a data set which is a large unweighted cyclic graph The cycles occur in loops of about 5-6 paths. It consists of about 8000 nodes and each node has from 1-6 (usually about 4-5) connections. I'm doing single pair shortest path calculations and have implemented the following code to do a breadth-first search.</... | 5 | 2009-11-18T02:33:23Z | 1,753,308 | <p>Well, given the upvotes on the comment, I'll make it an answer now.</p>
<p>The SQL in the tight loop is <strong>definitely</strong> slowing you down. I don't care how fast the call is. Think about it -- you're asking for a query to be parsed, a lookup to be run -- as fast as that is, it's still in a tight loop. Wha... | 11 | 2009-11-18T02:44:36Z | [
"python",
"algorithm",
"computer-science",
"breadth-first-search"
] |
Can this breadth-first search be made faster? | 1,753,257 | <p>I have a data set which is a large unweighted cyclic graph The cycles occur in loops of about 5-6 paths. It consists of about 8000 nodes and each node has from 1-6 (usually about 4-5) connections. I'm doing single pair shortest path calculations and have implemented the following code to do a breadth-first search.</... | 5 | 2009-11-18T02:33:23Z | 1,753,536 | <p>Something like this:</p>
<pre><code>#!/usr/bin/env python
from Queue import Queue
def traverse_path(fromNode, toNode, nodes):
def getNeighbours(current, nodes):
return nodes[current] if current in nodes else []
def make_path(toNode, graph):
result = []
while 'Root' != toNode:
resu... | 1 | 2009-11-18T04:03:00Z | [
"python",
"algorithm",
"computer-science",
"breadth-first-search"
] |
Python optparse Values Instance | 1,753,460 | <p>How can I take the opt result of</p>
<pre><code>opt, args = parser.parse_args()
</code></pre>
<p>and place it in a dict? Python calls opt a "Values Instance" and I can't find any way to turn a Values Instance into a list or dict. One can't copy items from opt in this way,</p>
<pre><code>for i in opt:
myDict[i... | 43 | 2009-11-18T03:31:53Z | 1,753,466 | <pre><code>options, args = parser.parse_args()
option_dict = vars(options)
</code></pre>
<p><a href="http://mail.python.org/pipermail/python-ideas/2009-March/003623.html">(Source is this python-ideas post.)</a></p>
| 74 | 2009-11-18T03:34:32Z | [
"python",
"dictionary",
"optparse"
] |
appcfg.py upload_data is failing with expected <directory> even though I've got it | 1,753,867 | <p>I am having trouble getting the bulk uploader to work. I have been
following the tutorial here:<a href="http://code.google.com/appengine/docs/" rel="nofollow">http://code.google.com/appengine/docs/</a>
python/tools/uploadingdata.html.</p>
<p>When I enter the following command (from Windows, using PowerShell)</p>
... | 0 | 2009-11-18T05:36:27Z | 1,754,127 | <p>Do you get any more information when you add "--noisy" ? Are you logged in before you run above line ?</p>
| 0 | 2009-11-18T06:56:10Z | [
"python",
"google-app-engine"
] |
appcfg.py upload_data is failing with expected <directory> even though I've got it | 1,753,867 | <p>I am having trouble getting the bulk uploader to work. I have been
following the tutorial here:<a href="http://code.google.com/appengine/docs/" rel="nofollow">http://code.google.com/appengine/docs/</a>
python/tools/uploadingdata.html.</p>
<p>When I enter the following command (from Windows, using PowerShell)</p>
... | 0 | 2009-11-18T05:36:27Z | 2,820,758 | <p>the last parameter ./src/ could you explain what are you using it for?
the tools is expecting a parameter of: the app_Id of your app running on the google app engine or the root path of your applicacion generally is something like.</p>
<pre><code>/appcfg.py --config_file=person_loader.py --kind=person --filename=p... | 0 | 2010-05-12T16:23:12Z | [
"python",
"google-app-engine"
] |
What approach(es) have you used for lightweight Python unit-tests on App Engine? | 1,753,897 | <p>I'm about to embark on some large Python-based App Engine projects, and I think I should check with Stack Overflow's "wisdom of crowds" before committing to a unit-testing strategy. I have an existing unit-testing framework (based on <a href="http://docs.python.org/library/unittest.html?highlight=unittest#module-un... | 38 | 2009-11-18T05:44:45Z | 1,754,426 | <p>I use GAEUnit for my Google App Engine App and I am quite happy with the speed of the tests. The thing that I like about GAEUnit,and I am sure Webtest does it, is that it creates its own version for stubs of everything for testing leaving your "live" versions alone for testing.</p>
<p>So your datastore that you may... | 4 | 2009-11-18T08:24:14Z | [
"python",
"unit-testing",
"google-app-engine"
] |
What approach(es) have you used for lightweight Python unit-tests on App Engine? | 1,753,897 | <p>I'm about to embark on some large Python-based App Engine projects, and I think I should check with Stack Overflow's "wisdom of crowds" before committing to a unit-testing strategy. I have an existing unit-testing framework (based on <a href="http://docs.python.org/library/unittest.html?highlight=unittest#module-un... | 38 | 2009-11-18T05:44:45Z | 1,755,291 | <p>You don't need to write your own stubs - the SDK includes them, since they're what it uses to emulate the production APIs. Not all of them are suitable for use in unit-tests, but most are. Check out <a href="http://gist.github.com/186251" rel="nofollow">this code</a> for an example of the setup/teardown code you nee... | 13 | 2009-11-18T11:12:23Z | [
"python",
"unit-testing",
"google-app-engine"
] |
What approach(es) have you used for lightweight Python unit-tests on App Engine? | 1,753,897 | <p>I'm about to embark on some large Python-based App Engine projects, and I think I should check with Stack Overflow's "wisdom of crowds" before committing to a unit-testing strategy. I have an existing unit-testing framework (based on <a href="http://docs.python.org/library/unittest.html?highlight=unittest#module-un... | 38 | 2009-11-18T05:44:45Z | 1,914,406 | <p><a href="http://farmdev.com/projects/nosegae/">NoseGAE</a> is a nose plugin that support unittests by automatically setting up the development environment and a test datastore for you. Very useful when developing on dev_appserver.</p>
| 5 | 2009-12-16T12:35:26Z | [
"python",
"unit-testing",
"google-app-engine"
] |
What approach(es) have you used for lightweight Python unit-tests on App Engine? | 1,753,897 | <p>I'm about to embark on some large Python-based App Engine projects, and I think I should check with Stack Overflow's "wisdom of crowds" before committing to a unit-testing strategy. I have an existing unit-testing framework (based on <a href="http://docs.python.org/library/unittest.html?highlight=unittest#module-un... | 38 | 2009-11-18T05:44:45Z | 3,515,022 | <p>I might also add that <a href="http://farmdev.com/projects/fixture/using-fixture-with-appengine.html" rel="nofollow">Fixture</a> has been very useful in my unit tests. It lets you create models in a declarative syntax, which it converts into stored entities that you can load in your tests. This way you have the same... | 3 | 2010-08-18T17:48:43Z | [
"python",
"unit-testing",
"google-app-engine"
] |
What approach(es) have you used for lightweight Python unit-tests on App Engine? | 1,753,897 | <p>I'm about to embark on some large Python-based App Engine projects, and I think I should check with Stack Overflow's "wisdom of crowds" before committing to a unit-testing strategy. I have an existing unit-testing framework (based on <a href="http://docs.python.org/library/unittest.html?highlight=unittest#module-un... | 38 | 2009-11-18T05:44:45Z | 4,667,061 | <p>Since <a href="http://googleappengine.blogspot.com/2010/02/app-engine-sdk-131-including-major.html" rel="nofollow">1.3.1 version of SDK</a> there is the build-in <a href="http://code.google.com/appengine/docs/java/tools/localunittesting.html" rel="nofollow">unit test framework</a>.</p>
<p>It is Java only right now ... | 0 | 2011-01-12T09:24:05Z | [
"python",
"unit-testing",
"google-app-engine"
] |
What approach(es) have you used for lightweight Python unit-tests on App Engine? | 1,753,897 | <p>I'm about to embark on some large Python-based App Engine projects, and I think I should check with Stack Overflow's "wisdom of crowds" before committing to a unit-testing strategy. I have an existing unit-testing framework (based on <a href="http://docs.python.org/library/unittest.html?highlight=unittest#module-un... | 38 | 2009-11-18T05:44:45Z | 5,496,898 | <p>The <a href="http://code.google.com/p/googleappengine/wiki/SdkReleaseNotes" rel="nofollow">SDK 1.4.3</a> <a href="https://developers.google.com/appengine/docs/python/tools/localunittesting" rel="nofollow">Testbed API</a> provides easy configuration of stub libraries for local integration tests.</p>
| 1 | 2011-03-31T08:10:05Z | [
"python",
"unit-testing",
"google-app-engine"
] |
Qt Python radiobutton: activate event | 1,753,939 | <p>I am developing a project for one customer, where the design has a radio button with exclusive options. </p>
<p>Here is a piece of the code that runs and show two nice radio buttons:</p>
<pre><code> self.performGroupBox = QtGui.QGroupBox(self.centralwidget)
self.performGroupBox.setGeometry(QtCore.QRect(50, ... | 2 | 2009-11-18T05:56:55Z | 1,754,167 | <p>Try this signal instead:</p>
<pre><code>void toggled (bool)
</code></pre>
<p><a href="http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qabstractbutton.html#toggled">http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qabstractbutton.html#toggled</a></p>
| 9 | 2009-11-18T07:10:11Z | [
"python",
"user-interface",
"qt",
"qt4",
"pyqt"
] |
Qt Python radiobutton: activate event | 1,753,939 | <p>I am developing a project for one customer, where the design has a radio button with exclusive options. </p>
<p>Here is a piece of the code that runs and show two nice radio buttons:</p>
<pre><code> self.performGroupBox = QtGui.QGroupBox(self.centralwidget)
self.performGroupBox.setGeometry(QtCore.QRect(50, ... | 2 | 2009-11-18T05:56:55Z | 1,761,168 | <p>Here is solution... now working:</p>
<pre><code>QtCore.QObject.connect(self.radioButton1,QtCore.SIGNAL("toggled(bool)"),self.radio_activateInput)
</code></pre>
<p>when have the parameter bool included into toggled to signal, it worked.</p>
| 0 | 2009-11-19T05:53:01Z | [
"python",
"user-interface",
"qt",
"qt4",
"pyqt"
] |
Qt Python radiobutton: activate event | 1,753,939 | <p>I am developing a project for one customer, where the design has a radio button with exclusive options. </p>
<p>Here is a piece of the code that runs and show two nice radio buttons:</p>
<pre><code> self.performGroupBox = QtGui.QGroupBox(self.centralwidget)
self.performGroupBox.setGeometry(QtCore.QRect(50, ... | 2 | 2009-11-18T05:56:55Z | 1,934,413 | <p>Take a look at QButtonGroup class</p>
| 0 | 2009-12-19T23:11:42Z | [
"python",
"user-interface",
"qt",
"qt4",
"pyqt"
] |
Qt Python radiobutton: activate event | 1,753,939 | <p>I am developing a project for one customer, where the design has a radio button with exclusive options. </p>
<p>Here is a piece of the code that runs and show two nice radio buttons:</p>
<pre><code> self.performGroupBox = QtGui.QGroupBox(self.centralwidget)
self.performGroupBox.setGeometry(QtCore.QRect(50, ... | 2 | 2009-11-18T05:56:55Z | 13,601,702 | <pre><code># Assuming 'self' is a QtGui object
self.consultRadioButton = QtGui.QRadioButton('Consult')
# I prefer layout managers, but that is another topic
self.consultRadioButton.setGeometry(QtCore.QRect(40, 30, 84, 18))
self.consultRadioButton.setObjectName("consultRadioButton")
self.insertRadioButton = QtGui.QRadi... | 0 | 2012-11-28T09:23:44Z | [
"python",
"user-interface",
"qt",
"qt4",
"pyqt"
] |
python multiprocessing db access is very slow | 1,754,438 | <p>I have GUI that will interact with a postgres database, using psycopg2. I have db connection in a multiprocessing process, and send SQL via a multiprocessing queue, and receive via another queue.</p>
<p>The problem is that the speed is very very slow. A simple select * from a small table (30 rows) can be 1/10th o... | 1 | 2009-11-18T08:26:21Z | 1,754,551 | <p>Try to isolate what is taking the time - is it the multiprocessing or the database? For example try calling the database directly from the python interactive shell - the <a href="http://ipython.scipy.org/" rel="nofollow">ipython</a> shell has 'time' and 'timeit' commands for measuring things like this. Alternative... | 0 | 2009-11-18T08:51:10Z | [
"python",
"multiprocessing"
] |
python multiprocessing db access is very slow | 1,754,438 | <p>I have GUI that will interact with a postgres database, using psycopg2. I have db connection in a multiprocessing process, and send SQL via a multiprocessing queue, and receive via another queue.</p>
<p>The problem is that the speed is very very slow. A simple select * from a small table (30 rows) can be 1/10th o... | 1 | 2009-11-18T08:26:21Z | 1,754,595 | <p>Have you tried opening new database connection for each of your processes? It seems to me that you are simply adding overhead trying to reuse them in different processes.</p>
<p>Also, I'm not sure (your sample is to small to deduce) but it looks like you're opening new DB connection for each query... Are you closin... | 0 | 2009-11-18T08:59:49Z | [
"python",
"multiprocessing"
] |
python multiprocessing db access is very slow | 1,754,438 | <p>I have GUI that will interact with a postgres database, using psycopg2. I have db connection in a multiprocessing process, and send SQL via a multiprocessing queue, and receive via another queue.</p>
<p>The problem is that the speed is very very slow. A simple select * from a small table (30 rows) can be 1/10th o... | 1 | 2009-11-18T08:26:21Z | 1,765,092 | <p>It seems to be problems or a bug specific to Ubuntu 9.10 </p>
<p>All works fine on Ubuntu 9.04 and win32, even on win32 on a virtual machine hosted on Ubuntu 9.10.</p>
<p>Thanks for all the advice.</p>
| 0 | 2009-11-19T17:31:02Z | [
"python",
"multiprocessing"
] |
DOM related question and problem | 1,754,675 | <p>these day im making python script related with DOM.</p>
<p>problem is these day many website structure is very complicate .</p>
<p>what is best method to check DOM structure and path..</p>
<p>i mean...following is some example.</p>
<p>what is best method to check can extract such like following info quickly?</p... | 1 | 2009-11-18T09:17:37Z | 1,754,723 | <p>I would hope that you've read <a href="http://docs.python.org/library/xml.dom.html" rel="nofollow">Python's implementation of the DOM</a> and <a href="http://www.boddie.org.uk/python/XML%5Fintro.html" rel="nofollow">here's a good tutorial</a>. Alternatively, if you know javascript jQuery makes it incredibly easy to ... | 2 | 2009-11-18T09:26:00Z | [
"python",
"dom"
] |
Get Intervals Between Two Times | 1,754,781 | <p>A User will specify a time <code>interval</code> of <em>n</em> secs/mins/hours and then two times (<code>start</code> / <code>stop</code>).</p>
<p>I need to be able to take this <code>interval</code>, and then step through the <code>start</code> and <code>stop</code> times, in order to get a list of these times. Th... | 0 | 2009-11-18T09:39:54Z | 1,754,847 | <p>Are you looking for something like this? (pseudo code)</p>
<pre><code>t = start
while t != stop:
t += interval
table.objects.filter(t)
</code></pre>
| 4 | 2009-11-18T09:55:41Z | [
"python",
"django",
"datetime"
] |
Get Intervals Between Two Times | 1,754,781 | <p>A User will specify a time <code>interval</code> of <em>n</em> secs/mins/hours and then two times (<code>start</code> / <code>stop</code>).</p>
<p>I need to be able to take this <code>interval</code>, and then step through the <code>start</code> and <code>stop</code> times, in order to get a list of these times. Th... | 0 | 2009-11-18T09:39:54Z | 1,755,088 | <p>What about ...</p>
<pre><code>result = RelevantModel.objects.filter(relavant_field__in=[
start + interval * i
for i in xrange((start - end).seconds / interval.seconds)
])
</code></pre>
<p>... ?</p>
<p>I can't imagine this is very different from what you're already doing, but perhaps it's more compact (pa... | 1 | 2009-11-18T10:33:41Z | [
"python",
"django",
"datetime"
] |
Get Intervals Between Two Times | 1,754,781 | <p>A User will specify a time <code>interval</code> of <em>n</em> secs/mins/hours and then two times (<code>start</code> / <code>stop</code>).</p>
<p>I need to be able to take this <code>interval</code>, and then step through the <code>start</code> and <code>stop</code> times, in order to get a list of these times. Th... | 0 | 2009-11-18T09:39:54Z | 1,755,177 | <p>it fits nicely as a generator, too:</p>
<pre><code>def timeseq(start,stop,interval):
while start <= stop:
yield start
start += interval
</code></pre>
<p>used as:</p>
<pre><code>for t in timeseq(start,stop,interval):
table.objects.filter(t)
</code></pre>
<p>or:</p>
<pre><code>data = [t... | 4 | 2009-11-18T10:49:52Z | [
"python",
"django",
"datetime"
] |
log pysvn update | 1,754,841 | <p>How could I, if possible, get information on what files have been added, removed, updated etc when running svn update in pysvn? I want to write this information to a log file.</p>
| 3 | 2009-11-18T09:53:52Z | 3,665,153 | <p>you can save the original and updated revision, then use diff_summarize getting updated files. (see <a href="http://pysvn.tigris.org/docs/pysvn_prog_ref.html" rel="nofollow">pysvn Programmer's reference</a>)</p>
<p>here's an example:</p>
<pre><code>import time
import pysvn
work_path = '.'
client = pysvn.Client()... | 1 | 2010-09-08T06:30:15Z | [
"python",
"logging",
"pysvn"
] |
log pysvn update | 1,754,841 | <p>How could I, if possible, get information on what files have been added, removed, updated etc when running svn update in pysvn? I want to write this information to a log file.</p>
| 3 | 2009-11-18T09:53:52Z | 3,665,186 | <p>When you create your client object, add a <a href="http://pysvn.tigris.org/docs/pysvn_prog_ref.html#pysvn_client_callback_notify" rel="nofollow">notify callback</a>. The callback is a function that takes a <code>dict</code> of information about the event.</p>
<pre><code>import pysvn
import pprint
def notify(event_... | 1 | 2010-09-08T06:36:20Z | [
"python",
"logging",
"pysvn"
] |
log pysvn update | 1,754,841 | <p>How could I, if possible, get information on what files have been added, removed, updated etc when running svn update in pysvn? I want to write this information to a log file.</p>
| 3 | 2009-11-18T09:53:52Z | 22,669,437 | <p>I know this is old but there is not an accepted answer and I stumbled across it while searching for info pertaining to <code>node_kind</code>.</p>
<pre><code>import pysvn
tmpFile = open('your.log', 'w')
repository = sys.argv[1]
transactionId = sys.argv[2]
transaction = pysvn.Transaction(repository, transactionId)... | 1 | 2014-03-26T18:05:01Z | [
"python",
"logging",
"pysvn"
] |
How can I run a Makefile in setup.py? | 1,754,966 | <p>I need to compile <a href="http://icu-project.org">ICU</a> using it's own build mechanism. Therefore the question:</p>
<p>How can I run a Makefile from <code>setup.py</code>? Obviously, I only want it to run during the build process, not while installing.</p>
| 24 | 2009-11-18T10:15:42Z | 1,757,199 | <p>If you are building a python extension you can use the distutils/setuptools Extensions. For example:</p>
<pre><code>from setuptools import Extension
# or:
# from distutils.extension import Extension
setup(...
ext_modules = [Extension("pkg.icu",
["icu-sqlite/icu.c"]),
... | 1 | 2009-11-18T16:20:56Z | [
"python",
"distutils"
] |
How can I run a Makefile in setup.py? | 1,754,966 | <p>I need to compile <a href="http://icu-project.org">ICU</a> using it's own build mechanism. Therefore the question:</p>
<p>How can I run a Makefile from <code>setup.py</code>? Obviously, I only want it to run during the build process, not while installing.</p>
| 24 | 2009-11-18T10:15:42Z | 1,763,900 | <p>The method I normally use is to override the command in question:</p>
<pre><code>from distutils.command.install import install as DistutilsInstall
class MyInstall(DistutilsInstall):
def run(self):
do_pre_install_stuff()
DistutilsInstall.run(self)
do_post_install_stuff()
...
setup(...,... | 27 | 2009-11-19T15:02:48Z | [
"python",
"distutils"
] |
How can I run a Makefile in setup.py? | 1,754,966 | <p>I need to compile <a href="http://icu-project.org">ICU</a> using it's own build mechanism. Therefore the question:</p>
<p>How can I run a Makefile from <code>setup.py</code>? Obviously, I only want it to run during the build process, not while installing.</p>
| 24 | 2009-11-18T10:15:42Z | 7,931,777 | <p>It is possible to build C libraries with distutils (see the libraries parameter of distutils.core.setup), but you may have to duplicate options that are already in the Makefile, so the easiest thing to do is probably to extend the install command as explained in other replies and call make with the subprocess module... | 0 | 2011-10-28T16:01:13Z | [
"python",
"distutils"
] |
'import feedparser' works via SSH, but fails when in browser | 1,755,043 | <p>I installed feedparser via SSH, using</p>
<pre><code>$ python setup.py install --home=~/httpdocs/python-libraries/feedparser-4.1/
</code></pre>
<p>I did that because I don't seem to have permission to properly run 'python setup.py install'</p>
<p>I am running the following python code in 'test.py'. </p>
<pre><co... | 1 | 2009-11-18T10:26:48Z | 1,755,102 | <p>Sounds like a PYTHONPATH problem. Try changing the code to this and see what happens:</p>
<pre><code>import sys
print "Content-type: text/html\n\n"
try:
print sys.path
import feedparser
except:
print "Cannot import feedparser.\n"
print sys.path
</code></pre>
<p>This probably will show that your ~/h... | 3 | 2009-11-18T10:36:40Z | [
"python",
"browser",
"feedparser",
"import"
] |
'import feedparser' works via SSH, but fails when in browser | 1,755,043 | <p>I installed feedparser via SSH, using</p>
<pre><code>$ python setup.py install --home=~/httpdocs/python-libraries/feedparser-4.1/
</code></pre>
<p>I did that because I don't seem to have permission to properly run 'python setup.py install'</p>
<p>I am running the following python code in 'test.py'. </p>
<pre><co... | 1 | 2009-11-18T10:26:48Z | 1,755,106 | <p>Maybe it's the problem with setting correct <code>sys.path</code> while running from shell vs from web server.</p>
<p>More about <code>sys.path</code> here: <a href="http://docs.python.org/library/sys.html#sys.path" rel="nofollow">sys module</a>.</p>
<p>I'd recomend to try adding <code>~/httpdocs/python-libraries/... | 7 | 2009-11-18T10:38:01Z | [
"python",
"browser",
"feedparser",
"import"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.