Run python code on login to raspberrypi

Currently I’m working on a project that requires a python code to trigger as soon as we have logged into the Raspberry-Pi. I have tried many things on the internet and what most of them does is, they start running the code immediately on the start-up, but the problem I’m facing right now is that as soon as the python code starts it creates a text (.txt) file on the desktop that contains the data extracted from the experiment, but while doing the running on start-up it is not creating the .txt file on the desktop, but it does create the text file when you run the python code manually using the terminal.

So I’m here to ask if there is a fix for this, what I’m thinking to do is, as soon as the Raspberry-pi lands on the desktop on startup, the terminal should launch and the python code should be fed into the terminal automatically and execute it to mimic the manual process. That’s what I’m thinking to do, but if there is something else I could do instead of doing this long process then every help will be appreciated.