존경하는 분의 인터뷰 기사.


http://v.media.daum.net/v/20170928202404220?d=y



문 대통령은 1970~1980년대 정권에 반대하는 시위에 참여하고 감옥까지 갔는데 어떻게 계속 투쟁할 수 있었느냐는 질문을 받았다. 이에 "그것은 낙관의 힘, 당장은 어렵더라도 역사의 발전을 잇는 낙관주의, 그게 중요하다고 생각한다"고 답했다. 이어 "그 시절에 '계란으로 바위치기다'라고 말했지만 저는 계란의 힘을 믿었다"며 "그리고 계란의 힘은 증명됐다"고 말했다.


Posted by '김용환'
,

[python3] ++ 연산자

python 2017. 9. 28. 20:03

python3에는 ++ 연산자가 없다.


+= 연산자만 있을 뿐이다.


예제



            if not self.conn.connected:

                retry_count += 1

Posted by '김용환'
,





            

            

python2에서 string 타입에 대해서 decode('utf-8')를 잘 실행할 수 있지만, 

python3에서는 기본이 utf-8이기 때문에 굳이 decode를 사용할 필요가 없다. 따라서 decode 함수도 없다. 



>>> result = ""

>>> str(type(result))

"<class 'str'>"

>>> result.decode('utf-8')

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

AttributeError: 'str' object has no attribute 'decode'

>>>


https://docs.python.org/3/howto/unicode.html


The default encoding for Python source code is UTF-8, so you can simply include a Unicode character in a string literal:





또한 None도 생겼다.


python2에서는 kazoo를 통해서 얻은 값은 empty string이였는데.. python3에서는 None타입을 사용했다.

flask에서는 다음과 같이 사용했다.

{% if node.data == None %}
{% else %}
<span style="word-wrap: break-word">
{{node.data}}
</span>
{% endif %}




그리고 




파이썬2에서 딕셔너리의 iteritems()는 사라지고 items()로 대체되었다.





message = '\n'.join("%s: %s" % (key, val) for (key, val) in (sorted(rep.items())))







그 외


https://wiki.python.org/moin/Python3.0#Built-In_Changes를 참고한다.





파이썬2에서 3로 전환하면서.. 발생했는데..


flask에서는 아래와 같은 코드는 에러가 발생한다 (TypeError: 'NoneType' object is not subscriptable)

if request.json['head_commit'] is not None:


flask 0.10부터 json 프로퍼티는 None을 리턴한다. 2->3 버전 이슈는 아니고 라이브러리 이슈가 있다.


if request.get_json('head_commit') is not None:


Posted by '김용환'
,


파이썬에서 타입, 값을 확인할 수 있는 예제이다. 



type()을 이용해 타입 확인할 수 있다. 


print("aaaaaaa : " + str(type(result)))


str()을 이용해 값을 확인할 수 있다.


print("aaaaaaa : " + str(result))



string 인스턴스라면..


if isinstance(result, str):


string 인스턴스가 아니라면.



if not isinstance(result, str):



None을 확인하는 코드이다.


a = None

if not a:

    print("1")

else:

    print("2")



결과는 다음과 같다.


1



None을 체크하는 코드이다. 


a = "1"

if not a:

    print("1")

else:

    print("2")



결과는 다음과 같다.

2



'python' 카테고리의 다른 글

[python3] ++ 연산자  (0) 2017.09.28
python2와 python3의 차이점 - string.decode()  (0) 2017.09.28
flask 환경 구성하기  (0) 2017.09.19
pyenv 설치 방법  (0) 2017.09.19
[python3] sorted 함수 예제  (0) 2017.07.20
Posted by '김용환'
,



rabbitmq에서 사용자를 추가하고 vhost 추가하는 예제이다. 



$ ./rabbitmqctl add_user rabbitmq password


$ ./rabbitmqctl add_vhost /vhost


$ ./rabbitmqctl  set_permissions -p /vhost guest ".*" ".*" ".*"




주의할 점은 vhost 생성시 /도 포함시켜야 말 지를 잘 결정해야 한다. 

Posted by '김용환'
,




http://flux.org.uk/projects/rackmonkey/





Posted by '김용환'
,