Python Custom Module usage instructions

Source: Internet
Author: User
Save a hello.py file in the F:/data/python directory

    • hello.py

>>> def hello (x):    print X

    • Directory

    • Import

>>> Import sys>>> sys.path.append (' F:/data/python ') #添加路径 >>> import hello>>> Hello.hello (5)  #调用5

Do not change sys.path import custom module:

The first method: Place the hello2.py file in the D:/python27/lib/site-packages directory

>>> Import sys,pprint>>> pprint.pprint (Sys.path) [', ' d:\\python27\\lib\\idlelib ', ' f:\\data\\s ', ' D:\\python27 ', ' c:\\windows\\system32\\python27.zip ', ' d:\\python27\\dlls ', ' d:\\python27\\lib ', ' D:\\Python27\\ Lib\\plat-win ', ' d:\\python27\\lib\\lib-tk ', ' d:\\python27\\lib\\site-packages ']>>> import hello2>> > Hello2.hello () hello,world!

The second method: Add the F:/data/python path to the environment variable (in the system variable, add the Pythonpath variable, and add the path to the value)

>>> Import sys>>> Import hello>>> Hello.hello (1) 1

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.