๋ฐ˜์‘ํ˜•

๐ŸŽˆ JSON Server ์‚ฌ์šฉํ•˜๊ธฐ

1. REST / REST API / Json Server

  • REST: ์›น์˜ ๊ธฐ๋ณธ ํ”„๋กœํ† ์ฝœ์ธ HTTP ๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ๊ตฌํ˜„๋˜๋ฉฐ , HTTP ๋ฉ”์„œ๋“œ์™€ URL ์„ ์ด์šฉํ•˜์—ฌ ์ž์›๊ณผ ํ•˜๊ณ ์žํ•˜๋Š” ํ–‰๋™์„ ํ‘œํ˜„ํ•จ.
  • REST API: REST ํ•œ ๋ฐฉ์‹์œผ๋กœ ์„ค๊ณ„๋œ API.
  • Json Server: JSON ํŒŒ์ผ์„ ์ด์šฉํ•˜์—ฌ Rest API ์„œ๋ฒ„๋ฅผ ๋น ๋ฅด๊ณ  ๊ฐ„๋‹จํ•˜๊ฒŒ ์ƒ์„ฑ ํ•˜๊ธฐ ์œ„ํ•œ ๋„๊ตฌ. 
    ex) (GET) http://example.com/wedding/1 : 1๋ฒˆ id ์ฒญ์ฒฉ์žฅ ๊ฐ€์ ธ์˜ค๊ธฐ

2. JSON Server ์‚ฌ์šฉํ•˜๊ธฐ

https://github.com/typicode/json-server

01. JSON Server ์„ค์น˜

yarn add -D json-server
  • ๋ฃจํŠธ๊ฒฝ๋กœ์— db.json ์ƒ์„ฑ
{
  "posts": [
    { "id": "1", "title": "a title", "views": 100 },
    { "id": "2", "title": "another title", "views": 200 },
    { "id": "3", "title": "json-server", "views": 200 }

  ],
  "comments": [
    { "id": "1", "text": "a comment about post 1", "postId": "1" },
    { "id": "2", "text": "another comment about post 1", "postId": "1" }
  ],
  "profile": {
    "name": "typicode"
  }
}
  • package.json์— ์•„๋ž˜ ๋‚ด์šฉ ์ถ”๊ฐ€
"dev:db": "json-server --watch db.json --port=8888" 
// watch์˜ต์…˜์„ ์ฃผ๋ฉด db.json์˜ ๋ณ€๊ฒฝ์‚ฌํ•ญ์„ ๊ฐœ๋ฐœ์„œ๋ฒ„์— ์‹ค์‹œ๊ฐ„ ๋ฐ˜์˜ํ•ด์ค€๋‹ค.
  • ์‹คํ–‰
yarn dev:db

json server ์„ค์น˜์™„๋ฃŒ!

 

