removing the ' from list elements

Jason Stokes jstok at bluedog.apana.org.au
Tue Mar 7 23:09:01 EST 2000


doyen at mediaone.net wrote in message <38C5C2C9.23915D88 at mediaone.net>...
>I think this is a newbie oops situation,  but I have read the tutorial,
>library reference and laguage reference without any Eureka!'s. Maybe
>it's too many years of basic.
>
>I've written a program that reads ftp LIST output, filters it and puts
>in in a list for sorting. I'm taking each line from the file listing I
>retrieve, parsing it into a list of year, month, day, time, size, name
>and source by using string.split. I then use sting.join on each 'mini
>list'  into a formated line and place it in a 'master' list to use
>list.sort() and list.reverse for sorting by date last modified.
>
>When I retirieve (or examine) the elements within the list, I use
>string.split again to parse them, then use strimg,replace('[', '') for
>compariisons, or for output.

I'm not quite sure what you're doing here.  It looks like this extra parsing
is unnecessary; you should store the information internally according to its
logical structure.  For example, as a list of tuples with each tuple having
year, month, day, time, size, name and source entries.  Or a list of "list
entry" objects.

>Other python newbie questions are....
>Should I always return something from a function (note the return 1's)

All functions return a result.  If you don't explicitly return something, a
"None" object is returned.  You should use this implicit return unless you
have something useful to return.  return 1 is possible, but unless your'e
defining a function that returns a boolean result, not particularly useful
and unpythonish.  In C functions and Perl, the return value is sometimes
used for error reporting purposes.  In Python, exceptions are used for this
purpose.







More information about the Python-list mailing list