Previous topic

spinnman.data.big_endian_byte_array_byte_writer module

Next topic

spinnman.data.little_endian_byte_array_byte_reader module

This Page

spinnman.data.file_data_reader module

Classes

FileDataReader(filename) A reader that can read data from a file
FileIO file(name: str[, mode: str]) -> file IO object
class spinnman.data.file_data_reader.FileDataReader(filename)[source]

Bases: spinnman.data.abstract_data_reader.AbstractDataReader

A reader that can read data from a file

Parameters:filename (str) – The file to read
Raises spinnman.exceptions.SpinnmanIOException:
 If the file cannot found or opened for reading

Methods

close() Closes the file
read(n_bytes) See spinnman.data.abstract_data_reader.AbstractDataReader.read()
readall() See spinnman.data.abstract_data_reader.AbstractDataReader.readall()
readinto(data) See spinnman.data.abstract_data_reader.AbstractDataReader.readinto()

Detailed Methods

close()[source]

Closes the file

Returns:Nothing is returned:
Return type:None
Raises spinnman.exceptions.SpinnmanIOException:
 If the file cannot be closed
read(n_bytes)[source]

See spinnman.data.abstract_data_reader.AbstractDataReader.read()

readall()[source]

See spinnman.data.abstract_data_reader.AbstractDataReader.readall()

readinto(data)[source]

See spinnman.data.abstract_data_reader.AbstractDataReader.readinto()

class spinnman.data.file_data_reader.FileIO

Bases: _io._RawIOBase

file(name: str[, mode: str]) -> file IO object

Open a file. The mode can be ‘r’, ‘w’ or ‘a’ for reading (default), writing or appending. The file will be created if it doesn’t exist when opened for writing or appending; it will be truncated when opened for writing. Add a ‘+’ to the mode to allow simultaneous reading and writing.

Attributes

closed True if the file is closed
closefd True if the file descriptor will be closed
mode String giving the file mode
next x.next() -> the next value, or raise StopIteration
closed True if the file is closed
next x.next() -> the next value, or raise StopIteration
closed True if the file is closed
next x.next() -> the next value, or raise StopIteration

Methods

close(() -> None.  Close the file.) A closed file cannot be used for further I/O operations.
fileno(() -> int. “file descriptor”.) This is needed for lower-level file interfaces, such the fcntl module.
flush Flush write buffers, if applicable.
isatty(...)
read(...) Only makes one system call, so less data may be returned than requested In non-blocking mode, returns None if no data is available.
readable(...)
readall(...) In non-blocking mode, returns as much as is immediately available, or None if no data is available.
readinto(() -> Same as RawIOBase.readinto().)
readline Read and return a line from the stream.
readlines Return a list of lines from the stream.
seek((offset: int[, ...) Argument offset is a byte count.
seekable(...)
tell(() -> int.  Current file position)
truncate(...) Size defaults to the current file position, as returned by tell().The current file position is changed to the value of size.
writable(...)
write(...) Only makes one system call, so not all of the data may be written.
writelines
close(() -> None.  Close the file.) A closed file cannot be used for further I/O operations.
fileno(() -> int. “file descriptor”.) This is needed for lower-level file interfaces, such the fcntl module.
flush Flush write buffers, if applicable.
isatty(...)
read(...) Only makes one system call, so less data may be returned than requested In non-blocking mode, returns None if no data is available.
readable(...)
readall(...) In non-blocking mode, returns as much as is immediately available, or None if no data is available.
readline Read and return a line from the stream.
readlines Return a list of lines from the stream.
seek((offset: int[, ...) Argument offset is a byte count.
seekable(...)
tell(() -> int.  Current file position)
truncate(...) Size defaults to the current file position, as returned by tell().The current file position is changed to the value of size.
writable(...)
writelines
close(() -> None.  Close the file.) A closed file cannot be used for further I/O operations.
fileno(() -> int. “file descriptor”.) This is needed for lower-level file interfaces, such the fcntl module.
flush Flush write buffers, if applicable.
isatty(...)
readable(...)
readline Read and return a line from the stream.
readlines Return a list of lines from the stream.
seek((offset: int[, ...) Argument offset is a byte count.
seekable(...)
tell(() -> int.  Current file position)
truncate(...) Size defaults to the current file position, as returned by tell().The current file position is changed to the value of size.
writable(...)
writelines

Detailed Methods

close() → None. Close the file.

A closed file cannot be used for further I/O operations. close() may be called more than once without error. Changes the fileno to -1.

fileno() → int. "file descriptor".

This is needed for lower-level file interfaces, such the fcntl module.

flush()

Flush write buffers, if applicable.

This is not implemented for read-only and non-blocking streams.

isatty() → bool. True if the file is connected to a tty device.
read(size: int) → bytes. read at most size bytes, returned as bytes.

Only makes one system call, so less data may be returned than requested In non-blocking mode, returns None if no data is available. On end-of-file, returns ‘’.

readable() → bool. True if file was opened in a read mode.
readall() → bytes. read all data from the file, returned as bytes.

In non-blocking mode, returns as much as is immediately available, or None if no data is available. On end-of-file, returns ‘’.

readinto() → Same as RawIOBase.readinto().
readline()

Read and return a line from the stream.

If limit is specified, at most limit bytes will be read.

The line terminator is always b’n’ for binary files; for text files, the newlines argument to open can be used to select the line terminator(s) recognized.

readlines()

Return a list of lines from the stream.

hint can be specified to control the number of lines read: no more lines will be read if the total size (in bytes/characters) of all lines so far exceeds hint.

seek(offset: int[, whence: int]) → None. Move to new file position.

Argument offset is a byte count. Optional argument whence defaults to 0 (offset from start of file, offset should be >= 0); other values are 1 (move relative to current position, positive or negative), and 2 (move relative to end of file, usually negative, although many platforms allow seeking beyond the end of a file). Note that not all file objects are seekable.

seekable() → bool. True if file supports random-access.
tell() → int. Current file position
truncate([size: int]) → None. Truncate the file to at most size bytes.

Size defaults to the current file position, as returned by tell().The current file position is changed to the value of size.

writable() → bool. True if file was opened in a write mode.
write(b: bytes) → int. Write bytes b to file, return number written.

Only makes one system call, so not all of the data may be written. The number of bytes actually written is returned.

writelines()
close() → None. Close the file.

A closed file cannot be used for further I/O operations. close() may be called more than once without error. Changes the fileno to -1.

fileno() → int. "file descriptor".

This is needed for lower-level file interfaces, such the fcntl module.

flush()

Flush write buffers, if applicable.

This is not implemented for read-only and non-blocking streams.

isatty() → bool. True if the file is connected to a tty device.
read(size: int) → bytes. read at most size bytes, returned as bytes.

Only makes one system call, so less data may be returned than requested In non-blocking mode, returns None if no data is available. On end-of-file, returns ‘’.

readable() → bool. True if file was opened in a read mode.
readall() → bytes. read all data from the file, returned as bytes.

In non-blocking mode, returns as much as is immediately available, or None if no data is available. On end-of-file, returns ‘’.

readline()

Read and return a line from the stream.

If limit is specified, at most limit bytes will be read.

The line terminator is always b’n’ for binary files; for text files, the newlines argument to open can be used to select the line terminator(s) recognized.

readlines()

Return a list of lines from the stream.

hint can be specified to control the number of lines read: no more lines will be read if the total size (in bytes/characters) of all lines so far exceeds hint.

seek(offset: int[, whence: int]) → None. Move to new file position.

Argument offset is a byte count. Optional argument whence defaults to 0 (offset from start of file, offset should be >= 0); other values are 1 (move relative to current position, positive or negative), and 2 (move relative to end of file, usually negative, although many platforms allow seeking beyond the end of a file). Note that not all file objects are seekable.

seekable() → bool. True if file supports random-access.
tell() → int. Current file position
truncate([size: int]) → None. Truncate the file to at most size bytes.

Size defaults to the current file position, as returned by tell().The current file position is changed to the value of size.

writable() → bool. True if file was opened in a write mode.
writelines()
close() → None. Close the file.

A closed file cannot be used for further I/O operations. close() may be called more than once without error. Changes the fileno to -1.

fileno() → int. "file descriptor".

This is needed for lower-level file interfaces, such the fcntl module.

flush()

Flush write buffers, if applicable.

This is not implemented for read-only and non-blocking streams.

isatty() → bool. True if the file is connected to a tty device.
readable() → bool. True if file was opened in a read mode.
readline()

Read and return a line from the stream.

If limit is specified, at most limit bytes will be read.

The line terminator is always b’n’ for binary files; for text files, the newlines argument to open can be used to select the line terminator(s) recognized.

readlines()

Return a list of lines from the stream.

hint can be specified to control the number of lines read: no more lines will be read if the total size (in bytes/characters) of all lines so far exceeds hint.

seek(offset: int[, whence: int]) → None. Move to new file position.

Argument offset is a byte count. Optional argument whence defaults to 0 (offset from start of file, offset should be >= 0); other values are 1 (move relative to current position, positive or negative), and 2 (move relative to end of file, usually negative, although many platforms allow seeking beyond the end of a file). Note that not all file objects are seekable.

seekable() → bool. True if file supports random-access.
tell() → int. Current file position
truncate([size: int]) → None. Truncate the file to at most size bytes.

Size defaults to the current file position, as returned by tell().The current file position is changed to the value of size.

writable() → bool. True if file was opened in a write mode.
writelines()