I'm trying to create a simple loop that prints out all available values of dir("Hello") side by side with the help("Hello".xxx) for each dir returned.
I've seen a number of stackoverflow threads on calling functions dynamically from a custom class, but it's not so clear how I can loop through built-in methods.
Taking this as an example:
for dr in dir("Hello"):
Using 'format' converts the "Hello.%d" % dr into a string of "hello.upper", but the print(help('hello.upper')) fails, because the help function expects "hello".upper, not "hello.upper":
for dr in dir("Hello"):
print(dr)
print(help("Hello.%d" % dr))
I've tried researching getattr, but the help function is not a method of the string, so getattr("Hello", "help")("upper") isn't working either.
expected results are:
dir value (followed by:)
dir help output
help doesn't return a string, it opens an interactive viewer for reading the help page.
To view each of these pages for some object (warning: there are going to be a lot of these pages), you can use getattr to get the attribute of the object given its name
obj = "Hello"
for attr_name in dir(obj):
help(getattr(obj, attr_name))
Related
I am using fullfilment section on dialogflow on a fairly basic program I have started to show myself I can do a bigger project on dialogflow.
I have an object setup that is a dictionary.
I can make the keys a constant through
const KEYS=Object.keys(overflow);
I am going through the values using
if(KEYS.length>0){
var dictionary = overflow[keys[i]]
if I stringify dictionary using
JSON.stringify(item);
I get:
{"stack":"overflow","stack2":"overflowtoo", "stack3":3}
This leads me to believe I am actually facing a dictionary, hence the name of the variable.
I am accesing a string variable such as stack and unlike stack3
Everything I have read online tells me
dictionary.stack
Should work since
JSON.stringify(item);
Shows me:
{"stack":"overflow","stack2":"overflowtoo","stack3":3}
Whenever I:
Try to add the variable to the response string.
Append it to a string using output+=${item.tipo};
I get an error that the function crashed. I can replace it with the stringify line and it works and it gives me the JSON provided so the issue isnt there
Dictionary values are created as such before being accessed on another function:
dictionary[request.body.responseId]={
"stack":"overflow",
"stack2":"overflowtoo",
"stack3":3 };
Based on the suggestion here I saw that the properties where being accessed properly but their type was undefined. Going over things repeatedly I saw that the properties where defined as list rather than single values.
Dot notation works when they stop being lists.
Thanks for guiding me towards the problem.
: 1495 : 2020-02-11 11:55:00 (1, 0)
Here is my sample result but then when I'm trying to split it gives me error
Process terminate : 'Attendance' object has no attribute 'split'
In the documentation it says
print (attendance) # Attendance object
How to access it?
Convert the attendance object into a string and split it.
str(attendance).split()
After splitting you can access the user ID and use it where ever you want.
found the solution
i check in the github repository of pyzk and look for the attendance class and found all the object being return by the live_capture thank you :)
It's an object of class Attendance. The split() is a method of string. So you can't directly split() an object. Dan is right, to split an object, first, you have to convert it to a string.
str(obj).split()
Although, you don't need to split this object to get the user id. All you have to do is, use accessor. e.g
user_id = attendance_obj.user_id
I have a WO in Maximo 7.6.1.1.
When a user updates the Service Address, I want to invoke an autoscript that has an Object Launch Point on the WORKORDER object.
Is there a way to invoke an autoscript (that has an object launch point on the WORKORDER object) when the Service Address is updated?
You should see if mbo.getOwner() returns something and if that something.getName() is WORKORDER and, further, the work order you are expecting it to be. Subject to all that, you can invoke that other autoscript with code like this:
from java.util import HashMap
lpVars = HashMap()
lpVars.put("mbo",mbo.getOwner())
#repeat the last line for any other implicit/explicit variables your target
#script is going to use / expect to be defined
service.invokeScript("YOURSCRIPTNAME", lpVars)
someVar = lpVars.get("someVarDefinedInYOURSCRIPTNAMEWhenItEnded")
Note the work with the lpVars variable. I use it to store the "implicit"/"explicit" variables (e.g. "mbo") that the script I'm calling will expect to be defined. Basically, I'm doing the setup a launch point normally does, since my code is the launch point. Then, since I'm the launch point, I have access to whatever variables were defined when the script ended by Maximo adding them to / updating them in lpVars.
You can create reusable "library" scripts that you can call directly as Preacher explained. See IBM example here: https://www.ibm.com/support/knowledgecenter/SSFGJ4_7.6.0/com.ibm.mbs.doc/autoscript/c_example_reuse.html
So you could have your WO object launchpoint call the library script and your SA object launchpoint calling the same. You then just need to make change to one script if needed and that's great.
I don't believe you can. An object launch point is all about telling Maximo which object to monitor for the following event(s), not exactly about which object to launch the script on (though, for various reasons, those two are necessarily tied together).
What you can do, though, is put your launch point on the service address as you really do want, but then in your script fetch the on-screen/in-memory work order that you want to do something with and do that. This is done through the getOwner() method call or the special ":owner" (maybe with the ampersands, I can't remember) relationship reference.
This is the solution I came up with:
mboName=mbo.getName()
if mboName == 'WOSERVICEADDRESS':
mboWO = mbo.getOwner()
elif mboName == 'WORKORDER':
mboWO=mbo
sax = mboWO.getDouble("SERVICEADDRESS.LONGITUDEX")
say = mboWO.getDouble("SERVICEADDRESS.LATITUDEY")
if sax and say:
mboWO.setValue("longitudex", sax)
mboWO.setValue("latitudey", say)
elif mboWO.getString("ASSETNUM") and mboWO.getBoolean("ASSET.PLUSSISGIS") == 1:
mboWO.setValue("longitudex", mboWO.getDouble("ASSET.longitudex"))
mboWO.setValue("latitudey", mboWO.getDouble("ASSET.latitudey"))
elif mboWO.getString("LOCATION") and mboWO.getBoolean("LOCATION.PLUSSISGIS") == 1:
mboWO.setValue("longitudex", mboWO.getDouble("LOCATION.longitudex"))
mboWO.setValue("latitudey", mboWO.getDouble("LOCATION.latitudey"))
else:
mboWO.setValue("longitudex", None)
mboWO.setValue("latitudey", None)
The script has launch points on multiple objects:
I'm trying to retrieve the value "CONGE STATUTAIRE" from the following html code
<span class="DescriptionLabel" id="lblProjectDescription">CONGE STATUTAIRE</span>
I've tried this
nom_proj = IE.Document.getElementsByClassName("DescriptionLabel")(0).innerText
The code pass this line without problem but the the value of nom_proj is " ", and I would have hope to get "CONGE STATUTAIRE" for result.
Could anyone tells me what's wrong with it? The rest of my code is working i.e. I can retrieve value by using the getelementbyID method.
Any help will be welcomed.
I would use the getElementById() method, to make sure it can return only one HTML element and not a collection of objects:
nom_proj = IE.Document.getElementById("lblProjectDescription").innerText
However, the reason why you get "" is most probably that the collection returned by getElementsByClassName() has more than one element (often, when retrieving object by class names).
Which means: in the Document of your browser there will be most probably more elements that are styled with the CSS class DescriptionLabel; for example, something like this:
<div name="emptyRow" class = "DescriptionLabel"></div>
You can test if there are more than one element by:
1) either, adding a watcher to IE.Document.getElementsByClassName("DescriptionLabel");
2) or, printing all the elements inside, I bet my hat you'll find inside more than one:
For Each obj In IE.Document.getElementsByClassName("DescriptionLabel")
Debug.Print obj.InnerText
Next obj
GENERAL SUGGESTION: if an HTML object has an id, use the getElementByID; that method returns a single object, not a collection, so even if you would be sure that the collection will contain a unique element, it would anyway be less clean and efficient in terms of coding.
I would like to find out if it is possible to get the custom properties of an object from its 2nd tier. An example is provided below which can be clearer than explaining in words.
objectA = display.newImage(...)
objectA.dmg = 100
objectA.firstBtn = display.newImage(...)
objectA.firstBtn.id = "firstBtn"
objectA.firstBtn:addEventListener("touch",touchHandler)
function touchHandler(event)
-- I want to get the dmg of objectA
-- I know that by calling event.target.id I can get "firstBtn"
-- but how do I get the dmg value like event.target.parent.dmg?
end
Thank you.
you cannot get the objectA.dmg in event.target even if you use event.target.parent you cannot get or access it. you can refer to this link you have similar question on why you can't access it