|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- def scode5(user_input):
- default_dir = r'codepath/scode5.mri'
- file_path = tkinter.filedialog.askopenfilename(filetypes=[('Text file', '*.mri')], title=u'请选择文件: ', initialdir=(os.path.expanduser(default_dir)))
- file = open(file_path, 'r')
- ranlist = file.read()
- ranlist = ranlist.split('\n')
- print(ranlist)
- for e in ranlist:
- jiexima = e.split(',')[0]
- shuliang = e.split(',')[1]
- print(shuliang)
- for i in range(int(shuliang)):
- kong = ''
- sone = jiexima[0]
- stwo = jiexima[1]
- sthree = jiexima[2]
- kong = random.sample(number, 3)
- kong = sorted(kong)
- randir = ''
- for i in range(9):
- randir = randir + random.choice(number)
- randir = randir[0:int(kong[0])] + sone + randir[int(kong[0]):int(kong[1])] + stwo + randir[int(kong[1]):int(kong[2])] + sthree + randir[int(kong[2]):] + '\n'
- ranlist.append(randir)
- if not os.path.exists('codepath/scode5.txt'):
- file = open('codepath/scode5.txt', 'w')
- else:
- file = open('codepath/scode5.txt', 'a')
- for j in ranlist:
- file.write(j)
- print(j)
- file.close()
复制代码
- Traceback (most recent call last):
- File "C:/Users/54358/Documents/python程序/项目实战/第二个/main.py", line 193, in <module>
- scode5(user_input)
- File "C:/Users/54358/Documents/python程序/项目实战/第二个/main.py", line 146, in scode5
- shuliang = e.split(',')[1]
- IndexError: list index out of range
复制代码
打印了shuliang的值,没看出问题,请大神们指点 |
|