Reputation: 57
I want the code below to print the selected file, But im doing something wrong. the code gives me this error:
TypeError: expected str, bytes or os.PathLike object, not _io.TextIOWrapper
def open_file():
global file
global wb
file = askopenfile(mode="a", filetypes=[("Excel Files", "*.xlsx *.xlsm *.sxc *.ods *.csv *.tsv")])
wb = openpyxl.load_workbook(filename=file.name)
filename = os.path.basename(file)
print(filename)
What am I doing wrong?
Upvotes: 1
Views: 100
Reputation: 15098
Perhaps your error is on this line:
filename = os.path.basename(file)
It should be:
filename = os.path.basename(file.name)
The error states that you are not passing a path(string), bytes or os.PathLike
object. Instead you are passing _io.TextIOWrapper
object, as file
is _io.TextIOWrapper
object.
Upvotes: 2