| | |
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
abrupt ansi anti apache approximation array backend beginner binary book builtin calculator chmod code converter countpasswordentry curved dan08 dictionaries dictionary drive dynamic examples excel file filename float format function gui heads homework import inches input java launcher library line lines linux list lists loop mouse mysql mysqlquery number numbers numeric output parsing path phonebook plugin pointer port prime programming progressbar projects py2exe pygame pyqt pysimplewizard python random recursion redirect refresh scrolledtext software statictext statistics string strings sum table terminal text textarea thread threading time tkinter tlapse trick tricks tuple tutorial twoup ubuntu unicode urllib urllib2 variable windows wordgame write wxpython






