Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 21st, 2012, 07:11 PM
Jboulger Jboulger is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2012
Posts: 2 Jboulger User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 24 m 25 sec
Reputation Power: 0
New to python need help with practice

Hello! Sorry to bother you folks with something that probably isn't very exciting, but it would really help me if anyone had a quick solution to my problem. I am working Byte of Python 1.92, and its his problem solving exercise in creating a zip backup of a directory. It looks like this:

Code:
import time 
import os  
source=['C:\\gs'] 
target_dir='C:\\backup' target=target_dir + os.sep +time.strftime('%Y%m%d%H%M%S')+'.zip' 
zip_command="zip -qr {0} {1}".format(target,''.join(source)) 
if os.system(zip_command) == 0:     
    print('Successful backup to', target) 
else:     
    print('Backup FAILED')


So, I understand that the directory that zip.exe is in has to be in the list, sys.path. I have already appended it, and have checked multiple times to make sure it is correct. I have also checked to make sure all proper directories exist. Finally, I have used "zip_command" string in command prompt and it worked perfectly. I am running out of ideas; essentially it seems that even though I have the directory zip.exe is in, I am unable to use it. Also, I have done previous things involving modules and I was able to make use of ones in the default directories (the current directory, ' ', mainly). Is there any other problem it could be?

The message in command prompt when I run in my python interpreter (a little window flashes and leaves, that I captured with a screenshot) says " ' zip' is not recognized as an internal or external command, operable program, or batch file. " Which I have understood to essentially mean that it is not seeing that directory (I have seen this same message when trying to run the command in command prompt in any other directory than the one zip.exe is in). So that leads me to believe that even though it is in sys.path, it is acting as if it isn't.

This is my sys.path:
Code:
['',
 'C:\\Windows\\system32\\python32.zip',  
'C:\\Python32\\Lib', 
'C:\\Python32\\DLLs', 
'C:\\Python32', 
'C:\\Python32\\lib\\site-packages', 
'C:\\Program Files (x86)\\GnuWin32\\bin']


I appreciate any help, even if its just shared befuddlement. Thanks!

Reply With Quote
  #2  
Old June 21st, 2012, 07:47 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,383 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 13 h 44 m 29 sec
Reputation Power: 383
Differences between this post and your post are 1) target= starts on a new line, and I've displayed the command you plan to run via the system function. Would that command work on the "DOS command line"?

Next, you're a bit confused. Python searches for dynamic libraries and .py files using sys.path .
The operating system, on the other hand, will search for zip.exe using the PATH in the shell. You can see that (and modify as you would a python dictionary)
print(os.environ['PATH'])
Code:
import time 
import os  
source=['C:\\gs'] 
target_dir='C:\\backup'
target=target_dir + os.sep +time.strftime('%Y%m%d%H%M%S')+'.zip' 
zip_command="zip -qr {0} {1}".format(target,''.join(source)) 

print(zip_command)

if os.system(zip_command) == 0:     
    print('Successful backup to', target) 
else:     
    print('Backup FAILED')
__________________
[code]Code tags[/code] are essential for python code!

Reply With Quote
  #3  
Old June 22nd, 2012, 03:41 PM
Jboulger Jboulger is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2012
Posts: 2 Jboulger User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 24 m 25 sec
Reputation Power: 0
Ahh I see now, so environmental variables are associated with the subshell. This dictionary does seem weirder than the previous ones I looked at though. I went ahead and added the directory in the control panel actually, through system. Thank you though for clearing up that misconception!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > New to python need help with practice

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap