每次我用鼠标悬停在任何内容上时,它都会打开这个令人讨厌的文档页面,我每次都必须关闭它。我已经搜索类似的线程像这样和其他一些那些没有解决我的问题。关闭PyCharm的自动弹出文档功能无法解决鼠标悬停问题。
问题:尝试将讲师的python 2代码翻译为python 3
具体问题:无法从 python 3 中的表单访问消息字段
def do_POST(self):
try:
self.send_response(301)
self.send_header('Content-type', 'text/html')
self.end_headers()
ctype, pdict = cgi.parse_header(
self.headers.getheader('content-type'))
if ctype == 'multipart/form-data':
fields = cgi.parse_multipart(self.rfile, pdict)
messagecontent = fields.get('message')
output = ""
output += "<html><body>"
output += " <h2> Okay, how about this: </h2>"
output += "<h1> %s </h1>" % messagecontent[0]
output += '''<form method='POST' enctype='multipart/form-data' action='/hello'><h2>What would you like me to say?</h2><input name="message" type="text" ><input type="submit" value="Submit"> </form>'''
output += …Run Code Online (Sandbox Code Playgroud) 我试图捕捉数字字符串与任意字符串之间的区别:
'0'.to_f
#=> 0.0
'hello'.to_f
#=> 0.0
Run Code Online (Sandbox Code Playgroud)
以上两者都归来了Float.如果用户输入实际值'0'或用户输入值,我如何捕捉差异'hello'?
我正在尝试创建一个简单的Celsius到华氏温度计算器.如果用户输入"hello"程序应输出,Please type in a number:但如果用户键入,0则程序应输出正确的华氏度计算.
for循环
string_grid = ''
for i in self.board:
string_grid += "\n" + str(i)
return string_grid
Run Code Online (Sandbox Code Playgroud)
返回:
[0, 0, 0, 0, 0]
[0, 0, 0, 0, 0]
[0, 0, 0, 0, 0]
[0, 0, 0, 0, 0]
[0, 0, 0, 0, 0]
Run Code Online (Sandbox Code Playgroud)
但是为什么列表理解:
return str(["\n" + str(col) for col in self.board])
Run Code Online (Sandbox Code Playgroud)
返回:
['\n[0, 0, 0, 0, 0]', '\n[0, 0, 0, 0, 0]', '\n[0, 0, 0, 0, 0]', '\n[0, 0, 0, 0, 0]', '\n[0, 0, 0, 0, 0]']
Run Code Online (Sandbox Code Playgroud)
我一直试图让它工作很长一段时间,但无论我做什么,新线都没有在标准输出中逃脱.
python ×2
boolean ×1
forms ×1
http-post ×1
newline ×1
pycharm ×1
python-2.7 ×1
python-3.x ×1
ruby ×1
stdout ×1