Remove imports of string when string methods will do.

This commit is contained in:
Fred Drake 2000-09-28 15:04:39 +00:00
parent b64c2239b0
commit 22fb839f0c

View file

@ -57,8 +57,7 @@ def join(a, *p):
def split(p): def split(p):
"""Split a pathname. Returns tuple "(head, tail)" where "tail" is """Split a pathname. Returns tuple "(head, tail)" where "tail" is
everything after the final slash. Either part may be empty""" everything after the final slash. Either part may be empty"""
import string i = p.rfind('/') + 1
i = string.rfind(p, '/') + 1
head, tail = p[:i], p[i:] head, tail = p[:i], p[i:]
if head and head <> '/'*len(head): if head and head <> '/'*len(head):
while head[-1] == '/': while head[-1] == '/':
@ -344,9 +343,8 @@ def normpath(path):
"""Normalize path, eliminating double slashes, etc.""" """Normalize path, eliminating double slashes, etc."""
if path == '': if path == '':
return '.' return '.'
import string
initial_slash = (path[0] == '/') initial_slash = (path[0] == '/')
comps = string.split(path, '/') comps = path.split('/')
new_comps = [] new_comps = []
for comp in comps: for comp in comps:
if comp in ('', '.'): if comp in ('', '.'):
@ -357,7 +355,7 @@ def normpath(path):
elif new_comps: elif new_comps:
new_comps.pop() new_comps.pop()
comps = new_comps comps = new_comps
path = string.join(comps, '/') path = '/'.join(comps)
if initial_slash: if initial_slash:
path = '/' + path path = '/' + path
return path or '.' return path or '.'