怎样才能增加双重形象?

2024-04-20 05:28:33 发布

您现在位置:Python中文网/ 问答频道 /正文

不知道我做错了什么。我得到的错误是:

let images = [UIImage(named: "Image1")!, UIImage(named: "Image2")!, UIImage(named: "Image3")!]
let yPositions = [0, 204, 693.5, 1186.5]

for (index, image) in images.enumerate() {
    let imageView = UIImageView(image: image)

    if let yPosition = yPositions[index] {
        imageView.frame = CGRectMake(0, CGFloat(yPosition), 375, 395)
    }
}

Tags: inimageforindex错误namedimageslet
1条回答
网友
1楼 · 发布于 2024-04-20 05:28:33

这应该更接近你的意图。你知道吗

将数据读入dict并计算发生次数:

def count_authors(file_name):
     invert = {}
     for k, v in load_library(file_name).items():
        invert[v] = invert.get(v, 0) + 1
     return invert

然后将数据写入另一个文件:

def write_authors_counts(counts, file_name):
    with open(file_name, 'w') as fobj:
        for name, count in counts.items():
            fobj.write('{}: {}\n'.format(name, count)

将两个功能放在一起:

def report_author_counts(lib_fpath, rep_filepath):
    counts = count_authors(lib_fpath)
    write_authors_counts(counts, rep_filepath))

调用函数:

write_authors_counts('file.txt', 'report.txt'))

相关问题 更多 >