小编Mat*_*hew的帖子

Python 3.6项目结构导致RuntimeWarning

我正在尝试打包我的项目以进行分发,但是RuntimeWarning当我运行模块时我正在尝试.

我在Python邮件列表上找到了一个错误报告,表明这RuntimeWarning是Python 3.5.2中引入的新行为.

阅读错误报告,似乎发生了双重导入,这RuntimeWarning在警告用户时是正确的.但是,我没有看到我需要对自己的项目结构进行哪些更改以避免此问题.

这是我试图"正确"构建的第一个项目.我希望在推送代码时有一个整洁的布局,以及一个可以被其他人轻松克隆和运行的项目结构.

我的结构主要基于http://docs.python-guide.org/en/latest/writing/structure/.

我在下面添加了最小工作示例的详细信息.

要复制该问题,我运行主文件python -m:

(py36) X:\test_proj>python -m proj.proj
C:\Users\Matthew\Anaconda\envs\py36\lib\runpy.py:125: RuntimeWarning: 
'proj.proj' found in sys.modules after import of package 'proj', but prior 
to execution of 'proj.proj'; this may result in unpredictable behaviour
  warn(RuntimeWarning(msg))
This is a test project.`
Run Code Online (Sandbox Code Playgroud)

运行我的测试很好:

(py36) X:\test_proj>python -m unittest tests.test_proj
This is a test project.
.
----------------------------------------------------------------------
Ran 1 test in 0.000s

OK
Run Code Online (Sandbox Code Playgroud)

复制问题的项目结构如下:

myproject/
    proj/
        __init__.py
        proj.py
    tests/
        __init__.py …
Run Code Online (Sandbox Code Playgroud)

python python-3.x

28
推荐指数
3
解决办法
5481
查看次数

使用Powershell递归重命名文件

我目前有一行批量重命名我目前在的文件夹中的文件.

dir | foreach { move-item -literal $_ $_.name.replace(".mkv.mp4",".mp4") }
Run Code Online (Sandbox Code Playgroud)

此代码适用于我当前所在的目录,但我想要的是从包含11个子文件夹的父文件夹运行脚本.我可以通过单独导航到每个文件夹来完成我的任务,但我宁愿运行一次脚本并完成它.

我尝试了以下方法:

get-childitem -recurse | foreach { move-item -literal $_ $_.name.replace(".mkv.mp4",".mp4") }
Run Code Online (Sandbox Code Playgroud)

任何人都可以指出我在正确的方向吗?我根本不熟悉Powershell,但在这种情况下它符合我的需要.

powershell rename

25
推荐指数
2
解决办法
3万
查看次数

标签 统计

powershell ×1

python ×1

python-3.x ×1

rename ×1