2016年7月5日 星期二

python 中使用 enum


from enum import Enum
class Color(Enum):
    red = 1
    green = 2
    blue = 3

python 如何安裝 .whl 檔

在命令列中執行:

 pip install some-package.whl

就可以了

2016年7月1日 星期五

把 list 的資料寫入到 file


bytesToWrite=[125,3,255,0,101]
newfile=open("hello.bin",'wb')
newfile.write(bytes(bytesToWrite))
newfile.close()

2016年6月6日 星期一

Atmel Studio 7 啟動時 Error ("ErrorListPackage did not load correctly") 解決方式

參考:
http://atmel.force.com/support/articles/en_US/Workaround/Installing-Visual-Studio-2015-Update-1-leads-to-Atmel-Studio-no-longer-starting

Root Cause
The Visual Studio 2015 Update 1 updates a dll that is shared between Atmel Studio and Visual Studio, without providing the correct dll load redirect information. Until we have had the chance to verify that this new dll (version 1.1.37) works with Atmel Studio, we suggest downloading the previous version (1.1.36) and place it in a load path for Atmel Studio with higher load precedence than the Visual Studio load path.
Workaround
This issue is fixed in Atmel Studio 7.0.790 and newer.

If you are using an older version, use to following workaournd:
  1. Download System.Collections.Immutable (1.1.36) from nuget.org
  2. The file downloaded is a zip file with a .nupkg extension, rename the file to .zip 
  3. Open the zip file, go to the lib folder and into a folder called portable-net45%2Bwin8%2Bwp8%2Bwpa81
  4. Copy the System.Collection.Immutable.dll file into one of the Atmel Studio load folders
    1. We suggest using '<installdir>\Extensions\Application', which might be 'C:\Program Files (x86)\Atmel\Studio\7.0\Extensions\Application' on your machine

使用 python 計算加入天數後的日期


要算出 2000/1/1 後的 100 天是幾月幾號?

import datetime
first_date = datetime.date(2000,1,1)
delta_day = datetime.timedelta(days=100)
cal_date = first_date+delta_day
print(cal_date)

2016年5月4日 星期三

Raspberry Pi 的版本

顯示目前 raspberry pi 的版本:

$ uname -a
   Linux RPi 3.1.19 #1 PREEMPT Fri Jun 1 14:16:38 CEST 2012 armv6l GNU/Linux

顯示目前  firmware 的版本:

$ /opt/vc/bin/vcgencmd version
Feb  4 2015 21:04:27
Copyright (c) 2012 Broadcom
version 115f63aa0915cdb5b6dff23822eb16699b72ae8b (clean) (release)



ref: http://elinux.org/R-Pi_Troubleshooting#Check_your_firmware_version

讀取特定的行數

要讀取文字檔中的特定行數, 除了 for line in file(file) 之外;
使用內建函式 enumerate()

    for i, line in enumerate(fin,1):
        if i == 5:
            #do something
            break
    fin.close()


enumerate(iterable, start=0), 預設 start 是 0; 但是行數從 1 開始, 所以把 start 設為 1