Re: [Tutor] Passing perimeters in dictionary values?

2009-02-25 Thread spir
Le Wed, 25 Feb 2009 00:01:49 -,
"Alan Gauld"  s'exprima ainsi:

> 
> "nathan virgil"  wrote 
> 
> > I'm not familiar with lambdas yet, and I don't think this book will
> > introduce me to them; they aren't listed in the index, anyway.
> 
> lambda is just a fancy mathematical name for a simple 
> concept - its a block of code, like the body of a function.
> In Python its even simpler, it is an expression. And we 
> store that expression and make it callable.
> 
> 
> def funcname(aParam):
>   return 
> 
> is the same as
> 
> funcname = lambda aParam: 
> 
> In some languages, including some Lisp dialects function 
> definitions are syntactic sugar for exactly that kind of lambda 
> assignment. Some even make it explicit as in:
> 
> (define func
>( lambda (aParam) 
>  (expression using aParam)))

In io (a wonderful prototype-based languages which syntax reflects the code 
structure (read: parse tree) like in Lisp), you would have:

method_name := method(aParam, )

for instance:

perimeter := method(radius, 2 * PI * radius)
average := method(values,
sum := values sum
sum / values count
)

[Above: there is not '.' -- return value needs not be explicit]

> In Python its more like the other way around, functions are 
> defined using def and lambdas are really syntax wrapped 
> around that. 
> 
> lambdas are often offputting to beginners but they are useful 
> in avoiding lots of small oneliner type functions (and the resultant 
> namespace clutter) and they are very important in understanding
> the theory behind computing (ie. Lambda calculus).
> 
> HTH,
> 
> 


--
la vita e estrany
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Passing perimeters in dictionary values?

2009-02-25 Thread Andre Engels
On Wed, Feb 25, 2009 at 2:32 AM, nathan virgil  wrote:
> Erm, it's still not working...
>
> Whenever I try to use the talk method (which reports the mood, and doesn't
> take parameters), it says I gave it too many parameters. Maybe it might help
> if I posted the code in it's entirety
>
>
> # Critter Caretaker
> # A virtual pet to care for
>
> class Critter(object):
>     """A virtual pet"""
>     def __init__(self, name, hunger = 0, boredom = 0):
>     self.name = name
>     self.hunger = hunger
>     self.boredom = boredom
>
>     def __pass_time(self):
>     self.hunger += 1
>     self.boredom += 1
>
>     def __get_mood(self):
>     unhappiness = self.hunger + self.boredom
>     if unhappiness < 5:
>     mood = "happy"
>     elif 5 <= unhappiness <= 10:
>     mood = "okay"
>     elif 11 <= unhappiness <= 15:
>     mood = "frustrated"
>     else:
>     mood = "mad"
>     return mood
>
>     mood = property(__get_mood)
>
>     def talk(self):
>     print "I'm", self.name, "and I feel", self.mood, "now.\n"
>     self.__pass_time()
>
>     def eat(self, food = 4):
>     print "Brruppp.  Thank you."
>     self.hunger -= food
>     if self.hunger < 0:
>     self.hunger = 0
>     self.__pass_time()
>
>     def play(self, fun = 4):
>     print "Wheee!"
>     self.boredom -= fun
>     if self.boredom < 0:
>     self.boredom = 0
>     self.__pass_time()
>
>     def backdoor(self):
>     print "hunger:", self.hunger, "boredom:", self.boredom
>
> def quit():
>     print "God-bye!"
>
>
> def main():
>     crit_name = raw_input("What do you want to name your critter?: ")
>     crit = Critter(crit_name)
>
>     selection = None
>     while selection != "0":
>     print \
>     """
>     Critter Caretaker
>
>     0 - Quit
>     1 - Listen to your critter
>     2 - Feed your critter
>     3 - Play with your critter
>     """
>
>     selection = raw_input("Choice: ")
>     choices = {"0":(quit, None), "1":(crit.talk, None), "2":(crit.eat,
> 3), "3":(crit.play, 3), "Xyzzy":(crit.backdoor, None)}
>     if selection in choices:
>    choice = choices[selection]
>    choice[0](choice[1])

Yes, that won't work - you are now calling 'quit' and 'talk' with the
argument 'None' rather than without an argument. One way to resolve
this would be to use my proposal: take out the "None"s (but keep the
comma before it) and chance this line to
  choice[0](*choice[1:])
