python中易错要点

在python中:

1.  image_raw_data = tf.gfile.FastGFile("../datasets/cat.jpg", 'r').read()

    表示在当前路径的上级目录下以只读的方式来操作datasets/cat.jpg

image_raw_data = tf.gfile.FastGFile("../../datasets/cat.jpg", 'r').read()

    表示在当前路径的上上级目录下以只读的方式来操作datasets/cat.jpg

2.   但是在运行的时候会提示:

        UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte

        解决办法:把操作方式改为“rb”,即:

        image_raw_data = tf.gfile.FastGFile("../datasets/cat.jpg", 'rb').read()

见:https://stackoverflow.com/questions/35184692/unicodedecodeerror-utf-8-codec-cant-decode-byte-0xff-in-position-0-invalid

3.        在python中下划线“_”也可以表示一个变量。在程序中见到别奇怪哈,如:

for _ in range(6):
    print(_)

猜你喜欢

转载自blog.csdn.net/qisheng_com/article/details/81777251