Python Tutorial: OS Module - Use Underlying Operating System Functionality

Поділитися
Вставка
  • Опубліковано 4 лют 2025

КОМЕНТАРІ • 638

  • @shreyaschavhan5522
    @shreyaschavhan5522 2 роки тому +236

    + os.getcwd() => get current working directory
    + os.chdir() => change directory
    + os.listdir() => list directory
    + os.mkdir() => create a directory
    + os.makedirs() => make directories recursively
    + os.rmdir() => remove directory
    + os.removedirs() => remove directory recursively
    + os.rename(, ) => rename file
    + os.stat() => print all info of a file
    + os.walk() => traverse directory recursively
    + os.environ => get environment variables
    + os.path.join(, ) => join path without worrying about /
    + os.path.basename() => get basename
    + os.path.dirname() => get dirname
    + os.path.exists() => check if the path exists or not
    + os.path.splitext() => split path and file extension
    + dir(os) => check what methods exists

  • @dev_soda8315
    @dev_soda8315 2 роки тому +164

    its so sad that this guy has not uploaded any content for over a year now... his tutorials are always the best, most methodically thought out pieces of work on the platform

  • @codaadoc5302
    @codaadoc5302 7 років тому +32

    A tutorial for the sys module would help tremendously. It's difficult to find someone like you who can explain things in such detail as well as show how useful certain things within python can be without half-assing it. Thanks, Corey.

  • @chuanliangjiang7390
    @chuanliangjiang7390 7 років тому +445

    It is very excellent tutorial, much better than some paid python tutorial vedios in Udemy
    for i in range(1,1000000):
    print('Thank you so much for sharing this wonderful tutorial')

    • @Pr0G4m3R4u
      @Pr0G4m3R4u 6 років тому +119

      while True:
      print('Thank you so much for sharing this wonderful tutorial')

    • @greenballscience9514
      @greenballscience9514 6 років тому +4

      (Python script is in c:/pyproj/thankyou.py)
      Import subsystem
      Subsystem.call([C://Python//Python.exe, C://pyproj//thankyou.py])
      while True:
      Print(“Thank You So Much”)

    • @grad6grade
      @grad6grade 5 років тому +8

      @@greenballscience9514 it should be like:
      import os
      os.system(''C://Python//Python.exe, C://pyproj//thankyou.py")

    • @oberyn.freezingmoon
      @oberyn.freezingmoon 5 років тому +2

      Error, wait for script to finish..
      .. CTRL+C
      >>> python Greenball_Science.py
      now you were saying?

    • @NobleSteed00
      @NobleSteed00 4 роки тому

      couldn't squeeze one more "thank you", could you?

  • @bactran7799
    @bactran7799 3 роки тому +16

    every time I need a tutorial video for Python, Corey is always the best one with really well organized, fully information and easily to remember. Thanks a lot Corey

    • @codingisthebest3914
      @codingisthebest3914 3 роки тому +1

      Your grammar is wrong, the quote should be, "Every time I need a tutorial video for Python, Corey is always the best one with really well organized, full information and easy to remember. Thanks a lot Corey."

    • @einekleineente1
      @einekleineente1 2 роки тому +1

      @@codingisthebest3914 Ich würde mal sagen,dass du ein Klugscheißer bist :)

    • @datgal2u
      @datgal2u 2 роки тому

      @@codingisthebest3914 Based on his name, he's not American, so it's fine. I agree with what oneLittleDuck wrote in German. LOL

  • @khaled-dz8357
    @khaled-dz8357 7 місяців тому +4

    The best one i have ever seen in teaching coding . Thank you so much man

  • @jordangillard2637
    @jordangillard2637 7 років тому +54

    Bless your soul Corey! The os module has always been such a pain to learn. When you first see it in code it's so cryptic. Thanks for breaking it down for us!

  • @knownwolf
    @knownwolf 6 років тому +27

    These Python videos are extremely helpful, thank you. I would be grateful if you added chapters. Some of the 10 minute plus videos have a lot of concepts and it would be great to jump back into a specific section when in need of a refresher. Keep up the excellent work and stay Pythonic my friend.

  • @АлексейСоков-ь8и
    @АлексейСоков-ь8и 3 роки тому +1

    It is so demonstrating that you can hardly find any questions in the comments - there are only thanks and insparations 😏 The explanation is so clear that it leaves nothing to ask about 💎 Great job 👍

  • @yomajo
    @yomajo 5 років тому +6

    I never read your descriptions, but after seeing what's on your amazons' wish list, I can tell, you aint no ordinary tutor. Respect. Sharp, evolving mind.

    • @engr.mubasharhanif
      @engr.mubasharhanif 10 місяців тому

      hey are you programmer now?

    • @yomajo
      @yomajo 10 місяців тому

      @@engr.mubasharhanif Hey. still and will continue to hold myself newbie, but I do have production web app running that I charge the client for.

  • @salkdjfasldkfjsdlk
    @salkdjfasldkfjsdlk 7 років тому +8

    You are very good at explaining Python modules and their practical uses.

  • @GihanJayaneththie
    @GihanJayaneththie 4 роки тому

    Simple, well organized, great for beginners and informative. Nothing but least speaks English doesn't try to showoff.

  • @sahajjaiswal1074
    @sahajjaiswal1074 6 років тому +5

    you are much better than my faculty handling python course....

  • @turboromy
    @turboromy 7 років тому +2

    I was surprised how quick that search was wth os.walk().... and at the same time, wondered why Windows "Find" takes so long. Thanks for the great teachings.

  • @sreedharIITR
    @sreedharIITR 7 років тому +318

    For windows users, print (os.environ.get("HOME")) won't work as there is no HOME folder, instead it is USERPROFILE. So, type USERPROFILE instead of HOME.

    • @murakumo222
      @murakumo222 7 років тому +2

      THANKS A LOT!!! i just can't get it work until i saw this comment. but why i can't get it to search other folders? am i only able to search within the same tree?

    • @kostasnikoloutsos5172
      @kostasnikoloutsos5172 7 років тому +4

      Thank you. Now I made this who gives you the desktop path.Pretty useful if you want to create something in the desktop.
      os.path.join(os.environ.get("USERPROFILE"), "Desktop")

    • @AnthonyMute
      @AnthonyMute 7 років тому +1

      @murakumo222 I don't know if you finally did it but assuming you are referring to os.walk() you could do the os.walk('C:\\Users') replacing the string with whatever directory you want the tree on.

    • @cjz5757
      @cjz5757 7 років тому

      Sukant Arora os.environ.get('HOME') works just fine for me

    • @MagnusAnand
      @MagnusAnand 6 років тому

      os.environ.get("HOME") worked fine for me in Windows 10

  • @MattWatsonHarmonica
    @MattWatsonHarmonica 2 роки тому

    Thank you! I've been using the os module for years and had no idea about os.walk()! Will be putting this to good use!

  • @sujithnair232
    @sujithnair232 4 роки тому +7

    for Windows users I used HOMEPATH instead of Home , use SET Command to be able to see all environment variables on CMD
    print(os.environ.get('HOMEPATH'))

  • @NicolasChanCSY
    @NicolasChanCSY 4 роки тому +3

    For anyone who needs to work with paths and don't want to deal with the forward/backward slashes difference between Linux, Windows, and MacOS, you can consider or at least take a look at the module `Pathlib`. It is simpler and easier to manipulate in my opinion.
    My favourite part of the module is its slash operator, e.g. taken from the documentation
    ```python
    >>> p = PurePath('/etc')
    >>> p
    PurePosixPath('/etc')
    >>> p / 'init.d' / 'apache2'
    PurePosixPath('/etc/init.d/apache2')
    ```
    Thus, you are free from the long `os.path.join()` method call introduced in 14:05 and make things cleaner and more readable.

  • @zacharysimpson4025
    @zacharysimpson4025 6 років тому +6

    I've been learning python for several months now, and not once did i ever see anything about print(dir())! Like given!

  • @JoyDavidson
    @JoyDavidson Рік тому +1

    Corey, I hope you are well today. 🤙🤙 I have been sober for one year. We got this.

  • @erfantaghvaei3952
    @erfantaghvaei3952 3 роки тому +1

    I love Corey's teaching ... and accent!

  • @sameerspl
    @sameerspl 7 років тому +1

    Thanks Corey. I have started following you.. You make things so simple when it comes to using necessary commands in python.

  • @mubashirmuhib8339
    @mubashirmuhib8339 3 роки тому +16

    From 00:02
    The Os Module
    From 00:06
    Os Module
    From 00:27
    Import the Os Module
    From 01:31
    Navigate to a New Location on the Filesystem
    From 04:32
    Leading Folders
    From 05:27
    Rename a File or a Folder
    From 10:09
    Walk Method
    From 14:04
    Os Path Join
    From 15:49
    Os Path Base Name
    From 17:31
    Split Ext

  • @manuelch4589
    @manuelch4589 3 роки тому +1

    Excellent! I really appreciate you sharing so much knowledge at no cost. I am getting it slowly. Thank you

  • @seanhogan317
    @seanhogan317 8 років тому +1

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

  • @Setssquare
    @Setssquare 2 роки тому

    Thanks a lot i started my cyber security journey yesterday , I was advised to learn this module thanks!!!!

  • @soumyazyx
    @soumyazyx 5 років тому +1

    I am a huge fan of yours .. like countless others. I have been telling about this python playlist to each and everyone of my colleagues who are interested in python. I also emphasize that wander nowhere else. This is the place to be.
    On a side, How do you feel Corey to read such overflowing wonderful comments on you and your work? Would really like to know :)

    • @coreyms
      @coreyms  5 років тому +1

      I'm extremely grateful for all of the kind comments. I love reading comments from you all each morning.

  • @veeresharadhya1430
    @veeresharadhya1430 8 років тому +224

    please make one tutorial for sys module as well... :-)

    • @ivandrofly
      @ivandrofly 7 років тому +4

      yeah thumbs up!

    • @Ryu23-x5
      @Ryu23-x5 7 років тому +5

      Yeah Corey! one for the sys module please! :)

    • @davidreynolds9649
      @davidreynolds9649 7 років тому +11

      and subprocess ;-)

    • @RaviTejaKalidindi
      @RaviTejaKalidindi 6 років тому +1

      and pdb debugger as well if possible :)

    • @beaconbecay1648
      @beaconbecay1648 5 років тому +2

      Veeresh Aradhya yes please. Been struggling with stdin and stdout

  • @MrKungfu218
    @MrKungfu218 4 роки тому +1

    This was a very good video lesson for me as a beginner. I signed up for a Udemy class but found the content on OS Module functionality left me with some questions. I will definitely be using your videos as a resource1

    • @abeburdock7791
      @abeburdock7791 4 роки тому

      Which Udemy python class are you taking? I plan on taking a Udemy class for Python to supplement what I learn from Corey's channel. Thanks.

  • @nameless191
    @nameless191 4 роки тому +1

    Great tutorial straight to point teaching the stuff that actually creates complex programs in a simple way is great

  • @jwarsame9661
    @jwarsame9661 8 років тому +1

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

  • @ABMA79
    @ABMA79 4 роки тому

    wonderful explanation.... Thanks a lot for making it more clear brother.
    you should honestly be a teacher.

  • @mansimandlik9013
    @mansimandlik9013 5 років тому +1

    You teach in a interesting way sir ,Thanks Today i have learned all things i was trying to learn from many days

  • @chaitanyayeturi1312
    @chaitanyayeturi1312 3 роки тому +2

    First of all, your teaching style is good, and anyone grabs ur teachings easily, and thanks for teaching us. you are the best tutor I have ever come up with in python language. can u suggest any python language book, which is best to go through other than your channel? Moreover, I am a beginner to python language I thoroughly enjoyed ur videos, if u can suggest me best python book to ur sensibility and I guess it suits me and it helps me to learn further (I like physical like books). In case if u written any books related to this language can u suggest one (or) your favorite book, please......................................

  • @kshitijkumar326
    @kshitijkumar326 7 років тому +4

    This is an important suggestion for tutorials. Use Jupyter notebooks for tutorials. You won't have to erase your codes and output is line by line which is really easy to understand.

    • @coreyms
      @coreyms  7 років тому +9

      I enjoy using Jupyter notebooks and have a video on how others can begin using them, but I have found that for tutorials it is best to stick with simple editors that beginners are more familiar with. They may become confused when their code with a notebook doesn't run top-to-bottom like a typical script. Thank you for the suggestion though. I will think more about it.

    • @rishabh.bharat
      @rishabh.bharat 4 роки тому

      @@coreyms exactly right sir Corey Scafer, you always think about your community....that's the real quality of a classic teacher :)
      ..also in Jupyter nb you may have to restart kernel or delete that cells to wash off unwanted variables from your code snippet..so I too think Sublime is best option from a learners point of view

  • @mr.curious1714
    @mr.curious1714 3 роки тому

    You are the greatest Python teacher

  • @soumyazyx
    @soumyazyx 5 років тому +3

    Thank you Corey for your time and effort. Keep spreading the knowledge.

  • @misty_jeera
    @misty_jeera 3 роки тому +3

    Tip : if you are in windows, always use // instead of / while defining path names, otherwise you get errors apparently : )
    Eg: os.chdir("C://Users//Desktop//text.txt")

    • @dostonbektoirov7110
      @dostonbektoirov7110 3 роки тому

      Also, you can use r'C:/Users/Desktop/..' to make Python treat it as a raw string.

  • @HW-ct1iq
    @HW-ct1iq 7 років тому

    Super good whistlestop tour. Just what I needed.

  • @klamentyne5991
    @klamentyne5991 4 роки тому +1

    Extremely useful and explained so well...thanks Corey!

  • @jackieinspace
    @jackieinspace 6 років тому +1

    Very nice! Tight and down to the core of what is needed!

  • @kom_senapati
    @kom_senapati Рік тому +1

    Yo this is included in summer analytics 2023 curriculum 👌

  • @akira_asahi
    @akira_asahi 2 роки тому

    Thank you for the video. I am grateful for your time and contribution. Kind regards, Akira.

  • @cibelless510
    @cibelless510 5 років тому

    OMG, you are really good! Very clear voice and excellent explanation. Thanks for share.

  • @heshankumarasinghe3159
    @heshankumarasinghe3159 4 роки тому

    An excellent tutorial. Learnt new stuff and this video helped me clear some doubts. Thanks a lot!!!

  • @shirzadroohi3000
    @shirzadroohi3000 4 роки тому

    Thanks, it was very useful for me as a python beginner.

  • @edchelstephens
    @edchelstephens 2 роки тому +1

    Another excellent tutorial! 💯
    Thanks a lot Corey 🙏

  • @justgivemethetruth
    @justgivemethetruth 7 років тому +3

    Good, useful. Lots of stuff in the os module, that is for sure.

  • @LeirbagIII
    @LeirbagIII 3 роки тому

    This si pretty interesting, Corey!! Thanks a lot for your help!

  • @samhhhhh
    @samhhhhh 2 роки тому +1

    Excellent explanations and examples, thank you!

  • @carltechnologies2829
    @carltechnologies2829 4 роки тому

    What a very helpful tutorial, I owe you more than a subscription

  • @Imran20091990
    @Imran20091990 2 роки тому

    Don't know what to say.. excellent 👌👌👌👌

  • @divyasris9231
    @divyasris9231 4 роки тому

    super super super. excellent teaching skills.

  • @Akashdoifode
    @Akashdoifode 4 роки тому +1

    Thanks a lot for this video. Really helpful

  • @juliankercsik5641
    @juliankercsik5641 4 роки тому +1

    Thanks Corey bloody good show old chap!!!

  • @learnpy2583
    @learnpy2583 Рік тому

    this guy is so clear,

  • @Tamer_Gomaa
    @Tamer_Gomaa 4 роки тому

    Awesome 👍🏼.
    Great explanation

  • @bharath695
    @bharath695 5 років тому

    I love this video tutorial just like many :-). As a systems admin, I would like to learn more about the os module. If possible you can make an advanced tutorial on this.

  • @geetavishwakarma4883
    @geetavishwakarma4883 3 роки тому

    Very informative and helpful. And also very well explained. Thank you

  • @ArunKumar-qy6fm
    @ArunKumar-qy6fm 5 років тому +1

    Superb Corey. You are going beyond of our expectations. Keep it up.

  • @Samuftie
    @Samuftie 4 роки тому +1

    very clear and precise. thank you.

  • @antonybelkovich7012
    @antonybelkovich7012 7 років тому +4

    Corey , thank YOU at the highest degree !

  • @heshankumarasinghe3159
    @heshankumarasinghe3159 4 роки тому

    Thank you for the video..... Learnt new stuff from this.....

  • @sacredinclinations
    @sacredinclinations 8 років тому

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

  • @karimkazia
    @karimkazia 4 роки тому

    Thank you very very much for these videos. Learning a lot from your videos.

  • @gregoryfenn1462
    @gregoryfenn1462 7 років тому +1

    Very helpful guide to such an import module :) thanks!

  • @SandraWantsCoke
    @SandraWantsCoke 3 роки тому +1

    because windows uses \ backslash for directories, Python will think you're using escape characters, because that's what backslash is for.
    So, before the string put the letter r to indicate you're passing the raw string as it is.
    import os
    os.chdir(r'C:\Users\Adolf\Desktop')
    print(os.getcwd())

  • @ai.simplified..
    @ai.simplified.. 3 роки тому

    It,s 3rd min &i already loved it.

  • @luisrosales3058
    @luisrosales3058 5 років тому

    Great tutorial. Simple and straight.

  • @barath961
    @barath961 4 роки тому

    Please post one lecture on data structure and algorithm. Thanks for your fantastic work as always

  • @nolevel433
    @nolevel433 3 роки тому

    Thats so brilliantly explained. Thanks a lot !!!!

  • @dilshadomar5078
    @dilshadomar5078 6 років тому +1

    grate video am always around and always learning somthing new from the same video

  • @hamedbakhti1752
    @hamedbakhti1752 4 роки тому

    Thanks bro!!! its very helpful... Good luck

  • @prabhavrajeev9682
    @prabhavrajeev9682 4 роки тому +1

    Heres a summary of all the functions he introduced, Hope somefun finds it useful
    import os
    print(dir(os)) # list all methods associated with the module
    cwd = os.getcwd() # get current working directory
    print(cwd)
    os.chdir('path to change into')
    print(os.listdir()) # list everything in current directory
    os.mkdir('test-folder') # Make directory
    os.makedirs('lvl1/lvl2') # Make directory from folder structure
    os.rmdir('test-folder') # remove a single folder
    os.removedirs('lvl1/lvl2') # for removing recursively
    os.rename('org name','new name') # renaming a file
    os.stat('folder name') # returns an array of usual information
    os.walk('path') # traversing top down
    for dirpath, dirnames, filenames in os.walk('path'):
    pass
    os.environ.get('HOME') # get home env variable
    os.environ # get all environ variables
    file_path = os.path.join('path1','path2')
    os.path.basename('path') # gets filename from path
    os.path.dirname('path') # gets the directory name
    os.path.exists('path') # such a path exists
    os.path.isdir('path') # check if directory
    os.path.isfile('path') # check if file
    os.path.spiltext('path') # split extension from path for eg : (file_path without extension, file_extension)

  • @RoamingRebel
    @RoamingRebel 4 роки тому +1

    Its very nice .Thank you

  • @ramnageena88
    @ramnageena88 6 років тому +3

    this is my first comment in youtube I like this video good work

  • @meowmeow70
    @meowmeow70 4 роки тому

    Thank you Corey. Truly appreciate what you share.

  • @bhargavanaik9562
    @bhargavanaik9562 4 роки тому +1

    It's awesome tutorial sir..
    Can u make a video difference between os module, sub process module and sys module in python..

  • @shashik962
    @shashik962 5 років тому +4

    This is different to improve knowledge of OS.

  • @shazkingdom1702
    @shazkingdom1702 5 років тому +1

    now I understand this OS & good use case for file manipulation!
    THANK YOU COREY!

  • @shriramkaucyk7491
    @shriramkaucyk7491 6 років тому +1

    Awesome one to start with. Just a lot of things.

  • @ji-axinliu4448
    @ji-axinliu4448 3 роки тому

    thank you Sir helped my work a lot

  • @Shlomojohn
    @Shlomojohn 4 роки тому

    Really well explained thanks 👍🏻

  • @tav9755
    @tav9755 4 роки тому

    Thanks for this very useful and well presented tut..

  • @moha_linus
    @moha_linus 5 років тому +2

    i'dont speak english but i understand what do u doing
    ur the bes bro ,, all love

  • @manjsc
    @manjsc 5 років тому +2

    Really informative and very well explained. Thank you

  • @TheMarbo74
    @TheMarbo74 5 років тому +3

    Hi Corey,
    As usual, great video!
    Can you explain (or make a video :) on the difference between OS and Pathlib?
    Thanks

    • @clerpington_the_fifth
      @clerpington_the_fifth Рік тому

      Pathlib is definitely superior from what I've read - as far as the details, you will just have to search online. My source is the 3rd edition of Python crash Course, 3rd ed. by Matthes - I do not know if it is available online.

  • @paula98033
    @paula98033 6 років тому +1

    HI Corey, thank you for all the great videos. I disagree with you in regard to not having numbers for your videos! specially for people my niece who started learning python, it is great way of organizing her thought and building solid foundation of how to. PLEASE NUMBER YOUR VIDEOS.. SAVY USER THEY CAN SEARCH FOR THEIR TOPIC ACCORDIGLY. THANK YOU AGAIN FOR ALL YOUR HARD WORK. I WILL CONTRIBUTE $100.00 AS A ONE TIME CONTRIBUTION VIA MY CREDIT CARD.

    • @coreyms
      @coreyms  6 років тому

      Thanks for the suggestion and thanks for the contribution! It helps more than you know!

  • @vladn.2332
    @vladn.2332 7 років тому

    Thank you for the clear and concise explanation!

  • @abdallah_eldesouky
    @abdallah_eldesouky 2 роки тому

    very informative tutorial, thanks

  • @marialoar6923
    @marialoar6923 5 років тому +1

    Great tutorials, extremely helpful and easy to understand! Which Python Interpreter are you using for coding in python? This looks very quick and easy to show putput.

  • @MatiasEzelQ
    @MatiasEzelQ 8 років тому +1

    Amazing the simplicity of python :O

  • @kelvinmacharia3715
    @kelvinmacharia3715 6 років тому +1

    This a very good tutorial.Thank you Corey

  • @kostasnikoloutsos5172
    @kostasnikoloutsos5172 7 років тому

    You can use Regex instead of splittext method.

  • @hamedakbari2652
    @hamedakbari2652 6 років тому

    It was so good, Please also train the sys module

  • @cooleekova
    @cooleekova 2 роки тому

    thank youuu! your tutorials are awesome!

  • @jignareshamwala3401
    @jignareshamwala3401 7 років тому +1

    @Corey Schafer. Your tutorials are awesome! Thank you! :)

  • @smithocoro1140
    @smithocoro1140 4 роки тому

    Asombroso amigo eres asombroso como explicas, tiene un suscriptor

  • @adamhendry945
    @adamhendry945 4 роки тому +1

    Corey, can you do a video on pathlib?

  • @sophiahao8137
    @sophiahao8137 6 місяців тому

    Hello! I love the videos so much and the first few were very clear. However, I am coding using Replit, so is there a major difference?