Reputation: 41
I'm a beginner at coding, currently I'm developing an app. Within that app I have an ImageButton, when I release it calls a .py script. However, for some reason it keeps giving me a SytanxError, even though (to my understanding) there's no SyntaxError.
The following is what I have in my main.py:
def run_test(self):
os.system("python externalconnection.py")
And the following is the code written in externalconnection.py:
import asyncio
from bleak import BleakClient
address = "#######"
rw_characteristic = '######'
async def connect(address):
async with BleakClient(address, loop=loop) as client:
await client.get_services()
value = await client.read_gatt_char(rw_characteristic)
print("Pre-Write Value: {0}".format(value))
await client.write_gatt_char(rw_characteristic, bytearray([0x01]), response=True)
value = await client.read_gatt_char(rw_characteristic)
print("Post-Write Value: {0}".format(value))
loop = asyncio.get_event_loop()
loop.run_until_complete(connect(address))
And below is the error I get:
File "externalconnection.py", line 7
async def connect(address):
^
SyntaxError: invalid syntax
Also in case you wonder, the externalconnection.py is running just fine and does what I need, if I run it by itself on a separate project from the app.
Any help that I can get will be very much appreciated!!!
Upvotes: 2
Views: 47
Reputation: 29488
This is the error you would get if running this code under a Python version that doesn't yet have the async def
syntax, such as Python 2.7.18.
Make sure the python
executable you're resolving is what you think it is, and is a Python version that supports this syntax.
Upvotes: 2