0

What is import os please using understandable language please thanks

I'm a computing gcse student

19th Nov 2016, 8:29 PM
abdi
3 ответов
+ 3
Here's an example: import os # add operating system support os.rename(source, destination) You don't need to know that Windows and Linux use different console commands; you just want Python to rename the file. and "os" is protecting you from stuff like this (in its docs): "The exact meaning...[of] attributes depend on the operating system and the file system. For example, on Windows systems using the FAT or FAT32..." When you just don't need to care.
19th Nov 2016, 10:21 PM
Kirk Schafer
Kirk Schafer - avatar
+ 1
import os to use system commands . if you ever used a Terminal to do some tasks, like cp - mv - ls - mkdir ... import os allows you to call those command in Python . it depends on what operating system you are using .
19th Nov 2016, 8:50 PM
Bahhaⵣ
Bahhaⵣ - avatar
+ 1
https://docs.python.org/3/library/os.html Summary: It makes essential operating system interaction (like opening a file) dead simple and you don't need to know where Python's running. Detail: Key concepts: Portable; that is: if it works "here", it works "there", without surprise differences. (Realistically, it's best effort; not everything in os is 100% portable). Abstraction. Regardless of how it's done 'behind the scenes', the part you work with stays the same. If you open a file for writing, you should not have to care that Windows, Linux, Android and OS X do it their way (or even why). You want a writable file, and Python gives you one...with one Python statement. Often called an "abstraction layer". If you want to know which operating system support "layer" Python loads when you "import os": >>> import os >>> os.name Posix # an Android device >>> os.name nt # Code Playground (this app) A disadvantage to abstraction is that the code can be slower than writing for the target operating system, but if you have that sort of concern you probably want to use something faster than an interpreter and "go native". Hence why Java is Android's "general, works everywhere, slow and reliable" language and Native Mode is for blazing fast games that crash... ...because the little 'operating system' details are important when 'abstracting away the differences' isn't holding your hand.
19th Nov 2016, 9:51 PM
Kirk Schafer
Kirk Schafer - avatar