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
Clojure equivalent to Python's lxml library?
1,569,223
<p>I'm looking for the Clojure/Java equivalent to Python's lxml library. </p> <p>I've used it a ton in the past for parsing all sorts of html (as a replacement for BeautifulSoup) and it's great to be able to use the same elementtree api for xml as well -- really a trusted friend! Can anyone recommend a similar Java/...
10
2009-10-14T21:51:49Z
1,572,391
<p>Enlive: <a href="http://github.com/cgrand/enlive">http://github.com/cgrand/enlive</a></p> <p>I've used it for screen-scraping and it works quite well for that. It uses a CSS selector like syntax for getting at elements in the document.</p>
7
2009-10-15T13:31:22Z
[ "java", "python", "clojure", "lxml" ]
"setup.py upload" is failing with "Upload failed (401): You must be identified to edit package information"
1,569,315
<p>When running..</p> <pre><code>python setup.py sdist register upload </code></pre> <p>..I get the following output:</p> <pre><code>running register We need to know who you are, so please choose either: 1. use your existing login, 2. register as a new user, 3. have the server generate a new password for you (and...
42
2009-10-14T22:15:41Z
1,569,331
<p>Just found <a href="http://www.davidcramer.net/code/python/443/problems-uploading-packages-with-setuptools-on-os-x.html">this page</a>, which solves the issue:</p> <blockquote> <p>I also noticed that while it was asking me to save my login information, and I hit Y everytime, it still asked me for the username and...
61
2009-10-14T22:19:24Z
[ "python", "packaging", "setuptools" ]
"setup.py upload" is failing with "Upload failed (401): You must be identified to edit package information"
1,569,315
<p>When running..</p> <pre><code>python setup.py sdist register upload </code></pre> <p>..I get the following output:</p> <pre><code>running register We need to know who you are, so please choose either: 1. use your existing login, 2. register as a new user, 3. have the server generate a new password for you (and...
42
2009-10-14T22:15:41Z
27,559,197
<p>I have the same problem, This is my solution.</p> <p>The python version is 2.7.7, my windows version is Windows-7-6.1.7601-SP1.</p> <p>here is my .pypirc file</p> <pre><code>[distutils] index-servers=pypi [pypi] repository = https://pypi.python.org/pypi [server-login] username = user password = password </cod...
4
2014-12-19T03:10:32Z
[ "python", "packaging", "setuptools" ]
"setup.py upload" is failing with "Upload failed (401): You must be identified to edit package information"
1,569,315
<p>When running..</p> <pre><code>python setup.py sdist register upload </code></pre> <p>..I get the following output:</p> <pre><code>running register We need to know who you are, so please choose either: 1. use your existing login, 2. register as a new user, 3. have the server generate a new password for you (and...
42
2009-10-14T22:15:41Z
29,389,352
<p>I have this problem and solved it by putting the file .pypirc under my home directory (~/), as the last past of the first comment suggests. </p> <p>I didn't have the need to modify the name of the section "pypi" of the file pypirc for "server-login", as suggested also in the first comment.</p>
1
2015-04-01T11:16:27Z
[ "python", "packaging", "setuptools" ]
"setup.py upload" is failing with "Upload failed (401): You must be identified to edit package information"
1,569,315
<p>When running..</p> <pre><code>python setup.py sdist register upload </code></pre> <p>..I get the following output:</p> <pre><code>running register We need to know who you are, so please choose either: 1. use your existing login, 2. register as a new user, 3. have the server generate a new password for you (and...
42
2009-10-14T22:15:41Z
36,268,165
<p>I changed <code>[distutils]</code> to <code>[pypirc]</code> as per the <a href="https://pythonhosted.org/an_example_pypi_project/setuptools.html#intermezzo-pypirc-file-and-gpg" rel="nofollow">docs</a> and this worked for me.</p> <p>Here is my <code>~/.pypirc</code> file:</p> <pre><code>[pypirc] index-servers = ...
0
2016-03-28T18:07:54Z
[ "python", "packaging", "setuptools" ]
"setup.py upload" is failing with "Upload failed (401): You must be identified to edit package information"
1,569,315
<p>When running..</p> <pre><code>python setup.py sdist register upload </code></pre> <p>..I get the following output:</p> <pre><code>running register We need to know who you are, so please choose either: 1. use your existing login, 2. register as a new user, 3. have the server generate a new password for you (and...
42
2009-10-14T22:15:41Z
37,899,752
<p>None of the changes to ~/.pypirc listed here worked for me.</p> <p>This worked for me, with no changes to ~/.pypirc. I added "-r <a href="https://www.python.org/pypi" rel="nofollow">https://www.python.org/pypi</a>" to the command line:</p> <pre><code>python setup.py register sdist upload -r https://www.python.org...
4
2016-06-18T17:25:16Z
[ "python", "packaging", "setuptools" ]
How can I build the Boost.Python example on Ubuntu 9.10?
1,569,490
<p>I am using Ubuntu 9.10 beta, whose repositories contain boost 1.38. I would like to build the hello-world example. I followed the instructions here (<a href="http://www.boost.org/doc/libs/1%5F40%5F0/libs/python/doc/tutorial/doc/html/python/hello.html" rel="nofollow">http://www.boost.org/doc/libs/1%5F40%5F0/libs/py...
4
2009-10-14T23:05:16Z
1,694,664
<p>The problem comes from using Ubuntu package instead of boost compiled from source. You have to edit you Jamroot to say it to use global libboost-python, instead of looking for lib in relative boost source tree.</p> <p>Summarily you should have these lines at the beginning of your Jamroot:</p> <pre><code>using pyth...
4
2009-11-07T22:30:57Z
[ "python", "boost", "ubuntu" ]
How to create a custom 404 page for my Django/Apache?
1,569,682
<p>I know that you use .htaccess in the document-root directory in standard apache. What if I use Django? Can someone give me step by step how to create a custom 404 page?</p> <p>THanks.</p>
3
2009-10-15T00:22:32Z
1,569,694
<p>The default 404 handler calls 404.html . You could edit that if you don't need anything fancy or can override the 404 handler by setting the handler404 view -- <a href="http://docs.djangoproject.com/en/dev/topics/http/views/#the-404-page-not-found-view">more here</a></p>
14
2009-10-15T00:26:36Z
[ "python", "django", "apache" ]
How to create a custom 404 page for my Django/Apache?
1,569,682
<p>I know that you use .htaccess in the document-root directory in standard apache. What if I use Django? Can someone give me step by step how to create a custom 404 page?</p> <p>THanks.</p>
3
2009-10-15T00:22:32Z
1,569,940
<p>In general the Django documentation is really great. Have a look at the <a href="http://www.djangobook.com/en/2.0/" rel="nofollow">Django Book</a> for a great intoduction to Django. They cover the 404 page in <a href="http://www.djangobook.com/en/2.0/chapter03/" rel="nofollow">chapter 3</a></p>
3
2009-10-15T02:00:41Z
[ "python", "django", "apache" ]
Relative imports from __init__ in multi-file Django apps
1,569,703
<p>I have a Django project located at /var/django/project/ where /var/django/ is in the PATH</p> <p>within that project I have:</p> <pre><code>___init__.py manage.py utils/ __init__.py tools.py </code></pre> <p><code>utils/__init__.py</code> contains a function named <code>get_preview</code></p> <p><code>ut...
0
2009-10-15T00:29:20Z
1,569,725
<p>You can't (and shouldn't). You are structuring your code very poorly if files in your module are referencing code in the <code>__init__.py</code> associated with it. Either move both functions into <code>__init__.py</code> or both of them out of <code>__init__.py</code> or put them into separate modules. Those are y...
2
2009-10-15T00:35:13Z
[ "python", "django", "import" ]
Relative imports from __init__ in multi-file Django apps
1,569,703
<p>I have a Django project located at /var/django/project/ where /var/django/ is in the PATH</p> <p>within that project I have:</p> <pre><code>___init__.py manage.py utils/ __init__.py tools.py </code></pre> <p><code>utils/__init__.py</code> contains a function named <code>get_preview</code></p> <p><code>ut...
0
2009-10-15T00:29:20Z
1,569,784
<p>Yeah, this is bad structure. You gotta watch out here with creating a circular import between the two files. <a href="http://effbot.org/zone/import-confusion.htm" rel="nofollow" title="Import Confusion">About circular imports</a>.</p>
2
2009-10-15T00:58:48Z
[ "python", "django", "import" ]
Relative imports from __init__ in multi-file Django apps
1,569,703
<p>I have a Django project located at /var/django/project/ where /var/django/ is in the PATH</p> <p>within that project I have:</p> <pre><code>___init__.py manage.py utils/ __init__.py tools.py </code></pre> <p><code>utils/__init__.py</code> contains a function named <code>get_preview</code></p> <p><code>ut...
0
2009-10-15T00:29:20Z
1,569,827
<p>You can do it, you just need to make one of the imports happen at runtime to avoid the circular import.</p> <p>For example, <code>__init__.py</code>:</p> <pre><code>from project.utils.tools import get_related def get_preview(): # ... </code></pre> <p>and <code>tools.py</code>:</p> <pre><code>def get_relate...
0
2009-10-15T01:17:57Z
[ "python", "django", "import" ]
Django - how can I get permalink to work with "throwaway" slug
1,569,837
<p>I'm trying to add slugs to the url in my django app, much like SO does.</p> <p>Currently, I have pages that work just fine with a url like this:</p> <pre><code>http://example.com/foo/123/ </code></pre> <p>I'd like to add 'slugified' urls like so:</p> <pre><code>http://example.com/foo/123/foo-name-here </code></p...
4
2009-10-15T01:21:36Z
1,569,882
<p>One thing to check for, because I also ran into this problem:</p> <pre><code>(?P&lt;name_slug&gt;\w+) </code></pre> <p>Is slugify adding hyphens anywhere? If so the regex won't match, hypens are a non-word character. To fix use <code>[\w-]+</code> or similar.</p>
7
2009-10-15T01:40:24Z
[ "python", "django", "django-urls", "permalinks" ]
How to write a RESTful URL path regex in GAE/Python for n parameters?
1,570,198
<p>Currently I have three URL paths that map to ServiceHandler. How do I combine the three into one neat regex that can pass n number of arguments to ServiceHandler?</p> <pre><code>(r'/s/([^/]*)', ServiceHandler), (r'/s/([^/]*)/([^/]*)', ServiceHandler), (r'/s/([^/]*)/([^/]*)/([^/]*)', ServiceHandler) </code></pre>
1
2009-10-15T03:49:54Z
1,570,358
<p>You can try something like</p> <p><code>(r'/s/([^/]*)/?([^/]*)/?([^/]*)', ServiceHandler)</code></p> <p>I think you will always get 3 parameters to ServiceHandler but the ones that aren't used will be empty strings</p>
0
2009-10-15T05:01:42Z
[ "python", "regex", "google-app-engine", "url-mapping" ]
How to write a RESTful URL path regex in GAE/Python for n parameters?
1,570,198
<p>Currently I have three URL paths that map to ServiceHandler. How do I combine the three into one neat regex that can pass n number of arguments to ServiceHandler?</p> <pre><code>(r'/s/([^/]*)', ServiceHandler), (r'/s/([^/]*)/([^/]*)', ServiceHandler), (r'/s/([^/]*)/([^/]*)/([^/]*)', ServiceHandler) </code></pre>
1
2009-10-15T03:49:54Z
1,572,298
<pre><code>(r'^/s/(([^/]*)((/[^/]+)*))$', ServiceHandler) </code></pre> <p>Should do the trick to match any amount of </p> <p>/s/foo/bar/baz/to/infinity/and/beyond/</p> <p>You can also limit it to a range by doing something like</p> <pre><code>^/s/(([^/]*)((/[^/]+){0,2}))$ </code></pre> <p>Which would only match t...
1
2009-10-15T13:15:12Z
[ "python", "regex", "google-app-engine", "url-mapping" ]
How to write a RESTful URL path regex in GAE/Python for n parameters?
1,570,198
<p>Currently I have three URL paths that map to ServiceHandler. How do I combine the three into one neat regex that can pass n number of arguments to ServiceHandler?</p> <pre><code>(r'/s/([^/]*)', ServiceHandler), (r'/s/([^/]*)/([^/]*)', ServiceHandler), (r'/s/([^/]*)/([^/]*)/([^/]*)', ServiceHandler) </code></pre>
1
2009-10-15T03:49:54Z
1,575,045
<p>This should work for any number</p> <pre><code>(r'(?&lt;!^)/([^/]+)', ServiceHandler) </code></pre> <p>Since I've looked in urlresolvers.py, I see this won't work although you could patch the correct behaviour into urlresolvers.py using regex.findall instead of re.search.</p>
0
2009-10-15T21:01:47Z
[ "python", "regex", "google-app-engine", "url-mapping" ]
In Python, how do I transform a string into a file?
1,570,230
<p>There is a read-only library function that takes a file as an argument. But I have a string.</p> <p>How do I convert a string to a file, that if you read the file it will return this string? I don't want to write to disk.</p>
3
2009-10-15T04:05:54Z
1,570,244
<p>The <code>StringIO</code> module:</p> <pre><code>&gt;&gt;&gt; import StringIO &gt;&gt;&gt; f = StringIO.StringIO("foo") &gt;&gt;&gt; f.read() 'foo' </code></pre> <p>The <code>cStringIO</code> module has the same interface, and is faster, but can't deal with Unicode strings that have non-ASCII characters.</p> <p><...
15
2009-10-15T04:15:29Z
[ "python", "string", "file", "types" ]
In Python, how do I transform a string into a file?
1,570,230
<p>There is a read-only library function that takes a file as an argument. But I have a string.</p> <p>How do I convert a string to a file, that if you read the file it will return this string? I don't want to write to disk.</p>
3
2009-10-15T04:05:54Z
1,570,892
<p>what do you want? if you want to read from file just use:</p> <pre><code>file('/path/to/file').read() </code></pre> <p>or</p> <pre><code>open('/path/to/file','r').read() </code></pre> <p>if you want to read string,just do as suggest by Phil</p>
0
2009-10-15T07:54:18Z
[ "python", "string", "file", "types" ]
Finding words from random input letters in python. What algorithm to use/code already there?
1,570,242
<p>I am trying to code a word descrambler like this one <a href="http://www.thewordfinder.com/scrabble.php" rel="nofollow">here</a> and was wondering what algorithms I should use to implement this. Also, if anyone can find existing code for this that would be great as well. Basically the functionality is going to be li...
2
2009-10-15T04:13:00Z
1,570,248
<p>I'd use a <a href="http://en.wikipedia.org/wiki/Trie" rel="nofollow">Trie</a>. Here's an implementation in Python: <a href="http://jtauber.com/2005/02/trie.py" rel="nofollow">http://jtauber.com/2005/02/trie.py</a> (credit to James Tauber)</p>
3
2009-10-15T04:17:00Z
[ "python", "ruby", "word", "anagram" ]
Finding words from random input letters in python. What algorithm to use/code already there?
1,570,242
<p>I am trying to code a word descrambler like this one <a href="http://www.thewordfinder.com/scrabble.php" rel="nofollow">here</a> and was wondering what algorithms I should use to implement this. Also, if anyone can find existing code for this that would be great as well. Basically the functionality is going to be li...
2
2009-10-15T04:13:00Z
1,570,386
<p>I may be missing an understanding of the game but barring some complications in the rules, such as with the introduction of "joker" (wildcard) letters, missing or additional letters, multiple words etc... I think the following ideas would help turn the problem in a somewhat relatively uninteresting thing. :-(</p> ...
2
2009-10-15T05:08:19Z
[ "python", "ruby", "word", "anagram" ]
Finding words from random input letters in python. What algorithm to use/code already there?
1,570,242
<p>I am trying to code a word descrambler like this one <a href="http://www.thewordfinder.com/scrabble.php" rel="nofollow">here</a> and was wondering what algorithms I should use to implement this. Also, if anyone can find existing code for this that would be great as well. Basically the functionality is going to be li...
2
2009-10-15T04:13:00Z
1,570,490
<p>For your dictionary index, build a map (Map[Bag[Char], List[String]]). It should be a hash map so you can get O(1) word lookup. A Bag[Char] is an identifier for a word that is unique up to character order. It's is basically a hash map from Char to Int. The Char is a given character in the word and the Int is the num...
2
2009-10-15T05:43:39Z
[ "python", "ruby", "word", "anagram" ]
Finding words from random input letters in python. What algorithm to use/code already there?
1,570,242
<p>I am trying to code a word descrambler like this one <a href="http://www.thewordfinder.com/scrabble.php" rel="nofollow">here</a> and was wondering what algorithms I should use to implement this. Also, if anyone can find existing code for this that would be great as well. Basically the functionality is going to be li...
2
2009-10-15T04:13:00Z
1,571,927
<p>This sounds like <a href="http://en.wikipedia.org/wiki/Rabin-Karp%5Fstring%5Fsearch%5Falgorithm#Rabin-Karp%5Fand%5Fmultiple%5Fpattern%5Fsearch" rel="nofollow">Rabin-Karp string search</a> would be a good choice. If you use a rolling hash-function then at each position you need one hash value update and one dictionar...
1
2009-10-15T11:58:10Z
[ "python", "ruby", "word", "anagram" ]
Finding words from random input letters in python. What algorithm to use/code already there?
1,570,242
<p>I am trying to code a word descrambler like this one <a href="http://www.thewordfinder.com/scrabble.php" rel="nofollow">here</a> and was wondering what algorithms I should use to implement this. Also, if anyone can find existing code for this that would be great as well. Basically the functionality is going to be li...
2
2009-10-15T04:13:00Z
1,574,996
<p>There are two ways to do this. One is to check every candidate permutation of letters in the word to see if the candidate is in your dictionary of words. That's an O(N!) operation, depending on the length of the word.</p> <p>The other way is to check every candidate word in your dictionary to see if it's containe...
1
2009-10-15T20:52:16Z
[ "python", "ruby", "word", "anagram" ]
Does configuring django's setting.TIME_ZONE affect datetime.datetime.now()?
1,570,339
<p>The documentation says:</p> <p><a href="http://docs.djangoproject.com/en/dev/ref/settings/#time-zone" rel="nofollow">http://docs.djangoproject.com/en/dev/ref/settings/#time-zone</a></p> <blockquote> <p>Note that this is the time zone to which Django will convert all dates/times -- not necessarily the timez...
4
2009-10-15T04:53:56Z
1,570,466
<p>Much to my surprise, it does appear to.</p> <pre><code>web81:~/webapps/dominicrodger2/dominicrodger$ python2.5 manage.py shell Python 2.5.4 (r254:67916, Aug 5 2009, 12:42:40) [GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2 Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole...
4
2009-10-15T05:34:56Z
[ "python", "django", "datetime" ]
Does configuring django's setting.TIME_ZONE affect datetime.datetime.now()?
1,570,339
<p>The documentation says:</p> <p><a href="http://docs.djangoproject.com/en/dev/ref/settings/#time-zone" rel="nofollow">http://docs.djangoproject.com/en/dev/ref/settings/#time-zone</a></p> <blockquote> <p>Note that this is the time zone to which Django will convert all dates/times -- not necessarily the timez...
4
2009-10-15T04:53:56Z
5,718,301
<p>With <code>TIME_ZONE</code> as UTC, utcnow() and now() are the same. This is probably what you want. Then you can record times as now/utcnow and functions like <code>timesince</code> will work perfectly for every user. To display absolute times to specific users, you can use utc offsets as you suggest.</p>
1
2011-04-19T14:48:39Z
[ "python", "django", "datetime" ]
Create a user-group in linux using python
1,570,401
<p>I want to create a user group using python on CentOS system. When I say 'using python' I mean I don't want to do something like os.system and give the unix command to create a new group. I would like to know if there is any python module that deals with this.</p> <p>Searching on the net did not reveal much about wh...
5
2009-10-15T05:13:02Z
1,570,429
<p>I think you <em>should</em> use the commandline programs from your program, a lot of care has gone into making sure that they don't break the groups file if something goes wrong. </p> <p>However the file format is quite straight forward to write something yourself if you choose to go that way</p>
4
2009-10-15T05:20:29Z
[ "python", "linux", "usergroups" ]
Create a user-group in linux using python
1,570,401
<p>I want to create a user group using python on CentOS system. When I say 'using python' I mean I don't want to do something like os.system and give the unix command to create a new group. I would like to know if there is any python module that deals with this.</p> <p>Searching on the net did not reveal much about wh...
5
2009-10-15T05:13:02Z
1,570,448
<p>I don't know of a python module to do it, but the /etc/group and /etc/gshadow format is pretty standard, so if you wanted you could just open the files, parse their current contents and then add the new group if necessary.</p> <p>Before you go doing this, consider:</p> <ul> <li>What happens if you try to add a gro...
9
2009-10-15T05:26:09Z
[ "python", "linux", "usergroups" ]
Create a user-group in linux using python
1,570,401
<p>I want to create a user group using python on CentOS system. When I say 'using python' I mean I don't want to do something like os.system and give the unix command to create a new group. I would like to know if there is any python module that deals with this.</p> <p>Searching on the net did not reveal much about wh...
5
2009-10-15T05:13:02Z
1,571,882
<p>There are no library calls for creating a group. This is because there's really no such thing as creating a group. A GID is simply a number assigned to a process or a file. All these numbers exist already - there is nothing you need to do to start using a GID. With the appropriate privileges, you can call chown(2) t...
1
2009-10-15T11:47:13Z
[ "python", "linux", "usergroups" ]
Create a user-group in linux using python
1,570,401
<p>I want to create a user group using python on CentOS system. When I say 'using python' I mean I don't want to do something like os.system and give the unix command to create a new group. I would like to know if there is any python module that deals with this.</p> <p>Searching on the net did not reveal much about wh...
5
2009-10-15T05:13:02Z
2,426,777
<p>If you are looking at Python, then try this program. Its fairly simple to use, and the code can easily be customized <a href="http://aleph-null.tv/downloads/mpb-adduser-1.tgz" rel="nofollow">http://aleph-null.tv/downloads/mpb-adduser-1.tgz</a></p>
0
2010-03-11T16:33:03Z
[ "python", "linux", "usergroups" ]
Please help install matplotlib. It won't work! (Python)
1,570,495
<p>I downloaded the source. Untarred it. "sudo python setup.py install". And below are the errors I get. Can someone help? By the way, Numpy is installed. Thanks a lot.</p> <pre><code>src/_image.cpp:5:17: error: png.h: No such file or directory src/_image.cpp: In member function 'Py::Object Image::write_png(const P...
8
2009-10-15T05:45:29Z
1,570,501
<p>Those particular errors stem from the lack of the development package for libpng.</p> <p>If you use Debian/Ubuntu, try <code>apt-get install libpng-dev</code> first.</p>
20
2009-10-15T05:47:56Z
[ "python", "installation", "matplotlib" ]
Please help install matplotlib. It won't work! (Python)
1,570,495
<p>I downloaded the source. Untarred it. "sudo python setup.py install". And below are the errors I get. Can someone help? By the way, Numpy is installed. Thanks a lot.</p> <pre><code>src/_image.cpp:5:17: error: png.h: No such file or directory src/_image.cpp: In member function 'Py::Object Image::write_png(const P...
8
2009-10-15T05:45:29Z
1,570,506
<p>if you are apt-based try</p> <p><code>$ sudo apt-get build-dep matplotlib</code></p>
9
2009-10-15T05:51:06Z
[ "python", "installation", "matplotlib" ]
Please help install matplotlib. It won't work! (Python)
1,570,495
<p>I downloaded the source. Untarred it. "sudo python setup.py install". And below are the errors I get. Can someone help? By the way, Numpy is installed. Thanks a lot.</p> <pre><code>src/_image.cpp:5:17: error: png.h: No such file or directory src/_image.cpp: In member function 'Py::Object Image::write_png(const P...
8
2009-10-15T05:45:29Z
1,570,514
<p>You don't need to compile from source: <code> sudo apt-get install python-matplotlib </code></p> <p>The easy way out.</p>
4
2009-10-15T05:53:33Z
[ "python", "installation", "matplotlib" ]
Displaying the Length of Individual Sequences in File
1,570,873
<p>I have a file that contains two sequences. I have a program that could read all sequences, combine them together, and display the length of both sequences together. Now I want to display the length individually. The two sequences are separated by the symbol <code>&gt;</code>.</p> <p>Example:</p> <pre><code>SEQ1 &...
0
2009-10-15T07:48:41Z
1,570,897
<pre><code>for line in open("clostp1.fa"): name, sequence = map(str.strip,line.split('&gt;')) print "The length of %s is %s"%(name, len(sequence)) </code></pre>
4
2009-10-15T07:55:41Z
[ "python" ]
Displaying the Length of Individual Sequences in File
1,570,873
<p>I have a file that contains two sequences. I have a program that could read all sequences, combine them together, and display the length of both sequences together. Now I want to display the length individually. The two sequences are separated by the symbol <code>&gt;</code>.</p> <p>Example:</p> <pre><code>SEQ1 &...
0
2009-10-15T07:48:41Z
1,570,937
<p>If I understood correctly, you want to print out each individual sequence followed by its length, right? I believe you just have a function to return the sequences and later do what ever yuo want with them.</p> <pre><code>#!usr/bin/python import re def get_content(file): """ Returns a dict with the name of...
1
2009-10-15T08:05:28Z
[ "python" ]
Displaying the Length of Individual Sequences in File
1,570,873
<p>I have a file that contains two sequences. I have a program that could read all sequences, combine them together, and display the length of both sequences together. Now I want to display the length individually. The two sequences are separated by the symbol <code>&gt;</code>.</p> <p>Example:</p> <pre><code>SEQ1 &...
0
2009-10-15T07:48:41Z
1,570,969
<pre><code>for line in open("clostp1.fa"): name, _, seq = line.partition('&gt;') name, seq = name.rstrip(), seq.rstrip() print("The length of {} is {}".format(name, len(seq))) </code></pre> <p><code>partition</code> is more appropriate here then <code>split</code>. you need to <code>rstrip</code> each indi...
0
2009-10-15T08:14:41Z
[ "python" ]
Displaying the Length of Individual Sequences in File
1,570,873
<p>I have a file that contains two sequences. I have a program that could read all sequences, combine them together, and display the length of both sequences together. Now I want to display the length individually. The two sequences are separated by the symbol <code>&gt;</code>.</p> <p>Example:</p> <pre><code>SEQ1 &...
0
2009-10-15T07:48:41Z
1,570,983
<pre><code>import re pattern = re.compile('(?P&lt;seqname&gt;\w*)\s*&gt;\s*(?P&lt;seqval&gt;\w*)') for item in open('clostp1.fa','r').readlines(): m = pattern.match(item) if m: print "sequence name: %s - %s length" % (m.groupdict()['seqname'],len(m.groupdict()['seqval'])) </code></pre>
0
2009-10-15T08:17:51Z
[ "python" ]
Vim, Python and curses
1,571,032
<p>I wrote a small python script for vim that uses the curses library. When I try to call the function curses complains about:</p> <pre><code>Traceback (most recent call last): File "&lt;string&gt;", line 9, in &lt;module&gt; File "/usr/lib/python2.6/curses/__init__.py", line 33, in initscr fd=_sys.__stdout__.fileno()...
0
2009-10-15T08:28:42Z
1,571,170
<p>I'm not very sure about the context, but "GVIM complains Vim works fine" is very insightful: curses are used in the console, gvim is run in a X window, thus there's no console.</p>
6
2009-10-15T09:06:42Z
[ "python", "vim", "curses" ]
Choose Python version for egg installation or install parallel versions of site-package
1,571,047
<p>Via <code>fink install</code> I put the following Python version on my Mac OS X computer:</p> <ul> <li><code>python2.3</code>,</li> <li><code>python2.4</code>,</li> <li><code>python2.5</code>,</li> <li><code>python2.6</code>.</li> </ul> <p>Further, <code>python</code> is alias for <code>python2.6</code> on my syst...
2
2009-10-15T08:30:26Z
1,571,104
<p><strong>Edit:</strong> Read <a href="http://stackoverflow.com/questions/1571047/choose-python-version-for-egg-installation-install-parallel-versions-of-site-pa/1571477#1571477">Ned Deily's answer</a> before you read this one</p> <p><hr /></p> <p><strong>1.</strong></p> <p>On my system I have different easy_instal...
2
2009-10-15T08:46:46Z
[ "python", "easy-install", "egg" ]
Choose Python version for egg installation or install parallel versions of site-package
1,571,047
<p>Via <code>fink install</code> I put the following Python version on my Mac OS X computer:</p> <ul> <li><code>python2.3</code>,</li> <li><code>python2.4</code>,</li> <li><code>python2.5</code>,</li> <li><code>python2.6</code>.</li> </ul> <p>Further, <code>python</code> is alias for <code>python2.6</code> on my syst...
2
2009-10-15T08:30:26Z
1,571,477
<p><code>easy_install</code> is part of the <code>setuptools</code> package. <code>Fink</code> has separate <code>setuptools</code> packages for python 2.5 and python 2.6:</p> <pre><code>fink install setuptools-py25 setuptools-py26 </code></pre> <p>You can then download and install <code>networkx</code> to both vers...
4
2009-10-15T10:18:46Z
[ "python", "easy-install", "egg" ]
Boost.Python - How to return by reference?
1,571,054
<p>I'm using Boost.Python to create Python modules from C++ classes. And I ran into a problem with references.</p> <p>Condider the following case where I have a class Foo with overloaded get methods that can either return by value or reference.</p> <p>Specifying that the return by value should be used was easy once I...
8
2009-10-15T08:31:54Z
1,571,163
<p>I don't know much about Boost.Python, so I may misunderstand the question, in which case this is completely unhelpful. But here goes:</p> <p>In Python you can't choose between returning by reference or by value, the distinction doesn't make sense in Python. I find it's easiest to think of it as everything being han...
0
2009-10-15T09:04:48Z
[ "python", "boost", "boost-python" ]
Boost.Python - How to return by reference?
1,571,054
<p>I'm using Boost.Python to create Python modules from C++ classes. And I ran into a problem with references.</p> <p>Condider the following case where I have a class Foo with overloaded get methods that can either return by value or reference.</p> <p>Specifying that the return by value should be used was easy once I...
8
2009-10-15T08:31:54Z
1,571,421
<p>Are you sure that the c++ object is being copied? You will get a new python object each time but which references the same c++ object. How are you determining that the object has been copied?</p>
0
2009-10-15T10:07:14Z
[ "python", "boost", "boost-python" ]
Boost.Python - How to return by reference?
1,571,054
<p>I'm using Boost.Python to create Python modules from C++ classes. And I ran into a problem with references.</p> <p>Condider the following case where I have a class Foo with overloaded get methods that can either return by value or reference.</p> <p>Specifying that the return by value should be used was easy once I...
8
2009-10-15T08:31:54Z
2,009,000
<p>I think you want <a href="http://www.boost.org/doc/libs/1_38_0/libs/python/doc/v2/return_internal_reference.html" rel="nofollow">return internal reference</a> instead. I have used it before to do something similar.</p>
2
2010-01-05T20:49:08Z
[ "python", "boost", "boost-python" ]
Boost.Python - How to return by reference?
1,571,054
<p>I'm using Boost.Python to create Python modules from C++ classes. And I ran into a problem with references.</p> <p>Condider the following case where I have a class Foo with overloaded get methods that can either return by value or reference.</p> <p>Specifying that the return by value should be used was easy once I...
8
2009-10-15T08:31:54Z
2,119,543
<p>In Python, there's the concept of <em>immutable types</em>. An immutable types can't have its value changed. Examples of built-in immutable types are int, float and str.</p> <p>Having said that, you can't do what you want with <code>boost::python</code>, because Python itself does not allow you to change the value ...
6
2010-01-22T18:33:31Z
[ "python", "boost", "boost-python" ]
ActiveMQ : Use Django Auth with Stomp
1,571,224
<p>I am working on <a href="http://blog.gridspy.co.nz/2009/09/introducing-the-nexus.html" rel="nofollow">power monitoring</a> and want to send live power data to authorised users only. Some users have opted to install power sensors in their houses, others are viewing those sensors. Each sensor sends samples to a <a hre...
4
2009-10-15T09:22:49Z
1,575,334
<p>If you use the restq extensions for morbidq, you can have it send an http callback to your application every time the user attempts to connect. (See <a href="http://www.morbidq.com/trac/wiki/RestQ" rel="nofollow">http://www.morbidq.com/trac/wiki/RestQ</a> ). Your django app can then just return yes or no to the conn...
1
2009-10-15T21:56:47Z
[ "python", "django", "stomp", "orbited" ]
ActiveMQ : Use Django Auth with Stomp
1,571,224
<p>I am working on <a href="http://blog.gridspy.co.nz/2009/09/introducing-the-nexus.html" rel="nofollow">power monitoring</a> and want to send live power data to authorised users only. Some users have opted to install power sensors in their houses, others are viewing those sensors. Each sensor sends samples to a <a hre...
4
2009-10-15T09:22:49Z
8,414,003
<p>Reviving an old thread: MorbidQ is not meant for production use AFAIK. ActiveMQ is a much more robust beast and provides much better ways to handle user-based authentication. I wrote <a href="http://pythonware.blogspot.com/2011/12/user-based-authentication-using-orbited.html" rel="nofollow">this</a> back in 2010 whi...
1
2011-12-07T10:41:29Z
[ "python", "django", "stomp", "orbited" ]
converting strptime into 'X hours ago'
1,571,272
<p>I have a a date in strptime that I want to show as 'X hours ago'. I can happily convert hours into days and weeks etc. but I don't know how to do the initial sum. Here is how I'm converting the string into strptime:</p> <pre><code>time.strptime(obj.created_at, '%a %b %d %H:%M:%S +0000 %Y') </code></pre> <p>p.s. bo...
1
2009-10-15T09:34:59Z
1,571,293
<p>It seems the <a href="http://docs.djangoproject.com/en/dev/ref/templates/builtins/#timesince" rel="nofollow"><code>timesince</code></a> in Django could help you out without you having to convert. The source for <code>timesince</code> is available <a href="http://code.djangoproject.com/browser/django/trunk/django/uti...
3
2009-10-15T09:38:51Z
[ "python", "timestamp", "strptime" ]
converting strptime into 'X hours ago'
1,571,272
<p>I have a a date in strptime that I want to show as 'X hours ago'. I can happily convert hours into days and weeks etc. but I don't know how to do the initial sum. Here is how I'm converting the string into strptime:</p> <pre><code>time.strptime(obj.created_at, '%a %b %d %H:%M:%S +0000 %Y') </code></pre> <p>p.s. bo...
1
2009-10-15T09:34:59Z
1,571,391
<p>Can you use datetime instead? (Or convert whatever you have into datetime?)</p> <pre><code>&gt;&gt;&gt; import datetime &gt;&gt;&gt; created_at = datetime.datetime(2009,10,15, 13) &gt;&gt;&gt; now = datetime.datetime.now() &gt;&gt;&gt; delta = now - created_at &gt;&gt;&gt; hours_ago = '%d Hours Ago' % (delta.second...
0
2009-10-15T10:01:02Z
[ "python", "timestamp", "strptime" ]
converting strptime into 'X hours ago'
1,571,272
<p>I have a a date in strptime that I want to show as 'X hours ago'. I can happily convert hours into days and weeks etc. but I don't know how to do the initial sum. Here is how I'm converting the string into strptime:</p> <pre><code>time.strptime(obj.created_at, '%a %b %d %H:%M:%S +0000 %Y') </code></pre> <p>p.s. bo...
1
2009-10-15T09:34:59Z
1,572,956
<p>The <code>datetime</code> module is definitely easier to use, but, if you insist, you can do it with the <code>time</code> module instead. I.e.:</p> <pre><code>&gt;&gt;&gt; import time &gt;&gt;&gt; fmt = '%a %b %d %H:%M:%S +0000 %Y' &gt;&gt;&gt; time.strftime(fmt) 'Thu Oct 15 07:54:07 +0000 2009' &gt;&gt;&gt; crea...
2
2009-10-15T15:01:37Z
[ "python", "timestamp", "strptime" ]
Can a dictionary be passed to django models on create?
1,571,570
<p>Is is possible to do something similar to this with a list, dictionary or something else even?</p> <pre><code>data_dict = { 'title' : 'awesome title', 'body' : 'great body of text', } Model.objects.create(data_dict) </code></pre> <p>Even better if I can extend it</p> <pre><code>Model.objects.create(data_d...
55
2009-10-15T10:41:29Z
1,571,593
<p>If <code>title</code> and <code>body</code> are fields in your model, then <a href="http://docs.python.org/tutorial/controlflow.html#unpacking-argument-lists">you can deliver the keyword arguments in your dictionary using the ** operator</a>.</p> <p>Assuming your model is called <code>MyModel</code>:</p> <pre><cod...
110
2009-10-15T10:49:09Z
[ "python", "django", "django-models", "dictionary" ]
Can a dictionary be passed to django models on create?
1,571,570
<p>Is is possible to do something similar to this with a list, dictionary or something else even?</p> <pre><code>data_dict = { 'title' : 'awesome title', 'body' : 'great body of text', } Model.objects.create(data_dict) </code></pre> <p>Even better if I can extend it</p> <pre><code>Model.objects.create(data_d...
55
2009-10-15T10:41:29Z
32,898,403
<p>Not directly an answer to the question, but I find this code helped me create the dicts that save nicely into the correct answer. The type conversions made are required if this data will be exported to json.</p> <p>I hope this helps:</p> <pre><code> #mod is a django database model instance def toDict( mod ): i...
1
2015-10-01T23:36:23Z
[ "python", "django", "django-models", "dictionary" ]
XML-RPC server with better error reporting
1,571,598
<p>Standard libraries (<code>xmlrpclib</code>+<code>SimpleXMLRPCServer</code> in Python 2 and <code>xmlrpc.server</code> in Python 3) report all errors (including usage errors) as python exceptions which is not suitable for public services: exception strings are often not easy understandable without python knowledge an...
1
2009-10-15T10:50:52Z
1,608,160
<p>I don't think you have a library specific problem. When using any library or framework you typically want to trap all errors, log them somewhere, and throw up "Oops, we're having problems. You may want to contact us at x@x.com with error number 100 and tell us what you did." So wrap your failable entry points in ...
1
2009-10-22T15:47:13Z
[ "python", "xml-rpc" ]
XML-RPC server with better error reporting
1,571,598
<p>Standard libraries (<code>xmlrpclib</code>+<code>SimpleXMLRPCServer</code> in Python 2 and <code>xmlrpc.server</code> in Python 3) report all errors (including usage errors) as python exceptions which is not suitable for public services: exception strings are often not easy understandable without python knowledge an...
1
2009-10-15T10:50:52Z
1,608,496
<p>It look like there is no ready library with my requirements, so a ended up with own implementation:</p> <pre><code>class ApplicationError(Fault): def __init__(self, exc_info): Fault.__init__(self, xmlrpclib.APPLICATION_ERROR, u'Application internal error') class NotWellformedEr...
1
2009-10-22T16:43:41Z
[ "python", "xml-rpc" ]
Iterating through a list in Python
1,571,651
<p>I am trying to iterate through a list and take each part of the list, encode it and join the result up when it is all done. As an example, I have a string which produces a list with each element being 16 characters in length.</p> <pre><code>message = (u'sixteen-letters.sixteen-letters.sixteen-letters.sixteen-lette...
0
2009-10-15T11:04:21Z
1,571,664
<p>Are you trying to do something like this?</p> <pre><code>';'.join(encode(i) for i in message.split('.')) </code></pre> <p>of course it could be just </p> <pre><code>';'.join(encode(i) for i in result) </code></pre> <p>if your <code>split16</code> function complicated enough.</p>
1
2009-10-15T11:06:53Z
[ "python", "list", "list-comprehension" ]
Iterating through a list in Python
1,571,651
<p>I am trying to iterate through a list and take each part of the list, encode it and join the result up when it is all done. As an example, I have a string which produces a list with each element being 16 characters in length.</p> <pre><code>message = (u'sixteen-letters.sixteen-letters.sixteen-letters.sixteen-lette...
0
2009-10-15T11:04:21Z
1,571,725
<p>I'm not quite clear what you are after, but</p> <pre><code>msg=";".join(map(encode,(message[i:i+16] for i in range(0,len(message),16)))) </code></pre>
0
2009-10-15T11:16:54Z
[ "python", "list", "list-comprehension" ]
Iterating through a list in Python
1,571,651
<p>I am trying to iterate through a list and take each part of the list, encode it and join the result up when it is all done. As an example, I have a string which produces a list with each element being 16 characters in length.</p> <pre><code>message = (u'sixteen-letters.sixteen-letters.sixteen-letters.sixteen-lette...
0
2009-10-15T11:04:21Z
1,571,729
<p>I am a bit confused about what you are exactly trying to do, which is compounded by a missing paren in the code you posted:</p> <pre><code>result = [encode(split16(message, 16) for message in list_of_messages] </code></pre> <p>Should that be:</p> <pre><code>result = [encode(split16(message, 16) for message in lis...
1
2009-10-15T11:17:42Z
[ "python", "list", "list-comprehension" ]
Select specific child elements with BeautifulSoup
1,571,699
<p>I'm reading up on BeautifulSoup to screen-scrape some pretty heavy html pages. Going through the documentation of BeautifulSoup I can't seem to find a easy way to select child elements.</p> <p>Given the html:</p> <pre><code>&lt;div id="top"&gt; &lt;div&gt;Content&lt;/div&gt; &lt;div&gt; &lt;div&gt;Content ...
2
2009-10-15T11:12:42Z
1,571,813
<p>You are more flexible with <code>find</code>, and to get what you want you just need to run:</p> <pre><code>node = p.find('div', text="Content I Want") </code></pre> <p>But since it might not be <em>how</em> you want to get there, following options might suit you better:</p> <pre><code>xml = """&lt;div id="top"&g...
2
2009-10-15T11:34:56Z
[ "python", "beautifulsoup", "html-parsing" ]
Python Vs C - Handling environment variable in Windows
1,572,153
<p>I see a variation in output between C and python code in Windows trying to get the same functionality. The c code ( similar to unix shell scripts ) shows the TEST1 environment variable in 'test.bat.output' with its value as empty string whereas the python code removes this environment variable. </p> <p>Is there a...
2
2009-10-15T12:48:29Z
1,572,348
<p>Yes empty values are not being put into environ, but interesting thing is calling SetEnvironmentVariable from win32api or ctypes module has same affect as os.environ though win32api.SetEnvironmentVariable would be calling the same function as in C .</p> <p>So are you sure you get different result in C code?</p> <...
0
2009-10-15T13:23:17Z
[ "python", "c", "environment-variables" ]
Python Vs C - Handling environment variable in Windows
1,572,153
<p>I see a variation in output between C and python code in Windows trying to get the same functionality. The c code ( similar to unix shell scripts ) shows the TEST1 environment variable in 'test.bat.output' with its value as empty string whereas the python code removes this environment variable. </p> <p>Is there a...
2
2009-10-15T12:48:29Z
1,572,352
<p>This is a possible answer. I don't have a Windows system handy to test with, so I don't really know what this code will do, but what happens if you do this:</p> <pre><code>import os, subprocess myenv = {} myenv.update(os.environ) myenv['TEST1'] = "" myenv['TEST2'] = "karthik" subprocess.Popen(('cmd', '/c', 'test.b...
0
2009-10-15T13:24:17Z
[ "python", "c", "environment-variables" ]
Python Vs C - Handling environment variable in Windows
1,572,153
<p>I see a variation in output between C and python code in Windows trying to get the same functionality. The c code ( similar to unix shell scripts ) shows the TEST1 environment variable in 'test.bat.output' with its value as empty string whereas the python code removes this environment variable. </p> <p>Is there a...
2
2009-10-15T12:48:29Z
1,572,698
<p>Cross-platform compatibility between Windows and "most everybody else" (operating systems derived or inspired from Unix) is often hard to get, especially in the innumerable corner cases that inevitably arise (e.g., as in this question, "does setting an environment variable to empty mean unsetting it"). Sometimes it'...
2
2009-10-15T14:25:07Z
[ "python", "c", "environment-variables" ]
script to find pagerank of domain
1,572,183
<p>how can I automate finding the pagerank of a domain? I came across <a href="http://blogmag.net/blog/read/91/Python%5Fcode%5Fto%5Fcheck%5Fyour%5FGoogle%5FPageRank" rel="nofollow">this Python script</a> but it no longer works. Seems Google doesn't like people automating this.</p> <p>So, is there an alternative provid...
5
2009-10-15T12:54:04Z
1,574,033
<p>Have you tried HalOtis Marketing's Page Rank script at <a href="http://www.halotis.com/2009/08/02/google-page-range-python-script/" rel="nofollow">http://www.halotis.com/2009/08/02/google-page-range-python-script/</a>? He generally writes good, simple Python code for exactly this kind of stuff.</p>
2
2009-10-15T17:56:03Z
[ "python", "api", "pagerank" ]
script to find pagerank of domain
1,572,183
<p>how can I automate finding the pagerank of a domain? I came across <a href="http://blogmag.net/blog/read/91/Python%5Fcode%5Fto%5Fcheck%5Fyour%5FGoogle%5FPageRank" rel="nofollow">this Python script</a> but it no longer works. Seems Google doesn't like people automating this.</p> <p>So, is there an alternative provid...
5
2009-10-15T12:54:04Z
1,574,836
<p>Here is a python script <a href="http://www.djangosnippets.org/snippets/221/" rel="nofollow">which does work</a>. I had to do exactly the same thing recently!</p>
4
2009-10-15T20:29:46Z
[ "python", "api", "pagerank" ]
Can I use Django's Generic Views with google-app-engine-django?
1,572,255
<p>Put simply, is there a way to get generic views to work?</p> <p>If I try the following in urls.py:</p> <pre><code>publisher_info = { 'queryset': Publisher.objects.all(), } urlpatterns = patterns('', (r'^publishers/$', list_detail.object_list, publisher_info) ) </code></pre> <p>I get the following error:</p...
1
2009-10-15T13:07:18Z
1,572,277
<p>It looks like this project should provide that functionality as a core feature.</p> <p><a href="http://code.google.com/p/app-engine-patch/" rel="nofollow">http://code.google.com/p/app-engine-patch/</a></p>
1
2009-10-15T13:11:10Z
[ "python", "django", "google-app-engine", "django-models", "django-generic-views" ]
Can I use Django's Generic Views with google-app-engine-django?
1,572,255
<p>Put simply, is there a way to get generic views to work?</p> <p>If I try the following in urls.py:</p> <pre><code>publisher_info = { 'queryset': Publisher.objects.all(), } urlpatterns = patterns('', (r'^publishers/$', list_detail.object_list, publisher_info) ) </code></pre> <p>I get the following error:</p...
1
2009-10-15T13:07:18Z
1,683,369
<p>The answer seems to be No.</p>
1
2009-11-05T20:28:47Z
[ "python", "django", "google-app-engine", "django-models", "django-generic-views" ]
How do I request data securely via Google OAuth?
1,572,450
<p>Until recently users of my site were able to import data from Google, via OAuth. However, recently they have received the warning below, in a yellow box, when authorising (although the import still works).</p> <p>I've also noticed this same warning on Facebook's GMail authenticator!</p> <p>What's changed / am I mi...
2
2009-10-15T13:40:14Z
1,572,588
<p>Did you try Googling the error message? Doing so took me to <a href="http://code.google.com/apis/accounts/docs/RegistrationForWebAppsAuto.html" rel="nofollow">this page</a>, which states:</p> <blockquote> <p>Registered with enhanced security: Registered applications <strong>with a security certificate on file</st...
1
2009-10-15T14:04:55Z
[ "python", "oauth" ]
How can I make Zenoss recognize skin changes?
1,572,661
<p>I'm writing a ZenPack for Zenoss which includes a new DataSource. The DataSource has a ToOne relationship with another persistent object and I'm trying to construct the user interface to allow a user to specify the value of this relationship. I've given the DataSource a factory_type_information attribute with an "...
0
2009-10-15T14:16:57Z
1,578,608
<p>The problem turned out to be that none of the template changes I made actually had any impact on the final page output. The changes were picked up, they just didn't matter.</p>
1
2009-10-16T14:59:24Z
[ "python", "zope", "zenoss" ]
Unexpected result in a simple example
1,572,676
<pre><code> def solve(numLegs, numHeads): for numSpiders in range(0, numHeads + 1): for numChicks in range(0, numHeads - numSpiders + 1): numPigs = numHeads - numChicks - numSpiders totLegs = 4*numPigs + 2*numChicks + 6*numSpiders if totLegs == numLegs: retur...
0
2009-10-15T14:21:44Z
1,572,713
<p>There is absolutely nothing wrong with your code. That's a completely valid result. With 10 pigs and 11 chickens, you get <code>10+11=21</code> heads, and <code>10*4 + 11*2</code> = 62 legs.</p> <p>So it returns a correct result.</p> <p>Now if you change that to 10 heads and 62 legs, and also change the code to ha...
2
2009-10-15T14:28:31Z
[ "python" ]
Unexpected result in a simple example
1,572,676
<pre><code> def solve(numLegs, numHeads): for numSpiders in range(0, numHeads + 1): for numChicks in range(0, numHeads - numSpiders + 1): numPigs = numHeads - numChicks - numSpiders totLegs = 4*numPigs + 2*numChicks + 6*numSpiders if totLegs == numLegs: retur...
0
2009-10-15T14:21:44Z
1,572,729
<p>A linear system with 2 equations and 3 variables is under-determined -- there may be multiple solutions for any given set of parameters; and this is indeed the case for the code you're showing. Nothing wrong with the code, if what you want is to get the solution (if any) with as few spiders as possible.</p> <p>If ...
2
2009-10-15T14:30:48Z
[ "python" ]
Unexpected result in a simple example
1,572,676
<pre><code> def solve(numLegs, numHeads): for numSpiders in range(0, numHeads + 1): for numChicks in range(0, numHeads - numSpiders + 1): numPigs = numHeads - numChicks - numSpiders totLegs = 4*numPigs + 2*numChicks + 6*numSpiders if totLegs == numLegs: retur...
0
2009-10-15T14:21:44Z
1,572,737
<p>Your code is correct - in the first iteration of the outermost <code>for</code> loop, <code>numChicks</code> is <code>0</code>. Since <code>solve</code> returns as soon as it finds a valid match, another possible valid match won't be attempted.</p> <p>You could change the <code>return</code> statement into a <code>...
5
2009-10-15T14:31:34Z
[ "python" ]
In Python, Python Image Library 1.1.6, how can I expand the canvas without resizing?
1,572,691
<p>I am probably looking for the wrong thing in the handbook, but I am looking to take an image object and expand it without resizing (stretching/squishing) the original image. </p> <p>Toy example: imagine a blue rectangle, 200 x 100, then I perform some operation and I have a new image object, 400 x 300, consisting ...
11
2009-10-15T14:23:55Z
1,572,966
<p>The ImageOps.expand function will expand the image, but it adds the same amount of pixels in each direction.</p> <p>The best way is simply to make a new image and paste:</p> <pre><code>newImage = Image.new(mode, (newWidth,newHeight)) newImage.paste(srcImage, (x1,y1,x1+oldWidth,y1+oldHeight)) </code></pre> <p>If p...
20
2009-10-15T15:03:47Z
[ "python", "python-imaging-library" ]
In Python, Python Image Library 1.1.6, how can I expand the canvas without resizing?
1,572,691
<p>I am probably looking for the wrong thing in the handbook, but I am looking to take an image object and expand it without resizing (stretching/squishing) the original image. </p> <p>Toy example: imagine a blue rectangle, 200 x 100, then I perform some operation and I have a new image object, 400 x 300, consisting ...
11
2009-10-15T14:23:55Z
1,573,679
<p>You might consider a rather different approach to your image... build it out of tiles of a fixed size. That way, as you need to expand, you just add new image tiles. When you have completed all of your computation, you can determine the final size of the image, create a blank image of that size, and paste the tile...
2
2009-10-15T16:55:26Z
[ "python", "python-imaging-library" ]
In Python, Python Image Library 1.1.6, how can I expand the canvas without resizing?
1,572,691
<p>I am probably looking for the wrong thing in the handbook, but I am looking to take an image object and expand it without resizing (stretching/squishing) the original image. </p> <p>Toy example: imagine a blue rectangle, 200 x 100, then I perform some operation and I have a new image object, 400 x 300, consisting ...
11
2009-10-15T14:23:55Z
27,784,150
<p>Based on interjays answer:</p> <pre><code>#!/usr/bin/env python from PIL import Image import math def resize_canvas(old_image_path="314.jpg", new_image_path="save.jpg", canvas_width=500, canvas_height=500): """Resize the canvas of old_image_path and store the new image in new_image_p...
2
2015-01-05T16:52:45Z
[ "python", "python-imaging-library" ]
Importing Python modules from a distant directory
1,572,967
<p>What's the shortest way to import a module from a distant, relative directory?</p> <p>We've been using this code which isn't too bad except your current working directory <em>has</em> to be the same as the directory as this code's or the relative path breaks, which can be error prone and confusing to users.</p> <p...
2
2009-10-15T15:04:08Z
1,572,979
<p>Any reason you wouldn't want to make your own shared-code dir under site-packages? Then you could just import import shared.code.module...</p>
1
2009-10-15T15:06:29Z
[ "python" ]
Importing Python modules from a distant directory
1,572,967
<p>What's the shortest way to import a module from a distant, relative directory?</p> <p>We've been using this code which isn't too bad except your current working directory <em>has</em> to be the same as the directory as this code's or the relative path breaks, which can be error prone and confusing to users.</p> <p...
2
2009-10-15T15:04:08Z
1,573,073
<p>You have several ways to handle imports, all documented in the Python language manual.</p> <p>See <a href="http://docs.python.org/library/site.html" rel="nofollow">http://docs.python.org/library/site.html</a> and <a href="http://docs.python.org/reference/simple%5Fstmts.html#the-import-statement" rel="nofollow">http...
-1
2009-10-15T15:19:11Z
[ "python" ]
Importing Python modules from a distant directory
1,572,967
<p>What's the shortest way to import a module from a distant, relative directory?</p> <p>We've been using this code which isn't too bad except your current working directory <em>has</em> to be the same as the directory as this code's or the relative path breaks, which can be error prone and confusing to users.</p> <p...
2
2009-10-15T15:04:08Z
1,573,088
<p>You've explained in a comment why you don't want to install "a single site-packages directory", but what about putting in <code>site-packages</code> a single, tiny <em>module</em>, say <code>jebootstrap.py</code>:</p> <pre><code>import os, sys def relative_dir(apath): return os.path.realpath( os.path.join(...
2
2009-10-15T15:21:44Z
[ "python" ]
Importing Python modules from a distant directory
1,572,967
<p>What's the shortest way to import a module from a distant, relative directory?</p> <p>We've been using this code which isn't too bad except your current working directory <em>has</em> to be the same as the directory as this code's or the relative path breaks, which can be error prone and confusing to users.</p> <p...
2
2009-10-15T15:04:08Z
1,573,105
<p>Since you don't want to install it in site-packages, you should use <a href="http://pypi.python.org/pypi/zc.buildout/" rel="nofollow">buildout</a> or <a href="http://pypi.python.org/pypi/virtualenv" rel="nofollow">virtualenv</a> to create isolated development environments. That solves the problem, and means you don'...
4
2009-10-15T15:26:04Z
[ "python" ]
Modifying state of other objects in a constructor: design no-no?
1,573,054
<p>I'm refactoring some code and found this (simplified of course, but general idea):</p> <pre><code>class Variable: def __init__(self): self.__constraints = [] def addConstraint(self, c): self.__constraints.append(c) class Constraint: def __init__(self, variables): for v in varia...
2
2009-10-15T15:16:29Z
1,573,078
<p>I agree with you. That's backwards. There may be some good reason for why, but it's unclear programming and it likely to bite someone if the foot sooner or later.</p>
0
2009-10-15T15:20:29Z
[ "python", "oop", "refactoring", "constructor" ]
Modifying state of other objects in a constructor: design no-no?
1,573,054
<p>I'm refactoring some code and found this (simplified of course, but general idea):</p> <pre><code>class Variable: def __init__(self): self.__constraints = [] def addConstraint(self, c): self.__constraints.append(c) class Constraint: def __init__(self, variables): for v in varia...
2
2009-10-15T15:16:29Z
1,573,091
<p>I see it as a self registration pattern. "Hello I'm new here, please allow me to join." </p> <p>I might prefer to have a differently named method so that the purpose is more clear, but I do actually quite like the approach.</p>
4
2009-10-15T15:23:26Z
[ "python", "oop", "refactoring", "constructor" ]
Modifying state of other objects in a constructor: design no-no?
1,573,054
<p>I'm refactoring some code and found this (simplified of course, but general idea):</p> <pre><code>class Variable: def __init__(self): self.__constraints = [] def addConstraint(self, c): self.__constraints.append(c) class Constraint: def __init__(self, variables): for v in varia...
2
2009-10-15T15:16:29Z
1,573,096
<p>This is common usage when you have two objects that are closely related (i.e. where only one of them alone doesn't make sense). Most common case: Parent child relations. When you add a child to a parent (i.e. <code>parent.children.append(child)</code>), you often also update the <code>child.parent</code> pointer.</p...
0
2009-10-15T15:24:22Z
[ "python", "oop", "refactoring", "constructor" ]
Modifying state of other objects in a constructor: design no-no?
1,573,054
<p>I'm refactoring some code and found this (simplified of course, but general idea):</p> <pre><code>class Variable: def __init__(self): self.__constraints = [] def addConstraint(self, c): self.__constraints.append(c) class Constraint: def __init__(self, variables): for v in varia...
2
2009-10-15T15:16:29Z
1,573,143
<p>I personally am not necessarily opposed to this, but...</p> <p>I would choose one usage pattern, and stick with it. In your case, since Variable already has a clean addConstraint method, my preference would be to use it.</p> <p>Otherwise, you'll need to add good checking to prevent the user from constructing a Co...
0
2009-10-15T15:32:28Z
[ "python", "oop", "refactoring", "constructor" ]
Modifying state of other objects in a constructor: design no-no?
1,573,054
<p>I'm refactoring some code and found this (simplified of course, but general idea):</p> <pre><code>class Variable: def __init__(self): self.__constraints = [] def addConstraint(self, c): self.__constraints.append(c) class Constraint: def __init__(self, variables): for v in varia...
2
2009-10-15T15:16:29Z
1,573,177
<p>I entirely concur with @djna's answer that the specific use case is perfectly legit -- here, it's an example of an object needing to en-register itself with a specified set of registries "at birth".</p> <p>A very sharp and extremely common subcase of that would be an observer object that exists strictly for the pur...
2
2009-10-15T15:38:16Z
[ "python", "oop", "refactoring", "constructor" ]
convert exponential to decimal in python
1,573,080
<p>I have an array in python that contains a set of values, some of them are</p> <p>2.32313e+07</p> <p>2.1155e+07</p> <p>1.923e+07</p> <p>11856</p> <p>112.32</p> <p>How do I convert the exponential formats to the decimal format</p> <p>Additional: Is there a way I can convert the exponent directly to decimal when...
6
2009-10-15T15:20:33Z
1,573,115
<p>I imagine you have a list rather than an array, but here it doesn't make much of a difference; in 2.6 and earlier versions of Python, something like:</p> <pre><code>&gt;&gt;&gt; L = [2.32313e+07, 2.1155e+07, 1.923e+07, 11856, 112.32] &gt;&gt;&gt; for x in L: print '%f' % x ... 23231300.000000 21155000.000000 19230...
5
2009-10-15T15:27:07Z
[ "python", "unix", "awk", "exponent" ]
convert exponential to decimal in python
1,573,080
<p>I have an array in python that contains a set of values, some of them are</p> <p>2.32313e+07</p> <p>2.1155e+07</p> <p>1.923e+07</p> <p>11856</p> <p>112.32</p> <p>How do I convert the exponential formats to the decimal format</p> <p>Additional: Is there a way I can convert the exponent directly to decimal when...
6
2009-10-15T15:20:33Z
1,573,146
<p>You can use locale.format() to format your numbers for output. This has the additional benefit of being consistent with any locale-specific conventions that might be expected in the presentation of the numbers. If you want complete control at the specific place where you do the output, you'd be better of with the <e...
1
2009-10-15T15:33:13Z
[ "python", "unix", "awk", "exponent" ]
convert exponential to decimal in python
1,573,080
<p>I have an array in python that contains a set of values, some of them are</p> <p>2.32313e+07</p> <p>2.1155e+07</p> <p>1.923e+07</p> <p>11856</p> <p>112.32</p> <p>How do I convert the exponential formats to the decimal format</p> <p>Additional: Is there a way I can convert the exponent directly to decimal when...
6
2009-10-15T15:20:33Z
1,573,542
<p>In answer to the last part of your question, <code>awk</code> can use the same <code>printf</code> format:</p> <pre><code>awk '{printf "%f\n",$1}' exponential_file </code></pre> <p>Where exponential_file contains:</p> <pre><code>2.32313e+07 2.1155e+07 1.923e+07 11856 112.32 </code></pre> <p>You can do the conver...
0
2009-10-15T16:32:11Z
[ "python", "unix", "awk", "exponent" ]
What is the typical workflow for development of a Zenoss ZenPack?
1,573,166
<p>ZenPack development seems to involve the creation of a variety of persistent state. There are model classes which represent explicitly persistent state. There are skins which are associated with model objects. There are organizers and instances of persistent classes (data sources, graphs, etc).</p> <p>Considerin...
2
2009-10-15T15:35:53Z
1,573,261
<p>I don't know anything about Zenoss specifically, but this situations are common for any syste that have persistent configuration in one form or another, like Zope and Plone for example.</p> <p>And the workflow is that you create a test environment that you can delete and replicate, but in parts and in whole. For a ...
2
2009-10-15T15:49:53Z
[ "python", "database", "zenoss" ]
What is the typical workflow for development of a Zenoss ZenPack?
1,573,166
<p>ZenPack development seems to involve the creation of a variety of persistent state. There are model classes which represent explicitly persistent state. There are skins which are associated with model objects. There are organizers and instances of persistent classes (data sources, graphs, etc).</p> <p>Considerin...
2
2009-10-15T15:35:53Z
7,033,005
<p>I am working on this very problem this week with Zenoss 3.1.</p> <p><strong>Caveat-</strong> If you make a bad zenpack - no wait - <strong>when</strong> you make a bad one, it can get stuck in Zope's db, and there is no way to get it out AFAIK. So-</p> <p><strong>First use the GUI to make a complete backup of a cl...
2
2011-08-11T21:21:22Z
[ "python", "database", "zenoss" ]
How do you implement a web-based direct deposit/eCheck payment system?
1,573,383
<p>I'm trying to develop a site that will allow users to pay for services with eChecks that other users are offering.</p> <p>The purchaser would pay money that would go into my account via direct deposit. The service provider could later withdraw money up to the amount they accumulated to their bank account.</p> <p>E...
4
2009-10-15T16:08:35Z
1,573,504
<p>I'm certain that you would not be able to do facilitated ACH/EFT transfers directly from one user's account to another user's account. However, as long as there's a third party in between the two users, this should be possible. But I'm assuming you'd want to do that anyways, so that you can get paid. The trick is...
3
2009-10-15T16:24:42Z
[ "python", "django", "payment-gateway", "payment" ]
Python def function: How do you specify the end of the function?
1,573,548
<p>I'm just learning python and confused when a "def" of a function ends?</p> <p>I see code samples like:</p> <pre><code>def myfunc(a=4,b=6): sum = a + b return sum myfunc() </code></pre> <p>I know it doesn't end because of the return (because I've seen if statements... if FOO than return BAR, else return F...
17
2009-10-15T16:32:53Z
1,573,554
<p>white spaces matter. when block is finished, that's when the function definition is finished.</p> <p>when function runs, it keeps going until it finishes, or until <code>return</code> or <code>yield</code> statement is encountered. If function finishes without encountering <code>return</code> or <code>yield</code> ...
0
2009-10-15T16:34:38Z
[ "python", "syntax" ]
Python def function: How do you specify the end of the function?
1,573,548
<p>I'm just learning python and confused when a "def" of a function ends?</p> <p>I see code samples like:</p> <pre><code>def myfunc(a=4,b=6): sum = a + b return sum myfunc() </code></pre> <p>I know it doesn't end because of the return (because I've seen if statements... if FOO than return BAR, else return F...
17
2009-10-15T16:32:53Z
1,573,555
<p>In Python whitespace is significant. The function ends when the indentation becomes smaller (less).</p> <pre><code>def f(): pass # first line pass # second line pass # &lt;-- less indentation, not part of function f. </code></pre> <p>Note that one-line functions can be written without indentation, on one l...
40
2009-10-15T16:34:42Z
[ "python", "syntax" ]
Python def function: How do you specify the end of the function?
1,573,548
<p>I'm just learning python and confused when a "def" of a function ends?</p> <p>I see code samples like:</p> <pre><code>def myfunc(a=4,b=6): sum = a + b return sum myfunc() </code></pre> <p>I know it doesn't end because of the return (because I've seen if statements... if FOO than return BAR, else return F...
17
2009-10-15T16:32:53Z
1,573,556
<p>Python is white-space sensitive in regard to the indentation. Once the indentation level falls back to the level at which the function is defined, the function has ended.</p>
20
2009-10-15T16:34:47Z
[ "python", "syntax" ]
Python def function: How do you specify the end of the function?
1,573,548
<p>I'm just learning python and confused when a "def" of a function ends?</p> <p>I see code samples like:</p> <pre><code>def myfunc(a=4,b=6): sum = a + b return sum myfunc() </code></pre> <p>I know it doesn't end because of the return (because I've seen if statements... if FOO than return BAR, else return F...
17
2009-10-15T16:32:53Z
1,573,564
<p>It uses indentation</p> <pre><code> def func(): funcbody if cond: ifbody outofif outof_func </code></pre>
1
2009-10-15T16:35:56Z
[ "python", "syntax" ]
Python def function: How do you specify the end of the function?
1,573,548
<p>I'm just learning python and confused when a "def" of a function ends?</p> <p>I see code samples like:</p> <pre><code>def myfunc(a=4,b=6): sum = a + b return sum myfunc() </code></pre> <p>I know it doesn't end because of the return (because I've seen if statements... if FOO than return BAR, else return F...
17
2009-10-15T16:32:53Z
1,573,666
<p>To be precise, a block ends when it encounter a non-empty line indented at most the same level with the start. This non empty line is not part of that block For example, the following print ends two blocks at the same time:</p> <pre><code>def foo(): if bar: print "bar" print "baz" # ends the if and foo...
6
2009-10-15T16:52:29Z
[ "python", "syntax" ]
Python def function: How do you specify the end of the function?
1,573,548
<p>I'm just learning python and confused when a "def" of a function ends?</p> <p>I see code samples like:</p> <pre><code>def myfunc(a=4,b=6): sum = a + b return sum myfunc() </code></pre> <p>I know it doesn't end because of the return (because I've seen if statements... if FOO than return BAR, else return F...
17
2009-10-15T16:32:53Z
1,574,034
<p>So its the indentation that matters. As other users here have pointed out to you, when the indentation level is at the same point as the def function declaration your function has ended. Keep in mind that you cannot mix tabs and spaces in Python. Most editors provide support for this.</p>
1
2009-10-15T17:56:30Z
[ "python", "syntax" ]
Python def function: How do you specify the end of the function?
1,573,548
<p>I'm just learning python and confused when a "def" of a function ends?</p> <p>I see code samples like:</p> <pre><code>def myfunc(a=4,b=6): sum = a + b return sum myfunc() </code></pre> <p>I know it doesn't end because of the return (because I've seen if statements... if FOO than return BAR, else return F...
17
2009-10-15T16:32:53Z
15,537,588
<p>Interestingly, if you're just typing at the python interactive interpreter, you have to follow a function with a blank line. This does not work:</p> <pre><code>def foo(x): return x+1 print "last" </code></pre> <p>although it is perfectly legal python syntax in a file. There are other syntactic differences when...
1
2013-03-21T00:54:48Z
[ "python", "syntax" ]
psycopg2 disconnects from server
1,573,579
<p>I've been tackling this for a while. I setup a completely new machine. I've installed a fresh copy of postgresql and all my other dependencies. Basically, I get these database disconnections at random times. I can perform identical requests and either it works or it doesn't. Very nondeterministic in outward appearan...
4
2009-10-15T16:38:27Z
1,573,673
<p>Do you <code>fork()</code> child processes (use preforked FastCGI or something similar)? This might be the reason that connection established in parent process doesn't work in child. If you use preforked method it's easy to switch to threading to see whether the problem has gone away. I saw exactly the same floating...
2
2009-10-15T16:53:15Z
[ "python", "database", "django", "postgresql", "psycopg2" ]
psycopg2 disconnects from server
1,573,579
<p>I've been tackling this for a while. I setup a completely new machine. I've installed a fresh copy of postgresql and all my other dependencies. Basically, I get these database disconnections at random times. I can perform identical requests and either it works or it doesn't. Very nondeterministic in outward appearan...
4
2009-10-15T16:38:27Z
1,579,793
<p>This is a very similar question to the one posted here:</p> <p><a href="http://stackoverflow.com/questions/393637/django-fastcgi-randomly-raising-operationalerror">http://stackoverflow.com/questions/393637/django-fastcgi-randomly-raising-operationalerror</a></p> <p>I imagine the answer will be the same to both if ...
3
2009-10-16T18:58:24Z
[ "python", "database", "django", "postgresql", "psycopg2" ]
Output in two rows for multiple columns in python
1,573,671
<p>I'm working with an output list that contains the following information: </p> <pre><code>[start position, stop position, chromosome, [('sample name', 'sample value'), ('sample name','sample value')...]] [[59000, 59500, chr1, [('cn_04', '1.362352462'), ('cn_01', '1.802001235')]], [100000, 11000...
0
2009-10-15T16:53:09Z
1,573,752
<p>You can create a simple text file with "*.csv" extension. Separate each field (column) by a comma. Optionally, use quotation marks for text fields, especially if a field is expected to contain your delimiter (comma). You can even put excel formulas (preceded by '=') and excel will parse them correctly.</p> <p>Doubl...
0
2009-10-15T17:07:20Z
[ "python", "file", "format", "bioinformatics" ]
Output in two rows for multiple columns in python
1,573,671
<p>I'm working with an output list that contains the following information: </p> <pre><code>[start position, stop position, chromosome, [('sample name', 'sample value'), ('sample name','sample value')...]] [[59000, 59500, chr1, [('cn_04', '1.362352462'), ('cn_01', '1.802001235')]], [100000, 11000...
0
2009-10-15T16:53:09Z
1,573,881
<p>Here's one approach. I made the simplifying assumption that there is a small finite limit to the possible number of observations, so I just loop from 1 to 6 explicitly. You can easily expand the upper limit of the loop, although if you go past 9 the logic in the get_obs function will need to change. You could als...
0
2009-10-15T17:27:17Z
[ "python", "file", "format", "bioinformatics" ]
Output in two rows for multiple columns in python
1,573,671
<p>I'm working with an output list that contains the following information: </p> <pre><code>[start position, stop position, chromosome, [('sample name', 'sample value'), ('sample name','sample value')...]] [[59000, 59500, chr1, [('cn_04', '1.362352462'), ('cn_01', '1.802001235')]], [100000, 11000...
0
2009-10-15T16:53:09Z
1,573,885
<p>Never do these types of nested lists/dictionary, they are not pythonic and are very likely to bring you to an error.</p> <p>Instead, either use a class:</p> <pre><code>&gt;&gt;&gt; class Gene: def __init__(self, start, end, chromosome, transcripts): self.start = start self.end = end ...
-1
2009-10-15T17:27:30Z
[ "python", "file", "format", "bioinformatics" ]
Output in two rows for multiple columns in python
1,573,671
<p>I'm working with an output list that contains the following information: </p> <pre><code>[start position, stop position, chromosome, [('sample name', 'sample value'), ('sample name','sample value')...]] [[59000, 59500, chr1, [('cn_04', '1.362352462'), ('cn_01', '1.802001235')]], [100000, 11000...
0
2009-10-15T16:53:09Z
1,574,384
<p>For sending data to Excel, I would use CSV instead of a fixed-length text format; that way, if it turns out (say) that you need more significant figures in your float values, the format of your output doesn't change. Also, you can just open CSV files in Excel; you don't have to import them. And the <code>csv.write...
3
2009-10-15T19:06:11Z
[ "python", "file", "format", "bioinformatics" ]
Output in two rows for multiple columns in python
1,573,671
<p>I'm working with an output list that contains the following information: </p> <pre><code>[start position, stop position, chromosome, [('sample name', 'sample value'), ('sample name','sample value')...]] [[59000, 59500, chr1, [('cn_04', '1.362352462'), ('cn_01', '1.802001235')]], [100000, 11000...
0
2009-10-15T16:53:09Z
1,576,437
<p>You can also use <a href="http://pypi.python.org/pypi/xlwt" rel="nofollow">xlwt</a> to write .xls files directly, without touching Excel. <a href="http://panela.blog-city.com/pyexcelerator%5Fxlwt%5Fcheatsheet%5Fcreate%5Fnative%5Fexcel%5Ffrom%5Fpu.htm" rel="nofollow">More info</a>.</p> <p>Here is some sample code t...
0
2009-10-16T06:31:44Z
[ "python", "file", "format", "bioinformatics" ]