libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ann Paul (JIRA)" <>
Subject [jira] [Created] (LIBCLOUD-763) Making str2dicts util function more pythonic and simpler.
Date Sun, 25 Oct 2015 06:30:27 GMT
Ann Paul created LIBCLOUD-763:

             Summary: Making str2dicts util function more pythonic and simpler.
                 Key: LIBCLOUD-763
             Project: Libcloud
          Issue Type: Improvement
          Components: Libcloud REST
    Affects Versions: 0.13.3
            Reporter: Ann Paul
            Priority: Minor

With reference to the *str2dicts* function here

Two suggestions: 
* I personally think the "\n\n" is not being taken advantage of.
* Initializing a list and appending a list with empty dict ({}) is not necessary and can be
removed. This will allow to remove negative indexing on the list as well.

My thoughts are to change it to look like so:
def str2dicts(data):
   if data is not None and data != "":
        data_blocks = data.split("\n\n")
        line_list = [line.rstrip("\n").lstrip("\n").split("\n") for line in data_blocks]
        return [dict(key_value_string.split(" ") for key_value_string in line) for line in
    return [{}]

Let me know your thoughts on this and when it looks good, i'd be happy to open a pull request
for with this change.

This message was sent by Atlassian JIRA

View raw message