0

In Jupyter Notebook my Code runs fine, but when I run it from shell i get a syntax error at this part of my code:

res = f'"x"'+" "+f'"y"'+" "+f'"t"'+" "+f'"id"'+" "+f'"id2"'
           ^
SyntaxError: invalid syntax

However I need the String res to look like:

""x" "y" "t" "id" "id2""

I guess that the way i create it is causing the error.

Is there any other way to create a String containing quotation marks? Or anything to get rid of the syntax error? Thanks!

9
  • Your expected output is not valid syntax. Did you mean a= '"x" "y" "t" "id" "id2"'? Commented Aug 18, 2018 at 11:16
  • 1
    Looks like left open parentheses in the line(s) before. Commented Aug 18, 2018 at 11:21
  • @roganjosh yes i want a to look as you said Commented Aug 18, 2018 at 11:22
  • @KlausD. no that is not the problem. The code runs fine in Jupyter notebook. It is just not valid shell syntax i guess, but i don't know how to get the same String with shell commands Commented Aug 18, 2018 at 11:24
  • What version of Python? Commented Aug 18, 2018 at 11:24

2 Answers 2

1

f-strings, or formatted string literals is supported only from python 3.6. If you are using old version of python, try to upgrade. If you have both python2 and python3 installed, make sure you are launching python3

But for the output you expect, you dont need f-strings

res = '"x" "y" "t" "id" "id2"'
Sign up to request clarification or add additional context in comments.

Comments

0

Got the answer now:

res= "\"x\" \"y\" \"t\" \"id\" \"id2\""

works for Shell as well as Python

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.