October 13th, 2013, 05:23 PM
Using Python as a Linux shell ?
Hi, I'm new to python.
I also tried to search the forum, but the search button did nothing when I clicked it.
I want to use Python as my shell, I cant find any commands like "ls" "cd"
How do you use Python as a default shell and have normal commands ?
October 13th, 2013, 11:49 PM
(Assuming python is installed on your system)
1. Launch a terminal and type "python".
2. This will not work if your environment path doesn't have path to python executable.
3. After you type python and hit enter, you can see the python shell's prompt (typically like this - ">>>")
4. And, to be able to use python shell to list files and change directory, you need to use the appropriate commands (since python is different from bash/ksh/csh/zsh, the commands too will be different)
5. Try this:
>>> import os
>>> # Equivalent of "pwd"
>>> # Equivalend of "cd"
>>> # Equivalent of "ls"
['file1', 'file2', 'file3']
October 14th, 2013, 07:34 AM
you could also use the subprocess module to run programs you have on your computers.