Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #73766

Re: Writing Multiple files at a times

From Denis McMahon <denismfmcmahon@gmail.com>
Newsgroups comp.lang.python
Subject Re: Writing Multiple files at a times
Date 2014-06-30 23:22 +0000
Organization A noiseless patient Spider
Message-ID <losrf2$c6i$2@dont-email.me> (permalink)
References <b8951113-5171-4441-b490-4d731eb56cec@googlegroups.com> <29f99276-9609-42cd-9210-5bc5e75aa364@googlegroups.com>

Show all headers | View raw


On Mon, 30 Jun 2014 12:23:08 -0700, subhabangalore wrote:

> Thank you for your kind suggestion. But I am not being able to sort out,
> "fp = open( "scraped/body{:0>5d}.htm".format( n ), "w" ) "
> please suggest.

look up the python manual for string.format() and open() functions.

The line indicated opens a file for write whose name is generated by the 
string.format() function by inserting the number N formatted to 5 digits 
with leading zeroes into the string "scraped/bodyN.htm"

It expects you to have a subdir called "scraped" below the dir you're 
executing the code in.

Also, this newsgroup is *NOT* a substitute for reading the manual for 
basic python functions and methods.

Finally, if you don't understand basic string and file handling in 
python, why on earth are you trying to write code that arguably needs a 
level of competence in both? Perhaps as your starter project you should 
try something simpler, print "hello world" is traditional.

To understand the string formatting, try:

print "hello {:0>5d} world".format( 5 )
print "hello {:0>5d} world".format( 50 )
print "hello {:0>5d} world".format( 500 )
print "hello {:0>5d} world".format( 5000 )
print "hello {:0>5d} world".format( 50000 )

-- 
Denis McMahon, denismfmcmahon@gmail.com

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Writing Multiple files at a times subhabangalore@gmail.com - 2014-06-29 03:49 -0700
  Re: Writing Multiple files at a times Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-06-29 12:17 +0100
  Re:Writing Multiple files at a times Dave Angel <davea@davea.name> - 2014-06-29 09:33 -0400
    Re: Writing Multiple files at a times Roy Smith <roy@panix.com> - 2014-06-29 10:01 -0400
      Re: Writing Multiple files at a times subhabangalore@gmail.com - 2014-06-29 10:32 -0700
        Re: Writing Multiple files at a times Denis McMahon <denismfmcmahon@gmail.com> - 2014-06-29 19:21 +0000
  Re: Writing Multiple files at a times subhabangalore@gmail.com - 2014-06-30 12:23 -0700
    Re: Writing Multiple files at a times Denis McMahon <denismfmcmahon@gmail.com> - 2014-06-30 23:22 +0000

csiph-web