我知道这是介绍性的东西,但我不是程序员,而且我已经做了好几天了,而且我要打败我的狗......
我有一个带有图像名和属性的csv文件,即
12-123.png中,M
12-124.png,F
12-241.phg中,M
...
我试图将它们移动到相应的目录中," orig_png / m /"或者" orig_png / f /",基于第二行数据," M"或" F"。我已经尝试过我在网上发现的每一个剧本,并且总是有一些问题,所以我修改了一个接近我需要的剧本,我能理解发生了什么......我知道我和#39; ve可能会破坏这个,但这就是我所拥有的(大多数PRINT声明让我看到发生了什么):
# Import csv
import csv
# Import os
import os, shutil
# Main Function
# def main():
# Open dataset file
# dataset = open('database_png.csv', newline='')
dataset = open('database_png.csv')
path = "home/darryl/Machine_Learning/ribs/200x200/orig_png/"
moveto1 = "home/darryl/Machine_Learning/ribs/200x200/orig_png/m/"
moveto2 = "home/darryl/Machine_Learning/ribs/200x200/orig_png/f/"
# Initialize csvreader for dataset
reader = csv.reader(dataset)
# Read data from reader
data = list(reader)
# Variables for progress counter
lines = len(data)
i = 0
# Analyze data in dataset
for row in data:
# Assign image name and state to variables
image = row[0]
state = row[1]
# Print image information
print image
print state
print('({}/{}) Processing image ({}): {}'.format(i + 1, lines, state, image))
# Increment i
i += 1
print moveto1
# Determine action to perform
if state is "M":
print moveto1+image
src = path+image
dst = moveto1+image
dst1 = moveto2+image
shutil.move(src,dst)
elif state is "F"
shutil.move(src,dst1)
主要是错误消息, IOError:[Errno 2]没有这样的文件或目录:&#39; home / darryl / Machine_Learning / ribs / 200x200 / orig_png / 12-094.png&#39;,当它看起来像它是正确的,并且< / p>
文件&#34; move4.py&#34;,第39行 埃利夫州是&#34; F&#34; ^ SyntaxError:语法无效
如果有人可以通过一种简单的方式来帮助我(我知道我已经让这个变得更加复杂),我会非常感激,我甚至可能在这个过程中学到一些东西!
注意:这是减少文件,但仍然是错误。我该如何解决这个问题?
import csv
import os, shutil
dataset = open('database_png.csv')
path = "/home/darryl/Machine_Learning/ribs/200x200/orig_png/"
moveto = "/home/darryl/Machine_Learning/ribs/200x200/orig_png/m/"
reader = csv.reader(dataset)
data = list(reader)
lines = len(data)
i = 0
for row in data:
image = row[0]
state = row[1]
i += 1
if state is "M":
src = path+image
dst = moveto+image
shutil.move(src,dst)