readlines

Collect all not in using Ruby

I have this small snipped of code. I don't know ruby and I think this is a great opportunity to apply it. I want to print all the lines in file e which are not in file c. Each line is a number. This is what I've got: e = File.new('e').readlines c = File.new('c').readlines x = e.collect do |item| c.include?( item ) ? "" : item...

vi input mode in command line Matlab?

I have these lines in my ~/.inputrc: set editing-mode vi set keymap vi This allows me to use vi keybindings in every program that uses GNU readlines for text input. Examples: python, irb, sftp, bash, sqlite3, and so on. It makes working with a command line a breeze. Matlab doesn't use readlines, but vi keybindings would be amazing...

ungetc in Python

Some file read (readlines()) functions in Python copy the file contents to memory (as a list) I need to process a file that's too large to be copied in memory and as such need to use a file pointer (to access the file one byte at a time) -- as in C getc(). The additional requirement I have is that I'd like to rewind the file pointe...

Does readlines() return a list or an iterator in Python 3?

I've read in "Dive into Python 3" that "The readlines() method now returns an iterator, so it is just as efficient as xreadlines() was in Python 2". See here: http://diveintopython3.org/porting-code-to-python-3-with-2to3.html . I'm not sure that it's true because they don't mention it here: http://docs.python.org/release/3.0.1/whatsnew/3...

What substitutes xreadlines() in Python 3?

In Python 2, file objects had an xreadlines() method which returned an iterator that would read the file one line at a time. In Python 3, the xreadlines() method no longer exists, and realines() still returns a list (not an iterator). Does Python 3 has something similar to xreadlines()? I know I can do for line in f: instead of for ...

Ignore last \n when using readlines with python

Hi, I have a file I read from that looks like: 1 value1 2 value2 3 value3 The file may or may not have a trailing \n in the last line. The code I'm using works great, but if there is an trailing \n it fails. Whats the best way to catch this? My code for reference: r=open(sys.argv[1], 'r'); for line in r.readlines(): ref...