[Tutor] how to unique the string

2011-10-22 Thread lina
Hi,

I googled for a while, but failed to find the perfect answer,

for a string

['85CUR', '85CUR']

how can I unique it as:

['85CUR']

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


Re: [Tutor] how to unique the string

2011-10-22 Thread Devin Jeanpierre
You should be able to do this yourself, with the help of the following link:

http://docs.python.org/library/stdtypes.html#set

Is this a homework question?

Devin

On Sat, Oct 22, 2011 at 12:09 PM, lina  wrote:
> Hi,
>
> I googled for a while, but failed to find the perfect answer,
>
> for a string
>
> ['85CUR', '85CUR']
>
> how can I unique it as:
>
> ['85CUR']
>
> Thanks,
> ___
> 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] how to unique the string

2011-10-22 Thread bob gailer

On 10/22/2011 12:09 PM, lina wrote:

Hi,

I googled for a while, but failed to find the perfect answer,

for a string

['85CUR', '85CUR']

how can I unique it as:

['85CUR']


Try

set(['85CUR', '85CUR']

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

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


Re: [Tutor] how to unique the string

2011-10-22 Thread Steven D'Aprano

lina wrote:

Hi,

I googled for a while, but failed to find the perfect answer,

for a string

['85CUR', '85CUR']



That's not a string, it is a list.



how can I unique it as:

['85CUR']


Your question is unclear. If you have this:

['85CUR', '99bcd', '85CUR', '85CUR']

what do you expect to get?


# keep only the very first item
['85CUR']
# keep the first copy of each string, in order
['85CUR', '99bcd']
# keep the last copy of each string, in order
['99bcd', '85CUR']
# ignore duplicates only when next to each other
['85CUR', '99bcd', '85CUR']


Does the order of the result matter?

If order matters, and you want to keep the first copy of each string:

unique = []
for item in items:
if item not in unique:
unique.append(item)


If order doesn't matter, then use this:

unique = list(set(items))



--
Steven

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


Re: [Tutor] how to unique the string

2011-10-22 Thread lina
On 23 Oct, 2011, at 0:22, Devin Jeanpierre  wrote:

> You should be able to do this yourself, with the help of the following link:
> 
> http://docs.python.org/library/stdtypes.html#set

Thanks. 
> 
> Is this a homework question?

No. 
> 
> Devin
> 
> On Sat, Oct 22, 2011 at 12:09 PM, lina  wrote:
>> Hi,
>> 
>> I googled for a while, but failed to find the perfect answer,
>> 
>> for a string
>> 
>> ['85CUR', '85CUR']
>> 
>> how can I unique it as:
>> 
>> ['85CUR']
>> 
>> Thanks,
>> ___
>> 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


[Tutor] python telnet

2011-10-22 Thread Rayon
 

 

 

From: Rayon [mailto:ra...@gtt.co.gy] 
Sent: 21 October 2011 18:53
To: 'tutor@python.org'
Subject: python telnet

 

Can I connect to a telnet session and return data without disconnecting the
data session.  

 

Regards Rayon

 

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


Re: [Tutor] python telnet

2011-10-22 Thread Tom Tucker
Take a look at pyexpect. I have used this mod to ssh into juniper firewalls,
excute a command, save results and exit. Instead of exiting you can drop
down to interactive mode.
On Oct 22, 2011 3:40 PM, "Rayon"  wrote:

> ** **
>
> ** **
>
> ** **
>
> *From:* Rayon [mailto:ra...@gtt.co.gy]
> *Sent:* 21 October 2011 18:53
> *To:* 'tutor@python.org'
> *Subject:* python telnet
>
> ** **
>
> Can I connect to a telnet session and return data without disconnecting the
> data session.  
>
> ** **
>
> Regards Rayon
>
> ** **
>
> ___
> 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] python telnet

2011-10-22 Thread Steven D'Aprano

Rayon wrote:


Can I connect to a telnet session and return data without disconnecting the
data session.  


Isn't this the same question you asked back in June?

We tried to answer your question then, did you see our responses, and 
were they useful?


