w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Read dictionary from python file in another python script

If you're confident that neither script will be tampered with you could use eval().

Your code would look like this:

data_file = '/Users/user/desktop/data_file.py'
print numbers

EDIT: Another method is to import the data_file.py as a module. If data_file.py is in /path/to/data

import sys
import data_file

print data_file.numbers

This is a better approach, unless you have a specific reason why you don't want the entirety of data_file.py evaluated.

© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.