Re: [Tutor] Python 3: string to decimal conversion

2016-05-24 Thread Peter Otten
c...@zip.com.au wrote: > On 23May2016 12:18, Saidov wrote: >>Thanks everyone for all your help. This solved my problem with >>parenthesis and $ signs in the data: >> >>if not row[4]: >>pass >>else: >>try: >>expenses[t

Re: [Tutor] Python 3: string to decimal conversion

2016-05-23 Thread cs
On 23May2016 12:18, Saidov wrote: Thanks everyone for all your help. This solved my problem with parenthesis and $ signs in the data: if not row[4]: pass else: try: expenses[ts.Date(row[0]).month] += decimal.Decimal(row

Re: [Tutor] Python 3: string to decimal conversion

2016-05-23 Thread US
Thanks everyone for all your help. This solved my problem with parenthesis and $ signs in the data: if not row[4]: pass else: try: expenses[ts.Date(row[0]).month] += decimal.Decimal(row[4].strip('()$ ,').replace(',',''

Re: [Tutor] Python 3: string to decimal conversion

2016-05-23 Thread Peter Otten
US wrote: > Thank you both for suggesting a way to handle errors. I have run the > suggested code. What I learned is that all the values (not only empty > cells) seem to be invalid for decimal.Decimal function. > > I tried the float() function instead of decimal.Decimal and got an > error message

Re: [Tutor] Python 3: string to decimal conversion

2016-05-23 Thread Alan Gauld via Tutor
On 23/05/16 02:45, US wrote: > I tried the float() function instead of decimal.Decimal and got an > error message: could not convert string to float: '($75.59)'. The problem is that the functions don;t recognize the parens as a negative sign. You will need to convert them yourself. I suggest you

Re: [Tutor] Python 3: string to decimal conversion

2016-05-23 Thread US
On Sun, May 22, 2016 at 5:36 PM, wrote: > On 22May2016 08:19, Saidov wrote: >> >> Thank you all for the useful feedback. I am new to programming so bear >> with me while I learn the rules... >> >> I have run Cameron's code to print the values and have the traceback >> results. please see below.

Re: [Tutor] Python 3: string to decimal conversion

2016-05-22 Thread cs
On 22May2016 08:19, Saidov wrote: Thank you all for the useful feedback. I am new to programming so bear with me while I learn the rules... I have run Cameron's code to print the values and have the traceback results. please see below. [...] for row in records: [...]

Re: [Tutor] Python 3: string to decimal conversion

2016-05-22 Thread Alan Gauld via Tutor
On 22/05/16 14:19, US wrote: >>with open(file) as csvfile: >>records = csv.reader(csvfile, quoting=csv.QUOTE_NONE) > [...] >>for row in records: > [...] >>try: >>expenses[ts.Date(row[0]).month] += > decimal.Decimal(row[4]) >>

Re: [Tutor] Python 3: string to decimal conversion

2016-05-22 Thread US
urday, May 21, 2016 10:32 PM To: Saidov Cc: tutor@python.org Subject: Re: [Tutor] Python 3: string to decimal conversion Hi Saidov, I'm going to reply to your post inline, as that is the etiquette here and in many technical mailing lists. On 21May2016 13:34, Saidov wrote: >I am working

Re: [Tutor] Python 3: string to decimal conversion

2016-05-22 Thread Steven D'Aprano
On Sat, May 21, 2016 at 01:34:20PM -0500, Saidov wrote: > "decimal.InvalidOperation was unhandled by user code > Message: []" > > *Question: *I tried looking up the meaning of this error, but couldn't find > anything on the internet. *Can someone help me understand what's wrong with > my code?*

Re: [Tutor] Python 3: string to decimal conversion

2016-05-21 Thread cs
Hi Saidov, I'm going to reply to your post inline, as that is the etiquette here and in many technical mailing lists. On 21May2016 13:34, Saidov wrote: I am working on a piece of python code that's supposed to help me manage a budget: 1. Read a banking statement 2. Categorize expenses and in

Re: [Tutor] Python 3: string to decimal conversion

2016-05-21 Thread Ben Finney
Saidov writes: > *Python Version: 3.5 (64 bit)* > IDE:Microsoft Visual Studio Community 2015 Your IDE is apparently suppressing, or hiding somewhere, the full traceback of the exception. It's important that you always have that in front of you when trying to diagnose an un-handled exception. >

[Tutor] Python 3: string to decimal conversion

2016-05-21 Thread Saidov
Hello all, I am working on a piece of python code that's supposed to help me manage a budget: 1. Read a banking statement 2. Categorize expenses and income by month and by type 3. Print out a report comparing the projected expenses/income with actual numbers. *File characteristics:* Banking stat