1

I restart the python repl by exit, then execute the python command again. But I am boring now, I would like to know how to restart the python repl on the fly, in other word, do not exit again.

acgtyrant
  • 1,721
  • 1
  • 16
  • 24
  • 1
    os.execv should do it. – mpez0 Oct 08 '18 at 12:29
  • 1
    What disadvantage does closing and reopening Python have over any other way? Is this not “on the fly” enough? – Konrad Rudolph Oct 08 '18 at 12:48
  • @mkrieger1 The REPL is not script, and I do not know is clearing all variables same as restarting the REPL. – acgtyrant Oct 08 '18 at 13:25
  • @KonradRudolph I want to get a clean REPL many times, this processes is boring. Not enough. – acgtyrant Oct 08 '18 at 13:26
  • @acgtyrant I can assure you that no other solution will be as fast as hitting ‹Ctrl›-‹D›, followed by ‹up-arrow› and ‹return›. Because that’s all it takes to restart Python. — Furthermore, if you need to clear your REPL very often this suggests that you’re doing something you’re not supposed to do: write reproducible scripts with functions etc. instead. – Konrad Rudolph Oct 08 '18 at 13:40
  • @KonradRudolph It is fast, but `%reset` is better that it will not produce too many promot as `-, python`. I want to play the Tensor from PyTorch, it can not be managed as the reproducible script. – acgtyrant Oct 08 '18 at 14:22
  • [%reset](https://stackoverflow.com/a/3543840/1546088) from [How do I clear all variables in the middle of a Python script?](https://stackoverflow.com/questions/3543833/how-do-i-clear-all-variables-in-the-middle-of-a-python-script) solve my problem now. – acgtyrant Oct 08 '18 at 14:23

0 Answers0