当前位置: 首页 > wzjs >正文

建立公司网站wordpress get option

建立公司网站,wordpress get option,哪里可以做免费网站,做高端网站建设公司最近博主被xml搞得很奔溃,因为在之前的小作业中使用ElementTree(元素树)解析xml文件非常的丝滑,但是当将xml文件改成大约2G的大文件时,他就罢工啦! xml的文件格式如下图所示: 之前的解析代码如下: def lo…

最近博主被xml搞得很奔溃,因为在之前的小作业中使用ElementTree(元素树)解析xml文件非常的丝滑,但是当将xml文件改成大约2G的大文件时,他就罢工啦!
xml的文件格式如下图所示:
在这里插入图片描述
之前的解析代码如下:

def load_xml(self, file):'''function: use the file in XML formatArgs:file (str): path to the xml fileReturns:         '''   # with open(file, 'r', encoding='utf-8') as f:#     xml = f.read()#load the xml file# root = ET.fromstring(xml) #root.tag is rowtree = ET.parse(file)root = tree.getroot()for child in root:docID = child.find('DOCNO').text #get docID# print(docID)content = child.find('TITLE').text +child.find('ARTIST').text +child.find('YEAR').text +child.find('LYRICS').text + child.find('GENRE').text #get content# print("content",content)self.docs_df.loc[docID] = content# use a dataframe to store each doc:docID,content(headline+text)  

之前的报错信息:

Traceback (most recent call last):File "/Users/xiaoxudemacbook/edinburgh/TTDS/cw/cw3/code/index.py", line 115, in <module>index = Index('data.xml', 'englishST.txt')File "/Users/xiaoxudemacbook/edinburgh/TTDS/cw/cw3/code/index.py", line 21, in __init__self.load_xml(xml_path)File "/Users/xiaoxudemacbook/edinburgh/TTDS/cw/cw3/code/index.py", line 34, in load_xmlroot = ET.fromstring(xml) #root.tag is documentFile "/Users/xiaoxudemacbook/opt/anaconda3/lib/python3.9/xml/etree/ElementTree.py", line 1344, in XMLparser.feed(text)
xml.etree.ElementTree.ParseError: out of memory: line 1, column 0

博主搜索过如何修复这个问题的方法,大部分人提到的是用lxml和iterparse,虽然它在google中是排列第一的解决方案,但是博主发现它已经是2014的,而且感觉修改起来比较复杂,博主还在CSDN中发了问答,然后突然想起我们的chatGPT小宝贝。它给出了非常清楚的4种解决方案,博主就贴在下面啦(ps:博主用第一种很简单的方法就解决了,但是根据菜鸟教程中Python XML解析中提供的3中方法,博主感觉好像SAX (simple API for XML )是针对大型xml文件的良方,有空的时候要回头看看,目前还是赶due要紧):

This error message suggests that the XML file being parsed by the load_xml() function is too large to fit in memory. When an XML file is parsed using the ET.fromstring() function, the entire contents of the file are loaded into memory as a string, which can be a problem for very large files.

To resolve this error, you can try one or more of the following solutions:

1. Use the ET.parse() function instead of ET.fromstring() to parse the XML file.

This function takes a file path as an argument, so the XML file is read and parsed incrementally, which can be more memory-efficient. Here’s an example of how you can modify the code:
makefile
Copy code

Replace this line:

root = ET.fromstring(xml)

With this line:

tree = ET.parse(xml_path)
root = tree.getroot()

2. Split the XML file into smaller files before parsing them

If the XML file contains a large number of documents, you can split it into smaller files that each contain a subset of the documents. This way, you can parse each file separately and avoid loading the entire XML file into memory at once.

3. Increase the amount of memory available to the Python process.

If you have enough memory available on your system, you can try increasing the amount of memory allocated to the Python process. One way to do this is by using a virtual environment and setting the PYTHONMALLOC environment variable to malloc. For example, you can try running the following command before running your Python script:

PYTHONMALLOC=malloc python index.py

This will tell Python to use the malloc memory allocator, which can increase the amount of memory available to the process.

4. Use a streaming XML parser.

If the XML file is too large to fit in memory even after trying the above solutions, you can use a streaming XML parser such as xml.sax or lxml.etree. These parsers allow you to process the XML file incrementally, without loading the entire file into memory at once. However, using a streaming parser can be more complex and require more code changes than the other solutions.

附:菜鸟教程Python XML解析:https://www.runoob.com/python/python-xml.html

http://www.dtcms.com/wzjs/559554.html

相关文章:

  • 梧州住房和建设局网站广州互联网营销师
  • 柬埔寨网站开发要学网页设计
  • 汉中网站建设公司电话学生作业做网站需要
  • 网站设计app苏州北京网站建设
  • 文档分享类网站建设系统网站建设ppt
  • 娱乐网站策划书域名查询网站入口
  • 网站建设价格槽闸阀域名 就一个网站
  • 做影视网站什么cms好用17网一起做网站广州
  • 公司网站打不开不知道谁做的网页的响应式布局
  • 学校网站建设发展概况分析简单网页尝试做教案
  • 电子商务网站的建设与规划书微信建站官网免费注册
  • 厦门建设网站首页网站推广的方法及技巧
  • 教育培训机构管理系统龙岗seo网络推广
  • 深圳招聘一般在哪个网站微信免费小程序开发平台
  • 广饶网站制作百度域名注册
  • 松原手机网站开发wordpress支持react
  • 合肥建站wordpress资源模板
  • 平面设计网站大全有哪些免费漫画软件app下载安装
  • 网站域名301如何网络营销
  • 推广做网站南充版面设计的基本元素是指
  • 建设网站运营成本wordpress主题图片修改
  • 网站营销方案家居在线设计平台
  • 网站建设薪水开源商城小程序
  • 做钢材销售客户哪里去开发网站百度网盘app怎么打开链接
  • 北京网站建设 fim重庆沙坪坝网站建设
  • 网站分几种类型在线做头像网站
  • 营销广告网站苏州小程序定制开发公司
  • 重庆建设厅网站首页musik wordpress
  • 湖北网站设计制作公司有哪些如何零基础学编程
  • 做网站的计划概要临沂做网站选盛誉