我有一个python脚本,它接受文件.txt作为论据。你知道吗
当我从windows命令行运行时,它会抱怨以下错误。你知道吗
*C:\Projects\ATR220TA\ISO8583_Payment>python C:\Projects\ATR220TA\ISO8583_Payment\ISO8583.py C:\Projects\ISO8583.txt
Traceback (most recent call last):
File "C:\Projects\ATR220TA\ISO8583_Payment\ISO8583.py", line 19, in <module>
from ISO8583_Payment.ISOErrors import InvalidIso8583, ValueToLarge, InvalidValueType, InvalidBitType, BitInexistent, \
ModuleNotFoundError: No module named 'ISO8583_Payment'
C:\Projects\ATR220TA\ISO8583_Payment>pause*
基本上,ISO8583_Payment
是我主项目的一个子文件夹,但是由于某种原因,ISO8583_Payment
被假定为一个模块,并抛出“modulenotfound”错误。你知道吗
ISO8583.py
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])
@Mikah Barnett,当我从命令提示符运行时,你的建议不起作用。我之前提到过它对我有效,但是我刚刚意识到它只在我从pyCharm IDE运行时才有效(很抱歉造成混乱)。
ISO8583.py
和ISO8583Errors.py
都位于ISO8583_payment
文件夹中。另外,我根据您的建议在ISO8583_Payment
文件夹中创建了__init.py__
。你知道吗ISO8583.py
等误差.py
当我从命令提示符运行时,仍然会出现以下错误。你知道吗
当你写作的时候
您告诉Python
ISO8583_Payment
是一个模块。你知道吗因此,您可以将一个空的
__init__.py
文件添加到该子目录中,或者,如果您想将其保留为目录,请使用以下代码将其添加到系统路径中,以便对其进行搜索:相关问题 更多 >
编程相关推荐