Competitive programming with python Local environment settings

Use paiza's skill check to study python. Among them, I thought about a configuration to reproduce the standard input locally and test it, so make a note. Please point out any typos, more efficient ways, etc.

__ Added on December 30, 2016 __ __ There is no need to take such a method, and clarinet758 commented. Everything was OK with the following method. __

$ python ./answer.py < ./input.txt

Preparation

Installation of python3. Introduction of pyperclip used for copying the clipboard Reference: Clipboard operation with python

Directory structure

.
├── answer.py #File for improving the production environment
├── conv.py #File for local conversion
├── input.txt #Input example file
└── proto.py #Main program description file

File contents

answer.py and input.py are empty at first, so the other two.

proto.py --For writing the main program

proto.py


#Creating a local execution environment
#Open file

inp =  open("input.txt", mode="r")

#----Program from here----



#----Program so far----

#File close
inp.close()

conv.py --For local specific description conversion

conv.py


#Regular expression import
import re
#Module import copy to clipboard
import pyperclip

#Read file for conversion
with open("proto.py", mode="r") as prot, open("answer.py", mode="w") as answ:
    #Loading the local environment
    for line in prot:
        #Replace keywords dedicated to local development environment with standard input
        tmp = line.replace('inp =  open("input.txt", mode="r")','')\
                 .replace('inp.readline()','input()')\
                 .replace('inp.close()','')
        #Delete comment
        tmp = re.sub(r'#.*','',tmp)
        #Export other than blank lines
        if tmp != '\n':
            answ.write(tmp)

#Load the answer for clipboard copy
with open("answer.py", mode="r") as answ:
    pyperclip.copy(answ.read())

procedure

1. Add input example, get standard input

First, copy and paste the standard input input example into input.txt as it is. Also, program from the comment of proto.py-Program from here. For standard input, get line by line with the following code.

proto.py


#For 1 row 1 data
date = inp.readline().rstrip() #rstrip removes rightmost blanks and line breaks

#For multiple data per line
date = inp.readline().rstrip().split(' ') #List by blank delimiter by split

2. Programming, testing

Programming as usual. Type the following command in the terminal each time and search while checking the result.

python


$ python proto.py

3. Convert to production environment, copy

After completion, delete the locally specific program and convert it to standard input with conv.py. Also copy to clipboard. All you have to do is paste it into the submission form.

python


$ python conv.py

Recommended Posts

Competitive programming with python Local environment settings
Competitive programming with python
python environment settings
3. 3. AI programming with Python
Competitive programming diary python 20201213
Python programming with Atom
Competitive programming diary python 20201220
Python environment with docker-compose
Competitive programming diary python
Local server with python
Programming with Python Flask
Virtual environment with Python 3.6
I made a competitive programming glossary with Python
Programming with Python and Tkinter
Install Python environment with Anaconda
Manage python environment with virtualenv
Build python3 environment with ubuntu 16.04
Prepare python3 environment with Docker
Build python environment with direnv
Python Competitive Programming Site Summary
Tips you should know when programming competitive programming with Python2
Network programming with Python Scapy
[Python] Building an environment for competitive programming with Atom (input () can be used!) [Mac]
Knowledge you need to know when programming competitive programming with Python2
Machine learning environment settings based on Python 3 on Mac (coexistence with Python 2)
Python3 standard input for competitive programming
Get started with Python! ~ ① Environment construction ~
Competitive programming, coding test template: Python3
Build python virtual environment with virtualenv
Setup modern Python environment with Homebrew
[Python] Object-oriented programming learned with Pokemon
Build Mysql + Python environment with docker
Create a virtual environment with Python!
Building a virtual environment with Python 3
Easy Python + OpenCV programming with Canopy
Emacs settings for Python development environment
Python3 environment construction with pyenv-virtualenv (CentOS 7.3)
Python Programming Workshop-Super Introductory Python Execution Environment
pytorch @ python3.8 environment construction with pipenv
Prepare Python development environment with Atom
Tips you should know when programming competitive programming with Python2 (useful library)
[Pyenv] Building a python environment with ubuntu 16.04
[Ubuntu 18.04] Python environment construction with pyenv + pipenv
[Python] Building an environment with Anaconda [Mac]
Change Python 64bit environment to 32bit environment with Anaconda
Building a Python3 environment with Amazon Linux2
Build Jupyter Lab (Python) environment with Docker
[Development environment] Python with Xcode [With screen transition]
Use smbus with python3 under pyenv environment
Note when creating an environment with python
[Python] Create a virtual environment with Anaconda
Creating amateur python environment settings (for MAC)
Building a Python 3.6 environment with Windows + PowerShell
Get a local DynamoDB environment with Docker
Create Python + uWSGI + Nginx environment with Docker
Build Python environment with Anaconda on Mac
Launch environment with LineBot + Heroku + Docker + Python
Build a python virtual environment with pyenv
Clean python environment with pythonz and virtualenv
[Competitive programming] [Python3] Required knowledge, for myself
Build a modern Python environment with Neovim