小编Joh*_*uid的帖子

尝试编写cPickle对象但得到'write'属性类型错误

当我尝试应用我在互联网上发现的一些代码时,它会出现错误:

TypeError                                 Traceback (most recent call last)
    <ipython-input-4-36ec95de9a5d> in <module>()
     13     all[i] = r.json()
     14 
---> 15 cPickle.dump(all, outfile)

TypeError: argument must have 'write' attribute
Run Code Online (Sandbox Code Playgroud)

这是我按顺序完成的工作:

outfile = "C:\John\Footy Bants\R COMPLAEX MATHS"
Run Code Online (Sandbox Code Playgroud)

然后,我粘贴了以下代码:

import requests, cPickle, shutil, time

all = {}
errorout = open("errors.log", "w")

for i in range(600):
    playerurl = "http://fantasy.premierleague.com/web/api/elements/%s/"
    r = requests.get(playerurl % i)

    # skip non-existent players
    if r.status_code != 200: continue

    all[i] = r.json()

cPickle.dump(all, outfile)
Run Code Online (Sandbox Code Playgroud)

这是原始文章,让您了解我正在努力实现的目标:

http://billmill.org/fantasypl/

python pickle

18
推荐指数
1
解决办法
2万
查看次数

将JSON转换为.csv

我发现有人将某些数据下载到JSON文件中(我想!-我是新手!)。该文件包含有关近600名足球运动员的数据。

这是文件:https : //raw.githubusercontent.com/llimllib/fantasypl_stats/f944410c21f90e7c5897cd60ecca5dc72b5ab619/data/players.1426687570.json

有没有办法可以获取一些数据并将其转换为.csv?特别是“固定记录”?

在此先感谢您的帮助:)

csv json

0
推荐指数
1
解决办法
1万
查看次数

标签 统计

csv ×1

json ×1

pickle ×1

python ×1