python script

  • 1, a terminal command

    • python “name.py”
  • 2, in python environment where the script content

    • 1
      2
      3
      a='head'
      b='hehe'
      print(a,b)
    • Use import name of the script is executed, then you can use the following statement to view the display

    • 1
      2
      print (name.a)
      print (name.b)
    • A python in the same environment, the first import After loading, the use of import later there will be corresponding results show that a large column  python script can use the reload (name) in this case to reload, in python3.0 ipm module needs to be loaded in order to use reload () function:

      • 1
        2
        from imp import reload
        reload(name)
  • 3, use the command to load a script from a variable or function

    • Also to name.py, for example, can use the following methods to run the script

    • 1
      2
      3
      from name import a,b
      type various a,b, the screen show:
      head,hehe
  • 4, the exec function

    • Execution name name.py script: exec (open ( 'name.py') read ().)

Guess you like

Origin www.cnblogs.com/dajunjun/p/11710877.html