[Tutor] http://www.google.com/coop/cse?cx=010104417661136834118%3Aat1-hsftvfo

2006-10-25 Thread anil maran
http://www.google.com/coop/cse?cx=010104417661136834118%3Aat1-hsftvfo

Anil

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] OOP and Python.. a gentle remark

2006-10-25 Thread Asrarahmed Kadri
 
 
Folks...
 
Please dont take it in a wrong sense. But I have a point to make regarding OOP and the way it is implemented in Python.
 
 Why is it necessary to explicity use self argument in the class functions ?? I feel the language/interpreter should figure out which object has called the function? Isnt it ? (the use of 'self' keyword really confuses me. and to make matter worse the variables can be accessed from outside teh class. Isnt it a violation of the OOP principle of ENCAPSULATION)

 
Also please let me know hwo can we declare PRIVATE VARIABLES in Python...??
 
Regards,
Asrarahmed
 
P.S. : I love Python. :)--- To HIM you shall return. 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] OOP and Python.. a gentle remark

2006-10-25 Thread Simon Brunning
On 10/25/06, Asrarahmed Kadri <[EMAIL PROTECTED]> wrote:
>  Why is it necessary to explicity use self argument in the class functions
> ?? I feel the language/interpreter should figure out which object has called
> the function? Isnt it ? (the use of 'self' keyword really confuses me. and
> to make matter worse the variables can be accessed from outside teh class.
> Isnt it a violation of the OOP principle of ENCAPSULATION)



> Also please let me know hwo can we declare PRIVATE VARIABLES in Python...??



-- 
Cheers,
Simon B
[EMAIL PROTECTED]
http://www.brunningonline.net/simon/blog/
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] OOP and Python.. a gentle remark

2006-10-25 Thread euoar
Asrarahmed Kadri escribió:
>  
>  
> Folks...
>  
> Please dont take it in a wrong sense. But I have a point to make 
> regarding OOP and the way it is implemented in Python.
>  
>  Why is it necessary to explicity use self argument in the class 
> functions ?? I feel the language/interpreter should figure out which 
> object has called the function? Isnt it ? (the use of 'self' keyword 
> really confuses me. and to make matter worse the variables can be 
> accessed from outside teh class. Isnt it a violation of the OOP 
> principle of ENCAPSULATION)
>  
> Also please let me know hwo can we declare PRIVATE VARIABLES in 
> Python...??
>  
> Regards,
> Asrarahmed
>  
> P.S. : I love Python. :)-
>
> -- 
> To HIM you shall return.
> 
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>   
That's something that I also don't understand, but I'm just a beginner 
in python, coming from java and C#, where this is not necessary. It 
seems to me quite annoying having to write this "self" each time, and I 
think it makes the code less readable. I have googled a little to see if 
there is an explanation to this particularity, with no sucess, so I will 
pay much attention to the answers here...




__ 
LLama Gratis a cualquier PC del Mundo. 
Llamadas a fijos y móviles desde 1 céntimo por minuto. 
http://es.voice.yahoo.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] OOP and Python.. a gentle remark

2006-10-25 Thread Andrei
Asrarahmed Kadri  googlemail.com> writes:

> the use of 'self' keyword really confuses me. 

I see how it can annoy you, but not how it can *confuse* you - if anything,
"self" removes any confusion about whether you're looking at a local variable or
an object property. By the way, the use of special identifiers is not uncommon
in dynamic languages. Ruby for example uses the prefixes @, @@ and $ to define
variable scope (which are not particularly self-explanatory - I think they're
class, instance and global vars) and keywords (private, protected, public) to
define method visibility. 

> and to make matter worse the variables can be accessed from outside teh 
> class. 
> Isnt it a violation of the OOP principle of ENCAPSULATION)

Python has conventions for this: prepend _ for protected and __ for private
(private names get mangled). In an interactive session:

  >>> class a(object):
  ... def _protected(s): # don't *have* to use "self" :)
  ... print s
  ... def __private(s):
  ... print "private"
  >>> A = a()
  >>> A._protected()
  <__main__.a object at 0x00AF2E10>
  >>> A.__private()
  Traceback (most recent call last):
