smpl.io

Simplified input and output.

append(destination, content[, mode])

Appends to file by string or writable destiantion.

files(ending[, folder])

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[, mode])

Write to file by string or writable destiantion.

Functions

smpl.io.append(destination, content, mode='a+')[source]

Appends to file by string or writable destiantion.

destinationstr, writeable

destination to write to.

contentstr

text to be written.

modestr

mode to open the file. Default is ‘a+’ (append and read).

>>> append(sys.stdout,"hi")
hi
smpl.io.files(ending, folder='.')[source]

Get all the files in folder ending with ending.

folderstr

folder name.

endingstr

ending of the files.

list

list of files.

>>> 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.

iint

Number of digits.

str

Scientific number format string.

>>> 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.

fnstr

file name.

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

Prints the passed a.

nnlbool

no-new-line

aany

unchanged a.

>>> 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).

str

path to the path of current file.

smpl.io.read(fname)[source]

Reads the file fname.

fnamestr

file name.

str

content of the file.

>>> read("nonexistent.txt")
''
>>> write("test.out","hi")
>>> read("test.out")
'hi'
smpl.io.write(destination, content, mode='w+')[source]

Write to file by string or writable destiantion.

destinationstr, writeable

destination to write to.

contentstr

text to be written.

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