# Raspberry pi Python(3) help needed

**URL:** <https://forum.core-electronics.com.au/t/raspberry-pi-python-3-help-needed/8320>\
**Category:** Raspberry Pi\
**Created:** [2 September 2020 05:46 UTC](https://forum.core-electronics.com.au/t/raspberry-pi-python-3-help-needed/8320 "2020-09-02T05:46:40Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrew41918](https://avatars.discourse-cdn.com/v4/letter/a/a4c791/32.png) [@Andrew41918](https://forum.core-electronics.com.au/u/Andrew41918)\
**Post date:** [2 September 2020 05:46 UTC](https://forum.core-electronics.com.au/t/raspberry-pi-python-3-help-needed/8320/1 "2020-09-02T05:46:40Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Andrew41918](https://avatars.discourse-cdn.com/v4/letter/a/a4c791/32.png) [@Andrew41918](https://forum.core-electronics.com.au/u/Andrew41918)\
**Post date:** [2 September 2020 06:32 UTC](https://forum.core-electronics.com.au/t/raspberry-pi-python-3-help-needed/8320/2 "2020-09-02T06:32:11Z")

</div>

Worked out an alternative way of doing it.

All good.

SOLVED!

---

<div class="post-metadata">

**Author:** ![Christoper97276](https://avatars.discourse-cdn.com/v4/letter/c/d9b06d/32.png) [@Christoper97276](https://forum.core-electronics.com.au/u/Christoper97276)\
**Post date:** [2 September 2020 23:35 UTC](https://forum.core-electronics.com.au/t/raspberry-pi-python-3-help-needed/8320/3 "2020-09-02T23:35:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Andrew41918](https://avatars.discourse-cdn.com/v4/letter/a/a4c791/32.png) [@Andrew41918](https://forum.core-electronics.com.au/u/Andrew41918)\
**Post date:** [2 September 2020 23:50 UTC](https://forum.core-electronics.com.au/t/raspberry-pi-python-3-help-needed/8320/4 "2020-09-02T23:50:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Christoper97276](https://avatars.discourse-cdn.com/v4/letter/c/d9b06d/32.png) [@Christoper97276](https://forum.core-electronics.com.au/u/Christoper97276)\
**Post date:** [3 September 2020 00:08 UTC](https://forum.core-electronics.com.au/t/raspberry-pi-python-3-help-needed/8320/5 "2020-09-03T00:08:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Christoper97276](https://avatars.discourse-cdn.com/v4/letter/c/d9b06d/32.png) [@Christoper97276](https://forum.core-electronics.com.au/u/Christoper97276)\
**Post date:** [3 September 2020 00:12 UTC](https://forum.core-electronics.com.au/t/raspberry-pi-python-3-help-needed/8320/6 "2020-09-03T00:12:38Z")

</div>

This is a resource that will help you a lot

[https://www.w3schools.com/python/](https://www.w3schools.com/python/)

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

---

<div class="post-metadata">

**Author:** ![Andrew41918](https://avatars.discourse-cdn.com/v4/letter/a/a4c791/32.png) [@Andrew41918](https://forum.core-electronics.com.au/u/Andrew41918)\
**Post date:** [3 September 2020 00:23 UTC](https://forum.core-electronics.com.au/t/raspberry-pi-python-3-help-needed/8320/7 "2020-09-03T00:23:17Z")

</div>

No,

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.

---

<div class="post-metadata">

**Author:** ![Andrew41918](https://avatars.discourse-cdn.com/v4/letter/a/a4c791/32.png) [@Andrew41918](https://forum.core-electronics.com.au/u/Andrew41918)\
**Post date:** [3 September 2020 00:29 UTC](https://forum.core-electronics.com.au/t/raspberry-pi-python-3-help-needed/8320/8 "2020-09-03T00:29:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Christoper97276](https://avatars.discourse-cdn.com/v4/letter/c/d9b06d/32.png) [@Christoper97276](https://forum.core-electronics.com.au/u/Christoper97276)\
**Post date:** [3 September 2020 01:04 UTC](https://forum.core-electronics.com.au/t/raspberry-pi-python-3-help-needed/8320/9 "2020-09-03T01:04:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![James46717](https://avatars.discourse-cdn.com/v4/letter/j/e5b9ba/32.png) [@James46717](https://forum.core-electronics.com.au/u/James46717)\
**Post date:** [3 September 2020 03:44 UTC](https://forum.core-electronics.com.au/t/raspberry-pi-python-3-help-needed/8320/10 "2020-09-03T03:44:55Z")

</div>

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.

Cheers  
Jim

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

---

<div class="post-metadata">

**Author:** ![Andrew41918](https://avatars.discourse-cdn.com/v4/letter/a/a4c791/32.png) [@Andrew41918](https://forum.core-electronics.com.au/u/Andrew41918)\
**Post date:** [3 September 2020 04:39 UTC](https://forum.core-electronics.com.au/t/raspberry-pi-python-3-help-needed/8320/11 "2020-09-03T04:39:41Z")

</div>

James.

Thanks.

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.](https://stackoverflow.com/questions/16166109/python-left-equivalent)

however, as said: That is now behind me.

Chris,

Got all those now installed and things are moving forward.

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

---

<div class="post-metadata">

**Author:** ![Bryce](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/bryce/32/3631_2.png) [@Bryce](https://forum.core-electronics.com.au/u/Bryce)\
**Post date:** [22 September 2020 02:38 UTC](https://forum.core-electronics.com.au/t/raspberry-pi-python-3-help-needed/8320/12 "2020-09-22T02:38:03Z")

</div>

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!

Bryce  
Core Electronics | Support

---

<div class="post-metadata">

**Author:** ![Robin57159](https://avatars.discourse-cdn.com/v4/letter/r/cc9497/32.png) [@Robin57159](https://forum.core-electronics.com.au/u/Robin57159)\
**Post date:** [22 September 2020 02:59 UTC](https://forum.core-electronics.com.au/t/raspberry-pi-python-3-help-needed/8320/13 "2020-09-22T02:59:11Z")

</div>

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](https://wiki.debian.org/DebianAlternatives)

---

<div class="post-metadata">

**Author:** ![polsky164684](https://avatars.discourse-cdn.com/v4/letter/p/9fc348/32.png) [@polsky164684](https://forum.core-electronics.com.au/u/polsky164684)\
**Post date:** [31 May 2021 05:02 UTC](https://forum.core-electronics.com.au/t/raspberry-pi-python-3-help-needed/8320/14 "2021-05-31T05:02:12Z")

</div>

> [@Christoper97276](#):
>
> Also there are amazing tutorials here. It will make it a lot easier for you.

Hope this will help you…[Python Tutorial](http://net-informations.com/python/default.htm)
