首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python字典提出了0x03B22CF8>中unicode对象的<内置方法替换。

Python字典提出了0x03B22CF8>中unicode对象的<内置方法替换。
EN

Stack Overflow用户
提问于 2017-05-07 11:32:32
回答 1查看 795关注 0票数 1

我的脚本贯穿并得到一个用户的csgo库存,然后运行它在蒸汽市场,以获得价格。它把价格打印得很好,但当我最后打印出世界卫生组织的字典时:

代码语言:javascript
复制
print(item_prices)) 

它给了我:

代码语言:javascript
复制
<built-in method replace of unicode object at 0x03B22CF8>

这是我的密码:

代码语言:javascript
复制
#!/usr/bin/python
# -*- coding: utf-8 -*-
import urllib2
import json
import datetime
import time

global file_name
file_name = "skins 2017-05-05 23-15-16.txt"

wear_list = ["Factory New", "Minimal Wear", "Field-Tested", "Well-Worn", "Battle-Scarred"]
wear_val = {"Factory New": 1, "Minimal Wear": 2, "Field-Tested": 3, "Well-Worn": 4, "Battle-Scarred": 5}
items = []
item_prices = {}

def getInventory(steamid):
    try:
        data = urllib2.urlopen('http://steamcommunity.com/profiles/'+steamid+'/inventory/json/730/2')
    except:
        print("Overloaded the server...")
        print("Waiting...")
        time.sleep(60)
        data = urllib2.urlopen('http://steamcommunity.com/profiles/'+steamid+'/inventory/json/730/2')
    json_data = json.loads(data.read())
    descriptions = json_data['rgDescriptions']
    now = datetime.datetime.now()
    date = now.strftime("%Y-%m-%d %H-%M-%S")
    global file_name
    file_name = "skins " + str(date) + ".txt"
    txt = open(file_name, "w+")
    for v in descriptions:
        name = str([descriptions[v]['market_name']])
        name = name[3:]
        name = name[:-2]
        if name.endswith("Flip Knife | Rust Coat (Battle-Scarred)"):
            name = name[7:]
        if name.startswith("StatTrak"):
            name = name[15:]
            name = 'StatTrak ' + name
        if name.endswith("(Dragon King) (Minimal Wear)"):
            name = "M4A4 | Dragon King (Minimal Wear"
        txt.write(name)
        txt.write('\n')
        #txt.write(str(descriptions[v]))
        #txt.write('\n')
        print(name)
    txt.close()
    print('Done!')
    return

def getPrice():
    x = 1
    gun_name_wear = 0
    txt = open(file_name, "r+")
    for line in txt:
        stattrak = 0
        wear = line[line.find("(")+1:line.find(")")]
        if wear in wear_list:
            print(wear)
            wear = wear.replace(" ","%20")
            gun = line.split(' |', 1)[0].replace('.', '')
            print(gun)
            if "StatTrak" in gun:
                stattrak = 1
                gun = gun.replace("StatTrak","")
            if gun.startswith(" "):
                gun = gun[1:]
            gun = gun.replace(" ", "%20")
            name = line[line.find("| ")+1:line.find(" (")]
            if name.startswith(" "):
                name = name[1:]
            print(name)
            name = name.replace(" ", "%20")
            if stattrak == 1:
                try:
                    data = urllib2.urlopen("http://steamcommunity.com/market/priceoverview/?appid=730&currency=2&market_hash_name=StatTrak%E2%84%A2%20" + gun + "%20|%20" + name + "%20(" + wear + ")")
                except:
                    print("Overloaded the server...")
                    print("Waiting...")
                    time.sleep(60)
                    data = urllib2.urlopen("http://steamcommunity.com/market/priceoverview/?appid=730&currency=2&market_hash_name=StatTrak%E2%84%A2%20" + gun + "%20|%20" + name + "%20(" + wear + ")")
                json_data = json.loads(data.read())
                print(json_data)
                try:
                    price = json_data['lowest_price']
                except KeyError:
                    price = json_data['median_price']
                price = price[-4:]
                print(price)
                gun = gun.replace("%20", " ")
                name = name.replace("%20", " ")
                wear = wear.replace("%20", " ")
                item_prices[str("StatTrak " + gun + " " + name + " " + wear)] = price
                continue
            if "knife" in line.lower():
                try:
                    data = urllib2.urlopen("http://steamcommunity.com/market/priceoverview/?appid=730&currency=2&market_hash_name=★%20" + gun + "%20|%20" + name + "%20(" + wear + ")")
                except:
                    print("Overloaded the server...")
                    print("Waiting...")
                    time.sleep(60)
                    data = urllib2.urlopen("http://steamcommunity.com/market/priceoverview/?appid=730&currency=2&market_hash_name=★%20" + gun + "%20|%20" + name + "%20(" + wear + ")")
                json_data = json.loads(data.read())
                print(json_data)
                try:
                    price = json_data['lowest_price']
                except KeyError:
                    price = json_data['median_price']
                price = price[-4:]
                print(price)
                gun = gun.replace("%20", " ")
                name = name.replace("%20", " ")
                wear = wear.replace("%20", " ")
                item_prices[str(gun + " " + name + " " + wear)] = price
                continue
            else:
                try:
                    data = urllib2.urlopen("http://steamcommunity.com/market/priceoverview/?appid=730&currency=2&market_hash_name=" + gun + "%20|%20" + name + "%20(" + wear + ")")
                except:
                    print("Overloaded the server...")
                    print("Waiting...")
                    time.sleep(60)
                    data = urllib2.urlopen("http://steamcommunity.com/market/priceoverview/?appid=730&currency=2&market_hash_name=" + gun + "%20|%20" + name + "%20(" + wear + ")")
                json_data = json.loads(data.read())
                print(json_data)
                try:
                    price = json_data['lowest_price']
                except KeyError:
                    price = json_data['median_price']
                price = price[-4:]
                print(price)
                gun = gun.replace("%20", " ")
                name = name.replace("%20", " ")
                wear = wear.replace("%20", " ")
                gun_name_wear = str(gun + " " + name + " " + wear)
                price = price.replace 
                item_prices[str(gun + " " + name + " " + wear)] = price
            time.sleep(5)
        else:
            continue
    print(item_prices)
    print(item_prices[gun_name_wear])

