小编teu*_*oon的帖子

从Twig中的Symfony 2自定义渲染"重复"字段

我刚开始使用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)

symfony twig

30
推荐指数
3
解决办法
2万
查看次数

C#Picturebox透明背景似乎不起作用

对于我的项目,我需要使用透明背景显示图像.我制作了一些具有透明背景的.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)

然而,这只是显示带有白色背景的图片框,我似乎无法使其与透明背景一起工作.

c# transparency picturebox

18
推荐指数
3
解决办法
9万
查看次数

Python使用utf-8编码逐行读取大文件

我想读一些非常大的文件(确切地说:谷歌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)

python file-io dataset

9
推荐指数
1
解决办法
1万
查看次数

标签 统计

c# ×1

dataset ×1

file-io ×1

picturebox ×1

python ×1

symfony ×1

transparency ×1

twig ×1