-1
def cd():
     person = {
    'name' : 'bhavya',
    'age' : 32,
    'birth_date' : '18/10/1996'
    }
    print(person)

cd()

This is a dictionary I've saved as ey.py. Now I want to import this whole data into another .py file with help of a module. So I can fetch whole data saved in ey.py.

Can anyone guide me?

  • Please put more detail into your question. It is very unclear what you are looking for. – CATboardBETA Mar 10 '21 at 09:03
  • IIUC, your goal is seperating data from main python file. Is it right? – Jaybe Park Mar 10 '21 at 09:05
  • Create a dict inside a function named hello and save the file --- Then create a new file and write import hello from the file name. Now when i import the function all i want is to access single data such as name or age that's all i want – blogs barrel Mar 10 '21 at 10:44

1 Answers1

1

If your goal is separating data from main python code, you have to make a new python code(ex. data.py)

data.py

def get_data():
    data = { 'name' : 'bhavya', 'age' : 32, 'birth_date' : '18/10/1996' }
    return data

main.py

from data import get_data

person = get_data()
print(person)

FYI

Jaybe Park
  • 172
  • 1
  • 5