0% found this document useful (0 votes)
5 views5 pages

Python Notes Set 4

The document provides a guide on Python virtual environments, package management with pip, unit testing using unittest, logging practices, and Python coding style according to PEP 8. It includes commands for creating and managing virtual environments, installing and uninstalling packages, writing unit tests, and configuring logging levels. Additionally, it emphasizes coding conventions such as indentation, line length, and naming conventions.

Uploaded by

fake786king
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views5 pages

Python Notes Set 4

The document provides a guide on Python virtual environments, package management with pip, unit testing using unittest, logging practices, and Python coding style according to PEP 8. It includes commands for creating and managing virtual environments, installing and uninstalling packages, writing unit tests, and configuring logging levels. Additionally, it emphasizes coding conventions such as indentation, line length, and naming conventions.

Uploaded by

fake786king
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Page 1: Python Virtual Environments

- Isolate dependencies per project

Create:

python -m venv env

Activate:

- Windows: env\Scripts\activate

- Unix/Mac: source env/bin/activate

Deactivate:

deactivate
Page 2: pip and Package Management

Install:

pip install package-name

Uninstall:

pip uninstall package-name

List installed:

pip list

Freeze (for [Link]):

pip freeze > [Link]


Page 3: Unit Testing

import unittest

class TestMath([Link]):

def test_add(self):

[Link](1 + 1, 2)

if __name__ == '__main__':

[Link]()

Assertions:

- assertEqual, assertTrue, assertRaises, etc.


Page 4: Logging

import logging

[Link](level=[Link])

[Link]("This is an info message")

[Link]("Warning!")

Levels:

DEBUG < INFO < WARNING < ERROR < CRITICAL


Page 5: Python Coding Style (PEP 8)

- Use 4 spaces for indentation

- Limit lines to 79 characters

- Use meaningful variable names

- Class names: CamelCase

- Function/variable names: snake_case

Use tools like flake8 or black for formatting

You might also like