A comma separated file is generated by an application. On the first column it contains a last name, on the second a first name and on the tenth column a telephone number. For each row of this csv an vcard entry should be generated.
This was my solution:
#!/usr/bin/python import csv import sys def convert(file): reader = csv.reader(open(file, 'rb')) for row in reader: print 'BEGIN:VCARD' print 'VERSION:2.1' print 'N:' + row + ';' + row print 'FN:' + row + ' ' + row print 'TEL;HOME;VOICE:' + row print 'END:VCARD' def main(args): if len(args) != 2: print "Usage:" print args + " filename" return convert(args) if __name__ == '__main__': main(sys.argv)
Outputting the generated vcard on stdout was fine for me, I just redirected it into an appropriate file.