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
Counting problem: possible sudoko tables?
2,570,799
<p><br> I'm working on a sudoko solver (python). my method is using a game tree and explore possible permutations for each set of digits by DFS Algorithm.</p> <p>in order to analyzing problem, i want to know what is the count of possible <strong>valid and invalid</strong> sudoko tables? </p> <p>-> a 9*9 table that ha...
0
2010-04-03T09:39:14Z
2,570,868
<p>The number of valid Sudoku solution grids for the standard 9×9 grid was calculated by Bertram Felgenhauer and Frazer Jarvis in 2005 to be 6,670,903,752,021,072,936,960.</p> <p><a href="http://en.wikipedia.org/wiki/Mathematics_of_Sudoku#cite_note-afj2-2" rel="nofollow">Mathematics of Sudoku</a> | <a href="http://w...
2
2010-04-03T10:02:13Z
[ "python", "algorithm", "math", "discrete-mathematics" ]
Counting problem: possible sudoko tables?
2,570,799
<p><br> I'm working on a sudoko solver (python). my method is using a game tree and explore possible permutations for each set of digits by DFS Algorithm.</p> <p>in order to analyzing problem, i want to know what is the count of possible <strong>valid and invalid</strong> sudoko tables? </p> <p>-> a 9*9 table that ha...
0
2010-04-03T09:39:14Z
2,570,879
<p>According to <a href="http://en.wikipedia.org/wiki/Mathematics_of_Sudoku" rel="nofollow">this Wikipedia article</a> (or <a href="http://www.research.att.com/~njas/sequences/A107739" rel="nofollow">this OEIS sequence</a>), there are roughly 6.6 * 10^21 different sudoku squares.</p>
1
2010-04-03T10:06:51Z
[ "python", "algorithm", "math", "discrete-mathematics" ]
Counting problem: possible sudoko tables?
2,570,799
<p><br> I'm working on a sudoko solver (python). my method is using a game tree and explore possible permutations for each set of digits by DFS Algorithm.</p> <p>in order to analyzing problem, i want to know what is the count of possible <strong>valid and invalid</strong> sudoko tables? </p> <p>-> a 9*9 table that ha...
0
2010-04-03T09:39:14Z
2,570,931
<p>What you did wrong was the last step: you shouldn't multiply the answer by <code>9!</code>. You have already counted all possible squares.</p> <p>This doesn't help you much when counting the possible Sudoku-tables. One other thing you could do is to count the tables where the "row-condition" holds: that is just <co...
1
2010-04-03T10:22:43Z
[ "python", "algorithm", "math", "discrete-mathematics" ]
urlencode an array of values
2,571,145
<p>I'm trying to urlencode an dictionary in python with urllib.urlencode. The problem is, I have to encode an array.</p> <p>The result needs to be:</p> <pre><code>criterias%5B%5D=member&amp;criterias%5B%5D=issue #unquoted: criterias[]=member&amp;criterias[]=issue </code></pre> <p>But the result I get is:</p> <pre><...
24
2010-04-03T11:41:54Z
2,571,182
<p>You can use a list of key-value pairs (tuples):</p> <pre><code>&gt;&gt;&gt; urllib.urlencode([('criterias[]', 'member'), ('criterias[]', 'issue')]) 'criterias%5B%5D=member&amp;criterias%5B%5D=issue' </code></pre>
9
2010-04-03T12:00:25Z
[ "python", "http" ]
urlencode an array of values
2,571,145
<p>I'm trying to urlencode an dictionary in python with urllib.urlencode. The problem is, I have to encode an array.</p> <p>The result needs to be:</p> <pre><code>criterias%5B%5D=member&amp;criterias%5B%5D=issue #unquoted: criterias[]=member&amp;criterias[]=issue </code></pre> <p>But the result I get is:</p> <pre><...
24
2010-04-03T11:41:54Z
2,571,189
<p>Listcomp of values:</p> <pre><code>&gt;&gt;&gt; criterias = ['member', 'issue'] &gt;&gt;&gt; urllib.urlencode([('criterias[]', i) for i in criterias]) 'criterias%5B%5D=member&amp;criterias%5B%5D=issue' &gt;&gt;&gt; </code></pre>
2
2010-04-03T12:04:27Z
[ "python", "http" ]
urlencode an array of values
2,571,145
<p>I'm trying to urlencode an dictionary in python with urllib.urlencode. The problem is, I have to encode an array.</p> <p>The result needs to be:</p> <pre><code>criterias%5B%5D=member&amp;criterias%5B%5D=issue #unquoted: criterias[]=member&amp;criterias[]=issue </code></pre> <p>But the result I get is:</p> <pre><...
24
2010-04-03T11:41:54Z
4,019,744
<p>To abstract this out to work for any parameter dictionary and convert it into a list of tuples:</p> <pre><code>import urllib def url_encode_params(params={}): if not isinstance(params, dict): raise Exception("You must pass in a dictionary!") params_list = [] for k,v in params.items(): ...
1
2010-10-25T23:57:52Z
[ "python", "http" ]
urlencode an array of values
2,571,145
<p>I'm trying to urlencode an dictionary in python with urllib.urlencode. The problem is, I have to encode an array.</p> <p>The result needs to be:</p> <pre><code>criterias%5B%5D=member&amp;criterias%5B%5D=issue #unquoted: criterias[]=member&amp;criterias[]=issue </code></pre> <p>But the result I get is:</p> <pre><...
24
2010-04-03T11:41:54Z
10,233,141
<p>The solution is far simpler than the ones listed above. </p> <pre><code>&gt;&gt;&gt; import urllib &gt;&gt;&gt; params = {'criterias[]': ['member', 'issue']} &gt;&gt;&gt; &gt;&gt;&gt; print urllib.urlencode(params, True) criterias%5B%5D=member&amp;criterias%5B%5D=issue </code></pre> <p>Note the True. See <a hre...
40
2012-04-19T17:05:00Z
[ "python", "http" ]
what is this mean .. "name__icontains" and "description__icontains" in django code,
2,571,149
<pre><code>maps = (maps.filter(name__icontains=search_terms) | maps.filter(description__icontains=search_terms)) </code></pre> <p>i can't find this filter .</p> <p>thanks</p>
4
2010-04-03T11:45:33Z
2,571,153
<p><code>xxx_icontains</code> searches the whole <code>xxx</code> field for the argument, case-insensitively. </p> <p><a href="http://docs.djangoproject.com/en/1.1/ref/models/querysets/#icontains" rel="nofollow">http://docs.djangoproject.com/en/1.1/ref/models/querysets/#icontains</a></p>
1
2010-04-03T11:48:33Z
[ "python", "django", "pinax" ]
what is this mean .. "name__icontains" and "description__icontains" in django code,
2,571,149
<pre><code>maps = (maps.filter(name__icontains=search_terms) | maps.filter(description__icontains=search_terms)) </code></pre> <p>i can't find this filter .</p> <p>thanks</p>
4
2010-04-03T11:45:33Z
2,571,154
<p>It's a case-insensitive containment test.</p> <p>Example:</p> <pre><code>Entry.objects.get(headline__icontains='Lennon') </code></pre> <p>SQL equivalent:</p> <pre><code>SELECT ... WHERE headline ILIKE '%Lennon%'; </code></pre> <p>In your case the code says maps should be True if either the name or the descripti...
5
2010-04-03T11:49:04Z
[ "python", "django", "pinax" ]
How to add a separator in a PyGTK combobox?
2,571,202
<p>I'm using gtk.combo_box_new_text() to make combobox list, this uses a gtk.ListStore to store only strings, so there are some way to add a separator between items without use a complex gtk.TreeModel? </p> <p>If this is not possible, what is the simplest way to use a gtk.TreeModel to able secuential widget addition?<...
4
2010-04-03T12:07:12Z
2,571,279
<p>I think that you should use ComboBox.set_row_separator_func to set a separator function where you would determine which items of your list will be separators. Since ListStore implements TreeModel interface, you should have no problem simply using it in your case.</p> <p>P.S.: nothing is easy in GTK :)</p>
3
2010-04-03T12:48:34Z
[ "python", "user-interface", "gtk", "pygtk", "gnome" ]
Python beautiful soup arguments
2,571,228
<p>I have this code that fetches some text from a page using BeautifulSoup</p> <pre><code>soup= BeautifulSoup(html) body = soup.find('div' , {'id':'body'}) print body </code></pre> <p>I would like to make this as a reusable function that takes in some htmltext and the tags to match it like the following </p> <pre><c...
5
2010-04-03T12:22:48Z
2,571,244
<p>I think you just need to add an asterisk here:</p> <pre><code>body = soup.find(*atrs) </code></pre> <p>Without the asterisk you are passing a single parameter which is a tuple:</p> <pre><code>body = soup.find(('div' , {'id':'body'})) </code></pre> <p>With the asterisk the tuple is expanded out and the statement ...
3
2010-04-03T12:29:00Z
[ "python", "beautifulsoup" ]
Python beautiful soup arguments
2,571,228
<p>I have this code that fetches some text from a page using BeautifulSoup</p> <pre><code>soup= BeautifulSoup(html) body = soup.find('div' , {'id':'body'}) print body </code></pre> <p>I would like to make this as a reusable function that takes in some htmltext and the tags to match it like the following </p> <pre><c...
5
2010-04-03T12:22:48Z
2,571,245
<pre><code>def parse(html, *atrs): soup= BeautifulSoup(html) body = soup.find(*atrs) return body </code></pre> <p>And then:</p> <pre><code>parse(htmlpage, 'div', {'id':'body'}) </code></pre>
7
2010-04-03T12:29:12Z
[ "python", "beautifulsoup" ]
Changing models in django results in broken database?
2,571,337
<p>I have added and removed fields in my models.py file and then run manage.py syncdb. Usually I have to quit out of the shell and restart it before syncdb does anything. And then even after that, I am getting errors when trying to access the admin pages, it seems that certain new fields that I've added still don't sho...
3
2010-04-03T13:20:17Z
2,571,349
<p>Django does not perform database migration for you, i.e., if you add new fields, Django won't modify your database schema.</p> <p>You can either:</p> <ol> <li>Drop the tables that changed and perform syncdb again. This is reasonnable when you are developing your application and you don't have any real data in your...
9
2010-04-03T13:26:36Z
[ "python", "django", "django-models", "django-admin" ]
Changing models in django results in broken database?
2,571,337
<p>I have added and removed fields in my models.py file and then run manage.py syncdb. Usually I have to quit out of the shell and restart it before syncdb does anything. And then even after that, I am getting errors when trying to access the admin pages, it seems that certain new fields that I've added still don't sho...
3
2010-04-03T13:20:17Z
2,572,070
<p>Just to expand on @Barthelemy's answer, there are several <a href="http://code.djangoproject.com/wiki/SchemaEvolution" rel="nofollow">Django migration tools</a>:</p> <ul> <li><a href="http://south.aeracode.org/" rel="nofollow">South</a></li> <li><a href="http://code.google.com/p/deseb/" rel="nofollow">Deseb</a></li...
2
2010-04-03T17:34:36Z
[ "python", "django", "django-models", "django-admin" ]
Changing models in django results in broken database?
2,571,337
<p>I have added and removed fields in my models.py file and then run manage.py syncdb. Usually I have to quit out of the shell and restart it before syncdb does anything. And then even after that, I am getting errors when trying to access the admin pages, it seems that certain new fields that I've added still don't sho...
3
2010-04-03T13:20:17Z
2,573,292
<p>For me, (so long as you're doing this with test data, and not doing this in a production environ) it's alot easier to just blow away the test.db and do a new ./manage.py syncdb. Just food for thought...</p>
4
2010-04-04T01:53:21Z
[ "python", "django", "django-models", "django-admin" ]
Extracting a string between specified characters in python
2,571,363
<p>I'm a newbie to regular expressions and I have the following string:</p> <pre><code>sequence = '["{\"First\":\"Belyuen,NT,0801\",\"Second\":\"Belyuen,NT,0801\"}","{\"First\":\"Larrakeyah,NT,0801\",\"Second\":\"Larrakeyah,NT,0801\"}"]' </code></pre> <p>I am trying to extract the text <code>Belyuen,NT,0801</code> an...
1
2010-04-03T13:34:50Z
2,571,385
<p>Don't use regex for this. It appears to be a rather strangely split set of JSON strings. Join them back together and use the <code>json</code> module to decode it.</p> <pre><code>import json sequence = '[%s]' % ','.join(sequence) data = json.loads(sequence) print data[0]['First'], data[0]['Second'] </code></pre> <...
3
2010-04-03T13:46:11Z
[ "python", "regex" ]
Extracting a string between specified characters in python
2,571,363
<p>I'm a newbie to regular expressions and I have the following string:</p> <pre><code>sequence = '["{\"First\":\"Belyuen,NT,0801\",\"Second\":\"Belyuen,NT,0801\"}","{\"First\":\"Larrakeyah,NT,0801\",\"Second\":\"Larrakeyah,NT,0801\"}"]' </code></pre> <p>I am trying to extract the text <code>Belyuen,NT,0801</code> an...
1
2010-04-03T13:34:50Z
2,571,387
<p>it seems like a proper serialization of the Python dict, you could just do:</p> <pre><code>&gt;&gt;&gt; sequence = ["{\"First\":\"Belyuen,NT,0801\",\"Second\":\"Belyuen,NT,0801\"}","{\"First\":\"Larrakeyah,NT,0801\",\"Second\":\"Larrakeyah,NT,0801\"}"] &gt;&gt;&gt; import json &gt;&gt;&gt; for i in sequence: d ...
3
2010-04-03T13:46:43Z
[ "python", "regex" ]
Extracting a string between specified characters in python
2,571,363
<p>I'm a newbie to regular expressions and I have the following string:</p> <pre><code>sequence = '["{\"First\":\"Belyuen,NT,0801\",\"Second\":\"Belyuen,NT,0801\"}","{\"First\":\"Larrakeyah,NT,0801\",\"Second\":\"Larrakeyah,NT,0801\"}"]' </code></pre> <p>I am trying to extract the text <code>Belyuen,NT,0801</code> an...
1
2010-04-03T13:34:50Z
2,571,389
<p>you don't need regex</p> <pre><code>&gt;&gt;&gt; sequence = ["{\"First\":\"Belyuen,NT,0801\",\"Second\":\"Belyuen,NT,0801\"}","{\"First\":\"Larrakeyah,NT,0801\",\"Second\":\"Larrakeyah,NT,0801\"}"] &gt;&gt;&gt; for item in sequence: ... print eval(item).values() ... ['Belyuen,NT,0801', 'Belyuen,NT,0801'] ['Larrake...
2
2010-04-03T13:47:47Z
[ "python", "regex" ]
One hour difference in Python
2,571,432
<p>I have a datetime.datetime property var. I would like to know if it is less than one hour of the current time. Something like</p> <pre><code>var.hour&lt;datetime.datetime.today().hour - 1 </code></pre> <p>Problem with the above syntax is that </p> <pre><code>datetime.datetime.today().hour </code></pre> <p>return...
4
2010-04-03T14:00:26Z
2,571,437
<p>Use <code>datetime.timedelta</code>.</p> <pre><code>var &lt; datetime.datetime.today() - datetime.timedelta(hours=1) </code></pre>
6
2010-04-03T14:02:39Z
[ "python", "datetime" ]
One hour difference in Python
2,571,432
<p>I have a datetime.datetime property var. I would like to know if it is less than one hour of the current time. Something like</p> <pre><code>var.hour&lt;datetime.datetime.today().hour - 1 </code></pre> <p>Problem with the above syntax is that </p> <pre><code>datetime.datetime.today().hour </code></pre> <p>return...
4
2010-04-03T14:00:26Z
2,571,558
<p>You can use <a href="http://labix.org/python-dateutil" rel="nofollow" title="dateutil.relativedelta">dateutil.relativedelta</a></p> <pre><code>from datetime import datetime, timedelta from dateutil.relativedelta import relativedelta now = datetime.now() other_time = now + timedelta(hours=8) diff = relativedelta(ot...
0
2010-04-03T14:49:01Z
[ "python", "datetime" ]
Using CookieJar in Python to log in to a website from "Google App Engine". What's wrong here?
2,571,450
<p>I've been trying to find a python code that would log in to my mail box on yahoo.com from <a href="http://code.google.com/intl/en/appengine/docs/whatisgoogleappengine.html" rel="nofollow">"Google App Engine"</a> . <a href="http://stackoverflow.com/questions/1914275/googles-app-engine-python-how-to-get-parameters-fro...
0
2010-04-03T14:07:39Z
2,572,263
<p>You send MD5 hash and not plain password. Also you'd have to play along with all kinds of CSRF protections etc. that they're implementing. Look:</p> <pre><code> &lt;input type="hidden" name=".tries" value="1"&gt; &lt;input type="hidden" name=".src" value="ym"&gt; &lt;input type=...
3
2010-04-03T18:43:34Z
[ "python", "google-app-engine", "logging", "cookiejar" ]
Self-referential ReferenceProperty in Google App Engine
2,571,507
<p>I'm having a bit of trouble with ReferencePropertys in App Engine (Python).</p> <p>For a bit of fun, I'm trying to model a folder/file system, but having trouble getting folders to reference folders.</p> <p>My first attempt was this: </p> <pre><code>class Folder(db.Model): id = db.StringProperty() name = ...
2
2010-04-03T14:31:06Z
2,571,521
<p>You could create a separate model to link the two, named something like FolderChild:</p> <pre><code>class FolderChild(db.Model): parent = db.ReferenceProperty(Folder) child = db.ReferenceProperty(Folder, collection_name="children") </code></pre>
0
2010-04-03T14:36:34Z
[ "python", "google-app-engine" ]
Self-referential ReferenceProperty in Google App Engine
2,571,507
<p>I'm having a bit of trouble with ReferencePropertys in App Engine (Python).</p> <p>For a bit of fun, I'm trying to model a folder/file system, but having trouble getting folders to reference folders.</p> <p>My first attempt was this: </p> <pre><code>class Folder(db.Model): id = db.StringProperty() name = ...
2
2010-04-03T14:31:06Z
2,571,576
<p>That's exactly what <a href="http://code.google.com/appengine/docs/python/datastore/typesandpropertyclasses.html#SelfReferenceProperty" rel="nofollow">SelfReferenceProperty</a> is for.</p>
9
2010-04-03T14:54:28Z
[ "python", "google-app-engine" ]
Using a Unicode format for Python's `time.strftime()`
2,571,515
<p>I am trying to call Python's <code>time.strftime()</code> function using a Unicode format string:</p> <pre><code>u'%d\u200f/%m\u200f/%Y %H:%M:%S' </code></pre> <p>(<a href="http://www.fileformat.info/info/unicode/char/200f/index.htm"><code>\u200f</code></a> is the "Right-To-Left Mark" (RLM).)</p> <p>However, I am...
12
2010-04-03T14:35:31Z
2,571,566
<p>You can format string through utf-8 encoding:</p> <pre><code>time.strftime(u'%d\u200f/%m\u200f/%Y %H:%M:%S'.encode('utf-8'), t).decode('utf-8') </code></pre>
4
2010-04-03T14:51:36Z
[ "python", "unicode" ]
Using a Unicode format for Python's `time.strftime()`
2,571,515
<p>I am trying to call Python's <code>time.strftime()</code> function using a Unicode format string:</p> <pre><code>u'%d\u200f/%m\u200f/%Y %H:%M:%S' </code></pre> <p>(<a href="http://www.fileformat.info/info/unicode/char/200f/index.htm"><code>\u200f</code></a> is the "Right-To-Left Mark" (RLM).)</p> <p>However, I am...
12
2010-04-03T14:35:31Z
2,571,568
<p>Many standard library functions still don't support Unicode the way they should. You can use this workaround:</p> <pre><code>fmt = u'%d\u200f/%m\u200f/%Y %H:%M:%S' time.strftime(fmt.encode('utf-8'), &lt;your time here&gt;).decode('utf-8') </code></pre>
21
2010-04-03T14:51:58Z
[ "python", "unicode" ]
How do I change my current directory from a python script?
2,571,524
<p>I'm trying to implement my own version of the 'cd' command that presents the user with a list of hard-coded directories to choose from, and the user has to enter a number corresponding to an entry in the list. The program, named <code>my_cd.py</code> for now, should then effectively 'cd' the user to the chosen direc...
3
2010-04-03T14:38:37Z
2,571,529
<p>This can't be done. Changes to the working directory are not visible to parent processes. At best you could have the Python script print the directory to change to, then have the sourced script actually change to that directory.</p>
1
2010-04-03T14:39:58Z
[ "python", "bash", "shell", "directory", "cd" ]
How do I change my current directory from a python script?
2,571,524
<p>I'm trying to implement my own version of the 'cd' command that presents the user with a list of hard-coded directories to choose from, and the user has to enter a number corresponding to an entry in the list. The program, named <code>my_cd.py</code> for now, should then effectively 'cd' the user to the chosen direc...
3
2010-04-03T14:38:37Z
2,571,561
<p><code>my_cd.py</code>:</p> <pre><code>#!/usr/bin/env python import sys dirs = ['/usr/bin', '/bin', '~'] for n, dir in enumerate(dirs): sys.stderr.write('%d) %s\n' % (n+1, dir)) sys.stderr.write('Choice: ') n = int(raw_input()) print dirs[n-1] </code></pre> <p>Usage:</p> <pre><code>nosklo:/tmp$ alias mcd="cd ...
3
2010-04-03T14:50:42Z
[ "python", "bash", "shell", "directory", "cd" ]
How do I change my current directory from a python script?
2,571,524
<p>I'm trying to implement my own version of the 'cd' command that presents the user with a list of hard-coded directories to choose from, and the user has to enter a number corresponding to an entry in the list. The program, named <code>my_cd.py</code> for now, should then effectively 'cd' the user to the chosen direc...
3
2010-04-03T14:38:37Z
2,571,571
<p>Change your sourced <code>bash</code> code to:</p> <pre><code>#! /bin/bash function my_cd() { cd `/path/to/my_cd.py` } </code></pre> <p>and your Python code to do all of its <code>cosmetic</code> output (messages to the users, menus, etc) on <code>sys.stderr</code>, and, at the end, instead of <code>os.chdir</...
6
2010-04-03T14:52:42Z
[ "python", "bash", "shell", "directory", "cd" ]
How do I change my current directory from a python script?
2,571,524
<p>I'm trying to implement my own version of the 'cd' command that presents the user with a list of hard-coded directories to choose from, and the user has to enter a number corresponding to an entry in the list. The program, named <code>my_cd.py</code> for now, should then effectively 'cd' the user to the chosen direc...
3
2010-04-03T14:38:37Z
2,571,691
<p>For what its worth, since this question is also tagged "bash", here is a simple bash-only solution:</p> <pre><code>$ cat select_cd #!/bin/bash PS3="Number: " dir_choices="/home/klittle /local_home/oracle" select CHOICE in $dir_choices; do break done [[ "$CHOICE" != "" ]] &amp;&amp; eval 'cd '$CHOICE </code>...
2
2010-04-03T15:36:18Z
[ "python", "bash", "shell", "directory", "cd" ]
How do I change my current directory from a python script?
2,571,524
<p>I'm trying to implement my own version of the 'cd' command that presents the user with a list of hard-coded directories to choose from, and the user has to enter a number corresponding to an entry in the list. The program, named <code>my_cd.py</code> for now, should then effectively 'cd' the user to the chosen direc...
3
2010-04-03T14:38:37Z
2,572,388
<p>Contrary to what was said, you can do this by replacing the process image, twice.</p> <p>In bash, replace your my_cd function with:</p> <pre><code>function my_cd() { exec /path/to/my_cd.py "$BASH" "$0" } </code></pre> <p>Then your python script has to finish with:</p> <pre><code>os.execl(sys.argv[1], sys.arg...
1
2010-04-03T19:27:47Z
[ "python", "bash", "shell", "directory", "cd" ]
Appengine Apps Vs Google bot web crawler
2,571,701
<p>i built an appengine web app cricket.hover.in. The web app consists of about 15k url's linked in it, But even after a long time of my launch, no pages are indexed on google.</p> <p>Any base link place on my root site hover.in are being indexed with in minutes. but i placed the same link home page of root site a lon...
1
2010-04-03T15:39:53Z
2,571,748
<p>Does your site have proper <a href="http://en.wikipedia.org/wiki/Sitemaps" rel="nofollow">sitemaps</a> and have you pushed them to Google and other search engines? I can't check because <code>http://cricket.hover.in</code> gives me a 404, so it could be a DNS problem. What happens when you point your browser to th...
1
2010-04-03T15:54:48Z
[ "python", "google-app-engine", "seo", "web-crawler", "bots" ]
Appengine Apps Vs Google bot web crawler
2,571,701
<p>i built an appengine web app cricket.hover.in. The web app consists of about 15k url's linked in it, But even after a long time of my launch, no pages are indexed on google.</p> <p>Any base link place on my root site hover.in are being indexed with in minutes. but i placed the same link home page of root site a lon...
1
2010-04-03T15:39:53Z
2,571,749
<p>Well, from this corner of the cyberspace, there is no such domain cricket.hover.in. </p> <pre><code>$ dig cricket.hover.in. ; &lt;&lt;&gt;&gt; DiG 9.6.1-P2 &lt;&lt;&gt;&gt; cricket.hover.in. ;; -&gt;&gt;HEADER&lt;&lt;- opcode: QUERY, status: NXDOMAIN, id: 30665 </code></pre> <p>I'd also guess that a URL that retur...
2
2010-04-03T15:55:03Z
[ "python", "google-app-engine", "seo", "web-crawler", "bots" ]
Python2.6 Decimal to Octal
2,571,840
<p>How can i convert decimal to Octal in Python2.6, for 1 to 100000? I wanna get this converted result as .txt too. Can someone help me?</p>
3
2010-04-03T16:22:48Z
2,571,849
<p>Use the <code>oct</code> function:</p> <pre><code>print oct(9) # prints 011 </code></pre>
9
2010-04-03T16:25:42Z
[ "python", "decimal", "octal" ]
Python2.6 Decimal to Octal
2,571,840
<p>How can i convert decimal to Octal in Python2.6, for 1 to 100000? I wanna get this converted result as .txt too. Can someone help me?</p>
3
2010-04-03T16:22:48Z
2,571,892
<p>This should do the trick:</p> <pre><code>text = '\n'.join(str(oct(i)) for i in xrange(100000)) f = open('foo.txt', 'w') f.write(text) f.close() </code></pre>
1
2010-04-03T16:38:30Z
[ "python", "decimal", "octal" ]
GUI IDE with PyDev Eclipse
2,571,858
<p>I have 2 weeks to finish my final year project.I need a GUI IDE or a GUI framework compatible with PyDev and Eclipse.</p> <p>I cannot spend time learning something cause the functionality is yet to be completed.I'm looking for very simple GUI for a simulation game.</p>
4
2010-04-03T16:28:40Z
2,572,207
<p>This page <a href="http://wiki.python.org/moin/GuiProgramming" rel="nofollow">http://wiki.python.org/moin/GuiProgramming</a> has a fairly complete list of gui frameworks and gui builders. I don't have too much experience with building gui's, but I've done a little bit with WxPython and PyQt. Both seem fairly eas...
1
2010-04-03T18:22:27Z
[ "python", "eclipse", "user-interface", "ide", "pydev" ]
GUI IDE with PyDev Eclipse
2,571,858
<p>I have 2 weeks to finish my final year project.I need a GUI IDE or a GUI framework compatible with PyDev and Eclipse.</p> <p>I cannot spend time learning something cause the functionality is yet to be completed.I'm looking for very simple GUI for a simulation game.</p>
4
2010-04-03T16:28:40Z
2,572,281
<p>PyQt is the fastest GUI toolkit to develop with IMO, partly because you can use <a href="http://qt.nokia.com/products/developer-tools" rel="nofollow">Qt Designer</a> to design your GUI instead of coding it by hand.</p> <p>You may want to also check out pygame - <a href="http://www.pygame.org/news.html" rel="nofollo...
4
2010-04-03T18:48:31Z
[ "python", "eclipse", "user-interface", "ide", "pydev" ]
GUI IDE with PyDev Eclipse
2,571,858
<p>I have 2 weeks to finish my final year project.I need a GUI IDE or a GUI framework compatible with PyDev and Eclipse.</p> <p>I cannot spend time learning something cause the functionality is yet to be completed.I'm looking for very simple GUI for a simulation game.</p>
4
2010-04-03T16:28:40Z
2,572,523
<blockquote> <p>I need a GUI IDE or a GUI framework compatible with PyDev and Eclipse.</p> </blockquote> <p>There is <strong>no</strong> Eclipse embedded GUI editor for any of the Python GUI frameworks, but it's not so bad. Do you really <em>need</em> for it to be integrated on Eclipse?</p> <p>The closest you can ...
2
2010-04-03T20:12:31Z
[ "python", "eclipse", "user-interface", "ide", "pydev" ]
GUI IDE with PyDev Eclipse
2,571,858
<p>I have 2 weeks to finish my final year project.I need a GUI IDE or a GUI framework compatible with PyDev and Eclipse.</p> <p>I cannot spend time learning something cause the functionality is yet to be completed.I'm looking for very simple GUI for a simulation game.</p>
4
2010-04-03T16:28:40Z
21,695,702
<p>I just installed mine folowing this <a href="http://popdevelop.com/2010/04/setting-up-ide-and-creating-a-cross-platform-qt-python-gui-application/" rel="nofollow">tutorial</a>. give it a try</p>
0
2014-02-11T07:30:39Z
[ "python", "eclipse", "user-interface", "ide", "pydev" ]
How can I configure vim syntax highlighting for mako templates?
2,571,893
<p>I'd like to get the HTML elements highlighted as well as the MAKO / Python elements.</p> <p>Thanks.</p>
4
2010-04-03T16:38:57Z
2,571,914
<p><a href="http://www.vim.org/scripts/script.php?script_id=1858" rel="nofollow" title="mako.vim">This syntax file</a> should (at least) highlight the mako elements.</p>
4
2010-04-03T16:48:08Z
[ "python", "vim", "mako" ]
What's the fastest way to convert a string of text into a url-safe variable?
2,571,930
<p>I'd like to convert a string of text, e.g., "User Name" into something which I can turn into part of a url, e.g., "User-Name." What's the fastest way to do a string replacement ("-" for " ") as well as make sure that characters are only [a-zA-Z0-9]?</p>
2
2010-04-03T16:53:30Z
2,571,970
<p>string.translate is often the fastest solution for these sorts of problems (assuming your strings aren't unicode).</p> <pre><code>def translate(x): if x == ' ': return '-' if 'a' &lt;= x &lt;= 'z': return x if 'A' &lt;= x &lt;= 'Z': return x if '0' &lt;= x &lt;= '9': return x def mk_translator(): ...
3
2010-04-03T17:06:24Z
[ "python", "string" ]
What's the fastest way to convert a string of text into a url-safe variable?
2,571,930
<p>I'd like to convert a string of text, e.g., "User Name" into something which I can turn into part of a url, e.g., "User-Name." What's the fastest way to do a string replacement ("-" for " ") as well as make sure that characters are only [a-zA-Z0-9]?</p>
2
2010-04-03T16:53:30Z
2,571,985
<p>I have used this function for that purpose:</p> <pre><code>import unicodedata def slugify(item): ret = item.lower().replace(u' ', u'_') return unicodedata.normalize('NFKD', ret).encode('ascii', 'ignore') </code></pre> <p>I'm not sure if it's the fastest way, though.</p>
0
2010-04-03T17:10:57Z
[ "python", "string" ]
What's the fastest way to convert a string of text into a url-safe variable?
2,571,930
<p>I'd like to convert a string of text, e.g., "User Name" into something which I can turn into part of a url, e.g., "User-Name." What's the fastest way to do a string replacement ("-" for " ") as well as make sure that characters are only [a-zA-Z0-9]?</p>
2
2010-04-03T16:53:30Z
2,572,031
<p><a href="http://docs.python.org/library/urllib.html#urllib.quote" rel="nofollow">urllib.quote</a> won't turn spaces to dashes, but to %20, but its designed exactly for the purpose of making string url-safe.</p>
1
2010-04-03T17:23:59Z
[ "python", "string" ]
What's the fastest way to convert a string of text into a url-safe variable?
2,571,930
<p>I'd like to convert a string of text, e.g., "User Name" into something which I can turn into part of a url, e.g., "User-Name." What's the fastest way to do a string replacement ("-" for " ") as well as make sure that characters are only [a-zA-Z0-9]?</p>
2
2010-04-03T16:53:30Z
16,180,365
<p>I like Ofri's version for simplicity and safety, and user97370's version for making spaces look nice.</p> <p>Why not have both?</p> <p>I would do it like this:</p> <pre><code>import string, urllib trans = string.maketrans(' ', '-') x = 'a sentence with a bunch of spaces' x2 = x.translate(trans) x3 = urllib.quote(...
0
2013-04-23T22:41:12Z
[ "python", "string" ]
Python's safest method to store and retrieve passwords from a database
2,572,099
<p>Looking to store usernames and passwords in a database, and am wondering what the safest way to do so is. I know I have to use a salt somewhere, but am not sure how to generate it securely or how to apply it to encrypt the password. Some sample Python code would be greatly appreciated. Thanks.</p>
23
2010-04-03T17:44:57Z
2,572,116
<p>Store the password+salt as a hash and the salt. Take a look at how Django does it: <a href="https://docs.djangoproject.com/en/1.8/topics/auth/passwords/" rel="nofollow">basic docs</a> and <a href="http://code.djangoproject.com/browser/django/trunk/django/contrib/auth/models.py" rel="nofollow">source</a>. In the db t...
30
2010-04-03T17:50:07Z
[ "python", "encryption", "passwords", "password-protection" ]
Python's safest method to store and retrieve passwords from a database
2,572,099
<p>Looking to store usernames and passwords in a database, and am wondering what the safest way to do so is. I know I have to use a salt somewhere, but am not sure how to generate it securely or how to apply it to encrypt the password. Some sample Python code would be greatly appreciated. Thanks.</p>
23
2010-04-03T17:44:57Z
2,591,711
<p>If you have enough control over both endpoints of the application, the absolute best way is using <a href="http://en.wikipedia.org/wiki/Secure_Remote_Password_protocol" rel="nofollow">SRP</a>.</p>
1
2010-04-07T10:46:24Z
[ "python", "encryption", "passwords", "password-protection" ]
Python's safest method to store and retrieve passwords from a database
2,572,099
<p>Looking to store usernames and passwords in a database, and am wondering what the safest way to do so is. I know I have to use a salt somewhere, but am not sure how to generate it securely or how to apply it to encrypt the password. Some sample Python code would be greatly appreciated. Thanks.</p>
23
2010-04-03T17:44:57Z
10,948,783
<p>I think it is best to use a package dedicated to hashing passwords for this like passlib: <a href="http://packages.python.org/passlib/">http://packages.python.org/passlib/</a> for reasons as I explained here: <a href="http://stackoverflow.com/a/10948614/893857">http://stackoverflow.com/a/10948614/893857</a></p>
12
2012-06-08T12:22:37Z
[ "python", "encryption", "passwords", "password-protection" ]
Python's safest method to store and retrieve passwords from a database
2,572,099
<p>Looking to store usernames and passwords in a database, and am wondering what the safest way to do so is. I know I have to use a salt somewhere, but am not sure how to generate it securely or how to apply it to encrypt the password. Some sample Python code would be greatly appreciated. Thanks.</p>
23
2010-04-03T17:44:57Z
14,168,056
<p>Here is a simpler way (taken from effbot), provided passwords with a length greater than 8 will not be a problem*:</p> <pre><code>import crypt import random, string def getsalt(chars = string.letters + string.digits): # generate a random 2-character 'salt' return random.choice(chars) + random.choice(chars...
0
2013-01-05T02:49:10Z
[ "python", "encryption", "passwords", "password-protection" ]
Python's safest method to store and retrieve passwords from a database
2,572,099
<p>Looking to store usernames and passwords in a database, and am wondering what the safest way to do so is. I know I have to use a salt somewhere, but am not sure how to generate it securely or how to apply it to encrypt the password. Some sample Python code would be greatly appreciated. Thanks.</p>
23
2010-04-03T17:44:57Z
18,494,729
<p>I answered this here: <a href="http://stackoverflow.com/a/18488878/1661689">http://stackoverflow.com/a/18488878/1661689</a>, and so did @Koffie.</p> <p>I don't know how to emphasize enough that the accepted answer is NOT secure. It is better than plain text, and better than an unsalted hash, but it is still <strong...
8
2013-08-28T17:42:49Z
[ "python", "encryption", "passwords", "password-protection" ]
Control links2 by python
2,572,123
<p>Is there any way to control links browser from python? I need to make some bot, twill don't work on my page, Selenium need's X server. Maybe other way to do it?</p>
1
2010-04-03T17:52:42Z
2,572,168
<p>I would try to use <a href="http://www.noah.org/wiki/Pexpect" rel="nofollow">pexpect</a> (on Unix-like systems; <a href="http://code.google.com/p/wexpect/downloads/list" rel="nofollow">wexpect</a> on Windows), just as I would for the purpose of controlling other text-based, interactive applications that don't offer ...
0
2010-04-03T18:09:38Z
[ "python", "control", "hyperlink" ]
Control links2 by python
2,572,123
<p>Is there any way to control links browser from python? I need to make some bot, twill don't work on my page, Selenium need's X server. Maybe other way to do it?</p>
1
2010-04-03T17:52:42Z
2,573,927
<p>Using X virtual framebuffer Xvfb you can run selenium/web browser without X:</p> <pre><code>Xvfb :1 -screen 0 1152x864x16 DISPLAY=1 ./firefox </code></pre> <p>and run the selenium tests from command line.</p>
1
2010-04-04T08:36:12Z
[ "python", "control", "hyperlink" ]
Using zc.buildout, how do I install a tarball from a website?
2,572,160
<p>I'm trying to get zc.buildout to install Gunicorn from source. Using the following configuration:</p> <pre><code>[gunicorn] recipe = collective.recipe.distutils url = http://github.com/benoitc/gunicorn/tarball/master </code></pre> <p>results in the following error:</p> <pre><code>SystemError: ('Failed', '"/usr/bi...
1
2010-04-03T18:04:16Z
2,599,629
<p>You can "just" install it. On the command line, "easy_install <a href="http://github.com/benoitc/gunicorn/tarball/master" rel="nofollow">http://github.com/benoitc/gunicorn/tarball/master</a>" works fine.</p> <p>The buildout equivalent would be to have a dependency on "gunicorn" (so that buildout attempts installin...
3
2010-04-08T12:08:28Z
[ "python", "buildout", "recipe" ]
Referencing other modules in atexit
2,572,172
<p>I have a function that is responsible for killing a child process when the program ends:</p> <pre><code>class MySingleton: def __init__(self): import atexit atexit.register(self.stop) def stop(self): os.kill(self.sel_server_pid, signal.SIGTERM) </code></pre> <p>However I get an err...
1
2010-04-03T18:11:48Z
2,572,181
<p>There are no strong guarantees about the order in which things are destroyed at program termination time, so it's best to ensure <code>atexit</code>-registered functions are self contained. E.g., in your case:</p> <pre><code>class MySingleton: def __init__(self): import atexit atexit.register(s...
6
2010-04-03T18:15:34Z
[ "python", "atexit" ]
Django ORM: Ordering w/ aggregate functions — None special treatment
2,572,201
<p>I'm doing this query:</p> <pre><code>SomeObject.objects.annotate(something=Avg('something')).order_by(something).all() </code></pre> <p>I normally have an aggregate field in my model that I use with Django signals to keep in sync, however in this case perfomance isn't an issue so I thought I'd keep it simple and j...
1
2010-04-03T18:20:28Z
2,572,573
<p>How about just adding a has_something=1,0 via extra() and then order on both has_something and something?</p> <pre><code>with_avg = SomeObject.objects.annotate(avg=Avg('something')) with_avg_and_has = with_avg.extra(select={'has_something': 'something is NULL'}) sorted_result = with_avg_and_has.order_by('-has_somet...
2
2010-04-03T20:31:56Z
[ "python", "django", "orm", "aggregate" ]
Starting out NLP - Python + large data set
2,572,205
<p>I've been wanting to learn python and do some NLP, so have finally gotten round to starting. Downloaded the english wikipedia mirror for a nice chunky dataset to start on, and have been playing around a bit, at this stage just getting some of it into a sqlite db (havent worked with dbs in the past unfort).</p> <p>B...
2
2010-04-03T18:22:12Z
2,572,260
<p><a href="http://www.nltk.org/" rel="nofollow">NLTK</a> is where you should start from (it's Python-based -- not sure why you're already thinking about parallelizing your processing at such an early stage... start with a more flexible experimental setup, is my advice). sqlite should be fine for a few GB -- if you ne...
3
2010-04-03T18:41:36Z
[ "java", "python", "database", "nlp" ]
Starting out NLP - Python + large data set
2,572,205
<p>I've been wanting to learn python and do some NLP, so have finally gotten round to starting. Downloaded the english wikipedia mirror for a nice chunky dataset to start on, and have been playing around a bit, at this stage just getting some of it into a sqlite db (havent worked with dbs in the past unfort).</p> <p>B...
2
2010-04-03T18:22:12Z
2,574,163
<p>There is a related talk on PyCon 2010 <a href="http://us.pycon.org/2010/conference/schedule/event/98/" rel="nofollow">"The Python and the Elephant: Large Scale Natural Language Processing with NLTK and Dumbo"</a>. The link has introductory information, slides and video.<br> I think sqlite is still a good choice for ...
1
2010-04-04T10:37:47Z
[ "java", "python", "database", "nlp" ]
Python's urllib2 doesn't work on some sites
2,572,266
<p>I found that you can't read from some sites using Python's urllib2(or urllib). An example...</p> <pre><code>urllib2.urlopen("http://www.dafont.com/").read() # Returns '' </code></pre> <p>These sites work when you visit the site with a browser. I can even scrape them using PHP(didn't try other languages). I have se...
2
2010-04-03T18:44:24Z
2,572,283
<p>I'm the guy who posted the question. I have some suspicions - but not sure about them - that's why I posted the question here.</p> <h2>What is the cause of this issue?</h2> <p>I think its due to the host blocking the urllib library using robot.txt or htaccess. But not sure about it. Not even sure if its possible.<...
0
2010-04-03T18:48:46Z
[ "python", "urllib2", "urllib" ]
Python's urllib2 doesn't work on some sites
2,572,266
<p>I found that you can't read from some sites using Python's urllib2(or urllib). An example...</p> <pre><code>urllib2.urlopen("http://www.dafont.com/").read() # Returns '' </code></pre> <p>These sites work when you visit the site with a browser. I can even scrape them using PHP(didn't try other languages). I have se...
2
2010-04-03T18:44:24Z
2,572,306
<p>I believe it gets blocked by the User-Agent. You can change User-Agent using the following sample code:</p> <pre><code>USERAGENT = 'something' HEADERS = {'User-Agent': USERAGENT} req = urllib2.Request(URL_HERE, headers=HEADERS) f = urllib2.urlopen(req) s = f.read() f.close() </code></pre>
6
2010-04-03T18:55:57Z
[ "python", "urllib2", "urllib" ]
Python's urllib2 doesn't work on some sites
2,572,266
<p>I found that you can't read from some sites using Python's urllib2(or urllib). An example...</p> <pre><code>urllib2.urlopen("http://www.dafont.com/").read() # Returns '' </code></pre> <p>These sites work when you visit the site with a browser. I can even scrape them using PHP(didn't try other languages). I have se...
2
2010-04-03T18:44:24Z
2,572,310
<p>Try setting a different user agent. Check the answers in <a href="http://stackoverflow.com/questions/802134/changing-user-agent-on-urllib2-urlopen">this link</a>.</p>
3
2010-04-03T18:56:09Z
[ "python", "urllib2", "urllib" ]
Returning a list in this recursive coi function in python
2,572,313
<p>I'm having trouble getting my list to return in my code. Instead of returning the list, it keeps returning None, but if I replace the return with print in the elif statement, it prints the list just fine. How can I repair this? </p> <pre><code>def makeChange2(amount, coinDenomination, listofcoins = None): #makes ...
2
2010-04-03T18:57:57Z
2,572,318
<p>You're not <code>return</code>ing the value of the recursive calls to <code>makeChange2</code>.</p> <p>Once control reaches either of those calls to <code>makeChange2</code> and completes the call, the program continues to the next statement, which is the end of the function; thus, it returns <code>None</code>.</p>...
3
2010-04-03T19:00:01Z
[ "python", "list", "recursion" ]
Python Equivalent to phpinfo()
2,572,371
<p>Quite simply, is there a <a href="http://www.python.org/">python</a> equivalent to php's <code>phpinfo();</code>? If so, what is it and how do I use it (a link to a reference page would work great). </p>
6
2010-04-03T19:22:08Z
2,572,384
<p>Afaik there is no similar function. However, the <a href="http://docs.python.org/library/platform.html" rel="nofollow">platform module</a> allows you to access some basic information about the machine, OS and Python.</p>
1
2010-04-03T19:26:46Z
[ "python", "phpinfo" ]
Python Equivalent to phpinfo()
2,572,371
<p>Quite simply, is there a <a href="http://www.python.org/">python</a> equivalent to php's <code>phpinfo();</code>? If so, what is it and how do I use it (a link to a reference page would work great). </p>
6
2010-04-03T19:22:08Z
2,572,387
<p>There is nothing directly comparable to <code>phpinfo()</code>, but you can get some bits of information ...</p> <pre><code>&gt;&gt;&gt; import sys &gt;&gt;&gt; sys.version '2.6.4 (r264:75706, Feb 6 2010, 01:49:44) \n[GCC 4.2.1 (Apple Inc. build 5646)]' &gt;&gt;&gt; sys.platform 'darwin' &gt;&gt;&gt; sys.modules...
2
2010-04-03T19:27:28Z
[ "python", "phpinfo" ]
Python Equivalent to phpinfo()
2,572,371
<p>Quite simply, is there a <a href="http://www.python.org/">python</a> equivalent to php's <code>phpinfo();</code>? If so, what is it and how do I use it (a link to a reference page would work great). </p>
6
2010-04-03T19:22:08Z
2,572,395
<p>Did you try this out: <a href="http://www.webhostingtalk.com/showpost.php?s=f55e18d344e3783edd98aef5be809ac8&amp;p=4632018&amp;postcount=4" rel="nofollow">http://www.webhostingtalk.com/showpost.php?s=f55e18d344e3783edd98aef5be809ac8&amp;p=4632018&amp;postcount=4</a></p>
3
2010-04-03T19:28:37Z
[ "python", "phpinfo" ]
Python Equivalent to phpinfo()
2,572,371
<p>Quite simply, is there a <a href="http://www.python.org/">python</a> equivalent to php's <code>phpinfo();</code>? If so, what is it and how do I use it (a link to a reference page would work great). </p>
6
2010-04-03T19:22:08Z
2,572,403
<p>phpinfo prints information about running PHP version, loaded modules and so on.</p> <p>AFAIK Python does not such a conventient function that dumps the complete configuration.</p> <p>But you should have a look at the <code>sys</code> package.</p> <pre><code>import sys # print all imported modules since start pri...
0
2010-04-03T19:30:37Z
[ "python", "phpinfo" ]
Python Equivalent to phpinfo()
2,572,371
<p>Quite simply, is there a <a href="http://www.python.org/">python</a> equivalent to php's <code>phpinfo();</code>? If so, what is it and how do I use it (a link to a reference page would work great). </p>
6
2010-04-03T19:22:08Z
3,440,230
<p>Check this one out!</p> <p><a href="http://bran.name/articles/pyinfo-a-good-looking-phpinfo-like-python-script">pyinfo() A good looking phpinfo-like python script</a></p>
5
2010-08-09T13:01:37Z
[ "python", "phpinfo" ]
Extract the SHA1 hash from a torrent file
2,572,521
<p>I've had a look around for the answer to this, but I only seem to be able to find software that does it for you. Does anybody know how to go about doing this in python?</p>
17
2010-04-03T20:10:21Z
2,573,715
<p>I wrote a piece of python code that verifies the hashes of <em>downloaded files</em> against what's in a <em>.torrent file</em>. Assuming you want to check a download for corruption you may find this useful.</p> <p>You need the <a href="http://pypi.python.org/pypi/BitTorrent-bencode">bencode package</a> to use this...
22
2010-04-04T05:59:06Z
[ "python", "hash", "extract", "sha1", "bittorrent" ]
Extract the SHA1 hash from a torrent file
2,572,521
<p>I've had a look around for the answer to this, but I only seem to be able to find software that does it for you. Does anybody know how to go about doing this in python?</p>
17
2010-04-03T20:10:21Z
2,573,810
<p>According to <a href="http://wiki.theory.org/BitTorrentSpecification#bencoding" rel="nofollow">this</a>, you should be able to find the md5sums of files by searching for the part of the data that looks like:</p> <p><code>d[...]6:md5sum32:[hash is here][...]e</code></p> <p>(SHA is not part of the spec)</p>
0
2010-04-04T07:11:41Z
[ "python", "hash", "extract", "sha1", "bittorrent" ]
Extract the SHA1 hash from a torrent file
2,572,521
<p>I've had a look around for the answer to this, but I only seem to be able to find software that does it for you. Does anybody know how to go about doing this in python?</p>
17
2010-04-03T20:10:21Z
4,173,411
<p>Here how I've extracted HASH value from torrent file:</p> <pre><code>#!/usr/bin/python import sys, os, hashlib, StringIO import bencode def main(): # Open torrent file torrent_file = open(sys.argv[1], "rb") metainfo = bencode.bdecode(torrent_file.read()) info = metainfo['info'] print hashlib...
13
2010-11-13T16:07:30Z
[ "python", "hash", "extract", "sha1", "bittorrent" ]
Python lambda returning None instead of empty string
2,572,564
<p>I have the following lambda function:</p> <pre><code>f = lambda x: x == None and '' or x </code></pre> <p>It should return an empty string if it receives None as the argument, or the argument if it's not None.</p> <p>For example:</p> <pre><code>&gt;&gt;&gt; f(4) 4 &gt;&gt;&gt; f(None) &gt;&gt;&gt; </code></pre> ...
7
2010-04-03T20:27:15Z
2,572,570
<p>It's not lambdas that are the problem here. It's the pythonic if/else expressiong you are using there.</p> <p><code>(condition) and (expression1) or (expression2)</code> most of the times means the <code>(condition) ? (expression1) : (expression2)</code> you'd expect, except when <code>expression1</code> evaluates ...
2
2010-04-03T20:30:47Z
[ "python", "lambda" ]
Python lambda returning None instead of empty string
2,572,564
<p>I have the following lambda function:</p> <pre><code>f = lambda x: x == None and '' or x </code></pre> <p>It should return an empty string if it receives None as the argument, or the argument if it's not None.</p> <p>For example:</p> <pre><code>&gt;&gt;&gt; f(4) 4 &gt;&gt;&gt; f(None) &gt;&gt;&gt; </code></pre> ...
7
2010-04-03T20:27:15Z
2,572,572
<p>The problem in your case that '' is considered as boolean False. bool('') == False. You can use</p> <pre><code>f =lambda x:x if x is not None else '' </code></pre>
8
2010-04-03T20:31:50Z
[ "python", "lambda" ]
Python lambda returning None instead of empty string
2,572,564
<p>I have the following lambda function:</p> <pre><code>f = lambda x: x == None and '' or x </code></pre> <p>It should return an empty string if it receives None as the argument, or the argument if it's not None.</p> <p>For example:</p> <pre><code>&gt;&gt;&gt; f(4) 4 &gt;&gt;&gt; f(None) &gt;&gt;&gt; </code></pre> ...
7
2010-04-03T20:27:15Z
2,572,574
<p>Try <a href="http://en.wikipedia.org/wiki/Short-circuit_evaluation" rel="nofollow">short-circuit evaluation</a>:</p> <pre><code> &gt;&gt;&gt; g = lambda x: x or '' &gt;&gt;&gt; g(3) 3 &gt;&gt;&gt; g(None) '' &gt;&gt;&gt; # beware that ... &gt;&gt;&gt; g(0) '' </code></pre>
2
2010-04-03T20:31:57Z
[ "python", "lambda" ]
Python lambda returning None instead of empty string
2,572,564
<p>I have the following lambda function:</p> <pre><code>f = lambda x: x == None and '' or x </code></pre> <p>It should return an empty string if it receives None as the argument, or the argument if it's not None.</p> <p>For example:</p> <pre><code>&gt;&gt;&gt; f(4) 4 &gt;&gt;&gt; f(None) &gt;&gt;&gt; </code></pre> ...
7
2010-04-03T20:27:15Z
2,572,575
<p>use the if else construct</p> <pre><code>f = lambda x:'' if x is None else x </code></pre>
15
2010-04-03T20:31:58Z
[ "python", "lambda" ]
Python lambda returning None instead of empty string
2,572,564
<p>I have the following lambda function:</p> <pre><code>f = lambda x: x == None and '' or x </code></pre> <p>It should return an empty string if it receives None as the argument, or the argument if it's not None.</p> <p>For example:</p> <pre><code>&gt;&gt;&gt; f(4) 4 &gt;&gt;&gt; f(None) &gt;&gt;&gt; </code></pre> ...
7
2010-04-03T20:27:15Z
2,572,587
<p>Python gives <code>and</code> a higher precedence than <code>or</code>, so the parentheses fall here:</p> <pre><code>lambda x: (x == None and '') or x </code></pre> <p>When passed <code>None</code>, this becomes <code>(True and '') or None</code>. Python’s boolean operators work by returning one argument or anot...
2
2010-04-03T20:36:03Z
[ "python", "lambda" ]
Python lambda returning None instead of empty string
2,572,564
<p>I have the following lambda function:</p> <pre><code>f = lambda x: x == None and '' or x </code></pre> <p>It should return an empty string if it receives None as the argument, or the argument if it's not None.</p> <p>For example:</p> <pre><code>&gt;&gt;&gt; f(4) 4 &gt;&gt;&gt; f(None) &gt;&gt;&gt; </code></pre> ...
7
2010-04-03T20:27:15Z
2,572,592
<p>The problem is that Python treats the empty string as False. When you pass None to your function, it evaluates to:</p> <pre><code>None == None and '' or None </code></pre> <p>which (effectively) becomes:</p> <pre><code>True and False or None </code></pre> <p>then:</p> <pre><code>False or None </code></pre> <p...
4
2010-04-03T20:38:26Z
[ "python", "lambda" ]
Return a list of imported Python modules used in a script?
2,572,582
<p>I am writing a program that categorizes a list of Python files by which modules they import. As such I need to scan the collection of .py files ad return a list of which modules they import. As an example, if one of the files I import has the following lines:</p> <pre><code>import os import sys, gtk </code></pre> ...
17
2010-04-03T20:33:45Z
2,572,623
<p>IMO the best way todo this is to use the <a href="http://furius.ca/snakefood/">http://furius.ca/snakefood/</a> package. The author has done all of the required work to get not only directly imported modules but it uses the AST to parse the code for runtime dependencies that a more static analysis would miss.</p> <...
9
2010-04-03T20:48:25Z
[ "python", "module" ]
Return a list of imported Python modules used in a script?
2,572,582
<p>I am writing a program that categorizes a list of Python files by which modules they import. As such I need to scan the collection of .py files ad return a list of which modules they import. As an example, if one of the files I import has the following lines:</p> <pre><code>import os import sys, gtk </code></pre> ...
17
2010-04-03T20:33:45Z
2,572,654
<p>Well, you could always write a simple script that searches the file for <code>import</code> statements. This one finds all imported modules and files, including those imported in functions or classes:</p> <pre><code>def find_imports(toCheck): """ Given a filename, returns a list of modules imported by the p...
2
2010-04-03T20:57:45Z
[ "python", "module" ]
Return a list of imported Python modules used in a script?
2,572,582
<p>I am writing a program that categorizes a list of Python files by which modules they import. As such I need to scan the collection of .py files ad return a list of which modules they import. As an example, if one of the files I import has the following lines:</p> <pre><code>import os import sys, gtk </code></pre> ...
17
2010-04-03T20:33:45Z
2,572,702
<p>It depends how thorough you want to be. Used modules is a turing complete problem: some python code uses lazy importing to only import things they actually use on a particular run, some generate things to import dynamically (e.g. plugin systems).</p> <p>python -v will trace import statements - its arguably the simp...
3
2010-04-03T21:14:38Z
[ "python", "module" ]
Return a list of imported Python modules used in a script?
2,572,582
<p>I am writing a program that categorizes a list of Python files by which modules they import. As such I need to scan the collection of .py files ad return a list of which modules they import. As an example, if one of the files I import has the following lines:</p> <pre><code>import os import sys, gtk </code></pre> ...
17
2010-04-03T20:33:45Z
11,705,973
<p>I'm editing my original answer to say this. This is doable with a code snippet like the one below, but parsing the <a href="https://docs.python.org/3/library/ast.html" rel="nofollow">AST</a> may be the best way to go.</p> <pre><code>def iter_imports(fd): """ Yield only lines that appear to be imports from an it...
-1
2012-07-29T01:38:43Z
[ "python", "module" ]
Return a list of imported Python modules used in a script?
2,572,582
<p>I am writing a program that categorizes a list of Python files by which modules they import. As such I need to scan the collection of .py files ad return a list of which modules they import. As an example, if one of the files I import has the following lines:</p> <pre><code>import os import sys, gtk </code></pre> ...
17
2010-04-03T20:33:45Z
19,385,691
<p>For the majority of scripts which only import modules at the top level, it is quite sufficient to load the file as a module, and scan its members for modules:</p> <pre><code>import sys,io,imp,types scriptname = 'myfile.py' with io.open(scriptname) as scriptfile: code = compile(scriptfile.readall(),scriptname,'e...
0
2013-10-15T15:54:37Z
[ "python", "module" ]
Return a list of imported Python modules used in a script?
2,572,582
<p>I am writing a program that categorizes a list of Python files by which modules they import. As such I need to scan the collection of .py files ad return a list of which modules they import. As an example, if one of the files I import has the following lines:</p> <pre><code>import os import sys, gtk </code></pre> ...
17
2010-04-03T20:33:45Z
22,441,743
<p>This works - using importlib to actually import the module, and inspect to get the members :</p> <pre><code>#! /usr/bin/env python # # test.py # # Find Modules # import inspect, importlib as implib if __name__ == "__main__": mod = implib.import_module( "example" ) for i in inspect.getmembers(mod, inspect...
1
2014-03-16T19:27:38Z
[ "python", "module" ]
Return a list of imported Python modules used in a script?
2,572,582
<p>I am writing a program that categorizes a list of Python files by which modules they import. As such I need to scan the collection of .py files ad return a list of which modules they import. As an example, if one of the files I import has the following lines:</p> <pre><code>import os import sys, gtk </code></pre> ...
17
2010-04-03T20:33:45Z
25,690,011
<p>I was looking for something similar and I found a gem in a package called <a href="https://pypi.python.org/pypi/PyScons" rel="nofollow">PyScons</a>. The Scanner does just what you want (in 7 lines), using an import_hook. Here is an abbreviated example:</p> <pre><code>import modulefinder, sys class SingleFileModule...
0
2014-09-05T16:10:40Z
[ "python", "module" ]
Return a list of imported Python modules used in a script?
2,572,582
<p>I am writing a program that categorizes a list of Python files by which modules they import. As such I need to scan the collection of .py files ad return a list of which modules they import. As an example, if one of the files I import has the following lines:</p> <pre><code>import os import sys, gtk </code></pre> ...
17
2010-04-03T20:33:45Z
35,495,585
<p>You might want to try <a href="https://docs.python.org/3/library/dis.html" rel="nofollow">dis</a> (pun intended): </p> <pre><code>import dis from collections import defaultdict from pprint import pprint statements = """ from __future__ import (absolute_import, division) import os import col...
0
2016-02-19T01:13:18Z
[ "python", "module" ]
Return a list of imported Python modules used in a script?
2,572,582
<p>I am writing a program that categorizes a list of Python files by which modules they import. As such I need to scan the collection of .py files ad return a list of which modules they import. As an example, if one of the files I import has the following lines:</p> <pre><code>import os import sys, gtk </code></pre> ...
17
2010-04-03T20:33:45Z
35,772,432
<p>It's actually working quite good with</p> <pre><code>print [key for key in locals().keys() if isinstance(locals()[key], type(sys)) and not key.startswith('__')] </code></pre>
0
2016-03-03T12:38:54Z
[ "python", "module" ]
Talking with a Bittorrent client listening on a port?
2,572,634
<p>I have one of my computers seeding a torrent file on port 45000. I am trying to write a small client in python (or perhaps perl) that helps me to determine the types of messages this client supports for which I need to perhaps do a handshake with the client. In Azureus, this is done using a call like peer.getSupport...
0
2010-04-03T20:51:02Z
2,572,821
<p>From what I can tell, the list of supported messages is a part of a custom handshake message supported only by Azureus (and possibly some Azureus-compliant tools) and is not part of the official BitTorrent system. However, you can probably craft a bencoded AZ handshake, send it to your seeder, decode the response, a...
2
2010-04-03T22:05:44Z
[ "python", "perl", "p2p", "bittorrent" ]
Using python to play two sine tones at once
2,572,651
<p>I'm using python to play a sine tone. The tone is based off the computer's internal time in minutes, but I'd like to simultaneously play one based off the second for a harmonized or dualing sound. </p> <p>This is what I have so far; can someone point me in the right direction?</p> <pre><code>from struct import pac...
4
2010-04-03T20:57:12Z
2,572,760
<p>What about the following minimal changes in your code...:</p> <pre><code>from struct import pack from math import sin, pi import time def au_file(name, freq, freq1, dur, vol): fout = open(name, 'wb') # header needs size, encoding=2, sampling_rate=8000, channel=1 fout.write('.snd' + pack('&gt;5L', 24, 8...
1
2010-04-03T21:41:35Z
[ "python", "audio" ]
Are there Python ORMs out there that support multiple independent databases concurrently in use?
2,572,686
<p>I'm writing an application in Python where I wish to use sqlite as the backing store for documents edited by the app, with documents generally living in memory, but being saved to disk-based databases when the application saves.</p> <p>Ideally I'd like to use something like an ORM to make access to the data from my...
3
2010-04-03T21:10:35Z
2,572,731
<p>The upcoming django 1.2 release supports this.</p> <p>Here's a description of it: <a href="http://djangoadvent.com/1.2/multiple-database-support/" rel="nofollow">http://djangoadvent.com/1.2/multiple-database-support/</a></p>
3
2010-04-03T21:28:28Z
[ "python", "orm" ]
Are there Python ORMs out there that support multiple independent databases concurrently in use?
2,572,686
<p>I'm writing an application in Python where I wish to use sqlite as the backing store for documents edited by the app, with documents generally living in memory, but being saved to disk-based databases when the application saves.</p> <p>Ideally I'd like to use something like an ORM to make access to the data from my...
3
2010-04-03T21:10:35Z
2,572,838
<p>SQLAlchemy does support multiple database connections per class, as in this example: <a href="http://svn.sqlalchemy.org/sqlalchemy/trunk/examples/sharding/attribute_shard.py" rel="nofollow">http://svn.sqlalchemy.org/sqlalchemy/trunk/examples/sharding/attribute_shard.py</a></p>
3
2010-04-03T22:10:35Z
[ "python", "orm" ]
Is frozenset adequate for caching of symmetric input data in a python dict?
2,572,899
<p>The title more or less says it all:</p> <p>I have a function which takes symmetric input in two arguments, e.g. something like</p> <pre><code>def f(a1, a2): return heavy_stuff(abs(a1 - a2)) </code></pre> <p>Now, I want to introduce some caching method. Would it be correct / pythonic / reasonably efficient to ...
1
2010-04-03T22:32:35Z
2,572,905
<p>Python always computes all arguments you're passing to a function, and only then does it call the function. In other words, like most other languages, Python is "eager" in its evaluation (the major exception today is probably Haskell, but that doesn't help you;-).</p> <p>So <code>setdefault</code> is a <strong>ver...
2
2010-04-03T22:36:22Z
[ "python", "caching", "set", "symmetric" ]
Numpy ‘smart’ symmetric matrix
2,572,916
<p>Is there a smart and space-efficient symmetric matrix in numpy which automatically (and transparently) fills the position at <code>[j][i]</code> when <code>[i][j]</code> is written to?</p> <pre><code>a = numpy.symmetric((3, 3)) a[0][1] = 1 a[1][0] == a[0][1] # True print a # [[0 1 0], [1 0 0], [0 0 0]] assert nump...
46
2010-04-03T22:39:56Z
2,573,982
<p>If you can afford to symmetrize the matrix just before doing calculations, the following should be reasonably fast:</p> <pre><code>def symmetrize(a): return a + a.T - numpy.diag(a.diagonal()) </code></pre> <p>This works under reasonable assumptions (such as not doing both <code>a[0, 1] = 42</code> and the cont...
53
2010-04-04T09:06:56Z
[ "python", "matrix", "numpy" ]
Numpy ‘smart’ symmetric matrix
2,572,916
<p>Is there a smart and space-efficient symmetric matrix in numpy which automatically (and transparently) fills the position at <code>[j][i]</code> when <code>[i][j]</code> is written to?</p> <pre><code>a = numpy.symmetric((3, 3)) a[0][1] = 1 a[1][0] == a[0][1] # True print a # [[0 1 0], [1 0 0], [0 0 0]] assert nump...
46
2010-04-03T22:39:56Z
9,455,669
<p>The more general issue of optimal treatment of symmetric matrices in numpy bugged me too.</p> <p>After looking into it, I think the answer is probably that numpy is somewhat constrained by the memory layout supportd by the underlying BLAS routines for symmetric matrices.</p> <p>While some BLAS routines do exploit ...
12
2012-02-26T18:06:50Z
[ "python", "matrix", "numpy" ]
Numpy ‘smart’ symmetric matrix
2,572,916
<p>Is there a smart and space-efficient symmetric matrix in numpy which automatically (and transparently) fills the position at <code>[j][i]</code> when <code>[i][j]</code> is written to?</p> <pre><code>a = numpy.symmetric((3, 3)) a[0][1] = 1 a[1][0] == a[0][1] # True print a # [[0 1 0], [1 0 0], [0 0 0]] assert nump...
46
2010-04-03T22:39:56Z
24,065,910
<p>This is plain python and not numpy, but I just threw together a routine to fill a symmetric matrix (and a test program to make sure it is correct):</p> <pre><code>import random # fill a symmetric matrix with costs (i.e. m[x][y] == m[y][x] # For demonstration purposes, this routine connect each node to all the othe...
1
2014-06-05T16:53:28Z
[ "python", "matrix", "numpy" ]
Numpy ‘smart’ symmetric matrix
2,572,916
<p>Is there a smart and space-efficient symmetric matrix in numpy which automatically (and transparently) fills the position at <code>[j][i]</code> when <code>[i][j]</code> is written to?</p> <pre><code>a = numpy.symmetric((3, 3)) a[0][1] = 1 a[1][0] == a[0][1] # True print a # [[0 1 0], [1 0 0], [0 0 0]] assert nump...
46
2010-04-03T22:39:56Z
24,563,079
<p>There are a number of well-known ways of storing symmetric matrices so they don't need to occupy n^2 storage elements. Moreover, it is feasible to rewrite common operations to access these revised means of storage. The definitive work is Golub and Van Loan, <em>Matrix Computations</em>, 3rd edition 1996, Johns Hop...
5
2014-07-03T20:47:39Z
[ "python", "matrix", "numpy" ]
What is float('123.987') in Python?
2,572,936
<p>It's <strong><em>123.98699999999999</em></strong> !</p> <p>Why is that?</p>
-1
2010-04-03T22:50:05Z
2,572,943
<p>See <a href="http://stackoverflow.com/questions/1089018/why-cant-decimal-numbers-be-represented-exactly-in-binary">Why can't decimal numbers be represented exactly in binary</a></p>
14
2010-04-03T22:51:57Z
[ "python", "floating-point" ]
What is float('123.987') in Python?
2,572,936
<p>It's <strong><em>123.98699999999999</em></strong> !</p> <p>Why is that?</p>
-1
2010-04-03T22:50:05Z
2,572,970
<p>The <a href="http://www.python.org/doc/faq/general/#why-are-floating-point-calculations-so-inaccurate" rel="nofollow">Python FAQ</a> and <a href="http://docs.python.org/tutorial/floatingpoint" rel="nofollow">tutorial</a> address this issue pretty well, I think. More generally, both are excellent resources, well wor...
5
2010-04-03T23:02:01Z
[ "python", "floating-point" ]
What is float('123.987') in Python?
2,572,936
<p>It's <strong><em>123.98699999999999</em></strong> !</p> <p>Why is that?</p>
-1
2010-04-03T22:50:05Z
2,572,982
<p>This has changed in/since <a href="http://docs.python.org/py3k/whatsnew/3.1.html#other-language-changes" rel="nofollow">Python 3.1</a>.</p> <p>See also: <a href="http://bugs.python.org/issue1580" rel="nofollow">issue 1580</a></p> <hr> <p>To your (already deleted) addition: Use the <a href="http://docs.python.org/...
3
2010-04-03T23:07:05Z
[ "python", "floating-point" ]
set timeout to http response read method in python
2,573,044
<p>I'm building a download manager in python for fun, and sometimes the connection to the server is still on but the server doesn't send me data, so read method (of HTTPResponse) block me forever. This happens, for example, when I download from a server, which located outside of my country, that limit the bandwidth to ...
1
2010-04-03T23:32:03Z
2,573,058
<p>You have to set it during <a href="http://docs.python.org/library/httplib.html#httplib.HTTPConnection" rel="nofollow">HTTPConnection</a> initialization.</p> <p>Note: in case you are using an older version of Python, then you can install <a href="http://code.google.com/p/httplib2/" rel="nofollow">httplib2</a>; by ma...
2
2010-04-03T23:37:16Z
[ "python", "timeout", "httpresponse" ]
set timeout to http response read method in python
2,573,044
<p>I'm building a download manager in python for fun, and sometimes the connection to the server is still on but the server doesn't send me data, so read method (of HTTPResponse) block me forever. This happens, for example, when I download from a server, which located outside of my country, that limit the bandwidth to ...
1
2010-04-03T23:32:03Z
2,573,134
<p>If you're stuck on some Python version <code>&lt; 2.6</code>, one (imperfect but usable) approach is to do</p> <pre><code>import socket socket.setdefaulttimeout(10.0) # or whatever </code></pre> <p>before you start using <code>httplib</code>. The docs are <a href="http://docs.python.org/library/socket.html?highl...
3
2010-04-04T00:27:51Z
[ "python", "timeout", "httpresponse" ]
set timeout to http response read method in python
2,573,044
<p>I'm building a download manager in python for fun, and sometimes the connection to the server is still on but the server doesn't send me data, so read method (of HTTPResponse) block me forever. This happens, for example, when I download from a server, which located outside of my country, that limit the bandwidth to ...
1
2010-04-03T23:32:03Z
3,602,969
<p>Setting the default timeout might abort a download early if it's large, as opposed to only aborting if it stops receiving data for the timeout value. HTTPlib2 is probably the way to go.</p>
1
2010-08-30T18:02:49Z
[ "python", "timeout", "httpresponse" ]
set timeout to http response read method in python
2,573,044
<p>I'm building a download manager in python for fun, and sometimes the connection to the server is still on but the server doesn't send me data, so read method (of HTTPResponse) block me forever. This happens, for example, when I download from a server, which located outside of my country, that limit the bandwidth to ...
1
2010-04-03T23:32:03Z
34,059,523
<p>5 years later but hopefully this will help someone else...</p> <p>I was wrecking my brain trying to figure this out. My problem was a server returning corrupt content and thus giving back less data than it thought it had.</p> <p>I came up with a nasty solution that seems to be working properly. Here it goes:</p> ...
-1
2015-12-03T06:50:09Z
[ "python", "timeout", "httpresponse" ]
Creating Instance of Python Extension Type in C
2,573,060
<p>I am writing a simple <code>Vector</code> implementation as a Python extension module in C that looks mostly like this:</p> <pre><code>typedef struct { PyObject_HEAD double x; double y; } Vector; static PyTypeObject Vector_Type = { ... }; </code></pre> <p>It is very simple to create instances of <...
0
2010-04-03T23:38:42Z
2,573,067
<p>Simplest is to call the type object you've created, e.g. with <a href="http://docs.python.org/c-api/object.html#PyObject_CallFunction" rel="nofollow">PyObject_CallFunction</a> -- don't let the name fool you, it lets you call <em>any</em> callable, <strong>not</strong> just a function.</p> <p>If you don't have a ref...
3
2010-04-03T23:43:08Z
[ "python", "extension-modules" ]
What is the best interface from Python 3.1.1 to R?
2,573,132
<p>I am using Python 3.1.1 on Mac OS X 10.6.2 and need an interface to R. When browsing the internet I found out about RPy. Is this the right choice? </p> <p>Currently, a program in Python computes a distance matrix and, stores it in a file. I invoke R separately in an interactive way and read in the matrix for cluste...
12
2010-04-04T00:25:43Z
2,573,204
<p>I don't believe there are any available options for Python 3.1.1.</p> <p>The current status of R-Python bindings:</p> <p>At the moment, three options: RPy, RPy2, and <a href="http://www.omegahat.org/RSPython/" rel="nofollow">RSPython</a>.</p> <p>RPy and RPy2 were developed and are maintained by the same team of d...
3
2010-04-04T01:02:10Z
[ "python", "interface", "python-3.x" ]