Python %s not working when printing another veriable - python-3.4

Me and my friend are working on a program that keeps track of swimmers times and all the times totaled is there aggregate. We also ask that the swimmers name which is equal to Name.
We are able to print out...
print('Swimmer had a total time of',aggregates[Name])
but the %Name stop the program from running properly, any suggestions to what we could use instead or maybe what we're doing wrong would be very helpful. Thanks!
print('''%s had a total aggregate time of
''',aggregates[Name] %Name)

Formatting print should be done like print("%s had a t..." % Name, aggregates[Name])

Related

Finding time between two patterns

I am new to unix and can someone help me with following query?
I have a deployment log file and there I wanted to search for two pattern (eg: started , completed ) and after getting the out put I just want to calculate and print the time taken between the started step and completed step
I tried a lot I’m able to print the the out put but unable to print the time taken between those steps
Thanks in advance,
Mahi
Below is the sample deployment log and at the starting line i am searching for "DeploymentStart" and, at the end of the line "DeploymentCompleted".
After printing this out put i want to calculate the time taken between deploymentStart time and DeployemntCompleted time.
us>InterimDeploymentStart1523623301227ETA0submittedCount3suppressedCount0listRejectedCount0<
/Pair>batchSplitRejectedCount0emailRendererRejectedCount0
Apr13 12:41:49,492 INFO com.epsilon.deploymentStatusNotifier.util.DeploymentStatusNotificationConverter taskScheduler-2 - JobMessage createdcom.epsilon.common.jobs.model.JobMessage#530c458e
Apr13 12:41:49,488 INFO com.epsilon.deploymentStatusNotifier.util.DeploymentStatusNotificationConverter taskScheduler-2 - JobMessage createdcom.epsilon.comm
JobMessage>de841c92-6682-4696-883c-3087a9194531HarmonyPipelinecompletedDeploymentCompleted1523623301227ETA0

Is there a way to let the console in RStudio produce time stamps? [duplicate]

I wonder if there is a way to display the current time in the R command line, like in MS DOS, we can use
Prompt $T $P$G
to include the time clock in every prompt line.
Something like
options(prompt=paste(format(Sys.time(), "%H:%M:%S"),"> "))
will do it, but then it is fixed at the time it was set. I'm not sure how to make it update automatically.
Chase points the right way as options("prompt"=...) can be used for this. But his solutions adds a constant time expression which is not what we want.
The documentation for the function taskCallbackManager has the rest:
R> h <- taskCallbackManager()
R> h$add(function(expr, value, ok, visible) {
+ options("prompt"=format(Sys.time(), "%H:%M:%S> "));
+ return(TRUE) },
+ name = "simpleHandler")
[1] "simpleHandler"
07:25:42> a <- 2
07:25:48>
We register a callback that gets evaluated after each command completes. That does the trick. More fancy documentation is in this document from the R developer site.
None of the other methods, which are based on callbacks, will update the prompt unless a top-level command is executed. So, pressing return in the console will not create a change. Such is the nature of R's standard callback handling.
If you install the tcltk2 package, you can set up a task scheduler that changes the option() as follows:
library(tcltk2)
tclTaskSchedule(1000, {options(prompt=paste(Sys.time(),"> "))}, id = "ticktock", redo = TRUE)
Voila, something like the MS DOS prompt.
NB: Inspiration came from this answer.
Note 1: The wait time (1000 in this case) refers to the # of milliseconds, not seconds. You might adjust it downward when sub-second resolution is somehow useful.
Here is an alternative callback solution:
updatePrompt <- function(...) {options(prompt=paste(Sys.time(),"> ")); return(TRUE)}
addTaskCallback(updatePrompt)
This works the same as Dirk's method, but the syntax is a bit simpler to me.
You can change the default character that is displayed through the options() command. You may want to try something like this:
options(prompt = paste(Sys.time(), ">"))
Check out the help page for ?options for a full list of things you can set. It is a very useful thing to know about!
Assuming this is something you want to do for every R session, consider moving that to your .Rprofile. Several other good nuggets of programming happiness can be found hither on that topic.
I don't know of a native R function for doing this, but I know R has interfaces with other languages that do have system time commands. Maybe this is an option?
Thierry mentioned system.time() and there is also proc.time() depending on what you need it for, although neither of these give you the current time.

