Solved: Python help. Why doesn't the first for loop execute properly?

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

cybarite

Thread Starter
Joined
Mar 28, 2006
Messages
8
Hi,

This is a small script that i am trying to get to execute. It should take the hosts in the first for loop and then for that host process the name in the list stored at c:\fldrname.txt file. But the code just executes the first host and stops the second one is not taken. Why?:confused: Any and all help is appreciated?

Code:
import string	
ourfile = r'c:\fldrname.txt'
hosts = ['a', 'b']
fldrlistfile = file(ourfile)
for x in hosts:
    for i in fldrlistfile.readlines():
        fldr = i.split('\n')
	print x + fldr[0]
fldrlistfile.close()
-----------------
Editing this since i got it to work. It seems assigning the fldrlistfile.readlines() to a variable did the trick.

Code:
import string	
ourfile = r'c:\fldrname.txt'
hosts = ['a', 'b']
fldrlistfile = file(ourfile)
z = fldrlistfile.readlines()
for x in hosts:
    for i in z:
        fldr = i.split('\n')
	print x + fldr[0]
fldrlistfile.close()
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Members online

Top