FAQ

# Python>python-list>February 2012

## 270 discussions - 1,442 posts

• 111

#### Python usage numbers

Does anyone have (or know of) accurate totals and percentages on how Python is used? I'm particularly interested in the following groupings: - new development vs. stable code-bases - categories (web, ...
 Eric SnowFeb 11, 2012 at 9:02 pmFeb 26, 2012 at 10:32 pm
• 40

#### PyWart: Language missing maximum constant of numeric types!

I get sick and tired of doing this!!! if maxlength == UNLIMITED: allow_passage() elif len(string) maxlength: deny_passage() What Python needs is some constant that can be compared to ANY numeric type ...
 Rick JohnsonFeb 24, 2012 at 1:37 pmFeb 27, 2012 at 12:25 pm
• 28

#### Is it necessary to call Tk() when writing a GUI app with Tkinter?

The book I'm reading about using Tkinter only does this when creating the top-level window: app = Application() app.mainloop() and of course the Application class has subclassed the tkinter.Frame ...
 John SalernoFeb 29, 2012 at 5:06 amMar 5, 2012 at 7:45 pm
• 25

#### New Science Discovery: Perl Idiots Remain Idiots After A Decade!New Science Discovery: Perl Idiots Remain Idiots After A Decade!

New Science Discovery: Perl Idiots Remain Idiots After A Decade! A excerpt from the new book ?Modern Perl?, just published, chapter 4 on ?Operators?. Quote: ?The associativity of an operator governs ...
 Xah LeeFeb 29, 2012 at 8:09 amMar 12, 2012 at 8:20 pm
• 25

#### Python math is off by .000000000000045

-60.950000000000045 That's wrong. Proof http://www.wolframalpha.com/input/?i00.00-1041.00-555.74%2B530.74-794.95 -60.95 aka (-(1219/20)) Is there a reason Python math is only approximated? - Or is ...
 Alec TaylorFeb 22, 2012 at 6:13 pmFeb 28, 2012 at 5:56 pm
• 24

#### [semi OT]: Smartphones and Python?

First of all: I don't have any first hand experience of smartphones but now that my trusted old GSM phone is getting old I decided I am in for an up-grade. It struck me it might be nice to get ...
 Martin SchöönFeb 15, 2012 at 8:58 pmFeb 27, 2012 at 1:44 pm
• 24

#### frozendict

Hi all, I've been trying for a few days (only a little bit at a time) to come up with a way of implementing a frozendict that doesn't suck. I'm gradually converging to a solution, but I can't help ...
 Evan DriscollFeb 9, 2012 at 1:23 amFeb 13, 2012 at 9:15 pm
• 20

#### PyCrypto builds neither with MSVC nor MinGW

PIL, PyCrypto and many other modules require a C compiler and linker. Unfortunately neither install on my computer, with a PATH with the following: C:\Program Files (x86)\Microsoft Visual Studio ...
 Alec TaylorFeb 5, 2012 at 2:40 pmAug 22, 2012 at 6:39 pm
• 19

Hi I am new to python language. On my first day, somebody told me that if any python script file is opened with any editor except python editor, the file is corrupted. Some spacing or indentation is ...
 Manish SharmaFeb 23, 2012 at 10:13 pmFeb 25, 2012 at 2:36 am
• 19

#### sum() requires number, not simply __add__

I feel like the design of sum() is inconsistent with other language features of python. Often python doesn't require a specific type, only that the type implement certain methods. Given a class that ...
 Buck GolemonFeb 23, 2012 at 9:19 pmFeb 24, 2012 at 9:58 pm
• 19

#### changing sys.path

So suppose I want to modify the sys.path on the fly before running some code which imports from one of the modules added. at run time I do sys.path.extend(paths_to_add) but it still doesn't work and ...
 Andrea CrottiFeb 1, 2012 at 4:15 pmFeb 10, 2012 at 8:58 pm
• 18

I am learning python and maybe this is obvious but I have not been able to see a solution. What I would like to do is to be able to execute a function within the namespace I would have obtained with ...
 OliveFeb 1, 2012 at 5:11 pmFeb 2, 2012 at 12:34 am
• 16

#### ANN: Sarge, a library wrapping the subprocess module, has been released.

Sarge, a cross-platform library which wraps the subprocess module in the standard library, has been released. What does it do? ---------------- Sarge tries to make interfacing with external programs ...
 Vinay SajipFeb 10, 2012 at 7:28 pmFeb 17, 2012 at 5:29 pm
• 16

#### round down to nearest number

How do you round down ALWAYS to nearest 100? Like, if I have number 3268, I want that rounded down to 3200. I'm doing my rounding like But, how to round DOWN?
 NoydbFeb 10, 2012 at 12:30 amFeb 11, 2012 at 10:26 am
• 15

#### Common LISP-style closures with Python

In Python textbooks that I have read, it is usually not mentioned that we can very easily program Common LISP-style closures with Python. It is done as follows: ------------------------------------- ...
 Antti J YlikoskiFeb 4, 2012 at 12:27 amFeb 10, 2012 at 7:55 am
• 15

#### iterating over list with one mising value

Hello experts, I am having trouble accessing the content of my list. my list content has 2-pair value with the exception of one which has single value. here is an example? ['a', 1, 'b', 1, 'c', 3, ...
 Sammy DansoFeb 7, 2012 at 12:27 pmFeb 8, 2012 at 1:50 am
• 14

#### A quirk/gotcha of for i, x in enumerate(seq) when seq is empty

This week I was slightly surprised by a behaviour that I've not considered before. I've long used for i, x in enumerate(seq): # do stuff as a standard looping-with-index construct. In Python for ...
 Alex WillmerFeb 24, 2012 at 12:30 amFeb 29, 2012 at 12:18 am
• 14

#### Iterate from 2nd element of a huge list

Hi! What is the best way to iterate thru a huge list having the 1st element a different process? I.e.: process1(mylist[0]) for el in mylist[1:]: process2(el) This way mylist is almost duplicated, ...
 Paulo da SilvaFeb 1, 2012 at 1:39 amFeb 2, 2012 at 7:38 am
• 13

#### Python as a default shell, replacement of bash, sh, cmd ?

Has it been considered to add shell features to python, such that it can be used as a default shell, as a replacement for bash, etc. I'm sure everyone would agree that doing this would make the ...
 SherjilOzairFeb 18, 2012 at 6:58 pmFeb 22, 2012 at 10:15 pm
• 13

#### Numeric root-finding in Python

This is only peripherally a Python problem, but in case anyone has any good ideas I'm going to ask it. I have a routine to calculate an approximation of Lambert's W function, and then apply a ...
 Steven D'ApranoFeb 12, 2012 at 6:41 amFeb 21, 2012 at 2:21 am
• 13

#### Cycle around a sequence

I'm looking at a way of cycling around a sequence i.e. starting at some given location in the middle of a sequence and running to the end before coming back to the beginning and running to the start ...
 Mark LawrenceFeb 8, 2012 at 1:10 amFeb 9, 2012 at 10:34 am
• 13

#### difference between random module in python 2.6 and 3.2?

Hi, I have this working function: def as_xml(self): out = etree.Element("or") for k in sorted(self.keys()): out.append(etree.Element("hostname", attrib={'op': '=', 'value': random.choice(self[k])})) ...
 Matej CeplFeb 6, 2012 at 1:27 amFeb 7, 2012 at 3:11 pm
• 12

Hi all I seem to have a recurring battle with circular imports, and I am trying to nail it once and for all. Let me say at the outset that I don't think I can get rid of circular imports altogether. ...
 Frank MillmanFeb 26, 2012 at 10:42 amFeb 28, 2012 at 5:58 pm
• 12

#### name of a sorting algorithm

Hi, Could someone please tell me what the following sorting algorithm is called? Let an array contain the elements a_1, a_2, ..., a_N. Then: for i = 1 to N-1: for j = i+1 to N: if a_j < a_i then ...
 Jabba LaciFeb 14, 2012 at 3:01 pmFeb 14, 2012 at 8:59 pm
• 12

#### SnakeScript? (CoffeeScript for Python)

Hello, I've been looking for something similar to CoffeeScript, but for python. Does anyone know of such project? So far I haven't found any attempt to do this, so I took few regular expressions and ...
 Michal HantlFeb 2, 2012 at 2:09 pmFeb 7, 2012 at 3:52 am
• 11

#### Listing children processes

I'm trying to compute the total CPU load of an external process and it's children. (so I cannot use resource.getrusage) For the load of the process I can just grab it from /proc/X/stat. How do I get ...
 Mihai BadoiuFeb 28, 2012 at 6:33 pmFeb 29, 2012 at 6:09 pm
• 11

Hi, I'm implementing Python 3 extension using the Python C API. I am familiar with defining new types, implementing get/set for attributes, etc. I'm wondering, is there any mean to implement ...
 Mateusz LoskotFeb 9, 2012 at 11:43 amFeb 13, 2012 at 11:57 am
• 10

#### namespace question

c = [1, 2, 3, 4, 5] class TEST(): c = [5, 2, 3, 4, 5] def add( self ): c[0] = 15 a = TEST() a.add() print( c, a.c, TEST.c ) result : [15, 2, 3, 4, 5] [5, 2, 3, 4, 5] [5, 2, 3, 4, 5] why a.add() do ...
 XixiliguoFeb 24, 2012 at 5:55 amFeb 28, 2012 at 2:06 pm
• 10

I want to download content asynchronously. This would be straightforward to do threaded or across processes, but difficult asynchronously so people seem to rely on external libraries (twisted / ...
 PlumoFeb 23, 2012 at 6:58 amFeb 25, 2012 at 9:44 pm
• 10

#### format a measurement result and its error in "scientific" way

Hi folks, often times in science one expresses a value (say 1.03789291) and its error (say 0.00089) in a short way by parentheses like so: 1.0379(9) One can vary things a bit, but let's take the ...
 Daniel FetchinsonFeb 16, 2012 at 12:18 amFeb 17, 2012 at 12:13 pm
• 10

#### Script randomly exits for seemingly no reason with strange traceback

It's a rare occurrence, but sometimes my script will terminate and I get this: Traceback (most recent call last): File "C:\path\to\script\script.py", line 992, in <module That's it. And the line ...
 Andrew BergFeb 3, 2012 at 8:14 pmFeb 15, 2012 at 9:41 pm
• 10

#### Guide to: Learning Python Decorators

Guide to: Learning Python Decorators New Book http://tinyurl.com/python-decorartor
 SajuptpmFeb 9, 2012 at 5:56 pmFeb 12, 2012 at 11:48 am
• 10

#### Reading files in from the proper directory

Hello. I am admittedly a Python novice, and ran into some trouble trying to write a program that will pull multiple excel files all into one file, with each file on a different sheet. I am confident ...
 SMac2347Feb 7, 2012 at 6:14 pmFeb 9, 2012 at 9:07 pm
• 9

#### [RELEASED] Release candidates for Python 2.6.8, 2.7.3, 3.1.5, and 3.2.3

We're pleased to announce the immediate availability of release candidates for Python 2.6.8, 2.7.3, 3.1.5, and 3.2.3 . The main impetus for these releases is fixing a security issue in Python's hash ...
 Benjamin PetersonFeb 25, 2012 at 5:56 pmFeb 27, 2012 at 9:30 pm
• 9

#### generate Windows exe on Linux

hello, I have a python script using only the standard libraries. Currently I use a Windows VM to generate exe's, which is cumbersome. Has anyone had success generating exe's from within Linux? Richard
 PlumoFeb 22, 2012 at 12:12 pmFeb 26, 2012 at 11:57 am
• 9

$cd /usr/bin$ ls -l python* -rwxr-xr-x 2 root root 9496 Oct 27 02:42 python lrwxrwxrwx 1 root root 6 Oct 29 19:34 python2 - python -rwxr-xr-x 2 root root 9496 Oct 27 02:42 python2.7 $diff -s ...  HoneyMonsterFeb 23, 2012 at 7:11 pmFeb 24, 2012 at 5:22 pm • 9 #### log and figure out what bits are slow and optimize them. Hi, I want to log time taken to complete database requests inside a method/ function using decorator . is it possible ???? I think, i have to inject log code inside the method/fuctions or modify it. ...  SajuptpmFeb 10, 2012 at 12:30 pmFeb 11, 2012 at 7:53 am • 9 #### multiple namespaces within a single module? Hello there is it possible to have multiple namespaces within a single python module? I have a small app which is in three or four .py files. For various reasons I would like to (perhaps optionally) ...  JknFeb 9, 2012 at 6:32 pmFeb 10, 2012 at 4:28 pm • 9 #### Naming convention for in-house modules (Newbie question) I am quite new to Python (2.7 on Linux), and have built a few modules using wxPython/wxGlade for GUI elements and Psycopg2 for database access. I adhere mostly to the PEP8 guidelines, and use Pylint ...  HoneyMonsterFeb 8, 2012 at 5:15 pmFeb 9, 2012 at 9:57 pm • 8 #### Complexity question on Python 3 lists What is the cost of calling primes(n) below ? I'm mainly interested in knowing if the call to append is O(1), even amortized. Do lists in Python 3 behave like ArrayList in Java (if the capacity is ...  Franck DitterFeb 15, 2012 at 6:20 pmFeb 16, 2012 at 12:41 am • 8 #### re module: Nothing to repeat, but no sre_constants.error: nothing to repeat ? Hey Pythonistas, Consider the regular expression "$*". Compilation fails with the exception, "sre_constants.error: nothing to repeat". Consider the regular expression "(?=\$)*". As far as I know it is ...
 Devin JeanpierreFeb 14, 2012 at 4:38 amFeb 15, 2012 at 1:43 pm
• 8

#### Formate a number with commas

How do you format a number to print with commas? Some quick searching, i came up with: '2,348,721' I'm a perpetual novice, so just looking for better, slicker, more proper, pythonic ways to do this. ...
 NoydbFeb 9, 2012 at 8:08 pmFeb 10, 2012 at 3:06 am
• 7

#### multiprocessing, what am I doing wrong?

Below is some pretty simple code and the resulting output. Sometimes the code runs through but sometimes it just freezes for no apparent reason. The output pasted is where it just got frozen on me. ...
 Eric FrederichFeb 23, 2012 at 5:59 pmFeb 28, 2012 at 6:12 pm
• 7

#### xlrd 0.7.2 released!

Hi All, I'm pleased to announce the release of xlrd 0.7.2. This release, like the xlwt release, is long overdue and has been over 2.5 years in the making! The highlights: - All messaging and debug ...
 Chris WithersFeb 21, 2012 at 9:17 amFeb 23, 2012 at 5:28 pm
• 7

#### XSLT to Python script conversion?

Hi, I am getting more and more discouraged from using XSLT for a transformation from one XML scheme to another one. Does anybody could share any experience with porting moderately complicated XSLT ...
 Matej CeplFeb 13, 2012 at 11:20 amFeb 17, 2012 at 9:11 pm
• 7

#### Is this the right list?

Hey folks, I looked all through the list of mailing lists on the mail.python.orgserver and this seems to be the only one that might apply to me other than maybe the German list which did not seem to ...
 Alan McKayFeb 15, 2012 at 9:51 pmFeb 16, 2012 at 4:29 pm
• 7

#### atexit.register in case of errors

I have the following very simplified situation from atexit import register def goodbye(): print("saying goodbye") def main(): while True: var = raw_input("read something") if __name__ == '__main__': ...
 Andrea CrottiFeb 15, 2012 at 1:12 pmFeb 15, 2012 at 9:31 pm
• 7

#### how to tell a method is classmethod or static method or instance method

how to tell a method is class method or static method or instance method?
 Zheng LiFeb 13, 2012 at 6:59 amFeb 15, 2012 at 6:31 pm
• 7

#### how to read serial stream of data [newbie]

I'd like to read in a stream of data which looks like this: the device sends out a byte-string of 11 bytes roughly every second: B0B0B0B0B03131B0B50D8A B0B0B0B0B03131B0B50D8A B0B0B031B63131B0310D8A ...
 Jean DupontFeb 6, 2012 at 9:40 pmFeb 7, 2012 at 5:44 pm
• 7

#### xhtml encoding question

I hope you are aware that this is about the slowest possible algorithm (well, the slowest one that doesn't do anything unnecessary). Since none of this is required when parsing or generating XHTML, I ...
 Stefan BehnelFeb 1, 2012 at 8:26 amFeb 2, 2012 at 12:40 pm