Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

python TypeError: join() argument must be str, bytes, or os.PathLike object, not 'list'

I have a CSV containing 28 UUIDs

I would like to create a python loop which runs each uuid individually and places it into a filepath

e.g. Org/datasets/uuid/data

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I have tried the below but failing

import os
import csv

uuid = []
with open('C:/Users/Public/file.csv', 'r') as file:
  reader = csv.reader(file)
  for row in reader:
    uuid.append(row)

for i in uuid:
  filepath = os.path.join("org/datasets/",  i , "/data")
  print(filepath)

error is TypeError: join() argument must be str, bytes, or os.PathLike object, not 'list'

The CSV is very simplistic and looks as follows:

uuid blank
uuid1 blank
uuid2 blank

>Solution :

In your for loop ever value of i corresponds to a row in your csv file. As such, it comes out as a list, something you cannot concat against a str. Instead, you should be taking the first element of your list(the actual uuid)

for i in uuid:
  filepath = os.path.join("org/datasets/",  i[0] , "/data")
  print(filepath)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading