Home > other >  Python is how to use the console to open the file, run the file functions, and enter the content?
Python is how to use the console to open the file, run the file functions, and enter the content?

Time:11-02

How do I use the sys module to add the console command control file? Add module function to sys. Argv [0], sys. Argv [1] this way,

The whole package of main function similar to the following code, the file name. The main py, CD to the console file path. After running the main py, can only open the file, don't know how to through the console call the main function? Admin. Welcome () will call other modules, it also has other functions, hope can console calls,

Thank you very much!

 
the import the OSThe import sys
Base_Dir=OS. The path. The dirname (OS) path) dirname (OS) path) abspath (__file__)))
Sys. Path. Append (Base_Dir)


From the core import memo, memo_admin_config


Def the main () :
Is_name=input (' please enter the username: ')
Me=memo. Memo (is_name 'date', 'thing')
Admin=memo_admin_config. MemoAdmin (me, f '{Base_Dir} \ conf', 'config. Ini')
Admin. Welcome ()

If __name__=="__main__" :
The main ()

CodePudding user response:

Generate a temporary py file, the file content is to import the model you need to run the py files, call the function model. The function ()

CodePudding user response:

reference 1st floor JMZL response:
generate a temporary py file, the file content is to import the model you need to run the py files, call the function model. The function ()

Then use the CMD command to run their generated py files
  • Related