Python Forum

Full Version: file handling
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
import os, sys
from subprocess import Popen,PIPE
myfs=input("myfs=")
try:
#grep myfs /etc/fstab
  p1 = Popen(['grep',myfs,'/etc/fstab'], stdout=PIPE)
  p1.communicate()[0].decode('utf-8').split()[1]
  p1.stdout.close()
except IndexError:
  with open("/etc/fstab", "a+") as f:
      f.write(`df -h|grep myfs|awk '{print $1,$6}'` + ext4 + defaults + 1 + 2)
      f.close()
------------------------
i am getting an error like this
Error:
[root@localhost mylvm]# python test9.py File "test9.py", line 11 f.write(`df -h|grep myfs|awk '{print $1,$6}'` + ext4 + defaults + 1 + 2) ^ SyntaxError: invalid syntax
i need to update like this in /etc/fstab

/dev/mapper/vgdata-lvmyfssiva /myfs/siva ext4 defaults 1 2
Please use Python tags around your code. Otherwise we lose indentation. For example, in this case the answer could be as simple as that you need to indent line 11. Can't tell.
Also you don't need to close f if you are using the with clause.