I have to make some bookmarks so I quickly knocked up the script below and ran it. It created the files fine but with a with an incorrect ip in the second file

The second bookmark created should be named York.URL which it is but the ip address of the url is 192.65.0.95 where it should be 192.65.2.95. It uses the enumerate value and adds 1 each time.

I'd imagine I'd be able to get the desired outcome by using other methods but what is going on here? Am I missing something obvious?

from __future__ import print_function

shops = [ 'Windermere',
          'York',
          'Chester' ]

for i, s in enumerate(shops):
    f = open('%s.URL' % (s), 'w')
    f.write('[InternetShortcut]\nURL=http://192.65.%s.95/BackO' % (i+1))
    f.close()
    print('%s completed' % s)

This little test code works fine ...

shops = [ 'Windermere',
          'York',
          'Chester' ]

for i, s in enumerate(shops):
    print(i, s)
    print('[InternetShortcut]\nURL=http://192.65.%s.95/BackO' % (i+1))

"""my result -->
(0, 'Windermere')
[InternetShortcut]
URL=http://192.65.1.95/BackO
(1, 'York')
[InternetShortcut]
URL=http://192.65.2.95/BackO
(2, 'Chester')
[InternetShortcut]
URL=http://192.65.3.95/BackO
"""

... and so does your code (removed first line since I am using Python25).

(removed first line since I am using Python25).

Why don't you install 2.6 ? It's even better.

I've just tried it again and it works. How odd, I thought I was going mad!

Could not reproduce it on python 2.6.2 linux either.
Maybe you have run the pyc version, which was older.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.