File "", line 1, in ?
  AttributeError: 'a' object has no attribute '__private'

Lets's examine what's happened:

  >>> dir(A) 
  [, '_a__private', '_protected']

See, __private was mangled to _a__private. We can still access it of course:

  >>> A._a__private()
  private

Python approaches the programmer as a responsible person: if I see a method name
is mangled (or marked with _), I know I'm not supposed to use it - but can use
it if I really need to (and suffer the consequences if the next version of the
class breaks my code). 
Other languages choose the opposite approach: private is private, don't trust
the programmer, tough luck if you really really need access to that private.
Unfortunately you will invariably encounter cases when you need to access
privates and these are major PITA's. Usually you can get your hands on the
secret stuff, it's just very annoying and silly (e.g. by creating shadow classes
or other workarounds).

In the end it comes down to a choice between making some unavoidable cases very
cumbersome to deal with, or trusting the programmer to do the right thing -
thereby making it easier to stick his grubby little fingers in places where he
shouldn't. Some people prefer the former, some the latter.

Yours,

Andrei

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


Re: [Tutor] OOP and Python.. a gentle remark

2006-10-25 Thread Alan Gauld

"Asrarahmed Kadri" <[EMAIL PROTECTED]> wrote
> Why is it necessary to explicity use self argument in the class 
> functions

Because Guido made it that way. :-)
But he did it for good reasons which others have pointed out already.

Although languages like C++ and Java use implicit object references,
you can make them explicit with the 'this' keyword and most industrial
coding standards mandate that 'this' be used when referencing class
level variables inside methods. As in so many things Python simply
takes best practice and makes it mandatory.

> the function? Isnt it ? (the use of 'self' keyword really confuses 
> me. and

If its the actual term 'self' then you can change it to anything
you prefer. C++/Java programmers might prefer 'this', some
others have used 'my':

class C:
  def __init__(my, aValue):
 my.value = aValue

is perfectly valid Python.

> to make matter worse the variables can be accessed from outside teh 
> class.
> Isnt it a violation of the OOP principle of ENCAPSULATION)

The original OOP concept of encapsulation refers to the ability
to bind functions and data together in a single unit - a class or
object - and had nothing to do with data hiding which is the ability
to conceal the implementation details behind an API.

It was only after C++ came out with its gazillion access
controls (public, private, protected, friend etc) that people started
to confuse data hiding and encapsulation. Many early OOP
languages (most Lisps included) do not offer explicit or strict
data hiding.

> Also please let me know hwo can we declare
> PRIVATE VARIABLES in Python...??

Why do you think you need them?
Do you frequently hit bugs because you couldn't resist the
urge to access members directly? While there can be problems
with badly behaved programmers on large projects, in the
things Python is typically used for its very rarely a problem.

And it can add significantly to the complexity of the code
when you try to derive a class from one with private data.
Very few designers are sufficiently ppsychic to predict
exactly how all future users will want to modify their class!
The result is they supply get/set methods for all data which
are simply pass through methods. In doing so they
completely annull any benefit of private members and
introduce potential performance problems.

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] OOP and Python.. a gentle remark

2006-10-25 Thread Chris Hengge
I dont know about the rest of you, but this thread posting from Alan cleared up some fuzzyness I've had about classes. /me is happier using this. instead of self. =DGreat post!
On 10/25/06, Alan Gauld <[EMAIL PROTECTED]> wrote:
"Asrarahmed Kadri" <[EMAIL PROTECTED]> wrote> Why is it necessary to explicity use self argument in the class> functionsBecause Guido made it that way. :-)
But he did it for good reasons which others have pointed out already.Although languages like C++ and Java use implicit object references,you can make them explicit with the 'this' keyword and most industrial
coding standards mandate that 'this' be used when referencing classlevel variables inside methods. As in so many things Python simplytakes best practice and makes it mandatory.> the function? Isnt it ? (the use of 'self' keyword really confuses
> me. andIf its the actual term 'self' then you can change it to anythingyou prefer. C++/Java programmers might prefer 'this', someothers have used 'my':class C:  def __init__(my, aValue):
 my.value = aValueis perfectly valid Python.> to make matter worse the variables can be accessed from outside teh> class.> Isnt it a violation of the OOP principle of ENCAPSULATION)
The original OOP concept of encapsulation refers to the abilityto bind functions and data together in a single unit - a class orobject - and had nothing to do with data hiding which is the abilityto conceal the implementation details behind an API.
It was only after C++ came out with its gazillion accesscontrols (public, private, protected, friend etc) that people startedto confuse data hiding and encapsulation. Many early OOPlanguages (most Lisps included) do not offer explicit or strict
data hiding.> Also please let me know hwo can we declare> PRIVATE VARIABLES in Python...??Why do you think you need them?Do you frequently hit bugs because you couldn't resist theurge to access members directly? While there can be problems
with badly behaved programmers on large projects, in thethings Python is typically used for its very rarely a problem.And it can add significantly to the complexity of the codewhen you try to derive a class from one with private data.
Very few designers are sufficiently ppsychic to predictexactly how all future users will want to modify their class!The result is they supply get/set methods for all data whichare simply pass through methods. In doing so they
completely annull any benefit of private members andintroduce potential performance problems.HTH,--Alan GauldAuthor 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
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] OOP and Python.. a gentle remark

2006-10-25 Thread Asrarahmed Kadri
 
Thanks a lot for explanation.
 
Regards,
Asrarahmed 
On 10/25/06, Alan Gauld <[EMAIL PROTECTED]> wrote:
"Asrarahmed Kadri" <[EMAIL PROTECTED]> wrote
> Why is it necessary to explicity use self argument in the class> functionsBecause Guido made it that way. :-)But he did it for good reasons which others have pointed out already.Although languages like C++ and Java use implicit object references,
you can make them explicit with the 'this' keyword and most industrialcoding standards mandate that 'this' be used when referencing classlevel variables inside methods. As in so many things Python simplytakes best practice and makes it mandatory.
> the function? Isnt it ? (the use of 'self' keyword really confuses> me. andIf its the actual term 'self' then you can change it to anythingyou prefer. C++/Java programmers might prefer 'this', some
others have used 'my':class C:def __init__(my, aValue):my.value = aValueis perfectly valid Python.> to make matter worse the variables can be accessed from outside teh> class.
> Isnt it a violation of the OOP principle of ENCAPSULATION)The original OOP concept of encapsulation refers to the abilityto bind functions and data together in a single unit - a class orobject - and had nothing to do with data hiding which is the ability
to conceal the implementation details behind an API.It was only after C++ came out with its gazillion accesscontrols (public, private, protected, friend etc) that people startedto confuse data hiding and encapsulation. Many early OOP
languages (most Lisps included) do not offer explicit or strictdata hiding.> Also please let me know hwo can we declare> PRIVATE VARIABLES in Python...??Why do you think you need them?
Do you frequently hit bugs because you couldn't resist theurge to access members directly? While there can be problemswith badly behaved programmers on large projects, in thethings Python is typically used for its very rarely a problem.
And it can add significantly to the complexity of the codewhen you try to derive a class from one with private data.Very few designers are sufficiently ppsychic to predictexactly how all future users will want to modify their class!
The result is they supply get/set methods for all data whichare simply pass through methods. In doing so theycompletely annull any benefit of private members andintroduce potential performance problems.
HTH,--Alan GauldAuthor of the Learn to Program web sitehttp://www.freenetpages.co.uk/hp/alan.gauld___
Tutor maillist  -  Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor
-- To HIM you shall return. 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] OOP and Python.. a gentle remark

2006-10-25 Thread Asrarahmed Kadri
Chris, you are right.
He (Alan) hits the bull's eye, always !!
 
