gaogaotiantian / objprint

A library that can print Python objects in human readable format
Apache License 2.0
519 stars 43 forks source link

question: how to use install() #59

Closed wwdok closed 2 years ago

wwdok commented 2 years ago

I created two python file to play with the install() feature:

temp1.py:

from objprint import op, install

# Now you can use op() in any file
install()

temp2.py:

op("hello")

But run the temp2.py, it throws error : NameError: name 'op' is not defined What is the correct usage of install() ? Thanks !

gaogaotiantian commented 2 years ago

There's no magic across interpreters. install() basically adds op to builtins so that it could be used in the SAME interpreter process elsewhere. In this case, in the temp2.py, you need to import temp1 so the install() executes before you try to use op. The feature saves you some imports when you have many files in your project.