Re: [Tutor] Question About Image Processing in Python

2015-05-28 Thread Todd
On Thu, May 28, 2015 at 1:05 PM, Terry Reedy  wrote:

> On 5/28/2015 6:34 AM, Serge Christian Ibala wrote:
>
>
>  I want to use the following package
>>
>> “numpy, matplotib, mahotas, ipython   OpenCV and SciPy"
>>
>
> opencv seems to be the only one not available for 3.x.
>
>
OpenCV 3 (which is in RC1 now) supports Python 3.x.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] a puzzle about -3**2 vs (-3)**2

2015-07-31 Thread Todd
On Fri, Jul 31, 2015 at 2:58 AM, D Wyatt  wrote:

> I just read in a book a little while ago that ** trumps a negative
> sign?  I am struggling with the audacity of that as -1 is negative 1,
> NOT minus 1.  How can an arithmetic operation trump an attribute of a
> negative integer?  It truly makes no sense to me.  Thank you for any
> enlightenment you can provide.
>
> Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:43:06) [MSC v.1600 32
> bit (In
> tel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
> >>> 3**2
> 9
> >>> (-3)**2
> 9
> >>> -3**2
> -9
> >>>
>
>
It is a matter of operator precedence.  Certain operators are carried out
before others.  See here:
https://docs.python.org/3/reference/expressions.html#operator-precedence

Negation has lower precedence than exponentiation.  That means that the
exponentiation is carried out first, and negation is carried out second.
So "-3**2" is equivalent to "-(3**2)".

This matches the precedence rules for written mathematics, where negation
has a lower precedence than exponentiation as well.  So python is doing the
correct thing here mathematically.  See, for example,
http://mathforum.org/library/drmath/view/53194.html
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] subprocess.Popen basics

2014-10-28 Thread Todd
Centos has SELinux enabled by default.  I dont know if SELinux is causing
your problem, but it is always worth looking at.

SELinux can keep a process from accessing files or executing another
process.

Try temporarily disabling  SELinux by running setenforce=0 as root.  Then
see if python does what you expect.



On Tue, Oct 28, 2014 at 3:04 PM, Alan Gauld 
wrote:

> On 28/10/14 19:23, Adam Jensen wrote:
>
>  platform. This is what I've discovered so far:
>>
>> | | CentOS-6.5   | OpenBSD-5.5  | DragonFly-3.8.2 |
>> | bufsize | Python-3.4.1 | Python-3.3.2 | Python-3.3.3|
>> |-+--+--+-|
>> | default | hangs| works| works   |
>> | -1  | hangs| works| works   |
>> | 0   | works| works| works   |
>> | 1   | hangs| works| works   |
>> | >=2 & <(# of bytes) | works| works| works   |
>> | >=(# of bytes)  | hangs| works| works   |
>>
>>
> Looks like you might be best trying this on a CentOS forum/list.
> Its not exactly a mainstream distro so the number of folks on this list
> who can help is probably limited and even on the main Python list there
> probably are only a handful of CentOS users. And it looks increasingly like
> a CentOS configuration issue.
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> 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] [SPAM]Re: O'Reilly is offering Learning Python (4th ed.), eBook form for USD 9.99

2010-08-11 Thread Todd Nannie
If you click on the ONE DAY DEAL on the front page it still list the Python
book and several others.
I just bought the python book for 9.99

Todd

-Original Message-
From: tutor-bounces+tnannie=strdetail@python.org
[mailto:tutor-bounces+tnannie=strdetail@python.org] On Behalf Of
Benjamin Castillo
Sent: Wednesday, August 11, 2010 8:30 AM
To: tutor@python.org; Richard D. Moores
Subject: [SPAM]Re: [Tutor] O'Reilly is offering Learning Python (4th
ed.),eBook form for USD 9.99

The site shows 39.99 for ebook.

Ben


--- On Wed, 8/11/10, Richard D. Moores  wrote:

> From: Richard D. Moores 
> Subject: [Tutor] O'Reilly is offering Learning Python (4th ed.), eBook
form for USD  9.99
> To: tutor@python.org
> Date: Wednesday, August 11, 2010, 1:45 AM
> I already own the PDF, as well as the
> paperback (1160 pages), but I
> thought I'd let the list know. See the deal, good for just
> today, on
> <http://oreilly.com/store/index.html>.
> 
> The 4th edition covers both Python 2.6 and 3.x.
> 
> So what does "today" mean? Beats me. O'Reilly's corporate
> headquarters
> are in California, but there are also O'Reilly offices in
> Massachusetts, Japan, China, Taiwan, Germany, and the UK.
> <http://oreilly.com/contact.html>
> 
> Dick Moores
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
> 


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

No virus found in this incoming message.
Checked by AVG - www.avg.com 
Version: 9.0.851 / Virus Database: 271.1.1/3060 - Release Date: 08/11/10
01:34:00

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


[Tutor] list index out of range

2010-09-12 Thread Todd Ballard
I am attempting to have a cummalative total of the y values and receive a "list 
index out of range" error message

import numpy
import matplotlib.pyplot as plt

import filereader
from filereader import *

My_Path="C:\\Python26\\assignment2\\datadownload.txt"
My_Data_Type=numpy.dtype([("year","int32"),("day","int32"),("MJ","float64")])
daily_solar_radiation=read_array(My_Path,My_Data_Type,separator=None)

y=[]
for i in xrange(0,365):
y+=[daily_solar_radiation["MJ"][i]]

x=[]
for i in xrange(0,365):
x+=[daily_solar_radiation["day"][i]]

plt.plot(x,y)
plt.title('Daily Radiation')
plt.xlabel('day of the year')
plt.ylabel('MJ/m**2')
plt.show()
plt.savefig('plot1.png')

from filereader import *

My_Path="C:\\Python26\\assignment2\\datadownload.txt"
My_Data_Type=numpy.dtype([("year","int32"),("day","int32"),("MJ","float64")])
daily_solar_radiation=read_array(My_Path,My_Data_Type,skip=91,separator=None)

y=[daily_solar_radiation["MJ"][0]]
for i in xrange(0,275):
y=[daily_solar_radiation["MJ"]][i]+y[i-1]

for i in xrange(0,275):
x+=[daily_solar_radiation["day"][i]]

plt.plot(x,y)
plt.title('Daily Radiation')
plt.xlabel('day of the year')
plt.ylabel('MJ/m**2')
plt.show()
plt.savefig('plot2.png')

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


Re: [Tutor] Please use plain text.

2009-04-06 Thread Todd Zullinger
bob gailer wrote:
> Please use plain text rather than formatted text.

Was sending this request in an html formatted message intentional?  I
don't know about most folks, but I consider plain text to mean a
content-type of text/plain rather than text/html. :)

-- 
ToddOpenPGP -> KeyID: 0xBEAF0CE3 | URL: www.pobox.com/~tmz/pgp
~~
Unquestionably, there is progress.  The average American now pays out
twice as much in taxes as he formerly got in wages.
-- H. L. Mencken



pgp9BfRGlPxyw.pgp
Description: PGP signature
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Please use plain text.

2009-04-07 Thread Todd Zullinger
bob gailer wrote:
> Thanks for the request for clarification. By plain text I mean:
>
> one font and one size that is "readable". Most of the emails I
> receive appear the same in font and size, so whatever that is I
> like.

What's readable to you may not be readable to the next person though.
Most likely is that many of the posters here are not sending HTML
formatted mail, and thus their messages don't contain any font or size
information.  That's left up to your mail client and it will use
whatever defaults you have chosen.

> Use of very small or very large font sizes or various fonts / colors
> makes it hard for me to read.
>
> As I compose this in Thunderbird I see Body Text and Variable Width.
> But I do appreciate code in Fixed Width.

I believe the best answer to this issue is to not send HTML formatted
mail at all.  A truly plain text email contains no markup telling
anyone's email client what fonts to use.  That is something that
rightly belongs to each user, IMO.  Most of the mailing lists I
subscribe to frown upon HTML mail.

I don't worry about it a lot though, as I use a console based email
tool and any HTML messages that are sent are simply dumped as text for
me to read.  (I know many others that direct all HTML mail to
/dev/null.)

-- 
ToddOpenPGP -> KeyID: 0xBEAF0CE3 | URL: www.pobox.com/~tmz/pgp
~~
I am not young enough to know everything.
-- Oscar Wilde (1854-1900)



pgprvwdmxDxfU.pgp
Description: PGP signature
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] While and for loops

2009-07-13 Thread Todd Matsumoto
Hello,

