-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinstalled.py
27 lines (22 loc) · 1.22 KB
/
installed.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import os
# To get list of all the installed libraries and write the list to a text file
def get_installed():
os.system("pip freeze > installed.txt")
# Return a list from the text file generated by the previous function
def clean():
installed_libraries = []
with open('installed.txt', 'r') as f: # Reading the data from text file
data = f.read()
for item in data.strip().split("\n"): # Stripping the data by new line
installed_libraries.append(item.split("==")[0]) # Selecting only the name of the package and discarding the version number installed
return installed_libraries
# Improvising the above function
# Return a list from the text file generated by the previous function
def clean_version():
installed_libraries = []
with open('installed.txt', 'r') as f: # Reading the data from text file
data = f.read()
for item in data.strip().split("\n"): # Stripping the data by new line
installed_libraries.append(item.split("==")) # Selecting only the name of the package and the version number installed in a list ["Package name","Package version"]
# installed_libraries.append({item.split("==")[0], item.split("==")[1]})
return installed_libraries