Automatic Command from output - jupyter-notebook

First code Automatically Print Second Code Result ?
#input first code
a='apple'
b='book'
c='command'
command = "abc"
print(",".join(command))
#output
a,b,c
is There Anyway , Output Result Automatically Print Like This.
input second code
a='apple'
b='book'
c='command'
print (a,b,c)
output
apple book command

Related

Why do input functions like readline() and scan() include code when scanning for inputs? How to fix?

If I run,
input <- as.integer(scan(what = "integer"))
I get no problems, but
input <- scan(what = "integer")
#Anything here, including whitespace
Now input incudes the "#Anything here" as part of the input, and trying to as.integer() it gives me an NA. (If nmax=1, it automatically reads that as the input and doesn't allow any more.)
How is this preventable? What am I doing wrong?
Only works when you run the individual input line all by itself, give the input, then run the rest by itself. Should run code until input function is called, then give an input interface, THEN include the rest of the code. I am using RStudio.
In RStudio, use Source to read the input the way you want. Using Ctrl-Enter or Run simulates pasting it into the console (which means text following the scan() is assumed to be input).
So this works with Ctrl-Enter:
input <- scan(what = integer())
3
#Anything here, including whitespace
and the input ends up containing 3. (what should be an example of the type you want, not the name of it. So use integer() if you want an integer result.)
This works with Source:
input <- scan(what = integer())
#Anything here, including whitespace
and will prompt you to enter the number.

How to check if data shows in html table else if the data didn't show in the table it will failed using robot framework

I have a new problem in my automation testing and I need to check if the data in my tables exist.
For Example.. I have a table below. I need to check if the cat and dog exist in the table.. else it will failed. so I create a run keyword if to verify if the data exist but first I need to get all the data because sometimes he table is dynamic. This is my sample code. my problem is.. what if the data(Dog) didn't exist in the table?
${Count} get element count ${Table_Row}
FOR ${i} IN RANGE 1 ${Count}
${Animals} get text xpath=//div[#id='table1']/table/tbody/tr/td[41]/div/table/tbody/tr[${i}]/td
Run Keyword If "${Animals}" == "Dog" Log to console Dog Exist ELSE fail Dog didn't exist
END
What you need is to get all the elements of first column into a array, something like:
${animals} Get WebElements xpath=//"xpath for all elements in first column"
then with that you can run a for cycle to check each element and fail the test if you don't find whatever you need to find:
FOR ${element} in #{animals}
${animal} Get Text ${element}
Log To Console ${animal}
END
You can check first expected data exists or not
${data}= Page Should Contain Element element xpath
if not exists you can fail the test.
Please let me know if I am not understood your question correctly..

Getting rid of an extra "Null" in an R Function

I've written a simple function in R (see below) which works well. But, I get an unwanted word: "Null" at the end of the output when I execute the code.
I was wondering how I could modify my current code to remove the the unwanted, extra word "Null" that appears at the end of the output given by this function?
Here is my R code:
postsigma <- function(n,sigma2,b2,mu,mean){
SigPost <- (1/((n/sigma2)+(1/b2)))
MuPost <- ((SigPost/b2)*mu)+((SigPost/(sigma2/n))*mean)
curve(dnorm(x,MuPost,sqrt(SigPost)),xlim=c(0,MuPost+4),ylim=c(0,dnorm(MuPost,MuPost,sqrt(SigPost))+.02),ylab="Density",main=expression("Posterior of "(mu)))
D <- cat("\t","Mu of Posterior:","\t",MuPost,"\n","\t","Sigma of Posterior:",SigPost)
return(D)}
postsigma(200,15,5,2,5)
The NULL is the value of D. R will print this out. Just remove the statement return(D) and it will get rid of the NULL. You might also want to add a linefeed \n to your cat statement
Also there is no reason to save the result of the cat in D. You can leave off D <- as well.

not able to understand NAWK use

I found a command which takes the input data from a binary file and writes into a output file.
nawk 'c-->0;$0~s{if(b)for(c=b+1;c>1;c--)print r[(NR-c+1)%b];print;c=a}b{r[NR%b]=$0}' b=1 a=19 s="<Comment>Ericsson_OCS_V1_0.0.0.7" /var/opt/fds/config/ServiceConfig/ServiceConfig.cfg > /opt/temp/"$circle"_"$sdpid"_RG.cfg
It's working but I am not able to find out how...Could anyone please help me out how above command is working and what is it doing?...this nawk is too tough to understand...:(
Thanks in advance......
nawk is not tough to understand and is same like other languages, I guess you are not able to understand it because it not properly formatted, if you format it you will know how it's working.
To answer your question this command is searching lines containing an input text in given input file, and prints few lines before matched line(s) and few lines after the matched line. How many lines to be printed are controlled by variable "b" (no of lines before) and "a" (no of lines after) and string/text to be searched is passed using variable "s".
This command will be helpful in debugging/troubleshooting where one want to extract lines from large size log files (difficult to open in vi or other editor on UNIX/LINUX) by searching some error text and print some lines above it and some line after it.
So in your command
b=1 ## means print only 1 line before the matching line
a=19 ## means print 19 lines after the matching line
s="<Comment>Ericsson_OCS_V1_0.0.0.7" ## means search for this string
/var/opt/fds/config/ServiceConfig/ServiceConfig.cfg ## search in this file
/opt/temp/"$circle"_"$sdpid"_RG.cfg ## store the output in this file
Your formatted command is below, the very first condition which was looking like c-->0 before format is easy to interpret which means c-- greater than 0. NR variable in AWK gives the line number of presently processing line in input file being processed.
nawk '
c-- > 0;
$0 ~ s
{
if(b)
for(c=b+1;c>1;c--)
print r[(NR-c+1)%b];
print;
c=a
}
b
{
r[NR%b]=$0
}' b=1 a=19 s="<Comment>Ericsson_OCS_V1_0.0.0.7" /var/opt/fds/config/ServiceConfig/ServiceConfig.cfg > /opt/temp/"$circle"_"$sdpid"_RG.cfg

How can I insert a column in numeric comma separated input?

Hi i have as text file below
input
326783,326784,402
326783,0326784,402
503534,503535,403
503534,0503535,403
429759,429758,404
429759,0429758,404
409626,409627,405
409626,0409627,405
369917,369916,402
369917,0369916,403
i want to convert it like below
condition :
1)input file column 3 and column 1 should be be same for 326784 and 0326784 and like that so on
2)if it different like the above input file last case then it should be printed in last line
output should be
326783,326784,0326784,402
503534,503535,0503535,403
429759,429758,0429758,404
409626,409627,0409627,405
369917,369916,402
369917,0369916,403
i am using solaris platform
please help me
I don't understand the logic of your computation, but some general advice: the unix tool awk can do such computations. It understands comma-separated files and you can get it to output other comma-separated files, manipulated by your logic (which you'll have to express in awk syntax).
This is, as I understand it, the unix way to do it.
The way I'd do it (being a non-expert on awk and just mentioning it for completeness ;) would be to write a little python script.
you want to
open an input and an output file
get each line from the input file
parse the integers
perform your logic
write integers to your output file
unchecked python-like code:
f_in = open("input", "r")
f_out = open("output", "w")
for line in f_in.readlines():
ints = [int(x) for x in line.split(",")]
f_out.write("%d, %d, %d\n" % (ints[0], ints[1], ints[0]+ints[1]))
f_in.close()
f_out.close()
Here, the logic is in the f_out.write(...) line (this example would output the first, the second and the sum of both input integers)
You can check if you have a Python interpreter at hand by simply typing python and seeing what happens. If you have, save your code into something.py and start it with "python something.py"

Resources