Python

Coders forum. Discuss techniques, swap code snippets, ask for help etc. relating to all forms of software development.
User avatar
Kelloggs
Baaaaa!
Baaaaa!
Posts: 1859
Joined: Wed Jun 22, 2005 11:38 pm 0
XBL Gamertag: TheAntiKelloggs
Location: Widnes or Altrincham. Take your pick.

Re: Python

Post by Kelloggs »

That'll mostly be historical from my end, then - I'd got to the stage on the Atari ST where, if you wanted to do anything low-level, or more than a little bit complex, 68K was the way to go (but you could still do an awful lot in GFA Basic, if you wielded a big enough hammer) and I picked up a book on x86 in '96, took one look and backed away swiftly.

Availability of raw CPU grunt has meant that I've not needed to re-evaluate that position since, which is why any programming I do in work is Bash or Perl, with C at home (and I'm not actually employed as a programmer). I can imagine that familiarity with assembly would be useful in your job though, Dio.
User avatar
Dio
Sheepie Whore
Sheepie Whore
Posts: 18887
Joined: Mon May 31, 2004 1:08 pm 0
Location: Newcastle UK

Re: Python

Post by Dio »

I wish. asm is too time-consuming to do much with it on modern programs. I really miss the days when I could spend a month picking individual cycles out of complicated routines.

That said, I hardly write any code of any kind anymore. Indeed, one of the joys of the last few weeks is that I've actually been writing some driver code again, instead of just haggling over specs.

Now, if you really want your hair stood on end, you need to look at the asm / microcode for the shader engines. Actually GCN isn't too bad again now because it's scalar and even it's SIMD-ness is very simple to understand and read, but the VLIW MIMD architecture that the previous chips had was insane.
User avatar
gilesgoat
Sheepie Whore
Sheepie Whore
Posts: 27259
Joined: Wed Sep 03, 2003 7:54 am 0
Location: Monfalcone, Italy
Contact:

Re: Python

Post by gilesgoat »

Dio wrote:I wish. asm is too time-consuming to do much with it on modern programs. I really miss the days when I could spend a month picking individual cycles out of complicated routines.

That said, I hardly write any code of any kind anymore. Indeed, one of the joys of the last few weeks is that I've actually been writing some driver code again, instead of just haggling over specs.

Now, if you really want your hair stood on end, you need to look at the asm / microcode for the shader engines. Actually GCN isn't too bad again now because it's scalar and even it's SIMD-ness is very simple to understand and read, but the VLIW MIMD architecture that the previous chips had was insane.
It's all useless Dio, they all use Unity nowdays and they complain why it's not so performant on <insert crap device> 8)
Giles the billy goat
"Baa"
User avatar
Dio
Sheepie Whore
Sheepie Whore
Posts: 18887
Joined: Mon May 31, 2004 1:08 pm 0
Location: Newcastle UK

Re: Python

Post by Dio »

Accept it Giles - us engine programmers are the weirdos, not them.

Better job prospects though :D .
User avatar
Kamineko
Baaaaaaa!
Baaaaaaa!
Posts: 7569
Joined: Fri Dec 17, 2004 2:53 pm 0
Contact:

Re: Python

Post by Kamineko »

gilesgoat wrote:
Dio wrote:I wish. asm is too time-consuming to do much with it on modern programs. I really miss the days when I could spend a month picking individual cycles out of complicated routines.

That said, I hardly write any code of any kind anymore. Indeed, one of the joys of the last few weeks is that I've actually been writing some driver code again, instead of just haggling over specs.

Now, if you really want your hair stood on end, you need to look at the asm / microcode for the shader engines. Actually GCN isn't too bad again now because it's scalar and even it's SIMD-ness is very simple to understand and read, but the VLIW MIMD architecture that the previous chips had was insane.
It's all useless Dio, they all use Unity nowdays and they complain why it's not so performant on <insert crap device> 8)
Shoulda used 3D Construction Kit...
User avatar
gilesgoat
Sheepie Whore
Sheepie Whore
Posts: 27259
Joined: Wed Sep 03, 2003 7:54 am 0
Location: Monfalcone, Italy
Contact:

Re: Python

Post by gilesgoat »

Dio wrote:Accept it Giles - us engine programmers are the weirdos, not them.

Better job prospects though :D .
And I am still trying to figure out how with a 25.175 dot cock one an have a bitmapped thing with a palette, you need first to fecth 1 byte, then load a shift register, then load 1 attribute byte, then load 1 ( or 2 ) palette bytes, then shift bits ...

On the middle of that you should allow a cycle for the CPU to read/write in ..

Folk .. Fastest on chip ram I can find is 10 ns .. It does not fit .. How the heck they do it ?
Giles the billy goat
"Baa"
User avatar
gilesgoat
Sheepie Whore
Sheepie Whore
Posts: 27259
Joined: Wed Sep 03, 2003 7:54 am 0
Location: Monfalcone, Italy
Contact:

Re: Python

Post by gilesgoat »

Kamineko wrote:
gilesgoat wrote:
Dio wrote:I wish. asm is too time-consuming to do much with it on modern programs. I really miss the days when I could spend a month picking individual cycles out of complicated routines.

That said, I hardly write any code of any kind anymore. Indeed, one of the joys of the last few weeks is that I've actually been writing some driver code again, instead of just haggling over specs.

Now, if you really want your hair stood on end, you need to look at the asm / microcode for the shader engines. Actually GCN isn't too bad again now because it's scalar and even it's SIMD-ness is very simple to understand and read, but the VLIW MIMD architecture that the previous chips had was insane.
It's all useless Dio, they all use Unity nowdays and they complain why it's not so performant on <insert crap device> 8)
Shoulda used 3D Construction Kit...
There are equivalent things man ... There are ... And people are using them ...
Giles the billy goat
"Baa"
User avatar
Dio
Sheepie Whore
Sheepie Whore
Posts: 18887
Joined: Mon May 31, 2004 1:08 pm 0
Location: Newcastle UK

Re: Python

Post by Dio »

gilesgoat wrote:Folk .. Fastest on chip ram I can find is 10 ns .. It does not fit .. How the heck they do it ?
Wide buses, big buffers, lots of synchronous burst reads.

It gets even worse when tiled memory gets involved.

On six displays simultaneously.

Palettising was a nightmare for high performance graphics though, that's why it was binned off 15 years ago.
User avatar
gilesgoat
Sheepie Whore
Sheepie Whore
Posts: 27259
Joined: Wed Sep 03, 2003 7:54 am 0
Location: Monfalcone, Italy
Contact:

Re: Python

Post by gilesgoat »

Dio wrote:
gilesgoat wrote:Folk .. Fastest on chip ram I can find is 10 ns .. It does not fit .. How the heck they do it ?
Wide buses, big buffers, lots of synchronous burst reads.

It gets even worse when tiled memory gets involved.

On six displays simultaneously.

Palettising was a nightmare for high performance graphics though, that's why it was binned off 15 years ago.
In fact I was thinking "stuff would get a little bit easier using more rams in parallel" ( i.e. larger bus width ) also quite a few things of the past were designed around 7 Mhz dot clock or less .. the moment you step into VGA frequencies things start to change .. lot .. palettes are truly a bad beast ..
Giles the billy goat
"Baa"
User avatar
Kamineko
Baaaaaaa!
Baaaaaaa!
Posts: 7569
Joined: Fri Dec 17, 2004 2:53 pm 0
Contact:

Re: Python

Post by Kamineko »

Python on Windows status: You download a thing and install it. It works. You want something, you pip it like an apt package manager, and it still works.

Portable Python on Windows status: You download a thing and don't install it. It works. You want something? You probably already have it, but you could pip it anyway.

Pypy3 was also portable! I ran my Python 3 Project Euler Fleas Per Square implementation through it and it ran ten times as fast as CPython, just like the wizard promised.

Yeah, it might not be the super future of all programming but in terms of Getting Things Done, they're onto a winner here. I can see why folks would use it as an introductory language instead of PUBLIC STATIC VOID MAIN STRING ARGS.

The worst thing about this stuff is that it's over 10MB big and that would have been a big killer for me before the broadband age. I could only get Mingw and Allegro and learn C after I had a connection big enough to download the utils. Before that, I was stuck with BlitzBasic and Dark Basic because I had those on physical discs.

Python for me is very BASICy, except it's not really basic so nobody sneers at it. (Everything is BASIClike to me. I would describe my general programming style as very basic BASICy, but I bet if I went back and actually tried to use a real BASIC now I'd probably get frustrated at the arbitrary rules they all have.)
adam
Baaaaaa!
Baaaaaa!
Posts: 4418
Joined: Sat Jun 24, 2006 9:15 pm 0

Re: Python

Post by adam »

one cs prof who's into it described it as being as close as you'd get to smalltalk in this modern age - apart from actual smalltalk that is
User avatar
Partz
Baaaaa!
Baaaaa!
Posts: 1511
Joined: Tue Apr 23, 2002 8:46 pm 0
Location: Chippenham, Wiltshire

