Re: [Tutor] Character Buffer Object Error

2012-02-07 Thread Asokan Pichai
Dear Michael Overall I see a few problems. 0. Functions should return values. Not print them 1. Why use enumerate? The code is not using the index anyway 2. The following line appears wrong. new_output = ' '.join(user_input) 3. This line has a very buggy possibility.

Re: [Tutor] Character Buffer Object Error

2012-02-07 Thread Christian Witts
On 2012/02/08 07:56 AM, Michael Lewis wrote: I want to find all digits in a string and then increment those digits by 1 and then return the same string with the incremented digits. I've tried the following code, but I am getting the following error. How do I do this properly? def AlterInput(

[Tutor] Character Buffer Object Error

2012-02-07 Thread Michael Lewis
I want to find all digits in a string and then increment those digits by 1 and then return the same string with the incremented digits. I've tried the following code, but I am getting the following error. How do I do this properly? def AlterInput(user_input): print user_input new_output =

Re: [Tutor] Tutor Digest, Vol 96, Issue 26

2012-02-07 Thread Alan Gauld
On 07/02/12 19:45, Michael Lewis wrote: As the instructions in the message you posted say... When replying, please edit your Subject line so it is more specific than "Re: Contents of Tutor digest..." And also please delete all the irrelevant stuff, it's almost impossible to spot the

Re: [Tutor] dictionary of methods calling syntax

2012-02-07 Thread Alan Gauld
On 07/02/12 19:32, Gregory, Matthew wrote: class Statistics(object): STAT = { 'MEAN': get_mean, 'SUM': get_sum, } ... if __name__ == '__main__': spam = Statistics(4, 3) print spam.get_stat('mean') print spam.get_stat('sum') Since a class is effect

Re: [Tutor] dictionary of methods calling syntax

2012-02-07 Thread Joel Goldstick
On Tue, Feb 7, 2012 at 2:32 PM, Gregory, Matthew wrote: > Hi list, > > I'm trying to understand how to use a class-level dictionary to act as a > switch for class methods.  In the contrived example below, I have the > statistic name as the key and the class method as the value. > > class Statist

Re: [Tutor] Tutor Digest, Vol 96, Issue 26

2012-02-07 Thread Michael Lewis
On Tue, Feb 7, 2012 at 10:57 AM, wrote: > Send Tutor mailing list submissions to >tutor@python.org > > To subscribe or unsubscribe via the World Wide Web, visit >http://mail.python.org/mailman/listinfo/tutor > or, via email, send a message with subject or body 'help' to >t

[Tutor] dictionary of methods calling syntax

2012-02-07 Thread Gregory, Matthew
Hi list, I'm trying to understand how to use a class-level dictionary to act as a switch for class methods. In the contrived example below, I have the statistic name as the key and the class method as the value. class Statistics(object): STAT = { 'MEAN': get_mean, 'SUM': ge

Re: [Tutor] (no subject)

2012-02-07 Thread bob gailer
Do Not Use (no subject) as a subject! Read the manual before asking questions like this. If you do not understand the documentation tell us what you do not understand. On 2/7/2012 1:50 PM, Debashish Saha wrote: for i in range(1, 8): print(i) if i==3: break else: print

Re: [Tutor] Question on how to do exponents

2012-02-07 Thread bob gailer
On 2/7/2012 1:57 PM, Sarma Tangirala wrote: Anyway, I was wondering about this, if internally pow() actually uses **. :P >>> from dis import dis >>> dis(lambda a,b:a**b) 1 0 LOAD_FAST0 (a) 3 LOAD_FAST1 (b) 6 BINARY_POWE

Re: [Tutor] Backspace Escape Sequence; \b

2012-02-07 Thread Peter Otten
Steven D'Aprano wrote: > Peter Otten wrote: >> Garland W. Binns wrote: >> >>> Could someone please tell me a common or semi-frequent scenario in which >>> a person would use a backspace escape sequence? >> >> Does >> >> $ python -c 'print "this is b\bbo\bol\bld\bd"' | less >> >> qualify? If yo

