'as'中的语法错误,是关于导入的吗?

时间:2017-08-24 07:25:34

标签: python django

我复制并粘贴了强力球模型from GitHub以制作强力球网站。

但它不适用于错误消息,即最后一个

中的语法无效
(as=rng, outsz=6)

我应该怎么做才能修复它?这是关于import的错误吗?我应该安装其他套餐吗?

from django.db import models
from django.conf import settings, BaseSettings
from django.utils import timezone
import random

from .rng import random_numbers, _sort
from .eth_tools import address, Contract

def buy_ticket(first,second,third,fourth,fifth,powerball):
 if msg.value >= self.config.ticket_cost:
    if block.number <= self.config.lottery_deadline:
        id = self.config.next_id

        if self._validate_ticket(first, second, third, fourth, fifth, powerball ) != 1:
             return(-3)

        self.tickets[id].owner = msg.sender
        self.tickets[id].numbers[0] = first
        self.tickets[id].numbers[1] = second
        self.tickets[id].numbers[2] = third
        self.tickets[id].numbers[3] = fourth
        self.tickets[id].numbers[4] = fifth
        self.tickets[id].powerball = powerball

        self.config.next_id = id + 1

        return([id], 1)
      else:
        return(-2)
 else:
    return(-1)

def check_winners():
    if (block.number <= self.config.lottery_deadline):
        return(-1)
    elif self.config.winning_numbers[0] != 0:
        return(-2)
    else:
        winning_numbers = self.config.rng_address.random_numbers(as = rng, outsz =  6)

    i = 0
    while i < 6:
        self.config.winning_numbers[i] = winning_numbers[i]
        i += 1
    i = 0
    while i < self.config.next_id:
        self._calculate_result(i)
        i += 1

    self._calculate_jackpot_results()

    return(winning_numbers, 6)

1 个答案:

答案 0 :(得分:6)

asreserved keywordwith statement的一部分,try statement中的except处理程序或import);关键字不能用作名称。

使用其他名称;一种常见的方法是在名称后添加_

self.config.rng_address.random_numbers(as_ = rng, outsz =  6)

但是,code you copied 不是Python代码

  

“强力球”式彩票 用蛇写的 ,用于先知的赏金。

(粗体斜体强调我的)。

而且,来自Serpent Builder's Guide

  

Serpent是用于编写以太坊合约的高级编程语言之一。该名称 的语言与Python非常相似 [。]

它也会在其他问题上失败;所有文件都有.se个扩展名,而不是.py个扩展名,表示这是一种不同的编程语言。与Python有许多相似之处,但更多差异不能被忽略。请改用serpent compiler