User avatar
RDK
Posts: 244
Joined: Wed Aug 13, 2014 10:19 am
Location: Wyoming and France

Object Programming in Python

Sat Apr 06, 2019 12:59 pm

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

Andyroo
Posts: 2986
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: Object Programming in Python

Sat Apr 06, 2019 1:34 pm

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
Need Pi spray - these things are breeding in my house...

User avatar
RDK
Posts: 244
Joined: Wed Aug 13, 2014 10:19 am
Location: Wyoming and France

Re: Object Programming in Python

Sat Apr 06, 2019 3:14 pm

Thanks....good to know I'm not the only one out walking in the wilderness

I'll check these out....RDK

Andyroo
Posts: 2986
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: Object Programming in Python

Sat Apr 06, 2019 3:33 pm

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)...
Need Pi spray - these things are breeding in my house...

User avatar
RDK
Posts: 244
Joined: Wed Aug 13, 2014 10:19 am
Location: Wyoming and France

Re: Object Programming in Python

Mon Apr 08, 2019 6:47 am

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

Heater
Posts: 12211
Joined: Tue Jul 17, 2012 3:02 pm

Re: Object Programming in Python

Mon Apr 08, 2019 5:31 pm

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.

B.Goode
Posts: 7756
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Object Programming in Python

Mon Apr 08, 2019 6:17 pm

. 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?

User avatar
RDK
Posts: 244
Joined: Wed Aug 13, 2014 10:19 am
Location: Wyoming and France

Re: Object Programming in Python

Tue Apr 09, 2019 4:23 am

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

User avatar
RDK
Posts: 244
Joined: Wed Aug 13, 2014 10:19 am
Location: Wyoming and France

Re: Object Programming in Python

Sat Apr 13, 2019 5:26 am

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
Last edited by RDK on Sat Apr 13, 2019 6:45 am, edited 1 time in total.

Heater
Posts: 12211
Joined: Tue Jul 17, 2012 3:02 pm

Re: Object Programming in Python

Sat Apr 13, 2019 6:08 am

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

Return to “Beginners”