Python Tutorial: OS Module - Use Underlying Operating System Functionality

Поделиться
HTML-код
  • Опубликовано: 5 апр 2016
  • 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.
    ✅ Support My Channel Through Patreon:
    / coreyms
    ✅ Become a Channel Member:
    / @coreyms
    ✅ One-Time Contribution Through PayPal:
    goo.gl/649HFY
    ✅ Cryptocurrency Donations:
    Bitcoin Wallet - 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3
    Ethereum Wallet - 0x151649418616068fB46C3598083817101d3bCD33
    Litecoin Wallet - MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot
    ✅ Corey's Public Amazon Wishlist
    a.co/inIyro1
    ✅ Equipment I Use and Books I Recommend:
    www.amazon.com/shop/coreyschafer
    ▶️ You Can Find Me On:
    My Website - coreyms.com/
    My Second Channel - / coreymschafer
    Facebook - / coreymschafer
    Twitter - / coreymschafer
    Instagram - / coreymschafer
    #Python

Комментарии • 628

  • @shreyaschavhan5522
    @shreyaschavhan5522 Год назад +180

    + 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 года назад +136

    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

  • @chuanliangjiang7390
    @chuanliangjiang7390 6 лет назад +438

    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 5 лет назад +112

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

    • @greenballscience9514
      @greenballscience9514 5 лет назад +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”)

    • @Nurtastube
      @Nurtastube 5 лет назад +2

      @@Pr0G4m3R4u 😂😂😂

    • @grad6grade
      @grad6grade 4 года назад +8

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

    • @oberyn.freezingmoon
      @oberyn.freezingmoon 4 года назад +2

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

  • @codaadoc5302
    @codaadoc5302 6 лет назад +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.

  • @jordangillard2637
    @jordangillard2637 6 лет назад +53

    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 5 лет назад +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.

  • @salkdjfasldkfjsdlk
    @salkdjfasldkfjsdlk 6 лет назад +8

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

  • @sameerspl
    @sameerspl 6 лет назад +1

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

  • @bactran7799
    @bactran7799 2 года назад +15

    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 2 года назад +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 :)

    • @doodahgurlie
      @doodahgurlie Год назад

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

  • @turboromy
    @turboromy 6 лет назад +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.

  • @manuelch4589
    @manuelch4589 3 года назад +1

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

  • @soumyazyx
    @soumyazyx 4 года назад +3

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

  • @seanhogan317
    @seanhogan317 8 лет назад +1

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

  • @HW-ct1iq
    @HW-ct1iq 6 лет назад

    Super good whistlestop tour. Just what I needed.

  • @MattWatsonHarmonica
    @MattWatsonHarmonica Год назад

    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!

  • @khaled-dz8357
    @khaled-dz8357 6 дней назад +1

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

  • @antonybelkovich7012
    @antonybelkovich7012 7 лет назад +4

    Corey , thank YOU at the highest degree !

  • @veeresharadhya1430
    @veeresharadhya1430 7 лет назад +223

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

  • @sahajjaiswal1074
    @sahajjaiswal1074 5 лет назад +5

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

  • @GihanJayaneththie
    @GihanJayaneththie 3 года назад

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

  • @jwarsame9661
    @jwarsame9661 7 лет назад +1

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

  • @klamentyne5991
    @klamentyne5991 3 года назад +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!

  • @nameless191
    @nameless191 4 года назад +1

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

  • @sreedharIITR
    @sreedharIITR 7 лет назад +314

    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 6 лет назад +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 6 лет назад +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 6 лет назад +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 6 лет назад

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

    • @MagnusAnand
      @MagnusAnand 5 лет назад

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

  • @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'))

  • @user-qn5by5iv7u
    @user-qn5by5iv7u 2 года назад +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 👍

  • @edchelstephens
    @edchelstephens 2 года назад +1

    Another excellent tutorial! 💯
    Thanks a lot Corey 🙏

  • @yomajo
    @yomajo 4 года назад +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 2 месяца назад

      hey are you programmer now?

    • @yomajo
      @yomajo 2 месяца назад

      @@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.

  • @jignareshamwala3401
    @jignareshamwala3401 7 лет назад +1

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

  • @gregoryfenn1462
    @gregoryfenn1462 6 лет назад +1

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

  • @luisrosales3058
    @luisrosales3058 5 лет назад

    Great tutorial. Simple and straight.

  • @mansimandlik9013
    @mansimandlik9013 4 года назад +1

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

  • @vladn.2332
    @vladn.2332 6 лет назад

    Thank you for the clear and concise explanation!

  • @sacredinclinations
    @sacredinclinations 8 лет назад

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

  • @ravialwayswins
    @ravialwayswins 6 лет назад

    Really really good stuff Corey!

  • @heshankumarasinghe3159
    @heshankumarasinghe3159 3 года назад

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

  • @samhhhhh
    @samhhhhh Год назад +1

    Excellent explanations and examples, thank you!

  • @justgivemethetruth
    @justgivemethetruth 7 лет назад +3

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

  • @kelvinmacharia3715
    @kelvinmacharia3715 5 лет назад +1

    This a very good tutorial.Thank you Corey

  • @zacharysimpson4025
    @zacharysimpson4025 5 лет назад +6

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

  • @cibelless510
    @cibelless510 4 года назад

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

  • @suryakantmishra6866
    @suryakantmishra6866 6 лет назад +1

    simply awesome.. thanks Corey :)

  • @ABMA79
    @ABMA79 3 года назад

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

  • @geetavishwakarma4883
    @geetavishwakarma4883 2 года назад

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

  • @erfantaghvaei3952
    @erfantaghvaei3952 3 года назад +1

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

  • @meowmeow70
    @meowmeow70 3 года назад

    Thank you Corey. Truly appreciate what you share.

  • @shriramkaucyk7491
    @shriramkaucyk7491 5 лет назад +1

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

  • @MatiasEzelQ
    @MatiasEzelQ 7 лет назад +1

    Amazing the simplicity of python :O

  • @Samuftie
    @Samuftie 4 года назад +1

    very clear and precise. thank you.

  • @Tamer_Gomaa
    @Tamer_Gomaa 3 года назад

    Awesome 👍🏼.
    Great explanation

  • @shirzadroohi3000
    @shirzadroohi3000 3 года назад

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

  • @ranjitrajput9297
    @ranjitrajput9297 7 лет назад +1

    Very useful video.Thanks.

  • @carltechnologies2829
    @carltechnologies2829 3 года назад

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

  • @dilshadomar5078
    @dilshadomar5078 5 лет назад +1

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

  • @LeirbagIII
    @LeirbagIII 2 года назад

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

  • @nolevel433
    @nolevel433 2 года назад

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

  • @dilipwarrier5199
    @dilipwarrier5199 7 лет назад +4

    Thank you, Sir. Your videos are extremely helpful.

  • @maheshjadhav8118
    @maheshjadhav8118 6 лет назад +1

    Awesome tutorial!

  • @smnsdf
    @smnsdf 2 года назад

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

  • @juliankercsik5641
    @juliankercsik5641 4 года назад +1

    Thanks Corey bloody good show old chap!!!

  • @bharath695
    @bharath695 4 года назад

    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.

  • @usamashami11
    @usamashami11 2 года назад

    Amazing and insightful video!

  • @akira_asahi
    @akira_asahi Год назад

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

  • @hamedbakhti1752
    @hamedbakhti1752 3 года назад

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

  • @agu8559
    @agu8559 7 лет назад

    Super helpful! Thank you!

  • @shazkingdom1702
    @shazkingdom1702 5 лет назад +1

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

  • @farimankashani8627
    @farimankashani8627 3 года назад

    Thank you so much. It was super helpful

  • @Shlomojohn
    @Shlomojohn 3 года назад

    Really well explained thanks 👍🏻

  • @karimkazia
    @karimkazia 4 года назад

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

  • @heshankumarasinghe3159
    @heshankumarasinghe3159 3 года назад

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

  • @opiyosebastian50
    @opiyosebastian50 6 лет назад

    Thanks for the video, always the best!

  • @Akashdoifode
    @Akashdoifode 4 года назад +1

    Thanks a lot for this video. Really helpful

  • @JoyDavidson
    @JoyDavidson 10 месяцев назад +1

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

  • @divyasris9231
    @divyasris9231 4 года назад

    super super super. excellent teaching skills.

  • @sibanandanayak2633
    @sibanandanayak2633 6 лет назад

    gr8 tutorial..looking forward more videos..

  • @cOnT3ST
    @cOnT3ST 3 года назад

    Great vid! Very useful

  • @thmmerd
    @thmmerd 2 года назад

    Thank you. This was super cool.

  • @dhanasekaranrajendran3773
    @dhanasekaranrajendran3773 7 лет назад

    Good tutorial... Thanks Corey....

  • @Wewereneveryoung
    @Wewereneveryoung Год назад

    THANK YOU for this tutorial

  • @abdallah_eldesouky
    @abdallah_eldesouky Год назад

    very informative tutorial, thanks

  • @RoamingRebel
    @RoamingRebel 3 года назад +1

    Its very nice .Thank you

  • @cooleekova
    @cooleekova 2 года назад

    thank youuu! your tutorials are awesome!

  • @rajatpai5048
    @rajatpai5048 6 лет назад

    Informative and chic tutorial :)

  • @abhisheksharma-ib5vw
    @abhisheksharma-ib5vw 5 лет назад +2

    Incredible info

  • @ji-axinliu4448
    @ji-axinliu4448 2 года назад

    thank you Sir helped my work a lot

  • @mr.curious1714
    @mr.curious1714 2 года назад

    You are the greatest Python teacher

  • @sundareshbarana7860
    @sundareshbarana7860 6 лет назад +1

    Thank You Corey. Your videos are best one for python beginners.

  • @umakanths6902
    @umakanths6902 4 года назад

    Awesome tutorial Bro......

  • @barath961
    @barath961 3 года назад

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

  • @rafaelchaves6920
    @rafaelchaves6920 11 месяцев назад

    great video, thank you!!

  • @tav9755
    @tav9755 3 года назад

    Thanks for this very useful and well presented tut..

  • @shrutigupta8818
    @shrutigupta8818 7 лет назад

    Awesome video sir.

  • @majidgharibi7357
    @majidgharibi7357 6 лет назад

    very helpful, thank you so much

  • @radmirsultamuratov3049
    @radmirsultamuratov3049 2 года назад

    Bless you Corey!

  • @TheNBKiller
    @TheNBKiller 5 лет назад

    This will be very useful. Thsnks!

  • @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.

  • @nagarjunavallabhu.8552
    @nagarjunavallabhu.8552 5 лет назад +1

    Hi Corey Schafer,
    It was awesome pin to pin teaching. Thank you so much!!

  • @sowmyashetty533
    @sowmyashetty533 3 года назад +1

    Really helpful

  • @LeandroCursinofoto
    @LeandroCursinofoto 3 года назад

    Top, excelent tutorial!