Passing a robot variable to Python Variable file

Hello please I am bloqued on a topic I need your help,

So I have this robot line {My Account number}= get text xpath:{Account number} that get’s me the created account number, I need to passe the result to my data.py file as follow:
#test.py
NumCompte = ${My Account number} (since it contains my data)

Thanks for your help I am open to other solutions (thinking outside the box)

It may depend on how you use data.py.

If you change it after being imported as variables file, it will not use the new value.

If that is the case, then it’s better to reassign ${NumCompte} and make it global.

A variable file is loaded when robot imports it.
You could try to work with properties, but i would assume, that it is a one way thing.
Just getting variables from python module or class.

I don’t think that if you change a variable, this variable is passed back to the module.
But maybe it is.

On the other hand, why do you Not use a python library with a keyword.
And this keyword takes as argument your data and returns what ever it has to return?

can anyone please tell me how to import a variable from a .robot file and use it in .py file?

Hi @amekkaoui,

The best way to approach this will depend on what you are trying to do, let me ask some questions to clarify:

  • is test.py and NumCompte being used as part of the same robot file (same or different test case) as the get text line that produces ${My Account number}?
  • is test.py and NumCompte being used as part of a different robot file that is executed separately from robot file that has the get text line that produces ${My Account number}?
  • is test.py executed as a standalone python file outside robotframework?

The first scenario is covered by the other answers here, but if either of the other 2 scenarios or something else then you might need a different solution.

Dave.