我刚开始使用Twig,我正在尝试建立一个注册表单.要添加密码/重新输入密码字段,我使用"重复"文件类型:
->add('password', 'repeated', array(
'type' => 'password',
'invalid_message' => 'Passwords have to be equal.',
'first_name' => 'Password',
'second_name' => 'Re-enter password',
));
Run Code Online (Sandbox Code Playgroud)
按预期工作.但问题是,我想在表单中添加一些自定义类等.所以我的模板看起来像这样:
<form action="{{ path('register') }}" method="post" {{ form_enctype(form) }}>
{{ form_errors(form) }}
{{ form_errors(form.username) }}
<div class="form-field">
{{ form_label(form.username, null, { 'attr': {'class': 'form-label'} }) }}
{{ form_widget(form.username, { 'attr': {'class': 'form-input'} }) }}
</div>
{{ form_errors(form.email) }}
<div class="form-field">
{{ form_label(form.email, null, { 'attr': {'class': 'form-label'} }) }}
{{ form_widget(form.email, { 'attr': {'class': 'form-input'} }) }}
</div> …Run Code Online (Sandbox Code Playgroud) 对于我的项目,我需要使用透明背景显示图像.我制作了一些具有透明背景的.png图像(为了检查这一点,我在Photoshop中打开它们).现在我有一个扩展PictureBox的类:
class Foo : PictureBox
{
public Foo(int argument)
: base()
{
Console.WriteLine(argument);//different in the real application of course.
//MyProject.Properties.Resources.TRANSPARENCYTEST.MakeTransparent(MyProject.Properties.Resources.TRANSPARENCYTEST.GetPixel(1,1)); //<-- also tried this
this.Image = MyProject.Properties.Resources.TRANSPARENCYTEST;
((Bitmap)this.Image).MakeTransparent(((Bitmap)this.Image).GetPixel(1, 1));
this.SizeMode = PictureBoxSizeMode.StretchImage;
this.BackColor = System.Drawing.Color.Transparent;
}
}
Run Code Online (Sandbox Code Playgroud)
然而,这只是显示带有白色背景的图片框,我似乎无法使其与透明背景一起工作.
我想读一些非常大的文件(确切地说:谷歌ngram 1字数据集)并计算一个字符出现的次数.现在我写了这个脚本:
import fileinput
files = ['../../datasets/googlebooks-eng-all-1gram-20090715-%i.csv' % value for value in range(0,9)]
charcounts = {}
lastfile = ''
for line in fileinput.input(files):
line = line.strip()
data = line.split('\t')
for character in list(data[0]):
if (not character in charcounts):
charcounts[character] = 0
charcounts[character] += int(data[1])
if (fileinput.filename() is not lastfile):
print(fileinput.filename())
lastfile = fileinput.filename()
if(fileinput.filelineno() % 100000 == 0):
print(fileinput.filelineno())
print(charcounts)
Run Code Online (Sandbox Code Playgroud)
哪个工作正常,直到达到约.第一个文件的700.000行,然后我得到这个错误:
../../datasets/googlebooks-eng-all-1gram-20090715-0.csv
100000
200000
300000
400000
500000
600000
700000
Traceback (most recent call last):
File "charactercounter.py", line 5, in <module> …Run Code Online (Sandbox Code Playgroud)