0

I have just moved from using Spyder to PyCharm & so far think its great. I have one issue though. When I run a simple function it runs as expected. The problem comes when I make a small change to the function, for example add an extra column to a dataframe that will be returned by the function, it is not reflected when I re-run the code. If I close & re-open PyCharm then the change is reflected, am I missing something?

Update

I run the function within the python console in pycharm. So,

from some_direcotry.some_file import some_function
output = some_function()

I then make a change to the function, crtl+s the file & run the line below,

output = some_function()

But it does not reflect the changes I made

mHelpMe
  • 6,336
  • 24
  • 75
  • 150
  • 2
    Did you save the file before running? `Ctrl+s` :) – kaliiiiiiiii Mar 24 '23 at 08:29
  • 1
    yes I did Crtl+s so bit confused. I'm running it from the console within pycharm – mHelpMe Mar 24 '23 at 08:58
  • Does this answer your question? [How to tell when PyCharm saves file?](https://stackoverflow.com/questions/34427857/how-to-tell-when-pycharm-saves-file) – bad_coder Apr 03 '23 at 04:42
  • The rule can be intuitive but PyCharm saves file changes whenever you run a file or exit the editor window, so clicking outside the code editing main window is enough to save the changes. See [save and revert changes](https://www.jetbrains.com/help/pycharm/saving-and-reverting-changes.html) – bad_coder Apr 03 '23 at 04:44

1 Answers1

2

when I make a small change to the function, for example add an extra column to a dataframe that will be returned by the function, it is not reflected when I re-run the code

With PyCharm, you re-run the file. So unless you have saved your file (e.g. with Ctrl+S / Cmd+S), you run the initial code, not the updated code.

A simple solution is to save the file before re-running it.

Update:

Since you saved the file, this seems to be an issue with module caching. Python thinks you have already imported the module, so it does not reload it again. However, you can reaload it manually:

from importlib import reload

import some_directory.some_file  # If you haven't already imported the module
reload(some_directory.some_file)
from some_directory.some_file import some_function

output = some_function()
DataJanitor
  • 1,276
  • 1
  • 8
  • 19