python中的实用工具 汉字转拼音、地址、电话、二维码

汉字转拼音: 

#pip install pypinyin
#python
将汉字翻译为带声调的拼音:
>>> from pypinyin import pinyin, lazy_pinyin, Style
>>> pinyin("武汉市中心")
[['wǔ'], ['hàn'], ['shì'], ['zhōng'], ['xīn']]


>>> pinyin('中心', heteronym=True)  #多音字风格:
[['zhōng', 'zhòng'], ['xīn']]

>>> pinyin('武汉市中心', style=Style.FIRST_LETTER)  # 设置拼音首字母风格
[['w'], ['h'], ['s'], ['z'], ['x']]


也可以直接使用命令进行翻译:
C:\>pypinyin 武汉市中心
wǔ hàn shì zhōng xīn

文章参考:

https://pypinyin.readthedocs.io/zh_CN/master/
https://github.com/mozillazg/python-pinyin

地理位置获取:

C:\>pip install geopy

C:\>pip list | findstr /i "geographiclib geopy"
geographiclib               1.49
geopy                       1.19.0

国内可以利用百度和高德地图的信息获取地理位置,经纬度,用于计算距离等.

文章参考:
https://github.com/geopy/geopy
https://blog.csdn.net/weixin_41561539/article/details/87277103

电话手机号

C:\>pip install phonenumbers

C:\>pip list | findstr /i "phone"
phonenumbers                8.10.10


>>> import phonenumbers
>>> x = phonenumbers.parse("+8613419534224", None)
>>> print(x)
Country Code: 86 National Number: 13419534224


参考:
https://github.com/daviddrysdale/python-phonenumbers

身份证:

身份证信息的生成和校验:

https://github.com/jayknoxqu/id-number-util

二维码:

二维码处理软件myqr:
>pip install MyQR
>pip list | findstr /i "imageio  numpy Pillow olefile myqr"
imageio                     2.5.0
MyQR                        2.3.1
numpy                       1.15.4
olefile                     0.44
Pillow                      4.2.1

# myqr www.github.com
line 16: mode: byte
Succeed! 
Check out your 3-H QR-code: /root/qrcode.png

帮助信息:
# myqr --help
usage: myqr [-h]
            [-v {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}]
            [-l {L,M,Q,H}] [-p PICTURE] [-c] [-con CONTRAST] [-bri BRIGHTNESS]
            [-n NAME] [-d DIRECTORY]
            Words

positional arguments:
  Words                 The words to produce you QR-code picture, like a URL
                        or a sentence. Please read the README file for the
                        supported characters.

optional arguments:
  -h, --help            show this help message and exit
  -v {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}, --version {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}
                        The version means the length of a side of the QR-Code
                        picture. From little size to large is 1 to 40.
  -l {L,M,Q,H}, --level {L,M,Q,H}
                        Use this argument to choose an Error-Correction-Level:
                        L(Low), M(Medium) or Q(Quartile), H(High). Otherwise,
                        just use the default one: H
  -p PICTURE, --picture PICTURE
                        the picture e.g. example.jpg
  -c, --colorized       Produce a colorized QR-Code with your picture. Just
                        works when there is a correct '-p' or '--picture'.
  -con CONTRAST, --contrast CONTRAST
                        A floating point value controlling the enhancement of
                        contrast. Factor 1.0 always returns a copy of the
                        original image, lower factors mean less color
                        (brightness, contrast, etc), and higher values more.
                        There are no restrictions on this value. Default: 1.0
  -bri BRIGHTNESS, --brightness BRIGHTNESS
                        A floating point value controlling the enhancement of
                        brightness. Factor 1.0 always returns a copy of the
                        original image, lower factors mean less color
                        (brightness, contrast, etc), and higher values more.
                        There are no restrictions on this value. Default: 1.0
  -n NAME, --name NAME  The filename of output tailed with one of {'.jpg',
                        '.png', '.bmp', '.gif'}. eg. exampl.png
  -d DIRECTORY, --directory DIRECTORY
                        The directory of output.
示例:
Linux下:
# myqr https://blog.csdn.net/vkingnew -n blog.jpg -d /data/
line 16: mode: byte
Succeed! 
Check out your 4-H QR-code: /data/blog.jpg

windows:
C:\>myqr https://blog.csdn.net/vkingnew -n blog.jpg  -d D:\QR -c
line 16: mode: byte
Succeed!
Check out your 4-H QR-code: D:\QR\blog.jpg


参考:
https://github.com/sylnsfar/qrcode

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值