adjusted filehandle conditional type

This commit is contained in:
Daniel Otto de Mentock 2022-01-13 13:27:50 +01:00
parent ffa80f6bef
commit b4088b666e
1 changed files with 6 additions and 4 deletions

View File

@ -1,13 +1,15 @@
import re
import copy
from typing import Union, Optional, Tuple, List, TextIO, Set
import pathlib
from typing import Union, Optional, Tuple, List, TextIO, Set
from _io import TextIOWrapper
import pandas as pd
import numpy as np
from . import util
class Table:
"""Manipulate multi-dimensional spreadsheet-like data."""
@ -239,7 +241,7 @@ class Table:
Table data from file.
"""
if isinstance(fname, TextIO):
if isinstance(fname, TextIOWrapper):
f = fname
f.seek(0)
elif isinstance(fname, (str, pathlib.Path)):
@ -298,7 +300,7 @@ class Table:
Table data from file.
"""
if isinstance(fname, TextIO):
if isinstance(fname, TextIOWrapper):
f = fname
f.seek(0)
elif isinstance(fname, (str, pathlib.Path)):
@ -569,7 +571,7 @@ class Table:
labels += [f'{util.srepr(self.shapes[l],"x")}:{i+1}_{l}' \
for i in range(np.prod(self.shapes[l]))]
if isinstance(fname, TextIO):
if isinstance(fname, TextIOWrapper):
fhandle = fname
elif isinstance(fname, (str, pathlib.Path)):
fhandle = open(fname,'w',newline='\n')