Re: Avoiding argument checking in recursive calls

2009-02-10 Thread Paul Rubin
Paul Rubin writes: > I'd write nested functions: > > def fact(n): >if n < 0: raise ValueError >def f1(n): > return 1 if n==0 else n*f1(n-1) >return f1(n) I forgot to add: all these versions except your original one should add a

Re: Avoiding argument checking in recursive calls

2009-02-10 Thread Paul Rubin
Steven D'Aprano writes: > def fact(n): > if n < 0: raise ValueError > if n = 0: return 1 > return fact(n-1)*n > > At the risk of premature optimization, I wonder if there is an idiom for > avoiding the unnecessary test for n <= 0 in the subsequent recursive > calls? I'd write nest

Re: Avoiding argument checking in recursive calls

2009-02-10 Thread Scott David Daniels
Steven D'Aprano wrote: I sometimes write recursive functions like this simple factorial: def fact(n): if n < 0: raise ValueError if n = 0: return 1 return fact(n-1)*n At the risk of premature optimization, I wonder if there is an idiom for avoiding the unnecessary test for n <= 0 i

Re: getopt

2009-02-10 Thread Matthew Sacks
I didn't realize that the no-value arguments, -b, -h, etc are required? This seems to make things a bit more difficult considering unless I use the GNU style getopt all arguments are required to be passed? I could be mistaken. I will have a look at what you have posted here and report my results.

Re: python3 tutorial for newbie

2009-02-10 Thread Akira Kitada
http://wiki.python.org/moin/Python3.0Tutorials On Wed, Feb 11, 2009 at 3:22 AM, Gary Wood wrote: > Can someone recommend a good tutorial for Python 3, ideally that has tasks > or assignments at the end of each chapter. > Please, > > -- > http://mail.python.org/mailman/listinfo/python-list > > --

Programmatically changing network proxy settings on the Mac

2009-02-10 Thread arunasunil
Hi, Anybody have suggestions of how network proxy settings can be changed programmatically on the Mac, Tiger and Leopard. Are there any helpful python api's that can be used. Thanks Sunil -- http://mail.python.org/mailman/listinfo/python-list

Browse Dialog

2009-02-10 Thread kamath86
Hi , I am using TKinter for creating a GUI. As of now i am using tkFileDialog module for selection of file/directory.But i see that i can use either of these at one go.Is there a way i can select a file or a directory through a single dialog box?? -- http://mail.python.org/mailman/listinfo/python-

Re: getopt

