As we all know, Operating System (OS) is a program that acts as an interface between computer hardware and user. Python has a standard utility module called "os module" to achieve a process of communicating directly to the operating system of your device.
The os module is one of the standard libraries in Python 3, so it doesn't need to be installed manually or externally. It comes along with the installation of Python. So it is mandatory to import this os module before using it in your program as it is not a built-in function.
Importing module
The os module can be used in a program by importing it initially. It is mandatory to import the os module as it is not a built-in function to use it without any importation.
To import the os module, use the command as
import os
Built-in functions inside os module
There are a bunch of built-in functions present inside the os module where one can invoke each function after the module gets imported inside a program.
To know about the list of built-in functions inside the os module, specify the code as
dir(os)
Here comes the list of built-in functions inside the os module,
To make the Operating System of your device interact with applications installed on your device, follow the syntax in command prompt as
os.system("application_name")
This os.system( ) function executes a command in a subshell, it has the same limitations as a system() in Standard C function as it implements the same. os.system( ) can be used only on Windows and Unix.
Code snippets to open system applications
Here are some python codes to open system applications on your device,
Notepad
To open notepad specify,
os.system("notepad")
This single line of code specified above will open the notepad immediately.
To open Google Chrome specify,
os.system("chrome")
This will open Google Chrome on your device
In the same way, to open File Explorer on your device specify,
os.system("explorer")
To open Microsoft Edge on your device, specify the code as
os.system("msedge")
Microsoft Edge gets launched |
Internet Explorer
To open Internet Explorer on your device, make sure to type your code as
os.system("iexplore")
Internet Explorer gets launched |
Windows Media Player
In the same way, try Windows media player to get opened by specifying,
os.system("wmplayer")
Windows Media Player gets launched |
Microsoft PowerPoint
To launch Microsoft PowerPoint use the command as
os.system("POWERPNT")
MS PowerPoint gets launched |
The application_name must be the same as specified in the location where it is installed.
For example, MS Word is specified as "WINWORD" inside C:\Program Files\Microsoft Office\Office14.
Thus use os.system("WINWORD") as a command in your program, so that MS Word will launch immediately. If the code doesn't work, then copy the path of the application where it is installed and change the environment variable of that application with the path copied.
Comments
Post a Comment