Python Forum
why I can't use "try" without "expect"
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
why I can't use "try" without "expect"
#2
This code is strange because bool() will never fail, so assuming sys.argv has the usual meaning, the code can raise an exception only when there are less than two command line arguments. You could replace the code with
EnableLoop = (len(sys.argv) >= 3)
When handling command line arguments it is much easier to use a module such as argparse. By scanning sys.argv, you are reinventing the wheel.

You can't use try without except, but you could use contextlib.suppress()
with suppress(Exception):
    EnableLoop = bool(sys.argv[2])
xMaxrayx likes this post
« We can solve any problem by introducing an extra level of indirection »
Reply


Messages In This Thread
RE: why I can't use "try" without "expect" - by Gribouillis - May-16-2024, 04:56 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Not able to read the text using pexpect/expect Bipinjohnson 7 7,050 Jan-10-2022, 11:21 AM
Last Post: Bipinjohnson
  Please help me. about self.expect() leeyoung 0 1,881 Nov-23-2020, 10:25 PM
Last Post: leeyoung
  can I use 2 child.expect at the same time? korenron 0 1,964 May-25-2020, 10:41 AM
Last Post: korenron
  Trying to convert my Expect/bash to Python sumncguy 4 5,599 Jun-07-2019, 07:14 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

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