running python function with arguments from cmd.exe -


i have python function takes 1 arguments

def build_ibs(nthreads,libcfg):  # nthreads int,libcfg string       import os  # module os must imported       import subprocess       import sys 

i use following in cmd.exe(on win7) call it

c:>cd c:\svn\python code c:\svn\python code>c:\python27\python.exe build_libs(4,'release')  

that throws error
enter image description here using following

 c:>cd c:\svn\python code  c:\svn\python code>c:\python27\python.exe 4 'release' # dosn't work  c:\svn\python code>c:\python27\python.exe 4 release   # dosn't work 

does nothing, , no error displayed even.

what correct way call both in cmd.exe or python shell command line?
thanks

sedy

you can't call function command line - must inside file. when type python filename.py @ command line, feed contents of filename.py python interpreter namespace set __main__.

so when type python.exe 4 'release' tries find file named 4. since file not exist, windows returns errno 2 - file not found.

instead, put code file - lets test.py:

test.py:

def build_libs(nthreads,libcfg):  # nthreads int,libcfg string       import os  # module os must imported       import subprocess       import sys       # ...  if __name__=='__main__':     numthreads = sys.argv[1] # first argument script - 4     libconfig = sys.argv[2] # second argument     # call build_libs planned     build_libs(numthreads, libconfig) 

then run command line: c:\python27\python.exe test.py 4 release in directory test.py saved in.

update: if need use build_libs in multiple files, it's best define in module, , import it. example:

mod_libs/__init__.py - empty file

mod_libs/core.py:

def build_libs(...):     ....     # function definition goes here 

test.py:

import sys import mod_libs if __name__ == '__main__':     mod_libs.build_libs(sys.argv[1], sys.argv[2]) 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -