pythonstring value vs string in django orm - python-3.x

this is what I want
I made the parameter by str value.
because I have to get parameters by list variable.
but when I use str parameter in filter, wrong result is comming.
whole source is here.

In the first picture, you are providing a list of strings and in the second picture, you are providing string.
You can solve it by:
import json
fieldQueryString = json.loads(fieldQueryString)
this will convert this string into a list. So the output will change from
'["001", "002", "004", "005", "006"]' # this is a string
to
["001", "002", "004", "005", "006"] # this is a list
(notice the quotes before and after [ and ]).

Related

How do i get only the Json keys as a output from ADF lookup activity

This is my json which read via a lookup activity
{
"key1" : { "id" = "100" },
"key2" : "XYZ",
"key3" : [1,2,3]
}
I need a activity that gives me all the keys alone from above json
Lookup.output.firstrow.key2 gives me the string XYZ
What expression i can use to get all the keys alone
I really looking for some expression like Lookup.output.firstrow.getKeys() which returns array of keys such as
["key1", "key2", "key3"]
How do i get only the Json keys as a output from ADF lookup activity
There is no such direct way to achieve this you have to do it by setting the variables and string manipulation.
Follow below procedure:
I took json file in look up and its output is as follow:
To get all keys from above Json first I took set variable activity and created a demo string variable with value.
#substring(string(activity('Lookup1').output.value),2,sub(length(string(activity('Lookup1').output.value)),4))
here we are converting lookup output to string and removing braces from start and end.
Then I took another set variable activity and created a demo2 array variable with value.
#split(substring(string(split(variables('demo'),':')),2,sub(length(string(split(variables('demo'),':'))),4)),',')
Here we are splitting the string with : and ,
Then I created an array with default range of even numbers of values 0,2,4,6 etc.
Then Passed it to ForEach activity
Then Inside For Each activity I took append variable activity and gave value as
#variables('demo2')[item()]
Output:
Note: if your values contain : or , the above expression will also split those values. and if we split the values with : then I will split the string with : only and rest thing it will consider as single value. In below image the highlighted value it is taking as single value.

Add single quotes around string in python

I have converted list to string.
but after conversion I am getting string without single quote around the string
for eg:
items = ['aa','bb','cc']
items = ','.join(items)
output is : aa,bb,cc
expected output: 'aa','bb','cc'
You could use a list comprehension to quote the individual strings in the list:
items = ['aa','bb','cc']
items = ','.join([f"'{i}'" for i in items])
print(items) # 'aa','bb','cc'
One way to accomplish this is by passing the list into a string formatter, which will place the outer quotes around each list element. The list is mapped to the formatter, then joined, as you have shown.
For example:
','.join(map("'{}'".format, items))
Output:
"'aa','bb','cc'"

groovy iterate through list of key and value

I have this list:
service_name_status=[a-service=INSTALL, b-service=UPGRADE, C-service=UPGRADE, D-service=INSTALL]
And I need to iterate through this list so the first element will be the value of a parameter called "SERVICE_NAME" and the second element will be the value of a parameter called "HELM_COMMAND",
after asserting those values to the parameters I will run my command that uses those parameters and then continue the next items on the list which should replace the values of the parameters with items 3 and 4 and so on.
So what I am looking for is something like that:
def service_name_status=[a-service=INSTALL, b-service=UPGRADE, C-service=UPGRADE, D-service=INSTALL]
def SERVICE_NAME
def HELM_COMMAND
for(x in service_name_status){
SERVICE_NAME=x(0,2,4,6,8...)
HELM_COMMAND=x(1,3,5,7,9...)
println SERVICE_NAME=$SERVICE_NAME
println HELM_COMMAND=$HELM_COMMAND
}
the output should be:
SERVICE_NAME=a-service
HELM_COMMAND=INSTALL
SERVICE_NAME=b-service
HELM_COMMAND=UPGRADE
SERVICE_NAME=c-service
HELM_COMMAND=UPGRADE
SERVICE_NAME=d-service
HELM_COMMAND=INSTALL
and so on...
I couldn't find anything that takes any other element in groovy, any help will be appreciated.
The collection you want is a Map, not a List.
Take note of the quotes in the map, the values are strings so you need the quotes or it won't work. You may have to change that at the source where your data comes from.
I kept your all caps variable names so you will feel at home, but they are not the convention.
Note the list iteration with .each(key, value)
This will work:
Map service_name_status = ['a-service':'INSTALL', 'b-service':'UPGRADE', 'C-service':'UPGRADE', 'D-service':'INSTALL']
service_name_status.each {SERVICE_NAME, HELM_COMMAND ->
println "SERVICE_NAME=${SERVICE_NAME}"
println "HELM_COMMAND=${HELM_COMMAND}"
}
EDIT:
The following can be used to convert that to a map. Be careful, the replaceAll part is fragile and depends on the data to always look the same.
//assuming you can have it in a string like this
String st = "[a-service=INSTALL, b-service=UPGRADE, C-service=UPGRADE, D-service=INSTALL]"
//this part is dependent on format
String mpStr = st.replaceAll(/\[/, "['")
.replaceAll(/=/, "':'")
.replaceAll(/]/, "']")
.replaceAll(/, /, "', '")
println mpStr
//convert the properly formatted string to a map
Map mp = evaluate(mpStr)
assert mp instanceof java.util.LinkedHashMap

