Workout 8. Modules & Packages Flashcards

(9 cards)

1
Q

Two-fold purpose of module?

A
  1. code reuse across multiple programs
  2. create namespace to avoid collision
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

_ achieves code reuse within a single program.
_ achieves code reuse across multiple programs.

A
  1. function
  2. module
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

import os module within your program.

A

import os

This defines all objects/functions/variables located in os module as your global variables (part of global namespace).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Import module X, but only
define Y (from X) as a global variable

A

from X import Y

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Re-import an already loaded
module os.

A

importlib.reload(os)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

import sep object from os module, but use it as variable s.

A

from os import sep as s

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

import all objects from os module.

A

from os import *

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

In your custom module, expose only foo and bar objects when imported using *.

A
\_\_all\_\_ = ['foo', 'bar']
# foo and bar are some functions defined below in the module
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly