pyhon第十四天作業

2022-04-10 20:46:44 字數 2232 閱讀 1950

def user(name):

import os

content = input('請輸入要修改的內容:')

end_content = input('請輸入修改之後的內容:')

if os.path.exists(name):

with open(name,'rb') as rf,\

open('.name.txt.swap','wb') as wf:

while true:

res = rf.readline().decode('utf-8')

if content in res:

i = res.replace(content, end_content)

wf.write(i.encode('utf-8'))

else:

wf.write(res.encode('utf-8'))

if len(res) == 0:

break

os.remove(name)

os.rename('.name.txt.swap',name)

print('修改完成')

else:

return '檔案不存在'

user(path_file)

def counts_func(*args):

number = 0

letter = 0

spc = 0

other = 0

for i in args:

if i.isdigit():

number +=1

elif i.isalpha():

letter +=1

elif i.isspace():

spc +=1

else:

other +=1

print('【數字】:{}個\n【字母】:{}個\n【空格】:{}個\n【其他】:{}個'.format(number,letter,spc,other))

res = input('寫入內容:>>')

counts_func(*res)

def len_func(name):

if len(name) > 5:

return true

return false

str = 'sadn'

print(str,len_func(str))

l = [111,1221,1231,51,2,12,5,1]

print(l,len_func(l))

tuq = (1,2,45,[1234,1239,'dasuidh'])

print(tuq,len_func(tuq))

def list_func(list):

l =

while true:

for list_num in list:

if len(l) < 2:

print(list_num)

else:

break

break

return l

a = ['asd','fudhf',3,4,5,6]

print(list_func(a))

def list_new_func(*args):

l =

for i in args:

if args.index(i) % 2 ==1:

return l

l = ['dasd','asdsa','123','ads3d',5,9]

print(list_new_func(*l))

t = ('dasd','asdsa','123','ads3d',5,9)

print(list_new_func(*t))

dic =

ps:字典中的value只能是字串或列表

def func(**kwargs):

print(kwargs)

d = {}

for k in kwargs.keys():

v = kwargs.get(k)

if len(v) > 2:

res = v[0:2]

d[k] = res

return d

dic =

print(func(**dic))

第十四天 Session

session通過sessionid來區分不同的客戶,session是以cookie或url重寫為基礎的,預設使用cookie來實現,系統會創造乙個名為jsessionid的輸出cookie,這稱之為session cookie,以區別persistent cookies 通常看不到jsession...

第十四天 response

教學導航 教學目標 案例二 生成驗證碼 了解 教學方法 我們在建立servlet時會覆蓋service 方法,或doget dopost 這些方法都有兩個引數,乙個為代表請求的request和代表響應response。service方法中的response的型別是servletresponse,而d...

Qt第十四天

qfiledialog檔案對話方塊 qcolordialog顏色對話方塊 qfontdialog字型對話方塊 qinputdialog輸入對話方塊 qmessagebox訊息框 dialog.h ifndef dialog h define dialog h include namespace ui...