I recently discovered that GitHub projects has TSV exports! ππΌ
I was super excited about this but it also made me realize that some folks may want/prefer csv files and so, I asked by bestie - GitHub Copilot Chat - to help me convert a TSV file to a CSV file in Python.
Now, I'm not a Python Developer, so I wasn't sure how I would do this in Python, and while I could use an npm module like PapaParse to accomplish this, I wanted to try another language.
Honestly, it was pretty seamless!
Here's how I did it:
Step 1: Download your TSV file and add it to a folder, then open said folder in VSCode (or your preferred editor).
Step 2: Create a new Python file, I called mine tsv_to_csv.py
.
Step 3: Navigate to GitHub Copilot Chat and ask "how do I convert a tsv file to csv with python?"
I was provided with the following code:
import csv
with open('ruby-study-guide.tsv', 'r') as tsvfile:
reader = csv.reader(tsvfile, delimiter='\t')
with open('ruby-study-guide.csv', 'w', newline='') as csvfile:
writer = csv.writer(csvfile)
for row in reader:
writer.writerow(row)
print("Conversion complete!")
If you're not familiar with GitHub Copilot Chat, read this blog post to learn how to get started with it.
Step 4: Paste the code into your file by clicking the "Insert at Cursor" icon.
Step 5: Save your file, run the code with python <<name of your file here>>
, for example python tsv_to_csv.py
, and enjoy your csv file!
Here's a video/gif on the steps I did above:
Now that you know that GitHub Projects has TSV exports, learn more tidbits that you possibly didn't know by reading this blog post I wrote on 10 things you didn't know you could do with GitHub Projects.
Let me know if you have any questions about GitHub Copilot or GitHub Projects below!
Top comments (3)
As you discovered with Copilot, Python's
csv
module is more versatile than just csv files, and can handle arbitrary delimiters.One random DEV tip for you: DEV's editor supports syntax highlighting in code blocks. Here's how:
Produces:
It works for most languages. Just put language name after opening backticks.
Thank you! I'm not too familiar with Python so can't wait to. learn more about the
csv
module!Also, Thanks so much for the tip! Updated! ππΌ
You're welcome. Python's a great language to learn. I use it a lot. It's not the language I use the most, but it's in my top 3.