Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use write in python

Shulou Source: shulou.com Published: 2022-05-31 11:14:13 09月15日 Update

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.

Tags: Files knowledge articles content methods projects different large code commands most characters strings examples that is file names more steps knowledge points results Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei MariaDB Xiaomi Apple MySQL