Where does the variable "name" come from? - python-3.x

Sample Code:
from enum import Enum
class Countries(Enum):
Afghanistan = 44
Andorra=88
Austrailia=38
print(Countries.Afghanistan.name)
output:Afghanistan
Question: Where is the variable "name" defined ? I couldn't locate in the source code of Enum which was very complicated anyway.

EnumMeta will use the names found in self._member_names as the enumeration member names. This defined values can be found at line 170 of enum.py.
But I could be wrong...

Enum is a class in python for creating enumerations, which are a set of symbolic names (members) bound to unique, constant values. The members of an enumeration can be compared by these symbolic anmes, and the enumeration itself can be iterated over. An enum has the following characteristics.
The enums are evaluatable string representation of an object also
called repr().
The name of the enum is displayed using ‘name’ keyword.
Using type() we can check the enum types.
I hope this will be helpfull for you.

Related

Problem to get integer values for Protege DataProperty from Excel using Cellfie

I am using Cellfie plug-in for Protégé to create ontological individuals from an Excel database of scientific articles. I face a problem when I try to assign an integer value to a property 'has interger value' which range is xsd:integer. In fact, the property is being assigned but without the ^^xsd:integer type specification, so the reasoner fail beacause those values are not recognized as integers. I am using this Manchester Syntax code, which is not causing any error, but the values given to the properties are not declared as integers inside the Protégé ontology:
Individual: #B*
Types: 'Publication year'
Facts: 'has integer value' #B*(xsd:integer)
The column B of the Excel is full of integer numbers (years). If I try using xsd:string, the properties have the correct type declaration ^^xsd:string, but if I try to use xsd:integer the axioms are created ignoring the type declaration.

drools adding fact types in excel file (declaring types)

I am looking on some example excel files to declare a Fact Type in the rule file. How can I add a a fact type in the excel file. I can do it in the drl file as given below.
package KieRule;
global java.util.List names;
declare Invoice
cardType : String
price : int
end
rule "HDFC"
when
invoiceObject : Invoice(cardType=="HDFC" && price>10000);
then
names.add( "discount for HDFC = 10" );
end;
I got a solution for that. Posting it here if it help others,

ElasticSearch datatype for a concrete value

I've encountered following error message when I've set Nested data type for such input ['abc', 'def', 'ghi'].
object mapping for [tags] tried to parse field [null] as object, but
found a concrete value
Please let me know which kind of datatype should I set for concrete value.
If it's an array of strings then use text datatype. if it's an array of objects use Nested datatype. See reference https://www.elastic.co/guide/en/elasticsearch/reference/current/array.html. the reason you've received this error it's because you've tried to index array of strings (concrete values) as Nested datatype but Nested datatype expects to see an object and not a string (concrete value). Also check this out https://discuss.elastic.co/t/object-mapping-for-configurationitems-configuration-state-tried-to-parse-field-state-as-object-but-found-a-concrete-value/80995

GraphQL Schema Definition Error

I am trying to define GraphQL schema like this:
type Obj {
id: Int
0_100: Int
}
But it gives following exception.
'GraphQLError: Syntax Error: Expected Name, found Int "0"',
How can I define attribute starting with numeric, -, + signs.
This is the regexp for names in GraphQL: /[_A-Za-z][_0-9A-Za-z]*/. Anything that does not match is not allowed.
Sample URL:
http://facebook.github.io/graphql/June2018/#sec-Names
Numerical parameter names do not work in GraphQL.
You can probably prefix it with a string like _0_100, but it's fairly unusual and I'd recommend against it. Consider using words to name your parameters instead.

VBA: Use a variable as a reference to a user defined type

How can I reference a user defined type using a local variable without creating a copy of the type instance?
As an example, in the code below what I would ideally like to do is in MySub3 where I create a local variable, MT, and reference a data structure nested inside another struct ... but VBA doesn't allow this. It allows it for objects but not for user defined types (arrggg!) ... and for no apparent reason ... it just doesn't allow it.
MySub1 shows how to reference the nested struct in a long clunky way.
MySub2 shows how to do this by passing in the nested struct, but this clutters up the calling routine, and having multiple such nested structs gets ugly.
MySub2 demonstrates that VBA can do what I want, it just doesn't seem to provide a way to do it. I'm hoping there is a method I just haven't stumbled upon.
Note that my actual code is MUCH more complicated than this example, with multiple independent structs providing indices to many arrays as struct elements. Using these local reference variables would make the code much more readable and manageable.
Also Note that I am aware of the "with" statement, and it does help, but can only be used on one struct at a time.
Also Note that I am aware that I could use an actual object class. My code started out using an object but I quickly found out that VBA places limitations on arrays as property members ... a limitation that user defined types don't have.
Type tMyType
VariableA As Single
End Type
Type tMyOtherType
MyTypeArray() As tMyType
End Type
Type tOneMoreType
MyOtherType As tMyOtherType
End Type
Dim GlobalIndex As Integer
Sub TopLevel()
Dim TopLevelType As tOneMoreType
ReDim TopLevelType.MyOtherType.MyTypeArray(0 To 10)
Call MySub1(TopLevelType)
Call MySub2(TopLevelType.MyOtherType.MyTypeArray(GlobalIndex))
Call MySub3(TopLevelType)
End Sub
Sub MySub1(OMT As tOneMoreType)
Dim VarA As Single
VarA = OMT.MyOtherType.MyTypeArray(GlobalIndex).VariableA
End Sub
Sub MySub2(MT As tMyType)
Dim VarA As Single
VarA = MT.VariableA
End Sub
Sub MySub3(OMT As tOneMoreType)
Dim VarA As Single
Dim MT
Set MT = OMT.MyOtherType.MyTypeArray(GlobalIndex)
VarA = MT.VariableA
End Sub
From my point of view you have made it vary complicated. But I believe you have the reason for that.
The example you submitted generate the error you mentioned. But, when I changed some lines there is no error. I am not sure if my suggestion is the result you expected (while the question isn't fully clear to me) but try this instead of your MySub3:
Sub MySub3(OMT As tOneMoreType)
Dim VarA As Single
Dim MT
MT = OMT.MyOtherType.MyTypeArray(GlobalIndex).VariableA
VarA = MT
End Sub
Generally, this way I'm able to read any element im MySub3 passed from TopLevel.
If it is not the answer please clarify more.
I think here you have hit one of the limitations of VBA. I know of no way round the limitation on partial dereferencing of nested user types.
I think you would be best using classes containing private arrays with getter and setter functions (sadly, VBA doesn't have operator overloading either).

Resources