In [19]: s='\xebmail'

 

In [20]: s

Out[20]: 'ëmail'

 

In [28]: file=open('unicode.txt','w',encoding='utf-8')

 

In [29]: file.write(s)

Out[29]: 5

 

In [30]: file.close()

 

In [31]: file=open('unicode16.txt','w',encoding='utf-16')

 

In [32]: file.write(s)

Out[32]: 5

 

In [33]: file.close()

 

In [34]: raw=open('unicode.txt','rb').read()

 

In [35]: raw

Out[35]: b'\xc3\xabmail'

 

In [36]: len(raw)

Out[36]: 6

 

In [37]: raw2=open('unicode16.txt','rb').read()

 

In [38]: raw2

Out[38]: b'\xff\xfe\xeb\x00m\x00a\x00i\x00l\x00'

 

In [39]: len(raw2)

Out[39]: 12

 

In [40]: raw.decode('utf-8')

Out[40]: 'ëmail'

 

In [41]: raw2.decode('utf-16')

Out[41]: 'ëmail'

 

In [42]: raw.decode('utf-16')

Out[42]: 'ꯃ慭汩'

 

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

format string  (0) 2019.12.27
반복되는 문자열 찾기  (0) 2019.12.27
append, pop, sort, reverse  (0) 2019.12.27
encode, decode  (0) 2019.12.26
ascii, hex, unicode  (0) 2019.12.26

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 [19]: c=['a','b','c','a','b','a','d']

 

In [20]: c.count(1)

Out[20]: 0

 

In [21]: c.count('a')

Out[21]: 3

 

In [22]: c.count('b')

Out[22]: 2

 

In [23]: c.index('b')

Out[23]: 1

 

In [28]: c.insert(2,0)

 

In [29]: c

Out[29]: ['a', 'b', 0, 'c', 'a', 'b', 'a', 'd']

 

In [31]: c.remove(0)

 

In [32]: c

Out[32]: ['a', 'b', 'c', 'a', 'b', 'a', 'd']

 

In [33]: c.pop()

Out[33]: 'd'

 

In [34]: c

Out[34]: ['a', 'b', 'c', 'a', 'b', 'a']

 

In [35]: c.pop(1)

Out[35]: 'b'

 

In [36]: c

Out[36]: ['a', 'c', 'a', 'b', 'a']

 

In [37]: c.extend([1,2])

 

In [38]: c

Out[38]: ['a', 'c', 'a', 'b', 'a', 1, 2]

 

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

comprehension syntax  (0) 2019.12.27
list comprehension 예  (0) 2019.12.27
nested list  (0) 2019.12.27

+ Recent posts