which also has the advantage of still working with more than one argument

Another would be to not change the definition of choices, but replace
choice[0](choice[1])

by:
if not choice[1] is None:
 choice[0](choice[1])



-- 
André Engels, andreeng...@gmail.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Passing perimeters in dictionary values?

2009-02-25 Thread Alan Gauld


"nathan virgil"  wrote

Whenever I try to use the talk method (which reports the mood, and 
doesn't

take parameters), it says I gave it too many parameters.


Sorry, I should have pointed out that you will need to redefine
all your functions to accept a parameter.

Alan G 



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


[Tutor] overwriting input file

2009-02-25 Thread Bala subramanian
Hello all,

query 1) How should i overwrite the input file
I want to open 5 files one by one, do some operation on the lines and write
the modified lines on the same file (overwritting). Can some please tell me
how to do it.

pat1=" R"
pat2="U5"
pat3="A3"
from sys import argv
files=argv[1:]
for names in files:
out=open(names + '_new','w')  # Here i creat new files to write the
content which i dnt want
for line in open(names):
if pat1 in line:
line=line.replace(pat1,"  ")
if pat2 in line:
line=line.replace(pat2,"U ")
if pat3 in line:
line=line.replace(pat3,"A ")
out.write(line)

query 2) How should I use wild cards to open files in python. Say I have
files with names *.dat  in a directory, i want the program to open every
file with extension .dat and do the process.

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


[Tutor] re Formating

2009-02-25 Thread prasad rao
hi
>>> licenseRe = re.compile(r'\(([A-Z]+)\)\s*(No.\d+)?')
>>> for license in licenses:
  m = licenseRe.search(license)
  print m.group(1, 3)



Traceback (most recent call last):
  File "", line 3, in 
print m.group(1, 3)
IndexError: no such group

Something wrong with this code.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] overwriting input file

2009-02-25 Thread A.T.Hofkamp

Bala subramanian wrote:

Hello all,

query 1) How should i overwrite the input file
I want to open 5 files one by one, do some operation on the lines and write
the modified lines on the same file (overwritting). Can some please tell me
how to do it.


You cannot write output to a file if you need the data in the file for input 
first.

You'll have to do it in sequence.

Either first read all input into memory, then open the file for output, or
write the output to a temporary file while reading the input, then rename the 
temporary file.



To prevent problems, be sure to close the input files after reading and before 
you overwrite them.



query 2) How should I use wild cards to open files in python. Say I have
files with names *.dat  in a directory, i want the program to open every
file with extension .dat and do the process.


The glob module should be able to solve that problem for you.


Sincerely,
Albert

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


[Tutor] Formatting

2009-02-25 Thread prasad rao
hi
 for license in licenses:
  m = licenseRe.search(license)
  print m.group(1, 2)


('ABTA', 'No.56542')
('ATOL', None)
('IATA', None)
('ITMA', None)
Yes It is working
Thank you
Prasad
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] overwriting input file

2009-02-25 Thread Noufal Ibrahim

Bala subramanian wrote:

Hello all,

query 1) How should i overwrite the input file
I want to open 5 files one by one, do some operation on the lines and 
write the modified lines on the same file (overwritting). Can some 
please tell me how to do it.


import fileinput
pat1=" R"
pat2="U5"
pat3="A3"
files = fileinput.Fileinput(sys.argv[1:], inplace = 1)
for i in files:
  if pat1 in i: print i.replace(pat1," ")
  if pat2 in i: print i.replace(pat2,"U ")
  if pat3 in i: print i.replace(pat3,"A ")
files.close()

should work for you. Check out the fileinput documentation for details 
especially the 'inplace' argument. It's untested though.


Personally speaking, I think the stdout redirection business violates 
the 'explicit is better than implicit' rule.



query 2) How should I use wild cards to open files in python. Say I have 
files with names *.dat  in a directory, i want the program to open every 
file with extension .dat and do the process.


import glob
glob.glob(r"*.dat")

should do that for you.

--
~noufal
http://nibrahim.net.in/
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] overwriting input file

2009-02-25 Thread Noufal Ibrahim

A.T.Hofkamp wrote:

write the output to a temporary file while reading the input, then 
rename the temporary file.


This I believe is what the fileinput module does when you use it with 
the inplace parameter set to 1.



