"Values" object has no attribute "save" - python

I am trying to work with the code below. However it is a written code by my professor and also in python2 (I already made quite some changes). I use python 3.8.5.
When I try to run the code it yield me the Attribute Error below. Trying to adapt it by changing it the syntax or shorten up to save did not work and I also do not came across any reference of save in the web.
def __init__(self, options):
self.save_each = options.save_each
self.origin_dir = "NET-%s-%s-%s"%(options.currency, options.heuristic, options.epoch)
if options.save_each is not None:
self.origin_dir += "_%s"%options.save_each
File "comp-1-network_centrality.py", line 31, in __init__
self.save_each = options.save_each
AttributeError: 'Values' object has no attribute 'save_each'
Looking forward to help.

Related

I'm having issues with subroutines inside of __getitem__()

I have created a piece of code in python which makes use of the getitem subroutine, which I am not too familiar with.
Inside the getitem subroutine, there are multiple subroutines, one of which is:
def load(self,i):
return str(i)
However when I try to call it elsewhere in the project...
self.load(x)
... it says that it cannot find the subroutine:
self.load(x)
AttributeError: 'Calc' object has no attribute 'load'
I have tried using
self.__getitem__.load(x)
but that doesn't work either.
Can someone help me?

AttributeError: 'str' object has no attribute 'items'; Trying to iterate through for loop in python

I'm trying to adapt a script from GitHub to get rid of some errors I'm getting. So far I have mainly changed directories. I just ran into this error and cannot find a solution for my particular problem. Here is the full output of the console:
Blender 2.81 (sub 16) (hash 26bd5ebd42e3 built 2019-11-20 16:31:09)
/run/user/1000/gvfs/ non-existent directory
Read prefs: /home/blender/.config/blender/2.81/config/userpref.blend
found bundled python: /usr/local/blender-2.81-linux-glibc217-x86_64/2.81/python
Traceback (most recent call last):
File "/usr/local/blender-2.81-linux-glibc217-x86_64/generate_classification_data.py", line 33, in <module>
image_generator.render()
File "/usr/local/blender-2.81-linux-glibc217-x86_64/utils/image_classifier_generator.py", line 74, in render
for class_name, model_path in self.data.items():
AttributeError: 'str' object has no attribute 'items'
Blender quit
Here is the code it is pointing to:
def render(self):
self.set_render_properties()
for class_name, model_path in self.data.items():
print(class_name, model_path)
for num_images_rendered in range(self.num_images_per_class):
obj = self.construct_scene(model_path, class_name)
box_coordinates = get_image_bounding_box(obj)
image_name = self.make_image_name(
class_name, num_images_rendered, box_coordinates)
render_image(image_name)
delete_scene(self.blender_save_path)
".self.data.items()"
class_name is an array originating from shapenet_data_manager.py, another file used in the script. I cant find any other reference to "model_path", including where it was declared. What I am trying to do is create images through domain randomization, so I am a bit out of my depth as far as the python goes. Thanks for all the help you can provide.
As #hpaulj said, items is a method of a dictionary, while self.data is a string. You need to figure out where self.data gets set to a string.
I would start by finding all the places where self.data is set, either internally in the object or from outside the object, by printing self.data out and seeing what it is.
Please update your answer and comment here if you have any more questions :) Good luck!

'module' object is not callable typeerror django

So I have a module that I successfully use. But now I added another file to module and it gives me this error.
I have a file generate_bags_uk that has method:
def generate_bags(bags, price):
And I use it like this:
from excelgenerator import generate_bags_uk
...
uk_bag = generate_bags_uk.generate_bags(tshirts, form.cleaned_data['price_uk_bag'])
And I get TypeError: module is not callable. What am I doing wrong here ?
Try the following code instead -
from excelgenerator.generate_bags_uk import generate_bags
...
uk_bag = generate_bags(tshirts, form.cleaned_data['price_uk_bag'])
and make sure excelgenerator folder has a __init__.py inside it, otherwise it will not be dealt as a python package.
Also, I guess the method has a body, if it does not then at least give it a definition -
def generate_bags(bags, price):
pass
COMMENT : From the looks of this error, the error is happening in file /home/marijus/workspace/tshirtnation/excelgenerator/generate_bags_uk.py. I think your other calls are also of similar format and thus causing error. Please change them as I mentioned. The problem should be solved.

How to properly extend other classes in Python? (python v3.3)

