|
|
 |
 |
 |
 |
Python Programming Language
|
 |
 |
 |
 |
 |
 |
 |
 |
Dynamic File Name Open()
Robert Rawlins - Think Blue wrote: > I'm trying to open a file using open() but the name of the file is created > dynamically as a variable, but also has part of a static path. For instance, > the file may be called 'dave' and will always be in '/my/files/here/'.
Well that's an absolutely normal way of doing things, so if my toy example below doesn't make things clear, you'd better post a code fragment and/or some traceback. <code> import os, sys path = "c:/temp" for filename in ["chas.txt", "dave.txt"]: f = open (os.path.join (path, filename)) print filename print f.read () print f.close () </code> TJG
|
 |
 |
 |
 |
|