The other day I was playing with a while loop with a for loop nested inside.

Within the for loop I had a condition to break the loop, but when loop ran it 
never existed the loop. I went back and looked in Programming Python to read 
about loops and I've got two questions (related to each other).

Can you run for loops in while loops and if yes, why did my if condition not 
break the loop?

I read that loops sort of have an order of precedence, does that have anything 
to do with this problem?

while True:

for i in items:
if i > 10:
break
else:



-- 
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] assigning list to keys

2009-07-14 Thread Todd Matsumoto
Hello,

The other day I needed to pack a dictionary, the value of each key was a list. 
In the code I was packing the list and the dictionary at the same time. First I 
tried something like this:

list = []
dict = {}
x = 1

dict['int'] = list.append(x)

The result was {'int': None}. Why is the value None?

Cheers,

T
-- 
Neu: GMX Doppel-FLAT mit Internet-Flatrate + Telefon-Flatrate
für nur 19,99 Euro/mtl.!* http://portal.gmx.net/de/go/dsl02
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] While and for loops

2009-07-14 Thread Todd Matsumoto
Okay,

So how would you break out from this situation?

T
 Original-Nachricht 
> Datum: Tue, 14 Jul 2009 06:57:41 +
> Von: sli1...@yahoo.com
> An: "Todd Matsumoto" 
> Betreff: Re: [Tutor] While and for loops

> Your break is for the for loop not the while. The condition true never
> goes false so your in a infinite loop
> Sent from my Verizon Wireless BlackBerry
> 
> -----Original Message-
> From: "Todd Matsumoto" 
> 
> Date: Tue, 14 Jul 2009 08:49:59 
> To: 
> Subject: [Tutor] While and for loops
> 
> 
> Hello,
> 
> The other day I was playing with a while loop with a for loop nested
> inside.
> 
> Within the for loop I had a condition to break the loop, but when loop ran
> it never existed the loop. I went back and looked in Programming Python to
> read about loops and I've got two questions (related to each other).
> 
> Can you run for loops in while loops and if yes, why did my if condition
> not break the loop?
> 
> I read that loops sort of have an order of precedence, does that have
> anything to do with this problem?
> 
> while True:
> 
> for i in items:
> if i > 10:
> break
> else:
> 
> 
> 
> -- 
> GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
> Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

-- 
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] While and for loops

2009-07-14 Thread Todd Matsumoto
Okay,

I'm not sure if this is good practice, but I could assign a variable within the 
while loop, that is assigned something that will then break the outer loop.

while True:
breakout = True

for i in items:
if i > 10:
breakout = False
else:

if break is False:
break

Is the above do-able? Is there a better way?

T
 Original-Nachricht 
> Datum: Tue, 14 Jul 2009 00:05:30 -0700
> Von: wesley chun 
> An: Todd Matsumoto 
> CC: tutor@python.org
> Betreff: Re: [Tutor] While and for loops

> > Can you run for loops in while loops and if yes, why did my if condition
> not break the loop?
> >
> > I read that loops sort of have an order of precedence, does that have
> anything to do with this problem?
> 
> 
> todd,
> 
> welcome to Python! you're right in that your questions are related to
> each other because the answer to both of your questions is the same:
> you can only break out of the innermost loop (from where you have your
> break statement). if you need to break out of the outer one, you need
> another break statement not contained in another loop.
> 
> hope this helps!
> -- wesley
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> "Core Python Programming", Prentice Hall, (c)2007,2001
> "Python Fundamentals", Prentice Hall, (c)2009
> http://corepython.com
> 
> wesley.j.chun :: wescpy-at-gmail.com
> python training and technical consulting
> cyberweb.consulting : silicon valley, ca
> http://cyberwebconsulting.com

-- 
Neu: GMX Doppel-FLAT mit Internet-Flatrate + Telefon-Flatrate
für nur 19,99 Euro/mtl.!* http://portal.gmx.net/de/go/dsl02
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] While and for loops

2009-07-14 Thread Todd Matsumoto
Okay,

Thanks guys.

That explains it.

Cheers,

T
 Original-Nachricht 
> Datum: Tue, 14 Jul 2009 00:16:30 -0700
> Von: wesley chun 
> An: "A.T.Hofkamp" 
> CC: Todd Matsumoto , "tutor@python.org" 
> Betreff: Re: [Tutor] While and for loops

> >> So how would you break out from this situation?
> >
> > finished = False
> > while not finished:
> >     
> >     for i in items:
> >         if i > 10:
> >             finished = True  # Do not do the next while-iteration
> >             break            # and break out of the for loop
> >         else:
> >             
> 
> 
> this solution is workable as well, plus it avoids having 2 break
> statements in the code. it "breaks" out of the while-loop in a natural
> way, making its conditional False.
> 
> -- wesley
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> "Python Web Development with Django", Addison Wesley, (c) 2009
> http://withdjango.com
> 
> wesley.j.chun :: wescpy-at-gmail.com
> python training and technical consulting
> cyberweb.consulting : silicon valley, ca
> http://cyberwebconsulting.com

-- 
Neu: GMX Doppel-FLAT mit Internet-Flatrate + Telefon-Flatrate
für nur 19,99 Euro/mtl.!* http://portal.gmx.net/de/go/dsl02
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] unittests, testing a type

2009-07-14 Thread Todd Matsumoto
Hi,

Does anyone know how to do a unittest assert for a type? 

So If you have a program returning a Decimal, lets say Decimal("1"), and you 
want to make sure that what is returned is a Decimal object.

At first I thought of importing Decimal and making my own Decimal("1") and 
doing an assertEquals, but this implies I know what the return type is before 
getting it.

Cheers,

T
-- 
Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3 -
sicherer, schneller und einfacher! http://portal.gmx.net/de/go/atbrowser
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] unittests, testing a type

2009-07-14 Thread Todd Matsumoto
Okay,

Thanks that worked. 

I still needed to import the Decimal class and I'm not sure that is okay. The 
reason why is I'm receiving the Decimal value from another program, if I 
already know that the value will be a Decimal why test it?

Perhaps I'm getting to caught up in this test-driven development thing.

Cheers,

T


 Original-Nachricht 
> Datum: Tue, 14 Jul 2009 15:45:18 +0200
> Von: "A.T.Hofkamp" 
> An: Todd Matsumoto 
> CC: "tutor@python.org" 
> Betreff: Re: [Tutor] unittests, testing a type

> Todd Matsumoto wrote:
> > Hi,
> > 
> > Does anyone know how to do a unittest assert for a type? 
> > 
> > So If you have a program returning a Decimal, lets say Decimal("1"), and
> you want to make sure that what is returned is a Decimal object.
> > 
> > At first I thought of importing Decimal and making my own Decimal("1")
> and
> doing an assertEquals, but this implies I know what the return type is
> before
> getting it.
> 
> 
> For new-style classes, you should be able to do
> 
> 
> type(result) is Decimal
> 
> 
> 
> (since the class is a singleton, 'is' should work).
> 
> 
> Albert

-- 
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] unittests, testing a type

2009-07-14 Thread Todd Matsumoto
Hi,

Thanks for all the comments so far.

DaveA, I'm receiving the value via pyODBC, after running a query on a database. 
The test is to first make sure the value is a Decimal (pyODBC returns a Decimal 
object if what is coming from the database is a decimal type). So if I don't 
have a value that is a Decimal object something is wrong.

Cheers,

T
 Original-Nachricht 
> Datum: Tue, 14 Jul 2009 22:36:14 -0400
> Von: Dave Angel 
> An: 
> CC: Todd Matsumoto , tutor@python.org
> Betreff: Re: Re: [Tutor] unittests, testing a type

> On Tue, Jul 14, 2009 at 9:59 AM, Todd Matsumoto wrote:
> >> The reason why is I'm receiving the Decimal value from another program,
> if I already know that the value will be a Decimal why test it?
> >> 
> >
> >   
> How are you receiving it?  File, pickle, pipe, socket, exit() return 
> value?  When I first read your question, I assumed you meant "from 
> another module."  But if it's another process, then you'd better tell us 
> how you're actually getting the value.  Maybe it's a Decimal because you 
> just got done converting it to one.
> 
> DaveA

-- 
Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3 -
sicherer, schneller und einfacher! http://portal.gmx.net/de/go/chbrowser
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] decorators, __call__ (able) objects

2009-07-15 Thread Todd Matsumoto
Hi,

Can some one give, or point to some good examples of how @decorators work, and 
__call__ (able) objects? I'm having trouble getting my head around these 
techniques (concepts).

