The python docs say: Return the length (the number of items) of an object. The argument may be a sequence (string, tuple or list) or a mapping (dictionary).
Code:
from sys import argv
script, from_file = argv
input = open(from_file)
indata = input.read()
print "The input file is %d bytes long" % len(indata)
Contents of the file:
One two three
Upon running this simple program I get as output: The input file is 14 bytes long
Qutestion:
I don’t understand, if my file has written in it only 11 characters(One two three) how can len return me 14 bytes and not just simply 11?(what’s with the bytes by the way?) In the python interpreter if I type s = “One two three” and then len(s) I get 13, so I am very confused.
“One two three” is indeed 13 chars (11 letters + 2 spaces).
Most likely you have an extra char for the endline, which explains the 14.