Skip to content

Instantly share code, notes, and snippets.

@garybake
Created December 5, 2024 09:57
Show Gist options
  • Save garybake/f4831d2679634fb5b926f8e2a8689561 to your computer and use it in GitHub Desktop.
Save garybake/f4831d2679634fb5b926f8e2a8689561 to your computer and use it in GitHub Desktop.
Print project structure, for pasting into chatgpt
"""
When asking for help with chatgpt it's sometimes helpful to add
in your project structure for context.
"""
import os
ignore = ['venv', '.git', '.pytest_cache', '__pycache__']
def print_structure(root_dir, indent=""):
for item in os.listdir(root_dir):
if not item.endswith('.pyc') and item not in ignore:
item_path = os.path.join(root_dir, item)
print(f"{indent}{item}/" if os.path.isdir(item_path) else f"{indent}{item}")
if os.path.isdir(item_path):
if item not in ignore:
print_structure(item_path, indent + " ")
print_structure(".")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment