What does the at sign do?

G

guruyaya

I'm reading a lot of python code lately, django code to be exact, and
I keep bumping into expressions that look like this
@register.filter

I see nothing importing @register, so I assume it's not just a
function name. Yet I cannot figure where this @ sign came from.
I hope I'm not just forgetting something out of the very basics.

Thanks in advance
Yaya
 
M

Martin v. Löwis

I'm reading a lot of python code lately, django code to be exact, and
I keep bumping into expressions that look like this
@register.filter

I see nothing importing @register, so I assume it's not just a
function name.

That can't be. register must be a bound name - not necessarily an
imported function; it could also be something being set through
assignment (register = Registry()).
Yet I cannot figure where this @ sign came from.

That's a function decorator; see PEP 318.

Regards,
Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top