At the time, you were complaining that the telnet session was too slow, 
but you didn't tell us what you were actually doing. David Heiserca took 
a guess as to what you were doing, and suggested what you should do 
again. Did you see his response, and was it helpful?


You should show us the code you are using.


--
Steven

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


[Tutor] Simple Question On A Method (in subclass)

2011-10-22 Thread Chris Kavanagh
Hello, First, thank you for providing this GREAT service, & THANKS to 
everyone who contributes. It's greatly appreciated. . .I'm new to Python 
(2.7, Win XP) & new to programming in general. I have been studying on 
my own for about a month now. I believe I have a good grasp of the basics.


Secondly, I have several questions about this piece of code from 'A Byte 
Of Python' by Swaroop. Hope that's ok to use this code. I guess I could 
try to write a new ex. on my own, but, figured it would be too confusing.


My question is regarding the tell methods in the subclasses,the code 
{SchoolMember.tell(self)}, in the class Teacher & Student. I just don't 
understand what this is doing? Calling the first method {def tell} from 
the parent class, I assume? There is already a print statement in each 
of the subclass {def tell} showing details, why call another print 
statement (from parent class {def tell})?? I know this should be simple, 
but I'm confused. LOL, obviously.


Thank you in advance!






class SchoolMember:
'''Represents any school member.'''
def __init__(self,name,age):
self.name = name
self.age = age
print '(Initialized SchoolMember: %s)' %self.name

def tell(self):
'''Tell my details.'''
print 'Name:"%s" Age:"%s"' % (self.name, self.age),

class Teacher(SchoolMember):
'''Represents a teacher'''
def __init__(self,name,age,salary):
SchoolMember.__init__(self,name,age)
self.salary = salary
print '(Initialized Teacher: %s)' %self.name

def tell(self):
SchoolMember.tell(self)
print 'Salary: "%d"' % self.salary

class Student(SchoolMember):
'''Represents a student.'''
def __init__(self,name,age,marks):
SchoolMember.__init__(self,name,age)
self.marks = marks
print '(Initialized Student: %s)' %self.name

def tell(self):
SchoolMember.tell(self)
print 'Marks: "%d"' % self.marks

t = Teacher('Mrs. Shrividya',40,3)
s = Student('Swaroop',22,75)

print ##prints a blank line

members = [t,s]
for member in members:



OUTPUT

$ python inherit.py
(Initialized SchoolMember: Mrs. Shrividya)
(Initialized Teacher: Mrs. Shrividya)
(Initialized SchoolMember: Swaroop)
(Initialized Student: Swaroop)

Name:"Mrs. Shrividya" Age:"40" Salary: "3"
Name:"Swaroop" Age:"22" Marks: "75"
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Simple Question On A Method (in subclass)

2011-10-22 Thread Dave Angel

On 10/22/2011 06:10 PM, Chris Kavanagh wrote:
Hello, First, thank you for providing this GREAT service, & THANKS to 
everyone who contributes. It's greatly appreciated. . .I'm new to 
Python (2.7, Win XP) & new to programming in general. I have been 
studying on my own for about a month now. I believe I have a good 
grasp of the basics.


Secondly, I have several questions about this piece of code from 'A 
Byte Of Python' by Swaroop. Hope that's ok to use this code. I guess I 
could try to write a new ex. on my own, but, figured it would be too 
confusing.


My question is regarding the tell methods in the subclasses,the code 
{SchoolMember.tell(self)}, in the class Teacher & Student. I just 
don't understand what this is doing? Calling the first method {def 
tell} from the parent class, I assume? There is already a print 
statement in each of the subclass {def tell} showing details, why call 
another print statement (from parent class {def tell})?? I know this 
should be simple, but I'm confused. LOL, obviously.


Thank you in advance!


class SchoolMember:
'''Represents any school member.'''
def __init__(self,name,age):
self.name = name
self.age = age
print '(Initialized SchoolMember: %s)' %self.name

def tell(self):
'''Tell my details.'''
print 'Name:"%s" Age:"%s"' % (self.name, self.age),

