[QUOTE=BearofNH;1474983]I just did the following interactively and as you can see, had no problems:

os.putenv('FK_DBO_PASS', '12345')
han = os.popen("SET FK") # Handle to output of subprocess SET FK command
for line in han: print line
...
[color=Green][b]FK_DBO_PASS=12345[/b][/color]

han.close()

Try this and be sure it works for you.

I trust you realize setting environment variables can only be done for the current process level and below. You can't set an environment variable for a higher level process. That's not Python, it's the O/S.[/QUOTE]

Hi BearofNH
I did and it works for current process.
But i want to do it for Higher level process , on O/S level for temporary.
do you have any idea how i can do it?
or how i can get value of a python variable in other batch file , then i will use that value and will set environment variable in batch?
Regards
SA

[QUOTE=tonyjv;1474724]Please include the error messages. The variable must of course be global variable in the python file. At least saving the value to text file to be read by the script should work.[/QUOTE]
HI Tonyjv
I write in abc.py

[I]import os
pname="fk12345"
os.putenv("FK_DBO_PASS",pname)
os.system("test.bat")[/I]

And then i write in my test.bat BATCH file

[I]@echo off
python setev.py
echo $FK_DBO_PASS[/I]

And it gives me this result
C:\Python26>test.
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS
$FK_DBO_PASS

c:\python26>

My goal is to set environment variable in python function. but os.environ is not working for this purpose. so i want to get value of variable in python function into my batch file and then i will use that value to set environment variable in batch file.
Can you please guide more on it. Thanks
Regards
Sarfraz

[QUOTE=slate;1473995]The last version would be:
test.bat
[code]
python -m abc -c print uname
[/code][/QUOTE]

Hi Slate
Thanks for help. i tried all 3 solutions but they are not working. i am using Windows 2003 as my OS and need to work on batch file and python script.
Do you have any more idea?

Best Regards
Sarfraz

HI All!
I need to have some help. I have a python function name is abc.py and variable is declared in abc.py, variable name is 'uname'. How can i call variable name 'uname' of abc.py in my batch file name testing.bat and get uname value in my batch testing.bat file?

Best Regards
Sarfraz

[QUOTE=BearofNH;1473774]Have you tried
os.putenv(key, value)
?[/QUOTE]

HI
Yes i tried now . i write
os.putenv('FK_DBO_PASS','12345') and also i tried os.putenv(FK_DBO_PASS,12345)
in 1ast case it is giving error that FK_DBO_PASS is not defined and also for 12345. And for 1st case it is not setting.
Am i doing right? do you have more suggestions?

Best Regards
Sarfraz

HI All!
I am creating a Python function that should set environment variable. My simple code is

[I]#!/usr/bin/python
import os
os.environ['FK_DBO_PASS']="12345"
print "After setting Environment Variable is ",os.environ['FK_DBO_PASS'][/I]

When i execute this code file in command prompt it is giving me this result

[I]After setting Environment Variable is 12345[/I]

But when i run this command in command prompt SET FK_DBO_PASS
The result is
[I]Environment variable FK_DBO_PASS not defined[/I]

My code is not setting environment variable .Can some one help me how i can fix this code? and how i can set temporary environment variable through python code just for my existing process?
Waiting for someone help. Thanks

Best Regards
Sarfraz

Hi there
I have following XML document that i want to read in python code. i know how to read, thing is i want to make hash/list from this XML document.

<?xml version="1.0" ?>
‐<TradeExt>
‐ <fxall category="buyer" version="2.0">
‐<tradeHeader>
<sourceId>test_sourceId1</sourceId>
<pmsId>4521363.0.0</pmsId>
<fundId>ACCT1@TESTCUST</fundId>
</tradeHeader>
‐ <tradeStatus>
<dealImmediately>F</dealImmediately>
<blockImmediately>F</blockImmediately>
</tradeStatus>
‐ <tradeFinancials>
<userDefinedFields Name="UDF_6">six</userDefinedFields>
<userDefinedFields Name="UDF_7">seven</userDefinedFields>
<remarks>test remark</remarks>
</tradeFinancials>
</fxall>

‐ <fxall category="buyer" version="2.0">
‐ <tradeHeader>
<sourceId>test-sourceId2</sourceId>
<pmsId>4521363.0.1</pmsId>
<fundId>ACCT2@TESTCUST</fundId>
<pomsId>4521363_0_1_0</pomsId>
<blockTicketId>4521363</blockTicketId>
<lastNegotiator>trader@TESTCUST</lastNegotiator>
<traderId>null Maker Name</traderId>
</tradeHeader>
‐ <tradeStatus>
<state>Completed</state>
<nonNegotiated>F</nonNegotiated>
<blockImmediately>F</blockImmediately>
</tradeStatus>
‐ <tradeFinancials>
<spotRate>1.4144</spotRate>
<forwardPoints>0</forwardPoints>
<allinRate>1.4144</allinRate>
<indicativeRate>1.1695</indicativeRate>
<counterParty>ABN</counterParty>
<userDefinedFields Name="UDF_9">nine</userDefinedFields>
<userDefinedFields Name="UDF_10">ten</userDefinedFields>
<userDefinedFields Name="UDF_11">eleven</userDefinedFields>
<remarks>test remark2</remarks>
</tradeFinancials>
</fxall>
</TradeExt>

-----------------------------END OF XML FILE-----------------------------
How i can make a list/hash for furthur using in code? that i can access keys and values in furthur code.
I want to have result like this

Field [sourceId : test_sourceId1 , pmsId : 4521363.0.0,fundId:ACCT1@TESTCUST, and so on..............]

I dont want to use getElementsByTagName.And i am using xml.dom import minidom already.

[QUOTE=ultimatebuster;1201623]try

if client == dealing_clients[data["fundId"]]:

() <- it's a tuple, or an immutable list.
= <- assign operator, you should never use that in a if statement. I'm going to guess you meant an compare operator, which is ==[/QUOTE]

HI
Its worked. Thanks buster....

Hi there
I am translating PERL code into PYTHON Code
My PERL code is

if ( my $client = $dealing_clients->{ $data->{fundId} } )

And i translated it into python as

if (client = dealing_clients[data["fundId"]]):

But it is giving my following Error
"Syntax Error While detecting Tuple"

Any one know how to fix this error and why i am getting this error?
Waiting for guidance. Thanks in advance.

Regards
Sarfraz

Hi there
I have following hash related code in Perl that i need to translate in Python

if ( exists $legs->{$reference} ) {
        logg(" 2nd leg of swapes: $ref - merging");
        my $swap = merge_swap_legs( $legs->{$ref}, $fields );
        $ref = new_fk_ref( $fxall, $ref, $swap );
      } else {
        $legs->{$ref} = $fields;
        logg("1st leg of swap: $ref");

Can anyone help me how i can translate above code into PYTHON?
Waiting for help from some one. Thanks
Regards

[QUOTE=hondros;1159940][code]

Hashes/Arrays are known as Libraries in Python:

a = {}
a['b'] = 0
print(a)
print(a['b'])
[/code][/QUOTE]

Thanks friend for guidance....

Hi there
I am translating PERL code into python and i am new on both language.I have one question if we have hash key reference in PERL like this way
$a->{b}
how we can traslate it into PYTHON?
and if we have this code $a->{$b} , how we translate it into PYTHON also?
Waiting for help. Thanks
Regards
Sarfraz