[Tutor] comparing almost equal strings

2007-02-08 Thread thomas coopman
Hi,

I need a function that groups almost equal strings.  It seems most easy
to me, to do this with a hash function.

So I would write a hash function like this:
string = string.replace( , ).lower()[0:6]

and then hash the string chars, but it should detect minor typo's, so
words with one different char in the 6 chars, should have the same hash.

I think I once read something about it, but I can't find it, 
does somebody know how to do this?

Also do you think this is a good way, or do some of you have experience
with this and know a better way?

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


Re: [Tutor] same output on diferent sys.stdout.encodings

2007-02-08 Thread Michael Lange
On Wed, 07 Feb 2007 17:30:26 +
Paulino [EMAIL PROTECTED] wrote:

 Hi everyone!
 
 I have some strings that include special characters, to be displayed in 
 widget labels ( PyQt4 ).
 The output changes in diferent OS's due to diferent sys.stdout encoding
 
 Not only the labels in the GUI change, but the source file strings are 
 altered when I move from win to linux and vice-versa.
 
 The solution I found for now was to replace the special characters in 
 the source file string for their representation:
 I replaced é (e acute ) by \xe9 wich correpsond to chr(233) in the 
 cp1252 encoding.
 
 The character é (e acute) in linux is not recognized in the source file, 
 neither in IDLE nor in Kate
 My win sys.stdout.encoding is cp850 and the linux one is utf-8
 
 Now I have d\xe9bito instead of débito (debit in portuguese). By 
 passing the string through unicode with the convinient encoding, I 
 ensure the labels are exibithed the same  in every OS but, this way the 
 code is not very readable.
 
 Is there a way of solving this, keeping the more readable?
 ___

Have you tried to declare the encoding in use at the top of your Python source 
file, like:

# -*- coding: iso-8859-1 -*-

If you put this at the first line of your .py files (of course replace 
iso-8859-1 with whatever
encoding you use) I think this should do the trick.

I hope this helps

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


[Tutor] resetting the python interpreter through manipulating globals()

