调用游标下的lastrowid 可以获取插入之前的表里id字段存放到哪个自增idcursor.lastrowidmysql> select * from userinfo;
+----+-------+-----+
| id | name | pwd |
+----+-------+-----+
| 1 | mike | 123 |
| 2 | jack | 456 |
| 3 | alex | 555 |
| 4 | peter | 989 |
| 5 | app | 123 |
| 6 | tom | 556 |
+----+-------+-----+
6 rows in set (0.03 sec)我再用脚本 插入三条记录 自增id就是从 7开始,获取我插入...
思考:如果把测试文件、测试报告、日志信息放在某一个路径下需要读取和保存的话 需要给对应方法提供路径,假如data放着测试数据:test_date.xlsx 路径如何获取那? 方法一:1)获取py脚本所在路径os.path.realpath((__file__))2)使用os.path.split()分割路径与文件,以元组的形式返回,我们运用这个特性获取py文件的上级路径‘script’。os.path.split(os.path.realpath(__file__))[0]3)使用os.path.join()进行路径拼接,如果直接...
爬虫代理IP由飞猪HTTP服务供应商提供
使用 python 代码收集主机的系统信息,主要:主机名称、IP、系统版本、服务器厂商、型号、序列号、CPU信息、内存等系统信息。代码开始:#!/usr/bin/env python
#encoding: utf-8‘‘‘
收集主机的信息:
主机名称、IP、系统版本、服务器厂商、型号、序列号、CPU信息、内存信息
‘‘‘from subprocess import Popen, PIPE
import os,sys‘‘‘ 获取 ifconfig 命令的输出 ‘‘‘
def getIfconfi...
原文链接:https://www.cnblogs.com/blog-rui/p/12108072.html安装的包pip install wmi
pip install pywin32import wmic = wmi.WMI()# # 硬盘序列号for physical_disk in c.Win32_DiskDrive():print(physical_disk.SerialNumber)# CPU序列号for cpu in c.Win32_Processor():print(cpu.ProcessorId.strip())# 主板序列号for board_id in c.Win32_BaseBoard():print(board_id.SerialNumber)# mac地址for mac in c.Win32_NetworkAdapt...
直接来几个简单的栗子:try: 100/0except Exception as err: print(err)输出结果:division by zero 只知道是报了这个错,却不知道在哪个文件哪个函数哪一行报的错。 使用 traceback 模块import traceback
try: 100/0
except Exception,e: traceback.print_exc() 输出结果:Traceback (most recent call last): File "D:/code/www/jiaoben/test/test1.py", line 3, in <module> 100/0ZeroDivisionError: division b...
python脚本中的变量经常会变动,所以考虑写到mysql里面如何获取mysql里面数据作为参数,参考如下脚本:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import MySQLdb
# 打开数据库连接
db = MySQLdb.connect("3.12.5.1", "root", "root", "test", charset=‘utf8‘)
# 使用cursor()方法获取操作游标
cursor = db.cursor()
# 使用execute方法执行sql语句
cursor.execute("select media_source_dir from app_configs a where a.ip_ad...
信息安全很重要,你的地理位置可能暴露了!!!使用python和GeoLite2获取目标的地理位置 1#! /usr/bin/env python 2#-*- coding:utf-8 -*- 3 4‘‘‘ 5Created on 2019年12月8日6 7@author: Admin8‘‘‘ 9 10from copy import copy11import optparse12import re13 14import geoip2.database15 16 17 reader = geoip2.database.Reader(‘GeoLite2-City.mmdb‘)18 19# 查询IP地址对应的物理地址 20def ip_get_location(ip_ad...
dict.get()和dict[‘key‘]总结: 对字典中已存在的键值对的获取,两者的结果没有区别: 当获取不存的键值对时dict[key]的方式会报错: 但是使用get的方式可对其设置默认值: ']的区别' ref='nofollow'>python获取字典键值对dict.get()和dict['key']的区别原文:https://www.cnblogs.com/01black-white/p/14002718.html
本文实例讲述了python获取目录下所有文件的方法。分享给大家供大家参考。具体分析如下:os.walk()函数声明:walk(top,topdown=True,onerror=None)1. 参数top表示需要遍历的目录树的路径2. 参数topdown的默认值是"True",表示首先返回目录树下的文件,然后在遍历目录树的子目录.Topdown的值为"False"时,则表示先遍历目录树的子目录,返回子目录下的文件,最后返回根目录下的文件3. 参数onerror的默认值是"None",表示忽略文件遍历时产...
page = urllib2.urlopen(url) contents = page.read() #获得了整个网页的内容也就是源代码 print(contents) url代表网址,contents代表网址所对应的源代码,urllib2是需要用到的包,以上三句代码就能获得网页的整个源代码 2 获取网页中想要的内容(先要获得网页源代码,再分析网页源代码,找所对应的标签,然后提取出标签中的内容) 2.1 以豆瓣电影排名为例子 网址是http://movie.douban.com/top250?format=text,进入网址后...
1. 获取用户输入
??要编写一个有实际价值的程序,就需要与用户交互。当然,与用户交互有很多方法,例如,GUI(图形用户接口)就是一种非常好的与用户交互的方式,不过我们先不讨论GUI的交互方式,本节会采用一种原始,但很有效的方式与用户交互,这就是命令行交互方式,也就是说,用户通过命令行方式输入数据,程序会读取这些数据,并做进一步的处理。??从命令行接收用户的输入数据,需要使用input函数。input函数接收一个字符串类...
获取对象信息拿到一个变量,除了用 isinstance() 判断它是否是某种类型的实例外,还有没有别的方法获取到更多的信息呢?例如,已有定义:class Person(object):def__init__(self, name, gender):self.name = nameself.gender = genderclass Student(Person):def__init__(self, name, gender, score):super(Student, self).__init__(name, gender)self.score = scoredef whoAmI(self):return‘I am a Student, my name is %s‘ % se...
import psutil
def get_netcard():"""获取网卡名称和ip地址"""netcard_info = []info = psutil.net_if_addrs()print(info.items())for k, v in info.items():for item in v:if item[0] == 2 andnot item[1] == ‘127.0.0.1‘ :#去除通过dhcp获取ip方式没获取时分配的的自动专有地址if"169.254."notin item[1]:# netcard_info.append((k, item[1]))netcard_info.append(item[1])print("K",k)return netcard_info
if__name__ == ‘__...
取得时间相关的信息的话,要用到python time模块,python time模块里面有很多非常好用的功能,你可以去官方文档了解下,要取的当前时间的话,要取得当前时间的时间戳,时间戳好像是1970年到现在时间相隔的时间。你可以试下下面的方式来取得当前时间的时间戳:import timeprint time.time()输出的结果是:1357723206.31但是这样是一连串的数字不是我们想要的结果,我们可以利用time模块的格式化时间的方法来处理:time.localtime(tim...
使用 python 代码收集主机的系统信息,主要:主机名称、IP、系统版本、服务器厂商、型号、序列号、CPU信息、内存等系统信息。#!/usr/bin/env python
#encoding: utf-8‘‘‘
收集主机的信息:
主机名称、IP、系统版本、服务器厂商、型号、序列号、CPU信息、内存信息
‘‘‘from subprocess import Popen, PIPE
import os,sys‘‘‘ 获取 ifconfig 命令的输出 ‘‘‘def getIfconfig():p = Popen([‘ifconfig‘], stdout = PIPE)dat...