MCPcopy Index your code
hub / github.com/ipython/ipython / load

Method load

IPython/core/magics/code.py:318–405  ·  view source on GitHub ↗

Load code into the current frontend. Usage:\\ %load [options] source where source can be a filename, URL, input history range, macro, or element in the user namespace If no arguments are given, loads the history of this session up to this poin

(self, arg_s)

Source from the content-addressed store, hash-verified

316
317 @line_magic
318 def load(self, arg_s):
319 """Load code into the current frontend.
320
321 Usage:\\
322 %load [options] source
323
324 where source can be a filename, URL, input history range, macro, or
325 element in the user namespace
326
327 If no arguments are given, loads the history of this session up to this
328 point.
329
330 Options:
331
332 -r <lines>: Specify lines or ranges of lines to load from the source.
333 Ranges could be specified as x-y (x..y) or in python-style x:y
334 (x..(y-1)). Both limits x and y can be left blank (meaning the
335 beginning and end of the file, respectively).
336
337 -s <symbols>: Specify function or classes to load from python source.
338
339 -y : Don&#x27;t ask confirmation for loading source above 200 000 characters.
340
341 -n : Include the user&#x27;s namespace when searching for source code.
342
343 This magic command can either take a local filename, a URL, an history
344 range (see %history) or a macro as argument, it will prompt for
345 confirmation before loading source with more than 200 000 characters, unless
346 -y flag is passed or if the frontend does not support raw_input::
347
348 %load
349 %load myscript.py
350 %load 7-27
351 %load myMacro
352 %load http://www.example.com/myscript.py
353 %load -r 5-10 myscript.py
354 %load -r 10-20,30,40: foo.py
355 %load -s MyClass,wonder_function myscript.py
356 %load -n MyClass
357 %load -n my_module.wonder_function
358 """
359 opts,args = self.parse_options(arg_s,'yns:r:')
360 search_ns = 'n' in opts
361 contents = self.shell.find_user_code(args, search_ns=search_ns)
362
363 if 's' in opts:
364 try:
365 blocks, not_found = extract_symbols(contents, opts['s'])
366 except SyntaxError:
367 # non python code
368 error("Unable to parse the input as valid Python code")
369 return
370
371 if len(not_found) == 1:
372 warn('The symbol `%s` was not found' % not_found[0])
373 elif len(not_found) > 1:
374 warn('The symbols %s were not found' % get_text_list(not_found,
375 wrap_item_with='`')

Callers 5

loadpyMethod · 0.95
test_navigable_providerFunction · 0.80

Calls 10

get_text_listFunction · 0.90
extract_symbolsFunction · 0.85
extract_code_rangesFunction · 0.85
strip_initial_indentFunction · 0.85
parse_optionsMethod · 0.80
find_user_codeMethod · 0.80
replaceMethod · 0.80
ask_yes_noMethod · 0.80
set_next_inputMethod · 0.80
formatMethod · 0.45