1. 程式人生 > >【原創】python學習筆記(5)--《笨辦法學python》,指令碼帶引數

【原創】python學習筆記(5)--《笨辦法學python》,指令碼帶引數

一 指令碼檔案

(1) 簡單的說就是一段自己寫的,可執行的程式碼,否則會報錯

(2)簡單指令碼,直接 python  xxx1.py

(3)帶引數指令碼,需要 python xxx2.py argv1 argv2 argv3

        根據指令碼引數的數量,傳入對應的引數,空格分隔即可,否則會報錯,無法解包unpack

# -*- coding:utf-8 -*-

from sys import argv
script,first,second,third=argv

print "the script is called:" ,script
print "the first var is :" ,first
print "the second var is :" ,second
print "the third var is :" ,third