Skip to main content

Create and edit multiline text(str), great tool to realize __repr__.

Project description

  • Create and edit multiline text.
  • A good tool to realize __repr__.

Methods:

Name: Doc:
__init__(extend=None) Extend value extend if it’s not None.
extend(o,_chack=True) Extend each line, align center (particulars the drawing after table). Auto lengthen the shape of ‘o’.
__add__(val) Return R.copy().extend(val).
mid Return len(self)//2.
change_mid(mid) Draw out until new mid == given-mid. Same as R.mid = mid.
combine() Combine all the str-blocks.
separate() Separate all the str-blocks to 1-length str.
smart_extend(o, Draw and then extend val ‘o’.
self_mid = None,  
o_mid = None)  
get_place_onto(bottom) Put self on bottom.
line(linenumber) Return the str at line ‘linenumber’.

The drawing about ‘extend’:

       l=6  lo=3
    0  ___
    1  ___
    2  ___  ___  0
mid>3  ___  ___  1<
    4  ___  ___  2
    5  ___
    6

        l=3     lo=7
               ___ 0
               ___ 1
    0  ___     ___ 2
mid>1  ___     ___ 3<
    2  ___     ___ 4
               ___ 5
               ___ 6
                   7

Demo 1:

e.g. Show “((Yx2^2)/3)X” in multiline.
In [1]: from reprlist import Reprlist

In [2]: Reprlist()
Out[2]:

In [3]: r = Reprlist([[' Y '],
...:                  ['---'],
...:                  [' 3 ']]);r
Out[3]:
0: Y
1:---
2: 3

In [4]: r.append('x2', 0)
Out[4]:
0: Y x2
1:---
2: 3

In [5]: r[:,:]
Out[5]: [[' Y ', 'x2'], ['---', '  '], [' 3 ', '  ']]

In [6]: r.extend(['X'])#Align center.
Out[6]:
0: Y x2
1:---  X
2: 3

In [7]: r[:,:]
Out[7]:
[[' Y ', 'x2', ' '],
 ['---', '  ', 'X'],
 [' 3 ', '  ', ' ']]

In [8]: r[1,1] = '- '#I want change the str.

In [9]: r
Out[9]:
0: Y x2
1:---- X
2: 3

In [10]: r = r.get_inserted('2',0);r
Out[11]:
0:     2
1: Y x2
2:---- X
3: 3

In [12]: print(str(r)) #Show it without line number.

     2
 Y x2
---- X
 3

Demo 2:

Create a class.
from reprlist import Reprlist
class UnKnow:
    def __init__(self, mul = 1, power = 1, num = 0):
        self.mul = mul
        self.power = power
        self.num = num
    def __repr__(self):
        r = Reprlist()
        m = (str(self.mul) + ' * ')if self.mul != 1 else ''
        r.extend([m + 'X'])
        if self.power != 1:
            r.smart_extend(str(self.power),o_mid=1)
        if self.num:
            n = str(self.num)
            if n.startswith('-'):
                n = ' - ' + n[1:]
            else:
                n = ' + ' + n
            r.extend([n])
        return str(r)
>>>UnKnow()

X
>>>UnKnow(2,2,3)

     2
2 * X  + 3
>>>UnKnow(4,5,-2)

     5
4 * X  - 2

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for reprlist-Juntong, version 1.1.0
Filename, size File type Python version Upload date Hashes
Filename, size reprlist_Juntong-1.1.0-py3-none-any.whl (8.1 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size reprlist-Juntong-1.1.0.tar.gz (6.7 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page