Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #2544
| From | ecu_jon <hayesjdno3@yahoo.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | string to path problem |
| Date | 2011-04-03 20:30 -0700 |
| Organization | http://groups.google.com |
| Message-ID | <7f0a2a35-8ae8-4625-9cef-8516b142cd25@f18g2000yqd.googlegroups.com> (permalink) |
i am writing a basic backup program for my school. so they wanted the
possibility to be able to set source/destination from a config file.
my source/destination was fine before, i would build it up with
functions, like 1 that got the user-name, and put it all together with
os.path.join. but if they set a source in the config file to something
like c:\users\jon\backup python tries to read from c:\\users\\jon\
\backup, and throws out a read permission (because it doesn't
exist ...). i am not sure what to do at this point. i have look at the
docs for string, and os.____ . i cant os.path.join anything if they
give me an absolute path. here is a bit of the code
import os,string,fnmatch,shutil,time,getpass,md5,ConfigParser
from datetime import *
from os.path import join, getsize
config = ConfigParser.ConfigParser()
config.read("config.ini")
source = config.get("myvars", "source")
destination = config.get("myvars", "destination")
helptext = config.get("myvars", "helptext")
def weekChoice():
dateNum = datetime.now().day
if dateNum <=7:
week = 1
elif (dateNum >= 8) and (dateNum <= 14):
week = 2
elif (dateNum >= 15) and (dateNum <= 21):
week = 3
elif dateNum > 22:
week = 4
else:
print "error"
return week
def destination1():
global destination
username = getpass.getuser()
week = weekChoice()
weekstr = "week"+str(week)
destination1 = os.path.join("//mothera","jon","week1") #where //
mothera is a samba server on the network
return destination1
print "source :",source
destination = destination1()
shutil.copy2(source, destination)
here is some of config.ini
[myvars]
source:c:\users\jon\backup
destination:
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
string to path problem ecu_jon <hayesjdno3@yahoo.com> - 2011-04-03 20:30 -0700
Re: string to path problem Chris Rebert <clp2@rebertia.com> - 2011-04-03 21:17 -0700
Re: string to path problem ecu_jon <hayesjdno3@yahoo.com> - 2011-04-03 21:18 -0700
Re: string to path problem Kushal Kumaran <kushal.kumaran+python@gmail.com> - 2011-04-04 14:36 +0530
Re: string to path problem ecu_jon <hayesjdno3@yahoo.com> - 2011-04-04 08:21 -0700
csiph-web