Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Can I store the creation of a db (peewee) model in a variable while still having that model be created?

example below

@app.route('arbitrary_url')
def random_route_function():
    created_database_row = models.Thingy.create(
                 username = 'stuff',
                 password = 'encrypted_stuff'
)
print('created_database_row')

Since i have stored the creation in a variable do i have to instantiate it or does it get created first and then stored into the variable. THANKS!!!!

1 Answer

Yes, that will create the database entry. You are calling the function and setting the variable to the return value of that function.

Sweet thanks!!! Had to be sure