codes:
>>> from test2.models import Member_info
>>> member = Member_info.objects.all()
>>> member
<QuerySet [<Member_info: John2>, <Member_info: John1>, <Member_info: John3>]>
>>> member = Member_info.objects.all()[0]
>>> member
<Member_info: gun2>
>>> member += Member_info.obejcts.all()[1]
Traceback (most recent call last):
File "<console>", line 1, in <module>
AttributeError: type object 'Member_info' has no attribute 'obejcts'
>>> member += Member_info.objects.all()[1]
Traceback (most recent call last):
File "<console>", line 1, in <module>
TypeError: unsupported operand type(s) for +=: 'Member_info' and 'Member_info'
>>> member.append(Member_info.objects.all()[1])
Traceback (most recent call last):
File "<console>", line 1, in <module>
AttributeError: 'Member_info' object has no attribute 'append'
2.How can i append,,,,?
You can append to list, but you are trying to append to Member_info. Try this one:
member = Member_info.objects.all()[0]
members = [member]
members.append(Member_info.objects.all()[1])
Related
I have the following code
histos = dict()
for key in list:
obj = file.Get(key)
if not key in histos:
histos[key] = obj.Clone()
else
histos[key].Add(obj)
Add() is a function of obj, however I get the following error if the object is retrieved from a python dict():
Traceback (most recent call last):
File "./script.py", line 35, in <module>
histos[key].Add(obj)
AttributeError: 'PyROOT_NoneType' object has no attribute 'Add'
How can I typecast objects retrieved from dict()
This is the code I currently have:
def uniform_distribution(users,radius):
user_coordinates_distance=[]
user_coordinates=[]
finding_shadowing=[]
r=radius*np.sqrt(np.random.uniform(0,1,users))
angle=2*np.pi*np.random.uniform(0,1,users)
x = r*np.cos(angle)
y = r*np.sin(angle)
user_distance = np.sqrt(x*x+y*y)
x_shadowing=1000*x
y_shadowing=1000*y
x_shadowing=(x_shadowing-x_shadowing%10)/10
y_shadowing=(y_shadowing-y_shadowing%10)/10
finding_shadowing=shadowing(x_shadowing,y_shadowing,shadowing_matrix)
print(finding_shadowing)
for i in range (0,users):
user_coordinates=[x[i],y[i],user_distance[i],finding_shadowing[i]]
user_coordinates_distance.append(user_coordinates)
return (user_coordinates_distance)
And this is the error I get when I run it:
Traceback (most recent call last):
File "C:\Users\Ajit\Desktop\maryland\Sem 2\ENTS 656\project656\main program and functions\main_1.py", line 136, in <module>
user_coordinates=uniform_distribution(attempts,cell_radius)#list [x,y,distance,shadowing]
File "C:\Users\Ajit\Desktop\maryland\Sem 2\ENTS 656\project656\main program and functions\main_1.py", line 81, in uniform_distribution
finding_shadowing=shadowing(x_shadowing,y_shadowing,shadowing_matrix)
TypeError: 'float' object is not callable
What exactly does this error mean?
When trying to set up the DataIterator as explained on neon tutorial.
from neon.data import DataIterator
import numpy as np
X = np.random.rand(10000, 3072)
y = np.random.randint(1, 11, 10000)
train = DataIterator(X=X, y=y, nclass=10, lshape=(3, 32, 32))
I encountered a weird error:
ERROR:neon.data.dataiterator:DataIterator class has been deprecated and renamed"ArrayIterator" please use that name.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "neon/data/dataiterator.py", line 168, in __init__
super(DataIterator, self).__init__(*args, **kwargs)
File "neon/data/dataiterator.py", line 82, in __init__
self.Xdev = [self.be.array(x) for x in X]
AttributeError: 'NoneType' object has no attribute 'array'
I then tried with ArrayIterator, keeping X, y the same.
ArrayIterator(X=X, y=y, nclass=10, lshape=(3,32,32))
With the same NoneType error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "neon/data/dataiterator.py", line 82, in __init__
self.Xdev = [self.be.array(x) for x in X]
AttributeError: 'NoneType' object has no attribute 'array'
Why would this be the case? Is there an easy fix?
Fixed the problem by generating backend.
from neon.backends import gen_backend
be = gen_backend()
(...)
I'm trying to set data in an existing chart using python-pptx.
from pptx import Presentation
pres_path = "C:\\pres.pptx"
pres = Presentation(pres_path)
pres.slides[3].shapes[4].chart.series[0].values
(92.0, 330.0, 309.0, 313.0, 356.0, 421.0, 457.0)
pres.slides[3].shapes[4].chart.series[0].values = (1,2,3)
Traceback (most recent call last):
File "<input>", line 1, in <module>
AttributeError: can't set attribute
There's a method mentioned in the documentation which seems relevant, but I can't understand how to use it:
http://python-pptx.readthedocs.org/en/latest/_modules/pptx/chart/data.html
pres.slides[3].shapes[4].chart.replace_data((1,2,3))
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Python27\lib\site-packages\pptx\chart\chart.py", line 119, in replace_data
_SeriesRewriter.replace_series_data(self._chartSpace, chart_data)
File "C:\Python27\lib\site-packages\pptx\chart\chart.py", line 197, in replace_series_data
sers = cls._adjust_ser_count(chartSpace, len(chart_data.series))
AttributeError: 'tuple' object has no attribute 'series'
I'd appreciate any help you can provide.
Thanks!
To add a new series to an existing table behind a chart you need to do 3 things:
create an instance of ChartData()
provide category name
add the new series to the ChartData() object, using the "add_series()" func.
chart_data = ChartData()
chart_data.categories = 'category_name'
for col_idx, col in enumerate(single_df.columns):
chart_data.add_series(col, (single_df.ix[:, col_idx].values))
shp.chart.replace_data(chart_data)
I am trying to port to Python some old VBA code.
In VBA I add Geo3D.dll as a project reference, then I use this:
Set P1 = New GEO3DLib.Point
P1.Set 1, 2, 3, 0.001
In Python I tried this:
import comtypes
import comtypes.client as cc
cc.GetModule('C:\\Program Files (x86)\\think3\\2009.3\\thinkdesign\\bin\\Geo3d.dll')
import comtypes.gen.GEO3DLib as Geo3d
pt = cc.CreateObject('Geo3d.Point', None, None, Geo3d.Point)
But I get this error:
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
pt = cc.CreateObject('Geo3d.Point', None, None, Geo3d.Point)
File "C:\Anaconda3\lib\site-packages\comtypes\client\__init__.py", line 238, in CreateObject
obj = comtypes.CoCreateInstance(clsid, clsctx=clsctx, interface=interface)
File "C:\Anaconda3\lib\site-packages\comtypes\__init__.py", line 1217, in CoCreateInstance
iid = interface._iid_
AttributeError: type object 'Point' has no attribute '_iid_'
Replacing the last line with:
pt = Geo3d.Point
pt.Set(1., 2., 3., 0.001)
I get this error:
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
pt.Set(1., 2., 3., 0.001)
AttributeError: type object 'Point' has no attribute 'Set'
Any idea?
Enure that the python implementation and the thinkdesign library are compiled for the same platform type: 64 bit or 32 bit.
I tested this as follows:
>>> p=Dispatch('Geo3d.Point')
>>> p
<win32com.gen_py.think3 thinkdesign Type Library.IPoint instance at 0x59554312>
>>> p.Set(0,0,0)
>>> p.X
0.0
or with comtypes:
>>> point=comtypes.CoCreateInstance(comtypes.GUID.from_progid('Geo3d.Point'))
>>> ipoint=point.QueryInterface(Geo3d.IPoint)
>>> ipoint.Set(0,0,0)
0
>>> ipoint.X
0.0