반응형

 

for i in range(0,20):
    globals()['value_{}'.format(i)] = i

print(value_1)
print(value_19)

 

참고로 동적변수를 print 하였을 때 계속 null값이 나와서 당황하였으나, 이후 알고 보니 변수 선언을 해줘서 발생했던 문제이다.

아래는 잘못된 표현이다.

value_1 = value_2 = ....... value_19 = '' => 잘못된 선언
for i in range(0,20):
    globals()['value_{}'.format(i)] = i

print(value_1)
print(value_19)

 

위 잘못된 선언을 하고자 한다면

globals() 대신 locals()를 사용하면된다.

value_1 = value_2 = ....... value_19 = ''
for i in range(0,20):
    locals()['value_{}'.format(i)] = i

print(value_1)

print(value_19)
반응형

'Programming > python' 카테고리의 다른 글

bz2  (0) 2022.07.20
반응형

>> import bz2
>> str = b"sqlplus scott/tiger"

 

# compress

>> compress_str = bz2.compress(str)

>> print(compress_str)

b'BZh91AY&SYY\xf9\xdb\xc5\x00\x00\x07\x11\x80@\x00\x8a\xa4\xfe\x00 \x001\x00\x00\x08@d\xf0\xa1X\xedh\x9b\x14\x18~N\xfe.\xe4\x8ap\xa1 \xb3\xf3\xb7\x8a'

 

# decompress

>> decompress_str = bz2.decompress(compress_str)

>> print(d)

b"sqlplus scott/tiger"

 

>> print(d.decode())
sqlplus scott/tiger

 

 

# 오라클 접속 예시

>> import os

>> os.system(bz2.decompress(compress_str))

 

https://docs.python.org/3/library/bz2.html

 

bz2 — Support for bzip2 compression — Python 3.10.5 documentation

bz2 — Support for bzip2 compression Source code: Lib/bz2.py This module provides a comprehensive interface for compressing and decompressing data using the bzip2 compression algorithm. The bz2 module contains: (De)compression of files bz2.open(filename,

docs.python.org

 

반응형

'Programming > python' 카테고리의 다른 글

동적변수  (0) 2022.07.28

+ Recent posts