Use code to do the work in the shortest time

Source: Internet
Author: User
Tags vps

Chapter 0 What is programming

I tasted all day and thought, as a moment of learning also, I tasted go and hope, than ascend the Bo see also. Ascend and recruit, arm non-length also, and see Far, Shin, sound not add disease also, and smell. The false-Zhou Ji, the non-profit-footed, are thousands of miles away, and the false, the non-energy water, and the river.

A gentleman is born non-dissimilar also, good false in things also.

0.0 A word for "non-programmers"

Programming is only a means of focusing our attention on improving work and living efficiency.

0.1 Two roads

Avenues and shortcuts

There are two ways to learn anything, I call it a road and a shortcut.

The boulevard is like the decent martial arts in fiction, Voudanchen boxing, Shaolin King Kong, etc., getting started slowly. Five-year station pile, ten years of learning boxing, practiced to 20 years to apprenticeship down the mountain, after the completion of the lake has become a master.

Shortcut is like the novel of the evil faction martial arts, nine yin Bones claw, evil sword spectrum of the genus, get started very fast, three days to get started, five days to learn, into the lake can also sweep a piece, but eventually become a first-class master, in the fight with decent is easy to be slapped dead.

For programming, the road and shortcut early learning are the same, after all, people who want to practice the sword must first know how to take the sword. After the first glimpse of the path, the difference began to appear, the Avenue began to study polymorphism, encapsulation, anomaly, began to explore sub-category lists, generators and backtracking, can write their own understanding of the code in one line, and a shortcut, just need to know what a line of code to achieve what function, that only know how and do not care why, Copy and paste other people's code one line at a line, and make a slight modification to implement your own function.

For me, programming is the way to achieve my purpose, I have my own field, I do not want to be a superb programmer, so I choose to shortcut the evil faction. As the novel said, "Can kill the sword, is a good sword" or "no matter black cat white cat, catch mouse is a good cat."

0.2 Why should I learn to program?

As a non-programmer, many colleagues and friends ask me: Why do you want to learn programming?

Why Learn to program? Everyone gives the answer is different, some people think that programming is cool, so I want to learn, some people think that programming will be helpful to my work, so I want to learn programming, some people think that programming can let me find a good job, so I have to learn programming.

So what exactly is programming?

I used to say that programming is a screwdriver, a wrench, a hammer. It's just a tool, no one can be respected by a tool, people respect the things you do through this tool, we have heard the master of Chinese painting, carpenter master, but never had a master brush, saw master. So, think well:

What do you want to make?!

Write the tools I want, and use my ideas to solve the problem, that's what I learned about Python.

0.3 What does programming mean to me?

For me, programming means I have enough material on hand and I can use it to build what I want. To improve my quality of life and work efficiency by building things.

0.4 How do I use programming

Work, I will often deal with a large amount of data, Excel, in my colleague's burned-out line of the copy and paste, I will put them into a CSV file, import python processing finished in the output as a CSV file, Excel opened and then rearrange the version. Other colleagues of the day's work, I only need 20 minutes to write the program, 10 minutes to debug, and then spend a half a minute to run the good.

In life, according to the knowledge of reptiles. Crawl rental information, analysis and comparison of regional prices, determine the best place to rent; timed to grab the high scores on the Watercress film, collected automatically sent to my daughter-in-law, write an automatic ping program, put on the VPS, detect the network through, the network broke automatic e-mail to me.

Chapter 1 I study python1.1 want to

Work with purpose, what I want to do, what I want to get.

For our non-programmers, more often, we don't need to know how the bottom of a program works, I just need to know what code it can do to achieve what function, the specific principle I will not go into the drill. It floats on the surface, but it is the most convenient way for people to improve their efficiency by writing programs.

So, when I get started with Python, I'm going to think about what I'm going to do, what I need to do to achieve this, and then search, know what libraries are needed to reach these features, and continue searching for examples of how these libraries are used.

