list to string

Graham Nicholls graham at rockcons.co.uk
Fri Sep 12 08:48:12 EDT 2003


Gonçalo Rodrigues wrote:

> On Thu, 11 Sep 2003 23:07:38 +0100, Graham Nicholls
> <graham at rockcons.co.uk> wrote:
> 
>>Hi.  Sorry if this is really dim, but I'm trying to do something like:
>>
>>main (args):
>>        fhand=open(args[1:],"r+")
>>
> 
> args[1:] is a slice. So if args is a list, args[1:] is a list, if it's
> a string, it's a string, etc... open expects a string -- as you
> probably have already figured out.
> 
>>and get an error that open is expecting a string not a list.
>>
> 
> So either you are passing the wrong argument: e.g. a list instead of a
> string, or then, if you do want to pass a list then you have to change
> your code. But now the course to follow depends on what you want to
> do. So you have to explain a little more.
> 
> With my best regards,
> G. Rodrigues
Thanks all - I knew it was something stupid.  These days I don't get to do
enough programming, so I tend to make silly mistakes like this one -
clearly I wanted something like:
        fhand=open(argv[1],"rw")

So thanks again.

Graham
-- 
#include <wit>




More information about the Python-list mailing list