Skip to content
Advertisement

Can’t write in csv file

When I try to write the information in the csv file, error is thrown:

JavaScript
JavaScript

How to keep the file open through the whole script execution ? Or I have to open it every time I am adding content ? EDIT In fact, the file is not even created.

Advertisement

Answer

JavaScript

The file closes at the end of the with block – that is the block’s purpose.

You could put everything inside the block, but that only makes the existing problem worse: the code is reaching several levels of indents, is long and becomes difficult to understand. This is why you use functions to organize the code. For example, if you have the big for loop set in a function:

JavaScript

Once you have that working, you can probably think of ways to apply the technique further. For example, pull out the innermost logic, for handling the variations for a single product. Or you can have a function to handle the creation of the categories data, and return it.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement