Re: [Tutor] Swapping variables ...

2007-11-11 Thread wesley chun
On 11/10/07, O.R.Senthil Kumaran <[EMAIL PROTECTED]> wrote: > > After quizzing newbies in C on swapping without 3rd variable, I found this > > to be really *cool* construct to swap :) > > x = 10 > > y = 20 > > x,y = y,x > > Keep in mind that, this is actually a tuple assignment. > A new tuple x,y

Re: [Tutor] assignment question

2007-11-11 Thread Jeff Younker
Append modifies the array as a side effect. It has no meaningful return value. >>> x = [1, 2, 3] >>> x.append(4) >>> print x [1, 2, 3, 4] - Jeff Younker - [EMAIL PROTECTED] - 510.798.5804 - On Nov 11, 2007, at 8:21 PM, Ryan Hughes wrote: Hello, Why does the following not return [1,2,3,4]

Re: [Tutor] assignment question

2007-11-11 Thread Steve Willoughby
Ryan Hughes wrote: > Hello, > > Why does the following not return [1,2,3,4] ? > x = [1,2,3].append(4) print x > None because the append() method doesn't return a copy of the list object; it just modifies the list itself. so your code constructs a list object with 3 elements, appends

Re: [Tutor] Wrong version of Python being executed

2007-11-11 Thread Tony Cappellini
Message: 2 Date: Sun, 11 Nov 2007 16:57:01 -0600 From: Martin Walsh <[EMAIL PROTECTED]> Subject: Re: [Tutor] Wrong version of Python being executed To: Tutor Python Message-ID: <[EMAIL PROTECTED]> Content-Type: text/plain; charset=ISO-8859-1 >>My initial thought based on your description was tha

[Tutor] assignment question

2007-11-11 Thread Michael H. Goldwasser
On Sunday November 11, 2007, Ryan Hughes wrote: >Hello, > >Why does the following not return [1,2,3,4] ? > >>>> x = [1,2,3].append(4) >>>> print x >None The reason is that the append method does not return anything. In effect, the expresison [1,2,3].append(4) tempo

Re: [Tutor] Tutor Digest, Vol 45, Issue 30

2007-11-11 Thread Tony Cappellini
> Message: 4 > Date: Mon, 12 Nov 2007 00:16:35 - > From: "Alan Gauld" <[EMAIL PROTECTED]> > Subject: Re: [Tutor] Wrong version of Python being executed > To: tutor@python.org > Message-ID: <[EMAIL PROTECTED]> > Content-Type: text/plain; format=flowed; charset="iso-8859-1"; > reply-type=

Re: [Tutor] assignment question

2007-11-11 Thread John Fouhy
On 12/11/2007, Ryan Hughes <[EMAIL PROTECTED]> wrote: > Why does the following not return [1,2,3,4] ? > > >>> x = [1,2,3].append(4) > >>> print x > None List methods like .append() and .sort() modify lists in-place, as opposed to creating new lists. To remind you of this, those methods return Non

[Tutor] assignment question

2007-11-11 Thread Ryan Hughes
Hello, Why does the following not return [1,2,3,4] ? >>> x = [1,2,3].append(4) >>> print x None ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

[Tutor] [tutor] File format conversion

2007-11-11 Thread Varsha Purohit
Hello All, In one application i want to convert format of ascii file to binary file. And using that binary file in a function of PIL i can convert it to an image file. So i wanted to know how to convert the file format in python... is it possible by Numpy ?? And is there any other alternativ

[Tutor] Problem with default arguments for function

