merlin.files

Functions for working with files in python

merlin.files.append(path, data)[source]

Append data to a text file.

Parameters:
  • path (str) – Full path to file
  • data (str) – File text
Returns:

Number of characters appended

Return type:

int

merlin.files.appendb(path, data)[source]

Write data to a binary file.

Parameters:
  • path (str) – Full path to file
  • data (str) – File bytes
Returns:

Number of bytes appended

Return type:

int

merlin.files.delete(path)[source]

Delete a file.

Parameters:path (str) – Full path to file
Returns:True if the file was deleted, False if not (with message logged)
Return type:bool
merlin.files.exists(path)[source]

Determine if a file exists.

Parameters:path (str) – Full path to file
Returns:True if the file exists, False if not
Return type:bool
merlin.files.mkdirs(filename)[source]

Ensures the set of directories exist for the supplied filename.

Parameters:filename (str) – Full path to where the file should exist
Returns:Full file path if the directories were created or None
merlin.files.read(path)[source]

Read a text file.

Parameters:path (str) – Full path to file
Returns:File text
Return type:str
merlin.files.readb(path)[source]

Read a binary file.

Parameters:path (str) – Full path to file
Returns:File bytes
merlin.files.readlines(path)[source]

Read lines from a text file.

Parameters:path (str) – Full path to file
Returns:File text
Return type:list
merlin.files.readlinesb(path)[source]

Read lines from a binary file.

Parameters:path (str) – Full path to file
Returns:File bytes
Return type:list
merlin.files.write(path, data)[source]

Write data to a text file.

Parameters:
  • path (str) – Full path to file
  • data (str) – File text
Returns:

Number of characters written

Return type:

int

merlin.files.writeb(path, data)[source]

Write data to a binary file.

Parameters:
  • path (str) – Full path to file
  • data (str) – File bytes
Returns:

Number of bytes written

Return type:

int