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 |
|---|---|---|---|---|---|---|---|---|---|
Get Root Domain of Link | 1,521,592 | <p>I have a link such as <a href="http://www.techcrunch.com/">http://www.techcrunch.com/</a> and I would like to get just the techcrunch.com part of the link. How do I go about this in python?</p>
| 10 | 2009-10-05T18:16:12Z | 3,369,248 | <p>This worked for my purposes. I figured I'd share it. </p>
<pre><code>".".join("www.sun.google.com".split(".")[-2:])
</code></pre>
| -2 | 2010-07-30T06:53:24Z | [
"python",
"regex",
"dns",
"root"
] |
Get Root Domain of Link | 1,521,592 | <p>I have a link such as <a href="http://www.techcrunch.com/">http://www.techcrunch.com/</a> and I would like to get just the techcrunch.com part of the link. How do I go about this in python?</p>
| 10 | 2009-10-05T18:16:12Z | 32,146,940 | <p>______Using Python 3.3 and not 2.x________</p>
<p>I would like to add a small thing to Ben Blank's answer.</p>
<pre><code>from urllib.parse import quote,unquote,urlparse
u=unquote(u) #u= URL e.g. http://twitter.co.uk/hello/there
g=urlparse(u)
u=g.netloc
</code></pre>
<p>By now, I just got the domain name from <a ... | 0 | 2015-08-21T18:19:11Z | [
"python",
"regex",
"dns",
"root"
] |
Using Python's isinstance | 1,521,655 | <p>The following usage of <code>isinstance</code> doesn't seem to work in Python 2.5.2 or 2.6.2:</p>
<pre><code>class BananaCake:
def __init__(self):
print 'Banana Cake'
class ChocolateCake:
def __init__(self):
print 'Chocolate Cake'
class CakeFactory:
@staticmethod
def create(name):
... | 1 | 2009-10-05T18:25:57Z | 1,521,678 | <p>You're returning a class instead of an instance.</p>
<pre>
>>> banana_cake is BananaCake
True
</pre>
<p>I believe you want this:</p>
<pre><code>class CakeFactory:
@staticmethod
def create(name):
if name == 'banana':
return BananaCake() # call the constructor
elif name =... | 8 | 2009-10-05T18:32:02Z | [
"python"
] |
Using Python's isinstance | 1,521,655 | <p>The following usage of <code>isinstance</code> doesn't seem to work in Python 2.5.2 or 2.6.2:</p>
<pre><code>class BananaCake:
def __init__(self):
print 'Banana Cake'
class ChocolateCake:
def __init__(self):
print 'Chocolate Cake'
class CakeFactory:
@staticmethod
def create(name):
... | 1 | 2009-10-05T18:25:57Z | 1,521,698 | <p>That's because 'banana_cake' is not an instance of BananaCake.</p>
<p>The CakeFactory implementation returns the BananaCake CLASS, not an instance of BananaCake.</p>
<p>Try modifying CakeFactory to return "BananaCake()". Calling the BananCake constructor will return an instance, rather than the class.</p>
| 2 | 2009-10-05T18:35:50Z | [
"python"
] |
Close Python when Parent is closed | 1,521,670 | <p>I have a Python program (PP) that loads another Program(AP) via COM, gets its window handle and sets it to be the PP parent.</p>
<p>This works pretty well except that I can't control that AP still has their [X] button available in the top left corner. Since this is a pretty obvious place for the user to close when... | 0 | 2009-10-05T18:28:55Z | 1,522,240 | <p>How's PP's control flow? If it's event-driven it could get appropriate events upon closure of that parent window or termination of that AP process; otherwise it could "poll" to check if the window or process are still around.</p>
| 1 | 2009-10-05T20:33:51Z | [
"python",
"com",
"wxpython",
"parent"
] |
Close Python when Parent is closed | 1,521,670 | <p>I have a Python program (PP) that loads another Program(AP) via COM, gets its window handle and sets it to be the PP parent.</p>
<p>This works pretty well except that I can't control that AP still has their [X] button available in the top left corner. Since this is a pretty obvious place for the user to close when... | 0 | 2009-10-05T18:28:55Z | 1,530,203 | <p>As you said you get AP's handle and pass it to PP, so PP has that handle around, so when AP is closed PP can check if that window handle exists using windows API IsWindow or IsWindowVisible depending on you needs</p>
<pre><code>import win32gui
win32gui.IsWindow(handle)
win32gui.IsWindowVisible(handle)
</code></pre>... | 0 | 2009-10-07T08:10:11Z | [
"python",
"com",
"wxpython",
"parent"
] |
How to prevent log file truncation with python logging module? | 1,521,681 | <p>I need to use python logging module to print debugging info to a file with statements like:</p>
<pre><code>logging.debug(something)
</code></pre>
<p>The file is truncated (i am assuming - by the logging module) and the messages get deleted before I can see them - how can that be prevented?</p>
<p>Here is my loggi... | 5 | 2009-10-05T18:32:29Z | 1,521,739 | <p><a href="http://docs.python.org/library/logging.html#simple-examples" rel="nofollow"><code>logging</code></a></p>
<blockquote>
<p>If you run the script repeatedly, the additional log messages are appended to the file. <strong>To create a new file each time, you can pass a filemode argument to basicConfig() with a... | 11 | 2009-10-05T18:45:23Z | [
"python",
"logging"
] |
Cost of list functions in Python | 1,521,784 | <p>Based on <a href="http://bytes.com/topic/python/answers/101848-list-implementation">this older thread</a>, it looks like the cost of list functions in Python is:</p>
<ul>
<li>Random access: O(1)</li>
<li>Insertion/deletion to front: O(n)</li>
<li>Insertion/deletion to back: O(1)</li>
</ul>
<p>Can anyone confirm wh... | 8 | 2009-10-05T18:58:42Z | 1,521,842 | <p>That's correct, inserting in front forces a move of all the elements to make place.</p>
<p><code>collections.deque</code> offers similar functionality, but is optimized for insertion on both sides.</p>
| 3 | 2009-10-05T19:10:59Z | [
"python",
"performance",
"list"
] |
Cost of list functions in Python | 1,521,784 | <p>Based on <a href="http://bytes.com/topic/python/answers/101848-list-implementation">this older thread</a>, it looks like the cost of list functions in Python is:</p>
<ul>
<li>Random access: O(1)</li>
<li>Insertion/deletion to front: O(n)</li>
<li>Insertion/deletion to back: O(1)</li>
</ul>
<p>Can anyone confirm wh... | 8 | 2009-10-05T18:58:42Z | 1,521,843 | <p>Take a look <a href="http://www.python.org/dev/peps/pep-3128/#motivation">here</a>. It's a PEP for a different kind of list. The version specified is 2.6/3.0.</p>
<p>Append (insertion to back) is <code>O(1)</code>, while insertion (everywhere else) is <code>O(n)</code>. So <strong>yes</strong>, it looks like this ... | 15 | 2009-10-05T19:11:08Z | [
"python",
"performance",
"list"
] |
Cost of list functions in Python | 1,521,784 | <p>Based on <a href="http://bytes.com/topic/python/answers/101848-list-implementation">this older thread</a>, it looks like the cost of list functions in Python is:</p>
<ul>
<li>Random access: O(1)</li>
<li>Insertion/deletion to front: O(n)</li>
<li>Insertion/deletion to back: O(1)</li>
</ul>
<p>Can anyone confirm wh... | 8 | 2009-10-05T18:58:42Z | 1,522,168 | <p>Python 3 is mostly an evolutionary change, no big changes in the datastructures and their complexities.</p>
<p>The canonical source for Python collections is <a href="http://wiki.python.org/moin/TimeComplexity" rel="nofollow">TimeComplexity</a> on the Wiki.</p>
| 4 | 2009-10-05T20:19:51Z | [
"python",
"performance",
"list"
] |
Cost of list functions in Python | 1,521,784 | <p>Based on <a href="http://bytes.com/topic/python/answers/101848-list-implementation">this older thread</a>, it looks like the cost of list functions in Python is:</p>
<ul>
<li>Random access: O(1)</li>
<li>Insertion/deletion to front: O(n)</li>
<li>Insertion/deletion to back: O(1)</li>
</ul>
<p>Can anyone confirm wh... | 8 | 2009-10-05T18:58:42Z | 1,522,519 | <p>Fwiw, there is a faster (for some ops... insert is O(log n)) <a href="http://www.python.org/dev/peps/pep-3128/" rel="nofollow">list implementation</a> called BList if you need it. <a href="http://stutzbachenterprises.com/blist/" rel="nofollow">BList</a></p>
| 2 | 2009-10-05T21:31:34Z | [
"python",
"performance",
"list"
] |
How to specify date and time in python? | 1,521,906 | <p>Quite simple newbie question:</p>
<p>What is the object used in python to specify date (and time) in Python?</p>
<p>For instance, to create an object that holds a given date and time, (let's say <code>'05/10/09 18:00'</code>).</p>
<p><strong>EDIT</strong></p>
<p>As per S.Lott request, what I have so far is:</p>
... | 2 | 2009-10-05T19:22:49Z | 1,521,922 | <p>Look at the <a href="http://docs.python.org/library/datetime.html" rel="nofollow">datetime</a> module; there are datetime, date and timedelta class definitions.</p>
| 4 | 2009-10-05T19:26:32Z | [
"python",
"datetime"
] |
How to specify date and time in python? | 1,521,906 | <p>Quite simple newbie question:</p>
<p>What is the object used in python to specify date (and time) in Python?</p>
<p>For instance, to create an object that holds a given date and time, (let's say <code>'05/10/09 18:00'</code>).</p>
<p><strong>EDIT</strong></p>
<p>As per S.Lott request, what I have so far is:</p>
... | 2 | 2009-10-05T19:22:49Z | 1,522,043 | <p>Simple example:</p>
<pre><code>>>> import datetime
# 05/10/09 18:00
>>> d = datetime.datetime(2009, 10, 5, 18, 00)
>>> print d.year, d.month, d.day, d.hour, d.second
2009 10 5 18 0
>>> print d.isoformat(' ')
2009-10-05 18:00:00
>>>
</code></pre>
| 18 | 2009-10-05T19:51:58Z | [
"python",
"datetime"
] |
How to specify date and time in python? | 1,521,906 | <p>Quite simple newbie question:</p>
<p>What is the object used in python to specify date (and time) in Python?</p>
<p>For instance, to create an object that holds a given date and time, (let's say <code>'05/10/09 18:00'</code>).</p>
<p><strong>EDIT</strong></p>
<p>As per S.Lott request, what I have so far is:</p>
... | 2 | 2009-10-05T19:22:49Z | 1,522,078 | <p>Nick D has the official way of handling your problem. If you want to pass in a string like you did in your question, the dateutil module (<a href="http://labix.org/python-dateutil" rel="nofollow">http://labix.org/python-dateutil</a>) has excellent support for that kind of thing.</p>
<p>For examples, I'm going to c... | 4 | 2009-10-05T20:01:29Z | [
"python",
"datetime"
] |
How to specify date and time in python? | 1,521,906 | <p>Quite simple newbie question:</p>
<p>What is the object used in python to specify date (and time) in Python?</p>
<p>For instance, to create an object that holds a given date and time, (let's say <code>'05/10/09 18:00'</code>).</p>
<p><strong>EDIT</strong></p>
<p>As per S.Lott request, what I have so far is:</p>
... | 2 | 2009-10-05T19:22:49Z | 1,522,102 | <pre><code>>>> import datetime
>>> datetime.datetime.strptime('05/10/09 18:00', '%d/%m/%y %H:%M')
datetime.datetime(2009, 10, 5, 18, 0)
>>> datetime.datetime.today()
datetime.datetime(2009, 10, 5, 21, 3, 55, 827787)
</code></pre>
<p>So, you can either use format string to convert to <code>da... | 1 | 2009-10-05T20:05:01Z | [
"python",
"datetime"
] |
How create jinja2 extension? | 1,521,909 | <p>I try to make extension for jinja2. I has written such code:</p>
<p><a href="http://dumpz.org/12996/" rel="nofollow">http://dumpz.org/12996/</a></p>
<p>But I receive exception: <code>'NoneType' object is not iterable</code>. Where is a bug?
That should return <code>parse</code>. Also what should accept and return ... | 1 | 2009-10-05T19:22:56Z | 1,796,953 | <p>You're using a <code>CallBlock</code>, which indicates that you want your extension to act as a block. E.g.</p>
<pre><code>{% mytest arg1 arg2 %}
stuff
in
here
{% endmytest %}
</code></pre>
<p><code>nodes.CallBlock</code> expects that you pass it a list of nodes representing the body (the inner statements) for yo... | 10 | 2009-11-25T13:36:49Z | [
"python",
"templates",
"jinja2"
] |
How to fix such ClientForm bug? | 1,522,125 | <pre><code>from mechanize import Browser
br = Browser()
page = br.open('http://wow.interzet.ru/news.php?readmore=23')
br.form = br.forms().next()
print br.form
</code></pre>
<p>gives me the following error:</p>
<pre><code>Traceback (most recent call last):
File "C:\Users\roddik\Desktop\mech.py", line 6, in <modu... | 1 | 2009-10-05T20:10:08Z | 1,522,392 | <p>The problem is caused by urls like this</p>
<pre><code>http://wow.zet/forum/index.php?showtopic=1197&pid=30419&st=0&#entry30419
</code></pre>
<p>ClientForm is looking for an integer after the &#</p>
<p>It is ok to have the # in the url, but it should be escaped in the html
as &# means a charac... | 1 | 2009-10-05T21:06:26Z | [
"python",
"mechanize",
"clientform"
] |
Put bar at the end of every line that includes foo | 1,522,386 | <p>I have a list with a large number of lines, each taking the subject-verb-object form, eg: </p>
<pre>
Jane likes Fred
Chris dislikes Joe
Nate knows Jill
</pre>
<p>To plot a network graph that expresses the different relationships between the nodes in directed color-coded edges, I will need to replace the verb with ... | 4 | 2009-10-05T21:04:32Z | 1,522,453 | <p>Simple enough; assuming the lists of verbs is fixed and small, this is easy to do with a dictionary and <code>for</code> loop:</p>
<pre><code>VERBS = {
"likes": "red"
, "dislikes": "blue"
, "knows": "black"
}
def replace_verb (line):
for verb, color in VERBS.items():
if verb in line:
... | 3 | 2009-10-05T21:19:22Z | [
"python",
"text-processing"
] |
Put bar at the end of every line that includes foo | 1,522,386 | <p>I have a list with a large number of lines, each taking the subject-verb-object form, eg: </p>
<pre>
Jane likes Fred
Chris dislikes Joe
Nate knows Jill
</pre>
<p>To plot a network graph that expresses the different relationships between the nodes in directed color-coded edges, I will need to replace the verb with ... | 4 | 2009-10-05T21:04:32Z | 1,522,461 | <p>Are you sure this isn't a little homeworky :) If so, it's okay to fess up. Without going into too much detail, think about the tasks you're trying to do:</p>
<p>For each line:</p>
<ol>
<li>read it</li>
<li>split it into words (on whitespace - .split() )</li>
<li>convert the middle word into a color (based on a m... | 1 | 2009-10-05T21:21:44Z | [
"python",
"text-processing"
] |
Put bar at the end of every line that includes foo | 1,522,386 | <p>I have a list with a large number of lines, each taking the subject-verb-object form, eg: </p>
<pre>
Jane likes Fred
Chris dislikes Joe
Nate knows Jill
</pre>
<p>To plot a network graph that expresses the different relationships between the nodes in directed color-coded edges, I will need to replace the verb with ... | 4 | 2009-10-05T21:04:32Z | 1,522,476 | <p>Python 2.5:</p>
<pre><code>import sys
from collections import defaultdict
codes = defaultdict(lambda: ("---", "Missing action!"))
codes["likes"] = ("-->", "red")
codes["dislikes"] = ("-/>", "green")
codes["loves"] = ("==>", "blue")
for line in sys.stdin:
subject, verb, object_ = line.strip().sp... | 0 | 2009-10-05T21:24:01Z | [
"python",
"text-processing"
] |
Put bar at the end of every line that includes foo | 1,522,386 | <p>I have a list with a large number of lines, each taking the subject-verb-object form, eg: </p>
<pre>
Jane likes Fred
Chris dislikes Joe
Nate knows Jill
</pre>
<p>To plot a network graph that expresses the different relationships between the nodes in directed color-coded edges, I will need to replace the verb with ... | 4 | 2009-10-05T21:04:32Z | 1,522,500 | <p>It sounds like you will want to research <a href="http://docs.python.org/tutorial/datastructures.html#dictionaries" rel="nofollow">dictionaries</a> and <a href="http://docs.python.org/library/stdtypes.html#string-formatting-operations" rel="nofollow">string formatting</a>. In general, if you need help programming, j... | 5 | 2009-10-05T21:27:41Z | [
"python",
"text-processing"
] |
Put bar at the end of every line that includes foo | 1,522,386 | <p>I have a list with a large number of lines, each taking the subject-verb-object form, eg: </p>
<pre>
Jane likes Fred
Chris dislikes Joe
Nate knows Jill
</pre>
<p>To plot a network graph that expresses the different relationships between the nodes in directed color-coded edges, I will need to replace the verb with ... | 4 | 2009-10-05T21:04:32Z | 1,522,530 | <pre><code>verbs = {"dislikes":"blue", "knows":"black", "likes":"red"}
for s in open("/tmp/infile"):
s = s.strip()
for verb in verbs.keys():
if (s.count(verb) > 0):
print s.replace(verb,"->")+" "+verbs[verb]+";"
break
</code></pre>
<p>Edit: Rather use "for s in open"</p>
| 2 | 2009-10-05T21:34:23Z | [
"python",
"text-processing"
] |
Put bar at the end of every line that includes foo | 1,522,386 | <p>I have a list with a large number of lines, each taking the subject-verb-object form, eg: </p>
<pre>
Jane likes Fred
Chris dislikes Joe
Nate knows Jill
</pre>
<p>To plot a network graph that expresses the different relationships between the nodes in directed color-coded edges, I will need to replace the verb with ... | 4 | 2009-10-05T21:04:32Z | 1,522,868 | <p>In addition to the question, Karasu also said (in a comment on one answer): "In the actual input both subjects and objects vary unpredictably between one and two words."</p>
<p>Okay, here's how I would solve this.</p>
<pre><code>color_map = \
{
"likes" : "red",
"dislikes" : "blue",
"knows" : "black",
}... | 0 | 2009-10-05T23:10:31Z | [
"python",
"text-processing"
] |
Put bar at the end of every line that includes foo | 1,522,386 | <p>I have a list with a large number of lines, each taking the subject-verb-object form, eg: </p>
<pre>
Jane likes Fred
Chris dislikes Joe
Nate knows Jill
</pre>
<p>To plot a network graph that expresses the different relationships between the nodes in directed color-coded edges, I will need to replace the verb with ... | 4 | 2009-10-05T21:04:32Z | 1,523,649 | <p>Here is an improved version of my previous answer. This one uses regular expression matching to make a fuzzy match on the verb. These all work:</p>
<pre><code>Steve loves Denise
Bears love honey
Maria interested Anders
Maria interests Anders
</code></pre>
<p>The regular expression pattern "loves?" matches "love"... | 0 | 2009-10-06T04:51:14Z | [
"python",
"text-processing"
] |
(Python) Passing a threading.Thread object through a function? | 1,522,409 | <p>I have a timer function:</p>
<pre><code># This is a class that schedules tasks. It will call it's ring() function
# when the timer starts, and call it's running() function when within the
# time limit, and call it's over() function when the time is up.
# This class uses SYSTEM time.
import time, threading
import ... | 0 | 2009-10-05T21:10:25Z | 1,522,753 | <p>You show us tons of code but not the key parts -- the Scheduler part (and what's that peculiar upper-case-O Object class...?). Anyway, to answer your question, passing instances of Thread subclasses through functions, adding them to lists, etc etc, is perfectly fine (though other things you're doing may not be -- e... | 2 | 2009-10-05T22:34:05Z | [
"python",
"class",
"inheritance",
"multithreading"
] |
(Python) Passing a threading.Thread object through a function? | 1,522,409 | <p>I have a timer function:</p>
<pre><code># This is a class that schedules tasks. It will call it's ring() function
# when the timer starts, and call it's running() function when within the
# time limit, and call it's over() function when the time is up.
# This class uses SYSTEM time.
import time, threading
import ... | 0 | 2009-10-05T21:10:25Z | 1,526,084 | <p>Ugh.. I feel stupid now. The problem was that, the blocks were being passed by reference to the scheduler, therefore everytime I added a timer to the block, I was overwriting the older timer. </p>
<p>I made a schedulerBlock class containing a timer and a block. It now works perfectly =)</p>
| 0 | 2009-10-06T14:51:17Z | [
"python",
"class",
"inheritance",
"multithreading"
] |
map string position to line number in regex output | 1,522,510 | <p>I'm working on a "grep-like" utility in Python for searching Oracle source code files. Coding standards have changed over time, so trying to find something like "all deletes from table a.foo" could span multiple lines, or not, depending on the age of that piece of code:</p>
<pre><code>s = """-- multiline DDL state... | 2 | 2009-10-05T21:30:29Z | 1,522,531 | <pre><code>lineno = s.count("\n",0,m.start())+1
</code></pre>
| 5 | 2009-10-05T21:34:40Z | [
"python",
"regex",
"grep",
"multiline"
] |
How do I run a Python program? | 1,522,564 | <p>So I'm starting like Python a bit, but I'm having trouble erm...running it. Lol</p>
<p>I'm using IDLE for now, but its no use whatsoever because you can only run a couple of lines at a time.</p>
<p>I'm also using Komodo Edit to create the actual .py files.</p>
<p>My question is, how can I run the .py files to tes... | 36 | 2009-10-05T21:42:30Z | 1,522,567 | <p>You can just call</p>
<pre><code>python /path/to/filename.py
</code></pre>
| 12 | 2009-10-05T21:43:01Z | [
"python",
"ide",
"debugging"
] |
How do I run a Python program? | 1,522,564 | <p>So I'm starting like Python a bit, but I'm having trouble erm...running it. Lol</p>
<p>I'm using IDLE for now, but its no use whatsoever because you can only run a couple of lines at a time.</p>
<p>I'm also using Komodo Edit to create the actual .py files.</p>
<p>My question is, how can I run the .py files to tes... | 36 | 2009-10-05T21:42:30Z | 1,522,599 | <p>In IDLE press F5</p>
<p>You can open your .py file with IDLE and press F5 to run it. </p>
<p>You can open that same file with other editor ( like Komodo as you said ) save it and press F5 again; F5 works with IDLE ( even when the editing is done with another tool ).</p>
<p>If you want to run it directly from Komo... | 11 | 2009-10-05T21:52:24Z | [
"python",
"ide",
"debugging"
] |
How do I run a Python program? | 1,522,564 | <p>So I'm starting like Python a bit, but I'm having trouble erm...running it. Lol</p>
<p>I'm using IDLE for now, but its no use whatsoever because you can only run a couple of lines at a time.</p>
<p>I'm also using Komodo Edit to create the actual .py files.</p>
<p>My question is, how can I run the .py files to tes... | 36 | 2009-10-05T21:42:30Z | 1,527,012 | <p>I'm very glad you asked! I was just working on explaining this very thing <a href="http://en.wikibooks.org/wiki/Choose%5FYour%5FOwn%5FPyventure">in our wikibook</a> (which is obviously incomplete). We're working with Python novices, and had to help a few through exactly what you're asking! </p>
<p><strong>Command... | 45 | 2009-10-06T17:37:26Z | [
"python",
"ide",
"debugging"
] |
How do I run a Python program? | 1,522,564 | <p>So I'm starting like Python a bit, but I'm having trouble erm...running it. Lol</p>
<p>I'm using IDLE for now, but its no use whatsoever because you can only run a couple of lines at a time.</p>
<p>I'm also using Komodo Edit to create the actual .py files.</p>
<p>My question is, how can I run the .py files to tes... | 36 | 2009-10-05T21:42:30Z | 25,067,116 | <p>if you dont want call <code>filename.py</code> you can add <code>.PY</code> to the PATHEXT, that way you will just call <code>filename</code></p>
| 0 | 2014-07-31T19:13:20Z | [
"python",
"ide",
"debugging"
] |
How do I run a Python program? | 1,522,564 | <p>So I'm starting like Python a bit, but I'm having trouble erm...running it. Lol</p>
<p>I'm using IDLE for now, but its no use whatsoever because you can only run a couple of lines at a time.</p>
<p>I'm also using Komodo Edit to create the actual .py files.</p>
<p>My question is, how can I run the .py files to tes... | 36 | 2009-10-05T21:42:30Z | 34,713,762 | <p>Python itself comes with an editor that you can access from the IDLE File > New File menu option.</p>
<p>Write the code in that file, save it as [filename].py and then (in that same file editor window) press F5 to execute the code you created in the IDLE Shell window.</p>
<p>Note: it's just been the easiest and mo... | 1 | 2016-01-11T03:26:27Z | [
"python",
"ide",
"debugging"
] |
should I call close() after urllib.urlopen()? | 1,522,636 | <p>I'm new to Python and reading someone else's code:</p>
<p>should <code>urllib.urlopen()</code> be followed by <code>urllib.close()</code>? Otherwise, one would leak connections, correct?</p>
| 48 | 2009-10-05T21:59:04Z | 1,522,662 | <p>Strictly speaking, this is true. But in practice, once (if) <code>urllib</code> goes out of scope, the connection will be closed by the automatic garbage collector.</p>
| 2 | 2009-10-05T22:07:57Z | [
"python",
"urllib"
] |
should I call close() after urllib.urlopen()? | 1,522,636 | <p>I'm new to Python and reading someone else's code:</p>
<p>should <code>urllib.urlopen()</code> be followed by <code>urllib.close()</code>? Otherwise, one would leak connections, correct?</p>
| 48 | 2009-10-05T21:59:04Z | 1,522,709 | <p>The <code>close</code> method must be called on the <em>result</em> of <code>urllib.urlopen</code>, <strong>not</strong> on the <code>urllib</code> module itself as you're thinking about (as you mention <code>urllib.close</code> -- which doesn't exist).</p>
<p>The best approach: instead of <code>x = urllib.urlopen(... | 80 | 2009-10-05T22:22:17Z | [
"python",
"urllib"
] |
should I call close() after urllib.urlopen()? | 1,522,636 | <p>I'm new to Python and reading someone else's code:</p>
<p>should <code>urllib.urlopen()</code> be followed by <code>urllib.close()</code>? Otherwise, one would leak connections, correct?</p>
| 48 | 2009-10-05T21:59:04Z | 1,522,713 | <p>Like @Peter says, out-of-scope opened URLs will become eligible for garbage collection.</p>
<p>However, also note that <code>urllib.py</code> defines:</p>
<pre><code> def __del__(self):
self.close()
</code></pre>
<p>This means that <strong>when the reference count for that instance reaches zero</strong>, ... | 11 | 2009-10-05T22:24:08Z | [
"python",
"urllib"
] |
should I call close() after urllib.urlopen()? | 1,522,636 | <p>I'm new to Python and reading someone else's code:</p>
<p>should <code>urllib.urlopen()</code> be followed by <code>urllib.close()</code>? Otherwise, one would leak connections, correct?</p>
| 48 | 2009-10-05T21:59:04Z | 35,426,368 | <p>If I am not mistaken,I guess even <code>del varname[:]</code> should work to decrement the reference count to zero which should ideally call the <code>__del__(self)</code> automatically</p>
| 0 | 2016-02-16T07:30:42Z | [
"python",
"urllib"
] |
How do I get the module instance for a class in Python? | 1,522,651 | <p>I am learning Python, and as always, I'm being ambitious with my starter projects. I am working on a plugin system for a community site toolkit for App Engine. My plugin superclass has a method called <code>install_path</code>. I would like to obtain the <code>__path__</code> for the <code>__module__</code> for <... | 8 | 2009-10-05T22:03:21Z | 1,522,667 | <p>How about <a href="http://effbot.org/zone/import-confusion.htm" rel="nofollow">Importing modules</a></p>
<blockquote>
<p><code>X = __import__(âXâ)</code> works like <code>import
X</code>, with the difference that you 1)
pass the module name as a string, and
2) explicitly assign it to a variable
in you... | 1 | 2009-10-05T22:09:45Z | [
"python"
] |
How do I get the module instance for a class in Python? | 1,522,651 | <p>I am learning Python, and as always, I'm being ambitious with my starter projects. I am working on a plugin system for a community site toolkit for App Engine. My plugin superclass has a method called <code>install_path</code>. I would like to obtain the <code>__path__</code> for the <code>__module__</code> for <... | 8 | 2009-10-05T22:03:21Z | 1,522,687 | <p>The <a href="http://docs.python.org/library/sys.html#sys.modules"><code>sys.modules</code></a> dict contains all imported modules, so you can use:</p>
<pre><code>mod = sys.modules[__module__]
</code></pre>
| 11 | 2009-10-05T22:13:24Z | [
"python"
] |
How do I get the module instance for a class in Python? | 1,522,651 | <p>I am learning Python, and as always, I'm being ambitious with my starter projects. I am working on a plugin system for a community site toolkit for App Engine. My plugin superclass has a method called <code>install_path</code>. I would like to obtain the <code>__path__</code> for the <code>__module__</code> for <... | 8 | 2009-10-05T22:03:21Z | 1,522,746 | <p>Alternatively, you can use the module's global <a href="http://docs.python.org/reference/datamodel.html?highlight=%5F%5Ffile%5F%5F" rel="nofollow"><code>__file__</code> variable</a> if all you want is the module's path.</p>
| 1 | 2009-10-05T22:31:26Z | [
"python"
] |
Problem running a very simple Python program | 1,522,708 | <p>Why is my program giving me an error here?</p>
<pre><code>import random
TheNumber = random.randrange(1,200,1)
NotGuessed = True
Tries = 0
GuessedNumber = int(input("Take a guess at the magic number!: "))
while NotGuessed == True:
if GuessedNumber < TheNumber:
print("Your guess is ... | 1 | 2009-10-05T22:22:08Z | 1,522,726 | <p>it's <code>str</code>, not <code>string</code>. but your infinite loop is a bigger problem. auto-increment is written like this:</p>
<pre><code>Tries += 1
</code></pre>
<p>General comment: you could improve your code slightly:</p>
<pre><code>the_number = random.randrange(1,200,1)
tries = 1
guessed_number = int(i... | 2 | 2009-10-05T22:26:45Z | [
"python",
"ide",
"python-idle"
] |
Problem running a very simple Python program | 1,522,708 | <p>Why is my program giving me an error here?</p>
<pre><code>import random
TheNumber = random.randrange(1,200,1)
NotGuessed = True
Tries = 0
GuessedNumber = int(input("Take a guess at the magic number!: "))
while NotGuessed == True:
if GuessedNumber < TheNumber:
print("Your guess is ... | 1 | 2009-10-05T22:22:08Z | 1,522,727 | <p>In your last line, replace <code>string</code> with <code>str</code> -- that should take care of the error python is complaining about, at least.</p>
| 3 | 2009-10-05T22:27:15Z | [
"python",
"ide",
"python-idle"
] |
how to apply "catch-all" exception clause to complex python web-scraping script? | 1,522,823 | <p>I've got a list of 100 websites in CSV format. All of the sites have the same general format, including a large table with 7 columns. I wrote this script to extract the data from the 7th column of each of the websites and then write this data to file. The script below partially works, however: opening the output fi... | 0 | 2009-10-05T22:53:39Z | 1,522,837 | <p>I'd recommend reading the <a href="http://docs.python.org/tutorial/errors.html" rel="nofollow">Errors and Exceptions</a> Python documentation, especially section 8.3 -- Handling Exceptions.</p>
| 1 | 2009-10-05T22:58:21Z | [
"python",
"list",
"exception-handling",
"loops",
"urllib2"
] |
how to apply "catch-all" exception clause to complex python web-scraping script? | 1,522,823 | <p>I've got a list of 100 websites in CSV format. All of the sites have the same general format, including a large table with 7 columns. I wrote this script to extract the data from the 7th column of each of the websites and then write this data to file. The script below partially works, however: opening the output fi... | 0 | 2009-10-05T22:53:39Z | 1,522,890 | <p>Make the body of your <code>for</code> loop into:</p>
<pre><code>for url in urls:
try:
...the body you have now...
except Exception, e:
print>>sys.stderr, "Url %r not processed: error (%s) % (url, e)
</code></pre>
<p>(Or, use <code>logging.error</code> instead of the goofy <code>print>></co... | 2 | 2009-10-05T23:19:37Z | [
"python",
"list",
"exception-handling",
"loops",
"urllib2"
] |
flup/fastcgi cpu usage under no-load conditions | 1,522,844 | <p>I'm running Django as threaded fastcgi via flup, served by lighttpd, communicating via sockets.</p>
<p>What is the expected CPU usage for each fastcgi thread under no load? On startup, each thread runs at 3-4% cpu usage for a while, and then backs off to around .5% over the course of a couple of hours. It doesn't s... | 1 | 2009-10-05T23:02:18Z | 1,526,653 | <p>Your fast-cgi threads must not consume any (noticeable) CPU if there are no requests to process.</p>
<p>You should investigate the load you are describing. I use the same architecture and my threads are completely idle.</p>
| 0 | 2009-10-06T16:27:19Z | [
"python",
"django",
"fastcgi",
"lighttpd",
"flup"
] |
flup/fastcgi cpu usage under no-load conditions | 1,522,844 | <p>I'm running Django as threaded fastcgi via flup, served by lighttpd, communicating via sockets.</p>
<p>What is the expected CPU usage for each fastcgi thread under no load? On startup, each thread runs at 3-4% cpu usage for a while, and then backs off to around .5% over the course of a couple of hours. It doesn't s... | 1 | 2009-10-05T23:02:18Z | 1,531,138 | <p>I've looked at this on django running as fastcgi on both Slicehost (django 1.1, python 2.6) and Dreamhost (django 1.0, python 2.5), and I can say this:</p>
<p>Running the <code>top</code> command shows the processes use a large amount of CPU to start up for ~2-3 seconds, then drop down to 0 almost immediately.</p>
... | 2 | 2009-10-07T11:48:17Z | [
"python",
"django",
"fastcgi",
"lighttpd",
"flup"
] |
python: how do you setup your workspace on Ubuntu? | 1,522,867 | <p>Lets say I have my workspace (on Eclipse) where I develop my Python modules and I would like to "link" my working files to system Python paths. I know I can drop .pth files etc. but I would like to get the community's wisdom as to the best practices.</p>
| 3 | 2009-10-05T23:10:22Z | 1,523,307 | <p>One thing you can try is creating a <a href="http://pypi.python.org/pypi/virtualenv" rel="nofollow">virtual environment</a> and then pointing pydev at the interpreter inside the virtual environment.</p>
<pre><code>$ virtualenv --no-site-packages myProject
$ cd myProject
$ source bin/activate
(myproject)$
</code></p... | 1 | 2009-10-06T02:16:03Z | [
"python",
"eclipse"
] |
Update a gallery webpage via Dropbox? | 1,522,951 | <p>I'd like to know if the following situation and scripts are at all possible: </p>
<p>I'm looking to have a photo-gallery (Javascript) webpage that will display in order of the latest added to the Dropbox folder (PHP or Python?). </p>
<p>That is, when someone adds a picture to the Dropbox folder, there is a script ... | 2 | 2009-10-05T23:43:07Z | 1,927,690 | <p>You can try this : <a href="http://forums.dropbox.com/topic.php?id=15885" rel="nofollow">http://forums.dropbox.com/topic.php?id=15885</a></p>
| 1 | 2009-12-18T11:34:08Z | [
"php",
"python",
"html",
"dropbox"
] |
Update a gallery webpage via Dropbox? | 1,522,951 | <p>I'd like to know if the following situation and scripts are at all possible: </p>
<p>I'm looking to have a photo-gallery (Javascript) webpage that will display in order of the latest added to the Dropbox folder (PHP or Python?). </p>
<p>That is, when someone adds a picture to the Dropbox folder, there is a script ... | 2 | 2009-10-05T23:43:07Z | 2,074,899 | <p>If you can install the DropBox client on the webserver then it would be simple to let it sync your folder and then iterate over the contents of the folder with a programming language (PHP, Python, .NET etc) and produce the gallery page. This could be done every time the page is requested or as a scheduled job which... | 2 | 2010-01-15T21:25:28Z | [
"php",
"python",
"html",
"dropbox"
] |
Update a gallery webpage via Dropbox? | 1,522,951 | <p>I'd like to know if the following situation and scripts are at all possible: </p>
<p>I'm looking to have a photo-gallery (Javascript) webpage that will display in order of the latest added to the Dropbox folder (PHP or Python?). </p>
<p>That is, when someone adds a picture to the Dropbox folder, there is a script ... | 2 | 2009-10-05T23:43:07Z | 2,950,259 | <p>You can use the (alpha) tool <a href="http://github.com/berkes/autodrop" rel="nofollow">autodrop</a>, wich is just that: a simple gallery frontend that uses images in Dropbox.</p>
<p>As said: alpha. I am still developing it, rewriting it and making it a little prettier and nicer.
Written in Ruby, using dropbox, si... | 0 | 2010-06-01T13:45:20Z | [
"php",
"python",
"html",
"dropbox"
] |
Python: List comprehension to assign different values | 1,522,960 | <p>I'm making a 2D list and I would like to initialize it with a list comprehension. I would like it to do something like this:</p>
<pre><code>[[x for i in range(3) if j <= 1: x=1 else x=2] for j in range(3)]
</code></pre>
<p>so it should return something like:</p>
<pre><code>[[1,1,1],
[1,1,1],
[2,2,2]]
</code... | 7 | 2009-10-05T23:45:02Z | 1,522,973 | <p>It appears as though you're looking for something like this:</p>
<pre><code>[[1 if j <= 1 else 2 for i in range(3)] for j in range(3)]
</code></pre>
<p>The Python <a href="http://docs.python.org/reference/expressions.html#boolean-operations">conditional expression</a> is a bit different from what you might be u... | 14 | 2009-10-05T23:49:46Z | [
"python",
"list-comprehension"
] |
Python: List comprehension to assign different values | 1,522,960 | <p>I'm making a 2D list and I would like to initialize it with a list comprehension. I would like it to do something like this:</p>
<pre><code>[[x for i in range(3) if j <= 1: x=1 else x=2] for j in range(3)]
</code></pre>
<p>so it should return something like:</p>
<pre><code>[[1,1,1],
[1,1,1],
[2,2,2]]
</code... | 7 | 2009-10-05T23:45:02Z | 1,522,986 | <p>Greg's response is correct, though a much simpler and faster expression to produce your desired result would be</p>
<pre><code>[[j] * 3 for j in (1, 1, 2)]
</code></pre>
<p>i.e., remember that <code>for</code> need not apply to a <code>range</code> only;-), list-multiplication exists, and so on;-).</p>
| 14 | 2009-10-05T23:55:08Z | [
"python",
"list-comprehension"
] |
Python: List comprehension to assign different values | 1,522,960 | <p>I'm making a 2D list and I would like to initialize it with a list comprehension. I would like it to do something like this:</p>
<pre><code>[[x for i in range(3) if j <= 1: x=1 else x=2] for j in range(3)]
</code></pre>
<p>so it should return something like:</p>
<pre><code>[[1,1,1],
[1,1,1],
[2,2,2]]
</code... | 7 | 2009-10-05T23:45:02Z | 1,522,988 | <p>Try that</p>
<pre><code>>>> [[(1 if j<1 else 2) for i in range(3)] for j in range(3)]
[[1, 1, 1], [2, 2, 2], [2, 2, 2]]
</code></pre>
<p>The second time j=1 so j<1 fails </p>
| 1 | 2009-10-05T23:55:33Z | [
"python",
"list-comprehension"
] |
python sax: is there a way to halt the parsing from inside a content handler? | 1,523,225 | <p>Is there a way to halt the parsing from inside a content handler? Or is throwing an exception the only way?</p>
<p>Note that I am using <em>xml.sax.parseString</em>.</p>
| 3 | 2009-10-06T01:42:41Z | 1,523,600 | <p>The complete API for Python's SAX content handlers is documented <a href="http://docs.python.org/library/xml.sax.handler.html#contenthandler-objects" rel="nofollow">here</a>: as you can see, the information flow is entirely one-way, parser to handler -- no way for the handler to supply info back to the parser (such ... | 4 | 2009-10-06T04:32:39Z | [
"python",
"sax"
] |
How do I do this in Python? List to function | 1,523,348 | <pre><code>def getStuff(x):
return 'stuff'+x
def getData(x):
return 'data'+x
thefunctions = []
thefunctions.append("getStuff")
thefunctions.append("getData")
for i in thefunctions:
print i('abc')
</code></pre>
<p>Is this possible? Thank you.</p>
| 2 | 2009-10-06T02:43:50Z | 1,523,364 | <pre><code>thefunctions = [ getStuff, getData ]
for f in thefunctions:
print f('shazam')
</code></pre>
<p>Once you've done a <code>def</code> statement, you've associated a name with a function. Just use that name to refer to the function.</p>
| 12 | 2009-10-06T02:50:44Z | [
"python"
] |
Elegant way to skip first line when using python fileinput module? | 1,523,378 | <p>Is there an elegant way of skipping first line of file when using <code>python</code> fileinput module?</p>
<p>I have data file with nicely formated data but the first line is header. Using <code>fileinput</code> I would have to include check and discard line if the line does not seem to contain data.</p>
<p>The p... | 11 | 2009-10-06T02:57:43Z | 1,523,395 | <p>It's right in the docs: <a href="http://docs.python.org/library/fileinput.html#fileinput.isfirstline">http://docs.python.org/library/fileinput.html#fileinput.isfirstline</a></p>
| 5 | 2009-10-06T03:05:43Z | [
"python",
"file-io"
] |
Elegant way to skip first line when using python fileinput module? | 1,523,378 | <p>Is there an elegant way of skipping first line of file when using <code>python</code> fileinput module?</p>
<p>I have data file with nicely formated data but the first line is header. Using <code>fileinput</code> I would have to include check and discard line if the line does not seem to contain data.</p>
<p>The p... | 11 | 2009-10-06T02:57:43Z | 1,523,396 | <p>The <code>fileinput</code> module contains a bunch of handy functions, one of which seems to do exactly what you're looking for:</p>
<pre><code>for line in fileinput.input(["file.dat"]):
if not fileinput.isfirstline():
data = proces_line(line);
output(data)
</code></pre>
<p><a href="http://docs.python.or... | 15 | 2009-10-06T03:05:47Z | [
"python",
"file-io"
] |
Elegant way to skip first line when using python fileinput module? | 1,523,378 | <p>Is there an elegant way of skipping first line of file when using <code>python</code> fileinput module?</p>
<p>I have data file with nicely formated data but the first line is header. Using <code>fileinput</code> I would have to include check and discard line if the line does not seem to contain data.</p>
<p>The p... | 11 | 2009-10-06T02:57:43Z | 1,523,466 | <pre><code>lines = iter(fileinput.input(["file.dat"]))
next(lines) # extract and discard first line
for line in lines:
data = proces_line(line)
output(data)
</code></pre>
<p>or use the itertools.islice way if you prefer</p>
<pre><code>import itertools
finput = fileinput.input(["file.dat"])
lines = itertools.i... | 14 | 2009-10-06T03:39:03Z | [
"python",
"file-io"
] |
What is the common header format of Python files? | 1,523,427 | <p>I came across the following header format for Python source files in a document about Python coding guidelines:</p>
<pre><code>#!/usr/bin/env python
"""Foobar.py: Description of what foobar does."""
__author__ = "Barack Obama"
__copyright__ = "Copyright 2009, Planet Earth"
</code></pre>
<p>Is this the sta... | 270 | 2009-10-06T03:23:14Z | 1,523,435 | <p>Here's a good place to start: <a href="http://www.python.org/dev/peps/pep-0257/">PEP 257</a>, which talks about Docstrings, and links to several other relevant documents.</p>
| 15 | 2009-10-06T03:25:12Z | [
"python",
"header",
"comments"
] |
What is the common header format of Python files? | 1,523,427 | <p>I came across the following header format for Python source files in a document about Python coding guidelines:</p>
<pre><code>#!/usr/bin/env python
"""Foobar.py: Description of what foobar does."""
__author__ = "Barack Obama"
__copyright__ = "Copyright 2009, Planet Earth"
</code></pre>
<p>Is this the sta... | 270 | 2009-10-06T03:23:14Z | 1,523,456 | <p>Its all metadata for the <code>Foobar</code> module.</p>
<p>The first one is the <code>docstring</code> of the module, that is already explained in <a href="http://stackoverflow.com/questions/1523427/python-what-is-the-common-header-format/1523435#1523435">Peter's answer</a>.</p>
<blockquote>
<h2><a href="http:/... | 323 | 2009-10-06T03:34:00Z | [
"python",
"header",
"comments"
] |
What is the common header format of Python files? | 1,523,427 | <p>I came across the following header format for Python source files in a document about Python coding guidelines:</p>
<pre><code>#!/usr/bin/env python
"""Foobar.py: Description of what foobar does."""
__author__ = "Barack Obama"
__copyright__ = "Copyright 2009, Planet Earth"
</code></pre>
<p>Is this the sta... | 270 | 2009-10-06T03:23:14Z | 1,523,621 | <p>Also see <a href="http://www.python.org/dev/peps/pep-0263/">PEP 263</a> if you are using a non-ascii characterset</p>
<blockquote>
<h2>Abstract</h2>
<p>This PEP proposes to introduce a syntax to declare the encoding of
a Python source file. The encoding information is then used by the
Python pars... | 12 | 2009-10-06T04:39:28Z | [
"python",
"header",
"comments"
] |
What is the common header format of Python files? | 1,523,427 | <p>I came across the following header format for Python source files in a document about Python coding guidelines:</p>
<pre><code>#!/usr/bin/env python
"""Foobar.py: Description of what foobar does."""
__author__ = "Barack Obama"
__copyright__ = "Copyright 2009, Planet Earth"
</code></pre>
<p>Is this the sta... | 270 | 2009-10-06T03:23:14Z | 9,225,336 | <p>I strongly favour minimal file headers, by which I mean just:</p>
<ul>
<li>The hashbang (<code>#!</code> line) if this is an executable script</li>
<li>Module docstring</li>
<li>Imports, grouped as described in <strong>voyager</strong>âs answer.</li>
</ul>
<p>Everything else is a waste of time, visual space, and... | 85 | 2012-02-10T09:13:33Z | [
"python",
"header",
"comments"
] |
Binary numbers in Python | 1,523,465 | <p>How can I add, subtract, and compare binary numbers in Python without converting to decimal?</p>
| 34 | 2009-10-06T03:37:55Z | 1,523,477 | <p>Binary, decimal, hexadecimal... the base only matters when reading or outputting numbers, adding binary numbers is just the same as adding decimal number : it is just a matter of representation.</p>
| 3 | 2009-10-06T03:44:26Z | [
"python",
"binary"
] |
Binary numbers in Python | 1,523,465 | <p>How can I add, subtract, and compare binary numbers in Python without converting to decimal?</p>
| 34 | 2009-10-06T03:37:55Z | 1,523,478 | <p>I think you're confused about what binary is. Binary and decimal are just different representations of a number - e.g. 101 base 2 and 5 base 10 are the same number. The operations add, subtract, and compare operate on numbers - 101 base 2 == 5 base 10 and addition is the same logical operation no matter what base ... | 9 | 2009-10-06T03:44:47Z | [
"python",
"binary"
] |
Binary numbers in Python | 1,523,465 | <p>How can I add, subtract, and compare binary numbers in Python without converting to decimal?</p>
| 34 | 2009-10-06T03:37:55Z | 1,523,514 | <p>If you're talking about bitwise operators, then you're after:</p>
<pre><code>~ Not
^ XOR
| Or
& And
</code></pre>
<p>Otherwise, binary numbers work exactly the same as decimal numbers, because numbers are numbers, no matter how you look at them. The only difference between decimal and binary is how we represen... | 5 | 2009-10-06T03:54:33Z | [
"python",
"binary"
] |
Binary numbers in Python | 1,523,465 | <p>How can I add, subtract, and compare binary numbers in Python without converting to decimal?</p>
| 34 | 2009-10-06T03:37:55Z | 1,523,581 | <p>You can convert between a string representation of the binary using bin() and int()</p>
<pre><code>>>> bin(88)
'0b1011000'
>>> int('0b1011000', 2)
88
>>>
>>> a=int('01100000', 2)
>>> b=int('00100110', 2)
>>> bin(a & b)
'0b100000'
>>> bin(a | b)
'0... | 65 | 2009-10-06T04:19:28Z | [
"python",
"binary"
] |
Binary numbers in Python | 1,523,465 | <p>How can I add, subtract, and compare binary numbers in Python without converting to decimal?</p>
| 34 | 2009-10-06T03:37:55Z | 33,672,372 | <p>I think you're confused about what binary is. Binary and decimal are just different representations of a number - e.g. 101 base 2 and 5 base 10 are the same number. The operations add, subtract, and compare operate on numbers - 101 base 2 == 5 base 10 and addition is the same logical operation no matter what base yo... | -4 | 2015-11-12T13:19:29Z | [
"python",
"binary"
] |
Binary numbers in Python | 1,523,465 | <p>How can I add, subtract, and compare binary numbers in Python without converting to decimal?</p>
| 34 | 2009-10-06T03:37:55Z | 37,560,399 | <p>Not sure if helpful, but I leave my solution here:</p>
<pre><code>class Solution:
# @param A : string
# @param B : string
# @return a strings
def addBinary(self, A, B):
num1 = bin(int(A, 2))
num2 = bin(int(B, 2))
bin_str = bin(int(num1, 2)+int(num2, 2))
b_index = bin_... | 0 | 2016-06-01T05:49:03Z | [
"python",
"binary"
] |
.vimrc configuration for Python | 1,523,482 | <p>My current .vimrc configuration is below:</p>
<pre><code>set nohlsearch
set ai
set bg=dark
set showmatch
highlight SpecialKey ctermfg=DarkGray
set listchars=tab:>-,trail:~
set list
autocmd BufRead *.py set smartindent cinwords=if,elif,else,for,while,try,except,finally,def,class
set tabstop=4
set shiftwidth=4
set... | 18 | 2009-10-06T03:45:54Z | 1,523,512 | <p>The short answer is that your autocmd is missing the BufEnter trigger, so it isn't being fired when you create a new file. Try this instead:</p>
<pre><code> au BufEnter,BufRead *.py setlocal smartindent cinwords=if,elif,else,for,while,try,except,finally,def,class
</code></pre>
<p>Note that I also changed the <code... | 12 | 2009-10-06T03:54:16Z | [
"python",
"vim"
] |
.vimrc configuration for Python | 1,523,482 | <p>My current .vimrc configuration is below:</p>
<pre><code>set nohlsearch
set ai
set bg=dark
set showmatch
highlight SpecialKey ctermfg=DarkGray
set listchars=tab:>-,trail:~
set list
autocmd BufRead *.py set smartindent cinwords=if,elif,else,for,while,try,except,finally,def,class
set tabstop=4
set shiftwidth=4
set... | 18 | 2009-10-06T03:45:54Z | 1,523,519 | <p>Try this:</p>
<pre><code>filetype indent on
filetype on
filetype plugin on
</code></pre>
<p>I primarily do Python programming and this is the brunt of my vimrc</p>
<pre><code>set nobackup
set nowritebackup
set noswapfile
set lines=40
set columns=80
set tabstop=4
set shiftwidth=4
set softtabstop=4
set autoindent
s... | 13 | 2009-10-06T03:56:30Z | [
"python",
"vim"
] |
.vimrc configuration for Python | 1,523,482 | <p>My current .vimrc configuration is below:</p>
<pre><code>set nohlsearch
set ai
set bg=dark
set showmatch
highlight SpecialKey ctermfg=DarkGray
set listchars=tab:>-,trail:~
set list
autocmd BufRead *.py set smartindent cinwords=if,elif,else,for,while,try,except,finally,def,class
set tabstop=4
set shiftwidth=4
set... | 18 | 2009-10-06T03:45:54Z | 1,524,853 | <p>You shouldn't have to explicitly indent python keywords. The $VIM/indent/python.vim file takes care of that. You just need to turn on filetype indent and autoindent. </p>
| 4 | 2009-10-06T10:46:42Z | [
"python",
"vim"
] |
.vimrc configuration for Python | 1,523,482 | <p>My current .vimrc configuration is below:</p>
<pre><code>set nohlsearch
set ai
set bg=dark
set showmatch
highlight SpecialKey ctermfg=DarkGray
set listchars=tab:>-,trail:~
set list
autocmd BufRead *.py set smartindent cinwords=if,elif,else,for,while,try,except,finally,def,class
set tabstop=4
set shiftwidth=4
set... | 18 | 2009-10-06T03:45:54Z | 9,606,530 | <p>Consider having a look at the official .vimrc for following PEP 7 & 8 conventions. Present over here</p>
<p><a href="http://svn.python.org/projects/python/trunk/Misc/Vim/vimrc" rel="nofollow">http://svn.python.org/projects/python/trunk/Misc/Vim/vimrc</a></p>
| 2 | 2012-03-07T17:44:16Z | [
"python",
"vim"
] |
.vimrc configuration for Python | 1,523,482 | <p>My current .vimrc configuration is below:</p>
<pre><code>set nohlsearch
set ai
set bg=dark
set showmatch
highlight SpecialKey ctermfg=DarkGray
set listchars=tab:>-,trail:~
set list
autocmd BufRead *.py set smartindent cinwords=if,elif,else,for,while,try,except,finally,def,class
set tabstop=4
set shiftwidth=4
set... | 18 | 2009-10-06T03:45:54Z | 17,102,397 | <p>I (simply) use this:</p>
<pre><code>set shiftwidth=4
set tabstop=4
set expandtab
filetype plugin on
filetype indent on
syntax on
</code></pre>
| 3 | 2013-06-14T06:29:46Z | [
"python",
"vim"
] |
Python module search path problem | 1,523,551 | <p>I am trying to work on a dev environment but am find problems in that python seems to be using modules from the site-packages directory. I want it to be using the modules from my dev directory.</p>
<p>sys.path returns a bunch of dirs, like this</p>
<pre><code>['', '/usr/lib/python26.zip', '/usr/lib/python2.6', '/u... | 2 | 2009-10-06T04:06:18Z | 1,523,624 | <p>You mention that there's a <code>foo</code> directory under your current directory, but you don't tell us whether <code>foo/__init__.py</code> exists (even possibly empty): if it doesn't, this tells Python that <code>foo</code> is <strong>not</strong> a package. Similarly for <code>foo/bar/__init__.py</code> -- if ... | 3 | 2009-10-06T04:40:06Z | [
"python",
"search",
"path",
"module"
] |
Python module search path problem | 1,523,551 | <p>I am trying to work on a dev environment but am find problems in that python seems to be using modules from the site-packages directory. I want it to be using the modules from my dev directory.</p>
<p>sys.path returns a bunch of dirs, like this</p>
<pre><code>['', '/usr/lib/python26.zip', '/usr/lib/python2.6', '/u... | 2 | 2009-10-06T04:06:18Z | 1,524,108 | <p>What is foo doing in /usr/lib/python2.6/site-packages?
It sounds like you have created foo in your local directory but that is not necessarily the one you are importing.</p>
<p>Try getting rid of the foo/bar in site-packages</p>
<p>Make sure your directory structure looks like this</p>
<pre><code>/foo/__init__.py... | 0 | 2009-10-06T07:39:04Z | [
"python",
"search",
"path",
"module"
] |
BioPython: Skipping over bad GIDs with Entrez.esummary/Entrez.read | 1,523,571 | <p>Sorry about the odd title.</p>
<p>I am using eSearch & eSummary to go from </p>
<p>Accession Number --> gID --> TaxID</p>
<p>Assume that 'accessions' is a list of 20 accession numbers (I do 20 at a time because that's the maximum that NCBI will allow).</p>
<p>I do:</p>
<pre><code>handle = Entrez.esearch(db=... | 3 | 2009-10-06T04:15:15Z | 1,523,590 | <p>I'd have a look at Parser.py and see what is being parsed. It looks like you are getting a result from the NCBI ok, but the format of one record is tripping up the parser.</p>
<p>It may be possible to subclass/monkeypatch the parser to get it past the exception.</p>
| 0 | 2009-10-06T04:24:01Z | [
"python",
"bioinformatics",
"biopython"
] |
BioPython: Skipping over bad GIDs with Entrez.esummary/Entrez.read | 1,523,571 | <p>Sorry about the odd title.</p>
<p>I am using eSearch & eSummary to go from </p>
<p>Accession Number --> gID --> TaxID</p>
<p>Assume that 'accessions' is a list of 20 accession numbers (I do 20 at a time because that's the maximum that NCBI will allow).</p>
<p>I do:</p>
<pre><code>handle = Entrez.esearch(db=... | 3 | 2009-10-06T04:15:15Z | 1,531,787 | <p>I sent a message out to the BioPython mailing list.Apparently it's a bug & they're working on it.</p>
| 3 | 2009-10-07T13:52:55Z | [
"python",
"bioinformatics",
"biopython"
] |
redirect() Not Actually Redirecting (Routes for Pylons) | 1,523,613 | <p>I am constructing a table of routes in my Pylons app. I can't get redirect() to work the way that it should work. I'm not sure what I'm doing wrong. </p>
<p>Here is an example of redirect() usage from the <a href="http://routes.groovie.org/manual.html#redirect-routes" rel="nofollow">Routes documentation</a>:</p>... | 1 | 2009-10-06T04:36:54Z | 1,526,917 | <p>That syntax works, so there must be something else going on.</p>
<p>Routes is sensitive to order. Is there another route above the redirect that would match <code>/view</code> to a controller that would return a 404?</p>
<p>Routes is also sensitive to trailing slashes. Did you accidentally type a trailing slash in... | 1 | 2009-10-06T17:16:19Z | [
"python",
"routes",
"pylons"
] |
How to disable URL redirection in Python when using M2Crypto SSL? | 1,523,654 | <p>This is what my code looks like:</p>
<pre><code>url_object = urlparse(url)
hostname = url_object.hostname
port = url_object.port
uri = url_object.path if url_object.path else '/'
ctx = SSL.Context()
if ctx.load_verify_locations(cafile='ca-bundle.crt') != 1: raise Exception("Could not load CA certificates.")
ctx.se... | 0 | 2009-10-06T04:52:37Z | 1,526,647 | <p>httpslib.HTTPSConnection does not redirect automatically. Like Lennart says in the comment, it subclasses from httplib.HTTPConnection which does not redirect either. It is easy to test with httplib:</p>
<pre><code>import httplib
c = httplib.HTTPConnection('www.heikkitoivonen.net', 80)
c.request('GET', '/deadwinter... | 0 | 2009-10-06T16:25:22Z | [
"python",
"url",
"redirect",
"m2crypto"
] |
How to print a list in Python "nicely" | 1,523,660 | <p>In PHP, I can do this:</p>
<pre><code>echo '<pre>'
print_r($array);
echo '</pre>'
</code></pre>
<p>In Python, I currently just do this:</p>
<pre><code>print the_list
</code></pre>
<p>However, this will cause a big jumbo of data. Is there any way to print it nicely into a readable tree? (with indents)... | 20 | 2009-10-06T04:55:40Z | 1,523,664 | <pre><code>from pprint import pprint
pprint(the_list)
</code></pre>
| 47 | 2009-10-06T04:57:49Z | [
"python"
] |
How to print a list in Python "nicely" | 1,523,660 | <p>In PHP, I can do this:</p>
<pre><code>echo '<pre>'
print_r($array);
echo '</pre>'
</code></pre>
<p>In Python, I currently just do this:</p>
<pre><code>print the_list
</code></pre>
<p>However, this will cause a big jumbo of data. Is there any way to print it nicely into a readable tree? (with indents)... | 20 | 2009-10-06T04:55:40Z | 1,523,674 | <p>You mean something like...:</p>
<pre><code>>>> print L
['this', 'is', 'a', ['and', 'a', 'sublist', 'too'], 'list', 'including', 'many', 'words', 'in', 'it']
>>> import pprint
>>> pprint.pprint(L)
['this',
'is',
'a',
['and', 'a', 'sublist', 'too'],
'list',
'including',
'many',
'word... | 16 | 2009-10-06T05:02:42Z | [
"python"
] |
How to print a list in Python "nicely" | 1,523,660 | <p>In PHP, I can do this:</p>
<pre><code>echo '<pre>'
print_r($array);
echo '</pre>'
</code></pre>
<p>In Python, I currently just do this:</p>
<pre><code>print the_list
</code></pre>
<p>However, this will cause a big jumbo of data. Is there any way to print it nicely into a readable tree? (with indents)... | 20 | 2009-10-06T04:55:40Z | 28,928,248 | <p>A quick hack while debugging that works without having to import <code>pprint</code> would be to join the list on <code>'\n'</code>.</p>
<pre><code>>>> lst = ['foo', 'bar', 'spam', 'egg']
>>> print '\n'.join(lst)
foo
bar
spam
egg
</code></pre>
| 4 | 2015-03-08T15:35:46Z | [
"python"
] |
How to print a list in Python "nicely" | 1,523,660 | <p>In PHP, I can do this:</p>
<pre><code>echo '<pre>'
print_r($array);
echo '</pre>'
</code></pre>
<p>In Python, I currently just do this:</p>
<pre><code>print the_list
</code></pre>
<p>However, this will cause a big jumbo of data. Is there any way to print it nicely into a readable tree? (with indents)... | 20 | 2009-10-06T04:55:40Z | 34,240,753 | <p><a href="https://docs.python.org/3/library/pprint.html" rel="nofollow">https://docs.python.org/3/library/pprint.html</a></p>
<p>If you need the text (for using with curses for example):</p>
<pre><code>import pprint
myObject = []
myText = pprint.pformat(myObject)
</code></pre>
<p>Then <code>myText</code> variabl... | 1 | 2015-12-12T14:08:13Z | [
"python"
] |
How to print a list in Python "nicely" | 1,523,660 | <p>In PHP, I can do this:</p>
<pre><code>echo '<pre>'
print_r($array);
echo '</pre>'
</code></pre>
<p>In Python, I currently just do this:</p>
<pre><code>print the_list
</code></pre>
<p>However, this will cause a big jumbo of data. Is there any way to print it nicely into a readable tree? (with indents)... | 20 | 2009-10-06T04:55:40Z | 35,211,376 | <p>Simply by "unpacking" the list in the print function argument and using a newline (\n) as separator.</p>
<p><strong>print(*lst, sep='\n')</strong></p>
<pre><code>lst = ['foo', 'bar', 'spam', 'egg']
print(*lst, sep='\n')
foo
bar
spam
egg
</code></pre>
| 0 | 2016-02-04T20:51:11Z | [
"python"
] |
An ALGORITHM to create one list from "X" nested lists in Python | 1,523,675 | <p>What is the simplest way to create this list in Python?</p>
<p>First, suppose I have this nested list:</p>
<pre><code>oldList = [ [{'letter':'a'}], [{'letter':'b'}], [{'letter':'c'}] ]
</code></pre>
<p>I want a function to spit out:</p>
<pre><code>newList = [ {'letter':a}, {'letter':'b'}, {'letter':'c'} ]
</code... | 0 | 2009-10-06T05:03:39Z | 1,523,693 | <p><a href="http://www.daniel-lemire.com/blog/archives/2006/05/10/flattening-lists-in-python/" rel="nofollow">http://www.daniel-lemire.com/blog/archives/2006/05/10/flattening-lists-in-python/</a></p>
<p>from that link (with a couple minor changes:</p>
<pre><code>def flatten(l):
if isinstance(l, list):
return s... | 2 | 2009-10-06T05:07:30Z | [
"python"
] |
An ALGORITHM to create one list from "X" nested lists in Python | 1,523,675 | <p>What is the simplest way to create this list in Python?</p>
<p>First, suppose I have this nested list:</p>
<pre><code>oldList = [ [{'letter':'a'}], [{'letter':'b'}], [{'letter':'c'}] ]
</code></pre>
<p>I want a function to spit out:</p>
<pre><code>newList = [ {'letter':a}, {'letter':'b'}, {'letter':'c'} ]
</code... | 0 | 2009-10-06T05:03:39Z | 1,523,711 | <p>The <a href="http://oreilly.com/catalog/9780596007973" rel="nofollow"><strong>Python Cookbook</strong></a> Martelli, Ravenscroft and Asher 2005 O'Reilley also offers a solution to this flattening problem.<br>
See <em>4.6 Flattening a nested sequence.</em><br>
This solution uses generators which can be a good thing i... | 0 | 2009-10-06T05:15:57Z | [
"python"
] |
An ALGORITHM to create one list from "X" nested lists in Python | 1,523,675 | <p>What is the simplest way to create this list in Python?</p>
<p>First, suppose I have this nested list:</p>
<pre><code>oldList = [ [{'letter':'a'}], [{'letter':'b'}], [{'letter':'c'}] ]
</code></pre>
<p>I want a function to spit out:</p>
<pre><code>newList = [ {'letter':a}, {'letter':'b'}, {'letter':'c'} ]
</code... | 0 | 2009-10-06T05:03:39Z | 1,523,726 | <p>Recursive solutions are simplest, but limited to at most a few thousand levels of nesting before you get an exception about too-deep recursion. For real generality, you can eliminate recursion by keeping your own stack; iterators are good things to keep on said stack, and the whole function's best written as a gener... | 4 | 2009-10-06T05:20:18Z | [
"python"
] |
An ALGORITHM to create one list from "X" nested lists in Python | 1,523,675 | <p>What is the simplest way to create this list in Python?</p>
<p>First, suppose I have this nested list:</p>
<pre><code>oldList = [ [{'letter':'a'}], [{'letter':'b'}], [{'letter':'c'}] ]
</code></pre>
<p>I want a function to spit out:</p>
<pre><code>newList = [ {'letter':a}, {'letter':'b'}, {'letter':'c'} ]
</code... | 0 | 2009-10-06T05:03:39Z | 1,523,978 | <p>I prefer Alex Martelli's post as usual. Just want to add a not recommended trick: </p>
<pre><code>from Tkinter import _flatten
print _flatten(oldList)
</code></pre>
| 0 | 2009-10-06T06:51:19Z | [
"python"
] |
An ALGORITHM to create one list from "X" nested lists in Python | 1,523,675 | <p>What is the simplest way to create this list in Python?</p>
<p>First, suppose I have this nested list:</p>
<pre><code>oldList = [ [{'letter':'a'}], [{'letter':'b'}], [{'letter':'c'}] ]
</code></pre>
<p>I want a function to spit out:</p>
<pre><code>newList = [ {'letter':a}, {'letter':'b'}, {'letter':'c'} ]
</code... | 0 | 2009-10-06T05:03:39Z | 1,524,950 | <p>The simplest answer is this</p>
<p><strong>Only you can prevent nested lists</strong></p>
<p>Do not create a list of lists using <code>append</code>. Create a flat list using <code>extend</code>. </p>
| 1 | 2009-10-06T11:06:42Z | [
"python"
] |
Werkzeug in General, and in Python 3.1 | 1,523,706 | <p>I've been looking really hard at all of the way**(s)** one can develop web applications using Python. For reference, we are using RHEL 64bit, apache, mod_wsgi.</p>
<p><strong>History:</strong></p>
<ol>
<li>PHP + MySQL <sup>years ago</sup></li>
<li>PHP + Python 2.x + MySQL <sup>recently and current</sup></li>
<li>... | 2 | 2009-10-06T05:13:48Z | 1,523,934 | <p>I haven't used Werkzeug, so I can only answer question 2:</p>
<p>No, Werkzeug does not work on Python 3. In fact, very little works on Python 3 as of today. Porting is not difficult, but you can't port until all your third-party libraries have been ported, so progress is slow.</p>
<p>One big stopper has been setup... | 1 | 2009-10-06T06:36:32Z | [
"python",
"python-3.x",
"werkzeug"
] |
Werkzeug in General, and in Python 3.1 | 1,523,706 | <p>I've been looking really hard at all of the way**(s)** one can develop web applications using Python. For reference, we are using RHEL 64bit, apache, mod_wsgi.</p>
<p><strong>History:</strong></p>
<ol>
<li>PHP + MySQL <sup>years ago</sup></li>
<li>PHP + Python 2.x + MySQL <sup>recently and current</sup></li>
<li>... | 2 | 2009-10-06T05:13:48Z | 1,525,943 | <p>mod_wsgi for Python 3.x is also not ready. There is no satisfactory definition of WSGI for Python 3.x yet; the WEB-SIG are still bashing out the issues. mod_wsgi targets a guess at what might be in it, but there are very likely to be changes to both the spec and to standard libraries. Any web application you write t... | 3 | 2009-10-06T14:29:19Z | [
"python",
"python-3.x",
"werkzeug"
] |
Werkzeug in General, and in Python 3.1 | 1,523,706 | <p>I've been looking really hard at all of the way**(s)** one can develop web applications using Python. For reference, we are using RHEL 64bit, apache, mod_wsgi.</p>
<p><strong>History:</strong></p>
<ol>
<li>PHP + MySQL <sup>years ago</sup></li>
<li>PHP + Python 2.x + MySQL <sup>recently and current</sup></li>
<li>... | 2 | 2009-10-06T05:13:48Z | 1,622,505 | <p>I can only answer question one:</p>
<p>I started using it for some small webstuff but now moved on to rework larger apps with it. Why Werkzeug? The modular concept is really helpful. You can hook in modules as you like, make stuff easily context aware and you get good request file handling for free which is able to... | 1 | 2009-10-25T23:45:30Z | [
"python",
"python-3.x",
"werkzeug"
] |
Reasons to use distutils when packaging C/Python project | 1,523,874 | <p>I have an open source project containing both Python and C code. I'm wondering that is there any use for distutils for me, because I'm planning to do a ubuntu/debian package. The C code is not something that I could or want to use as Python extension. C and Python programs communicate with TCP/IP through localhost.<... | 0 | 2009-10-06T06:17:53Z | 1,523,993 | <p>distutils can be used to install end user programs, but it's most useful when using it for Python libraries, as it can create source packages and also install them in the correct place. For that I would say it's more or less required.</p>
<p>But for an end user Python program you can also use make or whatever you l... | 1 | 2009-10-06T06:56:02Z | [
"python",
"c",
"packaging",
"distutils"
] |
Reasons to use distutils when packaging C/Python project | 1,523,874 | <p>I have an open source project containing both Python and C code. I'm wondering that is there any use for distutils for me, because I'm planning to do a ubuntu/debian package. The C code is not something that I could or want to use as Python extension. C and Python programs communicate with TCP/IP through localhost.<... | 0 | 2009-10-06T06:17:53Z | 1,525,194 | <p>Because it uses an unified <code>python setup.py install</code> command? distutils, or setuptools? Whatever, just use one of those.</p>
<p>For development, it's also really useful because you don't have to care where to find such and such dependency. As long as it's standard Python/basic system library stuff, <code... | 1 | 2009-10-06T12:07:21Z | [
"python",
"c",
"packaging",
"distutils"
] |
Convert a decimal matrix to a binary matrix in SciPy | 1,524,023 | <p>Suppose I have a integer matrix which represents who has emailed whom and how many times. For social network analysis I'd like to make a simple undirected graph. So I need to convert the matrix to binary matrix and later into a list of tuples.</p>
<p>My question: is there a fast, convenient way to reduce the decima... | 1 | 2009-10-06T07:03:42Z | 1,524,039 | <p>Apply the <code>scipy.sign</code> function to every cell in the matrix.</p>
<p>[EDIT] Cudos to <a href="http://stackoverflow.com/users/39584/speciousfool">speciousfool</a>:</p>
<p>If <code>x</code> is your matrix then <code>scipy.sign(x)</code> gives you the binary matrix.</p>
| 2 | 2009-10-06T07:14:19Z | [
"python",
"scipy"
] |
Convert a decimal matrix to a binary matrix in SciPy | 1,524,023 | <p>Suppose I have a integer matrix which represents who has emailed whom and how many times. For social network analysis I'd like to make a simple undirected graph. So I need to convert the matrix to binary matrix and later into a list of tuples.</p>
<p>My question: is there a fast, convenient way to reduce the decima... | 1 | 2009-10-06T07:03:42Z | 1,524,261 | <p>You can do the following:</p>
<pre><code>>>> import scipy
>>> a = scipy.array((12, 0, -1, 23, 0))
array([12, 0, -1, 23, 0])
>>> (a != 0).astype(int)
array([1, 0, 1, 1, 0])
</code></pre>
<p>The magic is in the <code>a != 0</code> part. You can apply boolean expressions to arrays and it ... | 2 | 2009-10-06T08:20:03Z | [
"python",
"scipy"
] |
Convert a decimal matrix to a binary matrix in SciPy | 1,524,023 | <p>Suppose I have a integer matrix which represents who has emailed whom and how many times. For social network analysis I'd like to make a simple undirected graph. So I need to convert the matrix to binary matrix and later into a list of tuples.</p>
<p>My question: is there a fast, convenient way to reduce the decima... | 1 | 2009-10-06T07:03:42Z | 8,470,103 | <p>You can also try this:</p>
<pre><code>>>>x,y = scipy.where(yourMatrix>0)
>>>yourMatrix[:,:] = 0
>>>yourMatrix[x,y] = 1
</code></pre>
<p>i guess this will also be faster.</p>
| 0 | 2011-12-12T04:55:14Z | [
"python",
"scipy"
] |
How to print a list more nicely? | 1,524,126 | <p>This is similar to <a href="http://stackoverflow.com/questions/1523660/how-to-print-a-list-in-python-nicely">How to print a list in Python ânicelyâ</a>, but I would like to print the list even more nicely -- without the brackets and apostrophes and commas, and even better in columns.</p>
<pre><code>foolist = ['... | 6 | 2009-10-06T07:43:58Z | 1,524,132 | <p>Simple:</p>
<pre><code>l = ['exiv2-devel', 'mingw-libs', 'tcltk-demos', 'fcgi', 'netcdf',
'pdcurses-devel', 'msvcrt', 'gdal-grass', 'iconv', 'qgis-devel',
'qgis1.1', 'php_mapscript']
if len(l) % 2 != 0:
l.append(" ")
split = len(l)/2
l1 = l[0:split]
l2 = l[split:]
for key, value in zip(l1,l2):
... | 8 | 2009-10-06T07:45:33Z | [
"python",
"printing"
] |
How to print a list more nicely? | 1,524,126 | <p>This is similar to <a href="http://stackoverflow.com/questions/1523660/how-to-print-a-list-in-python-nicely">How to print a list in Python ânicelyâ</a>, but I would like to print the list even more nicely -- without the brackets and apostrophes and commas, and even better in columns.</p>
<pre><code>foolist = ['... | 6 | 2009-10-06T07:43:58Z | 1,524,225 | <p>If the data is in the format you have provided, it is a little more work</p>
<pre><code>
>>> d = ['exiv2-devel', 'mingw-libs', 'tcltk-demos', 'fcgi', 'netcdf',
... 'pdcurses-devel', 'msvcrt', 'gdal-grass', 'iconv', 'qgis-devel',
... 'qgis1.1', 'php_mapscript']
>>> print "\n".join("%-20s %s"%(d[i],d[i+... | 2 | 2009-10-06T08:10:07Z | [
"python",
"printing"
] |
How to print a list more nicely? | 1,524,126 | <p>This is similar to <a href="http://stackoverflow.com/questions/1523660/how-to-print-a-list-in-python-nicely">How to print a list in Python ânicelyâ</a>, but I would like to print the list even more nicely -- without the brackets and apostrophes and commas, and even better in columns.</p>
<pre><code>foolist = ['... | 6 | 2009-10-06T07:43:58Z | 1,524,333 | <p>See <a href="http://stackoverflow.com/questions/171662/formatting-a-list-of-text-into-columns">formatting-a-list-of-text-into-columns</a>, </p>
<p>A general solution, handles any number of columns and odd lists.
Tab characters separate columns, using generator expressions to save space.</p>
<pre><code>def fmtcols(... | 4 | 2009-10-06T08:40:54Z | [
"python",
"printing"
] |
How to print a list more nicely? | 1,524,126 | <p>This is similar to <a href="http://stackoverflow.com/questions/1523660/how-to-print-a-list-in-python-nicely">How to print a list in Python ânicelyâ</a>, but I would like to print the list even more nicely -- without the brackets and apostrophes and commas, and even better in columns.</p>
<pre><code>foolist = ['... | 6 | 2009-10-06T07:43:58Z | 1,524,335 | <p>The way Aaron has done it can work with more than two colums</p>
<pre><code>
>>> l = ['exiv2-devel', 'mingw-libs', 'tcltk-demos', 'fcgi', 'netcdf',
... 'pdcurses-devel', 'msvcrt', 'gdal-grass', 'iconv', 'qgis-devel',
... 'qgis1.1', 'php_mapscript']
>>> cols = 4
>>> split=[l[i:i+len(l)/cols] for i in r... | 5 | 2009-10-06T08:41:10Z | [
"python",
"printing"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.