Re: Python

Post by Partz »

The best thing about python to me is that regardless of how bad your code is. it will always look beautiful. I love the forced indentation over {} use. It's a bit of a bind to start with and you start to become a little more shrewd in your choice of editor but every bit of crap code i've written in python at least *looks* great :) I keep meaning to toy around with the curses library. I had this idea to knock out an IRC client in python... (PY(i)R(a)C(y)?? ) and think it would be quite useful - but hearing bad things about windows implementations of curses not providing full spec compliance. Sods law says the first thing I would be wantingto use wouldn't adhere.
User avatar
gravy
Sheepie Whore
Sheepie Whore
Posts: 19572
Joined: Wed May 01, 2002 1:28 pm 0
Location: The Other Place

Re: Python

Post by gravy »

I like that golang comes with a standard for indentation and even ships with a utility that will format your code code correctly :)
User avatar
sdetoni
Baaaaa!
Baaaaa!
Posts: 1368
Joined: Tue Jun 18, 2002 4:14 am 0
Location: New Sheepland

Re: Python

Post by sdetoni »

Kamineko wrote:I decided to learn Python last week. That's some real nifty stuff right there. Every programmer worth their salt should have a go of Python at some point. I wanted to make a GUI application to learn how the language is used, with Qt for the interface and zipped JSON for files and Python replied 'Good idea, DONE.', and I said 'But... I just started. I can't be DONE', and Python said 'Nuh-uh. It's all done. You finished it. Go you!'. My tea hadn't even gotten cold.

What's going on?

I don't think it should be used as a teaching language though; it's too easy. It's the Super Nashwan Power of programming, except it doesn't wear off. It's cheating, and kids should be taught that programming is boring, brittle, longwinded and mostly not doing the algorithm you're trying to express, damn it.
Yeah, I too decided to give Python another go, and its relatively good experience.
I wrote an almost complete python based web server in 150 lines ....
well ok, I kind a cheated with the socket stuff, and the class BaseHTTPServer.BaseHTTPRequestHandler implementation is
what I call broken. But it works, mime type support, get/post, loading/running dynamic external python web pages,
and works relatively well.

Hell, here it is almost complete ...

httpd_example.py
Spoiler: show

Code: Select all

import time
import BaseHTTPServer
import re
import sys
import cgi

HOST_NAME = 'localhost'
PORT_NUMBER = 8081

class MyHTTPWebServer (BaseHTTPServer.BaseHTTPRequestHandler):
    classInit      = False
    dirHome        = './html'
    homeScriptName = 'index.py'
    mimeTypeFile   = 'mimetypes.txt'
    mimeDict       = {}

    # create our own custom constructor
    def __init__(self, dirHome, homeScriptName, mimeTypeFile, *args):
        if (MyHTTPWebServer.classInit == False):
            print "Init MyHTTPWebServer"
            MyHTTPWebServer.dirHome        = dirHome
            MyHTTPWebServer.homeScriptName = homeScriptName
            MyHTTPWebServer.mimeTypeFile   = mimeTypeFile
            MyHTTPWebServer.mimeDict       = {}

            # Load the mimetypes
            try:
               file = open (MyHTTPWebServer.mimeTypeFile)
               for line in file.readlines():
                    line = line.replace('\t', ' ')
                    s = line.split(' ');
                    if (len(s) > 1):
                        MyHTTPWebServer.mimeDict[s[0].lstrip().rstrip().lower()] = s[1].lstrip().rstrip()
            except IOError:
                print 'Mime File ' + MyHTTPWebServer.mimeTypeFile + ' not found!'

            MyHTTPWebServer.classInit = True
        else:
            print "Bypass Init MyHTTPWebServer"
        # call base class constructor as well
        BaseHTTPServer.BaseHTTPRequestHandler.__init__(self, *args)

    # ################################################################

    def constructCGIFormData(self):
        # Parse the form data posted
        self.cgiFormData = cgi.FieldStorage(fp=self.rfile,
                                            headers=self.headers,
                                            environ={'REQUEST_METHOD': 'POST',
                                                     'CONTENT_TYPE': self.headers['Content-Type'],
                                            }
                                           )
        return self.cgiFormData

    def dumpSubmitFormData(self, fileHandle):
        self.constructCGIFormData()

        fileHandle.write('Client: %s\n' % str(self.client_address))
        fileHandle.write('User-agent: %s\n' % str(self.headers['user-agent']))
        fileHandle.write('Path: %s\n' % self.path)
        fileHandle.write('Form data:\n')

        # Echo back information about what was posted in the form
        for field in self.cgiFormData.keys():
            field_item = self.cgiFormData[field]
            if field_item.filename:
                # The field contains an uploaded file
                file_data = field_item.file.read()
                file_len = len(file_data)
                del file_data
                fileHandle.write('\tUploaded %s as "%s" (%d bytes)\n' % (field, field_item.filename, file_len))
            else:
                # Regular form value
                fileHandle.write('\t%s=%s\n' % (field, self.cgiFormData[field].value))

    def do_HEAD(self):
        self.send_response(200)
        self.send_header("Content-type", 'text/html')
        self.end_headers()

    def do_POST(self):
        self.do_GET()

    def do_GET(self):
        """Respond to a GET request."""
        filePath = self.path.split('?')
        queryPath = ''
        if (len(filePath) > 1):
            queryPath = filePath[1]

        filePath = filePath[0]

        if (filePath == '/'):
            filePath = filePath + self.homeScriptName
            filePath.replace('..', '.')

        if (re.search('.py$', filePath)):
            try:
                fullname = self.dirHome + filePath
                execfile(fullname)
            except IOError:
                print 'Render page ' + fullname + ' not found!'
            except:
                print 'Exception in ' + fullname + ' :: ' + str(sys.exc_info()[0])
        else:
            try:
                # extract file extension so as to send the correct mime-type
                fileExt = re.findall('(\..*$)', filePath)
                if (len(fileExt) <= 0):
                    fileExt = '.txt'
                self.send_response(200)

                # match mime type based up extension
                if (len(self.mimeDict) > 0):
                    self.send_header('Content-type', self.mimeDict[fileExt[0].lower()]);
                else:
                    self.send_header('Content-type', 'application/octet-stream');
                self.end_headers()

                fullname = self.dirHome + filePath
                file = open(fullname, 'rb')
                self.wfile.write(file.read())
                file.close()
            except IOError:
                print 'File ' + fullname + ' not found!'