class Teacher(SchoolMember):
'''Represents a teacher'''
def __init__(self,name,age,salary):
SchoolMember.__init__(self,name,age)
self.salary = salary
print '(Initialized Teacher: %s)' %self.name

def tell(self):
SchoolMember.tell(self)
print 'Salary: "%d"' % self.salary

class Student(SchoolMember):
'''Represents a student.'''
def __init__(self,name,age,marks):
SchoolMember.__init__(self,name,age)
self.marks = marks
print '(Initialized Student: %s)' %self.name

def tell(self):
SchoolMember.tell(self)
print 'Marks: "%d"' % self.marks

t = Teacher('Mrs. Shrividya',40,3)
s = Student('Swaroop',22,75)

print ##prints a blank line

members = [t,s]
for member in members:



OUTPUT

$ python inherit.py
(Initialized SchoolMember: Mrs. Shrividya)
(Initialized Teacher: Mrs. Shrividya)
(Initialized SchoolMember: Swaroop)
(Initialized Student: Swaroop)

Name:"Mrs. Shrividya" Age:"40" Salary: "3"
Name:"Swaroop" Age:"22" Marks: "75"
Welcome to the python-tutor list.  We are all volunteers here, and most, 
like me, ask questions as well as answering them.  it's a two-way street.


The whole point of subclassing is to share either code, data, or both.  
In this example, the amount of shared data is just the name and age, and 
the shared method is tell().  Because the parent knows how to 'tell' its 
information, the child doesn't need to.  So instead of altering the 
prints in both the child classes to print name & age, you let the common 
code in the parent handle it.


It becomes more clearly a win when you have much more data, or much more 
complex methods involved.  But you have to start simple.


BTW, there were some transcription errors in the email.  For example, 
the code as written would be using a separate line for Salary on Mrs. 
Shrividya's record.   And you're missing the content of the for member 
in members: loop.   No problem, but it might have affected our 
discussion.  Did you retype it all, or was it just a glitch?  Presumably 
you know how to copy/paste from and to a console prompt?

--

DaveA

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


Re: [Tutor] Simple Question On A Method (in subclass)

2011-10-22 Thread Alan Gauld

On 22/10/11 23:10, Chris Kavanagh wrote:


My question is regarding the tell methods in the subclasses,the code
{SchoolMember.tell(self)}, in the class Teacher & Student. I just don't
understand what this is doing? Calling the first method {def tell} from
the parent class, I assume?


Thats right, the child class is calling its parent class method.
This saves the child class from copying the code in the parent.


There is already a print statement in each of the subclass {def tell}

> showing details, why call another print statement

In this case it doesn't same much code (a few charactrs less) but with a 
more complex method it couyld be a lot iof saving. However, that's not 
the only advantage. If you want to change the format of the parent 
message you only need to change the parent code, the children get the 
change for free. Also if you copied the code into each child there is a 
real risk that you'd get the formatting slightly different. Then when 
you try to call the tell() method of a list of objects, some parents and 
some children the outputs would look different - thats messy.



class SchoolMember:
def tell(self):
'''Tell my details.'''
print 'Name:"%s" Age:"%s"' % (self.name, self.age),

class Teacher(SchoolMember):
def tell(self):
SchoolMember.tell(self)
print 'Salary: "%d"' % self.salary

class Student(SchoolMember):
def tell(self):
SchoolMember.tell(self)
print 'Marks: "%d"' % self.marks

t = Teacher('Mrs. Shrividya',40,3)
s = Student('Swaroop',22,75)

members = [t,s]
for member in members: member.tell()



Name:"Mrs. Shrividya" Age:"40" Salary: "3"
Name:"Swaroop" Age:"22" Marks: "75"


HTH

--
Alan G
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


Re: [Tutor] python telnet

2011-10-22 Thread Rayon
Well  what I am doing is connecting to a telnet session sending some
commands, exiting and returning some data. 
What  I would to do is send the commands and return the data without exiting
the session. 
I would like to keep the same session and just send commands and return
data.

#!/usr/bin/env python
import telnetlib

class hlr_com():

#get host and command 
def __init__(self):
"""init host and command  """
self.user_name = ''
self.password = '**'
self.host = '172.20.50.176'
self.command = ''

