为什么在函数中执行一组命令:
def main():
[do stuff]
return something
print(main())
Run Code Online (Sandbox Code Playgroud)
在python中运行速度比在顶层执行命令1.5x要3x快得多:
[do stuff]
print(something)
Run Code Online (Sandbox Code Playgroud) 我最近更新了我的应用并尝试运行它,并得到以下关于"地址已在使用中"的错误.这是什么意思,我该如何解决?
Traceback (most recent call last):
File "/home/ubuntu/workspace/app.py", line 11, in <module>
app.run(host = os.getenv('IP', '0.0.0.0'), port=int(os.getenv('PORT',8080)))
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 772, in run
run_simple(host, port, self, **options)
File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 687, in run_simple
inner()
File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 653, in inner
fd=fd).serve_forever()
File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 557, in make_server
passthrough_errors, ssl_context, fd=fd)
File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 467, in __init__
HTTPServer.__init__(self, (host, int(port)), handler)
File "/usr/lib/python2.7/SocketServer.py", line 419, in __init__
self.server_bind()
File "/usr/lib/python2.7/BaseHTTPServer.py", line 108, in server_bind
SocketServer.TCPServer.server_bind(self)
File "/usr/lib/python2.7/SocketServer.py", line 430, in server_bind …Run Code Online (Sandbox Code Playgroud) 我刚开始学习 Haskell,但我遇到了困难,因为错误消息非常神秘。特别是,当我运行这个应该打印字符串排列数的代码时,我不理解错误消息,
import Data.List
main::IO()
main = do
str <- getLine
print putStrLn $ length $ nub $ permutations str
Run Code Online (Sandbox Code Playgroud)
我得到的错误信息是
但是,当我在 REPL 中运行它时,我没有收到这样的错误: