In this article, let's look at Python's Filewritelines () method, which I'll explain in Python
Write MethodAs well as its related
Lines MethodAnd it's going to put this
Write () methodCan be used in Python programming where to explain. No more nonsense, let's get started.
Overview
The Writelines () method is used to write a sequence of strings to a file.
This sequence string can be generated by an iterative object, such as a list of strings.
Line breaks need to be made with a newline character \ n.
Grammar
The Writelines () method syntax is as follows:
Fileobject.writelines ([str])
Parameters
STR-a sequence of strings to write to the file.
(The method has no return value.) )
Instance
The following example demonstrates the use of the Writelines () method:
#!/usr/bin/python#-*-coding:utf-8-*-# Open File fo = open ("Test.txt", "W") print "file name:", fo.nameseq = ["Blue Sky 1\n", "Blue Sky 2" ]fo.writelines (seq)
The result of the above example output is:
File name is: test.txt
To view the contents of a file:
$ cat Test.txt Blue Sky 1 Blue Sky 2
In this article, we explain what is the Writelines () method, do not understand the words can be hands-on to try, after all, hands-on practice is the best way to verify the learning. Finally, I hope that this article will give you a little help in learning about Python.
For more information, please visit the PHP Chinese Web Python tutorial section.