CBSE Class 12 Computer Science Question 57 of 62

Using Python Libraries — Question 10

Back to all questions
10
Question

Question 10

Consider the following package

music/                        Top-level package
 ├── __init__.py
 ├── formats/                 Subpackage for file format
 │      ├── __init__.py
 │      └── wavread.py
 │      └── wavwrite.py
 │
 ├── effects/                 Subpackage for sound effects
 │      └── __init__.py
 │      └── echo.py
 │      └── surround.py
 │      └── reverse.py
 │
 └── filters/                 Subpackage for filters
     ├── __init__.py
     └── equalizer.py
     └── vocoder.py
     └── karaoke.py

Each of the above modules contain functions play(), writefile() and readfile().

(a) If the module wavwrite is imported using command import music.formats.wavwrite. How will you invoke its writefile() function ? Write command for it.

(b) If the module wavwrite is imported using command from music.formats import wavwrite. How will you invoke its writefile() function ? Write command for it.

Answer

(a) If the module wavwrite is imported using the command import music.formats.wavwrite, we can invoke its writefile() function by using the module name followed by the function name:

import music.formats.wavwrite
music.formats.wavwrite.writefile()

(b) If the module wavwrite is imported using the command from music.formats import wavwrite, we can directly invoke its writefile() function without prefixing the module name:

from music.formats import wavwrite
writefile()