list to string

Sean Ross sross at connectmail.carleton.ca
Thu Sep 11 18:34:45 EDT 2003


"Graham Nicholls" <graham at rockcons.co.uk> wrote in message
news:Km68b.2494$YL.621 at news-binary.blueyonder.co.uk...
> Hi.  Sorry if this is really dim, but I'm trying to do something like:
>
> main (args):
>         fhand=open(args[1:],"r+")
>
> and get an error that open is expecting a string not a list.

args[1:] performs a slicing operation which returns a list.
You're asking for all of the elements in the list 'args' except for the very
first (arg[0]). If you only want the second argument, use arg[1]. If you
want the slice, but as a string, use ''.join(args[1:]) (or whatever
seperator you require).

HTH
Sean






More information about the Python-list mailing list