0

I have written a module which re-defines the print function. Is it possible to preimport it in order to redefine print() (with from [module] import print) to demonstrate or test it with a program, without having to modify this program ?

2
  • No. Each process is separate. Commented Jul 14, 2020 at 19:49
  • Why should it have to be another process ? I wasn't thinking about making it another process. More about chaining like when to chain shell scripts with . script Commented Jul 14, 2020 at 19:51

1 Answer 1

1

Eureka ! ;-)

One can import a module (here, redefine the print function) and then chain a new program (./PROGRAM) in the current environment by using the command :

from MODULE import print exec(open('./PROGRAM').read()) 

So (in linux) one can do it from command line (or script it) with :

python3 -c "from MODULE import print; exec(open('./PROGRAM').read())" 

This question also contains useful information on this topic.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.