2007-11-11 Thread Michael H. Goldwasser
Dick, Another typical strategy is to use some prescribed special value for the precision parameter to designate the desire for full precision. For example, since precisions should presumably be positive, one could design this function as: def fact(n, precision=15): """compute n!. preci

Re: [Tutor] Problem with default arguments for function

2007-11-11 Thread Dick Moores
At 05:10 PM 11/11/2007, Michael H. Goldwasser wrote: >Dick, > >Another typical strategy is to use some prescribed special value for >the precision parameter to designate the desire for full precision. >For example, since precisions should presumably be positive, one could >design this function as

Re: [Tutor] Problem with default arguments for function

2007-11-11 Thread Dick Moores
At 05:38 PM 11/11/2007, Kent Johnson wrote: >Dick Moores wrote: > >>def fact(n, precision=15, full=False): > ... > >># 3 (full set to True, forcing precision to be specified--but >>irrelevant what it is set to) >> >>> print fact(50, 3, True) >>304140932017133780436126081660647688443776415689605

Re: [Tutor] Problem with default arguments for function

2007-11-11 Thread Dick Moores
At 04:22 PM 11/11/2007, Alan Gauld wrote: >"Dick Moores" <[EMAIL PROTECTED]> wrote > > > And if the function is rewritten as def fact(n, full=False, > > precision=15) > > there would be the analogous problem involving full. > > > > Is there a way to solve this problem of the unnecessary setting of

Re: [Tutor] Problem with default arguments for function

2007-11-11 Thread Kent Johnson
Dick Moores wrote: > def fact(n, precision=15, full=False): ... > # 3 (full set to True, forcing precision to be specified--but > irrelevant what it is set to) > >>> print fact(50, 3, True) > 30414093201713378043612608166064768844377641568960512 You don't have to specify precisi

Re: [Tutor] manipulating data

2007-11-11 Thread Bryan Fodness
Using, fields = {} for line in open('data.txt') : if line : if line.split()[0] == 'field' : field = int(line.split()[-1]) else : fields[field] = tuple(line.split()) I get, fields[field] = tuple(line.split()) NameError: name 'field' is not defined On Nov

Re: [Tutor] Wrong version of Python being executed

2007-11-11 Thread Alan Gauld
"Martin Walsh" <[EMAIL PROTECTED]> wrote Try using the full path to python, just to be sure: c:\python25\python script.py -- do you get the same behavior? >> This works just fine- I would expect it to. > > Actually, I would have expected the opposite. Me too. > Though this still

Re: [Tutor] Problem with default arguments for function

2007-11-11 Thread Alan Gauld
"Dick Moores" <[EMAIL PROTECTED]> wrote > And if the function is rewritten as def fact(n, full=False, > precision=15) > there would be the analogous problem involving full. > > Is there a way to solve this problem of the unnecessary setting of > the 2nd argument? The most common solution I've s

[Tutor] Problem with default arguments for function

2007-11-11 Thread Dick Moores
I just discovered mpmath () and am trying to write a useful function that uses it to compute factorials. Here's what I have: def fact(n, precision=15, full=False): """ compute n! """ from mpmath import mpf if not isins

Re: [Tutor] Wrong version of Python being executed

2007-11-11 Thread Martin Walsh
Tony Cappellini wrote: > Martin Walsh mwalsh at groktech.org > Sun Nov 11 06:13:10 CET 2007 > >>> That is odd. > >>> Try using the full path to python, just to be sure: c:\python25\python >>> script.py -- do you get the same behavior? > This works just fine- I would expect it to. Actually, I wou

Re: [Tutor] Wrong version of Python being executed

2007-11-11 Thread Tony Cappellini
Martin Walsh mwalsh at groktech.org Sun Nov 11 06:13:10 CET 2007 >>That is odd. >>Try using the full path to python, just to be sure: c:\python25\python >>script.py -- do you get the same behavior? This works just fine- I would expect it to. >>Also, if you haven't already, you can run python wit

Re: [Tutor] Bitmap editor and File-saving

2007-11-11 Thread Alan Gauld
"Johnston Jiaa" <[EMAIL PROTECTED]> wrote > I am using Tkinter to create a program in which the user can draw a > simple bitmap image. What library would be best to use in this > circumstance? I have no idea how I would go about doing this except > maybe I would use Tkinter's canvas component?