write_rich_text of xlwt returns error - xlwt

I am using xlwt and the following code returns the error Worksheet object has no attribute write_rich_text Why would that be?
seg1 = ("NOT ", Font1)
seg2 = (str(data['Customer'])[:-1], Font2)
sheet1.write_rich_text(row, 4, (seg1, seg2) , Style1)
Note: I am using xlwt 0.7.5 and I see write_rich_text() defined in worksheet.py file

How are you initializing your sheet1 variable?
Make sure there is a page first:
wb = xlwt.Workbook()
sheet1 = wb.add_sheet('Sheet1')
sheet1.write_rich_text(....)
Also you want to take into consideration that write_rich_text is not included in all versions of xlwt so you might want to make sure that the version of xlwt that you are using is the same version that you verified that actually has write_rich_text. Clearly the version that is imported into your app doesn't know anything about a write_rich_text method.

Thank you Max for the pointer. Yes, I had an older version of xlwt in python27 that didn't have write_rich_text method. Replacing that xlwt with the newer version fixed the issue.

Related

JSON error with Julia Dash simple example

I've been trying to replicate the "A simple example" posted at https://dash-julia.plotly.com/clientside-callbacks
The server runs... but when I connect to it I get a JSON parse error in Firefox.
I was able to solve the problem, but I'd like to understand what's wrong...
The problem was this line inside the Dash app.layout:
options=[(label = country, value = country) for country in available_countries]
and the available_countries variable was obatined from:
read_remote_csv(url) = DataFrame(CSV.File(HTTP.get(url).body))
df = read_remote_csv("https://raw.githubusercontent.com/plotly/datasets/master/gapminderDataFiveYear.csv")
available_countries = unique(df.country)
Apparently the error showed because available_countries was an Array{String31,1}: and specifically the problem was the String31 type.
when I converted the variable to a plain String type:
available_countries = convert(Array{String,1},available_countries)
the problem solved.
Now... I'm not sure if the String31 type came from the HTTP.get(), CSV.File() or the DataFrame() functions.
I'm assuming the example used to work when it was originally written but it broke with an update...
Can anyone explain where exactly the error originates? Is it a Package version thing? which package? (HTTP, CSV, Dataframes)? How can I avoid it moving on?

Adam' object has no attribute 'zero_grads'

Im using a code not writing by me. So when executing this code we get error about the inexistance of zero_grads()
optimizer.zero_grads()
AttributeError: 'Adam' object has no attribute 'zero_grads'
This code is:
import chainer.optimizers as O
optimizer = O.Adam()
optimizer.setup(model)
clip = chainer.optimizer.GradientClipping(5.0)
optimizer.add_hook(clip)
....
optimizer.zero_grads()
optimizer.update()
Does i should change: optimizer.zero_grads()
to
optimizer.use_cleargrads(use=True)?
Note that im using chainer 4.0 version and the code what building with chainer 1.5.
optimizer's method zero_grads are deprecated and deleted, now it is preferable to use Link's method cleargrads.
So I guess you should change optimizer.zero_grads() to model.cleargrads()
Also, Refer
AttributeError: 'MomentumSGD' object has no attribute 'zero_grads'
However, when you want to use the code written in chainer v1.5, there may be several other places you need to update for chainer v4. It might be better to try executing the code with chainer v1.5 to see the behavior at first.

How to set INetFwPolicy2::ExcludedInterfaces property

I implementing basic library to deal with Windows Firewall API.
I faced with strange result with INetFwPolicy2::ExcludedInterfaces property.
I set excluded interface via Firewall.cpl and when read property I got array of some guids. I am not sure from where this GUID come. It is not Interface GUID. I select all interfaces from Win32_NetworkAdapter and there no such GUID.
Also when I try assign this value back I got invalid argument or not found errors.
This code based on msdn example written on on VBS, but it really does not matter I have same error on C. Original example did not works either.
Const NET_FW_PROFILE2_PRIVATE = 2
Set fwPolicy2 = CreateObject("HNetCfg.FwPolicy2")
CurrentProfiles = fwPolicy2.CurrentProfileTypes
if ( CurrentProfiles AND NET_FW_PROFILE2_PRIVATE ) then
InterfaceArray = fwPolicy2.ExcludedInterfaces(NET_FW_PROFILE2_PRIVATE)
if (IsEmpty(InterfaceArray)) then
WScript.Echo( "InterfaceArray is Empty" )
else
WScript.Echo( Join(InterfaceArray) )
end if
fwPolicy2.ExcludedInterfaces(NET_FW_PROFILE2_PRIVATE) = InterfaceArray
end if
Check your csproj file xml in your executing assembly (not necessarily the assembly that uses windows-firewall-api if it is referenced). For each configuration there is a <PropertyGroup> tag, and each should have a child tag <Prefer32Bit>false</Prefer32Bit> (or at least the one that you compile with).