2007-02-08 Thread Yi Qiang
Hi,
I have a program that talks to a python interpreter through pexpect  
(don't bother asking why ;).  What I would like to do is occasionally  
reset the interpreter to the state it would be in if it had just  
been launched.  I assumed I could simply clear out the globals()  
dictionary, minus '__builtins__' and some other important stuff, and  
recreate the globals.  But even a simple attempt has failed quite badly:

def reset_interpreter():
 rThis method will reset a python interpreters globals  
dictionary with
 the one provided as the input parameter.
 

 # This will just try to delete all non important keys in globals
 for k in globals().keys():
 print k
 if k == '__builtins__':
 continue
 else:
 try:
 del globals()[k]
 del locals()[k]
 except:
 continue
 print globals()

This does not seem to work at all, any suggestions?


Yi



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


[Tutor] Program Control

2007-02-08 Thread [EMAIL PROTECTED]

I am learning Python and have written several small programs of increasing
complexity but so far they are all linear programs meaning that they are
meant to do one thing.  I have yet to fully understand program control in
order to go to and return form modules (I think this is the correct term).
In other words, I have a menu which offers several options, I would like to
be able to combine several of my programs into seperate modules and put in
one larger program.  Then the user could select a menu item, be sent to a
module and return to the menu for another selection.  Can someone show me
how to do module or program control to accomplish the basic example below:

Main Menu
Select 1 for subtraction
Select 2 for addition
Select 3 to quit

***
Subtraction module:
Enter a number
Enter a second number
Answer =Number1-Number2

Menu:

Select 1 to return to main menu
Select 2 to subract again


Addition module:
Enter a number
Enter a second number
Answer = Number1+Number2

Menu

Select 1 to return to main menu
Select 2 to add again

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


Re: [Tutor] comparing almost equal strings

2007-02-08 Thread Christopher Arndt
thomas coopman schrieb:
 I need a function that groups almost equal strings.  It seems most easy
 to me, to do this with a hash function.

What do you mean be almost equal? By which criterium? Spelling,
Pronounciation? Semantics?

 I think I once read something about it, but I can't find it, 
 does somebody know how to do this?

Maybe you mean the soundex algorithm? See, for example, here:

http://diveintopython.org/performance_tuning/index.html

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


[Tutor] Range of float value

2007-02-08 Thread Johan Geldenhuys
Hi all,
 
I have a value that ranges between 48.01 and 48.57. a Float value in other
words.
 
I want to look at changes in the value. If my normal range is between 48.35
and 48.45, how will I identify the value below 48.35 and above 48.45?
 
Something I tried was:
 
for a in range(48.35, 48.45):
print a
 
It gives me a value of 100.
 
Is it possible to get a range of a float value?
 
Thanks
 
Johan

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.17.30/674 - Release Date: 2007/02/07
03:33 PM
 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Program Control

2007-02-08 Thread Kent Johnson
[EMAIL PROTECTED] wrote:
 I am learning Python and have written several small programs of 
 increasing complexity but so far they are all linear programs meaning 
 that they are meant to do one thing.  I have yet to fully understand 
 program control in order to go to and return form modules (I think this 
 is the correct term).  In other words, I have a menu which offers 
 several options, I would like to be able to combine several of my 
 programs into seperate modules and put in one larger program.

See for example
Modules and Functions in http://www.freenetpages.co.uk/hp/alan.gauld/
http://swaroopch.info/text/Byte_of_Python:Modules#Making_your_own_modules
http://docs.python.org/tut/node8.html

Kent

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


Re: [Tutor] same output on diferent sys.stdout.encodings

2007-02-08 Thread Kent Johnson
Paulino wrote:
 Hi everyone!
 
 I have some strings that include special characters, to be displayed in 
 widget labels ( PyQt4 ).
 The output changes in diferent OS's due to diferent sys.stdout encoding
 
 Not only the labels in the GUI change, but the source file strings are 
 altered when I move from win to linux and vice-versa.
 
 The solution I found for now was to replace the special characters in 
 the source file string for their representation:
 I replaced é (e acute ) by \xe9 wich correpsond to chr(233) in the 
 cp1252 encoding.
 
 The character é (e acute) in linux is not recognized in the source file, 
 neither in IDLE nor in Kate
 My win sys.stdout.encoding is cp850 and the linux one is utf-8
 
 Now I have d\xe9bito instead of débito (debit in portuguese). By 
 passing the string through unicode with the convinient encoding, I 
 ensure the labels are exibithed the same  in every OS but, this way the 
 code is not very readable.
 
 Is there a way of solving this, keeping the more readable?

I think the problem you are having is with the source code encoding, not 
sys.stdout.encoding. Probably your editor on linux expects a different 
file encoding than what you are using in Windows. Your windows editor is 
probably using cp1252; perhaps the linux editor expects utf-8.

You need to get the editors to agree on the source code encoding. Then 
put the coding declaration at the top of the file as Michael suggested.

Kent

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


Re: [Tutor] Program Control

2007-02-08 Thread [EMAIL PROTECTED]

Maybe I'm asking the wrong question.  This appears that a module is a
external program.  What I've seen on some programs but don't fully
understand is something of the sort: def main() and a def  sub() and def
add().  It appears that the program has calls to each of these sections.
The term module may be incorrect here.  I would  like to have all of my code
in one program but be able to call sections of code and return from them to
the main app.  That's where I'm lost.

On 2/8/07, Kent Johnson [EMAIL PROTECTED] wrote:


[EMAIL PROTECTED] wrote:
 I am learning Python and have written several small programs of
 increasing complexity but so far they are all linear programs meaning
 that they are meant to do one thing.  I have yet to fully understand
 program control in order to go to and return form modules (I think this
 is the correct term).  In other words, I have a menu which offers
 several options, I would like to be able to combine several of my
 programs into seperate modules and put in one larger program.

See for example
Modules and Functions in http://www.freenetpages.co.uk/hp/alan.gauld/
http://swaroopch.info/text/Byte_of_Python:Modules#Making_your_own_modules
http://docs.python.org/tut/node8.html

Kent


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


Re: [Tutor] same output on diferent sys.stdout.encodings

2007-02-08 Thread Paulino
Yes I have that declaration in my script.

Paulino


 Send Tutor mailing list submissions to
   tutor@python.org

   

# -*- coding: iso-8859-1 -*-

If you put this at the first line of your .py files (of course replace 
iso-8859-1 with whatever
encoding you use) I think this should do the trick.

I hope this helps

Michael


--

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


Re: [Tutor] same output on diferent sys.stdout.encodings

2007-02-08 Thread Paulino
Yes that is the problem.

But I canot control all the the encodings in every PC that the script is 
to be run...

Paulino


Kent Johnson escreveu:

 I think the problem you are having is with the source code encoding, 
 not sys.stdout.encoding. Probably your editor on linux expects a 
 different file encoding than what you are using in Windows. Your 
 windows editor is probably using cp1252; perhaps the linux editor 
 expects utf-8.

 You need to get the editors to agree on the source code encoding. Then 
 put the coding declaration at the top of the file as Michael suggested.

 Kent




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


Re: [Tutor] same output on diferent sys.stdout.encodings

2007-02-08 Thread Eike Welk
The Kate editor has also modelines, similar to the python interpreter:
http://kate-editor.org/article/katepart_modelines

HTH,
Eike.

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


Re: [Tutor] Program Control

2007-02-08 Thread Kent Johnson
[EMAIL PROTECTED] wrote:
 Maybe I'm asking the wrong question.  This appears that a module is a 
 external program.  What I've seen on some programs but don't fully 
 understand is something of the sort: def main() and a def  sub() and def 
 add().  It appears that the program has calls to each of these 
 sections.  The term module may be incorrect here.  I would  like to have 
 all of my code in one program but be able to call sections of code and 
 return from them to the main app.  That's where I'm lost.

Then it sounds like you need to learn about functions. The same 
tutorials, different sections.

Kent

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


Re: [Tutor] same output on diferent sys.stdout.encodings

2007-02-08 Thread Kent Johnson
Paulino wrote:
 Yes that is the problem.
 
 But I canot control all the the encodings in every PC that the script is 
 to be run...

The problem is in your *editor* not in Python. You have to control the 
encoding the *editor* expects. At least that is my guess - your 
complaint is that you can't find a way to represent the character that 
displays correctly in editors on both platforms.

In other words, if you have a Python file that includes characters in 
cp1252 and you open the file in an editor that expects utf-8, it will 
not display correctly.

Kent

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


Re: [Tutor] Range of float value

2007-02-08 Thread Luke Paireepinart
Kent Johnson wrote:
 Johan Geldenhuys wrote:
   
 Hi all,
  
 I have a value that ranges between 48.01 and 48.57. a Float value in 
 other words.
  
 I want to look at changes in the value. If my normal range is between 
 48.35 and 48.45, how will I identify the value below 48.35 and above 48.45?
  
 Something I tried was:
  
 for a in range(48.35, 48.45):
 print a
  
 It gives me a value of 100.
  
 Is it possible to get a range of a float value?
 

 You can't generate all the float values in a range. (OK, you probably 
 could, but it would not be practical or useful.) You can test for a 
 value in a range, e.g.
 if 48.35 = a = 48.45:
   
