Python Forum
Python equivalent to sed [solved]
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python equivalent to sed [solved]
#2
(Sep-24-2018, 02:32 PM)cygnus_X1 Wrote: time ="14:00"
content = os.popen("sed -n '/time/, +3p' mon").read()


It would be a crazy world indeed, if all your variables were just injected into strings. You need to specifically let python know in some way that you expect interpolation to be taking place:
>>> time = "14:00"
>>> "spam /time/ eggs"
'spam /time/ eggs'
>>> "spam /{0}/ eggs".format(time)
'spam /14:00/ eggs'
>>> f"spam /{time}/ eggs"
'spam /14:00/ eggs'
Reply


Messages In This Thread
Python equivalent to sed [solved] - by cygnus_X1 - Sep-24-2018, 02:32 PM
RE: Python equivalent to sed - by nilamo - Sep-24-2018, 03:08 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Equivalent Python code from VBA Mishal0488 4 1,030 May-02-2024, 10:17 PM
Last Post: DeaD_EyE
  Python C++ Template Equivalent deanhystad 7 3,458 May-04-2021, 07:45 PM
Last Post: deanhystad
  Hi Guys, please help me to write SAS macro parameter equivalent code in Python Manohar9589 2 2,639 Jun-14-2020, 05:07 PM
Last Post: Larz60+
  python equivalent to MATLAB xcov chai0404 2 3,921 Apr-02-2020, 10:29 PM
Last Post: chai0404
  Python equivalent of Matlab code kwokmaster 1 3,501 Mar-25-2020, 10:14 PM
Last Post: j.crater
  Equivalent of 'bwareafilt' for Python Mighty 1 3,646 Feb-05-2020, 10:32 PM
Last Post: Marbelous
  Convert a mongo db scrip to python equivalent Herath 1 2,222 Aug-20-2019, 02:28 PM
Last Post: fishhook
  SAS Equivalent of Macro variable in Python AI_ML_Neophyte 4 11,748 Mar-29-2019, 08:14 AM
Last Post: FelixS
  equivalent commands saeed_balk 2 2,755 Sep-23-2018, 05:44 AM
Last Post: saeed_balk
  Python "read -n" equivalent? rhubarbpieguy 8 6,837 Jan-24-2017, 12:51 PM
Last Post: rhubarbpieguy

Forum Jump:

User Panel Messages

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