You might want to convert a really long string in a single line into multiple lines with specified width. For example, if you have string like 12345678912345678912345678912345678912345678910 and want to split the long text to multi-line text, where each line is of length w, like w=9 123456789 123456789 123456789 123456789 123456789 10 In the above […]
Python
“with” statement in Python to Open a file
A common way to work with files in Python is to create file handler with “open” statement and work with the file. After finishing the work with the file, we need to close the file handler with close statement. For example, if we want to read all lines of a file using Python , we use […]
How to Run a Shell Command from Python and Get The Output?
In Python, often you may want to execute linux command and get the output of the command as string variable. There are multiple ways to execute shell command and get output using Python. A naive way to do that is to execeute the linux command, save the output in file and parse the file. Get […]
Eleven IPython Keyboard Shortcuts to Move Around Easily
Eleven IPython keyboard tips/shortcuts to Move Around Easily. Ctrl-p or up-arrow: Access command history in backward Ctrl-n or down-arrow: Access command history in forward Ctrl-a: Move cursor to beginning of line Ctrl-e: Move cursor to end of line Ctrl-f: Move cursor forward one character Ctrl-b: Move cursor back one character Ctrl-l: Clear screen Ctrl-r: reverse history […]
How To Paste Code in Python Interpreter? Hint: Use ipython
If you have formatted code block with proper indentation and want to test it by copying and pasting on a python interpreter, you will be frustrated at Python for complaining at you. iPython offers great solutions coding with Python and for copying and pasting the code on the terminal. One useful command in iPython to […]