| | |
Strange outcome using enumerate()
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jun 2009
Posts: 5
Reputation:
Solved Threads: 1
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?
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?
Python Syntax (Toggle Plain Text)
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)
Last edited by dads; Oct 25th, 2009 at 2:20 pm.
0
#2 Oct 25th, 2009
This little test code works fine ...
... and so does your code (removed first line since I am using Python25).
python Syntax (Toggle Plain Text)
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 """
Last edited by vegaseat; Oct 25th, 2009 at 2:50 pm.
May 'the Google' be with you!
![]() |
Similar Threads
- strange problem (C)
- Strange Boot Problems (Troubleshooting Dead Machines)
- ERROR with my email, getting sent strange emails :( (Geeks' Lounge)
- getting strange values in display??? (C++)
- Strange 'glitching' - possibly CPU issue (Motherboards, CPUs and RAM)
- strange problems (Windows 95 / 98 / Me)
- Suspected virus issue (Windows NT / 2000 / XP)
- HELP!!! very strange problem! (Troubleshooting Dead Machines)
- win2000pro SP3 hangs in strange way (Windows NT / 2000 / XP)
Other Threads in the Python Forum
- Previous Thread: Help with two questions
- Next Thread: Throttle CPU usage
| Thread Tools | Search this Thread |
Tag cloud for Python
alarm assignment avogadro beginner bluetooth character cmd code copy customdialog cx-freeze data decimals dictionary directory dynamic error examples excel exe file float format ftp function generator gnu graphics gui halp homework http ideas import input itunes java leftmouse line linux list lists logging loop module mouse number numbers output parsing path port prime program programming projects push py2exe pygame pyglet pyqt python random recursion recursive schedule screensaverloopinactive script scrolledtext slicenotation sqlite ssh stdout string strings sudokusolver table terminal text thread threading time tkinter tlapse tuple tutorial ubuntu unicode update urllib urllib2 variable ventrilo verify vigenere webservice wikipedia windows wxpython xlib






