Skip to content Skip to sidebar Skip to footer

How To Tell Python Not To Interpret Hash Symbol As Comment?

I wanted to turn on and turn off crone job from os.system command written in python. Basically, using sed command to comment/uncomment the crontab line to control the job schedule.

Solution 1:

You have no issue with the hash symbol but your quoting is not proper. Try this:

os.system(r"crontab -l | sed '/^\*.*heightSQL.py/s/^/#/' | crontab -")

And btw: Are you sure crontab -l produces proper output while crontab - is already running? I'm not. But that's beside the point here.

Post a Comment for "How To Tell Python Not To Interpret Hash Symbol As Comment?"