Automation with python

What are csv files ?

A) it is a comma separated value file , which consists of data separate by commas are the columns and the data separated by lines are rows. 

 Parsing -->    Analyzing a file's content to correctly structure the data

If we have data in a format we understand, we have what we need to parse the information from the file. What does parsing really mean.

Using rules to understand a file or data stream as structured data.

>>>    f  = open("csv_file.txt")
>>>    csv_f = csv.reader(f)
>>>    for row in csv_f:
                    name, Phone, role =row
                    print("Name: {}, Phone: {}, Role:{}".format(name,phone,role))
            f.close()

>>>


Generating CSV
>>>    hosts =[["workstation.local","192.168.25.46"],["webserver.cloud","10.2.5.6"]]
>>>    with open('hosts.csv','w') as hosts_csv:
                writer    =    csv.writer(hosts_csv)
                writer.writerows(hosts)

>>>cat hosts.csv
>>>

Reading and writing csv files with dictionaries

>>>cat software.csv
>>>name,version,status,users
>>>MailTree,5.34,production,324
>>>CalDoor,1.25,1,beta,22
>>>Chatty Chicken,0.34,alpha,4

Comments