๐Ÿ“—
JunegLee's TIL
  • TIL
  • python
    • class
    • String Basic
    • regularExpression
    • String function
    • Generator
    • String format
    • getset
    • module
    • while
    • numpy
    • print()
    • matplotlib
    • for
    • Boolean
    • tuple
    • package
    • input(variable)
    • list
    • if
    • file
    • type()
    • pandas
    • function
    • dictionary
    • ๊ตฌ๋ฌธ ์˜ค๋ฅ˜์™€ ์˜ˆ์™ธ
    • builtinFunction
    • Constructor
  • algorithm
    • sort
      • mergeSort
      • insertionSort
      • bubbleSort
      • heapSort
      • quickSort
      • selectionSort
    • recursion
    • Greedy
    • DepthFirstSearch
    • basic
      • DataStructure
    • hash
    • BreadthFirstSearch
  • tensorflow
    • keras
      • layers
        • Flatten
        • Flatten
        • Dense
        • Dense
        • Conv2D
        • Conv2D
    • tensorflow1x
    • tensorflow2x
  • DB
    • setting
    • join
    • subQuery
    • overview
  • deep-learning
    • neuralNetwork
    • perceptron
    • neuralNetworkLearning
    • convolution neural network
    • Gradient Descent
    • Linear Regression
    • backPropagation
    • logistic regression
    • overview
  • textPreprocessing
    • overview
  • java
    • basics
      • generic
      • Variable
      • String
    • theory
      • Object Oriented Programing
  • NLP
    • Embedding
    • Natural Language Processing
Powered by GitBook
On this page
  • Packages
  • ํŒจํ‚ค์ง€ ์•ˆ์˜ ํ•จ์ˆ˜ ์‹คํ–‰ํ•˜๊ธฐ
  • init.py ์˜ ์šฉ๋„
  • relative ํŒจํ‚ค์ง€

Was this helpful?

  1. python

package

Packages

: ํŒจํ‚ค์ง€๋Š” ๋„ํŠธ(.)๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํŒŒ์ด์ฌ ๋ชจ๋“ˆ์„ ๊ณ„์ธต์ (๋””๋ ‰ํ„ฐ๋ฆฌ ๊ตฌ์กฐ)์œผ๋กœ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•œ๋‹ค

number/
    __init__.py
    first/
        __init__.py
        echo.py
        wav.py
    second/
        __init__.py
        screen.py
        render.py
    third/
        __init__.py
        run.py
        test.py

ํŒจํ‚ค์ง€ ์•ˆ์˜ ํ•จ์ˆ˜ ์‹คํ–‰ํ•˜๊ธฐ

import number.first.echo
>>> game.sound.echo.echo_test() # echo

from number.first import echo
>>> echo.echo_test() # echo

from number.first.echo import echo_test
>>> echo_test() # echo

init.py ์˜ ์šฉ๋„

: ํ•ด๋‹น ๋””๋ ‰ํ„ฐ๋ฆฌ๊ฐ€ ํŒจํ‚ค์ง€์˜ ์ผ๋ถ€์ž„์„ ์•Œ๋ ค์ฃผ๋Š” ์—ญํ• ์„ ํ•œ๋‹ค. ๋งŒ์•ฝ ํŒจํ‚ค์ง€์— ํฌํ•จ๋œ ๋””๋ ‰ํ„ฐ๋ฆฌ์— init.py ํŒŒ์ผ์ด ์—†๋‹ค๋ฉด ํŒจํ‚ค์ง€๋กœ ์ธ์‹๋˜์ง€ ์•Š๋Š”๋‹ค (๋‹จ, python3.3 ๋ฒ„์ „ ๋ถ€ํ„ฐ๋Š” init.py ํŒŒ์ผ ์—†์–ด๋„ ํŒจํ‚ค์ง€๋กœ ์ธ์‹ํ•œ๋‹ค )

  • ์ด๋ ‡๊ฒŒ ํŠน์ • ๋””๋ ‰ํ„ฐ๋ฆฌ์˜ ๋ชจ๋“ˆ์„ *๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ importํ•  ๋•Œ์—๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด ํ•ด๋‹น ๋””๋ ‰ํ„ฐ๋ฆฌ์˜ init.py ํŒŒ์ผ์— all ๋ณ€์ˆ˜๋ฅผ ์„ค์ •ํ•˜๊ณ  importํ•  ์ˆ˜ ์žˆ๋Š” ๋ชจ๋“ˆ์„ ์ •์˜ํ•ด ์ฃผ์–ด์•ผ ํ•œ๋‹ค.

  • ์—ฌ๊ธฐ์—์„œ all์ด ์˜๋ฏธํ•˜๋Š” ๊ฒƒ์€ sound ๋””๋ ‰ํ„ฐ๋ฆฌ์—์„œ * ๊ธฐํ˜ธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ importํ•  ๊ฒฝ์šฐ ์ด๊ณณ์— ์ •์˜๋œ echo ๋ชจ๋“ˆ๋งŒ import๋œ๋‹ค๋Š” ์˜๋ฏธ

C:/user/number/sound/__init__.py
__all__ = ['echo']
rom game.sound import *
>>> echo.echo_test() # echo

relative ํŒจํ‚ค์ง€

: ์„œ๋กœ ๋‹ค๋ฅธ ๋””๋ ‰ํ„ฐ๋ฆฌ์— ๋ชจ๋“ˆ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ๋งŒ๋“ ๋‹ค relativeํ•œ ์ ‘๊ทผ์ž

  • .. ๋ถ€๋ชจ ๋””๋ ‰ํ„ฐ๋ฆฌ

  • . ํ˜„์žฌ ๋””๋ ‰ํ„ฐ๋ฆฌ

# render.py
from ..sound.echo import echo_test
def render_test():
    print ("render") # echo_test()
PrevioustupleNextinput(variable)

Last updated 4 years ago

Was this helpful?