Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I am trying to read excel file using python to do some data analysis. The data file is located in the same folder as the python program. However, the code is giving a syntax error. Do not know why. Appreciate your help.
import pandas as pd
dataIn_df = pd.read_excel(r 'C:\Users\Jon\AppData\Local\Programs\Python\data\InputData.xlsx', sheet_name='InputData')
File "C:\Users\Jon\AppData\Local\Programs\Python\data\RateRegulator.py", line 54
dataIn_df = pd.read_excel(r 'C:\Users\Jon\AppData\Local\Programs\Python\data\InputData.xlsx', sheet_name='InputData')
^
SyntaxError: invalid syntax
There is an extra space between r and 'C:\... this is causing the SyntaxError.
r 'C:\Users\Jon\AppData\Local\Programs\Python\data\InputData.xlsx'
should be
r'C:\Users\Jon\AppData\Local\Programs\Python\data\InputData.xlsx'
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 12 months ago.
Improve this question
Just starting out learning Python and programming in general. Following along with a video on LIL and everything has worked fine up until now. I'm trying to access the first 3 rows of a specified series with the following code. I keep getting a syntax error where it highlights my colon. What am I doing wrong? It looks exactly like the text in the video.
import pandas as pd
import xlsxwriter
from openpyxl.workbook import Workbook
df = pd.read_excel("C:/Users/Aaron/Desktop/filename.xlsx")
print(df['Visit '],[1:3])
print(df['Visit '],[1:3])
The placement of the comma means you are passing two separate items to print():
df['Visit ']
[1:3]
The problem is the second item. [1:3] is not valid by itself.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I am trying to generate a filename in python on mac to record data everyday so that the filename has date in filename. Please refer the command below.
oi_filename= os.path.join("markets","storage","oi_data_records_{0}.json".format(datetime.now().strftime(%d%m%Y)))
where markets is in Desktop and storage is in markets folder.
Error
File "<ipython-input-20-e3a1aee3f506>", line 21
oi_filename= os.path.join("markets","storage","oi_data_records_{0}.json".format(datetime.now().strftime(%d%m%y)))
^
SyntaxError: invalid syntax
The basic idea is everyday a file to be created with full date in name so that the rest of program can park the data in the respective file.
It's because you didn't put the %d%m%y in a string.
oi_filename= os.path.join("markets","storage","oi_data_records_{0}.json".format(datetime.now().strftime(%d%m%Y)))
should be:
oi_filename= os.path.join("markets","storage","oi_data_records_{0}.json".format(datetime.now().strftime("%d%m%Y")))
You are missing quotation marks for strftime(%d%m%y). It should be strftime('%d%m%y')
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I am trying to make a script that can delete a file with Python. When I moved the file to my startup directory with my script, a lot of the code was changed, not by me. I've just assumed this was normal and continued trying to make it delete a file on startup. I later realized it wasn't working because one of the call methods kept getting an invalid syntax. Here's my code.
Python Version: 3.8.7
Error message is :
invalid syntax (<unknown>, line 7)
LOAD_CONST(0), LOAD_CONST(None), IMPORT_NAME(os), STORE_NAME(os)
LOAD_CONST(0), LOAD_CONST(None), IMPORT_NAME(shutil), STORE_NAME(shutil)
source = 'C:\\Users\\me\\OneDrive\\Desktop\\startup.py'
destination = 'C:\\Users\\me\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup'
LOAD_NAME(shutil), LOAD_METHOD(move), LOAD_NAME(source), LOAD_NAME(destination), CALL_METHOD[2], STORE_NAME(new_path)
print(new_path)
LOAD_NAME(os), LOAD_METHOD(remove), LOAD_CONST('C:/Users/me/OneDrive/Desktop/delete.txt'), CALL_METHOD[1], POP_TOP
print('File Removed!'), return None
From the code, it's difficult to understand what you are trying to do. If you want to delete a file, you can use the os module in python. For example:
import os
os.remove("/some/file/path/to/remove.txt")
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I have this syntax error for exactly 1 line of code. The other don't seem to be having the problem. I am inputting from an excell file to the elements. therefore, the first cell seems to be working. The syntax error occurs at the 3rd time when searching for the element.
Tried multiple other ways to change the finding the element type. instead of driver.find_element_by_id("###") i tried driver.find element(BY.ID("####")
My Code:
driver.find_element_by_id("name").send_keys(sheet[("A"+ str(2))].value)
driver.find_element_by_id("day").send_keys(sheet[("B"+ str(2))].value)
driver.find_element_by_id("month").send_keys(sheet[("C"+ str(2))].value)
driver.find_element_by_id("year").send_keys(str("1997")
driver.find_element_by_id("hrs").send_keys(sheet[("E"+ str(2))].value)*
Output:
driver.find_element_by_id("hrs").send_keys(sheet[("E"+ str(2))].value)
^
SyntaxError: invalid syntax
Process finished with exit code 1
driver.find_element_by_id("year").send_keys(str("1997")
This line is missing a closing parentheses.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
There are different files in a folder, I would like to print files which are ended with IHDRT.exr. The correct answer for this job is as shown bellow:
#!/usr/bin/env python
import glob
for file in glob.glob("*.exr"):
if file.endswith('iHDRT.exr'):
print(file)
#!/usr/bin/env python
import glob
for file in glob.glob("*.exr"):
if file.endswith('iHDRT.exr'):
^^^^^^^^
print(file)
Its endswith and not endswidth
Use endswith, not endswidth! Error spelling