使用PyCharm進行python開發的簡介

來源:互聯網
上載者:User

標籤:python   ide   pycharm   

使用PyCharm進行python開發的簡介


這個是很常見的一個問題,我想學習python,用什麼編輯器呢?

eclipse+pydev?

IDLE?

vim?

每個人有自己的習慣,可能是自己琢磨的,也可能是前輩指導的,這裡只分享自己孤陋寡聞琢磨的。


簡單的小指令碼,,直接vim或者IDLE上即可。

那請問怎麼調試複雜一點兒的呢?還是用IDE吧,這裡我沒選eclipse,因為我討厭它,個人情緒問題。

好吧,其實我是被PyCharm吸引住了,用的是社區版本。

參考:http://www.jetbrains.com/pycharm/

傳送門:http://download.jetbrains.com/python/pycharm-professional-4.5.2.exe


咱們不花時間對比哪個IDE好,習慣是最好的方式。


1. 因為我習慣用python3,預設是utf-8的格式,所以做了調整:

File->Settings->File Encodings

設定Project Encoding: UTF-8



2. 試著用用吧,來調試一個小小的c/s指令碼

c.py

#!/usr/local/bin/python3# from multiprocessing.connection import Clientif __name__ == "__main__":    s_ip = ‘127.0.0.1‘    s_port = 15000    conn = Client((s_ip, s_port), authkey=b‘123456‘)    print(‘Connect to: \n {0}:{1}‘.format(s_ip, s_port))    while True:        try:            x = conn.recv()            print("GET: {0}".format(x))        except EOFError:            print(‘Why did you do an EOF on me?‘)        except KeyboardInterrupt:            print(‘You cancelled the operation.‘)        except WindowsError:            print(‘遠程主機強迫關閉了一個現有的串連。‘)            break        except Exception as err:            print("[ERROR] {0}".format(err))    conn.close()



s.py

#!/usr/local/bin/python3# from multiprocessing.connection import Listenerimport times_ip = ‘0.0.0.0‘s_port = 15000srv = Listener((s_ip, s_port), authkey=b‘123456‘)print(‘listen on: \n {0}:{1}‘.format(s_ip, s_port))def notify(x=10000, y=10000):    time.sleep(2)    for i in range(1,x):        for j in range (1,y):            try:                x = ‘SEND: i={0},j={1}‘.format(i,j)                print(x)                conn.send(x)            except EOFError:                print(‘[error] EOFError‘)                breakif __name__ == "__main__":    while True:        conn = srv.accept()        try:            notify()        except OSError:            print("[ERROR] IP或者連接埠已經被佔用?")    conn.close()


先在s.py中下個斷點:

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/6F/3A/wKiom1WU8zuTHibVAADrva2LYnI437.jpg" style="float:none;" title="1.png" alt="wKiom1WU8zuTHibVAADrva2LYnI437.jpg" />


右鍵菜單選擇debug:

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/6F/37/wKioL1WU9QLzKVpiAAJ-7N60rUw850.jpg" style="float:none;" title="2.png" alt="wKioL1WU9QLzKVpiAAJ-7N60rUw850.jpg" />

這是啟動後在左下角的debugger和console視窗,注意左下角有個灰色的tools方框可以開啟/關閉

3:Find 4:Run 5:Debug 6:TODO這類視窗。

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/6F/3A/wKiom1WU9GLRA1quAAGDZCb6qGI282.jpg" title="3.png" style="float:none;" alt="wKiom1WU9GLRA1quAAGDZCb6qGI282.jpg" />


好,現在以debug方式啟動了s.py,接著我們直接啟動c.py,同樣是用滑鼠右鍵的菜單:


650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/6F/37/wKioL1WU9inzwFeQAAHUQIZmt0g226.jpg" style="float:none;" title="4.png" alt="wKioL1WU9inzwFeQAAHUQIZmt0g226.jpg" />


指令碼跑起來了,嗶嗶。。。++。。。到斷點處停了下來,看圖說話,很清楚的:


650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/6F/37/wKioL1WU9irhhHuYAAPgQwhFEnQ496.jpg" style="float:none;" title="6.png" alt="wKioL1WU9irhhHuYAAPgQwhFEnQ496.jpg" />



我手累了,按了一會兒F8,我們再看變成了啥樣:

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/6F/37/wKioL1WU94SQU4D8AALAm6p3TRU134.jpg" style="float:none;" title="7.png" alt="wKioL1WU94SQU4D8AALAm6p3TRU134.jpg" />

見笑了,常用的該有的都有。

Step Over (F8)

Step Into (F7)

Step Into My Code (Alt+Shift+F7)

Step Out (Shift+F8)

Run to Cursor (Alt+F9)


對了,c.py的輸出呢?好吧,我們切到“4:Run”這個視窗來瞧瞧:

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/6F/3A/wKiom1WU9b7wnUKKAAFzoY6169c990.jpg" style="float:none;" title="8.png" alt="wKiom1WU9b7wnUKKAAFzoY6169c990.jpg" />



簡介到此結束,希望身為初學者的你,越來越棒。












使用PyCharm進行python開發的簡介

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.