Re: [Tutor] Simple Python Projects ?

2008-05-28 Thread ALAN GAULD

> > Or you could just try reading and playing with the samples
> > that come with Python. There are some simple code beautifier
> > scripts that could be easily enhanced and are not too hard.
> This looks very interesting to look at, on a windows installation of
> Python where would they be located ?


Look in the Tools directory.
I'd start with the scrips subdirectory or possibly the webchecker 
or versioncheck sub folders.

There are about 100 files in Tools which should be enough 
to keep you busy for a while! :-)

Alan g

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


Re: [Tutor] Simple Python Projects ?

2008-05-28 Thread Julia
I would recommend PyGame.org. While you'll have to learn to use the PyGame
library - there are alot of easy tutorials and open source projects.

/MJ


> Are there any simple python projects out there that have well documented
> code and are recommended for new users to read and modify ?
>
> I have created a few small programs on my own, but I feel that I will
> learn more now if I attempt to understand code that I have not written
> and then attempt to modify it.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] (no subject)

2008-05-28 Thread [EMAIL PROTECTED]
Hello,
(Sorry if this message gets double posted)

I have been looking at using Beautifulsoup python module to make 
changes to some static html files a total of 167 files, but being a 
newb in programming was wondering first how to open, read/process the 
file, then write it, close it and then open the next file thus creating 
the loop.

Can someone post me a simple example of doing this loop for a given 
directory.
Thanks
David




What can Tiscali do for you? http://www.tiscali.co.uk/services

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


[Tutor] Example of modifying files in directory

2008-05-28 Thread [EMAIL PROTECTED]
Hello,
I have been looking at using Beautifulsoup python module to make 
changes to some static html files a total of 167 files, but being a 
newb in programming was wondering first how to open, read/process the 
file, then write it, close it and then open the next file thus creating 
the loop.

Can someone post me a simple example of doing this loop for a given 
directory.
Thanks
David




What can Tiscali do for you? http://www.tiscali.co.uk/services

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


[Tutor] I am a web designer wanting to learn Python

2008-05-28 Thread Michael yaV
Where should I begin/go to learn how to create web apps using Python?  
I would like to create a dynamic "content managed" website and I have  
chosen Python as my language of choice. Can anybody show me, a Mac  
user, where I, a programming beginner, can find tutorials for using  
Python for web apps?


Thank you for any help.

Michael 
  
___

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


[Tutor] A video introducing Ulipad, an IDE mainly for Python

2008-05-28 Thread Dick Moores
I've been using Ulipad, a free IDE mainly for Python, and written in 
wxPython, for a couple of years, and think it's terrific. Now another 
user, Kelie Feng, has made an 8-minute video showing it off. The 
visual clarity of the video is remarkable. You can download it 
(Introducing_Ulipad_2008-05-22.avi), and a codec (tscc.exe) that may 
be necessary for your player, from .


Dick Moores

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


Re: [Tutor] I am a web designer wanting to learn Python

2008-05-28 Thread Alan Gauld

"Michael yaV" <[EMAIL PROTECTED]> wrote

Where should I begin/go to learn how to create web apps using 
Python?  I would like to create a dynamic "content managed" website 
and I have  chosen Python as my language of choice. Can anybody show 
me, a Mac  user, where I, a programming beginner, can find tutorials 
for using  Python for web apps?


If you expect to write several apps you should choose a Web Framework.
The two most poular are TurboGears and Django. Both have websites,
search Google...

To use either you will need a good knowledge of Python programming
in a non Web way, for that try the standard list of tutorials for 
either

non-programmers or programmers from another language.

http://wiki.python.org/moin/BeginnersGuide/NonProgrammers
http://wiki.python.org/moin/BeginnersGuide/Programmers

Then you can read about the fundamentals of web programming
in the Web Topic Guide area of the Python web site

http://wiki.python.org/moin/WebProgramming

If you do go for a Web Framework you might also like the ShowMeDo
website which has short video tutorials showing how to set up and
create yur first web site. They definitely do Django and I think
they might do TG too.

HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 



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


Re: [Tutor] A video introducing Ulipad, an IDE mainly for Python

2008-05-28 Thread Sean Azelton
For those looking for the codec and not running Windows, you can find
it here for Mac OS X as well

http://www.techsmith.com/download/codecs.asp

