
show_source 함수는 HTML 소스 코드를 보여주는 함수로, 기본적으로 HTML 파일만 열 수 있습니다. 하지만 다른 형식의 파일도 열 수 있습니다.
예를 들어, txt 파일이나 csv 파일을 열 수 있습니다.
txt 파일을 열기 위해서는 다음과 같이 사용할 수 있습니다.
#hostingforum.kr
python
from IPython.display import display, HTML
from IPython.display import IFrame
import os
def show_txt_file(file_path):
with open(file_path, 'r') as f:
txt = f.read()
display(HTML('' + txt + '
'))
# txt 파일 경로를 입력하세요
file_path = '경로를 입력하세요'
show_txt_file(file_path)
csv 파일을 열기 위해서는 다음과 같이 사용할 수 있습니다.
#hostingforum.kr
python
from IPython.display import display, HTML
from IPython.display import IFrame
import os
import pandas as pd
def show_csv_file(file_path):
df = pd.read_csv(file_path)
html = df.to_html()
display(HTML(html))
# csv 파일 경로를 입력하세요
file_path = '경로를 입력하세요'
show_csv_file(file_path)
파일의 경로를 보여주고 싶다면, show_source 함수 대신에 IFrame 함수를 사용할 수 있습니다.
#hostingforum.kr
python
from IPython.display import IFrame
# 파일 경로를 입력하세요
file_path = '경로를 입력하세요'
IFrame(file_path, width='100%', height='500')
이 코드는 파일의 경로를 보여주고, 파일의 내용도 보여줍니다.
파일의 경로만 보여주고 싶다면, IFrame 함수의 height 속성을 0으로 설정할 수 있습니다.
#hostingforum.kr
python
from IPython.display import IFrame
# 파일 경로를 입력하세요
file_path = '경로를 입력하세요'
IFrame(file_path, width='100%', height='0')
2025-03-24 00:11