Is there a function out there that will take a python datatype and return a tag datatype? I want to automate turning python objects into tags.
Sorry, I miss understand your question, you are talking about datatypes, not datasets. My bad.
In that case, what you mean by a python datatype?
your example looks like it is just reading one tag and writing the value back to the same tag. here is what I want
myInt01= 42
myInt02 = 2147483699
print pythonToTagDataType(myInt01)
print pythonToTagDataType(myInt02)
the above would print
Int4
Int8
Oh, ok now I understand. In your example. Assuming MyInt01&02 comes from any python expression and your data will always be int types, just write (use system.tag.write()) to a tag but this tag should an array type, for example:
But you just change it to
and inside it changes by itself like:
but if you trying to write the string “Int4” to a tag. Just make sure your target tag data type is set to string and code something like:
system.tag.write(‘tagpath’,str(pythonToTagDataType(myInt01))
I am not trying to write the datatype to a tag. I want to then use the result to make a tag with that data type using system.tag.configure().
tagSite = {
"name": "site",
"valueSource": "memory",
"dataType": pythonToTagDateType(self.site),
"value": self.site
}
system.tag.configure(basePath = "[tagProvider]", tags = [tagSite], collisionPolicy = "m")
maybe this is what you mean
num= 42.2
typ=type(num)
numtype = typ(num)
print typ
print numtype
Not going to work. Jython uses its “int” datatype for anything that fits in java’s signed 32-bit Integer, and its “long” datatype for any other integers. It uses its 64-bit float for both 32-bit and 64-bit Reals.
So what you are saying is i should just use the largest datatype for tags as possible? if the datatype in python is Integer then use Int8 when I create a tag?
If a python int, use Int4/Integer. If a python long, use Int8/Long, but be aware that python long is really an unlimited bit width type (Java BigInteger) that can lose data in an Int8. Python floats should be placed in Float8/Double.
You could use a dictionary for easy lookups.
typeDict = {
'int' : 'Int4',
'long' : 'Int8',
'float': 'Float8',
'str' : 'String'
}
type(value).__name__
should give you the type name.
@pturmel, didn’t know that about longs being BigInteger. Learned something new.
I learned it long ago when some old JDBC drivers blew up on prepUpdates with 64-bit columns. /:
This looks like what I might be looking for https://inductiveautomation.com/exchange/132/overview
I may have to modify it to work with lists.