On Wed, May 28, 2008 at 11:01 AM, Dick Moores <[EMAIL PROTECTED]> wrote:
> I've been using Ulipad, a free IDE mainly for Python, and written in
> wxPython, for a couple of years, and think it's terrific. Now another
> user, Kelie Feng, has made an 8-minute video showing it off. The
> visual clarity of the video is remarkable. You can download it
> (Introducing_Ulipad_2008-05-22.avi), and a codec (tscc.exe) that may
> be necessary for your player, from .
>
> Dick Moores
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
Sean Azelton
Systems Engineer : University of Notre Dame
Notre Dame, IN
http://www.linkedin.com/in/azelton
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] I am a web designer wanting to learn Python

2008-05-28 Thread wesley chun
> > Where should I begin/go to learn how to create web apps using Python?  I
> would like to create a dynamic "content managed" website and I have  chosen
> Python as my language of choice. Can anybody show me, a Mac  user, where I,
> a programming beginner, can find tutorials for using  Python for web apps?


hi, and welcome to Python!

out of curiosity, how did you arrive at the conclusion that you should
use Python?


>  If you expect to write several apps you should choose a Web Framework.
>  The two most poular are TurboGears and Django. Both have websites,
>  search Google...

you *could*, or we can just say http://djangoproject.com and
http://turbogears.org

if you are new to Python, i would suggest Django over TurboGears, not
that Django is "better than" TG, but because those who favor TG are
usually already familiar with Python, esp. the best-of-breed
components of which it serves as the "glue", i.e.
SQLObject/SQLAlchemy, CherryPy, MochiKit, Genshi/Kid. Django is an
"all-in-one" package and requires "less overhead" if you're new to
Python.

on a related note, if you're interested solely in creating, running,
managing, developing, and/or supporting a "content managed" site, i.e.
run by a "content management system" (or CMS), you may also wish to
look at Plone -- http://plone.org ... this is its speciality.

all 3 of these frameworks have documentation as well as video clips on
"how easy it is to use them" on their websites.

if you're looking for reading, we can also recommend some books for
you, but it will depend on your previous/current programming
experience.

best of luck!
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Example of modifying files in directory

2008-05-28 Thread Kent Johnson
On Wed, May 28, 2008 at 9:50 AM, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
> Hello,
> I have been looking at using Beautifulsoup python module to make
> changes to some static html files a total of 167 files, but being a
> newb in programming was wondering first how to open, read/process the
> file, then write it, close it and then open the next file thus creating
> the loop.

I guess this is the simplest possible loop to do something to each
file in a directory. You would call processDir() with the path to the
directory to process. Define a function doSomethingWith() that takes
the file contents as an argument and returns the new file contents.

import os

def processDir(dirpath):
  for name in os.listdir(dirpath):
filepath = os.path.join(dirpath, name)
f = open(filepath)
data = f.read()
f.close()

data = doSomethingTo(data)

f = open(filepath, 'w')
f.write(data)
f.close()

This modifies files in place so you should have a backup. It assumes
everything in the dir is a file; if not you need to check in the loop.

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


Re: [Tutor] I am a web designer wanting to learn Python

2008-05-28 Thread Michael yaV

Wesley,
I have been wanting to learn a language for the last 10 years, I am  
now just getting around to it. I did some research on languages,  
because I decided if I was going learn one, I wanted to learn  
something that I could use for many different applications (web being  
one). Python seemed to offer all I was looking for, plus, I have been  
told, it is rather easy to learn. Why?

Michael


On May 28, 2008, at 2:04 PM, wesley chun wrote:

Where should I begin/go to learn how to create web apps using  
Python?  I
would like to create a dynamic "content managed" website and I  
have  chosen
Python as my language of choice. Can anybody show me, a Mac  user,  
where I,
a programming beginner, can find tutorials for using  Python for  
web apps?



hi, and welcome to Python!

out of curiosity, how did you arrive at the conclusion that you should
use Python?


If you expect to write several apps you should choose a Web  
Framework.

The two most poular are TurboGears and Django. Both have websites,
search Google...


you *could*, or we can just say http://djangoproject.com and
http://turbogears.org

