unexpected error even though there is no syntax error in the statement.
i have tried restarting Pycharm.
i tried coping and pasting the code into new tab where every word is pasted in a new line somehow.
can anyone help me find the issue?
this is the image of the error. https://i.stack.imgur.com/Gx8qZ.png
Check to make sure that the name of your variable doesn't contain any spaces. I recommend using snake or camel casing.
total_number_of_times = 1 #snake
totalNumberOfTimes = 1 #camel
Related
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.
I'm currently trying to find the bug in the following piece of bash code:
for ((v=1; v<=${config[vnc_number]}; v++))
do
# Do something here
done
for ((l=1; l<=${config[number]}; l++))
do
# And do something here
done
Inside the loops I'm just creating a few VMs but think this is irrelevant for this question.
The values of config[vnc_number] and config[number] are defined in another file but reading these out works just fine, I tried it.
The first loop works just fine but the wierd thing is that in the second loop it throws the error:
create_vms.sh: line 109: ((: l<=3
2: syntax error in expression (error token is "2")
I tried various things to fix it but nothing seems to work so I am asking you guys.
Thanks in advance for the help.
I'm trying to access a search text box inside of our company's ERP system using Selenium. The screenshot shows the text box and the Xpath of the element.
This is a little tricky, because that Menu Search pop-up isn't really a pop-up. It somehow shows up when a user types Control + M.
By installing ChroPath and testing I've found the text-box always starts with the following string:
txtMenuSearch_Namespace_
I've tried to imitate what's described here, here and here with no luck.
The latest attempt in the snippet of my code looks like this:
menu_search_input_box_elements = driver.find_elements_by_xpath("//*[contains(#id, ‘txtMenuSearch_Namespace_’)]")
for item in menu_search_input_box_elements:
print(item)
I get the following error message:
SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//*[contains(#id, ‘txtMenuSearch_Namespace_’)]' is not a valid XPath expression.
In all my attempts to get the syntax right I keep getting this message. Any help in figuring out how to .send_keys() to this field is greatly appreciated.
You get en error because of the ‘’ quotes, replace them with correct ones.
# id starts with txtMenuSearch_Namespace_
menu_search_input_box_elements = driver.find_elements_css_selector("[id^='txtMenuSearch_Namespace_']")
menu_search_input_box_elements = driver.find_elements_by_xpath("//*[contains(#id, 'txtMenuSearch_Namespace_')]")
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.
I'm having trouble finding examples/troubleshooting tips online, and am not quite sure that I'm interpreting the documentation correctly. Any assistance would be greatly appreciated.
I'm connecting to an e-mail server, and want to read the e-mail subjects, and bodies. I first make my connection like so:
import imaplib
c = imaplib.IMAP4_SSL(hostname, port)
c.login(username, password)
foldername = 'INBOX/SSR'
c.select(str.encode(foldername), readonly = True)
today = datetime.date.today().strftime('%d-%b-%Y')
searchcriteria = '(SENTON '{}')'.format(today)
typ, msg_ids = c.search(None, searchcriteria)
msg_ids = [s.decode('ascii') for s in msg_ids]
for idnumber in msg_ids:
print(c.fetch(idnumber, "(BODY.PEEK[HEADER])"))
The code and works and output looks as expected, up until the last line, at which point, I get
imaplib.error: FETCH command error: BAD [b' Command Argument Error. 12']
My line of thought, and subsequent testing examined the following possible issues:
bytes vs. string. I converted input back to bytes, but the error remained constant
improper syntax: I tried other commands, such as BODY, SUBJECT, and ENVELOPE but still got the same message.
I'm not sure how to interpret the error, and don't really know where to start. Referencing https://www.rfc-editor.org/rfc/rfc3501.html from pp. 102+, I noticed that the values are labeled differently, but don't understand what the issue is with my implementation. How should I interpret the error? What is wrong with my syntax?
P.S. Correct me if I'm wrong, but the c.search shouldn't change my directory, yes? As in, by selecting foldername, I "navigate" to the selected folder, but just searching only returns values and shouldn't change my location?
I encountered the same problem while I tried to list or select a new mailbox - BAD [b' Command Argument Error. 12'], in my case, it didn't work with “Sent Box”, but it worked well with “Outbox”, so the space symbol is the point.
So it worked with c.select('"{}"'.format("Sent Box")...
Hope this information could help you.
Your last line is not correct msg_ids = [s.decode('ascii') for s in msg_ids]
msg_ids is a list with bytes string, not with elements of a list - example: [b'123 124 125']
Change the last line into msg_ids = msg_ids[0].split(b' ') and it will work as expected.