jsup 2.1 - investor's relief (experiment on separation of investment and SNS)

by joviansummer original STEEMIT post: https://steemit.com/blog/@joviansummer/jsup-2-1-investor-s-relief-experiment-on-separation-of-investment-and-sns Hello, this is @joviansummer(witness: @jswit). I'm starting a new experiment regarding my @jsup vote service. The purpose of this experiment is to separate STEEM investment and social interaction(posting/commenting). For many people, writing a post daily(literally 365 posts per year) is not easy. It's not fun, and mandatory daily post only written for self-voting delegation service tends to result in useless low-quality content. I hope this new function of @jsup will reduce those posts, and also make it a bit more easy to invest in STEEM without worrying about daily posting. I think pressure of daily posting significantly undermines Steem as SNS. It's not fun. This is how it works: From 11:45 PM to 11:50 PM every night(reference time zone is GMT+9), @jsup checks if eligible delegators wrote something and received daily v...

파이썬에서 텍스트 파일 읽기

by joviansummer
original STEEMIT post: https://steemit.com/blog/@joviansummer/2v14rm


파이선에서 텍스트 파일을 읽거나 쓰는 방법입니다.

먼저 텍스트 파일을 읽으려면 open() 함수에서 읽고자 하는 파일을 읽기(r) 모드로 지정합니다.

# test.txt 파일을 읽기 모드로 열어서 파일 객체 f에 할당
f = open('test.txt', 'r')

파일의 내용을 한꺼번에 읽을 경우에는 read()를 사용합니다. 읽은 후에는 열려 있는 파일을 닫아줍니다.

# 파일 객체 f에 의해 열려 있는 파일을 읽어서 문자열 전체를 변수 x에 할당
x = f.read()
f.close()

위의 예시에서는 여러줄로 된 내용 전체가 하나의 변수 x에 할당되었습니다. 만약 내용을 한줄씩 읽고 싶다면 readline()을 사용합니다.

예를 들어 파일의 내용을 한줄씩 읽어서 리스트(list)의 원소로 추가할 경우 아래와 같이 할 수 있겠습니다.

# 리스트 초기화
x_list = []
# 파일 열기
f = open('test.txt', 'r')
# 한줄씩 읽기 시작
while True:
  line_str = f.readline()
  if not line_str:
    # 읽은 줄이 null string일 경우 while 반복문 중단
    break
  else:
    # 리스트에 원소 추가
    x_list.append(line_str)
f.close()

Comments

Popular posts from this blog

스티미언의 영향력 지수 계산

jsup/avle code update - you don't have to write post everyday

jsup/avle 보팅 코드 갱신 - 1일1포스팅 강박에서 벗어나기