Advertisement

06.22.2008 at 11:39AM PDT, ID: 23505990
[x]
Attachment Details

Reading / Parsing IP and Port from file

Asked by mitchguy in Python Scripting Language

Tags: Python

I'm trying to read and parse the ip and port from a file. I'm pretty close to getting it, but
somethings not right.

The file is data.txt has the contents
IP_ADDRESS=127.0.0.1
PORT=3031

The result after running the program is backwards
PORT:  127.0.0.1

IP:  3031

Why I don't understand and what to do to make PORT: 3031 and IP: 127.0.0.1Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
myFile = open("data.txt","r")
for line in myFile.readlines():
	if line.find("PORT"):
		ip = line.split("=")[1]
		print "PORT:  " + str(ip)
	elif line.find("IP_ADDRESS"):
		port = line.split("=")[1]
		print "IP:  " + str(port)
 
Loading Advertisement...
 
[+][-]06.22.2008 at 12:19PM PDT, ID: 21841838

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Python Scripting Language
Tags: Python
Sign Up Now!
Solution Provided By: RichieHindle
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628