0

I have a strange issue in python (3.6.1):

a = 3 
f"""a= {a}""" # works

But this does not on the Cloudera Data Science Workbench (a unix system):

f"""a=
{a}"""  # error

Engine, line 1
"
  ^
SyntaxError: EOL while scanning string literal

On Windows I cannot recreate the problem and it did not use to be a problem on CDSW either. Has anyone had a similar problem or could point me towards what might cause such a problem?


Interestingly, this also works:

(f"""a=
{a}""")

To follow up on the comments:

my_frstring= f"""hello 
world {a}"""
for c in my_frstring:print(name(c))
LATIN SMALL LETTER H
LATIN SMALL LETTER E
LATIN SMALL LETTER L
LATIN SMALL LETTER L
LATIN SMALL LETTER O
SPACE
ValueError: no such name
ValueError                                Traceback (most recent call last)
in engine
----> 1 for c in my_frstring:print(name(c))

ValueError: no such name
safex
  • 2,398
  • 17
  • 40
  • 1
    Which python version is that? only python 3.6 >= versions support f-strings –  Jul 29 '21 at 15:54
  • 1
    it's working fine! **python3.7** or **newer** – Ali Aref Jul 29 '21 at 16:02
  • 1
    Maybe you have an invisible character in the string. Try doing `from unicodedata import name;for c in the_fstring:print(name(c))` – snakecharmerb Jul 29 '21 at 16:32
  • 2
    f-strings weren't added until Python 3.6 (see [What’s New In Python 3.6.14](https://docs.python.org/3.6/whatsnew/3.6.html#pep-498-formatted-string-literals)). You can determine what version you have via `print(sys.version)`. – martineau Jul 29 '21 at 16:46
  • To get around the value error: `for c in the_fstring:print(ord(c))` – snakecharmerb Aug 09 '21 at 19:21

0 Answers0