Opening Multiple files at one time

subhabrata.banerji at gmail.com subhabrata.banerji at gmail.com
Tue Apr 21 03:56:45 EDT 2015


On Tuesday, April 21, 2015 at 4:20:16 AM UTC+5:30, Dave Angel wrote:
> On 04/20/2015 07:59 AM,  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

Yes. They do not. They are opening one by one. 
I have some big chunk of data I am getting by crawling etc.
now as I run the code it is fetching data. 
I am trying to fetch the data from various sites.
The contents of the file are getting getting stored in 
separate files. 
For example, if I open the site of "http://www.theguardian.com/international", then the result may be stored in file in file "file1.txt", and the contents of site "http://edition.cnn.com/", may be stored in file "file2.txt". 

But the contents of each site changes everyday. So everyday as you open these sites and store the results, you should store in different text files. These text files I am looking to be created on its own, as you do not know its numbers, how many numbers you need to fetch the data. 

I am trying to do some results with import datetime as datetime.datetime.now()
may change everytime. I am trying to put it as name of file. But you may suggest better. 

Regards,
Subhabrata Banerjee.



More information about the Python-list mailing list