-3

I have been programming for around 3 years now. I've mainly been working with JavaScript and started with PHP about a year ago. I think so far that is a good start since i'm only 14 and I have taught myself most of what I know (no teacher). I want to further my language knowledge so that I can face new challenges. While I can do that by simply just learning more of PHP, I would like to learn a completely new language. I have been looking into Python and I like. I can't really figure out how I would implement it on a site (i've read that you could). Or what to even make using it.

So in a long run, here is what I need/want to know:

  • How do you implement the usage of Python, into Web Development? (if possible)

  • Is it possible to do AJAX request with them like you can with PHP?

Like:

$.post("/send.py", {
    foo: "bar"
}, function (data) { console.log(data); });

And then in the Python use some sort of POST variable like in PHP and get the data. (example)

  • What other things can I do with Python? besides than just playing with come code in the console?

I realize, there is a lot you can do with Python, or else it wouldn't be so popular. But I just don't really understand at the moment because both PHP and JavaScript are easily implemented.

Thanks for the help.

6
  • 1
    Python has libraries and bindings for and to everything under the sun and is a straightforward language with powerful and accessible features. It is also backed/used by big players like Google.
    – YXD
    Jun 20, 2013 at 17:36
  • That being so, it is very slow as a language. As you can see from this link, it is enormous compared to C or Java. That being said, it is much easier to write quicker. blog.dhananjaynene.com/2008/07/…
    – eatonphil
    Jun 20, 2013 at 17:38
  • @phileaton It is not valid to call a language slow.
    – Marcin
    Jun 20, 2013 at 17:42
  • Do I mean that it runs slowly? I'm not sure I am understanding my mistake. In any case, I mean that it can take a lot longer to run an algorithm in Python than to run it in C or Java. Again, that being said, due to Python's simplicity you can make up for that (at least partially) in how fast you can write the algorithm.
    – eatonphil
    Jun 20, 2013 at 17:44
  • 1
    @phileaton: It depends on the algorithm. Just as a lot of numerical code is faster with Python+numpy than with the obvious native C, a lot of server code is faster with, say, Python+gevent than with the obvious native C.
    – abarnert
    Jun 20, 2013 at 18:08

4 Answers 4

2

This is a number of separate questions, some of which are clearly not appropriate for SO's format, but I'll answer what I can.

How do you implement the usage of Python, into Web Development? (if possible)

You can find the Python documentation at docs.python.org. Within these docs, there's a section of HOWTOs, including HOWTO Use Python in the web, which includes a link to a wiki page on Web Programming in Python. You may also want to try googling things like "tutorial python web development" and "tutorial python web framework".

Is it possible to do AJAX request with them like you can with PHP?

Well, you can't really do "AJAX" from either Python or PHP, because it's not Asynchronous Javascript, it's Python or PHP (and may be asynchronous in the same way as AJAX, or synchronous, or threaded…).

But you certainly can make POST requests, including sending form-encoded data, JSON, or XML and receiving HTML, JSON, or XML, or anything else you might want.

Another HOWTO document, HOWTO Fetch Internet Resources Using the urllib Package shows the basics.

Many Python programmers prefer using requests to the built-in stdlib features. For trivial uses, it's no better, and for very complicated ones, it can be actually more complicated—but for everything in between, it's usually a lot simpler.

What other things can I do with Python? besides than just playing with come code in the console?

People use Python for all kinds of things besides web servers and web service clients—log parsing, audio processing, 3D games, you name it. You need to decide what you want to do, and then you can probably google up a tutorial for it.

But first, read through the official tutorial (on the same docs page), and maybe google for one more general-purpose tutorial.

2

PHP is built for the web. It is a web-based language. Python is not. Python normally (sanely) requires a framework to achieve the things you're looking for. While you can use Python without a web framework, it is not easy and does not get you very far. As far as being able to write Python like you write PHP, that probably won't happen. You will be able to write Python similar to writing Cake PHP. Consider googling Django or Web2Py for some examples of Python on the web.

1

Also you can check http://bottlepy.org/. It is micro web framework for Python.

0

Granted, this question is a bit open-ended, but hopefully this will provide some sort of rough starting point.

The first hallmark of Python is that it doesn't require brackets to demarcate code blocks (it uses tabs instead). While mostly stylistic, people often like this format and the rigidity it commands in coding style.

Additionally, it handles object-oriented programming easily, is 'Pythonic', and has a huge set of robust external libraries (modules).

Check out this tutorial: http://net.tutsplus.com/tutorials/python-tutorials/python-from-scratch-creating-a-dynamic-website/

More on Django here: https://www.djangoproject.com/.

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