What does the @ symbol mean ?

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
peter247
Posts: 8
Joined: Sat Oct 31, 2020 9:45 am

What does the @ symbol mean ?

Post by peter247 » Sat Oct 31, 2020 9:57 am

I new to the world of python programming and trying to set up a web server and going to use the picweb library for this task.
How I learn is take the program apart line by line and understand what each line does , change things and see what happens.
In this bit of code :-

Code: Select all

 @app.route("/temp")
def html(req, resp):
    hw_sensor.measure()
    t = hw_sensor.temperature()
I'm trying to work out what this part of the code does @app.route("/temp") or what the @ does.

Thank in advanced Peter A

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: What does the @ symbol mean ?

Post by dhylands » Sat Oct 31, 2020 4:32 pm

These are called decorators and part of regular python.
https://realpython.com/primer-on-python ... decorators

In your particular example. it causes the html function to be called when /temp is requested (the exact details will depend on the particular framework you're using).

peter247
Posts: 8
Joined: Sat Oct 31, 2020 9:45 am

Re: What does the @ symbol mean ?

Post by peter247 » Sat Oct 31, 2020 5:12 pm

dhylands wrote:
Sat Oct 31, 2020 4:32 pm
These are called decorators and part of regular python.
https://realpython.com/primer-on-python ... decorators

In your particular example. it causes the html function to be called when /temp is requested (the exact details will depend on the particular framework you're using).
Thank you , That explains it all , now all I need to do is understand it.

Post Reply