Plutonic Rainbows


In the last script, I mentioned about condensing the lines down. It’s actually very simple to do. Just insert a semi-colon between lines.

For example:

from sys import argv script, filename becomes from sys import argv;script, filename

If you apply this in your scripts, things become much more manageable to read. Here is the previous script with the new additions.

from sys import argv;script, file_name = argv

print "Hello. let's erase the contents of the file called: '%s'." % file_name
print "If you do not want this, hit CTRL-C."


print "Opening file..."

target = open(file_name, 'w');target.truncate()

print "Contents now erased."

line1 = raw_input("Line 1: ");line2 = raw_input("Line 2: ");line3 = raw_input("Line 3: ")

print "Writing three lines..."


print "Done.";print "Let's close the file."


print "All finished."

As you can see, most of the time is saved with the part where the script asks for raw_input and when using target.write.