Behavior of __name__?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Behavior of __name__?

Alan Field
Hey,

When I run a Jython module from the command line, __name__ is "__main__". When the same module is run from an embedded version of Jython using the Bean Scripting Framework __name__ is "main". Is this a bug in Jython or the BSF JythonEngine? Has anybody else seen this?

Thanks,
Alan



-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
<a href="http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642">http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642
_______________________________________________
Jython-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-dev
Reply | Threaded
Open this post in threaded view
|

Re: Behavior of __name__?

Jeff Emanuel
I don't know about BSF, but when I embed a jython interpreter,
I create a module named "__main__" like this:

      _interp = new PythonInterpreter();
      PyModule mod = imp.addModule("__main__");
      _interp.setLocals(mod.__dict__);


Alan Field wrote:

> Hey,
>
> When I run a Jython module from the command line, __name__ is "__main__". When the same module is run from an embedded version of Jython using the Bean Scripting Framework __name__ is "main". Is this a bug in Jython or the BSF JythonEngine? Has anybody else seen this?
>
> Thanks,
> Alan
>
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by xPML, a groundbreaking scripting language
> that extends applications into web and mobile media. Attend the live webcast
> and join the prime developer group breaking into this new coding territory!
> <a href="http://sel.as-us.falkag.net/sel?cmd=k&kid0944&bid$1720&dat1642">http://sel.as-us.falkag.net/sel?cmd=k&kid0944&bid$1720&dat1642
> _______________________________________________
> Jython-dev mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/jython-dev


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Jython-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-dev
Reply | Threaded
Open this post in threaded view
|

RE: Behavior of __name__?

Alan Field
In reply to this post by Alan Field
Jeff,

First what is the imp variable in the code below?

What appears to be happening is that when I run the module under BSF, __name__ is returning the name of the function defined in the file. I see a lot of code that tests for __name__ equal to "__main__", but I am not sure what __name__ returns when you import the module.

Thanks,
Alan

-----Original Message-----
From: Jeff Emanuel [mailto:[hidden email]]
Sent: Tuesday, March 21, 2006 5:16 PM
To: Alan Field
Cc: [hidden email]
Subject: Re: [Jython-dev] Behavior of __name__?

I don't know about BSF, but when I embed a jython interpreter, I create a module named "__main__" like this:

      _interp = new PythonInterpreter();
      PyModule mod = imp.addModule("__main__");
      _interp.setLocals(mod.__dict__);


Alan Field wrote:

> Hey,
>
> When I run a Jython module from the command line, __name__ is "__main__". When the same module is run from an embedded version of Jython using the Bean Scripting Framework __name__ is "main". Is this a bug in Jython or the BSF JythonEngine? Has anybody else seen this?
>
> Thanks,
> Alan
>
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by xPML, a groundbreaking scripting
> language that extends applications into web and mobile media. Attend
> the live webcast and join the prime developer group breaking into this new coding territory!
> <a href="http://sel.as-us.falkag.net/sel?cmd=k&kid0944&bid$1720&dat1642">http://sel.as-us.falkag.net/sel?cmd=k&kid0944&bid$1720&dat1642
> _______________________________________________
> Jython-dev mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/jython-dev


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
<a href="http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642">http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642
_______________________________________________
Jython-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-dev
Reply | Threaded
Open this post in threaded view
|

Re: Behavior of __name__?

Jeff Emanuel
It's the class org.python.core.imp.

Alan Field wrote:

> Jeff,
>
> First what is the imp variable in the code below?
>
> What appears to be happening is that when I run the module under BSF, __name__ is returning the name of the function defined in the file. I see a lot of code that tests for __name__ equal to "__main__", but I am not sure what __name__ returns when you import the module.
>
> Thanks,
> Alan
>
> -----Original Message-----
> From: Jeff Emanuel [mailto:[hidden email]]
> Sent: Tuesday, March 21, 2006 5:16 PM
> To: Alan Field
> Cc: [hidden email]
> Subject: Re: [Jython-dev] Behavior of __name__?
>
> I don't know about BSF, but when I embed a jython interpreter, I create a module named "__main__" like this:
>
>       _interp = new PythonInterpreter();
>       PyModule mod = imp.addModule("__main__");
>       _interp.setLocals(mod.__dict__);
>
>
> Alan Field wrote:
>
>>Hey,
>>
>>When I run a Jython module from the command line, __name__ is "__main__". When the same module is run from an embedded version of Jython using the Bean Scripting Framework __name__ is "main". Is this a bug in Jython or the BSF JythonEngine? Has anybody else seen this?
>>
>>Thanks,
>>Alan
>>
>>
>>
>>-------------------------------------------------------
>>This SF.Net email is sponsored by xPML, a groundbreaking scripting
>>language that extends applications into web and mobile media. Attend
>>the live webcast and join the prime developer group breaking into this new coding territory!
>><a href="http://sel.as-us.falkag.net/sel?cmd=k&kid0944&bid$1720&dat1642">http://sel.as-us.falkag.net/sel?cmd=k&kid0944&bid$1720&dat1642
>>_______________________________________________
>>Jython-dev mailing list
>>[hidden email]
>>https://lists.sourceforge.net/lists/listinfo/jython-dev


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Jython-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-dev
Reply | Threaded
Open this post in threaded view
|

Re: Behavior of __name__?

Kent Johnson
In reply to this post by Alan Field
Alan Field wrote:
> What appears to be happening is that when I run the module under BSF,
>
__name__ is returning the name of the function defined in the file. I
see a lot of code that tests for __name__ equal to "__main__", but I am
not sure what __name__ returns when you import the module.

Normally when a module is imported it's __name__ attribute is the name
of the module - not the name of the file (with .py) but the name you import.

Kent



-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Jython-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-dev
Reply | Threaded
Open this post in threaded view
|

RE: Behavior of __name__?

Alan Field
In reply to this post by Alan Field
OK, well it is very odd. When running under BSF, __name__ is always "main" instead of "__main__". (I was wrong about it returning the name of the function defined in the file.) I can work around it, but it seems weird. It's as if the underscores are getting removed at some point.

Thanks for the help,
Alan

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Kent Johnson
Sent: Wednesday, March 22, 2006 3:24 PM
Cc: [hidden email]
Subject: Re: [Jython-dev] Behavior of __name__?

Alan Field wrote:
> What appears to be happening is that when I run the module under BSF,
>
__name__ is returning the name of the function defined in the file. I see a lot of code that tests for __name__ equal to "__main__", but I am not sure what __name__ returns when you import the module.

Normally when a module is imported it's __name__ attribute is the name of the module - not the name of the file (with .py) but the name you import.

Kent



-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Jython-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-dev


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
<a href="http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642">http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642
_______________________________________________
Jython-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-dev