More on the IPython System
50 questions available
Questions
Which keyboard shortcut in the IPython terminal is used to perform a readline-style reverse history search for commands based on partial matching?
View answer and explanationWhat is the primary function of the `%timeit` magic command in IPython?
View answer and explanationIn an IPython session, how can you execute a shell command, such as `ls`, and store its standard output into a Python variable named `file_list`?
View answer and explanationWhich magic command invokes the postmortem debugger in IPython right after an exception has occurred?
View answer and explanationWhat is the purpose of IPython's directory bookmark system, accessed via the `%bookmark` magic command?
View answer and explanationIn an IPython session, if you execute a command at line `In [27]`, what variable would you use to access the text of the *input* command itself?
View answer and explanationWhich magic command is used to execute a preformatted block of Python code from the clipboard in the IPython shell, using a special prompt for pasting?
View answer and explanationWhat is the effect of running a Python script with the `%run -i` option in IPython?
View answer and explanationAccording to the code design tips, why is it generally better to avoid putting all interactive-use code inside a `main()` function that is called via an `if __name__ == '__main__'` block?
View answer and explanationWhat is the function of IPython's special `dreload()` function for managing module dependencies?
View answer and explanationWhich terminal command is used to create the default IPython configuration file (`ipython_config.py`) if it does not already exist?
View answer and explanationWhen profiling an entire script from the command line using `cProfile`, what argument is recommended to sort the output by cumulative time spent in each function, making it easier to identify performance bottlenecks?
View answer and explanationWhat is the key difference between the `%prun` and `%lprun` magic commands for profiling code in IPython?
View answer and explanationWhen interrupting a running code block in IPython, pressing Ctrl-C raises a `KeyboardInterrupt`. In which scenario described in the text might this interruption not happen immediately?
View answer and explanationWhich magic command would you use to delete a variable named `my_large_df` and attempt to clear all references to its object from within IPython's internal machinery, which is useful for managing memory with large datasets?
View answer and explanationIn a profiling output from cProfile, a function call to `linalg.py:702(eigvals)` shows 100 calls, a `tottime` of 0.003, and a `cumtime` of 0.586. What does the `cumtime` represent?
View answer and explanationWhat is the result of using the `%pdb` magic command in IPython?
View answer and explanationHow do you substitute the value of a Python variable `foo` into a shell command executed from IPython?
View answer and explanationWhich command-line debugger command is used to execute the current line and advance to the next line at the current level, stepping *over* any function calls?
View answer and explanationWhat is the term for special commands in IPython that are prefixed by the percent symbol `%` and are designed to facilitate common tasks?
View answer and explanationIn the line profiler output, `%lprun -f add_and_sum add_and_sum(x, y)`, the line `added = x + y` took 36510 units of time, which was 79.5 percent of the total time. The line `summed = added.sum(axis=1)` took 9425 units. What percentage of the total time did the `summed` line take?
View answer and explanationWhich magic command displays detailed documentation for all available magic commands in IPython?
View answer and explanationWhat is the keyboard shortcut to clear the terminal screen in IPython?
View answer and explanationIn a Jupyter notebook, what is the function of the `%load` magic command?
View answer and explanationWhat does the `%reset` magic command do in an IPython session?
View answer and explanationWhen using the `%run -d` command to debug a script, what must you immediately type to step into the script's execution?
View answer and explanationWhat is the code design principle, mentioned as part of the Zen of Python, that is recommended for developing code for interactive use to make it easier to test and debug?
View answer and explanationWhich terminal command generates a default configuration file for a Jupyter notebook?
View answer and explanationWhat is the purpose of the `-b` flag when using the `%run` command with the debugger, for example `%run -d -b2 script.py`?
View answer and explanationIn a timing comparison, `%timeit x.startswith(y)` ran 1,000,000 loops with a best time of 267 ns per loop. In contrast, `%timeit x[:3] == y` ran 10,000,000 loops with a best time of 147 ns per loop. How much faster is one loop of the slicing comparison (`x[:3] == y`) than one loop of the `startswith` method?
View answer and explanationWhich magic command is part of the `line_profiler` extension and is used for 'micro' profiling of individual functions line-by-line?
View answer and explanationWhat is the function of the `%alias` magic command in IPython?
View answer and explanationWhen you use a magic function like `%pwd` and assign its result to a variable (`foo = %pwd`), what happens?
View answer and explanationWhich magic command would you use to print the command input history of your IPython session?
View answer and explanationWhat is the primary difference in behavior between IPython directory bookmarks (created with `%bookmark`) and command aliases (created with `%alias`) regarding session persistence?
View answer and explanationWhen examining a variable `a` in the IPython debugger, why might you need to type `!a` instead of just `a`?
View answer and explanationWhich magic command is described as useful for getting a quick answer to the question, 'Why did that code block take so long to run?' in a Jupyter notebook by profiling an entire cell?
View answer and explanationAccording to the code design tips, what is a potential downside of working with many small, interconnected files compared to fewer, longer files during interactive development with IPython?
View answer and explanationHow can you launch IPython with a specific, non-default profile named 'secret_project'?
View answer and explanationIn the IPython debugger, what is the function of the `l(ist)` command?
View answer and explanationWhich magic command displays a list of variables defined in the interactive namespace, with varying levels of information and verbosity?
View answer and explanationWhat is the function of the semicolon (;) in an IPython input line?
View answer and explanationWhich keyboard shortcut in the IPython terminal deletes text from the cursor until the end of the line?
View answer and explanationWhy might you need to load the `line_profiler` extension using `%load_ext line_profiler`?
View answer and explanationIn the debugger, what is the function of the `w(here)` command?
View answer and explanationWhat is the key reason provided for why tracing the execution time of each line with `%lprun` can significantly alter profile results if used on functions that are not of interest?
View answer and explanationWhich magic command would you use to change the current working directory to a path stored in a bookmark named `py4da`?
View answer and explanationWhat is the purpose of the `automagic` feature in IPython?
View answer and explanationWhen you start IPython normally, without specifying a profile, which profile is loaded by default?
View answer and explanationIn a comparison of two methods for selecting strings, method1 took 52.1 ms (Wall time) and method2 took 64.8 ms (Wall time). Which magic command was used to get these single-run execution times?
View answer and explanation