>chr1 <_io.TextIOWrapper name='result.fa' mode='w' encoding='UTF-8'>

 

001、问题

复制代码
[root@pc1 test4]# ls
a.fa  test.py
[root@pc1 test4]# cat a.fa
>chr1
aatt
cc
>chr2
ttgg
ccttgg
>chr3
TTCCGG
cctt
ccgg
[root@pc1 test4]# cat test.py
#!/usr/bin/python

in_file = open("a.fa", "r")
out_file = open("result.fa", "w")

for i in in_file:
        i = i.strip()
        if i.startswith(">"):
                print(i, out_file)
[root@pc1 test4]# python test.py
>chr1 <_io.TextIOWrapper name='result.fa' mode='w' encoding='UTF-8'>
>chr2 <_io.TextIOWrapper name='result.fa' mode='w' encoding='UTF-8'>
>chr3 <_io.TextIOWrapper name='result.fa' mode='w' encoding='UTF-8'>
复制代码

 

 

002、解决方法

复制代码
[root@pc1 test4]# cat test.py
#!/usr/bin/python

in_file = open("a.fa", "r")
out_file = open("result.fa", "w")

for i in in_file:
        i = i.strip()
        if i.startswith(">"):
                print(i, file = out_file)   ## 在此处添加 file =
复制代码

 

posted @   小鲨鱼2018  阅读(88)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
历史上的今天:
2021-10-31 R语言中矩阵运算
2021-10-31 R语言实现计算两个向量的协方差、标准差、皮尔逊相关系数
2021-10-31 R语言统计 plink格式数据样本缺失率
2021-10-31 linux shell 统计plink格式样本缺失率
2021-10-31 plink + R PCA绘图自动设定颜色
2021-10-31 R语言实现统计 plink格式数据位点缺失率
2021-10-31 linux shell实现统计 位点缺失率
点击右上角即可分享
微信分享提示