-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPython_Vychytavky
More file actions
57 lines (40 loc) · 1.57 KB
/
Python_Vychytavky
File metadata and controls
57 lines (40 loc) · 1.57 KB
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
#!/bin/env python
# ---- python debug
# https://switowski.com/blog/ipython-debugging
```# Put breakpoint in code
import pdb;pdb.set_trace()
# Use h on the pdb command line to se see available commands```
More advanced (autocomplete, colors, contex) `ipdb` (pip installable)
```# Put breakpoint in code
import ipdb;ipdb.set_trace(context=30)
# Use h on the pdb command line to se see available commands```
# Using embed - run ipython at desired cmd line
from IPython import embed; embed()
# Editable instalation:
# -- paths are saved in:
envs/espnet/lib/python3.9/site-packages/easy-install.pth
# --------------
# ---- Conda
# --------------
# conda create
conda create --name ENV_NAME python=3.7.9
# conda remove
conda env remove -n ENV_NAME
# --------------------------
# --- Text processing
# ---- correct split utf characters
from pyuegc import EGC # pip install pyuegc
string = 'Puélla in vī́llā vīcī́nā hábitat.'
egc = EGC(string)
print(egc)
# ['P', 'u', 'é', 'l', 'l', 'a', ' ', 'i', 'n', ' ', 'v', 'ī́', 'l', 'l', 'ā', ' ', 'v', 'ī', 'c', 'ī́', 'n', 'ā', ' ', 'h', 'á', 'b', 'i', 't', 'a', 't', '.']
# -----------------------
# operands functions and so
https://www.itnetwork.cz/python/kolekce/komprehence-lambda-vyrazy-a-funkce-v-pythonu # nice overview
print(str(1).zfill(2)) # zero padding
# json load/write
with open('strings.json') as f:
data = json.load(f)
with open('strings.json','w') as f: json.dump(data,f) # python 2,3
with open('data.json', 'w', encoding='utf-8') as f: # python 3 only
json.dump(data, f, ensure_ascii=False, indent=4)