Python Forum
How to remove char from string??
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to remove char from string??
Good morning....

I have a string being returned '@S0601\r\n'.....I am trying to remove the @ at the front using .replace and .lstrip but to no avail....Below is my lastest code try with error that I seem to get on both .replace or .lstrip....Can someone tell me what I am doing wrong?

Traceback (most recent call last): File "", line 16, in <module> print(('@')) TypeError: a bytes-like object is required, not 'str'
(Sep-30-2020, 01:17 PM)ridgerunnersjw Wrote: I have a string being returned '@S0601\r\n'
I guess it's not a str object but bytes-like object, given that you have - we don't know what s is...

foo = b'@S0601\r\n'
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Thank you....Yes it is byte

adding the b in .lstrip(b'@') seemed to solve it

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to replace on char with another in a string? korenron 3 719 Dec-03-2020, 07:37 AM
Last Post: korenron
  Remove from end of string up to and including some character lbtdne 2 902 May-17-2020, 09:24 AM
Last Post: menator01
  Remove escape characters / Unicode characters from string DreamingInsanity 5 4,277 May-15-2020, 01:37 PM
Last Post: snippsat
  Highlight and remove specific string of text itsalmade 5 1,542 Dec-11-2019, 11:58 PM
Last Post: micseydel
  Sum char word dictionary RavCOder 3 1,020 Nov-08-2019, 01:32 PM
Last Post: perfringo
  Cannot Remove the Double Quotes on a Certain Word (String) Python BeautifulSoup soothsayerpg 5 4,174 Oct-27-2019, 09:53 AM
Last Post: newbieAuggie2019
  with input remove a string from the list konsular 3 1,160 Oct-12-2019, 09:25 AM
Last Post: konsular
  The use of escape char \ hishamzero1 2 1,156 Aug-12-2019, 10:20 PM
Last Post: hishamzero1
  remove string character from url jacklee26 10 3,080 Mar-25-2019, 03:56 PM
Last Post: Larz60+
  First non-repeating char and some errors. blackknite 1 1,021 Jan-06-2019, 02:19 PM
Last Post: stullis

Forum Jump:

User Panel Messages

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