Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
257 views
in Technique[技术] by (71.8m points)

list - python re.sub(" ", " ", str) return \ instread of

I need it for make that the rest of my code works I need replace the spaces for " " because it is a #linux directory path so I've tried with the method str.replace() and the method re.sub() but always that is replaced return "\ " instread of " " because "\ " in python writing mean " " but I don't need "\ " i need " " how i can replace " " for " "? it′s the part of code that replace the path:

from datetime import date
import os
import re
from os import listdir
import shutil
from os.path import isfile, join
ruta_de_descragas = "/home/carloseduardopalmalicea/Descargas/"

    def listfdesc():
        listfdesc.onlyfiles = os.listdir(path=ruta_de_descragas)
        inh = list(range(0,len(listfdesc.onlyfiles)))
        for i in inh:
            listfdesc.onlyfiles[i] = re.sub(" "," ",listfdesc.onlyfiles[i])
question from:https://stackoverflow.com/questions/65839504/python-re-sub-str-return-instread-of

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...