Cheers,

T
-- 
Neu: GMX Doppel-FLAT mit Internet-Flatrate + Telefon-Flatrate
für nur 19,99 Euro/mtl.!* http://portal.gmx.net/de/go/dsl02
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] decorators, __call__ (able) objects

2009-07-15 Thread Todd Matsumoto
hi kent,

thanks, i read through the link but still haven't got my head around this 
concept.

will read on.

cheers,

t
 Original-Nachricht 
> Datum: Wed, 15 Jul 2009 08:33:33 -0400
> Von: Kent Johnson 
> An: Todd Matsumoto 
> CC: tutor@python.org
> Betreff: Re: [Tutor] decorators, __call__ (able) objects

> On Wed, Jul 15, 2009 at 7:41 AM, Todd Matsumoto wrote:
> > Hi,
> >
> > Can some one give, or point to some good examples of how @decorators
> work, and __call__ (able) objects?
> 
> Decorators:
> http://personalpages.tds.net/~kent37/kk/1.html
> 
> Kent

-- 
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] decorators, __call__ (able) objects

2009-07-15 Thread Todd Matsumoto
Thanks guys,

In the example the __call__ method has *args and **kws as arguments. Is that 
required?

Also when, in what situation would you use callable objects?

Cheers,

T
 Original-Nachricht 
> Datum: Wed, 15 Jul 2009 12:02:05 -0700
> Von: wesley chun 
> An: vince spicer , tmatsum...@gmx.net
> CC: Kent Johnson , tutor@python.org
> Betreff: Re: [Tutor] decorators, __call__ (able) objects

> >>> > Can some one give, or point to some good examples of how @decorators
> >>> > work, and __call__ (able) objects?
> >
> > simple example of calling a class
> >
> > class myKlass(object):
> >
> > def __call__(self, *args, **kws):
> >  print "i was called"
> >
> > >>> test = myKlass()
> > >>> test()
> > i was called
> 
> 
> close. the example was right, but the description wasn't accurate...
> you meant, "calling an instance." i'm going to plagarize and rip this
> right out of section 14.1.4 from "Core Python Programming:"
> 
> "Python provides the __call__() special method for classes, which allows a
> programmer to create objects (instances) that are callable. By default,
> the
> __call__() method is not implemented, meaning that most instances are
> not callable. However, if this method is overridden in a class
> definition,
> instances of such a class are made callable. Calling such instance objects
> is
> equivalent to invoking the __call__() method. Naturally, any arguments
> given in the instance call are passed as arguments to __call__()."
> 
> as far as decorators go, kent's tutorial is great place to start. here
> are 2 more articles plus PEP 318, where they were defined:
> 
> http://www.ibm.com/developerworks/linux/library/l-cpdecor.html
> http://www.artima.com/weblogs/viewpost.jsp?thread=240808
> http://www.python.org/dev/peps/pep-0318
> 
> in addition, i devoted section 11.3.6 of Core Python to decorators.
> 
> finally, it should be mentioned that starting in 2.6, you can now
> decorate *classes*, as seen here in PEP 3129:
> 
> http://www.python.org/dev/peps/pep-3129/
> 
> hope this helps!
> -- wesley
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> "Core Python Programming", Prentice Hall, (c)2007,2001
> "Python Fundamentals", Prentice Hall, (c)2009
> http://corepython.com
> 
> wesley.j.chun :: wescpy-at-gmail.com
> python training and technical consulting
> cyberweb.consulting : silicon valley, ca
> http://cyberwebconsulting.com

-- 
Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3 -
sicherer, schneller und einfacher! http://portal.gmx.net/de/go/atbrowser
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Option parser tools

2009-07-22 Thread Todd Matsumoto
Hello Tutors,

I'm building a script that now needs a command line interface.

I'm aware of optparse, but I'm wondering if there are any other tools that may 
be better for building the interface.

Cheers,

T
-- 
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Checking for Python version

2009-10-06 Thread Todd Zullinger
Christian Witts wrote:
> Your version will fail if the person is running Python 3.0, 3.1 up
> until the 3.3 series which is not good.  Neater looking (imo) code
> below.
>
> from sys import version_info, exit
>
> if version_info[0] == 1 or (version_info[0] == 2 and version_info[1] < 4):
>exit("Please upgrade to Python 2.4 or greater.")

This would fail on python < 2.0, as version_info is not available.  So
you'd want to catch that, if you want to gracefully handle ancient
versions of python.  You could also just compare the version_info
tuple.

This is a bit ugly, but it works at least back to 1.5.2:

import sys

min_version = '2.4'
upgrade_msg = 'Please upgrade to Python %s or greater' % min_version

try:
min = tuple(map(int, min_version.split('.')))
ver = sys.version_info[:3]
if ver < min:
sys.exit(upgrade_msg)
except AttributeError:
sys.exit(upgrade_msg)

I don't have any python 3.x systems to test though.

-- 
ToddOpenPGP -> KeyID: 0xBEAF0CE3 | URL: www.pobox.com/~tmz/pgp
~~
Suppose I were a member of Congress, and suppose I were an idiot. But,
I repeat myself.
-- Mark Twain



pgpHQ1caffg6U.pgp
Description: PGP signature
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Testing for empty list

2009-10-19 Thread Todd Matsumoto
The while loop will print each index of the list. In a way it checks that if 
the list is empty by printing the items. As far as I know there isn't any 
'True' or 'False' output from a list.

If you want to do something if mylist is empty you can check it like this:

if not mylist:
   ... do something ...

T

 Original-Nachricht 
> Datum: Sun, 18 Oct 2009 20:29:53 -0500
> Von: Wayne 
> An: "tutor@python.org" 
> Betreff: [Tutor] Testing for empty list

> Hi, I think I recall seeing this here, but I wanted to make sure I'm
> correct.
> Is the best way to test for an empty list just test for the truth value?
> I.e.
> 
> mylist = [1,2,3]
> 
> while mylist:
>print mylist.pop()
> 
> Thanks,
> Wayne
> 
> -- 
> To be considered stupid and to be told so is more painful than being
> called
> gluttonous, mendacious, violent, lascivious, lazy, cowardly: every
> weakness,
> every vice, has found its defenders, its rhetoric, its ennoblement and
> exaltation, but stupidity hasn’t. - Primo Levi

-- 
Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3.5 -
sicherer, schneller und einfacher! http://portal.gmx.net/de/go/atbrowser
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Testing for empty list

2009-10-19 Thread Todd Matsumoto
I don't understand how the while loop efficiently tests if the list is empty. 
Why would going through the entire list be a good test to simply see find out 
if the list is empty or not.

Wouldn't you want to test the list itself, rather than the contents of it?

Cheers,

T

 Original-Nachricht 
> Datum: Mon, 19 Oct 2009 04:52:40 -0400
> Von: Dave Angel 
> An: Wayne 
> CC: "tutor@python.org" 
> Betreff: Re: [Tutor] Testing for empty list

> 
> 
> Wayne wrote:
> > Hi, I think I recall seeing this here, but I wanted to make sure I'm
> > correct.
> > Is the best way to test for an empty list just test for the truth value?
> > I.e.
> >
> > mylist = [1,2,3]
> >
> > while mylist:
> >print mylist.pop()
> >
> > Thanks,
> > Wayne
> >
> >   
> My take is simple:  Use the above form if you *know* that mylist is in 
> fact a list.  If you don't know its type for sure (the name is a clue, 
> but not conclusive ;-) ) then use a more specific test.
> 
> In your case, you know it's a list, or least something that supports 
> pop().  So your form should be great.
> 
> DaveA
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

-- 
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] A Really Quick Question

2005-10-22 Thread Todd Maynard
Hi Steve,

Here is the python documentation.  Hopefully it is a *little* clearer

http://docs.python.org/lib/bltin-file-objects.html

*** readlines ***

readlines(  [sizehint])
 Read until EOF using readline() and return a list containing the lines thus 
read. If the optional sizehint argument is present, instead of reading up to 
EOF, whole lines totalling approximately sizehint bytes (possibly after 
rounding up to an internal buffer size) are read. Objects implementing a 
file-like interface may choose to ignore sizehint if it cannot be 
implemented, or cannot be implemented efficiently.

*** read ***
read(  [size])
 Read at most size bytes from the file (less if the read hits EOF before 
obtaining size bytes). If the size argument is negative or omitted, read all 
data until EOF is reached. The bytes are returned as a string object. An 
empty string is returned when EOF is encountered immediately. (For certain 
files, like ttys, it makes sense to continue reading after an EOF is hit.) 
Note that this method may call the underlying C function fread() more than 
once in an effort to acquire as close to size bytes as possible. Also note 
that when in non-blocking mode, less data than what was requested may be 
returned, even if no size parameter was given.

