#! /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