Opening Multiple files at one time

Dave Angel davea at davea.name
Mon Apr 20 18:49:36 EDT 2015


On 04/20/2015 07:59 AM, subhabrata.banerji at gmail.com wrote:
> Dear Group,
>
> I am trying to open multiple files at one time.
> I am trying to do it as,
>
>   for item in  [ "one", "two", "three" ]:
>         f = open (item + "world.txt", "w")
>         f.close()
>
> This is fine.

But it does not open multiple files at one time.  Perhaps you'd better 
explain better what you mean by "at one time."

> But I was looking if I do not know the number of
> text files I would create beforehand,

So instead of using a literal list [ "one", "two... ]
you construct one, or read it in from disk, or use sys.argv.  What's the 
difficulty?  Nothing in the code fragment you show cares how long the 
list is.


  so not trying xrange option
> also.

No idea what "the xrange option" means.

>
> And if in every run of the code if the name of the text files have
> to created on its own.

So figure out what you're going to use for those names, and write the 
code to generate them.

>
> Is there a solution for this?

For what?


-- 
DaveA



More information about the Python-list mailing list