Saturday, 15 August 2015

simple string manipulation in python -



simple string manipulation in python -

how can obtain expected result below?

import glob infiles = glob.glob('e:\\test\\*.txt') print infiles ['e:\\test\\a.txt', 'e:\\test\\b.txt', 'e:\\test\\c.txt', 'e:\\test\\d.txt']

expected result is:

'e:\\test\\a.txt','e:\\test\\b.txt','e:\\test\\c.txt','e:\\test\\d.txt'

my effort is:

infiles = ','.join(x x in infiles) print infiles e:\test\a.txt,e:\test\b.txt,e:\test\c.txt,e:\test\d.txt

print ','.join(map(repr, infiles))

you're looking output containing repr representations of strings in lists, not literal character contents of strings. mapping repr on list gets that.

python

No comments:

Post a Comment