471,337 Members | 867 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 software developers and data experts.

get the following output

hi
i am using Python with Activegrid and with the help of python i am getting some output from Server and i have to display particular values from that output
for example:
after splitting i get the string as
server o/p:

yuvaraj,sfsfsf,fasdfsf,safsaf,raj,sadfsfsf,safsafsaf,safsdfa,inp,safsaf,sgsdg,inp,asdfsa,sgsdg,raj,adfsaf,sadfsaf,inp,wetwt,etwtw,raj,wrqrqr

and i need to pick the values from starting inp and the following 2 records continue's that such as


inp,safsaf,sgsdg,
inp,asdfsa,sgsdg
inp,wetwt,etwtw

please reply ASAP
regards
Dec 27 '07 #1
7 1329
bvdet
2,851 Expert Mod 2GB
hi
i am using Python with Activegrid and with the help of python i am getting some output from Server and i have to display particular values from that output
for example:
after splitting i get the string as
server o/p:

yuvaraj,sfsfsf,fasdfsf,safsaf,raj,sadfsfsf,safsafsaf,safsdfa,inp,safsaf,sgsdg,inp,asdfsa,sgsdg,raj,adfsaf,sadfsaf,inp,wetwt,etwtw,raj,wrqrqr

and i need to pick the values from starting inp and the following 2 records continue's that such as


inp,safsaf,sgsdg,
inp,asdfsa,sgsdg
inp,wetwt,etwtw

please reply ASAP
regards
This will do something similar to the output you want:
Expand|Select|Wrap|Line Numbers
  1. def filter_seq(seq, keyw='inp', no_records=2):
  2.     return [(seq[i], seq[i+1:i+1+no_records]) for i in range(len(seq)-no_records) if seq[i]==keyw]
  3.  
  4. seq = ['yuvaraj','sfsfsf','fasdfsf','safsaf','raj','sadfsfsf','safsafsaf','safsdfa',\
  5.        'inp','safsaf','sgsdg','inp','asdfsa','sgsdg','raj','adfsaf','sadfsaf','inp',\
  6.        'wetwt','etwtw','raj','wrqrqr']
  7.  
  8. print filter_seq(seq)
Output:
>>> [('inp', ['safsaf', 'sgsdg']), ('inp', ['asdfsa', 'sgsdg']), ('inp', ['wetwt', 'etwtw'])]
Dec 27 '07 #2
bvdet
2,851 Expert Mod 2GB
This is equivalent to the code in my previous post, but iterates to the end of the sequence:
Expand|Select|Wrap|Line Numbers
  1. def filter_seq1(seq, keyw='inp', no_records=2):
  2.     output = []
  3.     for i, item in enumerate(seq):
  4.         if item == keyw:
  5.             output.append((item, seq[i+1:i+1+no_records]))
  6.     return output
  7.  
Test:
Expand|Select|Wrap|Line Numbers
  1. >>> print filter_seq(seq, 'raj', 2)
  2. [('raj', ['sadfsfsf', 'safsafsaf']), ('raj', ['adfsaf', 'sadfsaf'])]
  3. >>> print filter_seq1(seq, 'raj', 2)
  4. [('raj', ['sadfsfsf', 'safsafsaf']), ('raj', ['adfsaf', 'sadfsaf']), ('raj', ['wrqrqr'])]
  5. >>> 
Dec 27 '07 #3
hi
thanks for ur reply and it helpled me and now here with the same i was not able to split or replace or sub with the output:
[('inp', ['safsaf', 'sgsdg']), ('inp', ['asdfsa', 'sgsdg']), ('inp', ['wetwt', 'etwtw'])]

i need to display it as

inp, safsaf, sgsdg, inp, asdfsa, sgsdg, inp, wetwt, etwtw
without any special characters and able to be split further if possible
Reply me ASAP
regards
Dec 28 '07 #4
hi
thanks for ur reply and it helpled me and now here with the same i was not able to split or replace or sub with the output:
[('inp', ['safsaf', 'sgsdg']), ('inp', ['asdfsa', 'sgsdg']), ('inp', ['wetwt', 'etwtw'])]

i need to display it as

inp, safsaf, sgsdg, inp, asdfsa, sgsdg, inp, wetwt, etwtw
without any special characters and able to be split further if possible
Reply me ASAP
regards
hi
thanks for replying before and finally i attain my task by converting the tuple as a string and able to do all the function
str()
regards
Dec 28 '07 #5
hi
here another problem and i am trying to display the output in HTML table as

before str() it is
[inp,sdfs,adsf,inp,sadf,sdfff,inp,sadf,affaf]

and i need to display it as

fun1 fun2 fun3
inp sdfs adsf
inp sadf sdfff
inp sadf affaf


but it displays as single character as
fun1 fun2 fun3
i n p
s d f
s a d
s f i

and so on...... how to convert character to string
or how to display this format
note:from inp i need only 2 strings and it will be static
reply me ASAP
regards
Dec 28 '07 #6
bvdet
2,851 Expert Mod 2GB
hi
here another problem and i am trying to display the output in HTML table as

before str() it is
[inp,sdfs,adsf,inp,sadf,sdfff,inp,sadf,affaf]

and i need to display it as

fun1 fun2 fun3
inp sdfs adsf
inp sadf sdfff
inp sadf affaf


but it displays as single character as
fun1 fun2 fun3
i n p
s d f
s a d
s f i

and so on...... how to convert character to string
or how to display this format
note:from inp i need only 2 strings and it will be static
reply me ASAP
regards
Original output from earlier post:
Expand|Select|Wrap|Line Numbers
  1. >>> [('inp', ['safsaf', 'sgsdg']), ('inp', ['asdfsa', 'sgsdg']), ('inp', ['wetwt', 'etwtw'])]
Reformat output string:
Expand|Select|Wrap|Line Numbers
  1. print '\n'.join([item for item in [' '.join([s[0], ' '.join(s[1])]) \
  2.                                       for s in filter_seq1(seq, 'inp', 2)]])
Output:
Expand|Select|Wrap|Line Numbers
  1. >>> inp safsaf sgsdg
  2. inp asdfsa sgsdg
  3. inp wetwt etwtw
  4. >>> 
Dec 28 '07 #7
hi
thanks for ur reply's and finally i got it with ur help
actually i am new to both python and Activegrid
thanks again
regards
Dec 29 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

8 posts views Thread by aditya | last post: by
4 posts views Thread by zaperaj | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.