confused genius
confused genius

Reputation: 3244

Reading IPs and manipulating URL with IP

I want to read a text file(ips.txt) with IP addresses in each line , Example file :

16.180.77.86
16.180.77.87
16.180.77.88
16.180.77.89
16.180.77.90
16.180.77.91

and then substitue that IP address in following url string "https://"+

I tried :

 readme=open("ips.txt","r")
 for readie in readme.readline():
     modi="https://"+ str(readie)+":8080/api/v1/credentials"
     print modi

But it replied:

https://1:8080/api/v1/credentials

Any suggestions?

Upvotes: 0

Views: 65

Answers (1)

Ionut Hulub
Ionut Hulub

Reputation: 6326

It should be readme.readlines(), not readme.readline().

readline() returns a line from the file, so you iterate through a line, one character at a time. readlines() returns a list of strings, so you will iterate through each line.

Also, as @Morb suggested, for readie in readme: will work as well.

Upvotes: 1

Related Questions