Skip to content

platformps/GLAB-370.3.1-Automatic-Code-Formatting-with-IDE

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 

Repository files navigation

GLAB-370.3.1 Guided Lab: Automatic Code Formatting with IDE

Introduction

Welcome to GLAB-370.3.1! In this guided lab, you will learn how to utilize the power of an Integrated Development Environment (IDE) to automatically format your Python code. Code formatting plays a crucial role in improving code readability and maintainability. Let's dive into the lab and discover how your IDE can assist you in this process.

Prerequisites

To fully benefit from this guided lab, you should have a basic understanding of Python syntax and be familiar with an IDE capable of automatic code formatting. We will use Visual Studio Code (VS Code) as an example in this lab.

Instructions

Step 1: Setting Up Visual Studio Code

ACT-370.1.1-InstallingPython

Step 2: Opening a Python File

  • Launch Visual Studio Code.
  • Open an existing Python file or create a new Python file by selecting "File" -> "New File" and saving it with a .py extension.

Step 3: Formatting Code with Autopep8 Extension

To automatically format your Python code in VS Code, we'll use the "Autopep8" extension. Follow these steps to install and utilize the extension:

  • Click on the "Extensions" icon in the left sidebar (or press Ctrl+Shift+X).
  • In the search bar, type "autopep8" and press Enter.
  • Look for the "Python - Autopep8" extension by "himanoa" in the search results and click on the "Install" button.
  • Once the installation is complete, open a Python file in VS Code.
  • Right-click within the editor or use the shortcut Ctrl+Shift+P to open the command palette.
  • Search for "Format Document" and select it. Alternatively, you can use the shortcut Shift+Alt+F.
  • Watch as your Python code gets automatically formatted according to the PEP 8 style guide.

Step 4: Configuring Formatting Rules

If you wish to customize the formatting rules used by Autopep8, you can configure it in your VS Code settings. Follow these steps:

  • Go to "File" -> "Preferences" -> "Settings" (or use the shortcut Ctrl+,).
  • In the search bar at the top, type "autopep8" to filter the settings.
  • Adjust the desired settings according to your preferences. For example, you can configure the line length or choose whether to sort the imports.
  • Save the changes to apply the new formatting rules.

Step 5: Experiment and Observe

Now it's time to experiment with automatic code formatting. Try writing some Python code in your file, intentionally introducing formatting issues like incorrect indentation, inconsistent spacing, or missing line breaks. After writing the code, follow Step 3 to format the document and observe how Autopep8 automatically corrects the formatting issues.

Submission

To further reinforce your understanding and share your knowledge with your instructor, we encourage you to submit one of the following:

Code Snippet: Share a code snippet from your lab exercise where you used automatic code formatting with Autopep8. Include both the original unformatted code and the formatted version. Explain how the automatic formatting improved the readability and structure of the code.

Summary of Experience: Write a brief summary of your experience with automatic code formatting. Share any insights, challenges, or surprises you encountered during the lab. Discuss how you plan to incorporate automatic code formatting into your future coding practices.

Conclusion

Congratulations on completing the Guided Lab on automatic code formatting with your IDE! You have learned how to leverage the power of an IDE, such as Visual Studio Code, to automatically format your Python code using the Autopep8 extension. By adopting automatic code formatting, you can enhance the readability, maintainability, and consistency of your code. Continue to utilize this practice in your future projects to optimize your coding workflow. Happy coding!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors