a funny coding challege - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Forum & Off Topic (https://python-forum.io/forum-23.html) +--- Forum: Bar (https://python-forum.io/forum-27.html) +--- Thread: a funny coding challege (/thread-6755.html) |
a funny coding challege - Skaperen - Dec-06-2017 write a script that is to be run as a command under either version of python and run itself under the other version and print "hello" the run itself again under the original version and print "world" and stop. RE: a funny coding challege - DeaD_EyE - Dec-06-2017 #!/usr/bin/env python2 from __future__ import print_function import subprocess print(subprocess.check_output(['/usr/bin/env', 'python3', '-c', 'print("Hello", end="")']), 'World') RE: a funny coding challege - Skaperen - Dec-07-2017 that's not running itself, it's running a command string. "itself" means the file, not a command string, and not some other file. running itself is to run the script file. if i run the script under python3 then it should run itself under python2, and while running under python2, print "hello", then run itself under python3, and while running under python3, print "world", then do nothing more. if i run the script under python2 then it should run itself under python3, and while running under python3, print "hello", then run itself under python2, and while running under python2, print "world", then do nothing more. |