Python Forum
Accessing varying command line arguements
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Accessing varying command line arguements
#4
Could do it like this,so with super() inherit all the methods and properties from its parent.
Then add another parameter in the __init__() function.
I guess also popejose way could work.
import re
import sys

import bs4 as bs4

inputURL = sys.argv[1]
inputConfig = sys.argv[2]
version = sys.argv[3]
print(len(sys.argv))
if len(sys.argv) > 4:
    typeOfTest = sys.argv[4]

class Client:
    def __init__(self, URL, Config, Version):
        self.Url = URL
        self.config = Config
        self.version = Version

    def perform_test(self):
        # subprocess.call(['java','-version'])
        if len(sys.argv) > 4:
            subprocess.call(
                ['java', '-jar', 'XXX.jar', '-url', self.Url, '-config', self.config, '-specVersion',
                 self.version])
        else:
            subprocess.call(
                ['java', '-jar', 'XXX.jar', '-url', self.Url, '-config', self.config, '-specVersion',
                 self.version, '-test', self.testType])

    def read_results(self):
        pass

class TestClient(Client):
    def __init__(self, URL, Config, Version, TestType):
        super().__init__(URL, Config, Version)
        self.testType = TestType

if __name__ == "__main__":
    if len(sys.argv) > 4:
        client = Client(inputURL, inputConfig, version)
    else:
        client = TestClient(inputURL, inputConfig, version, typeOfTest)
        client.perform_test()
        client.read_results()
Rakshan likes this post
Reply


Messages In This Thread
RE: Accessing varying command line arguements - by snippsat - Jul-28-2021, 03:18 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Command line argument issue space issue mg24 5 1,353 Oct-26-2022, 11:05 PM
Last Post: Yoriz
  accept command line argument mg24 5 1,342 Sep-27-2022, 05:58 PM
Last Post: snippsat
  How to input & output parameters from command line argument shantanu97 1 2,584 Apr-13-2021, 02:12 PM
Last Post: Larz60+
  Passing List of Objects in Command Line Python usman 7 3,206 Sep-27-2020, 03:45 PM
Last Post: ndc85430
  How to create a varying qty of instances of a Class and name them? KM007 2 2,053 May-29-2020, 12:30 PM
Last Post: KM007
  class arguements astral_travel 7 2,958 Apr-29-2020, 04:30 PM
Last Post: buran
  Taking Multiple Command Line Argument Input bwdu 6 4,068 Mar-29-2020, 05:52 PM
Last Post: buran
  python 3 from command line Dixon 1 2,006 Mar-01-2020, 08:35 PM
Last Post: snippsat
  Running linux command line apps... dbrdh 0 1,662 Jan-30-2020, 01:14 PM
Last Post: dbrdh
  command line input (arg parse) and data exchange Simba 7 4,340 Dec-06-2019, 11:58 PM
Last Post: Simba

Forum Jump:

User Panel Messages

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