一,安装模块
windows环境下安装模块
直接在CMD里面,运行命令: pip install paramiko, 删除命令,pip uninstall paramiko
用python连接linux,然后运行命令:
import paramiko
hostname='192.168.1.112'
username='root'
password='123456'
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect("192.168.1.112",22,"root","123456")
stdin,stdout,stderr = ssh.exec_command("ls")
print (stdout.read())
ssh.close()
注意::python2.X版本的print与python3.X版本的print不一样。
python2.x >>> print 'hello world'
python3.x >>> print ("hello world")
设置linux主机网卡为本地自定义模式
二,对EXcel表格的操作
#coding:utf-8
import xlsxwriter
#1,创建一个excel文件
work = xlsxwriter.Workbook("yao.xlsx")
#2,在eccel文件里面创建一个表格
worksheet = work.add_worksheet("test1")
#3,修改内容格式
#1,表格的格式,宽度
worksheet.set_column("A:A",20)
#2,内容的格式,
bold=work.add_format({"bold":True})
#4,写入内容
#1,写入字符
worksheet.write("A1","hello,world!!!!",bold)
###2,写入图片
worksheet.insert_image("A2","1.jpg")
###3,写入函数
worksheet.write("A3",2,bold)
worksheet.write("A4",3,bold)
worksheet.write("A5","=SUM(A3:A4)",bold)
work.close()
'''
#coding:utf-8
import xlsxwriter
#1,创建一个excel文件
work = xlsxwriter.Workbook("zhao.xlsx")
#2,创建图表
chart = work.add_chart({'type':'column'})
#column 柱状图 area 面积图 bar 条形图 line 折线图 radar 雷达图
#注意不可以插入空的图表
#2,在eccel文件里面创建一个表格
worksheet = work.add_worksheet()
#3,添加数据
title = "abcdefghi"
data = [1,23,23,34,445,56,78,55,23]
for i,j in enumerate(title):
print(i,j)
point = "A%d"%(i+1)
worksheet.write_string(point,j)
for i,j in enumerate(data):
point = "B%d"%(i+1)
worksheet.write(point,j)
#4,为图表添加数据
chart.add_series(
{
"categories":"=Sheet1!$a$1:$a$9", #类别标签的范围
"values":"=Sheet1!$b$1:$b$9", #图标数据的范围
"line":{"color":"red"} #图标线条的属性
}
)
worksheet.insert_chart("A10",chart)
work.close()
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
三,python运行linux命令的两种方法
import os
import subprocessos.system('ls')
subprocess.call('df -h'.split())++++++++++++++++++++++++++
四,
如何在已经存在python2的linux环境上安装python3
下载官方地址:https://www.python.org/downloads/release/python-361/
[root@localhost install]# wget https://www.python.org/ftp/python/3.4.4/Python-3.4.4.tgz [root@localhost install]# tar -zxf Python-3.4.4.tgz [root@localhost install]# cd Python-3.4.4 # 在安装包中有一个README的文件,里面有写如何安装 [root@localhost Python-3.4.4]# ls aclocal.m4 config.sub configure.ac Grammar install-sh LICENSE Makefile.pre.in Modules Parser PCbuild Python setup.py config.guess configure Doc Include Lib Mac Misc Objects PC pyconfig.h.in README Tools [root@localhost Python-3.4.4]# ./configure [root@localhost Python-3.4.4]# make [root@localhost Python-3.4.4]# make install
五,python3里面的print语法已经变了:
格式为:print("Error:'%s' already exits"%(fname))
标签:python,worksheet,work,Python,3.4,print,随笔,root From: https://blog.51cto.com/u_3369545/6595626