January 2019
Beginner
318 pages
8h 23m
English
In this section, we will list all of the content of a directory using listdir(). Create a script called list_dir.py and write the following code in it:
import osimport sysprint(sorted(os.listdir(sys.argv[1])))
Run the script as follows:
$ python3 list_dir.py /home/student/['.ICEauthority', '.bash_history', '.bash_logout', '.bashrc', '.cache', '.config', '.gnupg', '.local', '.mozilla', '.pam_environment', '.profile', '.python_history', '.ssh', '.sudo_as_admin_successful', '.viminfo', '1.sh', '1.sh.x', '1.sh.x.c', 'Desktop', 'Documents', 'Downloads', 'Music', 'Pictures', 'Public', 'Templates', 'Videos', 'examples.desktop', 'execute_external_commands.py', 'log.txt', 'numbers.txt', 'python_learning', 'work'] ...
Read now
Unlock full access