Excel_ReadWrite
Create empty Excel File
1 | import openpyxl |
Create Sheet工作表的
Create Empty Sheet 新增工作
1 | import openpyxl |
Read Excel Sheet 讀取excel檔案每個工作表的名稱
1 | import openpyxl |
output:
1 | ['Sheet1', 'Sheet2', 'Sheet'] |
1 | import openpyxl |
1 | import openpyxl |
1 | import openpyxl |
output:
1 | ['Sheet1', 'Sheet2', 'Sheet'] |
這裡會包含以下內內容:
for
*
list (快速讀 list 不需要用到 for
loop)enumerate
方法list : list = ['A','B','C','D','E','F']
我們可以用以下方法:
for
loop1 | list= [1,2,3] |
output:
1 2 3
*
list: 不需要 for loop ,可以 unpack list今天分享如何搜尋字串裡面的 substring 或如果有檔案(log)想找相關字來做分析。
我的 string 是:
st="[20221013.162853.788442][info]:[[40;32m>>> DL- ingress traffic: 0.010799(Mbps), egress traffic: 0.087016(Mbps), ReTx: 0.000220(Mbps)[0m]"
我想抓出時間和TPUT的直,如:[20221013.162853.788442]
和 0.010799(Mbps)
同時要把 []
和 (Mbps)
移除,可以用下面方式:
1 | st="[20221013.162853.788442][info]:[[40;32m>>> DL- ingress traffic: 0.010799(Mbps), egress traffic: 0.087016(Mbps), ReTx: 0.000220(Mbps)[0m]" |
1 | dateStr = st.split('[', 1)[1].split(']')[0] |
output:
20221013.162853.788442
open syntax:
open( file, mode, encoding="utf-8")
mode 字串 | 說明 |
---|---|
r | Read only 讀取模式 ( 預設 ) |
r+ | Read and write |
w | Write only 寫入模式,檔案若存在,會清空內容再寫入 ; 若檔案不存在,則建立新檔開啟寫入 |
w+ | write+read |
a | Append only 附加模式,若檔案存在,則寫入內容 會附加至檔 案尾端 |
a+ | Append and Read (‘a+’) |
讀取方法 | 描述 |
---|---|
read( ) | 一次讀取檔案所有的內容,回傳為字串 |
readline( ) | 只讀取一行內容 |
readlines( ) | 將所有檔案內容,每行讀入回傳為串列 |
1 | fileObj = open("路徑檔名" , "r", encoding="utf-8") |
1 | fileObj = open("路徑檔名" , "w", encoding="utf-8") |
I am sharing some Code Test during my Interview, and also some practice Code example.
今天分享我一些Live Coding 面試問題,還有一些刷題的問題。
If we have a log.txt, as below, you need to and search specfic string, like cat.
1 | 1 cat |
1 | with open("log.txt", "r") as textfile: |
1 | d={} |
1 | function createCard(initName){ |
output
createCard { name: ‘Ma’ }
createCard { name: ‘Ma2’ }
createCard { name: ‘Ma3’ }
=>
In ES6 there is a new function called array function, which you can write shorter function.
Before ES6
function hello(){}
after ES6
let hello = function (){}
shorthand
let hello = () =>{}
Before ES6 (normal function)
ex: function hello(){}
今天我想分享如何用linux shell script 語法。
我們需要加這個在script裡面,然後檔案改成.sh
1 | #! /bin/bash |
chmod 777 myscript.sh
./myscript.sh
1 | text1=Hello |
output:
Hello CC
read variable
read a
read vairable without skip new line:
read -p “Your Options: “ option
.alias_pofile
Recommend use this file, will not destory .bashrc
file.
1 | cd ~ |
.bashrc
This method need to reboot to take effect
cd
: change directory to home ~
directorycd folder
: change to specific directory
1 | str_name= "hello" |
output:
str value is hello, and number is 999
%
Operator1 | text = 'world' |
output:
hello world
hello world
Hello, Test. You are 100.
str.format() 是對 %-formatting 的改進,可以用函式呼叫語法,可以通過 format() 方法對被轉換為字串的物件
Browser- inspect
Method1:
Go to inspect > console
Method 2:
inspect> sources> snipperts> create js file
NodeJS environment
寫
XXX.js
//CREATE JS file
node XXX.js
//run .js file using node
//
single line comment/**/
: multiply line comment
console.log()
顯示在consolealert()
跳出顯示document.write("\<h1>hello <br\/>")
let
(新)可以取代varex:
let myName= "chenchih"
console.log(myName)
var
const
must be inital and not able to change
不被修改變數。如果不想被人修改
1 | const test= "heloo" |