***

If you want to only read X bytes at a time then read would be more 
appropriate.

Have fun learning,

--Todd


On Saturday 22 October 2005 10:18, Steve Haley wrote:
> Folks,
>
>
>
> I am running Python 2.1 which ships with ArcView 9.1.  I am going through
> the 2.1 tutorial and came across readlines().  Simply put it doesn't seem
> to be behaving as the tutorial describes.  Specifically, I created a small
> text file as shown below:
>
>
>
> f=open("c:/python21/sfh_modules/test.txt", "w")
>
> f.write("This is the second line\n")
>
> f.write("This is the second line\n")
>
> f.close()  # then closed and reopened in read mode
>
> f=open("c:/python21/sfh_modules/test.txt", "r")
>
> f.readlines(2)  # Here's my problem
>
> ['This is the first line\n', 'This is the second line\n']  # please note
> this output
>
>
>
> The tutorial seems to be telling me that 'f.readlines(2) should read out 2
> bytes plus what is needed to complete the current line.  Instead, it is
> reading out the entire file no matter what I enter as a parameter.  I know
> I am going to feel really dumb when I hear the explanation but please
> remember I'm new to this.
>
>
>
> Thanks very much,
>
> Steve
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Indexing in a series for a newbie

2006-01-19 Thread Todd Maynard
Another approach would be to change your data structure to include the words 
and hints together as tuples in the same tuple.

ie...

WORDS=( ("python","The python hint"),("program","The program hint"),
("code","The code hint") )

then you can do...

word, hint = random.choice(WORDS)


>>> WORDS=( ("python","The python hint"),("program","The program hint"),
("code","The code hint") )
>>> word, hint = random.choice(WORDS)
>>> word
'code'
>>> hint
'The code hint'
>>>


Happy coding,

-- Todd Maynard


On Thursday 19 January 2006 10:36, Jon Moore wrote:
> Hello
>
> I need some help for a program I am writing as a newbie to Python.
>
> I have created a series:
>
> WORDS = ("python", "program", "code", "xylophone")
>
> and then assigned one of them randomly to the variable 'word':
>
> word = random.choice(WORDS)
>
> I know that if I do:
>
> print word
>
> The randomly chosen word will be displayed. I also know that if I type:
>
> print WORDS[x]
>
> I will get the corresponding word back. But how do I find 'programaticaly'
> the index number for the string that random.choice has chosen?
>
> The reason I ask is that I an writing a simple word jumble game and need to
> link the randomly chosen word to a hint should the user need one.
>
> --
> Best Regards
>
> Jon Moore

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Starbucks does not use two-phase commit

2006-01-21 Thread Todd Maynard
Danny,

I want to thank you for ruining my plans for a relaxing Saturday morning.  As 
a thread newbie I killed several hours playing around with your code.

One thing I noticed is that sometimes the program would hang, which I figured 
was the Queue code blocking in the Ticket claim function. I used exception 
handling to deal with that situation cleanly. 

I then decided that it wasn't very nice of Starbucks to close after accepting 
my order without giving me my Latte, so I changed that part of the code to:

 def schedule(self,job):
"""Schedules a job and returns a "ticket" the user can later use 
to get the result."""
if self.acceptNew == True:
  outputQueue=Queue()
  self.queue.put((job,outputQueue))
  return Ticket(outputQueue)
else:
   print "Server not accepting any new requests."
   return None

 def scheduleShutdown(self):
"""Add a job that shuts the system down."""
print "Telling server to shut down"
self.queue.put((Server._QUIT_NICELY,None))

 def _jobLoop(self):
"""Continue looping through tasks."""
while True:
   print "Looping ... "
   (nextJob, outputQueue) = self.queue.get()
   if nextJob is server._QUIT_NOW:
  return
   if nextJob is server._QUIT_NICELY:
self.acceptNew = False
self.queue.put((Server._QUIT_NOW,None))
   else:
  returnValue=self._doJob(nextJob)
  outputQueue.put(returnValue)


I am 99.44% sure that this is thread safe, reasoning being:
 setting the acceptNew to False and adding the QUIT_NOW happens in the 
same 
thread so it is impossible for another job to get scheduled after the 
QUIT_NOW - so no thread will end up hanging...

However, I would sleep a little better if you could reassure me that I am 
right, and would sleep even better if you could give me a method to test 
this.  This kinda stuff looks tricky to test with standard unittest 
methodology

Thanks again for the enligntenment all you guys bring to this awesome 
language.

My bastardized code is below for reference.

--Todd Maynard < [EMAIL PROTECTED] >


[It is] best to confuse only one issue at a time.
-- K&R


**


from threading import Thread
from Queue import Queue,Empty

class Ticket(object):
   """A small token we can use to claim our result."""
   def __init__(self, q):
  self.q = q
  self.result = None
  self.done=False

   def claim(self):
  if not self.done:
 try:
self.result=self.q.get(True,5)
self.done=True
 except Empty:
print "We lost the server!"
self.result=None
  return self.result


class Server(object):
 _QUIT_NOW=['Quit!']
 _QUIT_NICELY=['Quit Nicely']

 def __init__(self):
"""A queue will contain 2-tuples of (job, outputQueue) 
elements."""
self.queue=Queue()
self.acceptNew=True

 def startServer(self):
"""Brings the server online."""
Thread(target=self._jobLoop).start()

 def schedule(self,job):
"""Schedules a job and returns a "ticket" the user can later use 
to get the result."""
if self.acceptNew == True:
  outputQueue=Queue()
  self.queue.put((job,outputQueue))
  return Ticket(outputQueue)
else:
   print "Server not accepting any new requests."
   return None

 def scheduleShutdown(self):
"""Add a job that shuts the system down."""
print "Telling server to shut down"
self.queue.put((Server._QUIT_NICELY,None))

 def _jobLoop(self):
"""Continue looping through tasks."""
while True:
   print "Looping ... "
   (nextJob, outputQueue) = self.queue.get()
   if nextJob is server._QUIT_NOW:
  return
   if nextJob is server._QUIT_NICELY:
self.acceptNew = False
self.queue.put((Server._QUIT_NOW,None))
   else:
  returnValue=self._doJob(nextJob)
  outputQueue.put(returnValue)

 def _doJob(self,job):
print "I'm doing " , job
return job + job #Something to show

Re: [Tutor] Starbucks does not use two-phase commit

2006-01-22 Thread Todd Maynard
Well Danny, now I know how I am gonna spend my Sunday

Thanks for the great explanation and the resources.   Of course do you think I 
could manage to get the code to break - of course not Usually I have the 
opposite problem.  Anyways I think that your explanation makes perfect sense.

My problem with your original code is that _jobLoop could sometimes return 
when there where still jobs (from separateCaller) still left in the queue.  
When separateCaller tried to ticket.claim , the self.result = self.q.get() 
would block, causing the program to hang indefinitely.  This is what I was 
trying to prevent by using the timeout in the get() call and then handling 
the possible Empty exception. 

I am now gonna play with this some more to see if I can build a robust/clean 
coffeeshop framework, with customers placing orders with a cashier , the 
cashier passing the orders to a barista and the barista processing the orders 
and delivering to the customers.  The idea of course being that the 
customers, cashier, and baristas each run in different threads.  Then to 
enhance with multiple cashiers and baristas

but first I need to put another pot of coffee on.

If you don't hear from me in a while, I've probably suffered a caffeine 
overdose.  


Thanks for the inspiration,

Todd Maynard


-- 
The tao that can be tar(1)ed
is not the entire Tao.
The path that can be specified 
is not the Full Path.

We declare the names
of all variables and functions.
Yet the Tao has no type specifier.

Dynamically binding, you realize the magic.
Statically binding, you see only the hierarchy.

Yet magic and hierarchy
arise from the same source,
and this source has a null pointer.

Reference the NULL within NULL,
it is the gateway to all wizardry.


