Python Forum
problem in output of a snippet code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
problem in output of a snippet code
#1
hi
assume the below snippet code(the code address is in the docstring of the code) :
 '''
from:https://www.knowledgehut.com/blog/programming/sys-argv-python-
examples#what-is-%22sys.%C2%A0argv%C2%A0[1]%22?-how-does%C2%A0it-work?%C2%A0
'''

import getopt
import sys
 
first =""
last =""
argv = sys.argv[1:]
try:
    options, args = getopt.getopt(argv, "f:l:",
                               ["first =",
                                "last ="])
except:
    print("Error Message ")
 
for name, value in options:
    if name in ['-f', '--first']:
        first = value
    elif name in ['-l', '--last']:
        last = value
 
print(first + " " + last)

# in cmd write: python getopt_module.py -f Knowledge -l Hut
# or
# in cmd write: python getopt_module.py --first Knowledge --last Hut
#### but the last line does not show anything in output, why?
after saving this file as getopt_module.py, if I write in cmd:
python getopt_module.py -f Knowledge -l Hut
The output will be:
Output:
Knowledge Hut
but if write in cmd:
python getopt_module.py --first Knowledge --last Hut
then nothing will be in the output. why?
thanks
Reply


Messages In This Thread
problem in output of a snippet code - by akbarza - Feb-28-2024, 07:57 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  output shape problem with np.arange alan6690 5 822 Dec-26-2023, 05:44 PM
Last Post: deanhystad
  problem in output of a function akbarza 9 1,388 Sep-29-2023, 11:13 AM
Last Post: snippsat
  I cannot able to see output of this code ted 1 803 Feb-22-2023, 09:43 PM
Last Post: deanhystad
  Python Pandas Syntax problem? Wrong Output, any ideas? Gbuoy 2 981 Jan-18-2023, 10:02 PM
Last Post: snippsat
  Facing problem with Pycharm - Not getting the expected output amortal03 1 902 Sep-09-2022, 05:44 PM
Last Post: Yoriz
  [Solved] Trying to rerun a snippet of code paracel 3 1,222 Jul-17-2022, 01:49 PM
Last Post: paracel
  why I dont get any output from this code William369 2 1,188 Jun-23-2022, 09:18 PM
Last Post: William369
  Can someone explain this small snippet of code like I am a 5 year old? PythonNPC 3 1,309 Apr-08-2022, 05:54 PM
Last Post: deanhystad
  How can I organize my code according to output that I want ilknurg 1 1,217 Mar-11-2022, 09:24 AM
Last Post: perfringo
  single input infinite output problem Chase91 2 2,024 Sep-23-2020, 10:01 PM
Last Post: Chase91

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020