My Coding >
Programming language >
Python >
Working with files in Python
Working with files in PythonWorking with files in Python Open and read fileFiles can be open for reading, writing and appending in binary and text mode. Pythong give a lot of different ways to work with files.# r – read (default, can be omitted), w-write, a-append, r+ - read write Read whole file in one goIt is possible to read all file in one go
If you will give parameters for read(N) – it will read next N-characters. You need to be careful with this parameters. It will read N-characters in selected coding. By default it will read N-bytes. If the file encoding will be stated, it will read N- characters in this encoding. Read file by linesIf file is pretty big, it is better to read it line by line and process accordingly
Open and immediately close fileTo avoid any problems with file, it is better to close it immediately after use. Python give very simple tool for closing file immediately after reading
Work with few files togetherPython allow to work in WITH block with few files together
|
Last 10 artitles
9 popular artitles
|
|
© 2020 MyCoding.uk -My blog about coding and further learning. This blog was writen with pure Perl and front-end output was performed with TemplateToolkit. |