(python) How to press win+R and then enter the file name to run it?
PHP中文网
PHP中文网 2017-06-28 09:26:26
0
2
1119

I just learned python not long ago, and I was reading "automate the boring stuff with python", but I still didn't understand this part. The relevant passages in the book are shown in the figure.

So what is going to happen?
What if pw.py in the previous picture does not exist on the C drive? For example, it exists in the pythonCodes folder of the D drive? I still don’t understand the second picture...Does that file need to be in the same folder as where python is installed?
Thank you, Taoist priests...

PHP中文网
PHP中文网

认证0级讲师

reply all (2)
滿天的星座

In fact, it just allows you to configure environment variables. If you have a project calledpythonCodes, then you have to set yourpythonCodesinSystem Properties->Environment Variables->pathAdd the absolute path. In this case, if you write a python script inpythonCodes, such ascommand.py, you can directly run it throughwin+R, and then entercommand.pyto run it directly...

However, I don’t recommend doing this, because it will develop bad habits and rely heavily on environment variables. Moreover, once the project changes location, the environment variables will have to be changed. Instead of doing this, it is better to directly select a working path. Then just develop on it!Environment variables only need to be set in the python program

    淡淡烟草味

    What it means is to create apw.batfile and register the directory where thispw.batis located into the global%PATH%environment variable.
    pw.batThe content is

    @eeeeee xxxxxx %* @pause

    Whereeeeeeerepresents the path of thepython.exeexecutable file. This book usespy.exe, but during actual installation, the default Python executable file for most users ispython.exe. If thispython.exeis not registered globally (that is to say, it is not in the%PATH%environment variable, and the command line directly runspythonand cannot be accessed), then theeeeeepart here needs to usepython The full path of .exe.

    Secondly,xxxxxis the path to the.pyfile. This method is to run a python file permanently, and only enter the parameters that need to be passed into the python file after Win+R. And if you need to enter the Python path in Win+R, you should omit thexxxxxpart.

    Then, since the path ofpw.batis registered to the%PATH%environment variable, you can call the script by runningpw python script pathdirectly from Win+R.

    It doesn’t matter where pw.py is placed, because for these paths, if the directory has been registered to the%PATH%environment variable, you can directly write the file name. If the directory has not been registered to%PATHEnvironment variables, you must write the entire path, nothing more, the same is true for the previouspy.exe.

      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!