append string and looping 'for'

Asked

Viewed 76 times

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']))

Since directories: 'w:/', ’d:/ and’d:/data ' do not exist as directories how to append a string to another string during internal looping and display the result at the end of the same looping.

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')

Browser other questions tagged

You are not signed in. Login or sign up in order to post.