I have a list of cities which have been stripped of punctuation and i need to format the URL correctly. My lists are ['New', 'York', 'NY'] and ['Lansing', 'MI'] and i need to format the query so that parameter assignments are seperated by the (&) symbol and words in the city are separated by the (+) sign.
For example it should look something like www.url.com/origin=New+York+NY&destination=Lansing+MI
From the urllib docs:
Convert a mapping object or a sequence of two-element tuples to a “percent-encoded” string
So
urllib.parse.urlencode({
'origin' : ' '.join(['New', 'York', 'NY']),
'destination' : ' '.join(['Lansing', 'MI'])
})
yields
'origin=New+York+NY&destination=Lansing+MI'
That documentation references the obsolete RFC 2396, but the differences between RFC 3986 and 2396 do not affect query string composition.
Related
I have a column in string format like below:
["name": "XXX","active": true,"locale": "EN","Channel":["1","2"]]
I would like to explode them like below in spark sql(preserving the quotes in string values).
This is code I used:
SELECT EXPLODE(from_json(col, 'map<string, string>>'))
FROM XXX;
I am not able to preserve the quotes in "XXX" and "EN" after exploding.
This is what I want:
key
value
name
"XXX"
active
true
locale
"EN"
Channel
[1,2]
The quotes are part of the JSON representation of the data and not the data itself. If there were embedded quotes in the data it would look like:
"\"SOME DATA\""
If you need to add quotes on strings, you can always concatenate them to the specific columns. You can use the concat operator to accomplish this, https://spark.apache.org/docs/latest/api/sql/index.html#concat
Alternatively, you can use get_json_object, which allows you to extract specific parts of a JSON object. https://spark.apache.org/docs/3.1.2/api/python/reference/api/pyspark.sql.functions.get_json_object.html
I'm using sqlite3 and trying to get the oid by using the title of the row and then trying to use that oid to update a column in my table.
allOID is a tuple, and when I print it i get this:
>>> <class 'tuple'>
>>> [(1,)]
I'm trying to get the integer out of this tuple but the comma is throwing it off and I can't seem to get it.
Here is all of the code being used currently:
c.execute("""SELECT oid FROM books
WHERE title = :title""",
{
'title': title
})
allOID = c.fetchall()
print(type(allOID[0]))
print(allOID)
c.execute("SELECT * FROM books")
c.execute("""UPDATE books SET
rented = :rented
WHERE oid = :oid""",
{
'rented': rentedVar,
'oid': allOID[0]
})
any help and comments are greatly appreciated!
The comma just indicates that it is a tuple with a single element.
Access it using allOID[0][0].
allOID[0] gets you the tuple out of the list of results, going one level further with allOID[0][0] gets you the first element of the tuple.
For more info, see the docs:
Empty tuples are constructed by an empty pair of parentheses; a tuple with one item is constructed by following a value with a comma (it is not sufficient to enclose a single value in parentheses). Ugly, but effective.
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 ]).
I have a document item called Pathname which is Text List containing paths to databases. I need to create a view, with only specific documents, which contain a specific database path in Pathname item.
I have tried these statements but none has worked:
1.#isMember("Databasepath",Pathname)
2.#Contains(#Implode(Pathname);"Databasepath")
Thank You for any suggestion.
There is no need for the "implode" in your code.
If Pathname looks like this:
apps\database1.nsf; apps\database2.nsf; mail\mailfile1.nsf;
and you want to filter out all in "apps" path, then the formula would look like this:
#Contains( PathName; "apps\\" )
Don't forget to duplicate the backslashes, if you "hardcode" them, as they are escape characters.
But now think about a Pathname containing:
localapps\db1.nsf; apps\db2.nsf; local\apps\db3.nsf
Then the formula above would select ALL entries. In that case this formula would be better:
#Contains( "#" + PathName; "#apps\\" )
Or (if the given path is always at the beginning):
#Begins( PathName; "apps\\" )
If it's truly a text list (i.e., "Path1\Db1.nsf" : "Path2\Db2.nsf" : "Path3\Db3.nsf"), then you should just be able to use the equals operator because a comparison of a scalar to a list value returns true if the scalar matches any of the list values. This detail of the semantics of formula language actually makes a lot of uses of #Contains unnecessary!
I.e., it should be as simple as
SELECT Pathname = "Path1\\Db1.nsf";
or if Pathname is not already case normalized, then
SELECT #uppercase(Pathname) = "PATH1\\DB1.NSF";
i have a list lets call it as
List1
in List1 list i have fields like the following
List1
ID
Title
....
also i have List2 and its columns like the following
List2
ID
Title
Type
now i added a lookup field from List2 to List1 and now my List1 columns becomes
List1
ID
Title
List2
List2:Title
when i look at the List2:Title i see its internal name is List2_x003a_Title
i easily can understand that ':' is represented as x003a
ie the hex code of ':' is x003a
after than i deleted column and readded it. oooooo
what i see is that the field added with the same external name but this time its INTERNAL NAME
List2_x003A_Title
can someone explain the reason. when the hex code is x003a or x003A
SharePoint internal name creation policy: the name is encoded to a valid XML name according to the XML specification.
Any XML name character that does not conform to the XML 1.0 spec (fourth edition) recommendation is escaped as _xHHHH_. The HHHH string stands for the four-digit hexadecimal UCS-2 code for the character in most significant bit first order. For example, the name Order Details is encoded as Order_x0020_Details.
.NET Framework contains XmlConvert.EncodeName Method that converts the name to a valid XML name. This method guarantees the name is valid according to the XML specification.
Example:
var fieldName = XmlConvert.EncodeName("Order Details"); //returns Order_x0020_Details