❶ python 篩選出中文文本中包含某一個名字的句子
#!usr/bin/envpython3
importre
name='喬峰'
text='''段譽的六賣神賤,虛竹的酒色為善佛祖皆空。喬峰的誰知心愛
朱顏消逝煙雨中。降龍無敵手,丐幫幫主喬峰。'''
results=re.findall(r'[^。]*?{}[^。]*?。'.format(name),text)
fori,rinenumerate(results,1):
print(i,r)
❷ 如何用python訪問網頁並在表單處輸入內容
我用過selenium模擬瀏覽器
使用selenium的chrome或firefox的webdriver打開瀏覽器
driver.get(url) #訪問你的網頁from=driver.find_elements_by_xpath("xxx")通過xpath或id等方法鎖定到網頁上表單的那個元素後,用
from.send_keys("xxx")來輸入內容
❸ 如何用Python語言實現在一個文件中查找特定的字元串
用正則表達式
>>>s='helloworld'
>>>importre
>>>re.search('wor',s)
<_sre.SRE_Matchobject;span=(6,9),match='wor'>
❹ 如何用Python語言實現在一個文件中查找特定的字元串
用正則表達式
>>> s='hello world'
>>> import re
>>> re.search('wor',s)
<_sre.SRE_Match object; span=(6, 9), match='wor'>
❺ python語言,s = "abcd1234",find()函數可以在字元串中搜索子串...
沒有問題,s.find("cd")是返回"cd"在s中出現的最小的index(序號,從0開始)
如果要統計出現的次數,可以用s.count("cd"),結果為1
❻ 怎樣用python實現自動登錄,自動填表
怎樣用python實現自動登錄,自動填表
也許最初設計 Python 這種語言的人並沒有想到今天Python 會在工業和科研上獲得如此廣泛的使用。著名的自由軟體作者Eric Raymond 在他的文章《如何成為一名黑客》中,將Python 列為黑客應當學習的四種編程語言之一,並建議人們從Python 開始學習編程。這的確是一個中肯的建議,對於那些從來沒有學習過編程或者並非計算機專業的編程學習者而言,Python 是最好的選擇之一。Python 第一次學習Python,我只用了不到二十分鍾的時間,站在書店裡把一本教初學編程的人學習Python 的書翻了一遍。也是從那時起,我開始被這種神奇的語言吸引。 Python 可以用來開發symbian 上的東西。
❼ 怎麼用python語言在一個已存在的excel表裡添加工作表啊。
import xlrd,xlwt
file_1 = r'g:\XX\XXXX.xls' #指定文件路徑
data_1 = xlrd.open_workbook(file_1) #打開文件
table_1 = data_1.sheet_by_index(0) #指定表1
wbk_1 = xlwt.Workbook() #建一個新文件
sheet_1 = wbk_1.add_sheet('XXX1',cell_overwrite_ok=True)
sheet_2 = wbk_1.add_sheet('XXX2',cell_overwrite_ok=True) #新文件表名稱,可改寫
sheet_1.write(0,0,test1)
sheet_2.write(0,0,test2)
wbk_1.save('g:\XX\XXXX.xls' )
這樣就在原excel里新建是XXX1和XXX2兩個sheet!
❽ Python常用語句有哪些
1、Python 條件語句
用法:
if 判斷條件1:
執行語句1……
elif 判斷條件2:
執行語句2……
elif 判斷條件3:
執行語句3……
else:
執行語句4……
實例:(要注意空格對齊)
num = 5
if num == 3: # 判斷num的值
print 'boss'
elif num == 2:
print 'user'
elif num == 1:
print 'worker'
elif num < 0: # 值小於零時輸出
print 'error' else: print 'roadman' # 條件均不成立時輸出
2、Python 循環語句
1)while
len=5
while len>0:
len-=1
if len%2>0:
continue
print(len)
else:
print(len)
2)for
fruits = ['banana', 'apple', 'mango']
for fruit in fruits: # 第二個實例
print('當前水果 :', fruit)
print ("Good bye!")
---------------------------------
fruits = ['banana', 'apple', 'mango']
for index in range(len(fruits)):
print ('當前水果 :', fruits[index])
else:
print("end")
print ("Good bye!")
學習Python等編程語言,推薦選擇北京尚學堂,雄厚的師資力量和多年的授課經歷,絕對會帶給你最完美的學習體驗。
❾ 如何利用python語言匹配文本文件中的指定字元串,並將其所在行的後面幾
s="指定字元串"
f=open("文本文件名")
n=int(raw_input("輸入輸出的行數:"))
line=f.readline()
whileline:
ifsinline:
printline
foriinrange(n):
line=f.readline()
ifline:
printline
else:
break
ifnotline:break
line=f.readline()
❿ python中sql語句多個 查詢條件的怎麼寫
python中有很多字元串連接方式,今天在寫代碼,順便總結一下:
最原始的字元串連接方式:str1 + str2
python 新字元串連接語法:str1, str2
奇怪的字元串方式:str1 str2
% 連接字元串:『name:%s; sex: 』 % ('tom', 'male')
字元串列表連接:str.join(some_list)
第四種功能比較強大,借鑒了C語言中 printf 函數的功能,如果你有C語言基礎,看下文檔就知道了。這種方式用符號「%」連接一個字元串和一組變數,字元串中的特殊標記會被自動用右邊變數組中的變數替換。
試試這個
results=self.db.query(
'SELECTLP.IdLineProctId,LP.SupplierLineTitle,LP.MainTitle,LP.SubTitle,LP.ShowTitle,LPC.CityIdDestinationCityId,
LPC.CityNameDestinationCityName,LP.Days,LP.DataFlag,LP.IfDel,LP.RecomImage_IdsASLineProctRecomImage
FROM[TCZiZhuYou].dbo.[ZZY_LineProct]LPWITH(NOLOCK)
INNERJOIN[TCZiZhuYou].dbo.[ZZY_LineProctCity]LPCWITH(NOLOCK)ONLPC.LineProct_Id=LP.IdANDLPC.DataFlag=1ANDLPC.IsDestination=1
WHERELP.Id=%dANDLP.LineProctType=%d'%(line_id,line_type))[0]