小编RRR*_*RRR的帖子

python:UnboundLocalError:赋值前引用的局部变量'open'

def read_lines():
    readFileName = "readfile.txt"
    f = open(readFileName, 'r+')
    contents = f.read()
        ... # and so on 

read_lines()
Run Code Online (Sandbox Code Playgroud)

当我运行它时,我收到一个错误:

f = open(readFileName, 'r+')
UnboundLocalError: local variable 'open' referenced before assignment
Run Code Online (Sandbox Code Playgroud)

python

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

是否可以将.c文件包含在另一个.c文件中?

例如:

file1.c 具有:

static const struct 
{ 
   int a;
   int b;
   int c;
} mystruct = { 1, 2, 3};
Run Code Online (Sandbox Code Playgroud)

file2.c 具有:

#include <stdio.h>
#include "file1.c"
Run Code Online (Sandbox Code Playgroud)

等等.

这样可以吗?

c struct include

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

宏等效(C/C++)?

鉴于这个宏:

#define SOME_MACRO(ret, f, args) \
    typedef ret (*some_func_##f) args; \
    static some_func_##f my_func_##f = NULL;
Run Code Online (Sandbox Code Playgroud)

请让我知道相应的:

SOME_MACRO(void,  myFunctionName, (int a));
Run Code Online (Sandbox Code Playgroud)

谢谢.

c macros c-preprocessor

0
推荐指数
1
解决办法
243
查看次数

C++ 宏#ifdef

void testFunc();

int myval = 0;

int main()
{
    int a = 1;

    if (a > 0)
    {
        #define TEST1
        testFunc();
        #undef TEST1
    }

    int b = 2;
    if ( b > 0)
    {
        #define TEST2
        testFunc();
        #undef TEST2
    }

    std::cout << "val : " << myval << endl;

    getchar();

    return 0;
}


void testFunc()
{

#ifdef TEST1
#define HERE 1
#endif

#ifdef TEST2
#define HERE 2
#endif

#ifdef HERE
    myval = HERE;
#else
    myval = -1;
#endif

}
Run Code Online (Sandbox Code Playgroud)

如何在第一次调用 …

c++ macros preprocessor

0
推荐指数
1
解决办法
201
查看次数

在Linux上批量运行python脚本?

请告诉我是否有一种方法可以在Linux上批量运行多个python脚本,就像在Windows上使用.bat文件批量运行多个python脚本的方式一样?谢谢.

python linux batch-file

-6
推荐指数
1
解决办法
4802
查看次数

标签 统计

c ×2

macros ×2

python ×2

batch-file ×1

c++ ×1

c-preprocessor ×1

include ×1

linux ×1

preprocessor ×1

struct ×1