Spyder 5 keeps inserting parenthesis after variable even when disabled - python

I am using the latest Spyder 5.3.3 and notice that almost any time I enter a variable id adds () to the end.
It does not happen all the time, but most of the time.
I noticed if I just make a variable testVar = 1 and print it it works normally. But if I take almost any variable from my code such as COUNT it does COUNT(). The code fails from the () as there is no such
testVar = 1
print(testVar)
print(COUNT())
COUNT is a variable and should never have parenthesis anyway.
[![enter image description here][1]][1]
The key part is that I have disabled Automatic insertion of pan theses.
[![enter image description here][2]][2]
My guess is that this is a bug in Spyder, if so can someone please help me report it?
[1]: https://i.stack.imgur.com/SyQnN.png
[2]: https://i.stack.imgur.com/isSjz.png
I found how to submit in Spyder with Help->Report issue which requires a github token.

Related

2nd int-casting input-taking variables causes problem

I'm working in PyCharm. I haven't been programming for a few months and when I came back I saw a problem.
There are 2 user-input-taking variables, input is converted to int.
height = int(input())
width = int(input())
(it's literally entire code, there's nothing more)
When I run the program and give the 1st integer value, it's still fine, but the 2nd integer causes the following error:
ValueError: invalid literal for int() with base 10: ''
For some reason, it is "ValueError", though I just give it integer value (see screen at the end) and it seems to indicate that I gave it an empty string which is untrue (again, see the screen - I even marked the values I had given; in this case it was 4 and 5).
If I put some code between the 2 variables, like below, the problem doesn't appear:
height = int(input())
print(height)
width = int(input())
Also note that if it's just one variable, the problem doesn't appear.
And the problem appears only in PyCharm, I did the same in VSCode and everything worked properly. I also reinstalled PyCharm to check if it helps, but it didn't.
I suppose the problem is related to PyCharm, but since hard reinstall (deleting all that Revo Uninstaller found being related to PyCharm) didn't help I have no more ideas...
Visualization:
error
Please, check your python --version in virtual environment (it should be python 3.x)
I just ran the code myself (with a few amendments just to see the prompts) and it runs completely fine in my vs code even before my prompt amendments.
height = int(input("Input Height: "))
width = int(input("Input Width: "))# Write your code here :-)
area = height * width
print(area)
I would suggest checking you have the most update version of python and that everything is configured correctly on your machine.
Also it might help to re-save the file and re run.
It seems to be a known issue which will be fixed in the next PyCharm version.
See: https://youtrack.jetbrains.com/issue/PY-54238/STDIN-is-lost-for-a-second-input-call
As suggested by the support current workaround is to enable the "Emulate terminal in output console".

How to get rid of run time error on code chef

The following code works fine on both the jupiter notebook and the pycharm but its showing runtime error on codechef. The code is to check whether the permutation is ambiguous or not.
for i in range(int(input())):
n=int(input())
l=list(map(int,input().split()))
p=l[:]
for j in range(n):
p[l[j]-1]=j+1
if(p==l):
print("ambiguous")
else:
print("not ambiguous")
Welcome to Stack Overflow!
When posting, it usually helps to add more information, such as the error message itself. Regardless, I pasted your code into Python and I've deduced that the problem arises from the input() statement- I'm not sure what 'code chef' is, but it probably doesn't know that the user should input an integer into the input() prompt.
Therefore, a workaround is to hardcode your inputs as variables:
input1 = "5"
input2 = ...
for i in range(int(input1)):
n=int(input2)
...

my python functions do not work in jupyter notebook

i have written lines of code that run normally in jupyter notebook (here is the code below):
umd_departments = requests.get("https://api.umd.io/v0/courses/departments")
umd_departments_list = umd_departments.json()
umd_departments_list2 = json.dumps(umd_departments_list, indent=1)
department_storage = [department['dept_id'] for department in umd_departments_list]
print(department_storage)
the code above usually gives me the output i want and prints it out immediately. the issue i run into is when i try and put the code above into a function of its own it doesn't work
def get_UMD_departments():
umd_departments = requests.get("https://api.umd.io/v0/courses/departments")
umd_departments_list = umd_departments.json()
umd_departments_list2 = json.dumps(umd_departments_list, indent=1)
department_storage = [department['dept_id'] for department in umd_departments_list]
print(department_storage)
the problem i face with this version of code is that it never prints out anything as oppose to the other code i showed. with this code, i also don't get an error when i run it since the * symbol doesn't show up and i don't get an error message. so i'm not sure what the problem is. it usually just shows how many times i ran the cell. i was wondering if anyone knew a way to make the function version of my code to work, greatly appreciated.

