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
Are there any libraries for Python to simulate keyboard action?
1,767,575
<p>The problem I have is that I have this Python script to launch a application. After the application is launched (the GUI is shown on screen), I want to make it de-activated. It can be done manually by activating another window, or minimizing this app, or pressing the Show Desktop key for WindowsXP.</p> <p>So is the...
2
2009-11-20T00:24:03Z
1,767,825
<p>You can use <a href="http://sourceforge.net/projects/pywin32/" rel="nofollow">pywin32</a> to <a href="http://msdn.microsoft.com/en-us/library/ms644950%28VS.85%29.aspx" rel="nofollow">send</a> a <a href="http://msdn.microsoft.com/en-us/library/ms632646%28VS.85%29.aspx" rel="nofollow">minimize event</a>.</p>
0
2009-11-20T01:47:43Z
[ "python", "windows", "keyboard" ]
Are there any libraries for Python to simulate keyboard action?
1,767,575
<p>The problem I have is that I have this Python script to launch a application. After the application is launched (the GUI is shown on screen), I want to make it de-activated. It can be done manually by activating another window, or minimizing this app, or pressing the Show Desktop key for WindowsXP.</p> <p>So is the...
2
2009-11-20T00:24:03Z
1,773,644
<p>I've used AutoIt (via it's COM interface) a lot of times</p>
0
2009-11-20T22:31:30Z
[ "python", "windows", "keyboard" ]
Python won't refresh URL to receive new forex ticker data
1,767,616
<p>I am trying to save updated Forex ticker data from this website: <a href="http://forex.offers4u.biz/TickDBReadDB.php?p=EURUSD" rel="nofollow">http://forex.offers4u.biz/TickDBReadDB.php?p=EURUSD</a></p> <p>just hit refresh to update the ticker.</p> <p>when I use my little python script, it saves the text once, but ...
0
2009-11-20T00:35:29Z
1,767,651
<p>urllib2 doesn't do any caching. Are you going through a proxy? Or the server may be caching.</p> <p>Try using a Cache-Control header described <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html" rel="nofollow">here</a>, section 14.9</p> <p>EDIT: Mind you, the most recent data on that page is from 200...
0
2009-11-20T00:48:30Z
[ "python", "refresh", "urllib", "ticker" ]
Find following tag with pyparsing
1,767,673
<p>I'm using pyparsing to parse HTML. I'm grabbing all <code>embed</code> tags, but in some cases there's an <code>a</code> tag directly following that I also want to grab if it's available.</p> <p>example:</p> <pre><code>import pyparsing target = pyparsing.makeHTMLTags("embed")[0] target.setParseAction(pyparsing.wit...
4
2009-11-20T00:56:10Z
1,767,689
<p>Why would you write your own HTML parser? The standard library includes <a href="http://docs.python.org/library/htmlparser.html" rel="nofollow">HTMLParser</a>, and BeautifulSoup can handle any job HTMLParser can't.</p>
1
2009-11-20T01:02:12Z
[ "python", "html", "parsing", "pyparsing" ]
Find following tag with pyparsing
1,767,673
<p>I'm using pyparsing to parse HTML. I'm grabbing all <code>embed</code> tags, but in some cases there's an <code>a</code> tag directly following that I also want to grab if it's available.</p> <p>example:</p> <pre><code>import pyparsing target = pyparsing.makeHTMLTags("embed")[0] target.setParseAction(pyparsing.wit...
4
2009-11-20T00:56:10Z
1,768,261
<p>If there is an optional <code>&lt;a&gt;</code> tag that would be interesting if it follows an <code>&lt;embed&gt;</code> tag, then add it to your search pattern:</p> <pre><code>embedTag = pyparsing.makeHTMLTags("embed")[0] aTag = pyparsing.makeHTMLTags("a")[0] target = embedTag + pyparsing.Optional(aTag) result = t...
5
2009-11-20T04:02:28Z
[ "python", "html", "parsing", "pyparsing" ]
Find following tag with pyparsing
1,767,673
<p>I'm using pyparsing to parse HTML. I'm grabbing all <code>embed</code> tags, but in some cases there's an <code>a</code> tag directly following that I also want to grab if it's available.</p> <p>example:</p> <pre><code>import pyparsing target = pyparsing.makeHTMLTags("embed")[0] target.setParseAction(pyparsing.wit...
4
2009-11-20T00:56:10Z
1,771,162
<p>you don't prefer using normal regex? or because its bad habit to parse html? :D</p> <pre><code>re.findall("&lt;object.*?&lt;/object&gt;(?:&lt;br /&gt;&lt;a.*?&lt;/a&gt;)?",a) </code></pre>
1
2009-11-20T15:21:13Z
[ "python", "html", "parsing", "pyparsing" ]
Find following tag with pyparsing
1,767,673
<p>I'm using pyparsing to parse HTML. I'm grabbing all <code>embed</code> tags, but in some cases there's an <code>a</code> tag directly following that I also want to grab if it's available.</p> <p>example:</p> <pre><code>import pyparsing target = pyparsing.makeHTMLTags("embed")[0] target.setParseAction(pyparsing.wit...
4
2009-11-20T00:56:10Z
1,772,820
<p>I was able to run your BeautifulSoup code and received no errors. I'm running BeautifulSoup 3.0.7a</p> <p>Please use BeautifulSoup 3.0.7a; 3.1.0.1 has bugs that prevent it from working at all in some cases (such as yours).</p>
1
2009-11-20T19:48:25Z
[ "python", "html", "parsing", "pyparsing" ]
Redirect realtime common line output to Django HttpResponse
1,767,675
<p>In a long run command line execution, like uncompressing a large .zip archive, how to redirect the realtime output of unzip command to browser via Django's HttpResponse? </p> <p><strong>EDIT:</strong> According to paul's suggestion, I did a search and found this question has answers to how to return a HttpResponse ...
4
2009-11-20T00:56:28Z
1,767,718
<p>The HttpResponse constructor takes either a string or an iterable.</p> <p>To trickle content down, you can make the iterable a generator.</p> <p>Provided, of course, your middleware isn't interfering.</p>
1
2009-11-20T01:10:04Z
[ "python", "django", "httpresponse" ]
django.utils.encoding.DjangoUnicodeDecodeError
1,767,848
<p>I got the following error when tried to add an entry to a Django model via generic relations.</p> <pre><code>django.utils.encoding.DjangoUnicodeDecodeError: 'utf8' codec can't decode byte 0xb8 in position 24: unexpected code byte. You passed in 'ASL/60Styles_Timeless-3_\xb8 CaLe.asl' (&lt;type 'str'&gt;) </code></p...
2
2009-11-20T01:54:10Z
1,769,426
<p>Your file system is apparently not using UTF-8 encoding:</p> <pre><code>&gt;&gt;&gt; a = 'ASL/60Styles_Timeless-3_\xb8 CaLe.asl' &gt;&gt;&gt; print a.decode('utf-8') Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; File "/usr/lib/python2.5/encodings/utf_8.py", line 16, in decod...
4
2009-11-20T09:44:38Z
[ "python", "django", "utf-8" ]
Using Numpy to find average value across data sets, with some missing data
1,767,865
<p>I have several (10 or so) CSV-formatted data sets. Each column of a data set represents one aspect of a running system (available RAM, CPU usage, open TCP connections, and so forth). Each row contains the values for these columns at one moment in time. </p> <p>The data sets were captured during individual runs of t...
4
2009-11-20T02:00:16Z
1,768,264
<p>Well, one way to do it would be to iterate over each row of each data set and append a given column value to an array that's stored in a dictionary, where the time index is used for its key value. You then iterate over the dictionary and pull the average for each array stored there. </p> <p>This isn't particularly ...
0
2009-11-20T04:03:39Z
[ "python", "numpy" ]
Using Numpy to find average value across data sets, with some missing data
1,767,865
<p>I have several (10 or so) CSV-formatted data sets. Each column of a data set represents one aspect of a running system (available RAM, CPU usage, open TCP connections, and so forth). Each row contains the values for these columns at one moment in time. </p> <p>The data sets were captured during individual runs of t...
4
2009-11-20T02:00:16Z
1,768,397
<p>Edit: I've revised my method, abandoning scipy.nanmean in favor of masked arrays.</p> <p>If it is unclear what the code is doing at any point, first try putting print statements in. If it is still unclear, feel free to ask; I'll try my best to explain. The trick part is getting the t-values merged. (That was done ...
1
2009-11-20T04:47:02Z
[ "python", "numpy" ]
Using Numpy to find average value across data sets, with some missing data
1,767,865
<p>I have several (10 or so) CSV-formatted data sets. Each column of a data set represents one aspect of a running system (available RAM, CPU usage, open TCP connections, and so forth). Each row contains the values for these columns at one moment in time. </p> <p>The data sets were captured during individual runs of t...
4
2009-11-20T02:00:16Z
1,769,444
<p>Why not just us numpy's ma (masked array) module?</p> <pre><code>maxLen = reduce(lambda a,b : max(a, b.shape[0]), dSets, 0) all = N.ma.zeros((maxLen,)+ dSets[0].shape[1:] + (len(dSets),), dtype=float) # set the dtype to whatever all.mask = True for i, set in enumerate(dSets...
3
2009-11-20T09:49:42Z
[ "python", "numpy" ]
checksum udp calculation python
1,767,910
<p>I'd like to calculate the checksum of an UDP header packet I want to send:</p> <pre><code>packetosend = """60 00 00 00 00 24 3a 40 20 02 c0 a8 01 50 00 01 00 00 00 00 00 00 09 38 20 02 c0 a8 01 50 00 01 00 00 00 00 00 00 09 6f""" </code></pre> <p>so I need to join this utf-16 (not a problem) and calculate the che...
4
2009-11-20T02:16:43Z
1,769,267
<p>This doesn't look like a UDP packet to me. It looks like an IPv6 header for an ICMPv6 packet, but the actual payload of the packet is missing.</p> <p>IPv6 headers <a href="http://mailman.isi.edu/pipermail/6bone/2002-November/006839.html">do not contain a checksum</a>.</p> <p>For <a href="http://www.networksorcery....
8
2009-11-20T09:17:24Z
[ "python", "networking", "checksum", "packet" ]
checksum udp calculation python
1,767,910
<p>I'd like to calculate the checksum of an UDP header packet I want to send:</p> <pre><code>packetosend = """60 00 00 00 00 24 3a 40 20 02 c0 a8 01 50 00 01 00 00 00 00 00 00 09 38 20 02 c0 a8 01 50 00 01 00 00 00 00 00 00 09 6f""" </code></pre> <p>so I need to join this utf-16 (not a problem) and calculate the che...
4
2009-11-20T02:16:43Z
20,721,559
<p>There is a solid checksum function that correctly deals with endianness problems in Scapy (<a href="http://www.secdev.org/projects/scapy" rel="nofollow">http://www.secdev.org/projects/scapy</a>, GPLv2).</p> <p>In Python 2.7, scapy's utils.py:</p> <pre><code>if struct.pack("H",1) == "\x00\x01": # big endian def...
3
2013-12-21T17:19:00Z
[ "python", "networking", "checksum", "packet" ]
Why am I getting this error in python ? (httplib)
1,767,934
<pre><code>if theurl.startswith("http://"): theurl = theurl[7:] head = theurl[:theurl.find('/')] tail = theurl[theurl.find('/'):] response_code = 0 import httplib conn = httplib.HTTPConnection(head) conn.request("HEAD",tail) res = conn.getresponse() response_code = int(res.status) http://www.garageband.com/mp3...
21
2009-11-20T02:24:19Z
1,767,954
<p>From the documentation for <a href="https://docs.python.org/2/library/httplib.html" rel="nofollow">httplib (Python 2)</a> (called <a href="https://docs.python.org/3/library/http.client.html" rel="nofollow">http.client in Python 3</a>):</p> <blockquote> <p><em>exception</em> <code>httplib.</code><strong><code>BadS...
23
2009-11-20T02:31:41Z
[ "python", "http" ]
Why am I getting this error in python ? (httplib)
1,767,934
<pre><code>if theurl.startswith("http://"): theurl = theurl[7:] head = theurl[:theurl.find('/')] tail = theurl[theurl.find('/'):] response_code = 0 import httplib conn = httplib.HTTPConnection(head) conn.request("HEAD",tail) res = conn.getresponse() response_code = int(res.status) http://www.garageband.com/mp3...
21
2009-11-20T02:24:19Z
1,767,959
<p>The Python Standard Library: <a href="https://docs.python.org/2/library/httplib.html" rel="nofollow">httplib (Python 2)</a> (called <a href="https://docs.python.org/3/library/http.client.html" rel="nofollow">http.client in Python 3</a>):</p> <blockquote> <p><code>exception httplib.BadStatusLine</code><br> A sub...
7
2009-11-20T02:33:15Z
[ "python", "http" ]
Why am I getting this error in python ? (httplib)
1,767,934
<pre><code>if theurl.startswith("http://"): theurl = theurl[7:] head = theurl[:theurl.find('/')] tail = theurl[theurl.find('/'):] response_code = 0 import httplib conn = httplib.HTTPConnection(head) conn.request("HEAD",tail) res = conn.getresponse() response_code = int(res.status) http://www.garageband.com/mp3...
21
2009-11-20T02:24:19Z
1,768,289
<p>Are you using a proxy?</p> <p>If so, perhaps the proxy server is rejecting <code>HEAD</code> requests.</p> <p>Do you get the same problem if you issue a <code>GET</code> request? If <code>GET</code> works I'd suspect that there is a proxy in your way.</p> <p>You can see what's going on in more detail by calling <...
4
2009-11-20T04:09:02Z
[ "python", "http" ]
Why am I getting this error in python ? (httplib)
1,767,934
<pre><code>if theurl.startswith("http://"): theurl = theurl[7:] head = theurl[:theurl.find('/')] tail = theurl[theurl.find('/'):] response_code = 0 import httplib conn = httplib.HTTPConnection(head) conn.request("HEAD",tail) res = conn.getresponse() response_code = int(res.status) http://www.garageband.com/mp3...
21
2009-11-20T02:24:19Z
19,017,158
<p>I recently got this error, in a situation where the method that contained the http request ran successfully once, and then threw this exception (with the status code as an empty string) the second time the method was called (with a different URL). I had a debugging advantage because this is calling my own REST api, ...
21
2013-09-26T00:02:36Z
[ "python", "http" ]
Why am I getting this error in python ? (httplib)
1,767,934
<pre><code>if theurl.startswith("http://"): theurl = theurl[7:] head = theurl[:theurl.find('/')] tail = theurl[theurl.find('/'):] response_code = 0 import httplib conn = httplib.HTTPConnection(head) conn.request("HEAD",tail) res = conn.getresponse() response_code = int(res.status) http://www.garageband.com/mp3...
21
2009-11-20T02:24:19Z
24,786,849
<p>The problem I had was with multiple requests, but BadStatusLine was only occurring between requests with more then a 5 second interval with a Keep-Alive timeout=5. I'm still uncertain why BadStatusLine was being raised instead of NotConnected. It seems that the connection also defaults to 5 when the header is missin...
1
2014-07-16T17:16:17Z
[ "python", "http" ]
Why am I getting this error in python ? (httplib)
1,767,934
<pre><code>if theurl.startswith("http://"): theurl = theurl[7:] head = theurl[:theurl.find('/')] tail = theurl[theurl.find('/'):] response_code = 0 import httplib conn = httplib.HTTPConnection(head) conn.request("HEAD",tail) res = conn.getresponse() response_code = int(res.status) http://www.garageband.com/mp3...
21
2009-11-20T02:24:19Z
26,063,085
<p>I just found when we get exception httplib.BadStatusLine , is when server goes down and doesn't send any response, so it means web server doesn't even send the http code [1] </p> <p>[1] <a href="http://en.wikipedia.org/wiki/List_of_HTTP_status_codes" rel="nofollow">http://en.wikipedia.org/wiki/List_of_HTTP_status_...
3
2014-09-26T15:28:05Z
[ "python", "http" ]
Why am I getting this error in python ? (httplib)
1,767,934
<pre><code>if theurl.startswith("http://"): theurl = theurl[7:] head = theurl[:theurl.find('/')] tail = theurl[theurl.find('/'):] response_code = 0 import httplib conn = httplib.HTTPConnection(head) conn.request("HEAD",tail) res = conn.getresponse() response_code = int(res.status) http://www.garageband.com/mp3...
21
2009-11-20T02:24:19Z
26,761,110
<p>I've also encountered this problem. Accordig to GmailAPI (python), it happens when the server closes the connection before sending a valid respone. Indeed, this only happened to me when my program ran on large DB.</p> <pre><code>def _read_status(self): # Initialize with Simple-Response defaults line = self....
1
2014-11-05T15:40:36Z
[ "python", "http" ]
Why am I getting this error in python ? (httplib)
1,767,934
<pre><code>if theurl.startswith("http://"): theurl = theurl[7:] head = theurl[:theurl.find('/')] tail = theurl[theurl.find('/'):] response_code = 0 import httplib conn = httplib.HTTPConnection(head) conn.request("HEAD",tail) res = conn.getresponse() response_code = int(res.status) http://www.garageband.com/mp3...
21
2009-11-20T02:24:19Z
29,435,542
<p>I know that "you should just use X" answers are frowned upon, but I have to say that after trying to diagnose this same problem for a couple hours I tried <a href="http://docs.python-requests.org/en/latest/" rel="nofollow">Requests</a> with the same set up and it worked perfectly. Easier to use and debug in my opini...
0
2015-04-03T15:56:21Z
[ "python", "http" ]
Why am I getting this error in python ? (httplib)
1,767,934
<pre><code>if theurl.startswith("http://"): theurl = theurl[7:] head = theurl[:theurl.find('/')] tail = theurl[theurl.find('/'):] response_code = 0 import httplib conn = httplib.HTTPConnection(head) conn.request("HEAD",tail) res = conn.getresponse() response_code = int(res.status) http://www.garageband.com/mp3...
21
2009-11-20T02:24:19Z
37,706,693
<p>We have no clues about what is in your <code>theurl</code> string, and I do not know whether your problem is solved or not (6 years have past and I hope you made it long before), so I just give you one possible reason I met and share it with someone who may find this later.</p> <p>I have encountered a quite similar...
0
2016-06-08T15:22:22Z
[ "python", "http" ]
Why am I getting this error in python ? (httplib)
1,767,934
<pre><code>if theurl.startswith("http://"): theurl = theurl[7:] head = theurl[:theurl.find('/')] tail = theurl[theurl.find('/'):] response_code = 0 import httplib conn = httplib.HTTPConnection(head) conn.request("HEAD",tail) res = conn.getresponse() response_code = int(res.status) http://www.garageband.com/mp3...
21
2009-11-20T02:24:19Z
39,346,910
<p>I saw this error when trying to access a HTTPS/SSL URL using httplib.HTTPConnection</p> <p>You should use httplib.HTTPSConnection to access SSL urls.</p>
0
2016-09-06T10:35:25Z
[ "python", "http" ]
How do I move data from local appengine datastore to remote datastore?
1,768,011
<p>I can see how to download the remote datastore to local, and how to upload a CSV to the remote app engine server as outlined here:</p> <p><a href="http://code.google.com/appengine/docs/python/tools/uploadingdata.html#Uploading%5Fthe%5FData%5Fto%5FApp%5FEngine" rel="nofollow">Uploading and Downloading Data</a></p> ...
2
2009-11-20T02:50:14Z
1,768,033
<p>Look at the Python Standard Library's <a href="http://docs.python.org/library/csv.html" rel="nofollow">csv module</a>.</p>
0
2009-11-20T02:54:32Z
[ "python", "google-app-engine", "gae-datastore" ]
How do I move data from local appengine datastore to remote datastore?
1,768,011
<p>I can see how to download the remote datastore to local, and how to upload a CSV to the remote app engine server as outlined here:</p> <p><a href="http://code.google.com/appengine/docs/python/tools/uploadingdata.html#Uploading%5Fthe%5FData%5Fto%5FApp%5FEngine" rel="nofollow">Uploading and Downloading Data</a></p> ...
2
2009-11-20T02:50:14Z
1,768,282
<p>The answer is to use the bulkloader.py pointing at your local box:</p> <p>bulkloader.py --dump --url=<a href="http://localhost:8080/remote%5Fapi" rel="nofollow">http://localhost:8080/remote%5Fapi</a> --filename=test.csv --kind=KindHere --app_id=app-id-here</p> <p>Then you can use the bulkloader.py --restore comman...
5
2009-11-20T04:07:35Z
[ "python", "google-app-engine", "gae-datastore" ]
Different response by screen solutions using Django and jQuery
1,768,179
<p>In a thumbnail website, if I want to display 100x100 thumbs on screnn resolutions lower than 1280x1024 while display 150x150 thumbs for screens higher than 1280x1024, is the following procedure correct?</p> <ol> <li>Render a page frame with no thumbs by view1()</li> <li>On page frame loaded, it detects client's scr...
0
2009-11-20T03:34:02Z
1,768,324
<p>i think you have few options</p> <ol> <li>Just change thumbnail at runtime based on $(window).width(); using jquery</li> <li>Pass on screen resolution to django first time from client side, and later store it in session and render templates accordingly</li> <li>Sometime you may get screen resolution in request head...
2
2009-11-20T04:22:53Z
[ "jquery", "python", "django" ]
Can't call a webservice method using SOAPpy
1,768,185
<p>I am trying to call a webservice using SOAPpy:</p> <pre><code>from SOAPpy import SOAPProxy url = 'http://www.webservicex.net/WeatherForecast.asmx' server = SOAPProxy(url); print server.GetWeatherByPlaceName('Dallas'); print server.GetWeatherByZipCode ('33126'); </code></pre> <p>The server call fails:</p> <pre><...
1
2009-11-20T03:35:42Z
1,769,994
<p>As error message states, SOAPpy doesn't add SOAPAction HTTP header. That's why SOAPpy won't work for many services. Try <a href="https://fedorahosted.org/suds/" rel="nofollow">suds</a>, here is a working example:</p> <pre><code>from suds.client import Client url = 'http://www.webservicex.net/WeatherForecast.asmx?W...
4
2009-11-20T11:49:11Z
[ "python", "soappy", "web-services", "soap", ".net" ]
Can't call a webservice method using SOAPpy
1,768,185
<p>I am trying to call a webservice using SOAPpy:</p> <pre><code>from SOAPpy import SOAPProxy url = 'http://www.webservicex.net/WeatherForecast.asmx' server = SOAPProxy(url); print server.GetWeatherByPlaceName('Dallas'); print server.GetWeatherByZipCode ('33126'); </code></pre> <p>The server call fails:</p> <pre><...
1
2009-11-20T03:35:42Z
2,495,261
<p>When consuming .NET webservices, you can add a soap action override to the call. Like the following. Confirmed working code. </p> <pre><code>import SOAPpy ns = 'http://www.webservicex.net' url = '%s/WeatherForecast.asmx' % ns server = SOAPpy.SOAPProxy( url, namespace=ns ) #following is required for .NET server.co...
7
2010-03-22T19:55:23Z
[ "python", "soappy", "web-services", "soap", ".net" ]
What is the best way to crawl a login based sites?
1,768,373
<p>I've to automate a file download activity from a website (similar to, let's say, yahoomail.com). To reach a page which has this file download link, i've to login, jump from page to page to provide some parameters like dates etc., and finally click on download link.</p> <p>I am thinking of three approaches:</p> <ol...
1
2009-11-20T04:38:13Z
1,768,383
<p><a href="http://www.freedownloadmanager.org/" rel="nofollow">Free Download Manager</a> is great for crawling, and you could use <a href="http://www.gnu.org/software/wget/" rel="nofollow">wget</a>.</p>
0
2009-11-20T04:41:19Z
[ "c#", "python", "watin", "web-crawler", "html-parsing" ]
What is the best way to crawl a login based sites?
1,768,373
<p>I've to automate a file download activity from a website (similar to, let's say, yahoomail.com). To reach a page which has this file download link, i've to login, jump from page to page to provide some parameters like dates etc., and finally click on download link.</p> <p>I am thinking of three approaches:</p> <ol...
1
2009-11-20T04:38:13Z
1,768,401
<p>Try a <a href="http://seleniumhq.org/" rel="nofollow">Selenium</a> script, automated with <a href="http://seleniumhq.org/projects/remote-control/" rel="nofollow">Selenium Remote Control</a>.</p>
0
2009-11-20T04:47:59Z
[ "c#", "python", "watin", "web-crawler", "html-parsing" ]
What is the best way to crawl a login based sites?
1,768,373
<p>I've to automate a file download activity from a website (similar to, let's say, yahoomail.com). To reach a page which has this file download link, i've to login, jump from page to page to provide some parameters like dates etc., and finally click on download link.</p> <p>I am thinking of three approaches:</p> <ol...
1
2009-11-20T04:38:13Z
1,768,407
<p>I use <a href="http://scrapy.org" rel="nofollow">scrapy.org</a>, it's a python library. It's quiet good actually. Easy to write spiders and it's very extensive in it's functionality. Scraping sites after login is available in the package.</p> <p>Here is an example of a spider that would crawl a site after authentic...
5
2009-11-20T04:49:53Z
[ "c#", "python", "watin", "web-crawler", "html-parsing" ]
What is the best way to crawl a login based sites?
1,768,373
<p>I've to automate a file download activity from a website (similar to, let's say, yahoomail.com). To reach a page which has this file download link, i've to login, jump from page to page to provide some parameters like dates etc., and finally click on download link.</p> <p>I am thinking of three approaches:</p> <ol...
1
2009-11-20T04:38:13Z
1,769,883
<p>I used <a href="http://wwwsearch.sourceforge.net/mechanize/" rel="nofollow">mechanize</a> for Python with success for a few things. It's easy to use and supports HTTP authentication, form handling, cookies, automatic HTTP redirection (30X), ... Basically the only thing missing is JavaScript, but if you need to rel...
3
2009-11-20T11:27:50Z
[ "c#", "python", "watin", "web-crawler", "html-parsing" ]
What is the best framework/cms and shopping cart plugin/module/etc. combination?
1,768,576
<p>What is the best framework/cms shopping cart for a beginner php/python developer to implement? I'm potentially going to be developing a site with an online catalog of about one hundred items. Info about the items will change every year. They might add new items. They want to admin their own items and such. I'm a...
0
2009-11-20T05:53:39Z
1,768,615
<p>I am not an expert but it seems that <a href="http://www.magentocommerce.com/" rel="nofollow">Magento</a> is one of the leading solutions for ecommerce. It is a CMS so the user will have the capability to modify its content without the need of a custom admin tool. That should be Ok for your customer.</p> <p>However...
1
2009-11-20T06:04:50Z
[ "php", "python", "e-commerce", "shopping-cart" ]
What is the best framework/cms and shopping cart plugin/module/etc. combination?
1,768,576
<p>What is the best framework/cms shopping cart for a beginner php/python developer to implement? I'm potentially going to be developing a site with an online catalog of about one hundred items. Info about the items will change every year. They might add new items. They want to admin their own items and such. I'm a...
0
2009-11-20T05:53:39Z
1,768,645
<p>In terms of market share, wordpress probably has the most widely accepted platform for this kind of stuff. Part of the reason is its maintainability; another is the breadth of its secondary sources for add-ons, especially including shopping-carts. It's written in PHP over MySQL.</p> <p>A project such as you describ...
1
2009-11-20T06:14:42Z
[ "php", "python", "e-commerce", "shopping-cart" ]
What is the best framework/cms and shopping cart plugin/module/etc. combination?
1,768,576
<p>What is the best framework/cms shopping cart for a beginner php/python developer to implement? I'm potentially going to be developing a site with an online catalog of about one hundred items. Info about the items will change every year. They might add new items. They want to admin their own items and such. I'm a...
0
2009-11-20T05:53:39Z
9,185,636
<p><a href="http://expressionengine.com" rel="nofollow">ExpressionEngine</a>, based on the <a href="http://codeigniter.com/" rel="nofollow">Codeigniter</a> framework, is an extremely flexible CMS with a few different good choices of commercial addons that implement ecommerce functionality.</p> <ul> <li><a href="http:/...
0
2012-02-07T23:24:45Z
[ "php", "python", "e-commerce", "shopping-cart" ]
Effective Interpreted Programming Language for File/Image manipulation
1,768,749
<p>I need to make a script to read images from a directory, rename them, resize them to a MAX_HEIGHT, MAX_WIDTH, put a watermark logo and save them in JPG.</p> <p>I was thinking on doing this with an interpreted language, like Ruby, PHP, Perl, Python, or any with the image manipulation capabilities.</p> <p>Which lang...
1
2009-11-20T06:45:23Z
1,768,767
<p>It seems, <a href="http://en.wikipedia.org/wiki/ImageMagick" rel="nofollow">ImageMagick</a> with <a href="http://www.imagemagick.org/script/perl-magick.php" rel="nofollow">PerlMagick</a> fits your task nicely.</p>
10
2009-11-20T06:50:09Z
[ "php", "python", "ruby", "perl", "image-manipulation" ]
Effective Interpreted Programming Language for File/Image manipulation
1,768,749
<p>I need to make a script to read images from a directory, rename them, resize them to a MAX_HEIGHT, MAX_WIDTH, put a watermark logo and save them in JPG.</p> <p>I was thinking on doing this with an interpreted language, like Ruby, PHP, Perl, Python, or any with the image manipulation capabilities.</p> <p>Which lang...
1
2009-11-20T06:45:23Z
1,768,777
<p>Offhand, Python with the <a href="http://www.pythonware.com/products/pil/" rel="nofollow">Python Imaging Library</a>.</p> <p>More answers here: <a href="http://stackoverflow.com/questions/158756/what-is-the-best-image-manipulation-library">What is the best image manipulation library?</a></p>
6
2009-11-20T06:51:52Z
[ "php", "python", "ruby", "perl", "image-manipulation" ]
Effective Interpreted Programming Language for File/Image manipulation
1,768,749
<p>I need to make a script to read images from a directory, rename them, resize them to a MAX_HEIGHT, MAX_WIDTH, put a watermark logo and save them in JPG.</p> <p>I was thinking on doing this with an interpreted language, like Ruby, PHP, Perl, Python, or any with the image manipulation capabilities.</p> <p>Which lang...
1
2009-11-20T06:45:23Z
1,768,851
<p>Any language + <a href="http://www.imagemagick.org/script/index.php" rel="nofollow">ImageMagick</a> set of programs. Using them via libraries (like PerlMagick) proved to be less than optimal, but doing it via system() calls worked incredibly well. You can find a <a href="http://www.fmwconcepts.com/imagemagick/" rel=...
9
2009-11-20T07:12:45Z
[ "php", "python", "ruby", "perl", "image-manipulation" ]
Effective Interpreted Programming Language for File/Image manipulation
1,768,749
<p>I need to make a script to read images from a directory, rename them, resize them to a MAX_HEIGHT, MAX_WIDTH, put a watermark logo and save them in JPG.</p> <p>I was thinking on doing this with an interpreted language, like Ruby, PHP, Perl, Python, or any with the image manipulation capabilities.</p> <p>Which lang...
1
2009-11-20T06:45:23Z
1,769,600
<p>You could look at what "phatch" does (<a href="http://photobatch.stani.be/" rel="nofollow">http://photobatch.stani.be/</a>), that's a python image batch pocessor.</p> <p>It tries to use all the various open source image manipulation libraries (imagemagick, python's PIL, exiftools, etc) for the parts where they are ...
2
2009-11-20T10:28:33Z
[ "php", "python", "ruby", "perl", "image-manipulation" ]
Effective Interpreted Programming Language for File/Image manipulation
1,768,749
<p>I need to make a script to read images from a directory, rename them, resize them to a MAX_HEIGHT, MAX_WIDTH, put a watermark logo and save them in JPG.</p> <p>I was thinking on doing this with an interpreted language, like Ruby, PHP, Perl, Python, or any with the image manipulation capabilities.</p> <p>Which lang...
1
2009-11-20T06:45:23Z
1,769,646
<p>In the past, I've found the <a href="http://search.cpan.org/dist/Imager">Imager</a> Perl module to be hugely useful. It has a better API than <a href="http://search.cpan.org/dist/GD">GD</a> and <a href="http://search.cpan.org/dist/PerlMagick/">ImageMagick</a> (IMHO) and is very fast. It also doesn't necessarily requ...
5
2009-11-20T10:39:25Z
[ "php", "python", "ruby", "perl", "image-manipulation" ]
Effective Interpreted Programming Language for File/Image manipulation
1,768,749
<p>I need to make a script to read images from a directory, rename them, resize them to a MAX_HEIGHT, MAX_WIDTH, put a watermark logo and save them in JPG.</p> <p>I was thinking on doing this with an interpreted language, like Ruby, PHP, Perl, Python, or any with the image manipulation capabilities.</p> <p>Which lang...
1
2009-11-20T06:45:23Z
1,771,700
<p>Yet another alternative: shell of your choice, using <a href="http://netpbm.sourceforge.net/" rel="nofollow">netpbm</a>.</p>
2
2009-11-20T16:36:42Z
[ "php", "python", "ruby", "perl", "image-manipulation" ]
How to make python_select work for '$>python' command?
1,768,881
<p>I installed a couple of pythons in different versions with macports, and the apple python 2.6 is also working. Now I need to run a program which requires MySQLdb package support in python, and this package was installed to the python I installed by macports. The program tells me that there is no MySQLdb installed, s...
2
2009-11-20T07:23:12Z
1,768,914
<p>First, I am not sure with Mac, coz I never use it before.</p> <p>but in Linux, when I do <code>whereis python</code></p> <p>It will show like <code>/usr/bin/python /usr/local/bin/python</code> ....etc</p> <p>in my <code>.bashrc</code> file, I just <code>export PATH=/usr/local/bin:/usr/bin:$PATH</code> when I want...
0
2009-11-20T07:35:03Z
[ "python", "osx", "mysql" ]
How to make python_select work for '$>python' command?
1,768,881
<p>I installed a couple of pythons in different versions with macports, and the apple python 2.6 is also working. Now I need to run a program which requires MySQLdb package support in python, and this package was installed to the python I installed by macports. The program tells me that there is no MySQLdb installed, s...
2
2009-11-20T07:23:12Z
1,769,070
<p>By default, MacPorts installs user programs (or links to them) in <code>/opt/local/bin</code>. The MacPorts <code>select_python</code> command selects which python instance is linked to <code>/opt/local/bin/python</code>. It has no effect (nor should it) on what Apple installs in <code>/usr/bin</code>, which is wh...
7
2009-11-20T08:37:54Z
[ "python", "osx", "mysql" ]
How to make python_select work for '$>python' command?
1,768,881
<p>I installed a couple of pythons in different versions with macports, and the apple python 2.6 is also working. Now I need to run a program which requires MySQLdb package support in python, and this package was installed to the python I installed by macports. The program tells me that there is no MySQLdb installed, s...
2
2009-11-20T07:23:12Z
2,497,447
<p>'python' in the Mac is just a link. Do a 'which python', 'cd' to the directory in which 'python' resides, and then do an 'ls -a py*'. You shall see where python is pointing too. If you want that python to point to your different version of python, just make it link to the right version.</p>
0
2010-03-23T03:46:35Z
[ "python", "osx", "mysql" ]
Python: pynotify network problem
1,768,918
<p>I am using <a href="http://pyinotify.sourceforge.net/#Description" rel="nofollow">pynotify</a> and this is the code I am trying to get to work:</p> <pre><code>#! /usr/bin/python try: import pynotify if pynotify.init("Telebrama Alert"): n = pynotify.Notification('Message','This is test message') ...
0
2009-11-20T07:37:19Z
1,769,007
<p><code>pynotify</code> is just an X client. To connect non-local X server you have to set DISPLAY environment variable. Note, that X server you are going to connect to should be configured to accept remote connections (see man pages for xhost and xauth).</p>
2
2009-11-20T08:13:36Z
[ "python", "pynotify" ]
Python: pynotify network problem
1,768,918
<p>I am using <a href="http://pyinotify.sourceforge.net/#Description" rel="nofollow">pynotify</a> and this is the code I am trying to get to work:</p> <pre><code>#! /usr/bin/python try: import pynotify if pynotify.init("Telebrama Alert"): n = pynotify.Notification('Message','This is test message') ...
0
2009-11-20T07:37:19Z
1,769,012
<p>Well you should understand pynotify is not about network.</p> <p>pynotify is the Python binding for libnotify. libnotify is about desktop (local) notification. It uses the local D-Bus message bus. No network. So if you want to send a notification to another desktop you will have to use some other tool.</p>
1
2009-11-20T08:17:44Z
[ "python", "pynotify" ]
Python: pynotify network problem
1,768,918
<p>I am using <a href="http://pyinotify.sourceforge.net/#Description" rel="nofollow">pynotify</a> and this is the code I am trying to get to work:</p> <pre><code>#! /usr/bin/python try: import pynotify if pynotify.init("Telebrama Alert"): n = pynotify.Notification('Message','This is test message') ...
0
2009-11-20T07:37:19Z
4,574,646
<p>Depending on your DISPLAY variable, you can get this to work by:</p> <p>import os os.environ['DISPLAY'] = ':0.0'</p>
0
2011-01-01T16:13:03Z
[ "python", "pynotify" ]
Template system for RDF?
1,768,921
<p><a href="http://en.wikipedia.org/wiki/Resource%5FDescription%5FFramework" rel="nofollow">RDF</a> is a schema-free system to represent data. However, most of the time I find myself writing a sort of well-known graph structure, and I have to build triple by triple. In the more general case, this well known graph stru...
2
2009-11-20T07:38:38Z
1,771,434
<p>Sounds a little like using a SPARQL <code>CONSTRUCT</code> query to make the final graph. Run a regular query (<code>WHERE {}</code> ) against a graph to form some variable bindings and then use the <code>CONSTRUCT {}</code> block to make the templated graph into your final answer. Any modern rdf library should ha...
3
2009-11-20T15:59:00Z
[ "python", "rdf" ]
Web timer using Python
1,769,028
<p>I would like to create web page which will print simple message</p> <pre><code>x minutes to shutdown </code></pre> <p>where 'x' would decrease once a minute automatically without clicking 'refresh' in web browser. The value will be counted from data downloaded from SNMP source (that is why I wanted to use Python)....
1
2009-11-20T08:23:49Z
1,769,035
<p>Javascript is the only language the works well on the web. So yes, you have to use it.</p>
1
2009-11-20T08:27:32Z
[ "python", "timer" ]
Web timer using Python
1,769,028
<p>I would like to create web page which will print simple message</p> <pre><code>x minutes to shutdown </code></pre> <p>where 'x' would decrease once a minute automatically without clicking 'refresh' in web browser. The value will be counted from data downloaded from SNMP source (that is why I wanted to use Python)....
1
2009-11-20T08:23:49Z
1,769,051
<p>Not very Web 2.0, and also discouraged by the W3C, but you could add this to your HTML header:</p> <pre><code>&lt;meta http-equiv="refresh" content="60" /&gt; </code></pre> <p>That will automatically refresh the page for you every 60 seconds without the user having to click refresh.</p> <p>To implement this you w...
1
2009-11-20T08:33:04Z
[ "python", "timer" ]
Web timer using Python
1,769,028
<p>I would like to create web page which will print simple message</p> <pre><code>x minutes to shutdown </code></pre> <p>where 'x' would decrease once a minute automatically without clicking 'refresh' in web browser. The value will be counted from data downloaded from SNMP source (that is why I wanted to use Python)....
1
2009-11-20T08:23:49Z
1,769,088
<p>You could use a scripting language of your choice to load the initial time on the server side, and just serve your page with a Javascript timer that modifies the time every minute. </p> <p>You would need to look into the <code>setTimeout()</code> Javascript function to manage the timer.</p> <p>Something like this:...
3
2009-11-20T08:41:55Z
[ "python", "timer" ]
Python Programming Help
1,769,278
<pre><code>#!/usr/bin/env python import math def primeTest(isPrime): print(' {0}=testnum'.format(testnum)) if testnum%2 == 0 and testnum != 2: #if divisible by 2 and not 2 isPrime = False print('{0} a'.format(isPrime)) print('a') else: numroot = round(math.sqrt(testnum)) i = 2 while i &lt;= numroot: if t...
1
2009-11-20T09:19:29Z
1,769,324
<p>Although you have set isPrime to be a global, you are modifying it inside the local bounds of the primeTest function. As a result, it won't be modified.</p> <p>If you need it changing, try passing it in as a parameter and having it modified that way.</p>
0
2009-11-20T09:27:41Z
[ "python" ]
Python Programming Help
1,769,278
<pre><code>#!/usr/bin/env python import math def primeTest(isPrime): print(' {0}=testnum'.format(testnum)) if testnum%2 == 0 and testnum != 2: #if divisible by 2 and not 2 isPrime = False print('{0} a'.format(isPrime)) print('a') else: numroot = round(math.sqrt(testnum)) i = 2 while i &lt;= numroot: if t...
1
2009-11-20T09:19:29Z
1,769,330
<p><code>global isPrime</code> needs to be inside the function where you assign to <code>isPrime</code>.</p>
3
2009-11-20T09:28:09Z
[ "python" ]
Python Programming Help
1,769,278
<pre><code>#!/usr/bin/env python import math def primeTest(isPrime): print(' {0}=testnum'.format(testnum)) if testnum%2 == 0 and testnum != 2: #if divisible by 2 and not 2 isPrime = False print('{0} a'.format(isPrime)) print('a') else: numroot = round(math.sqrt(testnum)) i = 2 while i &lt;= numroot: if t...
1
2009-11-20T09:19:29Z
1,769,331
<p><strike>I think that, since you are declaring the <code>isPrime</code> global variable after the definition of <code>primeTest()</code>, the Python interpreter treats the isPrime within the function as a local variable.</strike></p> <p>I was mistaken.. you have to declare it as <code>global isPrime</code> from with...
2
2009-11-20T09:28:10Z
[ "python" ]
Python Programming Help
1,769,278
<pre><code>#!/usr/bin/env python import math def primeTest(isPrime): print(' {0}=testnum'.format(testnum)) if testnum%2 == 0 and testnum != 2: #if divisible by 2 and not 2 isPrime = False print('{0} a'.format(isPrime)) print('a') else: numroot = round(math.sqrt(testnum)) i = 2 while i &lt;= numroot: if t...
1
2009-11-20T09:19:29Z
1,769,354
<p>global foo means, in this scope, let me say foo to refer to a foo accessible from outside this scope and persistent after this scope closes. It does not mean, let all variables named foo everywhere and forever refer to this foo. </p> <p>This is different from what you might expect if you're coming from, say, a C/C+...
1
2009-11-20T09:33:32Z
[ "python" ]
Script to remove python comments/docstrings
1,769,332
<p>Is there a python script or tool available which can remove comments and docstrings from python source?</p> <p>it should take care of cases like</p> <pre><code>""" aas """ def f(): m = { u'x': u'y' } # faake docstring ;) if 1: 'string' &gt;&gt; m if 2: 'strin...
5
2009-11-20T09:28:37Z
1,769,362
<p>This recipe <a href="http://code.activestate.com/recipes/576704/" rel="nofollow">here</a> claims to do what you want. And a few other things too.</p>
1
2009-11-20T09:35:18Z
[ "python", "comments" ]
Script to remove python comments/docstrings
1,769,332
<p>Is there a python script or tool available which can remove comments and docstrings from python source?</p> <p>it should take care of cases like</p> <pre><code>""" aas """ def f(): m = { u'x': u'y' } # faake docstring ;) if 1: 'string' &gt;&gt; m if 2: 'strin...
5
2009-11-20T09:28:37Z
1,769,577
<p>This does the job:</p> <pre><code>""" Strip comments and docstrings from a file. """ import sys, token, tokenize def do_file(fname): """ Run on just one file. """ source = open(fname) mod = open(fname + ",strip", "w") prev_toktype = token.INDENT first_line = None last_lineno = -1 ...
8
2009-11-20T10:23:52Z
[ "python", "comments" ]
Script to remove python comments/docstrings
1,769,332
<p>Is there a python script or tool available which can remove comments and docstrings from python source?</p> <p>it should take care of cases like</p> <pre><code>""" aas """ def f(): m = { u'x': u'y' } # faake docstring ;) if 1: 'string' &gt;&gt; m if 2: 'strin...
5
2009-11-20T09:28:37Z
1,769,794
<p>Try testing each chunk of tokens ending with NEWLINE. Then correct pattern for docstring (including cases where it serves as comment, but isn't assigned to <code>__doc__</code>) I believe is (assuming match is performed from start of file of after NEWLINE):</p> <pre><code>( DEDENT+ | INDENT? ) STRING+ COMMENT? NEWL...
1
2009-11-20T11:09:18Z
[ "python", "comments" ]
Script to remove python comments/docstrings
1,769,332
<p>Is there a python script or tool available which can remove comments and docstrings from python source?</p> <p>it should take care of cases like</p> <pre><code>""" aas """ def f(): m = { u'x': u'y' } # faake docstring ;) if 1: 'string' &gt;&gt; m if 2: 'strin...
5
2009-11-20T09:28:37Z
2,962,727
<p>I'm the author of the "<em>mygod, he has written a python interpreter using regex...</em>" (i.e. pyminifier) mentioned <a href="http://stackoverflow.com/questions/1769332/script-to-remove-python-comments-docstrings#comment1653880_1769362">at that link below</a> =).<br> I just wanted to chime in and say that I've imp...
8
2010-06-03T01:05:02Z
[ "python", "comments" ]
Script to remove python comments/docstrings
1,769,332
<p>Is there a python script or tool available which can remove comments and docstrings from python source?</p> <p>it should take care of cases like</p> <pre><code>""" aas """ def f(): m = { u'x': u'y' } # faake docstring ;) if 1: 'string' &gt;&gt; m if 2: 'strin...
5
2009-11-20T09:28:37Z
12,396,235
<p>I've just used the code given by Dan McDougall and I've found two problems.</p> <ol> <li>There where too many empty new lines, so I decided to remove line every time we have two consecurive NLs</li> <li>When the python code was processed all spaces were missing (except identation) and so such things as "import Anyt...
0
2012-09-12T21:09:56Z
[ "python", "comments" ]
Script to remove python comments/docstrings
1,769,332
<p>Is there a python script or tool available which can remove comments and docstrings from python source?</p> <p>it should take care of cases like</p> <pre><code>""" aas """ def f(): m = { u'x': u'y' } # faake docstring ;) if 1: 'string' &gt;&gt; m if 2: 'strin...
5
2009-11-20T09:28:37Z
19,438,141
<p>I think the best way is using ast.</p>
1
2013-10-17T22:05:37Z
[ "python", "comments" ]
Understanding kwargs in Python
1,769,403
<p>What are the uses for <code>**kwargs</code> in Python?</p> <p>I know you can do an <code>objects.filter</code> on a table and pass in a <code>**kwargs</code> argument. &nbsp;</p> <p>Can I also do this for specifying time deltas i.e. <code>timedelta(hours = time1)</code>? </p> <p>How exactly does it work? Is it cl...
397
2009-11-20T09:40:57Z
1,769,452
<p>kwargs is just a dictionary that is added to the parameters.</p> <p>A dictionary can contain key, value pairs. And that are the kwargs. Ok, this is how.</p> <p>The whatfor is not so simple.</p> <p>For example (very hypothetical) you have an interface that just calls other routines to do the job:</p> <pre><code>d...
40
2009-11-20T09:51:25Z
[ "python", "kwargs" ]
Understanding kwargs in Python
1,769,403
<p>What are the uses for <code>**kwargs</code> in Python?</p> <p>I know you can do an <code>objects.filter</code> on a table and pass in a <code>**kwargs</code> argument. &nbsp;</p> <p>Can I also do this for specifying time deltas i.e. <code>timedelta(hours = time1)</code>? </p> <p>How exactly does it work? Is it cl...
397
2009-11-20T09:40:57Z
1,769,475
<p>You can use <code>**kwargs</code> to let your functions take an arbitrary number of keyword arguments ("kwargs" means "keyword arguments"):</p> <pre><code>&gt;&gt;&gt; def print_keyword_args(**kwargs): ... # kwargs is a dict of the keyword args passed to the function ... for key, value in kwargs.iteritems()...
454
2009-11-20T09:58:18Z
[ "python", "kwargs" ]
Understanding kwargs in Python
1,769,403
<p>What are the uses for <code>**kwargs</code> in Python?</p> <p>I know you can do an <code>objects.filter</code> on a table and pass in a <code>**kwargs</code> argument. &nbsp;</p> <p>Can I also do this for specifying time deltas i.e. <code>timedelta(hours = time1)</code>? </p> <p>How exactly does it work? Is it cl...
397
2009-11-20T09:40:57Z
1,769,478
<h2>Unpacking dictionaries</h2> <p><code>**</code> unpacks dictionaries.</p> <p>This</p> <pre><code>func(a=1, b=2, c=3) </code></pre> <p>is the same as</p> <pre><code>args = {'a': 1, 'b': 2, 'c':3} func(**args) </code></pre> <p>It's useful if you have to construct parameters:</p> <pre><code>args = {'name': perso...
182
2009-11-20T09:59:16Z
[ "python", "kwargs" ]
Understanding kwargs in Python
1,769,403
<p>What are the uses for <code>**kwargs</code> in Python?</p> <p>I know you can do an <code>objects.filter</code> on a table and pass in a <code>**kwargs</code> argument. &nbsp;</p> <p>Can I also do this for specifying time deltas i.e. <code>timedelta(hours = time1)</code>? </p> <p>How exactly does it work? Is it cl...
397
2009-11-20T09:40:57Z
1,769,644
<p>kwargs are a syntactic sugar to pass name arguments as dictionaries(for func), or dictionaries as named arguments(to func)</p>
4
2009-11-20T10:39:06Z
[ "python", "kwargs" ]
Understanding kwargs in Python
1,769,403
<p>What are the uses for <code>**kwargs</code> in Python?</p> <p>I know you can do an <code>objects.filter</code> on a table and pass in a <code>**kwargs</code> argument. &nbsp;</p> <p>Can I also do this for specifying time deltas i.e. <code>timedelta(hours = time1)</code>? </p> <p>How exactly does it work? Is it cl...
397
2009-11-20T09:40:57Z
20,944,666
<p><strong>Motif: <code>*args</code> and <code>**kwargs</code> serves as a placeholder for the arguments that need to be passed to a function call</strong></p> <p>using <code>*args</code> and <code>**kwargs</code> to call a function </p> <pre><code>def args_kwargs_test(arg1, arg2, arg3): print "arg1:", arg1 ...
15
2014-01-06T06:57:50Z
[ "python", "kwargs" ]
Understanding kwargs in Python
1,769,403
<p>What are the uses for <code>**kwargs</code> in Python?</p> <p>I know you can do an <code>objects.filter</code> on a table and pass in a <code>**kwargs</code> argument. &nbsp;</p> <p>Can I also do this for specifying time deltas i.e. <code>timedelta(hours = time1)</code>? </p> <p>How exactly does it work? Is it cl...
397
2009-11-20T09:40:57Z
21,338,152
<p>On the basis that a good sample is sometimes better than a long discourse I will write two functions using all python variable argument passing facilities (both positional and named arguments). You should easily be able to see what it does by yourself:</p> <pre><code>def f(a = 0, *args, **kwargs): print("Receiv...
27
2014-01-24T16:56:02Z
[ "python", "kwargs" ]
Understanding kwargs in Python
1,769,403
<p>What are the uses for <code>**kwargs</code> in Python?</p> <p>I know you can do an <code>objects.filter</code> on a table and pass in a <code>**kwargs</code> argument. &nbsp;</p> <p>Can I also do this for specifying time deltas i.e. <code>timedelta(hours = time1)</code>? </p> <p>How exactly does it work? Is it cl...
397
2009-11-20T09:40:57Z
28,715,715
<p>As an addition, you can also mix different ways of usage when calling kwargs functions:</p> <pre><code>def test(**kwargs): print kwargs['a'] print kwargs['b'] print kwargs['c'] args = { 'b': 2, 'c': 3} test( a=1, **args ) </code></pre> <p>gives this output:</p> <pre><code>1 2 3 </code></pre> <p>No...
7
2015-02-25T09:45:23Z
[ "python", "kwargs" ]
Understanding kwargs in Python
1,769,403
<p>What are the uses for <code>**kwargs</code> in Python?</p> <p>I know you can do an <code>objects.filter</code> on a table and pass in a <code>**kwargs</code> argument. &nbsp;</p> <p>Can I also do this for specifying time deltas i.e. <code>timedelta(hours = time1)</code>? </p> <p>How exactly does it work? Is it cl...
397
2009-11-20T09:40:57Z
33,951,281
<p>Here's a simple function that serves to explain the usage:</p> <pre><code>def print_wrap(arg1, *args, **kwargs): print(arg1) print(args) print(kwargs) print(arg1, *args, **kwargs) </code></pre> <p>Any arguments that are <em>not</em> specified in the function definition will be put in the <code>args...
5
2015-11-27T06:15:50Z
[ "python", "kwargs" ]
Understanding kwargs in Python
1,769,403
<p>What are the uses for <code>**kwargs</code> in Python?</p> <p>I know you can do an <code>objects.filter</code> on a table and pass in a <code>**kwargs</code> argument. &nbsp;</p> <p>Can I also do this for specifying time deltas i.e. <code>timedelta(hours = time1)</code>? </p> <p>How exactly does it work? Is it cl...
397
2009-11-20T09:40:57Z
37,471,432
<p>Here is an example that I hope is helpful:</p> <pre><code>#! /usr/bin/env python # def g( **kwargs) : print ( "In g ready to print kwargs" ) print kwargs print ( "in g, calling f") f ( **kwargs ) print ( "In g, after returning from f") def f( **kwargs ) : print ( "in f, printing kwargs") print ( kwar...
0
2016-05-26T21:37:28Z
[ "python", "kwargs" ]
Understanding kwargs in Python
1,769,403
<p>What are the uses for <code>**kwargs</code> in Python?</p> <p>I know you can do an <code>objects.filter</code> on a table and pass in a <code>**kwargs</code> argument. &nbsp;</p> <p>Can I also do this for specifying time deltas i.e. <code>timedelta(hours = time1)</code>? </p> <p>How exactly does it work? Is it cl...
397
2009-11-20T09:40:57Z
39,587,967
<ul> <li><code>kwargs</code> in <code>**kwargs</code> is just variable name. You can very well have <code>**anyVariableName</code></li> <li><code>kwargs</code> stands for "keyword arguments". But I feel they should better be called as "named arguments", as these are simply arguments passed along with name. <code>func(p...
0
2016-09-20T07:19:29Z
[ "python", "kwargs" ]
parse query string with urllib in Python 2.4
1,769,625
<p>Using Python2.4.5 (don't ask!) I want to parse a query string and get a dict in return. Do I have to do it "manually" like follows?</p> <pre><code>&gt;&gt;&gt; qs = 'first=1&amp;second=4&amp;third=3' &gt;&gt;&gt; d = dict([x.split("=") for x in qs.split("&amp;")]) &gt;&gt;&gt; d {'second': '4', 'third': '3', 'first...
11
2009-11-20T10:34:03Z
1,769,643
<p>You have two options:</p> <pre><code>&gt;&gt;&gt; cgi.parse_qs(qs) {'second': ['4'], 'third': ['3'], 'first': ['1']} </code></pre> <p>or</p> <pre><code>&gt;&gt;&gt; cgi.parse_qsl(qs) [('first', '1'), ('second', '4'), ('third', '3')] </code></pre> <p>The values in the dict returned by <code>cgi.parse_qs()</code> ...
23
2009-11-20T10:39:02Z
[ "python", "parsing", "urllib" ]
parse query string with urllib in Python 2.4
1,769,625
<p>Using Python2.4.5 (don't ask!) I want to parse a query string and get a dict in return. Do I have to do it "manually" like follows?</p> <pre><code>&gt;&gt;&gt; qs = 'first=1&amp;second=4&amp;third=3' &gt;&gt;&gt; d = dict([x.split("=") for x in qs.split("&amp;")]) &gt;&gt;&gt; d {'second': '4', 'third': '3', 'first...
11
2009-11-20T10:34:03Z
19,214,238
<p>this solves the annoyance:</p> <pre><code>d = dict(urlparse.parse_qsl( qs ) ) </code></pre> <p>personally i would expect there two be a built in wrapper in urlparse. in most cases i wouldn't mind to discards the redundant parameter if such exist</p>
9
2013-10-06T21:35:22Z
[ "python", "parsing", "urllib" ]
parse query string with urllib in Python 2.4
1,769,625
<p>Using Python2.4.5 (don't ask!) I want to parse a query string and get a dict in return. Do I have to do it "manually" like follows?</p> <pre><code>&gt;&gt;&gt; qs = 'first=1&amp;second=4&amp;third=3' &gt;&gt;&gt; d = dict([x.split("=") for x in qs.split("&amp;")]) &gt;&gt;&gt; d {'second': '4', 'third': '3', 'first...
11
2009-11-20T10:34:03Z
21,014,092
<pre><code>import urlparse qs = 'first=1&amp;second=4&amp;third=3&amp;first=0' print dict(urlparse.parse_qsl(qs)) OR print urlparse.parse_qs(qs) </code></pre>
1
2014-01-09T07:28:56Z
[ "python", "parsing", "urllib" ]
How to resize just uploaded image?
1,769,683
<p>In VIEW I want to resize uploaded image and save 2 copies of it in model real and changed</p>
0
2009-11-20T10:46:45Z
1,769,767
<p>There's 1 things to note at beginning here:</p> <ul> <li>in your model (database) it's better to save the paths to images, not images themselves. Those should be kept in the filesystem and served directly from there, if possible (unless you don't have the access to the filesystem). </li> </ul> <p>So, in your view,...
3
2009-11-20T11:05:08Z
[ "python", "django", "python-imaging-library" ]
How to resize just uploaded image?
1,769,683
<p>In VIEW I want to resize uploaded image and save 2 copies of it in model real and changed</p>
0
2009-11-20T10:46:45Z
1,770,098
<p>Look at this <a href="http://biohackers.net/wiki/Django1.0/Thumbnail" rel="nofollow">http://biohackers.net/wiki/Django1.0/Thumbnail</a></p>
2
2009-11-20T12:13:47Z
[ "python", "django", "python-imaging-library" ]
How to resize just uploaded image?
1,769,683
<p>In VIEW I want to resize uploaded image and save 2 copies of it in model real and changed</p>
0
2009-11-20T10:46:45Z
1,770,215
<p>Sorl has great thumbnailing capabilities that can also be used in templates ... it will also check to see if an image is already in the filesystem if not it will create the new resized file.</p> <p>Depends really where your trying to call the image from.</p> <p><a href="http://thumbnail.sorl.net/docs" rel="nofoll...
8
2009-11-20T12:40:56Z
[ "python", "django", "python-imaging-library" ]
How to resize just uploaded image?
1,769,683
<p>In VIEW I want to resize uploaded image and save 2 copies of it in model real and changed</p>
0
2009-11-20T10:46:45Z
1,770,679
<p>Use sorl - <a href="http://thumbnail.sorl.net/docs/" rel="nofollow">http://thumbnail.sorl.net/docs/</a></p> <p>for you task <a href="http://thumbnail.sorl.net/docs/#multiple-thumbnails" rel="nofollow">See this</a> </p> <pre><code>class MyModel(models.Model): name = models.TextField(max_length=50) photo = I...
3
2009-11-20T14:12:11Z
[ "python", "django", "python-imaging-library" ]
How to resize just uploaded image?
1,769,683
<p>In VIEW I want to resize uploaded image and save 2 copies of it in model real and changed</p>
0
2009-11-20T10:46:45Z
1,774,426
<p><a href="http://bitbucket.org/jdriscoll/django-imagekit/wiki/Home" rel="nofollow">Django Imagekit</a> allows you to specify multiple image sizes. The resized images are cached, then you can access them and the original image file in your views and templates.</p>
1
2009-11-21T03:40:52Z
[ "python", "django", "python-imaging-library" ]
__unicode__(self) doesn't get called by logging
1,769,759
<p>Long story short:</p> <pre><code># this works as expected: logging.error(my_object.__unicode__()) # this doesn't: logging.error(my_object) </code></pre> <p>Same result with <code>__str__(self)</code>. Why?</p> <p>EDIT: <code>__str__</code> actually works.</p>
0
2009-11-20T11:03:19Z
1,769,807
<pre><code>&gt;&gt;&gt; class MyClass(object): ... def __str__(self): ... return "foobar" ... &gt;&gt;&gt; import logging &gt;&gt;&gt; logging.error(MyClass()) ERROR:root:foobar </code></pre> <p>Works as expected?!</p>
1
2009-11-20T11:11:28Z
[ "python", "logging" ]
__unicode__(self) doesn't get called by logging
1,769,759
<p>Long story short:</p> <pre><code># this works as expected: logging.error(my_object.__unicode__()) # this doesn't: logging.error(my_object) </code></pre> <p>Same result with <code>__str__(self)</code>. Why?</p> <p>EDIT: <code>__str__</code> actually works.</p>
0
2009-11-20T11:03:19Z
1,769,835
<p>Logging will call <code>str()</code> (which uses <code>__str__()</code> which falls back to <code>__repr__()</code> when it's not defined). This is because the logging framework is not Unicode safe (i.e. you can get errors when you try to write Unicode to the various logging sinks).</p>
1
2009-11-20T11:17:04Z
[ "python", "logging" ]
Importing python classes in the Google App Engine
1,770,037
<p>I am writing a GAE application and have run into an import problem.</p> <p>My <code>app.yaml</code> has the following lines:</p> <pre><code>- url: /py/classes/ static_dir: py/classes - url: /py/lib static_dir: py/lib - url: /py/bin/signin script: py/bin/signin.py </code></pre> <p>I am keeping a pyth...
2
2009-11-20T11:58:47Z
1,770,152
<p>The <code>static_dir</code> configuration option can not be used to extend <code>PYTHONPATH</code>. Using it you can serve static files like images, stylesheet, or Javascript files.</p> <p>If you want to use normal Python modules just put them next to your main Python files.</p> <p><strong>Edit:</strong></p> <p>A...
3
2009-11-20T12:25:08Z
[ "python", "google-app-engine" ]
Importing python classes in the Google App Engine
1,770,037
<p>I am writing a GAE application and have run into an import problem.</p> <p>My <code>app.yaml</code> has the following lines:</p> <pre><code>- url: /py/classes/ static_dir: py/classes - url: /py/lib static_dir: py/lib - url: /py/bin/signin script: py/bin/signin.py </code></pre> <p>I am keeping a pyth...
2
2009-11-20T11:58:47Z
1,773,512
<p>Any files specified as static files get uploaded separately from your code - they're not accessible by your Python code, so even with the PYTHONPATH set correctly, you won't be able to import them.</p>
1
2009-11-20T21:58:53Z
[ "python", "google-app-engine" ]
General Purpose Progressbar in Django
1,770,205
<p>I want to make a little web-frontend for copying (rsync) and encoding (ffmpeg) files for my Server using Django.<br> And I want to keep track of the progress of the processes.</p> <p>I saw a few jquery-scripts, but they are designed to be used with uploads, and I don't know enough javascript to modify these scripts...
8
2009-11-20T12:38:23Z
1,770,379
<p>See the code here <a href="http://www.djangosnippets.org/snippets/679/" rel="nofollow">http://www.djangosnippets.org/snippets/679/</a>, it says "upload progress for multipart forms" but there is nothing specific to forms, you can use it anywhere with few tweaks.</p> <p>General concept is:</p> <ol> <li>Write a web-...
9
2009-11-20T13:19:51Z
[ "javascript", "jquery", "python", "django", "progress-bar" ]
Run child processes as different user from a long running process
1,770,209
<p>I've got a long running, daemonized Python process that uses subprocess to spawn new child processes when certain events occur. The long running process is started by a user with super user privileges. I need the child processes it spawns to run as a different user (e.g., "nobody") while retaining the super user pri...
26
2009-11-20T12:39:09Z
1,770,247
<p>There is an <a href="http://docs.python.org/library/os.html#os.setuid"><code>os.setuid()</code></a> method. You can use it to change the current user for this script.</p> <p>One solution is, somewhere where the child starts, to call <code>os.setuid()</code> and <code>os.setgid()</code> to change the user and group ...
9
2009-11-20T12:49:01Z
[ "python", "fork", "subprocess", "setuid" ]
Run child processes as different user from a long running process
1,770,209
<p>I've got a long running, daemonized Python process that uses subprocess to spawn new child processes when certain events occur. The long running process is started by a user with super user privileges. I need the child processes it spawns to run as a different user (e.g., "nobody") while retaining the super user pri...
26
2009-11-20T12:39:09Z
6,037,494
<p>Since you mentioned a daemon, I can conclude that you are running on a Unix-like operating system. This matters, because how to do this depends on the kind operating system. This answer applies <em>only</em> to <strong>Unix</strong>, including Linux, and Mac OS X.</p> <ol> <li>Define a function that will set the gi...
46
2011-05-17T21:41:18Z
[ "python", "fork", "subprocess", "setuid" ]
Run child processes as different user from a long running process
1,770,209
<p>I've got a long running, daemonized Python process that uses subprocess to spawn new child processes when certain events occur. The long running process is started by a user with super user privileges. I need the child processes it spawns to run as a different user (e.g., "nobody") while retaining the super user pri...
26
2009-11-20T12:39:09Z
23,054,646
<p>Enable the user on sudo as requiring no password</p> <pre><code>username ALL=(ALL) NOPASSWD: ALL </code></pre> <p>Then call the root function with <code>sudo</code>, e.g.:</p> <pre><code>import pexpect child = pexpect.spawn('sudo apachectl restart') for i in child: print i #if you want to see the output from the ...
-1
2014-04-14T07:44:30Z
[ "python", "fork", "subprocess", "setuid" ]
Run child processes as different user from a long running process
1,770,209
<p>I've got a long running, daemonized Python process that uses subprocess to spawn new child processes when certain events occur. The long running process is started by a user with super user privileges. I need the child processes it spawns to run as a different user (e.g., "nobody") while retaining the super user pri...
26
2009-11-20T12:39:09Z
37,890,485
<p>Actually, example with preexec_fn did not work for me. <br> My solution that is working fine to run some shell command from another user and get its output is:</p> <pre><code>apipe=subprocess.Popen('sudo -u someuser /execution',shell=True,stdout=subprocess.PIPE) </code></pre> <p>Then, if you need to read from the ...
0
2016-06-17T21:16:23Z
[ "python", "fork", "subprocess", "setuid" ]
Is there a sendKey for Mac in Python?
1,770,312
<p>In Mac 10.6, I want to cause an active application to become de-active, or minimized by Python</p> <p>I know I could use sendKey in Windows with Python, then what about in Mac?</p>
15
2009-11-20T13:04:11Z
1,770,665
<p>Here is what I found from a different question on Stack Overflow. It works pretty good for my problem.</p> <pre><code>import os cmd = """ osascript -e 'tell application "System Events" to keystroke "m" using {command down}' """ # minimize active window os.system(cmd) </code></pre>
22
2009-11-20T14:10:30Z
[ "python", "osx", "sendkeys" ]
Is there a sendKey for Mac in Python?
1,770,312
<p>In Mac 10.6, I want to cause an active application to become de-active, or minimized by Python</p> <p>I know I could use sendKey in Windows with Python, then what about in Mac?</p>
15
2009-11-20T13:04:11Z
1,770,681
<p>Maybe you could run an OSA script (man osascript) from Python, for instance, and drive the application?</p>
0
2009-11-20T14:12:28Z
[ "python", "osx", "sendkeys" ]
Is there a sendKey for Mac in Python?
1,770,312
<p>In Mac 10.6, I want to cause an active application to become de-active, or minimized by Python</p> <p>I know I could use sendKey in Windows with Python, then what about in Mac?</p>
15
2009-11-20T13:04:11Z
4,201,244
<p>In addition to Yinan, which will send the keystroke to the currently active application, you can send it to a specific application as follows. Pass the following to osascript as before, or save it to a file and pass the file to osascript</p> <pre><code>tell application "Safari" activate tell application "Sy...
3
2010-11-17T03:35:03Z
[ "python", "osx", "sendkeys" ]
Is there a sendKey for Mac in Python?
1,770,312
<p>In Mac 10.6, I want to cause an active application to become de-active, or minimized by Python</p> <p>I know I could use sendKey in Windows with Python, then what about in Mac?</p>
15
2009-11-20T13:04:11Z
8,608,268
<p>Try <a href="http://appscript.sourceforge.net/">appscript</a>, an Apple event bridge available in PyPI:</p> <pre><code>from appscript import app, k app('System Events').keystroke('N', using=k.command_down) </code></pre>
6
2011-12-22T18:28:45Z
[ "python", "osx", "sendkeys" ]
Is there a sendKey for Mac in Python?
1,770,312
<p>In Mac 10.6, I want to cause an active application to become de-active, or minimized by Python</p> <p>I know I could use sendKey in Windows with Python, then what about in Mac?</p>
15
2009-11-20T13:04:11Z
29,044,535
<p>To make my scripts which already work on Windows using <code>SendKeys</code> from <code>pip</code> also work on OS X, I made a file <code>/Library/Python/2.7/site-packages/SendKeys/__init__.py</code> (<code>site-packages</code> is where <code>pip</code> puts everything it installs on my Mac... not sure if that's con...
0
2015-03-14T01:43:11Z
[ "python", "osx", "sendkeys" ]
Regex to Split 1st Colon
1,770,569
<p>I have a time in ISO <a href="http://en.wikipedia.org/wiki/ISO%5F8601" rel="nofollow">8601</a> ( <code>2009-11-19T19:55:00</code> ) which is also paired with a name <code>commence</code>. I'm trying to parse this into two. I'm currently up to here:</p> <pre><code>import re sColon = re.compile('[:]') aString = sCol...
2
2009-11-20T13:56:31Z
1,770,592
<p>Looks like you need .IndexOf(":"), then .Substring()?</p>
0
2009-11-20T14:00:47Z
[ "python", "regex" ]
Regex to Split 1st Colon
1,770,569
<p>I have a time in ISO <a href="http://en.wikipedia.org/wiki/ISO%5F8601" rel="nofollow">8601</a> ( <code>2009-11-19T19:55:00</code> ) which is also paired with a name <code>commence</code>. I'm trying to parse this into two. I'm currently up to here:</p> <pre><code>import re sColon = re.compile('[:]') aString = sCol...
2
2009-11-20T13:56:31Z
1,770,652
<pre><code>&gt;&gt;&gt; first, colon, rest = "commence:2009-11-19T19:55:00".partition(':') &gt;&gt;&gt; print (first, colon, rest) ('commence', ':', '2009-11-19T19:55:00') </code></pre>
5
2009-11-20T14:08:47Z
[ "python", "regex" ]
Regex to Split 1st Colon
1,770,569
<p>I have a time in ISO <a href="http://en.wikipedia.org/wiki/ISO%5F8601" rel="nofollow">8601</a> ( <code>2009-11-19T19:55:00</code> ) which is also paired with a name <code>commence</code>. I'm trying to parse this into two. I'm currently up to here:</p> <pre><code>import re sColon = re.compile('[:]') aString = sCol...
2
2009-11-20T13:56:31Z
1,770,690
<p>You could put maximum split parameter in split function</p> <pre><code>&gt;&gt;&gt; "commence:2009-11-19T19:55:00".split(":",1) ['commence', '2009-11-19T19:55:00'] </code></pre> <p>Official Docs</p> <blockquote> <p>S.split([sep [,maxsplit]]) -> list of strings</p> <pre><code>Return a list of the words in the s...
5
2009-11-20T14:15:08Z
[ "python", "regex" ]
Regex to Split 1st Colon
1,770,569
<p>I have a time in ISO <a href="http://en.wikipedia.org/wiki/ISO%5F8601" rel="nofollow">8601</a> ( <code>2009-11-19T19:55:00</code> ) which is also paired with a name <code>commence</code>. I'm trying to parse this into two. I'm currently up to here:</p> <pre><code>import re sColon = re.compile('[:]') aString = sCol...
2
2009-11-20T13:56:31Z
1,770,740
<p>@OP, don't do the unnecessary. Regex is not needed with what you are doing. Python has very good string manipulation methods that you can use. All you need is split(), and slicing. Those are the very basics of Python.</p> <pre><code>&gt;&gt;&gt; "commence:2009-11-19T19:55:00".split(":",1) ['commence', '2009-11-19T1...
0
2009-11-20T14:23:07Z
[ "python", "regex" ]
List of specific class names in Python
1,770,701
<p>Is there a way to flag class declarations so that later you can get a list of them flagged?</p> <p>Or a way to get all classes starting with a certain string ?</p> <p>Or all classes that are a subclass of a specific class?</p>
1
2009-11-20T14:17:20Z
1,770,753
<p><strong>Note:</strong> in the following I assume Python 3.x. For Python 2.x, use <a href="http://www.python.org/doc/newstyle/" rel="nofollow">new style classes</a>, i.e. write <code>class T(object): pass</code> instead of <code>class T: pass</code>.</p> <ol> <li><p>First, define some classes:</p> <pre><code>&gt;&g...
3
2009-11-20T14:25:23Z
[ "python" ]
List of specific class names in Python
1,770,701
<p>Is there a way to flag class declarations so that later you can get a list of them flagged?</p> <p>Or a way to get all classes starting with a certain string ?</p> <p>Or all classes that are a subclass of a specific class?</p>
1
2009-11-20T14:17:20Z
1,771,384
<p>You can also use metaclasses to collect up the classes as they are defined:</p> <pre><code>class AllSeeingMetaClass(type): # This will be a list of all the classes that use us as a metaclass. the_classes = [] def __new__(meta, classname, bases, classDict): # Invoked as new classes are defined. ...
1
2009-11-20T15:50:35Z
[ "python" ]