if you are new to Python, i would suggest Django over TurboGears, not
that Django is "better than" TG, but because those who favor TG are
usually already familiar with Python, esp. the best-of-breed
components of which it serves as the "glue", i.e.
SQLObject/SQLAlchemy, CherryPy, MochiKit, Genshi/Kid. Django is an
"all-in-one" package and requires "less overhead" if you're new to
Python.

on a related note, if you're interested solely in creating, running,
managing, developing, and/or supporting a "content managed" site, i.e.
run by a "content management system" (or CMS), you may also wish to
look at Plone -- http://plone.org ... this is its speciality.

all 3 of these frameworks have documentation as well as video clips on
"how easy it is to use them" on their websites.

if you're looking for reading, we can also recommend some books for
you, but it will depend on your previous/current programming
experience.

best of luck!
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
   http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com



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


Re: [Tutor] I am a web designer wanting to learn Python

2008-05-28 Thread wesley chun
>  I have been wanting to learn a language for the last 10 years, I am now
> just getting around to it. I did some research on languages, because I
> decided if I was going learn one, I wanted to learn something that I could
> use for many different applications (web being one). Python seemed to offer
> all I was looking for, plus, I have been told, it is rather easy to learn.
> Why?

the community is interested in knowing how new members came to the
Python family.  :-)

sounds like you're new to programming.  there are few good books on
this subject:
- Python Programming: An Introduction to Computer Science (John Zelle)
- Python Programming for the Absolute Beginner (Michael Dawson)
- Python For Dummies (Stef and Aahz Maruch)
- How To Think Like a Computer Scientist (Allen Downey, Jeffrey
Elkner, Chris Meyers)
- Introduction to Computing and Programming in Python (Mark Guzdial)
- Learn to Program Using Python (Alan Gauld)
- Python: Visual QuickStart Guide (Chris Fehily)

there are also some great online tutorials:
- Python.org tutorial http://docs.python.org/tut
- Instant Hacking http://www.hetland.org/python/instant-hacking.php
- How to Think Like a Computer Scientst http://openbookproject.net/thinkCSpy/
- Learning to Program http://www.freenetpages.co.uk/hp/alan.gauld/

here is a link to a more comprehsnvie list of Python-related tutorials:
- Python Tutorials http://awaretek.com/tutorials.html

cheers,
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] I am a web designer wanting to learn Python

2008-05-28 Thread Michael yaV

Thanks... I have my-work-cut-out-for-me.
Michael

On May 28, 2008, at 3:50 PM, wesley chun wrote:

I have been wanting to learn a language for the last 10 years, I am  
now
just getting around to it. I did some research on languages,  
because I
decided if I was going learn one, I wanted to learn something that  
I could
use for many different applications (web being one). Python seemed  
to offer
all I was looking for, plus, I have been told, it is rather easy to  
learn.

Why?


the community is interested in knowing how new members came to the
Python family.  :-)

sounds like you're new to programming.  there are few good books on
this subject:
- Python Programming: An Introduction to Computer Science (John Zelle)
- Python Programming for the Absolute Beginner (Michael Dawson)
- Python For Dummies (Stef and Aahz Maruch)
- How To Think Like a Computer Scientist (Allen Downey, Jeffrey
Elkner, Chris Meyers)
- Introduction to Computing and Programming in Python (Mark Guzdial)
- Learn to Program Using Python (Alan Gauld)
- Python: Visual QuickStart Guide (Chris Fehily)

there are also some great online tutorials:
- Python.org tutorial http://docs.python.org/tut
- Instant Hacking http://www.hetland.org/python/instant-hacking.php
- How to Think Like a Computer Scientst http://openbookproject.net/thinkCSpy/
- Learning to Program http://www.freenetpages.co.uk/hp/alan.gauld/

here is a link to a more comprehsnvie list of Python-related  
tutorials:

- Python Tutorials http://awaretek.com/tutorials.html

cheers,
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
   http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com



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


Re: [Tutor] A video introducing Ulipad, an IDE mainly for Python

2008-05-28 Thread bob gailer

Dick Moores wrote:
I've been using Ulipad, a free IDE mainly for Python, and written in 
wxPython, for a couple of years, and think it's terrific.


Thanks - IUlipad has some nice features, but I'd miss the debugging in 
PythonWin.



--
Bob Gailer
919-636-4239 Chapel Hill, NC

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


[Tutor] 'Right' way to implement mixins in Python?

