C/C++에서 include를 하듯이, Python에서는 import를 한다.

 

Python의 매력은 언어 자체에만 있는 것이 아니라,

필요하다고 생각하는 것은 거의 다 존재하는... 정말 다양하고 멋진 패키지들이 있기 때문이다.

 

그런 패키지들은 어디에 저장이 되어있을까?!

 

 

▶ PyPI (Python Package Index)

repository of software for the Python programming language
Python package: collection of related code modules (files) bundled with metadata describing
                                how the package should be installed and used.

 

https://pypi.org/

 

 

▶ pip (package installer for Python)

- standard tool to install packages from PyPI
- The most popular tool for installing Python packages

 

https://pip.pypa.io/en/stable/

 

 

Python을 공부하면 알 수 밖에 없는 명령어가 바로 pip 이다.

Python을 설치하면 기본적으로 같이 설치되기 때문에 접근성에 있어서도 문제가 없다.

 

그래서 가끔 파이썬 패키지는 무조건 pip를 통해서만 설치해야 하는 줄 아는 사람도 있는데,

위 설명에서도 나오지만, pip는 그냥 "popular tool" 이다 !!!

 

파이썬 패키지 설치를 위한 도구는 pip 외에도 더 있다.

특히, 최근에는 "uv"라는 도구가 엄청난 인기를 얻고 있다.

 

다른 패키지 설치 도구들도 천천히 알아보도록 하겠다.

반응형
Question 17 : import static

Given:
1. package sun.scjp;
2. public enum Color { RED, GREEN, BLUE }

1. package sun.beta;
2. // insert code here
3. public class Beta {
4.      Color g = GREEN;
5.      public static void main( String[] argv)
6.      { System.o ut.println( GREEN); }
7. }

The class Beta and the enum Color are in different packages.

Which two code fragments, inserted individually at line 2 of the Beta declaration, will allow this code to compile? (Choose two.)

A. import sun.scjp.Color.*;
B. import static sun.scjp.Color.*;
C. import sun.scjp.Color; import static sun.scjp.Color.*;
D. import sun.scjp.*; import static sun.scjp.Color.*;
E. import sun.scjp.Color; import static sun.scjp.Color.GREEN;

[HeadFirst Java - p.261]
# 패키지가 원래 이름 충돌을 방지하기 위한 용도로 만들어진 것은 아니지만, 이름 충돌을 방지하는 것도 패키지의 핵심적인 기능 가운데 하나라고 할 수 있습니다.
# 클래스를 package에 집어넣는 방법
     1. 패키지 명을 결정합니다.
          - "com.headfirstjava"를 예로 들면, 클래스 명이 'PackageExercise'라면
          - 전체이름은 "com.headfirstjava.PackageExercise"
     2. 클래스에 package 선언문을 집어넣습니다.
          - 소스코드 파일의 첫번째 선언문이어야 한다.
          - 소스 파일 하나에 들어있는 클래스는 모두 같은 패키지에 들어있어야 한다.
          - package 선언문이 하나밖에 들어갈 수 없기 때문이다.
     3.디렉토리 구조를 패키지 구조에 맞게 설정
          - PackageExercise의 소스코드는
          - com이라는 디렉토리 밑에 있는 headfirstjava라는 디렉토리 밑에 위치

[HeadFirst Java - p.261]
# 정적 임포트를 사용한 코드
     import static java.lang.System.out;
     import static java.lang.Math.*;
     class WithStatic {
          public static void main(String [] args) {
               out.println("sqrt " + sqrt(2.0));
               out.println("tan " + tan(60));
          }
     }

Answer: CE
반응형

'잘난놈되기 > SCJP' 카테고리의 다른 글

Q019. 클래스의 형변환  (0) 2008.04.13
Q018. 인터페이스  (0) 2008.04.13
Q016. 내부클래스  (0) 2008.04.04
Q015. 무명클래스의 형태  (1) 2008.04.04
Q014. 열거형  (0) 2008.04.03

+ Recent posts