Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. def pi_changehostname(oldname,newname):
  2. # hostname
  3. with fileinput.FileInput("/etc/hostname", inplace=True, backup='.bak') as file:
  4. for line in file:
  5. print(line.replace(oldname,newname), end='')
  6. if oldname in line:
  7. break
  8. # hosts
  9. with fileinput.FileInput("/etc/hosts", inplace=True, backup='.bak') as file:
  10. for line in file:
  11. print(line.replace(oldname,newname), end='')
  12. if oldname in line:
  13. break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement