本文介绍了切割字符串功能/ Python适用于生物信息学的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! >>> rs =''AUGCUAGACGUGGAGUAG'' Traceback(最近一次调用最后一次): 文件"< pyshell#119>",第1行,在? rs [12:15] =''GAG'' TypeError:对象不支持切片分配 你可以''分配给 Python 2.3中的切片字符串的一部分,并且似乎没有提到这个作为Python 2.4特性的(不要有时间实际尝试 2.4)。 Q1。扩展切片是否使用了Sequence协议? Q2。不是字符串也支持Sequence protcol? Q3。那么为什么你不能在处理字符串时进行扩展切片赋值工作 ? 这种操作(切片/拼接序列代表 作为字符串)在执行 rna / dna /蛋白质测序算法时似乎是一个非常基本的oepration,它会大大增强 Python'如果切片 和扩展切片操作符达到其逻辑限制,那么对生物信息学工作的人有吸引力。 粗略搜索看起来似乎没有揭示任何当前的PEP 处理扩展切片/扩展的功能 切片操作符。 语法和功能明智,有没有理由为什么Python不能踢? Perl's butt作为生物信息学的主导语言和 最终成为这种快速增长的通用语言和资金丰富的领域? 解决方案 Traceback(最近一次调用最后一次):文件"< pyshell#119>",第1行,在? rs [12:15] =''GAG' ' TypeError:对象不支持切片分配 你不能在Python 2.3中分配切片字符串的一部分而且似乎没有提到这个作为Python 2.4的功能(没有时间实际尝试 2.4)。 字符串是在Python中不可变,这就是为什么分配给切片不起作用的原因。 但为什么不使用列表呢? rs = list(''AUGC ...'') rs [12:15] = list(''GAG'') Reinhold Traceback(最近一次调用最后一次):文件"< pyshell#119>",第1行,in? rs [12:15] =''GAG'' TypeError:对象不支持切片分配 你不能分配切片字符串的一部分在Python 2.3中,似乎没有提到这个作为Python 2.4的功能(没有时间实际尝试 2.4)。 字符串在Python中是不可变的,这就是为什么分配到片段不起作用的原因。 但为什么不使用列表? rs = list(''AUGC ......'') rs [12:15] = list(''GAG'') 或者字符数组:参见数组模块。 Terry J. Reedy >>> rs=''AUGCUAGACGUGGAGUAG''Traceback (most recent call last):File "<pyshell#119>", line 1, in ?rs[12:15]=''GAG''TypeError: object doesn''t support slice assignmentYou can''t assign to a section of a sliced string inPython 2.3 and there doesn''t seem to be mention of thisas a Python 2.4 feature (don''t have time to actually try2.4 yet).Q1. Does extended slicing make use of the Sequence protocol?Q2. Don''t strings also support the Sequence protcol?Q3. Why then can''t you make extended slicing assignment workwhen dealing with strings?This sort of operation (slicing/splicing of sequences representedas strings) would seem to be a very fundamental oepration when doingrna/dna/protein sequencing algorithms, and it would greatly enhancePython''s appeal to those doing bioinformatics work if the slicingand extended slicing operators worked to their logical limit.Doing a cursory search doesn''t seem to reveal any current PEPsdealing with extending the functionality of slicing/extendedslicing operators.Syntax and feature-wise, is there a reason why Python can''t kickPerl''s butt as the dominant language for bioinformatics andeventually become the lingua franca of this fast-growing andfunding-rich field? 解决方案 Traceback (most recent call last): File "<pyshell#119>", line 1, in ? rs[12:15]=''GAG'' TypeError: object doesn''t support slice assignment You can''t assign to a section of a sliced string in Python 2.3 and there doesn''t seem to be mention of this as a Python 2.4 feature (don''t have time to actually try 2.4 yet).Strings are immutable in Python, which is why assignment toslices won''t work.But why not use lists?rs = list(''AUGC...'')rs[12:15] = list(''GAG'')Reinhold Traceback (most recent call last): File "<pyshell#119>", line 1, in ? rs[12:15]=''GAG'' TypeError: object doesn''t support slice assignment You can''t assign to a section of a sliced string in Python 2.3 and there doesn''t seem to be mention of this as a Python 2.4 feature (don''t have time to actually try 2.4 yet). Strings are immutable in Python, which is why assignment to slices won''t work. But why not use lists? rs = list(''AUGC...'') rs[12:15] = list(''GAG'')Or arrays of characters: see the array module.Terry J. Reedy 这篇关于切割字符串功能/ Python适用于生物信息学的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!