• <small id='UczNN'></small><noframes id='UczNN'>

    1. <legend id='UczNN'><style id='UczNN'><dir id='UczNN'><q id='UczNN'></q></dir></style></legend>
        <bdo id='UczNN'></bdo><ul id='UczNN'></ul>
      <tfoot id='UczNN'></tfoot>

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

        python return - “名称未定义"

        python return - quot;name not definedquot;(python return - “名称未定义)
            <tbody id='m73AU'></tbody>
          • <bdo id='m73AU'></bdo><ul id='m73AU'></ul>
            <i id='m73AU'><tr id='m73AU'><dt id='m73AU'><q id='m73AU'><span id='m73AU'><b id='m73AU'><form id='m73AU'><ins id='m73AU'></ins><ul id='m73AU'></ul><sub id='m73AU'></sub></form><legend id='m73AU'></legend><bdo id='m73AU'><pre id='m73AU'><center id='m73AU'></center></pre></bdo></b><th id='m73AU'></th></span></q></dt></tr></i><div id='m73AU'><tfoot id='m73AU'></tfoot><dl id='m73AU'><fieldset id='m73AU'></fieldset></dl></div>
            <tfoot id='m73AU'></tfoot>
          • <small id='m73AU'></small><noframes id='m73AU'>

                <legend id='m73AU'><style id='m73AU'><dir id='m73AU'><q id='m73AU'></q></dir></style></legend>
                1. 本文介绍了python return - “名称未定义"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试让此脚本将信息写入基本文本文件.我还在学习python.

                  I'm trying to get this script to write information into a basic text file. I'm still learning python.

                  问题出在这里:

                  file_text = """%s SHOOT DETAILS
                  
                  Number of shoots:	 %s
                  Maximum range:	 %s
                  Number of firers:	 %s
                  Number of lanes active:	 %s
                  Number of details:	 %s
                  Troops per detail:	 %s
                  
                   
                  RANGE STAFF
                  Ammo NCO:	 %s
                  Medical Supervisor:	 %s
                  IC Butts:	 %s""" % (shoot_name, number_of_shoots, max_range, number_of_firers, number_of_lanes, number_of_details, size_of_details, ammo_nco, medical_supervisor, ic_butts)
                  

                  错误信息:NameError: name 'number_of_details' 未定义

                  The error message: NameError: name 'number_of_details' is not defined

                  上面的内容(据说)是这样写到一个文件中的:

                  The above is (supposedly) written into a file with this:

                  def generatedocument():
                      file = open(file_name, 'w')
                      file.write(file_text)
                      os.startfile(file_name)
                  

                  但是我之前确实在以下函数中定义了它:

                  However I did define it earlier in the following function:

                  def detailformation():
                      number_of_details = number_of_firers / number_of_lanes
                      return number_of_details
                  

                  定义的 size_of_details 出现相同的问题:

                  Identical problems occur for the size_of_details, defined:

                  def detailsizer():
                      size_of_details = number_of_firers / detailformation()
                      return size_of_details
                  

                  还有范围工作人员选择器功能,有时它会给我一个类似的错误.它们来自这个从列表中随机选择它们的函数:

                  And also with the range staff chooser function, sometimes it gives me a similar error. They come from this function that randomly selects them from a list:

                  def range_staff():
                      print "
                  "
                      ammo_nco = (random.choice(fiveplatoon))
                      print "Ammo NCO: "+ammo_nco
                      fiveplatoon.remove(ammo_nco)
                      medical_supervisor = (random.choice(fiveplatoon))
                      print "Medical supervisor: "+medical_supervisor
                      fiveplatoon.remove(medical_supervisor)
                      ic_butts = (random.choice(fiveplatoon))
                      print "IC Butts/Console: "+ic_butts
                      fiveplatoon.remove(ic_butts)
                      return range_staff
                  

                  似乎我在这里遗漏了一些基本的东西.如何让python识别?

                  It seems like I'm missing something fundamental here. How can I get python to recognise?

                  推荐答案

                  变量只存在于你声明的范围内

                  The variables only exist in the scope you declare them

                  def fun():
                      x = 5
                      return x
                  
                  >>> x
                  Traceback (most recent call last):
                    File "<pyshell#4>", line 1, in <module>
                      x
                  NameError: name 'x' is not defined
                  

                  如果你想使用一个函数的return值,那么调用这个函数并将它赋值给这样一个变量

                  If you want to use the return value from a function, then call the function and assign it to such a variable

                  >>> x = fun()
                  >>> x
                  5
                  

                  这篇关于python return - “名称未定义"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 与否?)
                  <legend id='ANHKd'><style id='ANHKd'><dir id='ANHKd'><q id='ANHKd'></q></dir></style></legend>
                  <tfoot id='ANHKd'></tfoot>

                    • <bdo id='ANHKd'></bdo><ul id='ANHKd'></ul>

                        <tbody id='ANHKd'></tbody>

                      1. <i id='ANHKd'><tr id='ANHKd'><dt id='ANHKd'><q id='ANHKd'><span id='ANHKd'><b id='ANHKd'><form id='ANHKd'><ins id='ANHKd'></ins><ul id='ANHKd'></ul><sub id='ANHKd'></sub></form><legend id='ANHKd'></legend><bdo id='ANHKd'><pre id='ANHKd'><center id='ANHKd'></center></pre></bdo></b><th id='ANHKd'></th></span></q></dt></tr></i><div id='ANHKd'><tfoot id='ANHKd'></tfoot><dl id='ANHKd'><fieldset id='ANHKd'></fieldset></dl></div>
                      2. <small id='ANHKd'></small><noframes id='ANHKd'>