$ sudo pip install jupyterthemes

$ jt -l #테마 리스트 보기

$ jt -t onedork -T -f 폰트이름 -fs 폰트사이즈 -tf 텍스트셀폰트 -tfs 텍스트셀폰트사이즈 -nf 노트북폰트 -nfs 노트북폰트사이즈

 

이렇게 적용하면 된다.

'Python' 카테고리의 다른 글

iteration, iterable, iterator  (0) 2019.12.27
( ) = ( ) if ( ) else ( ) 구문  (0) 2019.12.27
변수명  (0) 2019.12.27
python statements  (0) 2019.12.27
binary data pack unpack examples  (0) 2019.12.27

software 설치/제거 메뉴에서

1. jupyter interactive notebook 찾아서 설치
2. interactive computing environment (metapackage) 설치

 

3. 환경설정
$ jupyter notebook --generate-config

 

4. 암호설정
$ jupyter notebook password

Enter password: ****

Verify password: ****

[NotebookPasswordApp] Wrote hashed password to /Users/you/.jupyter/jupyter_notebook_config.json

 

5. 해시된 패스워드 준비

In [1]: from notebook.auth import passwd

In [2]: passwd()

Enter password:

Verify password:

Out[2]: 'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed'

이 패스워드를 jupyter_notebook_config.py에 다음과 같은 항목에 넣는다.

 

c.NotebookApp.password = u'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed'

 

일단 이렇게 하면 앞의 jason 파일은 확장자를 고치고( *.org 처럼) 없앤다.

 

6. SSL 접속을 위한 준비

$ openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout mykey.key -out mycert.pem

이렇게 mykey.key, mycert.pem 2가지 파일을 만든다.

 

5. 외부접속을 위한 설정 파일 수정

.jupyter/jupyter_notebook_config.py를 수정

c.NotebookApp.allow_origin='*'
c.NotebookApp.allow_remote_access=True
c.NotebookApp.open_browser=False

c.NotebookApp.certfile = '/absolute/path/mycert.pem'

c.NotebookApp.keyfile = '/absolute/path/mykey.key'

c.NotebookApp.ip = '*'

c.NotebookApp.password = u'sha1:bcd259ccf...'

c.NotebookApp.open_browser = False

c.NotebookApp.port =8888

 

참고
1. https://jupyter-notebook.readthedocs.io/en/stable/public_server.html

2. https://m.blog.naver.com/seodaewoo/221710100262



'Raspberry Pi' 카테고리의 다른 글

원격 ssh로 라즈베리파이 sdcard 백업하기  (0) 2020.01.25
How to run Jupyter Notebooks on remote server — SSH  (0) 2020.01.21
라즈베리파이4  (0) 2020.01.17
라즈베리파이4 방열판 효과  (0) 2020.01.16
fail2ban  (0) 2020.01.15

1. Byte Order, Size, and Alignment

 

Character

Byte order

Size

Alignment

@

native

native

native

=

native

standard

none

<

little-endian

standard

none

>

big-endian

standard

none

!

network(=big-endian)

standard

none

 

 

2. Format Characters

 

Format

C type

Python type

Standard size

x

pad type

no value

 

c

char

bytes of length 1

1

b

signed char

integer

1

B

unsigned char

integer

1

?

_Bool

bool

1

h

short

integer

2

H

unsigned short

integer

2

i

int

integer

4

I

unsigned unt

integer

4

l

long

integer

4

L

unsigned long

integer

4

q

long long

integer

8

Q

unsigned long long

integer

8

n

ssize_t

integer

 

N

size_t

integer

 

e

 

float

2

f

float

float

4

d

double

float

8

s

char[]

bytes

 

p

char[]

bytes

 

P

void*

integer

 

 

Reference

https://docs.python.org/3.7/library/struct.html

'Python' 카테고리의 다른 글

