1. typeerror: coercing to UNICODE: need string or buffer, type found
Traceback (most recent call Last ): File " Unzip. py " , Line 20 , In <Module> Tar = Tarfile. Open ( File ) File " /System/library/frameworks/python. Framework/versions/2.7/lib/python2.7/tarfile. py " , Line 1658 , In Open return func (name, " R " , Fileobj ,** Kwargs) File " /System/library/frameworks/python. Framework/versions/2.7/lib/python2.7/tarfile. py " , Line 1720 , In Gzopen fileobj = Bltn_open (name, mode + " B " ) Typeerror: coercing to UNICODE: Need String Or buffer, type found
CodeIs:
# Scan all current GZ files Currdir = OS. getcwd () files = OS. listdir (currdir) dstdir = " 20130.009 " If Not OS. Path. exists (dstdir): OS. mkdir (dstdir) For Filename In Files: If OS. Path. isfile (filename) And Tarfile. is_tarfile (filename ): Print Filename Try : Tar = Tarfile. Open (file) # This should be filename, not file. Names = Tar. getnames () For Name In Names: tar. Extract (name, path = Dstdir) tar. Close () Except Tarfile. readerror: Print " Not a tarfile " Pass