can I do this in a loop, by producing the file name from the name of the array to store ?
ab = array.array('B', map( operator.xor, a, b ) )
f1 = open('ab', 'wb')
ab.tofile(f1)
f1.close
ac = array.array('B', map( operator.xor, a, c ) )
f1 = open('ac', 'wb')
ac.tofile(f1)
f1.close
ad = array.array('B', map( operator.xor, a, d ) )
f1 = open('ad', 'wb')
ad.tofile(f1)
f1.close
ae = array.array('B', map( operator.xor, a, e ) )
f1 = open('ae', 'wb')
ae.tofile(f1)
f1.close
af = array.array('B', map( operator.xor, a, f ) )
f1 = open('af', 'wb')
af.tofile(f1)
f1.close
thank you for any help!
Facundo Casco
10.7k8 gold badges45 silver badges66 bronze badges
2 Answers 2
Assuming you are storing all the intermediate arrays for a reason.
A={}
for v,x in zip((b,c,d,e,f),'bcdef'):
fname = 'a'+x
A[fname] = (array.array('B', map( operator.xor, a, v ) ))
f1 = open(fname, 'wb')
A[fname].tofile(f1)
f1.close
Or something like this should work too
A={}
for x in 'bcdef':
fname = 'a'+x
A[fname] = (array.array('B', map(a.__xor__, vars()[x] ) ))
f1 = open(fname, 'wb')
A[fname].tofile(f1)
f1.close
answered Mar 10, 2010 at 21:23
John La Rooy
306k54 gold badges379 silver badges514 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
Mark Dickinson
Doesn't this just compute
map(operator.xor, a, b) repeatedly?John La Rooy
@Mark Dickinson, yes it was. I fixed it now :)
One way is to have a,b,c,d,e,f in a dict. Then you'd just do something like:
for x in 'bcdef':
t = array.array('B', map( operator.xor, mydict['a'], mydict[x] ) )
f1 = open(''.join('a',x),'wb')
t.tofile(f1)
f1.close()
answered Mar 10, 2010 at 21:27
Justin Peel
47.1k6 gold badges62 silver badges81 bronze badges
3 Comments
Ian Clelland
They are in a dict -- it's called locals() :)
Justin Peel
@Ian Yes, but some people don't like to use that because it is kind of a hack.
Justin Peel
The way I was doing it was to have mydict['a'] return the array a. You can use locals() by just replacing mydict with locals().
Explore related questions
See similar questions with these tags.
lang-py