Home > OS >  How can I sort the data from csv file in python in ascending order by name?
How can I sort the data from csv file in python in ascending order by name?

Time:12-10

import csv
sure="y"
def create():
    s="y"
    f=open("tele.csv","w",newline="")
    print("="*184)
    print(" "*77,"Creating a telephone directory"," "*77)
    print("="*184)
    writer=csv.writer(f)
    while s=="y":
        a=input("Enter Name : ")
        b=input("Enter Contact Number : ")
        writer.writerow([a,b])
        print()
        s=input("Do you want to add another contact? (y/n) : ")
        print()
    print("Telehone Directory created successfully!")
    print("="*184)
    f.close()

def add():
    f=open("tele.csv","a",newline="")
    print("="*184)
    print(" "*82,"Add a New Contact"," "*82)
    print("="*184)
    writer=csv.writer(f)
    a=input("Enter Name : ")
    b=input("Enter Contact Number : ")
    writer.writerow([a,b])
    print()
    print("Telehone Directory created successfully!")
    print("="*184)
    f.close()


def disp():
    f=open("tele.csv","r")
    print("="*184)
    print(" "*83,"Telephone Directory"," "*83)
    print("="*184)
    print("Ps"%"Contact Name","           
  • Related