본문 바로가기
국비교육

Python 3일차

by Diligejy 2019. 5. 2.

1.

import os

print(os.getcwd())

-> 

print(os.curdir) -> curdir은 Attribute니까 ()를 붙이지 않는다.

 

2.

>>> os.sys.path
    
['', 'C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\Python36_64\\Lib\\idlelib', 'C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\Python36_64\\python36.zip', 'C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\Python36_64\\DLLs', 'C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\Python36_64\\lib', 'C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\Python36_64', 'C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\Python36_64\\lib\\site-packages']

 

>>> os.path
    
<module 'ntpath' from 'C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\Python36_64\\lib\\ntpath.py'>

 

3.

위에 거를 왜 했냐는 

https://wikidocs.net/21132

 

위키독스

온라인 책을 제작 공유하는 플랫폼 서비스

wikidocs.net

이 사이트에서 알 수 있다.

외부 모듈을 불러오기 위해서 path설정을 추가하는 작업이 필요하다.

그럴 때 sys.path.append("")를 통해 추가할 수 있다.

단, 주의사항은 c:/temp처럼 넣어야 한다는 점이다

 

모듈 안에 있는 모든 함수를 그대로 불러오고 싶다면 from 예약어 import * 를 사용한다.

 

4.

def Prn05():
    return {1:[2,1], 3 :[2,4]}
def View(var):
    for k in var:
        print(k, var[k])
        
if __name__ == '__main__':
    View(Prn05())

 

5.

def repeat_msg(msg, repeat = 3):
    for i in range(repeat):
        print(msg)


if __name__ == '__main__':
    repeat_msg("Hello")
    repeat_msg('Hi', repeat = 5) #repeat_msg('Hi', 5)로 호출변수 생락 할 수 있다.

 

6. 

    

'국비교육' 카테고리의 다른 글

Python 5일차  (0) 2019.05.07
Python 4일차  (0) 2019.05.03
Python 2일차  (0) 2019.04.30
자바 Lambda식  (0) 2019.04.25
Python 1일차  (0) 2019.04.24

댓글