首页 > 解决方案 > 如何将输入连接到函数

问题描述

我有一些设置器功能:

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

我想将输入 images_path 中包含:'BossGame'、'Resources'、'images'的输入传递给 os.path.join 函数

 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))

错误:

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

标签: python

解决方案


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

请注意,您同时使用images_path了变量名和函数名。这是非常糟糕的做法。


推荐阅读