[Tutor] OT: need computer advice from wise Tutors

2010-06-26 Thread Richard D. Moores
Sorry about the OT, but I'm really nervous about the possibility of
screwing up my laptop by upgrading the OS from Vista to 7, and can't
think of a better place than Tutors to ask for advice.

I bought this Toshiba Satellite last October. It came with the right
to receive the upgrade CD for Windows 7 when it became available. I
think I finally got the disk in February, but by that time I'd gotten
used to Vista, and Vista was then, as now, in SP2 (64-bit). By that
time a generally computer-savvy friend (but who runs linux) was
telling me to not do the upgrade because I'd end up with problems with
7 and also with a lot of the software I had already installed.

Then recently I've talked to a couple of guys (separately) in 2 Office
Depots near Seattle who both told me that the Vista -> 7 upgrade
should go without any trouble at all. That I should do the upgrade,
then immediately download and install all the updates for 7 that MS
has issued. Both used used to do such upgrades for customers for a fee
($40), but not anymore. So they didn't have anything to sell me -- I
think they were being honest about their experience.

Has anyone here done the upgrade I'm considering, or know of anyone
who has? Any advice or anecdotes for me?

Thanks,

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


Re: [Tutor] Use flag to exit? (OT - PEP 8 Gripe)

2010-06-26 Thread Richard D. Moores
On Fri, Jun 25, 2010 at 23:42, Dave Angel  wrote:
> Richard D. Moores wrote:
>>
>> On Fri, Jun 25, 2010 at 23:08, Dave Angel  wrote:
>>
>>>
>>> Do you activate Quick-Edit mode in your DOS box?  Once you have that on,
>>> it's not much of a pain to copy and paste, as long as what you're copying
>>> fits a rectangle.
>>>
>>
>> Yes, it's on. I agree that copying is easy, but if I can't use Ctrl+V,
>> pasting is a pain. Tell me your secret.
>>
>> Dick
>>
>>
>
> If you right-click on a DOS box without anything selected, then it pastes.
>  (Asssuming quickedit mode)
>
> For example, you run a command that displays a string, and you want to use
> that string as your next command:
>
> left-drag over the desired text.
> Right click to copy to clipboard
> Right click again to paste into current cursor position

Hey, terrific! Thanks, Dave! I didn't see any help available. Where'd
you learn this?

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


Re: [Tutor] OT: need computer advice from wise Tutors

2010-06-26 Thread Shashwat Anand
I am not a window user myself but all my friends who upgraded are quite
happy about it. AFAIK Vista was a failure but 7 is good, so it is worth
upgrading.

On Sat, Jun 26, 2010 at 12:30 PM, Richard D. Moores wrote:

> Sorry about the OT, but I'm really nervous about the possibility of
> screwing up my laptop by upgrading the OS from Vista to 7, and can't
> think of a better place than Tutors to ask for advice.
>
> I bought this Toshiba Satellite last October. It came with the right
> to receive the upgrade CD for Windows 7 when it became available. I
> think I finally got the disk in February, but by that time I'd gotten
> used to Vista, and Vista was then, as now, in SP2 (64-bit). By that
> time a generally computer-savvy friend (but who runs linux) was
> telling me to not do the upgrade because I'd end up with problems with
> 7 and also with a lot of the software I had already installed.
>
> Then recently I've talked to a couple of guys (separately) in 2 Office
> Depots near Seattle who both told me that the Vista -> 7 upgrade
> should go without any trouble at all. That I should do the upgrade,
> then immediately download and install all the updates for 7 that MS
> has issued. Both used used to do such upgrades for customers for a fee
> ($40), but not anymore. So they didn't have anything to sell me -- I
> think they were being honest about their experience.
>
> Has anyone here done the upgrade I'm considering, or know of anyone
> who has? Any advice or anecdotes for me?
>
> Thanks,
>
> 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


Re: [Tutor] Use flag to exit? (OT - PEP 8 Gripe)

2010-06-26 Thread Alan Gauld


"Richard D. Moores"  wrote

left-drag over the desired text.
Right click to copy to clipboard
Right click again to paste into current cursor position


Hey, terrific! Thanks, Dave! I didn't see any help available. 
Where'd

you learn this?


There is a fair amount of help in Wiindows Help.

Start->Help and search for CMD

The other way to paste is via the top left menu, Edit->Paste
which is what I tend to use.

Alan G. 



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


Re: [Tutor] Use flag to exit? (OT - PEP 8 Gripe)

2010-06-26 Thread Richard D. Moores
On Sat, Jun 26, 2010 at 01:21, Alan Gauld  wrote:
>
> "Richard D. Moores"  wrote
>>>
>>> left-drag over the desired text.
>>> Right click to copy to clipboard
>>> Right click again to paste into current cursor position
>>
>> Hey, terrific! Thanks, Dave! I didn't see any help available. Where'd
>> you learn this?
>
> There is a fair amount of help in Wiindows Help.
>
> Start->Help and search for CMD

OK. I'll take a look.

> The other way to paste is via the top left menu, Edit->Paste
> which is what I tend to use.

I knew about that. In fact, it's what I was calling a PITA. :)

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


Re: [Tutor] need computer advice from wise Tutors

2010-06-26 Thread Alan Gauld

"Richard D. Moores"  wrote


Sorry about the OT, but I'm really nervous about the possibility of
screwing up my laptop by upgrading the OS from Vista to 7, and can't
think of a better place than Tutors to ask for advice.


Going from Vista to Windows 7 is a relatively painless
process - unlike going from XP to 7. (Microsoft have scored a
huge own goal with missing out this upgrade path IMHO!)

And 7 is a vast improvement over Vista, which is appallingly
bad, again IMHO!

However, to quote the old adage - "If it ain't broke, don't fix it".
So what is the problem that you think the upgrade will fix?

Alan G.
Still on XP because nothing is broke...



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


[Tutor] Creating A Simple Blog System Using Python Programming

2010-06-26 Thread F C

Hi there,

