Getting The Error: Expected String Or Bytes-like Object When Using Re Split Method
This is continuation from the following OP1. While the suggestion by @Rakesh is awesomely compact, but the same solution cannot function properly when used with an open file which
Solution 1:
Dirty workaround
Extract the binary and get the string
raw_hypno_single = [x for x in str(f.read()).split('Sleep stage',1)][1:]
Then, split the sleep stage and movement as suggested in OP1
raw_hypno =re.split(r"Sleep stage|Movement time", raw_hypno_single[0])
The full code is
file= 'edfx\\SC4002EC-Hypnogram.edf'# Please change according to the location of you filewithopen(file, mode='rb') as f:
raw_hypno_single = [x for x instr(f.read()).split('Sleep stage',1)][1:]
raw_hypno =re.split(r"Sleep stage|Movement time", raw_hypno_single[0])
Post a Comment for "Getting The Error: Expected String Or Bytes-like Object When Using Re Split Method"