time command running on function wont let the function print

I have a problem with my code. It doesn't print out an error, it works but it doesn't do what I actually need it to do. I won't be posting all of the code because it is not needed, I will just post the line we need.
So I have this line of code:
TIME1=$( { time awkfun ; } 2>&1 >/dev/null);
Where awkfun is a function that should print 500 integers, and TIME1 is a variable to store the time that the function will need to run and print. Problem is that normally as I said the function would print around 500 integers in this occasion though that I am using this, it just runs and does the calculations but is not printing. So it actually runs the awkfun function but doesn't let it print, in the time output for this function I also need the time it needs to print everything.
How to do that?
I hope I explained it as good as possible, if any questions arise please don't hesitate to comment, thanks in advance!
P.S
Running in ksh in oracle solaris.
Here is the correct sequence. Adjust as needed:
TIME1=`time (awkfun > /dev/tty) 2>&1`

How to use create-<breeds>-with between two breed turtle agents?

I've been stuck by this issue for a long time. I have two networks in my model, so I want to create different types of links with different breed turtle agentsets.
Let's name the 1st turtle agentset T1 and the 2nd T2, so what I did is the following:
breed [T1s T1]
undirected-link-breed [TL1s TL1]
breed [T2s T2]
undirected-link-breed [TL2s TL2]
;;Got error report
ask T1s [create-TL1s-with other n-of 10 T1s]
The last line gave an error reporting that "You cannot use breeded and unbreeded links in the same world". I'm quite confused about what this means.
And then, I changed the last line to:
ask T1s [create-links-with other n-of 10 T1s]
It worked this time, but if that's the case, how can I define two different types of links, i.e., TL1 and TL2, with different turtle agentsets T1s and T2s?
Can anybody help me out? I really appreciate it!
Thanks
That error means that you've created some links that have no breed (probably with create-link-with) before creating links with a breed, or vice-versa. If you want to use link breeds, you can never use create-link-with, create-link-to, or create-link-from. You must always use create-<breed>-with, create-<breed>-to, and create-<breed>-from.
So, search your code for instances of create-link-with, create-link-to, or create-link-from and either delete them or change them to create-<breed>-with, create-<breed>-to, or create-<breed>-from. If you're still getting the error, call clear-all or clear-links to make sure you've removed all unbreeded links.

Making a self destructive code in R

I was making a package in R and would like it to make it as a trial version for a period of 30 days .
Well my question is how to make a code self destructive depends on number of days ??
I had played with time and date package for a while where i came to know ,
Sys.Date() could give todays date , so i get forard with something below
today=Sys.Date()
a=today
b=a+1
if(a==today)
{
print(paste("today is sunday"))
if(b==today){
print(paste("today is monday"))
}
I know it is stupid work whatever i had done , my sole idea was to fix the 1st use of package as starting day ,and every day it will increment till 30 days ,when it will reach the limit it will automatically destroy using
file.remove () <- through which I can remove some file ........
May be I am clear with my ideas .
Sorry for the novice question .
Add this condition to the license. ("30 days for free, after that you'll have to pay".) and expect users to comply with this.
There is really nothing else you can do.
Well, actually you can. For example, on the first occasion your code is run, save the current date to a file in a certain location (say, "~/.datetocheck"). Then every time your code is run, check for the existence of this file, and if it exists, compare the dates. If more than 30 days have passed, give an error message:
stop("Time is over! You have to pay!")
The problem is that nothing prevents the user from simply deleting this file.

Resources