How to import or include data structures (e.g. a dict) into a Python file from a separate file

Just import it

import myDict
print myDict.airportCode

or, better

from myDict import airportCode
print airportCode

Just be careful to put both scripts on the same directory (or make a python package, a subdir with __init__.py file; or put the path to script.py on the PYTHONPATH; but these are “advanced options”, just put it on the same directory and it’ll be fine).

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)