File Operations in python

1. Common File Operations in python include open, write, read, readline, readlines, writelines, seek, tell, and close. The prototype of the open function is open (name [, mode [, buffering]), and name is the path name of the file. The common mode is

Python checks whether the server is normal

Python is often used to check whether the server can be pinged and whether the program runs properly (check whether the corresponding port is normal) Previously, shell scripts were written as follows:Copy codeThe Code is as follows:PINGRET = $ (ping

Share an ftp client example using python

Copy codeThe Code is as follows:#! /Usr/bin/python# Coding: UTF-8# Write: JACK# Info: ftp exampleImport ftplib, socket, OSFrom time import sleep, ctime Def LoginFtp (self ):Ftps = ftplib. FTP ()Ftps. connect (self. host, self. port)Ftps. login (self.

Python dynamic variable loading example

As we all know, after a program is started, each program file will be loaded into the memory, so if the program text changes again, it will not affect the running of the current program, which is a protection for the program. However, for languages

Read and Write python files and use mysql to insert examples in batches (use python to operate mysql)

Copy codeThe Code is as follows:#-*-Coding: UTF-8 -*-'''Created on December 9, 2013 @ Author: hhdys''' Import OSImport mysql. connector Config = {'User': 'root ','Password ':'******','Host': '2017. 0.0.1 ','Database': 'test ','Raise _ on_warnings ':

Example of dict layout traversal using python

Copy codeThe Code is as follows:# _ * _ Coding: utf_8 _Import sysImport OS Class Graph ():Def _ init _ (self, V, E ):Self. V = VSelf. E = ESelf. visited = []Self. dict = {}Self. fd = open ("input.txt ")Def initGraph (self ):Self. visited = [0 for I

Example of using win32com to insert html elements in Baidu space in python

Copy codeThe Code is as follows:From win32com. client import DispatchExImport timeIe = DispatchEx ("InternetExplorer. Application ") Ie. Navigate ("http://hi.baidu.com/mirguest/creat/blog ")Ie. Visible = 1While ie. Busy:Time. sleep (1) Body = ie.

Python uses rabbitmq to implement web crawler examples

Compile tasks. pyCopy codeThe Code is as follows:From celery import CeleryFrom tornado. httpclient import HTTPClientApp = Celery ('task ')App. config_from_object ('celeryconfig ')@ App. taskDef get_html (url ):Http_client = HTTPClient ()Try:Response

Python and pyqt implement 360 CLable controls

 Copy codeThe Code is as follows:#! /Usr/bin/python#-*-Coding: UTF-8 -*- From PyQt4.QtGui import *From PyQt4.QtCore import *From PyQt4.Qt import * Class CLabel (QWidget ):SignalLabelPress = pyqtSignal ()Def _ init _ (self, parent = None ):Super

Python 360 character display interface

Copy codeThe Code is as follows:#! /Usr/bin/python#-*-Coding: UTF-8 -*- From push_button import *From clabel import *From common import * From PyQt4.QtGui import *From PyQt4.QtCore import *From PyQt4.Qt import * Class CharacterWidget (QWidget ):Def _

Use the python decorator to verify the configuration file example

Different verification function check inputs are called based on different configuration files. You can change the logic of the verification function as needed. Copy codeThe Code is as follows:Def VerifyData (func ): Def VerifyInt (data ):Assert

Python web page capture example sharing

Copy codeThe Code is as follows:Import socketDef open_tcp_socket (remotehost, servicename ):S = socket. socket (socket. AF_INET, socket. SOCK_STREAM)Portnumber = socket. getservbyname (servicename, 'tcp ')S. connect (remotehost, portnumber ))Return

How to extract web links using python

Copy codeThe Code is as follows:# Encoding: UTF-8Import socketImport htmllib and formatterDef open_socket (host, servname ):S = socket. socket (socket. AF_INET, socket. SOCK_STREAM)Port = socket. getservbyname (servname)S. connect (host, port

Sample git log analysis using python

Git log is a very useful 'historical 'material for managing project development with git. The requirement is from here. We hope to have a custom Filtering for git log. This script completes this type of task. For commit in all branch of a repo, the

Pyqt4 tutorial-Example of a translucent weather forecast Interface

Copy codeThe Code is as follows:#-*-Coding: cp936 -*-Import sysImport urllib2Import jsonFrom PyQt4 import QtCore, QtGuiClass MyWindow (QtGui. QLCDNumber, QtGui. QWidget ):Def _ init _ (self, parent = None ):Super (MyWindow, self). _ init _

Example of simulating Mouse clicking and keyboard inputting with python in windows

Install pywin32 first, and call winapi interfaces in windows Copy codeThe Code is as follows:## _ * _ Coding: UTF-8 _*__ Author _ = 'shanl' Import win32apiImport win32conImport win32guiFrom ctypes import *Import time VK_CODE = {'Backspace':

Example of a python puzzle game computing Tower

The quanta (also known as Hanoi) problem is originated from an ancient legend of India's educational toys. When I created the world, da fan Tian made three diamond pillars, stacked 64 gold disks from bottom to top in order of size. The great fan

Pyqt4 tutorial-messagebox example

Copy codeThe Code is as follows:# Coding = UTF-8# Dialog boxImport sysFrom PyQt4 import QtGui, QtCoreClass Window (QtGui. QWidget ):Def _ init _ (self ):Super (Window, self). _ init __()Self. setWindowTitle ("hello ")Self. resize (500,500)Gridlayout

Pyqt4 example of widget usage

Copy codeThe Code is as follows:#-*-Coding: UTF-8 -*-Import sysFrom PyQt4 import QtCore, QtGuiClass MyWindow (QtGui. QWidget ):Def _ init _ (self, parent = None ):QtGui. QWidget. _ init _ (self, parent)Self. setWindowTitle ("weather ")Self. resize (1

Python-02 quick introduction

Here, we will quickly introduce Python's process-oriented programming from the perspective of C language developers. 1> Basic Data Type Integer, long integer, floating point, and plural. The first three types are similar to those of C, and the

Total Pages: 4013 1 .... 3142 3143 3144 3145 3146 .... 4013 Go to: GO

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.