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.
- import sys
- sys.path.append('.')
- import Global
- str = "hello world"
- print str
- print Global.str1
Now we can execute such a statement in python command line.
- execfile("c:\\test.py")
- trouble shooting :
This problem may occur during the implementation of the Python Helloworld program.
- import Global
- 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.
- import os
- 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:
- C:\>python test.py
- hello world
- hello world2
The above are the main implementation steps of the Python Helloworld program.