I tried to compile fizzbuzz.c
, in order to import it by python. For building fizzbuzz.c
,I used python setup.py build_ext -i
.
After building it, I tried to import fizzbuzz.c
but the error below occurred.
How can I solve this problem ?
Error
>>> import fizzbuzz
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dynamic module does not define init function (initfizzbuzz)
fizzbuzz.c
#include <stdio.h>
void fizzbuzz(int n){
for (int i=1; i <= n; i++){
if (i % 3 == 0 && i % 5 ==0){
printf("fizzbuzz %d
", i);
}
else if (i % 3 == 0){
printf("fizz %d
", i);
}
else if(i % 5 == 0){
printf("buzz %d
", i);
}
}
}
setup.py
from distutils.core import setup, Extension
module = Extension('fizzbuzz', ['fizzbuzz.c'])
setup(
name='fizzbuzz',
version='1.0',
ext_modules=[module],
)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…