i searched my problem on stack and i didt find the solution so i come here to asking u about that .im learnin python with the book 'OReilly.Introducing.Python' and in chapter 5 in module section .the author says u can save a program and use in in another program as module when the 2 programs are saved in 1 directory. this is the fist program using as module. report.py
def get_description(): # see the docstring below?
"""Return random weather, just like the pros"""
from random import choice
possibilities = ['rain', 'snow', 'sleet', 'fog', 'sun', 'who knows']
return choice(possibilities)
and the main program is this :
import report
description = report.get_description()
print("Today's weather:", description)
its a simple program i know when i want to import that it apears with this error:
Traceback (most recent call last): File "H:\\python\\Lib\\weather.py", line 1, in import report File "H:\\python\\Lib\\report.py", line 2 """Return random weather, just like the pros""" ^ IndentationError: expected an indented block
i tried to change directory and copy that to lib folder or scripts and this is my sys.path: H:\\python\\Lib C:\\Windows\\System32 H:\\python\\Lib\\idlelib H:\\python\\python35.zip H:\\python\\DLLs H:\\python\\lib H:\\python H:\\python\\lib\\site-packages
Just as the error says, you must ident the docstring:
def get_description(): # see the docstring below?
"""Return random weather, just like the pros"""
from random import choice
possibilities = ['rain', 'snow', 'sleet', 'fog', 'sun', 'who knows']
return choice(possibilities)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.