Ivy League Python入门教程:Starting Out with Python第三版

需积分: 50 9 下载量 31 浏览量 更新于2024-07-19 1 收藏 23.97MB PDF 举报
"《Python入门:从入门到精通》全球版第三版" 《Starting Out with Python》第三版是由托尼·加迪斯编著的一本专为初学者设计的Python编程教程,特别适合美国常春藤联盟等高校的学生作为入门教材。这本书注重实践和理论相结合,旨在引导读者逐步掌握这门广泛应用于数据分析、Web开发、人工智能等领域的计算机语言。 该教程在全球范围内发行,附带一年免费预付费学生支持服务。这些支持包括视频笔记,这些视频可以加深对书中概念的理解;在线附录,提供额外的参考资料和技术细节;以及源代码,让学生可以直接查看和理解编写程序的过程,这对于学习者来说是非常宝贵的资源。 在开始使用在线资源之前,购买者需要通过一个互联网连接的电脑和网页浏览器进行注册。下面是操作步骤: 1. 访问官方网站:www.pearsonglobaleditions.com/gaddis。 2. 寻找“Companion Website”选项并点击进入。 3. 在新页面上找到“Register”按钮,点击开始注册过程。 4. 在注册页面上,输入在书本封底刮开涂层后显示的学生访问码(注意,不要输入破折号,可以使用大写或小写字母)。 5. 按照屏幕上的指示操作。如果在注册过程中遇到任何问题,可以随时点击帮助链接获取支持。 整个注册过程简单快捷,只需首次完成。通过这种方式,读者可以充分利用《Starting Out with Python》提供的全方位学习资源,确保他们在Python学习之旅中得到充分的指导和支持,从而快速建立起坚实的编程基础。无论你是零基础的初学者还是希望提升技能的开发者,这本书都是一个理想的起点。

#!/usr/bin/env python #coding: utf-8 import os from time import time from datetime import datetime from netmiko import ConnectHandler from openpyxl import Workbook from openpyxl import load_workbook def read_device_excel( ): ip_list = [] wb1 = load_workbook('E:\/Users/Wayne_Peng/Desktop/cs_lab.xlsx') ws1 = wb1.get_sheet_by_name("Sheet1") for cow_num in range(2,ws1.max_row+1): ipaddr = ws1["a"+str(cow_num)].value ip_list.append(ipaddr) return ip_list def get_config(ipaddr): session = ConnectHandler(device_type="huawei", ip=ipaddr, username="mtlops", password="cisco,123", banner_timeout=300) print("connecting to "+ ipaddr) print ("---- Getting HUAWEI configuration from {}-----------".format(ipaddr)) # config_data = session.send_command('screen-length 0 temporary') # config_data = session.send_command('dis cu | no-more ') # command = 'display version | display cpu-usage | display memory-usage' # config_data = session.send_command(command) commands = ['display version', 'display cpu-usage', 'display memory-usage'] config_data = '' for cmd in commands: output = session.send_command_timing(cmd) config_data += f'{cmd}\n{output}\n' session.disconnect() return config_data def write_config_to_file(config_data,ipaddr): now = datetime.now() date= "%s-%s-%s"%(now.year,now.month,now.day) time_now = "%s-%s"%(now.hour,now.minute) #---- Write out configuration information to file config_path = 'E:\/Users/Wayne_Peng/Desktop/' +date verify_path = os.path.exists(config_path) if not verify_path: os.makedirs(config_path) config_filename = config_path+"/"+'config_' + ipaddr +"_"+date+"_" + time_now # Important - create unique configuration file name print ('---- Writing configuration: ', config_filename) with open( config_filename, "w",encoding='utf-8' ) as config_out: config_out.write( config_data ) return def main(): starting_time = time() ip_list = read_device_excel() for ipaddr in ip_list: hwconfig = get_config(ipaddr) write_config_to_file(hwconfig,ipaddr) print ('\n---- End get config threading, elapsed time=', time() - starting_time) #======================================== # Get config of HUAWEI #======================================== if __name__ == '__main__': main() 加一段gevent,def run_gevent()

2023-05-26 上传