본문 바로가기

python6

[Rust] Variable : Python 코드 비교 예제 (58일차) [Python] if __name__ == '__main__': x = 1; print(x); # bind x again shadows old one from above x = 'i'; print(x) # declare, init something = None; x = 5; print("x, something", x, something); something = x * 5; print("x, something", x, something); # mutability y = 0; y = y * 2 + x; print(y); BLAH = 42; # only const by convention y *= BLAH; [Rust] fn main() { let x = 1; println!("x: {}", x); // bi.. 2023. 2. 18.
[Python] if __name__ == “__main__” 쓰는 이유 아래에 설명을 위한 예제 코드가 있다. // excuteThisModule.py def func(): print("function working") if __name__ == "__main__": print("직접 실행") print(__name__) else: print("import 되어 사용됨") print(__name__) 코드를 실행하기 위해선 2가지 방법이 있다, (1) 인터프리터에서 직접 실행 python3 executeThisModule.py (2) 다른 module에서 import 하여 실행 // import한 파일의 이름은 executor.py import executeThisModule.py executeThisModule.func() (1)번 방법으로 직접 실행시, __name__ .. 2022. 11. 11.
[Error, Python] pip command error - 운영체제로 윈10 을 사용. - python 설치 후 pip install [라이브러리] 를 입력하였으나 아래의 오류 발생 Fatal error in launcher: Unable to create process using ""C:\Program Files (x86)\Python33\python.exe" (1) 'pip install' 대신 아래의 명령어 입력 $ python -m pip install [라이브러리] ==> 근본 문제의 해결은 아니지만 설치는 해줌. (2) python 재설치 ==> 본인의 경우 각기 다른 버전의 python을 직접 설치 & vscode 확장자 설치하여, path 2개가 중첩되어 error 발생. ==> 해결하려면 python을 삭제하고 재설치하자. https://st.. 2022. 11. 1.
[Python] Python module source 보기 - 가끔 너무 궁금할 때 python module 구조가 어떻게 만들어졌는지 궁금하여 뜯어본다. - 구글링해보니 module 자체를 뜯어서 공유하는 이가 거의 없어 방법을 공유한다. """ random module을 console로 확인 """ import inspect import random code = inspect.getsource(random) print(code) - 본인은 내장함수인 set()을 찾고 싶었으나 에러가 뜬다. import inspect code = inspect.getsource(set) print(code) ==> [결과] # TypeError: is a built-in class # built-in 된 내장함수는 코드나 경로로 못찹음 https://github.com/pyt.. 2022. 7. 15.