Whenever I Make A Mistake In The Python Terminal, I Come across the three dots(as given below), However When I Then write the correct code, it gives a syntax error, but when I write the same code again, I get the desired output, Could someone please explain as to why this happens and what exactly happens.
Thanks.
>>> age=14_567_3745_4
>>> print(age0
... print(age)
File "<stdin>", line 2
print(age)
^
SyntaxError: invalid syntax
>>> print(age)
1456737454
As indicated by #MisterMiyagi it is expecting you to just complete the statement and not write it all over again, something like this:
>>> age = 1341
>>> print(age
... )
1341
What you have run into is called 'implicit line joining' in python. Have a look at the docs, https://docs.python.org/2.0/ref/implicit-joining.html
Related
I am running below the addition of two numbers in jupyter
'''
This program `summationoftwonumbers` and displays their results
'''
A = 1
B = 5
print('Sum of Numbers:',A+B)
It is running fine giving an output as "Sum of Numbers: 6"
But when running a file by using PyLint, summationoftwonumber.ipynb gives the below errors.
summationoftwonumbers.ipynb:1:0: C0114: Missing module docstring (missing-module-docstring)
summationoftwonumbers.ipynb:1:0: W0104: Statement seems to have no effect (pointless-statement)
I do not understand why this is happening.
It's that you used quotes to write a comment, which in some cases creates a docstring. Python is warning you that the statement has no effect in your program. To get rid of the warning you could rewrite the line:
''' This program summationoftwonumbers and displays their results '''
as a normal comment:
# This program summationoftwonumbers and displays their results
I'm trying to get the name of an element by way the ID using Revit python wrapper in Revit python shell but I'm having issues. I am typically able to do it using c# but rpw is new to me.
I try:
doc.GetElement(2161305).name or doc.GetElement(2161305).Name
and I get this error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: expected Reference, got int
I've looked a bit through the docs and watched some of the videos but haven't found anything that has covered this. I'm sure its easy, I'm just not not finding the answer.
Any help / direction is appreciated.
Got to answer my own question again.
>>> from rpw import db
>>> element = db.Element(SomeElement)
>>> element = db.Element.from_id(ElementId)
>>> element = db.Element.from_int(Integer) # this one worked for me
You need to cast the integer to an ElementId. The GetElement has three overloads. None of them takes an int, so you need to cast it to clarify which one is intended. Please read the GetElement documentation.
Input function is only accepting integers as an input otherwise I receive this error message when I run using REPL in python 3:
Entry:
b
Traceback (most recent call last):
File "Ex7.5.py", line 1, in <module>
a = input("Entry:\n")
File "<string>", line 1, in <module>
NameError: name 'b' is not defined
Need my code to accept both letters and numbers as input and cant understand why it's not taking b as a string and printing it?
Literally just trying to get this print input function to work currently to then use later in other functions.
If I run the same code with integers only it works no problem.
a = input("Entry:\n")
print(a)
print(type(a))
The answer I'm expecting is b.
This error is occurring because you're running the code in Python 2, not Python 3. input() in Python 2 will evaluate what you give it, in this case as a variable name, which doesn't exist; while input() in Python 3 will keep it as a string. For more details see What's the difference between raw_input() and input() in python3.x?
How to use the correct Python version is another question, but it looks like you're making some progress in the comments so far.
I have the following python code:
print 'This is a simple game.'
input('Press enter to continue . . .')
print 'Choose an option:'
...
But when I press Enter button, I get the following error:
Traceback (most recent call last):
File "E:/4.Python/temp.py", line 2, in <module>
input('Press enter to continue . . .')
File "<string>", line 0
^
SyntaxError: unexpected EOF while parsing
P.S. I am using python IDLE version 2.6 on Windows 7.
Related problem in IPython: Why does the IPython REPL tell me "SyntaxError: unexpected EOF while parsing" as I input the code?
For Python 2, you want raw_input, not input. The former will read a line. The latter will read a line and try to execute it, not advisable if you don't want your code being corrupted by the person entering data.
For example, they could do something like call arbitrary functions, as per the following example:
def sety99():
global y
y = 99
y = 0
input ("Enter something: ")
print y
If you run that code under Python 2 and enter sety99(), the output will 99, despite the fact that at no point does your code (in its normal execution flow) purposefully set y to anything other than zero (it does in the function but that function is never explicitly called by your code). The reason for this is that the input(prompt) call is equivalent to eval(raw_input(prompt)).
See here for the gory details.
Keep in mind that Python 3 fixes this. The input function there behaves as you would expect.
In Python 2, input() strings are evaluated, and if they are empty, an exception is raised. You probably want raw_input() (or move on to Python 3).
In Python 2.x, input() is equivalent to eval(raw_input()). And eval gives a syntax error when you pass it an empty string.
You want to use raw_input() instead.
If you use input on Python 2.x, it is interpreted as a Python expression, which is not what you want. And since in your case, the string is empty, an error is raised.
What you need is raw_input. Use that and it will return a string.
This seems to work in python 2.7, but not python 3. Is there an easy way to make a set a list in python 3 that I am missing? Thanks in advance.
mylist = [1,2,3,4,5]
list(set(mylist))
#Traceback (most recent call last):
# File "<stdin>", line 1, in <module>
#TypeError: 'list' object is not callable
Sorry if this has been asked before, I did a quick search and didn't see an answer specific to python3.
list(set(...)) works fine. The error indicates the 3.x version of the code has a variable called list or set, shadowing the built-in function. Perhaps you renamed mylist to list? Rest assured, that mistake would provoke the exact same error message in Python 2.