1

I was searching for the fnmatch module, and along the way, I came across a statement where I didn’t get what is happening… can anyone help me? I need to know what purpose the -25 serves in this code:

print 'Filename: %-25s %s' % (name, fnmatch.fnmatchcase(name, pattern))

fish2000
  • 4,289
  • 2
  • 37
  • 76

1 Answers1

1

The %-25s stands for a string comprising 25 spaces. It can as well be replaced with 25*" ".

The above line of code can be written as:

a_string_of_spaces = 25*" "
X = fnmatch.fnmatchcase(filename, pattern)
print("Filename:", name, a_string_of_spaces, X)

According to the python documentation:

fnmatch.fnmatchcase(filename, pattern): Test whether filename matches pattern, returning True or False; the comparison is case-sensitive and does not apply os.path.normcase()

Thus, the function parameter filename is checked for patterns of type pattern. The function then returns a boolean value of True or False

So, in entirety, that line of code prints something like this (FILE_NAME = name of the file, the pattern of PATTERN has matched with the file):

Filename: FILE_NAME                           True      

Hope that helps!

Eshita Shukla
  • 791
  • 1
  • 8
  • 30