[Tutor] For/Else loops

2012-02-07 Thread Jerry Hill
On Tue, Feb 7, 2012 at 1:50 PM, Debashish Saha wrote: > for i in range(1, 8): >    print(i) >    if i==3: >        break > else: >    print('The for loop is over') > > >  Output: > 1 > 2 > 3 > > Question:but after breaking the for loop why the else command could not work? Because that's the way a

Re: [Tutor] Question on how to do exponents

2012-02-07 Thread Dave Angel
On 02/07/2012 01:57 PM, Sarma Tangirala wrote: On 8 February 2012 00:01, Steven D'Aprano wrote: Sarma Tangirala wrote: Is is better to use pow() against **? Advantages of ** - it is shorter to type x**y vs pow(x, y) - being an operator, it is slightly faster than calling a function - you

Re: [Tutor] (no subject)

2012-02-07 Thread Hugo Arts
On Tue, Feb 7, 2012 at 7:50 PM, Debashish Saha wrote: > for i in range(1, 8): >    print(i) >    if i==3: >        break > else: >    print('The for loop is over') > > >  Output: > 1 > 2 > 3 > > Question:but after breaking the for loop why the else command could not work? > because the else state

Re: [Tutor] confusion with else command

2012-02-07 Thread Peter Otten
Debashish Saha wrote: > for i in range(1, 8): > print(i) > if i==3: > break > else: > print('The for loop is over') > Output: > 1 > 2 > 3 > > Question: > > but after breaking the for loop why the else loop could not work? The else suite is not invoked because that's the way

Re: [Tutor] confusion with else command

2012-02-07 Thread Dave Angel
On 02/07/2012 01:52 PM, Debashish Saha wrote: for i in range(1, 8): print(i) if i==3: break else: print('The for loop is over') Output: 1 2 3 Question: but after breaking the for loop why the else loop could not work? It works fine. The else clause of a for loop exe

Re: [Tutor] Question on how to do exponents

2012-02-07 Thread Sarma Tangirala
On 8 February 2012 00:01, Steven D'Aprano wrote: > Sarma Tangirala wrote: > > Is is better to use pow() against **? >> > > > Advantages of ** > > - it is shorter to type x**y vs pow(x, y) > - being an operator, it is slightly faster than calling a function > - you can't monkey-patch it > > Disad

[Tutor] confusion with else command

2012-02-07 Thread Debashish Saha
for i in range(1, 8): print(i) if i==3: break else: print('The for loop is over') Output: 1 2 3 Question: but after breaking the for loop why the else loop could not work? ___ Tutor maillist - Tutor@python.org To unsubscribe or c

[Tutor] (no subject)

2012-02-07 Thread Debashish Saha
for i in range(1, 8): print(i) if i==3: break else: print('The for loop is over') Output: 1 2 3 Question:but after breaking the for loop why the else command could not work? ___ Tutor maillist - Tutor@python.org To unsubscribe or

Re: [Tutor] Backspace Escape Sequence; \b

2012-02-07 Thread Alan Gauld
On 07/02/12 17:19, Garland W. Binns wrote: Could someone please tell me a common or semi-frequent scenario in which a person would use a backspace escape sequence? Do you mean backspace specifically or do you really mean backslash? In other words are you looking for a use of literal backspaces

Re: [Tutor] Question on how to do exponents

2012-02-07 Thread Steven D'Aprano
Sarma Tangirala wrote: Is is better to use pow() against **? Advantages of ** - it is shorter to type x**y vs pow(x, y) - being an operator, it is slightly faster than calling a function - you can't monkey-patch it Disadvantages of ** - being an operator, you can't directly use it as a fun

Re: [Tutor] Question on how to do exponents

2012-02-07 Thread Alan Gauld
On 07/02/12 16:54, Sarma Tangirala wrote: Is is better to use pow() against **? I suspect ** will be faster since it doesn't have the function call overhead. But I haven't tried timing it. Feel free to do some tests and find out. Let us know how you get on! -- Alan G Author of the Learn to

