https://docs.python.org/3/using/cmdline.html
This is the option documentation. but it doesn't provide me any useful message
I want to execute code in this way
python -c "def hello():\n print('hello world')"
the error message
PS C:\Users\Administrator> python -c "def hello():\n print('hello world')"
File "<string>", line 1
def hello():\n print('hello world')
^
SyntaxError: unexpected character after line continuation character
it works on Linux, but not windows.
Hope you can give a full fixed command ~~~
Another question connected with this one \n problem when using javascript to exec "python -c "
Go to your Start menu (lower left Windows icon), type "Microsoft Store", select the link to open the store. Once the store is open, select Search from the upper-right menu and enter "Python". Select which version of Python you would like to use from the results under Apps.
Try backtick instead of backslash.
Error:
PS C:\Users\me> python -c "def hello():\n print('hello world')"
File "<string>", line 1
def hello():\n print('hello world')
^
SyntaxError: unexpected character after line continuation character
PS C:\Users\me>
Ok:
PS C:\Users\me> python -c "def hello():`n print('hello world')"
PS C:\Users\me>
Useful:
PS C:\Users\me> python -c "def hello():`n print('hello world')`nhello()"
hello world
PS C:\Users\me>
Just echoing to see it:
PS C:\Users\me> echo "def hello():`n print('hello world')`nhello()"
def hello():
print('hello world')
hello()
PS C:\Users\me>
See PowerTip: New Lines with PowerShell
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With