<p>@Mikah Barnett,当我从命令提示符运行时,你的建议不起作用。我之前提到过它对我有效,但是我刚刚意识到它只在我从pyCharm IDE运行时才有效(很抱歉造成混乱)。<code>ISO8583.py</code>和<code>ISO8583Errors.py</code>都位于<code>ISO8583_payment</code>文件夹中。另外,我根据您的建议在<code>ISO8583_Payment</code>文件夹中创建了<code>__init.py__</code>。你知道吗</p>
<p><strong>ISO8583.py</strong></p>
<pre><code>import sys
sys.path.append("/ISO8583_Payment")
from ISO8583_Payment.ISOErrors import InvalidBitType,InvalidMTI,InvalidValueType,InvalidIso8583,ValueToLarge,BitInexistent,BitNotSet
''' I did not copy all the source code in here ''''
def ParseRawMessage(ISO8583TextFile):
with open(ISO8583TextFile, 'rb') as in_file:
contents = in_file.read()
hex_bytes = binascii.hexlify(contents)
IsoStr = hex_bytes.decode("ascii")
Iso8583 = ISO8583()
try:
Iso8583.setIsoContent(IsoStr)
except InvalidMTI as error:
print("{0}".format(error))
except InvalidBitType as error:
print("{0}".format(error))
except ValueToLarge as error:
print("{0}".format(error))
except InvalidValueType as error:
print("{0}".format(error))
except BitInexistent as error:
print("{0}".format(error))
except BitNotSet as error:
print("{0}".format(error))
except InvalidIso8583 as error:
print("{0}".format(error))
bitsAndValuesDictionary = Iso8583.getBitsAndValues()
for v in bitsAndValuesDictionary:
print('%s (BIT-%s) = %s' % (v['name'], v['bit'], v['value']))
if __name__ == '__main__':
ParseRawMessage(sys.argv[1])
</code></pre>
<p><strong>等误差.py</strong></p>
<pre><code>class ValueToLarge(Exception):
def __init__(self, value):
self.str = value
def __str__(self):
return repr(self.str)
class BitInexistent(Exception):
def __init__(self, value):
self.str = value
def __str__(self):
return repr(self.str)
class InvalidValueType(Exception):
def __init__(self, value):
self.str = value
def __str__(self):
return repr(self.str)
class InvalidBitType(Exception):
def __init__(self, value):
self.str = value
def __str__(self):
return repr(self.str)
class InvalidIso8583(Exception):
def __init__(self, value):
self.str = value
def __str__(self):
return repr(self.str)
class InvalidMTI(Exception):
def __init__(self, value):
self.str = value
def __str__(self):
return repr(self.str)
#Exception that indicate that bit is not there.
class BitNotSet(Exception):
def __init__(self, value):
self.str = value
def __str__(self):
return repr(
</code></pre>
<p>当我从命令提示符运行时,仍然会出现以下错误。你知道吗</p>
<pre><code>C:\Projects\ATR220TA_Work_On_Progress\ISO8583_Payment>python C:\Projects\ATR220TA_Work_On_Progress\ISO8583_Payment
C:\Users\gobiraaj.anandavel\AppData\Local\Programs\Python\Python37-32\python.exe: can't find '__main__' module in 'C:\\Projects\\ATR220TA_Work_On_Progress\\ISO8583_Payment'
</code></pre>