Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Print string after decode
#1
Hallo,

I have a small programm. In a function I receive date an decode it back to utf-8
the function returns the data:

def reliable_recv():
    data = ""
    while True: 
        try:
            data = data + target.recv(1024).decode('utf-8')
            return json.loads(data)
        except ValueError:
            continue
if I print the data it's printed like that:

b'this ist the text\nthis is more text'

If I try to

result = reliable_recv()
print(result.decode()) 
I get the error
Error:
AttributeError: 'str' object has no attribute 'decode'
so my question:
How can I print my data?

Thank you for your help

Martin
Reply


Messages In This Thread
Print string after decode - by martinzeifang - Jan-01-2020, 10:04 PM
RE: Print string after decode - by buran - Jan-02-2020, 10:16 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Decode string ? JohnnyCoffee 1 832 Jan-11-2023, 12:29 AM
Last Post: bowlofred
  Remove a space between a string and variable in print sie 5 1,801 Jul-27-2022, 02:36 PM
Last Post: deanhystad
  Can you print a string variable to printer hammer 2 1,963 Apr-30-2022, 11:48 PM
Last Post: hammer
  Print first day of the week as string in date format MyerzzD 2 2,033 Sep-29-2021, 06:43 AM
Last Post: MyerzzD
  code decode, string, image ... teckow 2 2,067 Aug-20-2021, 07:02 PM
Last Post: teckow
  if a string has a digit - print tester_V 2 2,155 Jan-16-2021, 04:48 AM
Last Post: tester_V
  How to print string multiple times on new line ace19887 7 5,781 Sep-30-2020, 02:53 PM
Last Post: buran
  how to encode and decode same value absolut 2 2,361 Sep-08-2020, 09:46 AM
Last Post: TomToad
  Print a certain string only the first time it appears in a test file buttercup 5 2,802 Jul-23-2020, 01:30 PM
Last Post: palladium
  How to print string multiple times separated by delimiter Mekala 1 1,914 May-23-2020, 09:21 AM
Last Post: Yoriz

Forum Jump:

User Panel Messages

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