- I have recently decided to learn Python. 
- It is my 
first programming language.
- I am new to programming.
- I know XHTML 
and CSS, and a few lines of PHP.
- I only started learning a couple of 
days ago.

What I want to do is create a simple blog system.
Where
 I can
- create posts, edit them and post them online 

Thus 
far, people have pointed me to frameworks.
>From what I see, the 
framework does the work for you...
I want to code the blog from 
scratch...after all - I want to learn the language - I don't want 
something to do the work for me.

I truly do not know where to 
start, because most of the tutorials are segmented, and I don't know how
 to structure the 
program, let alone what commands to include.

I
 would appreciate it if someone could give me some structure advice on 
how to tackle this.

Many thanks to the person(s) who can help.  
  
_
If It Exists, You'll Find it on SEEK. Australia's #1 job site
http://clk.atdmt.com/NMN/go/157639755/direct/01/___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Running external commands from Python

2010-06-26 Thread Alan Gauld


"Randy Kao"  wrote

In trying to do this in Python, I think I've read a couple ways to 
do this.


through: os.popen, os.popen2, os.popen3, os.system, 
commands.getoutput()




This is historically one of the things that Python has had trouble 
with.
The things you list have all been introduced over the years to 
"improve"

how it works. The current "official" method is to use the subprocess
module which replaces all of the above. But it does so by adding
some complexity and to really master it requires a fair bit of study
and experimentation. The good news is that the complexity offers
a very rich set of tools that can do pretty much anything tyou could
imagine in the way of working with external programs.


The "Working with the OS" topic in my tutorioal(V2 only) has some
basic examples of both the older techniques and the subprocess
method.

HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


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


[Tutor] Getting an object's attributes

2010-06-26 Thread mhw
Dear Tutors,

I have an object to which I dynamically add attributes. My question is how I 
can inspect and display them at run-time?

Class a():
pass

Obj1 = a()

Obj1.name = "Bob"
Obj1.age = 45

dir(a) returns a tuple which contains name and age, but also other things 
(includings methods, etc.) I could filter this tuple (checking for callable(), 
etc.)  but I just wondered if there was an existing way of getting just name 
and age.

Thanks,

Matt
Sent from my BlackBerry® wireless device
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Getting an object's attributes

2010-06-26 Thread Evert Rol
> I have an object to which I dynamically add attributes. My question is how I 
> can inspect and display them at run-time?
> 
> Class a():
>pass
> 
> Obj1 = a()
> 
> Obj1.name = "Bob"
> Obj1.age = 45

First off, a few suggestions:
- you probably mean 'class', not 'Class' (sorry, but it's just that correct 
actual code helps: copy-paste from the Python prompt when you can. If you have 
a text-editor in your mail program that capitalises things, be careful when 
pasting code).
- use capitalisation (or CamelCase) for class names, lowercase for instances: 
class A, obj1 = A(). This is the usual Python convention.
- I would use new-style classes, ie, inherit from object:
>>> class A(object):
...   pass
... 
>>> obj1 = A()



> dir(a) returns a tuple which contains name and age, but also other things 
> (includings methods, etc.) I could filter this tuple (checking for 
> callable(), etc.)  but I just wondered if there was an existing way of 
> getting just name and age.

Normally, you know which attributes you want to access, so you wouldn't have 
this problem. Better yet, you wrap things in a try-except clause and see if 
that works:
>>> try:
... obj1.name
... except AttributeError:
... print "not there"
... 
not there

 
But for this case, when using new-style classes, obj1.__dict__ can help you (or 
obj1.__dict__.keys() ). 
>>> obj1.name = "Bob"
>>> obj1.age = 45
>>> obj1.__dict__
{'age': 45, 'name': 'Bob'}

Or, perhaps somewhat silly: set(dir(obj1)) - set(dir(A)).
>>> set(dir(obj1)) - set(dir(A))
set(['age', 'name'])

but I wouldn't recommend that.

See eg http://docs.python.org/library/stdtypes.html#special-attributes


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


Re: [Tutor] OT: need computer advice from wise Tutors

2010-06-26 Thread Steven D'Aprano
On Sat, 26 Jun 2010 05:00:16 pm Richard D. Moores wrote:
> Sorry about the OT, but I'm really nervous about the possibility of
> screwing up my laptop by upgrading the OS from Vista to 7, and can't
> think of a better place than Tutors to ask for advice.

Because of course knowing Python makes you an expert on Windows :)


[...]
> Then recently I've talked to a couple of guys (separately) in 2
> Office Depots near Seattle who both told me that the Vista -> 7
> upgrade should go without any trouble at all. That I should do the
> upgrade, then immediately download and install all the updates for 7
> that MS has issued. Both used used to do such upgrades for customers
> for a fee ($40), but not anymore. 

Why did they stop? Could it be because the upgrade is sometimes 
difficult and requires huge amount of manual effort to get it working, 
far more than $40 will cover?

Cynical? Who, me?


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


Re: [Tutor] Getting an object's attributes

2010-06-26 Thread Steven D'Aprano
On Sat, 26 Jun 2010 06:39:29 pm m...@doctors.net.uk wrote:
> Dear Tutors,
>
> I have an object to which I dynamically add attributes. My question
> is how I can inspect and display them at run-time?
>
> Class a():
> pass
>
> Obj1 = a()
>
> Obj1.name = "Bob"
> Obj1.age = 45
>
> dir(a) returns a tuple which contains name and age, but also other
> things (includings methods, etc.) I could filter this tuple (checking
> for callable(), etc.)  but I just wondered if there was an existing
> way of getting just name and age.

If you know they are called name and age, just access them like you did 
above:

Obj1.name
Obj1.age


If you don't know they are called name and age, then how do you expect 
Python to know which of the many attributes and methods are the ones 
you want?

Before you start writing your own filters, you should check out the 
inspect module, which already has most of that functionality 
ready-made.

