파이썬 함수속 for 과if문에서 변수 선언

조회수 677회
        def run(command):
            subprocess.call(command, shell=True)


        # Real-time output but not color display, you can return the result
        def sh(command, print_msg=True):
            p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
            lines = []
            for line in iter(p.stdout.readline, b''):
                line = line.rstrip().decode('utf8')
                if print_msg:

                    global Save_text_console
                    Save_text_console = lines

                lines.append(line)
            return lines
        run("ipconfig")

        while True:
            print(Save_text_console)

함수 안에 있는 for 에서 변수를 선언하여 가져오고 싶습니다.

  • (•́ ✖ •̀)
    알 수 없는 사용자
  • 원하는게 정확히 무엇이고, 어떤 것이 문제인지 알려주세요 초보자 2021.5.14 08:51
  • 함수안에있는 for 문이라면 return 하시면되시지 않나용 김호원 2021.5.14 15:07

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)