Cheers...
 
Asrarahmed 
On 10/25/06, Chris Hengge <[EMAIL PROTECTED]> wrote:
I dont know about the rest of you, but this thread posting from Alan cleared up some fuzzyness I've had about classes. /me is happier using this. instead of self. =D
Great post! 

On 10/25/06, Alan Gauld <[EMAIL PROTECTED]
> wrote: 
"Asrarahmed Kadri" <
[EMAIL PROTECTED]> wrote> Why is it necessary to explicity use self argument in the class> functionsBecause Guido made it that way. :-) But he did it for good reasons which others have pointed out already.
Although languages like C++ and Java use implicit object references,you can make them explicit with the 'this' keyword and most industrial coding standards mandate that 'this' be used when referencing class
level variables inside methods. As in so many things Python simplytakes best practice and makes it mandatory.> the function? Isnt it ? (the use of 'self' keyword really confuses > me. and
If its the actual term 'self' then you can change it to anythingyou prefer. C++/Java programmers might prefer 'this', someothers have used 'my':class C:  def __init__(my, aValue):  my.value = aValue
is perfectly valid Python.> to make matter worse the variables can be accessed from outside teh> class.> Isnt it a violation of the OOP principle of ENCAPSULATION) The original OOP concept of encapsulation refers to the ability
to bind functions and data together in a single unit - a class orobject - and had nothing to do with data hiding which is the abilityto conceal the implementation details behind an API. It was only after C++ came out with its gazillion access
controls (public, private, protected, friend etc) that people startedto confuse data hiding and encapsulation. Many early OOPlanguages (most Lisps included) do not offer explicit or strict data hiding.
> Also please let me know hwo can we declare> PRIVATE VARIABLES in Python...??Why do you think you need them?Do you frequently hit bugs because you couldn't resist theurge to access members directly? While there can be problems 
with badly behaved programmers on large projects, in thethings Python is typically used for its very rarely a problem.And it can add significantly to the complexity of the codewhen you try to derive a class from one with private data. 
Very few designers are sufficiently ppsychic to predictexactly how all future users will want to modify their class!The result is they supply get/set methods for all data whichare simply pass through methods. In doing so they 
completely annull any benefit of private members andintroduce potential performance problems.HTH,--Alan GauldAuthor of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld___Tutor maillist  -  
Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor
___Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor-- To HIM you shall return. 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Self, Scopes and my unbelievable muddleheadedness.

2006-10-25 Thread doug shawhan
I'm having a rather difficult time understanding the proper use of "self".

I have two functions (yes, they are ugly, I was getting ready to split
them in to smaller bits when this particular hole in my skull opened
up) in a module. They use the same list of dictionaries to create some
tables in a gadfly database.

I know I could fix this in any number of ways (including, but not
limited to, acting on the same input list twice, or acting on it in
such a fashion in the first place), but I am trying to actually
understand "self".

Here's the horrid, horrid mess:

class Create:   
    def freshDB(self, DBPATH, Fields):
    self.Fields = Fields
    for field in self.Fields.keys():
    columns = self.Fields[field]
    columns = columns.split(',')
    query = ''
    for each in columns:
    query = "%s, %s varchar"%(query,each)
    query = query[1:]
    query = "Create Table %s (%s)"%(field,query)
    self.Fields[field] = query
   
    connection = gadfly.gadfly()
    connection.startup("InventoryDB", DBPATH)
    cursor = connection.cursor()
   
    for field in self.Fields.keys():
    cursor.execute(self.Fields[field])
    connection.commit()
   
    for field in self.Fields.keys():
    cursor.execute("Select * from %s"%field)
    print cursor.pp()
    connection.close()
   
    def comparisonTable(self, DBPATH, Fields, columns, mode):
    query = ""
    if mode == 'new':
    connection = gadfly.gadfly("InventoryDB",DBPATH)
    cursor = connection.cursor()
    try:
   
