Databases in Python

Intro to Backend >> Databases >> Databases in Python

 

Here is my explanation of how the line link = link(*link_tuple) comes to be:

print query()

def query()
    cursor = db.execute("select * from links")


#when you iterate over each link in cursor, you are iterating over tuples. aka each link is a tuple. it comes that way from cursor

    for link_tuple in cursor:


#we don't want tuples though. we want objects. so we turn each link_tuple into an object, each called link. but we also want each link to keep the parameters of each link_tuple, so we pass it in in the parenthesis

        link = link(*link_tuple)


#now that each link is an object and not a tuple, we can call whatever parameter name we want to call on it and print it right out!
        
        print link.votes


print query()
Advertisements

Author: ajoannaproject

Studying Udacity's Full Stack Web Developer program and passing on my improvements, hints, hacks, and updates to other students via ajoannaproject.wordpress.com.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s