Get Parent path value (bad design) Help
lbates at swamisoft.com
Mon Aug 30 16:44:51 CEST 2004
I think what you want is:
sys.path.append(parentpath) #append the path back to sys.path
This is shorter and portable.
"Golawala, Moiz M (GE Infrastructure)" <Moiz.Golawala at ge.com> wrote in
message news:mailman.2601.1093875943.5135.python-list at python.org...
What I am trying to do is write some generic code where I can get the path
of the parent directory. for example if current working directory is
I want to get a string which up like 'Z:\\dirA\\Parent'
Then I do a sys.path.append('Z:\\dirA\\Parent')
The code I have written below does all this.. but I have a feeling there is
a better way to do this.. Please can someone help me.
pathname = os.getcwd()
pathString = ''
pathList = pathname.split("\\")
pathList.pop() # removes the child
lastItem = pathList.pop() #remove to the parent, will be added back later.
counter = 0
while counter != len(pathList): #build up the path with items in the list
pathString = pathString + pathList[counter] + "\\\\"
pathString = pathString + lastItem #add parent back to the built up path
sys.path.append(pathString) #append the path back to sys.path
More information about the Python-list