DotProxyList usage examples — RedBaron 0.8 documentation

# DotProxyList usage examples

    In [1]: red = RedBaron("a.b(c).d[e]")

Please refer to python list documentation if you want to know the exact behavior or those methods (or send a patch to improve this documentation).

## append

    In [2]: red
    Out[2]: 0   a.b(c).d[e]

    In [3]: red[0].value.append("(stuff)")

    In [4]: red
    Out[4]: 0   a.b(c).d[e](stuff)

    In [5]: red[0].value
    Out[5]:
    0   a
    1   b
    2   (c)
    3   d
    4   [e]
    5   (stuff)

## insert

    In [6]: red
    Out[6]: 0   a.b(c).d[e](stuff)

    In [7]: red[0].value.insert(1, "[foobar]")

    In [8]: red
    Out[8]: 0   a[foobar].b(c).d[e](stuff)

    In [9]: red[0].value
    Out[9]:
    0   a
    1   [foobar]
    2   b
    3   (c)
    4   d
    5   [e]
    6   (stuff)

## extend

    In [10]: red
    Out[10]: 0   a[foobar].b(c).d[e](stuff)

    In [11]: red[0].value.extend(["a", "(hop)", "()"])

    In [12]: red
    Out[12]: 0   a[foobar].b(c).d[e](stuff).a(hop)()

    In [13]: red[0].value
    Out[13]:
    0   a
    1   [foobar]
    2   b
    3   (c)
    4   d
    5   [e]
    6   (stuff)
    7   a
    8   (hop)
    9   ()

## pop

    In [14]: red
    Out[14]: 0   a[foobar].b(c).d[e](stuff).a(hop)()

    In [15]: red[0].value.pop()

    In [16]: red
    Out[16]: 0   a[foobar].b(c).d[e](stuff).a(hop)

    In [17]: red[0].value
    Out[17]:
    0   a
    1   [foobar]
    2   b
    3   (c)
    4   d
    5   [e]
    6   (stuff)
    7   a
    8   (hop)

    In [18]: red[0].value.pop(3)

    In [19]: red
    Out[19]: 0   a[foobar].b.d[e](stuff).a(hop)

    In [20]: red[0].value
    Out[20]:
    0   a
    1   [foobar]
    2   b
    3   d
    4   [e]
    5   (stuff)
    6   a
    7   (hop)

## __getitem__

    In [21]: red
    Out[21]: 0   a[foobar].b.d[e](stuff).a(hop)

    In [22]: red[0].value
    Out[22]:
    0   a
    1   [foobar]
    2   b
    3   d
    4   [e]
    5   (stuff)
    6   a
    7   (hop)

    In [23]: red[0].value[2]
    Out[23]: b

## __setitem__

    In [24]: red
    Out[24]: 0   a[foobar].b.d[e](stuff).a(hop)

    In [25]: red[0].value[2] = "[1:2]"

    In [26]: red
    Out[26]: 0   a[foobar][1:2].d[e](stuff).a(hop)

    In [27]: red[0].value
    Out[27]:
    0   a
    1   [foobar]
    2   [1:2]
    3   d
    4   [e]
    5   (stuff)
    6   a
    7   (hop)

## remove

    In [28]: red
    Out[28]: 0   a[foobar][1:2].d[e](stuff).a(hop)

    In [29]: red[0].value.remove(red[0].value[2])

    In [30]: red
    Out[30]: 0   a[foobar].d[e](stuff).a(hop)

    In [31]: red[0].value
    Out[31]:
    0   a
    1   [foobar]
    2   d
    3   [e]
    4   (stuff)
    5   a
    6   (hop)

## index

    In [32]: red
    Out[32]: 0   a[foobar].d[e](stuff).a(hop)

    In [33]: red[0].value
    Out[33]:
    0   a
    1   [foobar]
    2   d
    3   [e]
    4   (stuff)
    5   a
    6   (hop)

    In [34]: red[0].value.index(red[0].value[2])
    Out[34]: 2

## count

    In [35]: red
    Out[35]: 0   a[foobar].d[e](stuff).a(hop)

    In [36]: red[0].value
    Out[36]:
    0   a
    1   [foobar]
    2   d
    3   [e]
    4   (stuff)
    5   a
    6   (hop)

    In [37]: red[0].value.count(red[0].value[2])
    Out[37]: 1

## len

    In [38]: red
    Out[38]: 0   a[foobar].d[e](stuff).a(hop)

    In [39]: red[0].value
    Out[39]:
    0   a
    1   [foobar]
    2   d
    3   [e]
    4   (stuff)
    5   a
    6   (hop)

    In [40]: len(red[0].value)
    Out[40]: 7

## __delitem__

    In [41]: red
    Out[41]: 0   a[foobar].d[e](stuff).a(hop)

    In [42]: del red[0].value[2]

    In [43]: red
    Out[43]: 0   a[foobar][e](stuff).a(hop)

    In [44]: red[0].value
    Out[44]:
    0   a
    1   [foobar]
    2   [e]
    3   (stuff)
    4   a
    5   (hop)

## in

    In [45]: red
    Out[45]: 0   a[foobar][e](stuff).a(hop)

    In [46]: red[0].value[2] in red[0].value
    Out[46]: False

## __iter__

    In [47]: red
    Out[47]: 0   a[foobar][e](stuff).a(hop)

    In [48]: for i in red[0].value:
       ....:     print(i.dumps())
       ....:
    a
    [foobar]
    [e]
    (stuff)
    a
    (hop)

## __getslice__

    In [49]: red
    Out[49]: 0   a[foobar][e](stuff).a(hop)

    In [50]: red[0].value
    Out[50]:
    0   a
    1   [foobar]
    2   [e]
    3   (stuff)
    4   a
    5   (hop)

    In [51]: red[0].value[2:4]
    Out[51]:
    0   [e]
    1   (stuff)

## __setslice__

    In [52]: red
    Out[52]: 0   a[foobar][e](stuff).a(hop)

    In [53]: red[0].value[2:4] = ["(foo)", "a", "b", "c"]

    In [54]: red
    Out[54]: 0   a[foobar](foo).a.b.c.a(hop)

    In [55]: red[0].value
    Out[55]:
    0   a
    1   [foobar]
    2   (foo)
    3   a
    4   b
    5   c
    6   a
    7   (hop)

## __delslice__

    In [56]: red
    Out[56]: 0   a[foobar](foo).a.b.c.a(hop)

    In [57]: red[0].value[2:5]
    Out[57]:
    0   (foo)
    1   a
    2   b

    In [58]: del red[0].value[2:5]

    In [59]: red
    Out[59]: 0   a[foobar].c.a(hop)

    In [60]: red[0].value
    Out[60]:
    0   a
    1   [foobar]
    2   c
    3   a
    4   (hop)