aboutsummaryrefslogtreecommitdiff
path: root/Python.wiki
blob: 5df7d2e82a5cba5920560167e9d151b81e270cf3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
%title Python

[[PEP3131]]

= Properties =
property

{{{python
field = property(get_f, set_f)
}}}

{{{python
class C:
    def __init__(self):
        self._x = 10
        
    @property
    def x(self):
        return self._x
    
    @x.setter
    def x(self, value):
        self._x = value
}}}

= Imports are lazy =

== main.py ==
{{{python
import sys

match sys.argv:
    case [prgr]:
        print('Please give a sub-option')
    case [prgr, 'a', *args]:
        from a import x
        print(f'x = {x}')
    case [prgr, 'b', *args]:
        from b import x
        print(f'x = {x}')
}}}


== a.py ==
{{{python
print('Importing a')
x = 10
}}}

== b.py ==
{{{python
print('Importing b')
x = 20
}}}