这段代码为什么在Jupyter Notebook上运行正常,但在新的Python文件上不起作用?

huangapple go评论81阅读模式
英文:

Why does this code work on jupyter notebook but don´t work on a new python file?

问题

为什么在.py(Python)格式上运行时,该代码显示缩进错误,但在.ipynb(Jupyter Notebook)上运行时可以顺利运行?

这是我在新的Python文件上使用代码时显示错误的图像

这是我在新的Jupyter Notebook文件上运行代码时的图像

我在互联网上搜索了关于缩进问题的所有信息,并且过去一天都在学习使用制表符和空格进行缩进时出现的问题,但对我来说似乎不是制表符和空格的问题,因为在Jupyter Notebook中可以正常工作。我已经激活了在我的代码上显示所有空白字符的选项,以更好地确定问题的所在,但是……我一头雾水。

我是编程新手,正在学习很多东西,您能帮助我吗?

英文:

Why does that code shows identation error when on a .py (Python) format and it runs smoothly when in a .ipynb (Jupiter Notebook)?

Here is the image showing the error when I´m using the code on a new Python file

Here is the image when I run the code a new Jupiter Notebook file

I searched for identation problems all over the internet and I spent the last day only studying about the problems that arise from using tab and space for identation but it really doesn´t appear for me that it´s a tab and space problem since it work inside Jupiter Notebook. I activated the option to show all whitespace on my code so I can better pin down where is the problem but...I´m clueless.

I´m new to programming and learning a lot so can you send me some help on this?

答案1

得分: 0

在第一张照片(Python文件)中,看起来你还没有保存文件,也许这可能会导致错误。

英文:

In the first photo (Python file), looks like you haven't saved the file and maybe this can cause the error.

huangapple
  • 本文由 发表于 2023年8月10日 19:08:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/76875155.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定