There's no general way to ask "which attributes were added dynamically?" 
because all of them are. The difference is that some of them are added 
dynamically when the class is created, some are added dynamically when 
the instance is initialised, and some are added dynamically later. But 
they're all added dynamically. Python doesn't track when attributes are 
added because, in general, it's an unimportant difference.


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


Re: [Tutor] OT: need computer advice from wise Tutors

2010-06-26 Thread Richard D. Moores
On Sat, Jun 26, 2010 at 03:10, Steven D'Aprano  wrote:
> On Sat, 26 Jun 2010 05:00:16 pm Richard D. Moores wrote:
>> Sorry about the OT, but I'm really nervous about the possibility of
>> screwing up my laptop by upgrading the OS from Vista to 7, and can't
>> think of a better place than Tutors to ask for advice.
>
> Because of course knowing Python makes you an expert on Windows :)
>
>
> [...]
>> Then recently I've talked to a couple of guys (separately) in 2
>> Office Depots near Seattle who both told me that the Vista -> 7
>> upgrade should go without any trouble at all. That I should do the
>> upgrade, then immediately download and install all the updates for 7
>> that MS has issued. Both used used to do such upgrades for customers
>> for a fee ($40), but not anymore.
>
> Why did they stop? Could it be because the upgrade is sometimes
> difficult and requires huge amount of manual effort to get it working,
> far more than $40 will cover?

Do you know that it does? Please tell me what you know.

>
> Cynical? Who, me?
>
>
> --
> Steven D'Aprano
> ___
> Tutor maillist  -  tu...@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


[Tutor] class questions

2010-06-26 Thread Payal
Hi,
Some questions about which I am a bit confused.

1. I know there is a difference between mro of classic and new style
classes. but I do not get why we need the new mro, the old one is easy
to predict and understand?

2. A friend of mine told me that in C++ abstract classes are classes
which can not be instatiated. Is she right, do we have them in python,
if yes can someone give a simple example?

3. In http://www.alan-g.me.uk/tutor/index.htm , Alan has given an
example in "User Defined Exceptions",
>>> class BrokenError(Exception): pass

Even after reading the section a few times over, I fail to get utility
of such a class. Can someone please explain with better example?
Alan can you please cleanup that section, maybe make it broader and put
the stuff about "SystemExit" elsewhere.

Thanks a lot in advance.

With warm regards,
-Payal
-- 


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


Re: [Tutor] OT: need computer advice from wise Tutors

2010-06-26 Thread Steven D'Aprano
On Sat, 26 Jun 2010 08:53:57 pm you wrote:
> > Why did they stop? Could it be because the upgrade is sometimes
> > difficult and requires huge amount of manual effort to get it
> > working, far more than $40 will cover?
>
> Do you know that it does? Please tell me what you know.

I have no idea. That's why I asked:

> > Cynical? Who, me?



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


Re: [Tutor] Use flag to exit? (OT - PEP 8 Gripe)

2010-06-26 Thread Dave Angel

Richard D. Moores wrote:

On Fri, Jun 25, 2010 at 23:42, Dave Angel  wrote:
  

Richard D. Moores wrote:


On Fri, Jun 25, 2010 at 23:08, Dave Angel  wrote:

  

Do you activate Quick-Edit mode in your DOS box?  Once you have that on,
it's not much of a pain to copy and paste, as long as what you're copying
fits a rectangle.



Yes, it's on. I agree that copying is easy, but if I can't use Ctrl+V,
pasting is a pain. Tell me your secret.

Dick


  

If you right-click on a DOS box without anything selected, then it pastes.
 (Asssuming quickedit mode)

For example, you run a command that displays a string, and you want to use
that string as your next command:

left-drag over the desired text.
Right click to copy to clipboard
Right click again to paste into current cursor position



Hey, terrific! Thanks, Dave! I didn't see any help available. Where'd
you learn this?

Dick

  
I really don't recall where I learned it, but I do remember 
approximately when.  It was about 1994, with Windows NT version 3.5



DaveA

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


Re: [Tutor] class questions

2010-06-26 Thread Steven D'Aprano
On Sat, 26 Jun 2010 10:17:45 pm Payal wrote:
> Hi,
> Some questions about which I am a bit confused.
>
> 1. I know there is a difference between mro of classic and new style
> classes. but I do not get why we need the new mro, the old one is
> easy to predict and understand?

The old MRO (Method Resolution Order) is broken for classes using 
multiple inheritance with a diamond shape inheritance diagram. Not a 
little bit broken, but horribly, horribly broken.

If you have something like this class hierarchy:

class A:
pass

class B(A):
pass

class C(A):
pass

class D(B, C):
pass


(only with actual methods, of course) then inheritance with old-style 
classes cannot work correctly in some circumstances. Fortunately this 
sort of inheritance diagram:

A
   / \
   B C
   \ /
D

is rare for old-style classes. But for new-style classes, *all* multiple 
inheritance is diamond-shaped, because all classes inherit back to 
object at the top of the diagram:

object
/\
  list   str
\/
myclass 

So in order to allow people to inherit from built-ins, we had a choice:

(1) Keep the old MRO and a bug which used to be rare would become 
common;

(2) Keep the old MRO but prohibit multiple inheritance and mixins (which 
would mean breaking a lot of existing code); or

(3) Change the MRO to one which doesn't have the bug.


The Python developers choose 3. Well, actually, that's not quite true: 
nobody noticed that the MRO was broken until *after* new-style classes 
were added in version 2.2, and so the new MRO was added in version 2.3.

http://www.python.org/download/releases/2.3/mro/


> 2. A friend of mine told me that in C++ abstract classes are classes
> which can not be instatiated. Is she right, do we have them in
> python, if yes can someone give a simple example?

Python doesn't have a special "abstract class" type, but it is easy to 
make one with just two lines of boilerplate:

class AbstractThing:
def __init__(self):
# Next two lines are boilerplate.
if type(self) is Abstract:
raise TypeError("abstract class, you must subclass this")
# init code for non-abstract Thing classes goes here


> 3. In http://www.alan-g.me.uk/tutor/index.htm , Alan has given an
> example in "User Defined Exceptions",
>
> >>> class BrokenError(Exception): pass
>
> Even after reading the section a few times over, I fail to get
> utility of such a class. Can someone please explain with better
> example? Alan can you please cleanup that section, maybe make it
> broader and put the stuff about "SystemExit" elsewhere.

The utility of user-defined exceptions is simply to allow your code to 
distinguish between *your* exceptions and other exceptions. Different 
people have different policies. Some people prefer this:


def func(x):
if x <= 0:
raise ValueError('x must be positive')
return sqrt(x) + x**2


Other people prefer this:


class DomainError(ValueError):
"""Used for mathematics domain errors."""
pass

def func(x):
if x <= 0:
raise DomainError('x must be positive')
return math.sqrt(x) + math.asin(x**2)


Then when you catch an error:


try:
print func(y)
except DomainError:
# only catches my own error
except ValueError:
# catches any other ValueError


But both solutions are equally good. Normally you don't want fifty 
different exception classes in a module, nor do you want every 
exception to be the same generic class. How finely you divide the error 
classes is up to you.



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


Re: [Tutor] need computer advice from wise Tutors

2010-06-26 Thread Wayne Werner
On Sat, Jun 26, 2010 at 3:30 AM, Alan Gauld wrote:

> "Richard D. Moores"  wrote
>
> However, to quote the old adage - "If it ain't broke, don't fix it".
> So what is the problem that you think the upgrade will fix?
>

The problem? He has Vista installed... (rimshot) ;)

-Wayne,
Also on XP (and Ubuntu...)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Creating A Simple Blog System Using Python Programming

2010-06-26 Thread Wayne Werner
On Fri, Jun 25, 2010 at 11:41 PM, F C  wrote:

>  Hi there,
>
> - I have recently decided to learn Python.
> - It is my first programming language.
> - I am new to programming.
> - I know XHTML and CSS, and a few lines of PHP.
> - I only started learning a couple of days ago.
>

Well congratulations on starting what many of us feel is a wonderful
journey! And probably most of us feel is an excellent choice for starting
out.


> What I want to do is create a simple blog system.
> Where I can
> - create posts, edit them and post them online
>

An ambitious goal... And a fairly achievable one (though of course you still
have plenty to learn at this point. I'd guess most of us who have been
programming in Python for a few years could probably knock something out in
a day or two, but I wouldn't expect results near that quick as you'll have
to learn both programming concepts and a language. But Python excels at
being a simple language to learn so you can ignore more of the "advanced"
programming topics until you're ready)


>
> Thus far, people have pointed me to frameworks.
> From what I see, the framework does the work for you...
> I want to code the blog from scratch...after all - I want to learn the
> language - I don't want something to do the work for me.
>
> I truly do not know where to start, because most of the tutorials are
> segmented, and I don't know how to structure the
> program, let alone what commands to include.
>
> I would appreciate it if someone could give me some structure advice on how
> to tackle this.
>

Well, here's what I would do:

1) Build a *simple* web form - an entry for a title, a text area for the
text of the post, and a submit/save button. You can add features later as
you feel you need them (like a login window), but for now simple is better.

2) Write a program that connects to a database (SQLite is included in most
Python installs) and allows you to insert and retrieve posts. You'll need to
learn some SQL syntax for this.

3) Hook the two together.

4) Enjoy the satisfaction of "completing" your first project.


I've really simplified the tasks here - you'll have to get a web host that
gives you access to python (or host it yourself), learn how to work with
Python+HTML (it's not that difficult, but you'll be learning several
concepts at once which adds some to the complexity), learn the SQL language
in addition to Python... and whatever else happens to pop up.

The important thing is to be able to look at the problem and break it up
into chunks. If you ask yourself these two questions: "What do I need next?"
"What can I do *now* to accomplish that?" you'll find yourself moving
rapidly towards finishing your project. That's how I came up with those
tasks - "What do I need next?" "Well, I can't post a blog without somewhere
to enter the post." - so that's the first task. What's next? Well, I have to
have a way to save the blog posts. Ooh, a database is ideal for collecting
data so I can easily retrieve it. So I'll need to be able to connect to the
DB somehow.

Once you get more familiar with programming and concepts, you'll start to be
able to break problems up into much more manageable chunks, and you'll start
to see where you can logically break your programs up into different modules
and functions - pieces of code that you can reuse as part of a larger
program.

Anyhow, good luck, and HTH!
-Wayne
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Confirm that Python 2.6 ftplib does not support Unicode file names? Alternatives?

2010-06-26 Thread python
Updating this thread for users searching the archives.

Additional commentary can be found in this thread I started on
Stackoverflow.com.
http://stackoverflow.com/questions/3120295/confirm-that-python-2-6-ftplib-does-not-support-unicode-file-names-alternatives

Gabriel Genellina added the following comment on Python-list:

According to RFC 2640, you should use UTF-8 instead. 
http://www.faqs.org/rfcs/rfc2640.html

The server software must be able to convert from file system encoding to
utf-8 and viceversa; check its configuration.

The stackoverflow thread mentioned above also contains a
workaround/ugly-hack if you need to use Unicode path/file names with
ftplib and/or a file server that does not support Unicode path/file
names.

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


Re: [Tutor] class questions

2010-06-26 Thread Payal
Thanks a lot for the quick answer. Still some doubts below.

On Sat, Jun 26, 2010 at 11:07:17PM +1000, Steven D'Aprano wrote:
> The old MRO (Method Resolution Order) is broken for classes using 
> multiple inheritance with a diamond shape inheritance diagram. Not a 
> little bit broken, but horribly, horribly broken.
> 
> If you have something like this class hierarchy:
[...]
> (only with actual methods, of course) then inheritance with old-style 
> classes cannot work correctly in some circumstances. Fortunately this 

Can you give any simple example where this simple mro will work
incorrectly? i read,
http://www.python.org/download/releases/2.3/mro/
butdid not get where mro will fail (ofcourse if python implemented it
corrrectly).

