截图来自鸢尾花书《编程不难》第三章



在 Conda 中修改 channels 的优先级可以确保包从特定的源获取,这对于解决包的兼容性问题和加速安装过程非常有用。以下是步骤:
继续阅读
1 2 |
# 启动 jupyter lab |
1 2 |
# 运行当前块代码 ctrl + enter |
1 2 |
# 查看Python库 conda list |
1 2 3 4 5 6 7 8 |
# 查看已经安装的所有Python库 pip list # 调取某个特定库信息 pip show library_name # 卸载 pip uninstall library_name # 更新 pip install library_name --upgrade |
1 2 |
# 在spyder编辑器中打开当前目录 spyder . |
1 2 3 4 5 |
# 金融数据 pip install pandas-datareader # 创建web应用程序的库 pip install streamlit |
内置函数:https://docs.python.org/zh-cn/3/library/functions.html
查看python库打分:https://snyk.io/advisor/python/scoring
数学工具:https://mathworld.wolfram.com
数学社区:https://math.stackexchange.com
常用可视化包:Matplotlib、Seaborn、Plotly等
机器学习常用包:Numpy、Pandas、Statsmodels、Scikit-learn、TensorFlow、Streamlit等
资料内容来自公众号:GeekHour,学习记录于此,方便日后查阅学习。
1 2 3 4 5 |
[root@ce5d8a78a3b5 /]# yum install -y epel-release Failed to set locale, defaulting to C.UTF-8 CentOS Linux 8 - AppStream 78 B/s | 38 B 00:00 Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist |
1 |
cd /etc/yum.repos.d/ |
1 |
cd /etc/yum.repos.d/ |
1 2 3 |
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-* sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-* |
1 2 3 4 5 |
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo yum clean all yum makecache |
1 |
yum install wget –y |
.pot
文件(Portable Object Template)是翻译模板文件,用于在 WordPress 主题和插件中管理翻译字符串。它包含主题或插件中所有可翻译的文本字符串,但不包含具体的翻译。翻译者可以使用 .pot
文件来生成特定语言的 .po
和 .mo
文件。
.pot
文件以下是如何生成和使用 .pot
文件的步骤:
Poedit 是一个流行的翻译编辑工具,可以用于创建和编辑 .pot
、.po
和 .mo
文件。
可以使用 Poedit 的“提取字符串”功能,也可以手动创建 .pot
文件。
__
、_e
、_n
等)。.pot
文件如果你想手动创建 .pot
文件,可以使用 WP-CLI 工具或其他命令行工具。
.pot
文件: wp i18n make-pot . languages/your-theme.pot --exclude=vendor
这将在当前目录下扫描所有 PHP 文件,并在 languages
目录下生成 your-theme.pot
文件。.po
和 .mo
文件使用 .pot
文件生成特定语言的 .po
和 .mo
文件。
.pot
文件创建翻译。.po
和 .mo
文件。.po
和 .mo
文件上传到主题或插件的 languages
文件夹确保翻译文件命名规范为 {textdomain}-{locale}.po
和 {textdomain}-{locale}.mo
。例如,对于中文翻译文件:
1 2 3 4 |
my-theme/ ├── languages/ │ ├── zh_CN.po │ ├── zh_CN.mo |
确保在主题的 functions.php
文件中正确加载语言文件。
1 2 3 4 |
function mytheme_setup() { load_theme_textdomain('my-theme', get_template_directory() . '/languages'); } add_action('after_setup_theme', 'mytheme_setup'); |
.pot
文件:.pot
文件。.po
和 .mo
文件。zh_CN.po
和 zh_CN.mo
文件上传到主题的 languages
文件夹中。functions.php
文件中添加加载语言文件的代码。
1 2 3 4 |
function mytheme_setup() { load_theme_textdomain('my-theme', get_template_directory() . '/languages'); } add_action('after_setup_theme', 'mytheme_setup'); |
完成这些步骤后,WordPress 应该会根据站点语言设置自动加载相应的翻译文件。如果你在站点设置中选择了中文(简体),主题中的文本应该会显示为中文。
WP-CLI 是 WordPress 的命令行工具,允许你通过命令行界面管理 WordPress 安装和操作。它可以用来执行各种任务,包括生成 .pot
文件、安装和更新插件、管理用户等等。
你可以按照以下步骤安装 WP-CLI:
1 |
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar |
1 |
php wp-cli.phar --info |
1 2 |
chmod +x wp-cli.phar sudo mv wp-cli.phar /usr/local/bin/wp |
1 |
wp --info |
.pot
文件以下是使用 WP-CLI 生成 .pot
文件的步骤:
1 |
cd /path/to/your/theme-or-plugin |
wp i18n make-pot
命令:
1 |
wp i18n make-pot . languages/your-theme-or-plugin.pot |
这将在当前目录下扫描所有 PHP 文件,并在 languages
目录下生成 your-theme-or-plugin.pot
文件。
假设你的主题目录结构如下:
1 2 3 4 |
my-theme/ ├── functions.php ├── style.css └── languages/ |
1 |
cd /path/to/my-theme |
.pot
文件:
1 |
wp i18n make-pot . languages/my-theme.pot |
这将在 languages
目录下生成 my-theme.pot
文件。
你可以通过 wp i18n make-pot
命令的一些选项来自定义扫描和生成 .pot
文件的行为。例如:
1 |
wp i18n make-pot . languages/my-theme.pot --exclude=vendor,tests |
1 |
wp i18n make-pot . languages/my-theme.pot --domain=my-theme |
.pot
文件创建翻译.pot
文件。.po
和 .mo
文件。将生成的 zh_CN.po
和 zh_CN.mo
文件上传到主题或插件的 languages
文件夹中:
1 2 3 4 5 6 |
my-theme/ ├── functions.php ├── style.css └── languages/ ├── zh_CN.po ├── zh_CN.mo |
确保在主题的 functions.php
文件中正确加载语言文件:
1 2 3 4 |
function mytheme_setup() { load_theme_textdomain('my-theme', get_template_directory() . '/languages'); } add_action('after_setup_theme', 'mytheme_setup'); |
通过以上步骤,你可以使用 WP-CLI 工具生成 .pot
文件,并通过 Poedit 创建和管理翻译文件。这样可以确保你的 WordPress 主题或插件能够支持多语言,并根据站点语言设置自动加载相应的翻译文件。
在 WordPress 中,Template Parts(模板部分)允许你在区块编辑器中插入可重复使用的模板片段,比如页眉、页脚或其他布局部分。通过使用 <!-- wp:template-part {"slug":"header","area":"header","tagName":"header"} /-->
这样的注释代码,你可以在页面或文章中插入特定的模板部分。
以下是如何使用 Template Parts 并在 WordPress 主题中定义和注册这些部分的详细步骤。
首先,确保你的主题支持区块编辑器。然后,在主题目录中创建一个文件夹来存放模板部分,例如 parts
。
在这个文件夹中创建一个文件,例如 header.html
,用来定义你的页眉模板部分。这个文件可以包含你想要在页眉中使用的区块。例如:
parts/header.html
:
1 2 3 4 5 6 7 8 9 |
<!-- wp:group {"align":"full","backgroundColor":"primary","textColor":"white","className":"site-header"} --> <div class="wp-block-group alignfull has-primary-background-color has-white-color site-header"> <!-- wp:heading {"level":1} --> <h1>My Site Header</h1> <!-- /wp:heading --> <!-- wp:navigation {"layout":{"type":"flex","justifyContent":"right"}} /--> </div> <!-- /wp:group --> |
theme.json
文件中注册模板部分在主题根目录中,编辑或创建 theme.json
文件来注册模板部分。确保模板部分与其在主题中的实际位置相匹配。
theme.json
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
{ "version": 2, "templateParts": [ { "name": "header", "slug": "header", "title": "Header", "description": "The site header", "path": "./parts/header.html", "area": "header" } ] } |
在页面或文章编辑器中,你可以通过以下步骤插入模板部分:
在编辑器的代码视图中,添加以下注释代码以插入特定的模板部分:
1 2 |
<!-- wp:template-part {"slug":"header","area":"header","tagName":"header"} /--> |
确保你的主题目录结构类似如下:
1 2 3 4 5 6 7 |
my-theme/ ├── parts/ │ ├── header.html ├── functions.php ├── style.css ├── theme.json |
parts/header.html
在 parts/header.html
文件中定义页眉模板部分:
1 2 3 4 5 6 7 8 9 |
<!-- wp:group {"align":"full","backgroundColor":"primary","textColor":"white","className":"site-header"} --> <div class="wp-block-group alignfull has-primary-background-color has-white-color site-header"> <!-- wp:heading {"level":1} --> <h1>My Site Header</h1> <!-- /wp:heading --> <!-- wp:navigation {"layout":{"type":"flex","justifyContent":"right"}} /--> </div> <!-- /wp:group --> |
theme.json
在 theme.json
文件中注册模板部分:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
{ "version": 2, "templateParts": [ { "name": "header", "slug": "header", "title": "Header", "description": "The site header", "path": "./parts/header.html", "area": "header" } ] } |
在你希望使用这个模板部分的页面或文章中,添加以下注释代码:
1 |
<!-- wp:template-part {"slug":"header","area":"header","tagName":"header"} /--> |
通过这些步骤,你可以在 WordPress 主题中定义和使用模板部分,使得页面布局更加模块化和可重用。
add_menu_page
是 WordPress 提供的一个函数,用于在 WordPress 管理后台菜单中添加一个顶级菜单页面。这个函数可以用来创建自定义的管理页面,例如插件设置页面或自定义的管理功能页面。以下是 add_menu_page
函数的详细解释和示例。
1 2 3 4 5 6 7 8 9 |
add_menu_page( string $page_title, string $menu_title, string $capability, string $menu_slug, callable $function = '', string $icon_url = '', int $position = null ); |
$page_title
(string) (必需):
<title>
标签中。$menu_title
(string) (必需):
$capability
(string) (必需):
$menu_slug
(string) (必需):
$function
(callable) (可选):
$icon_url
(string) (可选):
$position
(int) (可选):
以下是一个完整的示例代码,展示如何使用 add_menu_page
在 WordPress 管理后台添加一个自定义菜单页面。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
<?php /* Plugin Name: Custom Admin Page Description: 一个示例插件,展示如何在 WordPress 管理后台添加自定义菜单页面 Version: 1.0 Author: 你的名字 */ if (!defined('ABSPATH')) { exit; // 避免直接访问 } // 添加管理菜单 function custom_admin_menu() { add_menu_page( '自定义管理页面', // 页面标题 '自定义页面', // 菜单标题 'manage_options', // 权限 'custom-admin-page', // 菜单 slug 'custom_admin_page_content', // 回调函数 'dashicons-admin-generic', // 图标 25 // 位置 ); } add_action('admin_menu', 'custom_admin_menu'); // 回调函数,渲染页面内容 function custom_admin_page_content() { ?> <div class="wrap"> <h1><?php _e('欢迎来到自定义管理页面', 'textdomain'); ?></h1> <p><?php _e('这是一个自定义的管理页面。', 'textdomain'); ?></p> </div> <?php } ?> |
custom_admin_menu
函数:使用 add_menu_page
函数添加一个新的顶级菜单页面。
'自定义管理页面'
:这是页面标题。'自定义页面'
:这是菜单标题。'manage_options'
:只有具有 manage_options
权限的用户(通常是管理员)才能看到这个菜单。'custom-admin-page'
:这是菜单的 slug,URL 中会用到。'custom_admin_page_content'
:这是点击菜单项时调用的回调函数。'dashicons-admin-generic'
:这是菜单项旁边显示的图标。25
:这是菜单项在管理菜单中的位置。custom_admin_page_content
函数:这是回调函数,用于渲染自定义菜单页面的内容。
__('...')
和 _e('...')
用于国际化,分别返回和直接输出翻译后的字符串。通过使用 add_menu_page
函数,你可以轻松地在 WordPress 管理后台创建自定义的管理页面。这对于插件开发和为用户提供自定义功能非常有用。你可以根据需要进一步扩展页面的功能和内容,例如添加表单、处理表单提交等。
1 2 3 |
"editor.codeActionsOnSave": { "source.organizeImports": "always" } |
1 2 3 4 5 6 7 8 9 10 |
npm install --save-dev eslint-plugin-simple-import-sort module.exports = { // ... 其他配置 plugins: ['simple-import-sort'], rules: { 'simple-import-sort/imports': 'error', 'simple-import-sort/exports': 'error', }, }; |
Array里面存放key的字符串,而不是number
最后通过执行如下命令解决问题:
1 |
codesign -f -s - --deep /Applications/Eclipse.app |
1 |
data instanceOf FormData |
公众号
头条号