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的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-01-23供应链投毒预警 | 恶意Py包仿冒tensorflow AI框架实施后门投毒攻击
- 2024-01-19attributeerror: module 'tensorflow' has no attribute 'placeholder'
- 2024-01-19module 'tensorflow.compat.v2' has no attribute 'internal'
- 2023-07-17【2023年】第33天 Neural Networks and Deep Learning with TensorFlow
- 2023-07-10【2023年】第32天 Boosted Trees with TensorFlow 2.0(随机森林)
- 2023-07-09【2023年】第31天 Logistic Regression with TensorFlow 2.0(用TensorFlow进行逻辑回归)
- 2023-07-01【2023年】第30天 Supervised Learning with TensorFlow 2(用TensorFlow进行监督学习 2)
- 2023-06-18【2023年】第29天 Supervised Learning with TensorFlow 1(用TensorFlow进行监督学习 1)
- 2023-06-17【2023年】第28天 tensorflow的介绍
- 2023-05-16如何在 Windows10 下运行 Tensorflow 的目标检测?