2015年7月23日 星期四
Python 的 .py 和 .pyc 檔有什麼不同 ?
Source: http://www.arthurtoday.com/2010/02/python-py-pyc.html
Python 的程式是寫在 .py 裡,也就是說, .py 檔是 Python 的原始程式碼檔案,而 Python 會在執行 .py 檔時,將 .py 的程式碼編譯成中間程式碼檔 ( byte-compiled ) 的 .pyc 檔以加快下次執行的速度。
所以,當你執行一支 .py 檔時,Python 會先看看有沒有這支 .py 檔的 .pyc 檔,如果有,而且 .py 檔的修改時間和 .pyc 檔一樣時,Python 就會讀 .pyc 檔,否則,Python 就會去讀原來的 .py 檔。
不過,執行 .py 檔並不一定會產生出 .pyc 檔,通常是被 import 的 module 的 .py 檔才會產生出 .pyc 檔的
2015年7月22日 星期三
apt-get fails due to *openssl*
install libcurl4-openssl-dev pass
Command:
sudo apt-get remove --purge libcurl4-openssl-de
sudo dpkg -i --force-overwrite /var/cache/apt/archives/libssl-dev_1.0.1-4ubuntu5.31_i386.deb
sudo apt-get autoremove
sudo apt-get update
sudo apt-get install libcurl4-openssl-dev
sudo dpkg --configure -a
error: gnutls_handshake() failed: A TLS packet with unexpected length was received.
>>> Issue
error: gnutls_handshake() failed: A TLS packet with unexpected length was received. while accessing ...
fatal: HTTP request failed
<<< Fix
sudo apt-get install build-essential fakeroot dpkg-dev
mkdir ~/git-openssl
cd ~/git-openssl
sudo apt-get source git
sudo apt-get build-dep git
sudo apt-get install libcurl4-openssl-dev
sudo dpkg-source -x git_1.7.9.5-1.dsc
cd git_1.7.9.5
Then, edit debian/control file (run the command: gksu gedit debian/control) and replace all instances of libcurl4-gnutls-dev with libcurl4-openssl-dev.
Then build the package (if it's failing on test, you can remove the line TEST=test from the file debian/rules):
sudo dpkg-buildpackage -rfakeroot -b
Install new package:
i386: sudo dpkg -i ../git_1.7.9.5-1_i386.deb
x86_64: sudo dpkg -i ../git_1.7.9.5-1_amd64.deb
error: gnutls_handshake() failed: A TLS packet with unexpected length was received. while accessing ...
fatal: HTTP request failed
<<< Fix
sudo apt-get install build-essential fakeroot dpkg-dev
mkdir ~/git-openssl
cd ~/git-openssl
sudo apt-get source git
sudo apt-get build-dep git
sudo apt-get install libcurl4-openssl-dev
sudo dpkg-source -x git_1.7.9.5-1.dsc
cd git_1.7.9.5
Then, edit debian/control file (run the command: gksu gedit debian/control) and replace all instances of libcurl4-gnutls-dev with libcurl4-openssl-dev.
Then build the package (if it's failing on test, you can remove the line TEST=test from the file debian/rules):
sudo dpkg-buildpackage -rfakeroot -b
Install new package:
i386: sudo dpkg -i ../git_1.7.9.5-1_i386.deb
x86_64: sudo dpkg -i ../git_1.7.9.5-1_amd64.deb
GPG error: The following signatures were invalid: BADSIG 16126D3A3E5C1192 Ubuntu Extras Archive Automatic Signing Key
>>> Issue
W: GPG error: http://extras.ubuntu.com precise Release: The following signatures were invalid: BADSIG 16126D3A3E5C1192 Ubuntu Extras Archive Automatic Signing Key
<<< Fix #1 (NG)
sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 16126D3A3E5C1192
<<< Fix #2 (OK)
sudo -i
apt-get clean
cd /var/lib/apt
mv lists lists.old
mkdir -p lists/partial
apt-get clean
apt-get update
This will rebuild the cache !
W: GPG error: http://extras.ubuntu.com precise Release: The following signatures were invalid: BADSIG 16126D3A3E5C1192 Ubuntu Extras Archive Automatic Signing Key
<<< Fix #1 (NG)
sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 16126D3A3E5C1192
<<< Fix #2 (OK)
sudo -i
apt-get clean
cd /var/lib/apt
mv lists lists.old
mkdir -p lists/partial
apt-get clean
apt-get update
This will rebuild the cache !
2015年7月18日 星期六
Find the latest modified file in a directory recursively.
find . -type f -printf "%T@\0%p\0" | awk '
{
if ($0>max) {
max=$0;
getline mostrecent
} else
getline
}
END{print mostrecent}' RS='\0'
{
if ($0>max) {
max=$0;
getline mostrecent
} else
getline
}
END{print mostrecent}' RS='\0'
2015年7月17日 星期五
script 的執行方式差異 (source, sh script, ./script)
http://linux.vbird.org/linux_basic/0340bashshell-scripts.php
##### [ demo01.sh
#!/bin/bash
# Program:
# User inputs his first name and last name. Program shows his full name.
# History:
# 2005/08/23 VBird First release
# 2015/07/16 Yulin Modified for demo of different script execution ways.
read -p "Please input your first name: " firstname # 提示使用者輸入
read -p "Please input your last name: " lastname # 提示使用者輸入
echo -e "\nYour full name is: $firstname $lastname" # 結果由螢幕輸出
##### ] demo01.sh
$source demo01.sh
$. demo01.sh
==> both the above 2 ways alter the environment of the parent process.
#sh demo01.sh
#./demo01.sh
==> both the above 2 ways create a child process to carry out the script and won't alter the environment of the parent process.
##### [ demo01.sh
#!/bin/bash
# Program:
# User inputs his first name and last name. Program shows his full name.
# History:
# 2005/08/23 VBird First release
# 2015/07/16 Yulin Modified for demo of different script execution ways.
read -p "Please input your first name: " firstname # 提示使用者輸入
read -p "Please input your last name: " lastname # 提示使用者輸入
echo -e "\nYour full name is: $firstname $lastname" # 結果由螢幕輸出
##### ] demo01.sh
$source demo01.sh
$. demo01.sh
==> both the above 2 ways alter the environment of the parent process.
#sh demo01.sh
#./demo01.sh
==> both the above 2 ways create a child process to carry out the script and won't alter the environment of the parent process.
訂閱:
文章 (Atom)