Reputation: 1913
I am getting the FixVersion value for each my JIRA issue in below format from the below code and then I am trying to append the value using append method in python but not getting the desired results
for version in issue["fields"]["fixVersions"]:
cacheData = json.dumps(version)
jsonToPython = json.loads(cacheData)
#lines = jsonToPython.items()
if jsonToPython['name'][:8] == "Clignra ":
Fixversionmatch = re.findall(r"(\d+\.\d+)\.\d+\.\d+", jsonToPython['name'])
match = Fixversionmatch[0]
print match
for i in range(match):
allModules.append(i)
print allModules
from the above code I get the below error
for i in range(match):
TypeError: range() integer end argument expected, got unicode.
If I remove the below code and just do print match
for i in range(match):
allModules.append(i)
print allModules
then I get the below output after remove and get no unicode:
Processing TTPT-2
1.4
2.4
2.5
Processing TTPT-1
2.4
The output which I am trying to achieve is below
Processing TTPT-2
[1.4, 1.4, 1.5]
Processing TTPT-1
[1.4]
Upvotes: 0
Views: 61
Reputation: 25799
As I said in the comment, the error you're experiencing is due to the fact that re.findall()
returns a list of strings while range()
expects integer arguments. However, to get what you're trying to achieve you'd want to turn your capture into a list, something like:
fix_versions = []
for version in issue["fields"]["fixVersions"]:
cacheData = json.dumps(version)
jsonToPython = json.loads(cacheData)
if jsonToPython['name'][:8] == "Clignra ":
version_match = re.findall(r"(\d+\.\d+)\.\d+\.\d+", jsonToPython['name'])
if version_match:
fix_versions.append(version_match[0])
print(fix_versions)
Based on your question, this should print: ['4.4', '4.4', '4.5']
(and so on, for the next module...) If you want them as pure floats, you can do the conversion when appending to the fix_versions
list: fix_versions.append(float(version_match[0]))
Also, any particular reason why are you doing:
cacheData = json.dumps(version)
jsonToPython = json.loads(cacheData)
? This should result in an equal structure so you can completely omit it and perform your match on the version
directly, i.e.:
fix_versions = []
for version in issue["fields"]["fixVersions"]:
if version['name'][:8] == "Clignra ":
version_match = re.findall(r"(\d+\.\d+)\.\d+\.\d+", version['name'])
if version_match:
fix_versions.append(version_match[0])
print(fix_versions) # `['4.4', '4.4', '4.5']` etc. or similar
# or:
print("[{}]".format(", ".join(fix_versions))) # `[4.4, 4.4, 4.5]` etc.
Upvotes: 1