smpl.io

Simplified input and output.

files(folder, ending)

Get all the files in folder ending with ending.

find_file(fname[, up])

Searches for fname in all down folders or up folder to given order respectively.

gf([i])

Scientific number format.

mkdirs(fn)

Creates the neccessary directories above fn.

pr(a[, nnl])

Prints the passed a.

pwd()

Returns the path to the path of current file (in linux format).

read(fname)

Reads the file fname.

write(destination, content)

Write to file by string or writable destiantion.

Functions

smpl.io.files(folder, ending)[source]

Get all the files in folder ending with ending.

Parameters
folderstr

folder name.

endingstr

ending of the files.

Returns
list

list of files.

Examples

>>> files(".",".py")
[(0, 'setup', './setup.py')]
smpl.io.find_file(fname, up=0)[source]

Searches for fname in all down folders or up folder to given order respectively.

smpl.io.gf(i=3)[source]

Scientific number format.

Parameters
iint

Number of digits.

Returns
str

Scientific number format string.

Examples

>>> gf(2)
'{0:.2g}'
>>> gf(2).format(789234578934)
'7.9e+11'
>>> gf(5).format(789234578934)
'7.8923e+11'
smpl.io.mkdirs(fn)[source]

Creates the neccessary directories above fn.

Parameters
fnstr

file name.

Examples

>>> mkdirs("test.out")
smpl.io.pr(a, nnl=False)[source]

Prints the passed a.

Parameters
nnlbool

no-new-line

Returns
aany

unchanged a.

Examples

>>> 5 + pr(4)
4
9
>>> 5 + pr(4, nnl=True)
49
smpl.io.pwd()[source]

Returns the path to the path of current file (in linux format).

Returns
str

path to the path of current file.

smpl.io.read(fname)[source]

Reads the file fname.

Parameters
fnamestr

file name.

Returns
str

content of the file.

Examples

>>> read("nonexistent.txt")
''
>>> write("test.out","hi")
>>> read("test.out")
'hi'
smpl.io.write(destination, content)

Write to file by string or writable destiantion.

Parameters
destinationstr, writeable

destination to write to.

contentstr

text to be written.

Examples

>>> append(sys.stdout,"hi")
hi
>>> append("test.out","hi")
>>> read("test.out")
'hi'