<tfoot id='ycTKm'></tfoot>
  • <i id='ycTKm'><tr id='ycTKm'><dt id='ycTKm'><q id='ycTKm'><span id='ycTKm'><b id='ycTKm'><form id='ycTKm'><ins id='ycTKm'></ins><ul id='ycTKm'></ul><sub id='ycTKm'></sub></form><legend id='ycTKm'></legend><bdo id='ycTKm'><pre id='ycTKm'><center id='ycTKm'></center></pre></bdo></b><th id='ycTKm'></th></span></q></dt></tr></i><div id='ycTKm'><tfoot id='ycTKm'></tfoot><dl id='ycTKm'><fieldset id='ycTKm'></fieldset></dl></div>
      <bdo id='ycTKm'></bdo><ul id='ycTKm'></ul>

      1. <small id='ycTKm'></small><noframes id='ycTKm'>

        <legend id='ycTKm'><style id='ycTKm'><dir id='ycTKm'><q id='ycTKm'></q></dir></style></legend>

        Python3 exec,为什么返回None?

        Python3 exec, why returns None?(Python3 exec,为什么返回None?)
        <i id='59Wz9'><tr id='59Wz9'><dt id='59Wz9'><q id='59Wz9'><span id='59Wz9'><b id='59Wz9'><form id='59Wz9'><ins id='59Wz9'></ins><ul id='59Wz9'></ul><sub id='59Wz9'></sub></form><legend id='59Wz9'></legend><bdo id='59Wz9'><pre id='59Wz9'><center id='59Wz9'></center></pre></bdo></b><th id='59Wz9'></th></span></q></dt></tr></i><div id='59Wz9'><tfoot id='59Wz9'></tfoot><dl id='59Wz9'><fieldset id='59Wz9'></fieldset></dl></div>

            <bdo id='59Wz9'></bdo><ul id='59Wz9'></ul>
                <tbody id='59Wz9'></tbody>

            • <small id='59Wz9'></small><noframes id='59Wz9'>

              <legend id='59Wz9'><style id='59Wz9'><dir id='59Wz9'><q id='59Wz9'></q></dir></style></legend>

                <tfoot id='59Wz9'></tfoot>
                1. 本文介绍了Python3 exec,为什么返回None?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  当下面这段代码的代码,并返回结果None 为什么?

                  When the code below this text, and returns the result None why?

                  with open('exx.py', 'rb') as file:
                  ff = compile(file.read(), 'exx.py', 'exec')
                  snip_run = exec(ff, locals())
                  if 'result' in locals():
                      print(snip_run, result)
                  else:
                      print(snip_run)
                  

                  结果:

                  777777
                  None
                  

                  模块代码 exx.py:

                  Module code exx.py:

                  print('777777')
                  

                  推荐答案

                  问题当然不只是print返回None,而是exec 返回无,总是.

                  The problem of course is not only that print returns None, it is that exec returns None, always.

                  >>> exec('42') is None
                  True
                  

                  如果你需要返回值,你可以使用 eval:

                  If you'd need the return value, you'd use eval:

                  >>> eval('42')
                  42
                  

                  之后您会注意到 print 仍然返回 None...

                  after which you'd notice that print still returns None...

                  这篇关于Python3 exec,为什么返回None?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Initialize Multiple Numpy Arrays (Multiple Assignment) - Like MATLAB deal()(初始化多个 Numpy 数组(多重赋值) - 像 MATLAB deal())
                  How to extend Python class init(如何扩展 Python 类初始化)
                  What#39;s the difference between dict() and {}?(dict() 和 {} 有什么区别?)
                  What is a wrapper_descriptor, and why is Foo.__init__() one in this case?(什么是 wrapper_descriptor,为什么 Foo.__init__() 在这种情况下是其中之一?)
                  Initialize list with same bool value(使用相同的布尔值初始化列表)
                  setattr with kwargs, pythonic or not?(setattr 与 kwargs,pythonic 与否?)
                      <bdo id='OU2jU'></bdo><ul id='OU2jU'></ul>
                        <tbody id='OU2jU'></tbody>
                    • <i id='OU2jU'><tr id='OU2jU'><dt id='OU2jU'><q id='OU2jU'><span id='OU2jU'><b id='OU2jU'><form id='OU2jU'><ins id='OU2jU'></ins><ul id='OU2jU'></ul><sub id='OU2jU'></sub></form><legend id='OU2jU'></legend><bdo id='OU2jU'><pre id='OU2jU'><center id='OU2jU'></center></pre></bdo></b><th id='OU2jU'></th></span></q></dt></tr></i><div id='OU2jU'><tfoot id='OU2jU'></tfoot><dl id='OU2jU'><fieldset id='OU2jU'></fieldset></dl></div>

                          <legend id='OU2jU'><style id='OU2jU'><dir id='OU2jU'><q id='OU2jU'></q></dir></style></legend>

                          <small id='OU2jU'></small><noframes id='OU2jU'>

                          <tfoot id='OU2jU'></tfoot>