Did anyone spot the glaring error in the last script? It misses the len(indata)
which calculates the file size. I have corrected that now. Thanks to everyone who contacted me.
Error
April 29, 2018
Coda to Sublime Text
April 24, 2018
Panic's Coda 2 is an expensive piece of software when you are only writing in Python. I recently moved over to Sublime Text. It's actually free, if for the occasionally prompt to buy it. If you're on a budget, I totally recommend it.
Copying Again
April 19, 2018
A simple script that just checks the file size and copies the file to a target destination that you specify. That's done when you pass in script, file_from, file_to = argv
at the very beginning.
from sys import argv
script, file_from, file_to = argv
file_in = open(file_from)
indata = file_in.read()
print "The file called '%s'is %r bytes in length" % (file_from, len(indata))
file_out = open(file_to, 'w')
file_out.write(indata)
file_in.close()
file_out.close()
Functions in Math
April 17, 2018
I've been looking again at functions and how they work. They are great for simple math but can do a lot more besides. With that in mind, here is a simple way of multiplying numbers with user input. Remember to tell Python to use float
when handling numbers.
def calc(value1, value2):
return value1 * value2
print "\nLet's multiply two numbers.\n"
value1 = (float(raw_input("Enter a number: ")))
value2 = (float(raw_input("Enter another number: ")))
answer = calc(value1, value2)
print "\nThe answer is {0:.2f}.\n".format (answer)
A Neural Network in 11 lines
April 11, 2018