splitting tables

Ben Finney bignose-hates-spam at and-benfinney-does-too.id.au
Tue Feb 10 19:50:57 EST 2004


On Wed, 11 Feb 2004 00:44:18 +0000 (UTC), robsom wrote:
> I'm beginning to appreciate Python even though at first I hated this
> indentation thing

Yup.  Just because something seems limiting doesn't mean it is.

> and I (still) don't like the "for in range()" way to build loops.

The "for index in range( size )" is mostly recommended as a way to loop
over a list; range( size ) will elegantly generate a sequence of indices
into a list of size "size".

What is it you don't like?


> Il Tue, 10 Feb 2004 18:09:33 +0100, Karl Pflästerer ha scritto:
>> No.  The split method is a method of strings.  Since line is a string
>> you call here a method of a string object.
>
> Ok, but then why if I write this
>
> for line in fin.readlines():
> 	line = split(line)
>
> it does work anyway?

Because somewhere earlier in that code you must have imported the name
'split' into the base namespace.  It's not there to begin with (and
importing it is needlessly polluting the base namespace).


> Are there two ways to use the same function?

They're two different functions.  One is a method of string objects, one
is a function you've imported from somewhere.  (This confusion is partly
why importing symbols into the base namespace is a bad idea.)

-- 
 \         "I think a good gift for the President would be a chocolate |
  `\   revolver. And since he's so busy, you'd probably have to run up |
_o__)           to him real quick and hand it to him."  -- Jack Handey |
Ben Finney <http://bignose.squidly.org/>



More information about the Python-list mailing list