title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
listlengths
1
5
Why do pythonistas call the current reference "self" and not "this"?
1,079,983
<p>Python is the language I know the most, and strangely I still don't know why I'm typing "self" and not "this" like in Java or PHP.</p> <p>I know that Python is older than Java, but I can't figure out where does this come from. Especially since you can use any name instead of "self": the program will work fine.</p> ...
35
2009-07-03T16:06:00Z
1,079,995
<p>Smalltalk, which predates Java of course.</p>
18
2009-07-03T16:09:38Z
[ "python" ]
Why do pythonistas call the current reference "self" and not "this"?
1,079,983
<p>Python is the language I know the most, and strangely I still don't know why I'm typing "self" and not "this" like in Java or PHP.</p> <p>I know that Python is older than Java, but I can't figure out where does this come from. Especially since you can use any name instead of "self": the program will work fine.</p> ...
35
2009-07-03T16:06:00Z
1,080,001
<p>Check the <a href="http://python-history.blogspot.com/2009/02/adding-support-for-user-defined-classes.html">history of Python</a> for user defined classes:</p> <blockquote> <p>Instead, one simply defines a function whose first argument corresponds to the instance, which by convention is named "self." For example:...
27
2009-07-03T16:11:11Z
[ "python" ]
Why do pythonistas call the current reference "self" and not "this"?
1,079,983
<p>Python is the language I know the most, and strangely I still don't know why I'm typing "self" and not "this" like in Java or PHP.</p> <p>I know that Python is older than Java, but I can't figure out where does this come from. Especially since you can use any name instead of "self": the program will work fine.</p> ...
35
2009-07-03T16:06:00Z
1,080,192
<p>Smalltalk-80, released by Xerox in 1980, used <code>self</code>. Objective-C (early 1980s) layers Smalltalk features over C, so it uses <code>self</code> too. Modula-3 (1988), Python (late 1980s), and Ruby (mid 1990s) also follow this tradition.</p> <p>C++, also dating from the early 1980s, chose <code>this</code...
61
2009-07-03T17:09:52Z
[ "python" ]
Why do pythonistas call the current reference "self" and not "this"?
1,079,983
<p>Python is the language I know the most, and strangely I still don't know why I'm typing "self" and not "this" like in Java or PHP.</p> <p>I know that Python is older than Java, but I can't figure out where does this come from. Especially since you can use any name instead of "self": the program will work fine.</p> ...
35
2009-07-03T16:06:00Z
1,081,235
<p>I think that since it's explicitly declared it makes more sense seeing an actual argument called "self" rather than "this". From the grammatical point of view at least, "self" is not as context dependent as "this".</p> <p>I don't know if I made myself clear enough, but anyway this is just a subjective appreciation....
5
2009-07-04T00:54:30Z
[ "python" ]
Why do pythonistas call the current reference "self" and not "this"?
1,079,983
<p>Python is the language I know the most, and strangely I still don't know why I'm typing "self" and not "this" like in Java or PHP.</p> <p>I know that Python is older than Java, but I can't figure out where does this come from. Especially since you can use any name instead of "self": the program will work fine.</p> ...
35
2009-07-03T16:06:00Z
1,081,454
<p>The primary inspiration was Modula-3, which Guido was introduced to at DEC: </p> <blockquote> <p>the Modula-3 final report was being written there at about the same time. What I learned there showed up in Python's exception handling, modules, and the fact that methods explicitly contain “self” in th...
7
2009-07-04T03:56:41Z
[ "python" ]
Why do pythonistas call the current reference "self" and not "this"?
1,079,983
<p>Python is the language I know the most, and strangely I still don't know why I'm typing "self" and not "this" like in Java or PHP.</p> <p>I know that Python is older than Java, but I can't figure out where does this come from. Especially since you can use any name instead of "self": the program will work fine.</p> ...
35
2009-07-03T16:06:00Z
8,620,042
<p>With respect to python, there is nothing special about <code>self</code>. You can use <code>this</code> instead if you wanted:</p> <p>Here's an example:</p> <pre><code>&gt;&gt;&gt; class A(object): ... def __init__(this): ... this.x = 3 ... &gt;&gt;&gt; a = A() &gt;&gt;&gt; a.x 3 </code></pre> <p>Althou...
14
2011-12-23T19:49:27Z
[ "python" ]
Why do pythonistas call the current reference "self" and not "this"?
1,079,983
<p>Python is the language I know the most, and strangely I still don't know why I'm typing "self" and not "this" like in Java or PHP.</p> <p>I know that Python is older than Java, but I can't figure out where does this come from. Especially since you can use any name instead of "self": the program will work fine.</p> ...
35
2009-07-03T16:06:00Z
8,620,086
<p>Python follows Smalltalk's footsteps in the aspect - self is used in Smalltalk as well. I guess the <em>real</em> question should be 'why did Bjarne decide to use <code>this</code> in C++'...</p>
7
2011-12-23T19:54:24Z
[ "python" ]
Why do pythonistas call the current reference "self" and not "this"?
1,079,983
<p>Python is the language I know the most, and strangely I still don't know why I'm typing "self" and not "this" like in Java or PHP.</p> <p>I know that Python is older than Java, but I can't figure out where does this come from. Especially since you can use any name instead of "self": the program will work fine.</p> ...
35
2009-07-03T16:06:00Z
8,620,108
<p><code>self</code> is not a keyword (*).</p> <p><code>self</code> represents by convention the address of the current object</p> <p>You can get more info on <code>self</code> <a href="http://stackoverflow.com/questions/2709821/python-self-explained">here</a>.</p> <p>Why not <code>this</code> ? well it is a convent...
2
2011-12-23T19:56:17Z
[ "python" ]
Is there a map without result in python?
1,080,026
<p>Sometimes, I just want to execute a function for a list of entries -- eg.:</p> <pre><code>for x in wowList: installWow(x, 'installed by me') </code></pre> <p>Sometimes I need this stuff for module initialization, so I don't want to have a footprint like x in global namespace. One solution would be to just use m...
15
2009-07-03T16:20:11Z
1,080,053
<p>You might try this:</p> <pre><code>filter(lambda x: installWow(x, 'installed by me') and False, wowList) </code></pre> <p>That way, the return result is an empty list no matter what.</p> <p>Or you could just drop the <code>and False</code> if you can force <code>installWow()</code> to always return <code>False</c...
4
2009-07-03T16:30:22Z
[ "python", "iteration" ]
Is there a map without result in python?
1,080,026
<p>Sometimes, I just want to execute a function for a list of entries -- eg.:</p> <pre><code>for x in wowList: installWow(x, 'installed by me') </code></pre> <p>Sometimes I need this stuff for module initialization, so I don't want to have a footprint like x in global namespace. One solution would be to just use m...
15
2009-07-03T16:20:11Z
1,080,054
<p>Every expression evaluates to something, so you always get a result, whichever way you do it. And any such returned object (just like your list) will get thrown away afterwards because there's no reference to it anymore.</p> <p>To clarify: Very few things in python are statements that don't return anything. Even a ...
6
2009-07-03T16:30:39Z
[ "python", "iteration" ]
Is there a map without result in python?
1,080,026
<p>Sometimes, I just want to execute a function for a list of entries -- eg.:</p> <pre><code>for x in wowList: installWow(x, 'installed by me') </code></pre> <p>Sometimes I need this stuff for module initialization, so I don't want to have a footprint like x in global namespace. One solution would be to just use m...
15
2009-07-03T16:20:11Z
1,080,056
<p>You could use a filter and a function that doesn't return a True value. You'd get an empty return list since filter only adds the values which evaluates to true, which I suppose would save you some memory. Something like this:</p> <pre><code>#!/usr/bin/env python y = 0 def myfunction(x): global y y += x input ...
4
2009-07-03T16:32:07Z
[ "python", "iteration" ]
Is there a map without result in python?
1,080,026
<p>Sometimes, I just want to execute a function for a list of entries -- eg.:</p> <pre><code>for x in wowList: installWow(x, 'installed by me') </code></pre> <p>Sometimes I need this stuff for module initialization, so I don't want to have a footprint like x in global namespace. One solution would be to just use m...
15
2009-07-03T16:20:11Z
1,080,100
<p>How about this?</p> <pre><code>for x in wowList: installWow(x, 'installed by me') del x </code></pre>
12
2009-07-03T16:45:26Z
[ "python", "iteration" ]
Is there a map without result in python?
1,080,026
<p>Sometimes, I just want to execute a function for a list of entries -- eg.:</p> <pre><code>for x in wowList: installWow(x, 'installed by me') </code></pre> <p>Sometimes I need this stuff for module initialization, so I don't want to have a footprint like x in global namespace. One solution would be to just use m...
15
2009-07-03T16:20:11Z
1,080,269
<p>if it is ok to distruct wowList</p> <pre><code>while wowList: installWow(wowList.pop(), 'installed by me') </code></pre> <p>if you do want to maintain wowList</p> <pre><code>wowListR = wowList[:] while wowListR: installWow(wowListR.pop(), 'installed by me') </code></pre> <p>and if order matters</p> <pre><code>w...
3
2009-07-03T17:32:31Z
[ "python", "iteration" ]
Is there a map without result in python?
1,080,026
<p>Sometimes, I just want to execute a function for a list of entries -- eg.:</p> <pre><code>for x in wowList: installWow(x, 'installed by me') </code></pre> <p>Sometimes I need this stuff for module initialization, so I don't want to have a footprint like x in global namespace. One solution would be to just use m...
15
2009-07-03T16:20:11Z
1,080,293
<p>I can not resist myself to post it as separate answer</p> <pre><code>reduce(lambda x,y: x(y, 'installed by me') , wowList, installWow) </code></pre> <p>only twist is installWow should return itself e.g.</p> <pre><code>def installWow(*args): print args return installWow </code></pre>
3
2009-07-03T17:41:16Z
[ "python", "iteration" ]
Is there a map without result in python?
1,080,026
<p>Sometimes, I just want to execute a function for a list of entries -- eg.:</p> <pre><code>for x in wowList: installWow(x, 'installed by me') </code></pre> <p>Sometimes I need this stuff for module initialization, so I don't want to have a footprint like x in global namespace. One solution would be to just use m...
15
2009-07-03T16:20:11Z
1,080,300
<p>You could make your own "each" function:</p> <pre> <code> def each(fn, items): for item in items: fn(item) # called thus each(lambda x: installWow(x, 'installed by me'), wowList) </code> </pre> <p>Basically it's just map, but without the results being returned. By using a function you'll ensure that...
20
2009-07-03T17:45:30Z
[ "python", "iteration" ]
Is there a map without result in python?
1,080,026
<p>Sometimes, I just want to execute a function for a list of entries -- eg.:</p> <pre><code>for x in wowList: installWow(x, 'installed by me') </code></pre> <p>Sometimes I need this stuff for module initialization, so I don't want to have a footprint like x in global namespace. One solution would be to just use m...
15
2009-07-03T16:20:11Z
1,080,336
<p>first rewrite the for loop as a generator expression, which does not allocate any memory. </p> <pre><code>(installWow(x, 'installed by me') for x in wowList ) </code></pre> <p>But this expression doesn't actually do anything without finding some way to consume it. So we can rewrite this to yield something deter...
1
2009-07-03T18:00:03Z
[ "python", "iteration" ]
Is there a map without result in python?
1,080,026
<p>Sometimes, I just want to execute a function for a list of entries -- eg.:</p> <pre><code>for x in wowList: installWow(x, 'installed by me') </code></pre> <p>Sometimes I need this stuff for module initialization, so I don't want to have a footprint like x in global namespace. One solution would be to just use m...
15
2009-07-03T16:20:11Z
1,081,326
<p>Just make installWow return None or make the last statement be pass like so:</p> <pre><code> def installWow(item, phrase='installed by me'): print phrase pass </code></pre> <p>and use this:</p> <pre><code> list(x for x in wowList if installWow(x)) </code></pre> <p>x won't be set in the global name space and ...
1
2009-07-04T02:06:00Z
[ "python", "iteration" ]
Is there a map without result in python?
1,080,026
<p>Sometimes, I just want to execute a function for a list of entries -- eg.:</p> <pre><code>for x in wowList: installWow(x, 'installed by me') </code></pre> <p>Sometimes I need this stuff for module initialization, so I don't want to have a footprint like x in global namespace. One solution would be to just use m...
15
2009-07-03T16:20:11Z
15,772,561
<p>I tested several different variants, and here are the results I got.</p> <p>Python 2:</p> <pre><code>&gt;&gt;&gt; timeit.timeit('for x in xrange(100): L.append(x)', 'L = []') 14.9432640076 &gt;&gt;&gt; timeit.timeit('[x for x in xrange(100) if L.append(x) and False]', 'L = []') 16.7011508942 &gt;&gt;&gt; timeit.ti...
0
2013-04-02T19:21:47Z
[ "python", "iteration" ]
Is there a map without result in python?
1,080,026
<p>Sometimes, I just want to execute a function for a list of entries -- eg.:</p> <pre><code>for x in wowList: installWow(x, 'installed by me') </code></pre> <p>Sometimes I need this stuff for module initialization, so I don't want to have a footprint like x in global namespace. One solution would be to just use m...
15
2009-07-03T16:20:11Z
20,845,254
<p>If you're worried about the need to control the return value (which you need to do to use <strong>filter</strong>) and prefer a simpler solution than the <strong>reduce</strong> example above, then consider using <strong>reduce</strong> directly. Your function will need to take an additional first parameter, but you...
1
2013-12-30T18:26:45Z
[ "python", "iteration" ]
Is there a map without result in python?
1,080,026
<p>Sometimes, I just want to execute a function for a list of entries -- eg.:</p> <pre><code>for x in wowList: installWow(x, 'installed by me') </code></pre> <p>Sometimes I need this stuff for module initialization, so I don't want to have a footprint like x in global namespace. One solution would be to just use m...
15
2009-07-03T16:20:11Z
37,399,250
<p>Let me preface this by saying that it seems the original poster was more concerned about namespace clutter than anything else. In that case, you can wrap your working variables in separate function namespace and call it after declaring it, or you can simply remove them from the namespace after you've used them with ...
0
2016-05-23T19:42:50Z
[ "python", "iteration" ]
Handling authentication and proxy servers with httplib2
1,080,179
<p>I'm attempting to test interactions with a Nexus server that requires authentication for the operations I intend to use, but I also need to handle an internal proxy server.</p> <p>Based on my (limited) understanding I can add multiple handlers to the opener. However I'm still getting a 401 response. I've checked th...
2
2009-07-03T17:07:12Z
1,080,236
<p>Can you show the full headers of the 401 response you're getting? Maybe it's not a basic auth request, maybe it's the proxy wanting its own authentication -- it's hard to guess without seeing said headers!</p> <p><strong>Edit</strong>: thanks for showing the headers (I reformatted them as "code" else they were unre...
3
2009-07-03T17:22:58Z
[ "python", "nexus", "httplib2" ]
Cleaning an image to only black
1,080,219
<p>I have an image.</p> <p>I would like to go over that image, pixel by pixel, and any pixel that is not black should be turned to white. How do I do this?</p> <p>(Python).</p> <p>Thanks!</p>
1
2009-07-03T17:17:16Z
1,080,230
<p>You might want to check out the following library:</p> <p><a href="http://effbot.org/imagingbook/image.htm" rel="nofollow">http://effbot.org/imagingbook/image.htm</a></p> <p>Especially:</p> <pre><code>im.getpixel(xy) =&gt; value or tuple </code></pre> <p>and </p> <pre><code>im.putpixel(xy, colour) </code></pre>...
1
2009-07-03T17:20:47Z
[ "python", "image-processing", "python-imaging-library" ]
Cleaning an image to only black
1,080,219
<p>I have an image.</p> <p>I would like to go over that image, pixel by pixel, and any pixel that is not black should be turned to white. How do I do this?</p> <p>(Python).</p> <p>Thanks!</p>
1
2009-07-03T17:17:16Z
1,080,279
<p>The most efficient way is to use the point function</p> <pre><code>def only_black(band): if band &gt; 0: return 255 return 0 result = im.convert('L').point(only_black) </code></pre> <p>This is what the <a href="http://effbot.org/imagingbook/image.htm" rel="nofollow">PIL documentation</a> has to say...
6
2009-07-03T17:36:23Z
[ "python", "image-processing", "python-imaging-library" ]
Cleaning an image to only black
1,080,219
<p>I have an image.</p> <p>I would like to go over that image, pixel by pixel, and any pixel that is not black should be turned to white. How do I do this?</p> <p>(Python).</p> <p>Thanks!</p>
1
2009-07-03T17:17:16Z
1,080,444
<p>You should use the <code>point</code> function, which exists specifically for this reason.</p> <pre><code>converter= ( (0,) + 255*(255,) ).__getitem__ def black_or_white(img): return img.convert('L').point(converter) </code></pre>
3
2009-07-03T18:42:59Z
[ "python", "image-processing", "python-imaging-library" ]
Random list with rules
1,080,393
<p>I'm trying to create a list of tasks that I've read from some text files and put them into lists. I want to create a master list of what I'm going to do through the day however I've got a few rules for this. </p> <p>One list has separate daily tasks that don't depend on the order they are completed. I call this ...
0
2009-07-03T18:23:54Z
1,080,408
<p>Use random.shuffle to shuffle a list</p> <p>random.shuffle(["x", "y", "z"])</p>
1
2009-07-03T18:28:46Z
[ "python", "random" ]
Random list with rules
1,080,393
<p>I'm trying to create a list of tasks that I've read from some text files and put them into lists. I want to create a master list of what I'm going to do through the day however I've got a few rules for this. </p> <p>One list has separate daily tasks that don't depend on the order they are completed. I call this ...
0
2009-07-03T18:23:54Z
1,080,419
<p>How to fetch a random element in a list using python:</p> <pre><code>&gt;&gt;&gt; import random &gt;&gt;&gt; li = ["a", "b", "c"] &gt;&gt;&gt; len = (len(li))-1 &gt;&gt;&gt; ran = random.randint(0, len) &gt;&gt;&gt; ran = li[ran] &gt;&gt;&gt; ran 'b' </code></pre> <p>But it seems you're more curious about how to d...
1
2009-07-03T18:33:52Z
[ "python", "random" ]
Random list with rules
1,080,393
<p>I'm trying to create a list of tasks that I've read from some text files and put them into lists. I want to create a master list of what I'm going to do through the day however I've got a few rules for this. </p> <p>One list has separate daily tasks that don't depend on the order they are completed. I call this ...
0
2009-07-03T18:23:54Z
1,080,422
<p>First, copy and shuffle daily to initialize master:</p> <pre><code>master = list(daily) random.shuffle(master) </code></pre> <p>then (the interesting part!-) the alteration of master (to insert projects randomly but without order changes), and finally <code>random.shuffle(endofday); master.extend(endofday)</code>....
4
2009-07-03T18:36:07Z
[ "python", "random" ]
Random list with rules
1,080,393
<p>I'm trying to create a list of tasks that I've read from some text files and put them into lists. I want to create a master list of what I'm going to do through the day however I've got a few rules for this. </p> <p>One list has separate daily tasks that don't depend on the order they are completed. I call this ...
0
2009-07-03T18:23:54Z
1,080,440
<ol> <li>Combine all 3 lists into a DAG</li> <li>Perform all possible <a href="http://en.wikipedia.org/wiki/Topological%5Fsorting" rel="nofollow">topological sorts</a>, store each sort in a list.</li> <li>Choose one from the list at random</li> </ol>
1
2009-07-03T18:41:21Z
[ "python", "random" ]
Random list with rules
1,080,393
<p>I'm trying to create a list of tasks that I've read from some text files and put them into lists. I want to create a master list of what I'm going to do through the day however I've got a few rules for this. </p> <p>One list has separate daily tasks that don't depend on the order they are completed. I call this ...
0
2009-07-03T18:23:54Z
1,080,460
<p>In order for the elements of the "project" list to stay in order, you could do the following: Say you have 4 project tasks: "a,b,c,d". Then you know there are five spots where other, randomly chosen elements can be inserted (before and after each element, including the beginning and the end), while the ordering natu...
1
2009-07-03T18:48:51Z
[ "python", "random" ]
retrieve links from web page using python and BeautifulSoup
1,080,411
<p>How can I retrieve the links of a webpage and copy the url address of the links using Python?</p>
70
2009-07-03T18:29:56Z
1,080,427
<pre><code>import urllib2 import BeautifulSoup request = urllib2.Request("http://www.gpsbasecamp.com/national-parks") response = urllib2.urlopen(request) soup = BeautifulSoup.BeautifulSoup(response) for a in soup.findAll('a'): if 'national-park' in a['href']: print 'found a url with national-park in the link' </...
25
2009-07-03T18:37:53Z
[ "python", "hyperlink", "beautifulsoup" ]
retrieve links from web page using python and BeautifulSoup
1,080,411
<p>How can I retrieve the links of a webpage and copy the url address of the links using Python?</p>
70
2009-07-03T18:29:56Z
1,080,472
<p>Here's a short snippet using the SoupStrainer class in BeautifulSoup:</p> <pre><code>import httplib2 from BeautifulSoup import BeautifulSoup, SoupStrainer http = httplib2.Http() status, response = http.request('http://www.nytimes.com') for link in BeautifulSoup(response, parseOnlyThese=SoupStrainer('a')): if ...
108
2009-07-03T18:53:55Z
[ "python", "hyperlink", "beautifulsoup" ]
retrieve links from web page using python and BeautifulSoup
1,080,411
<p>How can I retrieve the links of a webpage and copy the url address of the links using Python?</p>
70
2009-07-03T18:29:56Z
1,081,404
<p>just for getting the links, without B.soup and regex:</p> <pre><code>import urllib2 url="http://www.somewhere.com" page=urllib2.urlopen(url) data=page.read().split("&lt;/a&gt;") tag="&lt;a href=\"" endtag="\"&gt;" for item in data: if "&lt;a href" in item: try: ind = item.index(tag) ...
3
2009-07-04T03:11:21Z
[ "python", "hyperlink", "beautifulsoup" ]
retrieve links from web page using python and BeautifulSoup
1,080,411
<p>How can I retrieve the links of a webpage and copy the url address of the links using Python?</p>
70
2009-07-03T18:29:56Z
1,223,008
<p>Others have recommended BeautifulSoup, but it's much better to use <a href="http://lxml.de/index.html">lxml</a>. Despite its name, it is also for parsing and scraping HTML. It's much, much faster than BeautifulSoup, and it even handles "broken" HTML better than BeautifulSoup (their claim to fame). It has a compatibi...
38
2009-08-03T15:34:01Z
[ "python", "hyperlink", "beautifulsoup" ]
retrieve links from web page using python and BeautifulSoup
1,080,411
<p>How can I retrieve the links of a webpage and copy the url address of the links using Python?</p>
70
2009-07-03T18:29:56Z
10,771,090
<p>Why not use regular expressions:</p> <pre><code>import urllib2 import re url = "http://www.somewhere.com" page = urllib2.urlopen(url) page = page.read() links = re.findall(r"&lt;a.*?\s*href=\"(.*?)\".*?&gt;(.*?)&lt;/a&gt;", page) for link in links: print('href: %s, HTML text: %s' % (link[0], link[1])) </code></...
0
2012-05-27T01:49:47Z
[ "python", "hyperlink", "beautifulsoup" ]
retrieve links from web page using python and BeautifulSoup
1,080,411
<p>How can I retrieve the links of a webpage and copy the url address of the links using Python?</p>
70
2009-07-03T18:29:56Z
19,222,808
<p>Under the hood BeautifulSoup now uses lxml. Requests, lxml &amp; list comprehensions makes a killer combo.</p> <pre><code>import requests import lxml.html dom = lxml.html.fromstring(requests.get('http://www.nytimes.com').content) [x for x in dom.xpath('//a/@href') if '//' in x and 'nytimes.com' not in x] </code><...
4
2013-10-07T10:46:27Z
[ "python", "hyperlink", "beautifulsoup" ]
retrieve links from web page using python and BeautifulSoup
1,080,411
<p>How can I retrieve the links of a webpage and copy the url address of the links using Python?</p>
70
2009-07-03T18:29:56Z
21,630,012
<p>The following code is to retrieve all the links available in a webpage using urllib2 and BeautifulSoup4</p> <pre><code> import urllib2 from bs4 import BeautifulSoup url = urllib2.urlopen("http://www.espncricinfo.com/").read() soup = BeautifulSoup(url) for line in soup.find_all('a'): p...
6
2014-02-07T14:17:08Z
[ "python", "hyperlink", "beautifulsoup" ]
retrieve links from web page using python and BeautifulSoup
1,080,411
<p>How can I retrieve the links of a webpage and copy the url address of the links using Python?</p>
70
2009-07-03T18:29:56Z
22,583,436
<p>For completeness sake, the BeautifulSoup 4 version, making use of the encoding supplied by the server as well:</p> <pre><code>from bs4 import BeautifulSoup import urllib2 resp = urllib2.urlopen("http://www.gpsbasecamp.com/national-parks") soup = BeautifulSoup(resp, from_encoding=resp.info().getparam('charset')) f...
23
2014-03-22T20:52:44Z
[ "python", "hyperlink", "beautifulsoup" ]
retrieve links from web page using python and BeautifulSoup
1,080,411
<p>How can I retrieve the links of a webpage and copy the url address of the links using Python?</p>
70
2009-07-03T18:29:56Z
25,673,146
<pre><code>import urllib2 from bs4 import BeautifulSoup a=urllib2.urlopen('http://dir.yahoo.com') code=a.read() soup=BeautifulSoup(code) links=soup.findAll("a") #To get href part alone print links[0].attrs['href'] </code></pre>
0
2014-09-04T19:00:16Z
[ "python", "hyperlink", "beautifulsoup" ]
retrieve links from web page using python and BeautifulSoup
1,080,411
<p>How can I retrieve the links of a webpage and copy the url address of the links using Python?</p>
70
2009-07-03T18:29:56Z
28,076,861
<p>This script does what your looking for, But also resolves the relative links to absolute links.</p> <pre><code>import urllib import lxml.html import urlparse def get_dom(url): connection = urllib.urlopen(url) return lxml.html.fromstring(connection.read()) def get_links(url): return resolve_links((link...
2
2015-01-21T21:10:19Z
[ "python", "hyperlink", "beautifulsoup" ]
retrieve links from web page using python and BeautifulSoup
1,080,411
<p>How can I retrieve the links of a webpage and copy the url address of the links using Python?</p>
70
2009-07-03T18:29:56Z
31,846,278
<p><strong><em>To find all the links, we will in this example use the urllib2 module together with the re.module</em></strong> *One of the most powerful function in the re module is "re.findall()". While re.search() is used to find the first match for a pattern, re.findall() finds <em>all</em> the matches and returns t...
3
2015-08-06T03:22:40Z
[ "python", "hyperlink", "beautifulsoup" ]
retrieve links from web page using python and BeautifulSoup
1,080,411
<p>How can I retrieve the links of a webpage and copy the url address of the links using Python?</p>
70
2009-07-03T18:29:56Z
37,758,066
<p>BeatifulSoup's own parser can be slow. It might be more feasible to use <strong>lxml</strong> which capable of parsing directly from a URL (with limitations).</p> <pre class="lang-python prettyprint-override"><code>import lxml.html doc = lxml.html.parse(url) links = doc.xpath('//a[@href]') for link in links: ...
0
2016-06-10T22:38:00Z
[ "python", "hyperlink", "beautifulsoup" ]
retrieve links from web page using python and BeautifulSoup
1,080,411
<p>How can I retrieve the links of a webpage and copy the url address of the links using Python?</p>
70
2009-07-03T18:29:56Z
38,314,240
<p>Here's an example using @ars accepted answer and the <code>BeautifulSoup4</code>, <code>requests</code>, and <code>wget</code> modules to handle the downloads.</p> <pre><code>import requests import wget import os from bs4 import BeautifulSoup, SoupStrainer url = 'https://archive.ics.uci.edu/ml/machine-learning-da...
0
2016-07-11T18:58:08Z
[ "python", "hyperlink", "beautifulsoup" ]
How to reload a Python module that was imported in another file?
1,080,521
<p>I am trying to learn how Python reloads modules, but have hit a roadblock. Let's say I have:</p> <p><code>dir1\file1.py</code>:</p> <pre><code>from dir2.file2 import ClassOne myObject = ClassOne() </code></pre> <p><code>dir1\dir2\file2.py</code>:</p> <pre><code>class ClassOne(): def reload_module(): re...
2
2009-07-03T19:13:42Z
1,080,534
<pre><code> def reload_module(): import file2 reload(file2) </code></pre> <p>However, this will <em>not</em> per se change the type of objects you've instantiated from classes held in the previous version of file2. The Python Cookbook 2nd edition has a recipe on how to accomplish such feats, and it's f...
3
2009-07-03T19:17:59Z
[ "python", "import", "module", "reload" ]
Removing the Label From Django's TextArea Widget
1,080,650
<p>How do I remove the label that comes attached to the TextArea I am trying to use with Django? I'm trying to find ANY information about this issue but I cannot seem to find anything relating to my problem. This is what I'm doing in my code:</p> <pre><code>class CommentForm(forms.Form): comment = forms.CharField(...
5
2009-07-03T19:57:55Z
1,080,735
<p>This should work with the latest version (trunk) of django:</p> <pre><code>comment = forms.CharField(label="", help_text="", widget=forms.Textarea()) </code></pre> <p>Hope that helps!</p>
19
2009-07-03T20:30:22Z
[ "python", "django", "textarea", "label", "widget" ]
Removing the Label From Django's TextArea Widget
1,080,650
<p>How do I remove the label that comes attached to the TextArea I am trying to use with Django? I'm trying to find ANY information about this issue but I cannot seem to find anything relating to my problem. This is what I'm doing in my code:</p> <pre><code>class CommentForm(forms.Form): comment = forms.CharField(...
5
2009-07-03T19:57:55Z
1,080,736
<p>The <a href="http://docs.djangoproject.com/en/dev/ref/forms/api/#ref-forms-api-configuring-label">Django documentation on customizing labels</a> says it could be turned off with <code>auto_id</code> argument to Form constructor:</p> <pre><code>f = ContactForm(auto_id=False) </code></pre>
8
2009-07-03T20:30:33Z
[ "python", "django", "textarea", "label", "widget" ]
Removing the Label From Django's TextArea Widget
1,080,650
<p>How do I remove the label that comes attached to the TextArea I am trying to use with Django? I'm trying to find ANY information about this issue but I cannot seem to find anything relating to my problem. This is what I'm doing in my code:</p> <pre><code>class CommentForm(forms.Form): comment = forms.CharField(...
5
2009-07-03T19:57:55Z
1,080,797
<p>A quick-and-dirty solution would be to iterate through the form manualy (with {% for field in form %}) and handle the "problematic" field specially. You could also override the as_p/as_table methods if needed. </p>
0
2009-07-03T20:55:07Z
[ "python", "django", "textarea", "label", "widget" ]
Removing the Label From Django's TextArea Widget
1,080,650
<p>How do I remove the label that comes attached to the TextArea I am trying to use with Django? I'm trying to find ANY information about this issue but I cannot seem to find anything relating to my problem. This is what I'm doing in my code:</p> <pre><code>class CommentForm(forms.Form): comment = forms.CharField(...
5
2009-07-03T19:57:55Z
25,619,766
<p>Try this in your form:</p> <pre><code>def __init__(self, *args, **kwargs): self.fields['comment'].label = '' </code></pre> <p>But for newer versions of django i prefer Iemonad's answer</p>
0
2014-09-02T09:09:33Z
[ "python", "django", "textarea", "label", "widget" ]
In Python, how do you change an instantiated object after a reload?
1,080,669
<p>Let's say you have an object that was instantiated from a class inside a module. Now, you reload that module. The next thing you'd like to do is make that reload affect that class.</p> <pre><code>mymodule.py --- class ClassChange(): def run(self): print 'one' myexperiment.py --- import mymodule from my...
12
2009-07-03T20:03:07Z
1,080,676
<p>You have to make a new object. There's no way to magically update the existing objects.</p> <p>Read the <a href="http://docs.python.org/library/functions.html#reload"><code>reload</code> builtin documentation</a> - it is very clear. Here's the last paragraph:</p> <blockquote> <p><em>If a module instantiates inst...
5
2009-07-03T20:04:49Z
[ "python", "module", "reload", "python-import" ]
In Python, how do you change an instantiated object after a reload?
1,080,669
<p>Let's say you have an object that was instantiated from a class inside a module. Now, you reload that module. The next thing you'd like to do is make that reload affect that class.</p> <pre><code>mymodule.py --- class ClassChange(): def run(self): print 'one' myexperiment.py --- import mymodule from my...
12
2009-07-03T20:03:07Z
1,080,724
<p>The following code does what you want, but <strong>please don't use it</strong> (at least not until you're very sure you're doing the right thing), <strong>I'm posting it for explanation purposes only</strong>.</p> <p>mymodule.py:</p> <pre><code>class ClassChange(): @classmethod def run(cls,instance): ...
2
2009-07-03T20:24:14Z
[ "python", "module", "reload", "python-import" ]
In Python, how do you change an instantiated object after a reload?
1,080,669
<p>Let's say you have an object that was instantiated from a class inside a module. Now, you reload that module. The next thing you'd like to do is make that reload affect that class.</p> <pre><code>mymodule.py --- class ClassChange(): def run(self): print 'one' myexperiment.py --- import mymodule from my...
12
2009-07-03T20:03:07Z
1,080,729
<p>I'm not sure if this is the best way to do it, or meshes with what you want to do... but this may work for you. If you want to change the behavior of a method, for all objects of a certain type... just use a function variable. For example:</p> <pre><code> def default_behavior(the_object): print "one" def some_ot...
1
2009-07-03T20:26:21Z
[ "python", "module", "reload", "python-import" ]
In Python, how do you change an instantiated object after a reload?
1,080,669
<p>Let's say you have an object that was instantiated from a class inside a module. Now, you reload that module. The next thing you'd like to do is make that reload affect that class.</p> <pre><code>mymodule.py --- class ClassChange(): def run(self): print 'one' myexperiment.py --- import mymodule from my...
12
2009-07-03T20:03:07Z
1,080,984
<p>To update all instances of a class, it is necessary to keep track somewhere about those instances -- typically via weak references (weak value dict is handiest and general) so the "keeping track" functionality won't stop unneeded instances from going away, of course!</p> <p>You'd normally want to keep such a contai...
12
2009-07-03T21:59:27Z
[ "python", "module", "reload", "python-import" ]
In Python, how do you change an instantiated object after a reload?
1,080,669
<p>Let's say you have an object that was instantiated from a class inside a module. Now, you reload that module. The next thing you'd like to do is make that reload affect that class.</p> <pre><code>mymodule.py --- class ClassChange(): def run(self): print 'one' myexperiment.py --- import mymodule from my...
12
2009-07-03T20:03:07Z
1,081,298
<p>There are tricks to make what you want possible.</p> <p>Someone already mentioned that you can have a class that keeps a list of its instances, and then changing the class of each instance to the new one upon reload.</p> <p>However, that is not efficient. A better method is to change the old class so that it is th...
1
2009-07-04T01:38:04Z
[ "python", "module", "reload", "python-import" ]
In Python, how do you change an instantiated object after a reload?
1,080,669
<p>Let's say you have an object that was instantiated from a class inside a module. Now, you reload that module. The next thing you'd like to do is make that reload affect that class.</p> <pre><code>mymodule.py --- class ClassChange(): def run(self): print 'one' myexperiment.py --- import mymodule from my...
12
2009-07-03T20:03:07Z
10,002,039
<p>My approach to this is the following:</p> <ol> <li>Look through all imported modules and reload only those with a new .py file (as compared to the existing .pyc file)</li> <li>For every function and class method that is reloaded, set old_function.__code__ = new_function.__code__. </li> <li>For every reloaded class,...
4
2012-04-03T21:58:55Z
[ "python", "module", "reload", "python-import" ]
In Python, how do you change an instantiated object after a reload?
1,080,669
<p>Let's say you have an object that was instantiated from a class inside a module. Now, you reload that module. The next thing you'd like to do is make that reload affect that class.</p> <pre><code>mymodule.py --- class ClassChange(): def run(self): print 'one' myexperiment.py --- import mymodule from my...
12
2009-07-03T20:03:07Z
15,839,610
<p>You have to get the new class from the fresh module and assign it back to the instance.</p> <p>If you could trigger this operation anytime you use an instance with this mixin:</p> <pre><code>import sys class ObjDebug(object): def __getattribute__(self,k): ga=object.__getattribute__ sa=object.__setattr__...
2
2013-04-05T17:09:14Z
[ "python", "module", "reload", "python-import" ]
screenshot an application in python, regardless of what's in front of it
1,080,719
<p>So I can use PIL to grab a screenshot of the desktop, and then use pywin32 to get its rectangle and crop out the part I want. However, if there's something in front of the window I want, it'll occlude the application I wanted a screenshot of. Is there any way to get what windows would say an application is currently...
4
2009-07-03T20:22:58Z
1,080,733
<p>IIRC, not in Windows pre-vista - with Aero each window has it's own buffer, but before that, you would just use your method, of getting the rectangle. I'm not sure if pywin32 has Aero support or not.</p>
0
2009-07-03T20:28:31Z
[ "python", "windows", "screenshot" ]
screenshot an application in python, regardless of what's in front of it
1,080,719
<p>So I can use PIL to grab a screenshot of the desktop, and then use pywin32 to get its rectangle and crop out the part I want. However, if there's something in front of the window I want, it'll occlude the application I wanted a screenshot of. Is there any way to get what windows would say an application is currently...
4
2009-07-03T20:22:58Z
1,080,741
<p>If you can, try saving the order of the windows, then move your app to the front, screenshot, and move it back really quickly. Might produce a bit of annoying flicker, but it might be better than nothing.</p>
1
2009-07-03T20:33:26Z
[ "python", "windows", "screenshot" ]
screenshot an application in python, regardless of what's in front of it
1,080,719
<p>So I can use PIL to grab a screenshot of the desktop, and then use pywin32 to get its rectangle and crop out the part I want. However, if there's something in front of the window I want, it'll occlude the application I wanted a screenshot of. Is there any way to get what windows would say an application is currently...
4
2009-07-03T20:22:58Z
1,080,847
<p>I've done the same thing by giving the application I want focus before taking the shot:</p> <pre><code>shell=win32com.client.Dispatch("Wscript.Shell") success = shell.AppActivate(app_name) # Returns true if focus given successfully. </code></pre>
3
2009-07-03T21:13:01Z
[ "python", "windows", "screenshot" ]
screenshot an application in python, regardless of what's in front of it
1,080,719
<p>So I can use PIL to grab a screenshot of the desktop, and then use pywin32 to get its rectangle and crop out the part I want. However, if there's something in front of the window I want, it'll occlude the application I wanted a screenshot of. Is there any way to get what windows would say an application is currently...
4
2009-07-03T20:22:58Z
1,270,114
<p>Maybe you can position the app offscreen, then take the screenshot, then put it back?</p>
1
2009-08-13T05:03:47Z
[ "python", "windows", "screenshot" ]
screenshot an application in python, regardless of what's in front of it
1,080,719
<p>So I can use PIL to grab a screenshot of the desktop, and then use pywin32 to get its rectangle and crop out the part I want. However, if there's something in front of the window I want, it'll occlude the application I wanted a screenshot of. Is there any way to get what windows would say an application is currently...
4
2009-07-03T20:22:58Z
3,586,035
<p>There is a way to do this, using the <code>PrintWindow</code> function. It causes the window to redraw itself on another surface.</p>
2
2010-08-27T16:01:46Z
[ "python", "windows", "screenshot" ]
screenshot an application in python, regardless of what's in front of it
1,080,719
<p>So I can use PIL to grab a screenshot of the desktop, and then use pywin32 to get its rectangle and crop out the part I want. However, if there's something in front of the window I want, it'll occlude the application I wanted a screenshot of. Is there any way to get what windows would say an application is currently...
4
2009-07-03T20:22:58Z
24,353,857
<p>I posted working code in the answer here: <a href="https://stackoverflow.com/questions/19695214/python-screenshot-of-inactive-window-printwindow-win32gui/24352388#24352388">Python Screenshot of inactive window</a>. It uses the <code>PrintWindow</code> function. This is the "correct" way to copy the image of a hidden...
1
2014-06-22T17:33:40Z
[ "python", "windows", "screenshot" ]
Changes to Python since Dive into Python
1,080,734
<p>I've been teaching myself Python by working through <a href="http://www.diveintopython.net/">Dive Into Python</a> by Mark Pilgrim. I thoroughly recommend it, as do <a href="http://stackoverflow.com/questions/34570/what-is-the-best-quick-read-python-book-out-there/34608#34608">other Stack Overflow users</a>.</p> <p>...
12
2009-07-03T20:28:33Z
1,080,763
<p>I suggest that you read the “what's in Python 2.x?” documents. Some things that may have missed:</p> <ul> <li>New-style classes (allows standard types subtyping, properties, ...).</li> <li>The <code>with</code> keyword, which helps allocating and releasing resources.</li> </ul>
0
2009-07-03T20:42:06Z
[ "python" ]
Changes to Python since Dive into Python
1,080,734
<p>I've been teaching myself Python by working through <a href="http://www.diveintopython.net/">Dive Into Python</a> by Mark Pilgrim. I thoroughly recommend it, as do <a href="http://stackoverflow.com/questions/34570/what-is-the-best-quick-read-python-book-out-there/34608#34608">other Stack Overflow users</a>.</p> <p>...
12
2009-07-03T20:28:33Z
1,081,056
<p>Mark(author of the book) had <a href="http://www.reddit.com/r/Python/comments/8miar/im%5Fnew%5Fto%5Fpython%5Fshould%5Fi%5Fread%5Fdive%5Finto%5Fpython%5F3/c09s45y">some comments</a> on this. I've shamelessly copied the related paragraph here:<br /> """If you choose Python 2, I can only recommend "Dive Into Python" ch...
6
2009-07-03T22:42:56Z
[ "python" ]
Changes to Python since Dive into Python
1,080,734
<p>I've been teaching myself Python by working through <a href="http://www.diveintopython.net/">Dive Into Python</a> by Mark Pilgrim. I thoroughly recommend it, as do <a href="http://stackoverflow.com/questions/34570/what-is-the-best-quick-read-python-book-out-there/34608#34608">other Stack Overflow users</a>.</p> <p>...
12
2009-07-03T20:28:33Z
1,081,188
<p>Here's a couple of examples of the sort of answer I was thinking of:</p> <h3>Conditional Expressions</h3> <p>Instead of the <a href="http://www.diveintopython.net/power_of_introspection/and_or.html#d0e9975" rel="nofollow">and-or trick</a>, 2.5 offers a new way to write <a href="http://docs.python.org/whatsnew/2.5....
3
2009-07-04T00:19:26Z
[ "python" ]
Changes to Python since Dive into Python
1,080,734
<p>I've been teaching myself Python by working through <a href="http://www.diveintopython.net/">Dive Into Python</a> by Mark Pilgrim. I thoroughly recommend it, as do <a href="http://stackoverflow.com/questions/34570/what-is-the-best-quick-read-python-book-out-there/34608#34608">other Stack Overflow users</a>.</p> <p>...
12
2009-07-03T20:28:33Z
1,081,252
<p>Check out <a href="http://docs.python.org/whatsnew/">What's New in Python</a>. It has all the versions in the 2.x series. Per Alex's comments, you'll want to look at all Python 2.x for x > 2.</p> <p>Highlights for day-to-day coding:</p> <p><em>Enumeration</em>: Instead of doing:</p> <pre><code>for i in xrange(len...
9
2009-07-04T01:02:12Z
[ "python" ]
Changes to Python since Dive into Python
1,080,734
<p>I've been teaching myself Python by working through <a href="http://www.diveintopython.net/">Dive Into Python</a> by Mark Pilgrim. I thoroughly recommend it, as do <a href="http://stackoverflow.com/questions/34570/what-is-the-best-quick-read-python-book-out-there/34608#34608">other Stack Overflow users</a>.</p> <p>...
12
2009-07-03T20:28:33Z
1,081,361
<p>A few "minor" features were added in 2.4 and are pervasive in new 2.x python code: decorator (2.4) and try/except/finally clauses. Before you could not do:</p> <pre><code>try: do_something() except FunkyException: handle_exception(): finally: clean_up() </code></pre> <p>Both are essentially syntactic s...
2
2009-07-04T02:33:06Z
[ "python" ]
Changes to Python since Dive into Python
1,080,734
<p>I've been teaching myself Python by working through <a href="http://www.diveintopython.net/">Dive Into Python</a> by Mark Pilgrim. I thoroughly recommend it, as do <a href="http://stackoverflow.com/questions/34570/what-is-the-best-quick-read-python-book-out-there/34608#34608">other Stack Overflow users</a>.</p> <p>...
12
2009-07-03T20:28:33Z
1,081,367
<pre><code>import antigravity </code></pre> <p><a href="http://imgs.xkcd.com/comics/python.png" rel="nofollow">See the documentation</a></p>
1
2009-07-04T02:36:22Z
[ "python" ]
How Do I Remove Text From Generated Django Form?
1,080,828
<p>So earlier I asked a question about removing the label that Django forms have by default. That worked out great, and I removed the label. However, the text that is generated by the form is still there! I would very much like to remove the text. Here is what I mean:</p> <pre><code>&lt;p&gt;Text: &lt;textarea rows="1...
1
2009-07-03T21:06:16Z
1,080,853
<p>Have you tried:</p> <pre><code>class CommentForm(forms.Form): comment = forms.CharField(widget=forms.Textarea(), label=None) </code></pre> <p>?</p>
1
2009-07-03T21:13:52Z
[ "python", "django", "forms", "textarea" ]
How Do I Remove Text From Generated Django Form?
1,080,828
<p>So earlier I asked a question about removing the label that Django forms have by default. That worked out great, and I removed the label. However, the text that is generated by the form is still there! I would very much like to remove the text. Here is what I mean:</p> <pre><code>&lt;p&gt;Text: &lt;textarea rows="1...
1
2009-07-03T21:06:16Z
1,080,882
<p>Try:</p> <pre><code>class CommentForm(forms.Form): comment = forms.CharField(widget=forms.Textarea(), help_text="") </code></pre>
0
2009-07-03T21:21:08Z
[ "python", "django", "forms", "textarea" ]
How Do I Remove Text From Generated Django Form?
1,080,828
<p>So earlier I asked a question about removing the label that Django forms have by default. That worked out great, and I removed the label. However, the text that is generated by the form is still there! I would very much like to remove the text. Here is what I mean:</p> <pre><code>&lt;p&gt;Text: &lt;textarea rows="1...
1
2009-07-03T21:06:16Z
1,081,150
<p>The answer:</p> <pre><code>class CommentForm(forms.Form): comment = forms.CharField(widget=forms.Textarea(), label='') </code></pre> <p>Also, no auto_id in the constructor when creating the object, it should be left as:</p> <pre><code>comment = new CommentForm() </code></pre>
4
2009-07-03T23:49:54Z
[ "python", "django", "forms", "textarea" ]
Accessing Python Objects in a Core Dump
1,080,832
<p>Is there anyway to discover the python value of a PyObject* from a corefile in gdb</p>
2
2009-07-03T21:07:30Z
1,080,869
<p>It's lots of work, but of course it can be done, especially if you have all the symbols. Look at the header files for the specific version of Python (and compilation options in use to build it): they define PyObject as a struct which includes, first and foremost, a pointer to a type. Lots of macros are used, so you ...
4
2009-07-03T21:18:06Z
[ "python", "python-c-api", "postmortem-debugging" ]
Implementing a custom Python authentication handler
1,080,920
<p>The answer to a <a href="http://stackoverflow.com/questions/1080179/handling-authentication-and-proxy-servers-with-httplib2">previous question</a> showed that Nexus implement a <a href="http://svn.sonatype.org/nexus/tags/nexus-1.3.4/nexus-clients/nexus-rest-client-java/src/main/java/org/sonatype/nexus/client/rest/Ht...
3
2009-07-03T21:35:58Z
1,084,522
<p>If, as described, name and description are the only differences between this "NxBasic" and good old "Basic", then you could essentially copy-paste-edit some code from urllib2.py (which unfortunately doesn't expose the scheme name as easily overridable in itself), as follows (see <a href="http://svn.python.org/view/p...
1
2009-07-05T17:55:26Z
[ "python", "restlet", "nexus", "httplib2" ]
Decompile .swf file to get images in python
1,081,183
<p>I would like to decompile a .swf file and get all the images from it, in python.</p> <p>Are there any libraries that do this?</p>
8
2009-07-04T00:15:11Z
1,081,195
<p>I don't think there are any libraries available for python, but maybe you can have an offline process to decompile swf using <a href="http://www.sothink.com/product/flashdecompiler/" rel="nofollow">sothink flash decompiler</a> Also I did not come across any decompiler so far that is 100% accurate.</p>
2
2009-07-04T00:24:59Z
[ "python", "flash" ]
Decompile .swf file to get images in python
1,081,183
<p>I would like to decompile a .swf file and get all the images from it, in python.</p> <p>Are there any libraries that do this?</p>
8
2009-07-04T00:15:11Z
1,081,288
<p>There are no public swf decompiler libraries for Python.</p> <p>Use a 3rd party program and the Python <a href="http://docs.python.org/library/subprocess.html" rel="nofollow">subprocess module</a> to execute it.</p>
2
2009-07-04T01:28:22Z
[ "python", "flash" ]
Decompile .swf file to get images in python
1,081,183
<p>I would like to decompile a .swf file and get all the images from it, in python.</p> <p>Are there any libraries that do this?</p>
8
2009-07-04T00:15:11Z
1,081,290
<p>The SWFTools distribution has a command line program, SWFExtract, that can do this. You could call that from python to do what you want:</p> <p><a href="http://www.swftools.org/">http://www.swftools.org/</a></p> <p><a href="http://www.swftools.org/swfextract.html">http://www.swftools.org/swfextract.html</a></p>
6
2009-07-04T01:31:22Z
[ "python", "flash" ]
Inheriting from instance in Python
1,081,253
<p>In Python, I would like to construct an instance of the Child's class directly from an instance of the Parent class. For example:</p> <pre><code>A = Parent(x, y, z) B = Child(A) </code></pre> <p>This is a hack that I thought might work:</p> <pre><code>class Parent(object): def __init__(self, x, y, z): ...
8
2009-07-04T01:02:45Z
1,081,271
<p>Once <code>__new__</code> in class <code>Child</code> returns an instance of <code>Child</code>, <code>Child.__init__</code> will be called (with the same arguments <code>__new__</code> was given) on that instance -- and apparently it just inherits <code>Parent.__init__</code>, which does not take well to being call...
7
2009-07-04T01:11:01Z
[ "python", "inheritance", "instance", "overloading" ]
Inheriting from instance in Python
1,081,253
<p>In Python, I would like to construct an instance of the Child's class directly from an instance of the Parent class. For example:</p> <pre><code>A = Parent(x, y, z) B = Child(A) </code></pre> <p>This is a hack that I thought might work:</p> <pre><code>class Parent(object): def __init__(self, x, y, z): ...
8
2009-07-04T01:02:45Z
1,081,280
<p>You don't define a constructor (init) for Child, so the Parent constructor is called, expecting 4 arguments while only 2 are passed in (from new). Here's one way to accomplish what you want:</p> <pre><code>class Child(Parent): def __init__(self, *args, **kwargs): if len(args) == 1 and isinstance(args[0...
3
2009-07-04T01:18:16Z
[ "python", "inheritance", "instance", "overloading" ]
Inheriting from instance in Python
1,081,253
<p>In Python, I would like to construct an instance of the Child's class directly from an instance of the Parent class. For example:</p> <pre><code>A = Parent(x, y, z) B = Child(A) </code></pre> <p>This is a hack that I thought might work:</p> <pre><code>class Parent(object): def __init__(self, x, y, z): ...
8
2009-07-04T01:02:45Z
1,081,295
<p>Thanks, guys, that was quick! I first read Alex's comment and I rewrote the Child's <code>__init__</code> as</p> <pre><code>def __init__(self, *args, **kwds): if len(args) == 1 and str(type(args[0])) == "&lt;class '__main__.Parent'&gt;": new_args = [args[0].x, args[0].y, args[0].z] super(Child, ...
0
2009-07-04T01:37:25Z
[ "python", "inheritance", "instance", "overloading" ]
Inheriting from instance in Python
1,081,253
<p>In Python, I would like to construct an instance of the Child's class directly from an instance of the Parent class. For example:</p> <pre><code>A = Parent(x, y, z) B = Child(A) </code></pre> <p>This is a hack that I thought might work:</p> <pre><code>class Parent(object): def __init__(self, x, y, z): ...
8
2009-07-04T01:02:45Z
1,081,925
<p>OK, so I didn't realize that you where happy with a static copy of the arguments until I was already halfway done with my solution. But I decided not to waste it, so here it is anyway. The difference from the other solutions is that it will actually get the attributes from the parent even if they updated.</p> <pre>...
3
2009-07-04T10:12:09Z
[ "python", "inheritance", "instance", "overloading" ]
Inheriting from instance in Python
1,081,253
<p>In Python, I would like to construct an instance of the Child's class directly from an instance of the Parent class. For example:</p> <pre><code>A = Parent(x, y, z) B = Child(A) </code></pre> <p>This is a hack that I thought might work:</p> <pre><code>class Parent(object): def __init__(self, x, y, z): ...
8
2009-07-04T01:02:45Z
11,974,673
<p>I know this is an extremely old thread, but I recently ran into the same challenge as Alexandra, and this was the most relavent topic I could find. I had a parent class with many, many attributes, and I wanted to essentially 'patch' an instance of it, by keeping all of its methods and attributes, adding a few, and m...
1
2012-08-15T18:09:21Z
[ "python", "inheritance", "instance", "overloading" ]
Inheriting from instance in Python
1,081,253
<p>In Python, I would like to construct an instance of the Child's class directly from an instance of the Parent class. For example:</p> <pre><code>A = Parent(x, y, z) B = Child(A) </code></pre> <p>This is a hack that I thought might work:</p> <pre><code>class Parent(object): def __init__(self, x, y, z): ...
8
2009-07-04T01:02:45Z
14,182,553
<p>I find this (encapsulation) to be the cleanest way:</p> <pre><code>class Child(object): def __init__(self): self.obj = Parent() def __getattr__(self, attr): return getattr(self.obj, attr) </code></pre> <p>This way you can use all Parent's method and your own without running into the proble...
1
2013-01-06T13:22:56Z
[ "python", "inheritance", "instance", "overloading" ]
How do you do something after you render the view? (Django)
1,081,340
<p>I want to do something after I have rendered the view using </p> <pre><code>return render_to_response() </code></pre> <p>Are signals the only way to do this? Do I need to write a custom signal or does request_finished give me enough information? Basically I need to know what page was rendered, and then do an actio...
6
2009-07-04T02:16:36Z
1,081,352
<p>In render to response, you pass the html page that you want displayed. That other page needs to send a post (via Javascript or something) that triggers the correct function in your views, then that view calls the correct next page to be shown.</p>
-1
2009-07-04T02:28:08Z
[ "python", "django" ]
How do you do something after you render the view? (Django)
1,081,340
<p>I want to do something after I have rendered the view using </p> <pre><code>return render_to_response() </code></pre> <p>Are signals the only way to do this? Do I need to write a custom signal or does request_finished give me enough information? Basically I need to know what page was rendered, and then do an actio...
6
2009-07-04T02:16:36Z
1,081,376
<p>If you have a long-running process, you have two simple choices.</p> <ol> <li><p>Spawn a subprocess prior to sending the response page.</p></li> <li><p>Create a "background service daemon" and pass work requests to it.</p></li> </ol> <p>This is all outside Django. You use <a href="http://docs.python.org/library/s...
3
2009-07-04T02:41:31Z
[ "python", "django" ]
How do you do something after you render the view? (Django)
1,081,340
<p>I want to do something after I have rendered the view using </p> <pre><code>return render_to_response() </code></pre> <p>Are signals the only way to do this? Do I need to write a custom signal or does request_finished give me enough information? Basically I need to know what page was rendered, and then do an actio...
6
2009-07-04T02:16:36Z
1,081,441
<p>A common way to do this is to use message queues. You place a message on the queue, and worker threads (or processes, etc.) consume the queue and do the work after your view has completed.</p> <p>Google App Engine has the task queue api <a href="http://code.google.com/appengine/docs/python/taskqueue/" rel="nofollo...
4
2009-07-04T03:44:31Z
[ "python", "django" ]
How do you do something after you render the view? (Django)
1,081,340
<p>I want to do something after I have rendered the view using </p> <pre><code>return render_to_response() </code></pre> <p>Are signals the only way to do this? Do I need to write a custom signal or does request_finished give me enough information? Basically I need to know what page was rendered, and then do an actio...
6
2009-07-04T02:16:36Z
1,081,766
<p>Django's HttpResponse object accepts an iterator in its constructor:</p> <p><a href="http://docs.djangoproject.com/en/dev/ref/request-response/#passing-iterators" rel="nofollow">http://docs.djangoproject.com/en/dev/ref/request-response/#passing-iterators</a></p> <p>So you could do something like:</p> <pre><code>d...
4
2009-07-04T07:57:28Z
[ "python", "django" ]
How do you do something after you render the view? (Django)
1,081,340
<p>I want to do something after I have rendered the view using </p> <pre><code>return render_to_response() </code></pre> <p>Are signals the only way to do this? Do I need to write a custom signal or does request_finished give me enough information? Basically I need to know what page was rendered, and then do an actio...
6
2009-07-04T02:16:36Z
1,081,935
<p>My favourite solution: A separate process that handles background tasks, typically things like indexing and sending notification mails etc. And then, during the view rendering, you send an event to the event handling system (I don't know if Django has one built in, but you always need one anyway so you should have o...
2
2009-07-04T10:16:44Z
[ "python", "django" ]
How do you do something after you render the view? (Django)
1,081,340
<p>I want to do something after I have rendered the view using </p> <pre><code>return render_to_response() </code></pre> <p>Are signals the only way to do this? Do I need to write a custom signal or does request_finished give me enough information? Basically I need to know what page was rendered, and then do an actio...
6
2009-07-04T02:16:36Z
1,082,785
<p>You spawn a separate thread and have it do the action.</p> <pre><code>t = threading.Thread(target=do_my_action, args=[my_argument]) # We want the program to wait on this thread before shutting down. t.setDaemon(False) t.start() </code></pre> <p>This will cause 'do_my_action(my_argument)' to be executed in a second...
6
2009-07-04T18:55:11Z
[ "python", "django" ]
How do you do something after you render the view? (Django)
1,081,340
<p>I want to do something after I have rendered the view using </p> <pre><code>return render_to_response() </code></pre> <p>Are signals the only way to do this? Do I need to write a custom signal or does request_finished give me enough information? Basically I need to know what page was rendered, and then do an actio...
6
2009-07-04T02:16:36Z
1,082,905
<p>Perhaps I do not understand your question. But why not something simple like:</p> <pre><code>try: return render_to_response() finally: do_what_needs_to_be_done() </code></pre>
0
2009-07-04T20:16:58Z
[ "python", "django" ]
How can I report the API of a class programmatically?
1,081,392
<p>My goal is to parse a class and return a data-structure (object, dictionary, etc) that is descriptive of the methods and the related parameters contained within the class. Bonus points for types and returns...</p> <p>Requirements: Must be Python</p> <p>For example, the below class:</p> <pre><code>class Foo: ...
4
2009-07-04T02:59:38Z
1,081,395
<p>You probably want to check out Python's <a href="http://docs.python.org/library/inspect.html#inspect.getmembers" rel="nofollow">inspect</a> module. It will get you most of the way there:</p> <pre><code>&gt;&gt;&gt; class Foo: ... def bar(hello=None): ... return hello ... def baz(world=None): ... ...
8
2009-07-04T03:03:39Z
[ "python", "api" ]
python tab completion in windows
1,081,405
<p>I'm writing a cross-platform shell like program in python and I'd like to add custom tab-completion actions. On Unix systems I can use the built-in readline module and use code like the following to specify a list of possible completions when I hit the TAB key:</p> <pre><code>import readline readline.parse_and_bind...
5
2009-07-04T03:11:37Z
1,081,416
<p>Do u have a look at <a href="http://ipython.scipy.org/moin/PyReadline/Intro" rel="nofollow">PyReadline: a ctypes-based readline for Windows</a>? Although 3rd-party packages is NOT your option, maybe it's useful for build one's own, isn't it:).</p>
2
2009-07-04T03:19:09Z
[ "python", "windows", "readline", "tab-completion" ]
python tab completion in windows
1,081,405
<p>I'm writing a cross-platform shell like program in python and I'd like to add custom tab-completion actions. On Unix systems I can use the built-in readline module and use code like the following to specify a list of possible completions when I hit the TAB key:</p> <pre><code>import readline readline.parse_and_bind...
5
2009-07-04T03:11:37Z
1,081,586
<p>you could look at how <a href="http://ipython.scipy.org/" rel="nofollow">ipython</a> does it with pyreadline as well, maybe </p>
0
2009-07-04T05:36:22Z
[ "python", "windows", "readline", "tab-completion" ]
python tab completion in windows
1,081,405
<p>I'm writing a cross-platform shell like program in python and I'd like to add custom tab-completion actions. On Unix systems I can use the built-in readline module and use code like the following to specify a list of possible completions when I hit the TAB key:</p> <pre><code>import readline readline.parse_and_bind...
5
2009-07-04T03:11:37Z
1,255,975
<p>Another possibility to check out is <a href="http://newcenturycomputers.net/projects/readline.html" rel="nofollow">readline.py</a>.</p>
0
2009-08-10T16:51:00Z
[ "python", "windows", "readline", "tab-completion" ]
Python: How to set breakpoints on mac with IDLE debugger?
1,081,536
<p>I have access to both a PC and a mac for a python class. I find I am unable to set breakpoints in the IDLE debugger in the mac (works fine on the PC). </p> <p>I've tried "ctrl-click" and configuring the touchpad to recognize two taps at once as a secondary click. I don't have a mouse for the mac, just the touchpad....
2
2009-07-04T05:00:20Z
1,081,590
<p>Have a look at the <a href="http://docs.python.org/library/pdb.html" rel="nofollow">pdb</a> module. I have just barely learned about it, and played with it a bit. It appears to enable command line debugging by allowing you to set traces within the code. This gives you interactive access to your variables and code...
1
2009-07-04T05:39:01Z
[ "python", "osx", "python-idle" ]
Python: How to set breakpoints on mac with IDLE debugger?
1,081,536
<p>I have access to both a PC and a mac for a python class. I find I am unable to set breakpoints in the IDLE debugger in the mac (works fine on the PC). </p> <p>I've tried "ctrl-click" and configuring the touchpad to recognize two taps at once as a secondary click. I don't have a mouse for the mac, just the touchpad....
2
2009-07-04T05:00:20Z
1,110,542
<p>If you put the following two lines:</p> <pre><code>import pdb pdb.set_trace() </code></pre> <p>Python will import the <strong>P</strong>ython <strong>D</strong>e <strong>B</strong>ugger and you will be in the interactive interpreter at this point in the code. It will evaluate all your Python expressions normally.<...
3
2009-07-10T16:21:09Z
[ "python", "osx", "python-idle" ]
Python: How to set breakpoints on mac with IDLE debugger?
1,081,536
<p>I have access to both a PC and a mac for a python class. I find I am unable to set breakpoints in the IDLE debugger in the mac (works fine on the PC). </p> <p>I've tried "ctrl-click" and configuring the touchpad to recognize two taps at once as a secondary click. I don't have a mouse for the mac, just the touchpad....
2
2009-07-04T05:00:20Z
4,251,733
<p>It's a bug in <code>IDLE</code>, specifically any <code>IDLE</code> on Mac OS X linked with the default Aqua <code>Tk</code>, supplied with Mac OS X or from ActiveState. That includes the Apple-supplied Pythons in OS X 10.4 through 10.6 and the python.org installers. The problem is that Aqua <code>Tk</code> has a ...
1
2010-11-23T00:49:03Z
[ "python", "osx", "python-idle" ]
Python: How to set breakpoints on mac with IDLE debugger?
1,081,536
<p>I have access to both a PC and a mac for a python class. I find I am unable to set breakpoints in the IDLE debugger in the mac (works fine on the PC). </p> <p>I've tried "ctrl-click" and configuring the touchpad to recognize two taps at once as a secondary click. I don't have a mouse for the mac, just the touchpad....
2
2009-07-04T05:00:20Z
6,274,526
<p>So, for newbies, a little more detail on Ned Deily's patch. Here is what I did. I'm running python 2.7.1 in idle on osx 10.6.5. I followed Ned's link for Issue 10404, and finally to the patched version of the file EditorWindow.py, which on my installation lives in the directory</p> <p>/Library/Frameworks/Python.fr...
0
2011-06-08T05:22:18Z
[ "python", "osx", "python-idle" ]
Transition from Python2.4 to Python2.6 on CentOS. Module migration problem
1,081,698
<p>Hey guys, I have a problem of upgrading python from 2.4 to 2.6:</p> <p>I have CentOS 5 (Full) <br>It has python 2.4 living in /usr/lib/python2.4/ <br>Additional modules are living in /usr/lib/python2.4/site-packages/</p> <p>I've built python 2.6 from sources at /usr/local/lib/python2.6/ <br>I've set default pyt...
3
2009-07-04T06:59:05Z
1,081,705
<p>There are a couple of options...</p> <ol> <li><p>If the modules will run under Python 2.6, you can simply create symbolic links to them from the 2.6 site-packages directory to the 2.4 site-packages directory.</p></li> <li><p>If they will not run under 2.6, then you may need to re-compile them against 2.6, or instal...
0
2009-07-04T07:04:44Z
[ "python", "linux", "upgrade", "centos", "python-2.6" ]
Transition from Python2.4 to Python2.6 on CentOS. Module migration problem
1,081,698
<p>Hey guys, I have a problem of upgrading python from 2.4 to 2.6:</p> <p>I have CentOS 5 (Full) <br>It has python 2.4 living in /usr/lib/python2.4/ <br>Additional modules are living in /usr/lib/python2.4/site-packages/</p> <p>I've built python 2.6 from sources at /usr/local/lib/python2.6/ <br>I've set default pyt...
3
2009-07-04T06:59:05Z
1,081,903
<p>They are not broken, they are simply not installed. The solution to that is to install them under 2.6. But first we should see if you really should do that...</p> <p>Yes, Python will when installed replace the python command to the version installed (unless you run it with --alt-install). You don't exactly state wh...
3
2009-07-04T09:46:06Z
[ "python", "linux", "upgrade", "centos", "python-2.6" ]
Transition from Python2.4 to Python2.6 on CentOS. Module migration problem
1,081,698
<p>Hey guys, I have a problem of upgrading python from 2.4 to 2.6:</p> <p>I have CentOS 5 (Full) <br>It has python 2.4 living in /usr/lib/python2.4/ <br>Additional modules are living in /usr/lib/python2.4/site-packages/</p> <p>I've built python 2.6 from sources at /usr/local/lib/python2.6/ <br>I've set default pyt...
3
2009-07-04T06:59:05Z
1,082,045
<p>Some Python libs may be still not accessible as with Python 2.6 <code>site-packages</code> is changed to <code>dist-packages</code>. </p> <p>The only way in that case is to do move all stuff generated in site-packages (e.g. by <code>make install</code>) to dist-packages and create a sym-link.</p>
0
2009-07-04T11:40:09Z
[ "python", "linux", "upgrade", "centos", "python-2.6" ]
Transition from Python2.4 to Python2.6 on CentOS. Module migration problem
1,081,698
<p>Hey guys, I have a problem of upgrading python from 2.4 to 2.6:</p> <p>I have CentOS 5 (Full) <br>It has python 2.4 living in /usr/lib/python2.4/ <br>Additional modules are living in /usr/lib/python2.4/site-packages/</p> <p>I've built python 2.6 from sources at /usr/local/lib/python2.6/ <br>I've set default pyt...
3
2009-07-04T06:59:05Z
1,085,044
<p>easy_install is good one but there are low level way for installing module, just:</p> <ol> <li>unpack module source to some directory</li> <li>type "python setup.py install"</li> </ol> <p>Of course you should do this with required installed python interpreter version; for checking it type:</p> <p>python -V</p>
0
2009-07-05T23:19:16Z
[ "python", "linux", "upgrade", "centos", "python-2.6" ]
PYTHON: Update MULTIPLE COLUMNS with python variables
1,081,750
<p>I'm trying to write a valid mysql statement that would allow me to update multiple columns in one record with values provided as python variables.</p> <p>My statement would look like this:</p> <pre><code>db = MySQLdb.connect(host="localhost", user="user", passwd="password", db="dbname") cursor = db.cursor() sql_up...
0
2009-07-04T07:42:43Z
1,081,760
<p>You are using string formatting, while what you SHOULD be doing is using a parametrized query. Do it like this:</p> <pre><code>cursor.execute("UPDATE table_name SET field1=%s ... field10=%s WHERE id=%s", (var1,... var10, id)) </code></pre> <p>Did you really need to post it with 10 variables? It was so frustrating ...
5
2009-07-04T07:53:12Z
[ "python", "mysql", "variables" ]