Able to access variable inside one if-statement but not other - python-3.x

Here's a snippet from my code and it's weird why I'm able to access the variable named 'calBegPoint ' inside 3rd if statement but not the second.
if graph != None:
for trace in graph['data']:
if 'LSR(' in trace['name']:
calBegPoint = trace['x'][0] #Statement 1
if '% change' in trace['name']:
print(calBegPoint) #Statement 2
if 'LSR Extended' in trace['name']:
print(calBegPoint) #Statement 3
When I run this code, I get the following error on Statement 2 but, if I comment it, I do not get the error for Statement 3. To solve, this problem, I tried declaring calBegPoint= "Hi" before the entire snippet. With that I did not get the error but, the value printed on Statement 2 was 'Hi' and not the one I calculated.
I've been trying to debug it for hours. Any direction/pointer will be appreciated
UnboundLocalError: local variable 'calBegPoint' referenced before assignment

The error message tries to tell you that you use calBegPoint before defining it.
In your case, the first execution of the second or third if statement lies before the first execution of the first if statement.

Related

How to solve run time error method failed?

I'm trying to run a piece of code in vba but I'm still getting this error whenever I try to run it.
When I use debug the cursor on top of the 2nd line says "partDocument1 = Nothing"
Here's the code:
Set partDocument1 = documents1.item(Right(activeComponentWorksheet.cells(R, tem).Value, nameLength))
Set part1 = partDocument1.Part
Set body1 = part1.Bodies.item("PartBody")
selection1.Add body1
I'm just trying to create a part from the excel values by using macros. Could anyone explain why would this error happen?
This error message "Run time error method failed" is a general error message that can occur for a variety of reasons in VBA. It typically indicates that an operation that the code is trying to perform has failed, but without more information about the error and the specific line of code that is causing the issue, it is difficult to determine the exact cause of the problem.
One possible cause of this error in the provided code snippet is that the documents1.item(Right(activeComponentWorksheet.cells(R, tem).Value, nameLength)) method call is returning Nothing. This means that the item being passed as the argument to the method is not found in the documents1 collection. This will cause the subsequent Set part1 = partDocument1.Part and Set body1 = part1.Bodies.item("PartBody") line of code to throw the "Run time error method failed" error.
You can try to debug the error by adding some debug information and check if the variable partDocument1 is not equal to nothing before the error is thrown.
If partDocument1 Is Nothing Then
Debug.Print "partDocument1 is not found"
End If
You can also try to check if the value of the Right(activeComponentWorksheet.cells(R, tem).Value, nameLength) is matching with the value that you are expecting.
It's also possible that the problem is related to the activeComponentWorksheet.cells(R, tem).Value cell value or with the nameLength variable, it may be referencing a non-existent cell or it may contain a value that is not expected.
It's also possible that the problem is with the Bodies.item("PartBody") method, it may be that the body is not present or the name passed to the method is not correct.
These are some possible causes of the problem, but without more information about the specific environment and configuration of the code, it is difficult to provide a more specific solution.

ue pyhton delete actor

I try to delete some actors in the scene using python but keep getting errors, I don't know how to modify my code.
The error is generated in the second sentence:
get_editor_subsystem() takes exactly 1 argument (0 given)
Here is my code:
path=“Test.thisIsTest”
unrealSystem=unreal.get_editor_subsystem()
delete_actor=unrealSystem.get_actor_reference(path)
unreal.EditorActorSubsystem.destroy_actor(delete_actor)

delay until function in azure logic apps throwing error

I am trying to add a minute delay to the "delay until" action by getting the utcnow timestamp, adding a minute and converting into the time format that the "delay until" expects (https://learn.microsoft.com/en-us/azure/connectors/connectors-native-delay#add-the-delay-until-action)
None of the following works and throw the error below, what am i missing here, and is there a way where we can test these function independently without logic apps ?
1) #addMinutes(utcNow('o'),1,'YYYY-MM-DDThh:mm:ssZ')
2) #addMinutes(utcNow('YYYY-MM-DDThh:mm:ssZ'),1,'YYYY-MM-DDThh:mm:ssZ')
3) #addMinutes(utcNow(),1,'YYYY-MM-DDThh:mm:ssZ')
Unable to process template language expressions in action 'Delay_until' inputs at line '1' and column '2265': 'The string was not recognized as a valid DateTime. There is an unknown word starting at index 0.'.
Please try to use this expression:
addMinutes(utcNow(),1)
I did a test, it seems to be no problem:

Logic APP : ActionFailed. An action failed. No dependent actions succeeded

I am facing the issue with for loop execution with logic APP in azure. Apparently complete playbook execute successfully and functionally its working good. However, i am getting this error because it takes "body" parameter from previous step as input and nothing else. The body is long json and therefore should not be the right input for foreach loop. I tried adding account or Ip address as input but that fails as well.
Input
Output
Please help here
As you mentioned there is just one item in your json data array which contains "MachineId", I assume the first item contains "MachineId". Please refer to the solution below, it will help you to use the only "MachineId" in the 24 cycles of your loop.
We can input an expression to use the "MachineId" in first item:
body('Parse_JSON')[0].MachineId
(In the screenshot above, I just use a "Set variable" to replace your two actions in "For each" loop, but I think there is no difference between them)
Please have a try with this solution~

Fortran error check on formatted read

In my code I am attempting to read in output files that may or may not have a formatted integer in the first line of the file. To aid backwards compatibility I am attempting to be able to read in both examples as shown below.
head -n 3 infile_new
22
8
98677.966601475651 -35846.869655806520 3523978.2959464169
or
head -n 3 infile_old
8
98677.966601475651 -35846.869655806520 3523978.2959464169
101205.49395364164 -36765.047712555031 3614241.1159234559
The format of the top line of infile_new is '(i5)' and so I can accommodate this in my code with a standard read statement of
read(iunit, '(I5)' ) n
This works fine, but if I attempt to read in infile_old using this, I as expected get an error. I have attempted to get around this by using the following
read(iunit, '(I5)' , iostat=ios, err=110) n
110 if(ios == 0) then
print*, 'error in file, setting n'
naBuffer = na
!rewind(iunit) #not sure whether to rewind or close/open to reset file position
close(iunit)
open (iunit, file=fname, status='unknown')
else
print*, "Something very wrong in particle_inout"
end if
The problem here is that when reading in either the old or new file the code ends up in the error loop. I've not been able to find much documentation on using the read statement in this way, but cannot determine what is going wrong.
My one theory was my use of ios==0 in the if statement, but figured since I shouldn't have an error when reading the new file it shouldn't matter. It would be great to know if anyone knows a way to catch such errors.
From what you've shown us, after the code executes the read statement it executes the statement labelled 110. Then, if there wasn't an error and iostat==0 the true branch of the if construct is executed.
So, if there is an error in the read the code jumps to that statement, if there isn't it walks to the same statement. The code doesn't magically know to not execute the code starting at label 110 if there isn't an error in the read statement. Personally I've never used both iostat and err in the same read statement and here I think it's tripping you up.
Try changing the read statement to
read(iunit, '(I5)' , iostat=ios) n
You'd then need to re-work your if construct a bit, since iostat==0 is not an error condition.
Incidentally, to read a line which is known to contain only one integer I wouldn't use an explicit format, I'd just use
read(iunit, * , iostat=ios) n
and let the run-time worry about how big the integer is and where to find it.

Resources