Python: Trying to import a loop -
i new programming python , have difficulties importing loop created in order manipulate data.
specifically, in main script have following code:
wb=xw.workbook('/census/b05.xls') numbers=range(16,56) multiples8=range(16,56,8) data=list(set(numbers)-set(multiples8)) import loop1
after run command import loop1
, error:
file "<ipython-input-15-d5d478cf704f>", line 10, in <module> import loop1 file "loop1.py", line 8, in <module> x in set(data): nameerror: name 'data' not defined.
the loop1 script reads:
for x in set(data): if x-1 in set(multiples8): xw.range('sql results','l'+str(x-1)+':s'+str(x-1)).value=xw.range('sql results','d'+str(x)+':k'+str(x), atleast_2d=true).value else: if x-2 in set(multiples8): xw.range('sql results','t'+str(x-2)+':aa'+str(x-2)).value=xw.range('sql results','d'+str(x)+':k'+str(x), atleast_2d=true).value else: if x-3 in set(multiples8): xw.range('sql results','ab'+str(x-3)+':ai'+str(x-3)).value=xw.range('sql results','d'+str(x)+':k'+str(x), atleast_2d=true).value else: if x-4 in set(multiples8): xw.range('sql results','aj'+str(x-4)+':aq'+str(x-4)).value=xw.range('sql results','d'+str(x)+':k'+str(x), atleast_2d=true).value else: if x-5 in set(multiples8): xw.range('sql results','ar'+str(x-5)+':ay'+str(x-5)).value=xw.range('sql results','d'+str(x)+':k'+str(x), atleast_2d=true).value else: if x-6 in set(multiples8): xw.range('sql results','az'+str(x-6)+':bg'+str(x-6)).value=xw.range('sql results','d'+str(x)+':k'+str(x), atleast_2d=true).value else: if x-7 in set(multiples8): xw.range('sql results','bh'+str(x-7)+':bo'+str(x-7)).value=xw.range('sql results','d'+str(x)+':k'+str(x), atleast_2d=true).value
i appreciate help.
thanks.
try make method in loop1.py
accepts data
parameter, import that.
# loop1.py def my_loop(data): x in set(data): # stuff
then rest of code read
wb=xw.workbook('/census/b05.xls') numbers=range(16,56) multiples8=range(16,56,8) data=list(set(numbers)-set(multiples8)) loop1 import my_loop my_loop(data)
Comments
Post a Comment