On Sunday 22 January 2006 03:13, Danny Yoo wrote:
> On Sat, 21 Jan 2006, Todd Maynard wrote:
> > I want to thank you for ruining my plans for a relaxing Saturday
> > morning.  As a thread newbie I killed several hours playing around with
> > your code.
>
> Hi Todd,
>
> Sorry about that.  I hope you were relaxing in a cafe while playing with
> the code.
>
> > One thing I noticed is that sometimes the program would hang, which I
> > figured was the Queue code blocking in the Ticket claim function. I used
> > exception handling to deal with that situation cleanly.
>
> That's odd.  There shouldn't be anything that blocks the code.  Oh!  Did
> you make changes to the test code, or did the hanging occur in the
> original code in:
>
> http://mail.python.org/pipermail/tutor/2006-January/044567.html
>
> I'm curious because nothing there should fundamentally block, assuming
> that _doJob() doesn't dies badly with an exception.  If _doJob() dies, the
> server dies, and that's bad.  *grin*
>
> Do you mind showing what the exception handling looks like in your code?
>
> > I then decided that it wasn't very nice of Starbucks to close after
> > accepting my order without giving me my Latte, so I changed that part of
> > the code to:
>
> [code cut]
>
> > I am 99.44% sure that this is thread safe, reasoning being:
> >  setting the acceptNew to False and adding the QUIT_NOW happens in the
> > same thread so it is impossible for another job to get scheduled after
> > the QUIT_NOW - so no thread will end up hanging...
>
> Bad news: no.  *grin*
>
> There's a "race condition".  Let's go into some detail with this, since
> this is not obvious stuff.
>
> First, let's look at the code again --- I'll label three lines with (a),
> (b), and (c), to make it a little easier to see the race.
>
>
> ###
> def schedule(self,job):
> if self.acceptNew == True:   ## (a)
> outputQueue=Queue()
> self.queue.put((job,outputQueue))
> return Ticket(outputQueue)
> else:
>  print "Server not accepting any new requests."
>  return None
>
> def scheduleShutdown(self):  ## (b)
> self.queue.put((Server._QUIT_NICELY,None))
>
> def _jobLoop(self):
> while True:
> print "Looping ... "
> (nextJob, outputQueue) = self.queue.get()
> if nextJob is server._QUIT_NOW:
> return
> if nextJob is server._QUIT_NICELY:   ## (c)
> self.acceptNew = False
> self.queue.put((Server._QUIT_NOW,None))
> else:
> returnValue=self._doJob(nextJob)
> outputQueue.put(returnValue)
> ##
>
>
> Let's imagine three threads, which I'll name C1, C2, and S

Re: [Tutor] G'day

2006-02-18 Thread Todd Maynard
John,

Just as an FYI, Dive into Python is available in printed form.   The 
http://diveintopython.org website has a link to it on Amazon.com. It might be 
cheaper than printing it out yourself..

--Todd Maynard



-- 
The world is coming to an end ... SAVE YOUR BUFFERS!!!



On Saturday 18 February 2006 07:11, John Connors wrote:
> G'day,
>
> Thanks to the people who replied, I only found them today and hopefully I
> didn't miss any. For some reason hotmail was sending them to junk even
> though it allowed the 1st message through and I had added tutor@python.org
> to my contact list. Should be sorted now I hope!
>
> > > print "Hello, World!"
> > >
> > > print ' 'Goodbye, World!"
> >
> >If you are referring to the bit on page 25 it is the same style of
> >quote in both examples in my copy of the book. Are you sure
> >its different? Or are you looking at another page?
>
> It was a library book and I have taken it back, there was typos all through
> it. I figured out that most of the syntax errors I was getting were from
> incorrect indentation. I knew indentation was important in python but I
> didn't realise it would return a syntax error if it was wrong. Not the
> authors fault BTW, just errors in the printing I think.
>
> I'm now using an ebook I found called Dive Into Python. I much prefer using
> a book so I can duck back a few pages to refresh my memory and reading on
> the monitor is a real pain. It seems an excellent reference though so I'll
> get around to printing it out sooner or latter (when the Mrs isn't here so
> she won't complain about me wasting ink and paper).
>
> John
>
> _
> realestate.com.au: the biggest address in property
> http://ninemsn.realestate.com.au
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] First Try

2006-02-19 Thread Todd Maynard
Nice Job John.  I made a few comments below on a few things I noticed.

On Sunday 19 February 2006 05:33, John Connors wrote:
> G'day :)
>
> I started getting sick of reading tutorials so for a bit of a break I set
> myself the task of writing a program to pick lotto numbers, 6 numbers
> between 1 and 44 (inclusive). I had done this many years before in basic
> and I thought back then it would be a simple task but I struck a problem of
> the random number generator repeating numbers occasionally so I had to
> check each number against the other and generate another random number if
> there were duplicates.
>
> So I was prepared for the same problem with python but I found that python
> takes care of that for me so the program would only have to be one line. I
> decided to make it a little more user friendly and allow the user to pick
> home many games they want generated. Then I made the output a little easier
> to read with a few blank lines. Here is what I came up with:
>
>
> import random
>
> numberof = int(raw_input('Enter how many games you would like generated
> :')) #user input for number of games to choose

10,000 lines of code or 6months later (whichever comes first...) will you 
remember what numberof represents?   Number of times the cow jumped over the 
moon?  I try not to end a var with a prep (and will usually just omit it).  I 
would personally go for num_games_wanted or num_tickets.  (Actually to tell 
the truth I am a mixedCase kinda guy so would really go for numGamesWanted or 
numTickets, but that is not really PEP 8 [1] friendly so I am trying to break 
my ways.)

>
> print
> print
> print "Here are your numbers :"
> print
>

If you desire you can use "\n" for return to reduce this all into one line:
   print "\n\n\Here are your numbers :\n\n"
No big deal.

> for games in range(1, numberof + 1): #loop for the number of games selected
> by user
> lotto = random.sample(xrange(1,45), 6) #generate 6 random numbers
> between 1 and 44 inclusive
> print games, lotto
> print
>
> else:
> print
> print "Hope you win!"
You don't need an else block (you will always enter it, ).

You can just do:

for games in range(1,numberof + 1):
lotto = random.sample(xrange(1,45),6)
print games, lotto
print
print "\nHope you win!"

>
>
> I know this is a very simple program but... could I have done this a better
> way?

Looks pretty good to me. If you want to expand this a little more you can 
try:

1.)  Assign all the lottery tickets to a variable and then print out the 
lottery tickets after you have them all.  ( A list would be helpful here...)

2.)  Break your program into functions so that you can do something like:

(num_tickets_wanted, min_num, max_num) = get_user_input()
lotto_tickets=generate_tickets(num_tickets_wanted, min_num,max_num)
print_results(lotto_tickets)

NOTE: It would be pure evil to drop that alll into one line.
print_results(generate_tickets(get_user_input()))

I shouldn't have even mentioned that, but you get the idea.
>
> John
>
> _
> Search for local singles online @ Lavalife - Click here
> http://a.ninemsn.com.au/b.aspx?URL=http%3A%2F%2Flavalife9%2Eninemsn%2Ecom%2
>Eau%2Fclickthru%2Fclickthru%2Eact%3Fid%3Dninemsn%26context%3Dan99%26locale%3
>Den%5FAU%26a%3D21550&_t=21550&_r=endtext&_m=EXT
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

Have some fun with itat least until you win the lottery.

--Todd Maynard

-- 
Computers are unreliable, but humans are even more unreliable.
Any system which depends on human reliability is unreliable.
-- Gilb
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] First Try

2006-02-19 Thread Todd Maynard
and for a belated footnote:

[1] = http://www.python.org/peps/pep-0008.html
Style Guide for python code.

--Todd


