0

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
Ender phan
  • 185
  • 2
  • 3
  • 10

1 Answers1

3

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.

Community
  • 1
  • 1
hurturk
  • 5,214
  • 24
  • 41