Re: [Tutor] C++ or Python?

2018-07-04 Thread Mark Lawrence

On 03/07/18 17:30, Carlton Banks wrote:

tir. 3. jul. 2018 18.25 skrev Bellamy Baron :


Hi,

I have heard C++ is faster than python and I have a few questions
1.Is there a way to make python run just as fast


Look Up cpython might be a bit faster



Really, or did you mean cython? :)

--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Need all values from while loop - only receiving one

2018-07-04 Thread Daryl Heppner
Hi Alan,

Extremely valuable guidance - thank you!  I will be adapting my script
once I get to the office but at a first glance, this appears to be
exactly what we need!  I'll confirm once I've had a chance to
implement this.

If you have any suggestions for continued self-learning (books,
courses, etc.) I'd appreciate any tips.

A bit of context, in case you're curious - we're parsing the XML for
load into a T SQL database for reporting purposes which is why I've
parsed each value to a unique "cell".  The print statement is merely a
QA step before ultimately making use of the pyodbc method.

For our Base Rent table, the final Python statement reads as:

x.execute("Insert into dealbaserents (dealid, dtermid, brentid, \
brbegin, brentamt, brentperiod, brentdur) values \
(?, ?, ?, ?, ?, ?, ?)", \
(dealid, dtid, brid, begmo, brentamt, brper, duration))
con.commit()

The need to extrapolate the full rent schedule is to address a few
reporting needs.  Free Rent, where applicable, is not expressed as a
dollar value with a specific date.  Rather, it is described as a
percentage of Base Rent with a reference to the month in which it
applies.  A lease can have multiple Free Rent periods which may or may
not be consecutive and there are several examples where a Free Rent is
applied in the 2nd month and again in the 14th month which means that
the dollar value of the Free Rent could be different if a rent step
occurs at the end of the first year.

We will also be calculating Net Present Value which will be much
easier to deal with using normalized data.  There are four scenarios
for calculating base rent - per square foot per month, per square foot
per year, monthly amount and annual amount.

Regards,

Daryl


On Tue, Jul 3, 2018 at 8:16 PM Alan Gauld via Tutor  wrote:
>
> On 04/07/18 01:08, Alan Gauld via Tutor wrote:
>
> > # Now the main code just needs the outer loops:
> > tree = ET.parse(r'\\DealData.xml')
> > root = tree.getroot()
> > deals = []
> > for deal in root.findall("Deals"):
> > for dl in deal.findall("Deal"):
> > deals.append( Deal(dl) )
> >
> > if dl.id == "706880":
> >print(dl)  #uses __str__() to create string
>
> Sorry, that last loop should be like this:
>
>  for xml_dl in deal.findall("Deal"):
>  theDeal = Deal(xml_dl)
>  deals.append( theDeal )
>
>  if theDeal.id == "706880":
> print(theDeal)  #uses __str__() to create string
>
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] C++ or Python?

2018-07-04 Thread Carlton Banks
Yes i meant cython.. can see that my phone autocorrects to cpython for some
reason..

ons. 4. jul. 2018 10.33 skrev Mark Lawrence :

> On 03/07/18 17:30, Carlton Banks wrote:
> > tir. 3. jul. 2018 18.25 skrev Bellamy Baron :
> >
> >> Hi,
> >>
> >> I have heard C++ is faster than python and I have a few questions
> >> 1.Is there a way to make python run just as fast
> >>
> > Look Up cpython might be a bit faster
> >
>
> Really, or did you mean cython? :)
>
> --
> My fellow Pythonistas, ask not what our language can do for you, ask
> what you can do for our language.
>
> Mark Lawrence
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Need all values from while loop - only receiving one

2018-07-04 Thread Alan Gauld via Tutor
On 04/07/18 12:08, Daryl Heppner wrote:

> If you have any suggestions for continued self-learning (books,
> courses, etc.) I'd appreciate any tips.

So far as OOP goes you can't go far wrong with the latest version
of Grady Booch's OOAD book. I've read both the previous versions
and the latest update is the best yet.

> A bit of context, in case you're curious - we're parsing the XML for
> load into a T SQL database for reporting purposes which is why I've
> parsed each value to a unique "cell".  The print statement is merely a
> QA step before ultimately making use of the pyodbc method.

I guessed as much.

As for the database inserts I'd consider making them part of the
class init method, so once you create the new class instance
it automatically saves itself (or updates if the ID already
exists?)

> The need to extrapolate the full rent schedule is to address a few
> reporting needs.  Free Rent, where applicable, is not expressed as a
> dollar value with a specific date.  Rather, it is described as a
> percentage of Base Rent with a reference to the month in which it
> applies.  A lease can have multiple Free Rent periods which may or may
> not be consecutive and there are several examples where a Free Rent is
> applied in the 2nd month and again in the 14th month which means that
> the dollar value of the Free Rent could be different if a rent step
> occurs at the end of the first year.

Put the calculations as methods into the corresponding classes.
If necessary break them up so each class does only its own bit
of the calculation. Remember the adage that "objects do things to
themselves". If an object owns a piece of data it should be the
thing that operates (including doing calculations) on that data.
Calculations are operations on objects not objects in their
own right. (Unless you are building a calculation framework,
like Matlab say...)

One of the most common OOP anti-patterns is having some kind of
calculator object that fetches data from all the surrounding
objects, does a complex calculation then stores the result
into some other object.

Instead the calculation should commence in the target object and it
should ask each of the supplier objects to do their own bits only
returning to the target the end result of their subcalculation.
The target object should, in turn, only be performing calculations
on the results returned plus the data actually stored in the
target itself. Of course it is not always that clean but if
the object data is partitioned well it should be pretty close.

But it takes most non-OOP programmers a little time to turn their
thinking inside out like that. So don't sweat if it feels
unnatural to start with.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor