Page 1 of 1

Object Programming in Python

Posted: Sat Apr 06, 2019 12:59 pm
by RDK
I'm an old time programmer brought up writing Fortran programs, ie what folks now call Procedural Programming. I've written a few things in Python, but for sure have not used many of the object-oriented features which are available.

I'm reading a couple books right now on the subject, but they mostly discuss theory or creating your own classes. What I really want is a way to find/list the classes and methods which already exist and are generally available in Python when using the IDLE interface.

I'm somewhat used to using Visual Basic for Applications (VBA) to write macros for Excel. In the VBA editor environment there is an 'object browser' which helps.

Is there anything available for Python newbies? Or, how did you folks learn about all of these objects and their methods?....RDK

Re: Object Programming in Python

Posted: Sat Apr 06, 2019 1:34 pm
by Andyroo
Not a complete answer by miles (as I am in the same learning stage as you with Python) but for a list of modules I use https://docs.python.org/3/py-modindex.html

From within Python 3, the following may help a little:

Code: Select all

help('modules')
and from the command line

Code: Select all

pydoc modules

Re: Object Programming in Python

Posted: Sat Apr 06, 2019 3:14 pm
by RDK
Thanks....good to know I'm not the only one out walking in the wilderness

I'll check these out....RDK

Re: Object Programming in Python

Posted: Sat Apr 06, 2019 3:33 pm
by Andyroo
I’m so well lost some days with the programming side even my GPS says do not start from here!

I old enough to remember Borland introducing OOP to Pascal just as I stepped into RPG and COBOL for a challenge running AS/400 and now find four spaces a pain to remember :lol:

Hopefully we will get a few more adding to the thread (please)...

Re: Object Programming in Python

Posted: Mon Apr 08, 2019 6:47 am
by RDK
Currently I'm writing code on my Windows 10 Pro laptop using IDLE and then transferring the code to a Raspberry Pi to run.

For the Pi I've installed some object packages, like RTL_433, pyModbus, etc, from a GIT site or other sources. My code generally works on the Pi, but on the laptop when coding I get no help/feedback on the available objects and their properties/methods. As I said above, I've done some macros programming for MS Excel and I like the VBA editor there as it does show the objects, etc.

Now I'm wondering if I have the right IDE or process for this type for code development. What do I have to do to have something like the MS VBA editor? A different IDE? How do I get the objects which I have installed on the Pi (Raspbian Stretch) also available to an IDE on my laptop? ....RDK

Re: Object Programming in Python

Posted: Mon Apr 08, 2019 5:31 pm
by Heater
You can get Microsoft style auto complete, IntelliSense and linting with MicroSofts Visual Studio Code editor:
https://code.visualstudio.com/docs/languages/python

This is not Visual Studio. It's "Visual Studio Code". Runs on Linux, Mac and Windows.

I have read that people have gotten VS Code to run on the Raspberry Pi. I have not tried that yet.

Re: Object Programming in Python

Posted: Mon Apr 08, 2019 6:17 pm
by B.Goode
. My code generally works on the Pi, but on the laptop when coding I get no help/feedback on the available objects and their properties/methods.
Can you confirm that you have installed the same libraries on your laptop as on the RPi?

Re: Object Programming in Python

Posted: Tue Apr 09, 2019 4:23 am
by RDK
B.Goode...No, I have not installed those libraries on the laptop. I've looked for a Windows install for pyModbus without success.

Heater....Sounds interesting. I will look at it...RDK

Re: Object Programming in Python

Posted: Sat Apr 13, 2019 5:26 am
by RDK
Heater....I have installed VS_Code on my laptop and I think it is operational. Seems like I have a lot to learn but it looks like something close to my wants.

EDIT: My error:
When coding an object, for example

Code: Select all

c=open(….), 
and I type

Code: Select all

x=c.
I expected then to immediately get a drop-down of the methods and properties for c. Nothing happens until I type the first letter and then I get the drop down with all of the methods and properties starting with that letter. This means one has to already know all of the properties and methods for that object or sequentially go through the alphabet.

When I install libraries (like

Code: Select all

pip install requests 
or twisted) where are they installed?

When I installed

Code: Select all

pip install pymodbus 
it threw a lot of permission errors. To get around that I had to run the cmd prompt with admin privileges. Also had to do that for twisted.

Thanks....RDK

Re: Object Programming in Python

Posted: Sat Apr 13, 2019 6:08 am
by Heater
Sorry but I don't use Python enough to have worried about auto completion and such yet.

It might help to have a look here:

https://code.visualstudio.com/docs/python/editing
https://marketplace.visualstudio.com/it ... hon.python