Error compressing tar file

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sun Mar 2 21:02:10 EST 2014


On Sun, 02 Mar 2014 17:11:19 -0800, Mike wrote:

> without ")" i have the same sintax error:
> 
> [root at master ~]# python bkp_db.py
> Traceback (most recent call last):
>   File "bkp_db.py", line 19, in <module>
>     tar = tarfile.open(dumpfile + '.tar.gz','w:gz')
> TypeError: unsupported operand type(s) for +: 'file' and 'str'


That is not a syntax error. It is a type error. You cannot add a file 
object and a string object together.

Please inspect the value of dumpfile. You are treating it as if it were a 
string, but it looks like it is an open file object. I think that you 
probably expect this:

dumpfile = "path to some file"
tarfile.open(dumpfile + '.tar.gz','w:gz')


but what you actually have is probably something like this:


dumpfile = open("path to some file")
tarfile.open(dumpfile + '.tar.gz','w:gz')





-- 
Steven D'Aprano
http://import-that.dreamwidth.org/



More information about the Python-list mailing list