# SSI Mentorship meeting Wednesday 10th May 2023 Have a separate function which generates the stimulus ordering, e.g.: ``` def generate_stimulus(): ... return stimuli ``` Later on in your code: ``` def run_presentation(): for stim in generate_stimuli(): text.text = stim ``` ## Saving stimulus data to a separate file You can create plain text files very easily in Python, e.g.: ``` with open('stim.csv', 'wt') as f: f.write('"col1","col2","col3"\n') f.write('1,2,3\n') f.write('4,5,6\n') # file will be automatically closed/saved when # the with statement ends ``` You could save your per-trial stimuli like so: ``` stimuli = [ ('green_circle', 'blue_triangle'), ('yellow_square', 'red_circle'), ] # list containing ordered stimuli with open('stim.csv', 'wt') as f: for i, (stim1, stim2) in enumerate(stimuli): f.write(f'{stim1},{stim2}\n') ``` # Programming with Python You might find these tutorials useful: - Python programming tutorial with a realistic use-case https://swcarpentry.github.io/python-novice-inflammation/ - Using conda to manage separate Python environments and dependencies: https://docs.conda.io/en/latest/miniconda.html You can create a separate conda environment for each separate project you are working on, with each environment only containing the dependencies that are needed. For example, you could create a separate conda environment with IPython, Jupyter Notebook, and JupyterLab with a command like this (the environment will be created in a sub-directory of the current directory called `my-env`): ``` conda create -c conda-forge -p ./my-env ipython notebook jupyterlab ``` Then you can _activate_ it (use it within your current terminal/powershell sesssion) by running `conda activate ./my-env`. When using Python interactively, you can use a python interpreter from the terminal/powershell - just run `python` to start the interpreter. There is also a third-party interpreter called `ipython` which is much nicer than the default interpreter. You also have the option of using a slightly fancier interpreter called Jupyter Notebook, or JupyterLab. When you start either of these, a page will open in your web browser. You can write and execute code from within the web browser interface - behind the scenes, the code gets sent back to a Python session running within your termihal/powershell, and the results sent back to the browser. These Jupyter interfaces are super useful for learning and playing around.