--
~noufal
http://nibrahim.net.in/
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] re Formating

2009-02-25 Thread Kent Johnson
On Wed, Feb 25, 2009 at 7:46 AM, prasad rao  wrote:
> hi
 licenseRe = re.compile(r'\(([A-Z]+)\)\s*(No.\d+)?')
 for license in licenses:
>       m = licenseRe.search(license)
>       print m.group(1, 3)
>
> Traceback (most recent call last):
>   File "", line 3, in 
>     print m.group(1, 3)
> IndexError: no such group
> Something wrong with this code.

There are only two groups in the re, try
  print m.group(1, 2)

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


Re: [Tutor] overwriting input file

2009-02-25 Thread Kent Johnson
On Wed, Feb 25, 2009 at 8:26 AM, Noufal Ibrahim  wrote:
> Bala subramanian wrote:
>>
>> Hello all,
>>
>> query 1) How should i overwrite the input file
>> I want to open 5 files one by one, do some operation on the lines and
>> write the modified lines on the same file (overwritting). Can some please
>> tell me how to do it.
>
> import fileinput
> pat1=" R"
> pat2="U5"
> pat3="A3"
> files = fileinput.Fileinput(sys.argv[1:], inplace = 1)
> for i in files:
>  if pat1 in i: print i.replace(pat1," ")
>  if pat2 in i: print i.replace(pat2,"U ")
>  if pat3 in i: print i.replace(pat3,"A ")
> files.close()
>
> should work for you. Check out the fileinput documentation for details
> especially the 'inplace' argument. It's untested though.

This doesn't do quite the same as the original, it only writes
modified lines. Also I think it will add extra newlines, you should
use sys.stdout.write(i) instead of print i.

I would put the patterns in a list and use a loop. I think the test
for the pattern is not needed, the replace does the same search.
patterns = [
  (' R', ' '),
  ('U5', 'U '),
  ('A3', 'A ')
]

files = fileinput.Fileinput(sys.argv[1:], inplace = 1)
for line in files:
  for pat, repl in patterns:
line = line.replace(pat, repl)
  sys.stdout.write(line)

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


Re: [Tutor] Standardizing on Unicode and utf8

2009-02-25 Thread Thorsten Kampe
* Dinesh B Vadhia (Fri, 20 Feb 2009 02:52:27 -0800)
> We want to standardize on unicode and utf8

Very good idea.

> and would like to clarify and verify their use to minimize encode
> ()/decode()'ing:
> 
> 1.  Python source files 
> Use the header: # -*- coding: utf8 -*-

Good idea (although only valid for comments and "inline" strings


> 2.  Reading files
> In most cases, we don't know the source encoding of the files being
> read. Do we have to decode('utf8') after reading from file?

No. If you don't know the encoding of the file you can't decode it, of 
course. You can read() it of course, but you can't process it (as text).
 
> 3. Writing files
> We will always write to files in utf8. Do we have to encode('utf8')
> before writing to file?

Yes, sure.

> Is there anything else that we have to consider?

Hm, in general nothing I'm aware of.

Thorsten

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


Re: [Tutor] Standardizing on Unicode and utf8

2009-02-25 Thread Thorsten Kampe
* spir (Fri, 20 Feb 2009 13:02:59 +0100)
> Le Fri, 20 Feb 2009 02:52:27 -0800,
> "Dinesh B Vadhia"  s'exprima ainsi:
> 
> > We want to standardize on unicode and utf8 and would like to clarify and
> > verify their use to minimize encode()/decode()'ing:
> > 
> > 1.  Python source files 
> > Use the header: # -*- coding: utf8 -*-
> 
> You don't even need fancy decoration:
> 
> # coding: utf-8
> 
> is enough.

Sure? Never heard of that. Interesting...

Thorsten

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


Re: [Tutor] Add readline capabilities to a Python build 2.6 on Ubuntu

2009-02-25 Thread Thorsten Kampe
* Eric Dorsey (Thu, 19 Feb 2009 12:24:07 -0700)
> Still doesnt work.. I just get this when I hit the up arrow:>>> ^[[A
> 
> Bah. It works in the 2.5 version that came packaged with it. Thanks for
> trying :)

There's a log for the ./configure. See if the configure script can find 
readline.

Thorsten

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


Re: [Tutor] overwriting input file

2009-02-25 Thread Alan Gauld


"Bala subramanian"  wrote


query 1) How should i overwrite the input file
I want to open 5 files one by one, do some operation on the lines 
and write
the modified lines on the same file (overwritting). Can some please 
tell me

how to do it.


You don't really want to do that! Too risky.
Better to do what you are doing and then when it has all worked
and you close both input and output files you can delete the
original and rename the outfile to the original input file name.
In fact to be really safe don't delete the old file but rename
it to .bak...

For copying and renaming filers see the os and shutil modules
and the Using the OS topic in my tutorial.


query 2) How should I use wild cards to open files in python.