2008-05-28 Thread chombee
I'm writing an event-driven GUI framework. I have several independent
units of functionality such as Draggable, Highlightable, etc. Although
these units of functionality are independent of each other, they do all
depend on a certain base implementation that they work with. I want
widget objects to be able to select different combinations of these
capabilities at will. So mixins seemed like the way to go.

It seemed to me that the most natural way to implement mixins in Python
is to use multiple inheritance with new-style classes. But I certainly
confused myself a lot trying to do it. I think I have come up with the
solution, although its late and this is pretty rushed, but I thought it
would put it out there for comment. Is this the right thing to do?

The lessons I learned are that, when implementing mixins using multiple
inheritance:

* Mixin classes should not derive from any base class (except object)
* But they may assume that the classes they will be mixed in with do
derive from a certain base class, so they may assume the base class is
there.

Here's some code showing the approach that seems to work for me:



class Base(object):
"""Base class for mixer classes. All mixin classes
require the classes they are mixed in with to be
instances of this class (or a subclass)."""

def __init__(self,b):
self.b = b # Mixin classes assume this attribute will be present

class MixinBPlusOne(object):
"""A mixin class that implements the print_b_plus_one
method."""

def __init__(self):
print 'MixinBPlusOne initialising'

def print_b_plus_one(self):
print self.b+1

class MixinBMinusOne(object):
"""A mixin class that implements the print_b_minus_one
method."""

def __init__(self):
print 'MixinBMinusOne initialising'

def print_b_minus_one(self):
print self.b-1
   
class Mixer(Base,MixinBPlusOne,MixinBMinusOne):
"""A mixer class (class that inherits some mixins), this
will work because it also inherits Base, which the
mixins expect."""

def __init__(self,b):
# I feel like I should be using super here because 
# I'm using new-style classes and multiple
# inheritance, but the argument list of
# Base.__init__ differs from those of the Mixin
# classes, and this seems to work anyway.
Base.__init__(self,b)
MixinBPlusOne.__init__(self)
MixinBMinusOne.__init__(self)

class BrokenMixer(MixinBPlusOne,MixinBMinusOne):
"""This will not work because it does not inherit Base,
which the mixins expect it to do."""

pass

m = Mixer(9)
m.print_b_plus_one()
m.print_b_minus_one()

m = BrokenMixer(9)
m.print_b_plus_one() # It'll crash here.



It outputs this, the result I expected:

MixinBPlusOne initialising
MixinBMinusOne initialising
10
8



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


[Tutor] Python Programming for the Absolute Beginner-OT

2008-05-28 Thread Tony Cappellini
A bit OT, but still within the realm of beginning Python...

My co-worker whom has just started learning Python, bought this book in used
condition.
http://www.courseptr.com/ptr_detail.cfm?group=Programming&subcat=Other&isbn=978%2D1%2D59863%2D112%2D8

Unfortunately it came without the CD, and the publisher does not have a link
for downloading the sources.

If you have this book AND the CD, please reply to me OFF-LIST.

I would like to get a copy of the files on the CD for my co-worker.

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


Re: [Tutor] A video introducing Ulipad, an IDE mainly for Python

2008-05-28 Thread Dick Moores

At 01:40 PM 5/28/2008, bob gailer wrote:

Dick Moores wrote:
I've been using Ulipad, a free IDE mainly for Python, and written 
in wxPython, for a couple of years, and think it's terrific.


Thanks - IUlipad has some nice features, but I'd miss the debugging 
in PythonWin.


Hey, Ulipad has WinPdb.

Dick Moores


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


Re: [Tutor] 'Right' way to implement mixins in Python?

2008-05-28 Thread Alan Gauld


"chombee" <[EMAIL PROTECTED]> wrote

I'm writing an event-driven GUI framework. I have several 
independent
units of functionality such as Draggable, Highlightable, etc. 
Although
these units of functionality are independent of each other, they do 
all

depend on a certain base implementation that they work with.


That's a bad thing in a mixin. Mixins should be as independant
as possible from any other classes. Unfortunately thats not
always possible so you should try to create an abstract
superclass/interface and use that in your mixins. You can then
subclass the mixin and replace the abstract class with the local
concrete manifestation. It means one extra level of inheritance 
because

