Python缩进问题不是由于不正确的空格

时间:2015-07-15 03:36:20

标签: python whitespace

我在以下代码中收到了一个缩进错误:

 28 def dropletExistsInSummaries( droplet ):                                                                                                                             
 29   """                                                                                                                                                                
 30   dropletExists() -- checks to see if a droplet's URL exists in the summary table, takes one argument                                                                
 31   * droplet is the DID of the raindrop                                                                                                                               
 32   """                                                                                                                                                                
 33   log.debug( "entering" )                                                                                                                                            
 34   c2 = db.cursor()                                                                                                                                                   
 35   d = ( droplet, )                                                                                                                                                   
 36   did = 0                                                                                                                                                            
 37   try:                                                                                                                                                               
 38     c2.execute( 'SELECT did from summaries where did = ?', d )                                                                                                       
 39     did = c2.fetchone()[0]                                                                                                                                           
 40   except Exception, e:                                                                                                                                               
 41     log.error( "dropletExists query failed: %s", e )                                                                                                                 
 42   if did > 0:                                                                                                                                                        
 43     return did                                                                                                                                                       
 44   else:                                                                                                                                                              
 45     return 0                                                                                                                                                         
 46                                                                                                                                                                      
 47                                                                                                                                                                      
 48 def summarizeDroplet( did, url ):                                                                                                                                    
 49   """                                                                                                                                                                
 50   TODO: document this                                                                                                                                                
:x                                                                                                                                                                      
sodaphish@svr-lnx02:~/semanticrss$ ./tst.py 
  File "./tst.py", line 37
    try: 
    ^
IndentationError: unexpected indent

...这对我没有任何意义,因为我已经检查确保所有内容都正确缩进!我已经盯着这看了好几个小时,并且因为我需要帮助而辞职。

说实话,我不完全确定为什么我必须在第35行用parens包围“Droplet”,我的猜测是造成这个问题的原因,但我无法确定这个问题。与此有关。

为了记录,我使用的是Python 2.7.9。

提前感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

您的函数缩进是三个空格,而try...except块的缩进是两个空格。解决这个问题,它应该可行。

PEP 8建议使用四个空格来缩进代码。

相关问题