Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ab99499

Browse filesBrowse files
author
RYAN R MCCOPPIN
committed
04/05 jupyter
1 parent 28d6d03 commit ab99499
Copy full SHA for ab99499

File tree

Expand file treeCollapse file tree

2 files changed

+260
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+260
-0
lines changed

‎04-text-byte/UnicodeText.ipynb

Copy file name to clipboard
+157Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 2,
6+
"metadata": {},
7+
"outputs": [
8+
{
9+
"name": "stdout",
10+
"output_type": "stream",
11+
"text": [
12+
"('en_US', 'cp1252')\n",
13+
"pt_BR.UTF-8\n"
14+
]
15+
}
16+
],
17+
"source": [
18+
"import locale\n",
19+
"\n",
20+
"my_loc = locale.setlocale(locale.LC_COLLATE, 'pt_BR.UTF-8')\n",
21+
"\n",
22+
"print(locale.getdefaultlocale() )\n",
23+
"print(my_loc)"
24+
]
25+
},
26+
{
27+
"cell_type": "code",
28+
"execution_count": 7,
29+
"metadata": {},
30+
"outputs": [
31+
{
32+
"data": {
33+
"text/plain": [
34+
"'LATIN CAPITAL LETTER A'"
35+
]
36+
},
37+
"execution_count": 7,
38+
"metadata": {},
39+
"output_type": "execute_result"
40+
}
41+
],
42+
"source": [
43+
"from unicodedata import name\n",
44+
"\n",
45+
"name('A')"
46+
]
47+
},
48+
{
49+
"cell_type": "code",
50+
"execution_count": 9,
51+
"metadata": {},
52+
"outputs": [
53+
{
54+
"name": "stdout",
55+
"output_type": "stream",
56+
"text": [
57+
"café 5\n"
58+
]
59+
},
60+
{
61+
"data": {
62+
"text/plain": [
63+
"('café', 4)"
64+
]
65+
},
66+
"execution_count": 9,
67+
"metadata": {},
68+
"output_type": "execute_result"
69+
}
70+
],
71+
"source": [
72+
"from unicodedata import normalize\n",
73+
"\n",
74+
"cafe = 'cafe\\N{COMBINING ACUTE ACCENT}'\n",
75+
"print(cafe, len(cafe))\n",
76+
"\n",
77+
"# NFC creates shortest equivalent string\n",
78+
"ncafe = normalize('NFC', cafe)\n",
79+
"ncafe, len(ncafe)"
80+
]
81+
},
82+
{
83+
"cell_type": "code",
84+
"execution_count": 11,
85+
"metadata": {},
86+
"outputs": [
87+
{
88+
"name": "stdout",
89+
"output_type": "stream",
90+
"text": [
91+
"Ω OHM SIGN\n",
92+
"Ω False\n"
93+
]
94+
}
95+
],
96+
"source": [
97+
"from unicodedata import normalize, name\n",
98+
"ohm = '\\u2126'\n",
99+
"print(ohm, name(ohm) )\n",
100+
"\n",
101+
"ohm_c = normalize('NFC', ohm)\n",
102+
"print(ohm_c, ohm==ohm_c)"
103+
]
104+
},
105+
{
106+
"cell_type": "code",
107+
"execution_count": 20,
108+
"metadata": {},
109+
"outputs": [
110+
{
111+
"name": "stdout",
112+
"output_type": "stream",
113+
"text": [
114+
"\n",
115+
"\n",
116+
"½ VULGAR FRACTION ONE HALF\n"
117+
]
118+
}
119+
],
120+
"source": [
121+
"print(\"\\N{BLACK CHESS QUEEN}\")\n",
122+
"print(\"\\N{WHITE CHESS QUEEN}\")\n",
123+
"\n",
124+
"# SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 0-29: unknown Unicode character name\n",
125+
"# print(\"\\N{CAT FACE WITH SMILING EYES}\")\n",
126+
"\n",
127+
"HALF = \"\\N{VULGAR FRACTION ONE HALF}\"\n",
128+
"print( HALF, name(HALF))"
129+
]
130+
}
131+
],
132+
"metadata": {
133+
"interpreter": {
134+
"hash": "a42ccb73e7d9bfdf27e036f1d2b8b681e55fc0743cc5586bc2474d4a60f4b886"
135+
},
136+
"kernelspec": {
137+
"display_name": "Python 3.10.4 64-bit",
138+
"language": "python",
139+
"name": "python3"
140+
},
141+
"language_info": {
142+
"codemirror_mode": {
143+
"name": "ipython",
144+
"version": 3
145+
},
146+
"file_extension": ".py",
147+
"mimetype": "text/x-python",
148+
"name": "python",
149+
"nbconvert_exporter": "python",
150+
"pygments_lexer": "ipython3",
151+
"version": "3.10.4"
152+
},
153+
"orig_nbformat": 4
154+
},
155+
"nbformat": 4,
156+
"nbformat_minor": 2
157+
}
+103Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 13,
6+
"metadata": {},
7+
"outputs": [
8+
{
9+
"name": "stdout",
10+
"output_type": "stream",
11+
"text": [
12+
"{'a': <class 'int'>, 'b': <class 'float'>}\n",
13+
"DemoNTClass(a, b)\n",
14+
"DemoNTClass(a=8, b=1.1)\n",
15+
"spam\n"
16+
]
17+
}
18+
],
19+
"source": [
20+
"from meaning.demo_nt import DemoNTClass\n",
21+
"print(DemoNTClass.__annotations__)\n",
22+
"print(DemoNTClass.__doc__)\n",
23+
"nt = DemoNTClass(8)\n",
24+
"print(nt)\n",
25+
"print(nt.c)\n"
26+
]
27+
},
28+
{
29+
"cell_type": "markdown",
30+
"metadata": {},
31+
"source": [
32+
"Trying to assign values gives **AttributeError** exceptions with different error messages"
33+
]
34+
},
35+
{
36+
"cell_type": "code",
37+
"execution_count": 14,
38+
"metadata": {},
39+
"outputs": [
40+
{
41+
"ename": "AttributeError",
42+
"evalue": "can't set attribute",
43+
"output_type": "error",
44+
"traceback": [
45+
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
46+
"\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)",
47+
"\u001b[1;32mc:\\Users\\Admin\\Documents\\GitHub\\Fluent-Python\\05-data-classes\\DataClassBuilder.ipynb Cell 2'\u001b[0m in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> <a href='vscode-notebook-cell:/c%3A/Users/Admin/Documents/GitHub/Fluent-Python/05-data-classes/DataClassBuilder.ipynb#ch0000001?line=0'>1</a>\u001b[0m nt\u001b[39m.\u001b[39ma \u001b[39m=\u001b[39m \u001b[39m\"\u001b[39m\u001b[39mnew\u001b[39m\u001b[39m\"\u001b[39m\n",
48+
"\u001b[1;31mAttributeError\u001b[0m: can't set attribute"
49+
]
50+
}
51+
],
52+
"source": [
53+
"nt.a = \"new\""
54+
]
55+
},
56+
{
57+
"cell_type": "code",
58+
"execution_count": 17,
59+
"metadata": {},
60+
"outputs": [
61+
{
62+
"ename": "AttributeError",
63+
"evalue": "'DemoNTClass' object attribute 'c' is read-only",
64+
"output_type": "error",
65+
"traceback": [
66+
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
67+
"\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)",
68+
"\u001b[1;32mc:\\Users\\Admin\\Documents\\GitHub\\Fluent-Python\\05-data-classes\\DataClassBuilder.ipynb Cell 3'\u001b[0m in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> <a href='vscode-notebook-cell:/c%3A/Users/Admin/Documents/GitHub/Fluent-Python/05-data-classes/DataClassBuilder.ipynb#ch0000002?line=0'>1</a>\u001b[0m nt\u001b[39m.\u001b[39mc \u001b[39m=\u001b[39m \u001b[39m\"\u001b[39m\u001b[39mnew\u001b[39m\u001b[39m\"\u001b[39m\n",
69+
"\u001b[1;31mAttributeError\u001b[0m: 'DemoNTClass' object attribute 'c' is read-only"
70+
]
71+
}
72+
],
73+
"source": [
74+
"nt.c = \"new\""
75+
]
76+
}
77+
],
78+
"metadata": {
79+
"interpreter": {
80+
"hash": "a42ccb73e7d9bfdf27e036f1d2b8b681e55fc0743cc5586bc2474d4a60f4b886"
81+
},
82+
"kernelspec": {
83+
"display_name": "Python 3.10.4 64-bit",
84+
"language": "python",
85+
"name": "python3"
86+
},
87+
"language_info": {
88+
"codemirror_mode": {
89+
"name": "ipython",
90+
"version": 3
91+
},
92+
"file_extension": ".py",
93+
"mimetype": "text/x-python",
94+
"name": "python",
95+
"nbconvert_exporter": "python",
96+
"pygments_lexer": "ipython3",
97+
"version": "3.10.4"
98+
},
99+
"orig_nbformat": 4
100+
},
101+
"nbformat": 4,
102+
"nbformat_minor": 2
103+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.