( ) = ( ) if ( ) else ( ) 구문  (0) 2019.12.27
변수명  (0) 2019.12.27
python statements  (0) 2019.12.27
binary data pack unpack examples  (0) 2019.12.27
list comprehension과 for loop 벤치  (0) 2019.12.27

#
In [1]: import timeit as ti
 
In [8]: a="""\
   ...: a1=[x**3 for x in [1,2,3,4,5,6,7,8,9,10]]
   ...: a1"""

In [9]: b="""\
   ...: b1=[]
   ...: for x in [1,2,3,4,5,6,7,8,9,10]:
   ...: b1.append(x**3)
   ...: b1"""

In [10]: ti.timeit(a, number=100000)
Out[10]: 0.4964596600000277

In [11]: ti.timeit(b, number=100000)
Out[11]: 0.5405233050000788 
 
결론
즉 큰 차이는 아니지만  동일한 결과를 내는 식이라면 for loop를 사용하는 것보다는 list comprehension을 사용하는 것이 대게 더 빠르다.
 
간단한 벤치마크는 timeit.timeit 함수를 사용하면 된다.
timeit(a, number=b) 에서 a는 벤치마크를 하려는 문자열이고, b는 이것을 몇번 반복하는지 지정하는 것이다.
 

'Python' 카테고리의 다른 글

( ) = ( ) if ( ) else ( ) 구문  (0) 2019.12.27
변수명  (0) 2019.12.27
python statements  (0) 2019.12.27
binary data pack unpack examples  (0) 2019.12.27
struct : binary data packing & unpacking options  (0) 2019.12.27

PYTHON/Types
#
딕셔너리에서는 인덱스가 아닌 키값으로 값을 참조한다.
In [18]: d
Out[18]: {'a': 1, 'b': 2, 'c': 3, 'f': 50}
 
In [20]: d[1]='e'

In [21]: d
Out[21]: {'a': 1, 'b': 2, 'c': 3, 'f': 50, 1: 'e'}

In [22]: del d[1]

In [23]: d
Out[23]: {'a': 1, 'b': 2, 'c': 3, 'f': 50}
 
즉 del d[1]에서 1은 인덱스 1이 아니라 키값 1을 말한다. 
 
In [23]: d
Out[23]: {'a': 1, 'b': 2, 'c': 3, 'f': 50}

In [24]: d.keys()
Out[24]: dict_keys(['a', 'b', 'c', 'f'])

In [25]: d.items()
Out[25]: dict_items([('a', 1), ('b', 2), ('c', 3), ('f', 50)])

In [26]: d.get('a')
Out[26]: 1

In [27]: d.get('x',8) # 두번째 인자는 'x'라는 키값이 존재하지 않을 때 반환하는 디폴트값을 지정한다
Out[27]: 8

In [1]: m=[[1,2,3],[4,5,6],[7,8,9]]

