How to use write in python
Today Xiaobian to share with you how to use python write related knowledge points, detailed content, clear logic, I believe most people still know too much about this knowledge, so share this article for everyone to refer to, I hope you read this article after some gains, let's learn about it together.
Specific steps:
First, open the Python editor and create a Python project.
2. Open a file using the open method in a python project
import random
3. Define a specified string and write it to the file using the write method.
str = ""
fo.write( str )
The full example code is as follows:
#!/ usr/bin/python
# -*- coding: UTF-8 -*-
#www.xieniao.com
#Open the file
fo = open("test.txt", "w")
print "filename: ", fo.name
str = ""
fo.write( str )
#Close the file
fo.close()
The output is:
test.txt #filename
View file content:
cat test.txt #View File Command
The above is "how to use write in python" all the contents of this article, thank you for reading! I believe everyone has a great harvest after reading this article. Xiaobian will update different knowledge for everyone every day. If you want to learn more knowledge, please pay attention to the industry information channel.