FANDOM


Genearl information Edit

Files are a basic data structure used in every programming language. In Python handling Files is especially easy.

Basic Syntax Edit

Open Files Edit

To open files we use the open-command:

open(filename, access-mode)

Closing files Edit

To close files, we use (well, what else) the close-command:

close()

Writing information Edit

To write information to a file, we use the write-command:

write('String_to_write_to_file')

Note that with the write-command, we can only write Strings to a file, for writing more complicated structures, please check out the Pickle module.

Reading informations Edit

Like the write-command, there exists the read-command:

read()

Access-mode Edit

There are several different access-modes:

Access-mode Explanation
w Write-mode, overwrites data if file is non-empty
r Read-mode, read-only
a Append-mode, writes informations at the end of the file
For all of these modes there exists the same one with a '+', e.g. w+. This is read-and-write-mode.
For all of these also exists the same name with 'b', e.g. wb. This stands for binary-mode.

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.