Linux running Python program

Source: Internet
Author: User

There are several ways to run Python under Linux: 1. Command line execution: Create a *.py document in which to write Python code. After that, execute at the command line: $python*.py Precautions: 1. The absolute path of the file needs to be specified; 2. The source code to indicate the output, such as print 2. Unix Scripts: After creating the *.py file, you need to add a Python execution path to the source code header, such as "#!/usr/bin/python"。 Among them, "#!" It is called "hash bang". After that, change the text permission to the executable file, then execute it: $chmod +x *.py$./*.py Precautions: 1. If the python execution path cannot be found, enter the $which PythonView; 2. Another way to do this is to add an env program that automatically looks for a python path, such as rewriting the first line to "#!/usr/bin/env python"。 This approach facilitates cross-platform execution of the program, but only if the path to Env is guaranteed; If you do not know the env path, enter $which EnvView. 3. Module loading and overloadingModules (module): A package of variable names, a module corresponding to this single "namespace". After loading the module, access the object via Object.attribute. A module can be understood as a "package", the benefits of which are: package All code that handles the same problem for easy reuse。 The module concept provided by Python,A good solution to the problem of duplicate variable names, because even if the variable name is the same, because the module name is different, it can still be distinguished (much like the "double colon" operator in the R language, package::function). Gta5-In:ImportMymoduelOr fromMyModuleImport Object; Another way to useexecfile ('mymodule.py')。 overloaded: Usingload ()functions, such asLoad (MyModule)。 Precautions: 1. Import/from/load () are no need to specify the module suffix, which implies that the module needs to be in the current running directory; 2. After Import/from, Import/from again does not work. Similarly, Import/from (the second) does not change after the module has been modified. This is to be loaded with load (). ExecFile () This problem does not exist. 4. The most refreshing approach:Configure the Python runtime environment in Emacs.

Linux running Python program

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.