On Sunday 19 February 2006 06:27, Todd Maynard wrote:
> Nice Job John.  I made a few comments below on a few things I noticed.
>
> On Sunday 19 February 2006 05:33, John Connors wrote:
> > G'day :)
> >
> > I started getting sick of reading tutorials so for a bit of a break I set
> > myself the task of writing a program to pick lotto numbers, 6 numbers
> > between 1 and 44 (inclusive). I had done this many years before in basic
> > and I thought back then it would be a simple task but I struck a problem
> > of the random number generator repeating numbers occasionally so I had to
> > check each number against the other and generate another random number if
> > there were duplicates.
> >
> > So I was prepared for the same problem with python but I found that
> > python takes care of that for me so the program would only have to be one
> > line. I decided to make it a little more user friendly and allow the user
> > to pick home many games they want generated. Then I made the output a
> > little easier to read with a few blank lines. Here is what I came up
> > with:
> >
> >
> > import random
> >
> > numberof = int(raw_input('Enter how many games you would like generated
> >
> > :')) #user input for number of games to choose
>
> 10,000 lines of code or 6months later (whichever comes first...) will you
> remember what numberof represents?   Number of times the cow jumped over
> the moon?  I try not to end a var with a prep (and will usually just omit
> it).  I would personally go for num_games_wanted or num_tickets.  (Actually
> to tell the truth I am a mixedCase kinda guy so would really go for
> numGamesWanted or numTickets, but that is not really PEP 8 [1] friendly so
> I am trying to break my ways.)
>
> > print
> > print
> > print "Here are your numbers :"
> > print
>
> If you desire you can use "\n" for return to reduce this all into one line:
>print "\n\n\Here are your numbers :\n\n"
> No big deal.
>
> > for games in range(1, numberof + 1): #loop for the number of games
> > selected by user
> > lotto = random.sample(xrange(1,45), 6) #generate 6 random numbers
> > between 1 and 44 inclusive
> > print games, lotto
> > print
> >
> > else:
> > print
> > print "Hope you win!"
>
> You don't need an else block (you will always enter it, ).
>
> You can just do:
>
> for games in range(1,numberof + 1):
>   lotto = random.sample(xrange(1,45),6)
>   print games, lotto
>   print
> print "\nHope you win!"
>
> > I know this is a very simple program but... could I have done this a
> > better way?
>
> Looks pretty good to me. If you want to expand this a little more you
> can try:
>
> 1.)  Assign all the lottery tickets to a variable and then print out the
> lottery tickets after you have them all.  ( A list would be helpful
> here...)
>
> 2.)  Break your program into functions so that you can do something like:
>
> (num_tickets_wanted, min_num, max_num) = get_user_input()
> lotto_tickets=generate_tickets(num_tickets_wanted, min_num,max_num)
> print_results(lotto_tickets)
>
> NOTE: It would be pure evil to drop that alll into one line.
> print_results(generate_tickets(get_user_input()))
>
> I shouldn't have even mentioned that, but you get the idea.
>
> > John
> >
> > _
> > Search for local singles online @ Lavalife - Click here
> > http://a.ninemsn.com.au/b.aspx?URL=http%3A%2F%2Flavalife9%2Eninemsn%2Ecom
> >%2
> > Eau%2Fclickthru%2Fclickthru%2Eact%3Fid%3Dninemsn%26context%3Dan99%26local
> >e%3 Den%5FAU%26a%3D21550&_t=21550&_r=endtext&_m=EXT
> >
> > ___
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
>
> Have some fun with itat least until you win the lottery.
>
> --Todd Maynard

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Running multiple version of Python on 1 windows machine

2006-10-30 Thread Todd Dahl
At work I have installed Python 2.4 but at home I have Python 2.5.
Until this point I didn't think nothing of it but now I have run into
a issue.

I have some code that I have worked on at work that uses the pySQLite
module which doesn't support 2.5, yet. I can run my code at work but I
can't even install the module at home.

So my question is how do I configure my machine at home so I can have
multiple versions of python running so I can run this code. Or is this
a bad and/or confusing thing to do.

Thanks

-Todd
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] GUI with Designer

2006-11-03 Thread Todd Dahl
I am wanting to get into some GUI coding with Python and have heard about PyQT and wxPython. Now I am definately not looking for some type of holy war but can anyone give me a good reason to pick one over the other.

 
Also I would like to have a designer with it or a seperate designer that could be used with either. I plan on coding in Windows XP.
 
Thanks,
 
-Todd
 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Windows Registry

2006-11-09 Thread Todd Dahl
I am currently working on a project that in a small part of it I need to find keys in the windows registry. I have found _winreg but was wondering if anyone knows of any modules that people have written as a wrapper for it. I have googled like crazy but am not finding anything. What I trying to do is search the registry for a list of known keys without knowing their specific locations and then find values of the other keys around it. Hope that makes sence. 
 Thanks, -Todd
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Recursive functions and the windows registry

2006-11-16 Thread Todd Dahl

I have been fighting with this for a couple of days and am getting
frustrated with it. I am trying to figure out a way to walk through the
windows registry and to capture all nodes under the HKEY_CLASSES_ROOT\CLSID
key and then put it into a list.



I have been trying to do it with a recursive function but am having no luck
with it. I am really hoping that it's because I am new to Python and not
because I am doing something stupid but it would not be the first time I
missed something obvious.



This script is a subset of the larger script that I am working on.  Any help
or feedback would be great. I'm getting to the end of my rope.



By the way I don't understand why it seems to work inside the
ListRegistryKeys function but it doesn't pass all the information back to
the parseRegistry function.



-Todd




#!/usr/bin/env python

import _winreg # _winreg module allows you to work with the windows registry

def ListRegistryKeys(path):
   # if its empty do nothing
   if not path: return

   key=_winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, path)

   i=0
   name = []

   try:
   while 1:
   name.append(path + "\\" + _winreg.EnumKey(key, i))
   print name[-1]
   i += 1
   except WindowsError:
   pass

   _winreg.CloseKey( key)


   for item in name:
   ListRegistryKeys(item)

   return name


def parseRegistry():
   guidlist = ListRegistryKeys("CLSID")

   for item in guidlist:
   print "parseRegistry: ", item

def main():
   parseRegistry()

if __name__=="__main__":
   main()
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] IIS and Virtual directories

2006-11-22 Thread Todd Dahl

I have been trying to figure out how to create an IIS Virtual Directory
through Python but can't find anything that works. I have done it in the
past with Perl with the script below but can't seem to figure out how to do
it in Python. I was wondering if someone could point me in the right
direction.

Thank you,
-Todd

P.S."Hope everyone who reads this has a nice Thanksgiving!"

=



##
# Description: Use ADSI to create IIS virtual#
##

use Win32::OLE;

my $server = "localhost";
my $VirtualDir = "AIRAdmin";

mkdir("nhvrweb",0777);


eval{

#Create WWW directory

#Check if the directory already exsist
if (! ($www =
Win32::OLE->GetObject("IIS://$server/W3svc/1/Root/$VirtualDir")))
{
 $www = Win32::OLE->GetObject("IIS://$server/W3svc/1");
 $vRoot = $www->GetObject("IIsWebVirtualDir", "Root");
 $vDir = $vRoot->Create("IIsWebVirtualDir",$VirtualDir);
 $vDir->{AccessScript} = 1;
 $vDir->{Path} = "C:\\nhvr\\$VirtualDir";
 $vDir->SetInfo();
 $vDir->AppCreate(1);
}

};
#In case of error
print Win32::OLE->LastError()."\n"if(Win32::OLE->LastError());
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python open of c:\ path Problem

2008-08-23 Thread Todd Zullinger
Kent Johnson wrote:
> The \ character is a special 'escape' character that is used to insert
> non-printing characters into a string. \t represents a single tab
> character, not the two characters \ and t.
> 
> To put an actual backslash into a string, you can either double it:
> 'c:\\tmp\\junkpythonfile'
> or prefix the string with r to make a 'raw' string, which doesn't have
> any special meaning for \:
> r'c:\tmp\junkpythonfile'

While I don't use Windows myself, I'm believe that you can also use
forward-slashes as the path separator, e.g.: 

junkfile = open('c:/tmp/junkpythonfile','w')

(Pardon me if I'm completely wrong.)

-- 
ToddOpenPGP -> KeyID: 0xBEAF0CE3 | URL: www.pobox.com/~tmz/pgp
~~
To grasp the true meaning of socialism, imagine a world where
everything is designed by the post office, even the sleaze.
-- P.J. O'Rourke



pgpK8dI0nX75c.pgp
Description: PGP signature
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] MP3Info class usage

2008-12-10 Thread Todd Zullinger
Gareth at Serif wrote:
> Has anyone any better suggestions for retreiving ID3 tags from an
> MP3 file using python?

I'd recommend eyeD3¹ and/or mutagen² for tag reading.  Both are pretty
easy to use.

¹ http://eyed3.nicfit.net/
² http://code.google.com/p/quodlibet/wiki/Development/Mutagen

-- 
ToddOpenPGP -> KeyID: 0xBEAF0CE3 | URL: www.pobox.com/~tmz/pgp
~~
A paranoid is someone who knows a little of what's going on.
-- William S. Burroughs



pgpqn2qXFwKw3.pgp
Description: PGP signature
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] MP3Info class usage

2008-12-15 Thread Todd Zullinger
Gareth at Serif wrote:
> Okay, I've moved over to eyeD3.py... fif nothing else, the
> documentation for it's usage is far superior.
> 
> However, I can't get anything to run.  The help gives examples of
> some simple tasks, but as soon as I 'import eyeD3', not even calling
> any functions within it, I start getting errors such as:
> 
> In eyeD3.py, the 'from eyeD3.tag import *;' line (and similar)
> didn't work until I removed the 'eyeD3.' part and just imported
> 'tag'.