02. ๋™์ž‘ test (https://github.com/typicode/json-server?tab=readme-ov-file)

  • Filter
  • ์‹คํ–‰๊ฒฐ๊ณผ 
    json server filter ์‹คํ–‰๊ฒฐ๊ณผ

  • Paginate
    Use _page and optionally _limit to paginate returned data. In the Link header you'll get firstprevnext and last links.
    GET /posts?_page=7   
    โ€‹
    • _page=7 : ์ผ๊ณฑ ๋ฒˆ์งธ ํŽ˜์ด์ง€๋ฅผ ์š”์ฒญํ•œ๋‹ค.
    • _limit ํŒŒ๋ผ๋ฏธํ„ฐ๊ฐ€ ๋ช…์‹œ๋˜์ง€ ์•Š์•˜์œผ๋ฏ€๋กœ, json-server๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ ํŽ˜์ด์ง€๋‹น 10๊ฐœ์˜ ํ•ญ๋ชฉ์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค.
    • ๊ฒฐ๊ณผ : ๊ธฐ๋ณธ ํŽ˜์ด์ง€๋‹น 10๊ฐœ ํ•ญ๋ชฉ์„ ์‚ฌ์šฉํ•ด 61~70๋ฒˆ์งธ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค.
    GET /posts?_page=7&_limit=20
    
    • _page=7: _page=7์œผ๋กœ ์ผ๊ณฑ ๋ฒˆ์งธ ํŽ˜์ด์ง€๋ฅผ ์š”์ฒญํ•œ๋‹ค.
    • _limit: _limit=20์„ ์ง€์ •ํ•˜์—ฌ ํŽ˜์ด์ง€๋‹น 20๊ฐœ์˜ ํ•ญ๋ชฉ์„ ๊ฐ€์ ธ์˜จ๋‹ค.
    • ์ผ๊ณฑ ๋ฒˆ์งธ ํŽ˜์ด์ง€์—์„œ 20๊ฐœ์˜ ํ•ญ๋ชฉ์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค. ๋”ฐ๋ผ์„œ, posts ๋ฐ์ดํ„ฐ ์ค‘ 121๋ฒˆ์งธ์—์„œ 140๋ฒˆ์งธ ํ•ญ๋ชฉ๊นŒ์ง€๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค. 
  • Sort
    _sort=f1,f2
    ๋ฐ์ดํ„ฐ๋ฅผ ํŠน์ • ํ•„๋“œ๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์ •๋ ฌํ•  ์ˆ˜ ์žˆ๋‹ค. ์ •๋ ฌํ•  ๋•Œ๋Š” ์ฟผ๋ฆฌ ํŒŒ๋ผ๋ฏธํ„ฐ _sort๋ฅผ ์‚ฌ์šฉํ•˜๊ณ , ์ •๋ ฌ ์ˆœ์„œ๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ ์˜ค๋ฆ„์ฐจ์ˆœ์ด๋ฉฐ, ๋‚ด๋ฆผ์ฐจ์ˆœ์œผ๋กœ ์„ค์ •ํ•˜๋ ค๋ฉด ํ•„๋“œ ์•ž์— -๋ฅผ ๋ถ™์ธ๋‹ค.
    GET /posts?_sort=id,-views
    1. GET /posts?_sort=id
    • id ํ•„๋“œ๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌ
    • posts ๋ฐ์ดํ„ฐ๊ฐ€ id ๊ฐ’์ด ์ž‘์€ ์ˆœ์„œ๋Œ€๋กœ ์ •๋ ฌ๋˜์–ด ๋ฐ˜ํ™˜ ๋œ๋‹ค.
    2. GET /posts?_sort=-views
    • views ํ•„๋“œ๋ฅผ ๊ธฐ์ค€์œผ๋กœ ๋‚ด๋ฆผ์ฐจ์ˆœ ์ •๋ ฌํ•ฉ๋‹ˆ๋‹ค.
    • posts ๋ฐ์ดํ„ฐ๊ฐ€ views ๊ฐ’์ด ํฐ ์ˆœ์„œ๋Œ€๋กœ ์ •๋ ฌ๋˜์–ด ๋ฐ˜ํ™˜ ๋œ๋‹ค.
    3. ๋‹ค์ค‘ ์ •๋ ฌ ์˜ˆ์‹œ: GET /posts?_sort=id,-views
    • ์—ฌ๋Ÿฌ ๊ฐœ์˜ ํ•„๋“œ๋ฅผ ์ •๋ ฌ ๊ธฐ์ค€์œผ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, id ํ•„๋“œ๋ฅผ ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ๋จผ์ € ์ •๋ ฌํ•œ ๋‹ค์Œ, ๋™์ผํ•œ id ๊ฐ’์ด ์žˆ์„ ๊ฒฝ์šฐ views ํ•„๋“œ๋ฅผ ๊ธฐ์ค€์œผ๋กœ ๋‚ด๋ฆผ์ฐจ์ˆœ ์ •๋ ฌํ•œ๋‹ค.
    • ์šฐ์„  id ๊ฐ’์ด ์ž‘์€ ์ˆœ์„œ๋Œ€๋กœ ์ •๋ ฌ๋˜๋ฉฐ, ๊ฐ™์€ id ๊ฐ’์„ ๊ฐ€์ง„ ํ•ญ๋ชฉ๋“ค์€ views ๊ฐ’์ด ํฐ ์ˆœ์„œ๋Œ€๋กœ ์ •๋ ฌ๋œ๋‹ค.

 

 

 

๋ฐ˜์‘ํ˜•
๋ฐ˜์‘ํ˜•

๐Ÿ‘ฟ ์—๋Ÿฌ์ƒํ™ฉ

eslint prettier ์ค„๋ฐ”๊ฟˆ ์—๋Ÿฌ ์™•์ฐฝ………

ERROR in [eslint]
src\\App.tsx
  Line 1:26:   Delete `โ`  prettier/prettier
  Line 2:30:   Delete `โ`  prettier/prettier
  Line 3:19:   Delete `โ`  prettier/prettier
  Line 4:1:    Delete `โ`  prettier/prettier
  Line 5:41:   Delete `โ`  prettier/prettier
  Line 6:39:   Delete `โ`  prettier/prettier
  Line 7:1:    Delete `โ`  prettier/prettier
  Line 8:35:   Delete `โ`  prettier/prettier
  Line 9:17:   Delete `โ`  prettier/prettier
  Line 10:11:  Delete `โ`  prettier/prettier
  Line 11:38:  Delete `โ`  prettier/prettier
  Line 12:38:  Delete `โ`  prettier/prettier
  Line 13:59:  Delete `โ`  prettier/prettier
  Line 14:12:  Delete `โ`  prettier/prettier
  Line 15:60:  Delete `โ`  prettier/prettier
  Line 16:13:  Delete `โ`  prettier/prettier
  Line 17:11:  Delete `โ`  prettier/prettier
  Line 18:31:  Delete `โ`  prettier/prettier
  Line 19:37:  Delete `โ`  prettier/prettier
  Line 20:26:  Delete `โ`  prettier/prettier
  Line 21:36:  Delete `โ`  prettier/prettier
  Line 22:10:  Delete `โ`  prettier/prettier
Failed to compile.

๐Ÿง ์—๋Ÿฌ ์›์ธ

Git ์„ค์ •๊ณผ VSCode ์„ค์ •์ด ์„œ๋กœ ์ถฉ๋Œํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— ์—๋Ÿฌ ๋ฐœ์ƒ. "files.eol": "\n" ์„ค์ •์ด ์ด๋ฏธ VSCode์— ์žˆ์—ˆ์ง€๋งŒ, Git์ด ์ค„ ๋ฐ”๊ฟˆ ํ˜•์‹์„ ์ž๋™์œผ๋กœ ๋ณ€ํ™˜ํ•˜๋Š” ์„ค์ •(core.autocrlf)์ด ํ™œ์„ฑํ™”๋œ ์ƒํƒœ์˜€๊ธฐ ๋•Œ๋ฌธ์— ๋ฐœ์ƒํ•œ ๋ฌธ์ œ

 

โœจ ์—๋Ÿฌ ํ•ด๊ฒฐ

โœ… Git ์„ค์ • ์—…๋ฐ์ดํŠธ

Windows์—์„œ CRLF๊ฐ€ ๊ธฐ๋ณธ ์ค„ ๋ฐ”๊ฟˆ์ด ๋˜์ง€ ์•Š๋„๋ก ๋‹ค์Œ ๋ช…๋ น์–ด๋กœ Git ์„ค์ •์„ ์—…๋ฐ์ดํŠธํ•ฉ๋‹ˆ๋‹ค.

# ํ”„๋กœ์ ํŠธ ๋กœ์ปฌ์—์„œ ์‹คํ–‰
git config core.autocrlf false

# ๊ธ€๋กœ๋ฒŒ ์„ค์ •์„ ์—…๋ฐ์ดํŠธํ•˜๋Š” ๊ฒฝ์šฐ
git config --global core.autocrlf false
  • ๋ชจ๋“  ํŒŒ์ผ LF๋กœ ๋ณ€ํ™˜
# Windows ํ™˜๊ฒฝ์—์„œ Git Bash ๋˜๋Š” WSL ์‚ฌ์šฉ ์‹œ
git ls-files -z | xargs -0 dos2unix

 

::์ฐธ๊ณ :: 

Prettier ๋ฐ ESLint ๊ฐ•์ œ ์ ์šฉ

npx prettier --write .
yarn eslint --fix .

VSCode์—์„œ ์ค„ ๋ฐ”๊ฟˆ ์ผ๊ด„ ๋ณ€๊ฒฝ

  • ๋ช…๋ น ํŒ”๋ ˆํŠธ(Ctrl+Shift+P)์—์„œ “Change All End Of Line Sequence”๋ฅผ ์„ ํƒํ•˜๊ณ , LF๋กœ ๋ณ€๊ฒฝ
๋ฐ˜์‘ํ˜•
๋ฐ˜์‘ํ˜•

๐Ÿ‘ฟ ์—๋Ÿฌ ์ƒํ™ฉ

Compiled with problems:
ERROR

[eslint] Invalid Options: - Unknown options: extensions, resolvePluginsRelativeTo - 'extensions' has been removed. - 'resolvePluginsRelativeTo' has been removed.

๐Ÿง ์—๋Ÿฌ ์›์ธ

ESLint 9 ๋ฒ„์ „ ๋ฌธ์ œ๋กœ ๋ฐœ์ƒ

โœจ ์—๋Ÿฌ ํ•ด๊ฒฐ

  • eslint 9๋ฒ„์ „ ์ œ๊ฑฐ
yarn remove eslint
  • ๋‹ค์šด๊ทธ๋ ˆ์ด๋“œ
yarn add -D eslint@8.57.0
  • yarn berry zero install - sdk ์—…๋ฐ์ดํŠธ
yarn dlx @yarnpkg/sdks vscode

 

 

์ถœ์ฒ˜: https://mariais.tistory.com/entry/Eslint-error-ํ•ด๊ฒฐ-๋ฐฉ๋ฒ•-extensions-has-been-removed-resolvepluginsrelativeto-has-been-removed

๋ฐ˜์‘ํ˜•
๋ฐ˜์‘ํ˜•

๐Ÿ‘ฟYarn Berry ํ”„๋กœ์ ํŠธ ํ™˜๊ฒฝ ์„ค์ • ์ค‘ .yarn/cache ์ƒ์„ฑ๋˜์ง€ ์•Š๋Š” ๋ฌธ์ œ

Yarn Berry ํ”„๋กœ์ ํŠธ ํ™˜๊ฒฝ ์„ค์ • ์ค‘ .yarn/cache ์ƒ์„ฑ๋˜์ง€ ์•Š๋Š” ๋ฌธ์ œ. yarn install์„ ์•„๋ฌด๋ฆฌ ์‹œ๋„ํ•ด๋„ ์บ์‹œํด๋”๊ฐ€ ์ƒ์„ฑ๋˜์ง€ ์•Š์Œ..

๐Ÿง ์—๋Ÿฌ ์›์ธ

  • ์ด์ „์—๋Š” enableGlobalCache์˜ ๊ธฐ๋ณธ๊ฐ’์ด false์˜€๊ธฐ ๋•Œ๋ฌธ์—, ๊ฐ ํ”„๋กœ์ ํŠธ๊ฐ€ ๋กœ์ปฌ .yarn/cache ํด๋”์— ์˜์กด์„ฑ์„ ์ €์žฅํ•˜๋„๋ก ๋˜์–ด ์žˆ์—ˆ๋‹ค.
  • ํ•˜์ง€๋งŒ ์ตœ๊ทผ ์—…๋ฐ์ดํŠธ์—์„œ enableGlobalCache์˜ ๊ธฐ๋ณธ๊ฐ’์„ true๋กœ ๋ณ€๊ฒฝํ•˜์—ฌ, ์ „์—ญ ์บ์‹œ ์‚ฌ์šฉ์„ ๊ธฐ๋ณธ ์„ค์ •์œผ๋กœ ์ ์šฉํ•˜๊ฒŒ ๋˜์—ˆ๋‹ค.
  • ๋”ฐ๋ผ์„œ Yarn์˜ ์ตœ์‹  ๋ฒ„์ „์—์„œ๋Š” enableGlobalCache: false ์„ค์ •์„ .yarnrc.yml์— ์ง์ ‘ ์ถ”๊ฐ€ํ•ด์•ผ๋งŒ ๋กœ์ปฌ ์บ์‹œ๊ฐ€ ์ƒ์„ฑ๋œ๋‹ค. ์„ค์ • ํŒŒ์ผ์— ํ•ด๋‹น ์˜ต์…˜์„ ์ง์ ‘ ์ถ”๊ฐ€ํ•˜์ง€ ์•Š์œผ๋ฉด, Yarn์€ ์ „์—ญ ์บ์‹œ๋ฅผ ์‚ฌ์šฉํ•˜๋ฏ€๋กœ .yarn/cache ํด๋”๊ฐ€ ์ƒ์„ฑ๋˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒ ํ–ˆ๋˜ ๊ฒƒ!

โœจ ์—๋Ÿฌ ํ•ด๊ฒฐ

  • .yarnrc.yml ํŒŒ์ผ์— enableGlobalCache: false ์„ค์ • ์ถ”๊ฐ€
    //.yarnrc.yml 
    nodeLinker: pnp
    enableGlobalCache: false
    โ€‹
  • ์„ค์ • ๋ณ€๊ฒฝ ํ›„ ํ”„๋กœ์ ํŠธ ์˜์กด์„ฑ ์žฌ์„ค์น˜
    yarn install

๋“œ๋””์–ด cacheํŒŒ์ผ์ด ์ƒ์„ฑ๋˜์—ˆ๋‹ค!!

๋ฐ˜์‘ํ˜•
๋ฐ˜์‘ํ˜•

ํ”„๋กœ์ ํŠธ ํ™˜๊ฒฝ์„ค์ •

๐Ÿ€ ES Lint / Prettier ์„ค์ •

  1. eslint, prettier ํŒจํ‚ค์ง€ ์„ค์น˜
    • yarn add -D eslint prettier eslint-plugin-prettier eslint-config-prettier eslint-plugin-react eslint-config-react-app
  2. Config ์„ค์ • ๋ถ„๋ฆฌ
    • package.json์˜ "eslintConfig”๋ถ€๋ถ„์„ ๋ณ„๋„์˜ .eslintrc.jsonํŒŒ์ผ๋กœ ๋ถ„๋ฆฌ ํ›„ ์ถ”๊ฐ€ ์„ค์ • ์ž‘์„ฑ
      //.eslintrc.json
      
      {
          "extends": [
              "react-app",
              "react-app/jest",
              "plugin:prettier/recommended"
          ],
          "plugins":["prettier"],
          "rules":{
              "prettier/prettier":"error"
          }
      }
      โ€‹
    • .prettierrc ํŒŒ์ผ ์ƒ์„ฑ
      //prettierrc 
      
      {
          "useTabs": false,
          "printWidth": 80,
          "tabWidth": 2,
          "singleQuote": true,
          "trailingComma": "all",
          "endOfLine": "lf",  // ํŒŒ์ผ์˜ ์ค„ ๋(Line Ending) ํ˜•์‹์„ ์ง€์ •
          "semi": false,
          "arrowParens": "always"
          }
      โ€‹
  3. setting.json ํŒŒ์ผ์— ์•„๋ž˜ ์ฝ”๋“œ ์ถ”๊ฐ€
    • Ctrl + Shift + P๋ฅผ ๋ˆŒ๋Ÿฌ ๋ช…๋ น ํŒ”๋ ˆํŠธ๋ฅผ ์—ด๊ธฐ → "Preferences: Open Settings (JSON)"์„ ์ž…๋ ฅํ•˜๊ณ  ์„ ํƒ
      // ์ˆ˜์ • ํ›„ ์ €์žฅํ•  ๋•Œ eslint๋กœ autofix ์‹คํ–‰
      "editor.codeActionsOnSave": {
        "source.fixAll.eslint": "true"
      },
      // ํŒŒ์ผ์˜ ์ค„ ๋(Line Ending) ํ˜•์‹์„ ์ง€์ •. ์•ž์œผ๋กœ ์ƒ์„ฑ๋˜๋Š” ํŒŒ์ผ๋“ค์€ lf(mac)๋กœ ์ƒ์„ฑ๋จ
      "files.eol":"\\n",
    
    โœ… ํŒŒ์ผ์˜ ์ค„ ๋ ํ˜•์‹ :: mac vs window
    "files.eol": "\n": ํŒŒ์ผ์˜ ์ค„ ๋์„ ์œ ๋‹‰์Šค/๋ฆฌ๋ˆ…์Šค ์Šคํƒ€์ผ์ธ LF (Line Feed) ํ˜•์‹์œผ๋กœ ์ง€์ •
    "files.eol": "\r\n" : ํŒŒ์ผ์˜ ์ค„ ๋์„ Windows ์‹œ์Šคํ…œ์˜ ๊ธฐ๋ณธ ํ˜•์‹์ธ CRLF ํ˜•์‹์œผ๋กœ ์ง€์ •

  4. vscode์— ์ ์šฉ
    yarn dlx @yarnpkg/sdks vscode
    
  5. prettier์—์„œ ์„ธ๋ฏธ์ฝœ๋ก  ์ œ๊ฑฐ ์„ค์ •ํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— package.json์— ์•„๋ž˜ ์ฝ”๋“œ ์ถ”๊ฐ€
    //package.json
        "lint": "eslint \\"src/**/*/{js,jsx,ts,tsx}\\"",
        "lint:fix": "eslint \\"src/**/*/{js,jsx,ts,tsx}\\""
    
    
    • ์ ์šฉ
    yarn lint:fix
    
  6. Craco Alias ์„ค์ •
    • ์„ค์น˜
      yarn add -D @craco/craco craco-alias
    • tsconfig.paths.json ์ •์˜
      // tsconfig.paths.json
      {
          "compilerOptions":{
              "baseUrl":".",
              "paths":{
                  "@/*": ["src/*"],
                  "@components/*":["src/components/*"]
              }
          }
      }
    • craco.config.js ์ •์˜
      // craco.config.js
      module.exports = {
        plugins: [
          {
            plugin: CracoAlias,
            options: {
              source: 'tsconfig',
              tsConfigPath: 'tsconfig.paths.json',
            },
          },
        ],
      }
    • Tsconfig์— tsconfig.paths.json extends ์‹œํ‚ค๊ธฐ
      // tsconfig.json
      {
        "extends": "./tsconfig.paths.json",
        "compilerOptions": {
          "target": "es5",
          "lib": ["dom", "dom.iterable", "esnext"],
          "allowJs": true,
          "skipLibCheck": true,
          "esModuleInterop": true,
          "allowSyntheticDefaultImports": true,
          "strict": true,
          "forceConsistentCasingInFileNames": true,
          "noFallthroughCasesInSwitch": true,
          "module": "esnext",
          "moduleResolution": "node",
          "resolveJsonModule": true,
          "isolatedModules": true,
          "noEmit": true,
          "jsx": "react-jsx"
        },
        "include": ["src", "tsconfig.paths.json"]
      }
      
      โ€‹

๐Ÿ€ scss ์„ค์ •

yarn add classnames sass
  • global.scss ์ƒ์„ฑ
  • App.module.scss ์ƒ์„ฑ
  • src\App.tsx
import classNames from 'classnames/bind'
import styles from './App.module.scss'

const cx = classNames.bind(styles)

//    <div className={cx('container')}> ์ด๋Ÿฐ์‹์œผ๋กœ ์‚ฌ์šฉ!
๋ฐ˜์‘ํ˜•
๋ฐ˜์‘ํ˜•

๐Ÿ€ 1. ํ”„๋กœ์ ํŠธ ์ƒ์„ฑํ•˜๊ธฐ

  • yarn ์„ค์น˜
npm install -g yarn
  • Create React App ๊ธฐ๋ฐ˜ ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ
yarn create react-app wedding --template typescript

๐Ÿ€ 2. Yarn Berry(PnP) ์„ค์ •

  1. node_modules ํด๋” ์‚ญ์ œ
  2. berry ๋ฒ„์ „ ์„ค์ • ::  yarn set version berry
    yarn set version berry
  3. root ๊ฒฝ๋กœ์— .yarnrc.ymlํŒŒ์ผ ์ƒ์„ฑ
    //.yarnrc.yml ํŒŒ์ผ์— pnp ์„ค์ •ํ•˜๊ธฐ (node_modules ๋Œ€์‹  pnp๋ฐฉ์‹ ์‚ฌ์šฉ!)
    nodeLinker: pnp
    
  4. yarn install
    yarn install
    

ํ™•์žฅ ํ”„๋กœ๊ทธ๋žจ ZipFS ์„ค์น˜


Yarn Berry์—์„œ TypeScript๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ zipfs ํ™•์žฅ ๊ธฐ๋Šฅ์ด ํ•„์š”ํ•œ ์ด์œ ๋Š” Yarn์˜ Plug'n'Play(PnP) ๋ฐฉ์‹ ๋•Œ๋ฌธ์ด๋‹ค. Yarn Berry๋Š” node_modules ํด๋” ์—†์ด .zip ํŒŒ์ผ์„ ํ†ตํ•ด ์˜์กด์„ฑ์„ ๊ด€๋ฆฌํ•˜๋Š”๋ฐ, ์ด๋•Œ ํŒŒ์ผ ์‹œ์Šคํ…œ์„ .zip ํ˜•์‹์œผ๋กœ ์ €์žฅํ•˜๊ณ  ๋ถˆ๋Ÿฌ์˜ค๋Š” ๊ณผ์ •์—์„œ zipfs๊ฐ€ ํ•„์š”ํ•˜๋‹ค.๋”ฐ๋ผ์„œ zipfs๋ฅผ ์„ค์น˜ํ•˜๋ฉด, Yarn Berry์˜ PnP ๋ฐฉ์‹๊ณผ TypeScript ํ™˜๊ฒฝ ๊ฐ„์˜ ํ˜ธํ™˜์„ฑ์„ ๋†’์—ฌ์ค€๋‹ค. zipfs ํ™•์žฅ ๊ธฐ๋Šฅ์€ .zip ํŒŒ์ผ๋กœ ์ €์žฅ๋œ ํŒจํ‚ค์ง€๋“ค์„ ํŒŒ์ผ ์‹œ์Šคํ…œ์ฒ˜๋Ÿผ ์ฝ์„ ์ˆ˜ ์žˆ๋„๋ก ์ง€์›ํ•˜์—ฌ, PnP ํ™˜๊ฒฝ์—์„œ TypeScript๋‚˜ ๊ธฐํƒ€ ํˆด์ด ์ •์ƒ์ ์œผ๋กœ ํŒจํ‚ค์ง€ ํŒŒ์ผ์„ ํƒ์ƒ‰ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•œ๋‹ค.

 

6. Yarn Berry์˜ Plug'n'Play(PnP) ๋ฐฉ์‹๊ณผ VSCode์˜ ํ†ตํ•ฉ ์„ค์ •

yarn dlx @yarnpkg/sdks vscode
๐Ÿ”ฅ๐Ÿ‘ฟ ์ฃผ์˜!!
๋ช…๋ น ํŒ”๋ ˆํŠธ(Ctrl+Shift+P)๋ฅผ ์—ด๊ณ  TypeScript: Restart TS Server"๋ฅผ ์„ ํƒ → "Use Workspace Version”๋ถ€๋ชจ ํด๋”๊ฐ€ ์•„๋‹Œ ํ”„๋กœ์ ํŠธ ํด๋” ์ž์ฒด์—์„œ VSCode๋ฅผ ์—ด์–ด์•ผ ํ•œ๋‹ค!!!! vscode๊ฐ€ ๋ถ€๋ชจํด๋”๋กœ ์—ด๋ ค์žˆ๋‹ค๋ฉด Use Workspace Version๊ฐ€ ๋ณด์ด์ง€ ์•Š์Œ...
์ฐธ๊ณ :: https://github.com/yarnpkg/berry/issues/4788

๐Ÿ€ 3. typescript ์„ค์ •

์›Œํฌ์ŠคํŽ˜์ด์Šค ๋ฒ„์ „์— ๋งž๋Š” ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ ๋ฒ„์ „์„ ์‚ฌ์šฉํ•˜๋„๋ก ํ—ˆ์šฉํ•ด์ฃผ๊ธฐ

๐Ÿ€ 4. .gitignore์— ์ถ”๊ฐ€

# yarn zero install
.yarn/*
!.yarn/cache
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions

# ์ฐธ๊ณ ::  https://yarnpkg.com/getting-started/qa#which-files-should-be-gitignored

 

Questions & Answers | Yarn

A list of answers to commonly asked questions.

yarnpkg.com

 

๐Ÿ€ 5. App.test.tsx์˜ ํƒ€์ž…์—๋Ÿฌ ์ œ๊ฑฐํ•˜๊ธฐ

ํƒ€์ž…์—๋Ÿฌ ์™•์ฐฝ

yarn remove @testing-library/jest-dom
yarn add -D @types/testing-library__jest-dom @testing-library/jest-dom

๐Ÿ€ 6. yarn start!!!!!!!!!!!!!!!!!!!!!!!

yarn start

 

๋ฐ˜์‘ํ˜•
๋ฐ˜์‘ํ˜•

๐ŸŽˆ ๊ฐ€์ƒ ํ™˜๊ฒฝ(virtual environment)

Python์˜ ๊ฐ€์ƒ ํ™˜๊ฒฝ(virtual environment)์€ ํ”„๋กœ์ ํŠธ๋งˆ๋‹ค ๊ณ ์œ ํ•œ ํŒจํ‚ค์ง€์™€ ์˜์กด์„ฑ์„ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ๋„๋ก ๋ณ„๋„์˜ Python ํ™˜๊ฒฝ์„ ์ƒ์„ฑํ•˜๋Š” ๋„๊ตฌ์ด๋‹ค. ๊ฐ€์ƒ ํ™˜๊ฒฝ์„ ์‚ฌ์šฉํ•˜๋ฉด ํ”„๋กœ์ ํŠธ๋งˆ๋‹ค ๋…๋ฆฝ์ ์ธ Python ํŒจํ‚ค์ง€ ํ™˜๊ฒฝ์„ ๊ตฌ์ถ•ํ•  ์ˆ˜ ์žˆ์–ด, ํŒจํ‚ค์ง€ ๋ฒ„์ „ ์ถฉ๋Œ์„ ๋ฐฉ์ง€ํ•˜๊ณ , ๋‹ค๋ฅธ ํ”„๋กœ์ ํŠธ์™€์˜ ์˜์กด์„ฑ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋‹ค.

** ๊ฐ€์ƒ ํ™˜๊ฒฝ์˜ ํ•„์š”์„ฑ

Python ํ”„๋กœ์ ํŠธ๋งˆ๋‹ค ์‚ฌ์šฉํ•ด์•ผ ํ•˜๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋“ค์ด ๋‹ค๋ฅผ ์ˆ˜ ์žˆ๊ณ , ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ๊ฐ™๋”๋ผ๋„ ๋ฒ„์ „์ด ๋‹ค๋ฅผ ์ˆ˜ ์žˆ๋‹ค. ์ด ๊ฒฝ์šฐ ๊ฐ™์€ ์‹œ์Šคํ…œ ํ™˜๊ฒฝ์—์„œ ์ด ๋‘ ํ”„๋กœ์ ํŠธ๋ฅผ ๊ด€๋ฆฌํ•˜๊ธฐ๊ฐ€ ์–ด๋ ค์šธ ์ˆ˜ ์žˆ๋‹ค. ๊ฐ€์ƒ ํ™˜๊ฒฝ์„ ์‚ฌ์šฉํ•˜๋ฉด ํ”„๋กœ์ ํŠธ๋ณ„๋กœ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๋ฒ„์ „์„ ๋…๋ฆฝ์ ์œผ๋กœ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ๋‹ค.

** ์š”์•ฝ

  • ๊ฐ€์ƒ ํ™˜๊ฒฝ ํ™œ์„ฑํ™”: conda activate myenv
  • ์ฝ”๋“œ ์‹คํ–‰: python my\_script.py ๋˜๋Š” python (์ธํ„ฐํ”„๋ฆฌํ„ฐ ์‚ฌ์šฉ)
  • ๊ฐ€์ƒ ํ™˜๊ฒฝ ๋น„ํ™œ์„ฑํ™”: conda deactivate

 

1. ๊ฐ€์ƒ ํ™˜๊ฒฝ ์ƒ์„ฑํ•˜๊ธฐ

 

โœ… ๊ฐ€์ƒ ํ™˜๊ฒฝ ์ƒ์„ฑ

์ƒˆ๋กœ์šด ๊ฐ€์ƒ ํ™˜๊ฒฝ์„ ์ƒ์„ฑํ•˜๋ ค๋ฉด conda create ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

conda create --name myenv

์œ„ ๋ช…๋ น์–ด๋Š” myenv๋ผ๋Š” ์ด๋ฆ„์˜ ๊ฐ€์ƒ ํ™˜๊ฒฝ์„ ์ƒ์„ฑํ•œ๋‹ค. ํ™˜๊ฒฝ ์ด๋ฆ„์€ ์›ํ•˜๋Š” ๋Œ€๋กœ ์ง€์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.

 

โœ… ํŠน์ • Python ๋ฒ„์ „์„ ์ง€์ •ํ•˜์—ฌ ํ™˜๊ฒฝ ์ƒ์„ฑ

ํŠน์ • Python ๋ฒ„์ „์„ ์‚ฌ์šฉํ•ด์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ, ๋ฒ„์ „์„ ๋ช…์‹œํ•˜์—ฌ ๊ฐ€์ƒ ํ™˜๊ฒฝ์„ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค.

conda create --name myenv python=3.8

์œ„ ๋ช…๋ น์–ด๋Š” Python 3.8 ๋ฒ„์ „์„ ์‚ฌ์šฉํ•˜๋Š” myenv ๊ฐ€์ƒ ํ™˜๊ฒฝ์„ ์ƒ์„ฑํ•œ๋‹ค.

 

โœ… Python 3.10** ๋ฒ„์ „์„ ์‚ฌ์šฉํ•˜๋Š” ์ƒˆ๋กœ์šด ๊ฐ€์ƒ ํ™˜๊ฒฝ myenv01์„ ์ƒ์„ฑํ•˜๋Š” ๋ช…๋ น์–ด

conda create -n myenv python=3.10

โญ --name ์˜ต์…˜์€ ํ™˜๊ฒฝ์˜ ์ด๋ฆ„์„ ์ง€์ •ํ•˜๋Š” ๋‘ ๊ฐœ์˜ ๋Œ€์‹œ(--)๊ฐ€ ์žˆ๋Š” ๊ธด ํ˜•ํƒœ์˜ ์˜ต์…˜์ด๋ฉฐ,

๋‹จ์ถ•ํ˜• ์˜ต์…˜์œผ๋กœ๋Š” -n(๋Œ€์‹œ ํ•˜๋‚˜)๋„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

 

2. ๊ฐ€์ƒ ํ™˜๊ฒฝ ํ™œ์„ฑํ™”

์ƒ์„ฑํ•œ ๊ฐ€์ƒ ํ™˜๊ฒฝ์„ ์‚ฌ์šฉํ•˜๋ ค๋ฉด ํ™œ์„ฑํ™”ํ•ด์•ผ ํ•œ๋‹ค.

conda activate myenv

ํ„ฐ๋ฏธ๋„์— (myenv)์™€ ๊ฐ™์ด ํ‘œ์‹œ๋˜๋ฉฐ, myenv ๊ฐ€์ƒ ํ™˜๊ฒฝ์ด ํ™œ์„ฑํ™”๋œ ์ƒํƒœ์ž„์„ ๋‚˜ํƒ€๋‚ธ๋‹ค.

3. ํŒจํ‚ค์ง€ ์„ค์น˜ ๋ฐ ๊ด€๋ฆฌ

๊ฐ€์ƒ ํ™˜๊ฒฝ์ด ํ™œ์„ฑํ™”๋œ ์ƒํƒœ์—์„œ conda install ๋ช…๋ น์–ด๋กœ ํŒจํ‚ค์ง€๋ฅผ ์„ค์น˜ํ•  ์ˆ˜ ์žˆ๋‹ค.

conda install requests

์œ„ ๋ช…๋ น์–ด๋Š” ํ˜„์žฌ ํ™œ์„ฑํ™”๋œ myenv ํ™˜๊ฒฝ์—๋งŒ requests ํŒจํ‚ค์ง€๋ฅผ ์„ค์น˜ํ•œ๋‹ค.

โœ… conda์™€ pip์„ ํ•จ๊ป˜ ์‚ฌ์šฉํ•˜๊ธฐ

Conda ํ™˜๊ฒฝ์—์„œ ์ œ๊ณต๋˜์ง€ ์•Š๋Š” ํŒจํ‚ค์ง€๊ฐ€ ์žˆ์„ ๊ฒฝ์šฐ, pip๋ฅผ ํ†ตํ•ด ์„ค์น˜ํ•  ์ˆ˜๋„ ์žˆ๋‹ค. Conda์™€ pip๋ฅผ ํ•จ๊ป˜ ์‚ฌ์šฉํ•  ๋•Œ๋Š” ๊ฐ€์ƒ ํ™˜๊ฒฝ์ด ํ™œ์„ฑํ™”๋œ ์ƒํƒœ์—์„œ pip install์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์ค‘์š”ํ•˜๋‹ค.

pip install some_package

์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ํ•ด๋‹น ํŒจํ‚ค์ง€๋Š” myenv ํ™˜๊ฒฝ ๋‚ด์—๋งŒ ์„ค์น˜๋˜๋ฉฐ, ์‹œ์Šคํ…œ ์ „์—ญ ํ™˜๊ฒฝ์—๋Š” ์˜ํ–ฅ์„ ๋ฏธ์น˜์ง€ ์•Š๋Š”๋‹ค.

4. ๊ฐ€์ƒ ํ™˜๊ฒฝ ๋น„ํ™œ์„ฑํ™”

๊ฐ€์ƒ ํ™˜๊ฒฝ ์‚ฌ์šฉ์„ ๋งˆ์ณค์œผ๋ฉด, conda deactivate ๋ช…๋ น์–ด๋กœ ํ™˜๊ฒฝ์„ ๋น„ํ™œ์„ฑํ™”ํ•˜์—ฌ ์‹œ์Šคํ…œ ๊ธฐ๋ณธ ํ™˜๊ฒฝ์œผ๋กœ ๋Œ์•„๊ฐˆ ์ˆ˜ ์žˆ๋‹ค.

conda deactivate

5. ๊ฐ€์ƒ ํ™˜๊ฒฝ ๊ด€๋ฆฌ

โœ… ๊ฐ€์ƒ ํ™˜๊ฒฝ ๋ชฉ๋ก ํ™•์ธ

ํ˜„์žฌ ์ƒ์„ฑ๋œ ๋ชจ๋“  ๊ฐ€์ƒ ํ™˜๊ฒฝ์„ ํ™•์ธํ•˜๋ ค๋ฉด conda env list ๋˜๋Š” conda info --envs ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

conda env list

โœ… ๊ฐ€์ƒ ํ™˜๊ฒฝ ์‚ญ์ œ

์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ํ™˜๊ฒฝ์€ conda remove --name myenv --all ๋ช…๋ น์–ด๋กœ ์‚ญ์ œํ•  ์ˆ˜ ์žˆ๋‹ค.

conda remove --name myenv --all

๐ŸŽˆ ๊ฐ€์ƒ ํ™˜๊ฒฝ์˜ ์žฅ์ 

  • ํ”„๋กœ์ ํŠธ ๋…๋ฆฝ์„ฑ: ์—ฌ๋Ÿฌ ํ”„๋กœ์ ํŠธ๋งˆ๋‹ค ํ•„์š”ํ•œ ํŒจํ‚ค์ง€์™€ Python ๋ฒ„์ „์„ ๋…๋ฆฝ์ ์œผ๋กœ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ์–ด, ์ถฉ๋Œ ์—†์ด ์ž‘์—…ํ•  ์ˆ˜ ์žˆ๋‹ค.
  • ๋ฒ„์ „ ์ œ์–ด: ํŠน์ • ํ”„๋กœ์ ํŠธ์˜ ์š”๊ตฌ ์‚ฌํ•ญ์— ๋งž์ถฐ Python ๋ฐ ํŒจํ‚ค์ง€ ๋ฒ„์ „์„ ๊ณ ์ •ํ•˜์—ฌ ์ž‘์—… ์žฌํ˜„์„ฑ์„ ๋†’์ผ ์ˆ˜ ์žˆ๋‹ค.
  • ์‹œ์Šคํ…œ ๋ณดํ˜ธ: ์‹œ์Šคํ…œ์˜ ๊ธฐ๋ณธ Python ํ™˜๊ฒฝ์— ์˜ํ–ฅ์„ ์ฃผ์ง€ ์•Š์œผ๋ฏ€๋กœ, ์‹œ์Šคํ…œ ์ „๋ฐ˜์˜ ์•ˆ์ •์„ฑ์„ ์œ ์ง€ํ•  ์ˆ˜ ์žˆ๋‹ค.

Miniconda๋ฅผ ์‚ฌ์šฉํ•œ ๊ฐ€์ƒ ํ™˜๊ฒฝ ๊ด€๋ฆฌ๋Š” ์—ฌ๋Ÿฌ ํ”„๋กœ์ ํŠธ๋ฅผ ํšจ์œจ์ ์œผ๋กœ ๊ด€๋ฆฌํ•˜๊ณ , ๊ฐ ํ”„๋กœ์ ํŠธ๋ณ„๋กœ ์ผ๊ด€๋œ ์ž‘์—… ํ™˜๊ฒฝ์„ ์„ค์ •ํ•˜๋Š” ๋ฐ ๋งค์šฐ ์œ ์šฉํ•˜๋‹ค.

๋ฐ˜์‘ํ˜•
๋ฐ˜์‘ํ˜•

๐ŸŽˆ ์™ธ๋ถ€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ (External Libraries)

Python์˜ ์™ธ๋ถ€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” ์ปค๋ฎค๋‹ˆํ‹ฐ๋‚˜ ํŠน์ • ๊ฐœ๋ฐœ์ž๊ฐ€ ์ œ๊ณตํ•˜๋Š” ํŒจํ‚ค์ง€๋กœ, ๊ธฐ๋ณธ ์„ค์น˜๋œ ํ‘œ์ค€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์™ธ์—๋„ ๋‹ค์–‘ํ•œ ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•œ๋‹ค. ์™ธ๋ถ€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” ๋ฐ์ดํ„ฐ ๋ถ„์„, ์›น ์Šคํฌ๋ž˜ํ•‘, HTTP ์š”์ฒญ ๋“ฑ ๋‹ค์–‘ํ•œ ์ž‘์—…์— ์œ ์šฉํ•˜๋ฉฐ, pip ํŒจํ‚ค์ง€ ๊ด€๋ฆฌ์ž๋ฅผ ํ†ตํ•ด ์„ค์น˜ํ•  ์ˆ˜ ์žˆ๋‹ค. ์™ธ๋ถ€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜๋ ค๋ฉด ๋จผ์ € ์„ค์น˜๊ฐ€ ํ•„์š”ํ•˜๋‹ค.์„ค์น˜ ํ›„, import ํ‚ค์›Œ๋“œ๋ฅผ ํ†ตํ•ด ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

1. pandas

๋ฐ์ดํ„ฐ ๋ถ„์„์„ ์œ„ํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ

pandas๋Š” ๋ฐ์ดํ„ฐ ๋ถ„์„๊ณผ ์กฐ์ž‘์— ์œ ์šฉํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋กœ, ํ…Œ์ด๋ธ” ํ˜•์‹์˜ ๋ฐ์ดํ„ฐ๋ฅผ ๋‹ค๋ฃจ๊ธฐ์— ํŽธ๋ฆฌํ•˜๋‹ค. ๋ฐ์ดํ„ฐํ”„๋ ˆ์ž„(DataFrame)์ด๋ผ๋Š” ๊ตฌ์กฐ๋ฅผ ํ†ตํ•ด ํ–‰๊ณผ ์—ด๋กœ ๊ตฌ์„ฑ๋œ ๋ฐ์ดํ„ฐ๋ฅผ ์‰ฝ๊ฒŒ ์กฐ์ž‘ํ•  ์ˆ˜ ์žˆ๋‹ค.

  • ์„ค์น˜ ๋ช…๋ น์–ด: pip install pandas
import pandas as pd

# ๋ฐ์ดํ„ฐํ”„๋ ˆ์ž„ ์ƒ์„ฑ
data = {'Name': ['Karina', 'Winter', 'Ningning', 'Giselle'], 'Age': [24, 23, 21, 23]}
df = pd.DataFrame(data)
print(df)

# ๋ฐ์ดํ„ฐํ”„๋ ˆ์ž„์˜ ํŠน์ • ์—ด ์ถœ๋ ฅ
print(df['Name'])  # Output: Name ์—ด์˜ ๊ฐ’

# ๊ธฐ์ดˆ ํ†ต๊ณ„ ์ •๋ณด ์ถœ๋ ฅ
print(df.describe())  # ๋ฐ์ดํ„ฐ์˜ ํ†ต๊ณ„ ์š”์•ฝ ์ •๋ณด

# DataFrame์„ Excel ํŒŒ์ผ๋กœ ์ €์žฅ
df.to_excel('aespa_data.xlsx', index=False)
  • to_excel() ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ DataFrame์„ Excel ํŒŒ์ผ๋กœ ์ €์žฅํ•  ์ˆ˜ ์žˆ๋‹ค.( openpyxl ๋˜๋Š” xlsxwriter ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์„ค์น˜)
  • ์„ค์น˜ ๋ช…๋ น์–ด: pip install openpyxl
  •  index=False: ์ด ์˜ต์…˜์€ DataFrame์˜ ์ธ๋ฑ์Šค๋ฅผ ํŒŒ์ผ์— ํฌํ•จ์‹œํ‚ค์ง€ ์•Š๋„๋ก ์„ค์ •ํ•œ๋‹ค. ๋งŒ์•ฝ ์ธ๋ฑ์Šค๋ฅผ ํฌํ•จํ•˜๋ ค๋ฉด index=True๋กœ ์„ค์ •ํ•˜๊ฑฐ๋‚˜, ์˜ต์…˜์„ ์ƒ๋žตํ•  ์ˆ˜ ์žˆ๋‹ค.

โญ ํ„ฐ๋ฏธ๋„ ์ถœ๋ ฅ ๊ฒฐ๊ณผ

2. requests

HTTP ์š”์ฒญ์„ ๋ณด๋‚ด๊ธฐ ์œ„ํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ. 

HTTP ์š”์ฒญ์„ ์‰ฝ๊ฒŒ ๋ณด๋‚ผ ์ˆ˜ ์žˆ๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋กœ, ์›น API๋ฅผ ํ˜ธ์ถœํ•˜๊ฑฐ๋‚˜ ์›น ํŽ˜์ด์ง€์˜ HTML์„ ๊ฐ€์ ธ์˜ฌ ๋•Œ ์ž์ฃผ ์‚ฌ์šฉ๋œ๋‹ค.

  • ์„ค์น˜ ๋ช…๋ น์–ด: pip install requests

โœ… GET ์š”์ฒญ 

import requests

response = requests.get("https://api.github.com")
print(response.status_code)   # ์‘๋‹ต ์ƒํƒœ ์ฝ”๋“œ ์ถœ๋ ฅ
print(response.json())        # JSON ํ˜•์‹์˜ ์‘๋‹ต ๋ฐ์ดํ„ฐ ์ถœ๋ ฅ

 

 

  • requests.get()๋Š” GET ์š”์ฒญ์„ ๋ณด๋‚ด์„œ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜ค๋Š” ๋ฉ”์„œ๋“œ.
  • https://api.github.com์€ GitHub์˜ API ์—”๋“œํฌ์ธํŠธ๋กœ, ๊ธฐ๋ณธ์ ์ธ ์ •๋ณด๋ฅผ ์ œ๊ณตํ•œ๋‹ค.
  • response.status_code: HTTP ์ƒํƒœ ์ฝ”๋“œ ์ถœ๋ ฅ. 200์€ ์š”์ฒญ์ด ์„ฑ๊ณต์ ์œผ๋กœ ์ฒ˜๋ฆฌ๋˜์—ˆ์Œ์„ ์˜๋ฏธํ•œ๋‹ค.
  • response.json(): JSON ํ˜•์‹์œผ๋กœ ์‘๋‹ต ๋ฐ์ดํ„ฐ๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค.

โœ… POST ์š”์ฒญ 

import requests

data = {'key': 'value'}
response = requests.post("https://httpbin.org/post", data=data)
print(response.json())        # JSON ํ˜•์‹์˜ ์‘๋‹ต ๋ฐ์ดํ„ฐ ์ถœ๋ ฅ

 

 

  • requests.post(): POST ์š”์ฒญ์„ ๋ณด๋‚ด๋Š” ๋ฉ”์„œ๋“œ๋กœ, ์ฃผ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ์„œ๋ฒ„์— ์ „์†กํ•  ๋•Œ ์‚ฌ์šฉํ•จ.
  • data=data: ์„œ๋ฒ„๋กœ ์ „์†กํ•  ๋ฐ์ดํ„ฐ๋ฅผ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ์‹œ์ฝ”๋“œ์—์„œ๋Š” {'key': 'value'}๋ผ๋Š” ๋”•์…”๋„ˆ๋ฆฌ๋ฅผ ๋ฐ์ดํ„ฐ๋กœ ์ „์†ก.
  • https://httpbin.org/post: httpbin.org๋Š” ํ…Œ์ŠคํŠธ์šฉ์œผ๋กœ ๋งŽ์ด ์‚ฌ์šฉ๋˜๋Š” ์„œ๋น„์Šค๋กœ, ์š”์ฒญ์„ ๊ทธ๋Œ€๋กœ ๋˜๋Œ๋ ค์ค€๋‹ค.
  • response.json(): JSON ํ˜•์‹์œผ๋กœ ์‘๋‹ต ๋ฐ์ดํ„ฐ๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค.

 

3. tqdm

๋ฐ˜๋ณต ์ž‘์—…์˜ ์ง„ํ–‰ ์ƒํƒœ๋ฅผ ์‹œ๊ฐ์ ์œผ๋กœ ๋ณด์—ฌ์ฃผ๋Š” ํ”„๋กœ๊ทธ๋ ˆ์Šค ๋ฐ” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ.

  • ์„ค์น˜ ๋ช…๋ น์–ด: pip install tqdm

์•„๋ž˜ ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•˜๋ฉด, 10๋ฒˆ์˜ ๋ฐ˜๋ณต ์ž‘์—…์ด ์ง„ํ–‰๋˜๋Š” ๋™์•ˆ ๊ฐ ์ž‘์—… ์‚ฌ์ด์— 0.1์ดˆ์”ฉ ์ง€์—ฐ๋˜๋ฉฐ ํ”„๋กœ๊ทธ๋ ˆ์Šค ๋ฐ”๊ฐ€ ์กฐ๊ธˆ์”ฉ ์ฑ„์›Œ์ง€๋Š” ๋ชจ์Šต์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

from tqdm import tqdm
import time

# tqdm์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ฐ˜๋ณต ์ž‘์—…์— ํ”„๋กœ๊ทธ๋ ˆ์Šค ๋ฐ” ์ ์šฉ
for i in tqdm(range(10)):
    time.sleep(0.1)  # ์ž‘์—…์„ ์ง€์—ฐ์‹œ์ผœ ์ง„ํ–‰ ์ƒํƒœ๋ฅผ ํ™•์ธ ๊ฐ€๋Šฅํ•˜๊ฒŒ ํ•จ
  • for i in tqdm(range(10)): range(10)์€ 0๋ถ€ํ„ฐ 9๊นŒ์ง€ 10๋ฒˆ ๋ฐ˜๋ณต๋˜๋Š” ๋ฃจํ”„๋ฅผ ์ƒ์„ฑํ•˜๋ฉฐ, tqdm์„ ํ†ตํ•ด ๊ฐ ๋ฐ˜๋ณต์„ ์‹œ๊ฐ์ ์œผ๋กœ ๋ณด์—ฌ์ค€๋‹ค.
  • time.sleep(0.1): ๊ฐ ๋ฐ˜๋ณต ์‚ฌ์ด์— 0.1์ดˆ์˜ ์ง€์—ฐ์„ ์ถ”๊ฐ€ํ•œ๋‹ค. ์ด ์ง€์—ฐ์ด ์—†์œผ๋ฉด ํ”„๋กœ๊ทธ๋ ˆ์Šค ๋ฐ”๊ฐ€ ๋„ˆ๋ฌด ๋น ๋ฅด๊ฒŒ ์ง€๋‚˜๊ฐ€, ์ง„ํ–‰ ์ƒํƒœ๋ฅผ ํ™•์ธํ•˜๊ธฐ ์–ด๋ ค์šธ ์ˆ˜ ์žˆ๋‹ค.

4. numpy

๋ฐฐ์—ด ๋ฐ ํ–‰๋ ฌ ์—ฐ์‚ฐ์— ๊ฐ•๋ ฅํ•œ ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•˜๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ. ๋ฐ์ดํ„ฐ ๋ถ„์„๊ณผ ๊ณผํ•™ ๊ณ„์‚ฐ์—์„œ ๋งŽ์ด ์‚ฌ์šฉ๋œ๋‹ค.

  • ์„ค์น˜ ๋ช…๋ น์–ด: pip install numpy
import numpy as np

# ๋ฐฐ์—ด ์ƒ์„ฑ ๋ฐ ์—ฐ์‚ฐ
array = np.array([1, 2, 3, 4])
print(array * 2)  # Output: [2 4 6 8]

# 2์ฐจ์› ๋ฐฐ์—ด ์ƒ์„ฑ
matrix = np.array([[1, 2], [3, 4]])
print(matrix)

5. matplotlib

๋ฐ์ดํ„ฐ ์‹œ๊ฐํ™”๋ฅผ ์œ„ํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ. ๊ทธ๋ž˜ํ”„์™€ ์ฐจํŠธ๋ฅผ ๊ทธ๋ฆฌ๋Š” ๋ฐ ์œ ์šฉํ•˜๋‹ค.

  • ์„ค์น˜ ๋ช…๋ น์–ด: pip install matplotlib
import matplotlib.pyplot as plt

# ๊ฐ„๋‹จํ•œ ๋ผ์ธ ๊ทธ๋ž˜ํ”„ ๊ทธ๋ฆฌ๊ธฐ
x = [1, 2, 3, 4]
y = [10, 20, 25, 30]
plt.plot(x, y)
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Simple Line Plot')
plt.show()
๋ฐ˜์‘ํ˜•

+ Recent posts