Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/360.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python3类型错误:replace()参数1必须是str,而不是int_Python_Python 3.x - Fatal编程技术网

Python3类型错误:replace()参数1必须是str,而不是int

Python3类型错误:replace()参数1必须是str,而不是int,python,python-3.x,Python,Python 3.x,我已经尝试了几天,现在让这个代码在MacOS上工作,但没有成功。你能看看我遗漏了什么吗 运行Python3.6,我上传了全部代码。非常感谢 #!/usr/bin/env python3 from __future__ import print_function try: import pymarketcap import decimal from operator import itemgetter import argparse except Exception

我已经尝试了几天,现在让这个代码在MacOS上工作,但没有成功。你能看看我遗漏了什么吗

运行Python3.6,我上传了全部代码。非常感谢

#!/usr/bin/env python3
from __future__ import print_function
try:
    import pymarketcap
    import decimal
    from operator import itemgetter
    import argparse
except Exception as e:
    print('Make sure to install {0} (pip3 install {0}).'.format(str(e).split("'")[1]))
    exit()

# arguments and setup
parser = argparse.ArgumentParser()
parser.add_argument('-m','--minimum_vol',type=float,help='Minimum Percent volume per exchange to have to count',default=1)
parser.add_argument('-p','--pairs',nargs='*',default=[],help='Pairs the coins can be arbitraged with - default=all')
parser.add_argument('-c','--coins_shown',type=int,default=10,help='Number of coins to show')
parser.add_argument('-e','--exchanges',nargs='*',help='Acceptable Exchanges - default=all',default=[])
parser.add_argument('-s','--simple',help='Toggle off errors and settings',default=False,action="store_true")
args = parser.parse_args()
cmc = pymarketcap.Pymarketcap()
info = []
count = 1
lowercase_exchanges = [x.lower() for x in args.exchanges]
all_exchanges = not bool(args.exchanges)
all_trading_pairs = not bool(args.pairs)
coin_format = '{: <25} {: >6}% {: >10} {: >15} {: <10} {: <10} {: <15} {: <5}'

if not args.simple:
    print('CURRENT SETTINGS\n* MINIMUM_PERCENT_VOL:{}\n* TRADING_PAIRS:{}\n* COINS_SHOWN:{}\n* EXCHANGES:{}\n* ALL_TRADING_PAIRS:{}\n* ALL_EXCHANGES:{}\n'.format(args.minimum_vol,args.pairs,args.coins_shown,lowercase_exchanges,all_trading_pairs,all_exchanges))
# retrieve coin data
for coin in cmc.ticker():
    try:
        markets = cmc.markets(coin["id"])
    except Exception as e:
        markets = cmc.markets(coin["symbol"])
    best_price = 0

    best_exchange = ''
    best_pair = ''
    worst_price = 999999
    worst_exchange = ''
    worst_pair = ''
    has_markets = False
    for market in markets:
        trades_into = market["pair"].replace (coin["symbol"]," ").replace("-"," ")
        if market['percent_volume'] >= args.minimum_vol and market['updated'] and (trades_into in args.pairs or all_trading_pairs) and (market['exchange'].lower() in lowercase_exchanges or all_exchanges):
            has_markets = True
            if market['price_usd'] >= best_price:
                best_price = market['price_usd']
                best_exchange = market['exchange']
                best_pair = trades_into
            if market['price_usd'] <= worst_price:
                worst_price = market['price_usd']
                worst_exchange = market['exchange']
                worst_pair = trades_into
    if has_markets:
        info.append([coin['name'],round((best_price/worst_price-1)*100,2),worst_price,worst_exchange,worst_pair,best_price,best_exchange,best_pair])
    elif not args.simple:
        print(coin['name'],'had no markets that fit the criteria.')

    print('[{}/100]'.format(count),end='\r')
    count += 1

# show data
info = sorted(info,key=itemgetter(1))[::-1]
print(coin_format.format("COIN","CHANGE","BUY PRICE","BUY AT","BUY WITH","SELL PRICE","SELL AT","SELL WITH"))
for coin in info[0:args.coins_shown]:
    print(coin_format.format(*coin))#
#/usr/bin/env蟒蛇3
来自未来导入打印功能
尝试:
进口pymarketcap
输入小数
从运算符导入itemgetter
导入argparse
例外情况除外,如e:
print('确保安装{0}(pip3安装{0})。'.format(str(e).split(“')”[1]))
退出()
#参数和设置
parser=argparse.ArgumentParser()
parser.add_参数('-m','-minimum_vol',type=float,help='每次交换必须计数的最小卷百分比',默认值=1)
parser.add_参数('-p','-pairs',nargs='*',default=[],help='pairs硬币可以用-default=all'套利)
parser.add_参数('-c','-coins_-show',type=int,default=10,help='Number of coins to show')
parser.add_参数('-e','-exchanges',nargs='*',help='Acceptable exchanges-default=all',default=[]))
parser.add_参数('-s','-simple',help='Toggle off errors and settings',default=False,action=“store_true”)
args=parser.parse_args()
cmc=pymarketcap.pymarketcap()
信息=[]
计数=1
小写字母交换=[x.lower()表示args.exchanges中的x]
所有交换=非布尔(参数交换)
所有交易对=非布尔(args.pairs)

coin_format='{:6}%{:>10}{:>15}{:您的错误告诉您需要知道的一切
coin[“symbol”]
是一个int,但是
replace
只接受字符串。您可以通过执行
str(coin[“symbol”])

来修复此问题,它表示您传递的参数格式不正确,需要字符串,并且您已经传递了int

写这个

trades_into = market["pair"].replace(str(coin["symbol"])," ").replace("-"," ")
而不是

trades_into = market["pair"].replace (coin["symbol"]," ").replace("-"," ")

在错误消息中,您不完全理解的是什么???它确切地告诉您问题是什么以及在哪里…请不要编辑您的问题以提出新问题。我已经更改了它,现在我有两个其他错误。结果应该是这样的-这是我的朋友使用相同的代码不断得到的。我建议“结束”这个问题(接受解决这个问题的答案),然后问一个新问题,并发布相关代码,现在会产生新的错误谢谢。刚刚运行它,我得到了一些其他信息:)谢谢,它起作用了。不幸的是,我只能选择一个答案。
trades_into = market["pair"].replace (coin["symbol"]," ").replace("-"," ")