How have you installed eyeD3?  Perhaps there's something wrong with
the installation.  Certainly, 'import eyeD3' should not create any
errors.

> Then in tag.py, some of the class defs complained about undefined
> variables, for example 'def link(self, f, v = ID3_ANY_VERSION)'
> needed to have quotes around 'ID3_ANY_VERSION'.

That's not what you want to do.  ID3_ANY_VERSION is defined in
eyeD3/__init__.py.  If you quote it, you're breaking it.

> I'm baffled that I'm having to jump through so many hoops because I
> imported eyeD3... is this typical?  What have I done wrong?

That's hard to guess at.  If you can explain what you have done and
how you've installed eyeD3, that would help.

-- 
ToddOpenPGP -> KeyID: 0xBEAF0CE3 | URL: www.pobox.com/~tmz/pgp
~~
Don't look for me in daylight where robots all assemble.  You'll find
me in my dark world, in my smoke-filled temple.



pgpcUXQkD7v1L.pgp
Description: PGP signature
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] MP3Info class usage

2008-12-18 Thread Todd Zullinger
Gareth at Serif wrote:
> I've not installed it, I've just imported it in my main program.
> How do you install eyeD3, there's no installation package?

What OS are you running?  I can help if you run some sort of *nix
system.  If you're on Windows, then I'll have to pass as I know
nothing about installing python modules on Windows. :)

> I read the readme, which talks about executing 'configure', but that
> just reports back that it is not recognized as an internal or
> external command, operable program or batch file.

Hmm, "... batch file" makes me think this is Windows.

On *nix systems, you run ./configure; make; sudo make install.  The ./
in front of configure tells the shell that the program you are trying
to run is in the current directory.  Otherwise, the shell would look
for configure in your $PATH, which does not include the current
directory.

-- 
ToddOpenPGP -> KeyID: 0xBEAF0CE3 | URL: www.pobox.com/~tmz/pgp
~~
Mollison's Bureaucracy Hypothesis:
If an idea can survive a bureaucratic review and be implemented it
wasn't worth doing.



pgp8LSNYi8sv7.pgp
Description: PGP signature
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] MP3Info class usage

2008-12-20 Thread Todd Zullinger
Terry Carroll wrote:
> On Fri, 19 Dec 2008, Terry Carroll wrote:
>> It would be nice if Eyed3, which is not OS-specific, did not have
>> such an OS-specific install process.

Perhaps.  But someone who cares about windows support would have to
submit patches.  I don't know if Travis uses windows or not.  I have
submitted a number of patches to eyeD3, but I don't use windows at all
myself.  I can't see spending any time to support a proprietary OS. :)

And, to be fair, the install process isn't really OS-specific.  It
works on a large number of operating systems -- just not on Windows.

> You know, I just reinstalled Eyed3, and compared the installed
> result to the six files distributed in the zipped tarfile, and
> they're identical except that one file is named __init__.py.in
> instead of __init__.py, and has two doc variables defined with
> templates.
> 
> If you want to avoid having to install a Unix-like environment,
> I suggest you just
> 
> 1) unzip and untar the zipped tarfile,
> 2) copy the eyeD3 directory from  eyeD3-0.6.16/src/ to Python's
> Lib/site-packages/ directory
> 3) rename __init__.py.in to  __init__.py
> 4) (probably cosmetic) in __init__.py, edit the lines:
> 
>   eyeD3Version = "@PACKAGE_VERSION@";
>   eyeD3Maintainer = "@PACKAGE_BUGREPORT@";
> 
> to:
> 
>   eyeD3Version = "0.6.16";
>   eyeD3Maintainer = "Travis Shirk ";
> 
> Someone else will now explain why this is a terrible idea.

I don't think it is a bad idea at all.  I was going to suggest
something similar.  If you do that, you should be able to copy the
src/eyeD3 directory somewhere in your PYTHONPATH and use it just fine.

-- 
ToddOpenPGP -> KeyID: 0xBEAF0CE3 | URL: www.pobox.com/~tmz/pgp
~~
I like this 'God'; he's so deliciously evil.
-- Stewie Griffin



pgpzJ8ONmIkTV.pgp
Description: PGP signature
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Search and replace text in XML file?

2012-07-27 Thread Todd Tabern
I'm looking to search an entire XML file for specific text and replace that 
text, while maintaining the structure of the XML file. The text occurs within 
multiple nodes throughout the file. 
I basically need to replace every occurrence C:\Program Files with C:\Program 
Files (x86), regardless of location. For example, that text appears within: 
C:\Program Files\\Map Data\Road_Centerlines.shp 
and also within: 
C:\Program 
Files\Templates\RoadNetwork.rtx 
...among others. 
I've tried some non-python methods and they all ruined the XML structure. I've 
been Google searching all day and can only seem to find solutions that look for 
a specific node and replace the whole string between the tags. 
I've been looking at using minidom to achieve this but I just can't seem to 
figure out the right method. 
My end goal, once I have working code, is to compile an exe that can work on 
machines without python, allowing a user can click in order to perform the XML 
modification. 
Thanks in advance. 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Topic #2 of Tutor Digest

2012-07-28 Thread Todd Tabern
Mark Lawrence: Yes, I did... I kept encountering errors when trying to post the 
first time. I didn't think my question went through, so I tried this one.
Even if I were to purposefully ask the question in multiple places, why does 
that concern you? I wasn't aware that asking for help in multiple places is 
forbidden.
I'm sorry that it offended you so much that you felt the need to respond in 
that manner instead of providing assistance...

Cheers

tutor-requ...@python.org wrote:


Send Tutor mailing list submissions to
tutor@python.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.python.org/mailman/listinfo/tutor
or, via email, send a message with subject or body 'help' to
tutor-requ...@python.org

You can reach the person managing the list at
tutor-ow...@python.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Tutor digest..."


