Created
December 21, 2024 06:12
-
-
Save WomB0ComB0/36574ed9f1ceb0ca9be58c22e58a1469 to your computer and use it in GitHub Desktop.
From ```pip list``` within an Anaconda envmt. write to current ide/envmt.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import defaultdict | |
try: | |
book: defaultdict[str, str] = defaultdict(str) | |
with open("test.txt", "r", encoding="utf-8") as file: | |
for line in file: | |
if line.strip(): | |
parts = line.split() | |
if len(parts) >= 2: | |
book[parts[0]] = parts[1] | |
with open("requirements.txt", "w", encoding="utf-8") as file: | |
for key, value in book.items(): | |
file.writelines(f"{key}=={value}\n") | |
except (FileNotFoundError, FileExistsError) as fe: | |
print(format("Error: {}", fe)) | |
finally: | |
print("Done!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment