Python Helloworld simple implementation

Source: Internet
Author: User

A friend who has learned programming languages will surely have a deep understanding of Helloworld. Almost at the early stage of language learning, we will have a deep understanding of the programming language through this simple applet. So today we will introduce the implementation method of the Python Helloworld program.

  • Analysis of Python multi-thread programming
  • Python thread synchronization functions in practical applications
  • Analysis of the correct application method of Python synchronization queue
  • Brief introduction to the basic application method of calling Python scripts
  • Python Class correct application code example analysis

Before creating the Python Helloworld program, you must create a new file c: \ test. py.

Write this stuff in this file

Str = "hello world"
Print str

In this way, we can write a script.

Execute such a statement in the command line of python.

Execfile ("c: \ test. py ")

Now, we can see the result.

Now we have another requirement, that is, we need to use an independent file to write some configuration parameters.

For example, we can create a Global. py file under the root directory of drive C.

Write some statements str1 = "hello world2" in it"

So how do we use them? Change test. py to the following.

 
 
  1. import sys  
  2. sys.path.append('.')  
  3. import Global  
  4. str = "hello world" 
  5. print str   
  6. print Global.str1 

Now we can execute such a statement in python command line.

 
 
  1. execfile("c:\\test.py")  
  2. trouble shooting :  

This problem may occur during the implementation of the Python Helloworld program.

 
 
  1. import Global  
  2. ImportError: No module named Global 

This is because he does not find the corresponding Global file below C:

Let's first confirm the details.

Check the current working directory.

 
 
  1. import os   
  2. os.getcwd() 

At this time, it may be the python installation directory.

Of course, the Global. py cannot be found.

What we need to do is OS. chdir ("c :\\")

Then we are executing OS. getcwd (). Let's see if the working directory has changed.

Execfile ("c: \ test. py ")

OK

Of course, we can also do this:

 
 
  1. C:\>python test.py  
  2. hello world  
  3. hello world2 

The above are the main implementation steps of the Python Helloworld 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.