Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Build a Social Network with Flask Takin' Names Flask-WTF Forms

Pete Jeffryes
Pete Jeffryes
5,752 Points

Within validators for each form field, why don't we need to use parenthesis after the methods that we write?

Such as email_exists and name_exists, there are no parenthesis when calling the method name. How is python going to know that is a method? Thanks.

3 Answers

Vittorio Somaschini
Vittorio Somaschini
33,371 Points

Hello Pete.

I had your same doubt and asked in the forums, I will link it here:

https://teamtreehouse.com/forum/1-question-and-1-code-problem-with-my-formspy-file

Basically it is syntax rules as per documentation and python will take care of it.

Vittorio

Farrah Dickerson
Farrah Dickerson
10,173 Points

"How is python going to know that is a method?" Your answer lies in .../wtfforms/fields/core.py—line 110—where the parenthesis are assumed by the gettattr() function's specified default. From there, it launches into a setattr() function, via a for loop, which 'constructs' our method's attributes—via instantiations of the Flags class, on line 352 of core.py.

That's cool, if you ask me...

Pete Jeffryes
Pete Jeffryes
5,752 Points

Thanks Vittorio. That helps.

Kenneth highlighted that the time stamp can also be called without parenthesis. The interesting thing is that it has a different function with or without the parenthesis. Like you said, its syntax, seems like I just gotta memorize some things...cheers and good luck with your coding..