Python editing skills

Source: Internet
Author: User

For users and scholars who first came into contact with Python editing, it is very important to understand the concept of Python. let's first talk about what is Python editing, the so-called Python language: it is a widely used computer programming language.

As the name implies, PILPython Imaging Library is based on Python editing, So I downloaded Python2.6 from the day before yesterday and read the Python Concise Manual. At the end of this manual, the author suggests that beginners create a command line Address Book Program.

In this program, you can add, modify, delete, and search for your contacts, friends, family, and colleagues) and their information such as email addresses and/or phone numbers ). The details should be saved for future extraction.

 
 
  1. #! /Usr/bin/env python
  2. #-*-Coding: GBK -*-
  3.  
  4. Import urllib
  5.  
  6. From sgmllib import SGMLParser
  7.  
  8. Class URLLister (SGMLParser ):
  9. Def reset (self ):
  10. SGMLParser. reset (self)
  11. Self. urls= []
  12. Def start_a (self, attrs ):
  13. Href= [V for k, v in attrs ifK= 'Href ']
  14. If href:
  15. Self. urls. extend (href)
  16. Url= R'Http: // www.sinc.sunysb.edu/Clubs/buddhism/JinGangJingShuoShenMo /' 
  17. Sock=Urllib. Urlopen (url)
  18. HtmlSource=Sock. Read ()
  19. Sock. close ()
  20. # Print htmlSource
  21. F=File('Jingangjing.html ', 'w ')
  22. F. write (htmlSource)
  23. F. close ()
  24.  
  25. Mypath= R'Http: // www.sinc.sunysb.edu/Clubs/buddhism/JinGangJingShuoShenMo /' 
  26.  
  27. Parser=URLLister()
  28. Parser. feed (htmlSource)
  29.  
  30. For url in parser. urls:
  31. Myurl=Mypath+ Url
  32. Print "get:" + myurl
  33. Sock2=Urllib. Urlopen (myurl)
  34. Html2=Sock2. Read ()
  35. Sock2.close ()
  36. # Save to file
  37. Print "save as:" + url
  38. F2=File(Url, 'w ')
  39. F2.write (html2)
  40. F2.close ()

I guess some basic things here are not very easy to use, and there must be a simpler and more perfect method. In the hosts file.

In addition to the PIL package that comes with python, you can also use ImageMagic, so that what Gimp can do, what python can do, and write 10 lines of programs to process a large number of images. This is not a pleasure. Three years ago, I helped JJ write a program to process satellite images. It was about to cut the satellite cloud map into 32*32 squares, calculate the threshold values in sequence, and then make statistics.

I spent all the afternoon of a week, pure c, about 1500 lines of code. At that time, I was in love and had a low IQ. On windows, I installed a gcc and used editplus as the editor, although I had a sense of accomplishment in the end, it took a lot of effort to debug gdb + printf. If you use Python to edit the core part of the program, just a few lines will be done.

Some articles from the Internet need to be deleted from the blank lines; large numbers without rules, need to be summed; header file conversion in different formats, etc.; this is better handled with perl, I did the same three years ago. When I met python, I gave up perl completely.

Perl is very good. Basically, it has the same function. Writing code using python will take longer. The network community provides more perl function packages, but Larry Wall is a poet, the poet's temperament makes perl's syntax look messy in the eyes of our programmers.

  • Introduction to Python control statements
  • Brief description of Python applications
  • How to better run the Python Interpreter
  • Research on the Python Module
  • Correct explanation of Python object Conversion

Basically it's not needed for two weeks. If you want to work with perl, you have to look for a grammar book. In linux, it's okay to have a man. If you have an ActivePerl installed on windows, you have to open the html file Perl Core Documentation to find help.

While the Help System of the scripting language cannot compare the help of commercial development tools such as. Net and Java, python also has a chm file that can be indexed. Perl is used for real hacker. It is concise and clear, but it is the advantage of python. If you select perl as a professional network administrator, It's right. As for the small toys of common programmers, python is better.

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.