Kent:
Why does this work?
In C++ this would go from

if (48.35 = a = 48.45)

to (assuming the right condition is met)

if (48.35 = true)

because it evaluates these things right to left, doesn't it?
does python treat chained comparisons differently than C++ or is C++ 
behaving differently than I think it does?
Thanks for your help,
-Luke
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Range of float value

2007-02-08 Thread Kent Johnson
Luke Paireepinart wrote:
 Kent Johnson wrote:

 You can't generate all the float values in a range. (OK, you probably 
 could, but it would not be practical or useful.) You can test for a 
 value in a range, e.g.
 if 48.35 = a = 48.45:
   
 Kent:
 Why does this work?

It is explicitly supported in Python. See
file:///C:/Python25/Doc/ref/comparisons.html

which says, Comparisons can be chained arbitrarily, e.g., x  y = z is 
equivalent to x  y and y = z, except that y is evaluated only once 
(but in both cases z is not evaluated at all when x  y is found to be 
false).

Kent

 In C++ this would go from
 
 if (48.35 = a = 48.45)
 
 to (assuming the right condition is met)
 
 if (48.35 = true)
 
 because it evaluates these things right to left, doesn't it?
 does python treat chained comparisons differently than C++ or is C++ 
 behaving differently than I think it does?
 Thanks for your help,
 -Luke
 
 


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


