fopen - Open function with CSV file on Python -


okay, want write csv file. i'm doing this:

directory = open('docs/directory.csv', 'a+', encoding='utf-8') name = input('please insert name: ') phone = input('please insert phone number: ')  directory.write(name + ',' + phone + ',\n')  print(directory.read()) 

i use 'a+' append every line @ end of file. here okay, data being added end of file everytime run script, problem data not being showed @ end, apparently, read() function not working.

am doing wrong? me please? thanks.

when call read, read current position of file pointer end of file. however, have file pointer @ end of file already, there nothing returned.

in case, open file in 'rw+' mode, seek end , append stuff.

directory = open('docs/directory.csv', 'a+', encoding='utf-8') directory.seek(0,2) #seek end  name = input('please insert name: ') phone = input('please insert phone number: ')  directory.write(name + ',' + phone + ',\n')  directory.seek(0) #seek beginning print(directory.read()) 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -