Error compressing tar file

Steven D'Aprano steve+comp.lang.python at
Mon Mar 3 03:02:10 CET 2014

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

> without ")" i have the same sintax error:
> [root at master ~]# python
> Traceback (most recent call last):
>   File "", line 19, in <module>
>     tar = + '.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" + '.tar.gz','w:gz')

but what you actually have is probably something like this:

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

Steven D'Aprano

More information about the Python-list mailing list