Re: programming by evolution?

2009-02-05 Thread Xah Lee
looking at the eXtreme Programing fuckheads's traffic history: http://groups.google.com/group/comp.software.extreme-programming/about for those who are not aware, it was one of the snake oil wildly popular in around 2001. Xah ∑ http://xahlee.org/ ☄ Jason wrote: I just started reading OnLisp

Re: is python Object oriented??

2009-02-05 Thread Bruno Desthuilliers
thmpsn@gmail.com a écrit : On Feb 4, 3:11 am, Bruno Desthuilliers wrote: thmpsn@gmail.com a écrit : On Feb 3, 1:14 am, David Cournapeau wrote: (snip) after all, we have used FILE* for years and I have no idea about the FILE structure. Your lack of knowledge about it doesn't mean

Re: Using while loop and if statement to tell if a binary has an odd or even number of 1's.

2009-02-05 Thread Mark Dickinson
On Feb 5, 1:18 am, Chris Rebert wrote: > For an integer: > is_even = bin(the_int)[2:].count('1') % 2 == 0 But the OP has to use if and while. How about: while 2+2 != 5: if 'wkw' in 'just being awkward': is_even = bin(the_int)[2:].count('1') % 2 == 0 break or (Python 2.5 com

global name 'sqrt' is not defined

2009-02-05 Thread Nick Matzke
Hi all, So, I can run this in the ipython shell just fine: === a = ["12", "15", "16", "38.2"] dim = int(sqrt(size(a))) dim >2 === But if I move these commands to a function in another file, it freaks out: = a = distances_matrix.split('\t') fro

Re: Use list name as string

2009-02-05 Thread Tino Wildenhain
Hi, Vincent Davis wrote: Sorry for not being clear I would have something like this x = [1, 2, 3,5 ,6 ,9,234] Then def savedata(dataname): .. savedata(x) this would save a to a file called x.csv This is my problem, getting the name to be x.csv which is the same as the name of the lis

Re: global name 'sqrt' is not defined

2009-02-05 Thread Chris Rebert
On Thu, Feb 5, 2009 at 1:08 AM, Nick Matzke wrote: > Hi all, > > So, I can run this in the ipython shell just fine: > > === > a = ["12", "15", "16", "38.2"] > dim = int(sqrt(size(a))) sqrt() is not a builtin function, it's located in the 'math' module. You must have imported it at some po

RE: How to find wxPython method documentation??

2009-02-05 Thread Barak, Ron
Hi Len, First off, there's the wxPython mailing list (To subscribe or unsubscribe via the World Wide Web, visit http://lists.wxwidgets.org/mailman/listinfo/wxpython-users or, via email, send a message with subject or body 'help' to wxpython-users-requ...@lists.wxwidgets.org) I also find Google

Re: time: Daylight savings confusion

2009-02-05 Thread Matt Nordhoff
Tim H wrote: > On Win XP 64bit, Python 2.6.1 64bit > > I am trying to rename files by their creation time. > > It seems the time module is too smart for its own good here. > > time.localtime(os.path.getctime(f)) returns a value one hour off from > what windows reports for files that were created

Re: Comparing two book chapters (text files)

2009-02-05 Thread andrew cooke
On Feb 4, 10:20 pm, Nick Matzke wrote: > So I have an interesting challenge.  I want to compare two book > chapters, which I have in plain text format, and find out (a) percentage > similarity and (b) what has changed. no idea if it will help, but i found this yesterday - http://www.nltk.org/ it

Re: How do i add body to email.mime.multipart.MIMEMultipart instance?

2009-02-05 Thread Justin Ezequiel
On Feb 4, 2:48 pm, srinivasan srinivas wrote: > Hi, > Could someone tell me the way to add body to the instance > email.mime.multipart.MIMEMultipart instance which has attachments? > > Thanks, msg = MIMEMultipart() msg.preamble = 'This is a multi-part message in MIME format.\n' msg.epilogue = ''

Re: sys.float_info.epsilon

2009-02-05 Thread Mark Dickinson
On Feb 4, 9:44 pm, Tim Rowe wrote: > That just leaves me puzzled as to why Mark Summerfield used it instead > of a check against zero on user input. No idea: you'd have to ask Mark Summerfield. If there's an email address published in his book, I'm sure he wouldn't object to the question. > So

Ordered dict by default

2009-02-05 Thread bearophileHUGS
Choosing the right data structure is usually a matter of compromises, and sometimes the best you can do is to change some data structures and look for the faster running time. To do this it helps to have a language that allows you to swap data structures in the more transparent way possible. It's

Re: Use list name as string

2009-02-05 Thread Tino Wildenhain
Hendrik van Rooyen wrote: > "MRAB" wrote: > >> The actual names of the variables and functions shouldn't matter to the >> outside world; the name of an output file shouldn't depend on the name >> of a variable. > > That is a matter of opinion. > It is however, an interesting problem, namely: > >

Re: Using while loop and if statement to tell if a binary has an odd or even number of 1's.

2009-02-05 Thread Tim Rowe
2009/2/5 Duncan Booth : > Mark Dickinson wrote: > >> def count_set_bits(n): >> # make sure we include an if, to >> # satisfy OP's requirements: >> if n < 0: >> raise ValueError >> count = 0 >> while n: >> count += 1 >> n &= n-1 >> return count >> >>

Re: Comparing two book chapters (text files)

2009-02-05 Thread Tino Wildenhain
andrew cooke wrote: On Feb 4, 10:20 pm, Nick Matzke wrote: So I have an interesting challenge. I want to compare two book chapters, which I have in plain text format, and find out (a) percentage similarity and (b) what has changed. no idea if it will help, but i found this yesterday - http:/

Re: Ordered dict by default

2009-02-05 Thread Steve Holden
bearophileh...@lycos.com wrote: [a somewhat feeble case for ordered dicts] > Once the default dicts are ordered, it can be possible to add an > unordereddict to the collections module to be used by programmers when > max performance or low memory usage is very important :-) > I have no real idea w

Re: Ordered dict by default

2009-02-05 Thread Paul Rubin
Steve Holden writes: > In mathematics mappings aren't ordered either, and a pure dict is pretty > much a mapping. So leave them alone, they are fine as they are! Ehhh, an ordered dict has to support a comparison operation on the keys, while a Python dict has to support a hashing operation on them

Re: parse date/time from a log entry with only strftime (and no regexen)

2009-02-05 Thread Simon Mullis
That, my friend, is ingenious...! Thankyou SM 2009/2/3 andrew cooke > > > ValueError: unconverted data remains: this is the remainder of the log > > > > line > > > that I do not care about > > you could catch the ValueError and split at the ':' in the .args > attribute to find the extra data.

Should "open(sys.stdin)" and "open(file, 'r')" be equivalent?

2009-02-05 Thread Simon Mullis
Hi All I've written a simple python script that accepts both stdin and a glob (or at least, that is the plan). Unfortunately, the glob part seems to hang when it's looped through to the end of the filehandle. And I have no idea why... ;-) sys.stdin and a normal file opened with "open" seem to bo

Re: Ordered dict by default

2009-02-05 Thread Duncan Booth
Paul Rubin wrote: > bearophileh...@lycos.com writes: >> Now Ruby dicts are ordered by default: >> http://www.igvita.com/2009/02/04/ruby-19-internals-ordered-hash/ > > Maybe I didn't read that carefully enough, but it looks like "ordered" > means the dict records com

Re: Understanding descriptors

2009-02-05 Thread Bruno Desthuilliers
Brian Allen Vanderburg II a écrit : I'm trying to better understand descriptors and I've got a few questions still after reading some sites. Here is what I 'think', but please let me know if any of this is wrong as I'm sure it probably is. First when accessing an attribute on a class or inst

Python 3.0 slow file IO

2009-02-05 Thread thomasvang...@gmail.com
I just recently learned python, I'm using it mainly to process huge <5GB txt files of ASCII information about DNA. I've decided to learn 3.0, but maybe I need to step back to 2.6? I'm getting exceedingly frustrated by the slow file IO behaviour of python 3.0. I know that a bug-report was submitted

Re: Ordered dict by default

