code:-
import wolframalpha
wolframappid = wolframalpha.Client("XXXXXX-XXXXXXXXXX")
res = wolframappid.query('temperature in mumbai')
answer = next(res.results).text
print(answer)
result:-
Traceback (most recent call last):
File "c:/Users/Harsh/Desktop/Harsh Python Projects/Test.py", line 5, in <module>
answer = next(res.results).text
File "C:\Users\Harsh\AppData\Roaming\Python\Python36\site-packages\wolframalpha\__init__.py", line 166, in text
return next(iter(self.subpod)).plaintext
ValueError: dictionary update sequence element #0 has length 1; 2 is required
any ideas how to solve this issue? i have also tried next(res.results).plaintext but another error pops up..
code:-
import wolframalpha
wolframappid = wolframalpha.Client("XXXXXX-XXXXXXXXXX")
res = wolframappid.query('temperature in mumbai')
answer = next(res.results).plaintext
print(answer)
result:-
Traceback (most recent call last):
File "C:\Users\Harsh\AppData\Roaming\Python\Python36\site-packages\wolframalpha\__init__.py", line 86, in __getattr__
val = self[name] if name in self else self[attr_name]
KeyError: '#plaintext'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:/Users/Harsh/Desktop/Harsh Python Projects/Test.py", line 5, in <module>
answer = next(res.results).plaintext
File "C:\Users\Harsh\AppData\Roaming\Python\Python36\site-packages\wolframalpha\__init__.py", line 88, in __getattr__
raise AttributeError(name)
AttributeError: plaintext
thanks in advance...
Related
i'm using replits database but when i try to load it in it returns an error
any ideas?
cookie = db[name]
cookiepc = db[name + "cookiepc"]
increase = db[name + "increase"]
the error is
Traceback (most recent call last):
File "main.py", line 25, in <module>
cookiepc = db[name + "cookiepc"]
File "/home/runner/Cookie-clicker/venv/lib/python3.8/site-packages/replit/database/database.py", line 439, in __getitem__
raw_val = self.get_raw(key)
File "/home/runner/Cookie-clicker/venv/lib/python3.8/site-packages/replit/database/database.py", line 479, in get_raw
raise KeyError(key)
KeyError: 'shdfgwbdhfbadwcookiepc'
According to the documentation for replit-py, a KeyError is raised when an attempt is made to read from a key that doesn't exist in the database.
You can use db.get to specify a default value for if the key doesn't exist:
print(db.get("b", "default")) # default
db["b"] = "pie"
print(db.get("b", "default")) # pie
I am trying to run a simple example using sbmltoodepy and I am receiving the following error.
Traceback (most recent call last):
File "C:\Users\AppData\Roaming\JetBrains\PyCharm2021.2\scratches\scratch_79.py", line 8, in
ParseAndCreateModel(inputFilePath)#, jsonFilePath=None, outputFilePath=None)#, className="SBMLmodel")
File "C:\Users\AppData\Roaming\Python\Python39\site-packages\sbmltoodepy\utilities.py", line 66, in ParseAndCreateModel
modelData = ParseSBMLFile(inputFilePath)
File "C:\Users\AppData\Roaming\Python\Python39\site-packages\sbmltoodepy\parse.py", line 284, in ParseSBMLFile
assert(doc.getNumErrors() == 0)
AssertionError
Here is the code that I used.
import sbmltoodepy
from sbmltoodepy import ParseAndCreateModel
inputFilePath = "E:/Borisov2009_insulin_EGF.xml"
ParseAndCreateModel(inputFilePath, jsonFilePath=None, outputFilePath=None, className="SBMLmodel")
model = sbmltoodepy.SBMLmodel()
model.RunSimulation(1, absoluteTolerance = 1e-12, relativeTolerance = 1e-6)
Thank you in advance for your time.
I want to create multiple databases but I don't know how I can make it
this is python code:
# 1 - for import data in listbox
def clear_item_list():
items.delete(0, END)
# 2 - for import data in listbox
def fill_item_list(items):
for item_ in items:
items.insert(END, item_)
# 3 - for import data in listbox
def item_list_view():
clear_item_list()
items = app.data_1.view()
fill_item_list(items)
# and that for placement data in entries
def get_selected_row_item(event):
global selected_item
if len(items.curselection()) > 0:
index = items.curselection()[0]
selected_item = items.get(index)[:]
item_name.delete(0, END)
item_name.insert(END, selected_item[1])
item_price.delete(0, END)
item_price.insert(END, selected_item[2])
items.bind("<<ListboxSelect>>", get_selected_row_item)
This code is for making a table:
"CREATE TABLE IF NOT EXISTS items (id INTEGER PRIMARY KEY , Namee VARCHAR , price INTEGER )"
I don't have any idea this is my problem or not, because when I wanna use price, type that data is string and python raise this error:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\Green\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1892, in __call__
return self.func(*args)
File "D:\python\WindowsProject\app\manager\manager_sign_in.py", line 44, in back_to_main_manager
main_screen()
NameError: name 'main_screen' is not defined
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\Green\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1892, in __call__
return self.func(*args)
File "D:\python\WindowsProject\app\manager\sign.py", line 33, in back_to_main_mngr
main_screen()
NameError: name 'main_screen' is not defined
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\Green\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1892, in __call__
return self.func(*args)
File "D:\python\WindowsProject\app\main.py", line 33, in user_sign
user_screen()
NameError: name 'user_screen' is not defined
Traceback (most recent call last):
File "D:\python\WindowsProject\app\main.py", line 4, in <module>
from app.user.user_sign_in import *
File "D:\python\WindowsProject\app\user\user_sign_in.py", line 240, in <module>
user_screen()
File "D:\python\WindowsProject\app\user\user_sign_in.py", line 236, in user_screen
item_list_view()
File "D:\python\WindowsProject\app\user\user_sign_in.py", line 55, in item_list_view
fill_item_list(items)
File "D:\python\WindowsProject\app\user\user_sign_in.py", line 48, in fill_item_list
items.insert(END, item_)
TypeError: 'str' object cannot be interpreted as an integer
and this is input data:
(1, 'pizza', '6')
if you can help me pls say to I give you more data about that if you need
The issue is on the below function:
def fill_item_list(items): # <- items is passed argument
for item_ in items:
# "items" below is expected to be an instance of tkinter Listbox
# but it is actually the passed argument (a list object)
items.insert(END, item_)
You used same name on the passed argument as the tkinter Listbox.
Use another name for the passed argument:
def fill_item_list(data): # used "data" instead of "items"
for item_ in data:
items.insert(END, item_)
In python 3, exceptions can be chained, like this:
try:
7/0
except ZeroDivisionError:
raise ValueError("Invalid division")
# Traceback (most recent call last):
# File "<stdin>", line 2, in <module>
# ZeroDivisionError: division by zero
#
# During handling of the above exception, another exception occurred:
#
# Traceback (most recent call last):
# File "<stdin>", line 4, in <module>
# ValueError: Invalid division
What if I have the following situation:
A class with a method that may either succeed or throw an error.
I have a bunch of instances of that class in a list.
Somewhere I call that method for every instance on the list.
It is enough for one of them to succeed. If every instance fails I throw an error.
Now, if I have to throw an error, I want to print all exceptions thrown during the test of each instance in the list. Code to clarify:
instances_to_test = [instance0, instance1, instance2]
failures = [] # List of all the thrown exceptions
success = False # True if one of the instances in the list succeeds
for instance in instances_to_test:
try:
instance.method_may_raise() # May raise an Error
success = True
break
except Exception as e:
failures.append(e)
if not success:
# ... What to do here ...
An ideal solution to the line in the comment would look something like:
if not success:
raise MultipleFailException("Could not find an adequate instance", parents=failures)
# 0 ------------------------------------
#
# Traceback (most recent call last):
# File "<stdin>", line 6, in <module>
# ValueError: Message of instance0
#
# 1 ------------------------------------
#
# Traceback (most recent call last):
# File "<stdin>", line 6, in <module>
# ValueError: Message of instance1
#
# 2 ------------------------------------
# Traceback (most recent call last):
# File "<stdin>", line 6, in <module>
# ValueError: Message of instance2
#
# During handling of the above exception(s), another exception occurred:
#
# Traceback (most recent call last):
# File "<stdin>", line 12, in <module>
# MultipleFailException: Could not find an adequate instance
Can this be done in a 'clean' way or should I fiddle with the stack trace like in the python 2 days?
Is there a way to simplify the following:
>>> pycountry.languages.get(name='english')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/pycountry/db.py", line 114, in get
return self.indices[field][value]
KeyError: 'english'
>>> pycountry.languages.get(name='ENGLISH')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/pycountry/db.py", line 114, in get
return self.indices[field][value]
KeyError: 'ENGLISH'
>>> pycountry.languages.get(name='English')
<pycountry.db.Language object at 0x1096374d0>
In the above, 'English' is the only item that doesn't result in an Exception.