> is rare for old-style classes. But for new-style classes, *all* multiple 
> inheritance is diamond-shaped, because all classes inherit back to 
> object at the top of the diagram:

still not getting , how do the new style classes solve the problem (if
there was any).

> Python doesn't have a special "abstract class" type, but it is easy to 
> make one with just two lines of boilerplate:
[...]

Sorry, I am not getting it. I get,
NameError: global name 'Abstract' is not defined
Was that a working code? (cos' I do not know what you mean by
boilerplate)

> class DomainError(ValueError):
> """Used for mathematics domain errors."""
> pass

Can we say that our own exception classes have only maybe a doc-string
and pass, nothing more?

Thanks a lot again.
With warm regards,
-Payal
-- 


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


Re: [Tutor] Creating A Simple Blog System Using Python Programming

2010-06-26 Thread Vern Ceder

F C wrote:

Hi there,

- I have recently decided to learn Python.
- It is my first programming language.
- I am new to programming.
- I know XHTML and CSS, and a few lines of PHP.
- I only started learning a couple of days ago.

What I want to do is create a simple blog system.
Where I can
- create posts, edit them and post them online

Thus far, people have pointed me to frameworks.
 From what I see, the framework does the work for you...
I want to code the blog from scratch...after all - I want to learn the 
language - I don't want something to do the work for me.


Managing the details of a framework could distract you from the basics 
of  learning Python, IMHO, but they do make a lot things much easier.


As it happens, I use a similar example (a message wall) in my book, The 
Quick Python Book, 2nd ed. (see link in my sig).


While I can't reproduce that chapter here, I can tell you that you want 
to use the wsgiref server included in the Python standard library, and 
you should read through the online docs and examples for the wsgiref 
module on the python.org site. Then for storage of your posts, you might 
just want to use text files at first, and then consider picking up 
sqlite3 or another database later on.


Cheers,
Vern


I truly do not know where to start, because most of the tutorials are 
segmented, and I don't know how to structure the

program, let alone what commands to include.

I would appreciate it if someone could give me some structure advice on 
how to tackle this.


Many thanks to the person(s) who can help.

Australia's #1 job site If It Exists, You'll Find it on SEEK 






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


--
This time for sure!
   -Bullwinkle J. Moose
-
Vern Ceder, Director of Technology
Canterbury School, 3210 Smith Road, Ft Wayne, IN 46804
vce...@canterburyschool.org; 260-436-0746; FAX: 260-436-5137

The Quick Python Book, 2nd Ed - http://bit.ly/bRsWDW
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] OT: need computer advice from wise Tutors

2010-06-26 Thread Sithembewena Lloyd Dube
Richard, I think you may go ahead without trepidation. I am not a Windows
fan at all, I prefer Ubuntu. But I started using Win. 7 at work about a
month ago, and I have to say it hasn't given me cause to grumble.

Of course, a month is hardly sufficient time to have a strong opinion, but I
can tell you that it works just fine.

On Sat, Jun 26, 2010 at 2:39 PM, Steven D'Aprano wrote:

> On Sat, 26 Jun 2010 08:53:57 pm you wrote:
> > > Why did they stop? Could it be because the upgrade is sometimes
> > > difficult and requires huge amount of manual effort to get it
> > > working, far more than $40 will cover?
> >
> > Do you know that it does? Please tell me what you know.
>
> I have no idea. That's why I asked:
>
> > > Cynical? Who, me?
>
>
>
> --
> Steven D'Aprano
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
Regards,
Sithembewena Lloyd Dube
http://www.lloyddube.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] OT: need computer advice from wise Tutors

2010-06-26 Thread Richard D. Moores
On Sat, Jun 26, 2010 at 11:55, Sithembewena Lloyd Dube
 wrote:
> Richard, I think you may go ahead without trepidation. I am not a Windows
> fan at all, I prefer Ubuntu. But I started using Win. 7 at work about a
> month ago, and I have to say it hasn't given me cause to grumble.
>
> Of course, a month is hardly sufficient time to have a strong opinion, but I
> can tell you that it works just fine.

Thanks, but I'm not worried about Win 7 working well when perfectly
installed. I'm concerned that if I upgrade to 7 from Vista using the
upgrade disk I have, that THAT 7 on my laptop will end up with
problems caused by the install.

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


Re: [Tutor] OT: need computer advice from wise Tutors

2010-06-26 Thread Sithembewena Lloyd Dube
Hi Dick,

In that case, perhaps you could externally back up all your important stuff
and then format your hard disk. That way, any drivers etc intended for
Windows Vista will be wiped off, and you can then perform a clean
installation from your disk. Now, as far as upgrade disks go, I do not know
whether it will work as a "clean installation" disk, or whether it is only
meant for use on an existing windows installation (hence the name
"upgrade"). You might want to check that out first.

Let us know how it goes.

On Sat, Jun 26, 2010 at 10:31 PM, Richard D. Moores wrote:

> On Sat, Jun 26, 2010 at 11:55, Sithembewena Lloyd Dube
>  wrote:
> > Richard, I think you may go ahead without trepidation. I am not a Windows
> > fan at all, I prefer Ubuntu. But I started using Win. 7 at work about a
> > month ago, and I have to say it hasn't given me cause to grumble.
> >
> > Of course, a month is hardly sufficient time to have a strong opinion,
> but I
> > can tell you that it works just fine.
>
> Thanks, but I'm not worried about Win 7 working well when perfectly
> installed. I'm concerned that if I upgrade to 7 from Vista using the
> upgrade disk I have, that THAT 7 on my laptop will end up with
> problems caused by the install.
>
> Dick
>



-- 
Regards,
Sithembewena Lloyd Dube
http://www.lloyddube.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] class questions

2010-06-26 Thread Eike Welk
Hello Payal!

On Saturday June 26 2010 19:05:16 Payal wrote:
> Can we say that our own exception classes have only maybe a doc-string
> and pass, nothing more?

No, you let the exception transport the information that you need for handling 
the error. This is an exception that I use to transport user visible error 
messages in a compiler, that I write as a hobby:


