Introduction to Python development using Pycharm

Source: Internet
Author: User

Introduction to Python development using Pycharm


This is a very common problem, I want to learn python, with what editor?

Eclipse+pydev?

IDLE?

Vim?

Everyone has their own habits, may be self-pondering, may also be the guidance of predecessors, here only to share their own ignorant pondering.


Simple small script, direct vim or idle on it.

Then how to debug a little bit more complicated? Or with the IDE, I didn't choose eclipse here because I hated it, personal emotional problems.

Well, actually I was attracted by the Pycharm, with the community version.

Reference: http://www.jetbrains.com/pycharm/

Portal: Http://download.jetbrains.com/python/pycharm-professional-4.5.2.exe


We don't take the time to compare which IDE is good, the habit is the best way.


1. Because I am accustomed to using Python3, the default is the Utf-8 format, so I made the adjustment:

File->settings->file Encodings

Set up Project Encoding:utf-8



2. Try to use it to debug a small C/s script

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 (' Remote host forced the shutdown of an existing connection. ')             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 or Port is already occupied? ")     conn.close ()


The next breakpoint in s.py first:

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


Select Debug on the right-click menu:

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 "/>

This is the debugger and console window in the lower left corner after startup, note that a gray tools box in the lower left corner can be turned on/off

3:find 4:run 5:debug 6:todo This type of window.

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


OK, now start the s.py in debug mode, and then we start the c.py directly, the same menu with the right mouse button:


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


The script runs and beeps ... + + ... Stop at the breakpoint and look at the picture and say it clearly:


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



My hands are tired, press for a while F8, we look at what became like:

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

Laughed at, there are all the usual ones.

Step Over (F8)

Step into (F7)

Step into My Code (ALT+SHIFT+F7)

Step Out (SHIFT+F8)

Run to Cursor (ALT+F9)


By the c.py, what about the output? Well, let's cut to the "4:run" window to see:

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



Introduction to this end, I hope that as a beginner you, more and more good.












Introduction to Python development using Pycharm

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.