TensorFlow工作笔记003---python异常大全IndentationError: unexpected indent_expected indented block

2021/5/20 12:29:10

本文主要是介绍TensorFlow工作笔记003---python异常大全IndentationError: unexpected indent_expected indented block,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!


我们在运行python脚本时遇到错误报错 IndentationError: unexpected indent。 
如下图:

>>>      with tf.variable_scope("",reuse=True):
  File "", line 1
    with tf.variable_scope("",reuse=True):
    ^
IndentationError: unexpected indent

原因

字母意思就是不希望有缩进,去掉空格和tab。 
看看我们的代码如下: 
 
发现第一行没有顶格写,python 对代码的格式要求很严格,python没有分号,用严格的缩进表示上下级从属层级关系,第一行需要顶格写,然后根据冒号:后续的代码行需要有缩进,并且有层级。

解决方式

把报错行多余的缩进删除即可。 
符合代码的格式要求:第一行需要定格写,然后根据冒号:之后的代码行需要有缩进,并且有层级,第二个冒号后面的代码不能超过第一个冒号后面的代码。同样的缩进表示同一个层级。

2.IndentationError: expected an indented block

>>> import tensorflow as tf
>>> g1 = tf.Graph()
>>> with g1.as_default():
... v=tf.get_variable("v",iinitializer=tf.zeros_initializer(shape=[1]))
  File "", line 2
    v=tf.get_variable("v",iinitializer=tf.zeros_initializer(shape=[1]))
    ^
IndentationError: expected an indented block

期望有缩进



这篇关于TensorFlow工作笔记003---python异常大全IndentationError: unexpected indent_expected indented block的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程