Create a Python environment for professionals in VS Code on Windows

The following is assumed. I will also write the version at hand when creating the article.

goal

You can run a test in the sample case with Ctrl + Shift + B, Create an environment where you can manually execute a test with Ctrl + Shift + T.

Folder structure

I did the following. As one file for each question, throw it all under src.

work
│  cptest.bat
│  input.txt
│
├─.vscode
│      launch.json
│      settings.json
│      tasks.json
│
├─src
│      abc114_a.py
│
└─test

cptest.bat

cptest.bat


@echo off

set problemname=%1
set testdir=test\%problemname%
set baseurl=%problemname:~0,-2%
set baseurlreplaced=%baseurl:_=-%

rem # log in
oj login -u username -p password "https://atcoder.jp/"
oj login --check "https://atcoder.jp/"

rem # make test directory
if not exist %testdir% (
  oj dl -d test/%problemname%/ https://atcoder.jp/contests/%baseurlreplaced%/tasks/%problemname%
)

oj test -c "python src/%problemname%.py" -d test/%problemname%/

Description

It is a batch file that runs by giving one argument like cptest.bat abc114_a. In addition, conversion processing is forcibly inserted so that it works even with cptest.bat ddcc2020_qual_a. Change ʻusername and password in the line of ʻoj login -u appropriately before using. On the last line, assuming that the python command is in the path, it will slam and spit out the result to standard output.

input.txt

input.txt


(Write what you want to pass as standard input)

Description

It is a text file used like python xxxxx.py <input.txt. Write the input you want to test on your own.

launch.json

launch.json


{
  //You can use IntelliSense to learn the available attributes.
  //Hover and display the description of existing attributes.
  //Check the following for more information: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Python: Current File",
      "type": "python",
      "request": "launch",
      "program": "${file}",
      "console": "integratedTerminal",
      "args": [
        "<",
        "input.txt"
      ]
    }
  ]
}

Description

This is a configuration file for running the debugger with F5. The following is how to make: You can open debug by opening the .py file and then suddenly pressing F5. You can prepare the launch.json template by pressing" Add Configuration "on the screen below. image.png If you write around ʻargs` on the prepared template, it is completed.

tasks.json

tasks.json


{
  // See https://go.microsoft.com/fwlink/?LinkId=733558
  // for the documentation about the tasks.json format
  "version": "2.0.0",
  "tasks": [
    {
      "label": "test_atcorder_sample",
      "group": {
        "kind": "build",
        "isDefault": true
      },
      "type": "shell",
      "command": "${workspaceFolder}/cptest.bat",
      "args": [
        "${fileBasenameNoExtension}"
      ],
      "problemMatcher": []
    },
    {
      "label": "test_manual_input",
      "group": {
        "kind": "test",
        "isDefault": true
      },
      "type": "shell",
      "command": "python",
      "args": [
        "${file}",
        "<",
        "input.txt"
      ]
    }
  ]
}

Description

This is a configuration file for writing Ctrl + Shift + B (build task) and Ctrl + Shift + T (test task). The following is how to make: If you suddenly press Ctrl + Shift + B after opening the .py file, the following screen will appear and you can prepare a template for tasks.json. image.png It is completed by editing the prepared template.

abc114_a.py

abc114_a.py


def main():
    x = int(input())
    ans = "NO"
    if (x == 7 or x == 5 or x == 3):
        ans = "YES"

    print(ans)

if __name__ == '__main__':
    main()

Description

Be careful with the file name so that it is [contest name] _ [problem name] .py. In the above case, write the code to solve the A problem of ABC114.

Operation

Create a .py file with an appropriate file name under src according to the contest. After making an answer, check the operation of the sample case with Ctrl + Shift + B, and submit it as it is if you like. If you notice a suspicious part, change ʻinput.txt as appropriate, check the operation with F5orCtrl + Shift + T`, correct it and submit it.

reference

Building a competitive professional environment with Visual Studio Code (Practice) --Qiita

Recommended Posts

Create a Python environment for professionals in VS Code on Windows
Steps to create a Python virtual environment with VS Code on Windows
Create a Python virtual development environment on Windows
Create a Python development environment on Windows (Visual Studio Code remote WSL).
Create a comfortable Python 3 (Anaconda) development environment on windows
Procedure for building a CDK environment on Windows (Python)
Create a decent shell and python environment on Windows
Create a Python environment on Mac (2017/4)
Create a Linux environment on Windows 10
Create a python environment on centos
How to use VS Code in venv environment on windows
Create a VS Code + Docker development environment on a Linux VM
Create a virtual environment for python on mac [Very easy]
Create a python environment on your Mac
Let's create a virtual environment for Python
Creating a python virtual environment on Windows
Create a Python execution environment for Windows with VScode + Remote WSL
Create a simple Python development environment with VS Code and Docker
Create a Python environment
Create a Vim + Python test environment in 1 minute
Simply build a Python 3 execution environment on Windows
Python (Windows 10) Virtual Environment / Package with VS Code
Create a virtual environment with conda in Python
[Venv] Create a python virtual environment on Ubuntu
Use Python in Anaconda environment with VS Code
Create a Python execution environment on IBM i
[Docker] Create a jupyterLab (python) environment in 3 minutes!
Build a python execution environment with VS Code
Prepare a Python virtual environment for your project with venv with VS Code
Create a Python development environment in 10 minutes (Mac OS X + Visual Studio Code)
Python with VS Code (Windows 10)
Build a GVim-based Python development environment on Windows 10 (3) GVim8.0 & Python3.6
Create a function in Python
Create a dictionary in Python
Create a QR code for the URL on Linux
Build a Python extension for E-Cell 4 on Windows 7 (64bit)
Until drawing a 3D graph in Python on windows10
VS Code settings for developing in Python with completion
Build a GVim-based Python development environment on Windows 10 (1) Installation
Build Python environment on Windows
Build python environment on windows
Expose settings.json for efficient Python coding in VS Code
Create a Python development environment on OS X Lion
I tried to build an environment with WSL + Ubuntu + VS Code in a Windows environment
Create an exe file that works in a Windows environment without Python with PyInstaller
What to do if Python IntelliSense is not displayed in VS Code on Windows
Until you create a machine learning environment with Python on Windows 7 and run it
Create a Python (pyenv / virtualenv) development environment on Mac (Homebrew)
Create a list in Python with all followers on twitter
Create a child account for connect with Stripe in Python
Building a development environment for Android apps-creating Android apps in Python
Build a GVim-based Python development environment on Windows 10 (2) Basic settings
Create code that outputs "A and pretending B" in python
Create a Python script for Wake on LAN (NAT traversal Wake on LAN [5])
UpNext2 Development Record # 1 Build Python CI environment in VS Code
Build a Python environment with WSL + Pyenv + Jupyter + VS Code
Build a python environment on CentOS 7.7 for your home server
[Python] Create a screen for HTTP status code 403/404/500 with Django
Building a Python environment on Mac
Python environment construction memo on Windows 10
Hit a command in Python (Windows)