Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

This question may seems a little bit silly, but what the heck.

I started to learn Python. I know basic syntax, etc.

When I work with HTML, PHP, etc., I simply write code, put it inside .html or .php file and double click this file. Then my code runs. I can work with databases and other stuff - it's just simple. But how does Python work? I'm working inside Eclipse or Python command line and I can run this code, but what if I want make website with Python for example?

I don't think it's like I put .py file on my server, so what I need to do? I understand I need to install Python on my webserver through some server command line (I've never used it, but I will find some tutorials day I will need it) but what's next? How can I combine my Python knowledge with HTML, CSS, PHP, etc.?

Python may also be used to create desktop apps, what then? Can I export .exe file with Python code or what?

Any links with content describing my concerns are welcome!

share|improve this question
5  
It sounds like you want to learn HOWTO Use Python in the Web. –  Mike Steinert Sep 13 '11 at 15:29
    
@Mike Steinert Yeah, it gives me a lot of information I wanted! Thank You very much –  smogg Sep 13 '11 at 15:39

3 Answers 3

up vote 6 down vote accepted

When I work with HTML, PHP, etc., I simply write code, put it inside .html or .php file and double click this file. Then my code runs.

But how does Python work?

Exactly the same way.

Double-click a .py file and your code runs.

I'm working inside Eclipse or Python command line and I can run this code, but what if I want make website with Python for example?

You usually use Apache to host a web site. You usually use mod_wsgi to run Python inside Apache. This is exactly like using mod_php to run PHP inside Apache.

Exactly the same.

I don't think it's like I put .py file on my server,

False. You do put .py files on your server. How else could it possibly work?

so what I need to do? I understand I need to install Python on my webserver through some server command line (I've never used it, but I will find some tutorials day I will need it) but what's next?

You need mod_php to run PHP. You need mod_wsgi to run Python.


So if I made some website with Python, then my user will see my index.py file when he comes to my server?

You could do that. It would be fairly silly, however.

Usually, you set up mod_wsgi so that it executes your .py file, and your .py file creates the HTML page.

This parallels the way mod_php executes the .php file to create an HTML page.

Or can I use Python code inside html like with php wrapped inside <?php ?>?

No. You put the HTML inside the Python.

share|improve this answer
    
Commenters: comments are for getting clarification and providing feedback to get an answer improved, not for extended discussion. If you still disagree with the current state of this answer, feel free to down-vote or leave your own answer. If you'd like to continue discussing it, please do so in chat. –  user8 Sep 14 '11 at 21:44

How can I combine my Python knowledge with html, css, php etc?

Use a web framework that supports Python, such as Django.

Python may also be used to create desktop apps, what then? Can I export .exe file with Python code or what?

Python is typically executed by an interpreter, so it's easy to use interactively and you can see results of your changes almost immediately. A Python program can also be packaged up into a stand-alone executable; more on how to do that here.

share|improve this answer
    
Django is big and good knowledge of Python is a prerequisite for it. I'd rather start with Flask. –  9000 Sep 13 '11 at 21:44

Can I export .exe file with Python code or what?

  1. py2exe turns Python programs into packages that can be run on other Windows computers without needing to install Python on those computers. Python is needed on the computer where py2exe itself is run because py2exe is a Python program and it includes parts of Python in the package that is built. http://www.py2exe.org/index.cgi/Tutorial
  2. Jython is an implementation of the Python programming language which is designed to run on the Java(tm) Platform. It consists of a compiler to compile Python source code down to Java bytecodes which can run directly on a JVM, a set of support libraries which are used by the compiled Java bytecodes, and extra support to make it trivial to use Java packages from within Jython. http://www.jython.org/index.html
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.