[Tutor] referencing vars()

Alan Gauld alan.gauld at btinternet.com
Sat Sep 15 22:03:14 CEST 2007


"John" <washakie at gmail.com> wrote

>        import csv
>        vardict=vars()
>        for var in vardict:
>                if var=='allcum' or var=='alldhdt':
> 
> outfile=in_path+'/'+dataset+'_'+str(var)+'.csv'
>                        writer = csv.writer(open(outfile, "wb"))
>                        writer.writerows(var)
>
> I'm trying to do the above, but of course get an error because 
> vardict is
> only referencing vars(), thus changes size... also, I tried
> vardict=[vars()], but this fails as well??

I'm not too sure what you are doing but on the last point:

Try converting to a list:

>>> vardict = list(vars())
>>> for var in vardict: print var
...
pp
shell
__builtins__
__file__
__doc__
vardict
filling
notebook
var
__name__
os
>>>


HTH,

Alan G. 




More information about the Tutor mailing list