Python errors All In One

SyntaxError: invalid character in identifier

\u200b, ZERO WIDTH SPACE

https://stackoverflow.com/questions/14844687/invalid-character-in-identifier

SyntaxError: invalid syntax

if__name__ == "__main__":

# if 关键字,后面加空格
if __name__ == "__main__":

用于区分,如何执行 Python 模块

https://www.jcchouinard.com/python-if-name-equals-main/

https://www.freecodecamp.org/news/if-name-main-python-example/#:~:text=We can use an if,name if it is imported.


# Python program to execute
# main directly
print ("Always executed") if __name__ == "__main__":
# 模块, 被直接执行的时候
print ("Executed when invoked directly")
else:
# 模块,被 import 使用的时候
print ("Executed when imported")

https://www.geeksforgeeks.org/what-does-the-if-name-main-do/

# Suppose this is foo.py.

print("before import")
import math print("before functionA")
def functionA():
print("Function A") print("before functionB")
def functionB():
print("Function B {}".format(math.sqrt(100))) print("before __name__ guard")
if __name__ == '__main__':
functionA()
functionB()
print("after __name__ guard")

https://stackoverflow.com/questions/419163/what-does-if-name-main-do

emoji bug

$ ls
# chmod 777 / chmod 755
$ chmod +x ./dict.py # 可执行脚本
# #!/usr/bin/python3
$ ./dict.py
# 指定解释器
$ python3 ./dict.py

#!/usr/bin/python3 # 一行 OK
# dict = {'Name': 'xgqfrms', 'Age': 18, 'Class': 'First'} # 多行错误
dict = {
'Name': 'xgqfrms',
'Age': 18,
'Class': 'First',
'Country': 'China ',
} # 更新 Age
dict['Age'] = 23 # 添加信息
dict['School'] = "Python 教程" print ("dict['Age']: ", dict['Age'])
print ("dict['School']: ", dict['School'])
print ("dict['Country']: ", dict['Country'])

https://www.runoob.com/python3/python3-dictionary.html

refs



xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


Python errors All In One的更多相关文章

  1. Python Errors and Exceptions

    1. python中的try{}catch{} 2. raise exception 3. try...except ... else.. 4. finally块 python中的异常处理的keywo ...

  2. arcgis python 异常处理

    import arcpy in_features = "c:/base/transport.gdb/roads" try: # Note: CopyFeatures will al ...

  3. arcgis python 发送邮件

    import arcgisscripting, smtplib, os, sys, traceback from email.MIMEMultipart import MIMEMultipart fr ...

  4. caffe2--Install

    Install Welcome to Caffe2! Get started with deep learning today by following the step by step guide ...

  5. caffe2--ubuntu16.04--14.04--install

    Install Welcome to Caffe2! Get started with deep learning today by following the step by step guide ...

  6. Linux下编译安装源码包软件 configure ,make, make install, make test/check, make clean

    http://www.360doc7.net/wxarticlenew/541275971.html 一.什么是源码包软件? 顾名思义,源码包就是源代码的可见的软件包,基于Linux和BSD系统的软件 ...

  7. linux安装python3.*,更换Python2.*

    下载并解压:Python-3.5.7.tgz [root@AH-aQYWTYSJZX01 python3]# ll total 20268 -rw-r----- 1 temp01 temp01 207 ...

  8. Linux下编译安装源码包软件 configure ,make, make install, make test/check, make clean 假目标

    http://www.360doc7.net/wxarticlenew/541275971.html 一.程序的组成部分 Linux下程序大都是由以下几部分组成: 二进制文件:也就是可以运行的程序文件 ...

  9. Python Tutorial 学习(八)--Errors and Exceptions

    Python Tutorial 学习(八)--Errors and Exceptions恢复 Errors and Exceptions 错误与异常 此前,我们还没有开始着眼于错误信息.不过如果你是一 ...

随机推荐

  1. 深入理解SPI机制-服务发现机制

    https://www.jianshu.com/p/3a3edbcd8f24 SPI ,全称为 Service Provider Interface,是一种服务发现机制.它通过在ClassPath路径 ...

  2. 【LinuxShell】命令行常用快捷键

    Ctrl + A :光标跳到一行命令的开头.一般来说,Home 键有相同的效果: Ctrl + E :光标跳到一行命令的结尾.一般来说,End 键有相同的效果:. Ctrl + U :删除所有在光标左 ...

  3. cookie,session,token傻傻分不清

    什么是认证(Authentication) • 通俗地讲就是验证当前用户的身份,证明"你是你自己"(比如:你每天上下班打卡,都需要通过指纹打卡,当你的指纹和系统里录入的指纹相匹配时 ...

  4. Elasticsearch从0到千万级数据查询实践(非转载)

    1.es简介 1.1 起源 https://www.elastic.co/cn/what-is/elasticsearch,es的起源,是因为程序员Shay Banon在使用Apache Lucene ...

  5. GeoJson的生成与解析,JSON解析,Java读写geojson,geotools读取shp文件,Geotools中Geometry对象与GeoJson的相互转换

    GeoJson的生成与解析 一.wkt格式的geometry转成json格式 二.json格式转wkt格式 三.json格式的数据进行解析 四.Java读写geojson 五.geotools读取sh ...

  6. 提高效率的Linux命令

    提高效率的Linux命令 一.fc 二.disown 三.Ctrl + x +e 四.!! 两个感叹号 五.一次创建多个目录或文件 六.tee 七.删除从开头到光标处的命令文本 八.删除从光标到结尾处 ...

  7. 压缩文件 .zip.001 .zip.002合并

    可以把名字特别长的命名为1  这样简单些 copy /B 1.zip.001+1.zip.002 1.zip

  8. Linux忽略大小写的查找技巧(转)

    1.vim 中的查找 Linux 下 vim搜索文件内容时加上 \c 参数可以忽略搜索字符的大小写. 比如用vim 搜索文件中的 China 时 可用 :/china\c 2. find 查找 Lin ...

  9. 远程url文件地址转成byte

    public static byte[] urlTobyte(String url) throws MalformedURLException { URL ur = new URL(url); Buf ...

  10. DedeCMS程序使用拼音首字母做栏目名称的方法

    Dedecms织梦程序默认使用拼音为保存目录的时候使用的是中文全拼,当遇到栏目名称比较长的时候目录名称看起来有点冗长,这时候大多数站长喜欢使用拼音首字母作为栏目的保存目录,那么就需要修改 dede/c ...