Detailed description of the Python solution executed in the Python dictionary

Source: Internet
Author: User

After learning the Python dictionary for a long time, I hope this article will teach you more things. This article describes the practical operation solutions used in the practical application of executable Python.

Executable Python

This part only applies to Linux/Unix users, but Windows users may be curious about the first line of the program. First, we need to run the chmod command to give the program executable permission, and then run the program.

 
 
  1. $ chmod a+x helloworld.py  
  2. $ ./helloworld.py  
  3. Hello World   
  4.  

The chmod command is used to change the file mode and allow all users in the system to execute the source file. Then we can directly execute the program by specifying the location of the source file. We use./to indicate that the program is located in the current directory. To be more interesting, you can change your file name to helloworld and run./helloworld. In this way, the program can still work because the system knows that it must run the program using the interpreter specified in the first line of the source file.

As long as you know the exact location of the program, you can run the program now-but what if you want your program to run from all locations? In this case, you can save your program to one of the directories in the PATH environment variable. Every time you run any program, the system will find the directories listed in the PATH environment variable. Then run the program. Simply copy the source file to one of the directories listed in PATH to make your program available anywhere.

 
 
  1. $ echo $PATH  
  2. /opt/mono/bin/:/usr/local/bin:/usr/bin:/bin:/usr/X11R6
    /bin:/home/swaroop/bin  
  3. $ cp helloworld.py /home/swaroop/bin/helloworld  
  4. $ helloworld  
  5. Hello World   
  6.  

We can use the echo command to display the PATH variable, and use $ to prefix the variable name to show the value of this variable to shell. We can see that/home/swaroop/bin is one of the directories in the PATH variable. Swaroop is the user name used in my system. Generally, there is a similar directory in your system. You can also add the directory you selected to the PATH variable -- this can be done by running PATH = $ PATH:/home/swaroop/mydir, where

 
 
  1. “/home/swaroop/mydir”  
  2.  

Is the directory that I want to add to the PATH variable.

This method is useful when you want to run your program anytime and anywhere. It is like creating your own commands, like cd or other Linux terminal or DOS prompt commands. Tip: For Python, programs, scripts, or software refer to the same thing.

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.