In [2]: m
Out[2]: [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

In [28]: a=map(sum,m)
#리스트 m의 원소들을 차례대로 입력 받아 함수에 넣고 값을 map object로 반환한다.

In [29]: a
Out[29]: <map at 0x278d2de6860>
 
 
In [31]: next(a)
Out[31]: 6
 
In [33]: next(a)
Out[33]: 15

In [34]: next(a)
Out[34]: 24 
 
 
In [36]: a=list(map(sum,m))

In [37]: a
Out[37]: [6, 15, 24]

In [38]: a=set(map(sum,m))

In [39]: a
Out[39]: {6, 15, 24}

In [40]: a=tuple(map(sum,m))

In [41]: a
Out[41]: (6, 15, 24) 

'Python > function' 카테고리의 다른 글

yield, return  (0) 2019.12.27

# 미리 만들어둔 테스트용 리스트
In [1]: m=[[1,2,3],[4,5,6],[7,8,9]]

In [2]: m
Out[2]: [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

# comprehension syntax를 사용하며 list 뿐만이 아니라 generator, dictionary, set등도 만들 수 있다.
 
1. 리스트
In [14]: [ row[2] for row in m]
Out[14]: [3, 6, 9]
 
2. 제너레이터
In [7]: g=(sum(row) for row in m)

In [8]: g
Out[8]: <generator object <genexpr> at 0x00000278D2D7A480>

In [9]: next(g)
Out[9]: 6

In [10]: next(g)
Out[10]: 15

In [11]: next(g)
Out[11]: 24

In [12]: next(g)
Traceback (most recent call last):

File "<ipython-input-12-e734f8aca5ac>", line 1, in <module>
next(g)

StopIteration
#제너레이터는 처음부터 한번씩 원소를 반환하며 끝에 도달하면 에러를 발생시킨다.
 
3. set
#세트는 괄호만 바꿔주면 된다
In [16]: g={sum(row) for row in m}

In [17]: g
Out[17]: {6, 15, 24}
 
4. dictionary
#딕셔너리 역시 괄호를 바꿔주고 키와 값을 지정해주고 그 사이를 콜론으로 마무리해주면 된다.
In [25]: g={m.index(row):sum(row) for row in m}

In [26]: g
Out[26]: {0: 6, 1: 15, 2: 24}
 
# 괄호를 사용하면 제너레이터를 생산하게 되므로 튜플은 만들 수가 없는 것 같다.

'Python > list' 카테고리의 다른 글

count, index, insert, remove, pop, extend  (0) 2019.12.27
list comprehension 예  (0) 2019.12.27
nested list  (0) 2019.12.27

1. 간단 예제
In [1]: m=[[1,2,3],[4,5,6],[7,8,9]]

In [2]: m
Out[2]: [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

In [3]: col2=[row[2] for row in m]

In [4]: col2
Out[4]: [3, 6, 9] 
 
 
2. 리스트 연산
In [6]: m2=[row+[1] for row in m]

In [7]: m2
Out[7]: [[1, 2, 3, 1], [4, 5, 6, 1], [7, 8, 9, 1]]
 
 
3. 각각의 원소에 1씩 더하기
In [9]: m3=[[row[0]+1,row[1]+1,row[2]+1] for row in m]

In [10]: m3
Out[10]: [[2, 3, 4], [5, 6, 7], [8, 9, 10]]
 

4. 튜플 형태로 변환
In [11]: m3=[(row[0]+1,row[1]+1,row[2]+1) for row in m]

In [12]: m3
Out[12]: [(2, 3, 4), (5, 6, 7), (8, 9, 10)]
 
 
5. 리스트 괄호에 유의
In [13]: m3=[[row[i]+1] for row in m for i in [0,1,2]]

In [14]: m3
Out[14]: [[2], [3], [4], [5], [6], [7], [8], [9], [10]]

In [15]: m3=[row[i]+1 for row in m for i in [0,1,2]]

In [16]: m3
Out[16]: [2, 3, 4, 5, 6, 7, 8, 9, 10] 
 
 
6. for-in-if 문
In [24]: l=[row[1] for row in m if row[1] % 2 == 0]

In [25]: l
Out[25]: [2, 8]

'Python > list' 카테고리의 다른 글

count, index, insert, remove, pop, extend  (0) 2019.12.27
comprehension syntax  (0) 2019.12.27
nested list  (0) 2019.12.27

In [19]: l=[[1,2,3],[4,5,6],[7,8,9]]

In [20]: l
Out[20]: [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

In [21]: l[1]
Out[21]: [4, 5, 6]

In [22]: l[1][2]
Out[22]: 6 

'Python > list' 카테고리의 다른 글

count, index, insert, remove, pop, extend  (0) 2019.12.27
comprehension syntax  (0) 2019.12.27
list comprehension 예  (0) 2019.12.27

In [1]: l=['abc',123,'1.23','spam']

In [2]: l+[23]
Out[2]: ['abc', 123, '1.23', 'spam', 23]

In [3]: l*2
Out[3]: ['abc', 123, '1.23', 'spam', 'abc', 123, '1.23', 'spam']

In [4]: l
Out[4]: ['abc', 123, '1.23', 'spam']

In [5]: l.append('mem')

In [6]: l
Out[6]: ['abc', 123, '1.23', 'spam', 'mem']

In [7]: l.pop(2)
Out[7]: '1.23'

In [8]: l
Out[8]: ['abc', 123, 'spam', 'mem']
 
In [13]: m=['22','11','33']

In [14]: m
Out[14]: ['22', '11', '33']

In [15]: m.sort()

In [16]: m
Out[16]: ['11', '22', '33']

In [17]: m.reverse()

In [18]: m
Out[18]: ['33', '22', '11']


'Python > string' 카테고리의 다른 글

반복되는 문자열 찾기  (0) 2019.12.27
binary, utf-8, utf-16  (0) 2019.12.27
encode, decode  (0) 2019.12.26
ascii, hex, unicode  (0) 2019.12.26
string format  (0) 2019.12.26

python에서 모든 기본적인 오브젝트는 mutable object와 immutable objects로 나눌 수 있다.
이것들을 구분하는 것은 매우 중요하며 모르면 프로그래밍 시 엉뚱한 결과를 나을 수도 있다.

mutable 이란 것은 'can be changed in place' 를 의미한다.

mutable
1. lists
2. dic
3. set

immutable
1. number
2. string
3. tuple

즉 immutable type인 string은 'cannot be changed in place'이다.

s='xyz'

s[0]=a
와 같은 식으로 일부를 변경할 수 없다.

s2='a'+s[1:] ; 과 같은 식으로 새로운 문자열을 만들어야 한다.
#

In [1]: import re

In [2]: m=re.match('[/:](.*)[/:](.*)[/:](.*)'.'/usr/home:robert')

In [7]: m.groups()
Out[7]: ('usr', 'home', 'robert')

In [8]: m.group()
Out[8]: '/usr/home:robert'

In [9]: re.split('[/:]', '/usr/home:robert')
Out[9]: ['', 'usr', 'home', 'robert']

'Regular expression' 카테고리의 다른 글

메타문자  (0) 2019.12.27
문자클래스  (0) 2019.12.27

In [9]: b='\xa3' ​

In [10]: b
Out[10]: '£' ​

In [11]: d='\u00a3'.encode('latin1') ​

In [12]: d
Out[12]: b'\xa3' ​
In [13]: d.decode('latin1')
Out[13]: '£'

'Python > string' 카테고리의 다른 글

binary, utf-8, utf-16  (0) 2019.12.27
append, pop, sort, reverse  (0) 2019.12.27
ascii, hex, unicode  (0) 2019.12.26
string format  (0) 2019.12.26
strip, rstrip, lstrip  (0) 2019.12.26

1. 아스키 10진수

In [19]: chr(65)
Out[19]: 'A'

In [1]: ord('A')
Out[1]: 65

2. 아스키 헥사
\x()() 형태로 \x 다음 2자리
In [11]: s='\x41'
In [12]: s
Out[12]: 'A'

In [13]: s='\xc4'
In [14]: s
Out[14]: 'Ä'

3. unicode short
\u()()()() 형태로 \u 다음 4자리

In [15]: s='\u00c4'
In [16]: s
Out[16]: 'Ä'

4. unicode long
\U()()()()()()()() 형태로 \U 다음 8자리

In [17]: s='\U000000c4'
In [18]: s
Out[18]: 'Ä'
#

'Python > string' 카테고리의 다른 글

append, pop, sort, reverse  (0) 2019.12.27
encode, decode  (0) 2019.12.26
string format  (0) 2019.12.26
strip, rstrip, lstrip  (0) 2019.12.26
isalpha  (0) 2019.12.26

2 methods

1. % method
2. format() method

example)
In [7]: '%s, A, %s, and B' % ('first', 'second')
Out[7]: 'first, A, second, and B'

In [8]: '{}, A, {}, and B'.format('first', 'second')
Out[8]: 'first, A, second, and B'

In [20]: '{:>30,.2f}'.format(296999.2567)
Out[20]: ' 296,999.26'

In [21]: '{:>30,.2f}'.format(296999.2567)
Out[21]: ' 296,999.26'

In [22]: '{:>20,.2f}'.format(296999.2567)
Out[22]: ' 296,999.26'

In [23]: '{:->20,.2f}'.format(296999.2567)
Out[23]: '----------296,999.26'

In [24]: '{:_>20,.2f}'.format(296999.2567)
Out[24]: '__________296,999.26'
#

'Python > string' 카테고리의 다른 글

encode, decode  (0) 2019.12.26
ascii, hex, unicode  (0) 2019.12.26
strip, rstrip, lstrip  (0) 2019.12.26
isalpha  (0) 2019.12.26
upper()  (0) 2019.12.26

명령어 string method

strip, rstrip, lstrip

사용법

결과

차례로 문자열의 양쪽, 오른쪽, 왼쪽 공백문자를 없애준다

예시

In [1]: a=' 111 '

In [2]: a

Out[2]: ' 111 '

In [3]: a.rstrip()

Out[3]: ' 111'

In [4]: a.lstrip()

Out[4]: '111 '

In [5]: a.strip()

Out[5]: '111'

'Python > string' 카테고리의 다른 글

ascii, hex, unicode  (0) 2019.12.26
string format  (0) 2019.12.26
isalpha  (0) 2019.12.26
upper()  (0) 2019.12.26
split  (0) 2019.12.26

명령어 string method

isalpha

사용법

문자열a.isalpha()

결과

문자열a가 알파벳으로만 이루어져 있는지 검사한다.

예시

In [1]: a='spam'

In [2]: a

Out[2]: 'spam'

In [7]: a.isalpha()

Out[7]: True

In [8]: a.isdigit()

Out[8]: False

In [10]: a='spam2'

In [11]: a

Out[11]: 'spam2'

In [12]: a.isdigit()

Out[12]: False

In [13]: a.isalpha()

Out[13]: False

 

'Python > string' 카테고리의 다른 글

string format  (0) 2019.12.26
strip, rstrip, lstrip  (0) 2019.12.26
upper()  (0) 2019.12.26
split  (0) 2019.12.26
replace  (0) 2019.12.26

string method

.upper()

사용법

문자열a.upper()

결과

문자열a를 대문자로 바꾼 문자열을 반환한다.

예시

In [1]: a='spam'

In [2]: a

Out[2]: 'spam'

In [3]: a.upper()

Out[3]: 'SPAM'

In [4]: a

Out[4]: 'spam'

In [5]: b=a.upper()

In [6]: b

Out[6]: 'SPAM'

'Python > string' 카테고리의 다른 글

strip, rstrip, lstrip  (0) 2019.12.26
isalpha  (0) 2019.12.26
split  (0) 2019.12.26
replace  (0) 2019.12.26
find  (0) 2019.12.26

split

사용법

문자열a.split(분리자)

결과

문자열a에서 분리자를 발견할 때마다 문자열을 끊고 분리자는 포함하지 않은 리스트를 반환한다.

예시

 

In [1]: s='ad;df;ffg;fgh;'

In [2]: s.split(';')

['d','df','ffg','fgh','']

 

'Python > string' 카테고리의 다른 글

isalpha  (0) 2019.12.26
upper()  (0) 2019.12.26
replace  (0) 2019.12.26
find  (0) 2019.12.26
find  (0) 2019.12.23

replace

사용법

문자열a.replace(문자열b,문자열c)

결과

문자열a에서 문자열b를 찾아서 문자열c로 바꾼 새로운 문자열을 만든다.

예시

In [1]: s='spam'

In [2]: s.replace('pa','123')

's123m'

 

'Python > string' 카테고리의 다른 글

upper()  (0) 2019.12.26
split  (0) 2019.12.26
find  (0) 2019.12.26
find  (0) 2019.12.23
join  (0) 2019.12.23

+ Recent posts