Time of Update: 2018-07-24
說明:從檔案中讀取資料,繪製直線圖 #coding:utf-8import matplotlib.pyplot as pltimport matplotlib as mplimport numpy as npfrom matplotlib.font_manager import FontPropertiesimport matplotlib as mplmpl.rcParams['font.family'] =
Time of Update: 2018-07-24
1 help函數:查看模組、函數、變數的詳細說明: 查看模組 >>> help("modules")Please wait a moment while I gather a list of all available modules...BaseHTTPServer array htmllib setsBastion ast
Time of Update: 2018-07-24
【一】range()函數 在python中可以使用range()函數來產生一系列數字 for w in range(1,11):print(w) 輸出: 1 2 3 4 5 6 7 8 9 10 #注意:這裡的到10就結束了,不包括11 【二】list()函數 如果將range()作為參數傳遞給list()函數,那麼就會將數字以列表的形式輸出
Time of Update: 2018-07-24
Python+opencv+tkinter整合demo 由於需要使用opencv進行小demo開發但是由於opencv所帶的GUI功能目前還是很簡單的,所以使用opencvv+tkinter組合實現。 先上結果圖。 在GUI中點擊點贊按鈕在控制台就可以顯示”有人給你點贊“。 直接上代碼: from tkinter import *import cv2from PIL import Image,ImageTkdef take_snapshot():
Time of Update: 2018-07-24
在mac OSX 上,使用python matplotlib庫時,出現問題: >>> import numpy as np>>> import matplotlib.pyplot as pltTraceback (most recent call last): File "<stdin>", line 1, in <module> File "/Users/david/anaconda2/envs/
Time of Update: 2018-07-24
問題描述 剛宿舍的問了個問題,簡單的說就是編程遇到了如下的這種情況: class Node(object): def __init__(self ,childrenList=[], name = '.' ): self.name = name self.childrenList = childrenLista = Node(name = 'wj')b =
Time of Update: 2018-07-24
從最初的“Hello World”,走到物件導向。該回過頭來看看,教程中是否遺漏了什麼。 我們之前提到一句話,"Everything is Object". 那麼我們就深入體驗一下這句話。 Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:43:06) [MSC v.1600 32 bit (Intel)] on win32Type "copyright",
Time of Update: 2018-07-24
https://pypi.python.org/simple/找你需要的安裝包。1.安裝twistedhttps://pypi.python.org/simple/twisted裡面有很多版本,最後下載exe格式的可以自動安裝,我下載的版本是Twisted-15.4.0.win-amd64-py2.7.exe安裝完成後,你會在C:\Python27\Lib\site-packages目錄下看到twisted檔案夾2.安裝zope.interfacehttps://pypi.python.org/
Time of Update: 2018-07-24
根據代碼中啟動並執行結果來看,主要由以下幾種: 1. sum():將array中每個元素相加的結果 2. axis對應的是維度相加。 比如: 1、axis=0時,對飲搞得是第一個維度元素的相加, [[0,1,2,3],[4,5,6,7]]和[[1,2,3,4],[5,6,7,8]]對應元素相加[[0+4,1+2,2+3,3+4],[4+5,5+6,7+7,7+8]]=[[1,3,5,7],[9,11,14,16]] 2、axis=1時,
Time of Update: 2018-07-24
Profile: PyCharm提供了效能分析工具Run-》Profile,如下圖所示。利用Profile工具可以對代碼進行效能分析,找出瓶頸所在。 測試: 下面以一段測試代碼來說明如何使用pycharm的Profile功能。 測試代碼見下文,檔案命名為Test.py, 一共有5個函數,每個函數都調用了time.sleep進行延時,其中fun5函數調用了fun4函數: import timedef fun1(a, b): print('fun1')
Time of Update: 2018-07-24
windows下: winpcap下載 http://www.pc6.com/softview/SoftView_17547.html#download pypcap-1.1.3-py2.7-win32.egg http://download.csdn.net/download/lone_wolf_pqj/8855665 使用方法: 安裝winpcap後,執行:easy_install
Time of Update: 2018-07-24
題目內容:找第n個默尼森數。P是素數且M也是素數,並且滿足等式M=2**P-1,則稱M為默尼森數。例如,P=5,M=2**P-1=31,5和31都是素數,因此31是默尼森數。 輸入格式:用input()函數輸入,注意如果Python 3中此函數的傳回型別。 輸出格式:int類型 輸入範例:4 輸出範例:127 時間限制:500ms記憶體限制:32000kb 思路:素數打表 + 枚舉 AC代碼: # -*-
Time of Update: 2018-07-24
數字轉成字串,使用格式化字串: 如 tt=322 tem='%d' %tt tem即為tt轉換成的字串 常用的格式化字串: %d 整數 %f%F 浮點數 %e%E 科學計數 %g%G e
Time of Update: 2018-07-24
Python的圖形庫太全了,導致我現在都有點要轉到python麾下的衝動了。 Graphical Representations of Data Over the years many different plotting modules and packages have been developed for Python. For most of that time there was no clear favorite package, but recently
Time of Update: 2018-07-24
查看python搜尋包的路徑的方法: python搜尋包的路徑儲存在sys.path下 查看方法: import syssys.path 臨時添加python搜尋包路徑的方法: 方法1:(先進入python) import syssys.path.append(‘路徑’) (這種方式僅對當前python有效) 方法2: export PYTHONPATH=路徑
Time of Update: 2018-07-24
Tkinter Classes Widget classes Tkinter supports 15 core widgets: Tkinter 支援15個核心組件: Button A simple button, used to execute a command or other operation.
Time of Update: 2018-07-24
Hello, Again When you write larger programs, it is usually a good idea to wrap your code up in one or more classes. The following example is adapted from the “hello world”program in Matt Conway’s A Tkinter
Time of Update: 2018-07-24
1)dir函數可以查看對象屬性,以str為例,輸入dir(str),就可以看到str的屬性。如下圖 2)如何查看對象某個屬性的協助文檔。如何查看str的capitalize屬性,可以用__doc__,使用方法為print(srt.capitalize__doc__),如下圖 3)查看對象屬性還可以用help函數,使用方法為help(str.capitalize),如下圖 4、查看某個對象的詳細文檔用help, 如查看str類型的詳細文檔可以用help(str)
Time of Update: 2018-07-24
但我們安裝了anaconda以後,我們使用ipython時我們所用的模組的路徑都是anaconda的路徑,並且我們用pip安裝的模組都不能再ipython中使用。 Anaconda利用工具/命令conda來進行package和environment的管理,並且已經包含了Python和相關的配套工具。 conda 就好想pip一樣,我們安裝包的時候也使用 conda install numpy 這樣的命令。 # 查看已經安裝的packagesconda list#
Time of Update: 2018-07-24
Python擷取當前系統使用者名稱 轉自http://www.codecho.com/get-current-username-in-python 某些時候我們需要獲得系統當前的使用者名稱,那麼在Pyton中有沒有一個可跨平台的方式或者類庫支援這一操作呢。 最常用的就是getpass模組: 1 2