tplmap 运行报错 Exiting: ‘bool‘ object has no attribute ‘replace‘

文章描述了一个在使用tplmap时遇到的错误:boolobjecthasnoattributereplace。解决方案是删除tplmap/core/checks.py文件中的Twig相关条目,保存并退出。这表明问题可能与Python的模板引擎Twig有关,且提供了解决此类问题的具体步骤。

报错信息:[!][tplmap] Exiting: 'bool' object has no attribute 'replace'

解决办法:删除tplmap/core/checks.py文件中Twig条目,保存退出。

Twig就在此列表中:
plugins = [
    Smarty,
    Mako,
    Python,
    Tornado,
    Jinja2,
    Freemarker,
    Velocity,
    Slim,
    Erb,
    Pug,
    Nunjucks,
    Dot,
    Dust,
    Marko,
    Javascript,
    Php,
    Ruby,
    Ejs
]

from typing import Optional import os from task7 import TextProcessor class Role: def __init__(self, user_name: str, access: str, name: str): # YOUR CODES START HERE self.user_name = user_name self.access = access self.name = name def get_user_name(self): # YOUR CODES START HERE return self.user_name def get_access(self): # YOUR CODES START HERE return self.access def get_name(self): # YOUR CODES START HERE return self.name class RoleBasedVocabSys: def __init__( self, users_info: dict, stopwords_filepath : str = "data/stop_words_english.txt", corpus_filepath : str = "data/ag_news_test.csv", idx2label_filepath : str = "data/idx2label.json" ): # YOUR CODES START HERE # replace with correct initialization #stopwords_filepath="data/stop_words_english.txt" #corpus_filepath="data/ag_news_test.csv" #idx2label_filepath="data/idx2label.json" self.users_info = users_info self.current_user : Optional[Role] = None self.text_processor = TextProcessor(stopwords_filepath, corpus_filepath, idx2label_filepath) def start(self): # YOUR CODES START HERE print("Welcome to the Mark system v0.0!") while True: menu = self.generate_menu() print(menu) choice = self.get_user_choice() if choice == "1": print("Exiting the system. See you!") break elif choice == "2": self.current_user = None self.login() elif choice == "3" and self.current_user: top_words = self.text_processor.get_top_n(10) print("The top 10 frequent words:") for word, freq in top_words: print(f"{word}:{freq}") elif choice == "4" and self.current_user: bottom_words = self.text_processor.get_bottom_n(10) print("The bottom 10 frequent words:") for word, freq in bottom_words: print(f"{word}:{freq}") elif choice == "5" and self.current_user and self.current_user.get_access() == "admin": self.text_processor.update_from_file("data/add.csv") print("Updated Vocabulary for adding.") elif choice == "6" and self.current_user and self.current_user.get_access() == "admin": self.text_processor.update_from_file("data/delete.csv") print("Updated Vocabulary for deleting.") def generate_menu(self) -> str: # YOUR CODES START HERE if self.current_user is None: return("Please Login:\n""1.Exit\n""2.Login") base_menu = (f"Welcome {self.current_user.get_name()}\n""Please choose one option below:\n" "1.Exit\n""2.Logout/Re-Login\n""3.Show top 10 frequency vocabularies\n" "4.Show last 10 frequency vocabularies") if self.current_user.get_access() == "admin": base_menu += ("\n5.Updating Vobulary for adding""\n6.Updating Vobulary for excluding") return base_menu def verify_user_choice(self, user_choice) -> bool: # YOUR CODES START HERE if not user_choice.isdigit(): return False elif self.current_user is None: return user_choice in ["1", "2"] elif self.current_user.get_access() == "reader": return user_choice in ["1", "2", "3", "4"] elif self.current_user.get_access() == "admin": return user_choice in ["1", "2", "3", "4", "5", "6"] return False def get_user_choice(self): # YOUR CODES START HERE choice = input("Enter your choice: ") while not self.verify_user_choice(choice): choice = input("Enter your choice: ") return choice def login(self): # YOUR CODES START HERE while self.current_user is None: username = input("Please key your account name: ") password = input("Please key your password: ") if username in self.users_info: user_data = self.users_info[username] if user_data["password"] == password: self.current_user = Role(user_name = username, access = user_data["role"], name = user_data["name"]) print(f"Welcome {self.current_user.get_name()}") return else: print("Username or password is incorrect.") if __name__ == "__main__": users_info = { "Jueqing": { "role": "reader", "password": "jueqing123", "name": "Jueqing Lu" }, "Trang": { "role": "admin", "password": "trang123", "name": "Trang Vu" }, "land": { "role": "admin", "password": "landu123", "name": "Lan Du" } } a_sys = RoleBasedVocabSys(users_info) a_sys.start()
09-24
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值