0

I would like to create and print a string variable with a percentage sign at the beginning. I use Python 3.7.3, zeppelin and pyspark.

For example, I code:

%livy2.pyspark
a = '% some characters %'
print(a)

What I get:

some characters %

what I expect:

% some characters %

How can I do this correctly?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
dellrew
  • 1
  • 2
  • 2
    Try adding `r'% string %'`, this defines it as a 'raw' string (escapes etc not interpreted) – ChrisOram Sep 23 '21 at 13:16
  • 3
    Cannot reproduce. The output is in fact `% some characters %` when running this code in a normal Python interpreter. Try https://stackoverflow.com/questions/28343745/how-do-i-print-a-sign-using-string-formatting – mkrieger1 Sep 23 '21 at 13:17
  • `a = 'some characters'; print(rf'% {a} %')` ? – rv.kvetch Sep 23 '21 at 13:18
  • Still doesn't work. I'm not sure if it's problem of zeppelin of python. – dellrew Sep 23 '21 at 13:37
  • have you tried `print('%%' + a + '%%)`? Added the double % there just in case. – rv.kvetch Sep 23 '21 at 13:46
  • If all else fails, how about `sys.stdout.write('% some characters %\n')`? – rv.kvetch Sep 23 '21 at 13:47
  • 1
    Guys, thank you all for your replies. Unfortunetely even `sys.stdout.write('% some characters %\n')` doesn't work. Here is [screen](https://i.stack.imgur.com/RiKrd.png) I believe it's zeppelin's error/bug. – dellrew Sep 23 '21 at 14:48

0 Answers0