scripts how example español ejemplo __doc__ python indentation docstring

how - python 3 docstring example



¿Error "Se esperaba un bloque sangrado"? (2)

También experimenté eso, por ejemplo:

Este código no funciona y obtiene el error de bloqueo deseado.

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

Sin embargo, cuando presiono la pestaña antes de escribir return self.title statement, el código funciona.

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

Esperanza, esto ayudará a los demás.

¿No entiendo por qué python da un error de "Bloqueo de sangría esperado"?

""" 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)


Tiene que sangrar la cadena de documentos después de la definición de la función allí (líneas 3, 4):

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

Sangrado:

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

O puedes usar # para comentar en su lugar:

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

Además, puedes ver PEP 257 sobre cadenas de documentación.

¡Espero que esto ayude!