Rprint

Pure python custom print implementation


Project maintained by Wirtos Hosted on GitHub Pages — Theme by mattgraham

Rprint is a faster pure python print implementation.

from rprintlib import Rprint
rprint = Rprint()

Main features:

from rprintlib import rprint #predefined rprint object
>>> rprint(12, 33, None, 'String', sep=' - ')
>>>
>>> rprint(1.23)
>>> 
>>> rprint.ret() # ->list copy
>>> ['12 - 33 - None - String\n', '1.23\n']
>>> str(rprint) # ->str
>>> '12 - 33 - None - String\n1.23\n'
>>> repr(rprint) # ->repr 
>>> "<rprintlib.rpmain.Rprint('12 - 33 - None - String\\n', '1.23\\n', sep='', end='')>"
>>> iter(rprint)
>>> <list_iterator object at 0x0000013AD992D320>

Why rprint?

Installation

requires python 3 and up

Packages required: None, you don’t need any installed

$ pip install rprintlib --upgrade

or

$ pip install git+https://github.com/Wirtos/Rprint

FAQ

Can i print to console or file with rprint?

yes:

import sys
rprint('something', file=sys.stdout)
>>> 'something'

It is possible to use starred expressions?

import sys
rprint(*('sure', 'why', 'not'), sep=" - ", file=sys.stdout)
>>> 'sure - why - not'

I need to type file= everytime i want to use stdout or other writable file?

Well, no. You can do something like:

import sys
rprint.rtdout.stdout = sys.stdout
rprint(1)
>>> 1
rprint('rtdout - default class for storing output source')
>>> 'rtdout - default class for storing output'

Or even better solution:

from rprintlib import sprint # predefined stdout Rprint object
sprint(2)
>>> 2

So, there are two base classes?

Yep. Here’s the argument list for each of them:

Rprint(self, *objects, sep=’ ‘, end=’\n’, flush=False, file=None)

Rtdout(self)

and usable methods and attributes for Rprint:

You can also use rprint with context manager:

with rprint:
    rprint(12)
    print(rprint.ret())
    >>> ['12\n']
# flush() on exit. Storage is empty now
print(rprint.ret())
>>> []