Re: How to check the exists of a name?

2009-10-18 Thread Chris Rebert
On Sat, Oct 17, 2009 at 11:43 PM, StarWing wrote: > On 10月18日, 下午2时37分, Chris Rebert wrote: >> On Sat, Oct 17, 2009 at 11:30 PM, StarWing wrote: >> > Sometimes I want to make a simple flags. and i need to check there is >> > a name in current scope or not (that is, we can visit this name, no >>

Re: How to check the exists of a name?

2009-10-18 Thread Ben Finney
David <71da...@libero.it> writes: > Il Sat, 17 Oct 2009 23:43:36 -0700 (PDT), StarWing ha scritto: > > > I got a idea, use a try...except statement. there are another way to > > do it ? > > > > (I just curious now, because I solve my problem in another way :-) > > locals().has_key(myname) > glob

Re: weekdays in range

2009-10-18 Thread Jive Dadson
Ben Finney wrote: Jive Dadson writes: Can someone think of an easy way to calculate the number of weekdays between two calendar dates (in Python)? That depends on what you mean by “weekdays”. >>> import datetime >>> begin_date = datetime.date(2009, 10, 9) >>> end_date = datetime

Re: The rap against "while True:" loops

2009-10-18 Thread Hendrik van Rooyen
On Saturday, 17 October 2009 16:30:55 Aahz wrote: > In article , > > Tim Rowe wrote: > >The point is that an exception causes a change in program flow, so of > >course they're used for flow control. It's what they do. The question > >is in what cases it's appropriate to use them. > > Standard Pyt

Re: a gap of do....while?

2009-10-18 Thread Lie Ryan
Chris Rebert wrote: On Sat, Oct 17, 2009 at 10:22 PM, StarWing wrote: okay, I think somethings dowhile is useful, but why python didn't have it? For simplicity of syntax and less duplication among the basic syntactic constructs. Less language features means less decisions to make. -- ht

Re: How to check the exists of a name?

2009-10-18 Thread Steven D'Aprano
On Sat, 17 Oct 2009 23:30:02 -0700, StarWing wrote: > Sometimes I want to make a simple flags. and i need to check there is a > name in current scope or not (that is, we can visit this name, no matter > where is it). and how to do that in python? (1) Use a sentinel: myname = None # always exist

Re: weekdays in range

2009-10-18 Thread Ben Finney
Jive Dadson writes: > Ben Finney wrote: > > >>> friday_weekday = 4 > > >>> len([ > > ... date for date in ( > > ... begin_date + datetime.timedelta(days) > > ... for days in range((end_date - begin_date).days)) > > ... if calendar.weekday(date.year,

Re: weekdays in range

2009-10-18 Thread Jive Dadson
Wow. It's a danged tutorial. Thanks again. Take a break. -- http://mail.python.org/mailman/listinfo/python-list

Sunday 18th 12N-3P PDST Global Python Mtg - BerkeleyTIP - for forwarding

2009-10-18 Thread john_re
Join the global Free SW HW & Culture meeting online via VOIP & IRC. Sunday Oct 18, 12N-3P Pacific Daylight Savings Time (UTC-8), 3P-6P Eastern, (7P-10P UTC?) http://sites.google.com/site/berkeleytip/remote-attendance Or, come to the UCBerkeley Free Speech Cafe. Discuss the videos, work on your o

Re: How to check the exists of a name?

2009-10-18 Thread Steven D'Aprano
On Sat, 17 Oct 2009 23:54:37 -0700, Chris Rebert wrote: > Perhaps if you could explain why there's the possibility these variables > might not be defined... If I have to support older versions of Python: try: bin except NameError: # Define my own. def bin(arg): ... But for m

Re: The rap against "while True:" loops

2009-10-18 Thread Steven D'Aprano
On Sat, 17 Oct 2009 23:37:51 -0700, Paul Rubin wrote: > Steven D'Aprano writes: >> For the record, the four lines Paul implies are "confusing" are: >> >> try: >> d[key] += value >> except KeyError: >> d[key] = value > > Consider what happens if the computation of "key" or "value" itself

Re: The rap against "while True:" loops

2009-10-18 Thread Lie Ryan
Paul Rubin wrote: Steven D'Aprano writes: For the record, the four lines Paul implies are "confusing" are: try: d[key] += value except KeyError: d[key] = value Consider what happens if the computation of "key" or "value" itself raises KeyError. Isn't key and value just a simple var

Re: The rap against "while True:" loops

2009-10-18 Thread Paul Rubin
Hendrik van Rooyen writes: > Standard Python idiom: > > if key in d: > d[key] += value > else: > d[key] = value The issue is that uses two lookups. If that's ok, the more usual idiom is: d[key] = value + d.get(key, 0) -- http://mail.python.org/mailman/listinfo/python-list

Re: The rap against "while True:" loops

2009-10-18 Thread Ben Finney
Lie Ryan writes: > Paul Rubin wrote: > > Steven D'Aprano writes: > >> For the record, the four lines Paul implies are "confusing" are: > >> > >> try: > >> d[key] += value > >> except KeyError: > >> d[key] = value > > > > Consider what happens if the computation of "key" or "value" itself

Re: restriction on sum: intentional bug?

2009-10-18 Thread Dave Angel
Dieter Maurer wrote: Christian Heimes writes on Fri, 16 Oct 2009 17:58:29 +0200: Alan G Isaac schrieb: I expected this to be fixed in Python 3: sum(['ab','cd'],'') Traceback (most recent call last): File "", line 1, in TypeError: sum() can't sum strings [use

Re: weekdays in range

2009-10-18 Thread Dave Angel
Jive Dadson wrote: Wow. It's a danged tutorial. Thanks again. Take a break. Ben Finney's method is a very good approach, and an experienced Python programmer would consider it straightforward. But I have to ask whether the range of dates you might be considering could be large. For ex

Re: The rap against "while True:" loops

2009-10-18 Thread Steven D'Aprano
On Sat, 17 Oct 2009 13:12:52 +0100, Tim Rowe wrote: > 2009/10/17 Steven D'Aprano : > >> No, you have a fundamental misunderstanding. They're called exceptions, >> not errors, because they represent exceptional cases. Often errors are >> exceptional cases, but they're not the only sort of exceptio

Re: print()

2009-10-18 Thread mattia
Il Sat, 17 Oct 2009 10:38:55 -0400, Dave Angel ha scritto: > mattia wrote: >> Il Fri, 16 Oct 2009 22:40:34 -0700, Dennis Lee Bieber ha scritto: >> >> >>> On Fri, 16 Oct 2009 23:39:38 -0400, Dave Angel >>> declaimed the following in gmane.comp.python.general: >>> >>> >>> You're presumably tes

Re: print()

2009-10-18 Thread mattia
Il Sat, 17 Oct 2009 10:02:27 -0400, Dave Angel ha scritto: > mattia wrote: >> Il Fri, 16 Oct 2009 21:04:08 +, mattia ha scritto: >> >> >>> Is there a way to print to an unbuffered output (like stdout)? I've >>> seen that something like sys.stdout.write("hello") works but it also >>> prints the

Re: print()

2009-10-18 Thread TerryP
On Oct 18, 12:35 pm, mattia wrote: > Yes, reading the doc I've come up with > s = "%(0)03.02f%(1)s done" % {"0": 100.0-100.0*(size/tot), "1": "%"} > but to it is not a good idea to use a dict here.. Also look at the new str.format() -- http://mail.python.org/mailman/listinfo/python-list

dav caldav webdav

2009-10-18 Thread nerak99
I want to write a script to add events to a groupware calendar. I am using sogo and i have a test server tom play with. I want to be able to script a process of accessing a file of ~10^5 events into a calendaring system so that I can prepopulate a load of calendars with the users' timetables at th

Re: Tracking down DLL load errors in Windows ?

2009-10-18 Thread Fred Pacquier
Fred P said : > Hi, a bit of platform-specific advice sought here... I'm trying to > diagnose one of those mysteries Windows is so fond of... > Say that I have code that imports some binary Python module from site- > packages (in this case, libpyexiv2.pyd through pyexiv2.py, could be > anythng els

Re: More & More Fun w/ Pics & MySQL

2009-10-18 Thread Victor Subervi
Thank you all. I have __no__idea__ why the link I sent you, that you tested, __didn't__ work for me. Was it a problem with the browser? Why did it render other images fine? Strange! Well, glad it works *today*. Hopefully it'll work tomorrow, when I try and pick up a check from my client! Regarding

Re: Spawning Cmd Window via Subprocess

2009-10-18 Thread D
On Oct 16, 5:26 pm, TerryP wrote: > On Oct 16, 8:15 pm, D wrote: > > > Hello, > > > I would like to be able to spawn a new CMD window (specifing size, > > color and placement of the window),  and write to it separately. > > Specifically, I have a backup program that displays each file backed > >

Re: help to convert c++ fonction in python

2009-10-18 Thread Thomas
If you change your last line from: print s to: print u you'll get different results :) TC -- http://mail.python.org/mailman/listinfo/python-list

Re: More & More Fun w/ Pics & MySQL

2009-10-18 Thread Carsten Haese
Victor Subervi wrote: > Thank you all. I have __no__idea__ why the link I sent you, that you > tested, __didn't__ work for me. Was it a problem with the browser? My Magic 8-Ball says "Unclear. Ask again later." > Regarding Carsten's misunderstanding of my mentioning of commenting out > statements

Re: The rap against "while True:" loops

2009-10-18 Thread Lie Ryan
Ben Finney wrote: Lie Ryan writes: Paul Rubin wrote: Steven D'Aprano writes: For the record, the four lines Paul implies are "confusing" are: try: d[key] += value except KeyError: d[key] = value Consider what happens if the computation of "key" or "value" itself raises KeyError.

Re: The rap against "while True:" loops

2009-10-18 Thread Paul Rubin
Lie Ryan writes: > If key and value had been anything but simple variable/name, then > definitely you're writing the try-block the wrong way. try-block must > be kept as simple as possible. Avoiding the try-block completely is the simplest possibility of them all. -- http://mail.python.org/mailm

[ANN] Python(x,y) 2.6.3.0 released

2009-10-18 Thread Pierre Raybaut
Hi all, I'm quite pleased (and relieved) to announce that Python(x,y) version 2.6.3.0 has been released. It is the first release based on Python 2.6 -- note that Python(x,y) version number will now follow the included Python version (Python(x,y) vX.Y.Z.N will be based on Python vX.Y.Z). Pyth

[ANN] Spyder v1.0.0 released

2009-10-18 Thread Pierre Raybaut
Hi all, I'm pleased to announce here that Spyder version 1.0.0 has been released: http://packages.python.org/spyder Previously known as Pydee, Spyder (Scientific PYthon Development EnviRonment) is a free open-source Python development environment providing MATLAB-like features in a simple and li

Re: help to convert c++ fonction in python

2009-10-18 Thread Lie Ryan
Thomas wrote: If you change your last line from: print s to: print u you'll get different results :) if you change: s1 = base64.b64decode( s ) into s = base64.b64decode( s ) you'll get the same result again. -- http://mail.python.org/mailman/listinfo/python-list

problem with re.MULTILINE

2009-10-18 Thread Necronymouse
Hello i ´ve got a little problem: I ´ve this text: http://openpaste.org/en/secret/17343/pass-python and I need to parse it. So i wrote this: >>> patternNode = re.compile(""" # Node (\w*).* (.*)""", re.MULTILINE) with open("test.msg", "r") as file: testData = file.read() for Node in re.finda

(from stdlib-sig) ctypes or struct from an h file

2009-10-18 Thread Yuvgoog Greenle
Is there a way that Python and C can have a shared definition for a binary data structure? It could be nice if: 1. struct or ctypes had a function that could parse a .h/.c/.cpp file to auto-generate constructors or 2. a ctypes definition could be exported to a .h file. So my question is - is ther

Re: problem with re.MULTILINE

2009-10-18 Thread MRAB
Necronymouse wrote: Hello i ´ve got a little problem: I ´ve this text: http://openpaste.org/en/secret/17343/pass-python and I need to parse it. So i wrote this: patternNode = re.compile(""" # Node (\w*).* (.*)""", re.MULTILINE) with open("test.msg", "r") as file: testData = file.read() fo

Re: More & More Fun w/ Pics & MySQL

2009-10-18 Thread Lie Ryan
Carsten Haese wrote: Victor Subervi wrote: Thank you all. I have __no__idea__ why the link I sent you, that you tested, __didn't__ work for me. Was it a problem with the browser? My Magic 8-Ball says "Unclear. Ask again later." Regarding Carsten's misunderstanding of my mentioning of comment

Re: (from stdlib-sig) ctypes or struct from an h file

2009-10-18 Thread geremy condra
On Sun, Oct 18, 2009 at 2:44 PM, Yuvgoog Greenle wrote: > Is there a way that Python and C can have a shared definition for a > binary data structure? > > It could be nice if: > 1. struct or ctypes had a function that could parse a .h/.c/.cpp file > to auto-generate constructors > or > 2. a ctypes

Re: The rap against "while True:" loops

2009-10-18 Thread NiklasRTZ
Russ P. wrote: > On Oct 10, 1:15pm, kj wrote: > > I'm coaching a group of biologists on basic Python scripting. One > > of my charges mentioned that he had come across the advice never > > to use loops beginning with "while True". Of course, that's one > > way to start an infinite loop, but thi

Re: problem with re.MULTILINE

2009-10-18 Thread Necronymouse
On 18 říj, 21:20, MRAB wrote: > Necronymouse wrote: > > Hello i ´ve got a little problem: I ´ve this text: > >http://openpaste.org/en/secret/17343/pass-pythonand I need to parse > > it. So i wrote this: > > > patternNode = re.compile(""" > > # Node (\w*).* > > (.*)""", re.MULTILINE) > > > with ope

Capturing a var from JavaScript

2009-10-18 Thread Victor Subervi
Hi; I have the following code: #!/usr/bin/python def getResolution(): print 'Content-Type: text/html\n' print ''' http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd'> var winX = screen.width; var winY = screen.height; ''' x = eval('document.write(winX)') #document.write('Your screen re

Re: (from stdlib-sig) ctypes or struct from an h file

2009-10-18 Thread Diez B. Roggisch
Yuvgoog Greenle schrieb: Is there a way that Python and C can have a shared definition for a binary data structure? It could be nice if: 1. struct or ctypes had a function that could parse a .h/.c/.cpp file to auto-generate constructors or 2. a ctypes definition could be exported to a .h file.

Re: (from stdlib-sig) ctypes or struct from an h file

2009-10-18 Thread Yuvgoog Greenle
I'd like to clarify the use case. Lets say you're writing a client and a server, one is in python and the other is C. If these 2 programs need to pass binary information between them (lets say over a socket) there are 2 options, it could be nice if you could only write the struct once (either in p

Re: (from stdlib-sig) ctypes or struct from an h file

2009-10-18 Thread geremy condra
On Sun, Oct 18, 2009 at 4:13 PM, Diez B. Roggisch wrote: > Yuvgoog Greenle schrieb: >> >> Is there a way that Python and C can have a shared definition for a >> binary data structure? >> >> It could be nice if: >> 1. struct or ctypes had a function that could parse a .h/.c/.cpp file >> to auto-gen

[ANN] "Python for Bioinformatics" available and in stock

2009-10-18 Thread Sebastian Bassi
I announced that Python for Bioinformatics was ready, now I want to announce that is available and in stock in most book sellers. Worldwide, use Amazon. In Argentina, it is more convenient buying it from me at MercadoLibre: http://articulo.mercadolibre.com.ar/MLA-64715574-libro-python-for-bioinform

Re: (from stdlib-sig) ctypes or struct from an h file

2009-10-18 Thread Diez B. Roggisch
geremy condra schrieb: On Sun, Oct 18, 2009 at 4:13 PM, Diez B. Roggisch wrote: Yuvgoog Greenle schrieb: Is there a way that Python and C can have a shared definition for a binary data structure? It could be nice if: 1. struct or ctypes had a function that could parse a .h/.c/.cpp file to aut

Re: Spawning Cmd Window via Subprocess

2009-10-18 Thread Gabriel Genellina
En Sun, 18 Oct 2009 14:22:07 -0200, D escribió: On Oct 16, 5:26 pm, TerryP wrote: On Oct 16, 8:15 pm, D wrote: > I would like to be able to spawn a new CMD window (specifing size, > color and placement of the window),  and write to it separately. > Specifically, I have a backup program that

Re: (from stdlib-sig) ctypes or struct from an h file

2009-10-18 Thread exarkun
On 08:13 pm, de...@nospam.web.de wrote: Yuvgoog Greenle schrieb: Is there a way that Python and C can have a shared definition for a binary data structure? It could be nice if: 1. struct or ctypes had a function that could parse a .h/.c/.cpp file to auto-generate constructors or 2. a ctypes def

Re: (from stdlib-sig) ctypes or struct from an h file

2009-10-18 Thread Erik Max Francis
Yuvgoog Greenle wrote: I'd like to clarify the use case. Lets say you're writing a client and a server, one is in python and the other is C. If these 2 programs need to pass binary information between them (lets say over a socket) there are 2 options, it could be nice if you could only write the

Re: slicing return iter?

2009-10-18 Thread Gabriel Genellina
En Sun, 18 Oct 2009 03:02:27 -0200, StarWing escribió: On 10月18日, 上午9时09分, Raymond Hettinger wrote: [StarWing] > > > sometimes I want to iterate a part of a sequence. but don't want to > > > copy it. i.e. . . . > I had checked it for serval times. maybe it's my inattention :-(. but > w

Reverse Iteration Through Integers

2009-10-18 Thread Benjamin Middaugh
I'm trying to make an integer that is the reverse of an existing integer such that 169 becomes 961. I guess I don't know enough yet to figure out how to do this without a ton of awkward-looking code. I've tried for loops without much success. I guess I need a good way of figuring out the length

Re: Reverse Iteration Through Integers

2009-10-18 Thread Lie Ryan
Benjamin Middaugh wrote: I'm trying to make an integer that is the reverse of an existing integer such that 169 becomes 961. I guess I don't know enough yet to figure out how to do this without a ton of awkward-looking code. I've tried for loops without much success. I guess I need a good way o

Re: Reverse Iteration Through Integers

2009-10-18 Thread Rhodri James
On Sun, 18 Oct 2009 19:34:09 +0100, Benjamin Middaugh wrote: I'm trying to make an integer that is the reverse of an existing integer such that 169 becomes 961. I guess I don't know enough yet to figure out how to do this without a ton of awkward-looking code. I've tried for loops withou

Re: Reverse Iteration Through Integers

2009-10-18 Thread Christian Heimes
Benjamin Middaugh schrieb: > I'm trying to make an integer that is the reverse of an existing integer > such that 169 becomes 961. I guess I don't know enough yet to figure out > how to do this without a ton of awkward-looking code. I've tried for > loops without much success. I guess I need a g

Re: How about adding slice notation to iterators/generators?

2009-10-18 Thread Eloff
On Oct 16, 7:38 pm, Carl Banks wrote: > You would burden everyone who writes a custom iterator to provide a > __getitem__ method just because you're too lazy to type out the word > islice? No, of course not. That would be stupid. Custom iterators are iterators, so they would also get the default

Re: Reverse Iteration Through Integers

2009-10-18 Thread Paul Rubin
Benjamin Middaugh writes: > I'm trying to make an integer that is the reverse of an existing > integer such that 169 becomes 961. I guess I don't know enough yet to > figure out how to do this without a ton of awkward-looking code. I've > tried for loops without much success. I guess I need a good

Re: print()

2009-10-18 Thread Gabriel Genellina
En Sun, 18 Oct 2009 10:35:34 -0200, mattia escribió: Il Sat, 17 Oct 2009 10:02:27 -0400, Dave Angel ha scritto: mattia wrote: Il Fri, 16 Oct 2009 21:04:08 +, mattia ha scritto: Another question (always py3). How can I print only the first number after the comma of a division? e.g. print(

Checking a Number for Palindromic Behavior

2009-10-18 Thread Benjamin Middaugh
Thanks to everyone who helped with my query on reversing integers. I have one more simple problem I'm having trouble solving. I want to check a number for palindromic behavior (reading the same backwards and forwards). So if I have an integer 1457 it can tell me this is not the same from both e

Re: Reverse Iteration Through Integers

2009-10-18 Thread MRAB
Benjamin Middaugh wrote: I'm trying to make an integer that is the reverse of an existing integer such that 169 becomes 961. I guess I don't know enough yet to figure out how to do this without a ton of awkward-looking code. I've tried for loops without much success. I guess I need a good way o

Re: print()

2009-10-18 Thread mattia
Il Sun, 18 Oct 2009 20:04:11 -0200, Gabriel Genellina ha scritto: > En Sun, 18 Oct 2009 10:35:34 -0200, mattia escribió: > >> Il Sat, 17 Oct 2009 10:02:27 -0400, Dave Angel ha scritto: >>> mattia wrote: Il Fri, 16 Oct 2009 21:04:08 +, mattia ha scritto: Another question (alway

Re: Checking a Number for Palindromic Behavior

2009-10-18 Thread MRAB
Benjamin Middaugh wrote: Thanks to everyone who helped with my query on reversing integers. I have one more simple problem I'm having trouble solving. I want to check a number for palindromic behavior (reading the same backwards and forwards). So if I have an integer 1457 it can tell me this is

Re: More & More Fun w/ Pics & MySQL

2009-10-18 Thread Gabriel Genellina
En Fri, 16 Oct 2009 16:23:31 -0300, Victor Subervi escribió: This will print all sorts of crap to the screen. I know it's an image, because for some reason "occasionally" it once upon a time today printed the actual image to the screen when I had these lines last:[...] Notice the commented

Frameworks

2009-10-18 Thread flebber
Hi I have been searching through the vast array of python frameworks http://wiki.python.org/moin/WebFrameworks and its quite astounding the choice available. I am looking at using a web framework for my personal project which isn't actually aimed at developing a website as such. However I deduce

Re: Checking a Number for Palindromic Behavior

2009-10-18 Thread Gary Herron
Benjamin Middaugh wrote: Thanks to everyone who helped with my query on reversing integers. I have one more simple problem I'm having trouble solving. I want to check a number for palindromic behavior (reading the same backwards and forwards). So if I have an integer 1457 it can tell me this is

Re: restriction on sum: intentional bug?

2009-10-18 Thread Ethan Furman
Dave Angel wrote: Dieter Maurer wrote: Christian Heimes writes on Fri, 16 Oct 2009 17:58:29 +0200: Alan G Isaac schrieb: I expected this to be fixed in Python 3: sum(['ab','cd'],'') Traceback (most recent call last): File "", line 1, in TypeError: sum() ca

Re: Tracking down DLL load errors in Windows ?

2009-10-18 Thread Mark Tolonen
"Fred Pacquier" wrote in message news:xns9ca8b91a1519apacmanr...@212.27.60.38... After installing the MS redistributable DLL package -- actually I had to install *three* before hitting the right one (2005SP1) -- libpyexiv2 finally loads all its dependencies. Of course I've still no idea why/

Re: How about adding slice notation to iterators/generators?

2009-10-18 Thread Gabriel Genellina
En Sun, 18 Oct 2009 19:53:20 -0200, Eloff escribió: On Oct 16, 7:38 pm, Carl Banks wrote: You would burden everyone who writes a custom iterator to provide a __getitem__ method just because you're too lazy to type out the word islice? No, of course not. That would be stupid. Custom iterato

Re: How about adding slice notation to iterators/generators?

2009-10-18 Thread Carl Banks
On Oct 18, 2:53 pm, Eloff wrote: > On Oct 16, 7:38 pm, Carl Banks wrote: > > > You would burden everyone who writes a custom iterator to provide a > > __getitem__ method just because you're too lazy to type out the word > > islice? > > No, of course not. That would be stupid. Custom iterators are

Re: restriction on sum: intentional bug?

2009-10-18 Thread Carl Banks
On Oct 18, 4:07 pm, Ethan Furman wrote: > Dave Angel wrote: > > Earlier, I would have agreed with you.  I assumed that this could be > > done invisibly, with the only difference being performance.  But you > > can't know whether join will do the trick without error till you know > > that all the i

Re: slicing return iter?

2009-10-18 Thread Raymond Hettinger
[Raymond] > > If it really is a sequence (with len and getitem), you can write your > > own indexing iterator: > > >   def myslice(seq, start, stop, step): > >        'Allow forward or backwards iteration over a subslice' > >        for i in range(start, stop, step): > >            yield seq[i] [S

Python 2.6.4rc2

2009-10-18 Thread Barry Warsaw
Hello everyone. The source tarballs and Windows installers for Python 2.6.4rc2 are now available: http://www.python.org/download/releases/2.6.4/ Please download them, install them, and try to use them with your projects and environments. Let's make 2.6.4 a rock solid release! If there

Re: Reverse Iteration Through Integers

2009-10-18 Thread Mick Krippendorf
Paul Rubin wrote: > Yet another way is to use recursion. I'll leave that as an exercise too. This time with big numbers: def trampoline(bouncing, *args, **kwargs): while bouncing: result, bouncing, args, kwargs = bouncing(*args, **kwargs) if result: return result

Re: Checking a Number for Palindromic Behavior

2009-10-18 Thread rurpy
On Oct 18, 4:20 pm, MRAB wrote: > Benjamin Middaugh wrote: > > Thanks to everyone who helped with my query on reversing integers. I > > have one more simple problem I'm having trouble solving. I want to check > > a number for palindromic behavior (reading the same backwards and > > forwards). So i

Re: restriction on sum: intentional bug?

2009-10-18 Thread Ethan Furman
Carl Banks wrote: On Oct 18, 4:07 pm, Ethan Furman wrote: Dave Angel wrote: Earlier, I would have agreed with you. I assumed that this could be done invisibly, with the only difference being performance. But you can't know whether join will do the trick without error till you know that all

Re: slicing return iter?

2009-10-18 Thread Gabriel Genellina
En Sun, 18 Oct 2009 23:07:40 -0200, Raymond Hettinger escribió: [Raymond] > If it really is a sequence (with len and getitem), you can write your > own indexing iterator: >   def myslice(seq, start, stop, step): >        'Allow forward or backwards iteration over a subslice' >        for i in

Re: SimpleXMLRPCServer clobbering sys.stderr? (2.5.2)

2009-10-18 Thread Joseph Turian
> > I was having a mysterious problem with SimpleXMLRPCServer. (I am using > > Python 2.5.2) > > I'd start updating Python to the latest 2.5 release: 2.5.4 Ubuntu doesn't have 2.5.4. :( > > The request handlers were sometimes failing without any error message > > to the log output. > > > What I d

Re: SimpleXMLRPCServer clobbering sys.stderr? (2.5.2)

2009-10-18 Thread Joseph Turian
> Here's what I see: > * If I use logging to write the output, I don't see any output in the > server log, but the client gets correct results. > * If I use sys.stderrto write the output, I don't see any output in > the server log AND the client gets INcorrect results. > * If I use sys.stdout to w

Re: restriction on sum: intentional bug?

2009-10-18 Thread Steven D'Aprano
On Sun, 18 Oct 2009 19:52:41 -0700, Ethan Furman wrote: > This is obviously slow on strings, but mention of that is already in the > docs, and profiling will also turn up such bottlenecks. Get the code > working first, then optimize, yes? Well, maybe. Premature optimization and all, but someti

Re: python along or bash combined with python (for manipulating files)

2009-10-18 Thread Peng Yu
On Tue, Oct 13, 2009 at 11:18 PM, TerryP wrote: > On Oct 14, 2:13 am, Peng Yu wrote: >> Bash is easy to use on manipulating files and directories (like change >> name or create links, etc) and on calling external programs. For >> simple functions, bash along is enough. However, bash does not supp

Re: Checking a Number for Palindromic Behavior

2009-10-18 Thread alex23
On Oct 19, 12:32 pm, ru...@yahoo.com wrote: > On Oct 18, 4:20 pm, MRAB wrote: > > > Benjamin Middaugh wrote: > > > Thanks to everyone who helped with my query on reversing integers. I > > > have one more simple problem I'm having trouble solving. I want to check > > > a number for palindromic beha

Re: Frameworks

2009-10-18 Thread flebber
On Oct 19, 10:01 am, flebber wrote: > Hi > > I have been searching through the vast array of python > frameworkshttp://wiki.python.org/moin/WebFrameworksand its quite astounding > the > choice available. > > I am looking at using a web framework for my personal project which > isn't actually aim

Re: Checking a Number for Palindromic Behavior

2009-10-18 Thread rurpy
On Oct 18, 9:45 pm, alex23 wrote: > On Oct 19, 12:32 pm, ru...@yahoo.com wrote: > > On Oct 18, 4:20 pm, MRAB wrote: > > > Benjamin Middaugh wrote: > > > > Thanks to everyone who helped with my query on reversing integers. I > > > > have one more simple problem I'm having trouble solving. I want t

Re: Reverse Iteration Through Integers

2009-10-18 Thread Jabba Laci
Hi, Would someone explain how str[::-1] work? I'm new to Python and I only saw so far the str[begin:end] notation. What is the second colon? Thanks, Laszlo > Here is a simplistic version that doesn't use fancy math: > str(24) > '24' str(24)[::-1] > '42' int(str(24)[::-1]) > 42 --

Re: Checking a Number for Palindromic Behavior

2009-10-18 Thread alex23
ru...@yahoo.com wrote: > One, it was suggested without any evidence the the OP was > "probably" asking about homework.  My observation over > several years is that this group has a very poor record > of identifying homework problems.  And if someone can > conclude that the OPs problem was homework

Re: Reverse Iteration Through Integers

2009-10-18 Thread Chris Rebert
On Sun, Oct 18, 2009 at 10:53 PM, Jabba Laci wrote: > Hi, > > Would someone explain how str[::-1] work? I'm new to Python and I only > saw so far the str[begin:end] notation. What is the second colon? Specifies the step value, as in: foo[start:stop:step] When not specified it, defaults to 1. S

Re: Reverse Iteration Through Integers

2009-10-18 Thread alex23
On Oct 19, 3:53 pm, Jabba Laci wrote: > Would someone explain how str[::-1] work? I'm new to Python and I only > saw so far the str[begin:end] notation. What is the second colon? Slice notation is of the form [start:stop:step]. start defaults to the start of the sequence, stop to the end, and ste

Re: Reverse Iteration Through Integers

2009-10-18 Thread alex23
alex23 wrote: > The only mention I could find was > http://docs.python.org/dev/3.0/library/functions.html#slice No idea why that link was the one that came up, this is more appropriate: http://docs.python.org/3.1/library/functions.html#slice -- http://mail.python.org/mailman/listinfo/python-l

Re: help to convert c++ fonction in python

2009-10-18 Thread Tim Roberts
You wrote: > >For the love of baby kittens, please, please, please tell me that >you do not believe this securely encrypts your data. The original poster asked to have two C++ functions converted to Python. That's what I did, using the same names as the original. I neither know nor care how th

Re: The rap against "while True:" loops

2009-10-18 Thread Hendrik van Rooyen
On Sunday, 18 October 2009 11:31:19 Paul Rubin wrote: > Hendrik van Rooyen writes: > > Standard Python idiom: > > > > if key in d: > > d[key] += value > > else: > > d[key] = value > > The issue is that uses two lookups. If that's ok, the more usual idiom is: > > d[key] = value + d.get(key,