VS code는 유저 스니핏(user snippet) 기능을 제공하고 있습니다.
User snippet이란?
반복 사용되는 코드 조각을 커스텀마이징하여 계속 복붙할 수 있다!
python.json 파일을 열고, {} 안에 본인이 커스텀마이징하길 희망하는 코드를 입력한다. prefix 부분만을 입력하여도, body부분을 호출할 수 있다.
vs code가 업데이트 되면서, 찾아가는 과정이 바뀌었습니다. 아래 자세하게 다시 알려드리겠습니다!
configure User Snippets 를 클릭하게 되면 상단에 검색창이 나오게 됩니다. 이후 검색창에 python.json을 검색해주시면 됩니다.
"sys.stdin = open(\"input.txt\",\"r\")": {
"prefix": "sys",
"body": ["import sys", "sys.stdin = open(\"input.txt\",\"r\")"],
"description": "make input.txt input"
},
해당 코드를 입력한 후, 파이썬 파일을 실행하여 prefix로 선언된 sys만 입력하여도 body부분이 모두 입력되는 것을 확인할 수 있습니다.
sys만을 입력해도 아래의 코드가 자동입력됩니다.
import sys
sys.stdin = open("input.txt","r")
되도록이면, 이미 정의되어있는 함수와는 겹치지 않는 함수명을 주는 것이 좋을 듯 합니다!
아래는, 저의 python.json입니다.
sys를 입력하시거나 ii만을 입력하여도 body부분을 받을 수 있습니다. 감사합니다!!
{
// Place your snippets for python here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
// "Print to console": {
// "prefix": "log",
// "body": [
// "console.log('$1');",
// "$2"
// ],
// "description": "Log output to console"
// }
"sys.stdin = open(\"input.txt\",\"r\")": {
"prefix": "sys",
"body": ["import sys", "sys.stdin = open(\"input.txt\",\"r\")"],
"description": "make input.txt input"
},
"int(input())": {
"prefix": "ii",
"body": ["int(input())"],
"description": "int input"
}
}