I want to disable those operator function when some error occur.
rightnow when i use button_operator['state'] = tkinter.DISABLED
it only disable '+' operator only
operations = {"/": "÷", "*": "x", "-": "-", "+": "+"}
i = 2
for operator, symbol in operations.items():
global button_operator
button_operator = tkinter.Button(button_frame, text=symbol, bg=LIGHT_GRAY, fg=LABEL_COLOR, font=DEFAULT_FONT_STYLE,borderwidth=0,command=lambda x=operator: self.evaluate(x),name = symbol)
button_operator.grid(row=i, column=4, sticky=tkinter.NSEW)
self.changeOnHover(button_operator,DARK_GRAY,LIGHT_GRAY)
i += 1
button_operator['state'] = tkinter.DISABLED
Related
I'm trying to parse this line:
01/11/1011 11:11:11: LOG SERVER = 1 URL = /one/one.aspx/ AccountId = 1111 MainId = 1111 UserAgent = Browser = Chrome , Version = 11.0, IsMobile = False, IP = 1.1.1.1 MESSAGE = sample message TRACE = 1
using this parse statement:
parse-where kind=regex flags=i message with
timestamp:datetime
":.*LOG SERVER = " log_server:string
".*URL = " url:string
".*AccountId = " account_id:string
".*MainId = " main_id:string
".*?UserAgent = " user_agent:string
",.*Version = " version:string
",.*IsMobile = " is_mobile:string
",.*IP = " ip:string
".*MESSAGE = " event:string
".*TRACE = " trace:string
now the thing is that sometimes I got records that has one "key=value" missing but the order of the rest of the columns remains the same.
to match all kinds of rows I just wanted to add (<name_of_colum>)? for example:
"(,.*Version = )?" version:string
but it fails everytime.
I think parse/parse-where operators are more useful when you have well formatted inputs - the potentially missing values in this case would make it tricky/impossible to use these operators.
If you control the formatting of the input strings, consider normalizing it to always include all fields and/or add delimiters and quotes where appropriate.
Otherwise, you could use the extract function to parse it - the following expression would work even if some lines are missing some fields:
| extend
timestamp = extract("(.*): .*", 1, message, typeof(datetime)),
log_server = extract(".*LOG SERVER = ([^\\s]*).*", 1, message),
url = extract(".*URL = ([^\\s]*).*", 1, message),
main_id = extract(".*MainId = ([^\\s]*).*", 1, message),
user_agent = extract(".*UserAgent = ([^,]*).*", 1, message),
version = extract(".*Version = ([^,]*).*", 1, message),
is_mobile = extract(".*IsMobile = ([^,]*).*", 1, message),
ip = extract(".*IP = ([^\\s]*).*", 1, message),
event = iff(message has "TRACE", extract(".*MESSAGE = (.*) TRACE.*", 1, message), extract(".*MESSAGE = (.*)", 1, message)),
trace = extract(".*TRACE = (.*)", 1, message)
I would like a function in Julia code, num2str, that would add commas or a specified delimiter, in the appropriate places on the left side of the decimal point for any kind of valid Julia number, including BigInt and BigFloat. It would return a string for printing.
For example:
flt1 = 122234.141567
println("flt1 num2str($flt1) = ", num2str(flt1))
# Expected output is:
flt1 num2str(122234.141567) = 122,234.141567
I want to use this function with the print and println built-in functions.
This question was partially answered here, i.e, for integers. The following function should answer the need for floats and "big" numbers.
"""
For any valid number, add appropriate delimiters.
See "Regular Expressions Cookbook," by Goyvaerts and Levithan, O'Reilly, 2nd Ed,
p. 402, for Regex that inserts commas into integers returning a string.
"""
function num2str(num::Number; delim=",")
decimal_point = "."
str = string(num)
strs = split(str, decimal_point)
left_str = strs[1]
right_str = length(strs) > 1 ? strs[2] : ""
left_str = replace(left_str, r"(?<=[0-9])(?=(?:[0-9]{3})+(?![0-9]))" => delim)
decimal_point = occursin(decimal_point, str) ? decimal_point : ""
return left_str * decimal_point * right_str
end
# Test integers, BigInts, floats, and BigFloats:
int0 = 0
int1 = 123
int2 = 123456789
big1 = big"123"
big2 = big"123456789123456789"
flt1 = 122234.141567
flt2 = 7.12345e9
big3 = big"260123.0"
big4 = big"7.12345e9"
setprecision(20)
println("int0 num2str($int0) \t\t\t\t = ", num2str(int0))
println("int1 num2str($int1) \t\t\t\t = ", num2str(int1))
println("int2 num2str($int2) \t\t\t = ", num2str(int2))
println("big1 num2str($big1) \t\t\t\t = ", num2str(big1))
println("big2 num2str($big2) \t\t = ", num2str(big2))
println("big2 num2str($big2) delim is _ \t = ", num2str(big2, delim="_"))
println("flt1 num2str($flt1) \t\t\t = ", num2str(flt1))
println("flt1 num2str($flt1) delim is _ \t\t = ", num2str(flt1, delim="_"))
println("flt2 num2str($flt2) \t\t\t = ", num2str(flt2))
println("big3 num2str($big3) \t\t\t = ", num2str(big3))
println("big4 num2str($big4) \t\t\t = ", num2str(big4))
println("big4 num2str($big4) delim is _ \t\t = ", num2str(big4, delim="_"))
## ============================== Output ===================================
int0 num2str(0) = 0
int1 num2str(123) = 123
int2 num2str(123456789) = 123,456,789
big1 num2str(123) = 123
big2 num2str(123456789123456789) = 123,456,789,123,456,789
big2 num2str(123456789123456789) delim is _ = 123_456_789_123_456_789
flt1 num2str(122234.141567) = 122,234.141567
flt1 num2str(122234.141567) delim is _ = 122_234.141567
flt2 num2str(7.12345e9) = 7.12345e9
big3 num2str(2.60123e+05) = 2.60123e+05
big4 num2str(7.12345e+09) = 7.12345e+09
big4 num2str(7.12345e+09) delim is _ = 7.12345e+09
I expect the ability to add comma delimiters will eventually be added to either print/println and/or #printf. Until then, this seems to work.
Trying to use multiple expression SET and DELETE. everything works fine for SET, But when i add DELETE, not able to figure out right syntax.
status = "Previously Deployed version"
message = "New version deployment started"
NewVersion = "PipelineTestAPI_1.5.0"
json_ = {":val1" : status,
":val2" : message,
":val4" : NewVersion
}
dynamo_json = ast.literal_eval(d_json.dumps(json_))
json_key = {"Environment" : "PipelineTestAPI-Prod"}
dynamo_key = ast.literal_eval(d_json.dumps(json_key))
resp = dynamo.update_item(
TableName = "CICDDeployment_Tracker",
Key = dynamo_key,
UpdateExpression = "SET currentstage = : val1, message = : val2 DELETE :val4",
ExpressionAttributeValues = dynamo_json
)
print resp
Error:
Invalid UpdateExpression: Syntax error; token: ":val4", near: "DELETE
:val4"
It should be REMOVE instead of DELETE, and REMOVE attributeName not the value
UpdateExpression = "SET currentstage = : val1, message = : val2 REMOVE newVersion",
I need a Classic ASP function that will take a string such as Jämshög and convert it to J\u00e4msh\u00f6gso that all the accented characters become their equivalent unicode escape codes.
I am sending this data in a JSON string to an API that requires all special characters to use unicode escape codes.
I've been searching for what seems like hours to come up with a solution and I haven't managed to come close. Any help would be greatly appreciated.
Take a look at the function from aspjson below. It also handles non-unicode characters that must to be escaped such as quote, tab, line-feed etc. Luckily no dependencies, so works stand-alone too.
Function jsEncode(str)
Dim charmap(127), haystack()
charmap(8) = "\b"
charmap(9) = "\t"
charmap(10) = "\n"
charmap(12) = "\f"
charmap(13) = "\r"
charmap(34) = "\"""
charmap(47) = "\/"
charmap(92) = "\\"
Dim strlen : strlen = Len(str) - 1
ReDim haystack(strlen)
Dim i, charcode
For i = 0 To strlen
haystack(i) = Mid(str, i + 1, 1)
charcode = AscW(haystack(i)) And 65535
If charcode < 127 Then
If Not IsEmpty(charmap(charcode)) Then
haystack(i) = charmap(charcode)
ElseIf charcode < 32 Then
haystack(i) = "\u" & Right("000" & Hex(charcode), 4)
End If
Else
haystack(i) = "\u" & Right("000" & Hex(charcode), 4)
End If
Next
jsEncode = Join(haystack, "")
End Function
I am working on the r panel package. Now if I have a function that uses a radiogroup button, and if i attempt to run the function from inside the rpanel menu, I get this error:
Error in panel$intname : $ operator is invalid for atomic vectors
However if I run the function per sé i.e. not from inside the rpanel menu, but by calling it independently, the above error doesn't appear. Here is a simple example. Try in 2 ways (1) run the whole code and click on Addition and then click Add in the menu (2) run the add function alone and call with add(). The former results in the above error and the latter doesn't. Also, i saw that this error comes only when i have a rp.radiogroup in my panel.
I saw the post in Why doesn't R allow $ operator on atomic vectors? but how do i solve my issue? My sample Code is below:
install.packages(c("rpanel","tkrplot"))
my.menu <- function(panel) {
library(rpanel,tkrplot)
if (panel$menu=="Add"){
add()
}
else
panel
}
main.panel <- rp.control(title = "Main Menu",size=c(200,150))
rp.menu(panel = main.panel, var = menu,
labels = list(list("Addition", "Add")),action = my.menu)
# function to do adddition
add <- function(){
my.draw <- function(panel) {
if(panel$vals=="numbers"){
val<-as.numeric(panel$nmbr1)+as.numeric(panel$nmbr2)
}
else if(panel$vals=="strings"){
val <- paste(as.character(panel$nmbr1), "and" ,as.character(panel$nmbr2))
}
plot(1:10, 1:10, type="n", xlab="", ylab="",
axes=FALSE, frame = TRUE)
text(5, 5, paste("Result: ", val),cex=1.4)
panel
}
my.redraw <- function(panel) {
rp.tkrreplot(panel, my.tkrplot)
panel
}
my.panel <- rp.control(title = "Addition")
rp.textentry(panel = my.panel, var = nmbr1,
labels = "First: ", action = my.redraw, initval="100")
rp.textentry(panel = my.panel, var = nmbr2,
labels = "Second:", action = my.redraw, initval="200")
rp.radiogroup(panel = my.panel, var = vals,
values = c("numbers", "strings"),
action = my.redraw, title = "Type")
rp.tkrplot(panel = my.panel, name = my.tkrplot, plotfun = my.draw)
}
You may simply escape using $: Change
panel$vals
to:
panel["vals"]