I'm having some problems with some python scripting I've been doing. The idea of the whole script is to read a csv document containing 4 coloumns of 'friends'. Being their name, address, phone number and birthday. Now, I've written out some code already, but having some issues.
- I have the code for the load_friends definition, however it seems it's code just to open the csv, not to open the csv whenever the function is loaded.
- I'm really struggling to find the right tutorials to write code that adds a new line to a csv file after the function so, add_friend (name, address, ph number, birthday), enter, then it adds it to the csv.
If anyone can help with any of this, that would be most appreciated!
My code:
def load_friends():
"""Loads the friends.csv file from disk
"""
reader = csv.reader(open("friends.csv", "rb"))
for row in reader:
print row
def save_friends():
print row
def add_friend():
"""Writes a new entry to friends.csv via Python commands
"""
aCSVReader = csv.reader(open('friends.csv', 'rb'), delimiter=' ', quotechar='|')
for row in aCSVReader:
print ', '.join(row)