Calling a C program from a Python Script
It's me
itsme at yahoo.com
Thu Dec 9 13:42:59 EST 2004
I would expect C to run circles around the same operation under Python. As
a general rule of thumb, you should use C for time cirtical operations
(computer time, that is), and use Python for human time critical situations
(you can get a program developed much faster).
I just discovered a magical package call SWIG (http://www.swig.org) that
makes writing C wrappers for Python always a child's play. It's incredible!
Where were these guys years ago when I had to pay somebody moocho money to
develop a script language wrapper for my application!!!
--
It's me
"Brad Tilley" <bradtilley at gmail.com> wrote in message
news:cpa5l5$aua$1 at solaris.cc.vt.edu...
> Grant Edwards wrote:
> > Huh? What do you mean "write a file open"? You want to read a
> > C source file and execute the C source? If you have access to
> > a C interpreter, I guess you could invoke the interpreter from
> > python using popen, and feed the C source to it. Alternatively
> > you could invoke a compiler and linker from C to generate an
> > executable and then execute the resulting file.
> >
> >
> >>for root, files, dirs in os.walk(path)
> >> for f in files:
> >> try:
> >> EXECUTE_C_PROGRAM
> >
> >
> > You're going to have to explain clearly what you mean by
> > "EXECUTE_C_PROGRAM". If you want to, you can certainly run a
> > binary executable that was generated from C source, (e.g. an
> > ELF file under Linux or whatever a .exe file is under Windows).
>
> Appears I was finger-tied. I meant "a C program that opens and reads
> files" while Python does everything else. How does one integrate C into
> a Python script like that?
>
> So, instead of this:
>
> for root, files, dirs in os.walk(path)
> for f in files:
> try:
> x = file(f, 'rb')
> data = x.read()
> x.close()
> this:
>
> for root, files, dirs in os.walk(path)
> for f in files:
> try:
> EXECUTE_C_PROGRAM
>
> From the Simpsons:
> Frink: "Here we have an ordinary square."
> Wiggum: "Whoa! Slow down egghead!"
More information about the Python-list
mailing list