# Python JSON

**URL:** https://forum.networklessons.com/t/python-json/10828
**Category:** Lessons Discussion
**Created:** [April 20, 2020, 2:59pm UTC](https://forum.networklessons.com/t/python-json/10828 "2020-04-20T14:59:09Z")
**Posts on this page:** 1
**Showing post:** 5

<div class="post-metadata">

### Author: ![ReneMolenaar](https://cdn-forum.networklessons.com/user_avatar/forum.networklessons.com/renemolenaar/32/488_2.png) [@ReneMolenaar](https://forum.networklessons.com/u/ReneMolenaar)
#### Post date: [November 30, 2020, 7:22pm UTC](https://forum.networklessons.com/t/python-json/10828/5 "2020-11-30T19:22:26Z")

</div>

Bonjour @syncope988,

Using `open` or `with open` is the same thing, except when you use “with”, it automatically closes.

**First Example**

- You use the read() function on “f” and assign the output to the “exemple1” variable. When you use the read() function, you get a **string**.
- You then run the reader() function from the CSV module, feed it the “exemple1” variable and assign the output to the “exemple\_f” variable.
- You then iterate over each item in the “exemple\_f” variable.

When you check what “row” is, you’ll see it’s a list with only a single character. That’s why you get an index out of range error. There is only one item in the list, that’s why [0] works but not [1] or [2].

**Second Example**

- You open the csv\_example.csv file and assign the output to variable “f”.
- You run the reader() function from the CSV module and assign the output to variable “exemple\_f”.
- You iterate over variable “exemple\_f”.

**This time, you didn’t use the read() function.**

By doing it like this, each line in your CSV file **becomes a list**. That’s why you can use [0], [1], [2], etc. to access the items in your list.

**In a nutshell:** data and data conversion can be a pain. You can’t always predict what kind of object you get in return…a string, tuple, list, or dictionary. For example, the read() function returns a string but the readlines() function returns a list.

To make your life a lot easier, try to run some Python scripts in visual studio code. When you add a breakpoint, you can visualize what your data looks like:

 ![image](https://cdn-forum.networklessons.com/uploads/default/original/2X/a/a9d75aa175bda8a8f2b9dd129c9e23f25cf796e8.png)

You can even right-click on what you want to use and choose “copy as expression”:

 ![image](https://cdn-forum.networklessons.com/uploads/default/original/2X/e/ec4bbc541979646eb8abe43b7b00ecac9cda027f.png)

And use it in your code, or in the debug console:

 ![image](https://cdn-forum.networklessons.com/uploads/default/original/2X/8/85366a5a5fffb065295120c3dcddc7c721abdb4a.png)

This makes it much easier compared to using the python interpreter or IDLE where you have to use the print or type function to see things. Give it a try, it will be very helpful 🙂

Doe this explanation help?

Rene

---

_[View the full topic](https://forum.networklessons.com/t/python-json/10828)._
