additional_features_of_ipython/questions.rst
author Puneeth Chaganti <punchagan@fossee.in>
Wed, 01 Dec 2010 16:51:35 +0530
changeset 522 d33698326409
permissions -rw-r--r--
Renamed all LOs to match with their names in progress.org.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
522
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     1
Objective Questions
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     2
-------------------
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     3
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     4
 1. How do you retrieve the recent 5 commands
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     5
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     6
    a. ``%hist``
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     7
    #. ``%hist -5``
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     8
    #. ``%hist 5``
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     9
    #. ``%hist 5-10``
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    10
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    11
    Answer: ``%hist 5``
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    12
    
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    13
 2. If there were 20 commands typed and ``%hist`` is used. How many commands 
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    14
    will be displayed.
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    15
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    16
    a. 10
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    17
    #. 20
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    18
    #. 21
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    19
    #. 19
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    20
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    21
    Answer: 21
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    22
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    23
.. #[Amit: I really don't get the question below]
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    24
 
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    25
 3. is ``%hist`` considered as a command
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    26
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    27
    a. True
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    28
    #. False
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    29
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    30
    Answer: True
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    31
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    32
 4. how do you retreive the commands from 20 to 50 (inclusive of 20 and 50)
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    33
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    34
    a. ``%hist 20 50``
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    35
    #. ``%hist 19 50``
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    36
    #. ``%hist 19 51``
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    37
    #. ``%hist 21 50``
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    38
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    39
    Answer: ``%hist 20 50``
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    40
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    41
 5. What does the ``%hist 2 5 7`` command do
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    42
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    43
    a. lists the second, fifth and seventh commands
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    44
    #. lists the commands from 2 to 5 and the seventh command
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    45
    #. raises an error
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    46
    #. lists the commands 2 to 7
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    47
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    48
    Answer: raises an error
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    49
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    50
 6. How many commands are displayed when lot of commands were typed and 
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    51
    ``%hist`` is used.
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    52
.. #[Amit: Ok something wrong with the question. 
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    53
.. Recommend : What is the default maximum number of commands %hist can show ]
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    54
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    55
    a. 20
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    56
    #. 10
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    57
    #. 50
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    58
    #. 40
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    59
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    60
    Answer: 40
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    61
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    62
 7. How do you save the lines 2 3 4 5 7 9 10 11
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    63
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    64
    a. ``%save filepath 2-5 7 9-11``
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    65
    #. ``%save filepath 2-11``
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    66
    #. ``%save filepath``
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    67
    #. ``%save 2-5 7 9 10 11``
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    68
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    69
    Answer: ``%save filepath 2-5 7 9-11``
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    70
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    71
 8. You are working in /home/user. Where is the file saved when you do
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    72
    ``%save hello.py 1-3`` 
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    73
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    74
    a. /home/user/hello.py
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    75
    #. /hello.py
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    76
    #. /home/hello.py
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    77
    #. /home/user/ipython/hello.py
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    78
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    79
    Answer: /home/user/hello.py
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    80
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    81
 9. Which lines are saved by the command ``%save filepath 2-5 7 1`` and in
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    82
    which order
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    83
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    84
    a. 2 3 4 5 7 1
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    85
    #. 1 2 3 4 5 6 7
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    86
    #. 2 5 7 1
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    87
    #. 1 2 5 7
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    88
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    89
    Answer: a
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    90
 
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    91
10. What happens when ``%save filepath line_numbers`` is used and a file
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    92
     already exists in that path.
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    93
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    94
    a. It is overwritten
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    95
    #. The commands are added to the file
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    96
    #. It raises an error
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    97
    #. A prompt to confirm overwriting is displayed 
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    98
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    99
    Answer: A prompt to confirm overwriting is displayed 
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   100
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   101
 11. Read through the documentation of ``%hist`` and find its alternative name
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   102
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   103
    Answer: ``%history``
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   104
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   105
 12. Are ``%run /home/user/saved.py`` and ``%run /home/user/saved`` the same
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   106
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   107
   a. Yes
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   108
   #. No
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   109
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   110
   Answer: Yes
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   111
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   112
 13. The file hello.py contains only one command ``x = x + 1``. What happens
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   113
     when you do ``%run hello.py``
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   114
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   115
    Answer: Raises a nameerror
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   116
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   117
  14. The file hello.py contains only one command ``x = x + 1``. If value of x
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   118
      is 5 and what does ``%run -i hello.py`` do.
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   119
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   120
    a. raises an error
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   121
    #. increments value of x by 1
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   122
    #. Does nothing
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   123
    
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   124
    Answer: increments the value of x by 1
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   125
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   126
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   127
Long Answer questions :
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   128
-----------------------
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   129
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   130
1. Question 1
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   131
2. Question 2
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   132
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   133
.. #[Amit: I think long answer questions for this script are
d33698326409 Renamed all LOs to match with their names in progress.org.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   134
.. not possible. Please add if someone comes up with any]