# #######################################################################################

# constructor
def main():
    # call our MyHTTPWebServer constructor with this anonymous function and append existing args from the
    # BaseHTTPServer calling process into MyHTTPWebServer __init__ constructor function
    def httpdConstructorLoader (dirHome, homeScriptName, mimeTypeFile):
        return lambda *args: MyHTTPWebServer(dirHome, homeScriptName, mimeTypeFile, *args)

    handler = httpdConstructorLoader('./html', 'index.py', 'mimetypes.txt')

    httpd = BaseHTTPServer.HTTPServer((HOST_NAME, PORT_NUMBER), handler)
    print time.asctime(), 'Server Starts - %s:%s' % (HOST_NAME, PORT_NUMBER)
    try:
        httpd.serve_forever()
    except KeyboardInterrupt:
        pass
    httpd.server_close()
    print time.asctime(), 'Server Stops - %s:%s' % (HOST_NAME, PORT_NUMBER)

main()
html/index.py
Spoiler: show

Code: Select all

self.do_HEAD()

self.wfile.write('''
<html><head><title>Title goes here.</title></head>
<link rel="stylesheet" type="text/css" href="/css/base.css" />
<body><p>Sarah.</p>

<p>You accessed path: %s</p>''' % self.path + '''
<img src="/icon_thread_new_hot.png"><a href="/my_page.py">load script</a>
</body></html>''')
html/my_page.py
Spoiler: show

Code: Select all

self.do_HEAD()

if self.command == "POST":
    self.dumpSubmitFormData(self.wfile)
elif self.command == "GET":
    self.wfile.write('''
<html>
<link rel="stylesheet" type="text/css" href="/css/base.css" />
<body><p>hello.</p>
<p>You accessed path: %s</p>''' % self.path + '''
<a href="/my_page.py">load script</a>
<form method=post>
<input type=hidden name=blah value="blah blah blah">
<input type=submit>
</form>
</body></html>''')
access it via python httpd_example.py
http://localhost:8081/
http://localhost:8081/index.py
http://localhost:8081/my_page.py
adam
Baaaaaa!
Baaaaaa!
Posts: 4418
Joined: Sat Jun 24, 2006 9:15 pm 0

Re: Python

Post by adam »

Micro Python Board status

snip...

The good news is we are planning a second manufacturing run of the board!

Sign up below if you are interested in getting a Micro Python Board, and we will make them available on a first-come first-served basis.
https://micropython.org/

they were about £20 on Kickstarter - no header pins or that
Post Reply