Forums

Could someone please help clear my Python fog?

Hi everyone, I'm a beginner at Python and Python anywhere and am a bit fuzzy on the nature of how Python works. If someone could please help clarify things for me, I have some questions:

  1. I copy/pasted a client.py and server.py for a basic chat app in python from a tutorial website> If I run the server.py using BASH on pythonanywhere - What ip address am I supposed to pass as a parameter to the client? When I put an ipaddress in the server code, it came up with 127.0.0.1 but that is not going to help me to connect from my client on my computer. The client is supposed to take two parameters: python server.py <ipaddress> <port>.

  2. Does a python web app behave in the same way as say a PHP web app (i.e. spit out html code for the browser to interpret as well as do it's processing stuff in the background on the server?

  3. Can I just set up my server.py file to be itself a web app? so that when I type http://myusername.pythonanywhere in my browser- it will run the server program server.py?

  4. Is it imperative to use Django or Flask or some alternative to make a web app? When I ran the client and server from PyCharm, although they couldn't connect to each other (I'm guessing because they don't like to be both run locally on my pc?) they at least ran, before I had even installed Django or Flask.

I'm sorry if these seem like silly questions, but I am really in a muddle and want to clear it all up. Thank you for all responses.

Keep well.

RoyalSon777

Taking your points in turn:

  1. That sounds like it's a raw socket client/server app rather than a website-based one, so that won't work on PythonAnywhere -- we only support WSGI-based website frameworks, like Django, Flask, Bottle and web2py.

  2. Yes, pretty much! Python is a full programming language, whereas PHP is more specifically designed for writing websites. A closer equivalent to PHP than Python on its own would be Python plus a web framework -- like one of the ones that I mentioned above.

  3. Not quite. You can write pretty low-level servers in Python by hand-coding a WSGI file, but I wouldn't recommend it, especially if you're just getting started. But by using a framework like Django or Flask, you can get started pretty quickly without having to write much code. Let my put in a plug for a Flask tutorial I wrote a while back -- if you go through that, it might clear some of the fog :-)

  4. See above -- it's not 100% necessary, but it will save you a lot of time and pain.

Hope that helps, but if you have any other questions, please do ask!

Dear Giles,

Thank you so much. Your post has cleared up some things for me. I really appreciate it. Now I'm off to check out your flask tutorial.

:)

No problem, glad to help!