getInventory('76561198216481185')
getPrice()

这是它输出的最后几行:

代码语言:javascript
复制
Battle-Scarred
Flip Knife
Rust Coat
{u'volume': u'16', u'median_price': u'\xa351.80', u'lowest_price': u'\xa352.28', u'success': True}
2.28
Field-Tested
SSG 08
Blood in the Water
{u'volume': u'10', u'median_price': u'\xa312.81', u'lowest_price': u'\xa313.76', u'success': True}
3.76
Field-Tested
StatTrak Dual Berettas
Dualing Dragons
{u'volume': u'173', u'median_price': u'\xa30.23', u'lowest_price': u'\xa30.25', u'success': True}
0.25
{'AK-47 Aquamarine Revenge Field-Tested': <built-in method replace of unicode object at 0x03B22608>, 'StatTrak Desert Eagle Bronze Deco Factory New': u'1.07', 'Flip Knife Rust Coat Battle-Scarred': u'2.28', 'StatTrak M249 Spectre Field-Tested': u'0.19', 'StatTrak MP9 Bioleak Field-Tested': u'0.21', 'Nova Caged Steel Factory New': <built-in method replace of unicode object at 0x03B22CF8>, 'StatTrak Dual Berettas Dualing Dragons Field-Tested': u'0.25', 'StatTrak G3SG1 Murky Minimal Wear': u'0.50', 'StatTrak R8 Revolver Crimson Web Field-Tested': u'0.60', 'SG 553 Pulse Minimal Wear': <built-in method replace of unicode object at 0x03B22620>, 'SSG 08 Detour Minimal Wear': <built-in method replace of unicode object at 0x03B272A8>, 'StatTrak P2000 Pulse Factory New': u'0.95', 'Glock-18 Death Rattle Field-Tested': <built-in method replace of unicode object at 0x03B27188>, 'StatTrak XM1014 Scumbria Field-Tested': u'0.18', 'Five-SeveN Capillary Minimal Wear': <built-in method replace of unicode object at 0x03B22CE0>, 'Sawed-Off Forest DDPAT Minimal Wear': <built-in method replace of unicode object at 0x03AE2170>, 'Glock-18 Water Elemental Field-Tested': <built-in method replace of unicode object at 0x03AE0FB0>, 'AWP BOOM Minimal Wear': <built-in method replace of unicode object at 0x03B22320>, 'AWP Safari Mesh Battle-Scarred': <built-in method replace of unicode object at 0x03B225A8>, 'M4A1-S VariCamo Field-Tested': <built-in method replace of unicode object at 0x03AE2038>, 'MAC-10 Neon Rider Field-Tested': <built-in method replace of unicode object at 0x03B22350>, 'StatTrak MP7 Urban Hazard Field-Tested': u'0.18', 'StatTrak Negev Bratatat Minimal Wear': u'0.96', 'StatTrak SCAR-20 Outbreak Field-Tested': u'0.26', 'MP7 Army Recon Field-Tested': <built-in method replace of unicode object at 0x03B27230>, 'UMP-45 Scaffold Field-Tested': <built-in method replace of unicode object at 0x03AE0E78>, 'StatTrak Galil AR Kami Minimal Wear': u'0.46', 'USP-S Cyrex Field-Tested': <built-in method replace of unicode object at 0x03B22380>, 'SSG 08 Blue Spruce Field-Tested': <built-in method replace of unicode object at 0x03AE0F98>, 'StatTrak Tec-9 Isaac Field-Tested': u'1.18', 'MAG-7 Heat Field-Tested': <built-in method replace of unicode object at 0x03B27218>, 'M4A1-S Hyper Beast Field-Tested': <built-in method replace of unicode object at 0x03B22D88>, 'Five-SeveN Monkey Business Field-Tested': <built-in method replace of unicode object at 0x03B271E8>, 'PP-Bizon Photic Zone Minimal Wear': <built-in method replace of unicode object at 0x03B27098>, 'StatTrak CZ75-Auto Twist Minimal Wear': u'0.35', 'SSG 08 Blood in the Water Field-Tested': <built-in method replace of unicode object at 0x03AE2068>, 'FAMAS Valence Field-Tested': <built-in method replace of unicode object at 0x03B22CC8>, 'P250 Valence Field-Tested': <built-in method replace of unicode object at 0x03B27170>, 'StatTrak P90 Elite Build Minimal Wear': u'0.74', 'P250 Supernova Minimal Wear': <built-in method replace of unicode object at 0x03B22C98>, 'StatTrak AK-47 Elite Build Well-Worn': u'2.62', 'UMP-45 Gunsmoke Minimal Wear': <built-in method replace of unicode object at 0x03AE2050>, 'StatTrak Sawed-Off Origami Minimal Wear': u'0.26'}
<built-in method replace of unicode object at 0x03AE2068>
>>> 

事先谢谢,请不要马上投反对票!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-07 11:39:26

排在队伍里

price = price.replace

将名称price重新分配给unicode对象price的方法replace

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43830962

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档