Entry
Substituting strings
Jul 5th, 2000 09:59
Nathan Wallace, unknown unknown, Hans Nowak, Snippet 10, Piet van Oostrum
"""
Packages: basic_datatypes.strings
"""
"""
DR> Hi,
DR> In this example, how do I get the shell to recognize the value
DR> for file[0] rather than the literal string 'file[0]'? Please email me...
DR> -------------------------------------------------------------------------
DR> import sys, os
DR> file = sys.argv[1:]
DR> print file[0]
DR> for name in os.popen("dir file[0]", 'r').readlines():
DR> print name,
DR> --------------------------------------------------------------------------
"""
file = ["myfile", "yourfile"] # added by PSST
print "dir " + file[0]
print "dir %s" % file[0] # alternative
"""
But in this example it may be better to use the os.listdir function rather
than calling the external dir program.
"""