Planet DebugUself

September 18, 2019

蠎周刊

Issue 386

原文: PyCoder's Weekly - Issue #386

PyCoder

  • 190918 Zoom.Quiet(大妈) 用时 42 分钟 完成快译
  • 190918 Zoom.Quiet(大妈) 用时 17 分钟 完成格式转抄.

The submission deadlines are: Tutorial proposals are due November 22, 2019. Talk, Charlas, Poster, and Education Summit proposals are due December 20, 2019.

(是也乎:

对比 PyCon China 2019

我们才开始, 人家已经面向 2020 了... 其实, 这才是应该的节奏;

不过, 今年 PyCon19中国, 扩张到6个城市, 也是世界之最了.

欢迎来嗯哼, 俺也去其中一个, 猜, 哪个?

)

Explore the similarities and differences you’ll find when comparing Python vs C++. You’ll learn about memory management, virtual machines, object-oriented programming differences, and much more.

(是也乎:

其实, C++ 是创始人都在警告: 想想瓦萨号 的一种失控语言

)

A draft PEP that proposes adding a new fully persistent and immutable mapping type called frozenmap to the collections module in the Python standard library.

(是也乎:

不可变量是系统安全的基础, 可惜...

)

“There are large distinctions between the two programming languages, but I’ll try to give the most notable that I encountered–as I approached Java from a Python-heavy background.”

The Python-powered tech stack of a one-person company (ListenNotes podcast search engine).

(是也乎:

单人企业就得优先选择 无聊技术栈; 终于, Python 从 PHP 手中抢走了这一称号.

)

How Instagram uses types to document and enforce a contract for their Python HTTP APIs.

讨论

Discussions

Also see the related discussion on Hacker News.

(是也乎:

在企业世界 Python 到底流行卟?


)

文章,教程和嗯哼

Articles, Tutorials and Talks

Learn how to use PyGame. This library allows you to create games and rich multimedia programs in Python. You’ll see how to draw items on your screen, implement collision detection, handle user input, and much more!

(是也乎:

其实, PyGame 才是 Python 世界中最受欢迎的 GUI 框架.

)

“Inspired by an actual incident we had in one of our systems caused by an Export to Excel functionality implemented in Python, we go through the process of identifying the problem, experimenting and benchmarking different solutions.”

(是也乎:

其实, 特别想说声: 活该

)

“With 35 million lines of Python code, the Athena trading platform is at the core of JPMorgan’s business operations. A late start to migrating to Python 3 could create a security risk.”

(是也乎:

JP魔根曰了, 俺不升级...

)

There are two ways to select a Series from a DataFrame: “dot notation” and “bracket notation” (square brackets). Find out which one you should use, and why.

(是也乎:

哪儿哪儿都有隐技.

)

How Python looks up object attributes like obj.name using a “instance, class, parent, object” search algorithm.

(是也乎:

OOP 是邪魔...叕来一堆新缩写.

)

Why you should (almost) never delete a bad release from PyPI—and what to do as a package maintainer instead.

(是也乎:

历史应该是绝对的...

)

A Python “gotcha” involving floating point numbers and tuples.

(是也乎:

Python 暗黑旮旯故事...

)

(是也乎:

URI 安全用

)

好物

Interesting Projects, Tools and Libraries, Projects & Code

(是也乎:

屌的...

)

(是也乎:

From Python to Silicon!

嗯哼, 这个 Slogan 够梗的...

)

(是也乎:

每一条都可以是个播客节目了...

)

(是也乎:

awesome 已经是github 第一子品牌了... )

📆🐍 活动/大会

Events, MeetUp 真的是全球线下活动组织中心

(是也乎:

大妈去 南宁 嗯哼 )

(是也乎:

DjangoGirls 活动大放光芒的社区...

)

DAMA

❤️ Happy Pythonic ;-(大妈私人无责任播报)

第3期已经上线, 为期6周

(是也乎:

没想到触发出一个 DoIs ~ 真正实用的 AI 落地方向: 辅助识别野外白海豚...

)

是也乎

NN 3774

by Zoom.Quiet at September 18, 2019 03:42 AM

September 12, 2019

bambooooooom

extract and update messages for vue-i18n

搞 Vue i18n 的时候暂时了解有两套方案。一套是主要用 vue-gettext 以及搭配 GNU gettext utilities 的几个 command (msgmerge / msginit / msgattrib)一起使用,整体工具链用起来并不是很舒服,上手难度并不小。 vue-gettext 本身也有几个 known issue 无法解决。 作为前端,比较希望能完全用 js 解决就好,不需要依赖其他。 然后才开始仔细研究另一种方案,也就是 vue-i18n。因为这个库的作者也是 vuejs core team,看着 star 最多,大概也是比较靠谱的。

大致试过之后觉得 vue-i18n 使用起来比 gettext 系列简单轻巧多了,唯一的不足是翻译的 messages 文件需要自己手写。

如果添加了新的页面,有新的 string 需要翻译,或者有些页面文字修改了,翻译也需要同步修改的时候, vue-i18n 就似乎没有这个 extract & update 的功能。

理想的工作流程是做页面的时候,文字全部都按照默认语言写上并标注(vue-i18n 的情况就是用上 $t 或者 $tc 等)。页面完成后,启用某个 npm script 即可生成或者更新待翻译的文件。 最不希望的就是在做页面中间或者完成后,还得自己记得维护去更新待翻译的字符串。

今天又搜索了一下能提取 vue-i18n 标注的现成方案,暂时只找到一个比较靠谱的, vue-i18n-extract

npm install 试了一下之后又仔细看了看文档和 issue,发现 vue-i18n-extract 其实也只做了 extract 部分,更新现有文件部分处于讨论阶段,并没有完成。 但是这个工具的作者做了提取之后也做了一个与现有翻译文件的比较,所以可以输出一个 report, 也就是我最想知道的哪些 string 还不在文件里(missingKeys),以及哪些已经不存在了(unusedKeys)。

report 本身就是个 plain object,自己基于这个再加工一下不就可以得到自己想要的东西了嘛!

Demo

假设现在有这么两个翻译文件

// lang/en_US.js
export default {
  'a-hello': 'Hello World!',
  'b-hello': 'Hello Banana!',
  //'c-hello': 'Hello Catherine!',
}

// lang/zh_CN.js
export default {
  'a-hello': '你好世界!',
  'b-hello': '你好🍌!',
  //'c-hello': '你好凯瑟琳!',
}

然后在页面上有一个新的 c-hello 需要提取出来进行翻译。 简单写个 helper script:

// extract.js
const fs = require('fs');
const path = require('path');
const {promisify} = require('util');
const Extract = require('vue-i18n-extract').default;

/* global __dirname */
const readDir = promisify(fs.readdir);
const writeFile = promisify(fs.writeFile);

(async() => {
  let langFiles = await readDir(path.resolve(__dirname, './lang'));
  langFiles = langFiles.map(file => {
    return path.resolve(process.cwd(), file);
  });

  for (let file of langFiles) {
    const langModule = require(file);
    // get the lang messages as an object
    const langObj = (langModule.default) ? langModule.default : langModule;
    // extract .vue/.js files and compare with current lang files
    const report = Extract.createI18NReport('./path/to/vue-files/**/*.?(js|vue)', file);
    // report object has two major parts:
    // - `missingKeys` part are those msgs lack of translations, not in current po file
    // - `unusedKeys` part are those msgs not present in vue/js files
    for (let item of report.missingKeys) {
      langObj[item.path] = item.path; // add missing string, default same as the source
    }
    for (let item of report.unusedKeys) {
      delete langObj[item.path]; // remove unused string
    }

    // langObj had been synced with vue/js files with latest message strings
    // now update the lang files
    const langStr = 'export default ' + JSON.stringify(langObj, null, 2);
    await writeFile(file, langStr, 'utf-8');
  }

  console.log('Updated all lang files');
})();

node extract.js 之后待翻译文件应该会变成这样:

// lang/en_US.js
export default {
  'a-hello': 'Hello World!',
  'b-hello': 'Hello Banana!',
  'c-hello': 'c-hello',
}

// lang/zh_CN.js
export default {
  'a-hello': '你好世界!',
  'b-hello': '你好🍌!',
  'c-hello': 'c-hello',
}

然后再统一进行翻译就可以了。

最后,仔细想了想,我可以比较简单处理 extract 的结果是因为我在 language files 里不使用复杂的嵌套结构, 和传统的 po 文件一致,就是 key:value 的一一对应关系,但很多使用 vue-i18n 的人大概还会利用 js object 嵌套很深, 比如 vue-i18n-extract 的 demo 中给的一个例子就是这个样子:

// de_DE.js
export default {
  header: {
    titles: {
      title_a: 'test',
      title_b: 'test',
      title_c: 'test',
    },
    paragraphs: {
      p_a: 'test',
      p_b: 'test',
    },
  },
};

如果是这个情况,更新起来的确费事一些,但根据自己实际情况,应该也还是可以处理的。

by bambooom ([email protected]) at September 12, 2019 04:42 PM

September 11, 2019

蠎周刊

Issue 385

原文: PyCoder's Weekly - Issue #385

PyCoder

  • 190911 Zoom.Quiet(大妈) 用时 42 分钟 完成快译
  • 190911 Zoom.Quiet(大妈) 用时 17 分钟 完成格式转抄.

Python’s growth in popularity has been incredible. This list is interesting because it allows you to adjust the weights for the various factors that determine the ranking.

(是也乎:

国内早已大吼了...

实在是其它语言, 对快速变化的混乱数据一直并没什么关注, 反而一直在一线和各种混乱共处的 Python 长期积累出来一堆神器.

)

Learn about MATLAB vs Python, why you should switch from MATLAB to Python, the packages you’ll need to make a smooth transition, and the bumps you’ll most likely encounter along the way.

(是也乎:

其实很友好咯...

)

“Dropbox has been one of the first companies to adopt Python static type checking at this scale. These days thousands of projects use mypy, and things are quite battle tested.” Related discussion on Hacker News.

(是也乎:

Dropbox 实锤,为什么值得上类型系统...

)

Repository to track the progress in Natural Language Processing (NLP), including the datasets and the current state-of-the-art for the most common NLP tasks.

In this step-by-step tutorial, you’ll learn how to use args and kwargs in Python to add more flexibility to your functions. You’ll also take a closer look at the single and double-asterisk unpacking operators, which you can use to unpack any iterable object in Python.

(是也乎:

这个插画很传神...

)

PSF notes about the end of support for Python 2.x. Related discussion on Hacker News.

Changelog here.

讨论

Discussions

(是也乎:

今日最佳:

)

文章,教程和嗯哼

Articles, Tutorials and Talks

If you’ve worked on a Python project that has more than one file, chances are you’ve had to use an import statement before. In this course, you’ll not only cover the pros and cons of absolute and relative imports but also learn about the best practices for writing import statements.

(是也乎:

import 在 Python 中是个迷宫, XKCD 都嗯哼了好几次... xkcd: Python Environment

python_environment

)

“Have you ever looked through your Django log files and console messages, felt something was out of order and didn’t make sense, but couldn’t quite put your finger on it? Let’s look at the log file…”

(是也乎:

简单说, admin 叕升级了...

)

“Async/Await helps speeding up applications that do a lot of I/O, but sprinkling some keywords around the code won’t magically make everything faster, you need to do a bit more.”

(是也乎:

XXX With Python Examples

这也是人气非常高的系列嗯哼,

因为, 直接提供了可以立即使用的框架代码, 这比官方文档, 嗯哼半天不知道具体怎么用要来的直接...

)

“pytest-mypy-plugins is an absolute must for people who work a lot with types or Mypy plugins in Python. It simplifies the process of refactoring and distributing types.”

Learn more about Python parallelization libraries (multiprocessing and threading) and understand which to use when for different data science problem sets.

(是也乎:

数据科学家需要明白的系统细节...

)

An interview about the SecureDrop platform that enables whistleblowers to share information safely and anonymously, without fear of tracking or identification.

(是也乎:

等等, 之前的 Tor 呢?

)

Use Python and the anybadge package to generate your own badges and covey project health and status in your online repositories.

(是也乎:

dashboard.webp (WEBP Image, 1000 × 431 pixels)

扫盲, github 中各种项目成熟度的自动嗯哼;

也是 github 生态中最受欢迎的周边

)

How probabilistic data structures and algorithms can be used for cardinality estimation in Big Data streams.

(是也乎:

这可是 Google 立命之本..

)

Learn how to move the objects on the screen and write you first collision detection with PyGame.

(是也乎:

当然, 现在有将 Scratch 结合的技术, 所以, PyGame 可能...

)

Learn how Django’s ORM manages Django database migrations.

(是也乎:

PyCon19China 大会中, 有对应主题分享, 推荐参与讨论

)

Part 7 of Guido’s series on PEG parsers.

(是也乎:

感觉老爹是想挑战 google 老同事们, 将 Python 提升到 Golang 之上...

Python 之父的解析器系列之五:左递归 PEG 语法

已有同步翻译...良心系列...不明觉厉

翻译项目在 -> chinesehuazhou/guido_blog_translation: 翻译 Guido 的解析器系列文章

)

(是也乎:

今天 Panda 大爆炸, 一堆相关推荐.... 看来无论什么 AI , 都要 Panda 来帮忙完成数据清洗...

)

(是也乎:

4366781.original.jpg (JPEG Image, 395 × 395 pixels)

作者...

)

(是也乎:

所以说: "Excel 中每一个功能, 都值得变成一个创业项目"

)

好物

Interesting Projects, Tools and Libraries, Projects & Code

(是也乎:

大集锦, 将各种库的 AI 模型都用 ipynb 整理了出来:

(TensorFlow, Theano, Caffe, Keras), scikit-learn, Kaggle, big data (Spark, Hadoop MapReduce, HDFS), matplotlib, pandas, NumPy, SciPy, Python essentials, AWS, and various command lines.

)

(是也乎:

github_logo_at

进一步的风格合成...

)

(是也乎:

嗯哼? 模糊搜索?

)

(是也乎:

这才是社区真汉子

)

📆🐍 活动/大会

Events, MeetUp 真的是全球线下活动组织中心

DAMA

❤️ Happy Pythonic ;-(大妈私人无责任播报)

第3期已经上线, 为期6周

190919 报名截止;
190922 正式开课;
191103 按时结束;

(是也乎:

没想到触发出一个 DoIs ~ 真正实用的 AI 落地方向: 辅助识别野外白海豚...

)

是也乎

NN 3767

by Zoom.Quiet at September 11, 2019 03:42 AM