Hello!

Tell me, please, on the python syntax. The task is to process several files whose names are automatically generated in the form file+i+j , where i and j are integers (that is, names like file11 , file12 ...). How to competently refer to the desired file, for example, in the following line:

 f = open("file+i+j.txt", "wb") 

And the second similar question is how to access the variable url (which also includes i and j ) url ='http://api.wikimapia.org/function=box&bbox["i","j"]&count=50000&format=kml&pack=gzip'

How to correctly enter these ["i","j"] ?

Thank!

    2 answers 2

     f = open("file{0}{1}.txt".format(i,j), "wb") 
    • Add: for python3 it is recommended to use format, and not operand% - gil9red

    Format strings,% operation.

     f = open("file%d%d.txt" % (i,j), "wb") url ='http://api.wikimapia.org/function=box&bbox["%d","%d"]&count=50000&format=kml&pack=gzip' % (i, j) 
    • Thank! And what about the url? - Sitizen Snips
    • one
      exactly the same - qnub
    • added to answer - alexlz