Я работаю над приложением, использующим Kivy и Buildozer. В какой-то момент текст загружается из простого текстового файла. Это прекрасно работает на моем P C, но, кажется, это вызывает приложение взломать sh на моем телефоне, когда я тестирую apk. Я использую Python3 .6 в Ubuntu 18.04.
Вот часть кода, в которую загружается текст:
class DataList(object):
def __init__(self, dict):
"""Construction of the total list depending on booleans"""
self.total_list = []
if dict["Characters"] is True:
char_list = (open("characters.txt", "r").read()).split("\n") # Here is the bug
#char_list = ["char1", "char2", "char3"]
self.total_list += char_list
if dict["Games"] is True:
#games_list = (open("games.txt", "r").read()).split("\n")
games_list = ["game1", "game2", "game3"]
self.total_list += games_list
if dict["Movies"] is True:
#movies_list = (open("movies.txt", "r").read()).split("\n")
movies_list = ["movie1", "movie2", "movie3"]
self.total_list += movies_list
while "" in self.total_list: self.total_list.remove("")
def pick(self):
"""Random picks of x elements in the data list"""
if self.total_list:
picks = random.sample(self.total_list, 3)
return picks
else:
return None
Вот результат adb logcat
:
04-27 15:21:21.395 25975 26011 I python : Traceback (most recent call last):
04-27 15:21:21.396 25975 26011 I python : File "/home/florian/Documents/App/My_apps/guess_android/.buildozer/android/app/main.py", line 116, in <module>
04-27 15:21:21.397 25975 26011 I python : File "/home/florian/Documents/App/My_apps/guess_android/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/myapp/kivy/app.py", line 855, in run
04-27 15:21:21.399 25975 26011 I python : File "/home/florian/Documents/App/My_apps/guess_android/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/myapp/kivy/base.py", line 504, in runTouchApp
04-27 15:21:21.400 25975 26011 I python : File "/home/florian/Documents/App/My_apps/guess_android/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/myapp/kivy/core/window/window_sdl2.py", line 747, in mainloop
04-27 15:21:21.402 25975 26011 I python : File "/home/florian/Documents/App/My_apps/guess_android/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/myapp/kivy/core/window/window_sdl2.py", line 479, in _mainloop
04-27 15:21:21.404 25975 26011 I python : File "/home/florian/Documents/App/My_apps/guess_android/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/myapp/kivy/base.py", line 342, in idle
04-27 15:21:21.406 25975 26011 I python : File "/home/florian/Documents/App/My_apps/guess_android/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/myapp/kivy/base.py", line 327, in dispatch_input
04-27 15:21:21.407 25975 26011 I python : File "/home/florian/Documents/App/My_apps/guess_android/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/myapp/kivy/base.py", line 293, in post_dispatch_input
04-27 15:21:21.409 25975 26011 I python : File "kivy/_event.pyx", line 707, in kivy._event.EventDispatcher.dispatch
04-27 15:21:21.410 25975 26011 I python : File "/home/florian/Documents/App/My_apps/guess_android/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/myapp/kivy/uix/behaviors/button.py", line 179, in on_touch_up
04-27 15:21:21.412 25975 26011 I python : File "kivy/_event.pyx", line 703, in kivy._event.EventDispatcher.dispatch
04-27 15:21:21.413 25975 26011 I python : File "kivy/_event.pyx", line 1214, in kivy._event.EventObservers.dispatch
04-27 15:21:21.415 25975 26011 I python : File "kivy/_event.pyx", line 1098, in kivy._event.EventObservers._dispatch
04-27 15:21:21.421 25975 26011 I python : File "/home/florian/Documents/App/My_apps/guess_android/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/myapp/kivy/lang/builder.py", line 64, in custom_callback
04-27 15:21:21.422 25975 26011 I python : File "/data/data/org.test.myapp/files/app/guess.kv", line 37, in <module>
04-27 15:21:21.424 25975 26011 I python : on_release: app.generate()
04-27 15:21:21.425 25975 26011 I python : File "/home/florian/Documents/App/My_apps/guess_android/.buildozer/android/app/main.py", line 63, in generate
04-27 15:21:21.427 25975 26011 I python : File "/home/florian/Documents/App/My_apps/guess_android/.buildozer/android/app/main.py", line 89, in __init__
04-27 15:21:21.429 25975 26011 I python : FileNotFoundError: [Errno 2] No such file or directory: 'characters.txt'
04-27 15:21:21.429 25975 26011 I python : Python for android ended.
Очевидно, существует проблема с путем. Какое решение?
Спасибо, ваша помощь очень ценится!