Skip to main content

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

Project description

  • Create and edit multiline text.

  • A good tool to realize __repr__.

import it by from reprlist import Reprlist

Initialize it with an iterable object (or None to do nothing), like ‘str’ or ‘list’.

In [1]: from reprlist import Reprlist

In [2]: Reprlist( '1-2' )        #Same as 'Reprlist(['1', '-', '2'])'.
Out[2]:
0:1
1:-
2:2

In [3]: Reprlist([               #Also supports 2D list.
...: ['=', '========', '='],
...: ['|', 'Hello world!', '|'],
...: ['=', '========', '='],
...: ])
Out[3]:
0:=========    =
1:|Hello world!|
2:=========    =

Extend by method extend with an iterable object, if iterable’s length ≠ R.length, align center. You can specify the number of aligned line with method smart_extend.

In [2]: Reprlist(' 1-2').extend([' + ']).extend(' 1-3 ').extend([' = ']).extend('5-6')
Out[2]:
0:
1:1   1   5
2:- + - = -
3:2   3   6
4:

Method insert(obj, new_index) inserts str starts at new_index with each item obj in the end.

In [7]: Reprlist([' 1 ','---',' 2 ']).insert('1-x', 2)
Out[7]:
0: 1
1:---
2:   1
3:   -
4:   x
5: 2

You can remove empty lines with method get_removed_empty_lines, this method will return a new object without changes.

In [2]: Reprlist(' ' if i%2 else '-' for i in range(5)).get_removed_empty_lines()
Out[2]:
0:-
1:-

Slice with [:], returns the text in each line;

with [:,:], you can see text blocks, the block shows the text each time you extended.

In [41]: R = Reprlist([' 1','--',' 2'])

In [42]: R[:, :]
Out[42]: [[' 1'], ['--'], [' 2']]

In [43]: R.extend('-')
Out[43]:
0: 1
1:---
2: 2

In [44]: R[:, :]
Out[44]: [[' 1', ' '], ['--', '-'], [' 2', ' ']]

In [45]: R.insert([' x '], 2)
Out[45]:
0: 1
1:---
2:    x
3: 2

In [46]: R[:, :]
Out[46]:
[[' 1', ' ', '   '],
['--', '-', '   '],
['  ', ' ', ' x '],
[' 2', ' ', '   ']]

In [47]: R[:, -1]
Out[47]: ['   ', '   ', ' x ', '   ']
``dev.Reprlist`` almost compatible with Reprlist, and it doesn't keep text blocks.

Methods:

Name:

Doc:

__init__(extend=None,rule=None)

Extend value extend if it’s not None. And set the rule from value rule, if rule is None, set with globle_rule,

extend(o,_chack=True)

Extend each line, align center. (particulars the drawing after table).

__add__(val)

Return R.copy().extend(val).

mid

Return len(self)//2.

change_mid(mid)

Draw out until new mid equal 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[,None,None])

Draw and then extend val ‘o’.

get_place_onto(bottom)

Put self on bottom.

line(linenumber)

Return the str at line ‘linenumber’.

to_tk(root=None)

Return root with tk.Label on it, if root is None, auto build a tk.TK.

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

What’s new ?

::
> 1.3.5 —> 1.3.6

Optimize the method extend.

> 1.3.4 —> 1.3.5

Now extend an empty obj will not raise ValueError: Empty sequence got..

Demo:

Creat 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

log

>  2020-3-12, `1.1.0` --> `1.2.0`
1.Add method `line`,`lmove`,'rmove','put_inbox'.
2.Add a new class `dev.Reprlist` do `from reprlist.dev import Reprlist` to import it.
  In dev.Reprlist, the text you extended saved after the text front as line, not block.
  So slice `R[<int1>,<int2>]` returns the char at the index.

>  2020-4-7, `1.2.1` --> `1.2.2`
1.You can set `maxstring``maxline``startswith` for Reprlist.
>  `1.2.8` ---> `1.2.9`
1.Method `place_onto``place_under` add value `wherejust`,
    `wherejust`
        --> 'l' / 'left': storter one in a position of lift.
        --> 'r' / 'right':storter one in a position of right.
        --> 'm' / 'middle':storter one in a position of middle.
2.Change methods `lmove``rmove`.The original char will be in place of lift if `lmove`,
      right if `rmove`.
3.Add methods `ljust` and `rjust`.
>  `1.2.2` ---> `1.2.10`
    Remove some bugs.
>  `1.2.10` ---> `1.3.4`
    Add method `to_tk`.

Project details


Download files

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

Source Distribution

reprlist.py-1.3.9.tar.gz (16.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

reprlist.py-1.3.9-py3-none-any.whl (17.5 kB view details)

Uploaded Python 3

File details

Details for the file reprlist.py-1.3.9.tar.gz.

File metadata

  • Download URL: reprlist.py-1.3.9.tar.gz
  • Upload date:
  • Size: 16.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.11.3 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.63.0 CPython/3.9.12

File hashes

Hashes for reprlist.py-1.3.9.tar.gz
Algorithm Hash digest
SHA256 f78563adc3dc0bb2907f4bc7c744be0b1514846223391b62620867e008297a8b
MD5 b8e7a728c277d6ec50170799e943f426
BLAKE2b-256 7c1a0a858a807ea5306df5db35a451a267ad47a2f636b0d237f9879997d5bcce

See more details on using hashes here.

File details

Details for the file reprlist.py-1.3.9-py3-none-any.whl.

File metadata

  • Download URL: reprlist.py-1.3.9-py3-none-any.whl
  • Upload date:
  • Size: 17.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.11.3 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.63.0 CPython/3.9.12

File hashes

Hashes for reprlist.py-1.3.9-py3-none-any.whl
Algorithm Hash digest
SHA256 1e9d5efdf1aaef32c1c732d83c34ffe88d0885393f6f61b8a7d1cb09df8cb45f
MD5 d2f1f070d88f5719af51fce0ea48a408
BLAKE2b-256 654f5c24d4bcf5a4bfa05650b8141d767076666c3331f863c48544c6f7fba8b8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page