Định dạng Python autopep8args thụt lề

RStudio là một IDE tuyệt vời xung quanh để phân tích dữ liệu. Một vài năm trước, tôi đã chuyển từ viết nhiều mã R sang viết nhiều mã Python hơn tại nơi làm việc. Ban đầu, tôi chọn PyCharm làm IDE Python của mình vì nhiều lý do được nêu trong một bài đăng trên blog khác của tôi. Người dùng R chọn một IDE Python. Tuy nhiên, kể từ mùa hè năm ngoái (tháng 6 năm 2019), tôi đã chuyển sang VS Code dưới dạng Python IDE và không bao giờ nhìn lại. Nhìn lại, PyCharm có vẻ quá rắc rối với GUI gồm các nút được thiết kế quá mức để nhấp và không thực sự chắc chắn điều gì đang xảy ra. VS Code đang có những bước tiến lớn để trở thành một IDE hoạt động tốt cho kiểu mã hóa REPL (read–eval–print loop) mà RStudio hỗ trợ vượt trội. Tôi thích cảm giác VS Code nhẹ và cách các cấu hình có thể di chuyển qua các tệp JSON giúp chia sẻ cấu hình chung với các thành viên trong nhóm dễ dàng hơn. Tôi sẽ tiếp tục viết mã R trong RStudio, nhưng VS Code nhanh chóng trở thành ngôi nhà thứ hai để tôi viết mã Python

Cách cấu hình Mã VS để chạy như RStudio

Tính thẩm mỹ (Chủ đề Textmate và thước đo cột lề)

Bạn có thể biết rằng chủ đề mặc định trong RStudio là “Textmate”. Điều này được tìm thấy trong Tools -> Global Options -> Appearance. Để có được bảng màu trong Mã VS, bạn có thể cài đặt cái này với tiện ích mở rộng chủ đề Textmate

Tôi có xu hướng không thay đổi nhiều ngoài cài đặt RStudio mặc định để không cần phải duy trì một thiết lập độc đáo và lạ lẫm so với các đồng nghiệp khác cũng đang sử dụng RStudio. Tùy chỉnh duy nhất tôi khuyên dùng là thêm một dòng dọc ở 80 ký tự. Đây là tính năng bắt buộc phải có để giữ cho mã của bạn có thể đọc được và bạn có thể làm điều tương tự với Mã VS bằng cách chỉ định "editor.rulers" trong cài đặt người dùng của mình. Chi tiết hơn về cách định cấu hình có trong phần của bài đăng này có tên

Mã chạy

Đối với mã đang chạy trong RStudio, việc viết mã trong ngăn “Nguồn” (thường phía trên bảng điều khiển) là khá phổ biến, sau đó gửi mã tới ngăn “Bảng điều khiển” để chạy bằng cách sử dụng # region ---- code here... # endregion0 (# region ---- code here... # endregion1 nếu trên Windows – vui lòng giả sử . Trong Mã VS, bạn có thể coi ngăn Trình chỉnh sửa có cùng mục đích chính xác (viết tập lệnh), nhưng thay vì tìm nguồn dòng cho “Bảng điều khiển”, bạn sử dụng cùng một lệnh (# region ---- code here... # endregion0) để chạy mã trong Cửa sổ tương tác Python. Cụ thể hơn, phím tắt bạn cần đặt trong VS Code là dành cho lệnh # region ---- code here... # endregion5

Đây là một công cụ thay đổi cuộc chơi khi viết mã Python để phân tích vì bạn không còn cần phải viết mã trong Jupyter Notebook để thực hiện phân tích của mình. Chỉ cần viết mã của bạn vào tệp # region ---- code here... # endregion6 và nhấn # region ---- code here... # endregion0 để thực thi từng dòng một trong Cửa sổ tương tác Python. Lặp lại quy trình này khi bạn chạy mã, khám phá và xây dựng phân tích của mình. Lưu ý rằng bạn cũng có thể nhập Python trực tiếp vào Cửa sổ tương tác giống như bạn có thể nhập trực tiếp vào Bảng điều khiển của R để thực thi mã

Trình khám phá biến ("Môi trường" tab trong R)

Notebook luôn có vẻ rắc rối khi thực thi các dòng mã đơn lẻ và xem xét các biến trong môi trường chung, nhưng Mã VS có một trình khám phá biến giống như tab “Môi trường” trong R

Trình xem dữ liệu (Giống như chạy View() trong R)

Khi bạn đã tạo Khung dữ liệu gấu trúc, bạn có thể khám phá chế độ xem động của khung dữ liệu với tính năng lọc và sắp xếp cơ bản. Tôi thấy cái này giống hệt hàm View() trong RStudio. Sự khác biệt duy nhất là nó dường như gặp một chút khó khăn khi xem các khung dữ liệu trên 1 triệu hàng. Nó bị lag hoặc treo Mã VS, nhưng tôi không thấy đó là vấn đề quá lớn vì bạn luôn có thể lưu một mẫu tập dữ liệu của mình vào một biến hoặc tổng hợp dữ liệu của bạn trước khi xem

Plot Viewer (“tab Plots” trong R)

Bạn có thể lướt qua các ô trước đó, lưu chúng, thay đổi kích thước và tương tác với các ô giống như cách bạn thực hiện trong khung “Plots” của RStudio. Không có gì khác nhau ở đây

Kiểm soát phiên bản (“tab Git” trong R)

