variable creation from a pathname

gimar paolo.marz at aliceposta.it
Sun Feb 1 18:48:19 CET 2004


Thank you very much.
If myvalue=123 could be myvalue=[], is string formatting also possible ?

Gpaolo


"Irmen de Jong" <irmen at -NOSPAM-REMOVETHIS-xs4all.nl> ha scritto nel
messaggio news:401d36c8$0$315$e4fe514c at news.xs4all.nl...
> gimar wrote:
>
> > I wonder if there's a way to assign a value to the object obtained with:
> >
> > from os.path import *
> > splitext(basename("c:\pyfiles\sample.txt"))[0]    -----> sample
> >
> > and make it possible something like this, for example:
> >
> > sample = 123
>
> import os
> name=os.path.splitext(os.path.basename("c:\pyfiles\sample.txt"))[0]
> myvalue = 123
> exec("%s=%d" % (name, myvalue))     # <-- this is what you wanted
> print sample
>
> (it will print 123).
>
> --Irmen





More information about the Python-list mailing list