小编mco*_*ley的帖子

在我的包的子包中运行python脚本

在找出正确的python 2.x首选方法进行相对导入时遇到一些麻烦,以便我可以将测试脚本保存在一个子包中,并让这些测试脚本能够测试我的库.

$ farm\testpad\testpad.py
Traceback (most recent call last):
  File "C:\farm\testpad\testpad.py", line 4, in <module>
    from ..animals.dog import dog
ValueError: Attempted relative import in non-package

$ python -m farm\testpad\testpad
C:\Python27\python.exe: No module named farm\testpad\testpad
Run Code Online (Sandbox Code Playgroud)

在以下示例中,我需要修改哪些内容才能执行我想要的操作?拜托,感谢您给予的任何帮助.

例如

包装结构:

farm/
    __init__.py # empty
    animals/
        __init__.py # empty
        dog.py
    testpad/
        __init__.py # empty
        testpad.py
Run Code Online (Sandbox Code Playgroud)

dog.py

import sys
import os

class dog():
  def __init__(self, name):
    self.name = name

  def speak(self):
    print "woof"
Run Code Online (Sandbox Code Playgroud)

testpad.py

import os
import sys

from ..animals.dog import …
Run Code Online (Sandbox Code Playgroud)

python import packages

10
推荐指数
1
解决办法
4293
查看次数

如何将flex lexical scanner生成器用作程序的一部分?

我如何使用我使用Flex编写的扫描仪作为我正在设计的程序的一部分?具体来说,在一个c ++类中作为一个类的方法,并从一个单独的文件中只用一个main方法来执行测试.

我不想使用%选项c ++,但会用g ++编译.

要回答如何从单独的文件主要测试扫描仪的问题,我尝试使用以下代码:

#include <iostream>
#include <stdio.h>
#include <stdlib.h>

using namespace std;

extern "C" {
    extern int yylex();
}

extern FILE* yyin;

int main(int argc, char *argv[]) {
    if (argc > 1)
        yyin = fopen(argv[1], "r");
    yylex();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我这样编译:

flex mylexer.l++
g++ lex.mylexer.C myDriver.C -o myLexer
Run Code Online (Sandbox Code Playgroud)

我明白了:

对yyin的未定义引用

对yylex的未定义引用

编译/设置驱动程序文件的正确方法是什么?感谢您阅读和贡献任何东西!

c c++ linux lex flex-lexer

5
推荐指数
1
解决办法
7920
查看次数

使用Bison构建AST

我正在与Bison合作,为正在编写的编译器构建AST。在AST中建立节点的最佳方法是什么?我的问题可能通过一个例子更加清楚。

给出以下代码段:

field
  : modifier type TOK_IDENT TOK_SEMICOLON
    {
      // I want to return a pointer to a node of type Field
      // i.e. $$ = new Field(name, isVisible, isStatic, type);
    }
  ;

modifier
    : visibility_opt static_opt
    {
      // Should I make the new Field here and pass it up?
      // Or a new type that contains both vis and static options?      
    }
  ;

visibility_opt
  : /* default */ { $$ = true; }
  | TOK_PUBLIC    { $$ = true; …
Run Code Online (Sandbox Code Playgroud)

c++ compiler-construction bison abstract-syntax-tree

5
推荐指数
1
解决办法
1664
查看次数

用Android实现Bouncy Castle密码算法

我如何使用Bouncy Castle提供程序来实现诸如Serpent和Twofish之类的算法,因为Sun的提供商根本不实现这些算法.我知道当多个提供商可以实现相同的算法时,您将获得最高等级提供商的实施,该提供商将成为Sun提供商.如果由于某种原因您想要使用特定提供程序的实现(可能因为您知道它更快),您可以在两个arg版本的getInstance()中指定提供程序.就我而言,Sun提供商根本没有实现我感兴趣的算法.

我试图实施Serpent:

    public static final String FILE_EXTENSION = ".serpent";
    public static final String PROVIDER = "BC"; // Bouncy Castle
    public static final String BLOCK_CIPHER = "Serpent";
    public static final String TRANSFORMATION = "Serpent/CBC/PKCS7Padding";
    public static final String KEY_ALGORITHM = "PBKDF2WithHmacSHA1";
    public static final String PRNG_ALGORITHM = "SHA1PRNG";

    public static final int BLOCK_SIZE = 128; // bits
    public static final int KEY_SIZE = 256; // bits
    public static final int ITERATION_COUNT = 1024; // for PBE

    /** Performs the encryption …
Run Code Online (Sandbox Code Playgroud)

java encryption android cryptography bouncycastle

4
推荐指数
1
解决办法
6281
查看次数

使用Google帐户保护Android身份验证

我的应用程序将处理敏感数据(私钥),因此必须有一种安全的方式来访问这些数据.我想将用户身份验证负担转嫁给Google,让他们根据验证其Google帐户信息来确定用户是否可以访问该应用.我正在研究使用WebView并使用OpenID协议,但作为一个更基于Web的协议,我仍在考虑其他选项.另一个要求也是用户必须在每次希望访问应用程序时进行身份验证,如果应用程序暂停,可能需要90秒窗口.

使用OpenID的WebView是我的最佳解决方案还是任何人都可以推荐更好的方法?

security openid authentication android

2
推荐指数
1
解决办法
3161
查看次数