Re: [Tutor] Tutor Digest, Vol 71, Issue 62

2010-01-24 Thread Kwaku Nuamah
ing use the >> join() >> method of a string using an empty string:print ''.join([str(s) for s in >> y])However this is an unusual way to print this type of output,It would be >> more normal to use a format string:print "Variable2: %f id greater than >> Variable1: %f." % (var1,var2)This reduces the numbe

Re: [Tutor] The magic parentheses

2010-01-24 Thread David Hutto
Re: [Tutor] The magic parentheses Sunday, January 24, 2010 9:28 PM From: "David Hutto" Add sender to Contacts To: "Alan Gauld" --- On Sun, 1/24/10, Alan Gauld wrote: > From: Alan Gauld > Subject: Re: [Tutor] The magic parentheses > To: tutor@python.org > Date: Sunday, January 24, 2010, 8:06

[Tutor] Updated topic on my tutorial

2010-01-24 Thread Alan Gauld
I don't normally announce new toppics as I translate them to v3 however I've done quite a bit of rework/expansion to my OOP topic, including adding some basic stuff about UML diagrams. I'm interested in any feedback, especially whether the UML helps or hinders understanding! And of course any e

Re: [Tutor] The magic parentheses

2010-01-24 Thread Alan Gauld
"Lie Ryan" wrote and used print, I thought they would be considered the same whether as a variable, or as a direct line, guess not. what is equivalent: print (a, b, c) and x = a, b, c print x both construct a tuple and prints a,b,c as tuple Not quite: a = 1 b = 2 c = 3 x = a,b,c print

Re: [Tutor] The magic parentheses

2010-01-24 Thread Lie Ryan
On 01/24/10 19:17, David Hutto wrote: > Thanks > for the solutions and the quick responses. I just removed the variable > and used print, I thought they would be considered the same whether as > a variable, or as a direct line, guess not. > what is equivalent: print (a, b, c) and x = a, b, c pr

Re: [Tutor] The magic parentheses

2010-01-24 Thread Kent Johnson
On Sun, Jan 24, 2010 at 12:08 PM, Alan Gauld wrote: > > "Hugo Arts" wrote > > print "this is {0}".format("formatted") >> >> this is formatted > > Caveat: > this style only works in Python 3.0 upwards  (or maybe in 2.6/2.7?) It's in 2.6 http://docs.python.org/library/stdtypes.html#str.for

Re: [Tutor] Is it pythonesque

2010-01-24 Thread Robert Berman
Thank you for the snippet and the insight. Robert -Original Message- From: tutor-bounces+bermanrl=cfl.rr@python.org [mailto:tutor-bounces+bermanrl=cfl.rr@python.org] On Behalf Of Alan Gauld Sent: Sunday, January 24, 2010 12:17 PM To: tutor@python.org Subject: Re: [Tutor] Is it py

Re: [Tutor] Is it pythonesque

2010-01-24 Thread Alan Gauld
"Robert Berman" wrote def getuserinput(): while True: s1 = raw_input('Enter fraction as N,D or 0,0 to exit>>') delim = s1.find(',') if delim < 0: print 'invalid user input' else: n = int(s1[0:delim]) d = int(s1[delim+1::])

Re: [Tutor] The magic parentheses

2010-01-24 Thread Alan Gauld
"Hugo Arts" wrote print "this is {0}".format("formatted") this is formatted Caveat: this style only works in Python 3.0 upwards (or maybe in 2.6/2.7?) Alan G. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription option

Re: [Tutor] Is it pythonesque

2010-01-24 Thread शंतनू
If the input has more than one ',', e.g. '1,2,3'. You may like to use 'split' function, and avoid find. On 24-Jan-2010, at 9:43 PM, Robert Berman wrote: > Good morning, > > Given the following code snippets: > > def getuserinput(): > while True: > s1 = raw_input('Enter fraction a

[Tutor] Is it pythonesque

2010-01-24 Thread Robert Berman
Good morning, Given the following code snippets: def getuserinput(): while True: s1 = raw_input('Enter fraction as N,D or 0,0 to exit>>') delim = s1.find(',') if delim < 0: print 'invalid user input' else: n = int(s1[0:delim

Re: [Tutor] The magic parentheses

2010-01-24 Thread Shashwat Anand
@David, Alan and rest have clarified your doubt I guess. However let me point you towards some other mistakes. def area1(radius): area1r = 3.14159 * mainvar1**2 return area1r print area1r def area2(radius): area2r = 3.14159 * mainvar2**2 return area2r print area2r Here y

Re: [Tutor] The magic parentheses

2010-01-24 Thread David Hutto
Thanks for the solutions and the quick responses. I just removed the variable and used print, I thought they would be considered the same whether as  a variable, or as a direct line, guess not. Thanks again, David ___ Tutor maillist - Tutor@py