简体   繁体   中英

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

Ok, obviously I am new at this. I got this Python traceback:

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

What does File "<string>" stand for?

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?

( I'm using Micropython on an ESP8266 )

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. The <string> apparently DOES just refer to my own code. I forgot to add a colon at the and of the pin_handler function and that somehow shifted the position the error occured downwards...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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