1

I'm trying to deploy a working python 3.6 notebook in Watson Studio (cloud). However I'm struggling to access files/assets. After uploading a .log file to my assets, I want to open and process it using

with open(project.get_file('messages.log'), 'r') as file:

the error message returns

TypeError: expected str, bytes, or os.PathLike object, not _io.BytesIO

Apart from telling me how to open/read the log-file, I'd also appreciate a short explanation on why project.get_file returns a BytesIo object.

Sasha C.
  • 11
  • 1

1 Answers1

0

project-lib's function get_file reads the file from your Watson Studio project's storage. You can read your file like this:

buffer = project.get_file('messages.log')
log_file = buffer.getvalue()

I am not hundred percent sure why it has been decided to return a BytesIo object but it is quite convenient e.g. if you want to read your data into a pandas dataframe:

my_file = project.get_file('myFile.csv')
my_file.seek(0)
import pandas as pd
pd.read_csv(my_file, nrows=10)

You can find project-lib's documentation here: project-lib for Python

  • Thanks Simone. Unfortunately this isn't working as it should. Although the object log_file is being created, it is empty. Also, note that I'm trying to use the function open, which leads to the described error. I could convert the bytes object into a string object (which I have done), but in any case, the object is empty/does not contain the log info. – Sasha C. Aug 07 '20 at 08:21