Question

I am making a tuple of all path but it also contains two extra paths

  1. /Users/sanjeevkumar/Pictures/.DS_Store
  2. /Users/sanjeevkumar/Pictures/.localized

how do i get rid of the above paths, I am generating the tuple path using the below technique

tuple(os.path.join(self._path,each) for each in os.listdir(self._path) if os.path.isfile(os.path.join(self._path,each)))
Was it helpful?

Solution 2

Alternatively I also realized that I can do it this way

tuple(os.path.join(self._path,each)
    for each in os.listdir(self._path) 
    if os.path.isfile(os.path.join(self._path,each))
    and each.endswith('png') or each.endswith('jpg')
)

I think this will also help me get rid of any other file extension that could appear and is not compatible.

OTHER TIPS

Expand the if clause using and operator.

tuple(
    os.path.join(self._path,each)
    for each in os.listdir(self._path)
    if os.path.isfile(os.path.join(self._path,each))
    and each not in ('.DS_Store', '.localized') # <-------------
)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top