2624 views|4 replies

479

Posts

0

Resources
The OP
 

Python syntax does not work with multiple spaces. [Copy link]

 
This post was last edited by kangkls on 2018-6-30 15:10 I was very lucky to get a PYboardCN V2. I tried a few programs with the serial port and it was very convenient. I wanted to save it as a main.py to save typing it every time. Single sentences sent through the serial port are executed, but they are not executed when written as main.py. I was confused. Some people said it was a problem with the editor. I changed several editors, but it still didn't work. Restoring the factory settings didn't work either. . On Saturday, I simply re-flashed the firmware. With the help of shaoziyang, I found that a capacitor actually affected the entry into DFU mode. I really didn't expect it. How did you find such a problem? I really admire you! I usually just pick up a capacitor and solder it, no matter if it is 10p or 20p, and I never found any problems. Today I encountered it. The firmware was refreshed successfully, but the simplest few LED marquees still didn't execute. It was really weird. Later I found that mobaXTERM is a really good software that can find syntax errors in the program. The previous program syntax was exposed at once. It turned out that tabs could not be used. Then I found that one more space was also fine. It’s really strict. # main.py -- put your code here! import pyb while True: pyb.LED(1).on() pyb.delay(300) pyb.LED(1).off() pyb.delay(300) pyb.LED(2).on() pyb.delay(300) pyb.LED(2).off() pyb.delay(300) pyb.LED(3).on() pyb.delay(300) pyb.LED(3).off() pyb.delay(300) pyb.LED(3).toggle() There must be and can only be one space before each line of pyb.LED, otherwise it is a syntax error and cannot be executed. It’s been a week and I’ve been stuck with this space! Take it as a warning.






Latest reply

I just learned Python by myself, and this syntax of using indentation to distinguish code segments is just looking for trouble  Details Published on 2018-7-3 15:41
Personal signaturehttp://www.jslaser.com高性价比激光测距传感器
 
 

1234

Posts

4

Resources
2
 
If you don't want to, you don't have to.
Personal signature天地庄周马;江湖范蠡船。
个性签名还是放QQ号吧,2060347305,添加说明EEworld好友
 
 
 

1w

Posts

25

Resources
3
 
Python programs use 4 spaces for indentation by default. Code with the same indentation is at the same level, and no brackets are used to distinguish code segments. Each level must strictly follow the indentation rules. You can also use a space or a tab, but you cannot mix them. A program can only use one style from beginning to end.

 
 
 

113

Posts

0

Resources
4
 
Before using Python syntax, you still need to read the precautions tab. This issue is something that all C-based to Python-based systems need to pay attention to.
 
 
 

1469

Posts

0

Resources
5
 
I just learned Python by myself, and this syntax of using indentation to distinguish code segments is just looking for trouble
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list