Re: [Tutor] Backspace Escape Sequence; \b

2012-02-07 Thread Steven D'Aprano
Peter Otten wrote: Garland W. Binns wrote: Could someone please tell me a common or semi-frequent scenario in which a person would use a backspace escape sequence? Does $ python -c 'print "this is b\bbo\bol\bld\bd"' | less qualify? If you are using (e. g.) Linux this technique is used to sh

Re: [Tutor] Backspace Escape Sequence; \b

2012-02-07 Thread Peter Otten
Garland W. Binns wrote: > Could someone please tell me a common or semi-frequent scenario in which a > person would use a backspace escape sequence? Does $ python -c 'print "this is b\bbo\bol\bld\bd"' | less qualify? If you are using (e. g.) Linux this technique is used to show some text in bo

[Tutor] Backspace Escape Sequence; \b

2012-02-07 Thread Garland W. Binns
Could someone please tell me a common or semi-frequent scenario in which a person would use a backspace escape sequence? Thanks, Garland -- Sent via Mobile ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http:

Re: [Tutor] Backwards message program

2012-02-07 Thread Joel Goldstick
On Tue, Feb 7, 2012 at 5:41 AM, Steven D'Aprano wrote: > myles broomes wrote: >> >> Im trying to code a program where the user enters a message and it is >> returned backwards. Here is my code so far: >>  message = input("Enter your message: ") >>  backw = "" >> counter = len(message) >> while mes

Re: [Tutor] Question on how to do exponents

2012-02-07 Thread Sarma Tangirala
On 7 February 2012 13:49, Alan Gauld wrote: > On 07/02/12 01:01, Nate Lastname wrote: > >> Exponents ... are **(or ^) >> > > Not quite the ^ operator is a bitwise XOR... > > >>> 2^2 > 0 > >>> 2^1 > 3 > > pow() is the other way to do exponents. > > Is is better to use pow() against **? > -- > Al

Re: [Tutor] decimal precision in python

2012-02-07 Thread Steve Willoughby
On 07-Feb-12 03:15, Steven D'Aprano wrote: Steve Willoughby wrote: If you need lots of precision, you might consider using the decimal class. It'll cost you speed vs. the native floating-point type but won't cause you round-off errors. I'm afraid that's not correct. Decimal is still subject to

Re: [Tutor] decimal precision in python

2012-02-07 Thread Steven D'Aprano
Col, I think you wrote to me personally by accident, instead of to the Tutor list. Nothing you said seems to be private, so I've taken the liberty of answering back on the list. col speed wrote: Just an idea - I'm not an expert by any means, just a dabbler, but: many years ago, when I was l

Re: [Tutor] decimal precision in python

2012-02-07 Thread Steven D'Aprano
Steve Willoughby wrote: On 06-Feb-12 07:25, Kapil Shukla wrote: i tried writing a small code to calculate option price using the binomial tree model. I compared my results with results of the same program in excel. There seems to be a minor difference due to decimal precision as excel is using 1

Re: [Tutor] Backwards message program

2012-02-07 Thread Steven D'Aprano
myles broomes wrote: Im trying to code a program where the user enters a message and it is returned backwards. Here is my code so far: message = input("Enter your message: ") backw = "" counter = len(message) while message != 0: backw += message[counter-1] counter -= 1 print(backw

[Tutor] Rép. : Re: Issue with a shapefile (ArcGIS) library (pyshp) "unpack requires a string argument of length 8"

2012-02-07 Thread Simeon Tesfaye
I just realized my first email was not very self explanatory, so let me start over. My system is Windows XP Professional, with Python 2.5, and the library I'm experiencing trouble with is pyshp, available (single version for all systems) here : http://code.google.com/p/pyshp/ Here is the corre

Re: [Tutor] Question on how to do exponents

2012-02-07 Thread Alan Gauld
On 07/02/12 01:01, Nate Lastname wrote: Exponents ... are **(or ^) Not quite the ^ operator is a bitwise XOR... >>> 2^2 0 >>> 2^1 3 pow() is the other way to do exponents. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/