我正在尝试创建一个自定义元素polymer-element,但我无法完成@CustomTag工作.我的dart文件(my_element.dart)看起来像这样:
@HtmlImport('my_element.html')
library projects.projectFolder.layout;
import 'package:polymer/polymer.dart';
import 'dart:html';
@CustomTag('my-element')
class MyElement extends PolymerElement {
@published String caption;
MyElement.created() : super.created();
}
Run Code Online (Sandbox Code Playgroud)
我的html文件(my_element.html)看起来像这样:
<link rel="import" href="../../../../packages/polymer/polymer.html">
<polymer-element name="my-element">
<template>
<link rel="stylesheet" href="my_element.css">
<core-toolbar>
<h1>{{ caption }}</h1>
</core-toolbar>
</template>
<script type="application/dart" src="../my_element.dart"></script>
</polymer-element>
Run Code Online (Sandbox Code Playgroud)
问题是Chrome控制台继续打印以下错误:
No elements registered in a while, but still waiting on 1 elements to be registered. Check that you have a class with an @CustomTag annotation for …Run Code Online (Sandbox Code Playgroud) 在呈现HTML之后,我希望从网站上看到所有文本.我在Python中使用Scrapy框架.随着xpath('//body//text()')我能够得到它,但与HTML标记,而我只想要的文字.对此有何解决方案?谢谢 !
我有一个包含字符串列表的输入文件.
我从第二行开始迭代每四行.
从这些行中的每一行开始,我从第一个和最后6个字符创建一个新字符串,并且仅当新字符串是唯一的时才将其放在输出文件中.
我写的代码可以实现这一点,但是我正在使用非常大的深度排序文件,并且已经运行了一天并且没有取得多大进展.所以我正在寻找任何建议,如果可能的话,这样做会更快.谢谢.
def method():
target = open(output_file, 'w')
with open(input_file, 'r') as f:
lineCharsList = []
for line in f:
#Make string from first and last 6 characters of a line
lineChars = line[0:6]+line[145:151]
if not (lineChars in lineCharsList):
lineCharsList.append(lineChars)
target.write(lineChars + '\n') #If string is unique, write to output file
for skip in range(3): #Used to step through four lines at a time
try:
check = line #Check for additional lines in file
next(f)
except StopIteration:
break …Run Code Online (Sandbox Code Playgroud) 我想在通过Vagrant运行的来宾计算机上添加一些别名.我的配置程序是Ansible,如果我可以在playbook中添加带有任务的别名,那将会很棒,我宁愿不必修改我的Vagrantfile.
我已经尝试了这两个角色:
command: alias serve='pub serve --hostname=0.0.0.0'
shell: "alias serve='pub serve --hostname=0.0.0.0'"
但它们都没有奏效.第一个提出了一个例外,我认为它来自''.第二个根本就不添加别名.
让我们Instrument与三个功能的一类piano(self),guitar(self)和trumpet(self).该类还有一个play(self)函数,它将根据类中表示的工具调用正确的方法.
有没有一种方法,只有一个类Instrument(即没有其他抽象类),来定义调用play方法时应该调用的方法?
换句话说,有没有办法做到以下几点:
my_piano = Instrument(piano)
my_piano.play() # calls piano(self) method
my_guitar = Instrument(guitar)
my_guitar.play() # calls guitar(self) method
my_trumpet = Instrument(trumpet)
my_trumpet.play() # calls trumpet(self) method
Run Code Online (Sandbox Code Playgroud)
一个相当简单的方法,但不是很干净,是在构造函数中放置一个变量,然后在play方法中放入很多条件,如下所示:
def Instrument(object):
def __init__(self, instrument_type):
self.instrument_type = instrument_type
def play(self):
if instrument_type == 0:
self.piano()
elif instrument_type == 1:
self.guitar()
elif instrument_type == 2:
self.trumpet()
Run Code Online (Sandbox Code Playgroud)
这样做的正确方法是拥有一个Instrument类,然后是三个Piano,Guitar以及Trumpet继承自的类Instrument.但是,对于我的需要,这将使事情变得复杂. …