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
### Python 多线程中的 AttributeError 错误分析 当处理 Python 的多线程编程时,可能会遇到 `AttributeError` 类似 `_MainThread object has no attribute '_is_stopped'` 这样的错误。此错误通常发生在尝试访问主线程对象不存在的属性上。 此类问题的一个常见原因是由于对 threading 模块内部实现细节的理解不足或不当操作引起的。具体来说,在某些情况下,程序可能试图在不适当的时间点检查或修改线程的状态[^1]。 为了防止这种类型的错误发生并提供一种解决方案: #### 解决方案一:使用 join 方法等待子线程完成 通过调用 `join()` 可以让主线程等待直到所有子线程结束再继续执行后续代码,从而避免了因过早终止而导致的对象状态异常情况的发生。 ```python import threading import time def worker(): print(f'Thread {threading.current_thread().name} starting') time.sleep(2) print(f'Thread {threading.current_thread().name} finishing') threads = [] for i in range(3): t = threading.Thread(target=worker) threads.append(t) t.start() # Wait for all threads to complete before exiting main program. for th in threads: th.join() print('All done.') ``` #### 解决方案二:捕获异常并安全退出 如果确实需要在线程运行期间对其进行监控,则可以考虑采用 try-except 结构来捕捉可能出现的任何未定义行为,并采取相应的措施确保应用程序能够正常关闭而不抛出不必要的警告信息。 ```python try: # Your multi-threaded operations here... except AttributeError as e: if "'_MainThread'" and "'_is_stopped'" in str(e): pass # Ignore this specific error or handle gracefully. else: raise # Re-raise other unexpected errors. finally: # Cleanup resources, close connections etc., ensuring proper shutdown. ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值