How to import or include data structures (e.g. a dict) into a Python file from a separate file -
I know that I can include Python code from a common file by using Import MyModuleName
Am I - But how can I go about importing only one word?
In the problem I am trying to solve, I have a word in it that should be in the file in an editable location, whereas the actual script is in another file. By a non-programmer, it can also be hand-edited.
script.py
airportName = 'BRISTOL' myAirportCode = airportCode [airport name]
'Belfs',' Billingham International ':' BHX ',' Belfast International ':' Belfast International ':' myDict.py
airportCode = {'ABERDEEN': 'ABZ', 'Belfast International' Birmingham, Intel: 'BHX', 'Bournemouth': 'BOH', 'Bristol': 'BRS'}
how script.py ?
Import from the script
Import script print script. Airport code
Or, better
Import Import AirportCode Print AirportCode
Be careful to insert both scripts (or a python package, with __init __.py
file) on the same directory. Make a subdir; Path is PYTHONPATH on path.py; But these are "advanced options", just keep it on the same directory and it will be fine).
Comments
Post a Comment