2013년 10월 2일 수요일

Python 작업 위치 변경

""" 명령의 일부만 입력하고 Tab을 누르면 가능한 명령 리스트가 나온다
    방금 입력했던 명령을 다시 보기 위해서는 Alt-p, Alt-n을 사용한다.
    (내 컴퓨터에서는 왼쪽 alt만 먹음)
"""
>>> from PIL import Image
>>> import os
>>> os.getcwd()   # 현재 작업 위치를 보여줌
'D:\\Opencv\\Python27'
>>> from os import chdir  # 작업 위치를 바꾸기 위한 헤드
>>> chdir('d:\\') # 작업 위치 변경
>>> os.getcwd()
'd:\\'
>>>

>>> chdir('D:\\다운로드_2013\\진충_크랙 검출')  # 한글도 입력됨. 2개의 백슬러시'\\'를 사용
>>> os.getcwd()  # 한글이 들어가니 이상한 글자가 나옴
'D:\\\xb4\xd9\xbf\xee\xb7\xce\xb5\xe5_2013\\\xc1\xf8\xc3\xe6_\xc5\xa9\xb7\xa2 \xb0\xcb\xc3\xe2'

>>> pil_im=Image.open('empire.jpg')  # 위치 변경이 잘 되었는지 확인하기 위해 그 위치의 파일하나를 오픈
>>>

>>> from pylab import *  # 영상의 화면 출력을 위해 matplotlit 헤드 입력



""" 작업 위치를 변경하기 위한 명령 """
>>> import os
>>> from os import chdir
>>> chdir('D:\\다운로드_2013\\진충_크랙 검출')
>>> os.listdir('.') # 모든 파일과 폴드명이 나타남...
....
....



(예)

>>> from PIL import Image
>>>
>>> im=Image.open('empire.jpg')
>>> imshow(im)  # pylab헤드를 입력하지 않았기 때문에 에러..

Traceback (most recent call last):
  File "<pyshell#6>", line 1, in <module>
    imshow(im)
NameError: name 'imshow' is not defined

>>> im1 = array(im) # array명령은 pylab에 있다...

Traceback (most recent call last):
  File "<pyshell#7>", line 1, in <module>
    im1 = array(im)
NameError: name 'array' is not defined
>>> from pylab import *



>>> im1 = array(im)  # array로 변환 안하면 이미지가 꺼꾸로 화면 출력
>>> imshow(im1)
<matplotlib.image.AxesImage object at 0x03C3C3D0>
>>> show()  # show가 실행된 이후에야 영상이 출력됨...

댓글 없음:

댓글 쓰기