Indizieren in die Liste der Diktate, die einen Syntaxfehler auslösen, aber nur unter Linux [geschlossen]Python

Python-Programme
Anonymous
 Indizieren in die Liste der Diktate, die einen Syntaxfehler auslösen, aber nur unter Linux [geschlossen]

Post by Anonymous »

Ich erstelle eine App, die, wenn sie unter Windows ausgeführt wird, eine virtuelle Linux-Maschinensitzung öffnet, in der bestimmte Teile des Prozesses ausgeführt werden. Ich verwende ein System zum Speichern/Laden von Konfigurationen, um Daten zwischen den beiden zu übertragen. Derzeit ist es sehr einfach eingerichtet, nur um zu testen, ob ich alle erforderlichen Daten problemlos senden kann. Daher sollte es noch überhaupt nicht von der Plattform abhängig sein. Der relevante Code lautet also:

Code: Select all

linux_hunt_process.py
:

Code: Select all

import process_properties as properties
...

if __name__ == "__main__":
properties.init()

if os.path.exists(properties.CONFIG_PATH):
print("Config file found, loading config...")
properties.load_config()
else:
print("Config file not found, creating new config...")
properties.reset_config()

print(properties.CONFIG['target_img'])

Code: Select all

process_properties.py
:

Code: Select all

import json
import os
import sys

def init():
global DEFAULT_CONFIG
DEFAULT_CONFIG = {...}
global CONFIG
CONFIG = DEFAULT_CONFIG.copy()
...
... # setting up global variables
...
global VIDEO_DEVICE_LIST
VIDEO_DEVICE_LIST = list()
global BLUETOOTH_LIST
BLUETOOTH_LIST = [{}]

def load_config():
global CONFIG
with open(CONFIG_PATH, "r") as configFile:
configData = json.loads(configFile.read())
...
... # copying configData into CONFIG
...

def reset_config():
global CONFIG
CONFIG = DEFAULT_CONFIG.copy()
if sys.platform != "linux":
CONFIG['bluetooth'] = f'{BLUETOOTH_LIST[0]['product']} ({BLUETOOTH_LIST[0]['manufacturer']})' # this is the line 46 mentioned in the error traceback
CONFIG['bluetooth_device'] = BLUETOOTH_LIST[0]
CONFIG['video'] = VIDEO_DEVICE_LIST[0].name
with open(CONFIG_PATH, "x") as configFile:
configFile.write(json.dumps(CONFIG, indent=4))
Wenn ich dies unter Windows ausführe, werden die gewünschten Daten ohne Probleme ausgeführt und gedruckt. Aber wenn ich es auf der Linux-VM ausführe, erhalte ich Folgendes:

Code: Select all

Traceback (most recent call last):
File "linux_hunt_process.py", line 1, in 
import process_properties as properties
File "/vagrant/process_properties.py", line 46
CONFIG['bluetooth'] = f'{BLUETOOTH_LIST[0]['product']} ({BLUETOOTH_LIST[0]['manufacturer']})'
^
SyntaxError: invalid syntax
Alle Schlüssel, die zum Indexieren in Wörterbüchern verwendet werden, sind diejenigen, von denen ich sicher bin, dass sie in allen Kontexten vorhanden sind. Warum wird je nach Plattform ein Fehler ausgegeben?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post