我在Rosetta Code上尝试了一个python代码示例- 一个编程的chrestomathy站点,其中相同任务的解决方案以尽可能多的不同编程语言呈现.对于此任务,目标是从图形用户界面输入字符串和整数75000.代码如下所示:
import tkSimpleDialog
number = tkSimpleDialog.askinteger("Integer", "Enter a Number")
string = tkSimpleDialog.askstring("String", "Enter a String")
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试运行代码时,我收到以下错误:
Traceback (most recent call last):
File "C:\Users\vix\Documents\.cache\GUIexample.py", line 3, in <module>
number = tkSimpleDialog.askinteger("Integer", "Enter a Number")
File "C:\Python27\lib\lib-tk\tkSimpleDialog.py", line 262, in askinteger
d = _QueryInteger(title, prompt, **kw)
File "C:\Python27\lib\lib-tk\tkSimpleDialog.py", line 189, in __init__
Dialog.__init__(self, parent, title)
File "C:\Python27\lib\lib-tk\tkSimpleDialog.py", line 53, in __init__
if parent.winfo_viewable():
AttributeError: 'NoneType' object has no attribute 'winfo_viewable'
Run Code Online (Sandbox Code Playgroud)
问题出在哪里?
谢谢
我的问题与此类似,只是我想搜索多个出现的情况chars,例如g,d和e,然后打印其中存在所有指定字符的行。
我已尝试以下方法,但没有成功:
searchfile = open("myFile.txt", "r")
for line in searchfile:
if ('g' and 'd') in line: print line,
searchfile.close()
Run Code Online (Sandbox Code Playgroud)
我得到的行中包含“g”或“d”或两者,我想要的只是两者都出现,而不是至少其中之一,就像运行上述代码的结果一样。