Microsoft Visual C + + Compiler for Python 2.7

Source: Internet
Author: User

EXTEST.C file:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "Python.h"

#define BUFSIZE 10

int FAC (int n) {
if (n < 2)
return 1;
return n * FAC (N-1);
}

Char *reverse (char *s) {
Register char t;
char *p = s;
Char *q = (s + (strlen (s)-1));
while (P < q) {
t = *p;
*p++ = *q;
*q--= t;
}
return s;
}

Static Pyobject *
EXTEST_FAC (Pyobject *self, Pyobject *args) {
int res;
int num;
pyobject* retval;

res = pyarg_parsetuple (args, "I", &num);
if (!res) {
return NULL;
}
RES = FAC (num);
retval = (Pyobject *) py_buildvalue ("I", res);
return retval;
}

Static Pyobject *
Extest_reverse (Pyobject *self, Pyobject *args) {
Char *orignal;
if (! ( Pyarg_parsetuple (args, "s", &orignal))) {
return NULL;
}
Return (Pyobject *) py_buildvalue ("s", Reverse (orignal));
}

Static Pyobject *
Extest_doppel (Pyobject *self, Pyobject *args) {
Char *orignal;
Char *RESV;
Pyobject *retval;
if (! ( Pyarg_parsetuple (args, "s", &orignal))) {
return NULL;
}
retval = (Pyobject *) Py_buildvalue ("ss", Orignal, Resv=reverse (StrDup (orignal)));
Free (RESV);
return retval;
}

Static Pymethoddef
Extestmethods[] = {
{"FAC", EXTEST_FAC, Meth_varargs},
{"Doppel", Extest_doppel, Meth_varargs},
{"Reverse", Extest_reverse, Meth_varargs},
{null, NULL},
};

void Initextest () {
Py_initmodule ("Extest", extestmethods);
}

int main () {
Char S[bufsize];
printf ("4! = =%d\n ", FAC (4));
printf ("8! = =%d\n ", FAC (8));
printf ("12! = =%d\n ", FAC (12));
strcpy (S, "abcdef");
printf ("Reversing ' abcdef ', we get '%s ' \ n", reverse (s));
strcpy (S, "Madam");
printf ("Reversing ' madam ', we get '%s ' \ n", reverse (s));
return 0;
}

Modify the Python installation directory under the lib\distutils\msvc9compiler.py file (if necessary msvccompiler.py the file will also need to make corresponding changes, depending on the system), find Get_build_ The version method directly return 9.0
Then find the Find_vcvarsall method to return the path of the Vcvarsall.bat directly (whichever is the path after the installation of your own machine)
return R ' C:\Users\Administrator\AppData\Local\Programs\Common\Microsoft\Visual C + + for Python\9.0\vcvarsall.bat ' Both changes are loaded with the substring string, and you can

To create the setup.py file, enter the following:
#!/usr/bin/env python
From Distutils.core import Setup, Extension
MOD = ' Extest '
Setup (Name=mod, Ext_modules=[extension (MOD, sources=[' extest.c ')])


Then enter the Python setup.py build in the corresponding prompt of Visual C + + for Python to build the C and Python version of the library file or python setup.py install

Of course, you can also create a Windows binary package
Python setup.py bdist_wininst

Microsoft Visual C + + Compiler for Python 2.7

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.