printing variables

John Machin sjmachin at lexicon.net
Fri Oct 6 05:02:53 CEST 2006


s99999999s2003 at yahoo.com wrote:
> hi
> say i have variables like these
>
> var1 = "blah"
> var2 = "blahblah"
> var3 = "blahblahblah"
> var4 = "...."
> var5 = "..."..
>
> bcos all the variable names start with "var", is there a way to
> conveniently print those variables out...
> eg print var* ??
> i don't want to do :
>
> print var1, var2, var3, var4 ......etc...
> thanks

| >>> var1 = 1
| >>> var2 = 2
| >>> variant = 3
| >>> variegated = 4
| >>> ' '.join(str(v) for k, v in locals().iteritems() if
k.startswith('var'))
| '1 2 3 4'

*BUT* why do you start off with those things in separate variables
instead of in some container (list, dict, object simulating a "record"
or "struct", ...?




More information about the Python-list mailing list