ensure Unix line endings

This commit is contained in:
Martin Diehl 2022-03-26 22:00:08 +01:00
parent ac49365e34
commit e9906864cf
3 changed files with 6 additions and 6 deletions

View File

@ -144,7 +144,7 @@ class Config(dict):
Configuration from file.
"""
fhandle = open(Path(fname).expanduser()) if isinstance(fname, (str, Path)) else \
fhandle = open(Path(fname).expanduser(),newline='\n') if isinstance(fname, (str, Path)) else \
fname
return cls(yaml.safe_load(fhandle))

View File

@ -1803,7 +1803,7 @@ class Result:
if type(obj) == h5py.Dataset and _match(output,[name]):
d = obj.attrs['description'] if h5py3 else obj.attrs['description'].decode()
if not Path(name).exists() or overwrite:
with open(name,'w') as f_out: f_out.write(obj[0].decode())
with open(name,'w',newline='\n') as f_out: f_out.write(obj[0].decode())
print(f'Exported {d} to "{name}".')
else:
print(f'"{name}" exists, {d} not exported.')

View File

@ -260,7 +260,7 @@ class Table:
Table data from file.
"""
f = open(Path(fname).expanduser()) if isinstance(fname, (str, Path)) else fname
f = open(Path(fname).expanduser(),newline='\n') if isinstance(fname, (str, Path)) else fname
f.seek(0)
comments = []
@ -281,7 +281,7 @@ class Table:
else:
shapes[label] = (1,)
data = pd.read_csv(f,names=list(range(len(labels))),sep=r'\s+')
data = pd.read_csv(f,names=list(range(len(labels))),sep=r'\s+',lineterminator='\n')
return Table(shapes,data,comments)
@ -312,7 +312,7 @@ class Table:
Table data from file.
"""
f = open(fname) if isinstance(fname, (str, Path)) else fname
f = open(Path(fname).expanduser(),newline='\n') if isinstance(fname, (str, Path)) else fname
f.seek(0)
content = f.readlines()
@ -597,4 +597,4 @@ class Table:
f = open(Path(fname).expanduser(),'w',newline='\n') if isinstance(fname, (str, Path)) else fname
f.write('\n'.join([f'# {c}' for c in self.comments] + [' '.join(labels)])+('\n' if labels else ''))
self.data.to_csv(f,sep=' ',na_rep='nan',index=False,header=False)
self.data.to_csv(f,sep=' ',na_rep='nan',index=False,header=False,line_terminator='\n')