Suppose I have a filename ./file and I want to remove the leading ./ (if it starts with ./). What would be the best python way to do this? My take at this is:
if filename.startswith("./"):
# remove leading ./
filename = filename[2:]
Isn't there a more elegant way?
PS: it should remove the leading part only if it matches exactly, think of the following filenames:
./filename
.configfile
../file
./.configfile
new_list = [element.replace("./", "") for element in old_list]if element.startswith(".\")if it's needed. It's just quick comment, not an nswer, feel the deffierenceregex:re.sub(r'^./', '', file)