strings.py
Others:
This definition encodes given data to unicode using package default settings.
Usage:
>>> encode("myData")
u'myData'
>>> encode("汉字/漢字")
u'\u6c49\u5b57/\u6f22\u5b57'
Parameters: | data – Data to encode. ( String ) |
---|---|
Returns: | Encoded data. ( Unicode ) |
This definition converts a string to nice string: currentLogText -> Current Log Text.
Usage:
>>> getNiceName("getMeANiceName")
'Get Me A Nice Name'
>>> getNiceName("__getMeANiceName")
'__Get Me A Nice Name'
Parameters: | name – Current string to be nicified. ( String ) |
---|---|
Returns: | Nicified string. ( String ) |
This definition converts a version string to it’s rank.
Usage:
>>> getVersionRank("4.2.8")
428
>>> getVersionRank("4.2.8").__class__
<type 'int'>
Parameters: | version – Current version to calculate rank. ( String ) |
---|---|
Returns: | Rank. ( Integer ) |
This definition gets the basename of a path without its extension.
Usage:
>>> getSplitextBasename("/Users/JohnDoe/Documents/Test.txt")
'Test'
Parameters: | path – Path to extract the basename without extension. ( String ) |
---|---|
Returns: | Splitext basename. ( String ) |
This definition gets common ancestor of given iterables.
Usage:
>>> getCommonAncestor(("1", "2", "3"), ("1", "2", "0"), ("1", "2", "3", "4"))
('1', '2')
>>> getCommonAncestor("azerty", "azetty", "azello")
'aze'
Parameters: | *args – Iterables to retrieve common ancestor from. ( Iterables ) |
---|---|
Returns: | Common ancestor. ( Iterable ) |
This definition gets common paths ancestor of given paths.
Usage:
>>> getCommonPathsAncestor("/Users/JohnDoe/Documents", "/Users/JohnDoe/Documents/Test.txt")
'/Users/JohnDoe/Documents'
Parameters: | *args – Paths to retrieve common ancestor from. ( Strings ) |
---|---|
Returns: | Common path ancestor. ( String ) |
This method extracts the words from given string.
Usage:
>>> getWords("Users are: John Doe, Jane Doe, Z6PO.")
['Users', 'are', 'John', 'Doe', 'Jane', 'Doe', 'Z6PO']
Parameters: | data – Data to extract words from. ( String ) |
---|---|
Returns: | Words. ( List ) |
This method filters the words using the given filters.
Usage:
>>> filterWords(["Users", "are", "John", "Doe", "Jane", "Doe", "Z6PO"], filtersIn=("John", "Doe"))
['John', 'Doe', 'Doe']
>>> filterWords(["Users", "are", "John", "Doe", "Jane", "Doe", "Z6PO"], filtersIn=("\w*r",))
['Users', 'are']
>>> filterWords(["Users", "are", "John", "Doe", "Jane", "Doe", "Z6PO"], filtersOut=("\w*o",))
['Users', 'are', 'Jane', 'Z6PO']
Parameters: |
|
---|---|
Returns: | Filtered words. ( List ) |
This definition replaces the data occurences in the string.
Usage:
>>> replace("Users are: John Doe, Jane Doe, Z6PO.", {"John" : "Luke", "Jane" : "Anakin", "Doe" : "Skywalker",
"Z6PO" : "R2D2"})
'Users are: Luke Skywalker, Anakin Skywalker, R2D2.'
Parameters: |
|
---|---|
Returns: | Manipulated string. ( String ) |
This definition removes the pattern occurences in the string and strip the result.
Usage:
>>> replaceStrip("John Doe", "John")
'Doe'
Parameters: |
|
---|---|
Returns: | Manipulated string. ( String ) |
This definition converts backward slashes to forward slashes.
Usage:
>>> toForwardSlashes("To\Forward\Slashes")
'To/Forward/Slashes'
Parameters: | data – Data to convert. ( String ) |
---|---|
Returns: | Converted path. ( String ) |
This definition converts forward slashes to backward slashes.
Usage:
>>> toBackwardSlashes("/Users/JohnDoe/Documents")
'\Users\JohnDoe\Documents'
Parameters: | data – Data to convert. ( String ) |
---|---|
Returns: | Converted path. ( String ) |
This definition converts Windows path to Posix path while stripping drives letters and network server slashes.
Usage:
>>> toPosixPath("c:\Users\JohnDoe\Documents")
'/Users/JohnDoe/Documents'
Parameters: | path – Windows path. ( String ) |
---|---|
Returns: | Path converted to Posix path. ( String ) |
This definition normalizes a path, escaping slashes if needed on Windows.
Usage:
>>> getNormalizedPath("C:\Users\JohnDoe\Documents")
'C:\Users\JohnDoe\Documents'
Parameters: | path – Path to normalize. ( String ) |
---|---|
Returns: | Normalized path. ( String ) |
This definition returns a random sequence.
Usage:
>>> getRandomSequence()
arGAqzf3
Parameters: | length – Length of the sequence. ( Integer ) |
---|---|
Returns: | Random sequence. ( String ) |