1

I'm trying to learn python and I've tried really hard but for some reason I can't figure this out.

This is the module, named user_profile, where the function that I want to import comes from:

def build_profile(first, last, **user_info):
    profile = {}
    profile['first name'] = first
    profile['last name'] = last
    for key, value in user_info.items():
        profile[key] = value
    return profile

user_profile = build_profile('john', 'smith', 
                            city = 'new york', 
                            occupation = 'banker', 
                            girlfriend = 'janice')

for key, value in user_profile.items():
    print(key.title() + ": " + value.title())

Now I want to import build_profile into another module like so:

from user_profile import build_profile

I just want build_profile to be imported, but for some reason it runs user_profile entirely. What's going on?

Fucchy
  • 11
  • 1
  • So I just need to put if __name__ == '__main__' in my module at the place where I don't want the code to be run in the main program? – Fucchy Sep 25 '19 at 22:06

0 Answers0