결과를 세로 방향으로 저장하는 방법 (How do i save the result in a Vertical direction)


문제 설명

결과를 세로 방향으로 저장하는 방법 (How do i save the result in a Vertical direction)

#This is a solarcell simulator.



def save(result):
    with open('text.txt', 'w') as file:
       file.write(result)                                    


def main():

result = []

while True:
    val=int(input("Do you want to check a new latitude? 1.yes  2.No" ))

    if val == 1:
        print("lets go")

        lat=latitude()

        result.append(calc(lat))



    elif val==2:
        print ("Bye!")
        spara(str(result))
        break
    else:
        print("yes or no")

이것은 text.txt 파일에서 얻은 것입니다.

[(1, 289.4736790328647), (2, 301.5078692306731)] 

하지만 이것이 제가 원하는 것입니다

[(1, 289.4736790328647) 
(2, 301.5078692306731)]

참조 솔루션

방법 1:

if result is a list of tuples then this would work:

file.write('[' + '\n'.join(map(str,result)) + ']') 

(by burhan hashiAyush)

참조 문서

  1. How do i save the result in a Vertical direction (CC BY‑SA 2.5/3.0/4.0)

#list #Python






관련 질문

파이썬에서 데이터를 정렬하는 방법 (How arrange data in python)

포스트백 후 모든 항목이 손실되는 CheckBoxList 컨트롤 (CheckBoxList control losing all items after post back)

목록 목록의 효과적인 구현 (Effective implementation of list of lists)

DictReader가 내 파일의 두 줄을 건너뛰고 있습니까? (DictReader is skipping two lines of my file?)

잘못된 값을 얻는 목록 확인 후 (After list checking getting wrong value)

결과를 세로 방향으로 저장하는 방법 (How do i save the result in a Vertical direction)

Python 2.x: 튜플 목록의 항목 합계 (Python 2.x: Summing items in a list of tuples)

itemgetter를 사용하지 않고 n번 발생하는 요소가 있는 목록 내 항목 인쇄 (Printing items inside a list which have an element that occurs n times without using itemgetter)

반환된 목록에서 장소가 바뀐 항목 삭제 (Deleting items that have the place swapped around in a returned list)

arrayToList가 홀수 출력을 생성합니다. 뭐가 문제 야? (arrayToList producing odd outputs. What's wrong?)

R 목록을 벡터로 바꾸는 방법과 목록이 필요한 이유 (R how to turn lists to vectors, and why a list at all)

python, 출력으로 코딩하는 동안 pycharm에서 이 메시지를 받았습니다. :TypeError: can't convert type 'list' to numerator/denominator (python , I got this message in pycharm while coding as output :TypeError: can't convert type 'list' to numerator/denominator)







코멘트