java.lang.NoSuchMethodError while switching from owl-api 3.5 to 4.x

I've used the owl-api version 3.5 and now I would like to switch to Version 4, but I get a runtime exception. Like in the following example code (which works fine with version 3.5) a java.lang.NoSuchMethodError it thrown every time invoking the function "manager.addAxiom(...)".
WLOntologyManager manager = OWLManager.createOWLOntologyManager();
IRI ontologyIRI = IRI.create("http://example.com/owlapi/families");
OWLOntology ont = manager.createOntology(ontologyIRI);
OWLDataFactory factory = manager.getOWLDataFactory();
OWLIndividual john = factory.getOWLNamedIndividual(IRI.create(ontologyIRI + "#John"));
OWLIndividual mary = factory.getOWLNamedIndividual(IRI.create(ontologyIRI + "#Mary"));
OWLObjectProperty hasWife = factory.getOWLObjectProperty(IRI.create(ontologyIRI + "#hasWife"));
OWLObjectPropertyAssertionAxiom axiom1 = factory.getOWLObjectPropertyAssertionAxiom(hasWife, john, mary);
manager.addAxiom(ont, axiom1);
...
The whole exeption which is thrown says:
Exception in thread "main" java.lang.NoSuchMethodError: org.semanticweb.owlapi.model.OWLOntologyManager.addAxiom(Lorg/semanticweb/owlapi/model/OWLOntology;Lorg/semanticweb/owlapi/model/OWLAxiom;)Lorg/semanticweb/owlapi/model/parameters/ChangeApplied;
at de.ifak.Writer.OWL.Example.OWLMinimalTest.main(OWLMinimalTest.java:26)
I've tested the code in a clean Java project and added the owl-api dependencies manual and later with maven. I've testet it with version 4.0.2 and 4.1.0-RC2. Both have shown the same behavior.
I couldn't find any solution for that. So I hope someone can help me.
Thanks,
Chris
Ok, I found a solution by myself.
If I change the code
manager.addAxiom(ont, axiom1);
to
Set<OWLAxiom> axiomsToAdd = new HashSet<OWLAxiom>();
axiomsToAdd.add(axiom1);
manager.addAxioms(ont, axiomsToAdd);
all works fine, even with version 4.1 of the owl-api.
Edit:
Ok I made a mistake. It works fine with version 4.0.2 but with version 4.1 I get the same exception when I call:
manager.addAxioms(ont, axiomsToAdd);
like when I call:
manager.addAxiom(ont, axiom1);
The addAxiom method is still there but its return type has changed. Are you assigning the value returned to a variable?

Refactor old Web Audio API to new one

I'm evaluating HTML5 Web Audio API example and trying to get it work. Here is what I'm working with. As far as I got I understood that it's using old API and I need to refactor function refreshFilterType() on line ~590. Link - www.smartjava.org/examples/webaudio-filters/
According to Web Audio BiquadFilterNode I need to rework switch statement and make it
and to use the new string-based values. (I.e. a value of "3" - the default lowshelf filter - needs to be passed into currentFilterType as "lowshelf"). I've tried to implement new BiquadFilterNode, but still it was unsuccessfully.
Thank you in advance.
I just opened a pull request with the necessary fixes. Or look at https://github.com/cwilso/smartjava.
...and actually, I note the real problem with the code you have is not that it's using numeric values - that's wrong, according to the spec, but it's still supported - it's line 663:
filter.type = currentFilterType;
currentFilterType is "3" - that is, the STRING "3" - and type now takes a string, so it's not being coerced. If you changed this line to
filter.type = parseInt(currentFilterType);
it would actually fix the problem (because filter.type accepts ints, and will coerce them to the appropriate string of "lowpass", etc. - but it doesn't accept the string of a number.)
However, this will fail in the long term, when we remove the deprecated types.