I am trying to learn object oriented programming and am still shaky on the ins and outs of classes. I understand their purpose, but can't seem to grasp many simple operations when using them.
The dive into python section on classes is not very helpful either, so if you know any resources, please let me know.
Here is what I seek to do:
Make a class that reads in data from a file.
Strips white space and splits the data.
Prints the output to the screen.
I seek to do that using classes.
Here is an attempt:
class FormatData:
"""
CLass to take data file and format it to my liking
"""
def __init__(self, file=none):
infile = open(file)
for line in infile:
line = line.strip()
sline = line.split()
print sline
The code runs, but nothing prints to the screen. I don't understand how to run this code properly. Unfortunately, the project I am working on has this identical operation stored in a class, and then goes on to create a dictionary so I need to understand this before I move on. Why is it not printing to screen? Do I have to do something special since I am working in classes?
Editor's note: Please do not mix tabs and spaces in your Python code! Proper indentations are just too important with Python. Avoid tabs.