到目前为止,我的代码存在的问题是,当我从选择中输入精灵时,出现错误,指出参数必须是表面而非字符串。我想知道如何解决此问题。我正在尝试做的是让用户从以下SP1R,SP1O等中选择一个精灵。但是在我输入了其中一个精灵之后,程序不接受它,并且出现以下错误:
var market1h = 'not yet defined'; var market5m = 'not yet defined'; binance.prevDay(false, (error, prevDay) => { let markets = []; for ( let obj of prevDay ) { let symbol = obj.symbol; markets.push(symbol); } setInterval(get1hData, 1500); setInterval(get5mData, 1200); function get1hData(){ binance.websockets.candlesticks(markets, '1h', (candlestickData) => { let tick = binance.last(candlestickData); market1h = candlestickData[tick]; io.emit('market1h', market1h); }); } function get5mData(){ binance.websockets.candlesticks(markets, '5m', (candlestickData) => { let tick = binance.last(candlestickData); market5m = candlestickData[tick]; io.emit("market5m", market5m); }); } });
Traceback (most recent call last):
File "C:\Users\User\Documents\Pygame\pygame1.py", line 90, in <module>
drawGrid()
File "C:\Users\User\Documents\Pygame\pygame1.py", line 60, in drawGrid
win.blit (UserSprite, (500, 500))
TypeError: argument 1 must be pygame.Surface, not str
答案 0 :(得分:1)
输入后
UserSprite = input("""Choose a sprite [...]""")
变量UserSprite
的内容是一个字符串。您必须找到名称存储在变量UserSprite
中的变量。
当调用不带任何参数的内置字典vars()
时,可以使用局部变量获取字典。这意味着vars()["SP1R"]
将返回对象SP1R
。
SpriteName = input("""Choose a sprite [...]""")
UserSprite = vars()[SpriteName] if SpriteName in vars() else None