How can I convert a list to a string in Terraform?

join works BUT i want to keep the double quotes join gives me this
[ben,linda,john]
BUT i want this
["ben", "linda", "john"]
this is getting crazy, spent over 2 hours trying to fix this
i want to pass in a list as a string variable
why can't terraform just take in my list as a string? why is this so difficult?
so i have
name = ["ben", "linda", "john"]
and i want to pass this to variable used in terrform
var.name
why can't terrform take this as is?
i get the error saying epxtected a string and i can not find a solution online after sarching everywhere
i have been able to get
[ ben,linda,john ] using join(",", var.name) but i want ["ben", "linda", "john"]
$ terraform --version
Terraform v0.12.18
+ provider.aws v2.42.0
+ provider.template v2.1.2
Conversion from list to string always requires an explicit decision about how the result will be formatted: which character (if any) will delimit the individual items, which delimiters (if any) will mark each item, which markers will be included at the start and end (if any) to explicitly mark the result as a list.
The syntax example you showed looks like JSON. If that is your goal then the easiest answer is to use jsonencode to convert the list directly to JSON syntax:
jsonencode(var.names)
This function produces compact JSON, so the result would be the following:
["ben","linda","john"]
Terraform provides a ready-to-use function for JSON because its a common need. If you need more control over the above decisions then you'd need to use more complex techniques to describe to Terraform what you need. For example, to produce a string where each input string is in quotes, the items are separated by commas, and the entire result is delimited by [ and ] markers, there are three steps:
Transform the list to add the quotes: [for s in var.names : format("%q", s)]
Join that result using , as the delimiter: join(", ", [for s in var.names : format("%q", s)])
Add the leading and trailing markers: "[ ${join(",", [for s in var.names : format("%q", s)])} ]"
The above makes the same decisions as the JSON encoding of a list, so there's no real reason to do exactly what I've shown above, but I'm showing the individual steps here as an example so that those who want to produce a different list serialization have a starting point to work from.
For example, if the spaces after the commas were important then you could adjust the first argument to join in the above to include a space:
"[ ${join(", ", [for s in var.names : format("%q", s)])} ]"

Mongodb text search not working with string Flask

I am trying to make text search with Flask.
For one word it works, but when I pass a string with multiple words it doesn't work.
But when I pass that string as hardcoded it works:
Suppose that string is this:
str = "SOME TEXT HERE"
if I pass it as variable like this:
newText= ' '.join(r'\"'+word+r'\"' for word in str.split())
result = app.data.driver.db[endpoint].find({"$text":{"$search":newText }}, {"score": {"$meta":"textScore"}}).sort([("score", {"$meta": "textScore"})])
it doesn't work.
But if I pass it as hardcoded like this:
result = app.data.driver.db[endpoint].find({"$text":{"$search":" \"SOME\" \"TEXT\" \"HERE\" " }}, {"score": {"$meta":"textScore"}}).sort([("score", {"$meta": "textScore"})])
It works.
The contents of variable newText are different from the contents in your hardcoded string.
Try removing 'r' during creation of newText to generate a string similar to the hardcoded string, as follows:
newText= ' '.join('\"'+word+'\"' for word in str.split())

Resources