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

leonardo valdes
leonardo valdes
12,384 Points

using methods in another file

The YatzyScoreSheet class uses methods such as 'ones' and' _sets' that are located in a separate file (hands.py) , yet scoresheets.py doesn't have 'import hands'. How does the file know to use the methods that are located in hands.py? are imports of other files not necessary? even if the 'hand' parameter is of class type YatzyHand and would therefore know to use those methods, dont you still need to import the necessary files?

scoresheets.py
class YatzyScoresheet:
    def score_ones(self, hand):
        return sum(hand.ones)

    def _score_set(self, hand, set_size):
        scores = [0]
        for worth, count in hand._sets.items():
            if count == set_size:
                scores.append(worth*set_size)
        return max(scores)

    def score_one_pair(self, hand):
        return self._score_set(hand, 2)

1 Answer

I viewed the challenge, and there is no hands.py. I think what you are referring to is the hand parameter in all three methods. When you call each method, you would provide the "hand," which would most likely come from hands.py. So for this code challenge, no imports are necessary because you aren't actually calling the methods. If you were creating the game in real life like Kenneth did, you would need to import hands.py.