Ok, so I'm trying my best to run this program, and I BELIEVE this function is the problem
urls = ('http://3.bp.blogspot.com/-SC-w7eTgpM0/URE9NsI_nuI/AAAAAAAAAGE/YmlWnimNuPM/s1600/7957178556_001939ffc5_z.jpg')
for addr in urls:
get_img_from_web(addr)
images, names = scan_dir()
lum_values = []
for i in range(256):
lum_values.append(i)
header = 'Jack Tompkins\n'+','.join(str(lum) for lum in lum_values)+'\n\n'
with open('p1TompkinsHistogram.csv', 'w') as f:
f.write(header)
for i, im in enumerate(images):
data = get_data(im)
path = names[i]
last_slash = path.rfind('/')
name = path[last_slash+1:]
f.write(name +',' + im.mode + ',' + data + ',')
h_r, h_g, h_b = get_histograms(im)
f.write(get_histogram_data(h_r, h_g, h_b) + '\n')
f.write(','.join(str(i) for i in h_r) + '\n')
f.write(','.join(str(i) for i in h_g) + '\n')
f.write(','.join(str(i) for i in h_b) + '\n')
`
This is the end of the error I get
raise ValueError("unknown url type: %r" % self.full_url)
ValueError:unknown url type: 'h'
Any thoughts?
Your problem is here:
urls = ('http://3.bp.blogspot.com/-SC-w7eTgpM0/URE9NsI_nuI/AAAAAAAAAGE/YmlWnimNuPM/s1600/7957178556_001939ffc5_z.jpg')
for addr in urls:
You meant to define urls
as a tuple, but it is in fact a single string. Because the parentheses don't include any commas, Python sees it as a single expression to be evaluated, much as (2 + 2)
is 4 and not a tuple containing 4. Strings are iterable and yield their constituent characters, so addr
is each character from the string. So you try to open h
, then t
, then t
, and so on. Or you would, if trying to open h
didn't give you an error.
The solution is to write urls
using a trailing comma, ensuring that Python sees it as a tuple, or to just use square brackets and make it a list. Or of course, use more than one item.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.