Gọi python __init__ theo cách thủ công

Theo mặc định, lệnh

pylint mydir
************* Module mydir
mydir/__init__.py:1:0: F0010: error while code parsing: Unable to load file mydir/__init__.py:
[Errno 2] No such file or directory: 'mydir/__init__.py' (parse-error)
1 chỉ chấp nhận danh sách các gói và mô-đun python. Trên các phiên bản bên dưới 2. 15, chỉ định một thư mục không phải là một gói rõ ràng (với
pylint mydir
************* Module mydir
mydir/__init__.py:1:0: F0010: error while code parsing: Unable to load file mydir/__init__.py:
[Errno 2] No such file or directory: 'mydir/__init__.py' (parse-error)
2) dẫn đến lỗi

pylint mydir
************* Module mydir
mydir/__init__.py:1:0: F0010: error while code parsing: Unable to load file mydir/__init__.py:
[Errno 2] No such file or directory: 'mydir/__init__.py' (parse-error)

Như vậy, trên các phiên bản trước 2. 15 hoặc khi xử lý một số trường hợp Edge chưa được giải quyết, sử dụng tùy chọn

pylint mydir
************* Module mydir
mydir/__init__.py:1:0: F0010: error while code parsing: Unable to load file mydir/__init__.py:
[Errno 2] No such file or directory: 'mydir/__init__.py' (parse-error)
3 cho phép tạo gói không gian tên

pylint --recursive=y mydir mymodule mypackage

Tùy chọn này làm cho

pylint mydir
************* Module mydir
mydir/__init__.py:1:0: F0010: error while code parsing: Unable to load file mydir/__init__.py:
[Errno 2] No such file or directory: 'mydir/__init__.py' (parse-error)
1 cố gắng khám phá tất cả các mô-đun (tệp kết thúc bằng phần mở rộng
pylint mydir
************* Module mydir
mydir/__init__.py:1:0: F0010: error while code parsing: Unable to load file mydir/__init__.py:
[Errno 2] No such file or directory: 'mydir/__init__.py' (parse-error)
5) và tất cả các gói rõ ràng (tất cả các thư mục chứa tệp
pylint mydir
************* Module mydir
mydir/__init__.py:1:0: F0010: error while code parsing: Unable to load file mydir/__init__.py:
[Errno 2] No such file or directory: 'mydir/__init__.py' (parse-error)
2)

Pylint sẽ không nhập gói hoặc mô-đun này, nhưng nó sử dụng các phần bên trong Python để định vị chúng và do đó tuân theo cùng các quy tắc và cấu hình. Bạn nên chú ý đến

pylint mydir
************* Module mydir
mydir/__init__.py:1:0: F0010: error while code parsing: Unable to load file mydir/__init__.py:
[Errno 2] No such file or directory: 'mydir/__init__.py' (parse-error)
0 của mình, vì việc phân tích phiên bản mô-đun đã cài đặt thay vì phiên bản phát triển là một lỗi phổ biến

Trên tập tin #

Cũng có thể phân tích các tệp Python, với một vài hạn chế. Để thuận tiện, bạn có thể đặt tên tệp nếu có thể đoán tên mô-đun từ đường dẫn của tệp bằng đường dẫn python. Vài ví dụ

pylint mydir
************* Module mydir
mydir/__init__.py:1:0: F0010: error while code parsing: Unable to load file mydir/__init__.py:
[Errno 2] No such file or directory: 'mydir/__init__.py' (parse-error)
1 phải luôn hoạt động vì thư mục làm việc hiện tại được tự động thêm vào đầu đường dẫn python

pylint mydir
************* Module mydir
mydir/__init__.py:1:0: F0010: error while code parsing: Unable to load file mydir/__init__.py:
[Errno 2] No such file or directory: 'mydir/__init__.py' (parse-error)
2 sẽ hoạt động nếu.
pylint mydir
************* Module mydir
mydir/__init__.py:1:0: F0010: error while code parsing: Unable to load file mydir/__init__.py:
[Errno 2] No such file or directory: 'mydir/__init__.py' (parse-error)
3 là một gói python (tôi. e. có tệp
pylint mydir
************* Module mydir
mydir/__init__.py:1:0: F0010: error while code parsing: Unable to load file mydir/__init__.py:
[Errno 2] No such file or directory: 'mydir/__init__.py' (parse-error)
2), gói không gian tên ẩn hoặc nếu
pylint mydir
************* Module mydir
mydir/__init__.py:1:0: F0010: error while code parsing: Unable to load file mydir/__init__.py:
[Errno 2] No such file or directory: 'mydir/__init__.py' (parse-error)
3 nằm trong đường dẫn python

