What's the best Python script you've ever written?

Source: Internet
Author: User
Tags xpath
From: Python (programming language): What is the best Python scripts you ' ve ever written?
Want to see more cool things:-|

Reply content:

Our office environment is window, the development environment is UNIX (you can approximate that everyone works on the same machine, most people's directory permissions are 755 ...) ), in order to prevent the development code out of the network, there is no internet connection between Windows and UNIX, we can only remotely log on to a jump server and then remotely log on to UNIX, if there is a UNIX network of files need to be sent out to the Windows network, need to lead strict approval (reverse direction no problem, There is a dedicated FTP server). The most intolerable scenario for me as a graduate of communications is that there is no two-way communication established. So, in order to be able to spread the UNIX network data, I use Python to convert binary data into an image, each pixel can represent 3 bytes, and then add the outer edge of the image to a width of 1 black border, outside to increase the width of 1 pixels of the white border, as the image boundary identifier. In this way, I am under Windows, using Python to reverse the operation, the data is well solved! In this case at least 1MB files can be transmitted (the larger the screen transmission more), 7z compression, you can pass a lot of text. If you need to pass more, you can also make animation ... The script was only dozens of lines, but it greatly improved the efficiency of my later work. Python is so cool, I love python!. Say two and know the relevant one.

Because I don't recognize it personally. The problem is everyone's"The view that everyone can edit the problem this setting is accepted but not agreed. So every time I see a good person to change the original question to beyond recognition, it feels like eating a dead fly as disgusting. (Although there is a problem log, most people will not go to see it.) )

Finally, one day, I was so sick of someone, I wrote a script in Python: For a problem, every 10 seconds to refresh, when it is found that someone has changed the problem and the idea is not the same, then automatically change back-this is not an extreme means, but only the use of rules. This script has been used two times, look at the log, really disgusting to a number of so-called "public editing program" of the students-imagine, sneak in the morning two or three points to modify the problem, less than 10 seconds to be changed back to the original, the kind of the crazy expression.

Another example, I like to pay attention to the sister, so there are a lot of people concerned, this brings a few problems: one is the TL too miscellaneous, one is not high enough. So you need to clean it up regularly. So write the script crawled so concerned about the gender, number of questions, approval number, recent active time and so on characteristics, and then extract 100 as training data, manual labeling whether to take off, and then use linear model training, to determine which concerns the value of low, good regular cleaning. (not yet cleaned up, as the results of machine learning for the value of followers are also being evaluated.) )

As a programmer, it's a bit of fun to amuse yourself, and Python does it handy. Think of a joke I used to chat with Shen
Code starts true, False = False, True
Then start writing the Python program thanks to the invitation. When I played http://projecteuler.net/ When I wrote a little script of some very chicken thieves, I was interested to see https:// github.com/riobard/proj ect-euler/blob/master/euler.py Python Online Editor

This is an editor I wrote in Python that can write and execute Python code on a Web page. Basic syntax and modules are supported. But for security reasons (and of course, because there is no improvement), the functionality is also limited.
Write the code can be automatically complete, but this is the JS thing, and Python has nothing to do.

Written more than two years ago, it has recently been slightly optimized, adding support for several grammars and modules. A further dozens of teaching routines were added. The purpose of this is to make it easy for the public readers to experiment with code directly inside.

Less than 200 lines of code implementation goagentgithub-larva-lang/larva-lang:the larva programming Language Verify that the URLLIB2 and webscraping libraries are installed, and then paste this code into Pythonide, and then open the D-disk for a while f.txt you understand!

#-*-Coding:utf-8-*-__author__ = ' ftium4.com '#导入urllib2库, for getting Web pagesImport Urllib2#使用开源库webscraping库的xpath模块 from webscraping Import XPath,Commondef Get_data(URL):    req = Urllib2.Request(URL)    req.Add_header(' User-agent ', ' mozilla/5.0 (Windows; U Windows NT 5.1; ZH-CN; rv:1.8.1.14) gecko/20080404 (foxplus) firefox/2.0.0.14 ')    #获得响应    reponse = Urllib2.Urlopen(req)    #将响应的内容存入html变量    HTML = reponse.Read()    #以下抓取页面的番号和片名    title = XPath.Search(HTML, '//div[@class = "av style1"]/a[1]/@title ')    return title#创建文本用于保存采集结果F=Open(R ' D:\f.txt ',' W ') for P inch Range(1,494):    URL = R ' http://dmm18.net/index.php?pageno_b=%s'%P    Print URL    title = Get_data(URL)     for  item1 inch title:            #将采集结果写入文本中            F.Write(Str(item1)+'\ n')            Print item1F.Close()
Wrote a thunder cloud broadcast push to XBMC on the script, very simple, there is no technical content, but for those who like to see the film, is really a big benefit ah, free use of thunder Cloud broadcast, through the XBMC with large TV to see HD

Script Address
https:// gist.github.com/zhu327/ 987f3fc288ca55939e73

XBMC is used in Raspberry Pi, general 720p+ external subtitles without pressure, and attached Raspberry Pi with XBMC experience an article
/ http bozpy.sinaapp.com/blog/ - Enter the animation name (fuzzy match) and the number of sets, directly get to download URL, paste to the Thunderbolt immediately use
http://www. KYLEN314.COM/ARCHIVES/5 729
  • 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.