Look at the glob module. It uses wildcards to build lists of
matching file names.

HTH,


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



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


Re: [Tutor] Standardizing on Unicode and utf8

2009-02-25 Thread Kent Johnson
On Wed, Feb 25, 2009 at 12:46 PM, Thorsten Kampe
 wrote:
> * spir (Fri, 20 Feb 2009 13:02:59 +0100)

>> > Use the header: # -*- coding: utf8 -*-
>>
>> You don't even need fancy decoration:
>>
>> # coding: utf-8
>>
>> is enough.
>
> Sure? Never heard of that. Interesting...

>From PEP 263 (http://www.python.org/dev/peps/pep-0263/):
To define a source code encoding, a magic comment must
be placed into the source files either as first or second
line in the file, such as:

  # coding=

or (using formats recognized by popular editors)

  #!/usr/bin/python
  # -*- coding:  -*-

or

  #!/usr/bin/python
  # vim: set fileencoding= :

More precisely, the first or second line must match the regular
expression "coding[:=]\s*([-\w.]+)".

The -*- style is also recognized by some editors.

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


Re: [Tutor] overwriting input file

2009-02-25 Thread Kent Johnson
On Wed, Feb 25, 2009 at 1:53 PM, Alan Gauld  wrote:
>
> "Bala subramanian"  wrote
>
>> query 1) How should i overwrite the input file
>> I want to open 5 files one by one, do some operation on the lines and
>> write
>> the modified lines on the same file (overwritting). Can some please tell
>> me
>> how to do it.
>
> You don't really want to do that! Too risky.
> Better to do what you are doing and then when it has all worked
> and you close both input and output files you can delete the
> original and rename the outfile to the original input file name.
> In fact to be really safe don't delete the old file but rename
> it to .bak...

The fileinput module with inplace=1, backup='.bak' does close to what
you are describing. It renames the input file before opening it, so if
there is a failure it will be renamed.

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


Re: [Tutor] Accessing callers context from callee method

2009-02-25 Thread mobiledreamers
i found the solution
This is my first attempt at memcaching html page using cheetah
since cheetah render needs locals() i use getCallerInfo() to get the
locals() and send to memcached
let me know if it is possible to better do this
*notice getCallerInfo
*

*utils.py*
@log_time_func
def renderpage(key, htmlfile, deleteafter=3600):
from globaldb import mc
try:page = mc.get(key)
except:
page=None
clogger.info('except error mc.get '+ key)
if not page:
clogger.info(key+ ' rendering cheetah page')
terms = getCallerInfo(1)
#print terms
page = str(web.render(htmlfile, asTemplate=True, terms=terms))
try:mc.set(key, page, deleteafter)
except:
clogger.info('except error mc.set '+ key)
return page

@log_time_func
@memcachethis
def mcrenderpage(key, htmlfile, deleteafter=3600):
terms = getCallerInfo(2)
#print terms
return str(web.render(htmlfile, asTemplate=True, terms=terms))

