MCPcopy Create free account
hub / github.com/ipython/ipython / load

Method load

IPython/core/magics/code.py:288–377  ·  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 Options: -r : Specify lines or ranges of lines to load from the so

(self, arg_s)

Source from the content-addressed store, hash-verified

286
287 @line_magic
288 def load(self, arg_s):
289 """Load code into the current frontend.
290
291 Usage:\\
292 %load [options] source
293
294 where source can be a filename, URL, input history range, macro, or
295 element in the user namespace
296
297 Options:
298
299 -r <lines>: Specify lines or ranges of lines to load from the source.
300 Ranges could be specified as x-y (x..y) or in python-style x:y
301 (x..(y-1)). Both limits x and y can be left blank (meaning the
302 beginning and end of the file, respectively).
303
304 -s <symbols>: Specify function or classes to load from python source.
305
306 -y : Don&#x27;t ask confirmation for loading source above 200 000 characters.
307
308 -n : Include the user&#x27;s namespace when searching for source code.
309
310 This magic command can either take a local filename, a URL, an history
311 range (see %history) or a macro as argument, it will prompt for
312 confirmation before loading source with more than 200 000 characters, unless
313 -y flag is passed or if the frontend does not support raw_input::
314
315 %load myscript.py
316 %load 7-27
317 %load myMacro
318 %load http://www.example.com/myscript.py
319 %load -r 5-10 myscript.py
320 %load -r 10-20,30,40: foo.py
321 %load -s MyClass,wonder_function myscript.py
322 %load -n MyClass
323 %load -n my_module.wonder_function
324 """
325 opts,args = self.parse_options(arg_s,'yns:r:')
326
327 if not args:
328 raise UsageError('Missing filename, URL, input history range, '
329 'macro, or element in the user namespace.')
330
331 search_ns = 'n' in opts
332
333 contents = self.shell.find_user_code(args, search_ns=search_ns)
334
335 if 's' in opts:
336 try:
337 blocks, not_found = extract_symbols(contents, opts['s'])
338 except SyntaxError:
339 # non python code
340 error("Unable to parse the input as valid Python code")
341 return
342
343 if len(not_found) == 1:
344 warn('The symbol `%s` was not found' % not_found[0])
345 elif len(not_found) > 1:

Callers 1

loadpyMethod · 0.95

Calls 10

UsageErrorClass · 0.90
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
ask_yes_noMethod · 0.80
set_next_inputMethod · 0.80
formatMethod · 0.45

Tested by

no test coverage detected