Import JSON data between Python files

Asked

Viewed 103 times

0

I’m having a hard time.

i have a code in Selenium(test.py) and I have another python queue code (Queue.py) my goal is to pass the error message [ error = {'Status': 'Error'} ] to the result(Queue.py)

test py.

    def run():
        try:
          driver = webdriver.Firefox()
          driver.get('https://www.google.com')
          elem =  driver.find_element_by_name('q')
          elem.send_keys()    
          elem.send_keys(Keys.RETURN)
        except:
            error = {'Status': 'Error'} 
            dados = json.loads(error)

Quepy.

It’s just a piece of code.

    import pika
    import json
    def worker(ch, method, properties, body):
        print("\tBody: %r" % body)
        try:
            data = json.loads(body)
            print(data['nome'])
            import teste

    result{
         "Status_de_error" : dados['Status'] 
      }

but the file (Queue.py) returns me the following error.

global name 'data' is not defined

Obs : both files are in the same folder

Can someone please help me???

1 answer

1


In part import teste nothing will happen because your function run() has not been called. You can do so:

    from teste import run
    teste.run()

Browser other questions tagged

You are not signed in. Login or sign up in order to post.