创建包含 >255 个元素的列表
好的,所以我正在编写一些 python 代码(我不怎么写 python,我更习惯 java 和 C)。
不管怎样,我有需要存储的整数文字集合。 (理想情况下超过 10,000 个,目前我只有 1000 个) 我本来希望通过文件 IO 或通过访问源 API 来访问文字,但这是不允许的。 无论如何,不是主题。
所以我将文字放入列表中:
src=list(0,1,2,2,2,0,1,2,... ,2,1,2,1,1,0,2,1)
#some code that uses the src
但是当我尝试运行该文件时,它会出现错误,因为参数超过 255 个。 所以构造函数就是问题所在。 我该怎么做?
这些数据最初是作为空格分隔的文本文件提供给我的。 我刚刚搜索并替换并复制了它
Ok, so I'm writing some python code (I don't write python much, I'm more used to java and C).
Anyway, so I have collection of integer literals I need to store.
(Ideally >10,000 of them, currently I've only got 1000 of them)
I would have liked to be accessing the literals by file IO, or by accessing there source API, but that is disallowed.
And not ontopic anyway.
So I have the literals put into a list:
src=list(0,1,2,2,2,0,1,2,... ,2,1,2,1,1,0,2,1)
#some code that uses the src
But when I try to run the file it comes up with an error because there are more than 255 arguments.
So the constructor is the problem.
How should I do this?
The data is intitally avaiable to me as a space deliminated textfile.
I just searched and replaced and copied it in
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用
[]
而不是list()
,则不会遇到限制,因为[]
不是函数。If you use
[]
instead oflist()
, you won't run into the limit because[]
is not a function.或者您无法在系统中保存文本文件?
Or are you not able to save text file in your system?