need python help

Discuss how to write good code, break bad code, your current pet projects, or the best way to approach novel problems

need python help

Post by phant0mrican on Sat Jun 25, 2011 3:54 pm
([msg=59013]see need python help[/msg])

Im reading this book called A Byte of Python
Im having trouble running this script, keep coming up as Back up FAILED, so any suggestions?

Code: Select all
#!/usr/bin/python
# Filename: backup_ver1.py

import os
import time

# 1. The files and directories to be backed up are specified in a list.
source = ['"C:\\My Documents"', 'C:\\Code']
# Notice we had to use double quotes inside the string for names with spaces in it.

# 2. The backup must be stored in a main backup directory
target_dir = 'C:\\Backup' # Remember to change this to what you will be using

# 3. The files are backed up into a zip file.
# 4. The name of the zip archive is the current date and time
target = target_dir + os.sep + time.strftime('%Y%m%d%H%M%S') + '.zip'

# 5. We use the zip command to put the files in a zip archive
zip_command = "zip -qr {0} {1}".format(target, ' '.join(source))

# Run the backup
if os.system(zip_command) == 0:
    print('Successful backup to', target)
else:
    print('Backup FAILED')
phant0mrican
New User
New User
 
Posts: 41
Joined: Sun May 23, 2010 3:00 pm
Blog: View Blog (0)


Re: need python help

Post by neuromanta on Sat Jun 25, 2011 4:54 pm
([msg=59017]see Re: need python help[/msg])

Did you try to run the zip dommand all by itself in the shell?
User avatar
neuromanta
Poster
Poster
 
Posts: 303
Joined: Mon Nov 30, 2009 9:29 am
Location: Hungary
Blog: View Blog (0)


Re: need python help

Post by phant0mrican on Sat Jun 25, 2011 5:03 pm
([msg=59019]see Re: need python help[/msg])

what would be the zip command? sorry if i sound like a total newb, i just started with python

-- Sat Jun 25, 2011 7:02 pm --

well im guessing im having trouble with the zip commands. I downloaded GnuWin32 as the book told me, so im guessing i installed it incorrectly? Any suggestions? btw im having trouble with the path of both python and gnuwin32, so is that something to do with it?
phant0mrican
New User
New User
 
Posts: 41
Joined: Sun May 23, 2010 3:00 pm
Blog: View Blog (0)


Re: need python help

Post by neuromanta on Sat Jun 25, 2011 8:32 pm
([msg=59023]see Re: need python help[/msg])

*sigh*
Just install linux, and use that... it will be easier to use for python programming.
User avatar
neuromanta
Poster
Poster
 
Posts: 303
Joined: Mon Nov 30, 2009 9:29 am
Location: Hungary
Blog: View Blog (0)


Re: need python help

Post by phant0mrican on Sat Jun 25, 2011 9:28 pm
([msg=59027]see Re: need python help[/msg])

kind of defeats the purpose. I know its a lot simpler running python in linux, but what bout if i want to use a program in windows? I really wouldn't know how to trouble shoot or fix it. And this problem really bothering me, and i dont want to take the easy way out. I want to know whats the problem, so maybe in the future i can fix something like itt
phant0mrican
New User
New User
 
Posts: 41
Joined: Sun May 23, 2010 3:00 pm
Blog: View Blog (0)


Re: need python help

Post by ampakine on Sun Jun 26, 2011 12:16 am
([msg=59037]see Re: need python help[/msg])

Why not just do your python programming on a Linux guest in VirtualBox? When somethings easier to do on Windows I just fire up my Windows 7 VB guest. Likewise some things are much easier to do with BackTrack (since it has a load of tools preinstalled) I just launch VirtualBox. When you're more advanced with python you'll have no trouble solving problems you run into programming on Windows but in the meantime theres no point creating additional obstacles for yourself. I've made this mistake a few times by insisting I do something on Linux that is a thousand times easier on Windows. I spent hours one day trying to install ChemDraw in WINE when all I had to do was install a Windows guest and install the program on that. Now that I'm familiar with the program I could probably get in installed in WINE if I had to.
ampakine
Experienced User
Experienced User
 
Posts: 65
Joined: Tue May 31, 2011 5:21 pm
Blog: View Blog (0)


Re: need python help

Post by fashizzlepop on Sun Jun 26, 2011 1:24 am
([msg=59044]see Re: need python help[/msg])

Notice your Python script is initiating a command line command. That's what "if os.system(zip_command) == 0:" does.

It puts zip_command into the terminal. On Windows it would obviously put it in cmd and on Linux, BASH/etc...

You need to make sure you zip_command is legal under Windows CMD. If not, fix it. This is why using os.system can be problematic, and un-portable to another system.
The glass is neither half-full nor half-empty; it's merely twice as big as it needs to be.
User avatar
fashizzlepop
Developer
Developer
 
Posts: 2304
Joined: Sat May 24, 2008 1:20 pm
Blog: View Blog (0)


Re: need python help

Post by phant0mrican on Sun Jun 26, 2011 10:56 am
([msg=59056]see Re: need python help[/msg])

Ok now i think i understand. And i guess I'm going to try on Linux for now on, maybe on a live cd
phant0mrican
New User
New User
 
Posts: 41
Joined: Sun May 23, 2010 3:00 pm
Blog: View Blog (0)


Re: need python help

Post by jpmut on Sun Jun 26, 2011 8:59 pm
([msg=59067]see Re: need python help[/msg])

Locate the zip.exe file (may be in the GnuWin32 Installation Folder), and add it's containing folder to the PATH system variable in Environment Variables. This might solve your problem...
The philosopher and mathematician Bertrand Russell was asked, "If a false premise can imply any conclusion, use 1 = 2 to prove you're the Pope!" Russell replied, "The Pope and I are two, so we are one."
User avatar
jpmut
New User
New User
 
Posts: 22
Joined: Fri Jul 03, 2009 1:13 pm
Blog: View Blog (0)



Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests