Open In App

Open computer drives like C, D or E using Python

Last Updated : 29 Dec, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

Have you ever wondered that you can open your drives by just typing C, D or E and then that drives are open.This can be possible by using Python. So, for performing this task this we are using os.startfile() method of OS library. This Method start a file with its associated program.

Syntax: os.startfile(file_name)

Return: None.

Now let’s see the code:

Python3




# import library
import os
  
# take Input from the user 
query = input("Which drive you have to open ? C , D or E: \n")
  
# Check the condition for 
# opening the C drive
if "C" in query or "c" in query:
  os.startfile("C:")
    
# Check the condition for 
# opening the D drive
elif "D" in query or "d" in query:
  os.startfile("D:")
  
# Check the condition for 
# opening the D drive
elif "E" in query or "e" in query:
  os.startfile("E:")
  
else:
    print("Wrong Input")


Output:


Previous Article
Next Article

Similar Reads

How to open multiple files using "with open" in Python?
Python has various highly useful methods for working with file-like objects, like the with feature. But what if we need to open several files in this manner? You wouldn't exactly be "clean" if you had a number of nested open statements. In this article, we will demonstrate how to open multiple files in Python using the with open statement. What is
2 min read
Circular (Oval like) button using canvas in kivy (using .kv file)
Kivy is a platform independent GUI tool in Python. As it can be run on Android, IOS, linux and Windows etc. It is basically used to develop the Android application, but it does not mean that it can not be used on Desktops applications.In this article we will going to learn about how can we create a rounded or circular button in kivy using canvas. Y
3 min read
Like instagram pictures using Selenium | Python
In this article, we will learn how can we like all the pictures of a profile on Instagram without scrolling and manually clicking the buttons. We will be using Selenium to do this task. Packages/Software needed: 1. Python 3 2. Chromedriver compatible with the existing chrome version (download chromedriver) 3. Google chrome 4. Selenium package (pip
3 min read
Create and display a one-dimensional array-like object using Pandas in Python
Series() is a function present in the Pandas library that creates a one-dimensional array and can hold any type of objects or data in it. In this article, let us learn the syntax, create and display one-dimensional array-like object containing an array of data using Pandas library. pandas.Series() Syntax : pandas.Series(parameters) Parameters : dat
2 min read
Reading Python File-Like Objects from C | Python
Writing C extension code that consumes data from any Python file-like object (e.g., normal files, StringIO objects, etc.). read() method has to be repeatedly invoke to consume data on a file-like object and take steps to properly decode the resulting data. Given below is a C extension function that merely consumes all of the data on a file-like obj
3 min read
Integrating Facebook Like & Share Plugin Using Django
Django is a Python-based web framework that allows you to quickly create efficient web applications. It is also called batteries included framework because Django provides built-in features for everything including Django Admin Interface, default database – SQLlite3, etc. In this article we will learn to integrate facebook comment plugin in django.
2 min read
Python | Convert a list of lists into tree-like dict
Given a list of lists, write a Python program to convert the given list of lists into a tree-like dictionary. Examples: Input : [[1], [2, 1], [3, 1], [4, 2, 1], [5, 2, 1], [6, 3, 1], [7, 3, 1]] Output : {1: {2: {4: {}, 5: {}}, 3: {6: {}, 7: {}}}} Input : [['A'], ['B', 'A'], ['C', 'A'], ['D', 'C', 'A']] Output : {'A': {'C': {'D': {}}, 'B': {}}} Meth
4 min read
Python - Like Index Common characters
Sometimes we come across this type of problem in which we require to intersect each element of one list with the other. This type of problems usually occurs in developments in which we have the combined information, like names and surnames in different lists. Let’s discuss certain ways in which this task can be performed. Method #1 : Using list com
3 min read
Python - Row Summation of Like Index Product
Given a Matrix and elements list, For every row, extract the summation of product of elements with argument list. Input : test_list = [[4, 5], [1, 5], [8, 2]], mul_list = [5, 2, 3] Output : [30, 15, 44] Explanation : For 1st row, (4*5) + (5*2) = 30, as value of 1st element of result list. This way each element is computed. Input : test_list = [[4,
4 min read
Python - Multiplication across Like Keys Value list elements
Given two dictionaries with value lists, perform element wise like keys multiplication. Input : test_dict1 = {"Gfg" : [4, 6], "Best" : [8, 6], "is" : [9, 3]}, test_dict2 = {"Gfg": [8, 4], "Best" : [6, 3], "is" : [9, 8]} Output : {'Gfg': [32, 24], 'Best': [48, 18], 'is': [81, 24]} Explanation : 4 * 8 = 32, 6 * 4 = 24 and so on, hence new list value.
9 min read
three90RightbarBannerImg