Plutonic Rainbows

Condensing

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."

raw_input("?")

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..."

target.write(line1);target.write("\n");target.write(line2);target.write("\n");target.write(line3);target.write("\n")

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

target.close()

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.