Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python SyntaxError:非关键字xlwings_Python_Python 2.7_Xlwings - Fatal编程技术网

Python SyntaxError:非关键字xlwings

Python SyntaxError:非关键字xlwings,python,python-2.7,xlwings,Python,Python 2.7,Xlwings,尝试运行以下代码时: import xlwings as xw from xlwings.constants import SortOrder from xlwings.constants import SortOrientation def xlwingstest(): wb = xw.Book.caller() wb.app.screen_updating = 'False' xw.Range('A3:B8501').api.Sort(Key1=wb.Sheets

尝试运行以下代码时:

import xlwings as xw
from xlwings.constants import SortOrder
from xlwings.constants import SortOrientation

def xlwingstest():
    wb = xw.Book.caller()
    wb.app.screen_updating = 'False'

    xw.Range('A3:B8501').api.Sort(Key1=wb.Sheets('Sheet1').xw.Range('A3'), SortOrder.xlDescending, 
             SortOrientation.xlSortColumns)
我得到以下错误:

回溯(最近一次呼叫最后一次):

文件“”,第1行,在

文件“xlwings\u sort\u data1.py”,第16行

SyntaxError:关键字arg之后是非关键字arg


我正在使用python 2.7

您不能在非关键字arg之前放置关键字arg,例如
Key1=
。从中,可以找到
范围.Sort
方法参数。我想你想做:

xw.Range('A3:B8501').api.Sort(Key1=wb.Sheets('Sheet1').xw.Range('A3'),
 Order1=SortOrder.xlDescending,
 Orientation=SortOrientation.xlSortColumns)

你知道什么是关键字和非关键字参数吗?正如错误所说,你不能把前者放在后者之后。我不知道什么是关键字和非关键字参数,但我在看了@Luca的答案后才知道。谢谢你的回答。我测试了它并得到了以下错误:
文件“c:\users\xlwings\u sort\u data1.py”,第16行,在xlwingstest xw.Range('A3:B8501').api.sort(Key1=wb.Sheets('Sheet1').xw.Range('A3'),AttributeError:'Book'对象没有属性'Sheets'
xw.Range('A3:B8501').api.Sort(Key1=wb.Sheets('Sheet1').xw.Range('A3'),
 Order1=SortOrder.xlDescending,
 Orientation=SortOrientation.xlSortColumns)