Giống như RStudio, bạn có thể sắp xếp các tệp, viết thông báo cam kết và đẩy vào kho lưu trữ git. Thay vì đánh dấu vào hộp kiểm để sắp xếp tệp, bạn sẽ phải nhấn dấu { "window.zoomLevel": 1, "explorer.confirmDelete": false, "explorer.confirmDragAndDrop": false, "files.associations": {}, "files.autoSave": "off", "files.exclude": { "**/.git": true, "**/.svn": true, "**/.hg": true, "**/CVS": true, "**/.DS_Store": true, "**/.history/**": true, "**/History_**": true }, "workbench.colorTheme": "textmate", "workbench.editor.enablePreview": false, "workbench.startupEditor": "welcomePageInEmptyWorkbench", "terminal.integrated.fontSize": 14, "terminal.integrated.cursorStyle": "line", "terminal.integrated.copyOnSelection": true, "terminal.integrated.confirmOnExit": false, "editor.largeFileOptimizations": false, "editor.suggest.shareSuggestSelections": true, "editor.suggestSelection": "first", "editor.minimap.enabled": false, "editor.foldingStrategy": "indentation", "editor.showFoldingControls": "always", "editor.rulers": [ 80 ], "editor.formatOnSave": true, "python.linting.enabled": true, "python.linting.flake8Enabled": true, "python.linting.flake8Args": [ "--ignore=E203, E266, E501, W503", "--max-line-length=79", "--select=B,C,E,F,W,T4,B9", "--max-complexity=18" ], "python.formatting.provider": "autopep8", "python.formatting.autopep8Args": [ "--ignore=E501,E402" ], "sonarlint.rules": { "python:S3776": { "level": "off" } }, "python.languageServer": "Microsoft", "python.dataScience.askForKernelRestart": false, "python.dataScience.runStartupCommands": "%load_ext autoreload\\n%autoreload 2", "python.dataScience.sendSelectionToInteractiveWindow": true, "python.dataScience.useNotebookEditor": false, "git.autofetch": true, "git.confirmSync": false, "gitlens.views.repositories.location": "gitlens", "gitlens.views.repositories.files.layout": "list", "gitlens.views.fileHistory.location": "gitlens", "gitlens.views.lineHistory.enabled": false, "gitlens.views.compare.location": "gitlens", "gitlens.views.search.location": "gitlens", "gitlens.mode.statusBar.enabled": true, "gitlens.mode.statusBar.alignment": "left", "gitlens.currentLine.enabled": false, "gitlens.hovers.enabled": false, "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue", "tabnine.experimentalAutoImports": true, "indentRainbow.errorColor": "rgba(255,255,255,0.0)", "todo-tree.tree.flat": true, "todo-tree.highlights.defaultHighlight": { "type": "text-and-comment", "foreground": "grey" }, "better-comments.tags": [ { "tag": "?", "color": "#8f5785", "strikethrough": false, "backgroundColor": "transparent" } { "tag": "*", "color": "#69a800", "strikethrough": false, "backgroundColor": "transparent" } ], "bracket-pair-colorizer-2.colors": [ "#992e24", "#ffb997", "#263859" ], "cSpell.userWords": [ "YYYYMMDD", "groupby", "idxmax", "inplace", "itertools", "multindex", "rfind", "strptime" ] }0, đây là điểm khác biệt duy nhất. Mọi thứ khác đều tương tự như cách nhấp vào tệp để xem “sự khác biệt”, viết thông báo cam kết và đẩy mã vào kho lưu trữ từ xa

Tất cả các tính năng git này thậm chí có thể được cải tiến tốt hơn với tiện ích mở rộng GitLens của Eric Amodio mà tôi thực sự khuyên dùng. Nó giúp điều hướng các nhánh dễ dàng hơn, xem khi nào các tệp được thay đổi và bởi ai

Điều gì còn thiếu hoặc khác biệt trong Mã VS?

Phác thảo tài liệu của R (còn gọi là Bản đồ nhỏ trong Mã VS)

RStudio tạo một phác thảo đẹp về các tập lệnh của bạn dựa trên các chức năng và nhận xét của bạn bắt đầu bằng

# A new section ---- code here...

Chế độ xem kiểu mục lục này rất hữu ích. Là một giải pháp thay thế hơi phù hợp, tôi đã quen với việc chú thích các khối mã Python bằng cú pháp gấp vùng để tạo các phần mã có thể thu gọn trong trình soạn thảo VS Code

# region ---- code here... # endregion

gỡ lỗi

RStudio có một tính năng hay sẽ hỏi bạn xem bạn có muốn chạy một đoạn mã với chế độ gỡ lỗi được bật hay không nếu ban đầu nó bị lỗi. Cửa sổ tương tác Python của VS Code cũng in ra các thông báo lỗi, nhưng sẽ không cho phép bạn gỡ lỗi bằng một nút bấm. Tuy nhiên, bạn có thể đặt các điểm dừng và chạy tập lệnh của mình ở chế độ gỡ lỗi, đây là một trải nghiệm quen thuộc, chỉ là không liền mạch như RStudio

Rõ ràng là có nhiều tính năng khác, như có thiết bị đầu cuối tích hợp, kết nối từ xa, phát triển ứng dụng qua Shiny, v.v. làm cho các công cụ R/RStudio và Python/VS Code khác nhau, nhưng nếu bạn chỉ đang chạy phân tích thì cả hai có thể cung cấp các quy trình công việc rất giống nhau, cho đến các phím tắt. Thách thức duy nhất mà bạn có thể còn lại là tìm ra cách làm cho mã gấu trúc của bạn dễ đọc và được tổ chức tốt như mã dplyr… nhưng đó là chuyện của một ngày khác. (Gợi ý. Có thể thực hiện được với cam kết mạnh mẽ đối với chuỗi phương thức)

Thiết lập tệp và tập lệnh

Cài đặt Tệp JSON

Để cập nhật tệp settings.json của bạn, hãy mở Bảng lệnh với { "window.zoomLevel": 1, "explorer.confirmDelete": false, "explorer.confirmDragAndDrop": false, "files.associations": {}, "files.autoSave": "off", "files.exclude": { "**/.git": true, "**/.svn": true, "**/.hg": true, "**/CVS": true, "**/.DS_Store": true, "**/.history/**": true, "**/History_**": true }, "workbench.colorTheme": "textmate", "workbench.editor.enablePreview": false, "workbench.startupEditor": "welcomePageInEmptyWorkbench", "terminal.integrated.fontSize": 14, "terminal.integrated.cursorStyle": "line", "terminal.integrated.copyOnSelection": true, "terminal.integrated.confirmOnExit": false, "editor.largeFileOptimizations": false, "editor.suggest.shareSuggestSelections": true, "editor.suggestSelection": "first", "editor.minimap.enabled": false, "editor.foldingStrategy": "indentation", "editor.showFoldingControls": "always", "editor.rulers": [ 80 ], "editor.formatOnSave": true, "python.linting.enabled": true, "python.linting.flake8Enabled": true, "python.linting.flake8Args": [ "--ignore=E203, E266, E501, W503", "--max-line-length=79", "--select=B,C,E,F,W,T4,B9", "--max-complexity=18" ], "python.formatting.provider": "autopep8", "python.formatting.autopep8Args": [ "--ignore=E501,E402" ], "sonarlint.rules": { "python:S3776": { "level": "off" } }, "python.languageServer": "Microsoft", "python.dataScience.askForKernelRestart": false, "python.dataScience.runStartupCommands": "%load_ext autoreload\\n%autoreload 2", "python.dataScience.sendSelectionToInteractiveWindow": true, "python.dataScience.useNotebookEditor": false, "git.autofetch": true, "git.confirmSync": false, "gitlens.views.repositories.location": "gitlens", "gitlens.views.repositories.files.layout": "list", "gitlens.views.fileHistory.location": "gitlens", "gitlens.views.lineHistory.enabled": false, "gitlens.views.compare.location": "gitlens", "gitlens.views.search.location": "gitlens", "gitlens.mode.statusBar.enabled": true, "gitlens.mode.statusBar.alignment": "left", "gitlens.currentLine.enabled": false, "gitlens.hovers.enabled": false, "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue", "tabnine.experimentalAutoImports": true, "indentRainbow.errorColor": "rgba(255,255,255,0.0)", "todo-tree.tree.flat": true, "todo-tree.highlights.defaultHighlight": { "type": "text-and-comment", "foreground": "grey" }, "better-comments.tags": [ { "tag": "?", "color": "#8f5785", "strikethrough": false, "backgroundColor": "transparent" } { "tag": "*", "color": "#69a800", "strikethrough": false, "backgroundColor": "transparent" } ], "bracket-pair-colorizer-2.colors": [ "#992e24", "#ffb997", "#263859" ], "cSpell.userWords": [ "YYYYMMDD", "groupby", "idxmax", "inplace", "itertools", "multindex", "rfind", "strptime" ] }2 và chọn { "window.zoomLevel": 1, "explorer.confirmDelete": false, "explorer.confirmDragAndDrop": false, "files.associations": {}, "files.autoSave": "off", "files.exclude": { "**/.git": true, "**/.svn": true, "**/.hg": true, "**/CVS": true, "**/.DS_Store": true, "**/.history/**": true, "**/History_**": true }, "workbench.colorTheme": "textmate", "workbench.editor.enablePreview": false, "workbench.startupEditor": "welcomePageInEmptyWorkbench", "terminal.integrated.fontSize": 14, "terminal.integrated.cursorStyle": "line", "terminal.integrated.copyOnSelection": true, "terminal.integrated.confirmOnExit": false, "editor.largeFileOptimizations": false, "editor.suggest.shareSuggestSelections": true, "editor.suggestSelection": "first", "editor.minimap.enabled": false, "editor.foldingStrategy": "indentation", "editor.showFoldingControls": "always", "editor.rulers": [ 80 ], "editor.formatOnSave": true, "python.linting.enabled": true, "python.linting.flake8Enabled": true, "python.linting.flake8Args": [ "--ignore=E203, E266, E501, W503", "--max-line-length=79", "--select=B,C,E,F,W,T4,B9", "--max-complexity=18" ], "python.formatting.provider": "autopep8", "python.formatting.autopep8Args": [ "--ignore=E501,E402" ], "sonarlint.rules": { "python:S3776": { "level": "off" } }, "python.languageServer": "Microsoft", "python.dataScience.askForKernelRestart": false, "python.dataScience.runStartupCommands": "%load_ext autoreload\\n%autoreload 2", "python.dataScience.sendSelectionToInteractiveWindow": true, "python.dataScience.useNotebookEditor": false, "git.autofetch": true, "git.confirmSync": false, "gitlens.views.repositories.location": "gitlens", "gitlens.views.repositories.files.layout": "list", "gitlens.views.fileHistory.location": "gitlens", "gitlens.views.lineHistory.enabled": false, "gitlens.views.compare.location": "gitlens", "gitlens.views.search.location": "gitlens", "gitlens.mode.statusBar.enabled": true, "gitlens.mode.statusBar.alignment": "left", "gitlens.currentLine.enabled": false, "gitlens.hovers.enabled": false, "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue", "tabnine.experimentalAutoImports": true, "indentRainbow.errorColor": "rgba(255,255,255,0.0)", "todo-tree.tree.flat": true, "todo-tree.highlights.defaultHighlight": { "type": "text-and-comment", "foreground": "grey" }, "better-comments.tags": [ { "tag": "?", "color": "#8f5785", "strikethrough": false, "backgroundColor": "transparent" } { "tag": "*", "color": "#69a800", "strikethrough": false, "backgroundColor": "transparent" } ], "bracket-pair-colorizer-2.colors": [ "#992e24", "#ffb997", "#263859" ], "cSpell.userWords": [ "YYYYMMDD", "groupby", "idxmax", "inplace", "itertools", "multindex", "rfind", "strptime" ] }3 để chỉnh sửa tệp JSON chứa cài đặt của bạn. Bạn có thể sao chép/dán toàn bộ khối JSON bên dưới hoặc chỉ từng dòng riêng lẻ

Ghi chú. Các tệp cài đặt này được tạo tự động từ cài đặt Mã VS của tôi bằng tiện ích mở rộng Đồng bộ hóa cài đặt của Shan Khan

cài đặt. json (Cài đặt người dùng, trái ngược với cài đặt dành riêng cho không gian làm việc/dự án)

________số 8_______

Phím tắt Tệp JSON

