I am trying to dynamically create a class for an owlready2 ontology. The documentation suggests the following line of code:
NewClass = types.new_class("NewClassName", (SuperClass,), kwds = { "namespace" : my_ontology })
In my case this equals
types.new_class("NewClassName", (onto["ParentClass"],), kwds={'namespace' : onto})
However, when I run the above code, I get the following exception:
Traceback (most recent call last):
(onto[object.get('owl_dataProperty_parent')],), kwds={'namespace' : onto})
File "/usr/lib/python3.6/types.py", line 62, in new_class
return meta(name, bases, ns, **kwds)
TypeError: __new__() got an unexpected keyword argument 'namespace
I have no idea what went wrong there and after hours of debugging I am still clueless.
I am using Python 3.6.6 and version 0.11 of owlready2
I figured out that the "namespace" attribute is not needed at all. So the following works just fine:
types.new_class("NewClassName", (onto["ParentClass"],))
Even though this does not solve the overall issue, it answered my question.
Additionally, it seams like this is the way to do it in general, cf.owlready forum. So maybe it is time to update the documentation.
Related
I have downloaded the procedure I have on my laptop on my lab’s computer from my Google Drive, and I had to take some edits to test it.In order to this, I have to add some text components with some specific code. However when I tried to add and use the $ symbol to read the text I would like to refer to, I get the following error:
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/psychopy/app/builder/dialogs/paramCtrls.py", line 31, in validate
validate(self, self.valType)
File "/usr/local/lib/python3.8/dist-packages/psychopy/app/builder/dialogs/paramCtrls.py", line 550, in validate
val = str(obj.GetValue())
RecursionError: maximum recursion depth exceeded while calling a Python object
Could anyone possibly have some good piece of advice or workaround to manage with it?
Thanks
What version of PsychoPy are you using? I believe this was fixed in Feb 2022 so probably updating to a new version of psychopy should fix it for you.
https://github.com/psychopy/psychopy/pull/4569
I'm trying to get the name of an element by way the ID using Revit python wrapper in Revit python shell but I'm having issues. I am typically able to do it using c# but rpw is new to me.
I try:
doc.GetElement(2161305).name or doc.GetElement(2161305).Name
and I get this error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: expected Reference, got int
I've looked a bit through the docs and watched some of the videos but haven't found anything that has covered this. I'm sure its easy, I'm just not not finding the answer.
Any help / direction is appreciated.
Got to answer my own question again.
>>> from rpw import db
>>> element = db.Element(SomeElement)
>>> element = db.Element.from_id(ElementId)
>>> element = db.Element.from_int(Integer) # this one worked for me
You need to cast the integer to an ElementId. The GetElement has three overloads. None of them takes an int, so you need to cast it to clarify which one is intended. Please read the GetElement documentation.
current_call.transfer("sip:1001#xx.xx.xx.xx") is working python2.7 How ever it is not working in python3.7
below is the error
Original exception was:
Traceback (most recent call last):
File "trycall.py", line 151, in <module>
current_call.transfer("sip:1001#xx.xx.xx.xx")
File "/usr/local/lib/python3.7/dist-packages/pjsua.py", line 1734, in transfer
Lib._create_msg_data(hdr_list))
SystemError: <built-in function call_xfer> returned NULL without setting an error
I am using this branch of PJSIP: Link
for PJSUA implementation with Python 3.6 and have encountered same problem with transfer.
Removing this check from function py_pjsua_call_xfer (pjproject/pjsip-apps/src/python/_pjsua.c) solved my problem:
if (!PyBytes_Check(pDstUri))
return NULL;
This check always returns NULL in all my tests. I was not able to solved this with Python. Removing code mentioned above solved the issue and for now it haven't created any new problems. I have tested this modification with Asterisk and 3 SIP endpoints and transfer was correctly processed.
(note: I am not a C/C++ programmer, so I cannot provide detail explenation why this code doesn't work. This approach is based on trial and error.)
I used Pytesseract module for OCR. It seems slow process. So I followed
Pytesseract is too slow. How can I make it process images faster? .
I used code mentioned in https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/tesseract-ocr/xvTFjYCDRQU/rCEwjZL3BQAJ . But getting error
!strcmp(locale, "C"):Error:Assert failed:in file baseapi.cpp, line 201
Segmentation fault (core dumped),
Then i check some post and get reference to add in my code locale.setlocale(locale.LC_ALL, "C").
So after added this in my code I got another error
Traceback (most recent call last):
File "master_doc_test3.py", line 107, in <module>
tess = Tesseract()
File "master_doc_test3.py", line 67, in __init__
if self._lib.TessBaseAPIInit3(self._api, datapath, language):
ctypes.ArgumentError: argument 3: <class 'TypeError'>: wrong type`
Can anyone give idea about this error? OR If anyone have idea about best way to make OCR in fastest way using python.
You should try to convert to bytes every parameter you pass to ctypes lib calls:
self._lib.TessBaseAPIInit3(self._api, datapath, language)
Something like this is working for me:
self._lib.TessBaseAPIInit3(self._api, bytes(datapath, encoding='utf-8'), bytes(language, encoding='utf-8'))
I have got the clue here.
Please, take into consideration that the code you are using needs more fine tuning in other lib calls as the next ones:
tess.set_variable(bytes("tessedit_pageseg_mode", encoding='utf-8'), bytes(str(frame_piece.psm), encoding='utf-8'))
tess.set_variable(bytes("preserve_interword_spaces", encoding='utf-8'), bytes(str(1), encoding='utf-8'))
For whatever reason, Python is not allowing me to access a custom method I created in moviepy's preview.py file. I just want to know how to correctly implement it into the file. For reference, before I changed the name of the method, it was working correctly.
I checked at least two __init.py__ files and they were effectively empty. I couldn't find if methods are initialized anywhere, and is probably what I'm missing.
I also tried restarting Git Bash and that didn't work either (another solution I saw).
Original:
#convert_masks_to_RGB
def preview(clip, fps=15, audio=True, audio_fps=22050, audio_buffersize=3000,
audio_nbytes=2, fullscreen=False):
Changed:
#requires_duration
#convert_masks_to_RGB
def preview_custom(clip, marker_overlay="marker_overlay.png", fps=15, audio=True, audio_fps=22050, audio_buffersize=3000,
audio_nbytes=2, fullscreen=False):
There are more than a few differences between the changed and original method, however at the moment the only result I expect is having the method be called correctly. Error is below:
Traceback (most recent call last):
File "T3AJM.py", line 249, in <module>
main()
File "T3AJM.py", line 34, in main
GUI_main_menu()
File "T3AJM.py", line 85, in GUI_main_menu
GUI_play_markers()
File "T3AJM.py", line 125, in GUI_play_markers
video.preview_custom(marker_overlay=TEMP_OVERLAY_FILE)
AttributeError: 'VideoFileClip' object has no attribute 'preview_custom'
Thank you for your time.
I'm not even sure if this technically fixes the problem, but just doing:
from moviepy.video.io.preview import *
and
preview_custom(video, marker_overlay=TEMP_OVERLAY_FILE)
fixed the problem. I have no idea why I had to change the way it was called, as doing clip.preview(), or in this case video.preview() worked perfectly fine before, but whatever.