Python : read / write file

Hi guys,

Yeah~ as you see on the top of this article,
I start to learn python now! hah

So... I gonna record some usage and some tutorial here about python.
Okay~ Let's go!

Python is good at text and data operating, so...
the first thing before you parsing or do some modified to the file,
you have to .... open and read / write the file!!

open / close the file:

file = open("filename", "type")
file.close()
As to type we can have :


r : read
w : write
r+ : read/write
a : append

Read method : 

To read all content in the file you can use...

print file.read()
Read line by line

print file.readline()

Write method :

file.write("aaaa")
file.write(str(123) + "\n")

Open file and make it close automatically :

with open("filename", "w") as file:
    file.write("Yes!!")

Yeah~~ this is the first step !
Let's continue!
                                            provide




Comments

Popular posts from this blog

UBoot with iMX6 - Part 1

Install chrome on CentOS

Can't find pip3 ? Here is it!