Dependency between "Session/line number was not unique in database." error and Python code

For some time I am getting the following error (warning?):
ERROR! Session/line number was not unique in database. History logging moved to new session
when working with Jupyter notebook (<XXXX> is a number, e.g. 9149).
As the same error has been reported for Spyder (Spyder's Warning: "Session/line number not unique in database") my guess is that there is some problem with the IPython kernel logging.
The question is: may there be any relation between running my code and the error?
Is it likely the error is caused by my code? I touch IPython API as following:
import IPython
def beep():
Python.display.display(IPython.display.Audio(url="http://www.w3schools.com/html/horse.ogg", autoplay=True))
def play_sound(self, etype, value, tb, tb_offset=None):
self.showtraceback((etype, value, tb), tb_offset=tb_offset)
beep()
get_ipython().set_custom_exc((Exception,), play_sound)
I use the beep() function in my code. I also work with large data which results in MemoryError exceptions.
And more importantly, may the error affect my code behaviour (given I do not try to access the logs)?
[EDIT]
It seems the issue is different than Spyder's Warning: "Session/line number not unique in database" as I am able to reproduce it with Jupyter Notebook but not with Spyder.
It is only a partial answer - the bounty is still eligible.
The error does depend on my code - at least when there is SyntaxError.
I have reproduced it with three following cells.
In [31]: print(1)
1
In [31]: print 2
File "<ipython-input-32-9d8034018fb9>", line 1
print 2
^
SyntaxError: Missing parentheses in call to 'print'
In [32]: print(2)
2
ERROR! Session/line number was not unique in database. History logging moved to new session 7
As you can see the line counter has been not increased in the second cell (with syntax issues).
Inspired by #zwer's comment, I have queried the $HOME/.ipython/profile_default/history.sqlite database:
sqlite> select session, line, source from history where line > 30;
6|31|print(1)
6|32|print 2
7|32|print(2)
It is clear that the line counter for the second cell has been increased in the database, but not in the notebook.
Thus when the third cell has been executed successfully, the notebook attempted to store its source with the same line, which offended the PRIMARY KEY constraint:
sqlite> .schema history
CREATE TABLE history
(session integer, line integer, source text, source_raw text,
PRIMARY KEY (session, line));
As a result, a failsafe has been triggered which issued the warning and created a new session.
I guess the issue is not affecting my code behaviour, however I miss a credible source for such statement.
I experienced the same error when I was trying to run some asyncio code in a jupyter notebook. The gist was like this (might make sense to those familiar with asyncio)
cell #1
output = loop.run_until_complete(future)
cell #2
print(output)
Run both cells together, and I would get OP's error.
Merge the cells together like so, and it ran cleanly
cell #1
output = loop.run_until_complete(future)
print(output)
This problem arises in the Jupyter Notebook cells when the cells have the same line number.
What you can do - if you are in Jupyter Notebook - is just restart the kernel.
The error will be solved.

Runtime Error (NZEC) - Python / Codechef

I'm getting started with Codechef. I submitted following code in python to solve this question.
The code below works fine with codechef's online (python) IDE as well as my local IDE. But, when I submit it on codechef, it results in Runtime Error (NZEC). Can someone explain to me the reason behind this?
withdrawCash = int(input())
totalCash = int(input())
if withdrawCash < totalCash and withdrawCash % 5 is 0:
totalCash = (totalCash - withdrawCash) - 0.5
print(totalCash)
The problem supplies both the inputs in a single line. Your code waits for input in 2 lines. Change it to:
withdrawCash,totalCash = map(int,raw_input.split())
NZEC (Non Zero Exit Code) occurs when your code doesn't return zero on exit. It can happen due to a number of reasons, but if splitting the input doesn't solve the problem, add an exception for EOFerror. Just write:
try:
withdrawCash = int(input().split()) # raw_input in the case of Python 2
except EOFerror:
print ("exit") # this is jst a pseudo statement `
Use indentation properly. I am currently using an android app of stack exchange in which writing code is not so easy. codechef is pretty poor when it comes to Python. Switch to any other lang for CP.
Try directly submitting the code without running it on Codechef ide because it with me also it showed the same but when I submitted directly I got submitted successfully. so Directly submit your code.

Categories

Resources