def getCallerInfo(decorators=0):
'''returns locals of caller using frame.optional pass number of
decorators\nFrom Dig deep into python internals
http://www.devx.com/opensource/Article/31593/1954'
''
f = sys._getframe(2+decorators)
args = inspect.getargvalues(f)
return args[3]

*Usage*
key=facebookstuff.APP_NAME+'newstart'+str(uid)
return utils.renderpage(key, 'pick.html')



-- 
Bidegg worlds best auction site
http://bidegg.com

On Tue, Feb 24, 2009 at 11:21 PM, A.T.Hofkamp  wrote:

> mobiledream...@gmail.com wrote:
>
>> when i call a method foo from another method func. can i access func
>> context
>> variables or locals() from foo
>> so
>> def func():
>>  i=10
>>  foo()
>>
>> in foo, can i access func's local variables on in this case i
>>
>
> As others have already pointed out, this is a really bad idea.
> Instead you can do:
>
>
> def func():
>  i = 10
>  i = foo(i)
>
> def foo(i):
>  i = i + 1
>  return i
>
> Sincerely,
> Albert
>
>
> ___
> 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] Accessing callers context from callee method

2009-02-25 Thread mobiledreamers
i found the solution
This is my first attempt at memcaching html page using cheetah
since cheetah render needs locals() i use getCallerInfo() to get the
locals() and send to memcached
let me know if it is possible to better do this
*notice getCallerInfo
*

*utils.py*
@log_time_func
def renderpage(key, htmlfile, deleteafter=3600):
from globaldb import mc
try:page = mc.get(key)
except:
page=None
clogger.info('except error mc.get '+ key)
if not page:
clogger.info(key+ ' rendering cheetah page')
terms = getCallerInfo(1)
#print terms
page = str(web.render(htmlfile, asTemplate=True, terms=terms))
try:mc.set(key, page, deleteafter)
except:
clogger.info('except error mc.set '+ key)
return page

@log_time_func
@memcachethis
def mcrenderpage(key, htmlfile, deleteafter=3600):
terms = getCallerInfo(2)
#print terms
return str(web.render(htmlfile, asTemplate=True, terms=terms))

def getCallerInfo(decorators=0):
'''returns locals of caller using frame.optional pass number of
decorators\nFrom Dig deep into python internals
http://www.devx.com/opensource/Article/31593/1954'
''
f = sys._getframe(2+decorators)
args = inspect.getargvalues(f)
return args[3]

*Usage*
key=facebookstuff.APP_NAME+'newstart'+str(uid)
return utils.renderpage(key, 'pick.html')



-- 
Bidegg worlds best auction site
http://bidegg.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Add readline capabilities to a Python build 2.6 on Ubuntu

2009-02-25 Thread Lie Ryan
On Thu, 19 Feb 2009 09:27:34 +0300, زياد بن عبدالعزيز الباتلي wrote:

> On Wed, 18 Feb 2009 20:19:56 -0700
> Eric Dorsey  wrote:
>> I did an aptitute install of  ibreadline5-dev and then did ./configure
>> and make again, and still don't have any functionality to be able to
>> hit up-arrow and get a command repeated while inside the interpreter.
>> Any ideas?
>> 
>> 
> I don't know what's wrong, Python should pickup "libreadline" and use it
> automatically if it was installed.
> 
> Try passing "--with-readline" to the "configure" script.
> 
> If that doesn't help, then I'm sorry, I'm out of ideas.
> 

Try installing other readline modules that looks suspicious. In my Ubuntu 
machine (these are all readline-related modules in my machine, not only 
the ones that is needed for python), I have these packages installed:
v   lib32readline-dev-
v   libghc6-readline-dev -
v   libghc6-readline-doc -
v   libghc6-readline-prof-
v   libreadline-dbg  -
v   libreadline-dev  -
i   libreadline5 - GNU readline and history libraries, run-ti
i A libreadline5-dev - GNU readline and history libraries, develo
i   readline-common  - GNU readline and history libraries, common

try matching that and ./configure then make.

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


Re: [Tutor] Add readline capabilities to a Python build 2.6 on Ubuntu

2009-02-25 Thread Eric Dorsey
Thanks for all your continued insights on this. I'm going to investigate the
.configure log, as well as look around at other readline packages.. But,
noob question, did you just go into something like synaptic to find out what
readline type packages are installed? (Sorry if this is annoying anyone on
the list, but its all in the name of getting the Python inerpreter to be
happy !) Or did you do some kind of command line aptitude "list out readine
stuff"?

On Wed, Feb 25, 2009 at 10:01 PM, Lie Ryan  wrote:

> On Thu, 19 Feb 2009 09:27:34 +0300, زياد بن عبدالعزيز الباتلي wrote:
>
> > On Wed, 18 Feb 2009 20:19:56 -0700
> > Eric Dorsey  wrote:
> >> I did an aptitute install of  ibreadline5-dev and then did ./configure
> >> and make again, and still don't have any functionality to be able to
> >> hit up-arrow and get a command repeated while inside the interpreter.
> >> Any ideas?
> >>
> >>
> > I don't know what's wrong, Python should pickup "libreadline" and use it
> > automatically if it was installed.
> >
> > Try passing "--with-readline" to the "configure" script.
> >
> > If that doesn't help, then I'm sorry, I'm out of ideas.
> >
>
> Try installing other readline modules that looks suspicious. In my Ubuntu
> machine (these are all readline-related modules in my machine, not only
> the ones that is needed for python), I have these packages installed:
> v   lib32readline-dev-
> v   libghc6-readline-dev -
> v   libghc6-readline-doc -
> v   libghc6-readline-prof-
> v   libreadline-dbg  -
> v   libreadline-dev  -
> i   libreadline5 - GNU readline and history libraries, run-ti
> i A libreadline5-dev - GNU readline and history libraries, develo
> i   readline-common  - GNU readline and history libraries, common
>
> try matching that and ./configure then make.
>
> ___
> 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] Add readline capabilities to a Python build 2.6 on Ubuntu

2009-02-25 Thread Lie Ryan
On Wed, 2009-02-25 at 22:23 -0700, Eric Dorsey wrote:
> Thanks for all your continued insights on this. I'm going to
> investigate the .configure log, as well as look around at other
> readline packages.. But, noob question, did you just go into something
> like synaptic to find out what readline type packages are installed?
> (Sorry if this is annoying anyone on the list, but its all in the name
> of getting the Python inerpreter to be happy !) Or did you do some
> kind of command line aptitude "list out readine stuff"?

Yeah, you can go to synaptic and and do a search. Alternatively, you
type "aptitude search readline" on the terminal (no need for sudo/root
access for search). If you found what you want to install, you can use
"sudo apt-get install " or "sudo aptitude install
". Synaptic is fine too, but not the "Add/Remove
Application", the "Add/Remove Application" allows you to install
applications not single packages.

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


[Tutor] how to instantiate a class

2009-02-25 Thread Abhishek Kumar
hello list,

Below is the sample code of a class.


import 

Class ABC:
 def __init__(self,a,b,c):
statement 1
 statement 2
 def func(x,y):
   statement 1
   statement 2

Here is the question:

how to make an object of this class and how to use the methods listed
in the class.
do i need to create the object in a separate file or in the same file
it can be done ??
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to instantiate a class

2009-02-25 Thread Lie Ryan
On Thu, 26 Feb 2009 12:38:27 +0530, Abhishek Kumar wrote:

> hello list,
> 

You need to read through the tutorial first: http://docs.python.org/
tutorial/

If there are still things you don't understand, please ask again.

As for your question, here is a sample useless python code:

class MyClass(object):
def __init__(self, arg):
self.a = arg
def foo(self, b):
return self.a + b

myinstance = MyClass(5)
print myinstance.foo(6)

# output
11

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


Re: [Tutor] how to instantiate a class

2009-02-25 Thread Lie Ryan
On Thu, 26 Feb 2009 12:38:27 +0530, Abhishek Kumar wrote:

> hello list,
> 

You need to read through the tutorial first: http://docs.python.org/
tutorial/

If there are still things you don't understand, please ask again.

As for your question, here is a sample useless python code:

class MyClass(object):
def __init__(self, arg):
self.a = arg
def foo(self, b):
return self.a + b

myinstance = MyClass(5)
print myinstance.foo(6)

# output
11

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


Re: [Tutor] how to instantiate a class

2009-02-25 Thread Arun Tomar
@Abhishek,

On 2/26/09, Abhishek Kumar  wrote:
> hello list,
>
> Below is the sample code of a class.
>
>
> import 
>
> Class ABC:
>  def __init__(self,a,b,c):
> statement 1
>  statement 2
>  def func(x,y):
>statement 1
>statement 2
>
> Here is the question:
>
> how to make an object of this class and how to use the methods listed
> in the class.

you can make object

newobj = ABC()

using the methods would be

newobj.func()

> do i need to create the object in a separate file or in the same file
> it can be done ??

It's upto you. You can create the object in the same file or separate
file, both works.

kindly read the documentation, especially the tutorial section. It's
one of the best available resources for learning python.

http://docs.python.org/

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


-- 
Regards,
Arun Tomar
blog: http://linuxguy.in
website: http://www.solutionenterprises.co.in
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to instantiate a class

2009-02-25 Thread Moos Heintzen
Here is a good book if you are already familiar with other languages.

http://diveintopython.org/object_oriented_framework/instantiating_classes.html
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor