<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          Github | 推薦一個Python腳本集合項目

          共 2157字,需瀏覽 5分鐘

           ·

          2020-12-04 17:39

          點擊上方"藍字"關(guān)注我們





          Python大數(shù)據(jù)分析


          記錄? ?分享? ?成長

          用python寫小腳本是一件好玩的事情,因為不是個大活兒,而且能解決眼邊前十分繁瑣的事情,這種輕松且便宜的代碼頗受人民群眾的歡迎~有點生活小妙招的意味

          大家較為熟知的腳本是用python來做爬蟲、搶票、簽到、自動回復(fù)機器人、批量處理文件等,這些比較常規(guī),還有些較復(fù)雜的,比如做物品識別、語義分析、圖像處理等,只要你有需求場景,總會想到辦法寫個腳本去處理它。

          github上有個python項目,里面提供了幾百個(可能上千)小腳本,涉及到算法、文件、文本、圖像、視頻、音樂、爬蟲、郵件、可視化、系統(tǒng)、下載等各種常用場景的處理腳本。

          項目地址:https://github.com/geekcomputers/Python

          這個項目不是什么牛逼的大程序,而是作者在日常工作和python學(xué)習(xí)過程中積累的腳本,一個腳本解決一個問題。獲得1萬9的贊,說明頗有群眾基礎(chǔ)。

          作者在介紹中所說,他并非專業(yè)程序員,而是為了解決問題、提高效率寫了這些代碼。我也是鼓勵初學(xué)者可以先按照這種模式來學(xué)習(xí)編程,從解決問題的角度來寫代碼,把python當(dāng)作一把錘子,不斷找釘子。

          分享其中幾個腳本:

          1、檢查主目錄中是否存在某文件夾,若不存在則創(chuàng)建文件

          #?Description???:?Checks?to?see?if?a?directory?exists?in?the?users?home?directory,?if?not?then?create?it

          import?os??#?Import?the?OS?module

          MESSAGE?=?'The?directory?already?exists.'
          TESTDIR?=?'testdir'
          try:
          ????home?=?os.path.expanduser("~")??#?Set?the?variable?home?by?expanding?the?user's?set?home?directory
          ????print(home)??#?Print?the?location

          ????if?not?os.path.exists(os.path.join(home,?TESTDIR)):??#?os.path.join()?for?making?a?full?path?safely
          ????????os.makedirs(os.path.join(home,?TESTDIR))??#?If?not?create?the?directory,?inside?their?home?directory
          ????else:
          ????????print(MESSAGE)
          except?Exception?as?e:
          ????print(e)

          2、打印圖片分辨率

          def?jpeg_res(filename):
          ???""""This?function?prints?the?resolution?of?the?jpeg?image?file?passed?into?it"""

          ???#?open?image?for?reading?in?binary?mode
          ???with?open(filename,'rb')?as?img_file:

          ???????#?height?of?image?(in?2?bytes)?is?at?164th?position
          ???????img_file.seek(163)

          ???????#?read?the?2?bytes
          ???????a?=?img_file.read(2)

          ???????#?calculate?height
          ???????height?=?(a[0]?<8)?+?a[1]

          ???????#?next?2?bytes?is?width
          ???????a?=?img_file.read(2)

          ???????#?calculate?width
          ???????width?=?(a[0]?<8)?+?a[1]

          ???print("The?resolution?of?the?image?is",width,"x",height)

          jpeg_res("img1.jpg")

          3、連接MySQL數(shù)據(jù)庫

          import?mysql.connector

          #?MySQl?databses?details

          mydb?=?mysql.connector.connect(
          ????host="0.0.0.0",
          ????user="root",
          ????passwd="",
          ????database="db_name"
          )
          mycursor?=?mydb.cursor()

          #?Execute?SQL?Query?=>>>>?mycursor.execute("SQL?Query")
          mycursor.execute("SELECT?column?FROM?table")

          myresult?=?mycursor.fetchall()

          for?x?in?myresult:
          ????print(x)

          4、PDF轉(zhuǎn)音頻

          import?pyttsx3
          import?pyPDF2
          book?=?open('book.pdf','rb')
          pdfreader?=?pyPDF2.PdfFileReader(book)
          pages?=?pdfreader.numPages
          print(pages)
          speaker?=?pyttsx3.init()
          page=?pdfreader.getpage(7)
          text?=?page.extractText()
          speaker.say(text)
          speaker.runAndWait()

          · 往期精選 ·
          1

          8個最高效的Python爬蟲框架,你用過幾個?

          2

          在模仿中精進數(shù)據(jù)可視化05:疫情期間市值增長top25公司

          3

          關(guān)于學(xué)習(xí)SQL的五個常見問題?




          Python大數(shù)據(jù)分析

          data creates?value

          掃碼關(guān)注我們

          瀏覽 51
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  国产精品内射视频免费 | 草逼网页 | 亚洲视频在线视频观看视频在线 | 黄片视频在线免费播放 | 国内屄视频 |