안녕하세요~ 강의 잘 듣고 있습니다~
텔레그램 봇 만들기 2번째 심화 강의 중 (강의 시작 9분 정도),
텔레그램에 '/dir' 을 입력하면
터미널 창에 module 'ntpath' has no attribute 'exist' 라는 메시지가 출력됩니다.
스택오버플로우로 검색해 봐도 어떤 문제인지 찾지를 못했어요;;
파이썬은 3버전 이상입니다.
어떤 문제일까요;;;
import os
import telepot
import logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
TELEGRAM_TOKEN = "1112174312:AAEyoQlv66VJuO2NyqLWHvjg7tAE4JMdavQ"
def get_dir_list(dir):
str_list = ""
if os.path.exists(dir):
file_list = os.listdir(dir)
file_list.sort()
for f in file_list:
full_path = os.path.join(dir, f)
if os.path.isdir(full_path):
f = "[" + f + "]"
str_list += f
str_list += "\n"
str_list.strip()
return str_list
def handler(msg):
content_type, chat_type, chat_id, msg_date, msg_id = telepot.glance(
msg, long=True)
print(msg)
# /dir c:\\test
if content_type == "text":
# bot.sendMessage(chat_id, "[반사] {}".format(msg["text"]))
str_message = msg["text"]
if str_message[0:1] == "/":
args = str_message.split(" ")
command = args[0]
del args[0]
if command == "/dir":
filepath = " ".join(args)
if filepath.strip() == "":
bot.sendMessage(chat_id, "/dir [대상폴더]로 입력해 주세요.")
else:
filelist = get_dir_list(filepath)
bot.sendMessage(chat_id, filelist)
bot = telepot.Bot(TELEGRAM_TOKEN)
bot.message_loop(handler, run_forever=True)