Skip to main content
Question

Parsing Filename(multiple) parameters

  • September 22, 2017
  • 2 replies
  • 9 views

jdh
Contributor
Forum|alt.badge.img+28
  • Contributor

What method do use to parse the Filename (multiple) parameter in python?

 

 

I currently use

 

source = FME_MacroValues['Param1']
if source.startswith('"'):
	from shlex import split
	fileList = split(source[1:-1])
else:
	fileList=[source

 

but it feels clunky.

 

 

The assumption is that if it's a single file, it is not wrapped in quotes, but if it's multiple files it is:

 

""file1" "file2" "file3""

2 replies

daveatsafe
Safer
Forum|alt.badge.img+19
  • Safer
  • September 22, 2017

Hi @jdh,

You could try:

source = FME_MacroValues['Param1']
filelist = shlex.split(shlex.split(source)[0])

takashi
Evangelist
  • September 22, 2017

The shlex.split method may not work as expected if a file path could contain a space, so I would use str.strip and str.split method simply. This works like the AttributeTrimmer and the AttributeSplitter.

source = FME_MacroValues['Param1']
filelist = source.strip('"').split('" "')


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings