Re: [Tutor] List comprehension question

2010-11-11 Thread Stefan Behnel
Steven D'Aprano, 12.11.2010 06:07: Richard D. Moores wrote: On Wed, Nov 10, 2010 at 01:30, Steven D'Aprano wrote: P.S. don't take that as a put down -- you should be pleased that your code is around as fast as Tim Peter's code :) Nah. But where is Tim Peter's code? The timeit module was w

Re: [Tutor] List comprehension question

2010-11-11 Thread Steven D'Aprano
Richard D. Moores wrote: On Wed, Nov 10, 2010 at 01:30, Steven D'Aprano wrote: P.S. don't take that as a put down -- you should be pleased that your code is around as fast as Tim Peter's code :) Nah. But where is Tim Peter's code? The timeit module was written by Tim Peters. Since then,

Re: [Tutor] variables question.

2010-11-11 Thread Steven D'Aprano
Jeff Honey wrote: I have a question about where variables are exposed in python. I have a monolothic script with a number of functions defined, can those functions share variables? can I instantiate them outside the function of where they are needed? do they need to be wrapped in quotes, ever?

Re: [Tutor] What is a "state variable"?

2010-11-11 Thread Steven D'Aprano
Emile van Sebille wrote: "A class is a container for shared state, combined with functions (methods) that operate on that state. By putting state variables into member fields, they are accessible to all the methods of the class without having to be passed as parameters." So, by his own defin

Re: [Tutor] What is a "state variable"?

2010-11-11 Thread Steven D'Aprano
Walter Prins wrote: Usually however people mean that objects (instances) have state variables, even when they talk about classes. The trouble is that classes are themselves objects, and can in fact have their own stat. This is true for Python, and Ruby, but not all languages. So what is sta

Re: [Tutor] A deeper explanation of ability to modify list elements in-place

2010-11-11 Thread Steven D'Aprano
Serdar Tumgoren wrote: In Python, if you have x[0] = Dummy(), the list object x stores the Dummy instance itself. I think the above example gets to the source of my confusion. Clearly the instance remains accessible via x[0], but I somehow never thought of a specific list index as an obvious

Re: [Tutor] What is a "state variable"?

2010-11-11 Thread Walter Prins
On 11 November 2010 22:47, Walter Prins wrote: > Enter object orientation: If instead however, you turn those functions > into a class, you can then instead have them all "share" the same > variable(s) that's commonly visible to each of them due to paramter passing > as shared "state" variables

Re: [Tutor] What is a "state variable"?

2010-11-11 Thread Walter Prins
On 11 November 2010 20:11, Richard D. Moores wrote: > The term comes up in the 2nd section of > > > > > didn't help. > >

Re: [Tutor] What is a "state variable"?

2010-11-11 Thread Emile van Sebille
On 11/11/2010 12:11 PM Richard D. Moores said... The term comes up in the 2nd section of didn't help. k = 23 Is k then a state variable in that its state is 23? What sorts of

[Tutor] What is a "state variable"?

2010-11-11 Thread Richard D. Moores
The term comes up in the 2nd section of didn't help. k = 23 Is k then a state variable in that its state is 23? What sorts of variables are, and are not, state variables? The co

Re: [Tutor] A deeper explanation of ability to modify list elements in-place

2010-11-11 Thread Serdar Tumgoren
First off, thanks for the detailed response! I had a few follow-up questions below, if you're willing to indulge. Feel free to direct me to RTM some books on C and the python source code, of course :) > Why? Because the designer of Python, Guido van Rossum, wanted it to be > possible, and he desi

Re: [Tutor] Creating one file out of all the files in a directory

2010-11-11 Thread Kushal Kumaran
- Original message - > Hi, > > I'm trying to create a script to do the following. I have a directory > containing hundreds of text files. I need to create a single file with > the contents of all the files in the directory. Within that file, > though, I need to create marks that indicate

Re: [Tutor] A deeper explanation of ability to modify list elements in-place

2010-11-11 Thread Steven D'Aprano
Serdar Tumgoren wrote: But I think I see your point. The list object behaves the same as the objects stored inside the list. Er, surely not... the list object is a list, the objects inside the list are ints. They do not behave the same. > In other words, the list object is a reference to

