问题标签 [python]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
530 浏览

python - 如何检查文件集是否符合命名方案

我有一堆文件(电视剧集,虽然这是相当随意的),我想检查它们是否匹配特定的命名/组织方案..

目前:我有三个正则表达式数组,一个用于有效文件名,一个用于缺少剧集名称的文件,一个用于有效路径。

然后,我遍历每个有效文件名正则表达式,如果匹配,则将其附加到“有效”字典,如果不匹配,则对缺少的 ep-name 正则表达式执行相同操作,如果匹配,我将其附加到“无效” " 带有错误代码 (2:'missing epsiode name') 的 dict,如果两者都不匹配,则使用 'malformed name' 错误代码将其添加为无效。

当前代码可以在这里找到

我想添加一个规则来检查每个目录中是否存在 folder.jpg 文件,但是添加它会使代码在当前状态下变得更加混乱。

我怎样才能以更可扩展的方式编写这个系统?

它需要检查的规则是..

  • 文件格式为Show Name - [01x23] - Episode Name.aviShow Name - [01xSpecial02] - Special Name.aviShow Name - [01xExtra01] - Extra Name.avi
  • 如果文件名的格式Show Name - [01x23].avi显示它输出的“缺少剧集名称”部分
  • 路径应采用格式Show Name/season 2/the_file.avi(其中第 2 季应为文件名中的正确季号)
  • 每个Show Name/season 1/文件夹应包含“folder.jpg”

。有任何想法吗?虽然我正在尝试检查电视剧集,但这个概念/代码应该能够适用于很多事情。

我唯一的想法是格式的字典列表:

0 投票
9 回答
410726 浏览

python - 如何构建一个基本的迭代器?

如何在 python 中创建迭代函数(或迭代器对象)?

0 投票
12 回答
187022 浏览

python - 转置/解压缩功能(zip的倒数)?

我有一个 2 项元组的列表,我想将它们转换为 2 个列表,其中第一个包含每个元组中的第一个项目,第二个列表包含第二个项目。

例如:

有没有内置函数可以做到这一点?

0 投票
8 回答
649 浏览

php - Introducing Python

The company I used to work with has two developers working fulltime, and a handful of freelancers. They're in the process of hiring a new lead developer to try to bring order and management to the development.

But, currently, one of the developers has seen the light of Django (the company has only developed in PHP to date) while the other developer is concerned that introducing a new language (Python) is a bad idea right now.

How should they approach introducing this new technology? Obviously with only one of the developers actually knowing Python, there will be no redundancy when that dev is away or leaves the company.

Should they bother to introduce Python, or should they look for PHP-only solutions until such a time when the team actually have more than one Pythonion? Without a team leader, the decisions are having to fall to them.

0 投票
15 回答
281603 浏览

python - 解析命令行参数的最佳方法是什么?

解析 Python 命令行参数的最简单、最简单、最灵活的方法或库是什么?

0 投票
8 回答
25140 浏览

python - 使用 Python 查找损坏的符号链接

如果我调用os.stat()一个 broken symlink,python 会抛出一个OSError异常。这对于找到它们很有用。但是,还有一些其他原因os.stat()可能会引发类似的异常。有没有更精确的方法symlinks在 Linux 下用 Python 检测损坏?

0 投票
3 回答
2233 浏览

python - 在 Django 的父模型中更新 auto_now DateTimeField

我有两个模型:消息和附件。每个附件都使用附件模型上的 ForeignKey 附加到特定消息。两个模型都有一个名为 updated 的 auto_now DateTimeField。我正在尝试这样做,以便在保存任何附件时,它还将关联消息上的更新字段设置为现在。这是我的代码:

这行得通吗?如果你能向我解释一下,为什么?如果没有,我将如何做到这一点?

0 投票
9 回答
60839 浏览

python - 在 Django 模型中指定 mySQL ENUM

如何在 Django 模型中指定和使用 ENUM?

0 投票
9 回答
19727 浏览

java - 为什么 Java 和 Python 的垃圾回收方法不同?

Python 使用引用计数方法来处理对象的生命周期。因此,不再使用的对象将立即被销毁。

但是,在 Java 中,GC(垃圾收集器)会销毁在特定时间不再使用的对象。

Java 为什么选择这种策略,这样做有什么好处?

这比 Python 方法好吗?

0 投票
4 回答
4447 浏览

python - 使用 time.mktime 进行日期/时间转换似乎是错误的

time.mktime应该返回自纪元以来的秒数。既然我在午夜给它一个时间并且时代是在午夜,那么结果不应该被一天中的秒数整除吗?