class UserException(Exception):
'''Exception that transports user visible error messages.'''
def __init__(self, message, loc=None, errno=None):
Exception.__init__(self)
self.msg = message
self.loc = loc
self.errno = errno

def __str__(self):
if self.errno is None:
num_str = ''
else:
num_str = '(#%s) ' % str(self.errno) 
return 'Error! ' + num_str + self.msg + '\n' + str(self.loc) + '\n'

def __repr__(self):
return self.__class__.__name__ + str((self.msg, self.loc, 
  self.errno))

It contains:
self.msg : The error message
self.loc : An object encoding the location of the error in the program's
   text. Together with the file name and the text.
self.errno : An integer to identify the error, for the test framework.

That said; the expression's type and the error message are often sufficient to 
handle the error.


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


[Tutor] Advice on math

2010-06-26 Thread Eduardo Vieira
Hello, I've enjoying learning python for the first few years, and
appreciate all the help I have received from this list. I had some
interest in programming and am very glad to have made python my choice
of programming language. Since I didn't go to college for computer
studies, I feel my math is kind of rusty in some areas, and looks like
improving/regaining math skills would help a lot in programming,
logic, algorithms, etc.
Right now I think I need a better understanding of logarithm, arrays
(matrixes), and even probability. What links would you all recommend
that would be useful for me to learn these things in a newbie-friendly
way?

With thankfulness,

Eduardo
www.expresssignproducts.com
www.express-sign-supply.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Advice on math

2010-06-26 Thread Shashwat Anand
On Sun, Jun 27, 2010 at 2:50 AM, Eduardo Vieira wrote:

> Hello, I've enjoying learning python for the first few years, and
> appreciate all the help I have received from this list. I had some
> interest in programming and am very glad to have made python my choice
> of programming language. Since I didn't go to college for computer
> studies, I feel my math is kind of rusty in some areas, and looks like
> improving/regaining math skills would help a lot in programming,
> logic, algorithms, etc.
> Right now I think I need a better understanding of logarithm, arrays
> (matrixes), and even probability. What links would you all recommend
> that would be useful for me to learn these things in a newbie-friendly
> way?
>
>
>
If you want to code+learn, nothing beats ProjectEuler (
http://projecteuler.net/ ). However I assume you have basic understanding of
maths.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] OT: need computer advice from wise Tutors

2010-06-26 Thread Richard D. Moores
On Sat, Jun 26, 2010 at 13:39, Sithembewena Lloyd Dube
 wrote:
> Hi Dick,
>
> In that case, perhaps you could externally back up all your important stuff
> and then format your hard disk. That way, any drivers etc intended for
> Windows Vista will be wiped off, and you can then perform a clean
> installation from your disk. Now, as far as upgrade disks go, I do not know
> whether it will work as a "clean installation" disk, or whether it is only
> meant for use on an existing windows installation (hence the name
> "upgrade"). You might want to check that out first.

I don't believe the disk I have will enable a clean installation.

I found a relevant thread in the WindowsSecrets Lounge:
, which seems to have some good
info and advice.

> Let us know how it goes.

OK.

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


Re: [Tutor] Advice on math

2010-06-26 Thread Alan Gauld


"Eduardo Vieira"  wrote


Right now I think I need a better understanding of logarithm, arrays
(matrixes), and even probability. What links would you all recommend
that would be useful for me to learn these things in a 
newbie-friendly

way?


Wikipedia?
Pretty good on most things math and science bawsed.
Just stop reading when it gets too deep - as it invariably will! :-)

Alan G. 



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


Re: [Tutor] OT: need computer advice from wise Tutors

2010-06-26 Thread Marc Tompkins
On Sat, Jun 26, 2010 at 2:30 PM, Richard D. Moores wrote:

> On Sat, Jun 26, 2010 at 13:39, Sithembewena Lloyd Dube
>  wrote:
> > Hi Dick,
> >
> > In that case, perhaps you could externally back up all your important
> stuff
> > and then format your hard disk. That way, any drivers etc intended for
> > Windows Vista will be wiped off, and you can then perform a clean
> > installation from your disk. Now, as far as upgrade disks go, I do not
> know
> > whether it will work as a "clean installation" disk, or whether it is
> only
> > meant for use on an existing windows installation (hence the name
> > "upgrade"). You might want to check that out first.
>
> I don't believe the disk I have will enable a clean installation.
>
I'm pretty sure it will:
http://www.winsupersite.com/win7/clean_install_upgrade_media.asp
http://www.mydigitallife.info/2009/10/27/clean-install-windows-7-with-upgrade-media-and-product-key-on-formatted-or-empty-blank-hard-drive/

The upshot of both those articles is: boot from the upgrade disk as if it
were a normal Full Install disk; when it asks for the Windows key, leave it
blank.  Don't enter the key until after the installation is complete, when
you want to activate.

Since you CAN use that disk as a clean install, I definitely recommend that
you DO.  When I upgraded my laptop to Windows 7, I bought myself a new 500GB
hard drive for the purpose.  $60 and five minutes with a small screwdriver
brought me a huge dividend in peace of mind.

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


Re: [Tutor] Getting an object's attributes

2010-06-26 Thread mhw
Apol. For TP:

This is perfect - thanks.
Matt
Sent from my BlackBerry® wireless device

-Original Message-
From: Evert Rol 
Date: Sat, 26 Jun 2010 11:13:16 
To: 
Cc: Python tutor
Subject: Re: [Tutor] Getting an object's attributes

> I have an object to which I dynamically add attributes. My question is how I 
> can inspect and display them at run-time?
> 
> Class a():
>pass
> 
> Obj1 = a()
> 
> Obj1.name = "Bob"
> Obj1.age = 45

First off, a few suggestions:
- you probably mean 'class', not 'Class' (sorry, but it's just that correct 
actual code helps: copy-paste from the Python prompt when you can. If you have 
a text-editor in your mail program that capitalises things, be careful when 
pasting code).
- use capitalisation (or CamelCase) for class names, lowercase for instances: 
class A, obj1 = A(). This is the usual Python convention.
- I would use new-style classes, ie, inherit from object:
>>> class A(object):
...   pass
... 
>>> obj1 = A()