cursor.execute("drop table comparison")
    except:
    print "No old table found."
    columns = Fields["Common"].split(',')
   
    for each in columns:
    query = "%s, %s varchar"%(query,each)
    query = query[1:]
    query = "Create Table comparison (%s)"%query
    cursor.execute(query)
    connection.commit()
    cursor.execute("select * from comparison")
    print cursor.pp()

Now when I run freshDB from the other script:

Fields = {"Common":"Inventory_Number, Stock_Number, Location, Year,
Make, Model, Part_Type, Mileage, Description, Interchange_Data,
Condition, Price",
    "EvilBay":"EvilBay_Title, EvilBay_Description",
    "HappyBase":"HappyBase_Description, HappyBase_Long_Description"}

d = DBMod

d.Create().freshDB(DBPATH, Fields)

d.Create().comparisonTable(DBPATH, Fields, columns, "new")


the resulting query is:

Create Table comparison ( Inventory_Number varchar,  Stock_Number
varchar,  Location varchar,  Year varchar,  Make
varchar,  Model varchar,  Part_Type varchar,  Mileage
varchar,  Description varchar,  Interchange_Data
varchar,  Condition varchar,  Price varchar)

The query from comparisonTable gives me:
Create Table comparison ( Create Table Common ( Inventory_Number
varchar varchar,   Stock_Number varchar varchar,  
Location varchar varchar,   Year varchar varchar,  
Make varchar varchar,   Model varchar varchar,  
Part_Type varchar varchar,   Mileage varchar
varchar,   Description varchar varchar,  
Interchange_Data varchar varchar,   Condition varchar
varchar,   Price varchar) varchar)

If I restate the "Fields" input list before running comparisonTable, my
results are as expected (i.e. exactly like the first query, exept the
table is named "comparison").

I thought that when "self" was invoked for a function then that data
was acted on only for the scope of that function, yet the data is
changed in the original. Why?

I'm sure this is so obvious that a crack-addled tapeworm head down in a
bucket of stupid could understand it, unfortunately, I'm not quite at
that level today. Sorry. 

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


Re: [Tutor] OOP and Python.. a gentle remark

2006-10-25 Thread wesley chun
on a related topic, if you're concerned about security, esp. of your
instance attributes, new-style classes offer you significantly more
control over them using descriptors (including properties [and to a
lesser extent, slots]). there is plenty of docs available on those, so
i'll defer describing them here.

good luck!
-wesley
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Self, Scopes and my unbelievable muddleheadedness.

2006-10-25 Thread Luke Paireepinart

>
> I'm sure this is so obvious that a crack-addled tapeworm head down in 
> a bucket of stupid could understand it, unfortunately, I'm not quite 
> at that level today. Sorry.
Uh, I don't understand why you're passing Fields to the functions but 
then putting the value in self.Fields...
but we'll ignore that for now :)

The problem it sounds like you're having is that you think that passing 
lists to functions copies them,
when in fact it just creates a reference to them.
Take this, for example:


 >>> def append_five(alist):
alist.append(5)
 >>> a = [1,2,3,4]
 >>> append_five(a)
 >>> a
[1, 2, 3, 4, 5]
 >>> append_five(a)
 >>> a
[1, 2, 3, 4, 5, 5]


Other than that,
Maybe you think self is used for something other than what it's intended 
to be used for...
but I can't be sure.
I'm sure someone else can give you a good example.
I, however, have to run.
HTH,
-Luke

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


Re: [Tutor] Self, Scopes and my unbelievable muddleheadedness.

