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 trialAndy McDonald
Python Development Techdegree Graduate 13,801 PointsHow to use like() method?
The quiz is expecting me to know how to use this when this is the first time I've ever seen anything like it. I can't google search for anything that is helping with this particular method. A hint on how to use this to get passed the quiz would be helpful
from sqlalchemy import create_engine, Column, Integer, String
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
engine = create_engine(βsqlite:///movies.dbβ, echo=False)
Session = sessionmaker(bind=engine)
session = Session()
Base = declarative_base()
class Movie(Base):
__tablename__ = βmoviesβ
id = Column(Integer, primary_key=True)
movie_title = Column(String)
genre = Column(String)
def the_movies():
return session.query(Movie).filter(Movie.movie_title.like('%The%').count()
1 Answer
Chris Freeman
Treehouse Moderator 68,441 PointsHey Andy McDonald, had to look a bit too! You are very close.
The
like()
is defined in the docs hereusage examples can be found in the docs on this page
The challenge asks to create a variable named the_movies
. You've defined a function. So use, the_movies = ...
- there is a syntax error where you are missing a closing paren before
.count()
Post back if you need more help. Good luck!!
Andy McDonald
Python Development Techdegree Graduate 13,801 PointsI was messing with count() in workspaces and it insisted on passing an argument. Why did the quiz allow me to use it with no argument?
Chris Freeman
Treehouse Moderator 68,441 PointsCan you show the code that caused the request for an argument?
Many objects may have their own method named count()
. The query set count()
does not take an argument. list.count()
takes exactly one argument, str.count()
takes one or more. Perhaps the object requiring arguments wasnβt a query set.
Andy McDonald
Python Development Techdegree Graduate 13,801 PointsAndy McDonald
Python Development Techdegree Graduate 13,801 PointsI did use it as a string and would never have known that it behaved completely differently with a query object had you not hinted to use it without any argument. I originally was just guessing what the quiz wanted but when I went back to look at my meticulous notes I started trying to pass arguments into it.