社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

python无法访问其他方法中的类方法[重复]

aditya rawat • 6 年前 • 1831 次点击  

这个问题已经有了答案:

我一直在创建一个python脚本,它基本上隐藏/取消隐藏Linux环境中的文件和文件夹。这是密码

import os


class unhide_files:
    def __init__(self, directory):
        self.parent_dir,self.sub_folders,self.files = list(os.walk(directory))[0]
        os.chdir(directory)

    def general_unhide(self,files):
        try:
            for f in files:
                if "." in f:
                    os.rename(f,f.replace(".","",True))
        except Exception as err:
            print(str(err))

    def unhide_file(self):
        general_unhide(self.files) #unhide_file could not use general_unhide


    def unhide_sub_folders(self):
        general_unhide(self.sub_folders) #unhide_sub_folders could not use general_unhide


    if __name__ == "__main__":
        path = input("Enter the directory's path ")
        unhid = unhide_files(path)

        # testing to see if it works. Directory unhiding is still to 
        be done
        unhid.unhide_file()
        # hiding files behaviour is still to be implemented

代码的问题是,除了作为类方法 general_unhide 类中的其他方法无法访问。

有什么特别的原因吗?或者只是一个愚蠢的错误?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/37916
 
1831 次点击  
文章 [ 1 ]  |  最新文章 6 年前