Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String python字符串拆分";大约80k个字符的字符串“;_String_Python 3.x_List - Fatal编程技术网

String python字符串拆分";大约80k个字符的字符串“;

String python字符串拆分";大约80k个字符的字符串“;,string,python-3.x,list,String,Python 3.x,List,这里有一些数据样本 f = "optimal after sales service. Our customer friendly support system is truly one of a kind giving A Avon Watches a pride of place in the world of Indian watches.\\t0210PBH2YCA\\t1002004\\t499\\t\\t2015-02-10 16:43:27 IST\\t\\ty\\t1\\t\\t

这里有一些数据样本

f = "optimal after sales service. Our customer friendly support system is truly one of a kind giving A Avon Watches a pride of place in the world of Indian watches.\\t0210PBH2YCA\\t1002004\\t499\\t\\t2015-02-10 16:43:27 IST\\t\\ty\\t1\\t\\t\\t11\\t\\t\\t\\tB00TFCNTGG\\t\\t\\t\\t\\t\\tB00TFCNTGG\\t\\t\\t\\tAMAZON_IN\\t\\tMigrated Template\\tActive\\t499.0\\nA Avon Sports Digital Black Dial Men\\\'s watch - 1002008\\tMulti functional Design Watch For Children\\\'s ; Tough Watch Case ; Stainless Steel Back ;Power Battery ; Tab For Date,Month & Multiple Light Effect ; Day & Time Display Together ; Stop Watch ; Calendar ; 12-24 Hour Time Display Option. A Avon Watches are Well known for amazing style and powerful features. The inbuilt features specify their usability. The elegantly designed A Avon Watches are apt to complement formal wear. A Avon Watches built with fine skills is backed by optimal after sales service. Our customer friendly support system is truly one of a kind giving A Avon Watches a pride of place in the world of Indian watches.\\t0216PZ3I06Y\\t1002008\\t499\\t\\t2015-02-16 15:45:58 IST\\t\\ty\\t5\\t\\t\\t11\\t\\t\\t\\tB00TOCAJ4C\\t\\t\\t\\t\\t\\t52E478CC519D7B2D\\t\\t\\t\\tAMAZON_IN\\t\\tMigrated Template\\tActive\\t499.0\\nA Avon Sports Digital Black Dial Women\\\'s Watch - 1002013\\tWatch Design For Children, Boys & Girls. A Avon Watches are Well known for amazing style and powerful features. The inbuilt features specify their usability. The elegantly designed A Avon Watches are apt to complement formal wear. A Avon Watches built with fine skills is backed by optimal after sales service. Our customer friendly support system is truly one of a kind giving A Avon Watches a pride of place in the world of Indian watches.\\t0216PZCK1E4\\t1002013\\t599\\t\\t2015-02-16 18:17:39 IST\\t\\ty\\t5\\t\\t\\t11\\t\\t\\t\\tB00TOGJ00M\\t\\t\\t\\t\\t\\t52E49B861FA1FF25\\t\\t\\t\\tAMAZON_IN\\t\ "
z=f.split("\\\t")
for i in z:
  print(i)
  print(len(z))
但它并不是在分裂,而是在打印同一个文件。 我也检查了z的长度,它显示为1


怎么做?

您的文本不包含任何选项卡
'\t'
,那么为什么会发生拆分?有很多反斜杠
\\
,后面跟着一个简单的
t
,但是您尝试在反斜杠后面跟着一个选项卡进行拆分。您可以尝试:

f.split('\\t')

查看差异。

您发布的代码引发异常,它不显示长度为1。
.readlines()
返回一个行列表,调用
.split
将引发异常。您好@l3via,我做了一些更改,而不是将文件作为字符串删除,因为它也不会拆分字符串。请删除一个反斜杠:
\\\t
->
\\t
。否则,在反斜杠后面加上制表符进行拆分。反斜杠也不起作用。我也试过了。