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

    <tfoot id='Lhefp'></tfoot>
    • <bdo id='Lhefp'></bdo><ul id='Lhefp'></ul>

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

        python返回函数

        时间:2023-09-02

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

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

                <legend id='Gzxs2'><style id='Gzxs2'><dir id='Gzxs2'><q id='Gzxs2'></q></dir></style></legend>
                  <bdo id='Gzxs2'></bdo><ul id='Gzxs2'></ul>
                    <tbody id='Gzxs2'></tbody>

                  <tfoot id='Gzxs2'></tfoot>
                • 本文介绍了python返回函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在 Python 中遇到语法错误,错误:

                  I'm getting a syntax error in Python, the error:

                  SyntaxError: 'return' outside function
                  

                  这似乎很容易解释,但就 可以看到 return 是 inside 一个函数.

                  That seems pretty self-explanatory but as far as I can see return is inside a function.

                  这是我的代码:

                  def getLinks(self, url, fandom, soup):
                      links = []
                  
                      searchElementDict = {
                      'aff':'select', 'fcwd':'select', 'ffn':'select', 'tthm':'select', 'lua':'select', 'ffa':'select', 
                      'hpfd':'select', 'phns':'select', 'mbba':'div', 'avgf':'div', 'mugn':'select', 'hpffa':'select',
                      'hpff':'select',
                      }
                      if fandom in searchElementDict:
                          searchElement = searchElementDict[fandom]
                  
                      searchElementForDict = {
                      'aff':'name', 'fcwd':'name', 'ffn':'title', 'tthm':'name', 'lua':'class', 'ffa':'class',
                      'hpfd':'name', 'phns':'name', 'mbba':'id', 'avgf':'id', 'mugn':'name', 'hpffa':'name',
                      'hppf':'name',
                      }
                      if fandom in searchElementForDict:
                          searchElementFor = searchElementForDict[fandom]
                  
                      withValueDict = {
                      'aff':'chapnav', 'fcwd':'goto', 'ffn':'Chapter Navigation', 'tthm':'chapnav', 'lua':'textbox',
                      'ffa':'locationSelect', 'hpfd':'sid', 'phns':'chao', 'mbba':'mibba-layout-parts', 'avgf':'chapters',
                      'mugn':'chapter', 'hpffa':'chapter', 'hpff':'chapterid',
                      }
                      if fandom in withValueDict:
                          withValue = withValueDict[fandom]   
                      try:    
                          if fandom == 'mbba' or fandom == 'avgf':
                              chapterGroup = soup.find(searchElement, attrs={searchElementFor : withValue})
                              individualChapters = chapterGroup.findAll('a')
                              for each in individualChapters:         
                                  chapterLink = each['href']
                                  links.append(chapterLink)       
                          else:   
                              chapterGroup = soup.find(searchElement, attrs={searchElementFor : withValue})
                              individualChapters = chapterGroup.findAll('option', attrs={'value=':''})
                              for each in individualChapters:         
                                  chapterLink = each.get('value')
                                  links.append(chapterLink)
                              if fandom == 'fcwd':
                                  del links[0]
                              elif fandom == 'hpfd' or fandom == 'hpff':
                                  del links[0]
                                  del links[0]
                      except:
                          links.append(1) 
                  
                  
                      return links
                  

                  我显然错过了一些东西,我只是想不通什么.

                  I'm obviously missing something, I just can't figure out what.

                  推荐答案

                  我怀疑你混合了制表符和空格.. 你的 def 前面有 4 个空格,随后你使用多个制表符进行缩进.

                  I suspect you are mixing tabs and spaces .. your def has 4 spaces preceding it, subsequently you are using multiple tabs for indentation.

                  PEP 8 建议使用 (4) 制表符上方的空格.

                  还要注意 PEP 8 中的以下内容:

                  Also note the following from PEP 8:

                  Python 3 不允许在缩进中混合使用制表符和空格.

                  Python 3 disallows mixing the use of tabs and spaces for indentation.

                  混合使用制表符和空格缩进的 Python 2 代码应该是转换为独占使用空格.

                  Python 2 code indented with a mixture of tabs and spaces should be converted to using spaces exclusively.

                  使用 -t 调用 Python 2 命令行解释器时选项,它会发出有关非法混合选项卡和代码的警告空格.使用 -tt 时,这些警告会变成错误.这些选项是强烈推荐!

                  When invoking the Python 2 command line interpreter with the -t option, it issues warnings about code that illegally mixes tabs and spaces. When using -tt these warnings become errors. These options are highly recommended!

                  这篇关于python返回函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Python 函数返回 None (检查了所有简单的解决方案并且它们不起作用) 下一篇:在 for 循环中使用 Return

                  相关文章

                • <legend id='9voz9'><style id='9voz9'><dir id='9voz9'><q id='9voz9'></q></dir></style></legend>

                • <small id='9voz9'></small><noframes id='9voz9'>

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

                  <tfoot id='9voz9'></tfoot>