Cập nhật các phím tắt Tệp JSON tương tự như chỉnh sửa settings.json. Mở Bảng lệnh với { "window.zoomLevel": 1, "explorer.confirmDelete": false, "explorer.confirmDragAndDrop": false, "files.associations": {}, "files.autoSave": "off", "files.exclude": { "**/.git": true, "**/.svn": true, "**/.hg": true, "**/CVS": true, "**/.DS_Store": true, "**/.history/**": true, "**/History_**": true }, "workbench.colorTheme": "textmate", "workbench.editor.enablePreview": false, "workbench.startupEditor": "welcomePageInEmptyWorkbench", "terminal.integrated.fontSize": 14, "terminal.integrated.cursorStyle": "line", "terminal.integrated.copyOnSelection": true, "terminal.integrated.confirmOnExit": false, "editor.largeFileOptimizations": false, "editor.suggest.shareSuggestSelections": true, "editor.suggestSelection": "first", "editor.minimap.enabled": false, "editor.foldingStrategy": "indentation", "editor.showFoldingControls": "always", "editor.rulers": [ 80 ], "editor.formatOnSave": true, "python.linting.enabled": true, "python.linting.flake8Enabled": true, "python.linting.flake8Args": [ "--ignore=E203, E266, E501, W503", "--max-line-length=79", "--select=B,C,E,F,W,T4,B9", "--max-complexity=18" ], "python.formatting.provider": "autopep8", "python.formatting.autopep8Args": [ "--ignore=E501,E402" ], "sonarlint.rules": { "python:S3776": { "level": "off" } }, "python.languageServer": "Microsoft", "python.dataScience.askForKernelRestart": false, "python.dataScience.runStartupCommands": "%load_ext autoreload\\n%autoreload 2", "python.dataScience.sendSelectionToInteractiveWindow": true, "python.dataScience.useNotebookEditor": false, "git.autofetch": true, "git.confirmSync": false, "gitlens.views.repositories.location": "gitlens", "gitlens.views.repositories.files.layout": "list", "gitlens.views.fileHistory.location": "gitlens", "gitlens.views.lineHistory.enabled": false, "gitlens.views.compare.location": "gitlens", "gitlens.views.search.location": "gitlens", "gitlens.mode.statusBar.enabled": true, "gitlens.mode.statusBar.alignment": "left", "gitlens.currentLine.enabled": false, "gitlens.hovers.enabled": false, "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue", "tabnine.experimentalAutoImports": true, "indentRainbow.errorColor": "rgba(255,255,255,0.0)", "todo-tree.tree.flat": true, "todo-tree.highlights.defaultHighlight": { "type": "text-and-comment", "foreground": "grey" }, "better-comments.tags": [ { "tag": "?", "color": "#8f5785", "strikethrough": false, "backgroundColor": "transparent" } { "tag": "*", "color": "#69a800", "strikethrough": false, "backgroundColor": "transparent" } ], "bracket-pair-colorizer-2.colors": [ "#992e24", "#ffb997", "#263859" ], "cSpell.userWords": [ "YYYYMMDD", "groupby", "idxmax", "inplace", "itertools", "multindex", "rfind", "strptime" ] }2 và chọn { "window.zoomLevel": 1, "explorer.confirmDelete": false, "explorer.confirmDragAndDrop": false, "files.associations": {}, "files.autoSave": "off", "files.exclude": { "**/.git": true, "**/.svn": true, "**/.hg": true, "**/CVS": true, "**/.DS_Store": true, "**/.history/**": true, "**/History_**": true }, "workbench.colorTheme": "textmate", "workbench.editor.enablePreview": false, "workbench.startupEditor": "welcomePageInEmptyWorkbench", "terminal.integrated.fontSize": 14, "terminal.integrated.cursorStyle": "line", "terminal.integrated.copyOnSelection": true, "terminal.integrated.confirmOnExit": false, "editor.largeFileOptimizations": false, "editor.suggest.shareSuggestSelections": true, "editor.suggestSelection": "first", "editor.minimap.enabled": false, "editor.foldingStrategy": "indentation", "editor.showFoldingControls": "always", "editor.rulers": [ 80 ], "editor.formatOnSave": true, "python.linting.enabled": true, "python.linting.flake8Enabled": true, "python.linting.flake8Args": [ "--ignore=E203, E266, E501, W503", "--max-line-length=79", "--select=B,C,E,F,W,T4,B9", "--max-complexity=18" ], "python.formatting.provider": "autopep8", "python.formatting.autopep8Args": [ "--ignore=E501,E402" ], "sonarlint.rules": { "python:S3776": { "level": "off" } }, "python.languageServer": "Microsoft", "python.dataScience.askForKernelRestart": false, "python.dataScience.runStartupCommands": "%load_ext autoreload\\n%autoreload 2", "python.dataScience.sendSelectionToInteractiveWindow": true, "python.dataScience.useNotebookEditor": false, "git.autofetch": true, "git.confirmSync": false, "gitlens.views.repositories.location": "gitlens", "gitlens.views.repositories.files.layout": "list", "gitlens.views.fileHistory.location": "gitlens", "gitlens.views.lineHistory.enabled": false, "gitlens.views.compare.location": "gitlens", "gitlens.views.search.location": "gitlens", "gitlens.mode.statusBar.enabled": true, "gitlens.mode.statusBar.alignment": "left", "gitlens.currentLine.enabled": false, "gitlens.hovers.enabled": false, "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue", "tabnine.experimentalAutoImports": true, "indentRainbow.errorColor": "rgba(255,255,255,0.0)", "todo-tree.tree.flat": true, "todo-tree.highlights.defaultHighlight": { "type": "text-and-comment", "foreground": "grey" }, "better-comments.tags": [ { "tag": "?", "color": "#8f5785", "strikethrough": false, "backgroundColor": "transparent" } { "tag": "*", "color": "#69a800", "strikethrough": false, "backgroundColor": "transparent" } ], "bracket-pair-colorizer-2.colors": [ "#992e24", "#ffb997", "#263859" ], "cSpell.userWords": [ "YYYYMMDD", "groupby", "idxmax", "inplace", "itertools", "multindex", "rfind", "strptime" ] }6 để chỉnh sửa tệp JSON chứa cài đặt của bạn. Bạn có thể sao chép/dán toàn bộ khối JSON bên dưới hoặc chỉ từng dòng riêng lẻ

