The properties can control the behavior of Jython. You can
override, for instance, the registry file settings.
john.m.baker@... wrote:
> That's great feedback. I think the documentation around the
> PythonInterpreter is a little lacking - I'm certainly confused to why we
> need to pass properties as a second parameter if that's not how I add to
> os.environ?
>
>
>> -----Original Message-----
>> From: Jeff Emanuel [mailto:jemanuel@...]
>> Sent: 26 January 2010 17:37
>> To: Baker, John (IT/UK)
>> Cc: jython-users@...
>> Subject: Re: [Jython-users] Setting environment variables
>>
>>
>> Properties are distinct from environment variables.
>>
>> os.environ is initialized from java.lang.System.getenv().
>> System has no setenv method. You can modify os.environ
>> after it initialized like this:
>>
>> interp.exec("os.environ[ABC]=value");
>>
>> or you can get the environ dict from sys and modify it
>> more directly
>>
>> PySystemState sys = new PySystemState();
>>
>>
> sys.getEnviron().__setitem__(Py.newString("ABC"),Py.newString("value"))
>
>> ;
>> interp=new PythonInterpreter(null,sys);
>>
>>
>>
>>
>>
>> john.m.baker@... wrote:
>>
>>> I still seem unable to set an environment variable. Would you expect
>>>
>> this:
>>
>>> Properties p = new Properties();
>>>
>>> p.setProperty("ABC", "value");
>>>
>>> PythonInterpreter.initialize(System.getProperties(), p, null);
>>>
>>> To allow me to use os.environ['ABC'] in the Python script?
>>>
>>> *From:* Josh Juneau [mailto:juneau001@...]
>>> *Sent:* 08 January 2010 17:52
>>> *To:* Baker, John (IT/UK)
>>> *Cc:* jython-users@...
>>> *Subject:* Re: [Jython-users] Setting environment variables
>>>
>>> Maybe try something like the following...similar to your code, but
>>>
> it
>
>>> is passing all system properties as a first argument, and then the
>>> customized properties as a second arg followed by any args needed by
>>> the interpreted code.
>>>
>>> PythonInterpreter interp;
>>>
>>> Properties props=new Properties();
>>>
>>> props.setProperty("python.home","c:\\jython-2.1");
>>>
>>> PythonInterpreter.initialize(System.getProperties(),props,args);
>>>
>>> interp = new PythonInterpreter();
>>>
>>> Josh Juneau
>>> juneau001@... <mailto:juneau001@...>
>>> http://jj-blogger.blogspot.com
>>> http://www.jythonpodcast.com
>>> Twitter ID: javajuneau
>>>
>>> On Thu, Jan 7, 2010 at 4:47 AM, <john.m.baker@...
>>> <mailto:john.m.baker@...>> wrote:
>>>
>>> Hello,
>>>
>>> How do I set an environment variable for the PythonInterpreter? I've
>>> tried this but it doesn't work:
>>>
>>> Properties p = System.getProperties();
>>>
>>> p.setProperty("MY_VAR", "abc");
>>>
>>> PythonInterpreter.initialize(p, null, null);
>>>
>>> PythonInterpreter pi = new PythonInterpreter();
>>>
>>> Thanks,
>>>
>>> John
>>>
>>> This e-mail (including any attachments) is confidential, may contain
>>>
>>> proprietary or privileged information and is intended for the named
>>>
>>> recipient(s) only. Unintended recipients are prohibited from taking
>>> action
>>>
>>> on the basis of information in this e-mail and must delete all
>>>
> copies.
>
>>> Nomura will not accept responsibility or liability for the accuracy
>>>
>> or
>>
>>> completeness of, or the presence of any virus or disabling code in,
>>>
>> this
>>
>>> e-mail. If verification is sought please request a hard copy. Any
>>> reference
>>>
>>> to the terms of executed transactions should be treated as
>>>
>> preliminary
>>
>>> only
>>>
>>> and subject to formal written confirmation by Nomura. Nomura
>>>
> reserves
>
>> the
>>
>>> right to monitor e-mail communications through its networks (in
>>> accordance
>>>
>>> with applicable laws). No confidentiality or privilege is waived or
>>> lost by
>>>
>>> Nomura by any mistransmission of this e-mail. Any reference to
>>> "Nomura" is
>>>
>>> a reference to any entity in the Nomura Holdings, Inc. group. Please
>>>
>> read
>>
>>> our Electronic Communications Legal Notice which forms part of this
>>> e-mail:
>>>
>>> http://www.Nomura.com/email_disclaimer.htm
>>>
>>>
>>>
>>>
> ---------------------------------------------------------------------
>
>> ---------
>>
>>> This SF.Net email is sponsored by the Verizon Developer Community
>>> Take advantage of Verizon's best-in-class app development support
>>> A streamlined, 14 day to market process makes app distribution fast
>>> and easy
>>> Join now and get one step closer to millions of Verizon customers
>>> http://p.sf.net/sfu/verizon-dev2dev
>>> _______________________________________________
>>> Jython-users mailing list
>>> Jython-users@...
>>> <mailto:Jython-users@...>
>>> https://lists.sourceforge.net/lists/listinfo/jython-users
>>>
>>>
>>>
>>> This e-mail (including any attachments) is confidential, may contain
>>> proprietary or privileged information and is intended for the named
>>> recipient(s) only. Unintended recipients are prohibited from taking
>>> action
>>> on the basis of information in this e-mail and must delete all
>>>
> copies.
>
>>> Nomura will not accept responsibility or liability for the accuracy
>>>
>> or
>>
>>> completeness of, or the presence of any virus or disabling code in,
>>>
>> this
>>
>>> e-mail. If verification is sought please request a hard copy. Any
>>> reference
>>> to the terms of executed transactions should be treated as
>>>
>> preliminary
>>
>>> only
>>> and subject to formal written confirmation by Nomura. Nomura
>>>
> reserves
>
>> the
>>
>>> right to monitor e-mail communications through its networks (in
>>> accordance
>>> with applicable laws). No confidentiality or privilege is waived or
>>> lost by
>>> Nomura by any mistransmission of this e-mail. Any reference to
>>> "Nomura" is
>>> a reference to any entity in the Nomura Holdings, Inc. group. Please
>>>
>> read
>>
>>> our Electronic Communications Legal Notice which forms part of this
>>> e-mail:
>>> http://www.Nomura.com/email_disclaimer.htm
>>>
>>>
> ---------------------------------------------------------------------
>
>> ---
>>
>>>
> ---------------------------------------------------------------------
>
>> ---------
>>
>>> The Planet: dedicated and managed hosting, cloud storage, colocation
>>> Stay online with enterprise data centers and the best network in the
>>>
>> business
>>
>>> Choose flexible plans and management services without long-term
>>>
>> contracts
>>
>>> Personal 24x7 support from experience hosting pros just a phone call
>>>
>> away.
>>
>>> http://p.sf.net/sfu/theplanet-com
>>>
>>>
> ---------------------------------------------------------------------
>
>> ---
>>
>>> _______________________________________________
>>> Jython-users mailing list
>>> Jython-users@...
>>> https://lists.sourceforge.net/lists/listinfo/jython-users
>>>
>>>
>
>
>
> This e-mail (including any attachments) is confidential, may contain
> proprietary or privileged information and is intended for the named
> recipient(s) only. Unintended recipients are prohibited from taking action
> on the basis of information in this e-mail and must delete all copies.
> Nomura will not accept responsibility or liability for the accuracy or
> completeness of, or the presence of any virus or disabling code in, this
> e-mail. If verification is sought please request a hard copy. Any reference
> to the terms of executed transactions should be treated as preliminary only
> and subject to formal written confirmation by Nomura. Nomura reserves the
> right to monitor e-mail communications through its networks (in accordance
> with applicable laws). No confidentiality or privilege is waived or lost by
> Nomura by any mistransmission of this e-mail. Any reference to "Nomura" is
> a reference to any entity in the Nomura Holdings, Inc. group. Please read
> our Electronic Communications Legal Notice which forms part of this e-mail:
> http://www.Nomura.com/email_disclaimer.htm
>
>
> ------------------------------------------------------------------------------
> The Planet: dedicated and managed hosting, cloud storage, colocation
> Stay online with enterprise data centers and the best network in the business
> Choose flexible plans and management services without long-term contracts
> Personal 24x7 support from experience hosting pros just a phone call away.
> http://p.sf.net/sfu/theplanet-com
> _______________________________________________
> Jython-users mailing list
> Jython-users@...
> https://lists.sourceforge.net/lists/listinfo/jython-users
>
|