I started studying Python with anaconda + VS code today.
In the book Marketing Python, the following code was introduced in the section "Automating excel routine work", so I just typed in the code manually.
Then, although it worked properly up to the glob part, it did not work from openpyxl, and the same phenomenon occurred even if I copied and executed the answer code as it was.
I found out that SyntaxError: invalid syntax is a syntax error, but I am confused because I do not know the reason because the same phenomenon occurs even if I copy and paste.
The content is to create a new file by collecting a lot of Excel files under/task2/data/in the folder directory into/task2/output /.
I am a beginner and the explanation may not be good, but I am sorry but I would appreciate it if you could answer.
I kindly thank you.
>>>C: /ProgramData/Anaconda3/python.exe c:/Users/[user name] /OneDrive/document/python/tutorial/task2/task2_excel-merge.py
File "<stdin>", line 1
C: /ProgramData/Anaconda3/python.exe c: /Users/[username]/OneDrive/document/python/tutorial/task2/task2_excel-merge.py
^ ^
SyntaxError: invalid syntax
Corresponding source code
import glob
filelist = glob.glob ('./task2/data/*.xlsx')
import openpyxl
out_workbook = openpyxl.Workbook ()
out_sheet = out_workbook.active
out_sheet.title ='Monthly report list'
out_sheet ['A1']. value ='report date'
out_sheet ['B1']. value ='branch'
out_sheet ['C1']. value ='person in charge'
out_sheet ['D1']. value ='Sales target (thousand yen)'
out_sheet ['E1']. value ='Sales record (thousand yen)'
out_sheet ['F1']. value ='Difference (thousand yen)'
out_sheet ['G1']. value ='Achievement rate (%)'
for i, file in enumerate (filelist):
workbook = openpyxl.load_workbook (file, data_only = True)
sheet = workbook ['business report']
report_date = sheet ['X1']. value
office = sheet ['X2']. value
person = sheet ['X3']. value
sales_goal = sheet ['H9']. value
sales_result = sheet ['H10']. value
sales_diff = sheet ['H11']. value
sales_percentage = sheet ['H12']. value
out_sheet.cell (row = i + 2, column = 1) .value = report_date
out_sheet.cell (row = i + 2, column = 2) .value = office
out_sheet.cell (row = i + 2, column = 3) .value = person
out_sheet.cell (row = i + 2, column = 4) .value = sales_goal
out_sheet.cell (row = i + 2, column = 5) .value = sales_result
out_sheet.cell (row = i + 2, column = 6) .value = sales_diff
out_sheet.cell (row = i + 2, column = 7) .value = sales_percentage
out_sheet.cell (row = i + 2, column = 7) .number_format = '0%'
out_sheet.cell (row = i + 2, column = 1) .number_format ='yyyy year mm month dd day'
out_filename ='./task2/output/ Monthly report list_202001.xlsx'
out_workbook.save (out_filename)
What I tried
nothing special
Supplementary information (FW/tool version, etc.)anaconda python 3.8
VS CODE 1.50.0
-
Answer # 1
-
Answer # 2
>>>
Is displayed after starting Python
C: /ProgramData/Anaconda3/python.exe c: /Users/[username]/OneDrive/document/python/tutorial/task2/task2_excel-merge.py
I think you are running.
Instead, on the terminal (command prompt)
C: /ProgramData/Anaconda3/python.exe c: /Users/[username]/OneDrive/document/python/tutorial/task2/task2_excel-merge.py
Please run the.
Related articles
- about the cause of the error in python pdto_datetime
- python 3x - best estimator: i get an error with no syntax, so please tell me what to do
- python - about anaconda exec format error
- syntaxerror: invalid syntax error python
- python - about the error log output method
- [python] i get a "syntax error" even if i enter a function according to the textbook
- python - i don't know the solution and cause of the attribute error that occurred when using pillow
- about python type error
- python 3x - about the contents of python error code
- python - about noreversematch error
- php - i'm getting a syntax error, but i don't know the cause i want to identify the cause
- ruby - about syntax error when running the calendar program
- python 3x - about value error in keras predict
- i want to resolve a syntax error in a python while statement
- python error (about arrays)
- about data acquisition using python from becoming a novelist
- python - about the implementation of fibonacci sequence
- python - about the average value calculation method of mass calculation
- python - about the fibonacci sequence using recursion
- the cause of the error related to the c language memory area is unknown
- python - vscode streamlit, pandas import error
- python - the web browser is garbled and the web application is not displayed
- python - 4 resolved title
- python - put your own data
- python - can't install with anaconda
- grayscale image acquisition of brightness value from each pixel also ported from c to python
- python - in jupyter, it comes out when the imported library is not found
- solution for error unexpected indent (python)
- python - importerror about xlrd that occurred when reading an excel file in jupyterlab
- how to organize data at creation time with python heatmap
There is nothing wrong with the code, but enter C: /ProgramData/Anaconda3/python.exe c: /Users/[username] /OneDrive/document/python/tutorial/task2/task2_excel-merge.py directly at the command prompt please.