我collect2: error: ld returned 1 exit status
经常看到这个错误.例如,我正在执行以下代码片段:
void main() {
char i;
printf("ENTER i");
scanf("%c",&i);
clrscr();
switch(i) {
default:
printf("\nHi..\n");
break;
case 1:
printf("\n\na");
break;
case 2:
printf("\nb\n");
break;
case 3:
printf("\nc");
break;
}
}
Run Code Online (Sandbox Code Playgroud)
我得到了这个:
main.c:(.text+0x33): undefined reference to `clrscr'
collect2: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
这是什么意思?
如何使用reStructuredText创建链接图像?
我发现了
.. image:: /path/to/image.jpg
Run Code Online (Sandbox Code Playgroud)
用于图像和外部超链接
'Python <http://www.python.org/>'_
Run Code Online (Sandbox Code Playgroud)
对于链接,但我不知道如何组合它们或者如果可能的话.
我有以下内容conf.py
:
def setup(app):
app.add_config_value('base_url','http://localhost:2000', True)
Run Code Online (Sandbox Code Playgroud)
如何将其插入我的.rst文件?我写了这个:
:base_url:/my_app/api/application/
Run Code Online (Sandbox Code Playgroud)
但它只打印:base_url:
而不是实际的URL.
如何获取要发出的实际配置值?
我想在re.findall
函数中使用多个标志.更具体地说,我想同时使用IGNORECASE
和DOTALL
标志.
x = re.findall(r'CAT.+?END', 'Cat \n eND', (re.I, re.DOTALL))
Run Code Online (Sandbox Code Playgroud)
错误:
Traceback (most recent call last):
File "<pyshell#78>", line 1, in <module>
x = re.findall(r'CAT.+?END','Cat \n eND',(re.I,re.DOTALL))
File "C:\Python27\lib\re.py", line 177, in findall
return _compile(pattern, flags).findall(string)
File "C:\Python27\lib\re.py", line 243, in _compile
p = sre_compile.compile(pattern, flags)
File "C:\Python27\lib\sre_compile.py", line 500, in compile
p = sre_parse.parse(p, flags)
File "C:\Python27\lib\sre_parse.py", line 673, in parse
p = _parse_sub(source, pattern, 0)
File "C:\Python27\lib\sre_parse.py", line 308, in _parse_sub
itemsappend(_parse(source, state)) …
Run Code Online (Sandbox Code Playgroud) 我正在测试代码,其中可以引发两个异常之一:MachineError或NotImplementedError.我想用它pytest.raises
来确保在运行我的测试代码时至少引发其中一个,但它似乎只接受一个异常类型作为参数.
这是签名pytest.raises
:
raises(expected_exception, *args, **kwargs)
Run Code Online (Sandbox Code Playgroud)
我尝试or
在上下文管理器中使用关键字:
with pytest.raises(MachineError) or pytest.raises(NotImplementedError):
verb = Verb("donner<IND><FUT><REL><SG><1>")
verb.conjugate()
Run Code Online (Sandbox Code Playgroud)
但我认为这只检查第一个pytest.raises
是否None
,并将第二个设置为上下文管理器(如果是).
将多个异常作为位置参数传递不起作用,因为pytest.raises
它的第二个参数是可调用的.每个后续位置参数都作为参数传递给该可调用对象.
从文档:
>>> raises(ZeroDivisionError, lambda: 1/0)
<ExceptionInfo ...>
>>> def f(x): return 1/x
...
>>> raises(ZeroDivisionError, f, 0)
<ExceptionInfo ...>
>>> raises(ZeroDivisionError, f, x=0)
<ExceptionInfo ...>
Run Code Online (Sandbox Code Playgroud)
将异常作为列表传递也不起作用:
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
with pytest.raises([MachineError, NotImplementedError]):
File "/usr/local/lib/python3.4/dist-packages/_pytest/python.py", line 1290, in raises
raise TypeError(msg …
Run Code Online (Sandbox Code Playgroud) 我在iOS应用程序中从API获取ISO语言代码.例如,en
对于英语,hi
印地语等,我想将这些ISO代码转换为各自的语言名称.
这是由API返回的:
"category": "TVCHANEL",
"chanellanguage": "ar",
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?我是否必须创建一个ISO代码作为每种语言的关键词典?
所以我在Python中为Fibonacci序列做了一个递归lambda.我使用递归,因为它最容易用lambda实现.
fib = lambda n: fib(n - 1) + fib(n - 2) if n > 1 else 1
Run Code Online (Sandbox Code Playgroud)
因为使用递归,相同的Fibonacci值被计算了很多次,我认为使用缓存装饰器会有所帮助,我知道这functools.lru_cache
是一个简单的选择.
我知道你不能将装饰器应用到@functools.lru_cache
像普通函数一样的lambda函数,但当我尝试这个时:
fib = functools.lru_cache((lambda n: fib(n - 1) + fib(n - 2) if n > 1 else 1), maxsize = None)
Run Code Online (Sandbox Code Playgroud)
我得到一个错误,functools.lru_cache
说不接受函数对象作为参数.
>>> fib = functools.lru_cache((lambda n: fib(n - 1) + fib(n - 2) if n > 1 else 1), maxsize = None)
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
fib …
Run Code Online (Sandbox Code Playgroud) 我在Python 2.7中使用ConfigParser从配置文件中读取,我想知道如何读取一个值,使其None
在Python中设置为常量.
目前,我的代码如下:
config.set("Test Series Parameters", "Test Series Parameter", None)
Run Code Online (Sandbox Code Playgroud)
但是,这显示为Test Series Parameter = "None"
(作为字符串).
我必须写两个线程.每个人打印5个偶数/奇数从1到100这样(奇数是impair
法语,偶数pair
).
even 2,4,6,8,10
odd 1,3,5,7,9
even 12,14,16,18,20
odd 13,15,17,19,21
etc...
Run Code Online (Sandbox Code Playgroud)
我写了这段代码:
#include <stdio.h>
#include <semaphore.h>
#include <pthread.h>
#define maxi 100
pthread_mutex_t mutex;
sem_t p;
sem_t imp;
int tour = 0;
void *pair(void *arg);
void *impair(void *arg);
int main() {
pthread_t tidp, tidimp;
pthread_mutex_init(&mutex, NULL);
sem_init(&p, 0, 1);
sem_init(&imp, 0, 1);
pthread_create(&tidp, NULL, pair, (void *)2);
pthread_create(&tidimp, NULL, impair, (void *)1);
pthread_join(tidp, NULL);
pthread_join(tidp, NULL);
sem_destroy(&imp);
sem_destroy(&p);
pthread_mutex_destroy(&mutex);
return 0;
}
void *pair(void *arg) {
int i …
Run Code Online (Sandbox Code Playgroud) 为什么哈希apple:2
在打印输出时会删除第一个值?
use warnings;
use strict;
use Data::Dumper;
my @array = ("apple:2", "pie:4", "cake:2");
my %wordcount;
our $curword;
our $curnum;
foreach (@array) {
($curword, $curnum) = split(":",$_);
$wordcount{$curnum}=$curword;
}
print Dumper (\%wordcount);
Run Code Online (Sandbox Code Playgroud) python ×4
c ×2
python-3.x ×2
arrays ×1
configparser ×1
exception ×1
hash ×1
ios ×1
ipc ×1
iso ×1
lambda ×1
mutex ×1
objective-c ×1
perl ×1
pytest ×1
python-2.7 ×1
recursion ×1
regex ×1
semaphore ×1