Hi fellow OCW student, I have a question about ps3b.py homework; writing hangman code computer part. from ps3a import * import time from perm import * what is importing other codes mean? are all the functions from the imported codes allowed to use ?
*correction-a word game, not hangman.
yep, the objects from those modules will be available in the local namespace.
The import statement imports ( brings in to ) other modules and libraries into your program. The two types of import statement that you have import things differently. import time imports the time module into your program, but in it's own namespace. To get the localtime, you have to call time's functions with time as the namespace: time.localtime( time.time() ) from perm import * imports all ( * ) of perm's functions into the local namespace. To use one of perm's functions or objects, you don't have to preface it with perm. Some other languages like C #include instead of import their libraries. Usage wise, it's basically the same.
Join our real-time social learning platform and learn together with your friends!