[英]How to make python code simpler
i have following python code.我有以下python代码。 Can i optimise it to one line:
我可以将其优化为一行:
url = request.session.get('my_value', '/')
if url == '/None/':
url = '/'
Any help will be appericiated任何帮助都会得到帮助
url = re.sub("^/None/$","/",request.session.get('my_value', '/'))
I think this should work:我认为这应该有效:
url = [request.session.get('my_value', '/'), '/']['/None/' in request.session.get('my_value', '/')]
But honestly, it makes the code much more horrible to read...但老实说,这让代码读起来更可怕……
url = '/' if url == '/None/': else url = request.session.get ('my_value', '/')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.