2006-10-25 Thread John Fouhy
On 26/10/06, doug shawhan <[EMAIL PROTECTED]> wrote:
>  class Create:
>  def freshDB(self, DBPATH, Fields):
>   # ...
>  def comparisonTable(self, DBPATH, Fields, columns, mode):
>   # ...
>  Now when I run freshDB from the other script:
>
>  Fields = {"Common":"Inventory_Number, Stock_Number, Location, Year, Make,
> Model, Part_Type, Mileage, Description, Interchange_Data, Condition, Price",
>  "EvilBay":"EvilBay_Title, EvilBay_Description",
>  "HappyBase":"HappyBase_Description,
> HappyBase_Long_Description"}
>
>  d = DBMod
>
>  d.Create().freshDB(DBPATH, Fields)
>
>  d.Create().comparisonTable(DBPATH, Fields, columns, "new")

What is the purpose of your Create class?  It seems to me that you are
not actually doing anything object-oriented here.  So maybe you're
confused about 'self' because you've got no object orientation?

I think you've got a couple of ways forward.  You could abandon your
class, and just put the functions directly into a module; ie:

## creategadfly.py ###

def freshDB(dbpath, fields):
   # etc

def comparisonTable(dbpath, fields, columns, mode):
   # etc

##

and then, in your code, you would do:

import creategadfly
creategadfly.freshDB(DBPATH, Fields)
creategadfly.comparisonTable(DBPATH, Fields, columns, "new")

Alternatively, you could restructure your code to make it OO.
Something like this:

##

class GadflyConnection(object):
   def __init__(self, dbpath, dbname, fields):
   self.createDB(dbpath, dbname, fields)

   def createDB(self, dbpath, dbname, fields):
   self.db = gadfly.gadfly()
   self.db.startup(dbname, dbpath)
   # etc

   def comparisonTable(self, mode):
   if mode == 'new':
   # insert code to create 'query'
   cursor = self.db.cursor()
   cursor.execute(query)
   cursor.close()

Maybe you would want a call to self.comparisonTable inside __init__?

Then to use:

gadflyDB = GadflyConnection(...)

I'm not sure what you want to do with your database, so I can't really
give you a bigger use example.  But do you see what is going on?  In
createDB(), you create a new gadfly connection, and then assign it to
'self.db'.  Then, in comparisonTable, you can reference self.db to
access that connection.

Hope this helps.

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


[Tutor] Decimal truncation, rounding etc.

2006-10-25 Thread Joe Cox



My next project is to read a doc file and do 
some number editing.
I can alter numbers in the Interactive Shell 
OK:
 
import mathprint 
round(7.12345,4)7.1234
 
from decimal 
import*Decimal('7.0').quantize(Decimal('1.000'),rounding = 
decimal.ROUND_DOWN)Decimal("7.")
 
But when I go in to IDLE, I just don't seem 
to be able to make this work.
 
A typical line of code for me to read and 
edit will look like:
G01 G91 X7.12345 Y7. 
Z-0.0086 
The underlines is what I need to edit, as 
above.
 
I must not understand something 
fundamental.
 
 
Joe Cox
513-293-4830
 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Decimal truncation, rounding etc.

2006-10-25 Thread Luke Paireepinart
Joe Cox wrote:
> My next project is to read a doc file and do some number editing.
> I can alter numbers in the Interactive Shell OK:
>  
> import math
> print round(7.12345,4)
> 7.1234
>  
> from decimal import*
> Decimal('7.0').quantize(Decimal('1.000'),rounding = 
> decimal.ROUND_DOWN)
> Decimal("7.")
>  
> But when I go in to IDLE, I just don't seem to be able to make this work.
>
What have you tried?
> A typical line of code for me to read and edit will look like:
> G01 G91 X_7.12345_ Y_7._ Z-0.0086 
> The underlines is what I need to edit, as above.
Okay, and what does it look like when you input these values?
Are you storing them in  Decimal instances, or floats, or what?

What exactly is it that doesn't work?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Decimal truncation, rounding etc.

2006-10-25 Thread Jason Massey
More specifically, Joe, where and what types of errors are you getting?When I type in your example exactly as above I get the following:>>>from decimal 
import *>>> Decimal('7.').quantize(Decimal('1.000'),rounding=decimal.ROUND_DOWN)Traceback (most recent call last):  File "", line 1, in ?NameError: name 'decimal' is not defined
That error appears because you've imported all of the decimal functions into the global namespace and you're trying to reference a value in the decimal namespace.  In your example it'd have to look like this to work:
>>>Decimal('7.').quantize(Decimal('1.000'),rounding=ROUND_DOWN)  #note the lack of decimal in front of ROUND_DOWNDecimal("7.000")Or is the problem that you're not able to read and parse the text file properly?
On 10/25/06, Joe Cox <[EMAIL PROTECTED]> wrote:





My next project is to read a doc file and do 
some number editing.
I can alter numbers in the Interactive Shell 
OK:
 
import mathprint 
round(7.12345,4)7.1234
 
from decimal 
import*Decimal('7.0').quantize(Decimal('1.000'),rounding = 
decimal.ROUND_DOWN)Decimal("7.")
 
But when I go in to IDLE, I just don't seem 
to be able to make this work.
 
A typical line of code for me to read and 
edit will look like:
G01 G91 X7.12345 Y7. 
Z-0.0086 
The underlines is what I need to edit, as 
above.
 
I must not understand something 
fundamental.
 
 
Joe Cox
513-293-4830
 

___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] Decimal truncation, rounding etc.

