简体   繁体   English

Python追溯:文件“ <string> ”。 这是什么意思?

[英]Python traceback: File “<string>”. What does it mean?

Ok, obviously I am new at this. 好吧,显然我是新来的。 I got this Python traceback: 我得到了这个Python追溯:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 30
SyntaxError: invalid syntax

What does File "<string>" stand for? File "<string>"代表什么?

My code contains an empty line @ line 30, so I'm assuming this doesn't refer to my code, but what DOES it refer to? 我的代码在第30行有一个空行,所以我假设这不是我的代码,但是它指的是什么?

( I'm using Micropython on an ESP8266 ) (我在ESP8266上使用Micropython)

This is my code: 这是我的代码:

import network
import tinyweb
import machine

# Connect to your WiFi AP
sta_if = network.WLAN(network.STA_IF)
sta_if.active(True)
sta_if.connect('blabla', 'blabla')

# Create web server application
app = tinyweb.webserver()
count = 0

# Hello world index page (just to be sure - let's handle most popular index links)
@app.route('/')
@app.route('/index.html')
async def index(req, resp):
    await resp.start_html()
    await resp.send('<html><body><h1>Hello, world!</h1></html>\n')

# Counter REST API endpoint
@app.resource('/counter')
def counter(data):
    return {'name': 'Foo', 'counter': counter}

def pin_handler(p)
    global count
    count =count + 1

#pin=machine.Pin(0, machine.Pin.IN, machine.Pin.PULL_UP)  
#pin.irq(handler = pin_handler, trigger = Pin.IRQ_FALLING, hard = True)

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=80)

Thanks to buran I found the cause. 多亏了buran,我找到了原因。 The <string> apparently DOES just refer to my own code. <string>显然只引用了我自己的代码。 I forgot to add a colon at the and of the pin_handler function and that somehow shifted the position the error occured downwards... 我忘了在pin_handler函数的和处添加一个冒号,并且以某种方式将错误发生的位置向下移动了...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM