Q:

How to write in a single cell in a csv file rather than separate ones?

import csv 
with open ("students.csv", "a") as newFile:
        newFileWriter = csv.writer(newFile)
        student = input("Enter a student's name: ")
        student_email = input("Enter a student's email: ")
        newFileWriter.writerow(student)
        newFileWriter.writerow(student_email)

Here's my code. When I run it, it prints the student's name with one letter in each cell (like B|o|b instead of Bob). The same happens with the email. Can somebody help in simple terms: I'm a bit of a python noob.

A:

writerow accepts a list as an argument and writes each element in a cell. Since strings are lists of characters in Python, each letter is getting stored in a cell. You should do this instead:
newFileWriter.writerow([student, student_email])

Hope it helps!

