Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8590387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:16:59+00:00 2026-06-11T23:16:59+00:00

I’m passing a set of MovieFile objects from x.py to y.py and iterating through

  • 0

I’m passing a set of MovieFile objects from x.py to y.py and iterating through them, trying to use each object’s attributes in y.py

x.py

mfSet = {}

def pop():
    ## populate mfSet with MovieFile objects
    m = MovieFile(title=t, year=y, dir=d, filename=f)
    mfSet.setdefault(str(m), []).append(m)

class MovieFile():
    def __init__(self, title, dir, filename, year=0):
        self.title = title
        self.year = year
        self.fulltitle = title if year == 0 else title + ' (' + year + ')'
        self.dir = dir
        self.filename = filename
    def __str__(self):
        return repr(self.title + ' (' + self.year + ') at ' + self.dir)

y.py

from x import MovieFile, mfSet, pop # not sure if I need to import MovieFile

pop()

for mf in mfSet:
    ft = mf.fulltitle # stacktrace says this attr doesn't exist for str object
    title = mf.title # printing shows that this is "<built-in method title of str object at 0x10d84a3f0>"

So my main questions are:

Why are the MovieFile objects compiling as str objects, and how can I use the fulltitle attr once I get use of those objects?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T23:17:00+00:00Added an answer on June 11, 2026 at 11:17 pm

    You haven’t shown what pop is (please include that code, it’s the important bit). However, I expect what the problem is that mfSet is a dict and you are assigning str keys—perhaps mfSet[str(mf)] = mf. Iteration of a dict produces the keys, not the values of a dictionary.

    You may want to use a set instead of a dict. Or, change for mf in mfSet: to for mf in mfSet.itervalues(): (and change the variable name mfSet to not be misleading about type; PEP 8 also recommends against camelCase in variable names).


    So, you’re grouping by MovieFile.__str__(). Very well, then. Here’s how I might write that code:

    from collections import defaultdict
    
    mf_collection = defaultdict(list)
    
    def pop():
        ## populate the collection with MovieFile objects
        m = MovieFile(title=t, year=y, dir=d, filename=f)
        mf_collection[str(m)].append(m)
    
    class MovieFile():
    
        def __init__(self, title, dir, filename, year=0):
            self.title = title
            self.year = year
            self.fulltitle = title if year == 0 else title + ' (' + year + ')'
            self.dir = dir
            self.filename = filename
    
        def __str__(self):
            return repr(self.title + ' (' + self.year + ') at ' + self.dir)
    

    And y.py:

    from x import mf_collection, pop
    
    pop()
    
    for mf_group in mf_collection.itervalues():  # this yields lists of MovieFiles
        for mf in mf_group:  # this yields the actual MovieFiles
            ft = mf.fulltitle
            title = mf.title
    

    Because you’re working with lists being the values, you’ve got another level of iteration to do.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a view passing on information from a database: def serve_article(request, id): served_article
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am trying to loop through a bunch of documents I have to put
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.