Closed. This question is off-topic。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
                        
                        2个月前关闭。
                                                                                            
                
        
我是python环境的新手,目前正在从事ml项目。当使用readlines函数读取CSV文件时,我得到“ tuple没有属性readlines”。请有人帮我.....

我的代码是

data_file=(r"C:\Users\Sury teja\temp\mnist_train.csv","r")
print(data_file.readlines())


错误是

AttributeError: 'tuple' object has no attribute 'readlines'

最佳答案

您错过了open

data_file = open(r"C:\Users\Sury teja\temp\mnist_train.csv", "r")
print(data_file.readlines())


在您编写的代码中,data_file只是一个元组,看起来像这样:

('C:\\Users\\Sury teja\\temp\\mnist_train.csv', 'r')

关于python - AttributeError:'tuple'对象没有属性'readlines',我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59436218/

10-10 19:40