Time of Update: 2017-01-18
在windows系統下寫的python指令碼,在linux下賦予許可權chmod +x xxx.py 以後,執行./xxx.py運行提示:bash: /usr/bin/autocrorder: /usr/bin/python^M: bad interpreter: No such file or directory分析:這是不同系統編碼格式引起的:在windows系統中編輯的.sh
Time of Update: 2017-01-18
1.在shell指令碼執行python指令碼時,需要通過python指令碼的傳回值來判斷後面程式要執行的命令例:有兩個py程式 hello.py複製代碼 代碼如下:def main(): print "Hello"if __name__=='__main__': main()world.pydef main(): print "Hello"if
Time of Update: 2017-01-18
檔案操作樣本複製代碼 代碼如下:#輸入檔案f = open(r'D:\Python27\pro\123.bak') #輸出檔案fw = open(r'D:\Python27\pro\123e.bak','w')#按行讀出所有文本lines = f.readlines()num = -1for line in lines: str = '@SES/%i/' %num line = line.replace('@SES/1/',
Time of Update: 2017-01-18
核心代碼:複製代碼 代碼如下:#!/usr/bin/python#Filename:friendbook.pyimport cPickle as pimport sysimport timeimport osab={'Xdex':'cneds@fnedf.com', 'Laexly':'fev@fe.com',
Time of Update: 2017-01-18
複製代碼 代碼如下:#設a為字串import timea = "2011-09-28 10:00:00"#中間過程,一般都需要將字串轉化為時間數組time.strptime(a,'%Y-%m-%d %H:%M:%S')>>time.struct_time(tm_year=2011, tm_mon=9, tm_mday=27, tm_hour=10, tm_min=50, tm_sec=0, tm_wday=1, tm_yday=270, tm_isdst=-1)#將"2011-09-
Time of Update: 2017-01-18
一.IPython簡介IPython 是一個互動shell,比預設終端好用,支援自動縮排,並且內建了很多有用的功能和函數。可以在任何作業系統上使用。二.安裝方法1.pip 線上安裝pip install ipython pip install “ipython[notebook]”2.下載安裝可以到GitHub 下載安裝包,切換到目錄下然後運行下面的指令碼Python setup.py install三.簡單使用開啟Linux終端,在命令列中輸入root@Linux:/#
Time of Update: 2017-01-19
python發送icmp echo requesy請求複製代碼 代碼如下:import socketimport structdef checksum(source_string): sum = 0 countTo = (len(source_string)/2)*2 count = 0 while
Time of Update: 2017-01-19
複製代碼 代碼如下:#!/usr/bin/env/ python#coding=utf-8import mechanizeimport cookielib# Cookie Jarcj = cookielib.LWPCookieJar()# Browserbr = mechanize.Browser()br.set_cookiejar(cj)# Browser
Time of Update: 2017-01-19
複製代碼 代碼如下:import urllib.parse,os.path,time,sysfrom http.client import HTTPSConnectionfrom PyQt5.QtCore import *from PyQt5.QtGui import *from PyQt5.QtWidgets import *#pathospath=sys.path[0]if len(ospath)!=3:
Time of Update: 2017-01-19
複製代碼 代碼如下:import urllib.parse,os.path,time,sys,re,urllib.requestfrom http.client import HTTPSConnectionfrom PyQt5.QtCore import *from PyQt5.QtGui import *from PyQt5.QtWidgets import *from PyQt5.QtWebKitWidgets import *from PyQt5.QtNetwork import
Time of Update: 2017-01-19
代碼基於Python3.3.3,PyQt5.1.1複製代碼 代碼如下:# -*- coding: utf-8 -*-# Python 3.3.3# PyQt 5.1.1import sys,time,re,urllib.parse,urllib.request,http.cookiejar,jsonfrom PyQt5.QtCore import *from PyQt5.QtGui import *from PyQt5.QtWidgets import
Time of Update: 2017-01-19
環境Python 2.7.6,BS4,在powershell或命令列均可運行。請確保安裝了BS模組複製代碼 代碼如下:# -*- coding:utf8 -*-# 2013.12.36 19:41 wnlo-c209# 抓取dbmei.com的圖片。from bs4 import BeautifulSoupimport os, sys, urllib2# 建立檔案夾,昨天剛學會path = os.getcwd()
Time of Update: 2017-01-19
複製代碼 代碼如下:# 比較兩個字串,如果不同返回第一個不相同的位置# 如果相同返回0def cmpstr(str1, str2): col = 0 for c1, c2 in zip(str1, str2): if c1 == c2:
Time of Update: 2017-01-19
複製代碼 代碼如下:from creepy import Crawlerfrom BeautifulSoup import BeautifulSoupimport urllib2import jsonclass MyCrawler(Crawler): def process_document(self, doc): if doc.status ==
Time of Update: 2017-01-19
大家都知道,linux裡一切皆為檔案,在linux/unix的根目錄下,有個/proc目錄,這個/proc 是一種核心和核心模組用來向進程(process)發送資訊的機制(所以叫做“/proc”),這個偽檔案系統允許與核心內部資料結構互動,擷取有關進程的有用資訊,在運行中(on the fly)改變設定(通過改變核心參數)。與其他檔案系統不同,/proc 存在於記憶體而不是硬碟中。proc 檔案系統提供的資訊如下:•進程資訊:系統中的任何一個進程,在 proc
Time of Update: 2017-01-19
直接上代碼了複製代碼 代碼如下:import smtplibmsg = MIMEMultipart()#構造附件1att1 = MIMEText(open('/home/a2bgeek/develop/python/hello.py', 'rb').read(), 'base64', 'gb2312')att1["Content-Type"] = 'application/octet-stream'att1["Content-Disposition"] = 'attachment;
Time of Update: 2017-01-19
win7以上需要使用管理員權限操作。複製代碼 代碼如下:# -*- coding: utf-8 -*-import osimport globimport shutildef format_file_list(files): all_files_str = "" for i in range(len(files)): &
Time of Update: 2017-01-19
考慮下述Python程式碼片段。對檔案中的資料進行某些操作,然後將結果儲存迴文件中:複製代碼 代碼如下:with open(filename) as f: input = f.read()output = do_something(input)with open(filename, 'w') as f:
Time of Update: 2017-01-18
標籤:冒泡排序#!/usr/bin/env python# -*- coding:utf-8 -*-l = [1, 8, 3, 5, 6, 2, 4, 7, 9, 0]for end in range(len(l))[::-1]: flag = Fals
Time of Update: 2017-01-18
標籤:python vscode 無意看到老男孩的博文:合格linux營運人員必會的30道shell編程面試題及講解http://oldboy.blog.51cto.com/2561410/1632876嘗試著用剛開始學的python解答一些,權當練手了!如有錯誤,還請批評!# 企業面試題28、請用shell或Python編寫一個等腰三角形(oldboy2_triangle.sh),接收使用者輸入的數字。# 例如:#