如何解决此SyntaxError:无效语法?

时间:2019-09-06 03:39:30

标签: python

我是Python的新手,从GitHub获得了此代码,但出现了错误 带有top margin符号:

constraint layout

我无法通过搜索此错误找到解决方案。

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="16dp"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/topLeftText"
        android:layout_width="182dp"
        android:layout_height="wrap_content"
        app:layout_constraintEnd_toStartOf="@+id/topRightText"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintHorizontal_chainStyle="packed"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/topRightText"
        android:text="Test test test test test test test test test test" />

    <TextView
        android:id="@+id/topRightText"
        android:layout_width="182dp"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toTopOf="@+id/bottomText"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintVertical_chainStyle="packed"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toEndOf="@+id/topLeftText"
        app:layout_constraintTop_toTopOf="parent"
        android:text="Test test test test test test test test test test test test test test test test test test test test" />

    <androidx.constraintlayout.widget.Barrier
        android:id="@+id/barrier"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:barrierDirection="bottom"
        app:constraint_referenced_ids="topLeftText,topRightText" />

    <TextView
        android:id="@+id/bottomText"
        android:layout_width="379dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        android:text="Test test test test test test test test test test test test test test test test test test test test"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/topRightText" />


</androidx.constraintlayout.widget.ConstraintLayout>

1 个答案:

答案 0 :(得分:1)

您正在使用旧版本的Python。根据{{​​3}},Python 3.5中引入了“ matmul”运算符@

请参见示例代码:

class Asdf:

    def __init__ (self, x):
        self.x = x

    def __matmul__ (self, y):
        return self.x * y

a = Asdf (5)

print (a @ 3)

在Python3上运行良好:

$ python3 ./asdf.py 
15

但是它在Python2上失败,出现与上面列出的错误相同的错误:

$ python2 ./asdf.py 
  File "./asdf.py", line 16
    print (a @ 3)
             ^
SyntaxError: invalid syntax

有关matmul运算符的详细信息,请参见documentation答案。