You are returning a tuple here:
elif retailer_pk:
return (request, 'page-retailer-single.html', {
"products": products,
"sorting": filt["sorting"],
"filtering": filt["filtering"],
"retailer": retailer,
})
Did you forget to add render there perhaps:
elif retailer_pk:
return render(request, 'page-retailer-single.html', {
"products": products,
"sorting": filt["sorting"],
"filtering": filt["filtering"],
"retailer": retailer,
})
Answer from Martijn Pieters on Stack OverflowYou are returning a tuple here:
elif retailer_pk:
return (request, 'page-retailer-single.html', {
"products": products,
"sorting": filt["sorting"],
"filtering": filt["filtering"],
"retailer": retailer,
})
Did you forget to add render there perhaps:
elif retailer_pk:
return render(request, 'page-retailer-single.html', {
"products": products,
"sorting": filt["sorting"],
"filtering": filt["filtering"],
"retailer": retailer,
})
There is an extra comma "," at the end of return function in views.py
return render(request, 'index.html',{}), #incorrect
return render(request, 'index.html',{}) #correct
ChatInterface getting AttributeError: 'tuple' object has no attribute 'get'
AttributeError: 'tuple' object has no attribute 'enter'
Getting AttributeError: 'tuple' object has no attribute 'items'
train error:AttributeError: 'tuple' object has no attribute 'get'
Videos
You return four variables s1,s2,s3,s4 and receive them using a single variable obj. This is what is called a tuple, obj is associated with 4 values, the values of s1,s2,s3,s4. So, use index as you use in a list to get the value you want, in order.
Copyobj=list_benefits()
print obj[0] + " is a benefit of functions!"
print obj[1] + " is a benefit of functions!"
print obj[2] + " is a benefit of functions!"
print obj[3] + " is a benefit of functions!"
You're returning a tuple. Index it.
Copyobj=list_benefits()
print obj[0] + " is a benefit of functions!"
print obj[1] + " is a benefit of functions!"
print obj[2] + " is a benefit of functions!"
from kubernetes import client, config
config.load_kube_config()
v1 = client.CoreV1Api()
print("Listing services with their IPs:")
ret = v1.list_service_for_all_namespaces_with_http_info(watch=False)
for i in ret.items:
print("%s\t%s\t%s" % (i.status.pod_ip, i.metadata.namespace, i.metadata.name)) This throws this error: File "filename.py", line 8, in <module> for i in ret.items: AttributeError: 'tuple' object has no attribute 'items'
But when I simply print(ret), it certainly LOOKS like a tuple, which means I should be able to iterate through with tuple.items, no?
zip returns a list of tuples; you can sort them by accessing the elements with their index:
result_list.sort(key=lambda x: x[1], reverse=True)
if you like to be more explicit, you can use collections.namedtuple, and access the element via dot notation on the attribute name:
from collections import namedtuple
Poll = namedtuple('Poll', ['candidate', 'numvotes'])
uniquecandidate = ['a', 'b', 'c', 'd']
votes = [3, 4, 7, 1]
poll_results = list(map(Poll, uniquecandidate, votes))
poll_results.sort(key=lambda x: x.numvotes, reverse=True)
print(poll_results)
or with typing.NamedTuple:
from typing import NamedTuple
class Poll(NamedTuple):
candidate: str
numvotes: int
uniquecandidate = ['a', 'b', 'c', 'd']
votes = [3, 4, 7, 1]
poll_results = list(map(Poll, uniquecandidate, votes))
poll_results.sort(key=lambda x: x.numvotes, reverse=True)
print(poll_results)
out:
[Poll(candidate='c', numvotes=7), Poll(candidate='b', numvotes=4), Poll(candidate='a', numvotes=3), Poll(candidate='d', numvotes=1)]
Because your candidates and votes are stored in a tuple objects, the get() method won't work on them like it would on a dictionary. I recommend switching from
x.get('votes')
to this:
x[1]
This will get index 1 of each tuple (which in your case is the vote count).
I am trying to make a discord bot that would turn a message into lowercase. I am encountering an error, as the title suggests, "AttributeError: 'tuple' object has no attribute 'lower'. "
Here is my code if anyone can help.
https://hastebin.com/ibareyilax.py
If this is the wrong subreddit I don't mind taking down my post and posting it elsewhere.
from django.shortcuts import render
from django.http import HttpResponse
import datetime
def home(request):
now=datetime.datetime.now()
context={'datetime_now':now}
return render(request, 'home.html', context)