Re: [Tutor] Stupid bug

2010-11-11 Thread Steven D'Aprano
Wayne Werner wrote: Including the sister bug - continually importing something and you still get the old function because you forgot to delete the .pyc file. Whoops! Er, whoops is right... I think you may have misinterpreted what you were seeing. When you import a module for the first time,

Re: [Tutor] A deeper explanation of ability to modify list elements in-place

2010-11-11 Thread Steven D'Aprano
Serdar Tumgoren wrote: Hi folks, I'm trying to gain a deeper understanding of why it's possible to modify list elements in-place *without* replacing them. For instance, why is the below possible? Why? Because the designer of Python, Guido van Rossum, wanted it to be possible, and he designed t

Re: [Tutor] put query result set into dictionary

2010-11-11 Thread Shawn Matlock
That was it. Thank you, Alan. -Original Message- From: tutor-bounces+matlocs=odscompanies@python.org [mailto:tutor-bounces+matlocs=odscompanies@python.org] On Behalf Of Alan Gauld Sent: Wednesday, November 10, 2010 5:04 PM To: tutor@python.org Subject: Re: [Tutor] put query resul

Re: [Tutor] A deeper explanation of ability to modify list elements in-place

2010-11-11 Thread Serdar Tumgoren
> > > Would you have the same question about what takes place here?: > > >>> list_ = [3,4,5] > >>> list_[1] = 10 > >>> list_ > [3, 10, 5] > >>> > > No surprise there. It's a familiar usage and it appears to be the canonical example (in textbooks/tuts) for demonstrating "in-place" object modificatio

Re: [Tutor] A deeper explanation of ability to modify list elements in-place

2010-11-11 Thread Richard D. Moores
On Thu, Nov 11, 2010 at 06:02, Serdar Tumgoren wrote: > Hi folks, > I'm trying to gain a deeper understanding of why it's possible to modify > list elements in-place *without* replacing them. For instance, why is the > below possible? > class Dummy(object): > ... pass > ... a = Dummy

[Tutor] A deeper explanation of ability to modify list elements in-place

2010-11-11 Thread Serdar Tumgoren
Hi folks, I'm trying to gain a deeper understanding of why it's possible to modify list elements in-place *without* replacing them. For instance, why is the below possible? >>> class Dummy(object): ... pass ... >>> a = Dummy() >>> b = Dummy() >>> x = [a, b] # modify list elements in-place >>>

Re: [Tutor] List comprehension question

2010-11-11 Thread Richard D. Moores
On Wed, Nov 10, 2010 at 02:35, Steven D'Aprano wrote: > Richard D. Moores wrote: >> >> On Tue, Nov 9, 2010 at 12:54, Steven D'Aprano wrote: >>> >>> Richard D. Moores wrote: >>> See for a speed test with n = 100,000 and 100,000 loops >>> >>> As a g

Re: [Tutor] Creating one file out of all the files in a directory

2010-11-11 Thread Evert Rol
> I'm trying to create a script to do the following. I have a directory > containing hundreds of text files. I need to create a single file with > the contents of all the files in the directory. Within that file, > though, I need to create marks that indicate the division between the > contents of

[Tutor] Creating one file out of all the files in a directory

2010-11-11 Thread Josep M. Fontana
Hi, I'm trying to create a script to do the following. I have a directory containing hundreds of text files. I need to create a single file with the contents of all the files in the directory. Within that file, though, I need to create marks that indicate the division between the contents of each

Re: [Tutor] List comprehension question

2010-11-11 Thread Richard D. Moores
On Wed, Nov 10, 2010 at 01:30, Steven D'Aprano wrote: > > Richard D. Moores wrote: > >> def proper_divisors_sum(n): >>    return sum(list(divisors(n))) - n > > There's no need to call list first. sum() will happily operate on any sort of > iterable -- lists, sums, iterators, generators, range obj

[Tutor] Fw: unicode nightmare

2010-11-11 Thread ALAN GAULD
forward to the list Alan Gauld Author of the Learn To Program website http://www.alan-g.me.uk/ - Forwarded Message > From: danielle davout > To: Alan Gauld > Sent: Thursday, 11 November, 2010 4:19:22 > Subject: Re: [Tutor] unicode nightmare > > First thanks to answer ... even if