Giter VIP home page Giter VIP logo

Comments (11)

minrk avatar minrk commented on July 22, 2024

weird - what do you see in ls ~/.ipython/extensions?

from ipython_extensions.

houshuang avatar houshuang commented on July 22, 2024

[~] ls ~/.ipython/extensions

        21:51:07

autosave.py

On Fri, Dec 14, 2012 at 10:00 PM, Min RK [email protected] wrote:

ls ~/.ipython/extensions

http://reganmian.net/blog -- Random Stuff that Matters

from ipython_extensions.

minrk avatar minrk commented on July 22, 2024

hm, I can't imagine why that wouldn't work, then.

What do you get for:

get_ipython().extension_manager.ipython_extension_dir

And what IPython version?

from ipython_extensions.

houshuang avatar houshuang commented on July 22, 2024

In [77]:

get_ipython().extension_manager.ipython_extension_dir

Out[77]:

u'/Users/Stian/.ipython/extensions'

Version 0.13.1, using EPD (but have upgraded iPython using enpkg).

On Fri, Dec 14, 2012 at 10:14 PM, Min RK [email protected] wrote:

get_ipython().extension_manager.ipython_extension_dir

http://reganmian.net/blog -- Random Stuff that Matters

from ipython_extensions.

minrk avatar minrk commented on July 22, 2024

One more thing - what are the contents of that autosave.py in your
extensions folder?

from ipython_extensions.

houshuang avatar houshuang commented on July 22, 2024

"""Extension for managing periodic autosave of IPython notebooks

Usage:

%load_ext autosave

autosave every 30 seconds:

%autosave 30

disable autosave:

%autosave 0

invoke save from Python:

%savenb

"""

from IPython.core.magic import magics_class, line_magic, Magics
from IPython.display import Javascript, display

_autosave_js_t = """

// clear previous interval, if there was one
if (IPython.autosave_extension_interval) {{
clearInterval(IPython.autosave_extension_interval);
IPython.autosave_extension_interval = null;
}}

// set new interval
if ({0}) {{
console.log("scheduling autosave every {0} ms");
IPython.notebook.save_notebook();
IPython.autosave_extension_interval = setInterval(function() {{
console.log("autosave");
IPython.notebook.save_notebook();
}}, {0});
}} else {{
console.log("canceling autosave");
}}
"""

@magics_class
class AutoSaveMagics(Magics):

interval = 60
enabled = False

@staticmethod
def autosave_js(interval):
    if interval:
        print("autosaving every %is" % interval)
    else:
        print("autosave disabled")
    display(Javascript(_autosave_js_t.format(1000 * interval)))

@line_magic
def autosave(self, line):
    """Schedule notebook autosave

    Usage:

        %autosave [interval]

    If `interval` is given, IPython will autosave the notebook every

interval seconds.
If interval is 0, autosave is disabled.

    If no interval is specified, autosave is toggled.
    """
    line = line.strip()
    if not line:
        # empty line, toggle
        self.enabled = bool(1 - self.enabled)
    else:
        interval = int(line)
        if interval:
            self.enabled = True
            self.interval = interval
        else:
            self.enabled = False

    self.autosave_js(self.enabled * self.interval)

@line_magic
def savenb(self, line):
    """save the current notebook

    This magic invokes the same javascript as the 'Save' button in the

notebook UI.
"""
display(Javascript("IPython.notebook.save_notebook();"))

_loaded = False

def load_ipython_extension(ip):
"""Load the extension in IPython."""
global _loaded
if not _loaded:
ip.register_magics(AutoSaveMagics)
_loaded = True
print ("Usage: %autosave [seconds]")

On Fri, Dec 14, 2012 at 10:51 PM, Min RK [email protected] wrote:

One more thing - what are the contents of that autosave.py in your
extensions folder?


Reply to this email directly or view it on GitHubhttps://github.com//issues/1#issuecomment-11393726.

http://reganmian.net/blog -- Random Stuff that Matters

from ipython_extensions.

minrk avatar minrk commented on July 22, 2024

Okay, then everything seems to be working perfectly. What if you define your own extension, just put an empty foo.py in your extension folder, and try %load_ext foo. If that doesn't work, something is wrong with your IPython installation, and you should bring that up as an IPython issue.

from ipython_extensions.

houshuang avatar houshuang commented on July 22, 2024

That went fine.

In [15]:

%load_ext foo

In [ ]:

On Fri, Dec 14, 2012 at 11:47 PM, Min RK [email protected] wrote:

%load_ext foo

http://reganmian.net/blog -- Random Stuff that Matters

from ipython_extensions.

minrk avatar minrk commented on July 22, 2024

Well, now that doesn't make even the slightest bit of sense. %load_ext autosave doesn't work, even after %load_ext foo does?

from ipython_extensions.

houshuang avatar houshuang commented on July 22, 2024

Of course, now it works perfectly. Apart from playing with different
notebooks, I am quite sure I have not touched the IPython setup. I'm sorry
if I have wasted your time, but glad that it works.

from ipython_extensions.

minrk avatar minrk commented on July 22, 2024

okay - I wonder why it didn't work. Might be something funky if you run %install_ext and %load_ext in the same session.

from ipython_extensions.

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.