def count_spaces(filename): input_file = open(filename,'r') file_contents = input_file.read() space = 0 tabs = 0 newline = 0 line in file_contents == " ": space +=1 return space line in file_contents == '\t': tabs += 1 return tabs line in file_contents == '\n': newline += 1 return newline input_file.close()
i'm trying write function takes filename parameter , returns total number of spaces, newlines , tab characters in file. want try use basic loop , if statement i'm struggling @ moment :/ great thanks.
c=counter(open(afile).read()) c[' ']
Comments
Post a Comment