Python Enclosing Words With Quotes In A String
Question: For Python I'm opening a csv file that appears like:

    
    
        jamie,london,uk,600087
        matt,paris,fr,80092
        john,newyork,ny,80071
    

How do I enclose the words with quotes in the csv file so it appears like:

    
    
        "jamie","london","uk","600087"
        etc...
    

What I have right now is just the basic stuff:

    
    
        filemame = "data.csv"
        file = open(filename, "r")
    

Not sure what I would do next.


Answer: If you are just trying to convert the file, use the `QUOTE_ALL` constant from
the [`csv` module](https://docs.python.org/2/library/csv.html#csv.QUOTE_ALL),
like this:

    
    
    import csv
    
    with open('data.csv') as input, open('out.csv','w') as output:
        reader = csv.reader(input)
        writer = csv.writer(output, delimiter=',', quoting=csv.QUOTE_ALL)
        for line in reader:
            writer.writerow(line)
    

