python - 得到错误:使用重新拆分方法时预期的字符串或类似字节的对象
问题描述
这是以下OP1的延续。虽然@Rakesh 的建议非常紧凑,但是当与可从edf_file 链接访问的打开文件一起使用时,相同的解决方案无法正常运行。
下面的代码
file= 'edfx\\SC4002EC-Hypnogram.edf' # Please change according to the location of you file
with open(file, mode='rb') as f:
raw_hypno = re.split(r"Sleep stage|Movement time", f)
将输出错误
TypeError:预期的字符串或类似字节的对象
感谢任何见解。
解决方案
肮脏的解决方法
提取二进制文件并获取字符串
raw_hypno_single = [x for x in str(f.read()).split('Sleep stage',1)][1:]
然后,按照OP1中的建议拆分睡眠阶段和运动
raw_hypno =re.split(r"Sleep stage|Movement time", raw_hypno_single[0])
完整的代码是
file= 'edfx\\SC4002EC-Hypnogram.edf' # Please change according to the location of you file
with open(file, mode='rb') as f:
raw_hypno_single = [x for x in str(f.read()).split('Sleep stage',1)][1:]
raw_hypno =re.split(r"Sleep stage|Movement time", raw_hypno_single[0])
推荐阅读
- amazon-web-services - 在单个 terraform 资源中具有受控循环
- sql - 使用链接服务器从 PostgreSQL 获取数据到 MS SQL Server 时出现特殊字符问题
- python - ModuleNotFoundError:没有名为“extruct”的模块(Python 3.7 Jupyter Notebook)
- javascript - 将 JavaScript 变量添加到 jQuery 选择器中的 href 值
- yolo - 从 yolov4 或 yolov5 转换为 coreml
- asp.net-core - 天蓝色服务总线:“MaxConcurrentCalls”的理想数量是多少
- python - 使用请求进行网络抓取时如何使用多线程
- spacy - 基于动词形式的Spacy模式异常案例
- kotlin - Kotlin 流程:奇怪的行为,代码执行了 3 次,而它应该只执行一次
- angular - 在严格模式下,我应该在 angular 10 的拦截器中为 HttpRequest 提供什么类型