Python Forum
Subprocess - get only first few lines of stdout
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Subprocess - get only first few lines of stdout
#4
(May-30-2017, 07:26 PM)j.crater Wrote: How did you know/decide to use decode('utf-8'), and not 'ascii' for example?
Python 3 represents strings as Unicode,and will not take in data without encoding(will be bytes string if try).
If have bytes,we can decode them to a Unicode string using UTF-8.
>>> b = b'hello'
>>> type(b)
<class 'bytes'>
>>> c = b.decode('utf-8') # Just b.decode() will do the same
>>> c
'hello'
>>> type(c)
<class 'str'>
Unicode was one biggest changes moving from Python 2 to Python 3.
Python 3 has UTF-8 as default encoding,Python 2 had ASCII as default encoding.
Reply


Messages In This Thread
RE: Subprocess - get only first few lines of stdout - by snippsat - May-30-2017, 08:12 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [subprocess] Why stdout sent to stderr? Winfried 3 526 Jan-26-2024, 07:26 PM
Last Post: snippsat
  Performance options for sys.stdout.writelines dgrunwal 11 3,207 Aug-23-2022, 10:32 PM
Last Post: Pedroski55
  Did subprocess.Popen() causes main routine to pause stdout? liudr 4 3,693 May-04-2021, 08:58 PM
Last Post: liudr
  changing stdout and stderr Skaperen 4 2,725 Dec-02-2020, 08:58 PM
Last Post: Skaperen
  Get stdout of a running process yok0 0 3,067 Aug-20-2020, 10:12 AM
Last Post: yok0
  Iterate 2 large text files across lines and replace lines in second file medatib531 13 6,011 Aug-10-2020, 11:01 PM
Last Post: medatib531
  will with sys.stdout as f: close sys.stdout? Skaperen 9 4,677 Nov-03-2019, 07:57 AM
Last Post: Gribouillis
  Add stdout to text file maxtimbo 3 3,198 Feb-05-2019, 12:53 AM
Last Post: maxtimbo
  stdout buffering Skaperen 5 4,785 Jun-12-2018, 06:14 AM
Last Post: Skaperen
  stdout Skaperen 0 2,668 Mar-19-2018, 01:23 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

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