diff --git a/python/hello.py b/python/hello.py index 154d35f..ed21fed 100755 --- a/python/hello.py +++ b/python/hello.py @@ -15,13 +15,13 @@ verinfo = subprocess.check_output(["git", "describe", "--abbrev=7", "--dirty", "--always", "--tags"]) # Obligatory Hello World with some version info -print "Hello Python World! Version: " +verinfo +print("Hello Python World! Version: {}".format(verinfo)) # Show list of command line arguments -print "Command line args: ", +print("Command line args: "), for i in sys.argv[1:]: - print " " + i, -print "" + print(" {}".format(i)) +print("") # Determine number of physical CPU sockets if os.name == 'nt': @@ -29,52 +29,52 @@ if os.name == 'nt': else: socketcount = subprocess.check_output(["bash","-c", "(cat /proc/cpuinfo | grep 'physical id' | sort | uniq | wc -l)"]) - print "CPU socket count: ", socketcount + print("CPU socket count: {}".format(socketcount)) # print out our animals array in reverse-sorted order -print "\nValue of animals array:" +print("\nValue of animals array:") for i in sorted(animals, reverse=True): - print "item = " + i + print("item = " + i) if (i == animals[0]): - print " Condition is TRUE, \"" +i+ "\" == " + animals[0] + print(" Condition is TRUE, \"" +i+ "\" == " + animals[0]) else: - print " Condition is FALSE, \"" +i+ "\" != " + animals[0] + print(" Condition is FALSE, \"" +i+ "\" != " + animals[0]) # print our fruit_color dictionary (key/value pairs) -print "\nValue of fruit_color hash:" +print("\nValue of fruit_color hash:") for fruit,color in sorted(fruit_color.items(), reverse=True): - print fruit, " = ", color + print(fruit, " = ", color) # Read a non-existent environment variable and supply default value... some_env_var = os.getenv("PROBABLY_NOT_THERE", "Default Value") -print "\nPROBABLY_NOT_THERE is set to '"+some_env_var+"'\n" +print("\nPROBABLY_NOT_THERE is set to '"+some_env_var+"'\n") # Let's read in the PATH variable from the OS and print it out... path_env_var = os.environ['PATH'] -print "OS PATH var is set to: '"+path_env_var+"'\n" +print("OS PATH var is set to: '"+path_env_var+"'\n") # Let's manipulate PATH variable and then restore it -print "Adding :/test to PATH variable" +print("Adding :/test to PATH variable") os.environ['PATH'] = os.environ['PATH'] + ":/test" -print "OS PATH var is set to: '"+os.environ['PATH']+"'\n" -print "Restoring original PATH value." +print("OS PATH var is set to: '"+os.environ['PATH']+"'\n") +print("Restoring original PATH value.") os.environ['PATH'] = path_env_var -print "OS PATH var is set to: '"+path_env_var+"'\n" +print("OS PATH var is set to: '"+path_env_var+"'\n") # Let's create the file test.out and write animals array to it... -print "\nWriting test.out file..." +print("\nWriting test.out file...") file = open("test.out", "w") for i in animals: file.write(i+"\n") file.close() # Now open the file we wrote and read it back... -print "\nContents of test.out file:" +print("\nContents of test.out file:") file = open("test.out", "r") linenum = 1 for line in file: - print "line "+str(linenum)+": "+line, + print("line "+str(linenum)+": "+line) linenum += 1 file.close()