Python Forum
macron on top of uppercase letters
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
macron on top of uppercase letters
#1
I'm having problems displaying a macron on top of uppercase (or if you prefer, capital or mayuscule) letters (for Roman numerals) in Python 3.7.4

Hi, I’m starting to learn Python, so I would appreciate your explanations like you would explain things to a kid. I’m using Python 3.7.4.

I want to represent the number 4000 in Roman numbers by putting a macron (a long line like ¯ ) on top of the letters IV (as the macron multiplies the value by 1000), so 4000 would be represented by IV (4) with a macron on top, 5000 would be represented by V (5) with a macron on top, etc.

The problem I have is that I cannot make it happen in Python. I’ve looked for and seen many answers related, but when I try them, they don’t work in the simplest command.

For example, in my Python 3.7.4 Shell, I write the following command:

1) >>>
print(u'\u004C'+ u'\u00AF')


with the following output:



which is not what I want. I want the macron on top of the letter, not beside it.

I’ve tried switching the order of the unicode numbers of the letter and the combining character, and even using the join function as in:

2) >>>
print('\u0305'.join('L'))
with the following output:

L

and I guess almost any combination you may think of, but no result.

I find it quite curious, because if I want to put an acute accent or a small macron on top of the letter ‘e’, I have no trouble:

3) >>>
print('fue'+u'\u0301')
with the following output:

fué

4) >>>
print('fue'+u'\u0304')
with the following output:

fuē

But if I try it with the letters ‘M’ or even ‘m’, I cannot:

5) >>>
print('M'+u'\u0304')
with the following output:



6) >>>
print('m'+u'\u0304')
with the following output:



Even the following command:

7) >>>
print('fue'+u'\u0305')
produces the output:

fue̅

Please, is there somebody out there who can help me to write I, V, X, L, C, D and M with a long macron on top of them ('\u00AF' or '\u0305')?

Thanks in advance,

newbieAuggie2019

IMPORTANT EDIT!!!:

While previewing the post, to put a bit of colour to it, I found out that HERE, IN THIS FORUM, OPTIONS 5), 6) and 7) WORK, BUT NOT IN MY PYTHON 3.7.4 Shell. WHY IS THAT??? Huh

Let me try here this, then:

print(u'\u0049'+ u'\u0305' + u'\u0056'+ u'\u0305' + u'\u0058'+ u'\u0305' + u'\u004C'+ u'\u0305' + u'\u0043'+ u'\u0305' + u'\u0044'+ u'\u0305' + u'\u004D'+ u'\u0305')
Output:

I̅V̅X̅L̅C̅D̅M̅ Sad Confused Dodgy Angry

Okey, then. Maybe I should make the question in this way: What do I have to do to make it work in my Python 3.7.4 Shell??? Pray
newbieAuggie2019

"That's been one of my mantras - focus and simplicity. Simple can be harder than complex: You have to work hard to get your thinking clean to make it simple. But it's worth it in the end because once you get there, you can move mountains."
Steve Jobs
Reply
#2
Hi again!

As I saw on the message I posted before (see the important edit note in it), it seems that the problem is in the Python 3.7.4 Shell itself, as it does not display properly what it should (it shows letters and macrons separated, while here in this forum, they appear as they should). It is a bit worrying that the shell doesn't display properly these unicode characters. I spent many many hours wasted trying to find a mistake on the code, that there wasn't. I almost gave up at trying to improve the calculator with a button that converts numbers in base 10 to Roman numerals.

After so many hours wasted, and seeing here that it seems to be a problem with the shell, I went on with the calculator, and blimey! In the box taking the role of a display of the calculator (made with tkinter), the Roman numbers with the macrons on top work just fine (not like in the shell!!!)

In view of this, I'm going to set the question solved, although I still don't understand why it doesn't work in the shell...
newbieAuggie2019

"That's been one of my mantras - focus and simplicity. Simple can be harder than complex: You have to work hard to get your thinking clean to make it simple. But it's worth it in the end because once you get there, you can move mountains."
Steve Jobs
Reply
#3
I think it depends on the encoding the OS uses. From the Unicode HOWTO https://docs.python.org/3/howto/unicode.html
Quote:Python supports writing source code in UTF-8 by default, but you can use almost any encoding if you declare the encoding being used. This is done by including a special comment as either the first or second line of the source file:

#!/usr/bin/env python
# -*- coding: latin-1 -*-

u = 'abcdé'
print(ord(u[-1]))
Reply
#4
(Aug-21-2019, 03:31 AM)woooee Wrote: I think it depends on the encoding the OS uses. From the Unicode HOWTO https://docs.python.org/3/howto/unicode.html
Quote:Python supports writing source code in UTF-8 by default, but you can use almost any encoding if you declare the encoding being used. This is done by including a special comment as either the first or second line of the source file:

#!/usr/bin/env python
# -*- coding: latin-1 -*-

u = 'abcdé'
print(ord(u[-1]))

Hi!

Thanks for your prompt (no pun intended Big Grin ) answer!

It might be due to the OS... I have no idea. I'm using Windows 10, 64 bits.

From your attached image, it seems a bit too complicated for my newbie status. I can only partially understand that somehow, you are using (in the example) the (sub)set of latin-1 characters, that you have a string named 'u' and that you made a statement of some sort for printing it, but I would have no idea about the bin, ord (maybe ordering?) or the -1 thingies...

The print command I used in my calculator program (adding the string of the uppercase letter and the combining character of the macron), works just fine there, although not in the Python 3.7.4 Shell... Before trying it directly in the application, I was really frustrated with the solutions provided in many places I checked. I thought that I was mistyping something, as they were not doing in the shell what they supposedly had to do, so I started to copy and paste those commands to my shell. When copying and pasting was not sorting the problem out either, I started to think that maybe the problem was that those solutions were for Python 2 and not for Python 3, so I concentrated on those posts specific to Python 3...

Anyway, enough of my rumblings... Thanks again for your time and help!
newbieAuggie2019

"That's been one of my mantras - focus and simplicity. Simple can be harder than complex: You have to work hard to get your thinking clean to make it simple. But it's worth it in the end because once you get there, you can move mountains."
Steve Jobs
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  AttributeError: module 'string' has no attribute 'uppercase' Anldra12 10 10,109 Apr-23-2021, 05:30 PM
Last Post: ibreeden
  Python uppercase conversion conditions Jaypeng 7 2,891 Apr-29-2020, 11:24 AM
Last Post: jefsummers
  'True' if 'string' has at least one uppercase letter ClassicalSoul 1 3,288 Feb-28-2019, 12:08 PM
Last Post: buran
  check if value of passed variable has uppercase characters in it. wfsteadman 3 3,194 Sep-01-2017, 05:52 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

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