Skip to content

Instantly share code, notes, and snippets.

@WomB0ComB0
Created December 21, 2024 06:12
Show Gist options
  • Save WomB0ComB0/36574ed9f1ceb0ca9be58c22e58a1469 to your computer and use it in GitHub Desktop.
Save WomB0ComB0/36574ed9f1ceb0ca9be58c22e58a1469 to your computer and use it in GitHub Desktop.
From ```pip list``` within an Anaconda envmt. write to current ide/envmt.
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