welcom ! Handel home

2016年5月10日 星期二

pip auto update the package tool Demo


PIP command example : 操作命令

  • pip list # 看目前系統有安裝哪些套件
  • pip search mysql # 搜尋相關套件
  • pip install package # 安裝套件
  • pip uninstall package # 移除套件
  • pip show --files package # 秀套件檔案列表
  • pip list --outdated # 列出過期套件
  • pip install --upgrade package # 升級

>> save next code to pipupv27.py
>> python2 pipupv27.py
then will auto scan the pip upgrade package list and  type y/a/n to select the function


#====================================================
import time
import sys
import os

os.system("pip2.7 list --outdated > chklist.txt")
f = open("chklist.txt",'r')
ss = f.read()
f.close()
kss = ss.split("\n")
#print ss

for i in kss:
    print (i)

kk='n'
kk2='n'
kk = raw_input("\nare you want to upgrate(y:1by1/a:all/n) : ")
if kk == 'n':
    print "\nby by ..."
    exit()

if kk == 'a':
        for i in kss:
                if i.split(" ")[0] != "numpy":
                    os.system("pip2.7 install --upgrade "+i.split(" ")[0])
else:
        for i in kss:
                ss2 = i.split(" ")[0]
                print (ss2)
                kk2 = raw_input("\n update it (y n):")
                if kk2 == 'y':
                    if i.split(" ")[0] != "numpy":
                        os.system("pip2.7 install --upgrade "+i.split(" ")[0])
                else:
                    print ("\npass to next")

#========================================================


2016年5月9日 星期一

python use dict function run ( by switch case example code )

# coding=utf-8

def key1(ss):
    print ("\n run %s ok !" % ss)
    pass
         
def key2(ss):
    print ("\n run %s ok !" % ss)
    pass
           
def key3(ss):
    print ("\n run %s ok !" % ss)
    pass
 
def key4(ss):
    print ("\n run %s ok !" % ss)
    pass

caseloop = {
    "k1":key1,
    "k2":key2,
    "k3":key3,
    "k4":key4
 }    
     
if __name__ == '__main__':
    while 1:
        kk = input("\n type key:")
        caseloop[kk](kk)

2016年5月8日 星期日

python Functin set array call Example

# Function Set call by index    
def aa():
  print ("is aa run !\n")
 
def bb():
  print ("is bb run !\n")  

def cc():
  print ("is cc run !\n")

def dd():
  print ("is dd run !\n")

workp = {0:aa,1:bb,2:cc,3:dd}  

if __name__ == '__main__':
  print ("hello dir call test ! \n ================== \n")
  aa(),bb(),cc(),dd()
  print ("hello set call test ! \n ================== \n")
  workp[0]()                                              
  workp[1]()
  workp[2]()
  workp[3]()


run Ex:
hello dir call test !
 ==================
is aa run !
is bb run !
is cc run !
is dd run !
hello set call test !
 ==================
is aa run !
is bb run !
is cc run !
is dd run !

================================================
EXample 2
def plus_1(x):
    return x + 1

def minus_1(x):
    return x - 1

func_map = {'+' : plus_1, '-' : minus_1}

print (func_map['+'](3))  # returns plus_1(3) ==> 4
print (func_map['-'](3))  # returns minus_1(3) ==> 2


2016年5月4日 星期三

python print format demo

>>> print (" %3d %3d %4x" %(9,9,9))
   9   9    9
>>> print (" %3d %3d %04x" %(9,9,9))
   9   9 0009
>>> print (" %3d %3d %04x" %(9,9,12))
   9   9 000c
>>> print (" %03d %03d %04x" %(9,9,12))
 009 009 000c
>>> print (" %03d %05d %04x" %(9,9,12))
 009 00009 000c
>>> print (" %03d %05d %04x %s" %(9,9,12,"hello"))
 009 00009 000c hello
>>> q = 459
>>> p = 0.098
>>> print(q, p, p * q)
459 0.098 44.982
>>> print(q, p, p * q, sep=",")
459,0.098,44.982
>>> print(q, p, p * q, sep=" :-) ")
459 :-) 0.098 :-) 44.982
>>> 
General way of working of the string modulo operator


General way of working of the string modulo operator, format string 
The format string contains placeholders. There are two of those in our example: "%5d" and "%8.2f". 

>>> print("%10.3e"% (356.08977))
 3.561e+02
>>> print("%10.3E"% (356.08977))
 3.561E+02
>>> print("%10o"% (25))
        31
>>> print("%10.3o"% (25))
       031
>>> print("%10.5o"% (25))
     00031
>>> print("%5x"% (47))
   2f
>>> print("%5.4x"% (47))
 002f
>>> print("%5.4X"% (47))
 002F
>>> print("Only one percentage sign: %% " % ())
Only one percentage sign: % 
>>> 
>>> print("%#5X"% (47))
 0X2F
>>> print("%5X"% (47))
   2F
>>> print("%#5.4X"% (47))
0X002F
>>> print("%#5o"% (25))
 0o31
>>> print("%+d"% (42))
+42
>>> print("% d"% (42))
 42
>>> print("%+2d"% (42))
+42
>>> print("% 2d"% (42))
 42
>>> print("%2d"% (42))
42
>>> s = "Price: $ %8.2f"% (356.08977)
>>> print(s)
Price: $   356.09
>>>

General way of working of the format method with positional parameters

Examples of positional parameters:
>>> "First argument: {0}, second one: {1}".format(47,11) 
'First argument: 47, second one: 11'
>>> "Second argument: {1}, first one: {0}".format(47,11) 
'Second argument: 11, first one: 47'
>>> "Second argument: {1:3d}, first one: {0:7.2f}".format(47.42,11) 
'Second argument:  11, first one:   47.42'
>>> "First argument: {}, second one: {}".format(47,11) 
'First argument: 47, second one: 11'
>>> # arguments can be used more than once:
... 
>>> "various precions: {0:6.2f} or {0:6.3f}".format(1.4148) 
'various precions:   1.41 or  1.415'
>>> 
In the following example we demonstrate how keyword parameters can be used with the format method:
>>> "Art: {a:5d},  Price: {p:8.2f}".format(a=453, p=59.058)
'Art:   453,  Price:    59.06'
>>> 
General way of working of the format method with keyword parameters  It's possible to left or right justify data with the format method. To this end, we can precede the formatting with a "<" (left justify) or ">" (right justify). We demonstrate this with the following examples: 
>>> "{0:<20s 6.99="" amp="" eggs:="" f="" format="" pam="">>> "{0:>20s} {1:6.2f}".format('Spam & Eggs:', 6.99)
'        Spam & Eggs:   6.99'
>>> "{0:>20s} {1:6.2f}".format('Spam & Ham:', 7.99)
'         Spam & Ham:   7.99'
>>> "{0:<20s 7.99="" amp="" f="" format="" ham:="" pam="">>> "{0:<20 7.99="" amp="" f="" format="" ham:="" pam="">>> "{0:>20} {1:6.2f}".format('Spam & Ham:', 7.99)
'         Spam & Ham:   7.99'
>>> 
OptionMeaning
'<'The field will be left-aligned within the available space. This is usually the default for strings.
'>'The field will be right-aligned within the available space. This is the default for numbers.
'0'If the width field is preceded by a zero ('0') character, sign-aware zero-padding for numeric types will be enabled.
>>> x = 378
>>> print("The value is {:06d}".format(x))
The value is 000378
>>> x = -378
>>> print("The value is {:06d}".format(x))
The value is -00378
','This option signals the use of a comma for a thousands separator.
>>> print("The value is {:,}".format(x))
The value is 78,962,324,245
>>> print("The value is {0:6,d}".format(x))
The value is 5,897,653,423
>>> x = 5897653423.89676
>>> print("The value is {0:12,.3f}".format(x))
The value is 5,897,653,423.897
'='Forces the padding to be placed after the sign (if any) but before the digits. This is used for printing fields in the form "+000000120". This alignment option is only valid for numeric types.
'^'Forces the field to be centered within the available space.
Unless a minimum field width is defined, the field width will always be the same size as the data to fill it, so that the alignment option has no meaning in this case.
Additionally, we can modify the formatting with the sign option, which is only valid for number types:
OptionMeaning
'+'indicates that a sign should be used for both positive as well as negative numbers.
'-'indicates that a sign should be used only for negative numbers, which is the default behavior.
spaceindicates that a leading space should be used on positive numbers, and a minus sign on negative numbers.

Using dictionaries in "format"

We have seen in the previous chapters that we have two ways to access the values to be formatted:
  • Using the position or the index:
    >>> print("The capital of {0:s} is {1:s}".format("Ontario","Toronto"))
    The capital of Ontario is Toronto
    >>> 
    
    Just to mention it once more: We could have used empty curly braces in the previous example!
  • Using keyword parameters:
    >>> print("The capital of {province} is {capital}".format(province="Ontario",capital="Toronto"))
    The capital of Ontario is Toronto
    >>>
    
The second case can be expressed with a dictionary as well, as we can see in the following code:
>>> print("The capital of {province} is {capital}".format(**k))
The capital of Ontario is Toronto
>>> 
Let's look at the following Python program:
capital_country = {"United States" : "Washington", 
                   "US" : "Washington", 
                   "Canada" : "Ottawa",
                   "Germany": "Berlin",
                   "France" : "Paris",
                   "England" : "London",
                   "UK" : "London",
                   "Switzerland" : "Bern",
                   "Austria" : "Vienna",
                   "Netherlands" : "Amsterdam"}

print("Countries and their capitals:")
for c in capital_country:
    print("{country}: {capital}".format(country=c, capital=capital_country[c]))
If we start this program, we get the following output:
$ python3 country_capitals.py 
Countries and their capitals:
United States: Washington
Canada: Ottawa
Austria: Vienna
Netherlands: Amsterdam
Germany: Berlin
UK: London
Switzerland: Bern
England: London
US: Washington
France: Paris
We can rewrite the previous example by using the dictionary directly. The output will be the same:
capital_country = {"United States" : "Washington", 
                   "US" : "Washington", 
                   "Canada" : "Ottawa",
                   "Germany": "Berlin",
                   "France" : "Paris",
                   "England" : "London",
                   "UK" : "London",
                   "Switzerland" : "Bern",
                   "Austria" : "Vienna",
                   "Netherlands" : "Amsterdam"}

print("Countries and their capitals:")
for c in capital_country:
    format_string = c + ": {" + c + "}" 
    print(format_string.format(**capital_country))

Using Local Variable Names in "format"

"locals" is a function, which returns a dictionary with the current scope's local variables, i.e- the local variable names are the keys of this dictionary and the corresponding values are the values of these variables:
>>> a = 42
>>> b = 47
>>> def f(): return 42
... 
>>> locals()
{'a': 42, 'b': 47, 'f': , '__builtins__': , '__package__': None, '__name__': '__main__', '__doc__': None}
>>> 
The dictionary returned by locals() can be used as a parameter of the string format method. This way we can use all the local variable names inside of a format string.  Continuing with the previous example, we can create the following output, in which we use the local variables a, b and f:
>>> print("a={a}, b={b} and f={f}".format(**locals()))
a=42, b=47 and f=

Other string methods for Formatting

The string class contains further methods, which can be used for formatting purposes as well: ljust, rjust, center and zfill  Let S be a string, the 4 methods are defined like this:
  • center(...):
    S.center(width[, fillchar]) -> str
    
    Return S centred in a string of length width. Padding is done using the specified fill character. The default value is a space.  Examples:
    >>> s = "Python"
    >>> s.center(10)
    '  Python  '
    >>> s.center(10,"*")
    '**Python**'
    
  • ljust(...):
     S.ljust(width[, fillchar]) -> str 
    
    Return S left-justified in a string of length "width". Padding is done using the specified fill character. If none is given, a space will be used as default.  Examples:
    >>> s = "Training"
    >>> s.ljust(12)
    'Training    '
    >>> s.ljust(12,":")
    'Training::::'
    >>> 
    
  • rjust(...):
    S.rjust(width[, fillchar]) -> str
    
    Return S right-justified in a string of length width. Padding is done using the specified fill character. The default value is again a space.  Examples:
    >>> s = "Programming"
    >>> s.rjust(15)
    '    Programming'
    >>> s.rjust(15, "~")
    '~~~~Programming'
    >>> 
    
  • zfill(...):
     
    S.zfill(width) -> str
    
    Pad a string S with zeros on the left, to fill a field of the specified width. The string S is never truncated. This method can be easily emulated with rjust.  Examples:
    >>> account_number = "43447879"
    >>> account_number.zfill(12)
    '000043447879'
    >>> # can be emulated with rjust:
    ... 
    >>> account_number.rjust(12,"0")
    '000043447879'
    >>> 
    

Python 應用實例


許多軟體及網站程式已經使用 Python 來開發,下列是一些例子:
  • 教學環境: 美國麻省理工學院 (MIT EECS) 新生程式語言入門,選用 Python 為預設教材。
  • 行動裝置開發環境: OLPCNokia S60Moblin 都提供 Python 應用程式的開發環境。
  • 入口網站服務: Google, YouTube, Yahoo! 網站的關鍵服務以 Python 語言開發。
  • 動畫軟體: MayaBlender 語言擴充介面支援 Python 語言。
  • 圖形介面及動畫遊戲: wxPythonPyGame 是協助創作的好工具。
  • 郵遞論壇: mailman 程式以 Python 語言寫成。
  • 網頁應用伺服與開發框架: Google App EnginelaunchpadZopeDjangoTurboGearsPylons 是主要的範例。
  • 安裝程式: Red Hat Linux 開機安裝程式及 Gentoo 套件管理。
  • 檔案點對點分享工具: BitTorrent 工具程式以 Python 語言開發。
  • 科學運算: BiopythonSciPyPyPVM

Python command demo Array , function call

# /pycode  code demo 1
__author__ ="Handel liao 20160505"
#simx1

#=====================================
print ("=====string and number  =====")
a =33
b = "abc"
c =12.1

print ("hello")
print (a)
print (b)
print (c)
print (a+c)

#=====================================
print ("===== python logic shift ===")
print (a<<1 p="">print (a/4)
print (a>>1)
print (a%4)


#=====================================
print ("====Array show =============")

a=['apple','welcom','car','table','telephone','tv','pc','nb']

for x in a:
  print (x,a.index(x))

print ("len = ",len(a))
print ("min = ",min(a))
print ("max = ",max(a))

print ("befert sort => ",a)
a.sort()
print ("after  sort => ",a)

# /pycode  code demo 2
__author__ ="Handel liao 20160505"
#simx2 by def test


#=====================================
print ("====function call ===================")
def fun1():
  print ("this is fun1 !")

def fun2(num):
  print ("this is fun2 = " + str(num))

def fun3(num1,num2):
  num3 = num1+num2
  print ("this is fun3 by "+str(num1)+"+"+str(num2)+"="+str(num3))
  return num3

#=====================================
print ("=============================")

fun1()
fun2(100)
yy = fun3(10,22)
print ("add fun => ",yy)

Raspberry Install python Package TOOL

#download ez_setup.py


$python3 ez_setup.py

$easy_install pip

#=====================================
#yolk the python package check TOOL
$easy_install yolk

   $ yolk -l   #list package
   $ yolk -a   #list active package
   $ yolk -U   #list need update package
 
#=====================================
#install python3 pyserial

$wget 
  1. $tar -xzf pyserial-3.0.1.tar.gz
  2. $cd pyserial-3.0.1
  3. $sudo python setup.py install

#=====================================
# install the minicom tool  by usrt com port test link

$sudo apt-get install minicom
$minicom -b 115200 -o -D /dev/ttyAMA0


2016年4月24日 星期日

CI工具的介紹 @ 敏捷開發 mode

CI工具的介紹
持續整合 (Continuous integration, CI)   一種軟體專發展的方法
由企劃規格開始就建立自動化 , 產出規範及測試程式 以CI 的精神
基於GIT SVN 版本管理自動化 到 測試驗證自動化 產出測試報告
將測試結果 自動發mail 給所有專案相關人 是一種即時回報開發進度及報告的開發作業流程 將專案管理提升到一個層次 而軟體設計師則變成 勞力密集的勞工 每天以 程式碼產出的數量 及 錯誤率高低 量化績效!
這是目前 網頁設計 或 軟體開發專案的主流管理模式
還在單打獨鬥 用傳統手工進行開發軟體的 公司或人 將成為 資訊石器時代的原始人 被 競爭的演化法則淘汰!


TFS
Hudson
TeamCity
CruiseControl
CruiseControl.NET

摘要比較:

TFS,要錢,Total Solution,與其他工具比是最完整貫穿整個ALM的工具。從需求分析開始,系統分析、Work item checking、版本庫、程式碼分析、測試、產生分析報表、建置、部署、bug tracking,都包含在裡面。(這麼完整的功能,就不難想像為什麼要收費)

Hudson,免費,產生的圖表介面相當好懂且平易近人,與多種語言平台相容性高,社群有開發不少外掛供使用。
[註]沒記錯的話,Hudson好像也被Oracle買走了,所以現在大部分都是改用Jenkins。

TeamCity,免費,簡單、快速建立,與JetBrains工具整合度高。

CC與CC.NET,免費、陽春、單純。

2016年4月20日 星期三

RTOS Design software VM 系統架構規劃

** 語言對平台的延續性 慎選語言 要能跨平台 要相容 才能累積成果經驗 減少歸零的挫折
** 軟體技術分析文件 資料結構 演算法 狀態圖 流程圖 才是軟體的靈魂 找對工具軟體 建立標準的文件格式 建立資料
** 建立函數庫 累積資源 提升coding 效率 , 結構化物件化 的規劃 建立 功能導向 需求導向的 函數庫或物件庫 以此 在上層建立 軟體的演算法 資料結構 如此 軟體轉換平台時 只要針對 底層函數庫改寫 或重新編譯
** 軟體系統的分層架構規劃
L00:[HardHDL] 硬體層
L01:[BIOS] 基本io 驅動
L02:[DRIVE1_LOW] 低階驅動 庫
L03:[DRIVE2_HIGH] 高階驅動 庫
L04:[SYS_PUBLIB] 系統公用函數庫
L05:[APP_PUBLIB] 應用公用函數庫
L06:[USER_PUBLIB] 使用及含庫
L07:[APP] 應用程式
各階層的關聯限制 嚴格遵守 提高系統的穩定及高度移植效率
L07 LINK L06,L05,L04
L06 LINK L04,L04
L05 LINK L04,L03
L04 LINK L03,L02
L03 LINK L02,L01
L02 LINK L01,L00
L01 LINK L00
由此理論 應建構一個 理想化的軟體虛擬平台 VM
累積設計資源

2016年1月12日 星期二

引用轉載: 安裝 VB6 到 (Win8 # 64bit)

安裝 VB6 到 (Win8 # 64bit)
試著安裝 VB6 到 Win8 64bit,安裝過程中,前面似乎都沒問題,但是到後面更新系統時,就不回應了,整個程式掛掉給你看。

因為win8 相容關係 得要先設定一些屬性

  1. 二個安裝檔案(setup.exe 以及 Setup 目錄下的 ACMSetup.exe )需設定相容模式為「Windows XP (Service Pack 3) 」;權限等級為「以系統管理員的身分執行此程式」。

  1. 安裝過程要選擇自訂安裝,把「資料存取」裡的「ADO、RDS 和 OLE DB Provider」選項勾勾拿掉。

以上完成後,安裝就不會再有問題。

但安裝完成後,還要做個小小的調整,否則在執行 VB6 後,引用元件或什麼的會有一些奇怪的問題。
  1. 到安裝完成後的目錄(預設應為 C:\Program Files (x86)\Microsoft Visual Studio\VB98),找到 VB6.EXE,將它設定相容模式為「Windows XP (Service Pack 3) 」;
  2. 權限等級為「以系統管理員的身分執行此程式」;勾選「在高 DPI 設定時,停用顯示調整值」。

有興趣看原文了解原因的,請參考 Install VB6 on Windows 8
2013-08-06 補充:
發現 VB6.EXE 還是不要設定相容模式,因為當我的程式裡使用了 DateAdd() 時,會造成引數錯誤的訊息。

2013-08-14 補充:
拿掉相容模式後,VB啟動時會出現「'~' 物件失敗」之類的訊息,這是由於 MDAC 版本所造成,由於我使用的是64bit Win8, 執行: Regedit 後出現登入編輯
需要到 => 
HKEY_LOCAL_MACHINE\SOFTWARE\wow6432node\Microsoft\DataAccess 將 FullInstallVer 及 Version 這二個的資料值都改
成 2.82.3959.0,就可以正常使用了。

ps: 原文引用自 [隨意窩 Blog]  我的電腦記事本 部落格