2012-10-24 74 views
0

Possible Duplicate:
Syntax error on print with Python 3語法錯誤:無效語法蟒蛇試圖使用tarfile.open()在.tgz的文件

我想查看一個.tgz的文件的內容,我發現蟒蛇的tar文件模塊時。我發現以下教程看起來很有希望。 http://www.doughellmann.com/PyMOTW/tarfile/

這裏是我下面的Python文件:

import tarfile 

tar = tarfile.open("exampleTar.tgz","r") 

print tar.getnames() 

當我實際執行我的Python文件,我得到一個胡蘿蔔標誌在最後一行和錯誤消息「R」指點:語法錯誤:無效句法。

+1

'print'是python-3.x中的一個函數 – SilentGhost

+0

這是問題,謝謝! – SpartaSixZero

回答

1

Print是python 3.x中的函數。

import tarfile 

tar = tarfile.open("exampleTar.tgz","r") 

print(tar.getnames())