Skip to main content

Thread: File i/o problem in python !!!!


i writing code in python 3.2 checking , writing (to text file) dynamic ip ,
here code:
code:
#!/usr/bin/python3.2 import urllib.request raw = urllib.request.urlopen('http://automation.whatismyip.com/n09230945.asp') finaldata=str(raw.read()) outputfile=open("iplist","a") outputfile.write(finaldata + "\n") print("finish!!!")
, output file "iplist" give data :
code:
b'currentip' b'currentip'
, question why "b" before ip ? , how rid of ?

first, there reason why want use python? looks more job shell script.

if want to...

code:
finaldata = "" in raw.read():     finaldata = finaldata + chr(i)
raw.read() returns bytes object, list of integers, each being ascii code of corresponding character in input.


Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk File i/o problem in python !!!!


Ubuntu

Comments

Popular posts from this blog

how to devide a circle into equal parts

"Could not fill because there are not enough opaque source pixels" - not solved by any other thread

Why can't I change the billing info for my account?