0

I am an R user who is increasing my knowledge of Python, and I wondered if Python is best understood as using Message Passing Object Oriented (MPOO) syntax, or like R, Generic Functional Object Oriented (GFOO) syntax?

I encouraged the MPOO and GFOO concepts in Hadley Wickham's 2010 Mutable Objects in R. The red font is my text. Red font is Rick Pack's text - MPOO vs. GFOO

The first question might be how to change the first lines of text in an opened file, in one line like the above, in Python. Examples I have found use multiple lines, such as what constructs the function found in this SO answer.

def replace_line(file_name, line_num, text):
    lines = open(file_name, 'r').readlines()
    lines[line_num] = text
    out = open(file_name, 'w')
    out.writelines(lines)
    out. Close()

replace_line('stats.txt', 0, 'Mage')
Rick Pack
  • 1,044
  • 10
  • 20

0 Answers0