1

i have some setter function :

      @images_path.setter
      def images_path(self, *images_path: tuple):
         self.__images_path = 
           os.path.abspath(os.path.join(os.pardir,'BossGame', 'Resources','images'))

i want to pass input that contain: 'BossGame', 'Resources', 'images' in the input images_path to the os.path.join function

 class Nature(object):

   def __init__(self):

    self.images_path = ['BossGame', 'Resources', 'images']
    self.sound_path = ['BossGame', 'Resources', 'music']

    pass

   @property
   def images_path(self)->str:
       return self.__images_path

   @images_path.setter
   def images_path(self, *images_path: tuple):
       self.__images_path = 
           os.path.abspath(os.path.join(os.pardir,images_path))

the Error:

      TypeError: join() argument must be str or bytes, not 'list'

2 Answers 2

3
def images_path(self, path_seq):
   self.__images_path = 
       os.path.abspath(os.path.join(os.pardir, *path_seq))

Please note that you have used images_path both as variable name and function name. This is really bad practice.

Sign up to request clarification or add additional context in comments.

Comments

2

Just do this:

self.__images_path = [os.path.abspath(os.path.join(os.pardir,pth)) for pth in images_path]

By default, the function doesn't accept a list so you can't force one to it, but you may loop over the list and run the function n times, where n is the size of the list

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.