Upgrade to Pro — share decks privately, control downloads, hide ads and more …

麻瓜也能上手的爬說語:開源社 Python 實用入門 / Parseltongue for M...

Poren Chiang
December 02, 2016

麻瓜也能上手的爬說語:開源社 Python 實用入門 / Parseltongue for Muggles: Pratical Introduction of Python

“Parseltongue for Muggles: Pratical Introduction of Python”
2016/12/2 Talk @ NTU Open Source Community, Taipei, Taiwan.

Poren Chiang

December 02, 2016
Tweet

More Decks by Poren Chiang

Other Decks in Programming

Transcript

  1. ߢ㾏
 ౯ฎভຣ犨կ Photo by Hiram Huang on Flickr, CC BY-SA

    2.0 岄傀य़䋊ဩ஌䋊羬ࢥଙ羷 岄य़樄რᐒ咳蚏Ո膑玊ێ SITCON 2017 者ݟ ݢ犥ࣁ [email protected] ౲ฎ poren.tw 膏౯肥媒牐
  2. 樄তԏ獮 • 嘦ਧ૪妿蕕অԧ Python 3.4+
 → 螭䷱伛猋অጱՈ牧纸盅䨝൉׀ݱଘݣጱਞ蕕ොୗ • 蝡ฎ樄硯ୗጱ抓纷牧֦ݢ犥ࣁ樄რᐒ Slack物

    • ܨ碻൉㺔ҁ哴ᓕ tag @RSChiang҂ • ᥝ穩᯿蕦Ӟ螁牏ے盠౲仂眸蝧ଶ • ૶磭౯氃क़䌘礓犚蟂獤狶愆獅
  3. For Mac • 羬翄獉ୌጱ Python 粚๜穉斃膑 • brew install pyenv

    • echo 'eval "$(pyenv init -)"' >> ~/.bash_profile • pyenv install 3.5.2 • 蝚螂 pyenv shell 獥矦 Python 粚๜
  4. For Linux • ֵአ python3 瞲犤珸㵕 Python 3
 Ubuntu 14.04+

    ૪妿獉ୌ Python ԧ • 蝚螂 python3 --version 䲒礚褰ᴫጱ粚๜ • sudo apt-get upgrade python3
 ݢ犥Ӥ翕ತತ֦ጱ咳ᤈ粚螕አጱॺկݷ圸
  5. ತک Python OS X: Spotlight → 奰ᒒ秚 Linux: Ctrl +

    Alt + Tҁ憙咳ᤈ粚ᘒਧ҂ Windows: ℂ纷ୗڜ蔭疨ತ IDLE
  6. import re re.match(r"\d+:\d+", "12:00") ྋ憒蔭螈ୗ (regular expression) ݢ犥አ㬵穉䌘牏玲դ෈ਁ 硯蝱౯㮉ᥝ䲒涢ጱਁԀ獉਻牧
 狶襎扖蒈嘨涢挨ጱ碻狡盄অአ߶牐

    矟蝄ᥝ穉䌘ጱฎ̿碍ਁ (\d) Ӟ㮆犥Ӥ (+) 牏 ٚӞ㮆ٛ蒈牏ٚ碍ਁӞ㮆犥Ӥ̀蝡䰬ጱ໒ୗ ”raw string” 虏 Python ஺ኼ愊ᶎጱ粬ྛᒧ蒈
  7. Ӟ犚ྋ憒蔭螈ୗ • 薫ೡ皭 [] 䨝穉䌘̿ೡ皭愊犨֜Ӟ㮆ਁ̀ • ူ窚ೡ皭 {n} դ蔭̿者و磪 n

    㮆̀ • 磪犚ଉአጱ䨝磪婘䌃牧ֺই藯 [0-9] ݢ犥䌃౮ \d • 膐蛪獤挨ਁ蒈傶ֺ牧[A-Z][12][0-9]{8}
  8. Cheat sheet [sudo] pip install Pillow from PIL import Image

    photo = Image.open('Desktop/AARRR/ਡਡ.jpg') ਡਡ = photo.crop((0, 0, ୽猟.width * 2 / 3, 
 ̴̴ photo.height * 2 / 3)).resize((1024, 768)) 箜ਡਡ = ਡਡ.convert('L') 箜ਡਡ.save('Desktop/AARRR/БББ.jpg')
  9. #include <iostream> using namespace std; int main(int argc, char* argv)

    { cout << “Hi NTUOSC!”; return 0; } print(“Hi NTUOSC!”) $ 1ZUIPO ٌ䋿Ӟᤈ疰胼蔭螈竃༩ 纷ୗᥝ狶Ջ讕ԧ牐 蚤 Python ጱ print() ఺௏ฎፘݶጱ牐
  10. string a = “ࠡ”;
 string b = “”; for (int

    i = 1; i <= 5; i++) { b += a; } cout << b; print(“ࠡ” * 5) $ 1ZUIPO ෈ਁᥝ虋Բ狝牫 ፗ矑犔犥 5 疰অԧ牧 犋஠᪒ࢧ݄䢏槑Ꭺ牐
  11. for (int i = 1; i <= 5; i++) {

    cout << “#” << i << “\n”; } for i in range(5): print(“#” + str(i)) $ 1ZUIPO 懿஑ᥝአ绚໒婘矎߶牐