$ python3
Python 3.6.9 (default, Nov  7 2019, 10:44:02)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

5.4.5. 문자열 포맷팅
>>> age = 20
>>> name = 'Swaroop'
>>> print ("{0} was {1} years old".format(name, age))
Swaroop was 20 years old
>>> print ("{1} was {0} years old".format(name, age))
20 was Swaroop years old
>>> print ("{1:.3f} was {0} years old".format(name, age))
20.000 was Swaroop years old

5.4.7 순 문자열
>>> print(r"\a")
\a
>>> print("\a")

'Programming > python(파이썬)' 카테고리의 다른 글

오랫만에 한가로움?  (0) 2020.01.11
python split  (0) 2020.01.10
python 관련 문서들  (0) 2020.01.09
python exception  (0) 2020.01.02
python 컴파일하기 및 디컴파일?  (0) 2019.12.14
Posted by 구차니

이제 다시 한번 마스터 해봐야지..

node.js 해서 문법적으로 유사성을 찾으면 좀 쉬우려나?

 

[링크 : https://docs.python.org/3.8/download.html]

[링크 : http://byteofpython-korean.sourceforge.net/byte_of_python.pdf] 2.7 기준

'Programming > python(파이썬)' 카테고리의 다른 글

python split  (0) 2020.01.10
python 겅부  (0) 2020.01.09
python exception  (0) 2020.01.02
python 컴파일하기 및 디컴파일?  (0) 2019.12.14
python indent  (0) 2019.12.13
Posted by 구차니

C만 쓰다 보니 예외처리 부터 공부를 좀 해야겠다..

Cpp만 써봤어도 이해가 쉬울텐데...

 

[링크 : https://docs.python.org/ko/3/tutorial/errors.html]

[링크 : https://wikidocs.net/30]

'Programming > python(파이썬)' 카테고리의 다른 글

python 겅부  (0) 2020.01.09
python 관련 문서들  (0) 2020.01.09
python 컴파일하기 및 디컴파일?  (0) 2019.12.14
python indent  (0) 2019.12.13
tensorflow, pytorch  (0) 2019.12.10
Posted by 구차니

심심해서 잠도 안오겠다 -_-

python 가지고 놀다가 신기한 것 발견(?)

 

1. python2.x와 python3.x의 pyc 경로는 다르다.

2. python2.x와 python3.x의 pyc는 호환되지 않는다.

 

환경은 우분투 18.04 LTS. 설치된 버전정보는 다음과 같고

$ python --version
Python 2.7.15+

$ python3 --version
Python 3.6.9

 

python -m compileall . 과

python3 -m compileall . 의 결과는 아래와 같이

python(2.7.15)는 동일 경로상에 pyc로 생성되는데 반해

python3(3.6.9)는 __pycache__ 디렉토리 아래에 cpython 버전 정보를 기재하면서 pyc로 생성하게 된다.

.:
합계 20
drwxr-xr-x 3 minimonk minimonk 4096 12월 14 23:43 ./
drwxr-xr-x 5 minimonk minimonk 4096 12월 13 21:51 ../
drwxr-xr-x 2 minimonk minimonk 4096 12월 14 23:44 __pycache__/
-rw-r--r-- 1 minimonk minimonk   42 12월 14 23:43 test.py
-rw-r--r-- 1 minimonk minimonk  145 12월 14 23:43 test.pyc

./__pycache__:
합계 12
drwxr-xr-x 2 minimonk minimonk 4096 12월 14 23:44 ./
drwxr-xr-x 3 minimonk minimonk 4096 12월 14 23:43 ../
-rw-r--r-- 1 minimonk minimonk  140 12월 14 23:43 test.cpython-36.pyc

 

그리고 file 정보를 보면 pyc도 2.7대와 3.6대 byte-compiled로 나뉘게 되는데

$ file *
__pycache__: directory
test.py:     ASCII text
test.pyc:    python 2.7 byte-compiled

 

$ file __pycache__/*
__pycache__/test.cpython-36.pyc: python 3.6 byte-compiled

 

python2.7의 pyc를 python2.7과 python3.6으로 실행하면

python3.6 버전으로는 2.7의 pyc를 실행할 수 없다면서 에러를 발생시킨다.

$ python test.pyc
hello world
aa

$ python3 test.pyc
RuntimeError: Bad magic number in .pyc file

 

반대로  python3로 컴파일한 파일은

python2.7에서는 실행이 불가하고, python3.6으로는 실행이 가능하다.

$ python test.cpython-36.pyc 
RuntimeError: Bad magic number in .pyc file

$ python3 test.cpython-36.pyc 
hello world
aa

 

----

python -m compileall .

[링크 : https://sysops.tistory.com/39]

 

$ pip3 install uncompyle6
$ uncompyle6 -o . your_filename.pyc

[링크 : https://askubuntu.com/questions/153823/how-to-run-a-pyc-compiled-python-file]

[링크 : https://g0pher.tistory.com/364]

'Programming > python(파이썬)' 카테고리의 다른 글

python 관련 문서들  (0) 2020.01.09
python exception  (0) 2020.01.02
python indent  (0) 2019.12.13
tensorflow, pytorch  (0) 2019.12.10
python pip 특정 버전설치 / 목록에서 설치  (0) 2019.09.09
Posted by 구차니

웬지 이유없는 들여쓰기로 블록 구분하는건 안되는 느낌이다.

 

:로 끝나면 한블럭 들어가야 하고 이 경우는 if나 함수 처럼 어떠한 블럭이 강제되는 부분일 경우

들여쓰기를 강제하게 된다.

 

[링크 : https://riptutorial.com/ko/python/example/3952/블록-들여-쓰기]

[링크 :https://offbyone.tistory.com/48]

 

+

그냥 이유없이 들여쓰기 해서 블럭을 쓰고 싶은데 그렇게는 안되는 건가?

문법 수준에서 들여쓰기, 블럭으로 인식을 하다보니 임의의 블럭을 지정을 하지 못하게 하는 듯 하다.

'Programming > python(파이썬)' 카테고리의 다른 글

python exception  (0) 2020.01.02
python 컴파일하기 및 디컴파일?  (0) 2019.12.14
tensorflow, pytorch  (0) 2019.12.10
python pip 특정 버전설치 / 목록에서 설치  (0) 2019.09.09
python expat parseFile()  (0) 2019.06.24
Posted by 구차니

기계학습 좀 공부해보면서

흐름을 파악하고 어떤식으로 구체화 하는지 방법론을 좀 공부할 필요가 있어서 찾는 중

 

[링크 : https://pytorch.org/]

[링크 : https://skymind.ai/kr/wiki/compare-dl4j-tensorflow-pytorch]

[링크 : http://blog.naver.com/rlaghlfh/221494731829]

Posted by 구차니

requires.txt 이런걸로 패키지 목록이 있으면 -r 옵션을 통해 손쉽게 설치할 수 있다.

pip install -r 파일명

[링크 : https://kwonnam.pe.kr/wiki/python/pip]

 

== 버전으로 특정 버전을 설치할 수 있다.

pip install module==1.10

[링크 : https://antilibrary.org/1122]

'Programming > python(파이썬)' 카테고리의 다른 글

python indent  (0) 2019.12.13
tensorflow, pytorch  (0) 2019.12.10
python expat parseFile()  (0) 2019.06.24
ubuntu에서 python으로 postgres 접속하기  (0) 2019.06.24
python pip 특정 버전 설치하기  (0) 2019.06.18
Posted by 구차니

python의 expat을 써보려는데 원하는대로 안되서 멘붕 중

 

xmlparser.ParseFile(file)
Parse XML data reading from the object file. file only needs to provide the read(nbytes) method, returning the empty string when there’s no more data.

[링크 : https://docs.python.org/3.1/library/pyexpat.html]

 

>>> r = open('18549666.xml')
>>> p.ParseFile(r)
Traceback (most recent call last):
  File "", line 1, in 
TypeError: read() did not return a bytes object (type=str)

 

rb(read binary)가 중요한거였냐..

>>> r = open('18549666.xml','rb')

[링크 : https://stackoverflow.com/questions/1179305/expat-parsing-in-python-3]

Posted by 구차니

 

$ sudo apt install postgresql-server-dev-all

$ pip3 install psycopg2

$ python3

import psycopg2 as pg2 
conn=pg2.connect(database="postgres",user="postgres",password="1234",host="localhost",port="5432") 
cur = conn.cursor() 
cur.execute("select * from table_name") 
cur.fetchall()

[링크 : https://freeprog.tistory.com/100]

'Programming > python(파이썬)' 카테고리의 다른 글

python pip 특정 버전설치 / 목록에서 설치  (0) 2019.09.09
python expat parseFile()  (0) 2019.06.24
python pip 특정 버전 설치하기  (0) 2019.06.18
python pdb를 이용한 디버깅  (0) 2019.05.15
anaconda(python)  (0) 2019.05.15
Posted by 구차니

pip install "package==version"

 

 

pip install 'stevedore>=1.3.0,<1.4.0'
pip install 'stevedore>=1.3.0,<1.4.0' --force-reinstall

[링크 : https://stackoverflow.com/questions/5226311/installing-specific-package-versions-with-pip]

'Programming > python(파이썬)' 카테고리의 다른 글

python expat parseFile()  (0) 2019.06.24
ubuntu에서 python으로 postgres 접속하기  (0) 2019.06.24
python pdb를 이용한 디버깅  (0) 2019.05.15
anaconda(python)  (0) 2019.05.15
파이썬 vscode 디버깅 하기  (0) 2019.05.14
Posted by 구차니