Python Tox 使用笔记

Tox是一个项目自动化工具,在此记录下没在文档和网上tutorial找到的使用细节。试验中尽可能使用最小tox.ini。本文使用tox --showconfig -- <args...>的形式观察配置结果。如果文中没有提<args...>是什么(例如直接说“配置结果为”,而不是“运行…后配置结果为“),那么运行的是tox --showconfig

默认basepython

情况一

tox.ini为空。此时只有一个匿名虚拟环境。

配置结果为:

...

[testenv:python]
...
basepython = /Library/Frameworks/Python.framework/Versions/3.9/bin/python3
...

这里的/Library/Frameworks/Python.framework/Versions/3.9/bin/python3是本机上按PATH顺序第一个遇到的Python解释器(注意这里既不是第一个python也不是第一个python3)。另外可以观察到,匿名虚拟环境被命名为python

情况二

tox.ini

[testenv:x]
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个移动笔记系统的示例Python代码,包括笔记的添加、编辑、删除、查询、导出和数据挖掘等全部功能: ```python import pandas as pd import numpy as np import hashlib import os import csv import matplotlib.pyplot as plt from sklearn.cluster import KMeans # 笔记文件路径 NOTES_FILE = 'notes.csv' # 初始化笔记数据 if not os.path.exists(NOTES_FILE): notes_df = pd.DataFrame(columns=['id', 'title', 'content', 'tags']) notes_df.to_csv(NOTES_FILE, index=False) # 生成唯一ID def generate_id(title): return hashlib.md5(title.encode('utf-8')).hexdigest() # 添加笔记 def add_note(): title = input('Enter note title: ').strip() content = input('Enter note content: ').strip() tags = input('Enter note tags (comma-separated): ').strip() # 生成唯一ID note_id = generate_id(title) # 读取笔记数据 notes_df = pd.read_csv(NOTES_FILE) # 检查笔记是否已存在 if note_id in notes_df['id'].tolist(): print('Note already exists!') return # 添加新笔记 new_note = pd.DataFrame({'id': [note_id], 'title': [title], 'content': [content], 'tags': [tags]}) notes_df = pd.concat([notes_df, new_note], ignore_index=True) # 保存笔记数据 notes_df.to_csv(NOTES_FILE, index=False) print('Note added successfully!') # 编辑笔记 def edit_note(): note_id = input('Enter note ID: ').strip() # 读取笔记数据 notes_df = pd.read_csv(NOTES_FILE) # 检查笔记是否存在 if note_id not in notes_df['id'].tolist(): print('Note not found!') return # 编辑笔记 title = input('Enter new note title (leave blank to keep existing): ').strip() content = input('Enter new note content (leave blank to keep existing): ').strip() tags = input('Enter new note tags (comma-separated, leave blank to keep existing): ').strip() note_idx = notes_df.index[notes_df['id'] == note_id][0] if title: notes_df.at[note_idx, 'title'] = title if content: notes_df.at[note_idx, 'content'] = content if tags: notes_df.at[note_idx, 'tags'] = tags # 保存笔记数据 notes_df.to_csv(NOTES_FILE, index=False) print('Note edited successfully!') # 删除笔记 def delete_note(): note_id = input('Enter note ID: ').strip() # 读取笔记数据 notes_df = pd.read_csv(NOTES_FILE) # 检查笔记是否存在 if note_id not in notes_df['id'].tolist(): print('Note not found!') return # 删除笔记 note_idx = notes_df.index[notes_df['id'] == note_id][0] notes_df = notes_df.drop(index=note_idx) # 保存笔记数据 notes_df.to_csv(NOTES_FILE, index=False) print('Note deleted successfully!') # 查询笔记 def search_notes(): query = input('Enter search query: ').strip().lower() # 读取笔记数据 notes_df = pd.read_csv(NOTES_FILE) # 搜索笔记 search_results = notes_df[notes_df.apply(lambda x: query in x['title'].lower() or query in x['content'].lower() or query in x['tags'].lower(), axis=1)] # 显示搜索结果 if search_results.empty: print('No notes found.') else: print(f'{len(search_results)} notes found:') for _, row in search_results.iterrows(): print(f"{row['title']} ({row['tags']})") print(row['content']) print() # 导出笔记 def export_notes(): export_file = input('Enter export file name (CSV format): ').strip() # 读取笔记数据 notes_df = pd.read_csv(NOTES_FILE) # 保存笔记数据到CSV文件 notes_df.to_csv(export_file, index=False) print('Notes exported successfully!') # 笔记数据挖掘 def data_mining(): # 读取笔记数据 notes_df = pd.read_csv(NOTES_FILE) # 提取笔记的标题和标签 notes_data = notes_df[['title', 'tags']] # 将标签转换为二进制特征 tags_dummies = notes_data['tags'].str.get_dummies(sep=',') # 合并标题和标签特征 notes_features = pd.concat([notes_data['title'], tags_dummies], axis=1) # 使用K-Means聚类算法将笔记分为不同的主题群组 kmeans = KMeans(n_clusters=3) kmeans.fit(notes_features.iloc[:, 1:]) notes_data['topic'] = kmeans.labels_ # 可视化笔记主题分布 plt.pie(notes_data['topic'].value_counts(), labels=['Topic 0', 'Topic 1', 'Topic 2'], autopct='%1.1f%%') plt.title('Note Topics') plt.show() # 主程序 while True: print('1. Add note') print('2. Edit note') print('3. Delete note') print('4. Search notes') print('5. Export notes') print('6. Data mining') print('7. Exit') choice = input('Enter your choice: ').strip() if choice == '1': add_note() elif choice == '2': edit_note() elif choice == '3': delete_note() elif choice == '4': search_notes() elif choice == '5': export_notes() elif choice == '6': data_mining() elif choice == '7': break else: print('Invalid choice. Please try again.') ``` 这段代码实现了笔记的添加、编辑、删除、查询、导出和数据挖掘等全部功能。其中,笔记数据使用CSV文件保存,每个笔记包括唯一的ID、标题、内容和标签。笔记的ID使用MD5哈希算法生成。笔记的查询使用简单的关键字搜索。笔记的数据挖掘使用K-Means聚类算法将笔记分为不同的主题群组,并使用Matplotlib库将笔记主题分布可视化。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值