creating a tar file with python

Steve Holden steve at holdenweb.com
Thu Aug 23 23:12:30 EDT 2007


Brian McCann wrote:
> 
> Hi,
>  
> I tried Steve's solution but get this error
> using the tar script below
> --Brian
> 
> tar = tarfile.open(".","test.tar.gz",w:gz)
> [viz at vizbld02 tmp]$ ./tarup.py
>   File "./tarup.py", line 24
>     tar = tarfile.open(".","test.tar.gz",w:gz)
>                                           ^
> SyntaxError: invalid syntax
> ######################################################
>  
> #!/usr/bin/python
> import string
> import os
> import sys
> import time
> import errno
> import shutil
> import tarfile
> 
> tar = tarfile.open(".","test.tar.gz",w:gz)
> <mailto:brian.mccann at viziant.net>
>  
>  
> 
> *From:* python-list-bounces+brian.mccann=viziant.net at python.org on 
> behalf of Steve Holden
> *Sent:* Thu 8/23/2007 5:24 PM
> *To:* python-list at python.org
> *Subject:* Re: creating a tar file with python
> 
> Brian McCann wrote:
>  > Hi,
>  > 
>  > I'm trying to create a tar file of the contents of the current directory
>  > 
>  > right now there is only one file "text.xml" in the current dir,  I'm
>  > using"." current dir as source
>  > but that gives syntax error
>  >
>  > any help would be greatly appreciated
>  > --Brian
>  > 
>  > 
>  > #!/usr/bin/python
>  > import string
>  > import os
>  > import sys
>  > import time
>  > import errno
>  > import shutil
>  > import tarfile
>  > 
>  >
>  > tar = tarfile.open(.,"test.tar.gz", "w:gz)
>  > <mailto:brian.mccann at viziant.net>
>  > 
>  >
> well, /probably/ (meaning I haven't done any testing) you need quotes
> around the name of the current directory just like you do around the
> name of the file. Try
> 
>    tar = tarfile(".", "test.tar.gz", "w:gz")
> 
> regards
>   Steve
> --
> Steve Holden        +1 571 484 6266   +1 800 494 3119
> Holden Web LLC/Ltd           http://www.holdenweb.com
> Skype: holdenweb      http://del.icio.us/steve.holden
> --------------- Asciimercial ------------------
> Get on the web: Blog, lens and tag the Internet
> Many services currently offer free registration
> ----------- Thank You for Reading -------------
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
> 
[Jeez, doesn't anybody use standard-conformant mailers any more: why is 
my signature quoted above, and what it it supposed to add? Couldn't you 
have taken a second to delete it: that would probably have taken about 
35 MB off the Internet backbone. Or perhaps you think that all resources 
are unlimited? Sorry, I'm a bit cranky this week, being short of sleep.]

I admitted my code was untested, but I believe if you had 
copied-and-pasted you would not have received the error you did (which 
is not to say you wouldn't have received some other error).

Don't run what you /think/ I wrote, run /what I wrote/, as pasted by 
your operating system, dammit. Or are you running on some platform that 
doesn't allow you to select what I wrote and paste it into an editor window?

sholden at bigboy /tmp
$ cat > Brian\'s\ Original
tar = tarfile.open(.,"test.tar.gz", w:gz)

sholden at bigboy /tmp
$ cat > what\ I\ wrote
tar = tarfile(".", "test.tar.gz", w:gz")

sholden at bigboy /tmp
$ diff Brian\'s\ Original what\ I\ wrote
1c1
< tar = tarfile.open(.,"test.tar.gz", w:gz)
---
 > tar = tarfile(".", "test.tar.gz", "w:gz")

sholden at bigboy /tmp

Hmm, you probably don't understand the gobbledygook above, but what it 
means is that you didn't pay sufficient attention to detail. This isn't 
a serious problem: Google will probably show you several thousand 
occurrences of me exhibiting similar symptoms. But remember, computers 
are TOMCATs: Thoroughly Obedient Moron, Cannot Actually Think.

regards
  Steve
-- 
Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd           http://www.holdenweb.com
Skype: holdenweb      http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------



More information about the Python-list mailing list