Python errors All In One
Python errors All In One
errors ❌
from: can't read /var/mail/gpiozero
https://stackoverflow.com/questions/16069816/getting-python-error-from-cant-read-var-mail-bio
SyntaxError: Non-ASCII character '\xe6' in file ./test.py on line 32, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
http://python.org/dev/peps/pep-0263/
Pyhton 2 不支持中文
和 emoji
❌
- 接收命令行参数 error ❌
-
sys
-
argparse
-
shell script
-
tensorflow
-
getopt
https://www.cnblogs.com/xgqfrms/p/17273858.html
- 类型转换 error ❌
https://www.cnblogs.com/xgqfrms/p/17273620.html
demos
#!/usr/bin/env python
# coding: utf8
from gpiozero import LED
from time import sleep
led = LED(12)
# Change 12 to your GPIO pin
# block comments
"""
led.on()
sleep(3)
led.off()
"""
def run(time):
led.on()
sleep(time)
led.off()
def init(n):
i = 0
while i < n:
print(i)
i += 1
sleep(1)
run(1)
# python 接收命令行参数❓
init(7)
bugs
- UTF8
# -*- coding: UTF-8 -*-
✅
# coding: utf8
✅
# coding: UTF-8
✅
Unicode & 中文
#!/usr/bin/python
# -*- coding: UTF-8 -*-
# UTF8 Emoji zh-Hans Test
if(1 < "3"):
print "ok ✅ 正确"
else:
print "bug ❌ 错误"
#!/usr/bin/python
# coding: utf8
# coding: UTF-8
# UTF8 Emoji zh-Hans Test
if(1 < "3"):
print "ok ✅ 正确"
else:
print "bug ❌ 错误"
- 类型转换
string to
int
#!/usr/bin/env python
# coding: utf8
import sys
# arg1 = sys.argv[1]
from gpiozero import LED
from time import sleep
led = LED(12)
# Change 12 to your GPIO pin
# order, import fisrt
arg1 = sys.argv[1]
print("arg1 =" + arg1)
# block comments
"""
led.on()
sleep(3)
led.off()
"""
def run(time):
led.on()
sleep(time)
led.off()
def init(n):
i = 0
while i < n:
print(i)
i += 1
sleep(1)
run(1)
# python command line args
# init(7)
init(arg1)
(🐞 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!
refs
©xgqfrms 2012-2021
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/17269990.html
未经授权禁止转载,违者必究!