Is it good style to call bash commands within a Py

2020-02-10 06:12发布

I was wondering whether or not it is considered a good style to call bash commands within a Python script using os.system(). I was also wondering whether or not it is safe to do so as well.

I know how to implement some of the functionality I need in Bash and in Python, but it is much simpler and more intuitive to implement it in Bash. However, I feel like it is very hackish to write os.system("bash code").

Specifically, I want to move all files that end with a certain extension to a directory.

In bash: *mv .ext /path/to/destination In Python (Pseudocode): for file in directory: if file.endswith("ext"): move file to destination

In this case, what should I do?

7条回答
甜甜的少女心
2楼-- · 2020-02-10 06:36

The quoting issues alone suggest that a pure Python solution is preferable.

查看更多
登录 后发表回答