Re: [Tutor] Range of float value

2007-02-08 Thread Andre Engels

2007/2/8, Johan Geldenhuys [EMAIL PROTECTED]:


 Hi all,

I have a value that ranges between 48.01 and 48.57. a Float value in other
words.

I want to look at changes in the value. If my normal range is between
48.35 and 48.45, how will I identify the value below 48.35 and above 48.45
?

Something I tried was:

for a in range(48.35, 48.45):
print a

It gives me a value of 100.

Is it possible to get a range of a float value?



It depends. What would you like it to be? All numbers in that range? They're
uncountably infinite, so no way we could ever get that out of the computer.
All actual float values? Depends too much on the implementation of the
specific machine you're working on to be workable.

Identifying values below 48.35 and above 48.45 is simply done by:
if value  48.35 or value  48.45 then...

No need to first create the range of values

--
Andre Engels, [EMAIL PROTECTED]
ICQ: 6260644  --  Skype: a_engels
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Range of float value

2007-02-08 Thread Luke Paireepinart
Kent Johnson wrote:
 Luke Paireepinart wrote:
 Kent Johnson wrote:

 You can't generate all the float values in a range. (OK, you 
 probably could, but it would not be practical or useful.) You can 
 test for a value in a range, e.g.
 if 48.35 = a = 48.45:
   
 Kent:
 Why does this work?

 It is explicitly supported in Python. See
 file:///C:/Python25/Doc/ref/comparisons.html
Do you mean http://docs.python.org/ref/comparisons.html ?
:)
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Range of float value

2007-02-08 Thread Kent Johnson
Luke Paireepinart wrote:
 Kent Johnson wrote:
 Luke Paireepinart wrote:
 Kent Johnson wrote:
 You can't generate all the float values in a range. (OK, you 
 probably could, but it would not be practical or useful.) You can 
 test for a value in a range, e.g.
 if 48.35 = a = 48.45:
   
 Kent:
 Why does this work?
 It is explicitly supported in Python. See
 file:///C:/Python25/Doc/ref/comparisons.html
 Do you mean http://docs.python.org/ref/comparisons.html ?

Jeez. I try so hard to bust out of here and every turn I take just 
brings me back to file://.

Now where did I put that internet, anyway?

Kent

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


Re: [Tutor] Range of float value

2007-02-08 Thread Johan Geldenhuys
OK, this what I wanted:
 
I have a value: a = 48.41
 
My lowValue is: lowValue = 48.35
My highValue is : highvalue = 48.45
 
if a = lowValue:
print 'value below limit'
 
if a = highValue:
print value above limit'
 
I though that it could be possible to have a range between 48.35 and 48.45
that could have a step of 0.1
 
This works fine with normal intgers:
 
 def lookAtRange(a):
... if a in range(40, 110, 10):#Would like to have: if a in
range(48.35, 48.45, 0.1):
... print 'In limits'
... else:
... print 'Out of limits'
... 
 lookAtRange(40)
In limits
 lookAtRange(50)
In limits
 
 lookAtRange(20)
Out of limits
 
 lookAtRange(120)
Out of limits
 
 
Johan
 

   _  

From: Andre Engels [mailto:[EMAIL PROTECTED] 
Sent: 08 February 2007 07:17 PM
To: [EMAIL PROTECTED]
Cc: tutor@python.org
Subject: Re: [Tutor] Range of float value


2007/2/8, Johan Geldenhuys HYPERLINK
mailto:[EMAIL PROTECTED][EMAIL PROTECTED]: 

Hi all,
 
I have a value that ranges between 48.01 and 48.57. a Float value in other
words.
 
I want to look at changes in the value. If my normal range is between 48.35
and 48.45, how will I identify the value below 48.35 and above 48.45?
 
Something I tried was:
 
for a in range(48.35, 48.45):
print a
 
It gives me a value of 100.
 
Is it possible to get a range of a float value?


It depends. What would you like it to be? All numbers in that range? They're
uncountably infinite, so no way we could ever get that out of the computer.
All actual float values? Depends too much on the implementation of the
specific machine you're working on to be workable. 

Identifying values below 48.35 and above 48.45 is simply done by:
if value  48.35 or value  48.45 then...

No need to first create the range of values

-- 
Andre Engels, HYPERLINK mailto:[EMAIL PROTECTED][EMAIL PROTECTED]
ICQ: 6260644  --  Skype: a_engels 


--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.17.30/674 - Release Date: 2007/02/07
03:33 PM



-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.17.30/674 - Release Date: 2007/02/07
03:33 PM
 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Range of float value

2007-02-08 Thread Kent Johnson
Johan Geldenhuys wrote:
 OK, this what I wanted:
  
 I have a value: a = 48.41
  
 My lowValue is: lowValue = 48.35
 My highValue is : highvalue = 48.45
  
 if a = lowValue:
 print 'value below limit'
  
 if a = highValue:
 print value above limit'
  
 I though that it could be possible to have a range between 48.35 and 
 48.45 that could have a step of 0.1

What is wrong with
def lookAtRange(a):
   if lowValue = a = highValue:
 print 'In limits'
..etc
??

  
 This works fine with normal intgers:
  
 * def lookAtRange(a):
 ... if a in range(40, 110, 10):*#Would like to have: if a in 
 range(48.35, 48.45, 0.1):
 *... print 'In limits'
 ... else:
 ... print 'Out of limits'
 ...
  lookAtRange(40)
 In limits
  lookAtRange(50)
 In limits
 
  lookAtRange(20)
 Out of limits
 
  lookAtRange(120)
 Out of limits
  *

Are you sure this is what you want? Have you tried lookAtRange(45) for 
example?

The range function creates a list of integers:
In [1]: range(40, 110, 10)
Out[1]: [40, 50, 60, 70, 80, 90, 100]

The 'in' operator tests for membership. 40 is in the list; 20 and 45 are 
not.

I think even in the case of integers the range test with  is what you want.

Kent

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


[Tutor] Debugging

2007-02-08 Thread Toon Pieton

Hey friendly users!

I have a question considering debugging: is it possible to get the current
code line that is being executed?

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


Re: [Tutor] Debugging

2007-02-08 Thread John Fouhy
On 09/02/07, Toon Pieton [EMAIL PROTECTED] wrote:
 Hey friendly users!

 I have a question considering debugging: is it possible to get the current
 code line that is being executed?

Are you using pdb [the python debugger]?

If you have a script 'myscript.py', you can start the script like this:

  python -m pdb myscript.py

You can then set breakpoints and step through the code line-by-line using pdb.

(brief summary:

'break module:line' -- set breakpoint, eg: 'break mymodule:23'
'r' -- run program
'n' -- move to next line
's' -- move to next line, or step into function call
'c' -- continue running until next breakpoint
'p' -- print; used to inspect variables, etc.
)

Note that pdb has difficulties with multithreaded programs.

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


[Tutor] file open error

2007-02-08 Thread Jalil

Hey guys,

I have this simple code and i cant seem to get it to run.
here is the code.


from os import *
import re

hostname =raw_input(Host name : ) or 'unknown'
mac_addr =input(Mac address : )

filename='/etc/dhcpd.conf'
fh=open(filename)

m = re.match(hostname,fh.readlines())
if m!=None:
   m.group()


Here is the error I get when i try to run the code


monkeysee% python sys_wireless.py
Host name :
Mac address : 1234567
Traceback (most recent call last):
 File sys_wireless.py, line 8, in ?
   fh=open(/etc/dhcpd.conf,r)
TypeError: an integer is required



I dont know what the issue is?

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


Re: [Tutor] file open error

2007-02-08 Thread John Fouhy
On 09/02/07, Jalil [EMAIL PROTECTED] wrote:

Hi Jalil,

Because you're doing this:

 from os import *

It means that when you get to this line:

 fh=open(filename)

You're actually calling os.open, which is lower-level than the
standard open() and expects different arguments.

Many people recommend not doing from .. import * if you can possibly
avoid it because of this precise problem!

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


Re: [Tutor] file open error

2007-02-08 Thread Bill Campbell
On Thu, Feb 08, 2007, Jalil wrote:

   Hey guys,
   I have this simple code and i cant seem to get it to run.
   here is the code.
   from os import *
   import re
   hostname =raw_input(Host name : ) or 'unknown'
   mac_addr =input(Mac address : )
   filename='/etc/dhcpd.conf'
   fh=open(filename)
   m = re.match(hostname,fh.readlines())
   if m!=None:
   m.group()
   Here is the error I get when i try to run the code
   monkeysee% python sys_wireless.py
   Host name :
   Mac address : 1234567
   Traceback (most recent call last):
 File sys_wireless.py, line 8, in ?
   fh=open(/etc/dhcpd.conf,r)
   TypeError: an integer is required
   I dont know what the issue is?
   any hints ?

It appears to me that your ``from os import *'' is biting you in
the butt as the os.open command is being executed instead of the
normal open.

Bill
--
INTERNET:   [EMAIL PROTECTED]  Bill Campbell; Celestial Software LLC
URL: http://www.celestial.com/  PO Box 820; 6641 E. Mercer Way
FAX:(206) 232-9186  Mercer Island, WA 98040-0820; (206) 236-1676

``Liberty don't work as good in practice as it does in speeches.''
Will Rogers
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Converting \x0e to string 0e in python

2007-02-08 Thread Sudarshana KS

Hi,

Currently i have data with the following type - Which is a x509 certificate
obtained from SSL server done. I need this to be converted to normal string,
so that i can use the load_certificate method of OpenSSL, which takes string
as the argument.

Kindly help me.


cert=
'\x00\x01\xa20\x82\x01\x9e0\x82\x01(\x02\x01\x000\r\x06\t*\x86H\x86\xf7\r\x01\x01\x04\x05\x000:1
\x120\x10\x06\x03U\x04\x03\x13\tConst2-
2.1$0\n\x06\x03U\x04\x05\x13\x0339B0\x16\x06\t*\x86H\x86\xf7\r
\x01\t\x02\x16\tConst2-
2.0\x1e\x17\r070207210438Z\x17\r170204210438Z0:1\x120\x10\x06\x03U\x04\x03
\x13\tConst2-
2.1$0\n\x06\x03U\x04\x05\x13\x0339B0\x16\x06\t*\x86H\x86\xf7\r\x01\t\x02\x16\tConst2-2.0|0\r
\x06\t*\x86H\x86\xf7\r\x01\x01\x01\x05\x00\x03k\x000h\x02a\x00\xc2\x99e2\xd0\xa5\xb67\x80iv.\x12I\x17
\xaa\xee9S\xdc\xee\xa1!\xb4\x94/\xf8\xe2\x0e%V\xdc\xa8%\x04\x03\x8dl\\\x8cJ\xec\x13\xd7\xe2\x96\x1b\xa8`
\xdf$\xfe\xb9\x9a\xf9\xb7[\x8f\xe6\xc7U?l\x04D\xfc\xd7\x96\x99\x04\xb1\x8c\xcd\xc3[\x17\xba\xb2+g5L
\x08~3B\xf9\x1dV\x1a\x84\x0eW\x94\x1f\x02\x03\x01\x00\x010\r\x06\t*\x86H\x86\xf7\r\x01\x01\x04\x05
[EMAIL PROTECTED]\xae\xc7\xf6l\xeam2\x8f[Z\xde\xd0\xbf\xd7\xd1/
[EMAIL PROTECTED]
\x88\xce|v\xb2\xc35#\xc5\xa7\xec\xdca\x12\xd8*\xc3k\xf8\x911}!\x861\xe2;\xd7'


--
Regards,
Sudarshana K S
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Property Question (Was: RE: Overloading assignment operator)

2007-02-08 Thread Carroll, Barry
 -Original Message-
 From: Tony Cappellini [mailto:[EMAIL PROTECTED]
 Sent: Thursday, February 08, 2007 5:41 PM
 To: Carroll, Barry
 Subject: re:Overloading assignment operator
 
 Hello Barry
 
 I'm trying to understand you post
 
 my question is, should this line
 
 result = property(get_result, set_result)
 
 actually be
 
 self.result = property(get_result, set_result)
 
 if result is an instance variable?
 
 Or did you intend it to be a class variable?
 
 Properties always confused me.
 
 
 thanks
 
 Overloading assignment operator
 Carroll, Barry Barry.Carroll at psc.com
 Wed Jan 24 00:32:34 CET 2007
 
 Hello, Achim,
 
 * ...here is where
 * properties become useful.  you can create a getter, setter, and even
a
 * deleter and doc string if you want. here's how you use it... add the
 * following to your class:
 
 * def get_result(self):
 * return self.__result
 *
 * def set_result (self, expression):
 * self.__result = expression
 *
 * result = property(get_result, set_ result, doc='result of
operations')
 *
 * -
 *
 
 I have tested this using the admittedly simple-minded code snipped
 below.
 
 
 @BCARROLL[Python]|3 class Aclass:
  |. def __init__(self):
  |. __result = None
  |. def get_result(self):
  |. return self.__result
  |. def set_result (self, result):
  |. self.__result = result
  |. result = property(get_result, set_result,
 doc='result of expression')
  |.
 @BCARROLL[Python]|5 a = Aclass()
 @BCARROLL[Python]|7 a.result = 2*3
 @BCARROLL[Python]|8 a.result
  8 6
 @BCARROLL[Python]|9 a.result = 25.0 * 5.25
 @BCARROLL[Python]|10 a.result
  10 131.25
 @BCARROLL[Python]|11
Hello, Tony:

First off, it's always a good idea to respond to the mailing list
instead of directly to an individual.  Everyone benefits from the
information instead of just one person.  Besides, if I make a mistake
(something I fo depressingly often) someone else on the list can correct
it so you get the right info.

Anyway, to your question: result vs self.result.  Look at the
interpreter session snippet above.  The assignment to result is inside
the class definition, so it is an attribute of Aclass.  At this point
Aclass.result is indeed a class variable.  Or, perhaps more correctly,
a class property.  

However, when a is set to Aclass(), an instance of Aclass is created
and given the name a.  a.result is therefore an instance variable.
I never use the class variable Aclass.result.  

Does that help any?

Regards,
 
Barry
[EMAIL PROTECTED]
541-302-1107

We who cut mere stones must always be envisioning cathedrals.

-Quarry worker's creed


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


Re: [Tutor] Range of float value

2007-02-08 Thread Daniel Yoo


On Thu, 8 Feb 2007, Johan Geldenhuys wrote:

 OK, this what I wanted:

 I have a value: a = 48.41

 My lowValue is: lowValue = 48.35
 My highValue is : highvalue = 48.45

Range does not work on floats: it's meant to work on integers.



 I though that it could be possible to have a range between 48.35 and 48.45
 that could have a step of 0.1

There's an unsafe assumption here: in general, comparing floats for 
equality won't work unless you are very very careful.  See:

 http://www.python.org/doc/tut/node16.html

Because floats aren't directly comparable (at least under normal cases), 
that negates the idea of build a list of floats and comparing for equality 
against one of them.

However, Kent mentioned a solution that should work better, a chained 
comparison:

 a = b = c

which is true if b is squeezed between a and b.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Converting \x0e to string 0e in python

2007-02-08 Thread Kent Johnson
Sudarshana KS wrote:
 Hi,
 
 Currently i have data with the following type - Which is a x509 
 certificate obtained from SSL server done. I need this to be converted 
 to normal string, so that i can use the load_certificate method of 
 OpenSSL, which takes string as the argument.

The below data is a string. It contains lots of non-ascii values which 
are printed as \x escapes, but it is still a string. Have you tried 
passing it to load_certificate? What happened?

Kent

 
 Kindly help me.
 
 
 cert= 
 '\x00\x01\xa20\x82\x01\x9e0\x82\x01(\x02\x01\x000\r\x06\t*\x86H\x86\xf7\r\x01\x01\x04\x05\x000:1
 \x120\x10\x06\x03U\x04\x03\x13\tConst2-2.1$0\n\x06\x03U\x04\x05\x13\x0339B0\x16\x06\t*\x86H\x86\xf7\r
  
 
 \x01\t\x02\x16\tConst2-2.0\x1e\x17\r070207210438Z\x17\r170204210438Z0:1\x120\x10\x06\x03U\x04\x03
 \x13\tConst2-2.1$0\n\x06\x03U\x04\x05\x13\x0339B0\x16\x06\t*\x86H\x86\xf7\r\x01\t\x02\x16\tConst2-2.0|0\r
 \x06\t*\x86H\x86\xf7\r\x01\x01\x01\x05\x00\x03k\x000h\x02a\x00\xc2\x99e2\xd0\xa5\xb67\x80iv.\x12I\x17
  
 
 \xaa\xee9S\xdc\xee\xa1!\xb4\x94/\xf8\xe2\x0e%V\xdc\xa8%\x04\x03\x8dl\\\x8cJ\xec\x13\xd7\xe2\x96\x1b\xa8`
 \xdf$\xfe\xb9\x9a\xf9\xb7[\x8f\xe6\xc7U?l\x04D\xfc\xd7\x96\x99\x04\xb1\x8c\xcd\xc3[\x17\xba\xb2+g5L
 \x08~3B\xf9\x1dV\x1a\x84\x0eW\x94\x1f\x02\x03\x01\x00\x010\r\x06\t*\x86H\x86\xf7\r\x01\x01\x04\x05
  
 
 [EMAIL PROTECTED]\xae\xc7\xf6l\xeam2\x8f[Z\xde\xd0\xbf\xd7\xd1/
 [EMAIL PROTECTED]
 \x88\xce|v\xb2\xc35#\xc5\xa7\xec\xdca\x12\xd8*\xc3k\xf8\x911}!\x861\xe2;\xd7' 
 
 
 
 -- 
 Regards,
 Sudarshana K S
 
 
 
 
 ___
 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] comparing almost equal strings

2007-02-08 Thread thomas coopman
Hi,

On Thu, 08 Feb
2007 13:07:41 +0100
Christopher Arndt [EMAIL PROTECTED] wrote:

 thomas coopman schrieb:
  I need a function that groups almost equal strings.  It seems most
  easy to me, to do this with a hash function.
 
 What do you mean be almost equal? By which criterium? Spelling,
 Pronounciation? Semantics?
 
  I think I once read something about it, but I can't find it, 
  does somebody know how to do this?
 
 Maybe you mean the soundex algorithm? See, for example, here:
 
 http://diveintopython.org/performance_tuning/index.html

This is what I was looking for!
 
 Chris
 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor

Thanks!

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