Skip to content

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions PyBank/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Copy link
Author

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:

sys.exit(1)
csvRecords = []

Expand All @@ -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

Expand Down Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function writeResult refactored with the following changes:

This removes the following comments ( why? ):

# print(f"averageChangePnL {averageChangePnL}")
# Create the Analysis Text

fileText += "------------------------------------\n"
fileText += f"Total Months: {totalMonths}\n"
fileText += f"Total: {totalPnL:.2f}\n"
Expand All @@ -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
Expand Down
16 changes: 7 additions & 9 deletions PyPoll/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Copy link
Author

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:

sys.exit(1)

# Read the file into an Election Dictionary and total the votes
Expand All @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function writeResult refactored with the following changes:

This removes the following comments ( why? ):

# Initialize Variables

fileText += "-------------------------\n"
fileText += f"Total Votes: {totalVotes}\n"
fileText += "-------------------------\n"
Expand All @@ -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
Expand Down