사용자 도구

사이트 도구


python:console

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

양쪽 이전 판이전 판
다음 판
이전 판
python:console [2016/08/09 04:21] rex8312python:console [2024/03/23 02:42] (현재) – 바깥 편집 127.0.0.1
줄 1: 줄 1:
 ====== Python Console ====== ====== Python Console ======
  
-  * 컬러 문자 출력 +===== 컬러 문자 출력 =====
-    *  [[https://pypi.python.org/pypi/colorama|colorama]]+
  
-  * ascii문자로 plotting+  * [[https://github.com/willmcgugan/rich|rich]] 
 +    * https://medium.com/trabe/building-rich-console-interfaces-in-python-16338cc30eaa 
 +  * [[https://pypi.org/project/termcolor/|termcolor]] 
 +  * [[https://pypi.python.org/pypi/colorama|colorama]] 
 + 
 +===== ascii문자로 plotting =====
     * http://stackoverflow.com/questions/20295646/python-ascii-plots-in-terminal     * http://stackoverflow.com/questions/20295646/python-ascii-plots-in-terminal
       * gnuplot 사용       * gnuplot 사용
- +      * 예제 
-<code python> +<code python ascii_plot.py
-def ascii_plot(xs, ys):+def ascii_plot(xs, ys, title=None, print_out=False):
     import subprocess     import subprocess
-    gnuplot = subprocess.Popen(["/usr/bin/gnuplot"], stdin=subprocess.PIPE, stdout=subprocess.PIPE) +    import platform 
-    input_string = "set term dumb 79 25\n" +    if platform.system().lower() == 'windows': 
-    input_string += "plot '-' using 1:2 title 'Line1' with linespoints \n" +        path = 'C:/Program Files/gnuplot/bin/gnuplot.exe' 
-    for i, j in zip(xs, ys): +    else: 
-        input_string += "%f %f\n" % (i, j) +        path = "/usr/bin/gnuplot" 
-    input_string += "e\n"+    gnuplot = subprocess.Popen([path],  
 +                               stdin=subprocess.PIPE,  
 +                               stdout=subprocess.PIPE
 +                               universal_newlines=True
 +    input_string = "set term dumb 90 25\n" 
 +    input_string += "set key off\n" 
 +     
 +    if not hasattr(ys[0], '__len__'): 
 +        ys_list = [ys] 
 +    else: 
 +        ys_list = ys 
 + 
 +    input_string += "plot "  
 +    input_string += ', '.join(["'-' using 1:2 title 'Line1' with linespoints" for ys in ys_list]) 
 +    input_string += '\n
 + 
 +    for ys in ys_list: 
 +        for i, j in zip(xs, ys): 
 +            input_string += "%f %f\n" % (i, j) 
 +        input_string += "e\n" 
     output_string, error_msg = gnuplot.communicate(input_string)     output_string, error_msg = gnuplot.communicate(input_string)
 +
 +    if title is not None:
 +        title = '** {} **\n'.format(title.title())
 +        output_string = title + output_string
 +
 +    if print_out:
 +        print(output_string)
 +        
     return output_string     return output_string
  
줄 32: 줄 64:
         sleep(1)         sleep(1)
 </code> </code>
-         + 
-  프로그래스 바 출력+===== 프로그래스 바 출력 =====
     * https://pypi.python.org/pypi/tqdm     * https://pypi.python.org/pypi/tqdm
     * https://pypi.python.org/pypi/progressbar2     * https://pypi.python.org/pypi/progressbar2
 +
 +===== TUI =====
 +
 +  * http://urwid.org/
 +  * http://npyscreen.readthedocs.io
python/console.1470716498.txt.gz · 마지막으로 수정됨: 2024/03/23 02:38 (바깥 편집)