Shop OBEX P1 Docs P2 Docs Learn Events
Python — Parallax Forums

Python

To be honest, since Apple dropped support of Pascal, I have hated all computer languages... but the one I hate the least is Python.

I was happy to see interest in Python raised early and often and that there is now a serious effort to get uPython implemented.
I hope that it gets full support from everyone.

But...

What I like most about Python might not be what uPython on a P2 is able to offer... and that is a HUGE base of supporting modules.


1. Would it be possible to put true Python on a system that had multiple P2's and gobs of memory? If possible...how much more difficult would it be than say...uPython to impement?

2. If it is possible, would standard modules be available without having to recompile or reconfigure them in some way?

Thanks,

Rich



Comments

  • jmgjmg Posts: 15,140
    rjo__ wrote: »
    1. Would it be possible to put true Python on a system that had multiple P2's and gobs of memory?

    Anything is possible, but why would anyone want to is a better question.
    Before someone deploys "multiple P2's and gobs of memory", purely to run Python, they will more likely reach for a RaspPi Zero.

    or, if they need more grunt, they may reach for something like this
    https://www.nvidia.com/en-us/autonomous-machines/embedded-systems/jetson-nano/

    rjo__ wrote: »
    ... If possible...how much more difficult would it be than say...uPython to impement?
    uPython seems to be running already in alpha form, on P2, and part of the appeal there is easy access to the Smart Pins.
    It's not clear what you call 'true Python' would add ?

    rjo__ wrote: »
    2. If it is possible, would standard modules be available without having to recompile or reconfigure them in some way?
    Do you mean 'standard modules' in the hardware or software sense ?
    Any code that connects to hardware, is going to be non-portable by nature, but higher level code can be more portable.

    It's likely to be more practical use getting a P2 to talk to (eg) a Nvidia jetson-nano, than it is to add multiple P2's to try to improve uPython performance.
    rjo__ wrote: »
    To be honest, since Apple dropped support of Pascal, I have hated all computer languages... but the one I hate the least is Python.

    Modern Basic dialects are quite close to Pascal, and Project Oberon may well run on a P2.

  • As a datapoint my Python3 installation is well over 1GB... Not really microcontroller territory, Python with lots of
    packages installed (about 200).
  • Mark_T wrote: »
    As a datapoint my Python3 installation is well over 1GB... Not really microcontroller territory, Python with lots of
    packages installed (about 200).

    I work for a company that ships a homegrown Linux distribution. We recently added Python 2.7 to our firmware and were able to squeeze it down to about 20 MB I think. That required removing a few things we deemed "non essential" (though I don't remember what all was removed, I think the .pyc and .pyo files, all documentation, and maybe a few libraries were included in that).

    Indeed - getting full-blown Python running on P2 seems a waste of time. If you need that kind of power, use a Pi.
  • Python2 is officially obsolete now isn't it?
  • DavidZemonDavidZemon Posts: 2,973
    edited 2019-03-26 19:51
    Mark_T wrote: »
    Python2 is officially obsolete now isn't it?

    Very very soon... we're well aware lol

    https://pythonclock.org/
  • Cluso99Cluso99 Posts: 18,066
    NotePad++ has a Python 2.7 plugin for scripting. Don't think there is any intention of the plugin author to upgrade to Python 3 tho.
  • Mark_T wrote: »
    Python2 is officially obsolete now isn't it?

    That doesn't mean you won't find it in the world. I work for a cyber-security company and we're required to know both because not everybody will pay to have legacy code upgraded.
  • rjo__rjo__ Posts: 2,114
    I use 2.7 mostly. Here is a Python2.7 script which gives me my very own diy Notepad++ IDE, which uses Notepad++'s ability to call this script.

    To use it:

    I designate a PNut P2 file in the script and then manually open it in Notepad++… after that I can run PNut with an F5 key.

    I use NotePad++ because it is a fabulous editor... I like the find utility, the user designated highlighting and the user designated code folding... makes things a lot easier.


    On the face of it... Python on a super-P2 system seems pretty stupid. But it looks like serious work to get uPython working... mostly I was wondering how much more it would take to go straight to Python.


    I read somewhere that it takes about 2MB of RAM to get Python going... that would be 4 P2s … so maybe an OctoProp2 would be the entry point.
  • jmgjmg Posts: 15,140
    rjo__ wrote: »
    On the face of it... Python on a super-P2 system seems pretty stupid. But it looks like serious work to get uPython working... mostly I was wondering how much more it would take to go straight to Python.
    I read somewhere that it takes about 2MB of RAM to get Python going... that would be 4 P2s … so maybe an OctoProp2 would be the entry point.

    ? but uPython already exists, and is working on other MCUs, for precisely the reason that full python is too large for MCUs.
    Yes, it was serious work, but that work has been done, plus there is a alpha version of uPython running on P2 already, using that existing other MCU work.

  • rjo__rjo__ Posts: 2,114
    edited 2019-03-27 18:50
    David

    "Indeed - getting full-blown Python running on P2 seems a waste of time. If you need that kind of power, use a Pi. "


    You could be right. Your insistence upon logic is to be commended:)


    Forget reason for the moment... What if major players want to use the P2? What if they want an integrated environment, which is easy to build and easy to maintain? What if calling the P2 over some kind of fancy wire just isn't going to cut it for them?
  • jmgjmg Posts: 15,140
    rjo__ wrote: »
    Forget reason for the moment... What if major players want to use the P2? What if they want an integrated environment, which is easy to build and easy to maintain? What if calling the P2 over some kind of fancy wire just isn't going to cut it for them?

    Forgetting reason, you can also run Linux on a 8 bit AVR.
    Logic is the reason no one does that commercially.
  • rjo__ wrote: »
    On the face of it... Python on a super-P2 system seems pretty stupid. But it looks like serious work to get uPython working... mostly I was wondering how much more it would take to go straight to Python.

    uPython is already running on the P2. See the first post in https://forums.parallax.com/discussion/169862/micropython-for-p2/p1.
    Ozpropdev has done some cool demos with it.

    MicroPython is actually pretty compatible with Python 2.7. It's set up to be modular so you can remove features, but if you enable everything the language is very similar to regular Python. Of course it doesn't have as rich an ecosystem, but I think you could change that by porting code over.
  • rjo__rjo__ Posts: 2,114
    jmg

    Remember... I'm not actually arguing for full blown Python, because I don't know how much more effort would be required than for uPython.

    Right now, if you want to use something like Intel's Realsense technology and a P2 together, the simplest thing to do is use Python... you then broadcast requests and data between Python and the P2 in some way.

    What is the difference? ... it is like comparing a neural-activated prosthetic hand to a real hand.

    In a robot, the P2 is analogous to a mid-brain. It uses its own logic, but doesn't necessarily have executive control...putting the midbrain as close as possible to the executive is the best way to use it. That way the communication(feedback) loops are as short and simple as possible.


    I think this would make a great topic for a DD grant application.

  • rjo__rjo__ Posts: 2,114
    Of course... part of any such grant would have to include consulting fees.

    I'm thinking that someone reading this could... you know, call a friend:)

  • jmgjmg Posts: 15,140
    rjo__ wrote: »
    ..
    Right now, if you want to use something like Intel's Realsense technology and a P2 together, the simplest thing to do is use Python... you then broadcast requests and data between Python and the P2 in some way.
    That will always be the use of P2 in larger systems. If you want the complex OS+Language top layer, you need a link to the P2, and the P2 needs to be made smart enough, to tolerate the link speed.

    This item in the news recently, was very much P2 territory (hard real time control), and a good example of that Host-Node link. AP1050 SPI to 3 phase PWM motor driver.

    https://www.akm.com/akm/en/aboutus/news/20181018AP1050_001/

    Maybe there is enough analog stuff inside AP1050 that it gets used with a P2 ? These decisions come down to price and PCB area.
  • Cluso99Cluso99 Posts: 18,066
    rjo__ wrote: »
    I use 2.7 mostly. Here is a Python2.7 script which gives me my very own diy Notepad++ IDE, which uses Notepad++'s ability to call this script.

    To use it:

    I designate a PNut P2 file in the script and then manually open it in Notepad++… after that I can run PNut with an F5 key.

    I use NotePad++ because it is a fabulous editor... I like the find utility, the user designated highlighting and the user designated code folding... makes things a lot easier.


    On the face of it... Python on a super-P2 system seems pretty stupid. But it looks like serious work to get uPython working... mostly I was wondering how much more it would take to go straight to Python.


    I read somewhere that it takes about 2MB of RAM to get Python going... that would be 4 P2s … so maybe an OctoProp2 would be the entry point.

    Thanks for posting this. I'm not proficient but here is a couple of extracts of what I wrote for NotePad++ to do some automatic file conversions for work
    import Npp
    import re
    #-------------------------------------------------------------------------------
    for f in notepad.getFiles():                                                    # loop through all files f:filename,bufferid,index,view
        sss = f[0]                                                                  # filename
        num = f[1]                                                                  # bufferid
        ndx = f[2]                                                                  # index
        vvv = f[3]                                                                  # view
        # save the bufferid for the first 3 tabs
        if ndx == 0:
            doc0 = f[1]
        elif ndx == 1:
            doc1 = f[1]
        elif ndx == 2:
            doc2 = f[1]
    #    console.write("Current BufID: %d %d %d %s \r\n" % (num, ndx, vvv, sss))
    notepad.activateBufferID(doc1)
    editor.setCurrentPos(0)
    #-------------------------------------------------------------------------------
    # run macro to convert special characters
    notepad.runMenuCommand('Macro', 'fix_special_chars')
    #-------------------------------------------------------------------------------
    x = len(notepad.getCurrentFilename()) - 5 # less ".html"
    newFilename = notepad.getCurrentFilename()[0:x] + " - xxxx.html"                # get full filename incl path & modify it
    notepad.saveAs(newFilename);                                                    # and save it renamed
    #-------------------------------------------------------------------------------
    
  • rjo__rjo__ Posts: 2,114
    Yes... there are programmers... and then there are programmers.

    I am in awe at guys(and gals) that can just inhale this stuff and spit it back as beautiful as a sculpture.
    Not only could I not do this... I didn't even know it was possible:0

    Thanks
Sign In or Register to comment.