Tùy chọn dòng lệnh #

Trước hết, chúng tôi có hai tùy chọn cơ bản (nhưng hữu ích)

--phiên bản

hiển thị số phiên bản của chương trình và thoát

-h , --trợ giúp

hiển thị trợ giúp về các tùy chọn dòng lệnh

Pylint được kiến ​​trúc xung quanh một số quân cờ. Bạn có thể tắt một trình kiểm tra cụ thể hoặc một số tin nhắn hoặc danh mục tin nhắn của nó bằng cách chỉ định

pylint mydir
************* Module mydir
mydir/__init__.py:1:0: F0010: error while code parsing: Unable to load file mydir/__init__.py:
[Errno 2] No such file or directory: 'mydir/__init__.py' (parse-error)
6. Nếu bạn chỉ muốn bật một số trình kiểm tra hoặc một số ký hiệu thư, trước tiên hãy sử dụng
pylint mydir
************* Module mydir
mydir/__init__.py:1:0: F0010: error while code parsing: Unable to load file mydir/__init__.py:
[Errno 2] No such file or directory: 'mydir/__init__.py' (parse-error)
7 rồi đến
pylint mydir
************* Module mydir
mydir/__init__.py:1:0: F0010: error while code parsing: Unable to load file mydir/__init__.py:
[Errno 2] No such file or directory: 'mydir/__init__.py' (parse-error)
8 với
pylint mydir
************* Module mydir
mydir/__init__.py:1:0: F0010: error while code parsing: Unable to load file mydir/__init__.py:
[Errno 2] No such file or directory: 'mydir/__init__.py' (parse-error)
9 là danh sách tên trình kiểm tra và ký hiệu thư được phân tách bằng dấu phẩy. Xem danh sách các tính năng có sẵn để biết mô tả về các trình kiểm tra được cung cấp với các chức năng của chúng. Các tùy chọn
pylint --recursive=y mydir mymodule mypackage
0 và
pylint --recursive=y mydir mymodule mypackage
1 có thể được sử dụng với các danh sách được phân tách bằng dấu phẩy, trộn các bộ kiểm tra, id thư và danh mục như
pylint --recursive=y mydir mymodule mypackage
2

Có thể vô hiệu hóa tất cả các tin nhắn với

pylint mydir
************* Module mydir
mydir/__init__.py:1:0: F0010: error while code parsing: Unable to load file mydir/__init__.py:
[Errno 2] No such file or directory: 'mydir/__init__.py' (parse-error)
7. Điều này hữu ích khi chỉ kích hoạt một vài trình kiểm tra hoặc một vài thông báo bằng cách tắt mọi thứ trước tiên, sau đó chỉ kích hoạt lại những gì bạn cần

Mỗi trình kiểm tra có một số tùy chọn cụ thể, có thể lấy giá trị có/không, số nguyên, biểu thức chính quy python hoặc danh sách giá trị được phân tách bằng dấu phẩy (thường được sử dụng để ghi đè biểu thức chính quy trong trường hợp đặc biệt). Để biết danh sách đầy đủ các tùy chọn, hãy sử dụng

pylint --recursive=y mydir mymodule mypackage
4

Chỉ định tất cả các tùy chọn phù hợp với tiêu chuẩn thiết lập và mã hóa của bạn có thể rất tẻ nhạt, vì vậy có thể sử dụng tệp cấu hình để chỉ định các giá trị mặc định. Bạn có thể chỉ định tệp cấu hình trên dòng lệnh bằng tùy chọn

pylint --recursive=y mydir mymodule mypackage
5. Mặt khác, Pylint tìm kiếm tệp cấu hình theo thứ tự sau và sử dụng tệp đầu tiên mà nó tìm thấy

  1. pylint --recursive=y mydir mymodule mypackage
    
    6 trong thư mục làm việc hiện tại

  2. pylint --recursive=y mydir mymodule mypackage
    
    7 trong thư mục làm việc hiện tại

  3. pylint --recursive=y mydir mymodule mypackage
    
    8 trong thư mục làm việc hiện tại, miễn là nó có ít nhất một phần
    pylint --recursive=y mydir mymodule mypackage
    
    9.
    pylint --recursive=y mydir mymodule mypackage
    
    8 phải đặt trước tên phần bằng
    pylint --recursive=y mydir mymodule mypackage
    
    9, ví dụ như
    pylint mydir
    ************* Module mydir
    mydir/__init__.py:1:0: F0010: error while code parsing: Unable to load file mydir/__init__.py:
    [Errno 2] No such file or directory: 'mydir/__init__.py' (parse-error)
    
    32. Chúng cũng có thể được truyền vào dòng lệnh

  4. pylint mydir
    ************* Module mydir
    mydir/__init__.py:1:0: F0010: error while code parsing: Unable to load file mydir/__init__.py:
    [Errno 2] No such file or directory: 'mydir/__init__.py' (parse-error)
    
    33 trong thư mục làm việc hiện tại, miễn là nó có ít nhất một phần
    pylint mydir
    ************* Module mydir
    mydir/__init__.py:1:0: F0010: error while code parsing: Unable to load file mydir/__init__.py:
    [Errno 2] No such file or directory: 'mydir/__init__.py' (parse-error)
    
    34

  5. Nếu thư mục làm việc hiện tại nằm trong gói Python, Pylint sẽ tìm kiếm theo thứ bậc của các gói Python cho đến khi tìm thấy tệp

    pylint --recursive=y mydir mymodule mypackage
    
    6. Điều này cho phép bạn chỉ định các tiêu chuẩn viết mã trên cơ sở từng mô-đun. Tất nhiên, một thư mục được đánh giá là gói Python nếu nó chứa tệp
    pylint mydir
    ************* Module mydir
    mydir/__init__.py:1:0: F0010: error while code parsing: Unable to load file mydir/__init__.py:
    [Errno 2] No such file or directory: 'mydir/__init__.py' (parse-error)
    
    2

  6. Tệp được đặt tên theo biến môi trường

    pylint mydir
    ************* Module mydir
    mydir/__init__.py:1:0: F0010: error while code parsing: Unable to load file mydir/__init__.py:
    [Errno 2] No such file or directory: 'mydir/__init__.py' (parse-error)
    
    37

  7. nếu bạn có một thư mục chính không phải là

    pylint mydir
    ************* Module mydir
    mydir/__init__.py:1:0: F0010: error while code parsing: Unable to load file mydir/__init__.py:
    [Errno 2] No such file or directory: 'mydir/__init__.py' (parse-error)
    
    38

    1. pylint --recursive=y mydir mymodule mypackage
      
      7 trong thư mục nhà của bạn

    2. pylint mydir
      ************* Module mydir
      mydir/__init__.py:1:0: F0010: error while code parsing: Unable to load file mydir/__init__.py:
      [Errno 2] No such file or directory: 'mydir/__init__.py' (parse-error)
      
      10 trong thư mục nhà của bạn

  8. pylint mydir
    ************* Module mydir
    mydir/__init__.py:1:0: F0010: error while code parsing: Unable to load file mydir/__init__.py:
    [Errno 2] No such file or directory: 'mydir/__init__.py' (parse-error)
    
    11

Tùy chọn

pylint mydir
************* Module mydir
mydir/__init__.py:1:0: F0010: error while code parsing: Unable to load file mydir/__init__.py:
[Errno 2] No such file or directory: 'mydir/__init__.py' (parse-error)
12 sẽ tạo tệp cấu hình nhận xét trên đầu ra tiêu chuẩn theo cấu hình hiện tại và thoát. Điêu nay bao gôm

  • Bất kỳ tệp cấu hình nào được tìm thấy như đã giải thích ở trên

  • Các tùy chọn xuất hiện trước

    pylint mydir
    ************* Module mydir
    mydir/__init__.py:1:0: F0010: error while code parsing: Unable to load file mydir/__init__.py:
    [Errno 2] No such file or directory: 'mydir/__init__.py' (parse-error)
    
    12 trên dòng lệnh Pylint

Tất nhiên, bạn cũng có thể bắt đầu với các giá trị mặc định và điều chỉnh cấu hình bằng tay

Các tùy chọn toàn cầu hữu ích khác bao gồm

--ignore=

Tập tin hoặc thư mục bị bỏ qua. Chúng phải là tên cơ sở, không phải đường dẫn

--output-format=

Chọn định dạng đầu ra (văn bản, json, tùy chỉnh)

--msg-template=