aboutsummaryrefslogtreecommitdiff
path: root/Python.wiki
blob: 492102018ff64a5ed3145b263afb4b744cabd077 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
%title Python

- [[PEP3131]] :: Handling of weird unicode characters
- [[Python Operators]] :: And operator overloading
- [[Python Pipeline]]

= String IO =
Open strings as file descriptors

{{{python
import io
f = io.StringIO("Hello, World")
f.read()
# ⇒ 'H'
}}}


= Disable typing for line =
{{{python
somethintg_which_doesnt_typecheck()  # type: ignore
}}}

= 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
}}}