我正在尝试使用Cmd模块开发Binance客户端,但是当我尝试从另一个文件调用函数时,它给我一个错误。
这是给我正在写的Binance客户的。
def do_order(self, *args):
"""Places an order.\n
Arguments in order:\n
Buy or Sell option.\n
Market or Limit option.\n
The crypto symbol.\n
The quantity of the order.\n
The price of the order.\n"""
market.Market.xch(*args[0], *args[1], *args[2], *args[3], *args[4])
class Market():
#l = 0
#m = 0
#b = 0
#s = 0
def xch(self, xtype1, xtype2, xsymbol, xquantity, xprice ):
print("Formulating the order...")
#Time to sort the parameters
#xtype1...
[verl@verlpc Interface]$ python main.py
Loading Accounts...
CRYPTOANAYLISIS: PREDICTOR
> order 0 0 0 0 0
Traceback (most recent call last):
File "main.py", line 99, in <module>
m.initAccounts()
File "main.py", line 92, in initAccounts
prompt.cmdloop('CRYPTOANAYLISIS: PREDICTOR')
File "/usr/lib/python3.7/cmd.py", line 138, in cmdloop
stop = self.onecmd(line)
File "/usr/lib/python3.7/cmd.py", line 217, in onecmd
return func(arg)
File "main.py", line 50, in do_order
market.Market.xch(*args[0], *args[1], *args[2], *args[3], *args[4])
IndexError: tuple index out of range
答案 0 :(得分:0)
首先,您必须创建此类的实例
m = market.Market()
然后您使用了一个*args
m.xch(*args)
或许多参数,但没有*
m.xch(args[0], args[1], args[2], args[3], args[4])
工作示例
class Market():
def xch(self, xtype1, xtype2, xsymbol, xquantity, xprice ):
print("Formulating the order...", xtype1, xtype2, xsymbol, xquantity, xprice)
args = [1,2,3,4,5]
m = Market()
m.xch(*args)
编辑:您必须使用do_order(...)
具有*
的定义和运行时
def do_order(*args):
m = Market()
m.xch(*args)
args = [1,2,3,4,5]
do_order(*args)
或两个地方都没有*
def do_order(args):
m = Market()
m.xch(*args)
args = [1,2,3,4,5]
do_order(args)