升华文本不';t执行所有Python代码行
使用未注册版本的Sublime文本(这就是问题所在) 当我运行以下代码时,它会提示我输入我的名字,我输入它并单击enter,然后什么也不会发生:升华文本不';t执行所有Python代码行,python,sublimetext3,Python,Sublimetext3,使用未注册版本的Sublime文本(这就是问题所在) 当我运行以下代码时,它会提示我输入我的名字,我输入它并单击enter,然后什么也不会发生: dict_1 = [] count = 0 while count < 3: fn = input('What is your first name:') ln = input('What is your last name:') dict_1.append({ "first_name": fn,
dict_1 = []
count = 0
while count < 3:
fn = input('What is your first name:')
ln = input('What is your last name:')
dict_1.append({
"first_name": fn,
"last_name": ln
})
count += 1
print(dict_1)
dict_1=[]
计数=0
当计数小于3时:
fn=input('您的名字是什么:')
ln=input('您姓什么:')
格言1({
“名字”:fn,
“姓氏”:ln
})
计数+=1
打印(dict_1)
然而,当我在PyCharm中运行完全相同的代码时,它会根据循环提示输入名字和姓氏3次,然后打印出结果字典
我更喜欢Sublime文本而不是Pycharm(不太臃肿),但如果它不执行所有代码,那么它可能对我不起作用
有什么想法吗?我缺少升华文本中的某些设置吗?升华文本“生成结果”窗格(界面底部):
不是交互式的,您不能在那里键入输入
为了解决这个问题,除了标准的CTRL+B构建快捷方式外,我还添加了另一个快捷方式(在“菜单首选项”>“键绑定-用户”中):
这允许在新的终端窗口中使用Python启动当前文件(在那里,您可以输入一些数据)
这是python\u run.py
文件(将在C:\Users\User\AppData\Roaming\Sublime Text 2\Packages\User
中复制):
升华文本“构建结果”窗格(界面底部):
不是交互式的,您不能在那里键入输入
为了解决这个问题,除了标准的CTRL+B构建快捷方式外,我还添加了另一个快捷方式(在“菜单首选项”>“键绑定-用户”中):
这允许在新的终端窗口中使用Python启动当前文件(在那里,您可以输入一些数据)
这是python\u run.py
文件(将在C:\Users\User\AppData\Roaming\Sublime Text 2\Packages\User
中复制):
正如其他人所指出的,Sublime的控制台不支持输入。如果要运行需要标准输入的程序。您可以在GUI终端中运行它。您可以修改Sublime的内置python,并为python添加一个变体
prv
,然后选择Open Resource
。
python
,并选择结果列表中的第一项Python.sublime build
李>
在打开的文件中,使用以下设置:
{
"shell_cmd": "python -u \"$file\"",
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python",
"env": {"PYTHONIOENCODING": "utf-8"},
"variants":
[
{
"name": "Syntax Check",
"shell_cmd": "python -m py_compile \"${file}\"",
},
{
"name": "Run in console",
"windows":{
"shell_cmd": "start cmd /k python -u \"$file\""
},
"linux":{
"shell_cmd": "xterm -hold -e python -u \"$file\""
},
"osx":{
"shell_cmd": "xterm -hold -e python -u \"$file\""
}
}
]
}
正如其他人所指出的,Sublime的控制台不支持输入。如果要运行需要标准输入的程序。您可以在GUI终端中运行它。您可以修改Sublime的内置python,并为python添加一个变体
prv
,然后选择Open Resource
。
python
,并选择结果列表中的第一项Python.sublime build
李>
在打开的文件中,使用以下设置:
{
"shell_cmd": "python -u \"$file\"",
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python",
"env": {"PYTHONIOENCODING": "utf-8"},
"variants":
[
{
"name": "Syntax Check",
"shell_cmd": "python -m py_compile \"${file}\"",
},
{
"name": "Run in console",
"windows":{
"shell_cmd": "start cmd /k python -u \"$file\""
},
"linux":{
"shell_cmd": "xterm -hold -e python -u \"$file\""
},
"osx":{
"shell_cmd": "xterm -hold -e python -u \"$file\""
}
}
]
}
您是否在sublime中使用Python3,或者您是否在Python2上运行可能的副本如果您使用Python2在sublime文本上运行它,它不知道输入是什么。所以它不会要求你one@dfundako exactly@JD2775请阅读链接。它应该能解决你的问题。下次在这里提问之前,一定要用谷歌搜索你的问题。我们不想继续回答重复的问题:)你是在sublime中使用Python3,还是在Python2上运行可能的重复:如果你使用Python2在sublime文本上运行它,它不知道输入是什么。所以它不会要求你one@dfundako exactly@JD2775请阅读链接。它应该能解决你的问题。下次在这里提问之前,一定要用谷歌搜索你的问题。我们不想继续回答重复的问题:)
{
"shell_cmd": "python -u \"$file\"",
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python",
"env": {"PYTHONIOENCODING": "utf-8"},
"variants":
[
{
"name": "Syntax Check",
"shell_cmd": "python -m py_compile \"${file}\"",
},
{
"name": "Run in console",
"windows":{
"shell_cmd": "start cmd /k python -u \"$file\""
},
"linux":{
"shell_cmd": "xterm -hold -e python -u \"$file\""
},
"osx":{
"shell_cmd": "xterm -hold -e python -u \"$file\""
}
}
]
}