Page 1 of 1

What does the @ symbol mean ?

Posted: Sat Oct 31, 2020 9:57 am
by peter247
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

Re: What does the @ symbol mean ?

Posted: Sat Oct 31, 2020 4:32 pm
by dhylands
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).

Re: What does the @ symbol mean ?

Posted: Sat Oct 31, 2020 5:12 pm
by peter247
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.