1.2 See

Study other people's similar code and learn the solution to the problem.

After finding someone else's code, copy, run, test the code by running the results, filter the Part I need, store in Evernote, annotate.

To view its superficial understanding. 1.3 Dry

To deal with, in addition to encounter completely do not understand, the code needs to change the book to check the principle, other situations as long as the program can run successfully, even if it is done.

1.4 Change

With the continuous growth, the ability to constantly improve, I will slowly understand the previous written or pasted over some of the meaning of the code, this time back to look at the code, the miscellaneous part of the changes to streamline, re-think, re-run, to further consolidate their knowledge.

Chapter 2 Examples

Only has the basic knowledge of magic Tutorial, how to do a batch ping tool without touching the network programming.

2.0 Why write This example

Make it easy for you to do what you can, and someone who has the ability to do what he doesn't do.
2.1 Situation

Early in the morning just to work, the leader: "Listen to the rain you come to me!" Today's intranet how this card! Give me statistics on how many people are using! Find out if anyone's unassigned ip!.

"I:" Leadership, our intranet computer is not allowed to install the software back under the net, you have not bought network management equipment and software, to take care of very slow ... "

Leader: "I don't care!" I don't care! Let me know within an hour! ”

2.2 Want to

Met so proud of the leadership, I also very helpless, introduce the situation: Our LAN address for 192.168.159.0, 192.168.160.0, 192.168.161.0, 192.168.162.0, are 22-bit mask (do not ask me why it is such a wonderful address section, I also want to know the superior network management is not the head of the door clip).

This task can be manually ping, but I need to ping 1024 address (VLSM), regardless of the time problem, I ping also absolutely tired of vomiting blood. So, the function I need to implement is: Batch ping My network segment to see which hosts are online.

2.3 See

Google search for "python ping" easily found two examples:

Http://blog.chinaunix.net/uid-23855119-id-3895547.html's A


and http://blog.topspeedsnail.com/archives/963 's B.


Obviously, B is more concise, but clearly beyond what we can understand in the Magic tutorial, so I choose a.

Copy directly to Pycharm.


These lines of error is obviously prompted to have the library is not imported, Google knows that is the library itself. Add 3 Import after found error, so only step by step disassembly

(1) Finding key statements

The key statement of the function that we are going to implement is obviously the line that performs the ping command because it is known to have a ping, so it is easy to navigate to:


Copy to a new file


(2) Up-down comparison guessing

Variable IP refers to the IP address that you want to ping, Ip_num is the number of times to ping. Modified to:


Operation Result:


Success! (Please ignore that pile of question marks ...) This is the IDE's problem, there is no problem in cmd, see)


So here we have our core statement--ping command

2.4 Dry

Start building the program body, define a function and invoke:


Running results (no pycharm in Intranet computer, running under CMD):


Success!

Modify the network segment to a local area network segment, change the number of packets after-N to 1 (there is no problem with ARP), and the For loop repeats 4 times:


Then go to brew a cup of tea, run the program, while drinking tea on the books on the painting "positive" word on the good.


The code is hard to read and inefficient, but it takes the place of my repetitive work, without the 11 lines of code, and I'm going to play the IP address ping in one morning, and now I can finish it in one hours. (The program speed of about 3 seconds an address, the presence of the address will be faster)

2.5 change

Next time I am free, I can add judgment to this program, output which hosts are online, and use multithreading to speed up the operation, and finally make a GUI to facilitate my colleagues to use. But that's what happened later.

I don't know how the Os.system is going to work, but I've been right about it, and I guess the right thing to do is to change it and achieve the goal. The total time is less than 10 minutes. When I have free time can slowly study the use of the OS this library, and now, I use the shortest time to do something, this is called to improve efficiency.

Chapter 3 Comprehension of programming 3.1 how to use programming to add points to your work

3.1.1 Save time

