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
where does django install in ubuntu
1,095,725
<p>I am looking for the <strong>init</strong>.py file for django. I tried whereis and find, but I get a lot of dirs.</p>
29
2009-07-08T01:38:33Z
14,089,054
<p>Its now at </p> <pre><code>/usr/lib/python2.7/dist-packages/django/.... </code></pre> <p>circa 2012</p>
3
2012-12-30T07:29:48Z
[ "python", "django", "ubuntu" ]
what next after 'dive into python'
1,095,768
<p>I've been meaning to learn another language than java. So I started to poke around with python. I've gone over 'dive into python' so I have a decent knowledge about python now. </p> <p>where do you suggest I go from here? I dont want to go through another advanced book again and would like to use the python knowl...
10
2009-07-08T01:50:19Z
1,095,784
<p>Is web crawling something you want to do or just something you think you can accomplish? Python is a good tool for web crawling(see <a href="http://www.drewconway.com/zia/?p=1037" rel="nofollow">here</a> and <a href="http://www.drewconway.com/zia/?p=1096" rel="nofollow">here</a>), but if you really just want ANY pr...
3
2009-07-08T01:56:40Z
[ "python" ]
what next after 'dive into python'
1,095,768
<p>I've been meaning to learn another language than java. So I started to poke around with python. I've gone over 'dive into python' so I have a decent knowledge about python now. </p> <p>where do you suggest I go from here? I dont want to go through another advanced book again and would like to use the python knowl...
10
2009-07-08T01:50:19Z
1,095,787
<p>You can try my <a href="http://homepage.mac.com/s%5Flott/books/oodesign.html" rel="nofollow">Building Skills in OO Design</a>.</p> <p><a href="http://homepage.mac.com/s_lott/books/oodesign.html" rel="nofollow">http://homepage.mac.com/s_lott/books/oodesign.html</a></p>
7
2009-07-08T01:57:04Z
[ "python" ]
what next after 'dive into python'
1,095,768
<p>I've been meaning to learn another language than java. So I started to poke around with python. I've gone over 'dive into python' so I have a decent knowledge about python now. </p> <p>where do you suggest I go from here? I dont want to go through another advanced book again and would like to use the python knowl...
10
2009-07-08T01:50:19Z
1,095,803
<p>I always find making a small game is a nice way to learn a language <a href="http://www.pygame.org/" rel="nofollow">PyGame</a> makes it simple and could help learn more about python. I suggest giving it ago if your that way inclined. </p>
4
2009-07-08T02:02:55Z
[ "python" ]
what next after 'dive into python'
1,095,768
<p>I've been meaning to learn another language than java. So I started to poke around with python. I've gone over 'dive into python' so I have a decent knowledge about python now. </p> <p>where do you suggest I go from here? I dont want to go through another advanced book again and would like to use the python knowl...
10
2009-07-08T01:50:19Z
1,095,809
<p>That really kind of depends on what you enjoy, or would like to build. Since you haven't said, I'll recommend something I enjoyed instead. <a href="http://rads.stackoverflow.com/amzn/click/0596529325" rel="nofollow" title="Programming Collective Intelligence">Programming Collective Intelligence</a> by Toby Segaran...
12
2009-07-08T02:05:48Z
[ "python" ]
what next after 'dive into python'
1,095,768
<p>I've been meaning to learn another language than java. So I started to poke around with python. I've gone over 'dive into python' so I have a decent knowledge about python now. </p> <p>where do you suggest I go from here? I dont want to go through another advanced book again and would like to use the python knowl...
10
2009-07-08T01:50:19Z
1,095,814
<p>Find an interesting open source project to participate in. You could start looking on <a href="http://pythonsource.com/" rel="nofollow">pythonsource</a> or <a href="http://sourceforge.net/" rel="nofollow">sourceforge</a>.</p>
3
2009-07-08T02:06:45Z
[ "python" ]
what next after 'dive into python'
1,095,768
<p>I've been meaning to learn another language than java. So I started to poke around with python. I've gone over 'dive into python' so I have a decent knowledge about python now. </p> <p>where do you suggest I go from here? I dont want to go through another advanced book again and would like to use the python knowl...
10
2009-07-08T01:50:19Z
1,095,821
<p>The <a href="http://svn.python.org/view/python/trunk/Tools/webchecker/" rel="nofollow">Tools/webchecker/</a> directory, which should be in your Python distribution (otherwise you can get it via the link I gave), is a start -- with lots of limitations (no threading except in <code>wsgui.py</code>, no async operation,...
1
2009-07-08T02:09:40Z
[ "python" ]
what next after 'dive into python'
1,095,768
<p>I've been meaning to learn another language than java. So I started to poke around with python. I've gone over 'dive into python' so I have a decent knowledge about python now. </p> <p>where do you suggest I go from here? I dont want to go through another advanced book again and would like to use the python knowl...
10
2009-07-08T01:50:19Z
1,096,016
<p>To get started with web crawling, consider the Scrapy framework.</p> <p><a href="http://scrapy.org/" rel="nofollow">http://scrapy.org/</a></p> <p>"Scrapy is a high level scraping and web crawling framework for writing spiders to crawl and parse web pages for all kinds of purposes, from information retrieval to mon...
4
2009-07-08T03:31:40Z
[ "python" ]
what next after 'dive into python'
1,095,768
<p>I've been meaning to learn another language than java. So I started to poke around with python. I've gone over 'dive into python' so I have a decent knowledge about python now. </p> <p>where do you suggest I go from here? I dont want to go through another advanced book again and would like to use the python knowl...
10
2009-07-08T01:50:19Z
1,096,045
<p>If you like math try learning Python by solving <a href="http://projecteuler.net/" rel="nofollow">Project Euler problems</a> using python. Each problem is not too much code and it helped me increase my python skills.</p>
5
2009-07-08T03:49:17Z
[ "python" ]
what next after 'dive into python'
1,095,768
<p>I've been meaning to learn another language than java. So I started to poke around with python. I've gone over 'dive into python' so I have a decent knowledge about python now. </p> <p>where do you suggest I go from here? I dont want to go through another advanced book again and would like to use the python knowl...
10
2009-07-08T01:50:19Z
1,096,106
<p>If you wanna "advanced book", I recommend Alex's <a href="http://oreilly.com/catalog/9780596100469/" rel="nofollow">Python in a Nutshell, Second Edition</a>, learn quite a lot from the book, and Tarek's <a href="http://www.packtpub.com/expert-python-programming/book" rel="nofollow">Expert Python Programming</a>,we a...
0
2009-07-08T04:19:19Z
[ "python" ]
what next after 'dive into python'
1,095,768
<p>I've been meaning to learn another language than java. So I started to poke around with python. I've gone over 'dive into python' so I have a decent knowledge about python now. </p> <p>where do you suggest I go from here? I dont want to go through another advanced book again and would like to use the python knowl...
10
2009-07-08T01:50:19Z
1,096,469
<p>If you want to expand beyond web crawling and don't want to start a your own project (or don't know what to do), check out <a href="http://www.pythonchallenge.com/" rel="nofollow">The Python Challenge</a>. It's a game where you have to solve puzzles with a bit of python code. I really enjoyed it.</p>
4
2009-07-08T06:50:53Z
[ "python" ]
what next after 'dive into python'
1,095,768
<p>I've been meaning to learn another language than java. So I started to poke around with python. I've gone over 'dive into python' so I have a decent knowledge about python now. </p> <p>where do you suggest I go from here? I dont want to go through another advanced book again and would like to use the python knowl...
10
2009-07-08T01:50:19Z
1,098,152
<p>Others have said it but I'll repeat: work on something you are interested in or it won't be fun. </p> <p>If you do decide that a crawler would be fun, take a look at <a href="http://code.google.com/p/google-kongulo/" rel="nofollow"><code>google-kongulo</code></a>, web spider plugin for Google desktop search. The co...
0
2009-07-08T13:41:27Z
[ "python" ]
what next after 'dive into python'
1,095,768
<p>I've been meaning to learn another language than java. So I started to poke around with python. I've gone over 'dive into python' so I have a decent knowledge about python now. </p> <p>where do you suggest I go from here? I dont want to go through another advanced book again and would like to use the python knowl...
10
2009-07-08T01:50:19Z
1,099,195
<p>If you're specifically interested in crawling the Web, check out the three-part talk called "Scrape the Web" given at PyCon 2009. It's part of this <a href="http://advocacy.python.org/podcasts/pycon.rss" rel="nofollow">RSS feed</a>.</p>
0
2009-07-08T16:34:03Z
[ "python" ]
what next after 'dive into python'
1,095,768
<p>I've been meaning to learn another language than java. So I started to poke around with python. I've gone over 'dive into python' so I have a decent knowledge about python now. </p> <p>where do you suggest I go from here? I dont want to go through another advanced book again and would like to use the python knowl...
10
2009-07-08T01:50:19Z
12,092,279
<p>Read <em>Dive Into Python</em> again, it discusses <a href="http://www.diveintopython.net/html_processing/index.html" rel="nofollow">HTML processing</a> and <a href="http://www.diveintopython.net/http_web_services/index.html" rel="nofollow">HTTP web services</a> in chapters 8 and 11.</p>
0
2012-08-23T13:06:12Z
[ "python" ]
Comparing and updating array values in Python
1,096,003
<p>I'm developing a Sirius XM radio desktop player in Python, in which I want the ability to display a table of all the channels and what is currently playing on each of them. This channel data is obtained from their website as a JSON string. </p> <p>I'm looking for the best data structure that would allow the cleanes...
1
2009-07-08T03:26:44Z
1,096,014
<p>Why not a dict, with channel number as the key and "what's playing" as the value? Easy to make from JSON, easy to sort (<code>sorted(thedict)</code> sorts by channel, <code>sorted(thedict, key=thedict.get)</code> sorts by value -- all operations are pretty easy (if you specify better exactly what operations you wan...
4
2009-07-08T03:30:44Z
[ "python", "arrays", "list", "data-structures" ]
Comparing and updating array values in Python
1,096,003
<p>I'm developing a Sirius XM radio desktop player in Python, in which I want the ability to display a table of all the channels and what is currently playing on each of them. This channel data is obtained from their website as a JSON string. </p> <p>I'm looking for the best data structure that would allow the cleanes...
1
2009-07-08T03:26:44Z
1,096,290
<p>In this kind of situation, I often use a dict. It looks to me as the simplest solution. </p> <p>I think that Sqlite will cause some unecessary overhead. However it would give you persistence of data. But I guess that your app needs to be online so you don't really need persistence</p>
2
2009-07-08T05:46:11Z
[ "python", "arrays", "list", "data-structures" ]
Override namespace in Python
1,096,216
<p>Say there is a folder, '/home/user/temp/a40bd22344'. The name is completely random and changes in every iteration. I need to be able to import this folder in Python using a fixed name, say 'project'. I know I can add this folder to sys.path to enable import lookup, but is there a way to replace 'a40bd22344' with 'pr...
13
2009-07-08T05:20:31Z
1,096,220
<p>Sure, <code>project = __import__('a40bd22344')</code> after <code>sys.path</code> is set properly will just work.</p> <p>Suppose you want to do it in a function taking the full path as an argument and setting the <em>global</em> import of <code>project</code> properly (as well as magically making <code>import proje...
17
2009-07-08T05:22:28Z
[ "python", "python-import" ]
Override namespace in Python
1,096,216
<p>Say there is a folder, '/home/user/temp/a40bd22344'. The name is completely random and changes in every iteration. I need to be able to import this folder in Python using a fixed name, say 'project'. I know I can add this folder to sys.path to enable import lookup, but is there a way to replace 'a40bd22344' with 'pr...
13
2009-07-08T05:20:31Z
1,096,247
<p>Here's one way to do it, without touching sys.path, using the <code>imp</code> module in Python:</p> <pre><code>import imp f, filename, desc = imp.find_module('a40bd22344', ['/home/user/temp/']) project = imp.load_module('a40bd22344', f, filename, desc) project.some_func() </code></pre> <p>Here is a link to some...
21
2009-07-08T05:33:14Z
[ "python", "python-import" ]
Override namespace in Python
1,096,216
<p>Say there is a folder, '/home/user/temp/a40bd22344'. The name is completely random and changes in every iteration. I need to be able to import this folder in Python using a fixed name, say 'project'. I know I can add this folder to sys.path to enable import lookup, but is there a way to replace 'a40bd22344' with 'pr...
13
2009-07-08T05:20:31Z
1,097,237
<p>You first import it with <strong>import</strong>:</p> <pre><code>&gt;&gt;&gt; __import__('temp/a40bd22344') &lt;module 'temp/a40bd22344' from 'temp/a40bd22344/__init__.py'&gt; </code></pre> <p>Then you make sure that this module gets known to Python as <code>project</code>:</p> <pre><code>&gt;&gt;&gt; import sys ...
19
2009-07-08T10:21:15Z
[ "python", "python-import" ]
Pylons/Routes rewrite POST or GET to fancy URL
1,096,300
<p><strong>The behavior I propose:</strong></p> <p>A user loads up my "search" page, www.site.com/search, types their query into a form, clicks submit, and then ends up at www.site.com/search/the+query instead of www.site.com/search?q=the+query. I've gone through a lot of the Pylons documentation already and just fini...
2
2009-07-08T05:49:59Z
1,096,315
<p>HTML forms are designed to go to a specific URL with a query string (<code>?q=</code>) or an equivalent body in a <code>POST</code> -- either you write clever and subtle Javascript to intercept the form submission and rewrite it in your preferred weird way, or use <code>redirect_to</code> (and the latter will take s...
2
2009-07-08T05:56:42Z
[ "python", "routes", "pylons" ]
Pylons/Routes rewrite POST or GET to fancy URL
1,096,300
<p><strong>The behavior I propose:</strong></p> <p>A user loads up my "search" page, www.site.com/search, types their query into a form, clicks submit, and then ends up at www.site.com/search/the+query instead of www.site.com/search?q=the+query. I've gone through a lot of the Pylons documentation already and just fini...
2
2009-07-08T05:49:59Z
1,097,943
<p>You can send whatever content you want for any URL, but if you want a particular URL to appear in the browser's address bar, you have to use a redirect. This is independent of whether you use Pylons, Django or Rails on the server side.</p> <p>In the handling for <code>/search</code> (whether <code>POST</code> or <c...
2
2009-07-08T13:03:58Z
[ "python", "routes", "pylons" ]
How to make urllib2 requests through Tor in Python?
1,096,379
<p>I'm trying to crawl websites using a crawler written in Python. I want to integrate Tor with Python meaning I want to crawl the site anonymously using Tor.</p> <p>I tried doing this. It doesn't seem to work. I checked my IP it is still the same as the one before I used tor. I checked it via python.</p> <pre><code>...
41
2009-07-08T06:22:08Z
1,096,419
<p>Perhaps you're having some network connectivity issues? The above script worked for me (I substituted a different URL - I used <code>http://stackoverflow.com/</code> - and I get the page as expected:</p> <pre><code>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd" &gt; &l...
1
2009-07-08T06:34:44Z
[ "python", "tor" ]
How to make urllib2 requests through Tor in Python?
1,096,379
<p>I'm trying to crawl websites using a crawler written in Python. I want to integrate Tor with Python meaning I want to crawl the site anonymously using Tor.</p> <p>I tried doing this. It doesn't seem to work. I checked my IP it is still the same as the one before I used tor. I checked it via python.</p> <pre><code>...
41
2009-07-08T06:22:08Z
1,097,697
<p>Using privoxy as http-proxy in front of tor works for me - here's a crawler-template:</p> <pre><code> import urllib2 import httplib from BeautifulSoup import BeautifulSoup from time import sleep class Scraper(object): def __init__(self, options, args): if options.proxy is None: options.pro...
2
2009-07-08T12:13:35Z
[ "python", "tor" ]
How to make urllib2 requests through Tor in Python?
1,096,379
<p>I'm trying to crawl websites using a crawler written in Python. I want to integrate Tor with Python meaning I want to crawl the site anonymously using Tor.</p> <p>I tried doing this. It doesn't seem to work. I checked my IP it is still the same as the one before I used tor. I checked it via python.</p> <pre><code>...
41
2009-07-08T06:22:08Z
2,015,649
<p>You are trying to connect to a SOCKS port - Tor rejects any non-SOCKS traffic. You can connect through a middleman - Privoxy - using Port 8118.</p> <p>Example:</p> <pre><code>proxy_support = urllib2.ProxyHandler({"http" : "127.0.0.1:8118"}) opener = urllib2.build_opener(proxy_support) opener.addheaders = [('User-...
19
2010-01-06T19:37:37Z
[ "python", "tor" ]
How to make urllib2 requests through Tor in Python?
1,096,379
<p>I'm trying to crawl websites using a crawler written in Python. I want to integrate Tor with Python meaning I want to crawl the site anonymously using Tor.</p> <p>I tried doing this. It doesn't seem to work. I checked my IP it is still the same as the one before I used tor. I checked it via python.</p> <pre><code>...
41
2009-07-08T06:22:08Z
9,037,155
<p>Here is a code for downloading files using tor proxy in python: (update url)</p> <pre><code>import urllib2 url = "http://www.disneypicture.net/data/media/17/Donald_Duck2.gif" proxy = urllib2.ProxyHandler({'http': '127.0.0.1:8118'}) opener = urllib2.build_opener(proxy) urllib2.install_opener(opener) file_name = u...
2
2012-01-27T17:02:29Z
[ "python", "tor" ]
How to make urllib2 requests through Tor in Python?
1,096,379
<p>I'm trying to crawl websites using a crawler written in Python. I want to integrate Tor with Python meaning I want to crawl the site anonymously using Tor.</p> <p>I tried doing this. It doesn't seem to work. I checked my IP it is still the same as the one before I used tor. I checked it via python.</p> <pre><code>...
41
2009-07-08T06:22:08Z
30,404,083
<p>The following code is 100% working on Python 3.4</p> <p>(you need to keep TOR Browser open wil using this code)</p> <p>This script connects to TOR through socks5 get the IP from checkip.dyn.com, change identity and resend the request to get a the new IP (loops 10 times)</p> <p>You need to install the appropriate ...
2
2015-05-22T19:01:22Z
[ "python", "tor" ]
How to make urllib2 requests through Tor in Python?
1,096,379
<p>I'm trying to crawl websites using a crawler written in Python. I want to integrate Tor with Python meaning I want to crawl the site anonymously using Tor.</p> <p>I tried doing this. It doesn't seem to work. I checked my IP it is still the same as the one before I used tor. I checked it via python.</p> <pre><code>...
41
2009-07-08T06:22:08Z
30,649,544
<p>Tor is a socks proxy. Connecting to it directly with <a href="http://sacharya.com/crawling-anonymously-with-tor-in-python/" rel="nofollow">the example you cite</a> fails with "urlopen error Tunnel connection failed: 501 Tor is not an HTTP Proxy". As others have mentioned you can get around this with Privoxy.</p> <p...
0
2015-06-04T16:41:28Z
[ "python", "tor" ]
How to make urllib2 requests through Tor in Python?
1,096,379
<p>I'm trying to crawl websites using a crawler written in Python. I want to integrate Tor with Python meaning I want to crawl the site anonymously using Tor.</p> <p>I tried doing this. It doesn't seem to work. I checked my IP it is still the same as the one before I used tor. I checked it via python.</p> <pre><code>...
41
2009-07-08T06:22:08Z
33,875,868
<p>Even though this is an old post, answering because no one seems to have mentioned the <a href="https://pypi.python.org/pypi/requesocks" rel="nofollow"><code>requesocks</code></a> library.</p> <p>It is basically a port of the <a href="http://docs.python-requests.org/en/latest/" rel="nofollow"><code>requests</code></...
2
2015-11-23T16:28:09Z
[ "python", "tor" ]
How to make urllib2 requests through Tor in Python?
1,096,379
<p>I'm trying to crawl websites using a crawler written in Python. I want to integrate Tor with Python meaning I want to crawl the site anonymously using Tor.</p> <p>I tried doing this. It doesn't seem to work. I checked my IP it is still the same as the one before I used tor. I checked it via python.</p> <pre><code>...
41
2009-07-08T06:22:08Z
34,493,721
<pre><code>pip install PySocks </code></pre> <p>Then:</p> <pre><code>import socket import socks import urllib2 ipcheck_url = 'http://checkip.amazonaws.com/' # Actual IP. print(urllib2.urlopen(ipcheck_url).read()) # Tor IP. socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, '127.0.0.1', 9050) socket.socket = socks.sock...
3
2015-12-28T12:40:16Z
[ "python", "tor" ]
What is the easiest way to handle dates/times in Python?
1,096,396
<p>My use case is that I'm just making a website that I want people all over the world to be able to use, and I want to be able to say things like "This happened at 5:33pm on October 5" and also "This happened 5 minutes ago," etc.</p> <p>Should I use the datetime module? Or just strftime? Or something fancier that is...
1
2009-07-08T06:29:03Z
1,096,409
<p>Take a look at the dateutil module:</p> <p><a href="http://labix.org/python-dateutil" rel="nofollow">http://labix.org/python-dateutil</a></p> <p>It's good at doing the types of things you're looking for - see some of the examples in the documentation.</p>
2
2009-07-08T06:32:55Z
[ "python", "datetime" ]
What is the easiest way to handle dates/times in Python?
1,096,396
<p>My use case is that I'm just making a website that I want people all over the world to be able to use, and I want to be able to say things like "This happened at 5:33pm on October 5" and also "This happened 5 minutes ago," etc.</p> <p>Should I use the datetime module? Or just strftime? Or something fancier that is...
1
2009-07-08T06:29:03Z
1,096,413
<p>If you're going to use <code>datetime</code>, make sure you read this recent and most excellent article: <a href="http://www.enricozini.org/2009/debian/using-python-datetime/" rel="nofollow">Tips on using python's datetime module</a>. <code>datetime</code> will take care of most of the niceties of handling time ari...
1
2009-07-08T06:33:22Z
[ "python", "datetime" ]
What is the easiest way to handle dates/times in Python?
1,096,396
<p>My use case is that I'm just making a website that I want people all over the world to be able to use, and I want to be able to say things like "This happened at 5:33pm on October 5" and also "This happened 5 minutes ago," etc.</p> <p>Should I use the datetime module? Or just strftime? Or something fancier that is...
1
2009-07-08T06:29:03Z
1,096,415
<p>I have always been very happy using the datetime package. You get a lot of stuff for free, and it's pretty easy to create datetime objects as well, calculate duration ect.</p>
0
2009-07-08T06:33:46Z
[ "python", "datetime" ]
What is the easiest way to handle dates/times in Python?
1,096,396
<p>My use case is that I'm just making a website that I want people all over the world to be able to use, and I want to be able to say things like "This happened at 5:33pm on October 5" and also "This happened 5 minutes ago," etc.</p> <p>Should I use the datetime module? Or just strftime? Or something fancier that is...
1
2009-07-08T06:29:03Z
1,096,445
<p>There is also the <a href="http://docs.python.org/library/time.html" rel="nofollow">Time module</a>.</p>
0
2009-07-08T06:42:28Z
[ "python", "datetime" ]
What is the easiest way to handle dates/times in Python?
1,096,396
<p>My use case is that I'm just making a website that I want people all over the world to be able to use, and I want to be able to say things like "This happened at 5:33pm on October 5" and also "This happened 5 minutes ago," etc.</p> <p>Should I use the datetime module? Or just strftime? Or something fancier that is...
1
2009-07-08T06:29:03Z
1,096,455
<p>The datetime module in Python will allow you to get/set/manipulate dates and times. A question about relative date formatting in Python has already been asked: <a href="http://stackoverflow.com/questions/410221/natural-relative-days-in-python">Stack Overflow Post</a> but with very little responce. </p>
1
2009-07-08T06:47:06Z
[ "python", "datetime" ]
What is the easiest way to handle dates/times in Python?
1,096,396
<p>My use case is that I'm just making a website that I want people all over the world to be able to use, and I want to be able to say things like "This happened at 5:33pm on October 5" and also "This happened 5 minutes ago," etc.</p> <p>Should I use the datetime module? Or just strftime? Or something fancier that is...
1
2009-07-08T06:29:03Z
1,096,495
<p>You may have a look at Django's <a href="http://docs.djangoproject.com/en/dev/ref/contrib/humanize/#ref-contrib-humanize" rel="nofollow">humanize module</a>.<br /> It is part of Django, but I think it would be quite easy to adapt it to your needs.</p>
2
2009-07-08T06:58:00Z
[ "python", "datetime" ]
What is the easiest way to handle dates/times in Python?
1,096,396
<p>My use case is that I'm just making a website that I want people all over the world to be able to use, and I want to be able to say things like "This happened at 5:33pm on October 5" and also "This happened 5 minutes ago," etc.</p> <p>Should I use the datetime module? Or just strftime? Or something fancier that is...
1
2009-07-08T06:29:03Z
1,096,688
<p>Try <a href="http://jehiah.cz/archive/printing-relative-dates-in-python" rel="nofollow">relativeDates Module</a> module. It exactly brings you the stuff you wanted.</p>
1
2009-07-08T07:57:58Z
[ "python", "datetime" ]
Display triangles in 3D using Python
1,096,476
<p>Disclaimer: The context is a project I'm working on as part of my Master's degree. I guess it qualifies as homework.</p> <p><hr /></p> <h2>Introduction</h2> <p>(feel free to skip to the bottom line)</p> <p>Curved 3D surfaces are commonly displayed as a large set of very small triangles. Each triangle has the ...
1
2009-07-08T06:52:18Z
1,096,521
<p>Well, that depends, very much, like which OS you are using, do you need to be portable, etc.</p> <p>But a generic answer is probably to use something like OpenGL, which is a portable API, and has Python bindings. <a href="http://pyopengl.sourceforge.net/" rel="nofollow">http://pyopengl.sourceforge.net/</a></p> <p>...
7
2009-07-08T07:05:35Z
[ "python", "3d", "geometry" ]
Display triangles in 3D using Python
1,096,476
<p>Disclaimer: The context is a project I'm working on as part of my Master's degree. I guess it qualifies as homework.</p> <p><hr /></p> <h2>Introduction</h2> <p>(feel free to skip to the bottom line)</p> <p>Curved 3D surfaces are commonly displayed as a large set of very small triangles. Each triangle has the ...
1
2009-07-08T06:52:18Z
1,096,539
<p>EDIT: I misread your question. This is only for 2D:</p> <p>You can use a wx.Canvas of <a href="http://www.wxpython.org/" rel="nofollow">wxpython</a> or implement your application using <a href="http://www.pygame.org/" rel="nofollow">pygame</a>. </p>
0
2009-07-08T07:10:48Z
[ "python", "3d", "geometry" ]
Display triangles in 3D using Python
1,096,476
<p>Disclaimer: The context is a project I'm working on as part of my Master's degree. I guess it qualifies as homework.</p> <p><hr /></p> <h2>Introduction</h2> <p>(feel free to skip to the bottom line)</p> <p>Curved 3D surfaces are commonly displayed as a large set of very small triangles. Each triangle has the ...
1
2009-07-08T06:52:18Z
1,097,876
<p>Here's an example integrating OpenGL with wxPython.</p> <p><a href="http://code.activestate.com/recipes/325392/" rel="nofollow">http://code.activestate.com/recipes/325392/</a></p>
2
2009-07-08T12:52:47Z
[ "python", "3d", "geometry" ]
Combining two JSON objects in to one
1,096,554
<p>I have two JSON objects. One is python array which is converted using json,dumps() and other contains records from database and is serialized using json serializer. I want to combine them into a single JSON object. </p> <p>For eg: </p> <pre><code>obj1 = ["a1", "a2", "a3"] obj2 = [ { "pk": "e1", ...
6
2009-07-08T07:13:13Z
1,096,575
<p>You can't do it once they're in JSON format - JSON is just text. You need to combine them in Python first:</p> <pre><code>data = { 'obj1' : obj1, 'obj2' : obj2 } json.dumps(data) </code></pre>
13
2009-07-08T07:19:26Z
[ "python", "json" ]
Combining two JSON objects in to one
1,096,554
<p>I have two JSON objects. One is python array which is converted using json,dumps() and other contains records from database and is serialized using json serializer. I want to combine them into a single JSON object. </p> <p>For eg: </p> <pre><code>obj1 = ["a1", "a2", "a3"] obj2 = [ { "pk": "e1", ...
6
2009-07-08T07:13:13Z
1,096,580
<p>Not sure if I'm missing something, but I think this works (tested in python 2.5) with the output you specify:</p> <pre><code>import simplejson finalObj = { 'obj1': obj1, 'obj2': obj2 } simplejson.dumps(finalObj) </code></pre>
6
2009-07-08T07:20:48Z
[ "python", "json" ]
Combining two JSON objects in to one
1,096,554
<p>I have two JSON objects. One is python array which is converted using json,dumps() and other contains records from database and is serialized using json serializer. I want to combine them into a single JSON object. </p> <p>For eg: </p> <pre><code>obj1 = ["a1", "a2", "a3"] obj2 = [ { "pk": "e1", ...
6
2009-07-08T07:13:13Z
1,097,257
<p>You have two techniques. The list version suffers from the limitation that the order matters. However, the JSON is slightly simpler-looking. The dictionary version has nested data, which looks more complex.</p> <pre><code>data = { 'obj1' : obj1, 'obj2' : obj2 } json.dumps(data,indent=2) data = [ obj1, obj2 ] j...
1
2009-07-08T10:25:51Z
[ "python", "json" ]
Incorporate custom template into the django admin interface and session
1,096,607
<p>I have made a custom formwizard and incorporated it into my admin interface.</p> <p>Basically I have taken the change_form.html and left it under the admin interface url:</p> <pre><code> (r'^admin/compilation/evaluation/add/$', EvaluationWizard([EvaluationForm1, EvaluationForm2])), </code></pre> <p>It works, b...
0
2009-07-08T07:29:52Z
1,097,055
<p>If you need to make sure only authorised users access the page, you need to check for an admin user in your request handler. This will be the <code>__call__</code> method in your EvaluationWizard class.</p> <p>Basically, the logic used by the admin is available for viewing <a href="http://code.djangoproject.com/bro...
1
2009-07-08T09:27:23Z
[ "python", "django", "django-admin", "django-templates" ]
Can I view the doc string of a function in Python using VIM?
1,096,912
<p>Is there any way to view a function's doc string when writing Python in VIM?</p> <p>For instance:</p> <pre><code>def MyFunction(spam): """A function that foobars the spam returns eggs""" return foobar(spam).eggs() </code></pre> <p>I'd like to be able to type <code>MyFunction(spam0)</code> and see the...
8
2009-07-08T08:50:39Z
1,096,952
<p>The <a href="http://www.vim.org/scripts/script.php?script%5Fid=1542" rel="nofollow">pythoncomplete script</a> is probably what you are looking for.</p>
2
2009-07-08T08:58:44Z
[ "python", "vim", "docstring" ]
Can python mechanize handle HTTP auth?
1,097,380
<p>Mechanize (Python) is failing with 401 for me to open http digest URLs. I googled and tried debugging but no success. </p> <p>My code looks like this.</p> <pre><code>import mechanize project = "test" baseurl = "http://trac.somewhere.net" loginurl = "%s/%s/login" % (baseurl, project) b = mechanize.Browser() b.add_...
4
2009-07-08T11:03:27Z
1,097,614
<p>Mechanize claims that the parameters should be uri, username and password as parameters, but you have four parameters. Four parameters are correct for urllib2.add_password, but then the first parameter should be the realm, not the uri.</p> <p><a href="http://wwwsearch.sourceforge.net/mechanize/" rel="nofollow">http...
6
2009-07-08T11:57:21Z
[ "python", "mechanize" ]
Can python mechanize handle HTTP auth?
1,097,380
<p>Mechanize (Python) is failing with 401 for me to open http digest URLs. I googled and tried debugging but no success. </p> <p>My code looks like this.</p> <pre><code>import mechanize project = "test" baseurl = "http://trac.somewhere.net" loginurl = "%s/%s/login" % (baseurl, project) b = mechanize.Browser() b.add_...
4
2009-07-08T11:03:27Z
1,097,732
<p>Depending on how complex your web automation project is, consider using iMacros. Unlike Mechanize it runs in the web browser, so it works with most websites out of the box.</p> <p>I use both the free Firefox addon via a command line (on our Linux server) and the iMacros Scripting Edition via COM object (on a Window...
0
2009-07-08T12:22:37Z
[ "python", "mechanize" ]
Can python mechanize handle HTTP auth?
1,097,380
<p>Mechanize (Python) is failing with 401 for me to open http digest URLs. I googled and tried debugging but no success. </p> <p>My code looks like this.</p> <pre><code>import mechanize project = "test" baseurl = "http://trac.somewhere.net" loginurl = "%s/%s/login" % (baseurl, project) b = mechanize.Browser() b.add_...
4
2009-07-08T11:03:27Z
2,659,135
<p>#!/usr/bin/env python # -<em>- coding: utf-8 -</em>- </p> <pre><code>import mechanize a=mechanize.Browser() a.open("http://www.facebook.com/login.php") a.select_form(nr=0) #form number. a["email"]="mailaddress" a["pass"]="password" a.submit() print a </code></pre>
1
2010-04-17T16:35:43Z
[ "python", "mechanize" ]
Can python mechanize handle HTTP auth?
1,097,380
<p>Mechanize (Python) is failing with 401 for me to open http digest URLs. I googled and tried debugging but no success. </p> <p>My code looks like this.</p> <pre><code>import mechanize project = "test" baseurl = "http://trac.somewhere.net" loginurl = "%s/%s/login" % (baseurl, project) b = mechanize.Browser() b.add_...
4
2009-07-08T11:03:27Z
4,089,075
<p>For http authentication with mechanize you need to provide the complete url to the <code>add_password</code> method and not just the host base address.</p> <pre><code>import mechanize project = "test" baseurl = "http://trac.somewhere.net" loginurl = "%s/%s/login" % (baseurl, project) b = mechanize.Browser() b.add_...
3
2010-11-03T16:08:49Z
[ "python", "mechanize" ]
How to get repository for core-plot
1,097,711
<p>I am not able to get the repository for core-plot. What I am doing is that I am typing this in the terminal:</p> <pre><code>hg clone https://core-plot.googlecode.com/hg/ core-plot </code></pre> <p>and this is what I get:</p> <pre> Traceback (most recent call last): File "/usr/local/bin/hg", line 25, in mercuria...
0
2009-07-08T12:16:56Z
1,098,101
<p>Have you installed Mercurial on your computer? If not, you can download an installer here: <a href="http://mercurial.berkwood.com/" rel="nofollow">http://mercurial.berkwood.com/</a></p>
1
2009-07-08T13:30:42Z
[ "python", "osx", "mercurial", "terminal", "core-plot" ]
How to get repository for core-plot
1,097,711
<p>I am not able to get the repository for core-plot. What I am doing is that I am typing this in the terminal:</p> <pre><code>hg clone https://core-plot.googlecode.com/hg/ core-plot </code></pre> <p>and this is what I get:</p> <pre> Traceback (most recent call last): File "/usr/local/bin/hg", line 25, in mercuria...
0
2009-07-08T12:16:56Z
1,098,304
<p>The repository works perfectly fine:</p> <pre><code>↪ hg clone https://core-plot.googlecode.com/hg/ core-plot requesting all changes adding changesets adding manifests adding file changes added 406 changesets with 3444 changes to 1861 files updating working directory 1018 files updated, 0 files merged, 0 files re...
0
2009-07-08T14:06:06Z
[ "python", "osx", "mercurial", "terminal", "core-plot" ]
How to get repository for core-plot
1,097,711
<p>I am not able to get the repository for core-plot. What I am doing is that I am typing this in the terminal:</p> <pre><code>hg clone https://core-plot.googlecode.com/hg/ core-plot </code></pre> <p>and this is what I get:</p> <pre> Traceback (most recent call last): File "/usr/local/bin/hg", line 25, in mercuria...
0
2009-07-08T12:16:56Z
1,104,685
<p>It looks like you're having a problem with your locale. Are you using Leopard? If so, check your Terminal preferences. In the Terminal prefs, open up the Settings pane, and click the Advanced tab. The "Character Encoding" menu should be set to "Unicode (UTF-8)". Also make sure that "Set LANG variable on startup" is ...
1
2009-07-09T15:35:23Z
[ "python", "osx", "mercurial", "terminal", "core-plot" ]
How to get repository for core-plot
1,097,711
<p>I am not able to get the repository for core-plot. What I am doing is that I am typing this in the terminal:</p> <pre><code>hg clone https://core-plot.googlecode.com/hg/ core-plot </code></pre> <p>and this is what I get:</p> <pre> Traceback (most recent call last): File "/usr/local/bin/hg", line 25, in mercuria...
0
2009-07-08T12:16:56Z
1,106,587
<p>It looks to me like you have a broken Python installation. However, since you're trying to get Mercurial working, please contact the Mercurial team through the correct channels. Use the</p> <ul> <li><strong><a href="http://mercurial.selenic.com/wiki/MailingLists" rel="nofollow">Mercurial mailinglist</a></strong> or...
0
2009-07-09T21:34:51Z
[ "python", "osx", "mercurial", "terminal", "core-plot" ]
How to get repository for core-plot
1,097,711
<p>I am not able to get the repository for core-plot. What I am doing is that I am typing this in the terminal:</p> <pre><code>hg clone https://core-plot.googlecode.com/hg/ core-plot </code></pre> <p>and this is what I get:</p> <pre> Traceback (most recent call last): File "/usr/local/bin/hg", line 25, in mercuria...
0
2009-07-08T12:16:56Z
1,141,724
<p>LANG can be overridden by HGENCODING. If "echo $HGENCODING" produces "UTF-8" that's your culprit. Unset it or set it to en_US.UTF-8 (or whatever language you prefer, but it should end in .UTF-8). You could also try setting HGENCODING or LANG to "C" if you have no need for non-ascii characters, or just as a test.</p>...
0
2009-07-17T06:45:16Z
[ "python", "osx", "mercurial", "terminal", "core-plot" ]
How to get repository for core-plot
1,097,711
<p>I am not able to get the repository for core-plot. What I am doing is that I am typing this in the terminal:</p> <pre><code>hg clone https://core-plot.googlecode.com/hg/ core-plot </code></pre> <p>and this is what I get:</p> <pre> Traceback (most recent call last): File "/usr/local/bin/hg", line 25, in mercuria...
0
2009-07-08T12:16:56Z
1,717,970
<p>See following question here,</p> <p><a href="http://stackoverflow.com/questions/1694539/how-to-create-line-chart-in-iphone-application/1717734#1717734">http://stackoverflow.com/questions/1694539/how-to-create-line-chart-in-iphone-application/1717734#1717734</a></p> <p>I have added my answer there for the same one....
0
2009-11-11T20:49:33Z
[ "python", "osx", "mercurial", "terminal", "core-plot" ]
How do I sort unicode strings alphabetically in Python?
1,097,908
<p>Python sorts by byte value by default, which means é comes after z and other equally funny things. What is the best way to sort alphabetically in Python?</p> <p>Is there a library for this? I couldn't find anything. Preferrably sorting should have language support so it understands that åäö should be sorted aft...
78
2009-07-08T12:59:09Z
1,097,961
<p>Try James Tauber's <a href="http://jtauber.com/blog/2006/01/27/python%5Funicode%5Fcollation%5Falgorithm/">Python Unicode Collation Algorithm</a>. It may not do exactly as you want, but seems well worth a look. For a bit more information about the issues, see <a href="http://www.cmlenz.net/archives/2008/07/the-truth-...
9
2009-07-08T13:08:24Z
[ "python", "sorting", "unicode", "internationalization", "collation" ]
How do I sort unicode strings alphabetically in Python?
1,097,908
<p>Python sorts by byte value by default, which means é comes after z and other equally funny things. What is the best way to sort alphabetically in Python?</p> <p>Is there a library for this? I couldn't find anything. Preferrably sorting should have language support so it understands that åäö should be sorted aft...
78
2009-07-08T12:59:09Z
1,097,980
<p>Jeff Atwood wrote a good post on <a href="http://www.codinghorror.com/blog/archives/001018.html" rel="nofollow">Natural Sort Order</a>, in it he linked to a script which does <a href="http://personal.inet.fi/cool/operator/Human%20Sort.py" rel="nofollow">pretty much what you ask</a>.</p> <p>It's not a trivial script...
1
2009-07-08T13:11:58Z
[ "python", "sorting", "unicode", "internationalization", "collation" ]
How do I sort unicode strings alphabetically in Python?
1,097,908
<p>Python sorts by byte value by default, which means é comes after z and other equally funny things. What is the best way to sort alphabetically in Python?</p> <p>Is there a library for this? I couldn't find anything. Preferrably sorting should have language support so it understands that åäö should be sorted aft...
78
2009-07-08T12:59:09Z
1,097,994
<p>To implement it you will need to read about "Unicode collation algorithm" see <a href="http://en.wikipedia.org/wiki/Unicode_collation_algorithm" rel="nofollow">http://en.wikipedia.org/wiki/Unicode_collation_algorithm</a></p> <p><a href="http://www.unicode.org/unicode/reports/tr10/" rel="nofollow">http://www.unicode...
2
2009-07-08T13:13:38Z
[ "python", "sorting", "unicode", "internationalization", "collation" ]
How do I sort unicode strings alphabetically in Python?
1,097,908
<p>Python sorts by byte value by default, which means é comes after z and other equally funny things. What is the best way to sort alphabetically in Python?</p> <p>Is there a library for this? I couldn't find anything. Preferrably sorting should have language support so it understands that åäö should be sorted aft...
78
2009-07-08T12:59:09Z
1,098,160
<p>IBM's <a href="http://site.icu-project.org/">ICU</a> library does that (and a lot more). It has Python bindings: <a href="http://pypi.python.org/pypi/PyICU">PyICU</a>. </p> <p><strong>Update</strong>: The core difference in sorting between ICU and <code>locale.strcoll</code> is that ICU uses the full <a href="http:...
57
2009-07-08T13:42:40Z
[ "python", "sorting", "unicode", "internationalization", "collation" ]
How do I sort unicode strings alphabetically in Python?
1,097,908
<p>Python sorts by byte value by default, which means é comes after z and other equally funny things. What is the best way to sort alphabetically in Python?</p> <p>Is there a library for this? I couldn't find anything. Preferrably sorting should have language support so it understands that åäö should be sorted aft...
78
2009-07-08T12:59:09Z
1,098,616
<p>I see the answers have already done an excellent job, just wanted to point out one coding inefficiency in <a href="http://personal.inet.fi/cool/operator/Human%20Sort.py" rel="nofollow">Human Sort</a>. To apply a selective char-by-char translation to a unicode string s, it uses the code:</p> <pre><code>spec_dict = {...
6
2009-07-08T14:57:16Z
[ "python", "sorting", "unicode", "internationalization", "collation" ]
How do I sort unicode strings alphabetically in Python?
1,097,908
<p>Python sorts by byte value by default, which means é comes after z and other equally funny things. What is the best way to sort alphabetically in Python?</p> <p>Is there a library for this? I couldn't find anything. Preferrably sorting should have language support so it understands that åäö should be sorted aft...
78
2009-07-08T12:59:09Z
1,098,751
<p>It is far from a complete solution for your use case, but you could take a look at the <a href="http://svn.effbot.org/public/stuff/sandbox/text/unaccent.py" rel="nofollow">unaccent.py</a> script from effbot.org. What it basically does is remove all accents from a text. You can use that 'sanitized' text to sort alpha...
0
2009-07-08T15:18:03Z
[ "python", "sorting", "unicode", "internationalization", "collation" ]
How do I sort unicode strings alphabetically in Python?
1,097,908
<p>Python sorts by byte value by default, which means é comes after z and other equally funny things. What is the best way to sort alphabetically in Python?</p> <p>Is there a library for this? I couldn't find anything. Preferrably sorting should have language support so it understands that åäö should be sorted aft...
78
2009-07-08T12:59:09Z
1,318,709
<p>I don't see this in the answers. My Application sorts according to the locale using python's standard library. It is pretty easy.</p> <pre><code># python2.5 code below # corpus is our unicode() strings collection as a list corpus = [u"Art", u"Älg", u"Ved", u"Wasa"] import locale # this reads the environment and i...
41
2009-08-23T14:32:43Z
[ "python", "sorting", "unicode", "internationalization", "collation" ]
How do I sort unicode strings alphabetically in Python?
1,097,908
<p>Python sorts by byte value by default, which means é comes after z and other equally funny things. What is the best way to sort alphabetically in Python?</p> <p>Is there a library for this? I couldn't find anything. Preferrably sorting should have language support so it understands that åäö should be sorted aft...
78
2009-07-08T12:59:09Z
5,013,415
<p>A summary and extended answer:</p> <p><code>locale.strcoll</code> under Python 2, and <code>locale.strxfrm</code> will in fact solve the problem, and does a good job, assuming that you have the locale in question installed. I tested it under Windows too, where the locale names confusingly are different, but on the ...
7
2011-02-16T07:00:15Z
[ "python", "sorting", "unicode", "internationalization", "collation" ]
How do I sort unicode strings alphabetically in Python?
1,097,908
<p>Python sorts by byte value by default, which means é comes after z and other equally funny things. What is the best way to sort alphabetically in Python?</p> <p>Is there a library for this? I couldn't find anything. Preferrably sorting should have language support so it understands that åäö should be sorted aft...
78
2009-07-08T12:59:09Z
5,024,116
<h1>A Complete UCA Solution</h1> <p>The simplest, easiest, and most straightforward way to do this it to make a callout to the Perl library module, <a href="http://search.cpan.org/perldoc?Unicode%3A%3ACollate%3A%3ALocale" rel="nofollow">Unicode::Collate::Locale</a>, which is a subclass of the standard <a href="http:/...
3
2011-02-17T01:19:02Z
[ "python", "sorting", "unicode", "internationalization", "collation" ]
How do I sort unicode strings alphabetically in Python?
1,097,908
<p>Python sorts by byte value by default, which means é comes after z and other equally funny things. What is the best way to sort alphabetically in Python?</p> <p>Is there a library for this? I couldn't find anything. Preferrably sorting should have language support so it understands that åäö should be sorted aft...
78
2009-07-08T12:59:09Z
8,535,192
<p>You might also be interested in <strong>pyuca</strong>:</p> <p><a href="http://jtauber.com/blog/2006/01/27/python_unicode_collation_algorithm/">http://jtauber.com/blog/2006/01/27/python_unicode_collation_algorithm/</a></p> <p>Though it is certainly not the most exact way, it is a very simple way to at least get it...
6
2011-12-16T13:54:45Z
[ "python", "sorting", "unicode", "internationalization", "collation" ]
How do I sort unicode strings alphabetically in Python?
1,097,908
<p>Python sorts by byte value by default, which means é comes after z and other equally funny things. What is the best way to sort alphabetically in Python?</p> <p>Is there a library for this? I couldn't find anything. Preferrably sorting should have language support so it understands that åäö should be sorted aft...
78
2009-07-08T12:59:09Z
16,480,912
<p>Lately I've been using zope.ucol (<a href="https://pypi.python.org/pypi/zope.ucol" rel="nofollow">https://pypi.python.org/pypi/zope.ucol</a>) for this task. For example, sorting the german ß:</p> <pre><code>&gt;&gt;&gt; import zope.ucol &gt;&gt;&gt; collator = zope.ucol.Collator("de-de") &gt;&gt;&gt; mylist = [u"a...
1
2013-05-10T11:08:14Z
[ "python", "sorting", "unicode", "internationalization", "collation" ]
How to empty a socket in python?
1,097,974
<p>I need to empty the data on a socket (making sure that there is nothing to receive). Unfortunately, there is no function for this in the python socket module.</p> <p>I've implemented something this way:</p> <pre><code>def empty_socket(sock): """remove the data present on the socket""" input = [sock] wh...
5
2009-07-08T13:10:12Z
1,098,016
<p>Not sure if this will work, but you could attach a file object to the socket's file descriptor and call the <code>flush()</code> method on that file object:</p> <pre><code>import os file_obj = os.fdopen(your_socket.fileno()) file_obj.flush() </code></pre> <p>This won't work in Windows because the descriptor retur...
-1
2009-07-08T13:18:16Z
[ "python", "sockets", "select" ]
How to empty a socket in python?
1,097,974
<p>I need to empty the data on a socket (making sure that there is nothing to receive). Unfortunately, there is no function for this in the python socket module.</p> <p>I've implemented something this way:</p> <pre><code>def empty_socket(sock): """remove the data present on the socket""" input = [sock] wh...
5
2009-07-08T13:10:12Z
1,098,025
<p>Using <code>select.select</code> is good practice, as indicated in the <a href="http://www.amk.ca/python/howto/sockets/sockets.html#SECTION000600000000000000000" rel="nofollow">Socket Programming HOWTO</a>. You'll need to set the socket as non-blocking, using <code>sock.setblocking(0)</code>.</p> <p>Just a comment ...
1
2009-07-08T13:19:32Z
[ "python", "sockets", "select" ]
How to empty a socket in python?
1,097,974
<p>I need to empty the data on a socket (making sure that there is nothing to receive). Unfortunately, there is no function for this in the python socket module.</p> <p>I've implemented something this way:</p> <pre><code>def empty_socket(sock): """remove the data present on the socket""" input = [sock] wh...
5
2009-07-08T13:10:12Z
1,098,216
<p>If by "flush" you mean throw away any pending incoming data then you can either use select() like you do, or set the socket to nonblocking and read in a loop until you're out of data.</p> <p>Also note that (from the Linux manpage):</p> <blockquote> <p>Under Linux, select() may report a socket file descriptor as ...
6
2009-07-08T13:51:46Z
[ "python", "sockets", "select" ]
How to empty a socket in python?
1,097,974
<p>I need to empty the data on a socket (making sure that there is nothing to receive). Unfortunately, there is no function for this in the python socket module.</p> <p>I've implemented something this way:</p> <pre><code>def empty_socket(sock): """remove the data present on the socket""" input = [sock] wh...
5
2009-07-08T13:10:12Z
23,276,613
<p>For UDP packets, I did the following:</p> <ol> <li><p>After creating the socket, setting options, and binding, I use <code>socket.settimeout()</code>. Note the documentation for <a href="https://docs.python.org/3.4/library/socket.html#socket.socket.setblocking" rel="nofollow"><code>setblocking()</code></a> gives so...
0
2014-04-24T18:10:29Z
[ "python", "sockets", "select" ]
Stripping spaces between XML nodes with Python
1,098,118
<p>Is there a easy way to accomplish the same thing in Python as xsl accomplishes with:</p> <pre><code>&lt;xsl:strip-space elements="*"/&gt; </code></pre> <p>So for instance in the following </p> <pre><code>for event, elem in ElementTree.iterparse("/tmp/example.xml"): if elem.tag == "example": print Elem...
2
2009-07-08T13:34:20Z
1,098,514
<p>I believe you need to explicitly manipulate the subtree to strip every text and tail:</p> <pre><code>from xml.etree import ElementTree for event, elem in ElementTree.iterparse("/tmp/example.xml"): if elem.tag == "example": subiter = ElementTree.ElementTree(elem).getiterator() for x in subiter: ...
3
2009-07-08T14:37:49Z
[ "python", "xml", "xslt" ]
Stripping spaces between XML nodes with Python
1,098,118
<p>Is there a easy way to accomplish the same thing in Python as xsl accomplishes with:</p> <pre><code>&lt;xsl:strip-space elements="*"/&gt; </code></pre> <p>So for instance in the following </p> <pre><code>for event, elem in ElementTree.iterparse("/tmp/example.xml"): if elem.tag == "example": print Elem...
2
2009-07-08T13:34:20Z
1,098,536
<p>An elegant solution could have an iterator which simply filters out whitespace-only text nodes:</p> <pre><code>import re whitespaces = re.compile('\s*$') def omit_whitespaces(iter): for event, elem in iter: if whitespaces.match(elem.text): elem.text = '' if whitespaces.match(elem.tail): elem.ta...
1
2009-07-08T14:43:21Z
[ "python", "xml", "xslt" ]
Stripping spaces between XML nodes with Python
1,098,118
<p>Is there a easy way to accomplish the same thing in Python as xsl accomplishes with:</p> <pre><code>&lt;xsl:strip-space elements="*"/&gt; </code></pre> <p>So for instance in the following </p> <pre><code>for event, elem in ElementTree.iterparse("/tmp/example.xml"): if elem.tag == "example": print Elem...
2
2009-07-08T13:34:20Z
7,323,908
<p>If you can use the <a href="http://pypi.python.org/pypi/lxml" rel="nofollow">lxml</a> module, this becomes much easier. From <a href="http://lxml.de/tutorial.html#parser-objects" rel="nofollow">the lxml tutorial</a>:</p> <pre><code>&gt;&gt;&gt; parser = etree.XMLParser(remove_blank_text=True) # lxml.etree only! &gt...
3
2011-09-06T17:41:02Z
[ "python", "xml", "xslt" ]
Reallocating list in python
1,098,202
<p>Ok this is my problem. I am trying something like this:</p> <pre><code>for i in big_list: del glist[:] for j in range(0:val) glist.append(blah[j]) </code></pre> <p>The idea is to reset the list and reuse it for the next set of data points. The problem is, for some reason, if the first list has 3 po...
0
2009-07-08T13:50:05Z
1,098,240
<p>Change <code>del glist[:]</code> to <code>glist = []</code>. You don't need to "reuse" or "reallocate" in Python, the garbagecollector will take care of that for you.</p> <p>Also, you use 'i' as the loop variable in both loops. That's going to confuse you sooner or later. :)</p>
4
2009-07-08T13:54:47Z
[ "python", "list", "memory-management", "collections" ]
Reallocating list in python
1,098,202
<p>Ok this is my problem. I am trying something like this:</p> <pre><code>for i in big_list: del glist[:] for j in range(0:val) glist.append(blah[j]) </code></pre> <p>The idea is to reset the list and reuse it for the next set of data points. The problem is, for some reason, if the first list has 3 po...
0
2009-07-08T13:50:05Z
1,098,262
<p>you can try </p> <pre><code>glist=[] </code></pre>
1
2009-07-08T13:58:08Z
[ "python", "list", "memory-management", "collections" ]
Reallocating list in python
1,098,202
<p>Ok this is my problem. I am trying something like this:</p> <pre><code>for i in big_list: del glist[:] for j in range(0:val) glist.append(blah[j]) </code></pre> <p>The idea is to reset the list and reuse it for the next set of data points. The problem is, for some reason, if the first list has 3 po...
0
2009-07-08T13:50:05Z
1,098,280
<p><code>del glist[:]</code> works fine for clearing a list. You need to show us your exact code. As shown below, the behavior you're describing does not happen. The <code>append</code> after the <code>del a[:]</code> puts the item at index 0.</p> <pre><code>&gt;&gt;&gt; a = [1,2,3] &gt;&gt;&gt; del a[:] &gt;&gt;&g...
1
2009-07-08T14:02:56Z
[ "python", "list", "memory-management", "collections" ]
How to make Python check if ftp directory exists?
1,098,218
<p>I'm using this script to connect to sample ftp server and list available directories:</p> <pre><code>from ftplib import FTP ftp = FTP('ftp.cwi.nl') # connect to host, default port (some example server, i'll use other one) ftp.login() # user anonymous, passwd anonymous@ ftp.retrlines('LIST') # li...
8
2009-07-08T13:51:56Z
1,098,253
<p>you can use a list. example</p> <pre><code>import ftplib server="localhost" user="user" password="test@email.com" try: ftp = ftplib.FTP(server) ftp.login(user,password) except Exception,e: print e else: filelist = [] #to store all files ftp.retrlines('LIST',filelist.append) # append t...
8
2009-07-08T13:56:38Z
[ "python", "ftp" ]
How to make Python check if ftp directory exists?
1,098,218
<p>I'm using this script to connect to sample ftp server and list available directories:</p> <pre><code>from ftplib import FTP ftp = FTP('ftp.cwi.nl') # connect to host, default port (some example server, i'll use other one) ftp.login() # user anonymous, passwd anonymous@ ftp.retrlines('LIST') # li...
8
2009-07-08T13:51:56Z
3,703,987
<p>The examples attached to ghostdog74's answer have a bit of a bug: the list you get back is the whole line of the response, so you get something like</p> <pre><code>drwxrwxrwx 4 5063 5063 4096 Sep 13 20:00 resized </code></pre> <p>This means if your directory name is something like '50' (which is was...
2
2010-09-13T20:07:19Z
[ "python", "ftp" ]
How to make Python check if ftp directory exists?
1,098,218
<p>I'm using this script to connect to sample ftp server and list available directories:</p> <pre><code>from ftplib import FTP ftp = FTP('ftp.cwi.nl') # connect to host, default port (some example server, i'll use other one) ftp.login() # user anonymous, passwd anonymous@ ftp.retrlines('LIST') # li...
8
2009-07-08T13:51:56Z
13,155,592
<p>Tom is correct, but no one voted him up however for the satisfaction who voted up ghostdog74 I will mix and write this code, works for me, should work for you guys.</p> <pre><code>import ftplib server="localhost" user="user" uploadToDir="public_html" password="test@email.com" try: ftp = ftplib.FTP(server) ...
1
2012-10-31T10:12:31Z
[ "python", "ftp" ]
How to make Python check if ftp directory exists?
1,098,218
<p>I'm using this script to connect to sample ftp server and list available directories:</p> <pre><code>from ftplib import FTP ftp = FTP('ftp.cwi.nl') # connect to host, default port (some example server, i'll use other one) ftp.login() # user anonymous, passwd anonymous@ ftp.retrlines('LIST') # li...
8
2009-07-08T13:51:56Z
14,331,184
<p>Nslt will list an array for all files in ftp server. Just check if your folder name is there.</p> <pre><code>from ftplib import FTP ftp = FTP('yourserver') ftp.login('username', 'password') folderName = 'yourFolderName' if folderName in ftp.nlst(): #do needed task </code></pre>
10
2013-01-15T04:28:30Z
[ "python", "ftp" ]
How to make Python check if ftp directory exists?
1,098,218
<p>I'm using this script to connect to sample ftp server and list available directories:</p> <pre><code>from ftplib import FTP ftp = FTP('ftp.cwi.nl') # connect to host, default port (some example server, i'll use other one) ftp.login() # user anonymous, passwd anonymous@ ftp.retrlines('LIST') # li...
8
2009-07-08T13:51:56Z
17,346,128
<p>In 3.x <code>nlst()</code> method is deprecated. Use this code:</p> <pre><code>import ftplib remote = ftplib.FTP('example.com') remote.login() if 'foo' in [name for name, data in list(remote.mlsd())]: # do your stuff </code></pre> <p>The <code>list()</code> call is needed because <code>mlsd()</code> returns ...
1
2013-06-27T14:38:08Z
[ "python", "ftp" ]
How to make Python check if ftp directory exists?
1,098,218
<p>I'm using this script to connect to sample ftp server and list available directories:</p> <pre><code>from ftplib import FTP ftp = FTP('ftp.cwi.nl') # connect to host, default port (some example server, i'll use other one) ftp.login() # user anonymous, passwd anonymous@ ftp.retrlines('LIST') # li...
8
2009-07-08T13:51:56Z
19,950,512
<p>You can send "MLST path" over the control connection. That will return a line including the <em>type</em> of the path (notice 'type=dir' down here):</p> <pre><code>250-Listing "/home/user": modify=20131113091701;perm=el;size=4096;type=dir;unique=813gc0004; / 250 End MLST. </code></pre> <p>Translated into python t...
1
2013-11-13T09:50:51Z
[ "python", "ftp" ]
How to make Python check if ftp directory exists?
1,098,218
<p>I'm using this script to connect to sample ftp server and list available directories:</p> <pre><code>from ftplib import FTP ftp = FTP('ftp.cwi.nl') # connect to host, default port (some example server, i'll use other one) ftp.login() # user anonymous, passwd anonymous@ ftp.retrlines('LIST') # li...
8
2009-07-08T13:51:56Z
20,205,019
<p>=> I found this web-page while googling for a way to check if a file exists using ftplib in python. The following is what I figured out (hope it helps someone):</p> <p>=> When trying to list non-existent files/directories, ftplib raises an exception. Even though Adding a try/except block is a standard practice and ...
1
2013-11-25T22:46:48Z
[ "python", "ftp" ]
Is os.popen really deprecated in Python 2.6?
1,098,257
<p>The on-line <a href="http://docs.python.org/library/os.html#os.popen">documentation</a> states that os.popen is now deprecated. All other deprecated functions duly raise a DeprecationWarning. For instance:</p> <pre><code>&gt;&gt;&gt; import os &gt;&gt;&gt; [c.close() for c in os.popen2('ps h -eo pid:1,command')] __...
6
2009-07-08T13:57:19Z
1,098,268
<p>one thing that I can think of is that os.popen exists in python3, while os.popen2 doesn't. So one is "more deprecated" than the other, and scheduled for sooner removal from the language.</p>
4
2009-07-08T13:59:47Z
[ "python", "deprecated", "std" ]
Is os.popen really deprecated in Python 2.6?
1,098,257
<p>The on-line <a href="http://docs.python.org/library/os.html#os.popen">documentation</a> states that os.popen is now deprecated. All other deprecated functions duly raise a DeprecationWarning. For instance:</p> <pre><code>&gt;&gt;&gt; import os &gt;&gt;&gt; [c.close() for c in os.popen2('ps h -eo pid:1,command')] __...
6
2009-07-08T13:57:19Z
1,098,460
<p>Here is the <a href="http://www.python.org/dev/peps/pep-0361/">PEP</a>.</p> <blockquote> <pre><code>Deprecated modules and functions in the standard library: - buildtools - cfmfile - commands.getstatus() - macostools.touched() - md5 - MimeWriter - mimify - popen2, os.popen[234]() ...
5
2009-07-08T14:28:01Z
[ "python", "deprecated", "std" ]
Is os.popen really deprecated in Python 2.6?
1,098,257
<p>The on-line <a href="http://docs.python.org/library/os.html#os.popen">documentation</a> states that os.popen is now deprecated. All other deprecated functions duly raise a DeprecationWarning. For instance:</p> <pre><code>&gt;&gt;&gt; import os &gt;&gt;&gt; [c.close() for c in os.popen2('ps h -eo pid:1,command')] __...
6
2009-07-08T13:57:19Z
1,223,080
<p>In the meanwhile I have opened a <a href="http://bugs.python.org/issue6490" rel="nofollow">ticket</a> on the Python issue tracker. I'll keep this question open until the ticket is closed.</p>
2
2009-08-03T15:45:21Z
[ "python", "deprecated", "std" ]
Is os.popen really deprecated in Python 2.6?
1,098,257
<p>The on-line <a href="http://docs.python.org/library/os.html#os.popen">documentation</a> states that os.popen is now deprecated. All other deprecated functions duly raise a DeprecationWarning. For instance:</p> <pre><code>&gt;&gt;&gt; import os &gt;&gt;&gt; [c.close() for c in os.popen2('ps h -eo pid:1,command')] __...
6
2009-07-08T13:57:19Z
1,801,288
<p><a href="http://docs.python.org/library/commands.html" rel="nofollow">commands.getstatusoutput</a> still uses it according to the 2.6.4 documentation.</p>
0
2009-11-26T02:47:37Z
[ "python", "deprecated", "std" ]
Looking for elegant glob-like DNA string expansion
1,098,461
<p>I'm trying to make a glob-like expansion of a set of DNA strings that have multiple possible bases.</p> <p>The base of my DNA strings contains the letters A, C, G, and T. However, I can have special characters like M which could be an A or a C.</p> <p>For example, say I have the string:</p> <p><code>ATMM</code><...
2
2009-07-08T14:28:03Z
1,098,478
<p>This isn't really an "expansion" problem and it's almost certainly not doable with any sensible regular expression.</p> <p>I believe what you're looking for is "how to generate permutations".</p>
0
2009-07-08T14:31:13Z
[ "python", "permutation", "glob", "dna-sequence" ]
Looking for elegant glob-like DNA string expansion
1,098,461
<p>I'm trying to make a glob-like expansion of a set of DNA strings that have multiple possible bases.</p> <p>The base of my DNA strings contains the letters A, C, G, and T. However, I can have special characters like M which could be an A or a C.</p> <p>For example, say I have the string:</p> <p><code>ATMM</code><...
2
2009-07-08T14:28:03Z
1,098,498
<p>You could for example do this recursively. Pseudo-code:</p> <pre><code>printSequences(sequence s) switch "first special character in sequence" case ... case M: s1 = s, but first M replaced with A printSequences(s1) s2 = s, but first M replaced with C printSequences(s2) case non...
0
2009-07-08T14:35:40Z
[ "python", "permutation", "glob", "dna-sequence" ]
Looking for elegant glob-like DNA string expansion
1,098,461
<p>I'm trying to make a glob-like expansion of a set of DNA strings that have multiple possible bases.</p> <p>The base of my DNA strings contains the letters A, C, G, and T. However, I can have special characters like M which could be an A or a C.</p> <p>For example, say I have the string:</p> <p><code>ATMM</code><...
2
2009-07-08T14:28:03Z
1,098,510
<p>You probably could do something like this in python using the yield operator</p> <pre><code>def glob(str): if str=='': yield '' return if str[0]!='M': for tail in glob(str[1:]): yield str[0] + tail else: for ...
1
2009-07-08T14:37:12Z
[ "python", "permutation", "glob", "dna-sequence" ]
Looking for elegant glob-like DNA string expansion
1,098,461
<p>I'm trying to make a glob-like expansion of a set of DNA strings that have multiple possible bases.</p> <p>The base of my DNA strings contains the letters A, C, G, and T. However, I can have special characters like M which could be an A or a C.</p> <p>For example, say I have the string:</p> <p><code>ATMM</code><...
2
2009-07-08T14:28:03Z
1,098,546
<p>Regexps <em>match</em> strings, they're not intended to be turned into every string they might match.</p> <p>Also, you're looking at a lot of strings being output from this - for instance:</p> <pre><code>MMMMMMMMMMMMMMMM (16 M's) </code></pre> <p>produces 65,536 16 character strings - and I'm guessing that DNA se...
0
2009-07-08T14:45:23Z
[ "python", "permutation", "glob", "dna-sequence" ]
Looking for elegant glob-like DNA string expansion
1,098,461
<p>I'm trying to make a glob-like expansion of a set of DNA strings that have multiple possible bases.</p> <p>The base of my DNA strings contains the letters A, C, G, and T. However, I can have special characters like M which could be an A or a C.</p> <p>For example, say I have the string:</p> <p><code>ATMM</code><...
2
2009-07-08T14:28:03Z
1,098,598
<p>Agree with other posters that it seems like a strange thing to want to do. Of course, if you really want to, there is (as always) an elegant way to do it in Python (2.6+):</p> <pre><code>from itertools import product map("".join, product(*[['A', 'C'] if x == "M" else [x] for x in "GMTTMCA"])) </code></pre> <p>Full...
2
2009-07-08T14:54:21Z
[ "python", "permutation", "glob", "dna-sequence" ]
Proper way to use **kwargs in Python
1,098,549
<p>What is the proper way to use <code>**kwargs</code> in Python when it comes to default values?</p> <p><code>kwargs</code> returns a dictionary, but what is the best way to set default values, or is there one? Should I just access it as a dictionary? Use get function? </p> <pre><code>class ExampleClass: def ...
247
2009-07-08T14:45:53Z
1,098,556
<p>You can pass a default value to <code>get()</code> for keys that are not in the dictionary:</p> <pre><code>self.val2 = kwargs.get('val2',"default value") </code></pre> <p>However, if you plan on using a particular argument with a particular default value, why not use named arguments in the first place?</p> <pre><...
245
2009-07-08T14:47:38Z
[ "python", "kwargs" ]
Proper way to use **kwargs in Python
1,098,549
<p>What is the proper way to use <code>**kwargs</code> in Python when it comes to default values?</p> <p><code>kwargs</code> returns a dictionary, but what is the best way to set default values, or is there one? Should I just access it as a dictionary? Use get function? </p> <pre><code>class ExampleClass: def ...
247
2009-07-08T14:45:53Z
1,098,577
<p>You'd do</p> <pre><code>self.attribute = kwargs.pop('name', default_value) </code></pre> <p>or</p> <pre><code>self.attribute = kwargs.get('name', default_value) </code></pre> <p>If you use <code>pop</code>, then you can check if there are any spurious values sent, and take the appropriate action (if any).</p>
42
2009-07-08T14:49:58Z
[ "python", "kwargs" ]
Proper way to use **kwargs in Python
1,098,549
<p>What is the proper way to use <code>**kwargs</code> in Python when it comes to default values?</p> <p><code>kwargs</code> returns a dictionary, but what is the best way to set default values, or is there one? Should I just access it as a dictionary? Use get function? </p> <pre><code>class ExampleClass: def ...
247
2009-07-08T14:45:53Z
1,098,588
<p>You could do something like this</p> <pre><code>class ExampleClass: def __init__(self, **kwargs): arguments = {'val':1, 'val2':2} arguments.update(kwargs) self.val = arguments['val'] self.val2 = arguments['val2'] </code></pre>
8
2009-07-08T14:51:57Z
[ "python", "kwargs" ]
Proper way to use **kwargs in Python
1,098,549
<p>What is the proper way to use <code>**kwargs</code> in Python when it comes to default values?</p> <p><code>kwargs</code> returns a dictionary, but what is the best way to set default values, or is there one? Should I just access it as a dictionary? Use get function? </p> <pre><code>class ExampleClass: def ...
247
2009-07-08T14:45:53Z
1,098,605
<p>Using **kwargs and default values is easy. Sometimes, however, you shouldn't be using **kwargs in the first place.</p> <p>In this case, we're not really making best use of **kwargs.</p> <pre><code>class ExampleClass( object ): def __init__(self, **kwargs): self.val = kwargs.get('val',"default1") ...
30
2009-07-08T14:55:22Z
[ "python", "kwargs" ]
Proper way to use **kwargs in Python
1,098,549
<p>What is the proper way to use <code>**kwargs</code> in Python when it comes to default values?</p> <p><code>kwargs</code> returns a dictionary, but what is the best way to set default values, or is there one? Should I just access it as a dictionary? Use get function? </p> <pre><code>class ExampleClass: def ...
247
2009-07-08T14:45:53Z
1,098,639
<p>I suggest something like this</p> <pre><code>def testFunc( **kwargs ): options = { 'option1' : 'default_value1', 'option2' : 'default_value2', 'option3' : 'default_value3', } options.update(kwargs) print options testFunc( option1='new_value1', option3='new_value3' )...
36
2009-07-08T15:03:14Z
[ "python", "kwargs" ]
Proper way to use **kwargs in Python
1,098,549
<p>What is the proper way to use <code>**kwargs</code> in Python when it comes to default values?</p> <p><code>kwargs</code> returns a dictionary, but what is the best way to set default values, or is there one? Should I just access it as a dictionary? Use get function? </p> <pre><code>class ExampleClass: def ...
247
2009-07-08T14:45:53Z
1,098,834
<p>While most answers are saying that, e.g.,</p> <pre><code>def f(**kwargs): foo = kwargs.pop('foo') bar = kwargs.pop('bar') ...etc... </code></pre> <p>is "the same as"</p> <pre><code>def f(foo=None, bar=None, **kwargs): ...etc... </code></pre> <p>this is not true. In the latter case, <code>f</code...
156
2009-07-08T15:29:29Z
[ "python", "kwargs" ]
Proper way to use **kwargs in Python
1,098,549
<p>What is the proper way to use <code>**kwargs</code> in Python when it comes to default values?</p> <p><code>kwargs</code> returns a dictionary, but what is the best way to set default values, or is there one? Should I just access it as a dictionary? Use get function? </p> <pre><code>class ExampleClass: def ...
247
2009-07-08T14:45:53Z
2,053,613
<p>Here's another approach:</p> <pre><code>def my_func(arg1, arg2, arg3): ... so something ... kwargs = {'arg1': 'Value One', 'arg2': 'Value Two', 'arg3': 'Value Three'} # Now you can call the function with kwargs like this: my_func(**kwargs) </code></pre>
11
2010-01-13T00:44:27Z
[ "python", "kwargs" ]
Proper way to use **kwargs in Python
1,098,549
<p>What is the proper way to use <code>**kwargs</code> in Python when it comes to default values?</p> <p><code>kwargs</code> returns a dictionary, but what is the best way to set default values, or is there one? Should I just access it as a dictionary? Use get function? </p> <pre><code>class ExampleClass: def ...
247
2009-07-08T14:45:53Z
12,492,336
<p>If you want to combine this with *args you have to keep *args and **kwargs at the end of the definition.</p> <p>So:</p> <pre><code>def method(foo, bar=None, *args, **kwargs): do_something_with(foo, bar) some_other_function(*args, **kwargs) </code></pre>
1
2012-09-19T09:50:37Z
[ "python", "kwargs" ]
Proper way to use **kwargs in Python
1,098,549
<p>What is the proper way to use <code>**kwargs</code> in Python when it comes to default values?</p> <p><code>kwargs</code> returns a dictionary, but what is the best way to set default values, or is there one? Should I just access it as a dictionary? Use get function? </p> <pre><code>class ExampleClass: def ...
247
2009-07-08T14:45:53Z
13,629,607
<p>Since <code>**kwargs</code> is used when the number of arguments is unknown, why not doing this?</p> <pre><code>class Exampleclass(object): def __init__(self, **kwargs): for k in kwargs.keys(): if k in [acceptable_keys_list]: self.__setattr__(k, kwargs[k]) </code></pre>
19
2012-11-29T15:55:28Z
[ "python", "kwargs" ]