Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/300.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
在Python中使用用户输入生成数组时遇到的问题_Python_Arrays_Tkinter - Fatal编程技术网

在Python中使用用户输入生成数组时遇到的问题

在Python中使用用户输入生成数组时遇到的问题,python,arrays,tkinter,Python,Arrays,Tkinter,我有一个使用tkinter的窗口,用户可以在其中键入数组的值:即“x”、“y”、“z”。然后,当我将数据放入一个数组(myarray=[myuserinput])时,它会在其周围加上两个单引号:““x”、“y”、“z”。这会阻止数组被读取-索引器错误:列表索引超出范围 另外,当我尝试使用一些数据和while循环创建另一个数组时,它会在数组前面插入很多括号: firstcounter = "1" thecounters = "0" while int(firstcounte

我有一个使用tkinter的窗口,用户可以在其中键入数组的值:即
“x”、“y”、“z”
。然后,当我将数据放入一个数组(
myarray=[myuserinput]
)时,它会在其周围加上两个单引号:
““x”、“y”、“z”
。这会阻止数组被读取-索引器错误:列表索引超出范围
另外,当我尝试使用一些数据和while循环创建另一个数组时,它会在数组前面插入很多括号:

    firstcounter = "1"
    thecounters = "0"
    while int(firstcounter) < newfilter :
        thecounters = thecounters,0
        firstcounter = int(firstcounter) + 1
    counters = [thecounters]
firstcounter=“1”
计数器=“0”
而int(firstcounter)
此代码还会导致列表索引超出范围错误


请帮忙

我在这里做一个粗略的猜测,假设您处理的是一个字符串,其中元素由
分隔

您需要拆分字符串以获得元素列表

myarray = myuserinput.split(",")
例如:

In [3]: myuserinput = '"x","y","z"'

In [4]: my_list = myuserinput.split(",")

In [5]: my_list
Out[5]: ['"x"', '"y"', '"z"']
您可以在拆分之前替换

In [11]: myuserinput = myuserinput.replace('"', '')

In [12]: myuserinput
Out[12]: 'x,y,z'

这里有两个问题。问一个问题,得到一个答案。如果您还有其他问题,请打开一个新问题。请将其称为list@msvalkon下次我会记住的;)