python 2.7.5 获取文本关键字符所在行
#!/usr/bin/env python
#-*- coding: UTF- -*-
from __future__ import print_function
import time,os,sys,re,subprocess,commands,itertools,readline dt=time.localtime()
ft=" %Y-%m-%d %H:%M:%S %p %A"
date=time.strftime(ft,dt)
print(" 当前系统时间为:\n",date) #---------------------------------------------------------------------------------
#f0 = open('/etc/ssh/sshd_config','r')
#f1 = f0.readline()
#def get_number():
#sshd_config = "/etc/ssh/sshd_config"
#with open(sshd_config,'r') as f:
#for line in f.readlines():
#try:
#if'Port' in line:
#strlist = line.split('Port ')
#for sshdport in strlist[:]:
#print(sshdport)
#except:
#print('获取失败')
#if __name__ == '__main__':
#get_number()
#---------------------------------------------------------------------------------
#f = open('/etc/ssh/sshd_config','r')
#lines = f.readlines()
#for line in lines:
#if "Port " in line:
#print(line) #[root@localhost ~]# python .py
#当前系统时间为:
#-- :: PM Thursday
#Port
#--------------------------------------------------------------------------------- #yum install -y python python-devel #
#Port
#AddressFamily any #with open('/etc/ssh/sshd_config') as infile, open('/root/1.txt', 'w') as outfile:
#copy = False
#for line in infile:
#if line.strip() == "#":
#copy = True
#elif line.strip() == "#AddressFamily any":
#copy = False
#elif copy:
#outfile.write(line)
#[root@localhost ~]# cat .txt
#Port #---------------------------------------------------------------------------------
#pathfile = raw_input('文件绝对路径:')
#keyname = raw_input('查找内容:') #FoundFlag = False
#f00 = open(pathfile)
#f01 = f00.readline()
#while f01:
#if f01.find(keyname) == 0:
#FoundFlag = True
#print("---------------------------------------------------------------------------------")
#print(" 所在行: " + f01, end='')
#print("---------------------------------------------------------------------------------")
#break
#else:
#f01 = f00.readline()
#f00.close()
#if FoundFlag == False:
#print("获取失败.....!")
#raw_input() # 从下标0开始,查找在字符串里第一个出现的子串,返回结果: #[root@localhost ~]# python .py
#文件绝对路径:/etc/ssh/sshd_config
#查找内容:#Port
#---------------------------------------------------------------------------------
#所在行: #Port
#--------------------------------------------------------------------------------- #[root@localhost ~]# python .py
#文件绝对路径:/etc/ssh/sshd_config
#查找内容:
#获取失败.....!
#Traceback (most recent call last):
#File "1.py", line , in <module>
#raw_input()
#KeyboardInterrupt
#[root@localhost ~]# python .py
#文件绝对路径:/etc/ssh/sshd_config
#查找内容:Port
#获取失败.....!
#find 模块查询只能从左到右
#---------------------------------------------------------------------------------
python 2.7.5 获取文本关键字符所在行的更多相关文章
- Python中使用正则表达式获取两个字符中间部分
问题背景:当我们爬取网页信息时,对于一些标签的提取是没有意义的,所以需要提取标签中间的信息. 解决办法:用到了re包下的函数 方法1:用到了research()方法和group()方法 方法2:用到了 ...
- 【NLP】Python NLTK获取文本语料和词汇资源
Python NLTK 获取文本语料和词汇资源 作者:白宁超 2016年11月7日13:15:24 摘要:NLTK是由宾夕法尼亚大学计算机和信息科学使用python语言实现的一种自然语言工具包,其收集 ...
- python中的关键字符
from keyword import kwlistprint(kwlist)for i in kwlist: print(i) 可以显示所有的关键字符,开发者不要重新赋予其他值. a = 10000 ...
- python开发_tkinter_获取文本框内容_给文本框添加键盘输入事件
在之前的blog中有提到python的tkinter中的菜单操作 python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推荐 python开发_tkinter_窗口控件_自 ...
- Python+selenium之获取文本值和下拉框选择数据
Python+selenium之获取文本值和下拉框选择数据 一.结合实例进行描述 1. 实例如下所示: #新增标签操作 def func_labels(self): self.driver.find_ ...
- 使用python处理selenium中的获取文本问题
# 获取文本 button_name = self.driver.find_element_by_id("sign_in_display").text
- selenium+python自动化104-如何获取隐藏元素text文本
前言 首先 selenium 是可以定位到隐藏元素的,但是 selenium 不能跟隐藏元素交互,也就是隐藏元素element不能使用element.click()方法. 隐藏元素element.te ...
- js/jquery获取文本框的值与改变文本框的值
我们就用它来学习获取文本框的值及改变文本框的值. 代码如下 复制代码 <script>function get1(){ document.getElementById("txtb ...
- Java使用正则表达式获取文本的章节名称
获取文本的章节,首先要确定章节的开始标准,一般中文的章节都是以“第”开头,第一章.第二章等.所以使用“^”字符来确定首位,但是很多时候章节前面会有空白字符,所有以“第”作为章节的开始,进行以下的匹配 ...
随机推荐
- 1、DNS服务基础
w'indows上名称解析目录: C:\Windows\System32\drivers\etc https://jocent.me/2017/06/18/dns-protocol-principle ...
- Unreal Engine* 4/英特尔® VTune™ Amplifier 使用指南
借助英特尔 VTune Amplifier,可以通过单一易用的分析界面获得先进的分析功能.UE4 和英特尔 VTune Amplifier 相互配合,支持调查代码并进行分析,从而在多个内核上顺畅运行. ...
- PJzhang:CVE-2019-14287 sudo权限绕过漏洞复现
猫宁!!! 参考链接:Ms08067实验室公众号 sudo 1.8.28版本之前有漏洞. 更新完kali linux,deepin截图工具失效,只能用自带的,不能划重点. 看一下sudo版本,1.8. ...
- 【CodeForces - 707B】Bakery(思维水题)
Bakery Descriptions 玛莎想在从1到n的n个城市中开一家自己的面包店,在其中一个城市烘焙松饼. 为了在她的面包房烘焙松饼,玛莎需要从一些储存的地方建立面粉供应.只有k个仓库,位于不同 ...
- 安装vsftpd
通用安装和配置 1.下载安装包并安装 wget http://mirror.centos.org/centos/7/os/x86_64/Packages/vsftpd-3.0.2-25.el7.x86 ...
- B. Grow The Tree Codeforces Round #594 (Div. 2)
Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on t ...
- dfs入门-cogs1640[黑白图像]
题目链接:http://cogs.pro:8081/cogs/problem/problem.php?pid=vxSmxkeqa [题目描述] 输入一个n×n的黑白图像(1表示黑色,0表示白色),任务 ...
- 【并行计算-CUDA开发】CUDA线程、线程块、线程束、流多处理器、流处理器、网格概念的深入理解
GPU的硬件结构,也不是具体的硬件结构,就是与CUDA相关的几个概念:thread,block,grid,warp,sp,sm. sp: 最基本的处理单元,streaming processor 最 ...
- MySQL中的聚集索引和辅助索引
MySQL中的聚集索引和辅助索引 当你定义一个主键时,innodb存储引擎就把他当做聚集索引 如果你没有定义一个主键,则innodb定位到第一个唯一索引,且改索引的所有列值均为非空,就将其当做聚集索引 ...
- 菜鸟系列Fabric——Fabric 私密数据(6)
Fabric 私密数据 1.私密数据的定义 如果某个渠道上的一组组织需要将数据与该渠道上的其他组织保密,他们可以选择创建一个仅包含需要访问数据的组织的新渠道.但是,在每种情况下创建单独的通道会产生额外 ...