Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kdcllc/csharptopythonlearning
C# Developer's Exciting Journey into Python World 🐍
https://github.com/kdcllc/csharptopythonlearning
csharp pip poetry-python python python3
Last synced: 6 days ago
JSON representation
C# Developer's Exciting Journey into Python World 🐍
- Host: GitHub
- URL: https://github.com/kdcllc/csharptopythonlearning
- Owner: kdcllc
- License: gpl-3.0
- Created: 2023-08-13T13:59:24.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-08-02T18:51:46.000Z (3 months ago)
- Last Synced: 2024-08-03T21:29:50.677Z (3 months ago)
- Topics: csharp, pip, poetry-python, python, python3
- Language: Jupyter Notebook
- Homepage:
- Size: 218 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# C# Developer's Exciting Journey into Python World 🐍
![I stand with Israel](./images/IStandWithIsrael.png)
Embark on an exhilarating voyage as a C# developer diving headfirst into the captivating realm of Python! This GitHub repository chronicles the adventures, challenges, and triumphs of a seasoned C# developer as they navigate the exciting landscape of Python programming. From mastering Python's elegant syntax to exploring its rich ecosystem of libraries and frameworks, follow along as we uncover the synergies between these two powerful languages. Whether you're a fellow developer looking to expand your horizons or a curious learner eager to understand the nuances of Python from a C# perspective, this repository offers insightful code examples, tutorials, and resources to make your transition smooth and enjoyable. Join us on this transformative journey, where the familiarity of C# meets the versatility of Python, creating a holistic skill set that's bound to shape the future of your development endeavors. 🚀🐍 Let's code, learn, and grow together!
## Hire mePlease send [email](mailto:[email protected]) if you consider to **hire me**.
[![buymeacoffee](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/vyve0og)
## Give a Star! :star
If you like or are using this project to learn or start your solution, please give it a star. Thanks!
## Key Differences and Similarities Between C# and Python
- **Syntax**: Python's syntax is more concise and readable compared to C#. Indentation is significant in Python.
- **Type System**: Python is dynamically typed, whereas C# is statically typed.
- **Memory Management**: Both languages use garbage collection, but Python's memory management is more automated.
- **Libraries and Frameworks**: Python has a rich ecosystem of libraries for data science, web development, and more.## Advanced Topics
- **Performance Optimization**: Strategies for profiling and optimizing Python code.
- **Concurrency**: Using `asyncio`, threading, and multiprocessing in Python.
- **Integration**: Interfacing Python with C# and other languages.## Tooling and Best Practices
- **Virtual Environments**: Use `venv` or `virtualenv` to manage dependencies.
- **Package Management**: Use `pip` for installing packages and `pipenv` or `poetry` for managing dependencies.
- **Code Quality**: Tools like `flake8`, `pylint`, and `black` for linting and formatting.
- **Testing**: Frameworks like `unittest`, `pytest`, and `nose` for writing tests.## VSCode Python Extensions
- [Python extension for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=ms-python.python)
- Provides rich support for the Python language, including features like IntelliSense, linting, debugging, and more.
- [Pylance](https://marketplace.visualstudio.com/items?itemName=ms-python.vscode-pylance)
- A performant, feature-rich language server for Python in VSCode, offering fast IntelliSense and type checking.
- [Ruff extension for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=charliermarsh.ruff)
- A fast Python linter, written in Rust, that integrates seamlessly with VSCode.
- [Import sorting extension for Visual Studio Code using isort](https://marketplace.visualstudio.com/items?itemName=ms-python.isort)
- Automatically sorts Python imports according to PEP8 standards.
- [IntelliCode](https://marketplace.visualstudio.com/items?itemName=VisualStudioExptTeam.vscodeintellicode)
- AI-assisted code completions and recommendations based on best practices from open-source projects.
- [Error Lens](https://marketplace.visualstudio.com/items?itemName=usernamehw.errorlens)
- Highlights errors and warnings directly in the code, making them more visible.
- [Indent-Rainbow](https://marketplace.visualstudio.com/items?itemName=oderwat.indent-rainbow)
- Adds color to indentation levels, making it easier to read and understand code structure.
- [Mypy extension](https://marketplace.visualstudio.com/items?itemName=ms-python.mypy-type-checker)
- Integrates Mypy type checking into VSCode, helping to catch type errors early.
- [Django extension](https://marketplace.visualstudio.com/items?itemName=batisteo.vscode-django)
- Provides support for Django development, including features like template debugging and model completion.
- [Jinja extension](https://marketplace.visualstudio.com/items?itemName=wholroyd.jinja)
- Adds syntax highlighting and other features for Jinja templates.### Additional Helpful Extensions
- [Python Docstring Generator](https://marketplace.visualstudio.com/items?itemName=njpwerner.autodocstring)
- Automatically generates docstrings for your Python functions and classes.
- [Python Test Explorer](https://marketplace.visualstudio.com/items?itemName=LittleFoxTeam.vscode-python-test-adapter)
- A test explorer for running and debugging Python tests in VSCode.
- [Python Environment Manager](https://marketplace.visualstudio.com/items?itemName=donjayamanne.python-environment-manager)
- Helps manage Python environments and virtual environments within VSCode.
- [Python Snippets](https://marketplace.visualstudio.com/items?itemName=frhtylcn.pythonsnippets)
- Provides a collection of useful Python code snippets to speed up development.## Linux Ubuntu DevBox Setup
Ubuntu 22.04 comes with Python `3.10.12`.
### How to Install and Manage Other Versions of Python Interpreters
The default Python interpreter is located at `/usr/bin/python3`.
#### Display All Installed Dependencies
To list all installed Python dependencies, use the following command:
```bash
apt list --installed | grep python
```### Installing Multiple Versions of Python and Switching Between Them
[`pyenv`](https://github.com/pyenv/pyenv) is a utility for managing multiple Python versions, similar to [`nvm`](https://github.com/nvm-sh/nvm) for Node.js.
An alternative method is to use `apt`:
```bash
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install python3.5
```### Install [pyenv](https://github.com/pyenv/pyenv)
#### Install Dependencies
This script installs the necessary dependencies and clones the `pyenv` repository.
```bash
# Prerequisites
sudo apt install libedit-dev
sudo apt uninstall python3-pip
sudo apt-get install build-essential zlib1g-dev libffi-dev libssl-dev libbz2-dev libreadline-dev libsqlite3-dev liblzma-dev
sudo apt-get install python-tk python3-tk tk-dev
```#### Install `pyenv`
```bash
curl https://pyenv.run | bash
```#### Update `~/.bashrc` File
Add the following lines to the end of your `~/.bashrc` file to initialize `pyenv`:
```bash
export PYENV_ROOT="$HOME/.pyenv"
[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"# Build Location
export TMPDIR="$HOME/.pyenv-tmp"# Load Virtualenv
# Load pyenv-virtualenv automatically by adding
# the following to ~/.bashrc:
eval "$(pyenv virtualenv-init -)"
```#### Install the Latest Version of Python
```bash
pyenv install --list | grep " 3\.[12]"# Downloads and builds the specified version
pyenv install 3.12.3# List installed versions
pyenv versions# Set global Python version
pyenv global 3.12.3
```![env](images/pyenv-python-version.png)
[pyenv-virtualenv](https://github.com/pyenv/pyenv-virtualenv)
### Install Aider or Poetry Virtual Environments
Once you have multiple Python versions running, you may need to set up global dependencies for your projects.
#### Aider
[aider](https://github.com/paul-gauthier/aider) is a tool for managing virtual environments.
```bash
# Create an environment
pyenv virtualenv 3.12.3 aider# Display newly created environment
pyenv versions# Activate the environment
pyenv activate aider# Deactivate the environment
pyenv deactivate# Install aider
pip install aider-chat# Display the number of installed packages
pip freeze | wc -l
```By default, auto-commit changes are enabled. To override the default, add the following line to your `~/.bashrc` file:
```bash
export AIDER_AUTO_COMMITS=0
```To add this automatically from a bash command, you can use the following script:
```bash
echo 'export AIDER_AUTO_COMMITS=0' >> ~/.bashrc
source ~/.bashrc
``````bash
#OLLAMA_API_BASE=http://localhost:11434/# https://aider.chat/docs/llms.html#azure
# aider --model azure/gpt-4-32k --no-auto-commitsAZURE_API_KEY=
AZURE_API_VERSION=
AZURE_API_BASE=# https://github.com/paul-gauthier/aider/issues/596
# https://aider.chat/docs/llms.html#ollama
# export OLLAMA_API_BASE=http://127.0.0.1:11434
# aider --model ollama/mistral:latest
# aider --model ollama/codellama:7b --no-auto-commits
```
#### Poetry[Poetry](https://python-poetry.org/) is another tool for dependency management and packaging in Python.
```bash
# Create an environment
pyenv virtualenv 3.12.3 poetry# Display newly created environment
pyenv versions# Activate the environment
pyenv activate poetry# Deactivate the environment
pyenv deactivate# Install Poetry
curl -sSL https://install.python-poetry.org | python -# Configure Poetry to create virtual environments inside the project directory
poetry config virtualenvs.in-project true# Create a new Poetry project
poetry new my-project# Navigate to the project directory
cd my-project# Add dependencies
poetry add requests# Activate the virtual environment
poetry shell# Deactivate the virtual environment
exit
```### Additional Useful Commands
#### Updating Python Packages
To update all installed Python packages, use the following command:
```bash
pip list --outdated | grep -v '^\-e' | cut -d ' ' -f1 | xargs -n1 pip install -U
```#### Uninstalling Python Packages
To uninstall a Python package, use the following command:
```bash
pip uninstall
```#### Creating and Managing Virtual Environments with `venv`
To create a virtual environment using `venv`, use the following command:
```bash
python3 -m venv myenv
```To activate the virtual environment:
```bash
source myenv/bin/activate
```To deactivate the virtual environment:
```bash
deactivate
```#### Checking Python Version
To check the current Python version, use the following command:
```bash
python --version
```#### Basic Git Commands
To initialize a new Git repository:
```bash
git init
```To clone an existing repository:
```bash
git clone
```To check the status of your repository:
```bash
git status
```To add changes to the staging area:
```bash
git add
```To commit changes:
```bash
git commit -m "Your commit message"
```To push changes to a remote repository:
```bash
git push origin
```## Resources
- [CPython internals - Interpreter and source code overview](https://www.youtube.com/watch?v=LhadeL7_EIU&list=PLzV58Zm8FuBL6OAv1Yu6AwXZrnsFbbR0S)
- [Language syntax specific practices](./practices)
- [VSCode python specific extensions](vscode-python-extensions.md)
- [Python3 dependencies and package management](./deps-management)
- [Python3 and databases](./databases)
- [Python3 and Azure Development](./azure/)## Questions
1. **How do I choose the right Python version for my project?**
- Understanding which Python version suits your project's requirements is crucial. Are you using Python 2.x or Python 3.x? How do you make the choice?
2. **What are virtual environments, and why should I use them?**- Exploring the concept of virtual environments to isolate project dependencies and avoid version conflicts. How do you create and manage virtual environments in Python?
3. **How can I effectively manage project dependencies?**- Discussing package management tools like pip and exploring methods for defining and maintaining project dependencies.
4. **What's the best way to handle configuration settings in Python projects?**- Strategies for managing configuration settings, such as using configuration files or environment variables.
5. **How do I write clean and maintainable code in Python?**- Best practices for Python code formatting, naming conventions, and code organization to enhance readability and maintainability.
6. **What's the role of documentation in Python development?**- The importance of documentation, including docstrings, comments, and generating documentation for your code using tools like Sphinx.
7. **How do I implement error handling and debugging in Python?**- Techniques for handling exceptions, logging, and debugging to ensure robust and bug-free code.
8. **What are Pythonic coding practices, and why are they essential?**- Understanding Pythonic coding principles, which emphasize readability and simplicity. How to write idiomatic Python code?
9. **What are the different testing frameworks available for Python, and how do I write effective tests?**- Exploring testing frameworks like unittest, pytest, and nose, and learning how to create comprehensive test suites.
10. **How do I integrate version control into my Python project?**- Setting up and using version control systems like Git to track changes, collaborate with a team, and manage project history.
11. **How can I optimize the performance of my Python application?**- Strategies for profiling and optimizing Python code, including identifying bottlenecks and implementing performance enhancements.
12. **What are the security considerations when developing with Python?**- Addressing security concerns such as input validation, handling sensitive data, and protecting against common vulnerabilities.
13. **How do I handle data storage and databases in Python projects?**- Discussing options for working with databases, including using SQLite, PostgreSQL, or other database systems, as well as ORM (Object-Relational Mapping) libraries.
14. **What steps are involved in deploying a Python application to a production environment?**- The process of preparing and deploying a Python application to a production server, including considerations for scalability and reliability.
15. **How can I keep my Python project up-to-date and maintainable over time?**- Strategies for continuous integration and continuous deployment (CI/CD), code review, and long-term project maintenance.
These questions cover various aspects of the software development process with Python, helping programmers gain a comprehensive understanding of how to create robust, maintainable, and efficient Python applications.
## Additional Resources
- [`python` documentation](https://docs.python.org/3/)
- [`pip` documentation](https://pip.pypa.io/en/stable/)
- [`setuptools` documentation](https://setuptools.pypa.io/en/latest/userguide/quickstart.html)
- [`pyenv` documentation](https://github.com/pyenv/pyenv)
- [Programming For Everybody](https://online.dr-chuck.com/)