Would Python make a good substitute for the Window

2019-03-08 00:39发布

I've got some experience with Bash, which I don't mind, but now that I'm doing a lot of Windows development I'm needing to do basic stuff/write basic scripts using the Windows command-line language. For some reason said language really irritates me, so I was considering learning Python and using that instead.

Is Python suitable for such things? Moving files around, creating scripts to do things like unzipping a backup and restoring a SQL database, etc.

12条回答
在下西门庆
2楼-- · 2019-03-08 01:28

As much as I love python, I don't think it a good choice to replace basic windows batch scripts.

I can't see see someone having to import modules like sys, os or getopt to do basic things you can do with shell like call a program, check environment variable or an argument.

Also, in my experience, goto is much easier to understand to most sysadmins than a function call.

查看更多
啃猪蹄的小仙女
3楼-- · 2019-03-08 01:29

@BKB definitely has a valid concern. Here's a couple links you'll want to check if you run into any issues that can't be solved with the standard library:

  • Pywin32 is a package for working with low-level win32 APIs (advanced file system modifications, COM interfaces, etc.)
  • Tim Golden's Python page: he maintains a WMI wrapper package that builds off of Pywin32, but be sure to also check out his "Win32 How Do I" page for details on how to accomplish typical Windows tasks in Python.
查看更多
小情绪 Triste *
4楼-- · 2019-03-08 01:29

Anything is a good replacement for the Batch file system in windows. Perl, Python, Powershell are all good choices.

查看更多
Root(大扎)
5楼-- · 2019-03-08 01:32

Python is certainly well suited to that. If you're going down that road, you might also want to investigate SCons which is a build system itself built with Python. The cool thing is the build scripts are actually full-blown Python scripts themselves, so you can do anything in the build script that you could otherwise do in Python. It makes make look pretty anemic in comparison.

Upon rereading your question, I should note that SCons is more suited to building software projects than to writing system maintenance scripts. But I wouldn't hesitate to recommend Python to you in any case.

查看更多
你好瞎i
6楼-- · 2019-03-08 01:32

I've been using a lot of Windows Script Files lately. More powerful than batch scripts, and since it uses Windows scripting, there's nothing to install.

查看更多
神经病院院长
7楼-- · 2019-03-08 01:36

Python is well suited for these tasks, and I would guess much easier to develop in and debug than Windows batch files.

The question is, I think, how easy and painless it is to ensure that all the computers that you have to run these scripts on, have Python installed.

查看更多
登录 后发表回答