-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored main branch #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ def parseCSV(csvFile): | |
try: | ||
reader = csv.reader(open(csvFile)) | ||
except IOError: | ||
print("Error, could not open CSV File: " + csvFile) | ||
print(f"Error, could not open CSV File: {csvFile}") | ||
sys.exit(1) | ||
csvRecords = [] | ||
|
||
|
@@ -43,8 +43,9 @@ def parseCSV(csvFile): | |
csvRecords.append(rec) | ||
|
||
except csv.Error as e: | ||
sys.exit('Error reading CSV File: ' + csvFile + " line number " + | ||
str(line) + " error: " + str(e)) | ||
sys.exit( | ||
f'Error reading CSV File: {csvFile} line number {str(line)} error: {str(e)}' | ||
) | ||
# Return the results | ||
return csvRecords | ||
|
||
|
@@ -101,11 +102,7 @@ def writeResult(trackingDict, outputFile): | |
greatestDec_val = currentChange | ||
# print(f"netChangePnL {netChangePnL} totalMonths {totalMonths}") | ||
averageChangePnL = netChangePnL/(totalMonths-1) | ||
# print(f"averageChangePnL {averageChangePnL}") | ||
|
||
# Create the Analysis Text | ||
fileText = "" | ||
fileText += "Financial Analysis\n" | ||
fileText = "" + "Financial Analysis\n" | ||
Comment on lines
-104
to
+105
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
This removes the following comments ( why? ):
|
||
fileText += "------------------------------------\n" | ||
fileText += f"Total Months: {totalMonths}\n" | ||
fileText += f"Total: {totalPnL:.2f}\n" | ||
|
@@ -115,9 +112,8 @@ def writeResult(trackingDict, outputFile): | |
|
||
# Write the Analysis out | ||
print(fileText) | ||
fh = open(outputFile, "w") | ||
fh.write(fileText) | ||
fh.close() | ||
with open(outputFile, "w") as fh: | ||
fh.write(fileText) | ||
|
||
############################################################################### | ||
# Main | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ def parseCSV(csvFile): | |
try: | ||
reader = csv.reader(open(csvFile)) | ||
except IOError: | ||
print("Error, could not open CSV File: " + csvFile) | ||
print(f"Error, could not open CSV File: {csvFile}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
sys.exit(1) | ||
|
||
# Read the file into an Election Dictionary and total the votes | ||
|
@@ -49,18 +49,17 @@ def parseCSV(csvFile): | |
elctionDict[colCandidate] += 1 | ||
|
||
except csv.Error as e: | ||
sys.exit('Error reading CSV File: ' + csvFile + " line number " + | ||
str(line) + " error: " + str(e)) | ||
sys.exit( | ||
f'Error reading CSV File: {csvFile} line number {str(line)} error: {str(e)}' | ||
) | ||
# Return the results | ||
return totalVotes, elctionDict | ||
|
||
############################################################################### | ||
# Tally the results and write them out | ||
############################################################################### | ||
def writeResult(totalVotes, elctionDict, outputFile): | ||
# Initialize Variables | ||
fileText = "" | ||
fileText += "Election Results\n" | ||
fileText = "" + "Election Results\n" | ||
Comment on lines
-61
to
+62
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
This removes the following comments ( why? ):
|
||
fileText += "-------------------------\n" | ||
fileText += f"Total Votes: {totalVotes}\n" | ||
fileText += "-------------------------\n" | ||
|
@@ -79,9 +78,8 @@ def writeResult(totalVotes, elctionDict, outputFile): | |
|
||
# Write the Analysis out | ||
print(fileText) | ||
fh = open(outputFile, "w") | ||
fh.write(fileText) | ||
fh.close() | ||
with open(outputFile, "w") as fh: | ||
fh.write(fileText) | ||
|
||
############################################################################### | ||
# Main | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
parseCSV
refactored with the following changes:use-fstring-for-concatenation
)