Question: How Python iterates through all the files in a folder and invokes the EXE file with parameters.
**************************************
Import OS, re
def enum_exe (ARG, dirname, names):
For name in Names:
If Re.search (R '/.exe$ ', Name.lower ()):
Dosomthing (dirname + "//" + name)
Os.path.walk (".", Enum_exe, ())
**************************************
Import Glob
Filelist=glob.glob ("E://pythonwork/*.exe")
For filename in filelist:
Call filename with parameter
**************************************
For Root, dirs, the files in Os.walk (path, topdown=false):
#hanlde file
For name in Files:
If name[:-3] = ' exe ':
Print Name
For subfolder in dirs:
Print subfolder
-------------------------------------------------------------------------------
Range () function:
**************************************
The range () function can generate a arithmetic progression. For example, the result of a range (n) is a list of all integers in [m,n] with a list,range (m,n) result that contains all the integers in the 0~n-1, and Range (M,n,d) just represents the list that starts with M, and does not exceed the n-1 with D as the tolerance.
-------------------------------------------------------------------------------
Break and continue statements, and ELSE statements that are used with the Loop statement:
**************************************
The function of break and continue is the same as in C language.
It is noteworthy that the for and while statements can be paired with the else-guided statement. Obviously, it means that the operation is performed when the cyclic condition is no longer valid. The example in the document is a program that determines whether each integer in [2,10] is a prime number.
For n in range (2,10):
For x in range (2,n):
If n%x==0:
Print n, ' equals ', X, ' * ', n/x
Break
Else
Print N, ' is a prime number '
-------------------------------------------------------------------------------
How python can get a path to the imported module:
**************************************
>>> Import WxPython
>>> Import Imp
>>> imp.find_module ("WxPython")
(None, ' C://python25//lib//site-packages//wx-2.6-msw-unicode//wxpython ', (",", 5))
>>>
**************************************
>>> Import Telnetlib
>>> telnetlib.__file__
' e://python25//lib//telnetlib.py '
>>>
-------------------------------------------------------------------------------
How to get the current application path in Python:
**************************************
Import OS
Print Os.path.abspath (Os.curdir)
Print Os.path.abspath ('. ')
**************************************
Os.chdir (path) # change Dir
OS.GETSWD () # display Dir
-------------------------------------------------------------------------------
PYTHON and C interact with each other to invoke instance resolution:
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service