Discussion:
[Tutor] How to import a dictionary from another module?
David Aldrich
2015-06-15 11:03:27 UTC
Permalink
Hi

I have defined a dictionary in a module:

mydir.py:

REG_LOOKUP = {
'REG_1' : some_value1,
'REG_2' : some_value2,
}

How would I import that dictionary from my main() function (which lives in a different module) please?

Best regards

David

_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Mark Lawrence
2015-06-15 15:07:34 UTC
Permalink
Post by David Aldrich
Hi
REG_LOOKUP = {
'REG_1' : some_value1,
'REG_2' : some_value2,
}
How would I import that dictionary from my main() function (which lives in a different module) please?
Best regards
David
import othermodule
...
othermodule.REG_LOOKUP{whatever}

OR

from othermodule import REG_LOOKUP
...
REG_LOOKUP{whatever}

You can also use

from othermodule import *

but this is frowned upon as it pollutes your namespace, potentially
giving all sorts of weird and wonderful situations. I never use it.
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
David Aldrich
2015-06-15 14:49:39 UTC
Permalink
Hi

I have a solution for this now.

Best regards

David
-----Original Message-----
On Behalf Of David Aldrich
Sent: 15 June 2015 12:03
Subject: [Tutor] How to import a dictionary from another module?
Hi
REG_LOOKUP = {
'REG_1' : some_value1,
'REG_2' : some_value2,
}
How would I import that dictionary from my main() function (which lives in a
different module) please?
Best regards
David
_______________________________________________
https://mail.python.org/mailman/listinfo/tutor
Click
https://www.mailcontrol.com/sr/Q2tIWP1gKVLGX2PQPOmvUlvAwUAcTfZne
qTtIw9m3Q8SQ0yRarxngdZVWY3fkqP66uKlINFphbKNI5tH4SJ!Mg== to
report this email as spam.
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Loading...