Skip to content

Commit d191cd2

Browse files
committed
debug challenge5.py
1 parent 1b476fe commit d191cd2

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

05-income-tax-calculator-use-modules/challenge5.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import csv
44
import queue
55
import configparser
6-
from getopt import getopt
6+
from getopt import getopt, GetoptError
77
from datetime import datetime
88
from multiprocessing import Process, Queue
99
from collections import namedtuple
@@ -33,8 +33,19 @@
3333
class Args(object):
3434

3535
def __init__(self):
36-
options, _ = getopt(sys.argv[1:], 'C:c:d:o:')
37-
self.options = dict(options)
36+
self.options = self._options()
37+
38+
def _options(self):
39+
try:
40+
opts, _ = getopt(sys.argv[1:], 'hC:c:d:o:', ['help'])
41+
except GetoptError:
42+
print('Parameter Error')
43+
exit()
44+
options = dict(opts)
45+
if len(options) == 1 and ('-h' in options or '--help' in options):
46+
print('Usage: calculator.py -C cityname -c configfile -d userdata -o resultdata')
47+
exit()
48+
return options
3849

3950
def _value_after_option(self, option):
4051
value = self.options.get(option)
@@ -187,4 +198,4 @@ def run(self):
187198
Exporter()
188199
]
189200
for worker in workers:
190-
worker.run()
201+
worker.run()

0 commit comments

Comments
 (0)