Python Tutorial: OS Module – Use Underlying Operating System Functionality

///Python Tutorial: OS Module – Use Underlying Operating System Functionality

Python Tutorial: OS Module – Use Underlying Operating System Functionality

FavoriteLoadingAdd to favorites

In this Python Tutorial, we will be going over the ‘os’ module. The os module allows us to access functionality of the underlying operating system. So we can perform tasks such as: navigate the file system, obtain file information, rename files, search directory trees, fetch environment variables, and many other operations. We will cover a lot of what the os module has to offer in this tutorial, so let’s get started.

If you enjoy these videos and would like to support my channel, I would greatly appreciate any assistance through my Patreon account:

Or a one-time contribution through PayPal:

If you would like to see additional ways in which you can support the channel, you can check out my support page:

You can find me on:
My website –
Facebook –
Twitter –
Google Plus –
Tumblr –

By |2017-05-01T12:19:42+00:00April 27th, 2017|Programming Video Tutorials, Python Video Tutorials|32 Comments


  1. Project -iFi- April 27, 2017 at 12:52 am - Reply

    LoL if you followed the video and u still can’t figure out y it’s not working… check what version of Python ur using by opening a shell and typing: Python -V

  2. Dilip Warrier April 27, 2017 at 12:54 am - Reply

    Thank you, Sir. Your videos are extremely helpful.

  3. xu zeyuan April 27, 2017 at 12:54 am - Reply

    does this OS module function similar with system calls in C library? Do the instruction of this python library has a higher privilege than normal user mode instructions?

  4. Otto Fazzl April 27, 2017 at 12:54 am - Reply

    I wonder who put a dislike to this video…

  5. Thomas Sitter April 27, 2017 at 12:55 am - Reply

    os.path.join accepts any number of arguments so you can join multiple paths:

    os.path.join(homedir, ‘subdir’, ‘test.txt’)

  6. Rick Cable April 27, 2017 at 12:55 am - Reply

    Thank you!

  7. Jorrit787 April 27, 2017 at 12:56 am - Reply

    Very helpful video, thank you!

  8. Ivandro Ismael April 27, 2017 at 1:02 am - Reply

    thank you 🙂

  9. sabiq al hasby April 27, 2017 at 1:04 am - Reply

    ——>> os.environ.get(‘HOME’)
    i dont get it, i cant use this function. the result is None.

  10. Matias Daneri April 27, 2017 at 1:04 am - Reply

    Amazing the simplicity of python :O

  11. J Warsame April 27, 2017 at 1:07 am - Reply

    Thank you Corey Schafer you’re the best teacher for pyhton

  12. JESÚS VLADIMIR SACCSA CÁCEDA April 27, 2017 at 1:09 am - Reply

    How can I open a file like a document, excel or powerpoint to edit it?
    for example: I need to open a CSV file in case the user wants to edit it before use.

  13. Veeresh Aradhya April 27, 2017 at 1:09 am - Reply

    please make one tutorial for sys module as well… 🙂

  14. Sean Hogan April 27, 2017 at 1:12 am - Reply

    You are an excellent presenter. The details were very  well explained. I learned a lot. Thank you

  15. Jellyman142 April 27, 2017 at 1:13 am - Reply

    When you write a ”print (dir (os))” so show me the options at the bottom and do not know if I have a well-adjusted Sublime Text 3?

  16. Sunny Sharma April 27, 2017 at 1:14 am - Reply

    Hey Corey, Do you have any tutorial for sys module…Thanks

  17. Peter Trouwers April 27, 2017 at 1:15 am - Reply

    Great video,
    I was wondering, how can i find the last created file in a directory?

  18. taha sabushanab April 27, 2017 at 1:16 am - Reply

    How do you run your script in sublime text?

  19. Matthew Prescod April 27, 2017 at 1:17 am - Reply

    An informative and helpful video, thank you!

  20. soul strategy April 27, 2017 at 1:24 am - Reply

    thanks for this video, clear and helpful and I learnt some new stuff. Please keep on releasing more!

  21. Mark Wilson April 27, 2017 at 1:30 am - Reply

    This is sort of a related topic with importing (my personal library is called "common" or more specifically "". On my particular computer I had to include the sys.path.insert(0, ‘j:\blender library\scripts\common\’) so that my other *.py scripts would recognise

    The real line of interest is reloading a module needs to be reloaded to obtain the lastest changes (without having to restart python).

    #import bmesh
    #import bpy
    import os
    import sys
    import importlib

    # clear the system.console

    # make the default directory where my current script is running….
    os.chdir("j:\blender library\scripts\")

    # add the common directory so my modules can be found when called
    import sys
    sys.path.insert(0, ‘j:\blender library\scripts\common\’)

    # line(s) of interest – import my common module that I reuse over and over again
    import common
    # reload itself … so any recent changes will be included (without having to restart python).
    common = importlib.reload(common)

  22. Ahmed Aldarmaki April 27, 2017 at 1:31 am - Reply

    boss  I’m beginner in python from where get all function

  23. Ashish Kulkarni April 27, 2017 at 1:33 am - Reply

    Am I the only one who thinks his voice sounds like Leonard in the Big Bang Theory

  24. Nitesh Vaidyanath April 27, 2017 at 1:34 am - Reply

    Thank you for sharing video Corey. Can i know which python interpreter you are using?

  25. Akshay Kg April 27, 2017 at 1:37 am - Reply

    how can i open an exe file and feed some input to that opened application and get the output out of it ?? is it able to do in os module ??

  26. Antony Belkovich April 27, 2017 at 1:42 am - Reply

    Corey , thank YOU at the highest degree !

  27. Jellyman142 April 27, 2017 at 1:42 am - Reply

    What program script

  28. Sulfen April 27, 2017 at 1:46 am - Reply

    What IDE is this?

  29. Lachlan McLeod April 27, 2017 at 1:48 am - Reply
  30. Digant Goradia April 27, 2017 at 1:48 am - Reply

    Hi There,
    I’m trying to move from E:/…/… dir to C:/…/… dir in windows using os.chdir() function , but it gives error.. How to do that??

  31. Venkat Danda April 27, 2017 at 1:50 am - Reply

    how can i find the latest creation of file

  32. Digwijoy Mandal April 27, 2017 at 1:50 am - Reply

    I am trying the below :
    print(os.path.splitext(‘G:Titanic Machine learningpoka.txt’))
    The output is :
    (‘G:\Titanic Machine learning\poka’, ‘.txt’)

    I am not sure why the ‘\’ is coming. I am expecting a single ”.
    Any help would be much appreciated.

Leave A Comment