Jon*_*now 5 python class-method
#! /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()
Run Code Online (Sandbox Code Playgroud)
有了我收到的代码
> 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)
Run Code Online (Sandbox Code Playgroud)
有什么想法吗?
Set*_*eth 16
python类方法的第一个参数是self变量.如果您调用classInstance.method(parameter),则调用该方法method(self, parameter).
所以,当你定义你的课时,做这样的事情:
class MyClass(Object):
def my_method(self, parameter):
print parameter
Run Code Online (Sandbox Code Playgroud)
您可能想要阅读Python教程.
| 归档时间: |
|
| 查看次数: |
419 次 |
| 最近记录: |