Packages ใน Python
Packages คือ ลำดับชั้นในรูปแบบ directory ซึ่งอยู่ใน folder ที่เก็บ application ของเรา
ทำความเข้าในการ packages โดยสร้าง folder Mypg
และสร้าง
ตัวอย่างไฟล์ hello_mindphp.py อยู่ในโฟเดอร์ Mypg
def hello_mindphp():
print 'สวัสดดี เว็บ mindphp.com'
ตัวอย่างไฟล์ hello_mindphp2.py อยู่ในโฟเดอร์ Mypg
def hello_mindphp2():
print 'สวัสดดี 2 เว็บ mindphp.com'
ตัวอย่างไฟล์ hello_mindphp3.py อยู่ในโฟเดอร์ Mypg
def hello_mindphp3():
print 'สวัสดดี 3 เว็บ mindphp.com'
สร้างไฟล์
Mypg/__init__.py
# ตัวอย่าง สอน Python ในเว็บ Mindphp.com
# Packages in Python:
from hello_mindphp import hello_mindphp
from hello_mindphp2 import hello_mindphp2
from hello_mindphp3 import hello_mindphp3
สร้างไฟล์ mypg.py เพื่เป็นไฟล์รวมงานทำงานของ packages
# ตัวอย่าง สอน Python ในเว็บ Mindphp.com
# Packages in Python:
import Mypg
Mypg.hello_mindphp();
Mypg.hello_mindphp2();
Mypg.hello_mindphp3();
ผลที่ได้จากไฟล์ทั้งหมด เมือรันไฟล์ mypg.py
สวัสดดี เว็บ mindphp.com
สวัสดดี 2 เว็บ mindphp.com
สวัสดดี 3 เว็บ mindphp.com