我有这个问题,AttributeError: type object 'ElementTree' has no attribute 'tostring'我不知道什么是错的,我导入到字符串,它不起作用.尝试按照另一个教程,但没有.
有没有其他方法将ElementTree对象转换为XML字符串?
import os
import re
import glob
from xml.dom import minidom
from time import strftime
from xml.etree.ElementTree import ElementTree
from xml.etree.ElementTree import Element, SubElement, Comment, tostring
date=strftime("%Y-%m-%dT%H:%M:%S")
os.chdir('/home/guillermo/TclsPy/XML_Level2/')
def prettify(elem):
"""Return a pretty-printed XML string for the Element.
"""
rough_string = ElementTree.tostring(elem, 'utf-8',method="xml" , short_empty_elements=True)
reparsed = minidom.parseString(rough_string)
return reparsed.toprettyxml(indent=" ")
for nameXml in glob.glob("*.xml"):
new_nameXml = re.sub(r'tlmy',r'AUX',nameXml,flags=re.IGNORECASE)
new_nameXml = re.sub('.xml','_AlarmEnabled.xml',new_nameXml, flags=re.IGNORECASE)#new_nameXml.lower().replace('.xml','_AlarmEnabled.xml')
match = re.search(r'TSL_TM_TLMY_(.+).xml', nameXml,flags= re.IGNORECASE )
if match: …Run Code Online (Sandbox Code Playgroud) 我有以下类代表树的节点:
class Node:
def __init__(self, name, parent=None):
self.name = name
self.parent = parent
self.children = []
# ...
if parent:
self.parent.children.append(self)
Run Code Online (Sandbox Code Playgroud)
如何打印这样的树?
我尝试使用该xml.etree.ElementTree模块解析带有Python脚本的html文件.根据标题,字符集应为UTF-8.但文件中有一个奇怪的字符.因此,解析器无法解析它.我在Notepad ++中打开文件来查看该字符
.我尝试用几种编码打开它,但我找不到正确的编码.
由于我有许多要解析的文件,我想知道如何删除所有无法解码的字节.有解决方案吗?
我想在NLTK中使用WordNet-Affect.我下载了WordNet Domains(3.2),其中包含一个文件绑定(我认为)WordNet synset偏移与一类情感.示例:
<noun-syn id="n#05574157" categ="weakness"/>
Run Code Online (Sandbox Code Playgroud)
我认为id属性是synset偏移量.然后我尝试了这段代码:
from nltk.corpus import wordnet as wn
idToSynset = {s.offset():s for s in wn.all_synsets()}
idToSynset[5574157]
Run Code Online (Sandbox Code Playgroud)
但是我收到了一个关键错误...... WordNet-Affect是为WordNet 1.6构建的,但当前版本的WordNet是3.0.这可能是synset偏移不再匹配的原因,不是吗?是否可以在NLTK中使用旧的WordNet版本?
我有以下模板:
*ngFor="let contact of contacts | async"
Run Code Online (Sandbox Code Playgroud)
在哪里:
contacts: Observable<any>;
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
ERROR Error: Cannot find a differ supporting object '[object Object]'
of type 'object'. NgFor only supports binding to Iterables such as Arrays.
Run Code Online (Sandbox Code Playgroud)
为什么需要 ngFor 异步管道Observable<any[]>而不是Observable<T>?
我使用 docker-compose 并尝试从 Web 容器连接到 postgres 数据库。我使用这个 URI:
postgresql://hola:hola@postgres/holadb
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
Connection refused
Is the server running on host "postgres" (172.18.0.2) and accepting
TCP/IP connections on port 5432?
Run Code Online (Sandbox Code Playgroud)
version: '2'
services:
web:
restart: always
build: ./web
expose:
- "8000"
volumes:
- /usr/src/app/project/static
command: /usr/local/bin/gunicorn -w 2 -b :8000 project:app
depends_on:
- postgres
postgres:
image: postgres:9.6
ports:
- "5432:5432"
environment:
- POSTGRES_USER=hola
- POSTGRES_PASSWORD=hola
- POSTGRES_DB=holadb
volumes:
- ./data/postgres:/var/lib/postgresql/data
Run Code Online (Sandbox Code Playgroud)
我在构建和运行之前删除 ./data/postgres 。
postgres_1 | The files belonging to this database …Run Code Online (Sandbox Code Playgroud) 我有以下模板AppComponent:
<div>
<div>
<router-outlet name="menu"></router-outlet>
</div>
<div>
<router-outlet name="main"></router-outlet>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我想在两种情况下使用这个模板:
/page1,我希望menuoutlet 包含Menu1Component和mainoutlet 包含Main1Component/page2,我希望menuoutlet 包含Menu2Component和mainoutlet 包含Main2Component我不明白儿童和命名插座是如何工作的。我在模块导入中的路由应该是什么?
我使用 Angular 5。
python ×3
angular ×2
elementtree ×1
encoding ×1
nltk ×1
postgresql ×1
pretty-print ×1
python-2.7 ×1
reactivex ×1
rxjs ×1
tostring ×1
tree ×1
wordnet ×1
xml ×1