从函数中返回数组,该函数从文件中读取

时间:2015-12-08 22:13:16

标签: python-2.7

我的第一个问题。 如何从正在读取我的txt文件的函数中获取保存在变量中的数组。 TY。

def reading(a):
    read = open(a, "r")
    rows = read.readlines()
    print(rows)
    read.close()
    return rows

reading("datoteka.txt")
print(reading)

基本上我把它作为输出: [' prvi red \ n',' 25 \ n',' treci red \ n',' cetvrti red'] [函数读取位于0x02B13B70>

1 个答案:

答案 0 :(得分:1)

您没有保存reading("datoteka.txt")的返回值,而是打印了函数对象reading。而不是最后两行,你想要:

data = reading("datoteka.txt")
print(data)
相关问题