import os,sys,shutil,zipfile,shelve
print(os.environ[
'os'])
os.
system(
'dir')
a=os.popen(
'dir').
read()
print(a,
'\n-------------------------')
print(os.
stat(
'info'))
print(os.path.abspath(__file_
_))
print(os.path.isfile(
'info'))
print(sys.argv)
print(sys.stdout.
write(
'please:'))
print(sys.platform)
shutil.copyfile(
'info',
'test')
z=zipfile.ZipFile(
'../test.zip',
'r')
z.extractall(
'../test/')
z.
close()
shelve模块
import shelve
s=shelve.
open(
'shelve_test')
name=[
'laowang',
'21',
22]
s[
'name']=name
s[
'b']=[
1,
23]
s.
close()
a=shelve.
open(
'shelve_test')
b=
a.
get(
'name')
print(
a.
get(
'name'))
print(
a.
get(
'b'))
xml模块
import xml.etree.ElementTree
as ET
tree = ET.parse(
'test.xml')
root = tree.getroot()
print(root.tag)
for child
in root:
print(child.tag, child.attrib)
for i
in child:
print(
'---->',
'tag:', i.tag,
'\ntext:', i.
text,
'\nattrib:', i.attrib)
print(
'\n-------------------\n')
for node
in root.iter(
'year'):
print(node.tag, node.
text)
new_year = int(node.
text) +
1
node.
text = str(new_year)
node.
set(
'update',
'yes')
tree.
write(
'xmlchange.xml')
for country
in root.findall(
'country'):
rank = int(country.find(
'rank').
text)
if rank >
50:
root.remove(country)
tree.
write(
'xmldel.xml')
create_xml = ET.Element(
'namelist')
name = ET.SubElement(create_xml,
'name', attrib={
'enrolled':
'yes'})
age = ET.SubElement(name,
'age', attrib={
'checked':
'no'})
sex = ET.SubElement(name,
'sex')
age.
text =
'29'
sex.
text =
'male'
name = ET.SubElement(create_xml,
'name',attrib={
'enrolled':
'no'})
age=ET.SubElement(name,
'age')
age.
text=
'33'
et=ET.ElementTree(create_xml)
et.
write(
'create_xml.xml',encoding=
'utf-8',xml_declaration=True)
<?xml
version=
"1.0" encoding=
"utf-8" ?>
<alex>
<country name=
"guojia1">
<rank updated=
"yes">
2</rank>
<year>
2008</year>
<neighbor name=
"neighbor1" direction=
"E"/>
<neighbor name=
"neighbor2" direction=
"R"/>
</country>
<country name=
"guojia2">
<rank updated=
"yes">
200</rank>
<year>
2008</year>
<neighbor name=
"guojia2_neighbor1" direction=
"c"/>
<neighbor name=
"guojia2_neighbor2" direction=
"w"/>
</country>
</alex>
import hashlib
md5 = hashlib.md5()
md5.update(
b'123456')
print(md5.hexdigest())
转载请注明原文地址: https://ju.6miu.com/read-668662.html