2006-10-25 Thread Joe Cox



Yes, I made a typo in 
the quantize. You are correct I am not able to read and parse the text 
file properly? 
I just face that IDE screen and it's all white. I am 
lost. 

  -Original Message-From: Jason Massey 
  [mailto:[EMAIL PROTECTED]Sent: Wednesday, October 25, 2006 
  4:25 PMTo: [EMAIL PROTECTED]Cc: 
  tutorSubject: Re: [Tutor] Decimal truncation, rounding 
  etc.More specifically, Joe, where and what types of 
  errors are you getting?When I type in your example exactly as above I 
  get the following:>>>from decimal import 
  *>>> 
  Decimal('7.').quantize(Decimal('1.000'),rounding=decimal.ROUND_DOWN)Traceback 
  (most recent call last):  File "", line 1, 
  in ?NameError: name 'decimal' is not defined That error appears 
  because you've imported all of the decimal functions into the global namespace 
  and you're trying to reference a value in the decimal namespace.  In your 
  example it'd have to look like this to work: 
  >>>Decimal('7.').quantize(Decimal('1.000'),rounding=ROUND_DOWN)  
  #note the lack of decimal in front of ROUND_DOWNDecimal("7.000")Or 
  is the problem that you're not able to read and parse the text file properly? 
  
  On 10/25/06, Joe 
  Cox <[EMAIL PROTECTED]> 
  wrote:
  

My next project is to read a doc file and do some number 
editing.
I can alter numbers in the Interactive Shell OK:
 
import mathprint round(7.12345,4)7.1234
 
from decimal 
import*Decimal('7.0').quantize(Decimal('1.000'),rounding = 
decimal.ROUND_DOWN)Decimal("7.")
 
But when I go in to IDLE, I just don't seem to be able to make 
this work.
 
A typical line of code for me to read and edit will look 
like:
G01 G91 X7.12345 Y7. 
Z-0.0086 
The underlines is what I need to edit, as above.
 
I must not understand something fundamental.
 
 
Joe Cox
513-293-4830
 ___Tutor 
maillist  -  Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] New to programming and Python

2006-10-25 Thread Jorge Azedo
Hi guys ( and gals )

I'm totally new to the whole programming scene (I decided to enter it 
for many reasons, one of which is the fact that I *want* to know how to 
program my computer) and I decided to start out with Python. I'm reading 
lots of tutorials on it, trying to understand how to work with it, but 
for some reason or another, it all seems a great mess to me. Am I doing 
something wrong? Also, can anyone give me any pointers on how to start 
working with Python?

Thanks in advance for any help you can give me
- Jorge
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] python2vb.net

2006-10-25 Thread hok kakada
Dear All,

A friend of mine is well programming in vb.net and C#. 
He got a python sourcecode of KhmerConverter tool. 
He would like to port to either vn.net or C#.

Are there any tools to do this?
Thanks,
da
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor