① python从txt文件中读取数字,并且判断其大小。
#!/usr/bin/python
#encoding:utf-8
importre
context="""
0.00000000E+001.99000000E-021.05000000E+000.00000000E+003.88519671E+02
4.20000000E-021.99000000E-021.00800000E+000.00000000E+004.23216155E+02
8.40000000E-021.99000000E-029.66000000E-010.00000000E+004.67920285E+02
1.26000000E-011.99000000E-029.24000000E-010.00000000E+004.89975818E+02
1.68000000E-011.99000000E-028.82000000E-010.00000000E+005.01845166E+02
2.10000000E-011.99000000E-028.40000000E-010.00000000E+005.10017363E+02
2.52000000E-011.99000000E-027.98000000E-010.00000000E+005.15927207E+02
2.94000000E-011.99000000E-027.56000000E-010.00000000E+005.18914324E+02
3.36000000E-011.99000000E-027.14000000E-010.00000000E+005.18683254E+02
"""
patt=re.compile(r"d.d+E[+-]d{2}")
array=[]
forlninfilter(None,context.splitlines()):
array.append(map(float,patt.findall(ln)))
debug=True
defdebugView(obj):
importpprint
ifdebug:
pprint.pprint(obj)
debugView(array)
你的数据来自文本文件,可以用 for ln in filter(None, open(datafile, 'rt'))
替代 for ln in filter(None, context.splitlines())
② python字符串长度len
我是这方面的老师,这个问题其实挺简单的
新建一个 使用len()函数得到字符的总长度.py
中文编码声明注释:# coding=gbk
len() 方法的作用:获取字符串的长度
输入代码:str1 = "海翔飞"
使用 len() 函数获取 str1 的字符串长度
运行脚本,输出 str1 的字符串长度
ok,到这就完工了,祝你学习愉快,记得采纳
③ python字符串长度判断问题
ascii字符长度只有8位,而其他编码的字符往往有16位或32位
利用这一点可以进行判断
将字符串解码成unicode,判断长度是否与解码前相同
#
-*-
coding:
utf-8
-*-a
=
'中国123'b
=
a.decode('utf-8')print
a,len(a)
==
len(b)a
=
'abc'b
=
a.decod...
④ python文本长度处理
#-*-coding:utf-8-*-
"""
:createdon:2015年4月17日
:author:ChuanqingQin
:contact:[email protected]
"""
defstr_len(temp):
returnlen(unicode(temp,'utf-8'))
defdeal_file(file_in):
withopen(file_in,'r')asf:
forlineinf:
file_out=str(str_len(line.strip()))+'.txt'
withopen(file_out,'w')astemp_file:
temp_file.write(line+' ')
if__name__=='__main__':
printstr_len('ewdfw交换生的as到发斯蒂')
deal_file('a.txt')
⑤ Python字符串有没有字符串长度方法
name[1:-2:-2]表示从第2个字符(参数1)开始,往回(左)数每两个字符取一个(第三个参数-2),结束于倒数第三个字符(第二个参数-2),由于结束位置在开始位置的右边,所以得到一个空字符串
第一个参数表示开始位置,第二个表示结束位置,第三个标志步速(step,正数表示从左到右,负数表示从右到左,绝对值表示步进速度)
⑥ python判断字符串有几个字符
字符串长度
通过内置方法len()来计算字符串的长度,注意这个计算的是字符的长度。
aa = 'afebb'
bb = '你'
print len(aa)
print len(bb)
http://www.cnpythoner.com/wiki/string.html
⑦ python获取txt内容并判断
#!/usr/bin/python
# -*- coding:utf-8 -*-
spath="./123.txt"
def existError(spath):
file=open(spath)
flag=0
for line in file:
#忽略大小写
if 'error' in str.lower(line):
flag=1
break
return flag
if __name__=="__main__":
flag=existError(spath)
print(str(flag))
⑧ python判断字符串长度
那段时间长的都一样,成绩不同,一切不同判断标准不一样。
⑨ [编程python]python中字符串的长度是如何计算的
一对引号之间的任何东西都算一个字符,包括字母、数字、符号、汉字、空白符等。
⑩ python如何判断字符串的长度是否大于0
这种量长度是大于零的,只不过就是比零多一点点,不到一。也可以去量一下,我没有那么多准确的数据。