#! /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()
Với mã mà tôi nhậnTại sao lớp Python của tôi cho rằng tôi có 2 đối số thay vì 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)
Bất kỳ suy nghĩ?
Cảm ơn tất cả, tôi quên điều đó. Đây là lớp thực tế đầu tiên tôi đã tạo với Python, vì vậy cảm ơn sự kiên nhẫn. Tôi bắt đầu trên Java nên hiện tại điều này cảm thấy khá khác nhau! – jphenow
Vâng, tôi nhớ có vấn đề tương tự khi tôi lần đầu tiên bắt đầu làm việc với các lớp Python (không phải đề cập đến hơi khó chịu mà tôi đã phải viết một cách rõ ràng "tự" ở khắp mọi nơi). Phần khó nhất về việc đi python là học cách quên tất cả các cruft mà bạn đã học được từ Java hoặc C++ :) – Seth