Time of Update: 2018-07-29
題目連結 https://leetcode.com/problems/binary-tree-level-order-traversal/ 題目原文 Given a binary tree, return the level order traversal of its nodes’ values. (ie, from left to right, level by level). For example: Given binary tree {3,9,20,#,#,
Time of Update: 2018-07-29
python發送郵件,smtp伺服器用新浪 import smtplibFROMADDR = "anit_nait@sina.com"LOGIN = FROMADDRPASSWORD = "xxxxxx"TOADDRS = ["xxx@sina.com","xxx@hpe.com"]SUBJECT = "hello world from smtp.sina.com
Time of Update: 2018-07-29
Strings can be indexed (subscripted), with the first character having index 0. There is no separate character type; a character is simply a string of size one: >>> word = 'Python'>>> word[0] # character in position 0
Time of Update: 2018-07-29
初學python語言,竟然很久才發現python沒有switch-case語句,查看官方文檔說是可以用if-elseif-elseif。。。。代替。 講真,這都不是問題。不就是一個條件判斷嗎。用if-elseif-.......肯定沒問題,同時也用其他的解決方案,比較簡單的就是利用 字典來實現同樣的功能。寫一個字典,每個key對應的值是一個方法。如switch =
Time of Update: 2018-07-29
在python中是通過使用 bytes 和 str 類型之間的轉換解決多編碼之間的問題的 假設有字串: str1 = "諸葛亮" 要將 str1 轉換為 gbk 編碼的,怎麼辦呢。 在python中,可以認為一切皆對象,這裡的 "諸葛亮" 就是一個str類型的對象 那麼只需要 (1) str1.encode("gbk") 這樣就可以得到 gbk 編碼的 "諸葛亮"
Time of Update: 2018-07-29
因為需要通過http協議向伺服器post一些資料,於是用python寫了一個相關小程式,沒想到遇到了一些問題,於是就在這裡將這個問題記錄一下。 先上源碼: import urllib.requestimport jsondata = { 'ssid':'123', 'passwd':'456'}values = urllib.parse.urlencode(data).encode(encoding='UTF8')//注釋1
Time of Update: 2018-07-29
1、 scrapy運行項目error:unknown command crawl 在32位WINDOW7下運行項目,拋出unknown command crawl,發現是環境變數和執行路徑問題 首先在PATH中加入D:\Python27\Scripts 環境變數,這樣才能保證在項目目錄下執行scrapy命令能找到 執行時,把路徑切換到項目目錄下 2、1ImportError: No module named win32api 原因是缺少32位的API包,
Time of Update: 2018-07-29
路漫漫其修遠兮 Python中對檔案檔案夾的操作 在windows可能出現問題。當使用os模組中的mknod方法時,Traceback報以下錯誤: AttributeError: 'module' object has no attribute 'mknod' 原因是因為windows檔案系統與linux檔案系統不同,沒有node的概念,所以提示錯誤。 當在使用追加開啟檔案的時候,python會自動建立檔案。 檔案操作
Time of Update: 2018-07-29
python 內部內建大整數運算能力,整數運算不會溢出,只要記憶體足夠,就oK 下面的例子示範了兩個32位整數加法的情況(通過位元運算實現),為了類比溢出的效果,必須人工的進行位元運算,~運算子除了求反,還是二進位的補運算子,運算過後的位元字按照補碼解釋,例如 ~(0011 1100) = (1100 0011) = -61 def getSum(a, b): ""&
Time of Update: 2018-07-29
迭代,即重複做一些事很多次,python中通過for迴圈可以對序列、字典以及其他的對象進行迭代。在其他對象進行迭代時,需要在其他對象中實現__iter__方法。 __iter__方法返回一個迭代器,所謂的迭代器就是具有next方法的對象。在調用next方法時,迭代器會返回它的下一個值。如果next方法被調用,但迭代器沒有值可以返回,就會引發一個StopIteration異常。 用迭代器實現一個斐波那契數列 class Fab(object): def
Time of Update: 2018-07-29
switch語句相信大家都很熟悉,而且swith語句表達的分支結構比if...elif...else語句表達更清晰,代碼的可讀性更高,但是在Python中,卻沒有提供這一個關鍵字。那我們該如何通過其他方式來實現這類似的結構呢。 雖然沒有switch語句,但是我們可以通過Python中的dict即字典來實作類別似switch結構的方法 實現代碼如下: def operator(o,x,y):result={ '+' : x+y, '-' : x-
Time of Update: 2018-07-29
Python Access Secured Hadoop Cluster Through Thrift API Apache Thrift Python Kerberos Support Typical way to connect kerberos secured thrift server Example - Hive Example - HBase Apache Thrift Python Kerberos Support Both
Time of Update: 2018-07-29
face_recognition簡介: 使用世界上最簡單的Face Service庫從Python或命令列識別和操作人臉。數字圖書館的使用最先進的Face Service與深度學習建。該模型在野生基準的標記面上具有99.38%的準確度。這也提供了一個簡單的face_recognition命令列工具,可以讓你從命令列影像檔夾做Face Service。 face_recognition安裝: pip3 install face_recognition
Time of Update: 2018-07-29
描述: python split() 通過指定分隔字元對字串進行切片,如果參數num 有指定值,則僅分隔 num 個子字串 方法解釋: def split(self, sep=None, maxsplit=-1): # real signature unknown; restored from __doc__ """ S.split(sep=None, maxsplit=-1) -> list of strings
Time of Update: 2018-07-29
稍微總結一下,否則總是忘。 x = 'abc'def fetcher(obj, index): return obj[index]fetcher(x, 4) 輸出: File "test.py", line 6, in <module> fetcher(x, 4) File "test.py", line 4, in fetcher return obj[index]IndexError:
Time of Update: 2018-07-29
# -*- coding: utf-8 -*-"""Created on Sat Oct 22 21:01:23 2016@author: hhxsym"""import requestsimport jsonimport osimport pymongoimport timefrom bs4 import BeautifulSoupfrom multiprocessing import Pool
Time of Update: 2018-07-29
lambad運算式 lambda運算式可以建立一個可以調用的函數,但它返回一個函數,而不是將函數賦值給一個變數名,因此,lambda函數也被稱為“匿名函數”。 lambda函數的形式為: lambda arg1, arg2, …argN: expression using args 即:lambda關鍵字,參數,冒號,運算式 例如: ”’ f = lambda x, y, z: x+y+z f(2, 3,4) ”’ 兩個特點: 1.
Time of Update: 2018-07-29
深度學習訓練需要標記映像位置和類別,之前用的時候是叫做BBox-Label-Tool-master,遇到大映像就顯示不完整了,沒有自適應縮放, 這是改進後的Python指令碼。 目錄結構:圖片目錄名images, 標籤目錄名labels,映像目錄下各類別目錄名要以001,002,003,...的格式命名。 這是運行labelTool ( python main.py)時的截屏,映像框記錄的是比例值,
Time of Update: 2018-07-29
密度聚類(Density-based Clustering)假設聚類結構能夠通過樣本分布的緊密程度來確定。DBSCAN是常用的密度聚類演算法,它通過一組鄰域參數( ϵ \epsilon, MinPts MinPts)來描述樣本分布的緊密程度。給定資料集 D D={ x⃗ 1,x⃗ 2,x⃗ 3,...,x⃗ N \vec{x}_1
Time of Update: 2018-07-29
source: http://blog.163.com/lxq_102172/blog/static/133398015201231012213428/ # -*- coding: utf-8 -*-from __future__ import divisionimport wximport mathlabels='1 1 1 1 1 MC MR MS M+ M- <- CE C +- Sqr 7 8 9 / % 4 5 6 * 1/x 1 2 3 - 0 0 . . + 2'