Most efficient way to open a file and read the lines?

I've got this:

vlgaStream = open('vlgaChcWaves.txt', 'r+')
vlgaBuffer = vlgaStream.readlines()
vlgaStream.close()

But need a way to directly and efficiently read all of the lines from a file into a buffer?

Answers


Iterating over a file yields lines.

with open('vlgaChcWaves.txt', 'r+') as vlgaStream:
  for line in vlgaStream:
    dosomethingwith(line)

Need Your Help

Alternatives to nth-last-of-type and nth-last-child in nokogiri gem

ruby css3 nokogiri

i'm using nokogiri gem, i want to extract the last number for a pagination (4) with :nth-last-of-type(3) or nth-last-child(3) but show 0 in my ruby test.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.