尝试这个:
~$ cat test.py
name = raw_input('Please insert a name: ')
phone = raw_input('Please insert a phone number: ')
# Opening in a+ mode will point the file pointer to the end of the file.
# We will fix this with seek().
directory = open('test.csv', 'a+')
# Seek to the 0th offset from the end of the file (option 2).
directory.seek(0, 2)
# Write the data at the end of the file.
directory.write(name + ',' + phone + '\n')
# Seek to the beginning of the file (option 0).
directory.seek(0, 0)
# Read the file and print output.
print(directory.read())
~$ >test.csv
~$ python test.py
Please insert a name: Test Name 1
Please insert a phone number: 111-222-3344
Test Name 1,111-222-3344
~$ python test.py
Please insert a name: Test Name 2
Please insert a phone number: 222-333-4444
Test Name 1,111-222-3344
Test Name 2,222-333-4444
~$