-
Notifications
You must be signed in to change notification settings - Fork 0
/
File_write().py
39 lines (28 loc) · 1.07 KB
/
File_write().py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# Python File write() Method
# Example
# Open the file with "a" for appending, then add some text to the file:
f = open("demofile2.txt", "a")
f.write("See you soon!")
f.close()
#open and read the file after the appending:
f = open("demofile2.txt", "r")
print(f.read())
# Definition and Usage
# The write() method writes a specified text to the file.
# Where the specified text will be inserted depends on the file mode and stream position.
# "a": The text will be inserted at the current file stream position, default at the end of the file.
# "w": The file will be emptied before the text will be inserted at the current file stream position, default 0.
# Syntax
# file.write(byte)
# Parameter Values
# Parameter Description
# byte The text or byte object that will be inserted.
# More examples
# Example
# The same example as above, but inserting a line break before the inserted text:
f = open("demofile2.txt", "a")
f.write("\nSee you soon!")
f.close()
#open and read the file after the appending:
f = open("demofile2.txt", "r")
print(f.read())