Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
converting backslash codes
#5
warning: very old thread

(Oct-18-2016, 03:08 PM)nilamo Wrote: You mean marking the string as 'raw' by putting "r" in front of it?
>>> x = '\\n'
>>> y = r'\n'
>>> x == y
True

no.

i mean converting the kinds of backslash codes you might see expressed in source code, from being in actual strings to the binary result.

if i have code that reads input into a string and i type in a backslash and an 'r' i will have 2 characters, a backslash and an 'r'. source code to get exactly the same thing would be '\r'. but source code is merely explaining this; not how it is actually gotten. wherever those 2 characters come from, i want to apply the same effect as you see in source code:
    foo = '\r'
in the above case the variable named foo will end up with just 1 character. what i want (and have coded) is a function to do that.

my struggle has been explaining what i am doing. the "raw" concept is not what i am doing, although a reference to it might explain it to you. i'm thinking of it as an encoding.

perhaps this code would explain better what i have and what i want that can do the conversion
   abc = chr(92)
   xyz = chr(114)
   woot = convert(abc+xyz)
   print(ord(woot))
this would print out 13. what i want is that convert() function in a form that supports all such control codes.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Messages In This Thread
converting backslash codes - by Skaperen - Oct-14-2016, 04:49 AM
RE: converting backslash codes - by Mekire - Oct-14-2016, 05:17 AM
RE: converting backslash codes - by Skaperen - Oct-14-2016, 08:59 AM
RE: converting backslash codes - by nilamo - Oct-18-2016, 03:08 PM
RE: converting backslash codes - by Skaperen - Apr-21-2018, 04:07 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  change backslash into slash in a path paul18fr 7 3,050 Jul-21-2022, 04:26 PM
Last Post: deanhystad
  Deny backslash using regex JohnnyCoffee 1 1,787 Mar-18-2020, 10:21 PM
Last Post: snippsat
  Reading and writing Windows filepath without treating backslash as escape character Dangthrimble 3 3,694 Dec-18-2017, 06:18 PM
Last Post: DeaD_EyE
  Replace Single Backslash with Double Backslash in python saswatidas437 2 33,917 Mar-19-2017, 10:48 AM
Last Post: Ofnuts

Forum Jump:

User Panel Messages

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