[Tutor] dynamically creating files
dyoo at hkn.eecs.berkeley.edu
Fri Nov 14 13:51:00 EST 2003
On Fri, 14 Nov 2003, bob wrote:
> I am creating a program and have come to a problem. I wish to write a
> class that handles file objects, ie opening, writing to, and closing a
> file. I wish to dynamically create the file name, as each instance would
> have its own file too use for processing.
Sounds good. Can you tell us how you would like to make those names? The
open() or file() function will let us open up a file of our choice. When
we call it, we always pass in the name of the file to open:
It turns out that we can send in any "expression" in there, as long as it
calculates to a string. So:
open("hello" + "world1.txt")
will do the same thing. Would something like this work for your program?
Tell us more details about what kind of files you're trying to create; you
might not even have to write a class.
Good luck to you!
More information about the Tutor