Skip to content

Extra files and modules ​

The open button, the console's open as the notebook's open, opens a script or a notebook, but it also gives your program files of your computer: extra files (images, texts, data…) or modules to import.

These files can also be loaded from the web when the page opens, with the aux and module URL parameters: see Sharing an activity.

The program does not see the files of your computer: it works in a virtual filesystem, specific to the page, where the files are copied and from which they can be retrieved.

Using extra files ​

To work with an image, a text document, a CSV file, etc. stored on your machine, open it with the open button. The end of the load is notified as below.

Notification of the load of an extra file

Then open it from your program (with open in Python for instance), as if it were in the current directory.

Astuce

To get the list of the available files, ask for the content of the current directory, in Python, like this (try it):

python
>>> import os
>>> os.listdir()
['my_file.csv']

Here, the user has loaded the file my_file.csv.

Info

Extra files are available with the kernels that have a filesystem: Python, OCaml, C and R. They are not in JavaScript, SQL and XCAS (see Other languages).

Info

If instead of loading an extra file you want, conversely, to retrieve one, see the section Retrieving a file.

Importing your own module ​

To import your own Python module (held in a *.py file), open it with the open button and answer the question below that you want to "Installer le module" (install the module).

Question asked when a Python file is opened

Basthon then loads its dependencies if needed and notifies you that the module is available.

Notification that the module is available

You can then import your module with import my_module.

Astuce

In Python, the help('modules') command (try it) lists every module that can be imported, including the modules loaded this way.

Info

The other languages have their modules too (*.ml files in OCaml, *.c and *.h in C, *.js in JavaScript…): see the Other languages page.

After a restart ​

The extra files and modules loaded stay available after a restart of the kernel.