> dir(a) returns a tuple which contains name and age, but also other things 
> (includings methods, etc.) I could filter this tuple (checking for 
> callable(), etc.)  but I just wondered if there was an existing way of 
> getting just name and age.

Normally, you know which attributes you want to access, so you wouldn't have 
this problem. Better yet, you wrap things in a try-except clause and see if 
that works:
>>> try:
... obj1.name
... except AttributeError:
... print "not there"
... 
not there

 
But for this case, when using new-style classes, obj1.__dict__ can help you (or 
obj1.__dict__.keys() ). 
>>> obj1.name = "Bob"
>>> obj1.age = 45
>>> obj1.__dict__
{'age': 45, 'name': 'Bob'}

Or, perhaps somewhat silly: set(dir(obj1)) - set(dir(A)).
>>> set(dir(obj1)) - set(dir(A))
set(['age', 'name'])

but I wouldn't recommend that.

See eg http://docs.python.org/library/stdtypes.html#special-attributes


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


Re: [Tutor] class questions

2010-06-26 Thread Christopher King
Well the application of defining ones own error is in a module. For example,
if I make a banking account module, I might define a WithdrawError if there
is a place where a error might occur. That way if client code tries to
withdraw too much, you can have a very descriptive error making it easier to
understand.

On Sat, Jun 26, 2010 at 8:17 AM, Payal wrote:

> Hi,
> Some questions about which I am a bit confused.
>
> 1. I know there is a difference between mro of classic and new style
> classes. but I do not get why we need the new mro, the old one is easy
> to predict and understand?
>
> 2. A friend of mine told me that in C++ abstract classes are classes
> which can not be instatiated. Is she right, do we have them in python,
> if yes can someone give a simple example?
>
> 3. In http://www.alan-g.me.uk/tutor/index.htm , Alan has given an
> example in "User Defined Exceptions",
> >>> class BrokenError(Exception): pass
>
> Even after reading the section a few times over, I fail to get utility
> of such a class. Can someone please explain with better example?
> Alan can you please cleanup that section, maybe make it broader and put
> the stuff about "SystemExit" elsewhere.
>
> Thanks a lot in advance.
>
> With warm regards,
> -Payal
> --
>
>
> ___
> 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


Re: [Tutor] class questions

2010-06-26 Thread Christopher King
only new classes can have properties, a major tool

On Sat, Jun 26, 2010 at 8:17 AM, Payal wrote:

> Hi,
> Some questions about which I am a bit confused.
>
> 1. I know there is a difference between mro of classic and new style
> classes. but I do not get why we need the new mro, the old one is easy
> to predict and understand?
>
> 2. A friend of mine told me that in C++ abstract classes are classes
> which can not be instatiated. Is she right, do we have them in python,
> if yes can someone give a simple example?
>
> 3. In http://www.alan-g.me.uk/tutor/index.htm , Alan has given an
> example in "User Defined Exceptions",
> >>> class BrokenError(Exception): pass
>
> Even after reading the section a few times over, I fail to get utility
> of such a class. Can someone please explain with better example?
> Alan can you please cleanup that section, maybe make it broader and put
> the stuff about "SystemExit" elsewhere.
>
> Thanks a lot in advance.
>
> With warm regards,
> -Payal
> --
>
>
> ___
> 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


Re: [Tutor] finally

2010-06-26 Thread Christopher King
sorry, my reply to all button goofed up

On Sat, Jun 26, 2010 at 7:43 PM, Steven D'Aprano wrote:

> Hi Christopher,
>
> Are you aware you have written directly to me instead of the tutor
> mailing list? It's normally considered rude to do so, unless your
> message truly is meant to be private.
>
>
> On Sun, 27 Jun 2010 09:24:22 am you wrote:
> > what about more complex cleanup code, like saving data or showing a
> > error message
> > how would the with statement coop with that
>
> Exactly the same as simple cleanup code. Just be careful not to rely on
> things which may not have happened inside the try block. E.g. this
> won't work:
>
> x = something()
> try:
>y = x - 8
>z = 100/y
> finally:
>write_data_file(x, y, z)
>
> This will fail if something() returns 8, because z won't be defined, and
> your cleanup block itself will raise a NameError exception.
>
>
> --
> Steven D'Aprano
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] OT: need computer advice from wise Tutors

2010-06-26 Thread Steven D'Aprano
On Sun, 27 Jun 2010 04:55:13 am Sithembewena Lloyd Dube wrote:
> Richard, I think you may go ahead without trepidation. I am not a
> Windows fan at all, I prefer Ubuntu. But I started using Win. 7 at
> work about a month ago, and I have to say it hasn't given me cause to
> grumble.

I don't think Richard is asking whether Windows 7 is worth using. I 
think he's asking, is it painful to upgrade from Vista to Windows 7.


> Of course, a month is hardly sufficient time to have a strong
> opinion, but I can tell you that it works just fine.

Apart from:

having no default email client (what sort of two-bit operating system 
doesn't have an email client in 2010?);

the automatic upgrades that run silently in the background with no easy 
way to turn them on or off (always fun when your Internet download cap 
is completely used up TWO DAYS into the month -- especially when you 
don't know because you can't read the email from your ISP due to not 
having an email client, and you can't download one because all the 
available bandwidth is being consumed by the updates);

the gratuitous UI changes (am I missing something, or does Internet 
Explorer no longer have a menubar?);

the use of third-party applications like Adobe Acrobat Reader which have 
become overloaded with *stupid* security vulnerabilities *by design* 
(years after Microsoft themselves got burnt, time and time again, by 
allowing the web-browser and mail client to execute random code found 
on the internet, somebody at Adobe apparently thought it would be a 
good idea for the PDF reader to do the same thing *facepalms*); and

consequently the proliferation of adware and spyware (even 
the "legitimate" anti-malware companies fill your browser with ad-laden 
toolbars and try terrifying the user with "your computer is 
unprotected" warnings -- no wonder the average user can't tell the 
difference between legitimate anti-malware and trojan horses).

On the other hand, it is quite pretty.

(Yes, I am speaking from experience. Everything I have mentioned I have 
seen with my own eyes.)


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


[Tutor] socket

2010-06-26 Thread Christopher King
   I'm wondering how to allow one process to communicate with another
process. In other words, I want to connect two computers. I've looked up
socket but the explanations are too complex. I think I need a 2-way
conversation with a expert to understand it. Or even better, point me to a
easier module.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] class questions

