且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将带有通配符的参数传递给Python脚本

更新时间:2022-05-07 00:46:23

您可以使用glob模块,这样,您就不必依赖特定shell的行为了(嗯,您仍然依赖于shell不会扩展参数,但至少可以通过转义通配符:-)来使这种情况在Unix中发生.

You can use the glob module, that way you won't depend on the behavior of a particular shell (well, you still depend on the shell not expanding the arguments, but at least you can get this to happen in Unix by escaping the wildcards :-) ).

from glob import glob
filelist = glob('*.csv') #You can pass the sys.argv argument