You can often guess
which course I'm giving by the topic of the my daily writing ....
"How do I list out the contents of all variables with names starting v-a-r ... a question from yesterday.
The immediate answer:
# print all variables starting with "var"
sum = 9
var3 = 78
var6 = 99
varsity = 56
variable = "hello"
for name in dir():
if name.startswith("var"):
exec("print "+name)
A more thoughtful answer would be to suggest that you might have used a dictionary to store all this information, then you could simply use the keys method ....
(written 2006-10-21 07:40:02)
Associated topics are indexed under
Y115 - Additional Python Facilities [2655] Python - what is going on around me? - (2010-02-28)
[2462] Python - how it saves on compile time - (2009-10-20)
[2435] Serialization - storing and reloading objects - (2009-10-04)
[2407] Testing code in Python - doctest, unittest and others - (2009-09-16)
[1876] Python Regular Expressions - (2008-11-08)
[1337] A series of tyre damages - (2007-09-08)
[1336] Ignore case in Regular Expression - (2007-09-08)
[1305] Regular expressions made easy - building from components - (2007-08-16)
[1149] Turning objects into something you can store - Pickling (Python) - (2007-04-15)
[1136] Buffering output - why it is done and issues raised in Tcl, Perl, Python and PHP - (2007-04-06)
[1043] Sending an email from Python - (2007-01-18)
[753] Python 3000 - the next generation - (2006-06-09)
[672] Keeping your regular expressions simple - (2006-04-05)
[663] Python to MySQL - (2006-03-31)
[463] Splitting the difference - (2005-10-13)
[239] What and why for the epoch - (2005-03-08)
[208] Examples - Gadfly, NI Number, and Tcl to C interface - (2005-02-10)
[183] The elegance of Python - (2005-01-19)
Some other Articles
Not proud to be BritishOf course I'll tell you by emailPieces of PythonBrand new hotel and training centre, MelkshamPython - listing out the contents of all variablesPython - function v methodPython - extend v append on a listCourses at Well House ManorToo much for the National TrustPHP - good coding practise and sticky radio buttons