Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
file handling
#1
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
Reply
#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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  File Handling not working properly TheLummen 8 566 Feb-17-2024, 07:47 PM
Last Post: TheLummen
  file handling Newbee question middlecope 2 745 Jan-18-2023, 03:09 PM
Last Post: middlecope
Star python exception handling handling .... with traceback mg24 3 1,216 Nov-09-2022, 07:29 PM
Last Post: Gribouillis
  File handling issue GiggsB 4 1,393 Mar-31-2022, 09:35 PM
Last Post: GiggsB
  How can I solve this file handling issue? GiggsB 17 3,421 Feb-14-2022, 04:37 AM
Last Post: GiggsB
  How to solve this file handling issue? GiggsB 3 1,633 Jan-10-2022, 09:36 AM
Last Post: Gribouillis
  File handling knollfinder 3 2,005 Jun-28-2020, 07:39 PM
Last Post: knollfinder
  delete file with handling 3Pinter 1 2,071 Oct-17-2019, 04:06 PM
Last Post: 3Pinter
  Help with file handling gonzo620 10 8,264 Sep-27-2018, 06:28 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020