Taking on C from a cold start and being able to handle the ins and
outs of interfacing with Python isn't something that's feasible in
'two or three weeks'. Here are a couple of options -- take 'em or
leave 'em:
1) Put the code in Cython: http://www.cython.org/ (full disclosure:
I'm doing a GSoC project with Cython). It will convert pretty much
any python code into C code (even closures are supported in the most
recent version, I think), and the C code can then be compiled into an
extension module.
The only problem with the above is the C code isn't, at first blush,
easy to read. Nor is it supposed to be changed by the user. So that
leads us to option...
2) Write the core functionality in C yourself, and then wrap those C
functions in Cython. You'll want to take a look at the documentation:
and, more specifically on wrapping C code:
http://docs.cython.org/docs/external_C_code.html
I don't think you'll be able to avoid learning C, though.
Kurt
http://mail.python.org/pipermail/python-list/2000-June/039779.html
My experience is that developers who know C and C++ can be productive in
less than 1 week in python, and find it liberating, and educational, to
do so. And at the same time they will have added a second language to
their toolbox. As Kurt points out, learning C/C++ takes considerably
longer (weeks/months to attain a level of competence).
Python is now used in a number of universities as the language in which
to teach comp sci undergraduate courses (I know of Leeds, & MIT),
biomathematics, and my daughter just finished her PhD in speech and
language processing at Edinburgh .. using python and Matplotlib .. as
the extensive C/C++ libraries in that infomatics world are wrapped in
python - and the MSc Comp Sci course has replaced Java as the language
for teaching with Python.
Dr Tim Couper
http://docs.cython.org/docs/external_C_code.html
Kurt
--
http://mail.python.org/mailman/listinfo/python-list
*****************************************************************************
This communication is sent by the Standard Bank Plc or one of its affiliates
The registered details of Standard Bank Plc are:
Registered in England No. 2130447, Registered Office 25 Dowgate Hill London EC4R 2SB
Authorised and Regulated by the Financial Services Authority.
More information on Standard Bank is available at www.standardbank.com
Everything in this email and any attachments relating to the official business of Standard Bank Group Limited and any or all subsidiaries, the Company, is proprietary to the Company. It is confidential, legally privileged and protected by relevant laws. The Company does not own and endorse any other content. Views and opinions are those of the sender unless clearly stated as being that of the Company.
The person or persons addressed in this email are the sole authorised recipient. Please notify the sender immediately if it has unintentionally, or inadvertently reached you and do not read, disclose or use the content in any way and delete this e-mail from your system.
The Company cannot ensure that the integrity of this email has beenmaintained nor that it is free of errors, virus, interception or interference. The sender therefore does not accept liability for any errors or omissions in the contents of this message which arise as a result of e-mail transmission. If verification is required please request a hard-copy version. This message is provided for informational purposes and should not be construed as a solicitation or offer to buy or sell any securities or related financial instruments.
*****************************************************************************
> Your prof. may find this thread of interest
>
> http://mail.python.org/pipermail/python-list/2000-June/039779.html
>
> My experience is that developers who know C and C++ can be productive in
> less than 1 week in python, and find it liberating, and educational, to
> do so. And at the same time they will have added a second language to
> their toolbox. As Kurt points out, learning C/C++ takes considerably
> longer (weeks/months to attain a level of competence).
I agree. Your professor is deluded and knows nothing about
software development [not that either is particularly unusual
in an academic setting]. Converting a Python program to C or
C++ is a complete waste of time (both now _and_ later) unless
there are severe, insurmountable performance problems with the
Python version.
Python is a far, far better language for both real-world
production application development and for algorithm R&D. With
Python, you spend your time working on algorithms and solving
real-world problems. In C or C++, you spend your time fighting
with the bugs in your code that are preventing the program from
running. An algorithm that takes a few hours to implement and
test in Python will take weeks in C or C++.
That said, you'll be niether the first nor last person to be
forced by a professor or manager to waste weeks or months of
time doing something that's obviously stupid and futile from a
technical point of view.
--
Grant Edwards grante Yow! What's the MATTER
at Sid? ... Is your BEVERAGE
visi.com unsatisfactory?
3) use Python-SIMPL to connect your C module to your Python module
using a 5 function API without any need for wrappers. ie. have your
cake and eat it too
http://www.icanprogram.com/06py/main.html
bob
Yup. Remember that "be productive" is not quite the same as "master."
The nice thing is that the mastery comes on a gentle slope, adding to
your productivity without requiring drastic rethinking of all you
understood (as is done to physics students, for example).
> Python is now used in a number of universities as the language in which
> to teach comp sci undergraduate courses (I know of Leeds, & MIT),
> biomathematics, and my daughter just finished her PhD in speech and
> language processing at Edinburgh .. using python and Matplotlib .. as
> the extensive C/C++ libraries in that infomatics world are wrapped in
> python - and the MSc Comp Sci course has replaced Java as the language
> for teaching with Python.
As a data point, Georgia Tech (I believe) had a two-semester Computer
Science intro course in C++. In introducing a Python intro course, they
provided for a few years both the Python and the C++ first semester,
and kept the C++ second semester. They found no measurable difference
in the performance on the second course (still in C++) even though the
Python course people had to learn a new language in addition to learning
the rest of the coursework. The first course is now in Python, since
at the end of the two-semester sequence they know two languages and
apparently suffer no compensating loss.
--Scott David Daniels
Scott....@Acm.Org
Your professor should wait until your Python version is complete and in
final form and until a C version is needed. Then hire someone competent
in both languages to do the translation.
> Your professor should wait until your Python version is complete and in
> final form and until a C version is needed. Then hire someone competent
> in both languages to do the translation.
Professor... hire...
Good one! :)
--
Grant Edwards grante Yow! BARRY ... That was
at the most HEART-WARMING
visi.com rendition of "I DID IT MY
WAY" I've ever heard!!
There's another (very good) option: Try shedskin http://code.google.com/p/shedskin/
.
Shedskin can compile a whole program or part of it as an extension
module.
It translates python code to c++ and compiles it.
The good thing is that you don't have to know anything about c or c++.
You simply have to restrict your coding style a little bit to make it
explicitly static.
For example: if you declare a = 5, that means that "a" is an integer,
so you cannot then change it to a string (a = "hello", won't work).
Luis
What if the point of asking a student to convert Python to C is to
teach them this:
> Python is a far, far better language for both real-world
> production application development and for algorithm R&D. With
> Python, you spend your time working on algorithms and solving
> real-world problems. In C or C++, you spend your time fighting
> with the bugs in your code that are preventing the program from
> running. An algorithm that takes a few hours to implement and
> test in Python will take weeks in C or C++.
If that [teaching them this] is the case, it might be best use of time
they will ever have.
Carl Banks