#edit top of return 
def fix_return(self,hia_return):
"""
edit the top of data returned form the hia
"""
try:
  data = str(hia_return).strip('\r')
  return data
except Exception,error:
   logs("error",str(err),'null')
 

#set host ip address
def set_host(self,host):
""" set host ipaddress"""
self.host = host

   

#send command to hia and end session
def hlr_telnet(self,command):
"""
connect to host and execute command and
exit
"""
try: 
hlr_tel = telnetlib.Telnet(self.host)
hlr_tel.read_until('login:')
hlr_tel.write(self.user_name+"\r")
hlr_tel.read_until('Password:')
hlr_tel.write(self.password+"\r")
#execute command 
hlr_tel.read_until('maint@atcaHLRds0 /public/users/maint>')
hlr_tel.write(command+'\r')
#end session
data = hlr_tel.read_until('maint@atcaHLRds0
/public/users/maint>')
hlr_tel.write('exit'+'\r')
data2 = self.fix_return(data)
#return data
return data2
except Exception,error:
logs("error",str(err),'null')

   
def logs(self,log_type,log_data,ip_address):
 """
 Log for errors 
 """
 try:
conn =
psycopg2.connect(database="hlr_proxy",user="postgres",host="localhost",
password="bb_server_1",port="5432") #connect to database
create_date = str(datetime.datetime.now())
cur = conn.cursor() # create cursor
cur.execute("insert into
hlr_logs(create_date,log_type,log_data,ip_address)values(%s,%s,%s,%s)",
(create_date,log_type,log_data,ip_address))
conn.commit()
cur.close()
conn.close()
 finally:
try: 
  log_file = open(r"text_log.txt","a")
 
log_file.write(create_date+","+log_type+","+log_data+","+str(ip_address)+'\r
'+'\n')
  log_file.close()
except Exception,error:
pass 








-Original Message-
From: tutor-bounces+evosweet=hotmail@python.org
[mailto:tutor-bounces+evosweet=hotmail@python.org] On Behalf Of Steven
D'Aprano
Sent: 22 October 2011 15:55
To: tutor@python.org
Subject: Re: [Tutor] python telnet

Rayon wrote:

> Can I connect to a telnet session and return data without 
> disconnecting the data session.

Isn't this the same question you asked back in June?

We tried to answer your question then, did you see our responses, and were
they useful?

At the time, you were complaining that the telnet session was too slow, but
you didn't tell us what you were actually doing. David Heiserca took a guess
as to what you were doing, and suggested what you should do again. Did you
see his response, and was it helpful?

You should show us the code you are using.


--
Steven

___
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] python telnet

2011-10-22 Thread Steven D'Aprano

Rayon wrote:

Well  what I am doing is connecting to a telnet session sending some
commands, exiting and returning some data. 
What  I would to do is send the commands and return the data without exiting
the session. 
I would like to keep the same session and just send commands and return

data.


Change the work-flow from:

repeatedly:-
  log in
  write data
  log out

to:

log in
repeatedly:
  write data
log out



This is untested, but it should point you in the right direction. For 
brevity, anything unchanged will be left out.



#!/usr/bin/env python
import telnetlib

class hlr_com():
#get host and command
def __init__(self):
"""init host and command  """
self.user_name = ''
self.password = '**'
self.host = '172.20.50.176'
self.command = ''
self._connected = False

def fix_return(self,hia_return):
# UNCHANGED FROM YOUR VERSION

#set host ip address
def set_host(self,host):
# UNCHANGED FROM YOUR VERSION

def connect(self):
# If already connected, do nothing.
if self._connected:
return
try:
hlr_tel = telnetlib.Telnet(self.host)
hlr_tel.read_until('login:')
hlr_tel.write(self.user_name+"\r")
hlr_tel.read_until('Password:')
hlr_tel.write(self.password+"\r")
self._connected = True
except Exception,error:
logs("error",str(err),'null')

def execute(self, command):
"""execute command"""
try:
self._execute_or_fail(command)
except Exception,error:
logs("error",str(err),'null')

def _execute_or_fail(self, command):
if not self._connected:
# This is probably the wrong exception type
raise ValueError('you must connect first')
# otherwise execute the command
hlr_tel.read_until('maint@atcaHLRds0 /public/users/maint>')
hlr_tel.write(command+'\r')

def end_session(self):
data = hlr_tel.read_until(
'maint@atcaHLRds0 /public/users/maint>'
)
hlr_tel.write('exit'+'\r')
data = self.fix_return(data)
return data

def logs(self,log_type,log_data,ip_address):
# UNCHANGED FROM YOUR VERSION



To use it:


instance = hlr_com()
instance.connect()
instance.execute("fe")
instance.execute("fi")
instance.execute("fo")
instance.execute("fum")
instance.end_session()


As I said, untested. Good luck!



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


Re: [Tutor] python telnet

2011-10-22 Thread Rayon
Thanks  I will try it and post the code, looks like what I need.

-Original Message-
From: tutor-bounces+evosweet=hotmail@python.org
[mailto:tutor-bounces+evosweet=hotmail@python.org] On Behalf Of Steven
D'Aprano
Sent: 22 October 2011 21:13
To: tutor@python.org
Subject: Re: [Tutor] python telnet

Rayon wrote:
> Well  what I am doing is connecting to a telnet session sending some 
> commands, exiting and returning some data.
> What  I would to do is send the commands and return the data without 
> exiting the session.
> I would like to keep the same session and just send commands and 
> return data.

Change the work-flow from:

repeatedly:-
   log in
   write data
   log out

to:

log in
repeatedly:
   write data
log out



This is untested, but it should point you in the right direction. For
brevity, anything unchanged will be left out.


#!/usr/bin/env python
import telnetlib

class hlr_com():
 #get host and command
 def __init__(self):
 """init host and command  """
 self.user_name = ''
 self.password = '**'
 self.host = '172.20.50.176'
 self.command = ''
 self._connected = False

 def fix_return(self,hia_return):
 # UNCHANGED FROM YOUR VERSION

 #set host ip address
 def set_host(self,host):
 # UNCHANGED FROM YOUR VERSION

 def connect(self):
 # If already connected, do nothing.
 if self._connected:
 return
 try:
 hlr_tel = telnetlib.Telnet(self.host)
 hlr_tel.read_until('login:')
 hlr_tel.write(self.user_name+"\r")
 hlr_tel.read_until('Password:')
 hlr_tel.write(self.password+"\r")
 self._connected = True
 except Exception,error:
 logs("error",str(err),'null')

 def execute(self, command):
 """execute command"""
 try:
 self._execute_or_fail(command)
 except Exception,error:
 logs("error",str(err),'null')

 def _execute_or_fail(self, command):
 if not self._connected:
 # This is probably the wrong exception type
 raise ValueError('you must connect first')
 # otherwise execute the command
 hlr_tel.read_until('maint@atcaHLRds0 /public/users/maint>')
 hlr_tel.write(command+'\r')

 def end_session(self):
 data = hlr_tel.read_until(
 'maint@atcaHLRds0 /public/users/maint>'
 )
 hlr_tel.write('exit'+'\r')
 data = self.fix_return(data)
 return data

 def logs(self,log_type,log_data,ip_address):
 # UNCHANGED FROM YOUR VERSION



To use it:


instance = hlr_com()
instance.connect()
instance.execute("fe")
instance.execute("fi")
instance.execute("fo")
instance.execute("fum")
instance.end_session()


As I said, untested. Good luck!



-- 
Steven
___
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


[Tutor] Praser

2011-10-22 Thread Henry
Hi Steven,

First of all, I want to able to download the data from the web into
the database. Here is the part of the link:

http://boc.quotepower.com/web/bochk/stocks_mktTransactions.jsp?lang=en&domain=NCBHK&rand=-74344993&lastLevel1Name=nav_stocks&lastStock=5

I hope I can use the download data to do some analysis.

I know it is an impossible task for a newbie; however, I don't mind
doing it step by step. Thank you

Regads,
Crusier



On Fri, Oct 21, 2011 at 1:40 PM,   wrote:
> Send Tutor mailing list submissions to
>        tutor@python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>        http://mail.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
>        tutor-requ...@python.org
>
> You can reach the person managing the list at
>        tutor-ow...@python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Tutor digest..."
>
>
> Today's Topics:
>
>   1. functions and default argument (Praveen Singh)
>   2. Re: functions and default argument (Christian Witts)
>   3. Web Praser (Crusier)
>   4. Re: functions and default argument (Steven D'Aprano)
>   5. Re: Web Praser (Steven D'Aprano)
>   6. Re: functions and default argument (Prasad, Ramit)
>   7. Re: functions and default argument (Albert-Jan Roskam)
>
>
> --
>
> Message: 1
> Date: Fri, 21 Oct 2011 09:00:08 -0400
> From: Praveen Singh 
> To: tutor@python.org
> Subject: [Tutor] functions and default argument
> Message-ID:
>        
> Content-Type: text/plain; charset="iso-8859-1"
>
> In function-
>
> "Default value is *evaluated only once*.This makes different when the
> default is a mutable object such as a list, dictionary or instance of most
> classes."
>
> I am not getting it properly-evaluated once?? different behaviour???--
> please explain this.
> -- next part --
> An HTML attachment was scrubbed...
> URL: 
> 
>
> --
>
> Message: 2
> Date: Fri, 21 Oct 2011 15:19:39 +0200
> From: Christian Witts 
> To: Praveen Singh 
> Cc: tutor@python.org
> Subject: Re: [Tutor] functions and default argument
> Message-ID: <4ea1716b.5060...@compuscan.co.za>
> Content-Type: text/plain; charset="windows-1252"; Format="flowed"
>
> On 2011/10/21 03:00 PM, Praveen Singh wrote:
>> In function-
>>
>> "Default value is *evaluated only once*.This makes different when the
>> default is a mutable object such as a list, dictionary or instance of
>> most classes."
>>
>> I am not getting it properly-evaluated once?? different behaviour???--
>> please explain this.
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>
> Mutable defaults for function/method arguments is a Python Gotcha, you
> can find a good read here [1].  It's a better read than how I would
> explain it.
>
> [1] http://www.ferg.org/projects/python_gotchas.html#contents_item_6
> --
>
> Christian Witts
> Python Developer
>
> //
> -- next part --
> An HTML attachment was scrubbed...
> URL: 
> 
>
> --
>
> Message: 3
> Date: Fri, 21 Oct 2011 09:37:40 -0700
> From: Crusier 
> To: tutor@python.org
> Subject: [Tutor] Web Praser
> Message-ID:
>        
> Content-Type: text/plain; charset=ISO-8859-1
>
> Hi,
>
> I am new to programming. I want to know what I should look at if I
> want to learn more about Web Praser. I know there is something called
> Beautiful Soup but I think it is kind of difficult for me at this
> stage.
>
> Thank you
>
> Regards,
> Crusier
>
>
> --
>
> Message: 4
> Date: Sat, 22 Oct 2011 04:25:51 +1100
> From: Steven D'Aprano 
> To: tutor@python.org
> Subject: Re: [Tutor] functions and default argument
> Message-ID: <4ea1ab1f.4090...@pearwood.info>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> Praveen Singh wrote:
>> In function-
>>
>> "Default value is *evaluated only once*.This makes different when the
>> default is a mutable object such as a list, dictionary or instance of most
>> classes."
>>
>> I am not getting it properly-evaluated once?? different behaviour???--
>> please explain this.
>
>
> Look at an example:
>
>
>  >>> import time
>  >>> def test(t=time.asctime()):
> ...     print t, "***", time.asctime()
> ...
>  >>> time.sleep(30)  # wait a little bit
>  >>> test()
> Sat Oct 22 04:17:08 2011 *** Sat Oct 22 04:17:57 2011
>  >>> time.sleep(30)  # wait a little bit longer
>  >>> test()
> Sat Oct 22 04:17:08 2011 *** Sat Oct 22 04:18:46 2011
>
>
> Notice that the first time printed, using the default value, is the
> same. The default value for