2017-01-30 126 views
-2

我打电话的功能和a不从下面的功能保持值即mob_freturn编辑:从函数外部调用函数时不返回值吗?

a = get_mobile()

功能是:

def get_mobile(): 
    ws = sheet_select() 
    mobile = [] 
    mob_i = [] 
    mob_f = [] 
    mob_j = [] 

    for col in ws.iter_cols(): 
     for cell in col: 
      if cell.value == 'Mobile': 
       x=column_index_from_string(cell.column) 
       for row in ws.iter_rows(min_col = x, min_row = 2, max_col = x): 
        for cell in row: 
         if cell.value != None: 
          mobile.append(cell.value) 
    for i in mobile: 
     h = i 
     h = h.replace(" ", "") 
     h = h.replace("+(91)-", ",") 
     h = h.replace("+91", "") 
     h = h.replace("-", "") 
     mob_i.append(h) 

    for i in mob_i: 
     h = i 
     h = h.split(',') 
     mob_j.append(h) 
    mob_x = [item for sublist in mob_j for item in sublist] 
    for i in mob_x: 
     if i != '': 
      h = i 
      return mob_f.append(h) 

如果我使用的代码没有定义它作为function,它运行没有问题,我得到mob_f

我认为问题是return放置不正确。我尝试了很多组合并保持失败。昨天晚上这个相同的功能正在工作,我不明白我出错的地方。

+1

您可以包括Excel文件? – MYGz

+0

@MYGz,excel文件打开等运行平稳。如果您认为它是必需的,我会包括它。 – Sid

+0

Yeap。如果可以,请包括它。它提供了一个更好的理解。 – MYGz

回答

1

追加返回任何内容,我想你想的:

... 
for i in mob_x: 
    if i != '': 
     h = i 
     mob_f.append(h) 
return mob_f 
+0

谢谢。这固定了一切。我阅读文档,不知何故,得到的印象是,如果“返回”没有评估表达式,它将不会返回。 – Sid