How to avoid writing request.GET.get() twice in order to print it?

前端 未结 10 741
名媛妹妹
名媛妹妹 2020-12-04 21:34

I come from a PHP background and would like to know if there\'s a way to do this in Python.

In PHP you can kill 2 birds with one stone like this:

Instead of

10条回答
  •  时光取名叫无心
    2020-12-04 22:30

    config_hash = {}
    tmp_dir = ([config_hash[x]  for x in ["tmp_dir"] if config_hash.has_key(x)] or ["tmp"])[0]
    print tmp_dir
    config_hash["tmp_dir"] = "cat"
    tmp_dir = ([config_hash[x]  for x in ["tmp_dir"] if config_hash.has_key(x)] or ["tmp"])[0]
    print tmp_dir
    

提交回复
热议问题