Python教程
Python教程:包含了所有代写案例以及部分答案
-
from pymongo import MongoClient client = MongoClient(‘localhost’, 27017) #建立和数据库系统的连接,创建Connection时,指定host及port参数 db_auth = client.admin db_auth.authenticate("account", "password") #admin 数据库有帐号,连接-认证-切换库 db = client.dbname #连接数据库 … 继续阅读“Python数据库-链接mongodb带用户验证”
:
-
import ftplib, sys ftp1 = ftplib.FTP(‘127.0.0.1’, ‘book’, ‘bookpw’) ftp1.cwd(‘/Dir’) ftp2 = ftplib.FTP(‘www.holdenweb.com’, ‘bookuser’, ‘bookpw’) ftp2.cwd(‘/public’) sock1 = ftp1.transfercmd(‘RETR a.zip’) sock2 = ftp2.transfercmd(‘STOR b.zip’) flen = … 继续阅读“python实现ftp传输”
:
-
import subprocess command = "pip list –outdated" outdatelist = subprocess.Popen (command, stdout=subprocess.PIPE,stderr=subprocess.PIPE, shell = True).stdout.readlines() updatelist = [x.split("(")[0] for x in outdatelist ] for x … 继续阅读“python 双击更新所有已安装的python模块”
:
-
#!/usr/bin/python # -*- coding: utf-8 -*- import ftplib import os import socket HOST = ‘ftp.mozilla.org’ DIRN = ‘pub/mozilla.org/webtools’ FILE = ‘bugzilla-3.6.9-to-3.6.10-nodocs.diff.gz’ def writedata(data): f = open(FILE,’wb’) try: f.write(data) fi … 继续阅读“python 一个简单python ftp客户端代码”
:
-
python判断远程端口是否打开,下面的代码判断指定网站的80端口是否打开 import socket sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sk.settimeout(1) try: sk.connect((‘www.open-open.com’,80)) print ‘Server port 80 OK!’ except Exception: print ‘Server port 80 not connect!’ sk. … 继续阅读“python判断远程端口是否打开”
:
-
一个python自定义的加密解密函数,下面的代码实现了对字符串的加密盒解密,调用简单 def encrypt(key, s): b = bytearray(str(s).encode("gbk")) n = len(b) # 求出 b 的字节数 c = bytearray(n*2) j = 0 for i in range(0, n): b1 = b[i] b2 = b1 ^ key # b1 = b2^ key c1 = b2 % 16 c2 = b2 // 16 # b2 … 继续阅读“python 一个python自定义的加密解密函数”
:
-
引入ftplib模块通过ftp发送文件的方法 import ftplib # We import the FTP module session = ftplib.FTP(‘myserver.com’,’login’,’passord’) # Connect to the FTP server myfile = open(‘toto.txt’,’rb’) # Open the file to send session.storbinary(‘STOR toto.txt’, myfile) # Se … 继续阅读“python通过ftp上传文件”
:
-
# -*- coding: utf-8 -*- import os import time import datetime rootDir = "I:/1/" dic={} for dirName,subDirs,fileList in os.walk(rootDir): print dirName for fn in fileList: fnpath=dirName+fn st = os.stat(fnpath) mode, ino, dev, nlink, uid, gi … 继续阅读“python 文件按照日期命名”
:
-
""" python 3个文件合并成3列.py 依山居 7:47 2015/12/15 先写个简单的实现。主要是itertools.zip_longest()的用法: https://docs.python.org/3.5/library/itertools.html """ import itertools with open("1.txt") as f: txt1=[r.rstrip("\n" … 继续阅读“python 3个文件合并成3列.py”
:
-
#!/usr/bin/env python #coding=utf-8 import os dir = ‘.’ dirApp = "%s\Data" % dir file_type = ".app" default_file = "default" use_file = "AppData.mdb" def re_file(file, tofile): os.renames(‘%s\%s’ % (dirApp, fil … 继续阅读“python 帮同事写的一个切换数据库启动的小工具”
: