-1

I'm just getting started on python programming.

Here is an example of my CSV file :

Name tag. description
Cool cool,fun cool ...
Cell Cell,phone Cell ...
Rang first,third rang ...

The print with the CSV module gives me a list of all rows, either:

['cool',''cool,fun'','cool...']
['cell',''cell,phone'','cell...']

What I want to do is to printer that cool or cell, phone

Timeless
  • 22,580
  • 4
  • 12
  • 30
JustMe
  • 9
  • 2
    Can you add to your question a _clear expected output_ ? Also, are you open to external libraries ? – Timeless Jan 31 '23 at 11:14
  • Welcome to the world of programming! What you are looking for is a way to format the output. The csv module itself works very well out of the box. Take a look at Alan's answer, please. Happy coding! – zhengliw Jan 31 '23 at 12:36

1 Answers1

2

I'm also new to programming, but I think I know what you're asking.


How to use CSV module in python

The answer for your question

  • What you asked "printer that cool or cell, phone" is easy to implement, you can try below code in terminal:

import csv
with open('your_file_path', 'r', newline='', encoding='utf-8') as f:
    reader = csv.reader(f)
    rows = list(reader)
    print(rows[1][0])
    print(rows[2][1])

My thoughts

  • Actually, you should consider the following two points when understanding this problem:
  1. Content, that is, the content you want to print in your terminal, you need to first make sure that what you want is a specific row or column or a specific cell;
  2. The format, that is, the list you side or those quotation marks, these are the types of data in the file, and they must be carefully distinguished.

In addition, it would be better for you to read some articles or materials processed about CSV module, such as the following:

https://docs.python.org/3/library/csv.html#reader-objects

https://www.geeksforgeeks.org/reading-rows-from-a-csv-file-in-python

https://www.tutorialspoint.com/working-with-csv-files-in-python-programming


I am also unskilled in many places, please forgive me if there are mistakes or omissions.

Alan
  • 21
  • 2