[IronPython] Newbie question about 'import'

Martin Maly Martin.Maly at microsoft.com
Sat Jan 7 09:29:28 CET 2006


Depends what you want to find out. The easy way is using dir and __doc__:

import sys
dir(sys)

dir(obj) lists attributes available on the given object
dir() lists contents of global namespace

__doc__ provides documentation, if any:

>>> import first
>>> first.add.__doc__
'add(a, b) -> returns a + b'

However, IronPython only provides some information... Consider:

IronPython:
>>> print pow.__doc__
static object pow(object x, object y)
static object pow(object x, object y, object z)

CPython:
>>> print pow.__doc__
pow(x, y[, z]) -> number

With two arguments, equivalent to x**y.  With three arguments,
equivalent to (x**y) % z, but may be more efficient (e.g. for longs).

I find the CPython help extremely useful when it comes to questions on built-in modules or functions, language definition etc.

Hope this helps.
Martin

________________________________

From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Fabio
Sent: Saturday, January 07, 2006 12:21 AM
To: Discussion of IronPython
Subject: Re: [IronPython] Newbie question about 'import'

Thank you, Martin. Worked very fine!

Do you know if have some command to obatin help about the commands? like in DOS we can use DIR /?

Regards
Fabio


2006/1/7, Martin Maly <Martin.Maly at microsoft.com>:

Hi Fabio,

The tutorial is meant to be ran from the Tutorial directory (there are 2 batch files to execute the IronPythonConsole from there)

Other option is to add the Tutorial directory to your sys.path:

>>> import sys

>>> sys.path.append(sys.prefix + "\\Tutorial")

>>> import first

Since the tutorial is designed to work from the tutorial directory, I'd recommend using the batch files to start the console. This way, IronPython will run in the correct directory and import lookup paths will be set correctly.

Martin

________________________________

From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Fabio
Sent: Friday, January 06, 2006 11:43 PM
To: IronPython
Subject: [IronPython] Newbie question about 'import'

I'm new in python (and IronPython).

I have used the tutorial of IronPython 1.0 Beta, and when I "import first" I receive this error:

>>> import first
Traceback (most recent call last):
  File , line 0, in input##0
ImportError: No module named first

I think what I need set some like import "Tutorial\first" but I know not the syntax...

Someone can help?

PS: How I do to in console get help about any command?

Thanks for all!

Fabio

_______________________________________________
users mailing list
users at lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20060107/7faec690/attachment.html>


More information about the Ironpython-users mailing list