Any reason to try and replace it with something else? I'm a beginner to python, but have encountered problems with C and importing CGI. List of instance where import cgi would not be the best option would be great for further understanding of language use.
-
What are you trying to do? – Blender May 09 '13 at 17:37
-
What do you mean by "problems with C and importing CGI"? I can think of lots of ways to interpret that phrases, but none of them make any sense. Are you trying to write `import CGI` in C code? Trying to run C code as Python? Successfully importing the Gateway Interface but can't get the Common? Your CGIs work, but whatever page you generate, the `C`s run around beating up the lowercase letters and stealing their lunch money? – abarnert May 09 '13 at 18:08
2 Answers
You should choose WSGI instead of CGI. CGI applications are generally slow as they need re- invocation of interpreter for every request, WSGI on the other hand pools them and is much more efficient. WSGI is also more mainstream. Do a little research on web and you will get better and more detailed answers.
In the past I have used CGI with python but generally the usage has been for image/chart generation,where the core lib was implemented in c/c++.

- 4,522
- 33
- 28
-
I found one link which might help http://stackoverflow.com/questions/1813394/why-should-i-use-wsgi – varun May 09 '13 at 17:48
List of instance where import cgi would not be the best option
If you're writing a script which will be installed and run as a CGI script on a web server, and you're not using some other framework that replaces it, import cgi
is always the best option.
So, the cases where it's not the best option:
- You're not writing a CGI script.
- You don't need access to
FieldStorage
or anything else from the gateway. - You're using a framework with its own replacement for
cgi
.
That's about it.
If you're not sure whether you want to use CGI or not in the first place… you probably don't. If you want the same general style of coding as CGI, WSGI is just as simple, more flexible, and usually faster.
But if you're just starting at this stuff, that may not even be the style you want. Start at the high level. Do you want to template web pages, or serve JSON to JavaScript code that does the dynamic stuff in the browser? What features do you need on your user sessions? And so on. Once you know what you want, then see if there's a framework—Django, Tornado, CherryPy, whatever—that looks like it'll make your design easier. Only then ask yourself whether you want WSGI, CGI, mod_python, an embedded server, …

- 354,177
- 51
- 601
- 671