Differences between revisions 2 and 4 (spanning 2 versions)
Revision 2 as of 2008-04-16 17:37:43
Size: 329
Editor: anonymous
Comment:
Revision 4 as of 2008-04-16 17:52:48
Size: 904
Editor: anonymous
Comment:
Deletions are marked like this. Additions are marked like this.
Line 14: Line 14:
The [[http://docs.python.org/lib/bltin-file-objects.html|file object]] can be used for reading and
writing plain text as well as unformatted binary data. The following code
writes a message in the file with the name ''out.txt'', reads and print the data
{{{#!python
file('out.txt','w').write('Hallo Datentraeger')
print file('out.txt').read()
}}}

 * {{{write()}}} writes a string to the file
 * {{{read()}}} reads complete file
 * {{{read(N)}}} reads N bytes
 * {{{readlines()}}} reads the file with linebreaks
 * {{{readline()}}} reads only the next line

SiaProgrammingPython

Input/Output

This lesson deals with the ways of reading and writing data

Basic Python

The file object can be used for reading and writing plain text as well as unformatted binary data. The following code writes a message in the file with the name out.txt, reads and print the data

   1 file('out.txt','w').write('Hallo Datentraeger')
   2 print file('out.txt').read()
  • write() writes a string to the file

  • read() reads complete file

  • read(N) reads N bytes

  • readlines() reads the file with linebreaks

  • readline() reads only the next line

NumPy/SciPy

HDF

netCDF

Various Satellite data formats

LehreWiki: SiaProgrammingPythonIo (last edited 2008-04-21 12:10:37 by anonymous)