writing_python_scripts/questions.rst
author amit
Tue, 26 Oct 2010 15:44:09 +0530
changeset 349 9ced58c5c3b6
parent 335 d5248a15274c
child 465 78d20cd87c7e
permissions -rw-r--r--
Added long answer type problems in all scripts

Objective Questions
-------------------

 1. Which of the following variables contains the locations to search for
    python modules

   a. sys.pythonpath
   #. sys.path
   #. os.pythonpath
   #. os.path

   Answer: sys.path

 2. What is the type of ``sys.path``

   a. list of strings
   #. list of int
   #. string
   #. tuple of strings

   Answer: list of strings

 3. The script ``utils.py`` is in one of locations of PYTHONPATH and contains
    the following code:

      def show(x):
          print x

      show("Hello World")

      if __name__ == "__main__":

          show("Hello Test")

    How do you import the file.

   a. import utils
   #. import utils.py
   #. import /home/user/utils
   #. import /home/user/utils.py

   Answer: import utils

 4. The script ``utils.py`` is in one of locations of PYTHONPATH and contains
    the following code:

      def show(x):
          print x

      show("Hello World")

      if __name__ == "__main__":

          show("Hello Test")

    How do you use the ``show`` function after doing ``import utils``

   a. utils.show("hey")
   #. show("hey")
   #. utils.py.show("hey")
   #. utils.py.show.py("hey")

   Answer: utils.show("hey")

 5. The script ``utils.py`` is in one of locations of PYTHONPATH and contains
    the following code:

      def show(x):
          print x

      show("Hello World")

      if __name__ == "__main__":

          show("Hello Test")

    How do you use the ``show`` function after doing ``from utils import show``

   a. utils.show("hey")
   #. show("hey")
   #. utils.py.show("hey")
   #. utils.py.show.py("hey")

   Answer: show("hey")

 5. The script ``utils.py`` is in one of locations of PYTHONPATH and contains
    the following code:

      def show(x):
          print x

      show("Hello World")

      if __name__ == "__main__":

          show("Hello Test")

    What is printed when you do ``import utils``

   Answer::
      Hello World

 6. The script ``utils.py`` is in one of locations of PYTHONPATH and contains
    the following code:

      def show(x):
          print x

      show("Hello World")

      if __name__ == "__main__":

          show("Hello Test")

    What is printed when the script is executed.

   Answer::
      Hello World
      Hello Test