Ngoài việc đặt phím tắt # region ---- code here... # endregion0 để thực hiện các dòng trong Cửa sổ tương tác, tôi đã đặt một vài phím tắt khác để hoạt động chính xác như RStudio. Ví dụ: xóa bảng điều khiển và khởi động lại phiên R

  • { "window.zoomLevel": 1, "explorer.confirmDelete": false, "explorer.confirmDragAndDrop": false, "files.associations": {}, "files.autoSave": "off", "files.exclude": { "**/.git": true, "**/.svn": true, "**/.hg": true, "**/CVS": true, "**/.DS_Store": true, "**/.history/**": true, "**/History_**": true }, "workbench.colorTheme": "textmate", "workbench.editor.enablePreview": false, "workbench.startupEditor": "welcomePageInEmptyWorkbench", "terminal.integrated.fontSize": 14, "terminal.integrated.cursorStyle": "line", "terminal.integrated.copyOnSelection": true, "terminal.integrated.confirmOnExit": false, "editor.largeFileOptimizations": false, "editor.suggest.shareSuggestSelections": true, "editor.suggestSelection": "first", "editor.minimap.enabled": false, "editor.foldingStrategy": "indentation", "editor.showFoldingControls": "always", "editor.rulers": [ 80 ], "editor.formatOnSave": true, "python.linting.enabled": true, "python.linting.flake8Enabled": true, "python.linting.flake8Args": [ "--ignore=E203, E266, E501, W503", "--max-line-length=79", "--select=B,C,E,F,W,T4,B9", "--max-complexity=18" ], "python.formatting.provider": "autopep8", "python.formatting.autopep8Args": [ "--ignore=E501,E402" ], "sonarlint.rules": { "python:S3776": { "level": "off" } }, "python.languageServer": "Microsoft", "python.dataScience.askForKernelRestart": false, "python.dataScience.runStartupCommands": "%load_ext autoreload\\n%autoreload 2", "python.dataScience.sendSelectionToInteractiveWindow": true, "python.dataScience.useNotebookEditor": false, "git.autofetch": true, "git.confirmSync": false, "gitlens.views.repositories.location": "gitlens", "gitlens.views.repositories.files.layout": "list", "gitlens.views.fileHistory.location": "gitlens", "gitlens.views.lineHistory.enabled": false, "gitlens.views.compare.location": "gitlens", "gitlens.views.search.location": "gitlens", "gitlens.mode.statusBar.enabled": true, "gitlens.mode.statusBar.alignment": "left", "gitlens.currentLine.enabled": false, "gitlens.hovers.enabled": false, "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue", "tabnine.experimentalAutoImports": true, "indentRainbow.errorColor": "rgba(255,255,255,0.0)", "todo-tree.tree.flat": true, "todo-tree.highlights.defaultHighlight": { "type": "text-and-comment", "foreground": "grey" }, "better-comments.tags": [ { "tag": "?", "color": "#8f5785", "strikethrough": false, "backgroundColor": "transparent" } { "tag": "*", "color": "#69a800", "strikethrough": false, "backgroundColor": "transparent" } ], "bracket-pair-colorizer-2.colors": [ "#992e24", "#ffb997", "#263859" ], "cSpell.userWords": [ "YYYYMMDD", "groupby", "idxmax", "inplace", "itertools", "multindex", "rfind", "strptime" ] }8 – “Xóa Bảng điều khiển” (trong RStudio) => Xóa các ô (trong Cửa sổ tương tác Python)
  • { "window.zoomLevel": 1, "explorer.confirmDelete": false, "explorer.confirmDragAndDrop": false, "files.associations": {}, "files.autoSave": "off", "files.exclude": { "**/.git": true, "**/.svn": true, "**/.hg": true, "**/CVS": true, "**/.DS_Store": true, "**/.history/**": true, "**/History_**": true }, "workbench.colorTheme": "textmate", "workbench.editor.enablePreview": false, "workbench.startupEditor": "welcomePageInEmptyWorkbench", "terminal.integrated.fontSize": 14, "terminal.integrated.cursorStyle": "line", "terminal.integrated.copyOnSelection": true, "terminal.integrated.confirmOnExit": false, "editor.largeFileOptimizations": false, "editor.suggest.shareSuggestSelections": true, "editor.suggestSelection": "first", "editor.minimap.enabled": false, "editor.foldingStrategy": "indentation", "editor.showFoldingControls": "always", "editor.rulers": [ 80 ], "editor.formatOnSave": true, "python.linting.enabled": true, "python.linting.flake8Enabled": true, "python.linting.flake8Args": [ "--ignore=E203, E266, E501, W503", "--max-line-length=79", "--select=B,C,E,F,W,T4,B9", "--max-complexity=18" ], "python.formatting.provider": "autopep8", "python.formatting.autopep8Args": [ "--ignore=E501,E402" ], "sonarlint.rules": { "python:S3776": { "level": "off" } }, "python.languageServer": "Microsoft", "python.dataScience.askForKernelRestart": false, "python.dataScience.runStartupCommands": "%load_ext autoreload\\n%autoreload 2", "python.dataScience.sendSelectionToInteractiveWindow": true, "python.dataScience.useNotebookEditor": false, "git.autofetch": true, "git.confirmSync": false, "gitlens.views.repositories.location": "gitlens", "gitlens.views.repositories.files.layout": "list", "gitlens.views.fileHistory.location": "gitlens", "gitlens.views.lineHistory.enabled": false, "gitlens.views.compare.location": "gitlens", "gitlens.views.search.location": "gitlens", "gitlens.mode.statusBar.enabled": true, "gitlens.mode.statusBar.alignment": "left", "gitlens.currentLine.enabled": false, "gitlens.hovers.enabled": false, "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue", "tabnine.experimentalAutoImports": true, "indentRainbow.errorColor": "rgba(255,255,255,0.0)", "todo-tree.tree.flat": true, "todo-tree.highlights.defaultHighlight": { "type": "text-and-comment", "foreground": "grey" }, "better-comments.tags": [ { "tag": "?", "color": "#8f5785", "strikethrough": false, "backgroundColor": "transparent" } { "tag": "*", "color": "#69a800", "strikethrough": false, "backgroundColor": "transparent" } ], "bracket-pair-colorizer-2.colors": [ "#992e24", "#ffb997", "#263859" ], "cSpell.userWords": [ "YYYYMMDD", "groupby", "idxmax", "inplace", "itertools", "multindex", "rfind", "strptime" ] }9 – “Khởi động lại R” (trong RStudio) => Khởi động lại hạt nhân (trong Cửa sổ tương tác Python)

Tất nhiên, có những phím tắt khác mà bạn có thể định cấu hình như lệnh nhận xét khối của R (// Place your key bindings in this file to override the defaultsauto[] [ { "key": "cmd+enter", "command": "python.datascience.execSelectionInteractive", "when": "editorTextFocus && python.datascience.featureenabled && python.datascience.ownsSelection && !findInputFocussed && !notebookEditorFocused && !replaceInputFocussed && editorLangId == 'python'" }, { "key": "shift+enter", "command": "-python.datascience.execSelectionInteractive", "when": "editorTextFocus && python.datascience.featureenabled && python.datascience.ownsSelection && !findInputFocussed && !notebookEditorFocused && !replaceInputFocussed && editorLangId == 'python'" }, { "key": "cmd+enter", "command": "python.datascience.runcurrentcell", "when": "editorTextFocus && python.datascience.featureenabled && python.datascience.hascodecells && !editorHasSelection && !notebookEditorFocused" }, { "key": "ctrl+enter", "command": "-python.datascience.runcurrentcell", "when": "editorTextFocus && python.datascience.featureenabled && python.datascience.hascodecells && !editorHasSelection && !notebookEditorFocused" }, { "key": "cmd+enter", "command": "notebook.cell.executeAndSelectBelow", "when": "notebookEditorFocused && activeEditor == 'workbench.editor.notebook'" }, { "key": "shift+enter", "command": "-notebook.cell.executeAndSelectBelow", "when": "notebookEditorFocused && activeEditor == 'workbench.editor.notebook'" }, { "key": "ctrl+l", "command": "python.datascience.removeallcells", "when": "python.datascience.featureenabled && !terminalFocus" }, { "key": "ctrl+l", "command": "workbench.action.terminal.clear", "when": "terminalFocus" }, { "key": "cmd+shift+f10", "command": "python.datascience.restartkernel" }, { "key": "cmd+shift+c", "command": "editor.action.commentLine", "when": "editorTextFocus && !editorReadonly" }, { "key": "cmd+/", "command": "-editor.action.commentLine", "when": "editorTextFocus && !editorReadonly" }, { "key": "cmd+i", "command": "python.datascience.showhistorypane" }, { "key": "ctrl+shift+/", "command": "rewrap.rewrapComment", "when": "editorTextFocus" }, { "key": "alt+q", "command": "-rewrap.rewrapComment", "when": "editorTextFocus" }, { "key": "ctrl+shift+s", "command": "extension.updateSettings" }, { "key": "shift+alt+u", "command": "-extension.updateSettings" } ]0) (CMD+SHIFT+C). Chỉ cần đặt lệnh VS Code // Place your key bindings in this file to override the defaultsauto[] [ { "key": "cmd+enter", "command": "python.datascience.execSelectionInteractive", "when": "editorTextFocus && python.datascience.featureenabled && python.datascience.ownsSelection && !findInputFocussed && !notebookEditorFocused && !replaceInputFocussed && editorLangId == 'python'" }, { "key": "shift+enter", "command": "-python.datascience.execSelectionInteractive", "when": "editorTextFocus && python.datascience.featureenabled && python.datascience.ownsSelection && !findInputFocussed && !notebookEditorFocused && !replaceInputFocussed && editorLangId == 'python'" }, { "key": "cmd+enter", "command": "python.datascience.runcurrentcell", "when": "editorTextFocus && python.datascience.featureenabled && python.datascience.hascodecells && !editorHasSelection && !notebookEditorFocused" }, { "key": "ctrl+enter", "command": "-python.datascience.runcurrentcell", "when": "editorTextFocus && python.datascience.featureenabled && python.datascience.hascodecells && !editorHasSelection && !notebookEditorFocused" }, { "key": "cmd+enter", "command": "notebook.cell.executeAndSelectBelow", "when": "notebookEditorFocused && activeEditor == 'workbench.editor.notebook'" }, { "key": "shift+enter", "command": "-notebook.cell.executeAndSelectBelow", "when": "notebookEditorFocused && activeEditor == 'workbench.editor.notebook'" }, { "key": "ctrl+l", "command": "python.datascience.removeallcells", "when": "python.datascience.featureenabled && !terminalFocus" }, { "key": "ctrl+l", "command": "workbench.action.terminal.clear", "when": "terminalFocus" }, { "key": "cmd+shift+f10", "command": "python.datascience.restartkernel" }, { "key": "cmd+shift+c", "command": "editor.action.commentLine", "when": "editorTextFocus && !editorReadonly" }, { "key": "cmd+/", "command": "-editor.action.commentLine", "when": "editorTextFocus && !editorReadonly" }, { "key": "cmd+i", "command": "python.datascience.showhistorypane" }, { "key": "ctrl+shift+/", "command": "rewrap.rewrapComment", "when": "editorTextFocus" }, { "key": "alt+q", "command": "-rewrap.rewrapComment", "when": "editorTextFocus" }, { "key": "ctrl+shift+s", "command": "extension.updateSettings" }, { "key": "shift+alt+u", "command": "-extension.updateSettings" } ]1 thành phím tắt đó

Một ví dụ khác là lệnh của R (// Place your key bindings in this file to override the defaultsauto[] [ { "key": "cmd+enter", "command": "python.datascience.execSelectionInteractive", "when": "editorTextFocus && python.datascience.featureenabled && python.datascience.ownsSelection && !findInputFocussed && !notebookEditorFocused && !replaceInputFocussed && editorLangId == 'python'" }, { "key": "shift+enter", "command": "-python.datascience.execSelectionInteractive", "when": "editorTextFocus && python.datascience.featureenabled && python.datascience.ownsSelection && !findInputFocussed && !notebookEditorFocused && !replaceInputFocussed && editorLangId == 'python'" }, { "key": "cmd+enter", "command": "python.datascience.runcurrentcell", "when": "editorTextFocus && python.datascience.featureenabled && python.datascience.hascodecells && !editorHasSelection && !notebookEditorFocused" }, { "key": "ctrl+enter", "command": "-python.datascience.runcurrentcell", "when": "editorTextFocus && python.datascience.featureenabled && python.datascience.hascodecells && !editorHasSelection && !notebookEditorFocused" }, { "key": "cmd+enter", "command": "notebook.cell.executeAndSelectBelow", "when": "notebookEditorFocused && activeEditor == 'workbench.editor.notebook'" }, { "key": "shift+enter", "command": "-notebook.cell.executeAndSelectBelow", "when": "notebookEditorFocused && activeEditor == 'workbench.editor.notebook'" }, { "key": "ctrl+l", "command": "python.datascience.removeallcells", "when": "python.datascience.featureenabled && !terminalFocus" }, { "key": "ctrl+l", "command": "workbench.action.terminal.clear", "when": "terminalFocus" }, { "key": "cmd+shift+f10", "command": "python.datascience.restartkernel" }, { "key": "cmd+shift+c", "command": "editor.action.commentLine", "when": "editorTextFocus && !editorReadonly" }, { "key": "cmd+/", "command": "-editor.action.commentLine", "when": "editorTextFocus && !editorReadonly" }, { "key": "cmd+i", "command": "python.datascience.showhistorypane" }, { "key": "ctrl+shift+/", "command": "rewrap.rewrapComment", "when": "editorTextFocus" }, { "key": "alt+q", "command": "-rewrap.rewrapComment", "when": "editorTextFocus" }, { "key": "ctrl+shift+s", "command": "extension.updateSettings" }, { "key": "shift+alt+u", "command": "-extension.updateSettings" } ]2) bao bọc cứng mã thành 80 ký tự bằng cách sử dụng // Place your key bindings in this file to override the defaultsauto[] [ { "key": "cmd+enter", "command": "python.datascience.execSelectionInteractive", "when": "editorTextFocus && python.datascience.featureenabled && python.datascience.ownsSelection && !findInputFocussed && !notebookEditorFocused && !replaceInputFocussed && editorLangId == 'python'" }, { "key": "shift+enter", "command": "-python.datascience.execSelectionInteractive", "when": "editorTextFocus && python.datascience.featureenabled && python.datascience.ownsSelection && !findInputFocussed && !notebookEditorFocused && !replaceInputFocussed && editorLangId == 'python'" }, { "key": "cmd+enter", "command": "python.datascience.runcurrentcell", "when": "editorTextFocus && python.datascience.featureenabled && python.datascience.hascodecells && !editorHasSelection && !notebookEditorFocused" }, { "key": "ctrl+enter", "command": "-python.datascience.runcurrentcell", "when": "editorTextFocus && python.datascience.featureenabled && python.datascience.hascodecells && !editorHasSelection && !notebookEditorFocused" }, { "key": "cmd+enter", "command": "notebook.cell.executeAndSelectBelow", "when": "notebookEditorFocused && activeEditor == 'workbench.editor.notebook'" }, { "key": "shift+enter", "command": "-notebook.cell.executeAndSelectBelow", "when": "notebookEditorFocused && activeEditor == 'workbench.editor.notebook'" }, { "key": "ctrl+l", "command": "python.datascience.removeallcells", "when": "python.datascience.featureenabled && !terminalFocus" }, { "key": "ctrl+l", "command": "workbench.action.terminal.clear", "when": "terminalFocus" }, { "key": "cmd+shift+f10", "command": "python.datascience.restartkernel" }, { "key": "cmd+shift+c", "command": "editor.action.commentLine", "when": "editorTextFocus && !editorReadonly" }, { "key": "cmd+/", "command": "-editor.action.commentLine", "when": "editorTextFocus && !editorReadonly" }, { "key": "cmd+i", "command": "python.datascience.showhistorypane" }, { "key": "ctrl+shift+/", "command": "rewrap.rewrapComment", "when": "editorTextFocus" }, { "key": "alt+q", "command": "-rewrap.rewrapComment", "when": "editorTextFocus" }, { "key": "ctrl+shift+s", "command": "extension.updateSettings" }, { "key": "shift+alt+u", "command": "-extension.updateSettings" } ]3. Mã VS có thể làm điều tương tự sau khi cài đặt tiện ích mở rộng có tên là “rewrap” và sau đó đưa ra lệnh của nó // Place your key bindings in this file to override the defaultsauto[] [ { "key": "cmd+enter", "command": "python.datascience.execSelectionInteractive", "when": "editorTextFocus && python.datascience.featureenabled && python.datascience.ownsSelection && !findInputFocussed && !notebookEditorFocused && !replaceInputFocussed && editorLangId == 'python'" }, { "key": "shift+enter", "command": "-python.datascience.execSelectionInteractive", "when": "editorTextFocus && python.datascience.featureenabled && python.datascience.ownsSelection && !findInputFocussed && !notebookEditorFocused && !replaceInputFocussed && editorLangId == 'python'" }, { "key": "cmd+enter", "command": "python.datascience.runcurrentcell", "when": "editorTextFocus && python.datascience.featureenabled && python.datascience.hascodecells && !editorHasSelection && !notebookEditorFocused" }, { "key": "ctrl+enter", "command": "-python.datascience.runcurrentcell", "when": "editorTextFocus && python.datascience.featureenabled && python.datascience.hascodecells && !editorHasSelection && !notebookEditorFocused" }, { "key": "cmd+enter", "command": "notebook.cell.executeAndSelectBelow", "when": "notebookEditorFocused && activeEditor == 'workbench.editor.notebook'" }, { "key": "shift+enter", "command": "-notebook.cell.executeAndSelectBelow", "when": "notebookEditorFocused && activeEditor == 'workbench.editor.notebook'" }, { "key": "ctrl+l", "command": "python.datascience.removeallcells", "when": "python.datascience.featureenabled && !terminalFocus" }, { "key": "ctrl+l", "command": "workbench.action.terminal.clear", "when": "terminalFocus" }, { "key": "cmd+shift+f10", "command": "python.datascience.restartkernel" }, { "key": "cmd+shift+c", "command": "editor.action.commentLine", "when": "editorTextFocus && !editorReadonly" }, { "key": "cmd+/", "command": "-editor.action.commentLine", "when": "editorTextFocus && !editorReadonly" }, { "key": "cmd+i", "command": "python.datascience.showhistorypane" }, { "key": "ctrl+shift+/", "command": "rewrap.rewrapComment", "when": "editorTextFocus" }, { "key": "alt+q", "command": "-rewrap.rewrapComment", "when": "editorTextFocus" }, { "key": "ctrl+shift+s", "command": "extension.updateSettings" }, { "key": "shift+alt+u", "command": "-extension.updateSettings" } ]4 cùng một phím tắt. Tùy thuộc vào bạn để định cấu hình các phím tắt mà bạn sử dụng thường xuyên nhất

tổ hợp phím. json

// Place your key bindings in this file to override the defaultsauto[] [ { "key": "cmd+enter", "command": "python.datascience.execSelectionInteractive", "when": "editorTextFocus && python.datascience.featureenabled && python.datascience.ownsSelection && !findInputFocussed && !notebookEditorFocused && !replaceInputFocussed && editorLangId == 'python'" }, { "key": "shift+enter", "command": "-python.datascience.execSelectionInteractive", "when": "editorTextFocus && python.datascience.featureenabled && python.datascience.ownsSelection && !findInputFocussed && !notebookEditorFocused && !replaceInputFocussed && editorLangId == 'python'" }, { "key": "cmd+enter", "command": "python.datascience.runcurrentcell", "when": "editorTextFocus && python.datascience.featureenabled && python.datascience.hascodecells && !editorHasSelection && !notebookEditorFocused" }, { "key": "ctrl+enter", "command": "-python.datascience.runcurrentcell", "when": "editorTextFocus && python.datascience.featureenabled && python.datascience.hascodecells && !editorHasSelection && !notebookEditorFocused" }, { "key": "cmd+enter", "command": "notebook.cell.executeAndSelectBelow", "when": "notebookEditorFocused && activeEditor == 'workbench.editor.notebook'" }, { "key": "shift+enter", "command": "-notebook.cell.executeAndSelectBelow", "when": "notebookEditorFocused && activeEditor == 'workbench.editor.notebook'" }, { "key": "ctrl+l", "command": "python.datascience.removeallcells", "when": "python.datascience.featureenabled && !terminalFocus" }, { "key": "ctrl+l", "command": "workbench.action.terminal.clear", "when": "terminalFocus" }, { "key": "cmd+shift+f10", "command": "python.datascience.restartkernel" }, { "key": "cmd+shift+c", "command": "editor.action.commentLine", "when": "editorTextFocus && !editorReadonly" }, { "key": "cmd+/", "command": "-editor.action.commentLine", "when": "editorTextFocus && !editorReadonly" }, { "key": "cmd+i", "command": "python.datascience.showhistorypane" }, { "key": "ctrl+shift+/", "command": "rewrap.rewrapComment", "when": "editorTextFocus" }, { "key": "alt+q", "command": "-rewrap.rewrapComment", "when": "editorTextFocus" }, { "key": "ctrl+shift+s", "command": "extension.updateSettings" }, { "key": "shift+alt+u", "command": "-extension.updateSettings" } ]

Tập lệnh cài đặt tiện ích mở rộng

Bạn có thể chạy từng dòng bên dưới trong Terminal hoặc Dấu nhắc lệnh khác sau khi cài đặt Mã VS để cài đặt tiện ích mở rộng. Hoặc bạn có thể tìm kiếm chúng trong VS Code Marketplace (chi tiết có tại đây. )

# editor visual aids code --install-extension CoenraadS.bracket-pair-colorizer-2 code --install-extension oderwat.indent-rainbow code --install-extension gerane.Theme-textmate # development aids code --install-extension eamodio.gitlens code --install-extension aaron-bond.better-comments code --install-extension Gruntfuggly.todo-tree code --install-extension mikestead.dotenv code --install-extension streetsidesoftware.code-spell-checker # code formatting code --install-extension ms-python.python code --install-extension VisualStudioExptTeam.vscodeintellicode code --install-extension TabNine.tabnine-vscode code --install-extension christian-kohler.path-intellisense code --install-extension stkb.rewrap code --install-extension SonarSource.sonarlint-vscode # file viewer tools code --install-extension DotJoshJohnson.xml code --install-extension jithurjacob.nbpreviewer code --install-extension GrapeCity.gc-excelviewer # remote development tools code --install-extension ms-azuretools.vscode-docker code --install-extension ms-vscode-remote.remote-containers code --install-extension ms-vscode-remote.remote-ssh code --install-extension ms-vscode-remote.remote-ssh-edit code --install-extension ms-vscode-remote.remote-wsl code --install-extension ms-vscode-remote.vscode-remote-extensionpack # tool to save your settings as a gist code --install-extension Shan.code-settings-sync

Có liên quan

Chia sẻTweet

Để lại nhận xét cho tác giả, vui lòng theo liên kết và nhận xét trên blog của họ. stevenmortimer. com

Làm cách nào để đặt nhà cung cấp định dạng Python làm autopep8?

trường hợp định dạng. .
Cài mới VSCode mới
Cài đặt phần mở rộng Python
Cài đặt gói autopep8
Bật định dạng khi lưu
Đặt nhà cung cấp định dạng Python làm autopep8
Tạo một tệp python trống, được đặt tên là. py
Hang on Saving 'a. py'. Chạy Trình định dạng 'Python' (cấu hình)

Làm cách nào để định dạng mã Python?

Hoặc mở tệp của bạn trong trình chỉnh sửa và nhấn Ctrl+Alt+Shift+L hoặc trong cửa sổ Công cụ dự án, nhấp chuột phải vào tệp và chọn Mã định dạng lại.

Làm cách nào để bật intellisense trong mã phòng thu trực quan cho python?

Đầu tiên là intellisense. Tôi đã tải xuống tiện ích mở rộng python cho Mã, hứa hẹn intellisense. .
Mở bảng lệnh (Ctrl + Shift + P)
Gõ "Trăn. Build Workspace Symbols" và nhấn Enter

Chủ đề