FreeStyle4 FreeStyle4 - 1 year ago 77
Python Question

Sending in String vs Reading String

I have a text file that contains something like:

IP_ADD = ""

and the code to read it in:

counter = 0
wordList = [None] * 100

with open("config.txt") as f:
content =

for line in content:
line = line.split(' ',2)[-1]
wordList[counter] = line
counter = counter + 1

which will return to me just the IP Address with the quotes inside wordList.. IE

wordList[0] = ""

I then try to send an SNMP command using the OID and that IP address. IE


but this doesnt work. If I change it to the following:


it works. What am I missing here?

Answer Source

You almost got it, you just need to strip the double quotes around your IPs. Use strip('"') to do that.

line.split(' ',2)[-1].strip('"')

Your code seems too shabby, no offence. You are doing things many of which are not necessary. You can do it much simply this way:

wordList = []
with open('config.txt') as file:
    for line in file:



['', '']
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download