Enhanced Python scripting techniques and file handling

  • Day: 2023-01-20
  • Time: 16:50 to 18:10
  • Project: Dev
  • Workspace: WP 2: Operational
  • Status: Completed
  • Priority: MEDIUM
  • Assignee: Matías Nehuen Iglesias
  • Tags: Python, File Handling, Ipython, Automation, Data Processing

Description

Session Goal

The session aimed to explore and enhance Python scripting techniques, focusing on file handling, loop optimization, and code organization.

Key Activities

  • File Listing with glob.glob(): Demonstrated how to list files in Python using the glob.glob() function, applicable to both current and specified directories.
  • Loop Automation: Showcased the use of for loops for executing yearly commands, employing both fixed lists and range-based approaches.
  • Directory Management: Discussed best practices for managing working directories in loops, advocating for setting the directory once before the loop.
  • Year Extraction: Provided methods for extracting years from filenames using regular expressions and string slicing.
  • DataFrame Export: Illustrated saving pandas DataFrames to CSV with file path and size reporting, using the humanize library for size formatting.
  • Variable Management in IPython: Explained defining and importing variables from external Python files into IPython notebooks to enhance code organization.

Achievements

  • Clarified the use of glob.glob() for file listing and for loops for automation.
  • Established best practices for directory management in scripts.
  • Enhanced understanding of file size formatting with humanize.
  • Improved code organization through external variable management in IPython.

Pending Tasks

  • Further exploration of advanced file handling techniques and optimizations in Python scripting.
  • Investigate additional libraries for enhancing file operations and data processing efficiency.

Evidence

  • source_file=2023-01-20.sessions.jsonl, line_number=0, event_count=0, session_id=846013df845a59a4a6fa4ae6f14a84a3c0b47b7766e01a622d8df9608e50167a
  • event_ids: []