2009-02-05 Thread Paul Rubin
Duncan Booth writes: > If you want to write doctests then any stable order in the default dict > type would be helpful no matter whether it means that keys are in original > insertion or latest insertion order or sorted. Just use "sorted" in the test code: >>> print sorted(dict((a**2,a) for a

Re: Python 3.0 slow file IO

2009-02-05 Thread Ulrich Eckhardt
thomasvang...@gmail.com wrote: > C:\python30> patch -p0 < fileio_buffer.patch > The patch command is not recognized.. You need the 'patch' program first. Further, you will need a C compiler. If you don't know how to compile from sources, I would postpone patching sources to after learning that. >

Re: Using while loop and if statement to tell if a binary has an odd or even number of 1's.

2009-02-05 Thread Tim Rowe
2009/2/5 Duncan Booth : >>> I remember a programming exercise when I was an undergraduate and >>> anyone who *didn't* use that trick got marked down for writing >>> inefficient code. >> >> Is adding and a modulus *really^ more efficient than flipping a bool >> as I suggested? I think I'd want to s

Re: JDBC in CPYTHON

2009-02-05 Thread M.-A. Lemburg
On 2009-02-05 03:49, KMCB wrote: > Thanks Simon and Marc, > > I currently have an app on OSX that I wanted to migrate to NIX, it > uses a ODBC DBAPI interface to communicate with Filemaker. > Unfortunately, FMP does not support linux drivers. They do have a > JDBC driver that looks like it may wo

Re: Using while loop and if statement to tell if a binary has an odd or even number of 1's.

2009-02-05 Thread Duncan Booth
Tim Rowe wrote: > 2009/2/5 Duncan Booth : >> Mark Dickinson wrote: >> >>> def count_set_bits(n): >>> # make sure we include an if, to >>> # satisfy OP's requirements: >>> if n < 0: >>> raise ValueError >>> count = 0 >>> while n: >>> count += 1 >>> n &=

Re: Using while loop and if statement to tell if a binary has an odd or even number of 1's.

2009-02-05 Thread Duncan Booth
Mark Dickinson wrote: > def count_set_bits(n): > # make sure we include an if, to > # satisfy OP's requirements: > if n < 0: > raise ValueError > count = 0 > while n: > count += 1 > n &= n-1 > return count > > is_even = count_set_bits(the_int) % 2

Re: string replace for back slash

2009-02-05 Thread Chris Rebert
On Thu, Feb 5, 2009 at 3:40 AM, S.Selvam Siva wrote: > Hi all, > > I tried to do a string replace as follows, > s="hi & people" s.replace("&","\&") > 'hi \\& people' > > but i was expecting 'hi \& people'.I dont know ,what is something different > here with escape sequence. The Pyt

Re: Comparing two book chapters (text files)

2009-02-05 Thread M.-A. Lemburg
On 2009-02-05 02:20, Nick Matzke wrote: > Hi all, > > So I have an interesting challenge. I want to compare two book > chapters, which I have in plain text format, and find out (a) percentage > similarity and (b) what has changed. > > Some features make this problem different than what seems to

Re: global name 'sqrt' is not defined

2009-02-05 Thread M.-A. Lemburg
On 2009-02-05 10:08, Nick Matzke wrote: > Hi all, > > So, I can run this in the ipython shell just fine: > > === > a = ["12", "15", "16", "38.2"] > dim = int(sqrt(size(a))) > > dim >>2 > === > > > But if I move these commands to a function in another file, it freaks out: You n

Re: Understanding descriptors

2009-02-05 Thread Brian Allen Vanderburg II
bruno.42.desthuilli...@websiteburo.invalid wrote: So the lookup chain is: 1/ lookup the class and bases for a binding descriptor 2/ then lookup the instance's __dict__ 3/ then lookup the class and bases for a non-binding descriptor or plain attribute 4/ then class __getattr__ Also and FWIW,

Re: Ordered dict by default

2009-02-05 Thread Duncan Booth
Paul Rubin wrote: > Duncan Booth writes: >> If you want to write doctests then any stable order in the default >> dict type would be helpful no matter whether it means that keys are >> in original insertion or latest insertion order or sorted. > > Just use "sorted"

string replace for back slash

2009-02-05 Thread S.Selvam Siva
Hi all, I tried to do a string replace as follows, >>> s="hi & people" >>> s.replace("&","\&") 'hi \\& people' >>> but i was expecting 'hi \& people'.I dont know ,what is something different here with escape sequence. -- Yours, S.Selvam -- http://mail.python.org/mailman/listinfo/python-list

Re: Python 3.0 slow file IO

2009-02-05 Thread Christian Heimes
thomasvang...@gmail.com schrieb: > I just recently learned python, I'm using it mainly to process huge > <5GB txt files of ASCII information about DNA. I've decided to learn > 3.0, but maybe I need to step back to 2.6? > > I'm getting exceedingly frustrated by the slow file IO behaviour of > pytho

string replace for back slash

2009-02-05 Thread rdmurray
"S.Selvam Siva" wrote: > I tried to do a string replace as follows, > > >>> s="hi & people" > >>> s.replace("&","\&") > 'hi \\& people' > >>> > > but i was expecting 'hi \& people'.I dont know ,what is something different > here with escape sequence. You are running into the difference between

Re: Should "open(sys.stdin)" and "open(file, 'r')" be equivalent?

2009-02-05 Thread Simon Mullis
Hi Chris 2009/2/5 Chris Rebert > > I'd add some print()s in the above loop (and also the 'for f in files' > loop) to make sure the part of the code you didn't want to share ("do > stuff with the line") works correctly, and that nothing is improperly > looping in some unexpected way. The point is

Re: Should "open(sys.stdin)" and "open(file, 'r')" be equivalent?

2009-02-05 Thread Chris Rebert
On Thu, Feb 5, 2009 at 2:58 AM, Simon Mullis wrote: > Hi All > > I've written a simple python script that accepts both stdin and a glob (or > at least, that is the plan). > Unfortunately, the glob part seems to hang when it's looped through to the > end of the filehandle. > > And I have no idea wh

Re: x64 speed

2009-02-05 Thread Robin Becker
Martin v. Löwis wrote: Is it the x64 working faster at its design sizes Another guess (still from the darkness of not having received the slightest clue what the test actually does): if it creates integers in range(2**32, 2**64), then they fit into a Python int on AMD64-Linux, but require a Pyt

Arguments for map'ped functions

2009-02-05 Thread mk
Hello everyone, So I have this function I want to map onto a list of sequences of *several* arguments (while I would want to pass those arguments to each function in the normal fashion). I realize this is contrived, maybe an example would make this clear: params = [ ('comp.lang.python', ['rt

Re: Ordered dict by default

2009-02-05 Thread andrew cooke
so what is happening with pep 372? http://www.python.org/dev/peps/pep-0372/ -- http://mail.python.org/mailman/listinfo/python-list

Re: x64 speed

2009-02-05 Thread Robin Becker
... -- Ran 193 tests in 27.841s OK real0m28.150s user0m26.606s sys 0m0.917s [rpt...@localhost tests]$ magical how the total python time is less than the real time. time(1) also measures the Python startup and

python 3 error i know the file works in python 2.6

2009-02-05 Thread garywood
can someone help me please #open file and read last names filename = input('name file') file = open(filename, 'r') names_list = file.readlines() file.close() #open a file for saving passwords outfile_name = input('Save passwords') outfile = open(outfile_name, 'a') #create a password for each n

Re: Arguments for map'ped functions

2009-02-05 Thread Peter Otten
mk wrote: > So I have this function I want to map onto a list of sequences of > *several* arguments (while I would want to pass those arguments to each > function in the normal fashion). I realize this is contrived, maybe an You can either use a list comprehension [f(*args) for args in seq] or

[SOLVED] Re: Should "open(sys.stdin)" and "open(file, 'r')" be equivalent?

2009-02-05 Thread Simon Mullis
Forget it all... I was being very very daft! The "default = 'False'" in the options for stdin was not being evaluated as I thought, so the script was waiting for stdin even when there was the glob switch was used...No stdin equals the script seeming to "hang". Ah well. SM -- http://mail.python.o

Flattening lists

2009-02-05 Thread mk
Hello everybody, Any better solution than this? def flatten(x): res = [] for el in x: if isinstance(el,list): res.extend(flatten(el)) else: res.append(el) return res a = [1, 2, 3, [4, 5, 6], [[7, 8], [9, 10]]] print flatten(a) [1, 2, 3, 4, 5

Re: Ordered dict by default

2009-02-05 Thread Christian Heimes
andrew cooke schrieb: > so what is happening with pep 372? > > http://www.python.org/dev/peps/pep-0372/ It's still a draft and hasn't been implemented yet. Now is the time to get it ready for Python 3.1 and 2.7. Christian -- http://mail.python.org/mailman/listinfo/python-list

Re: Python 3.0 slow file IO

2009-02-05 Thread rdmurray
Quoth Christian Heimes : > thomasvang...@gmail.com schrieb: > > I just recently learned python, I'm using it mainly to process huge > > <5GB txt files of ASCII information about DNA. I've decided to learn > > 3.0, but maybe I need to step back to 2.6? > > > > I'm getting exceedingly frustrated by

RE: python 3 error i know the file works in python 2.6

2009-02-05 Thread Andreas Tawn
>#open file and read last names >filename = input('name file') >file = open(filename, 'r') >names_list = file.readlines() >file.close() >#open a file for saving passwords >outfile_name = input('Save passwords') >outfile = open(outfile_name, 'a') > > >#create a password for each name in list >import

Re: Should "open(sys.stdin)" and "open(file, 'r')" be equivalent?

2009-02-05 Thread Simon Mullis
Last try at getting the indenting to appear correctly.. #!/usr/bin/env python import glob, os, sys class TestParse(object): def __init__(self): if options.stdin: self.scan_data(sys.stdin) if options.glob: self.files = glob.glob(options.glob)

Re: Flattening lists

2009-02-05 Thread Brian Allen Vanderburg II
mrk...@gmail.com wrote: Hello everybody, Any better solution than this? def flatten(x): res = [] for el in x: if isinstance(el,list): res.extend(flatten(el)) else: res.append(el) return res a = [1, 2, 3, [4, 5, 6], [[7, 8], [9, 10]]] print fl

Re: Ordered dict by default

2009-02-05 Thread Paul Rubin
bearophileh...@lycos.com writes: > Now Ruby dicts are ordered by default: > http://www.igvita.com/2009/02/04/ruby-19-internals-ordered-hash/ Maybe I didn't read that carefully enough, but it looks like "ordered" means the dict records come out in the same order you inserted them in. That is if yo

Re: How to find wxPython method documentation??

2009-02-05 Thread Egon Frerich
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 The documentation is here: http://www.wxpython.org/onlinedocs.php In "Alphabetical class reference" you can find for example wxButton with its methods. Yes - there is no function 'SetBackgroundColour'. But there is a list with classes from which wxB

Re: string replace for back slash

2009-02-05 Thread S.Selvam Siva
On Thu, Feb 5, 2009 at 5:59 PM, wrote: > "S.Selvam Siva" wrote: > > I tried to do a string replace as follows, > > > > >>> s="hi & people" > > >>> s.replace("&","\&") > > 'hi \\& people' > > >>> > > > > but i was expecting 'hi \& people'.I dont know ,what is something > different > > here with e

os.system issues

2009-02-05 Thread Youri Lammers
Ok, I want to run a program called 'muscle' with my python script, muscle uses the following command: 'muscle.exe -in filename -out filename' so far I got: import os args = ['-in filename', '-out filename'] os.system('E:\Programs\muscle\muscle.exe args') However, when I run this nothing happ

Re: How to find wxPython method documentation??

2009-02-05 Thread Mike Driscoll
On Feb 4, 5:49 pm, andrew cooke wrote: > On Feb 4, 8:06 pm, len wrote: > > > How does one find the methods that are available in the classes. > > heh.  welcome to the wonderful world of wxpython :o( > > if you use eclipse to edit your code, then (providing the wind is in > the right direction and

Re: How to find wxPython method documentation??

2009-02-05 Thread Mike Driscoll
On Feb 4, 5:06 pm, len wrote: > Hi > > I am going through the "wxPython in Action" book by Noel Rappin and > Robin Dunn. > > I have been typing in the example programs as I go and play with > modifing the code. > Thought I should start trying to find my way around the documentation > found on the

Re: Flattening lists

2009-02-05 Thread mk
Brian Allen Vanderburg II wrote: >> def flatten(x): >> res = [] >> for el in x: >> if isinstance(el,list): >> res.extend(flatten(el)) >> else: >> res.append(el) >> return res > > I think it may be just a 'little' more efficient to do this: > > d

Re: os.system issues

2009-02-05 Thread Christian Heimes
Youri Lammers schrieb: > Ok, > > I want to run a program called 'muscle' with my python script, > muscle uses the following command: > 'muscle.exe -in filename -out filename' > so far I got: > > import os > args = ['-in filename', '-out filename'] > os.system('E:\Programs\muscle\muscle.exe args

os.system issues

2009-02-05 Thread rdmurray
Youri Lammers writes: > I want to run a program called 'muscle' with my python script=2C > muscle uses the following command: > 'muscle.exe -in filename -out filename' > so far I got: > > import os > args = ['-in filename', '-out filename'] > os.system('E:\Programs\muscle\muscle.exe args') > > H

Re: Flattening lists

2009-02-05 Thread Baolong zhen
less list creation. On Thu, Feb 5, 2009 at 10:17 PM, mk wrote: > Brian Allen Vanderburg II wrote: > >> def flatten(x): > >> res = [] > >> for el in x: > >> if isinstance(el,list): > >> res.extend(flatten(el)) > >> else: > >> res.append(el) > >>

Re: Flattening lists

2009-02-05 Thread mk
Brian Allen Vanderburg II wrote: def flatten(x): res = [] for el in x: if isinstance(el,list): res.extend(flatten(el)) else: res.append(el) return res I think it may be just a 'little' more efficient to do this: def flatten(x, res=None):

Re: Flattening lists

2009-02-05 Thread Shane Geiger
These functions come from goopy: def flatten1(seq): """ Return a list with the contents of SEQ with sub-lists and tuples "exploded". This is only done one-level deep. """ lst = [] for x in seq: if type(x) is list or type(x) is tuple: for val in x: lst.append(val) else:

Re: os.system issues

2009-02-05 Thread Grant Edwards
On 2009-02-05, Christian Heimes wrote: > Youri Lammers schrieb: >> Ok, >> >> I want to run a program called 'muscle' with my python script, >> muscle uses the following command: >> 'muscle.exe -in filename -out filename' >> so far I got: >> >> import os >> args = ['-in filename', '-out filenam

Cheetah and hungarian charset...

2009-02-05 Thread durumdara
Hi! I wanna ask that have anyone some exp. with Cheetah and the non-ascii chars? I have a site. The html template documents are saved in ansi format, psp liked them. But the cheetah parser makes ParseError on hungarian characters, like "á", "é", "í", etc. When I remove them, I got good result,

Re: Tkinter

2009-02-05 Thread Luke
Thanks, Its working smoothly now -- http://mail.python.org/mailman/listinfo/python-list

Re: Flattening lists

2009-02-05 Thread Mark Dickinson
On Feb 5, 1:17 pm, mk wrote: > Hello everybody, > > Any better solution than this? > > def flatten(x): Just out of interest, how often do people really need such a recursive flatten, as opposed to a single-level version? I often find myself needing a 'concat' method that turns a list of lists (o

Re: [Web 2.0] Added-value of frameworks?

2009-02-05 Thread J Kenneth King
Bruno Desthuilliers writes: > Gilles Ganault a écrit : >> Hello >> >> If I wanted to build some social web site such as Facebook, what do >> frameworks like Django or TurboGears provide over writing a site from >> scratch using Python? > > Quite a lot of abstractions and factorisation of the boil

Re: Flattening lists

2009-02-05 Thread mk
Baolong zhen wrote: less list creation. At the cost of doing this at each 'flatten' call: if res is None: res = [] The number of situations of executing above code is the same as the number of list creations (once for each 'flatten' call, obviously). Is list creation really more costly

Re: time: Daylight savings confusion

2009-02-05 Thread MRAB
Matt Nordhoff wrote: Tim H wrote: On Win XP 64bit, Python 2.6.1 64bit I am trying to rename files by their creation time. It seems the time module is too smart for its own good here. time.localtime(os.path.getctime(f)) returns a value one hour off from what windows reports for files that were

Re: Flattening lists

2009-02-05 Thread Michele Simionato
On Feb 5, 2:17 pm, mk wrote: > Hello everybody, > > Any better solution than this? > > def flatten(x): >      res = [] >      for el in x: >          if isinstance(el,list): >              res.extend(flatten(el)) >          else: >              res.append(el) >      return res > > a = [1, 2, 3, [4

Re: Using while loop and if statement to tell if a binary has an odd or even number of 1's.

2009-02-05 Thread MRAB
Mark Dickinson wrote: On Feb 5, 1:18 am, Chris Rebert wrote: For an integer: is_even = bin(the_int)[2:].count('1') % 2 == 0 But the OP has to use if and while. How about: while 2+2 != 5: if 'wkw' in 'just being awkward': is_even = bin(the_int)[2:].count('1') % 2 == 0 bre

Re: Cheetah and hungarian charset...

2009-02-05 Thread Diez B. Roggisch
durumdara schrieb: Hi! I wanna ask that have anyone some exp. with Cheetah and the non-ascii chars? I have a site. The html template documents are saved in ansi format, psp liked them. But the cheetah parser makes ParseError on hungarian characters, like "á", "é", "í", etc. When I remove th

Re: Flattening lists

2009-02-05 Thread jason-sage
mk wrote: Hello everybody, Any better solution than this? def flatten(x): res = [] for el in x: if isinstance(el,list): res.extend(flatten(el)) else: res.append(el) return res a = [1, 2, 3, [4, 5, 6], [[7, 8], [9, 10]]] print flatten(a) It

Re: global name 'sqrt' is not defined

2009-02-05 Thread Scott David Daniels
M.-A. Lemburg wrote: On 2009-02-05 10:08, Nick Matzke wrote: ..., I can run this in the ipython shell just fine: a = ["12", "15", "16", "38.2"] dim = int(sqrt(size(a))) ...But if I move these commands to a function in another file, it freaks out: You need to add: from math import sqrt or:

Is c.l.py becoming less friendly?

2009-02-05 Thread mk
(duck) 542 comp.lang.python rtfm 467 comp.lang.python shut+up 263 comp.lang.perl rtfm 45 comp.lang.perl shut+up Code: import urllib2 import re import time def fillurlfmt(args): urlfmt, ggroup, gkw = args return {'group':ggroup, 'keyword':gkw, 'url': urlfmt % (gkw, ggroup)} def

Re: Ordered dict by default

2009-02-05 Thread Stephen Hansen
> That page about Ruby dicts show a higher traversal speed (probably > just because the CPU has to scan less memory, but I am not sure, > because mordern CPUs are very complex) but lower insertion speed (I > think mostly not because the added management of two pointers, but > because the memory use

Re: Is c.l.py becoming less friendly?

2009-02-05 Thread Dan Upton
On Thu, Feb 5, 2009 at 11:00 AM, mk wrote: > > (duck) > > 542 comp.lang.python rtfm > > 467 comp.lang.python shut+up > > 263 comp.lang.perl rtfm > > 45 comp.lang.perl shut+up > But over how many messages for each group? Wouldn't the percentage of messages containing those be more interesting than

Re: Ordered dict by default

2009-02-05 Thread Stephen Hansen
> Now, I also do recognize the utility of ordered dictionaries in some cases, > but > exactly what you mean by ordered varies. I have two cases where "ordered" > has the keys are in a specific custom order. I have four cases where "ordered" > means maintaining insertion order. For the former I do

Re: Flattening lists

2009-02-05 Thread mk
Mark Dickinson wrote: I often find myself needing a 'concat' method that turns a list of lists (or iterable of iterables) into a single list; itertools.chain does this quite nicely. But I don't think I've ever encountered a need for the full recursive version. You're most probably right in th

Re: Flattening lists

2009-02-05 Thread mk
Michele Simionato wrote: Looks fine to me. In some situations you may also use hasattr(el, '__iter__') instead of isinstance(el, list) (it depends if you want to flatten generic iterables or only lists). Thanks! Such stuff is what I'm looking for. Regards, mk -- http://mail.python.org/mailma

Re: Flattening lists

2009-02-05 Thread Brian Allen Vanderburg II
mrk...@gmail.com wrote: Baolong zhen wrote: less list creation. At the cost of doing this at each 'flatten' call: if res is None: res = [] The number of situations of executing above code is the same as the number of list creations (once for each 'flatten' call, obviously). Is list cre

Re: Is c.l.py becoming less friendly?

2009-02-05 Thread Tim Rowe
2009/2/5 mk : > > (duck) > > 542 comp.lang.python rtfm > > 467 comp.lang.python shut+up > > 263 comp.lang.perl rtfm > > 45 comp.lang.perl shut+up Yes, but is there any real traffic on comp.lang.perl nowadays? Sorry, cheap shot ;-) -- Tim Rowe -- http://mail.python.org/mailman/listinfo/python-li

Re: Couple of noobish question

2009-02-05 Thread Bruno Desthuilliers
Tim Rowe a écrit : 2009/2/4 Bruno Desthuilliers : # somemodule.py import os if os.uname()[0] == "Linux": On an MS Windows system, os.uname()[0] raises an AttributeError Thanks for the correction - as you may have guessed, I have not used windows for years !-) -- http://mail.python.org/m

Re: Ordered dict by default

2009-02-05 Thread MRAB
Paul Rubin wrote: bearophileh...@lycos.com writes: Now Ruby dicts are ordered by default: http://www.igvita.com/2009/02/04/ruby-19-internals-ordered-hash/ Maybe I didn't read that carefully enough, but it looks like "ordered" means the dict records come out in the same order you inserted them

Is the subprocess module robust enough in 2.4?

2009-02-05 Thread skip
The subprocess module was added in Python 2.4. I'm running 2.4.5 at work. I know it's seen many bugfixes since first released. Is the version in 2.4 robust enough to use in preference to os.popen and friends? Thx, -- Skip Montanaro - s...@pobox.com - http://www.smontanaro.net/ -- http://mail.p

Re: Is c.l.py becoming less friendly?

2009-02-05 Thread Diez B. Roggisch
mk schrieb: (duck) 542 comp.lang.python rtfm 467 comp.lang.python shut+up 263 comp.lang.perl rtfm 45 comp.lang.perl shut+up It appears to me that comp.lang.perl isn't even active anymore. Or googles interface is just crappy. c.l.perl.misc seems to be the place to search. And raw number

Re: Flattening lists

2009-02-05 Thread mk
Brian Allen Vanderburg II wrote: Is list creation really more costly than above? Probably not. I wrote a small test program using a list several levels deep, each list containing 5 sublists at each level and finally just a list of numbers. Flattening 1000 times took about 3.9 seconds for th

Re: Flattening lists

2009-02-05 Thread Stephen Hansen
> Either list creation is somewhat > costly, or "if var is None" is really cheap. "if x is y" is extremely cheap, I believe. Unlike most comparisons which are (relatively) expensive, that one is just comparing simple object address. You can't override "is" so there's a whole series of checks that

Re: Flattening lists

2009-02-05 Thread rdmurray
Baolong zhen wrote: > On Thu, Feb 5, 2009 at 10:17 PM, mk wrote: > > > Brian Allen Vanderburg II wrote: > > >> def flatten(x): > > >> res = [] > > >> for el in x: > > >> if isinstance(el,list): > > >> res.extend(flatten(el)) > > >> else: > > >> res.

Re: Flattening lists

2009-02-05 Thread J Kenneth King
mk writes: > Hello everybody, > > Any better solution than this? > > def flatten(x): > res = [] > for el in x: > if isinstance(el,list): > res.extend(flatten(el)) > else: > res.append(el) > return res > > a = [1, 2, 3, [4, 5, 6], [[7, 8], [9, 10

Re: Flattening lists

2009-02-05 Thread Sion Arrowsmith
mk wrote: >Brian Allen Vanderburg II wrote: >> I think it may be just a 'little' more efficient to do this: >> >> def flatten(x, res=None): >>if res is None: >> res = [] >>for el in x: >> if isinstance(el, (tuple, list)): >> flatten(el, res) >> else: >>

Re: Scanning a file character by character

2009-02-05 Thread Gabriel Genellina
En Thu, 05 Feb 2009 04:48:13 -0200, Spacebar265 escribió: Hi. Does anyone know how to scan a file character by character and have each character so I can put it into a variable. I am attempting to make a chatbot and need this to read the saved input to look for spelling mistakes and further ana

Re: Structuring Modules with a Ubiquitous Base Class (Circular Dependencies)

2009-02-05 Thread Gabriel Genellina
En Wed, 04 Feb 2009 21:12:58 -0200, andrew cooke escribió: On Feb 4, 7:49 pm, andrew cooke wrote: This leads to a circular dependency - the base class wants to import the components, which in turn want to import the base class. well, to partially answer my own question, this is certainly po

HOWTO for setting up a PyQt project in Eclipse ?

2009-02-05 Thread Linuxguy123
Does anyone know of a HOWTO for setting up a PyQt project in Eclipse ? I know about setting up a PyDev project, just wondering how to integrate the QtDesigner parts. For example, should I save the QtDesigner project in the root PyDev directory ? Thanks -- http://mail.python.org/mailman/listin

Re: subprocess.Popen not creating a pipe

2009-02-05 Thread Gabriel Genellina
En Sun, 01 Feb 2009 18:00:36 -0200, Andrew Parker escribió: On Sun, Feb 1, 2009 at 1:46 PM, Andrew Parker wrote: I'm having some fun with Popen. I have the following line: process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) print process.stdout Under

Re: Is c.l.py becoming less friendly?

2009-02-05 Thread Tim Chase
(duck) 542 comp.lang.python rtfm 467 comp.lang.python shut+up 263 comp.lang.perl rtfm 45 comp.lang.perl shut+up Is this where we tell you to shut up? ;-) As others mentioned, the raw numbers don't mean much without a total-volume-of-posts to demonstrate the percentage. It would also be int

Re: Flattening lists

2009-02-05 Thread rdmurray
Quoth rdmur...@bitdance.com: > This is all premature optimization, except for the goopy code, which is > presumably used enough to make it worth optimizing. And guess what? > The goopy code wins. What the people theorizing about the speed of > extend vs list creation miss is that the things with

Re: sorting mesh data an from abaqus simulation

2009-02-05 Thread Gabriel Genellina
En Mon, 02 Feb 2009 10:10:15 -0200, Alessandro Zivelonghi escribió: *Ntop = odb.rootAssembly.instances['PART-1-1'].nodeSets['TOP'].nodes * Problem: 1) the list of nodes Ntop contains all the node labels [2673, 2675, 2676, 2677, 2678, 3655, 3656, 119939, 124154, 127919] already ordered

Re: Ordered dict by default

2009-02-05 Thread Bryan Olson
MRAB wrote: Paul Rubin wrote: bearophileh...@lycos.com writes: Now Ruby dicts are ordered by default: http://www.igvita.com/2009/02/04/ruby-19-internals-ordered-hash/ Maybe I didn't read that carefully enough, but it looks like "ordered" means the dict records come out in the same order you i

  1   2   >