Hello guest, if you read this it means you are not registered. Click here to register in a few simple steps, you will enjoy all features of our Forum.
Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
a funny coding challege
#1
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.
Skaaaaaperen........
Quote
#2
#!/usr/bin/env python2
from __future__ import print_function
import subprocess

print(subprocess.check_output(['/usr/bin/env', 'python3', '-c', 'print("Hello", end="")']), 'World')
My code examples are always for Python 3.x.
All humans together. We don't need politicians!
Quote
#3
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.
Skaaaaaperen........
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Funny things Java Devs do but Python Devs Don't QueenSvetlana 1 116 Nov-02-2017, 08:45 PM
Last Post: nilamo
  what i am currently coding Skaperen 0 317 Jan-18-2017, 02:39 AM
Last Post: Skaperen
  Funny English Kebap 25 2,486 Jan-13-2017, 10:08 PM
Last Post: ichabod801

Forum Jump:


Users browsing this thread: 1 Guest(s)