make string append and looping 'for'

0
def conf_dir_exist(lines):
    temp = ''
    print(lines) #isso é uma tuple.
    for line_a in lines:
        for line_b in line_a:
            if(os.path.exists(line_b) != False):
                pass
            else:
                temp += ''.join(line_b + '; ')
                print('\n\tDirectory ' + str(line_a) + ' < ' + temp + '> not exist.')

if __name__ == '__main__':
    conf_dir_exist((['w:/', 'g:/', 'd:/', 'x:/', 'y:/'], ['c:/data', 'd:/data']))

Given that directories: 'w: /', 'd: / e' d: / data 'do not exist as directories like appending to a string in another one during the internal looping and displaying the result at the end of even looping.

    
asked by anonymous 25.07.2016 / 21:37

1 answer

0

Just set a string for this effect at the beginning before looping:

def conf_dir_exist(lines):
    temp = ''
    print(lines) #isso e uma tuple.
    string_final = ''
    for line_a in lines:
        for line_b in line_a:
            if(os.path.exists(line_b) != False):
                pass
            else:
                temp += ''.join(line_b + '; ')
                string_final += '\n\tDirectory ' + str(line_a) + ' < ' + temp + '> not exist.'
    print(string_final)


if __name__ == '__main__':
    conf_dir_exist((['w:/', 'g:/', 'd:/', 'x:/', 'y:/'], ['c:/data', 'd:/data']))

You can also save them in an array of strings to manipulate as you want later:

log = []
log.append('my string')
    
26.07.2016 / 19:45