AnotherSam
Posts: 14
Joined: Thu Aug 12, 2021 2:37 pm

Help with simple file inclusion

Wed Sep 15, 2021 2:40 am

Hello all,

Pretty new to Raspberry Pico and python in general, and I had a very basic question. I got minipython working and i can connect to the Pi over serial and Thonny. below is a screen shot of my thonny window and code. I have two python files saved on my pico. BitFunctions which has a few defined functions. BitFunctions compiles with no errors. The second python file, playground, failed when I attempt to import the first python file. This is what I did on my Raspberry Pi 4, but I suppose pico is different. Any thoughts on why I can't include the file? Thanks in advance!
Capture.PNG
Capture.PNG (169.45 KiB) Viewed 536 times
Bonus question: In my work with the raspberry pi 4, the module 'Fractions' was included in the system. I wanted to download Fractions from GitHub but I ran into an error

Code: Select all

 git clone https://github.com/bradley101/fraction.git
Traceback (most recent call last):
  File "<stdin>", line 1
SyntaxError: invalid syntax
A lot of folks ran into this, the answer seemed simple... don't run the code through the interpreter, but i get the same result when I run the code in the command window through the serial connection. Any suggestions?

dbrion06
Posts: 690
Joined: Tue May 28, 2019 11:57 am

Re: Help with simple file inclusion

Wed Sep 15, 2021 5:56 am

Bonus question: In my work with the raspberry pi 4, the module 'Fractions' was included in the system. I wanted to download Fractions from GitHub but I ran into an error
bonus answer:

Code: Select all

git clone https://github.com/bradley101/fraction.git
Clonage dans 'fraction'...
remote: Enumerating objects: 231, done.
remote: Counting objects: 100% (128/128), done.
remote: Compressing objects: 100% (84/84), done.
remote: Total 231 (delta 48), reused 101 (delta 30), pack-reused 103
Réception d'objets: 100% (231/231), 73.00 Kio | 24.33 Mio/s, fait.
Résolution des deltas: 100% (94/94), fait.
worked for me ; was it a weird line before invoking git clone?(

Code: Select all

history | grep  -a10 -b10 git
reminds of 10 lines before and 10 after invoking git (tested)

edited: you should not use github to download modules (too new, can be buggy).
there is an 'official' python(3) installer https://pypi.org/project/Fraction/

Code: Select all

pip(3) install Fraction 
should work (without sudo not to mess with debian installer...)

dbrion06
Posts: 690
Joined: Tue May 28, 2019 11:57 am

Re: Help with simple file inclusion

Wed Sep 15, 2021 6:22 am

could you post (with code tags: do not break indents and you already know them)
Playground.py and BitFunctions.py ?
things would be easier.

horuable
Posts: 257
Joined: Sat Mar 06, 2021 12:35 am

Re: Help with simple file inclusion

Wed Sep 15, 2021 8:52 am

I think the problem is that the files don't have the .py extension, so you should rename both files to include it. Thonny doesn't add any extension automatically when creating a new file and you have to remember to name the files include the extension. As a bonus after doing that you'll get the syntax coloring and other QOL stuff.

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

Re: Help with simple file inclusion

Wed Sep 15, 2021 9:54 am

AnotherSam wrote:
Wed Sep 15, 2021 2:40 am
In my work with the raspberry pi 4, the module 'Fractions' was included in the system. I wanted to download Fractions from GitHub but I ran into an error

Code: Select all

 git clone https://github.com/bradley101/fraction.git
Traceback (most recent call last):
  File "<stdin>", line 1
SyntaxError: invalid syntax
A lot of folks ran into this, the answer seemed simple... don't run the code through the interpreter, but i get the same result when I run the code in the command window through the serial connection. Any suggestions?


A lot of folks apparently have the right answer.

I can recreate this on an RPi running RasPiOS, using just the Python3 interpreter.

Code: Select all

pi@raspberrypi:~ $ python3
Python 3.7.3 (default, Jan 22 2021, 20:04:44)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> git clone https://github.com/bradley101/fraction.git
  File "<stdin>", line 1
    git clone https://github.com/bradley101/fraction.git
            ^
SyntaxError: invalid syntax
>>>

The reason is very simple. git clone <some_repository> is NOT a valid Python statement. So it makes no sense to expect the Python interpreter to process it.

That command needs to be processed by the Operating System shell (CLI/Terminal).

And in case it is what you were asking, for that reason it would be equally not appropriate to expect an instance of Thonny configured to interact with an RPi Pico board to be able to handle that command: because it isn't a microPython statement either, and the Pico has no Operating System that could process that command.

AnotherSam
Posts: 14
Joined: Thu Aug 12, 2021 2:37 pm

Re: Help with simple file inclusion

Wed Sep 15, 2021 1:40 pm

horuable wrote:
Wed Sep 15, 2021 8:52 am
I think the problem is that the files don't have the .py extension,
Thank you so much. Its the simple that keep you down sometimes.

Return to “MicroPython”