从脚本中获取的电影信息与从 python shell 中获取的电影信息不同

Getting different movie info from script than from python shell

我有以下脚本可以将电影演员表输出到文本文档:

import imdb

ia = imdb.IMDb()
movie = ia.get_movie(0111161)
cast = movie['cast']
text_file = open("Cast.txt", "w")
text_file.write("{0}".format(movie))
text_file.write("{0}".format(cast))
text_file.close()

如您所见,我是从 IMDB 网站而不是数据库中抓取的。 当我在 python shell (2.7.13) 中执行此脚本时,我得到了 'The Shawshank Redemption' 的转换,但是当我从命令行执行它时 (python myscript.py), 我得到了电影'29 Acacia Avenue'的演员表,ID = 0037489。 怎么会这样?

0111161 以 0 开头,因此 Python 将其解释为 八进制 数字。它的十进制值为 37489。

你应该使用

movie = ia.get_movie("0111161")

而不是

movie = ia.get_movie(0111161)