2010-06-26 Thread Steven D'Aprano
On Sun, 27 Jun 2010 03:05:16 am Payal wrote:
> Thanks a lot for the quick answer. Still some doubts below.
>
> On Sat, Jun 26, 2010 at 11:07:17PM +1000, Steven D'Aprano wrote:
> > The old MRO (Method Resolution Order) is broken for classes using
> > multiple inheritance with a diamond shape inheritance diagram. Not
> > a little bit broken, but horribly, horribly broken.
> >
> > If you have something like this class hierarchy:
>
> [...]
>
> > (only with actual methods, of course) then inheritance with
> > old-style classes cannot work correctly in some circumstances.
> > Fortunately this
>
> Can you give any simple example where this simple mro will work
> incorrectly?

Probably not... it's quite complicated, which is why it's rare. I'll 
have a think about it and see what I can come up with.


> i read, 
> http://www.python.org/download/releases/2.3/mro/
> butdid not get where mro will fail (ofcourse if python implemented it
> corrrectly).

I think you have misunderstood, which is probably my fault. It's not 
that the implementation of the classic MRO was buggy, but that the MRO 
*itself* does not work as wanted. That's why the fix wasn't "just fix 
the code", but "change the MRO".


> > is rare for old-style classes. But for new-style classes, *all*
> > multiple inheritance is diamond-shaped, because all classes inherit
> > back to object at the top of the diagram:
>
> still not getting , how do the new style classes solve the problem
> (if there was any).

By changing the MRO, new-style classes avoid the problem completely. I 
know it's hard to understand without seeing an example, sorry.


> > Python doesn't have a special "abstract class" type, but it is easy
> > to make one with just two lines of boilerplate:
>
> [...]
>
> Sorry, I am not getting it. I get,
> NameError: global name 'Abstract' is not defined

Oops! That was my fault. I changed the name of the class from Abstract 
to AbstractThing but only changed it in one place. Oh, and I had 
another bug in it too. Here's the code corrected, and tested this time:

class AbstractThing(object):
    def __init__(self):
        # Next two lines are boilerplate.
        if type(self) is AbstractThing:
            raise TypeError("abstract class, you must subclass this")
        # init code for non-abstract Thing classes goes here

class MyThing(AbstractThing):
pass

x = MyThing()  # works
y = AbstractThing()  # fails



> Was that a working code? (cos' I do not know what you mean by
> boilerplate)

"Boilerplate" means the sort of boring code that doesn't actually solve 
your problem, but just sets things up for the rest of your code to 
solve your problem. Boilerplate is usually bad because you have to 
repeat it over and over again, e.g. declarations in languages like 
Pascal, C or Java.  The amount of boilerplate sometimes exceeds the 
amount of code actually doing something!

If you have a class with twenty methods that all start like this:

def method(self, other):
if other is None:
 other = something_else
# more code here

you'll quickly get bored and frustrated writing the if clause. 
Especially when later on you realise that you mean something_different 
instead of something_else, and now you have to go back and change it in 
twenty places instead of one. *That's* boilerplate.



> > class DomainError(ValueError):
> > """Used for mathematics domain errors."""
> > pass
>
> Can we say that our own exception classes have only maybe a
> doc-string and pass, nothing more?

Technically speaking, if you have a doc string, you don't need the 
pass :)

This is a common design pattern. It is creating a new exception that is 
exactly the same as ValueError but with a different name. But that's 
not all you can do -- you can add as much, or as little, functionality 
to the exception subclass as you like.



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


Re: [Tutor] OT: need computer advice from wise Tutors

2010-06-26 Thread Richard D. Moores
On Sat, Jun 26, 2010 at 15:04, Marc Tompkins  wrote:
> On Sat, Jun 26, 2010 at 2:30 PM, Richard D. Moores 
> wrote:
>>
>> On Sat, Jun 26, 2010 at 13:39, Sithembewena Lloyd Dube
>>  wrote:
>> > Hi Dick,
>> >
>> > In that case, perhaps you could externally back up all your important
>> > stuff
>> > and then format your hard disk. That way, any drivers etc intended for
>> > Windows Vista will be wiped off, and you can then perform a clean
>> > installation from your disk. Now, as far as upgrade disks go, I do not
>> > know
>> > whether it will work as a "clean installation" disk, or whether it is
>> > only
>> > meant for use on an existing windows installation (hence the name
>> > "upgrade"). You might want to check that out first.
>>
>> I don't believe the disk I have will enable a clean installation.
>
> I'm pretty sure it will:
> http://www.winsupersite.com/win7/clean_install_upgrade_media.asp
> http://www.mydigitallife.info/2009/10/27/clean-install-windows-7-with-upgrade-media-and-product-key-on-formatted-or-empty-blank-hard-drive/
>
> The upshot of both those articles is: boot from the upgrade disk as if it
> were a normal Full Install disk; when it asks for the Windows key, leave it
> blank.  Don't enter the key until after the installation is complete, when
> you want to activate.
>
> Since you CAN use that disk as a clean install, I definitely recommend that
> you DO.  When I upgraded my laptop to Windows 7, I bought myself a new 500GB
> hard drive for the purpose.  $60 and five minutes with a small screwdriver
> brought me a huge dividend in peace of mind.

I have to get some sleep right now, but I'll give your suggestion
serious consideration when I get up.

Thanks very much, Marc.

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