Skip to main content

Can unicode characters be programatically defined in python 3.7? [Resolved]

I'm trying to write a python 3.7 function that prints the unicode character for a playing card (using wikipedia as a reference).

Each of the unicode character is a string that can be represented as '\U1F0{SUIT_ID}{VALUE_ID}'. For instance, '\U1F0A1' is the ace of spades ??.

My code is

def print_card(suit_id, value_id):
    print(f'\U1F0{suit_id}{value_id}')

Theoretically, the command print_card('A', '1') would then print the ace of spades. The command print_card('C', 'D') would print the queen of diamonds.

However, attempting to define this function results in the following error:

  File "", line 2
    print(f'\U1F0{suit_id}{value_id}')
         ^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 0-4: truncated \UXXXXXXXX escape

What's wrong here?


Question Credit: Brian Fitzpatrick
Question Reference
Asked July 20, 2019
Posted Under: Unix Linux
12 views
1 Answers

Your Answer
D:\Adnan\Candoerz\CandoProject\vQA