Python Command Line Arguments tutorial for Beginners

Поделиться
HTML-код
  • Опубликовано: 28 ноя 2024

Комментарии • 21

  • @PeranMe
    @PeranMe Год назад +2

    I have to admit that I felt a little sceptical when someone recommended I use the argparse module when all I was looking for was if Python exposes arguments like in a list or something. But 5 minutes later, after skimming the documentation, boy, was I grateful that whoever it was that suggested argparse had done so! You’re definitely right to be introducing it this early in your Python series; it’s a great example of why your FIRST instinct when looking to solve a problem in Python should be to google for a module.
    As always a great video, thanks!

  • @alhabib_o
    @alhabib_o 3 месяца назад

    Shouldn't we remove the 'required=True' from the add_argumetn( ) ?
    but this way we can run from anywhere not just from the terminal window.....
    And, why do I need to mark the name parameter as 'nonlocal' if I'm not going to modify it?
    Thank you so much, Dave for this amazing tutorial !!

  • @deepatterson1894
    @deepatterson1894 8 месяцев назад +2

    For some reason I keep getting : can't open file error message, I've tried everything even copying your lesson running it directly I save it in the LESSON 15 directory. It seems when I have to use commands in the terminal is when I run into problems. One thing I notice is that you always have a $ that comes before the py but mine doesn't the $. Everything else has been great, It must be something changed with Python since you did these lessons.

    • @deepatterson1894
      @deepatterson1894 8 месяцев назад

      Figured out what I did wrong. The folder DAVE GREY or whatever name for folder chosen to put lessons in. Example in my case I used DAVE GREY. It needs the underscore in-between first and last name DAVE_GREY. Simple thing I thought I even did this at one point but now works! Just incase anyone else has the same or similar issue.

  • @ahmad-murery
    @ahmad-murery Год назад +1

    Thanks for the shoutout Dave! I really appreciate that.
    Now, we can go further and localize this game by expanding the technique used in the hello_person example,
    msg = {
    "English": {
    "player choice": "
    {name}, please enter...
    1 for Rock,
    2 for Paper, or
    3 for Scissors:

    ",
    "choice confirm": "{name}, please enter 1, 2, or 3",
    },
    "German": {
    "player choice": "
    {name}, bitte geben Sie ein...
    1 für Stein,
    2 für Papier oder
    3 für Schere:

    ",
    "choice confirm": "{name}, bitte geben Sie 1, 2 oder 3 ein.",
    }
    }
    lang = "German"
    data = {"name": "Ahmad"}
    print(msg[lang]["player choice"].format(**data))
    # or maybe use
    # print(msg[lang]["player choice"].format(name = 'Ahmad'))
    Maybe it's better to save language dictionary to a separate module per language and then import necessary one into the main game file, this will allow contributors to add more languages (and will keep the game small, clean and easier to update independently)
    Google translate was used for German messages, so please forgive me for any mistakes😁

  • @ayushman1325
    @ayushman1325 Год назад +1

    Dave The Great!❤❤

  • @johnaweiss
    @johnaweiss 10 месяцев назад

    Does "description" refer to the entire function?

  • @markyuuki5736
    @markyuuki5736 4 месяца назад

    Thank you for your videos. I am recently dealing with this error:
    File "", line 1
    py rps8.py -n "Dave"
    ^^^^
    SyntaxError: invalid syntax
    Can you help me in fixing it? Thank you in advance

  • @herway1875
    @herway1875 9 месяцев назад

    This is a good tutorial.

    • @deepatterson1894
      @deepatterson1894 8 месяцев назад

      you were able to get your code to work? It's not working for me.

  • @utinthein7274
    @utinthein7274 Год назад +1

    Thanks you, sir.

  • @dimabrinza
    @dimabrinza Год назад

    Thank you!

  • @quarkorion
    @quarkorion 7 месяцев назад

    My code works fine without the ".title" in line 33 and 34. Why do you include that?

    • @mrsengeel
      @mrsengeel 6 месяцев назад +3

      to convert the first character of a word to upper case while the rest of the character will be in lower case
      For example:
      friends = "hello world"
      find = friends.title()
      print(find)
      #output will be "Hello World"
      hope this helps

  • @quinnjin2
    @quinnjin2 Месяц назад

    [Errno 2] No such file or directory ??

    • @quinnjin2
      @quinnjin2 Месяц назад

      so I tried to "CD ~/" (Mac OS) to the directory to run the file... didn't work... so then I quit out, saved everything, and just drugged this lesson folder on to the visual studio file, opened terminal typed "python3 hello_person.py" and it worked, listed "usages:" and left me with "MacBook-Pro 15 COMMAND LINE ARRGUMENTS %" and a cursor...