Skip to main content

Posts

Showing posts with the label Python

How to debug Python code in VS Code with arguments passed from command line

 Debugging Python code in VS Code with arguments passed from the command line is a straightforward process. Here are the steps you can follow: 1. Open the Python file that you want to debug in VS Code. 2. Set breakpoints in the code where you want to pause and inspect variables. 3. Open the Debug panel in VS Code by clicking on the Debug icon in the Activity Bar or by pressing `Ctrl+Shift+D` on Windows or `Cmd+Shift+D` on Mac. 4. Click on the "create a launch.json file" button and select "Python" as the environment. 5. In the launch.json file that opens, modify the "args" attribute to include the command-line arguments you want to pass to the Python script. For example:    ```    "args": ["arg1", "arg2"]    ```    Replace "arg1" and "arg2" with the actual arguments you want to pass. NOTE: Add the below property in the launch.json file.     "purpose" : [ "debug-in-terminal" ] 6. Save the ...

Regular Expressions

Regular Expressions List of meta characters: . ---> Any one character ? ---> Zero or one + ---> One or more * ---> zero or more ^ ---> at the beginning of the string $ ---> at the end of the string [abc] ---> any one of a b c {m} ---> 'm' times {m,n} ---> at least m times, at most n times | ---> or \ ---> escape sequence character \s ---> a space \d ---> a digit \w ---> a word \b ---> a word boundary examples: \d ---> a single digit number (0 to 9) \d\d ---> a two digit number (0 to 99) \d\d\d ---> a three digit number (000 to 999) NOTE: ?, +, *, {} are used as Quantifiers (to represent quantity) \d{3} ---> same as above \d{3,5} ---> either 3 digit or 5 digit number hell?o ---> helo | hello hell+o ---> hello | helllo | helllllo | ... hrll*o ---> helo | hello | helllo | helllllo | ... he(ll)+o ---> hello | hellllo | hellllllo | ... S = "hi hello how are hello" hello ---> Yes ^hello ---> No h...

Installing pip with get-pip.py in a Python virtual environment on Windows MacOS & Linux

To create a Python virtual environment type below commands on the required console prompt: On Windows     python -m venv ./venv     .\venv\Scripts\activate On Ubuntu     python3 -m venv ./venv      source ./venv/bin/activate There are some exceptional cases where vent creation might fail. Here are some workarounds - https://askubuntu.com/questions/1268833/error-command-path-to-env-bin-python3-7-im-ensurepip-upgrade Exiting a Python Virtual Environment 1 2 3 To exit a Python virtual environment, you can use the  deactivate  command. This command is available in most Unix-like systems and Windows. Example $ deactivate Steps to Exit Virtual Environment 1. Using deactivate Command The most common way to exit a virtual environment is by using the  deactivate  command 1 . Example: $ deactivate 2. Using source deactivate In some cases, especially with certain virtual environment management tools like  virt...