PIA-Group / BioSPPy

Biosignal Processing in Python
Other
569 stars 273 forks source link

Path to file not working on Windows #55

Closed Arinelle closed 5 years ago

Arinelle commented 5 years ago

When I run the following: ecg_signal, ecg_mdata = storage.load_txt('D:\Data\bitalinoECG.txt')

I obtain this error: OSError: [Errno 22] Invalid argument: 'D:\\Data\x08italinoECG.txt'

Apparently the string is not properly escaped.

capcarr commented 5 years ago

Hi @Arinelle

I'm assuming you are working on Windows, where it is frequent to have problems with path handling within Python. Note that Windows uses the backslash (\) in paths, which is an escape character in Python strings (\b actually represents a backspace ASCII character).

To overcome this, use either raw string literals (does not escape backslashes): ecg_signal, ecg_mdata = storage.load_txt(r'D:\Data\bitalinoECG.txt') or escape the backslash: ecg_signal, ecg_mdata = storage.load_txt('D:\\Data\\bitalinoECG.txt')