Error to create the txt file in loop

Ender phan

All IP address written in the file line by line and it will be executed by given command line. I want to save the result to each file with file's name is standing by each IP.

with open(list) as l:
    for line in l:
            file = line+".txt"
            os.system("whois "+line+" >> "+file)

list contains:

192.168.0.1
192.168.0.2
192.168.0.3

Errors:

sh: 3: .txt: not found
sh: 3: .txt: not found
sh: 3: .txt: not found
hurturk

You should add line = line.strip() at beginning of your for loop to clear \n from your line variable, that will fix it.

Please see this answer for examples of debugging methodologies for python. In your case, a print() statement can help you see what you are generating.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related