The dash is a invalid syntax in the import settings [duplicate] - python

This question already has answers here:
What are the requirements for naming python modules?
(3 answers)
Closed 3 months ago.
I have a problem with launching the code, the problem was
"File C:\Users\User\Something\main.py
import color-utility
^
SyntaxError: invalid syntax'
Is there any fix for this?

Well, you should use import color_utility instead of -.

Related

I don't understand this syntax error in python [duplicate]

This question already has answers here:
What does "SyntaxError: Missing parentheses in call to 'print'" mean in Python?
(11 answers)
Closed 2 months ago.
print list(prolog.query(code))
^
SyntaxError: invalid syntax
can anyone tell me what does this syntax error mean?
I tried to install but it doesn't work.
check which python version you are using.
The code shown in question is valid until python 2.7, but not in Python 3 onward.
valid for Python 3:
print(list(prolog.query(code)))
(note the additional parenthesis like any function for print).
And as general advice, as noticed in comments, a syntax error marked at a line could be confusing and caused by a problem on the line before. Comment the line where you have the error and check.
This code is not valid in python 3.x
But this is valid in 2.x
Change the syntax to print(list(prolog.query(code)) (recommended)
or, Change your python version to 2.x (Not recommended)
Check this article.

Python2 And Python3 [duplicate]

This question already has answers here:
"print" throws an invalid syntax error in Python 3
(4 answers)
Closed 2 years ago.
This is for Python 2:
import re
print sum([int(i) for i in re.findall('[0-9]+',open(raw_input('What is the file you want to analyze?\n'),'r').read())])
But why do I get a syntax error with Python 3?
Python3
import re
print sum([int(i) for i in re.findall('[0-9]+',open(input('What is the file you want to analyze?\n')).read())])
That is because in Python3 you should use brackets around the argument for the print function.
print()
so your code will work as soon as you write
print(sum([int(i) for i in re.findall('[0-9]+',open(input('What is the file you want to analyze?\n')).read())]))

How to fix "invalid syntax for (>>>import datetime)"? [duplicate]

This question already has answers here:
What do the three arrow (">>>") signs mean?
(6 answers)
Closed 3 years ago.
>>>import datetime
>>>now = datetime.datetime.now()
>>>print ("Current date and time : ")
>>>print (now.strftime("%Y-%m-%d %H:%N:%S"))```
Error:
error: >>>import datetime
^
it seems like that you have copied code from an interpreter or a book to a file and tried to run it with python command.
if you want to do so you need to remove >>> from lines and run again.

How to call various strings without using %s? [duplicate]

This question already has answers here:
Type Error: Format Requires Mapping
(2 answers)
Closed 3 years ago.
text1="Python"
text2="with me"
print("Study %(language)s" %{'language':text1})
This works. But I am wondering whether it is using dictionary to call string?
print("Study %(language)s %(with whom)" %({'language':text1},{'with whom':text2}))
But it doesn't work. How can I fix it?
The error says 'format requires a mapping'
It would have worked, if you noticed that:
you've forgotten to put an s after %(with whom) --> %(with whom)s,
and instead of this %({'language':text1},{'with whom':text2}) --> %{'language':text1,'with whom':text2}
so the line would be like this:
print("Study %(language)s %(with whom)s" %{'language':text1,'with whom':text2})

'End of statement expected' in pycharm [duplicate]

This question already has answers here:
What does "SyntaxError: Missing parentheses in call to 'print'" mean in Python?
(11 answers)
Closed 4 years ago.
Why am I getting this error (see linting) saying 'End of statement expected' in pycharm?
I am very new to python.
Try print with parenthesis in Python3 i.e. print(x) instead of print x

Categories