Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: enclose path with quotes #159

Open
sslupsky opened this issue Oct 1, 2021 · 1 comment
Open

Feature request: enclose path with quotes #159

sslupsky opened this issue Oct 1, 2021 · 1 comment

Comments

@sslupsky
Copy link

sslupsky commented Oct 1, 2021

Some hyperlinks contain paths with commas which is a problem within a CSV. I am wondering if it would be beneficial to enclose the path or link for the datasheet within quotes?

In the screenshot below, you can see an example of how this might cause a problem. In this example, vscode appends the fields after the datasheet into the datasheet link.
Screen Shot 2021-10-01 at 2 30 15 PM

@set-soft
Copy link
Contributor

set-soft commented Oct 4, 2021

Which Python is installed in your system?
I tried the KiBoM code on Python 3.9 and it defaults to quoting=csv.QUOTE_MINIMAL
This means you should get strings with the delimiter quoted.
I tried this example (from Python manual):

import csv
with open('eggs.csv', 'w', newline='') as csvfile:
    spamwriter = csv.writer(csvfile, delimiter=',', lineterminator="\n") # quotechar='|', quoting=csv.QUOTE_MINIMAL)
    spamwriter.writerow(['Spam'] * 5 + ['Baked, Beans'])
    spamwriter.writerow(['Spam', 'Lovely Spam', 'Wonderful Spam'])

And got:

$ cat eggs.csv 
Spam,Spam,Spam,Spam,Spam,"Baked, Beans"
Spam,Lovely Spam,Wonderful Spam

In KiBoM's code the file csv_writer.py writes the CSV output, the csv writer is initialized like this:

    writer = csv.writer(f, delimiter=delimiter, lineterminator="\n")

You could modify it to:

    writer = csv.writer(f, delimiter=delimiter, lineterminator="\n", quoting=csv.QUOTE_ALL)

This will force quotes in all fields.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants