[Tutor] Re: Why is this write defined as a tuple, instead ofpicking list?

Alan Gauld alan.gauld at blueyonder.co.uk
Sat Apr 17 10:43:36 EDT 2004


CC'd to tutor....

> > > > >     for x in article_items:
> > > > >         write = "<h3>", article_items[0], "</h3>"

> I've realised that I really don't need the loop here, just
> the statement which adds each part of article_items(x). 

If you know how many items you can certainly do it in one 
write, thats true.

> I'm looking into saving two versions of this data - the list
> itself and then the 'exported' html version. 

> here). Is it easy to parse the list text file back into a
> python script? 

OK, The list can be written to a file as text quite easily 
using the repr() function and on reading it back eval() 
will convert it back into a list - but beware that eval() 
has security implications since it will evaluate any 
arbitrary string as a python expression, including 
'os.system(.....)' strings and the like.


> What is the separator between them, 

Whatever you want it to be! :-)

> imagine that Python will just 'see' it as text initially. 

Yes but if you use the repr/eval pair it should write/read 
fairly transparently.

Alan G.




More information about the Tutor mailing list