Giter VIP home page Giter VIP logo

Comments (5)

hoodmane avatar hoodmane commented on June 3, 2024

This isn't a bug in Pyodide because you'll get the same behavior in native Python.

from pyodide.

tomitrescak avatar tomitrescak commented on June 3, 2024

Yup, and just to help the noobie the solution is to use the following method to delete it from the cache between saves:

import sys
del sys.modules['mymodule']

so the full solution would be:

import importlib 
from pathlib import Path 
import time
import sys

del sys.modules['mymodule']
 
Path("mymodule.py").write_text("""\
def hello(): 
  print("hello world!") 
""" 
) 
# importlib.invalidate_caches() # Make sure Python notices the new .py file 
from mymodule import hello 
hello() 

del sys.modules['mymodule']

with open("mymodule.py", "w") as f:
     f.write("""\
def hello():  
  print("hola mundo!")  
""" )

# importlib.invalidate_caches()
from mymodule import hello  
hello()  # <-- ๐Ÿ•บ yea baby! "hola mundo!"

from pyodide.

hoodmane avatar hoodmane commented on June 3, 2024

It's hit or miss for me whether del sys.modukes['mymodule'] works. Which is strange. A bunch of other people report it working for them, but when I tried the code with del sys.modukes['mymodule'] I saw hello world twice. Otherwise I would have suggested it. No idea why other people see it working but I don't...

from pyodide.

tomitrescak avatar tomitrescak commented on June 3, 2024

Thatโ€™s not good ;( I will have to test it thoroughly then :/

from pyodide.

hoodmane avatar hoodmane commented on June 3, 2024

I just tried your code out both in Pyodide and with native Python 3.11 on linux and both ways it worked the way you say it should. So hopefully I just messed up something silly when I tried it before.

from pyodide.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.