Learning Python

Started by Pfaber11, April 30, 2019, 14:13:49

Previous topic - Next topic

Steve Elliott

#75
The 3 problems I have with Python are:

1) It's just another generic language, so it relies on extra libraries to do anything but basic text programs.  Which means you have to 'bolt-on' libraries written by other people that might have a very different design philosophy to Python.  Plus it's something else not native and so must be learnt for each library added, is the documentation any good?

2) Blocks of code and scope are based on what column the text is in!  While looking neat when correct, this is a terrible idea imo!  Bugs will be harder to spot, and if your code file ever gets inputted to another text editor the code might get out of column alignment, so the program will not work immediately and easily.

3) It's interpreted and therefore slow compared to compiled code.  Computers these days are so fast that a lot of 2d games are possible and it runs immediately, but when you need extra speed it's not there.
Win11 64Gb 12th Gen Intel i9 12900K 3.2Ghz Nvidia RTX 3070Ti 8Gb
Win11 16Gb 12th Gen Intel i5 12450H 2Ghz Nvidia RTX 2050 8Gb
Win11  Pro 8Gb Celeron Intel UHD Graphics 600
Win10/Linux Mint 16Gb 4th Gen Intel i5 4570 3.2GHz, Nvidia GeForce GTX 1050 2Gb
macOS 32Gb Apple M2Max
pi5 8Gb
Spectrum Next 2Mb

Aurel [banned]

Yes Steve i agree with you in all 3 points

let say this program should be web server on local machine in 3 lines of code

import os
from http.server import HTTPServer, CGIHTTPRequestHandler
# Make sure the server is created at current directory
os.chdir('.')
# Create server object listening the port 80
server_object = HTTPServer(server_address=('', 80), RequestHandlerClass=CGIHTTPRequestHandler)
# Start the web server
server_object.serve_forever()


ok i save code ,do exectly what is stated on that site and then i try to run
it looks that interpreter run code but then i figure that is not
then as thay say user need to run it from CMD...yeah
windows says ..it is not recognized...i am not surprized at all...and so on
ok maybe i do something wrong ...but what a heck...

Yes as you say ...user must learn all stuff if you using specific lib...so you dont learn python then
user must learn how to use this lib and how is designed ..all that is such a mess.
(Y)

Aurel [banned]

Then i become pissed off and try another one ...

# Python 3 server example
from http.server import BaseHTTPRequestHandler, HTTPServer
import time

hostName = "localhost"
serverPort = 8080

class MyServer(BaseHTTPRequestHandler):
    def do_GET(self):
        self.send_response(200)
        self.send_header("Content-type", "text/html")
        self.end_headers()
        self.wfile.write(bytes("<html><head><title>https://pythonbasics.org</title></head>", "utf-8"))
        self.wfile.write(bytes("<p>Request: %s</p>" % self.path, "utf-8"))
        self.wfile.write(bytes("<body>", "utf-8"))
        self.wfile.write(bytes("<p>This is an example web server.</p>", "utf-8"))
        self.wfile.write(bytes("</body></html>", "utf-8"))

if __name__ == "__main__":
    webServer = HTTPServer((hostName, serverPort), MyServer)
    print("Server started http://%s:%s" % (hostName, serverPort))

    try:
        webServer.serve_forever()
    except KeyboardInterrupt:
        pass

    webServer.server_close()
    print("Server stopped.")


..OK ...this one work because i see in console (IDE output message )

*** Remote Interpreter Reinitialized  ***
Server started http://localhost:8080


OK ...BUT this is not in just 3 LINES OF CODE !!!

..OMG ...i become a python programmer ... ::)
(Y)

TomToad

Just like any other language, Python has its positives and negatives. 

Python is very good at processing large amounts of data.  With things like list comprehensions, and statistical functions, all fine tuned and handled in the runtime, makes it good for things like machine learning and scientific research.  It's dynamic nature makes it highly scalable which makes it good for large web services.  There is a reason why sites like Facebook and Twitter use Python on their servers.

As for games and GUI applications, Python is not the best choice.  Python does have TKInter, but it is very basic and outdated, mainly used to make a quick interface for your program.  Python also has PyGame, but it is slow and jerky.  There are better 3rd party modules you can use such as WxPython or AGK for Python, but if you are developing a full featured GUI app or game, I think there are better languages.

Basically it comes down to using the right tool for the right job.  You should learn several languages, not just one.  To criticize Python as a language because you cannot make a good game with it, or criticize C++ because it takes 10x more lines to do the same code than Python, is like criticizing the pliers in your toolbox because it is poor at hammering in screws.
------------------------------------------------
8 rabbits equals 1 rabbyte.

Aurel [banned]

Look
I do not critic python as it is then in general ...what many around promoted..
alsmost looks like we dont need any other programming language than python..
do you get it now..?
also i am not new in programming and i know very well what is what !
(Y)

Steve Elliott

Quote
almost looks like we dont need any other programming language than python..

They said that about Java  :))
Win11 64Gb 12th Gen Intel i9 12900K 3.2Ghz Nvidia RTX 3070Ti 8Gb
Win11 16Gb 12th Gen Intel i5 12450H 2Ghz Nvidia RTX 2050 8Gb
Win11  Pro 8Gb Celeron Intel UHD Graphics 600
Win10/Linux Mint 16Gb 4th Gen Intel i5 4570 3.2GHz, Nvidia GeForce GTX 1050 2Gb
macOS 32Gb Apple M2Max
pi5 8Gb
Spectrum Next 2Mb

Scaremonger

You can do a lot without any external libraries apart from those shipped with Python. I mentioned a 5 line bit of code, but it can be even easier:

1. Put an index.html and style.css file into a folder (Samples below).
2. Open a command prompt and navigate to that folder.
3. Type the following

python -m SimpleHTTPServer

4. Point your browser at 127.0.0.1:8000 and check it is working.

index.html

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>


style.css

body { background-color: powderblue; }
h1 { color: blue; }
p { color: red; }



LineOf7s

Show us on the doll where the bad programming language hurt you.

It's okay.  Python can't hurt you anymore.
"Life's biggest obstacles are your greatest opportunities to excel"

Aurel [banned]

QuoteShow us on the doll where the bad programming language hurt you

wait a moment ..are you one of this which constantly spreading such
patronized and insulting ...babeling ..

I can only say to you ...PUT THE PIPE DOWN !
(Y)

Steve Elliott

Quote
Show us on the doll where the bad programming language hurt you

Quote
wait a moment ..are you one of this which constantly spreading such
patronized and insulting ...babeling ..

I can only say to you ...PUT THE PIPE DOWN !

:))
Win11 64Gb 12th Gen Intel i9 12900K 3.2Ghz Nvidia RTX 3070Ti 8Gb
Win11 16Gb 12th Gen Intel i5 12450H 2Ghz Nvidia RTX 2050 8Gb
Win11  Pro 8Gb Celeron Intel UHD Graphics 600
Win10/Linux Mint 16Gb 4th Gen Intel i5 4570 3.2GHz, Nvidia GeForce GTX 1050 2Gb
macOS 32Gb Apple M2Max
pi5 8Gb
Spectrum Next 2Mb