Remove quotes from the output of a list

1

I would like to present a problem that came up with the outputs of a list in python, the fact is that I am doing a program that runs through the directories of a PC, by getting the first list of directories (The one that is available from the first working directory) has to access the lists found in that directory, and that's where it fails:

import os
import ftplib
carpetas = []
actuals = os.getcwd()
print actuals
def paso1 ():
    lista = os.listdir(".")
    for x in lista:
        if os.path.isdir(x) == True:
            num = lista.index(x)
            carpetas.append(lista[num])
paso1()

def paso2():
    for i in carpetas:
        os.chdir(i)
        direct = str(os.getcwd())
        directorios = {direct : ""}
        lista = os.listdir(".")
        for x in lista:
            if os.path.isdir(x) == True:
                num = lista.index(x)
                directorios[direct].append(lista[num])
        os.chdir("..")

step2 ()

When I try to access the following directory in "os.chdir (i)" it gives an error, since "i" is presented with quotation marks, like the outputs of a list.

Can you think of any way for the output to be without quotes?

The error:

/home/angrymasther/Escritorio
Traceback (most recent call last):
File "Servidor2.py", line 28, in <module>
paso2()
File "Servidor2.py", line 17, in paso2
os.chdir(i)
OSError: [Errno 2] No such file or directory: 'Web'

Thanks in advance.

    
asked by angrymasther 03.04.2017 в 23:02
source

2 answers

1

before doing os.chdir(i) , try to replace it with characters

something like that

i.replace('"', '');
    
answered by 03.04.2017 / 23:07
source
0

It could be a replace of the elements in the list, but in addition to double quote also remove single quote:

String palabrasinQuotes = palabra.replace('"', '').replace("'", '')

example:

   String palabrasinQuotes = lista[num].replace('"', '').replace("'", ''))
    
answered by 03.04.2017 в 23:40