2009-02-10 Thread John Machin
On Feb 11, 4:36 pm, Matthew Sacks wrote: > The documentation leaves lack for want, especially the examples. You had two problems: (1) str(passedArgs): The docs make it plain that "args" is a list, not a str instance: """args is the argument list to be parsed, without the leading reference to the

Re: python3 tutorial for newbie

2009-02-10 Thread Gabriel Genellina
En Tue, 10 Feb 2009 16:22:36 -0200, Gary Wood escribió: Can someone recommend a good tutorial for Python 3, ideally that has tasks or assignments at the end of each chapter. I don't know of any specifically targetted to Python 3, except the official one at http://www.python.org/doc/3.0/

Re: getopt

2009-02-10 Thread John Machin
On Feb 11, 12:25 pm, John Machin wrote: > On Feb 11, 12:12 pm, Matthew Sacks wrote: > > > if anyone can have a look at this code and offer suggestions i would > > appreciate it. > > i am forced to use getopt, so i cant use something good like optparse > > > passedArgs = sys.argv[1:] > > optlist,

Re: can multi-core improve single funciton?

2009-02-10 Thread Paul Rubin
oyster writes: > Hi, guys, my fib(xx) is just an example to show "what is a single > function" and "what is the effect I expect to see when enable > multi-core". > > My real purpose is to know "whether multi-core can help to improve > the speed of a common function". But I know definitely that th

Re: Iterable Ctypes Struct

2009-02-10 Thread Gabriel Genellina
En Wed, 11 Feb 2009 00:31:26 -0200, escribió: I like the ability to access elements of a struct such as with ctypes Structure: myStruct.elementName1 4 What I like about it is there are no quotes needed. What I don't like about it is that it's not iterable: for n in myStruct: <== gives err

Re: getopt

2009-02-10 Thread Matthew Sacks
The documentation leaves lack for want, especially the examples. On Tue, Feb 10, 2009 at 5:25 PM, John Machin wrote: > On Feb 11, 12:12 pm, Matthew Sacks wrote: >> if anyone can have a look at this code and offer suggestions i would >> appreciate it. >> i am forced to use getopt, so i cant use s

Re: bool evaluations of generators vs lists

2009-02-10 Thread Gabriel Genellina
On Tue, 2009-02-10 at 12:50 -0800, Josh Dukes wrote: The thing I don't understand is why a generator that has no iterable values is different from an empty list. Why shouldn't bool == has_value?? Technically a list, a tuple, and a string are also objects but if they lack values they're evaluated

Re: can multi-core improve single funciton?

2009-02-10 Thread Chris Rebert
On Tue, Feb 10, 2009 at 8:57 PM, James Mills wrote: > On Wed, Feb 11, 2009 at 2:21 PM, oyster wrote: >> My real purpose is to know "whether multi-core can help to improve the >> speed of a common function". But I know definitely that the answer is >> NO. > > As stated by others, and even myself,

Re: can multi-core improve single funciton?

2009-02-10 Thread James Mills
On Wed, Feb 11, 2009 at 2:21 PM, oyster wrote: > My real purpose is to know "whether multi-core can help to improve the > speed of a common function". But I know definitely that the answer is > NO. As stated by others, and even myself, it is not possible to just "automagically" improve the execut

Re: "Super()" confusion

2009-02-10 Thread Michele Simionato
On Feb 10, 9:19 am, "Gabriel Genellina" wrote: > You really should push them to be included in python.org, even in their   > unfinished form. (At least a link in the wiki pages). Their visibility is   > almost null now. It looks like I made an unfortunate choice with the title ("Things to Know ab

Re: Avoiding argument checking in recursive calls

2009-02-10 Thread afriere
On Feb 11, 1:48 pm, Jervis Whitley wrote: > Hello, an idea is optional keyword arguments. > > def fact(n, check=False): >   if not check: >     if n < 0: raise ValueError >   if n == 0: return 1 >   return fact(n - 1, check=True) * n > > essentially hiding an expensive check with a cheap one. It

Re: Avoiding argument checking in recursive calls

2009-02-10 Thread Gabriel Genellina
En Tue, 10 Feb 2009 23:58:07 -0200, Steven D'Aprano escribió: I sometimes write recursive functions like this simple factorial: def fact(n): if n < 0: raise ValueError if n = 0: return 1 return fact(n-1)*n At the risk of premature optimization, I wonder if there is an idiom for

Re: can multi-core improve single funciton?

2009-02-10 Thread oyster
Hi, guys, my fib(xx) is just an example to show "what is a single function" and "what is the effect I expect to see when enable multi-core". My real purpose is to know "whether multi-core can help to improve the speed of a common function". But I know definitely that the answer is NO. -- http://ma

Re: Difference between vars() and locals() and use case for vars()

2009-02-10 Thread python
Thank you Gabriel! Malcolm - Original message - From: "Gabriel Genellina" To: python-list@python.org Date: Wed, 11 Feb 2009 02:04:47 -0200 Subject: Re: Difference between vars() and locals() and use case for vars() En Wed, 11 Feb 2009 01:38:49 -0200, escribió: > Can someone explain t

Re: Difference between vars() and locals() and use case for vars()

2009-02-10 Thread Gabriel Genellina
En Wed, 11 Feb 2009 01:38:49 -0200, escribió: Can someone explain the difference between vars() and locals()? I'm also trying to figure out what the use case is for vars(), eg. when does it make sense to use vars() in a program? Without arguments, vars() returns the current namespace -- same

Difference between vars() and locals() and use case for vars()

2009-02-10 Thread python
Can someone explain the difference between vars() and locals()? I'm also trying to figure out what the use case is for vars(), eg. when does it make sense to use vars() in a program? Thank you, Malcolm -- http://mail.python.org/mailman/listinfo/python-list

Re: "Super()" confusion

2009-02-10 Thread Gabriel Genellina
En Wed, 11 Feb 2009 00:31:06 -0200, Benjamin Kaplan escribió: On Tue, Feb 10, 2009 at 9:25 PM, Daniel Fetchinson < fetchin...@googlemail.com> wrote: Okay, I think we converged to a common denominator. I agree with you that the documentation needs additions about super and I also agree with yo

Re: pySerial help please!

2009-02-10 Thread Grant Edwards
On 2009-02-10, bmasch...@gmail.com wrote: > Hello all, > > I am very new to Python and I am using it because I needed an > easy language to control a piece of equipment that connects to > my computer via a serial cable. I am running Python 2.6 with > pySerial 2.4 under Windows. I can get Python to

Re: Avoiding argument checking in recursive calls

2009-02-10 Thread Jervis Whitley
> I've done this: > > def _fact(n): >if n = 0: return 1 >return _fact(n-1)*n > > def fact(n): >if n < 0: raise ValueError >return _fact(n) > > but that's ugly. What else can I do? > > Hello, an idea is optional keyword arguments. def fact(n, check=False): if not check: if n <

Iterable Ctypes Struct

2009-02-10 Thread mark . seagoe
I like the ability to access elements of a struct such as with ctypes Structure: >>>myStruct.elementName1 4 What I like about it is there are no quotes needed. What I don't like about it is that it's not iterable: >>>for n in myStruct: <== gives error >>>print n I don't want to force the en

Re: "Super()" confusion

2009-02-10 Thread Benjamin Kaplan
On Tue, Feb 10, 2009 at 9:25 PM, Daniel Fetchinson < fetchin...@googlemail.com> wrote: > >>> Consider whether you really need to use super(). > >>> http://fuhm.net/super-harmful/ > > Because throwing around that link carries about the same amount of > information as "perl is

Re: "Super()" confusion

2009-02-10 Thread Daniel Fetchinson
>>> Consider whether you really need to use super(). >>> http://fuhm.net/super-harmful/ Because throwing around that link carries about the same amount of information as "perl is better than python", "my IDE is better than yours", "vim rulez!", "emacs is cooler than vim"

Avoiding argument checking in recursive calls

2009-02-10 Thread Steven D'Aprano
I sometimes write recursive functions like this simple factorial: def fact(n): if n < 0: raise ValueError if n = 0: return 1 return fact(n-1)*n At the risk of premature optimization, I wonder if there is an idiom for avoiding the unnecessary test for n <= 0 in the subsequent recurs

Re: Upgrade 2.6 to 3.0

2009-02-10 Thread Aahz
In article <2ba4f763-79fa-423e-b082-f9de829ae...@i20g2000prf.googlegroups.com>, Giampaolo Rodola' wrote: > >Just out of curiosity, am I the only one who think that switching to >3.x right now is not a good idea? Hardly. I certainly wouldn't consider it for production software, but installing it

Re: getopt

2009-02-10 Thread John Machin
On Feb 11, 12:12 pm, Matthew Sacks wrote: > if anyone can have a look at this code and offer suggestions i would > appreciate it. > i am forced to use getopt, so i cant use something good like optparse > > passedArgs = sys.argv[1:] > optlist, args = getopt.getopt(str(passedArgs), ["connectPassword

Re: Propagating function calls

2009-02-10 Thread James Mills
On Wed, Feb 11, 2009 at 11:02 AM, Noam Aigerman wrote: > Suppose I have a python object X, which holds inside it a python object Y. > How can I propagate each function call to X so the same function call in Y > will be called, i.e: > > X.doThatFunkyFunk() > > Would cause > > Y.doThatFunkyFunk() N

getopt

2009-02-10 Thread Matthew Sacks
if anyone can have a look at this code and offer suggestions i would appreciate it. i am forced to use getopt, so i cant use something good like optparse passedArgs = sys.argv[1:] optlist, args = getopt.getopt(str(passedArgs), ["connectPassword=", "adminServerURL=", "action=", "targets=", "appDir=

Re: Propagating function calls

2009-02-10 Thread Chris Rebert
On Tue, Feb 10, 2009 at 5:02 PM, Noam Aigerman wrote: > Suppose I have a python object X, which holds inside it a python object Y. > How can I propagate each function call to X so the same function call in Y That'd be a method call actually, not a function call. > will be called, i.e: > > X.doTh

Re: Functional schmunctional...

2009-02-10 Thread python
> This is a fantastically didactic newsgroup: you start off just musing about > , you end up learning python has , > brilliant :-) +1 !! Malcolm -- http://mail.python.org/mailman/listinfo/python-list

Propagating function calls

2009-02-10 Thread Noam Aigerman
Suppose I have a python object X, which holds inside it a python object Y. How can I propagate each function call to X so the same function call in Y will be called, i.e: X.doThatFunkyFunk() Would cause Y.doThatFunkyFunk() Thanks, Noam -- http://mail.python.org/mailman/listinfo/python-list

relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC

2009-02-10 Thread tkevans
Found a couple of references to this in the newsgroup, but no solutions. I'm trying to build libsbml-3.3.0 with python 2.5.4 support on RHEL 5.3. This RedHat distro has python 2.4.5, and libsbml builds ok with that release. After building 2.5.4 (./configure CFLAGS=-fPIC , as the error message su

Re: "Super()" confusion

2009-02-10 Thread Gabriel Genellina
En Tue, 10 Feb 2009 18:01:53 -0200, Daniel Fetchinson escribió: On 2/9/09, Gabriel Genellina wrote: En Mon, 09 Feb 2009 23:34:05 -0200, Daniel Fetchinson escribió: Consider whether you really need to use super(). http://fuhm.net/super-harmful/ Because throwing around that link carries ab

Re: re.sub and named groups

2009-02-10 Thread Aahz
In article <4c7158d2-5663-46b9-b950-be81bd799...@z6g2000pre.googlegroups.com>, Emanuele D'Arrigo wrote: > >I'm having a ball with the power of regular expression but I stumbled >on something I don't quite understand: Book recommendation: _Mastering Regular Expressions_, Jeffrey Friedl -- Aahz (a

Re: pySerial help please!

2009-02-10 Thread bmaschino
On Feb 10, 5:41 pm, "Diez B. Roggisch" wrote: > bmasch...@gmail.com schrieb: > > > > > > > Hello all, > > > I am very new to Python and I am using it because I needed an easy > > language to control a piece of equipment that connects to my computer > > via a serial cable. I am running Python 2.6 w

Escaping my own chroot...

2009-02-10 Thread r0g
I'm writing a linux remastering script in python where I need to chroot into a folder, run some system commands and then come out and do some tidying up, un-mounting proc & sys etc. I got in there with os.chroot() and I tried using that to get back out but that didn't work so... is my script trapp

Re: zlib interface semi-broken

2009-02-10 Thread Paul Rubin
Scott David Daniels writes: > I suspect that is why such an interface never came up (If > you can clone states, then you can say: "compress this, then use the > resultant state to compress/decompress others." The zlib C interface supports something like that. It is just not exported to the pyth

Re: Functional schmunctional...

2009-02-10 Thread r0g
bearophileh...@lycos.com wrote: > Here a small benchmark: > > def ip2inet01(a): # can't be used with 6 > li = a.split('.') Wow, thanks everybody for all the suggestions, v.interesting esp as I didn't even ask for any suggestions! This is a fantastically didactic newsgroup: you start off jus

Re: optparse versus getopt

2009-02-10 Thread Robert Kern
On 2009-02-10 17:32, Matthew Sacks wrote: its a debian package. 2.5 importing optparse works with interactive python, but not through the jython interpreter i an using. Ah, yes. The current version of Jython is still based off of Python 2.2 whereas optparse was introduced in Python 2.3. is

Re: optparse versus getopt

2009-02-10 Thread Matthew Sacks
its a debian package. 2.5 importing optparse works with interactive python, but not through the jython interpreter i an using. is there some way i can force the import based on the the absolute path to the module? On Tue, Feb 10, 2009 at 1:48 PM, Robert Kern wrote: > On 2009-02-10 15:42, Matthe

embedding Python in a shared library

2009-02-10 Thread Deepak Chandran
I have embedded Python in a shared library. This works fine in Windows (dll), but I get the following error is Ubuntu when I try to load modules: /usr/lib/python2.5/lib-dynload/*time.so*: error: symbol lookup error: * undefined* symbol: PyExc_ValueError I found many postings on this issue on the

Re: Scanning a file character by character

2009-02-10 Thread MRAB
Steven D'Aprano wrote: On Tue, 10 Feb 2009 16:46:30 -0600, Tim Chase wrote: Or for a slightly less simple minded splitting you could try re.split: re.split("(\w+)", "The quick brown fox jumps, and falls over.")[1::2] ['The', 'quick', 'brown', 'fox', 'jumps', 'and', 'falls', 'over'] Perhaps

Re: Scanning a file character by character

2009-02-10 Thread Steven D'Aprano
On Tue, 10 Feb 2009 16:46:30 -0600, Tim Chase wrote: >>> Or for a slightly less simple minded splitting you could try re.split: >>> >> re.split("(\w+)", "The quick brown fox jumps, and falls >> over.")[1::2] >>> ['The', 'quick', 'brown', 'fox', 'jumps', 'and', 'falls', 'over'] >> >> >> P

Re: zlib interface semi-broken

2009-02-10 Thread Travis
On Tue, Feb 10, 2009 at 01:36:21PM -0800, Scott David Daniels wrote: > >A simple way to fix this would be to add a finished attribute to the > >Decompress object. > Perhaps you could submit a patch with such a change? Yes, I will try and get to that this week. > >However, perhaps this would be a

Re: Replace unknow string varible in file.

2009-02-10 Thread Terry Reedy
namire wrote: Hey .python first time poster here. I'm pretty good with python so far, but I keep needed a function in my program but not knowing how to build it. =( Here's the problem: Imagine a html file full of 100's of these strings all mooshed together onto many lines; ITEM Where the word 'M

Re: "Super()" confusion

2009-02-10 Thread Paul Boddie
On 10 Feb, 20:45, Jean-Paul Calderone wrote: > > It replaces one kind of repetition with another. I think each kind is > about as unpleasant. Has anyone gathered any data on the frequency of > changes of base classes as compared to the frequency of classes being > renamed? I don't think either

Re: Functional schmunctional...

2009-02-10 Thread Terry Reedy
r0g wrote: def inet2ip(n): p = (n/16777216) q = ((n-(p*16777216))/65536) r = ((n-((p*16777216)+(q*65536)))/256) s = ((n-((p*16777216)+(q*65536)+(r*256 return str(p)+"."+str(q)+"."+str(r)+"."+str(s) Beyond what other wrote: To future-proof code, use // instead of / for integer di

Re: Scanning a file character by character

2009-02-10 Thread Rhodri James
On Tue, 10 Feb 2009 22:02:57 -, Steven D'Aprano wrote: On Tue, 10 Feb 2009 12:06:06 +, Duncan Booth wrote: Steven D'Aprano wrote: On Mon, 09 Feb 2009 19:10:28 -0800, Spacebar265 wrote: How would I do separate lines into words without scanning one character at a time? Scan a l

Re: Scanning a file character by character

2009-02-10 Thread Tim Chase
Or for a slightly less simple minded splitting you could try re.split: re.split("(\w+)", "The quick brown fox jumps, and falls over.")[1::2] ['The', 'quick', 'brown', 'fox', 'jumps', 'and', 'falls', 'over'] Perhaps I'm missing something, but the above regex does the exact same thing as line

Re: pySerial help please!

2009-02-10 Thread Diez B. Roggisch
bmasch...@gmail.com schrieb: Hello all, I am very new to Python and I am using it because I needed an easy language to control a piece of equipment that connects to my computer via a serial cable. I am running Python 2.6 with pySerial 2.4 under Windows. I can get Python to create a serial port o

Re: pySerial help please!

2009-02-10 Thread MRAB
bmasch...@gmail.com wrote: Hello all, I am very new to Python and I am using it because I needed an easy language to control a piece of equipment that connects to my computer via a serial cable. I am running Python 2.6 with pySerial 2.4 under Windows. I can get Python to create a serial port on

Re: can multi-core improve single funciton?

2009-02-10 Thread Gerhard Weis
On 2009-02-11 08:01:29 +1000, Steven D'Aprano said: On Tue, 10 Feb 2009 22:41:25 +1000, Gerhard Weis wrote: btw. the timeings are not that different for the naive recursion in OP's version and yours. fib(500) on my machine: OP's: 0.00116 (far away from millions of years) This here: 0

Re: zlib interface semi-broken

2009-02-10 Thread Scott David Daniels
Paul Rubin wrote: Travis writes: However, perhaps this would be a good time to discuss how [zlib] works... It is missing some other features too, like the ability to preload a dictionary. I'd support extending the interface. The trick to defining a preload interface is avoiding creating a b

Re: Working with propositional formulae in Python

2009-02-10 Thread Terry Reedy
nnp wrote: Hey, I'm currently working with propositional boolean formulae of the type 'A & (b -> c)' (for example). I was wondering if anybody knows of a Python library to create parse trees and convert such formulae to conjunctive, disjunctive and Tseitin normal forms? You would probably do b

RE: Python binaries with VC++ 8.0?

2009-02-10 Thread Delaney, Timothy (Tim)
bearophileh...@lycos.com wrote: > Paul Rubin: >> Gideon Smeding of the University of >> Utrecht has written a masters' thesis titled "An executable >> operational semantics for Python". > > A significant part of Computer Science is a waste of time and money. The same can be said for any research

Re: can multi-core improve single funciton?

2009-02-10 Thread Steven D'Aprano
On Tue, 10 Feb 2009 02:05:35 -0800, Niklas Norrthon wrote: > According to the common definition of fibonacci numbers fib(0) = 0, fib > (1) = 1 and fib(n) = fib(n-1) + fib(n-2) for n > 1. So the number above > is fib(501). So it is. Oops, off by one error! Or, if you prefer, it's the right algori

Re: bool evaluations of generators vs lists

2009-02-10 Thread Terry Reedy
Josh Dukes wrote: I was actually aware of that (thank you, though, for trying to help). What I was not clear on was if the boolean evaluation is a method of an object that can be modified via operatior overloading (in the same way + is actually .__add__()) or not. Clearly __nonzero__ is the ope

Re: Python Launcher.app on OS X

2009-02-10 Thread kpp9c
So how does this effect the install instructions found on the link: http://wiki.python.org/moin/MacPython/Leopard do you trash that when you do an install on OS X? I am so hesitant to delete anything that resides in /System -- http://mail.python.org/mailman/listinfo/python-list

Re: Logging in Python

2009-02-10 Thread Vinay Sajip
On Feb 10, 9:38 pm, aha wrote: > Thanks for your suggestions. I've also figured that I can test > iflogging.RootLogger.manager.loggerDict has any items in it. Or if it > has a logger for the module that I wish to start. I like basicLogger > idea though as it seems like the cleanest implementat

Re: bool evaluations of generators vs lists

2009-02-10 Thread Josh Dukes
ahhh any! ok, yeah, I guess that's what I was looking for. Thanks. On 10 Feb 2009 21:57:56 GMT Steven D'Aprano wrote: > On Tue, 10 Feb 2009 12:50:02 -0800, Josh Dukes wrote: > > > The thing I don't understand is why a generator that has no iterable > > values is different from an empty list. >

Re: bool evaluations of generators vs lists

2009-02-10 Thread Chris Rebert
On Tue, Feb 10, 2009 at 1:57 PM, Steven D'Aprano wrote: > On Tue, 10 Feb 2009 12:50:02 -0800, Josh Dukes wrote: > >> The thing I don't understand is why a generator that has no iterable >> values is different from an empty list. > > How do you know it has no iterable values until you call next() o

Re: Scanning a file character by character

2009-02-10 Thread Steven D'Aprano
On Tue, 10 Feb 2009 12:06:06 +, Duncan Booth wrote: > Steven D'Aprano wrote: > >> On Mon, 09 Feb 2009 19:10:28 -0800, Spacebar265 wrote: >> >>> How would I do separate lines into words without scanning one >>> character at a time? >> >> Scan a line at a time, then split each line into word

Re: can multi-core improve single funciton?

2009-02-10 Thread Steven D'Aprano
On Tue, 10 Feb 2009 22:41:25 +1000, Gerhard Weis wrote: > btw. the timeings are not that different for the naive recursion in OP's > version and yours. > fib(500) on my machine: > OP's: 0.00116 (far away from millions of years) > This here: 0.000583 I don't believe those timings are credib

Re: Replace unknow string varible in file.

2009-02-10 Thread r0g
namire wrote: > Just as a comparison in the Windows OS this seems easy to do when > managing files, say for the file a-blah-b-blah.tmp where blah is an > unknown you can use: del a-*-b-*.tmp to get rid of that file. But for > python and a string in text file I don't have a clue. @_@ could > someone

Re: generator object or 'send' method?

2009-02-10 Thread Terry Reedy
Aaron Brady wrote: I guess a generator that counts, but skips K numbers, where K can be varied. For instance, you initialize it with N, the starting number, and K, the jump size. Then, you can change either one later on. This specification is incomplete as to the timing of when changes to N

Re: can multi-core improve single funciton?

2009-02-10 Thread Steven D'Aprano
On Tue, 10 Feb 2009 12:43:20 +, Lie Ryan wrote: > Of course multi-core processor can improve single function using > multiprocessing, as long as the function is parallelizable. The > Fibonacci function is not a parallelizable function though. As I understand it, there's very little benefit to

Re: bool evaluations of generators vs lists

2009-02-10 Thread Steven D'Aprano
On Tue, 10 Feb 2009 12:50:02 -0800, Josh Dukes wrote: > The thing I don't understand is why a generator that has no iterable > values is different from an empty list. How do you know it has no iterable values until you call next() on it and get StopIteration? By the way, your "has_values" funct

Re: Functional schmunctional...

2009-02-10 Thread bearophileHUGS
Here a small benchmark: def ip2inet01(a): # can't be used with 6 li = a.split('.') assert len(li) == 4 a = int(li[0])*16777216 b = int(li[1])*65536 c = int(li[2])*256 d = int(li[3]) return a+b+c+d from itertools import count def ip2inet02(a): blocks = a.split('.')

Re: zlib interface semi-broken

2009-02-10 Thread Paul Rubin
Travis writes: > However, perhaps this would be a good time to discuss how this library > works; it is somewhat awkward and perhaps there are other changes which > would make it cleaner. > > What does the python community think? It is missing some other features too, like the ability to preload

Re: GAE read binary file into db.BlobProperty()

2009-02-10 Thread alex goretoy
was not able to use open to open a binary file so what I did was use urlfetch to fetch the image for me and read the content into BlobProperty() Not sure why it took me so long to figure this out. Hope it helps someone. thx def post(self,key): k=db.get(key) img=images.Image(urlfetc

Re: Using TK and the canvas.

2009-02-10 Thread Kalibr
On Feb 11, 5:51 am, r wrote: > On Feb 10, 1:27 pm, Kalibr wrote: > [snip] > > You should really check out wxPython, there is support for just this > type of thing. of course you could do this with Tkinter, but just > thinking about it makes my head hurt :). Alright, I shall investigate. Thank yo

Re: optparse versus getopt

2009-02-10 Thread Robert Kern
On 2009-02-10 15:42, Matthew Sacks wrote: it seems as if optparse isn't in my standard library. How did you install your Python? It has been part of the standard library for a very long time. is there a way to add a lib like ruby gems? http://docs.python.org/install/index.html But optpar

Cannot get python to read a CAP file link in an ATOM feed

2009-02-10 Thread Brian Kaplan
Hi List, I'm trying to get python to parse a CAP file in an ATOM feed from the National Weather Service. Here's one states ATOM feed. http://www.weather.gov/alerts-beta/ky.php?x=0. If you view the source of this file, there is a reference to another web feed. For instance, href="http://www.weathe

Re: optparse versus getopt

2009-02-10 Thread Matthew Sacks
it seems as if optparse isn't in my standard library. is there a way to add a lib like ruby gems? On Tue, Feb 10, 2009 at 1:38 PM, Tim Chase wrote: > Matthew Sacks wrote: >> >> does anyone have any arguments against optparse vs getopt > > I've found that the optparse module beats getopt on *every

Re: Logging in Python

2009-02-10 Thread aha
Thanks for your suggestions. I've also figured that I can test if logging.RootLogger.manager.loggerDict has any items in it. Or if it has a logger for the module that I wish to start. I like basicLogger idea though as it seems like the cleanest implementation. On Feb 10, 3:21 pm, Vinay Sajip w

Re: optparse versus getopt

2009-02-10 Thread Tim Chase
Matthew Sacks wrote: does anyone have any arguments against optparse vs getopt I've found that the optparse module beats getopt on *every* aspect except in the event that you have experience with the C getopt libraries *and* just want something that behaves like those libraries. Optparse is

Re: zlib interface semi-broken

2009-02-10 Thread Scott David Daniels
Travis wrote: The zlib interface does not indicate when you've hit the > end of a compressed stream The underlying zlib functionality provides for this. With python's zlib, you have to read past the compressed data and into the uncompressed, which gets stored in Decompress.unused_data. ...

Re: bool evaluations of generators vs lists

2009-02-10 Thread Albert Hopkins
On Tue, 2009-02-10 at 12:50 -0800, Josh Dukes wrote: > The thing I don't understand is why a generator that has no iterable > values is different from an empty list. Why shouldn't bool == > has_value?? Technically a list, a tuple, and a string are also objects > but if they lack values they're eva

Re: Replace unknow string varible in file.

2009-02-10 Thread Vlastimil Brom
2009/2/10 namire : > Hey .python first time poster here. I'm pretty good with python so > far, but I keep needed a function in my program but not knowing how to > build it. =( Here's the problem: > > Imagine a html file full of 100's of these strings all mooshed > together onto many lines; > ITEM >

Re: Functional schmunctional...

2009-02-10 Thread Scott David Daniels
For expressiveness, try something like: def ip2in(dotted_ip_addr): result = 0 assert dotted_ip_addr.count('.') in (3, 7) for chunk in dotted_ip_addr.split('.'): result = (result << 8) + int(chunk) return result def inet2ip(ip_number): assert 0 < ip_number < 1 << 48

Re: optparse versus getopt

2009-02-10 Thread Robert Kern
On 2009-02-10 15:06, Matthew Sacks wrote: does anyone have any arguments against optparse vs getopt As the getopt docs say: "A more convenient, flexible, and powerful alternative is the optparse module." I have found all three statements to be true. But I've found argparse to be even better

pySerial help please!

2009-02-10 Thread bmaschino
Hello all, I am very new to Python and I am using it because I needed an easy language to control a piece of equipment that connects to my computer via a serial cable. I am running Python 2.6 with pySerial 2.4 under Windows. I can get Python to create a serial port on COM1, but when I try to write

optparse versus getopt

2009-02-10 Thread Matthew Sacks
does anyone have any arguments against optparse vs getopt -- http://mail.python.org/mailman/listinfo/python-list

zlib interface semi-broken

2009-02-10 Thread Travis
Hello all, The zlib interface does not indicate when you've hit the end of a compressed stream. The underlying zlib functionality provides for this. With python's zlib, you have to read past the compressed data and into the uncompressed, which gets stored in Decompress.unused_data. As a result

Re: Python Module: nift

2009-02-10 Thread r0g
J wrote: > Thanks for your answers, especially Chris Rebert and Paul McGuire's. I > have a question: > How far does Python go in the Game Development field? (Using Python > only, no extensions) Hey J, Python's all about the libraries (extensions), you won't be able to do much without them but th

Replace unknow string varible in file.

2009-02-10 Thread namire
Hey .python first time poster here. I'm pretty good with python so far, but I keep needed a function in my program but not knowing how to build it. =( Here's the problem: Imagine a html file full of 100's of these strings all mooshed together onto many lines; ITEM Where the word 'MARKER' is a cons

Re: Functional schmunctional...

2009-02-10 Thread Paul Rubin
r0g writes: > def inet2ip(n): > p = (n/16777216) > q = ((n-(p*16777216))/65536) > r = ((n-((p*16777216)+(q*65536)))/256) > s = ((n-((p*16777216)+(q*65536)+(r*256 > return str(p)+"."+str(q)+"."+str(r)+"."+str(s) from struct import pack def inet2ip(n): xs = pack('L',n) return '.'.

Re: Functional schmunctional...

2009-02-10 Thread andrew cooke
r0g wrote: > def ip2inet(a): > li = a.split('.') > assert len(li) == 4 or len(li) == 6 > return reduce(add,[int(li[e])*(256**((len(li)-1)-e)) for e in > xrange(0,len(li))]) what a mess. i don't use this extreme a functional style in python (it's not really how the language is intended to be

Re: bool evaluations of generators vs lists

2009-02-10 Thread Josh Dukes
> The first example is a list. A list of length 0 evaluates to False. > > The second example returns a generator object. A generator object > apparently evaluates to true. Your example is not iterating of their > values of the generator, but evaluating bool(generator_object) itself. > My feelin

Change in cgi module's handling of POST requests

2009-02-10 Thread Bob Kline
[Didn't realize the mirror didn't work both ways] We just upgraded Python to 2.6 on some of our servers and a number of our CGI scripts broke because the cgi module has changed the way it handles POST requests. When the 'action' attribute was not present in the form element on an HTML page th

Re: How to get a return from Button?

2009-02-10 Thread Chris Rebert
On Tue, Feb 10, 2009 at 12:21 PM, Muddy Coder wrote: > Hi Folks, > > I want to use a Button to trigger askopenfilename() dialog, then I can > select a file. My short code is below: > > > def select_file(): >filenam = askopenfilename(title='Get the file:') > return filenam > > root =

Functional schmunctional...

2009-02-10 Thread r0g
I remember being forced to do a bit of functional programming in ML back at Uni in the mid 90, the lecturers were all in a froth about it and I must admit the code was elegant to look at. The problem was the dog slow performance for anything half practical, especially with recursion being the techn

Re: Logging in Python

2009-02-10 Thread Vinay Sajip
On Feb 10, 5:50 pm, aha wrote: > Hello All, > > I have an application whereloggingmay need to be configured in > multiple places. I've used the PythonLoggingFramework for sometime, > but I'm still not sure how to test iflogginghas configured. For > example, I have modules A, B, and C. > > Below

How to get a return from Button?

2009-02-10 Thread Muddy Coder
Hi Folks, I want to use a Button to trigger askopenfilename() dialog, then I can select a file. My short code is below: def select_file(): filenam = askopenfilename(title='Get the file:') return filenam root = Tk() Button(root, text='Select a file', command=select_file).pack() ro

  1   2   >