Cloud computing Python Automation Operations Development: Interactive mode programming

Source: Internet
Author: User
Tags python script

The so-called interaction is interacting with the user that we use Python, you give instructions or code, and the Python interpreter gives the result. The call interpreter does not pass the script file as a parameter and displays the following prompt:

Python

Python 2.7.10 (default, Jul 14 2015, 19:46:27)

[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on Darwin

Type "Help", "copyright", "credits" or "license" for more information.

>>

Type the following text at the Python prompt, and then press ENTER:

>> print "Hello, python!" #python2.0

>> print ("Hello, python!") #python3.0

Hello, python!.

It is highly recommended to use Ipython, which is installed in the following ways: http://blog.51cto.com/fklinux/2046741

Script Mode Programming:

So-called scripting, which is to write Python instructions or code into a text file, and then specify a command interpreter for these instructions, this file is a Python script.

For example: write the following code in a test.py file

Print "Hello, python!"

To run the program:

Python test.py

Hello, python!.

Another way to execute a python script, modify the test.py file:

#!/usr/bin/python

Print "Hello, python!"

To run the program:

chmod +x test.py

#./test.py

Hello, python!.

Using Chinese in script mode programming

Python uses ASCII code by default, does not support Chinese, the Chinese language needs to be declared to support the Chinese character set, generally utf8, the way is as follows:

#!/usr/bin/python

#coding =utf8

#encoding: Utf-8

#* coding:utf-8 *

print "Hello China!" "

Why are there so many ways to write all 3 of them? Python is a regular way to detect that your character set definition has something he wants to see, as long as it matches the following:

coding[:=]\s* ([-\w.] +)

[email protected] python]# cat a.py

#!/usr/bin/env python

#fdsf Coding=utf8 Fdaf like here fdsf Fdaf is I casually write, as long as there are coding utf8 and so on can

Print "Hello China"

Note: Chinese is already available directly in Python3 and does not need to specifically specify a character set that supports Chinese

Cloud computing Python automation Operations Development: Interactive mode programming

Related Article

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.