נבנה על ידיBuilt by Ariel Yohimovich

PythonPython
27
חלקPart 5: בונים דבריםBuilding things כ-3 שעות (כולל הפסקה)About 3 hours (with a break)

כלי שורת פקודה עם argparseCommand-line tools with argparse

ארגומנטים, תתי-פקודות, עזרה אוטומטית.

Arguments, sub-commands, automatic help.

בסוף המפגש תדעוBy the end you will

  • להריץ סקריפט עם ארגומנטים מהטרמינלRun a script with arguments from the terminal
  • להגדיר ארגומנטים עם argparse: חובה, אופציות ודגליםDefine arguments with argparse: required, options and flags
  • לבנות פקודות-משנה כמו shelf add ו-shelf listBuild subcommands like shelf add and shelf list
  • להחזיר קוד יציאה ולכתוב שגיאות ל-stderrReturn an exit code and write errors to stderr
להתחיל בהרצאהStart the lecture

לפני שמתחיליםBefore you start

זמן: Time: כ-3 שעות (כולל הפסקה)About 3 hours (with a break)

דרישות קודמות: Prerequisites: מפגשים 1–26Sessions 1–26

מה צריך: You need: מחשב עם Python ו-VS Code מותקנים (מפגש 1), או רק דפדפן: כל הקוד רץ גם כאן באתר.A computer with Python and VS Code (session 1), or just a browser: all code also runs here on the site.

סדר המפגשSession plan

  1. 0:00פתיחה וחזרה קצרהOpening and quick review
  2. 0:10argvargv
  3. 0:30argparseargparse
  4. 0:50עזרהHelp
  5. 1:10הפסקהBreak
  6. 1:20פקודותCommands
  7. 1:40יציאהExit
  8. 2:00בדיקהTesting
  9. 2:20תרגולPractice
  10. 2:50סיכום ושאלותWrap-up and questions

ארגומנטים, תתי-פקודות, עזרה אוטומטית. בסוף המפגש מוסיפים צעד לפרויקט המלווה.

Arguments, sub-commands, automatic help. At the end we add a step to the companion project.

הפרויקט המלווהThe companion project: מדף: ספרייה אישיתShelf: a personal library

פרויקט אחד שגדל איתך לאורך כל הקורס: מתחיל כסקריפט של 10 שורות ונגמר כ-API עם מסד נתונים, בדיקות ו-CLI.

One project that grows with you through the whole course: it starts as a 10-line script and ends as an API with a database, tests and a CLI.

השלב של היוםToday's step shelf add / list / search מהטרמינלshelf add / list / search from the terminal. לתרגילGo to the exercise

מונחים חדשים במפגשNew terms in this session

נבנה על ידיBuilt by Ariel Yohimovich