I have an actor object, and it has both name and id, i could take the name, but it couldn't take the id
look please
>>> actor
<Person id:0000199[http] name:_Pacino, Al_>
>>> actor["name"]
u'Al Pacino'
>>> actor["id"]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/IMDbPY-5.0-py2.7-macosx-10.6-intel.egg/imdb/utils.py", line 1469, in __getitem__
rawData = self.data[key]
KeyError: 'id'
>>>
Use the .personID property of a Person object:
actor.personID
Related
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_)
This is my first time looking into the 'dbm' module as part of an exercise in a book and I can't figure out why I'm getting this error.
import dbm
db = dbm.open('chapt14/dbtest/captions', 'c')
db['cleese.png'] = 'Photo of John Cleese'
db['testeroni.png'] = 'Photo of Cohn Jleese'
for key in db:
print(key, db[key])
db.close()
Traceback (most recent call last):
File "/home/individuation/Documents/Code/ThinkPython/chapt14/dbtest/db_test.py", line 7, in <module>
for key in db:
TypeError: '_gdbm.gdbm' object is not iterable
I have a Mongo Document with some fields (_id, id, name, status, etc...). I wrote a typical document in a class(like a model would do):
class mod(Document):
id=fields.IntField()
name = fields.StringField()
status=fields.StringField()
description_summary = fields.StringField()
_id = fields.ObjectIdField()
And with this model, I tried to access them:
>>> from mongoengine import *
>>> from api.models import *
>>> connect('doc')
MongoClient(host=['localhost:27017'], document_class=dict, tz_aware=False, connect=True, read_preference=Primary())
I tried to fetch all the entries in the "mod" document: It Worked! I can get all the fields of all the entries (id, name, etc...)
>>> mod_ = mod.objects.all()
>>> mod_[0].name
'Name of entry'
>>> mod_[0].id
102
I tried to filter and return all the entries with the field "status" = "Incomplete": It works, just like before.I tried to filter other fields: it works too
>>> mod_ = mod.objects(status="Incomplete")
>>> mod_[0].name
'Name of entry'
>>> mod_[0].id
102
But When I try to filter with the id I don't manage to get a result:
>>> mod_ = mod.objects(id=102)
>>> mod_[0].name
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/.../lib/python3.4/site-packages/mongoengine/queryset/base.py", line 193, in __getitem__
return queryset._document._from_son(queryset._cursor[key],
File "/.../lib/python3.4/site-packages/pymongo/cursor.py", line 570, in __getitem__
raise IndexError("no such item for Cursor instance")
IndexError: no such item for Cursor instance
>>> mod_[0].id
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/.../lib/python3.4/site-packages/mongoengine/queryset/base.py", line 193, in __getitem__
return queryset._document._from_son(queryset._cursor[key],
File "/.../lib/python3.4/site-packages/pymongo/cursor.py", line 570, in __getitem__
raise IndexError("no such item for Cursor instance")
IndexError: no such item for Cursor instance
So I tried with mod.objects.get(id=102)
>>> mod_ = mod.objects.get(id=102)
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/.../lib/python3.4/site-packages/mongoengine/queryset/base.py", line 271, in get
raise queryset._document.DoesNotExist(msg)
api.models.DoesNotExist: mod matching query does not exist.
Mod matching query does not exist, so it doesn't recognize the id field but when I write mod_[0].id I do have a result, so what can be wrong?
EDIT: I believe that when writing mod.objects(id=102), the field id is interpreted as the _id. How can I specify, I want to query by id and not _id? My Document is already written, so I cannot change the name of the fields.
So, the problem does not come from the difference between _id and id, like said #HourGlass. The values of the id field were stored as integer, I wrote fields.IntField() for the id field, and called mod.objects(id=102) (without quotes).
But for some reason, I have to write them as fields.StringField(), and call mod.objects(id='102').
I'm trying to call a class method inside the init function of the class. I pass in a string to the function but the error shows that its a none type object.
class UserSettings(object):
"""Value object representing a user's settings."""
def __init__(
self, user_id, email, username=None):
self.user_id = user_id
self.email = email
self.profile_picture_data_url = self.fetch_gravatar(email)
#classmethod
def fetch_gravatar(cls, email):
base_url = "http://www.gravatar.com/avatar/"
avatar_url = base_url + hashlib.md5(email.lower()).hexdigest() + "?"
avatar_url += urllib.urlencode({'d':'retro', 's':str(AVATAR_SIZE)})
return avatar_url
Here's the error:
Traceback (most recent call last):
File "/home/travis/build/oppia/oppia/core/domain/user_services_test.py", line 78, in test_invalid_emails
user_services.get_or_create_user('user_id', email)
File "/home/travis/build/oppia/oppia/core/domain/user_services.py", line 297, in get_or_create_user
user_settings = _create_user(user_id, email)
File "/home/travis/build/oppia/oppia/core/domain/user_services.py", line 284, in _create_user
preferred_language_codes=[feconf.DEFAULT_LANGUAGE_CODE])
File "/home/travis/build/oppia/oppia/core/domain/user_services.py", line 55, in __init__
self.profile_picture_data_url = self.fetch_gravatar(email)
File "/home/travis/build/oppia/oppia/core/domain/user_services.py", line 129, in fetch_gravatar
avatar_url = base_url + hashlib.md5(email.lower()).hexdigest() + "?"
AttributeError: 'NoneType' object has no attribute 'lower'
AttributeError: 'NoneType' object has no attribute 'lower'
This tells you that you are attempting to read an attribute named lower on the singleton object None.
Now, you use lower in a method call on email. Therefore, email is None.
You must be calling the method with the value None, or an argument that evaluates to None.
# calling the class method:
>>> UserSettings.fetch_gravatar('a#example.com')
'http://www.gravatar.com/avatar/b418773a2c51fb9777a1648346fa7394?s=16&d=retro'
# create instance, call method:
>>> user_settings = UserSettings(user_id=1, email='jill#example.com')
>>> user_settings.fetch_gravatar('jill#example.com')
'http://www.gravatar.com/avatar/e84a7df193a44f643668b74a2bbfdde6?s=16&d=retro'
# calling with a No arguments gives TypeError
>>> UserSettings.fetch_gravatar()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: fetch_gravatar() takes exactly 2 arguments (1 given)
# calling with None gives your error:
>>> UserSettings.fetch_gravatar(None)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 11, in fetch_gravatar
AttributeError: 'NoneType' object has no attribute 'lower'
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.