1. Find out the most time-to-work work (of course, the computer can solve)

2. Consider the common part of these tasks, whether these generic parts can be completed using the program.

3. Write the program

3.1.2

A few days ago I had the privilege of sitting in a car with two bureau leaders (that is, the mayor's level) and asked them about their young people's development and growth, and one of the leaders told me a word: "What is opportunity?" Opportunity is to do the best thing in front of a certain leader. ”

So think about it, if you use programming to make it the best thing you can do in your small environment.

Understand people already understand, do not know people can think slowly, the people who scoff, oh da.

3.2 How to use programming to add points to your life

3.2.1 Single people.

Learn to crawl your sister in bulk do not use this skill to climb a large number of sister photos! Do not use this skill to climb a large number of sister photos! Do not use this skill to climb a large number of sister photos!

Computer play good don't always think by give sister repair computer can find object, there is an old saying good "computer repair good, spare tire when to age." ”

To your unit single artist sister batch processing picture name, to your unit single Accounting sister batch processing Excel form, to your unit single personnel sister batch distribution salary table. To the Chase star automatically push her idol information, to the flower crazy climb point handsome photos. In case just said those people have thought the programming interesting wants to learn, the initiative teaches her AH! Carefree matter, you have to think about your looks.

Learn one-month crawler, you learned the crawler, database, data visualization, Web site, the four kind of add up, enough to let you become your company beauty small white people in the eyes of the same as the presence of God! At that time, also climbed his sister's beautiful pictures ah?!

3.2.1 have objects.

The daughter-in-law is your party, the demand of party A is imperial decree, party A wants you to realize, party a unexpectedly you want to realize for her.

3.2.2 Interests and Hobbies

Crawler is a large number of mobile phone data method, you can try to crawl your interests and hobbies related to the site's information, by the number of clicks or responses to order, priority to read high-quality parts.

3.2.3 The final thought

What things in life can be programmed to become better?

3.3 To help you write better code

In addition to the world's smallest eyewear maker Google and the world's largest gay dating site, the two sites that everyone knows, what else can help you write better code.

3.3.1 English

Often in the group to see someone talk about VPN, help FQ with what good, I want to ask, you go out and how can? Do you understand the voluminous English material? With a bunch of Chinese friends on Facebook and Twitter, how are you getting back to everyone and Weibo?

Therefore, must have the good English reading ability, so you can read the English document, searches the question when does not encounter the English website to skip. If you only look at Chinese content, Google and Baidu how different?

Outside the world is wonderful, wonderful from the rich, the outside world is very helpless, but because too many people do not understand those rich.

3.3.2 Virtual Machines and VPS

Most people use Windows and Macs, and the number of people in the non-IT industry using Linux can be almost negligible. But to write good code, you should learn to edit under Linux, whether in a visual desktop or command line, should understand learning.

This is where virtual machines and VPS are involved.

Virtual functions provide a Linux environment that is easy to practice without compromising your system. Because a lot of people are starting to use virtual machines, here I focus on VPS.

With the VPS, you will find a different world.

With a VPS, you can test the crawler in the hundred trillion to crawl the internet speed, fully develop their own "anti-anti-crawler strategy", with a VPS, you can make your program when needed to run 24 hours, with a VPS, you can more easily deploy your site ... This is a lot of examples. With their own servers, their public IP, you will find life in the innovation point a lot more.

3.3.3 Dual Monitor

A graph stream, seconds understand.


Double screen This kind of thing is like solid-state hard disk, the use of can not quit.

3.4 Comprehension and Final Chapter

What you become, depends on what you want to be and what you are trying to become, and what program you write, depending on what program you want to write and try to write.

It ' s no use going back to Yesterday,because I am a different person then.

It's useless to go back to yesterday, because I was different from today.

-"Alice in Wonderland"

I hope my friends will not disappoint their good times.

Use code to do the work in the shortest time

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.