FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
HelloPython/basicKnowledge/Encode.py at master · tanglei168/HelloPython · GitHub
tanglei168
/
HelloPython
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Issues
0
Pull requests
1
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
HelloPython
/
basicKnowledge
/
Encode.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
36 lines (26 loc) · 787 Bytes
Breadcrumbs
HelloPython
/
basicKnowledge
/
Encode.py
Copy path
File metadata and controls
36 lines (26 loc) · 787 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'''
什么?编码问题
没有的事~~
'''
__author__
=
'tzl'
import
sys
,
locale
print
(
"代码默认编码格式:"
,
sys
.
getdefaultencoding
())
print
(
"系统源码默认保存格式:"
,
sys
.
getfilesystemencoding
())
print
(
"系统源码默认保存格式:"
,
locale
.
getdefaultlocale
())
##########
# Python3 中需要关注的是str(字符)和bytes(字节)之间的关系
##########
a
=
'a'
print
(
a
,
type
(
a
))
print
(
'中国'
.
encode
(
'utf-8'
))
print
(
len
(
'中国'
.
encode
(
'utf-8'
)))
# ascii 不支持中文编码
# print('中国'.encode('ascii'))
print
(
'ABC'
.
encode
(
'utf-8'
))
print
(
len
(
'ABC'
.
encode
(
'utf-8'
)))
# 忽略错误字节 errors='ignore'
print
(
b'
\xe4
\xb8
\xad
\xff
'
.
decode
(
'utf-8'
,
errors
=
'ignore'
))
b
=
b'a'
print
(
b
,
type
(
b
))
Back
|
FazBrowse Home
|
New Git URL