Raspberry pi Python(3) help needed

How do you do substrings?

Or more so: left( )

I have a string and need to check if the left n characters are …

left( throws up an error.

So I don’t know if that isn’t the command, or I have to import something else to get that command active.

Some one?

1 Like

Worked out an alternative way of doing it.

All good.


There are great resources on Google for that info. They come up immediately.
Happy scripting.

Every one says “Use google!”

You do understand you are basically saying “My job is redundant because of google.”?

I can sit here searching google (or whichever search engine) until the cows come home.

If I can’t get the words exact, I am losing a lot of time.

I try, but my vocabulary isn’t that great and so I go down a lot of time wasting trips.

Why can’t the basics be included with the display?

  • Where to get the software for it?
  • A comprehensive command list (that is seriously lacking)
  • Example scripts to show how to use the commands.

Anyway, I’ll leave it at that.

So you are saying everyone do the work for me because I am special.

You asked a question on how to do something in a script.

Instead of googling it and finding your answer in a tutorial site exactly as you need it you post here.

I am only trying to help and not get my head bitten off.

Search for “python subscript” and you will get what you need.
What job are you referring to ?

Your language is just fine so why you had your outburst I don’t know.

We come here to help people and no one is paid to answer your questions.

You were on the right track in the first place just use key words in Google and go from there.

This is a resource that will help you a lot


Also there are amazing tutorials here. It will make it a lot easier for you.


I am saying it would be nice if when I buy something, it comes with usable instructions.

Having to spend 2 days on the net trying to find how to use it seems wrong.

Yes, but the whole thing was made … worse? By RasPi not being compliant with industry standards of python.

All other systems use pip to install the latest version of python. Be it 2, 3, 4, 5… what ever.

The Pi needs to me to use pip3 to install python3 files.

Then, when I install the python2 stuff and am then told the problem is because I haven’t installed the latest version - for python3.

Yet, when I install that, the problem remains.

Then the commands that can be sent to the display not being documented in the python3 stuff. Yet they were a lot of good example files with the python2 stuff.

Don’t worry about it. I’ll get it worked out eventually.

Though as I did say it would be nicer is Sparkfun put a bit more effort in what is supplied.

Even a basic piece of paper with the links to software which is needed to talk to the device.

I’ve now been there and done that and I now have the python3 software.

But still there is a chronic lack of documentation of what commands are; their syntax and what they do.

  1. If you want full instructions buy products that give full instructions. In most cases you will not get this because it is all available online via a simple search. You learn by working it out not by being given everything.
  2. Raspberry Pi OS is a linux dist like any other and is fully compliant.
    There is Python 2 and Python 3, I believe both are installed. Pip is used to install modules and not install Python.
    Both Python 2 and 3 (2 is being phased out now) have pip and pip(2 or 3) executables, if you call pip you get the first one found on the path statement. if you uninstall python 2 you will only get pip from python 3, if you change the path or links you can control it.
    So if you want to install a module into python 2 type pip2 if you want to install in python 3 use pip3.
    You need to work out which version of python you are using.
    python --version will tell you which is the DEFAULT version of python.
    It sounds like you are installing modules into Python 2 but running a Python 3 script (focus on 3 as 2 is going away soon)

So run pip commands as pip3 install module and run your script using python3 scriptname.py

There is so much documentation online about all of it that it is insane. Remember you learn more by working it out yourself.

BTW Python 3 isn’t that much different to 2, there are changes but that is things like the print statement, 2 supports print “some text” but 3 supports print(“some text”) plus heaps of new features.

You need a better understanding of Linux I suspect, that will help you understand what is going on. This is what the Raspberry Pi is so good at, giving you a system you can play with and learn, if you screw up who cares, as long as you backup the work you have done you can re-install the OS in a short time and be back at it.

I suggest if you have a pc or other get Bitvise SSH client. It will log you into your Pi, supply a terminal window and ftp file access so you can copy scripts etc you write from the pi to another location, easy backups.
Also lookup Headless setup, this will show you how to enable SSH and wifi before you boot the first time so the pi is online as soon as it starts and you can remote in.

1 Like

To answer your original question.

someString[:4] get the first 4 characters in the string, positions 0 to 3
someString[2:4] get characters from position 2 to position 3 in string

First digit is first position in string, : is from to indication, second digit is last position in string -1.


PS There is no built in left() command in Python. w3schools is an excellent resource.



I worked out a way to cheat with the split command. As that is something I noticed could actually do the same.

While searching I found this though on the left( in python
This uses the left command but it isn’t explained how to do it.

however, as said: That is now behind me.


Got all those now installed and things are moving forward.

Side project to make the RasPi default to python 3 for future use.

1 Like

Hey Andrew,

Excellent idea, glad to hear you’ve fixed it up. Feel free to use this resource any time with your questions regarding your code and projects. If you’re looking for pure code debugging I’d suggest using Stack Overflow too, most devs on there should be able to assist with your code directly as well as this forum. Have a great day!

Core Electronics | Support

I haven’t checked, but this may be very simple. If the different version of python are set up using the Debian Alternatives system, a simple call to updatealternatives will change everything. If the slaves like pip are configured properly, they will be handled as well.

Refer https://wiki.debian.org/DebianAlternatives

Hope this will help you…Python Tutorial

1 Like