"Girintili bir blok bekleniyor" hatası?

Python'un neden "Expected indentation block" hatası verdiğini anlayamıyorum?

""" This module prints all the items within a list"""
def print_lol(the_list):
""" The following for loop iterates over every item in the list and checks whether
the list item is another list or not. in case the list item is another list it recalls the function else it prints the ist item"""

    for each_item in the_list:
        if isinstance(each_item, list):
            print_lol(each_item)
        else:
            print(each_item)
Çözüm

Oradaki fonksiyon tanımından sonra doküman dizesini girintilemeniz gerekir (satır 3, 4):

def print_lol(the_list):
"""this doesn't works"""
    print 'Ain't happening'

Girintili:

def print_lol(the_list):
    """this works!"""
    print 'Aaaand it's happening'

Ya da bunun yerine yorum yapmak için # kullanabilirsiniz:

def print_lol(the_list):
#this works, too!
    print 'Hohoho'

Ayrıca, docstrings hakkında PEP 257 adresine bakabilirsiniz.

Umarım bu yardımcı olur!

Yorumlar (1)

Ben de bunu yaşadım mesela:

Bu kod çalışmıyor ve amaçlanan blok hatasını alıyorum.

class Foo(models.Model):
title = models.CharField(max_length=200)
body = models.TextField()
pub_date = models.DateTimeField('date published')
likes = models.IntegerField()

def __unicode__(self):
return self.title

Ancak return self.title ifadesini yazmadan önce tab tuşuna bastığımda kod çalışıyor.

class Foo(models.Model):
title = models.CharField(max_length=200)
body = models.TextField()
pub_date = models.DateTimeField('date published')
likes = models.IntegerField()

def __unicode__(self):
    return self.title

Umarım bu başkalarına da yardımcı olur.

Yorumlar (0)