Today's Topics:

   1. Re: Encoding error when reading text files in Python 3
  (Steven D'Aprano)
   2. Re: Search and replace text in XML file? (Mark Lawrence)
   3. Re: Encoding error when reading text files in Python 3 (Dat Huynh)
   4. Re: Flatten a list in tuples and remove doubles
  (Francesco Loffredo)
   5. Re: Flatten a list in tuples and remove doubles
  (Francesco Loffredo)


--

Message: 1
Date: Sat, 28 Jul 2012 20:09:28 +1000
From: Steven D'Aprano 
To: tutor@python.org
Subject: Re: [Tutor] Encoding error when reading text files in Python
3
Message-ID: <5013ba58.1040...@pearwood.info>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Dat Huynh wrote:
> Dear all,
>
> I have written a simple application by Python to read data from text files.
>
> Current I have both Python version 2.7.2 and Python 3.2.3 on my laptop.
> I don't know why it does not run on Python version 3 while it runs
> well on Python 2.

Python 2 is more forgiving of beginner errors when dealing with text and
bytes, but makes it harder to deal with text correctly.

Python 3 makes it easier to deal with text correctly, but is less forgiving.

When you read from a file in Python 2, it will give you *something*, even if
it is the wrong thing. It will not give an decoding error, even if the text
you are reading is not valid text. It will just give you junk bytes, sometimes
known as moji-bake.

Python 3 no longer does that. It tells you when there is a problem, so you can
fix it.


> Could you please tell me how I can run it on python 3?
> Following is my Python code.
>
>  --
>for subdir, dirs, files in os.walk(rootdir):
> for file in files:
> print("Processing [" +file +"]...\n" )
> f = open(rootdir+file, 'r')
> data = f.read()
> f.close()
> print(data)
> --
>
> This is the error message:
[...]
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xd1 in position
> 4980: ordinal not in range(128)


This tells you that you are reading a non-ASCII file but haven't told Python
what encoding to use, so by default Python uses ASCII.

Do you know what encoding the file is?

Do you understand about Unicode text and bytes? If not, I suggest you read
this article:

http://www.joelonsoftware.com/articles/Unicode.html


In Python 3, you can either tell Python what encoding to use:

f = open(rootdir+file, 'r', encoding='utf8')  # for example

or you can set an error handler:

f = open(rootdir+file, 'r', errors='ignore')  # for example

or both

f = open(rootdir+file, 'r', encoding='ascii', errors='replace')


You can see the list of encodings and error handlers here:

http://docs.python.org/py3k/library/codecs.html


Unfortunately, Python 2 does not support this using the built-in open
function. Instead, you have to uses codecs.open instead of the built-in open,
like this:

import codecs
f = codecs.open(rootdir+file, 'r', encoding='utf8')  # for example

which fortunately works in both Python 2 or 3.


Or you can read the file in binary mode, and then decode it into text:

f = open(rootdir+file, 'rb')
data = f.read()
f.close()
text = data.decode('cp866', 'replace')
print(text)


If you don't know the encoding, you can try opening the file in Firefox or
Internet Explorer and see if they can guess it, or you can use the chardet
library in Python.

http://pypi.python.org/pypi/chardet

Or if you don't care about getting moji-bake, you can pretend that the file is
encoded using Latin-1. That will pretty much read anything, although what it
gives you may be junk.



--
Steven


---

Re: [Tutor] Flip the coin 10x and count heads and tails: It works now!

2013-05-26 Thread Todd Matsumoto
May I suggest running randint using 0, 1. The results can be tested like a
boolean. See what happens when you do an if test on 1 versus an if test on
0.

Also perhaps store your results in a dictionary with 'heads', 'tails' each
value set to 0.


On Sat, May 25, 2013 at 3:13 PM, Steven D'Aprano wrote:

> On 25/05/13 19:25, Rafael Knuth wrote:
>
>  flips = 0
>> heads = 0
>> tails = 0
>>
>> while flips < 10:
>>  flips = flips + 1
>>
>
> Don't do this. It's not 1971 any more, we've had for loops for forty years
> :-)
>
> Use while loops when you don't know how many loops you need. When you know
> how many loops you will have, use a for loop.
>
> for flip in range(10):
> print(flip)
>
> will print 0 1 2 3 ... 9 which makes ten loops altogether. If you want to
> start counting at 1 instead of 0, use:
>
> for flip in range(1, 11):
> print(flip)
>
> which will print 1 2 3 ... 9 10.
>
>
> There's no need to count the number of heads and tails separately, since
> every loop is guaranteed to give either head or tails. So just count the
> number of heads, then the number of tails will be ten less the number of
> heads.
>
>
>
>
> --
> Steven
>
> __**_
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/**mailman/listinfo/tutor<http://mail.python.org/mailman/listinfo/tutor>
>



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


Re: [Tutor] Regarding python function arguments

2013-06-11 Thread Todd Matsumoto
One way you can do that is by using default arguments.

def my_func (arg1=False, arg2=False, arg3=False):
# Check the arguments.


On Tue, Jun 11, 2013 at 10:54 AM, Arijit Ukil  wrote:

> i am writing following python function:
>
> def my_func (arg1, arg2, arg3):
>
> however, I am not always going to pass all the arguments. sometimes only
> arg1 is passed, sometimes arg1 and arg2 are passed; sometimes arg1, arg2,
> arg3 are passed.
> How can i manage this?
>
> Regards,
> Arijit Ukil
> Tata Consultancy Services
> Mailto: arijit.u...@tcs.com
> Website: http://www.tcs.com
> 
> Experience certainty.IT Services
>Business Solutions
>Consulting
> 
>
> =-=-=
> Notice: The information contained in this e-mail
> message and/or attachments to it may contain
> confidential or privileged information. If you are
> not the intended recipient, any dissemination, use,
> review, distribution, printing or copying of the
> information contained in this e-mail message
> and/or attachments to it are strictly prohibited. If
> you have received this communication in error,
> please notify us by reply e-mail or telephone and
> immediately and permanently delete the message
> and any attachments. Thank you
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>


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


Re: [Tutor] producing PDF files

2013-06-11 Thread Todd Matsumoto
I don't know how good it is, but OpenERP's report.pyPdf module is what I've
been using to do this.

As quoted from the pdf.py module:

"A pure-Python PDF library with very minimal capabilities.  It was designed
to
be able to split and merge PDF files by page, and that's about all it can
do.
It may be a solid base for future PDF file work in Python."


On Tue, Jun 11, 2013 at 11:53 AM, Khalid Al-Ghamdi wrote:

> Hi,
>
> Do you know of a python module for converting text files to PDF format?
>
> thanks
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>


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


Re: [Tutor] sqlite question

2013-06-11 Thread Todd Matsumoto
I think you are missing the fetch call. The cursor only executed your
query, but hasn't fetched any thing out.


On Tue, Jun 11, 2013 at 12:20 PM, Khalid Al-Ghamdi wrote:

> Hi,
>
> I have a dictionary with keys as employee badges and values as their
> names. Both key and value are strings.
>
> I want to read the badges from a sql select and use that to look up the
> names in the dictionary. But since the result is a tuple, it doesnt' work.
>
> how can i overcome this?
>
>
>1. >>> for data in cur.execute('select badge from sched'):
>2. r_data()[data]
>3.
>4.
>5. Traceback (most recent call last):
>6.   File "", line 2, in 
>7. r_data()[data]
>8. KeyError: (80385,)
>
>PS: the r_data () above is just a func that returns the before
>mentioned dictionary. Here is r_data().
>
>1. def r_data():
>   2. d={}
>   3. with open('data.csv') as f:
>   4. reader = csv.reader(f)
>   5. for sn, badge, name, grp, major, track, stage, tc,
>subject, course in reader:
>   6. d[badge]=name
>   7. return d
>
>
>
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>


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


Re: [Tutor] Help please

2013-10-17 Thread Todd Matsumoto

Hello Ruben,

You might already know this, but the Python documentation will get you 
pretty far: http://www.python.org/doc/


Here are some things to lookup that may help you solve the problems.

On 10/16/2013 08:49 PM, Pinedo, Ruben A wrote:

I was given this code and I need to modify it so that it will:

#1. Error handling for the files to ensure reading only .txt file

Look up exceptions.
Find out what the string method endswith() does.

#2. Print a range of top words... ex: print top 10-20 words
#3. Print only the words with > 3 characters

Look up how the built-in len() works.

#4. Modify the printing function to print top 1 or 2 or 3 
#5. How many unique words are there in the book of length 1, 2, 3 etc
Read up on different datatypes and choose the one, or combination types 
that would solve this for you.


T

P.S. Tutors I hope this is posted to the list and the top. I always get 
that wrong!

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


[Tutor] vol 166, issue 20, 1. installing python and numpy on the Mac (OSX) (Peter Hodges)

2017-12-24 Thread Bruce Todd Puls
sudo -H python3.6 -m pip install numpy
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] prime factorisation

2018-03-12 Thread Bruce Todd Puls
I think You would do much better if You wrote pseudo code first,
i.e. write each step out in words,
code is much easier to write following pseudo code

Are You trying to factor Prime Numbers?
Prime Number factored (Prime Number and 1)


https://en.wikipedia.org/wiki/Table_of_prime_factors#1_to_100

https://www.mathsisfun.com/prime-factorization.html
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Calculation error with a simple program

2015-12-12 Thread Todd Purple via Tutor


> On Dec 12, 2015, at 2:03 AM, Jim Gallaher  wrote:
> 
> Hi everyone. I'm reading through a beginners Python book and came up with a 
> super simple program. I'm not getting any errors and everything runs through, 
> but there's a logical calculation error. What the program does is take an 
> amount and calculate a couple percentages and add a couple fees.
> 
> For example, if I put in a value of 1, it will output 752.12 as the sub total 
> and 753.12 as the grand total. It's off by 1 on sub total and 2 on grand 
> total.
> 
> Thanks in advance! Jim Gallaher
> 
> # Car Salesman Calculator
> 
> # User enters the base price of the car and the program adds tax, license, 
> dealer prep, and destination charge.
> 
> print("Car Sales Calculator")
> basePrice = int(input("Please enter in the price of the car: "))
> 
> # Misc charges to be added to the total cost of the car
> tax = basePrice * .07
> license = basePrice * .05
> dealerPrep = basePrice + 500
> destinationCharge = basePrice + 250
> 

I think your main problem is right here. Why do dealerPrep and 
destinationCharge include the basePrice in their equation? This will add the 
basePrice in multiple times. I would simply set it like this:

dealerPrep = 500
destinationCharge = 250

If these charges ever change, you can put in some sort of equation. However, it 
looks like these are meant to be a flat fee. 

> # Add the total misc charges together
> subTotal = float(tax + license + dealerPrep + destinationCharge)
> 
> # Add all the misic charges and include the base pricem
> grandTotal = float(subTotal + basePrice)
> 
> # Display the results
> print("\nThe sub total is", subTotal)
> print("\nYour grand Total is", grandTotal)
> 
> input("\nPress the enter key to close the program.")
> ___
> 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