you wind up with an abstract mixin plus the localised mixin.


widget objects to be able to select different combinations of these
capabilities at will. So mixins seemed like the way to go.


Sounds a fair approach. So long as you are aware of the extra
coomplexities asociated with maintaining very wide  multi-inheritance
heirarchies.

It seemed to me that the most natural way to implement mixins in 
Python
is to use multiple inheritance with new-style classes. But I 
certainly

confused myself a lot trying to do it.


Mixins are normally done using MI. I''m interested in your 
experiences.

Did new style classes specifically add problems(I've only done mixins
in old style classes in Python, I've mainly used mixins in Lisp)

The lessons I learned are that, when implementing mixins using 
multiple

inheritance:

* Mixin classes should not derive from any base class (except 
object)

* But they may assume that the classes they will be mixed in with do
derive from a certain base class, so they may assume the base class 
is

there.


Yes to both, regardless of language. As I said above you can make the
mixins slightly more generally reusable by creating abstact mixins
with explicit dependancy on an abstact interface. But better still is 
to

avoid dependencies as much as possible where mixins are concerned.
Instead build a protocol in the class framework outside the mixins
and let them coerce the dependencies to suit the mixin interfaces.

--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 



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


Re: [Tutor] 'Right' way to implement mixins in Python?

2008-05-28 Thread chombee
Thanks Alan. Well, it looks like I've worked it out as far as small
example programs go, hope I can get it working in my actual codebase
now.

On Wed, 2008-05-28 at 23:30 +0100, Alan Gauld wrote:
> > It seemed to me that the most natural way to implement mixins in 
> > Python
> > is to use multiple inheritance with new-style classes. But I 
> > certainly
> > confused myself a lot trying to do it.
> 
> Mixins are normally done using MI. I''m interested in your 
> experiences.
> Did new style classes specifically add problems(I've only done mixins
> in old style classes in Python, I've mainly used mixins in Lisp)

The reason I started using new-style classes was that I had a diamond
shape in my class inheritance hierarchy. All my mixin classes inherited
from a single base class, and then all my widget classes
multiple-inherited from selections of mixin classes. (I realise this is
wrong now, but that's how I had it.)

So to get the method resolution order working right with this diamond
formation, I needed new-style classes. And with this diamond formation,
to prevent the __init__ method of the base class being called many times
when a widget class inherits many mixin classes, you have to use super()
instead of explicit calls to all the parent __init__ methods. Then you
run into  a problem when the parameters taken the by __init__ methods of
the mixins do not match each other or the paramaters taken by the
__init__ method of the base class. If a multiple-inheriting widget class
has in its class ancestry a number of different __init__ methods with
different parameter lists, how can it call them all with a single use of
super?

So then you have to use *args and **kwargs in the __init__ method of
_every_ class instead of specifying the parameters normally, and this
has a disadvantage, that the checking of the parameter lists that Python
would normally do is circumvented and you end up having to reimplement
it yourself. By this time I was pretty put off by this approach, and was
getting TypeErrors in my implementation, and decided not to push forward
with it.

Basically, I think that super in Python is a total mess, very tricky and
unwieldy. To be avoided. And also, I think multiple inheritance is
tricky and to be used minimally, avoiding diamond formations or worse. I
understand now why Java does not allow multiple inheritance.

But it all stemmed from my initial mistake, of having all the mixin
classes inherit from a common base class. Take away that and you get rid
of the diamond inheritance formation, you no longer need to use super,
in fact, I probably don't need to use new-style classes at all.

That's an entire days work summed up, trying to refactor my codebase to
use mixins.


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


Re: [Tutor] 'Right' way to implement mixins in Python?

2008-05-28 Thread Kent Johnson
On Wed, May 28, 2008 at 6:30 PM, Alan Gauld <[EMAIL PROTECTED]> wrote:

> Mixins should be as independant
> as possible from any other classes. Unfortunately thats not
> always possible so you should try to create an abstract
> superclass/interface and use that in your mixins. You can then
> subclass the mixin and replace the abstract class with the local
> concrete manifestation. It means one extra level of inheritance because
> you wind up with an abstract mixin plus the localised mixin.

I don't understand what you mean by this. Python doesn't really have
abstract classes and interfaces. And how is this different than
requiring the mixins to be used with only subclasses of a certain
concrete class?

> Instead build a protocol in the class framework outside the mixins
> and let them coerce the dependencies to suit the mixin interfaces.

Can you explain? I don't know what this means.

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


[Tutor] why?

2008-05-28 Thread Robert William Hanks
 Need ti find out whem a number o this form i**3+j**3+1 is acube.
 tryed a simple brute force code but, why this not work?

def iscube(n):
cubed_root = n**(1/3.0)
if round(cubed_root)**3 == n:
return True
else:
return False

for i in range(1,1000):
for j in range(1,1000):
 soma= i**3 +j**3 +1
 if isCube(soma):
 print i
 print j
 print soma
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] why?

2008-05-28 Thread John Fouhy
On 29/05/2008, Robert William Hanks <[EMAIL PROTECTED]> wrote:
>
>  Need ti find out whem a number o this form i**3+j**3+1 is acube.
>  tryed a simple brute force code but, why this not work?
[deleted code]

Why doesn't this work?  What problems are you having?

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


Re: [Tutor] why?

2008-05-28 Thread bob gailer

Robert William Hanks wrote:
 
 Need ti find out whem a number o this form i**3+j**3+1 is acube.

 tryed a simple brute force code but, why this not work?
 
def iscube(n):

cubed_root = n**(1/3.0)
if round(cubed_root)**3 == n:
return True
else:
return False

for i in range(1,1000):
for j in range(1,1000):
 soma= i**3 +j**3 +1
 if isCube(soma):
 print i
 print j
 print soma
   

Always report the specific problem. Saying "why this not work?" does not 
help.


What happens when you run this program?

When I do I get:
 File "J:\pipelines\cubed.py", line 11, in 
   if isCube(soma):
NameError: name 'isCube' is not defined

When I examine the program I'm not surprised to get that exception.

--
Bob Gailer
919-636-4239 Chapel Hill, NC

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


Re: [Tutor] why?

2008-05-28 Thread bob gailer

Robert William Hanks wrote:
 
 Need ti find out whem a number o this form i**3+j**3+1 is acube.

 tryed a simple brute force code but, why this not work?
 
def iscube(n):

cubed_root = n**(1/3.0)
if round(cubed_root)**3 == n:
return True
else:
return False

for i in range(1,1000):
for j in range(1,1000):
 soma= i**3 +j**3 +1
 if isCube(soma):
 print i
 print j
 print soma

Assuming you fixed the problem, do you know of any cases for which i**3 
+j**3 +1 is a cube?


Also note this program will run for a LONG time.

You can shorten the run time:

for i in range(1,1000):
   for j in range(j,1000): # test each combination once
soma =  i**3 +j**3 +1
cubed_root = soma**(0.333) # function call and division take 
extra time and there is no need for either
if abs(cubed_root  - round(cubed_root)) < .01: # this is a 
guess at close enough, and cheaper than cubing?

print i
print j
print soma

--
Bob Gailer
919-636-4239 Chapel Hill, NC

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


Re: [Tutor] why?

2008-05-28 Thread Kent Johnson
On Wed, May 28, 2008 at 8:43 PM, Robert William Hanks
<[EMAIL PROTECTED]> wrote:
>
>  Need ti find out whem a number o this form i**3+j**3+1 is acube.
>  tryed a simple brute force code but, why this not work?
>
> def iscube(n):
> cubed_root = n**(1/3.0)
> if round(cubed_root)**3 == n:
> return True
> else:
> return False
>
> for i in range(1,1000):
> for j in range(1,1000):
>  soma= i**3 +j**3 +1
>  if isCube(soma):
>  print i
>  print j
>  print soma

Let's see. The inner loop will run 1000 * 1000 =
100 times. That's a pretty big number. Suppose each
iteration of the loop takes 1 microsecond. (That seems optimistic but
not too much - on my computer iscube(27) takes about 1.3
microseconds.) Then the entire program will complete in 1000 *
1000 / 100 / 60 / 60 / 24 / 365 = 3 years. Other than that it
look OK to me...

Looks like you need either a better algorithm or a faster computer!

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


Re: [Tutor] I am a web designer wanting to learn Python

2008-05-28 Thread python
Wesley,

Don't be so modest - your "Core Python Programming" (by Wesley Chun) is
also a great book for those looking to learn Python.

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