commands of files Flashcards

1
Q

target = open(filename, ‘w’)

A

This is the way of opening files
we assign them to variables .
And the “open” command holds two values inside: the name of the file, and the mode in which file will be opened

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

target.close()

A

It closes the file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

target.write(“something”)

A

This command writes in the file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

target.truncate()

A

Deletes what’s inside the file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

print(target.read())

A

We print what’s inside the file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

w+, r+, a+

A

Modifier allows you to open python in both read and write mode

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

from os.path import exists

{exists(name_of_file)}

A

This is imported function that’s used to show «True» if file exists or false if doesn’t

How well did you know this?
1
Not at all
2
3
4
5
Perfectly