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
#3
This line was wrong.
options, args = getopt.getopt(argv, "f:l:", ["first =", "last ="])
It should be
options, args = getopt.getopt(argv, "f:l:", ["first=", "last="])
from getopt import getopt

def getargs(argv):
    options, args = getopt(argv, "f:l:", ["first=", "last="])
    options = dict(options)
    return (
        options.get('--first', options.get('-f')),
        options.get('--last', options.get('-l')),
        *args
    )

print(getargs("-f Knowledge -l Hut".split()))
print(getargs("--first Knowledge --last Hut".split()))
print(getargs("-f Knowledge --last Hut".split()))
print(getargs("-f Knowledge --last Hut arg1 arg2".split()))
Output:
('Knowledge', 'Hut') ('Knowledge', 'Hut') ('Knowledge', 'Hut') ('Knowledge', 'Hut', 'arg1', 'arg2')
akbarza likes this post
Reply


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

Possibly Related Threads…
Thread Author Replies Views Last Post
  output shape problem with np.arange alan6690 5 763 Dec-26-2023, 05:44 PM
Last Post: deanhystad
  problem in output of a function akbarza 9 1,295 Sep-29-2023, 11:13 AM
Last Post: snippsat
  I cannot able to see output of this code ted 1 782 Feb-22-2023, 09:43 PM
Last Post: deanhystad
  Python Pandas Syntax problem? Wrong Output, any ideas? Gbuoy 2 956 Jan-18-2023, 10:02 PM
Last Post: snippsat
  Facing problem with Pycharm - Not getting the expected output amortal03 1 877 Sep-09-2022, 05:44 PM
Last Post: Yoriz
  [Solved] Trying to rerun a snippet of code paracel 3 1,185 Jul-17-2022, 01:49 PM
Last Post: paracel
  why I dont get any output from this code William369 2 1,160 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,283 Apr-08-2022, 05:54 PM
Last Post: deanhystad
  How can I organize my code according to output that I want ilknurg 1 1,201 Mar-11-2022, 09:24 AM
Last Post: perfringo
  single input infinite output problem Chase91 2 1,977 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