#! /usr/bin/env python
import os
import stat
import sys
class chkup:
def set(file):
filepermission = os.stat(file)
user_read()
user_write()
user_exec()
def user_read():
"""Return True if 'file' is readable by user
"""
# Extract the permissions bits from the file's (or
# directory's) stat info.
b = bool(filepermission.st_mode & stat.S_IRUSR)
print b
return b
def user_write():
"""Return True if 'file' is readable by user
"""
# Extract the permissions bits from the file's (or
# directory's) stat info.
b = bool(filepermission.st_mode & stat.S_WRUSR)
print b
return b
def user_exec():
"""Return True if 'file' is readable by user
"""
# Extract the permissions bits from the file's (or
# directory's) stat info.
b = bool(filepermission.st_mode & stat.S_IXUSR)
print b
return b
def main():
i = chkup()
place = '/net/home/f08/itsrsw1/ScriptingWork/quotacheck'
i.set(place)
if __name__ == '__main__':
main()
与该代码我收到为什么我的Python类声称我有2个参数而不是1?
> Traceback (most recent call last):
File "chkup.py", line 46, in <module>
main()
File "chkup.py", line 43, in main
i.set(place)
TypeError: set() takes exactly 1 argument (2 given)
有什么想法?
谢谢大家,我忘了那件事。这是我用Python创建的第一个实际的类,所以感谢耐心。我开始使用Java,所以目前这感觉非常不同! – jphenow 2009-12-08 17:58:24
是的,我记得当我第一次开始使用Python类时有类似的问题(更不用说有点恼火,我不得不在任何地方明确地写“self”)。关于python最难的部分是学习忘记所有从Java或C++学到的东西:) – Seth 2009-12-08 19:19:39