I've started to learn python in the past few days, and while exploring object-oriented programming I'm running into problems.
I'm using Eclipse while running the pydev plugin, am running on the python 3.3 beta, and am using a windows 64 bit system.
I can initialize a class fine and use any methods within it, as long as I'm not trying to extend the superclass (each class I've coded in a different source file)
For example, the following code compiles and runs fine.
class pythonSuper:
string1 = "hello"
def printS():
print pythonSuper.string1
and the code to access and run it...
from stackoverflow.questions import pythonSuper
class pythonSub:
pysuper = pythonSuper.pythonSuper()
pysuper.printS()
Like I said, that works. The following code doesn't
class pythonSuper: """Same superclass as above. unmodified, except for the spacing"""
string1 = "hello"
def printS(self):
print(pythonSuper.string1)
Well, that's not quite true. The superclass is absolutely fine, at least to my knowledge. It's the subclass that weirds out
from stackoverflow.questions import pythonSuper
class pythonSub(pythonSuper):
pass
pythonObject = pythonSub()
pythonSub.pythonSuper.printS()
when the subclass is run Eclipse prints out this error
Traceback (most recent call last):
File "C:\Users\Anish\workspace\Python 3.3\stackoverflow\questions\pythonSub.py",
line 7, in <module>
class pythonSub(pythonSuper):
TypeError: module.__init__() takes at most 2 arguments (3 given)
I have no idea what's going on. I've been learning python from thenewboston's tutorials, but those are outdated (I think his tutorial code uses python version 2.7). He also codes in IDLE, which means that his classes are all contained in one file. Mine, however, are all coded in files of their own. That means I have no idea whether the code errors I'm getting are the result of outdated syntax or my lack of knowledge on this language. But I digress. If anyone could post back with a solution and/or explanation of why the code is going wrong and what I could do to fix it. An explanation would be preferred. I'd rather know what I'm doing wrong so I can avoid and fix the problem in similar situations than just copy and paste some code and see that it works.
Thanks, and I look forward to your answers
I ran your code, albeit with a few modifications and it runs perfectly. Here is my code:
pythonSuper:
class pythonSuper:
string1 = 'hello'
def printS(self):
print(self.string1)
main:
from pythonSuper import pythonSuper as pySuper
class pythonSub(pySuper):
pass
pythonObject = pythonSub()
pythonObject.printS()
NOTE: The change I have made to your code is the following:
In your code, you have written pythonSub.pythonSuper.printS() which is not correct, because via pythonSub you already support a printS() method, directly inherited from the superclass. So there is no need to refer to the superclass explicitly in that statement. The statement that I used to substitute the aforementioned one, pythonObject.printS(), seems to have addressed this issue.
pythonSuper refers to the module, not the class.
class pythonSub(pythonSuper.pythonSuper):
pass

added typelib via makepy for AutoCAD, now win32com not working for AutoCAD

I have been running win32com to access AutoCAD for quite some time without issue. I learned that applying the makepy utility could create a more user friendly experience at the interactive prompt, so I ran it and added the "AutoCAD 2006 Type Library". Now, some common attributes that I used to access are no longer available. Consider the code:
acad = win32com.client("AutoCAD.Application")
doc = acad.Documents.Open('mydoc.dwg')
ms = doc.ModelSpace
count = ms.Count #counts all entities in dwg
for i in range(count):
item = ms.Item(i)
if 'block' in item.ObjectName.lower():
print item.Name
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
File "C:\Python27\lib\site-packages\win32com\client\__init__.py", line 462, in
__getattr__ raise AttributeError("'%s' object has no attribute '%s'"
(repr(self),attr))
AttributeError: '<win32com.gen_py.AutoCAD 2006 Type Library.IAcadEntity instance
at 0x34894552>' object has no attribute 'Name'
Name has always been an accessible attribute of a block until I ran makepy. I've tried reinstalling Python for windows to see if that would reset it, but it didn't work.
Does makepy create another file upon implementation that I need to remove?
So many of my scripts depend upon the Name attribute. Any suggestions or help you could offer would be greatly appreciated.
The main reason for this attribute error is because your COM-server has shifted from late-binding (dynamic) to early binding (static).
In Late Binding, whenever a method is called, the object is queried for the method and if it succeeds, then the call can be made.
In Early Binding, the information of the object model is determined in advance from type information supplied by the object call. Early binding makes use of MakePy. Also, early binding is case sensitive.
There are two ways to fix this issue:
Use the dynamic module to force your code to work in a late-bound oriented way. Example use:
win32com.client.dynamic.Dispatch() instead of win32com.client.Dispatch()
Use camelcase sensitive keywords for the early bound oriented way. Example use:
excel.Visible() instead of excel.VISIBLE() or excel.visible()
So try using dynamic.Dispatch or case-sensitive variable names.
I encounter a similar problem when I run win32com to access DELMIA. I find out that delmia has lots of com stuff as .tlb files. When I type:
from win32com.client.gencache import EnsureDispatch
EnsureDispatch('DELMIA.Application')
Python will automatically generate some stuff in win32com\gen_py directory, same as example of Word or Excel. But, the difference is that the generated stuff is from only one .tlb file of delmia. If I access some variable in the `.tlb, it's ok:
docs = delmia.Documents
If I access some variable in other .tlb, I get a similar error:
pdoc = docs.Add('Process')
Python says that:
... object has no attribute ...
So I delete all files in the win32com\gen_py directory but keep gen_py directory, and it is ok now.

Categories