==========py to exe with sign==========
參考網址https://steward-fu.github.io/website/driver/wdm/self_sign.htm
或這個也寫得不錯http://mqjing.blogspot.tw/2009/03/plugin-activex-cab-signtool.html
signtool get from MS SDK or Visual C++ for Python (http://aka.ms/vcpython27)
First time
Makecert -r -pe -ss YourName YourName.cer
certmgr.exe -add YourName.cer -s -r localMachine root
After
signtool sign /s YourName YourApp.exe
==========bundle exe to py.exe==========
http://blog.csdn.net/Sagittarius_Warrior/article/details/73998548
currPath = sys.path[0]
os.system(currPath+"\\exe.exe") #exe.exe can not be found if without sys.path[0]
#or add sys.path[0] to cwd path
os.path.join(os.getcwd(),sys.path[0])
C:\Python27\Scripts\pyinstaller --uac-admin ^
--uac-uiaccess ^
--win-private-assemblies ^
--clean ^
--key 1234512345 ^
-i Home.ico ^
--add-data=exe.exe;. ^
--add-data=signtool.exe;. ^
-F exe_Test.py
註: ^ 是換行的意思
====================
====================
====================
====================
======同時安裝python2 & 3==============
https://www.zhihu.com/question/21653286
py -2 v2.py
py -3 v3.py
py -2 -m pip install package
py -3 -m pip install package
header #! python2 or #! python3
==========Server & Client的部分==========
http://www.bogotobogo.com/python/python_network_programming_server_client_file_transfer.php
加一下自己寫的東西... https://github.com/kyc1109/devcon
# Compile .py to class ==========================================
#https://stackoverflow.com/questions/14205464/converting-jython-code-into-a-java-class
Test file: A31Mod.py, A31Mod$py.class
指令如下: #若直接用Jython編譯則產出class, 但是如果直接用Python編譯則產出pyc檔。
java -jar jython-standalone-2.7.0.jar #run Jython
>>> import compileall # import for compile multi file。
#>>> compileall.compile_dir('directory/', force=True) #compile multi file
>>> import py_compile # import for compile single file。
>>> py_compile.compile("A31Mod.py") #compile single file from A31Mod.py to A31Mod$py.class
>>> from A31Mod import A31Mod #import A31Mod$py.class
>>> a31 = A31Mod("TC_COM_1436") # use A31Mod()
>>> a31.LAN_PING()
ping www.compal.com #result
LAN check Pass #result
Python 中文教學
http://mirror.sars.tw/Python_tut_tw/tut.html
#How to overload __init__ method based on argument type?==========================================
#https://stackoverflow.com/questions/141545/how-to-overload-init-method-based-on-argument-type
class MyData: #Quick and dirty fix
def __init__(string=None,list=None):
if string is not None:
#do stuff
elif list is not None:
#do other stuff
else:
#make data empty
#===import py part 1=======================================
#Complex.py
class Complex:
def __init__(self, realpart, imagpart): #__init__ 就是class的方法,所以等於Complex()
self.r = realpart
self.i = imagpart
#test.py
from Complex import Complex
x = Complex(3.0,-4.5)
print x.r, x.i
#===import py part 2=======================================
import os, subprocess, time
#變數和呼叫的方法要前面要加self.,所以會有一堆self.xxx。
class DevCompareMod:
def __init__(self, original_file, unoriginal_file, log_file): #__init__ equal DevCompareMod()
self.original_file = original_file #"original.txt"
self.unoriginal_file = unoriginal_file #"unoriginal.txt"
self.log_file = log_file #"log_DevCompare.txt"
def wLog(self, txtLog):
if not os.path.exists(self.log_file):
wLog=open(self.log_file, "w")
wLog.write(txtLog)
wLog.close()
else:
wLog=open(self.log_file, "a")
wLog.write(txtLog)
wLog.close()
self.wLog(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())+"=======================================\n")
self.wLog(strLost)
#使用方式
from DevCompareMod import DevCompareMod
DevCompareMod("original.txt","unoriginal.txt","log_DevCompare.txt")
#===import py part 3=======================================
#__init__ 和 __name__是可以一起用的
class DevCompareMod:
def __init__(self): #__init__ equal DevCompareMod()
if __name__ == '__main__':
if len(sys.argv) < 2 or sys.argv[1].lower()=="/h" or sys.argv[1].lower()=="-h" or sys.argv[1].lower()=="/?" or sys.argv[1].lower()=="-?" : #len小於2也就是不帶參數啦
print "no/wrong argument."
else:
DevCompareMod()
# 參考網址 http://www.kaiching.org/2012/12/Python-Constructor.html
http://usyiyi.cn/documents/python_278/library/subprocess.html
簡中的翻譯版
建議優先使用 subprocess.call()或是subprocess.check_call()或是subprocess.check_output()(回傳值不為0則丟出例外),
如果不行的話,再用Popen 搭配communicate()
#Popen VS. check_output
#因為check_outputt因為已經內建stdout,所以如果有問題只會出現error code和error msg,但不會出現執行的內容。
try:
p = subprocess.check_output(["ls non_existent_file; exit 1"],shell=True, stderr=subprocess.STDOUT) #不允許stdout因為已經內建了
print p
except subprocess.CalledProcessError,e:
print e.output
輸出ls: cannot access 'non_existent_file': No such file or directory
q = subprocess.Popen(["ls","-a"],shell=True, stdout=PIPE, stderr=PIPE)
stdout, stderr = q.communicate()
print stdout
輸出README.md
輸出Test_1.ipynb
https://docs.python.org/2/library/subprocess.html
#method2, output="dmesg | grep hda"
p1 = Popen(["dmesg"], stdout=PIPE)
p2 = Popen(["grep", "hda"], stdin=p1.stdout, stdout=PIPE)
p1.stdout.close() # Allow p1 to receive a SIGPIPE if p2 exits.
output = p2.communicate()[0]
http://www.powenko.com/wordpress/?p=8697
翻譯的有點怪,但還可以接受啦
https://stackoverflow.com/questions/4348524/subprocess-variables
https://blog.aweimeow.tw/2016/09/09/python-subprocess-%E5%90%84%E5%87%BD%E5%BC%8F%E7%9A%84%E4%BD%BF%E7%94%A8%E6%99%82%E6%A9%9F/
參考上述網頁,Popen裡面的指令與參數,用逗號","取代空格" "可以避免不必要的錯誤。
透過PIPE把結果回傳到stdout或是stderr。
def subxx():
import sys, os, subprocess # Import socket module
from subprocess import Popen, PIPE
try:
output = subprocess.Popen(["ping","localhost"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) #useing , not space in cmd
stdout, stderr= output.communicate()
print ("output: \n"+str(output))
print ("stdout: \n"+stdout)
except subprocess.CalledProcessError:
print('Exception handled')
subxx()
====以下為輸出結果=============================================
output:
<subprocess.Popen object at 0x8>
stdout:
Ping localhost [127.0.0.1] (使用 32 位元組的資料):
回覆自 127.0.0.1: 位元組=32 time<1ms TTL=128
回覆自 127.0.0.1: 位元組=32 time<1ms TTL=128
回覆自 127.0.0.1: 位元組=32 time<1ms TTL=128
回覆自 127.0.0.1: 位元組=32 time<1ms TTL=128
127.0.0.1 的 Ping 統計資料:
封包: 已傳送 = 4,已收到 = 4, 已遺失 = 0 (0% 遺失),
大約的來回時間 (毫秒):
最小值 = 0ms,最大值 = 0ms,平均 = 0ms
沒有留言:
張貼留言