Python Forum
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
octal instead of hex
#3
How about:
astring = 'Hello.'
for c in astring:
   print('\\{:03o}'.format(ord(c)), end='')
print()
results:
Output:
/110/145/154/154/157/056
or use list comprehension
[print('\\{:03o}'.format(ord(c)), end='') for c in astring]
Reply


Messages In This Thread
octal instead of hex - by Skaperen - Jun-05-2017, 03:25 AM
RE: octal instead of hex - by rrashkin - Jun-05-2017, 01:30 PM
RE: octal instead of hex - by Larz60+ - Jun-05-2017, 04:18 PM
RE: octal instead of hex - by wavic - Jun-05-2017, 08:00 PM
RE: octal instead of hex - by Skaperen - Jun-06-2017, 02:00 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  regex octal replace chaz_sliger 1 2,929 Sep-06-2018, 01:21 AM
Last Post: scidam
  octal encoding Skaperen 4 4,048 Dec-06-2017, 02:53 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