Guest User

Untitled

a guest
Dec 9th, 2019
83
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def readFile(name, separator=','):
  2.     csvList = []
  3.     try:
  4.         with open(name, 'r') as csvFile:
  5.             for line in csvFile.readlines():
  6.                 if line.isspace(): continue
  7.                 csvList.append(line.strip().split(separator))
  8.                 assert len(csvList[0]) == len(csvList[-1]), "Unproper number of column in a row"
  9.         return csvList
  10.    
  11.     except FileNotFoundError:
  12.         print("File has not found. Please provide correct path")
  13.        
  14.  
  15. def saveFile(file, fileName, separator=','):
  16.     try:
  17.         with open(fileName+'_writed.csv','w+') as csvFile:
  18.             for line in file:
  19.                 csvFile.writelines("{}\n".format(separator.join(line)))
  20.     except IndexError:
  21.         print('Probably your list is empty.')  
  22.  
  23.  
  24. def main():
  25.     path = 'cities.csv'
  26.     readedFile = readFile(path)
  27.     saveFile(readedFile,path)  
  28.    
  29. if __name__ == '__main__':
  30.     main()
RAW Paste Data