1

I have the following function in a Python module called dictbuilder.py:

def my_dictbuilder(reader_o, writer):
    fieldnames = ('name', 'number')
    reader = csv.DictReader(reader_o, fieldnames = fieldnames, delimiter="\t")
    my_dict = {}
    id = 0
    for row in reader:
       id += 1
       my_dict[id] = row['name'], row['number']
       id += 1
    return(my_dict)

I have imported and called this function from a module called main.py. I would like to also use the my_dict variable from the dictbuilder.py module I have imported into main.py. When I try to printmy_dictbuilder.mydict I get this error:

AttributeError: 'function' object has no attribute 'my_dict'

Can anyone help me figure out how to access the my_dict variable from my main.py file? Thanks for the help!

3
  • 2
    Where does the fimo_dict come from? Commented Aug 10, 2011 at 19:51
  • You need to post a working (or nonworking) example of what failed. Commented Aug 10, 2011 at 19:55
  • @GabrielRoss Sorry, I made a typo. It should read my_dict Commented Aug 10, 2011 at 20:05

1 Answer 1

1

Well, you're returning my_dict, so just store the return value in your main module when you call it.

my_dict = dictbuilder.my_dictbuilder(reader_o, writer)
Sign up to request clarification or add additional context in comments.

1 Comment

Weird, I tried this before asking the question and it didn't work. I tried it again and it worked this time. Many thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.