Sponsored Content
Top Forums Shell Programming and Scripting Use the variables in a python script. Post 302999816 by apmcd47 on Wednesday 28th of June 2017 09:56:17 AM
Old 06-28-2017
Using Python 2.7 on Ubuntu 16.04 (Xenial) - What is your system?

Does this help?
Code:
$ python
Python 2.7.12 (default, Nov 19 2016, 06:48:10) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> from ConfigParser import SafeConfigParser
>>> parser = SafeConfigParser()
>>> parser.read('pltfm.ini')
['pltfm.ini']
>>> help(parser)

>>> parser.sections()
['test_ini', 'ptfm_dgnst']
>>> parser.items('test_ini')
[('region', 'North'), ('country', 'USA')]
>>> parser.items('ptfm_dgnst')
[('conn_fl', "`perl -F= -lane 'print $F[1] if m!^com.cis.b33.team_db_conn!' $HOME/opt/config.ini`"), 
('conn', '`$HOME/opt/bin/decrypt $CONN_FL`')]
>>> ptfm_dgnst = dict(parser.items('ptfm_dgnst'))
>>> conn_str = ptfm_dgnst['conn']
>>> print conn_str
`$HOME/opt/bin/decrypt $CONN_FL`
>>>

As you can see I am using the Python CLI - it's so much easier for testing snippets of code. Note the use of the help function - it shows the equivalent of a man page of Python classes and their methods. I don't know what you were trying to achieve with
Code:
conn_str=os.system("echo $CONN")

but I hope the above helps you with achieving that.

A quick look at the statements I typed in:
parser.sections() lists the section of the ini file.
parser.items('test_ini') lists the section test_ini as a list of tuples; each tuple a name/value pair.
ptfm_dgnst = dict(parser.items('ptfm_dgnst')) creates a dictionary (simplistically Python's hash table) so you can now access the values through their names.
conn_str = ptfm_dgnst['conn'] does what I think you were trying to do with the conn_str = os.system() statement.

I hope this helps.

Andrew

Last edited by apmcd47; 06-28-2017 at 12:03 PM.. Reason: Typo! con.system instead of os.system
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to run python script from a Tcl script

Hi I have a python script,i need to run this script from a tcl script.Can anyone let me know how to do this (1 Reply)
Discussion started by: nathgopi214
1 Replies

2. Shell Programming and Scripting

Hi Python and shell script,the script hangs

Hi I need to run a shell script from a TCL script,the shell script in trun will run a python script 1.Tcl script set filename "./GopiRun.sh" 2.GopiRun.sh python ./psi.py $MYSB/test_scripts/delivery/gpy1.py 3.I have my gpy1.py script. Here the problem i am facing is on running... (0 Replies)
Discussion started by: nathgopi214
0 Replies

3. Web Development

passing variables to python script

Hello again, You guys might remember me from the "Apache problems" thread. And because this forum is the only one that actually helped me out after months of problems I was hoping you could help me with something related. Now if you remember the final code that we made for creating an account... (0 Replies)
Discussion started by: darkphaux
0 Replies

4. Shell Programming and Scripting

Passing variable from shell script to python script

I have a shell script main.sh which inturn call the python script ofdm.py, I want to pass two variables from shell script to python script for its execution. How do i achieve this ????? Eg: main.sh a=3 b=3; c= a+b exec python ofdm.py ofdm.py d=c+a Thanks in Anticipation (4 Replies)
Discussion started by: shashi792
4 Replies

5. Shell Programming and Scripting

Python script called by a shell script

experts, i wrote a python script to do a certain job, i tried it and it is working fine, i want this script to be executed automatically after a ksh script, the problem is when i execute the ksh script my python script runes perfectly after the ksh script as I have include it at the end of the ksh... (1 Reply)
Discussion started by: q8devilish
1 Replies

6. Shell Programming and Scripting

Running a script with multiple variables like 25 variables.

Hi All, i have a requirement where i have to run a script with at least 25 arguements and position of arguements can also change. the unapropriate way is like below. can we achieve this in more good and precise way?? #!/bin/ksh ##script is sample.ksh age=$1 gender=$2 class=$3 . . .... (3 Replies)
Discussion started by: Lakshman_Gupta
3 Replies

7. Shell Programming and Scripting

Using Python Variables in one Instance

I have another basic Pythonic question that I cant seem to figure out. Here we go. So what I am trying to accomplish is simply using a second variable in my "scanjob" variable adding "api_tok". I am using a product that needs an api_token for every call so I just want to persistently add "api_tok"... (0 Replies)
Discussion started by: metallica1973
0 Replies

8. Shell Programming and Scripting

Capture run time of python script executed inside shell script

I have bash shell script which is internally calling python script.I would like to know how long python is taking to execute.I am not allowed to do changes in python script.Please note i need to know execution time of python script which is getting executed inside shell .I need to store execution... (2 Replies)
Discussion started by: Adfire
2 Replies

9. Windows & DOS: Issues & Discussions

How to execute python script on remote with python way..?

Hi all, I am trying to run below python code for connecting remote windows machine from unix to run an python file exist on that remote windows machine.. Below is the code I am trying: #!/usr/bin/env python import wmi c = wmi.WMI("xxxxx", user="xxxx", password="xxxxxxx")... (1 Reply)
Discussion started by: onenessboy
1 Replies
XML_SET_PROCESSING_INSTRUCTION_HANDLER(3)				 1				 XML_SET_PROCESSING_INSTRUCTION_HANDLER(3)

xml_set_processing_instruction_handler - Set up processing instruction (PI) handler

SYNOPSIS
bool xml_set_processing_instruction_handler (resource $parser, callable $handler) DESCRIPTION
Sets the processing instruction (PI) handler function for the XML parser $parser. A processing instruction has the following format: target data?> ?>) can not be quoted, so this character sequence should not appear in the PHP code you embed with PIs in XML documents.If it does, the rest of the PHP code, as well as the "real" PI end tag, will be treated as character data. PARAMETERS
o $parser - A reference to the XML parser to set up processing instruction (PI) handler function. o $handler -$handler is a string containing the name of a function that must exist when xml_parse(3) is called for $parser. The function named by $handler must accept three parameters: handler (resource $parser, string $target, string $data) o $parser - The first parameter, parser, is a reference to the XML parser calling the handler. o $target - The second parameter, $target, contains the PI target. o $data - The third parameter, $data, contains the PI data. If a handler function is set to an empty string, or FALSE, the handler in question is disabled. Note Instead of a function name, an array containing an object reference and a method name can also be supplied. RETURN VALUES
Returns TRUE on success or FALSE on failure. PHP Documentation Group XML_SET_PROCESSING_INSTRUCTION_HANDLER(3)
All times are GMT -4. The time now is 07:58 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy