[Tutor] backreferences - \0

2010-06-06 Thread Payal
Hi,
A newbie re query.

>>> import re
>>> s='one'
>>> re.sub('(one)','only \\0',s)
'only \x00'
>>> re.sub('(one)','only \0',s)
'only \x00'

I expected the output to be 'only one' with \0 behaving like "&" in sed.
What is wrong with my syntax?

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


Re: [Tutor] backreferences - \0

2010-06-06 Thread Payal
On Sun, Jun 06, 2010 at 06:26:18PM +1000, Steven D'Aprano wrote:
> Two things. Firstly, the Python regex engine numbers backreferences from 
> 1, not 0, so you need \1 and not \0.

Thank for the mail, but i am still not getting it. e.g.


>>> import re
>>> s = 'one two'
>>> re.sub('(one) (two)', r'\1 - \2 \3',s)
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python2.6/re.py", line 151, in sub
return _compile(pattern, 0).sub(repl, string, count)
  File "/usr/lib/python2.6/re.py", line 278, in filter
return sre_parse.expand_template(template, match)
  File "/usr/lib/python2.6/sre_parse.py", line 795, in expand_template
raise error, "invalid group reference"
sre_constants.error: invalid group reference
>>> re.sub('(one) (two)', r'\1 - \2',s)
'one - two'

In first sub I expected,
one two - one two

I understand that \1 is first (group), \2 the second and etc.
But what is the entire regex?

With warm regards,
-Payal
-- 

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


Re: [Tutor] backreferences - \0

2010-06-06 Thread Payal
On Sun, Jun 06, 2010 at 07:52:43PM +1000, Lie Ryan wrote:
> >>> re.sub('(one) (two)', r'\g<0> - \1 \2',s)
> 
> the \g is equivalent to \number but is intended to ambiguate
> cases like "\g<2>0" vs. "\20". It happens that \g<0> refers to the
> entire group.

Thanks a lot. It works as you say.

With warm regards,
-Payal
-- 

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


[Tutor] a class query

2010-06-07 Thread Payal
Hi all,
I know the difference  between
class Parent :
class Parent(object) :

But in some softwares i recall seeing,
class Parent() :

Is this legal syntax?

With warm regards,
-Payal
-- 



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


[Tutor] no. of references

2010-06-07 Thread Payal
Hi,
If I have a list (or a dict), is there any way of knowing how many other
variables are referencing the same object?

With warm regards,
-Payal
-- 



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


Re: [Tutor] a class query

2010-06-07 Thread Payal
On Tue, Jun 08, 2010 at 02:11:10AM +1000, Steven D'Aprano wrote:
> In Python 2.x, all classes are old-style unless you directly or 
> indirectly inherit from object. If you inherit from nothing, it is an 
> old-style class regardless of whether you say 
> 
> class Name: pass
> 
> or 
> 
> class Name(): pass
> 
> In Python 3.x, there are no old-style classes.

Thanks, that clears my doubt.


With warm regards,
-Payal
-- 

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


Re: [Tutor] no. of references

2010-06-08 Thread Payal
Hi all,
Excuse for TOFU. Thanks a lot Steven, Dave and Hugo.
Steven the explanation was really great. Thanks a  lot for it.
Hugo, I was just curious, have no real need. Thanks.

With warm regards,
-Payal
-- 


On Tue, Jun 08, 2010 at 08:07:28PM +1000, Steven D'Aprano wrote:
> On Tue, 8 Jun 2010 04:08:15 pm Payal wrote:
> > Hi,
> > If I have a list (or a dict), is there any way of knowing how many
> > other variables are referencing the same object?
> 
> Sort of. The question is simple, but the answer isn't. It depends what 
> you mean by "variables", and it requires a good understanding of 
> Python's programming model.
> 
> Python doesn't have "variables" like C or Pascal, it has names and 
> objects. Objects can be bound to no names at all:
> 
> len([1,2,4])
> 
> or to a single name:
> 
> x = [1,2,4]
> len(x)
> 
> or to multiple names:
> 
> x = y = z = [1,2,4]
> w = y
> len(w)
> 
> 
> Objects can also be referenced by other objects, which in turn could 
> have zero, one or more names. Consider this example:
> 
> >>> a = [1,2,4]
> >>> b = a
> >>> c = {None: ('xyz', b)}
> >>> class K:
> ... pass 
> ...
> >>> d = K()
> >>> d.attr = [c]
> 
> 
> Given your question, how many "variables" refer to the list [1,2,4]?, 
> what answer would you expect? Depending on how I count them, I get 
> either 4, 5 or 6:
> 
> 4:
> "variables" (names) a, b, c and d
> 
> 5:
> the dict globals() has two references to the list, using keys 'a' 
> and 'b';
> the tuple ('xyz', b);
> the dict with key None and value the above tuple;
> the list [c];
> the instance d has a dict __dict__ with key 'attr'
> 
> 6:
> same as five, but counting globals() twice
> 
> 
> Interestingly, Python has a standard tool for tracking referrers, the gc 
> (garbage collector) module, and it disagrees with all of those counts:
> 
> >>> import gc
> >>> len(gc.get_referrers(a))
> 2
> >>> print gc.get_referrers(a)
> [('xyz', [1, 2, 4]), {'a': [1, 2, 4], 'c': {None: ('xyz', [1, 2, 
> 4])}, 'b': [1, 2, 4], 'd': <__main__.C instance at 0xb7f6008c>, 'gc': 
> , '__builtins__':  (built-in)>, 'C':  0xb7d0602c>, '__name__': '__main__', '__doc__': None}]
> 
> So gc says two objects *directly* refer to the list: the tuple, and 
> globals(). But of course there are multiple *indirect* references to 
> the list as well. So the answer you get depends on the way you ask it.
> 
> 
> -- 
> Steven D'Aprano
> ___
> 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] pickling/shelve classes

2010-06-16 Thread Payal
Hi all,
Can someone please help in this below?

class F(object) :
   ...: def __init__(self, amt) : self.amt = amt
   ...: def dis(self) : print 'Amount : ', self.amt
   ...: def add(self, na) :
   ...: self.amt += na
   ...: F.dis(self)

pickle.dumps(F)
gives PicklingError: Can't pickle : it's not found
as __main__.F

What is my mistake? I want to pickle and shelve classes as well as
instances.

With warm regards,
-Payal
-- 


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


Re: [Tutor] pickling/shelve classes

2010-06-18 Thread Payal
On Thu, Jun 17, 2010 at 11:11:11AM +0200, Eike Welk wrote:
> I think it is a bug in IPython: I can do this in regular Python, but in 
> IPython I get the same error that you get:
> 

Thanks a lot. It works in normal python. Thanks again.


With warm regards,
-Payal
-- 

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


[Tutor] how to shelve classes

2010-06-18 Thread Payal
Hi,
I want to carry my classes around, so I wrote foo.py as,

#!/usr/bin/python

import pickle, shelve

f = shelve.open('movies')

class F(object) :
def __init__(self, amt) : self.amt = amt
def dis(self) : print 'Amount : ', self.amt
def add(self, na) :
self.amt += na
F.dis(self)

f['k'] = F
x=F(99)
f['k2']=x

Now in python interpreter I get,
>>> import shelve
>>> f = shelve.open('movies')
>>> F2=f['k']
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python2.6/shelve.py", line 122, in __getitem__
value = Unpickler(f).load()
AttributeError: 'module' object has no attribute 'F'

How do I carry around my classes and instances?

With warm regards,
-Payal
-- 


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


Re: [Tutor] how to shelve classes

2010-06-18 Thread Payal
On Fri, Jun 18, 2010 at 03:16:36PM +0200, Eike Welk wrote:
> See:
> http://docs.python.org/library/pickle.html#what-can-be-pickled-and-unpickled

Thanks for the link and the explanation.
With warm regards,
-Payal
-- 

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


[Tutor] re.sub() query

2010-06-20 Thread Payal
Hi,
Is it possible to solve the below, w/o making a re object?

>>> a
'Mary Had a Little Lamb'
>>> p=re.compile('l',re.I)
>>> re.sub(p,'-',a)
'Mary Had a -itt-e -amb'

I cannot figure how to se re.I w/o involving  p.

Thanks.
With warm regards,
-Payal
-- 



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


Re: [Tutor] Question

2010-06-20 Thread Payal
On Sat, Jun 19, 2010 at 11:24:44AM +, ALAN GAULD wrote:
> Actually that's a point. I favour learning two languages that are 
> semantically 
> similar buut syntactically different. Thats why I chose JavaScript and 
> VBScript 
> as my tutorial languages, because the syntax of each is so different you are 
> less likely to get confused, but the underlying programming model is very 
> similar in each case.

Hijacking the thread a bit. What about learning Jython and Python? Do I
need to know Java to learn Jython?

With warm regards,
-Payal
-- 

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


Re: [Tutor] re.sub() query

2010-06-20 Thread Payal
On Sun, Jun 20, 2010 at 12:03:47PM +0200, Evert Rol wrote:
> >>> re.sub('(?i)l', '-', a)
> 
> See http://docs.python.org/library/re.html#regular-expression-syntax , search 
> for iLmsux, which provide flags inside the regex.
 
Goodness that was fast. Thanks a lot Evert. For records,

>>> re.sub('l(?i)','-',a)
'Mary Had a -itt-e -amb'


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


[Tutor] class questions

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

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

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

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

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

Thanks a lot in advance.

With warm regards,
-Payal
-- 


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


Re: [Tutor] class questions

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

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

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

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

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

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

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

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

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

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


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


Re: [Tutor] class questions

2010-06-27 Thread Payal
Hi Hugo,

On Sun, Jun 27, 2010 at 01:27:37PM +0200, Hugo Arts wrote:
> Here's my attempt. Consider this simple Diamond hierarchy:
[...]
> Now, with this diagram the following code probably doesn't do what you expect:

Actually, it does what is expected. The old mro specifically says,
bottom-top, left-right. So we expected D-B-A-C-A.
Steven says in some cases even this simple logic of bottom-top,
left-right search will not work. As he says, a simple example of it
failing is diffclt to write, so meanwhile I will take his word for it.

Thanks for the help.
With warm regards,
-Payal
-- 

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


Re: [Tutor] class questions

2010-06-27 Thread Payal
Hi Steven,

Thanks a lot for patiently explaining the concepts. I uderstood most of
it.

With warm regards,
-Payal
-- 


On Sun, Jun 27, 2010 at 10:09:38AM +1000, Steven D'Aprano wrote:
> Probably not... it's quite complicated, which is why it's rare. I'll 
> have a think about it and see what I can come up with.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] class questions

2010-06-27 Thread Payal
Thanks a lot Eike for the code snippet. I got the idea now.

With warm regards,
-Payal
-- 


On Sat, Jun 26, 2010 at 10:41:59PM +0200, Eike Welk wrote:
> Hello Payal!
> 
> On Saturday June 26 2010 19:05:16 Payal wrote:
> > Can we say that our own exception classes have only maybe a doc-string
> > and pass, nothing more?
> 
> No, you let the exception transport the information that you need for 
> handling 
> the error. This is an exception that I use to transport user visible error 
> messages in a compiler, that I write as a hobby:
> 
> 
> class UserException(Exception):
> '''Exception that transports user visible error messages.'''
> def __init__(self, message, loc=None, errno=None):
> Exception.__init__(self)
> self.msg = message
> self.loc = loc
> self.errno = errno
> 
> def __str__(self):
> if self.errno is None:
> num_str = ''
> else:
> num_str = '(#%s) ' % str(self.errno) 
> return 'Error! ' + num_str + self.msg + '\n' + str(self.loc) + '\n'
> 
> def __repr__(self):
> return self.__class__.__name__ + str((self.msg, self.loc, 
>   self.errno))
> 
> It contains:
> self.msg : The error message
> self.loc : An object encoding the location of the error in the program's
>text. Together with the file name and the text.
> self.errno : An integer to identify the error, for the test framework.
> 
> That said; the expression's type and the error message are often sufficient 
> to 
> handle the error.
> 
> 
> Eike.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] capturing error msg in exception

2010-06-27 Thread Payal
Hi,
Again a few queries regarding exceptions,

a. What is the difference between,

except ZeroDivisionError as e: print 'Msg : ' , e
except ZeroDivisionError ,e: print 'Msg : ' , e

Both show,
Msg :  integer division or modulo by zero

b. What is portable and correct way of writing,

except (NameError, ZeroDivisionError) as e: print 'Msg : ' , e

c. What is the correct Python of writing,
except  as e: print 'Msg : ' , e# Capturing all exceptions

Thanks a lot for the help in advance.
With warm regards,
-Payal
-- 

p.s. I am always confused where does one put the "?" when I am framing the
questions like I have done above (a, b and c)? 
This is completely OT query for native english speaking people :-)

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


[Tutor] statements vs. expression and types

2010-06-27 Thread Payal
Hello,
Please forgive for such a silly questions. I have never taken a course on
computers so am rough with some of basic technical terminology.

a. I read in a book that "lambdas are expressions ... so they can go
where functions are not allowed". What are expressions and what are
statements? A simple example of both in Python will suffice.

b. I read on web that Python has in new releases done "unifications of
types and classes". I know what classes are, what are types in simple
language.

Again please excuse for simple questions and thanks a lot in advance.

With warm regards,
-Payal
-- 



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


[Tutor] newbie to gui programming

2010-07-06 Thread Payal
Hi all,
Some background before the actual query.
A friend of mine, an electronics engineer has a
small co. He had a computer engg. with him who used to design GUI
front-ends
for his products in Visual Basic. These apps used to take data from
serial port, store it on disk put and show it in excel also plot graphs. 
Now the engg has left. So my friend has asked me to help him out till 
he finds a replacement. I don't know a word of electronics and know Python to
extend of understanding almost 90% of "Learning Python" and 70-75% of
"Core Python programming" books.
Now my real query, do you think it is possible for me to try my hand at
gui programming? There seems to be many ways to do gui programming in
Python namely wxpython, tkinter, gtk, qt etc. Which is the easiest and
nice looking one and works on both windows and Linux? The interfaces
will be used by other electronics enggs. so they do not expect real
swell gui, but it should be bearable and more importantly easy for me to
learn, cos' I have a day time job and I am doing this just as a help and
eagerness to learn.
Looking  for advice.

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



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


Re: [Tutor] newbie to gui programming

2010-07-08 Thread Payal
On Tue, Jul 06, 2010 at 07:48:53PM +0100, Alan Gauld wrote:
> Nowadays they are all acceptable looking but wxPython would
> be my recommendation, mainly for its support for printing, which
> sounds easy but in Guis is surprisingly difficult. wxPython makes
> it about as easy as it can be.
>

Thanks a lot for the mails all of you.
Someone commented that wxpython occassionally shows it C/C++ roots. Will
that haunt me cos' I have zero knowledge of C/C++.

What about py-gtk? Is it more pythonic to learn and hence easy?
Or can I start with tkinter (and maybe remain with it), if it is easy to
learn? (I liked fetchmailconf and I think it was done in tkinter).

I get discouraged a bit fast, so I want the first toolset to be as easy
as possible.

With warm regards,
-Payal
-- 

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


Re: [Tutor] Having a return when subprocess.Popen finishes

2010-07-08 Thread Payal
On Thu, Jul 08, 2010 at 09:04:54AM -0400, Paul VanGundy wrote:
> Hi All,
> 
> I'm trying to get data from subprocess.Popen. To be specific, I am
> trying to read a ping echo and take the output and assign it to a
> variable like below:
> 
> ping = subprocess.Popen("ping -c 5 %s" % (server),
> stdout=subprocess.PIPE, shell=True)

>>> import subprocess
>>> server = 'localhost'
>>> ping = subprocess.Popen("ping -c 5 %s" %
>>> (server),stdout=subprocess.PIPE, shell=True)
>>> ping.communicate()
('PING localhost (127.0.0.1) 56(84) bytes of data.\n64 bytes from
localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.044 ms\n64 bytes from
localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.046 ms\n64 bytes from
localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.052 ms\n64 bytes from
localhost (127.0.0.1): icmp_seq=4 ttl=64 time=0.046 ms\n64 bytes from
localhost (127.0.0.1): icmp_seq=5 ttl=64 time=0.049 ms\n\n--- localhost
ping statistics ---\n5 packets transmitted, 5 received, 0% packet loss,
time 3997ms\nrtt min/avg/max/mdev = 0.044/0.047/0.052/0.006 ms\n', None)
>>>

hth,
With warm regards,
-Payal
-- 

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


Re: [Tutor] Request for help learning the right way to deal with listsin lists

2010-07-15 Thread Payal
On Tue, Jul 13, 2010 at 08:35:45AM +0100, Alan Gauld wrote:
> If the data gets more complex you could put the data into a class:
>
> class Book:
>  def __init__(self, title, pages=[]):
>  self.title = title
>  self.pages = pages
>
> Books = [ Book('War & Peace", [3,56,88]),
>   Book("Huck Finn", [2,5,19]) ]

Can someone please explain the above 2 lines?

> for book in Books:
>     print book.title, book.pages

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


[Tutor] __new__ over __init__

2010-08-30 Thread Payal
Hi all,

Can someone please give a very simple example of using __new__ wherein
__init__ cannot be used?

With warm regards,
-Payal
-- 


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


Re: [Tutor] __new__ over __init__

2010-09-01 Thread Payal
On Tue, Aug 31, 2010 at 08:27:10AM +0200, Peter Otten wrote:
> Subclasses of immutable types, e. g. tuple:

That was one great example, thanks. Some doubts,

a. I have seen this cls before, what does it mean?
b. What does type(_) mean?

Thanks a lot in advance.

With warm regards,
-Payal
-- 


> >>> class A(tuple):
> ... def __new__(cls, a, b):
> ... return tuple.__new__(cls, (a, b))
> ...
> >>> A(1, 2)
> (1, 2)
> >>> type(_)
> 
> 
> Peter
> 
> ___
> 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] __new__ over __init__

2010-09-02 Thread Payal
On Wed, Sep 01, 2010 at 09:14:50AM +0100, Alan Gauld wrote:
> It is an abbreviation for class. The first parameter to new() must be a 
> refernce to the class.
> It is similar to self in an instance method, where the first parameter  
> is a reference
> to the instance.

Thanks a lot.

With warm regards,
-Payal
-- 


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


[Tutor] need help to learn threading

2011-08-28 Thread Payal
Hi all,
Can someone suggest a resource for me to learn threading in python? I
don't know threading in any other language.
I tried a few online tutorials but got lost soon. How do I start?

With warm regards,
-Payal
-- 


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


[Tutor] failing to learn python

2006-04-10 Thread Payal Rathod
Hi,
I am trying to learn Python seriously for almost 2 months but have not 
gotten far at all. Infact, it seems I have not understood even the basic 
concepts itself. I know some shell, sed and awk programming.
I have tried reading Learning Python - Mark Lutz
Think C Spy
A byte of Python 
Non-Programmers Tutorial For Python
etc.
But I have not got anything from them. I am feeling that they are 
superficial and do not touch real life problems. Also, not enough 
examples are provided which can help newbies like me.

Can anyone help me, it is pretty pretty frustating thing for last couple 
of months?

With warm regards,
-Payal

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


Re: [Tutor] failing to learn python

2006-04-10 Thread Payal Rathod
On Mon, Apr 10, 2006 at 10:05:45AM -0400, Kent Johnson wrote:
> You might like to look at "Python Programming for the absolute 
> beginner". It is oriented to beginners and has many examples and 
> exercises.

I might not be able to afford another book, due to high dollar-to-ruppee 
rate.

> What kind of real life problems are you interested in? You might like 

I am a parttime sys admin so I want system admin problem which usually I 
do through shell scripts like parsing logs, generating reports, greping 
with regexes etc.
The only thing I don't want is silly problems like generate fibonnacci 
series, add numbers frm 0-n etc. non required silly stuff.

With warm regards,
-Payal
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] failing to learn python

2006-04-11 Thread Payal Rathod
On Mon, Apr 10, 2006 at 04:20:37PM -0700, Danny Yoo wrote:
> http://gnosis.cx/TPiP/

I will read that and Alan's tutorial too (isn't that MS-Windows specific 
???)

The reason I am disgrunted with Python is because lack of good 
documentation. Shell programming has great text and so do sed and awk 
but Python texts are rather boring and just hooting that Python is cool 
without proving it at all. All the examples I wanted were done better in 
shell/sed/awk.  But anyways thanks for the support I will dive into it 
again with fresh vigour. I will get back with any stupid queries I have.

With warm regards,
-Payal
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] failing to learn python

2006-04-12 Thread Payal Rathod
On Tue, Apr 11, 2006 at 07:35:15PM +0100, Alan Gauld wrote:
> Python is a general programmjing language great for bigger jobs.  If 

But what does Python excel at. That si my main question. Whatevfer I 
think of I can already do or know a way to do in shell. I am not getting 
where would I need Python.
e.g. for parsing log files with regex I rather use egrep than Python.  
For counting the number of mails received for a user I use awk, where 
can I use Python. Everyone says it is a "general programming language", 
but what in the world is a "general programming language"?
The Python video said that one can take this language to good level in 1 
afternoon, for me it has been 2 months and more. What is wrong?

With warm regards,
-Payal
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] functions in Python

2006-04-17 Thread Payal Rathod
Hi,
I am now reading Alan's tut on Python, before that I have read a few other tuts 
too.
But I am not getting functions exactly. I mean what is the difference between,

def func():


and

def func(x):


When to use which? (please do not say "returns a value" for I do not understand 
the meaning
of the same)

With warm regards,
-Payal
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] functions in Python

2006-04-17 Thread Payal Rathod
On Mon, Apr 17, 2006 at 05:02:07PM +0100, Adam wrote:
> The x is a name for a value that you pass in to the function. To call
> the first function you would do
> >>> func()
> 
> and the second function:
> >>> func(5) # 5 is just an example it could be any value depending on
> the function.

Sorry but it is very confusing, couldn't get it at all.
With warm regards,
-Payal

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


Re: [Tutor] functions in Python

2006-04-17 Thread Payal Rathod
On Mon, Apr 17, 2006 at 05:10:51PM +0100, Robert Schumann wrote:
> You could say "I kick" (which is like func(), because you're not 
> specifying an object to operate on) or your could say "I kick the 
> ball" (in which case x = "the ball").
> 

Sorry, but you have confused me more ;)
Can you give an simple example of just function() ?
Where can it be useful?

And when you say it returns a value, what do you mean by that? return to 
whom and what exactly?

With warm regards,
-Payal
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] functions in Python

2006-04-17 Thread Payal Rathod
On Mon, Apr 17, 2006 at 05:42:05PM +0100, Steve Nelson wrote:
> When you define a function, you are writing a block of code which you
> can ask to perform a task.  The task may be simple, and not require
> any additional information, or it may be more complex and need
> information.

What is the difference between,

>>> def f(x):
... return x
...
>>> f(4)
4

>>> def f(x):
... print x
...
>>> f(4)
4

Both give same results. So, why return statement is needed?
With warm regards,
-Payal
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Alan Gauld Tutorial - OOP

2006-04-18 Thread Payal Rathod
Hi,
I am reading Alan's tut and have stuck on the  OOP chapter.
What does he mean by,

| Objects are collections of data and functions that operate on that 
|data.  These are bound together so that you can pass an object from one 
|part of your program and they automatically get access to not only the 
|data attributes but the operations that are available too.

What are exactly "data attributes" and what "operations" is he referring 
to?
With warm regards,
-Payal
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] functions in Python

2006-04-18 Thread Payal Rathod
On Mon, Apr 17, 2006 at 10:31:04AM -0700, Danny Yoo wrote:
> One view that's common is the idea that a function is a box that takes 
> an input and returns an output:

Thanks a lot for the detailed help. Well, I have now got atleast basics 
of functions, will be doing some more reading on it in next few days.

Thanks again.
With warm regards,
-Payal
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Alan Gauld Tutorial - OOP

2006-04-18 Thread Payal Rathod
On Tue, Apr 18, 2006 at 11:19:32AM +0100, Alan Gauld wrote:
> I mean the data and the functions that are used to create an object.
> As the definition above states, objects are collections of data and 
> the functions that operate on the data. Another name for a function
> inside an object is "operation", and as you'll discover the most 
> common name of all is "method"

Thanks for the prompt response. My real problem is that there is no 
place inside a tutorial where all the terms like object, data, method, 
operation, attributes are explained on a single page *with* one small 
example of each. I am *really* confused when they occur now. I found 
this place a better help 
http://www.devshed.com/c/a/Python/Object-Orientation-in-Python/

I want something like this. e.g. Alan when I read  your tut for OOP, I 
don't get what you mean by data, variable, and object and difference 
between them. 


Thanks again.
With warm regards,
-Payal
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Alan Gauld Tutorial - OOP

2006-04-18 Thread Payal Rathod
On Tue, Apr 18, 2006 at 03:29:28PM +0100, Alan Gauld wrote:
> Have you read through the basics section of the tutor or are you 
> simply picking topics of intrest? You can do that with the advanced 

No, I read the tutorial from start.  I am not understanding how data, 
objects, attributes etc. are related to each other.

I am really curious, why didn't you make the whole tutorial Python only.  
As you Python people say - python is a language to teach programming, 
why unnecessary stuff about Vbscript or Javascript?
Is there any page which tell me how do I read the tutorial, I mean I 
don't want to learn Vbscript or Javascript, what do I do then, am I 
supposed to skip those parts?

With warm regards,
-Payal

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


[Tutor] wanted exercises in python

2006-04-18 Thread Payal Rathod
Hi,
As  I mentioned I have been reading Python a lot in last 2 months but 
lack of examples and coding is not getting me anywhere. Can someone give 
me some exercises or I can try them myself (pythonchallenge.com please 
excuse). I am reading Alan's tut now and covered Basis set and regex 
from advanced set, so please give me exercises based on those topics 
i.e. don't tell me to code a http client or a GUI based program in 
Python :)

With warm regards,
-Payal

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


[Tutor] need to automate connection

2006-04-24 Thread Payal Rathod
Hi,
I need to automate connection to a IP like this. The IP (or domain name) 
is taken from command line or from user (whichever is easier for me to 
code). It should emulate,

telnet 127.0.0.1 25

mail from: 
250 ok
rcpt to: <[EMAIL PROTECTED]>
250 ok
quit

Can Python do this for me? How do I start?

With warm regards,
-Payal

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


Re: [Tutor] need to automate connection

2006-04-25 Thread Payal Rathod
On Tue, Apr 25, 2006 at 06:59:29PM +1200, Liam Clarke wrote:
> Hi Payal,
> 
> I see you're connecting to an smtp server Any particular reason yoou
> can't use smtplib?
> http://www.python.org/doc/current/lib/module-smtplib.html

Because I don't know it exists :)

But I don't want to send any mail. I just want to establish a connection 
send MAIL TO: and RCPT TO: and exit.
Any ideas with that? With warm regards,
-Payal
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Alan Gauld's tut - namespaces

2006-04-26 Thread Payal Rathod
Hi,
In Alan's tutorial I haven't got the example of print42() even after 
reading the explanation.
I get 110 if I use it as a function.

>>> spam = 42
>>> def print42(): print spam
...
>>> spam = 110
>>> print42()
110

Why do you get 42 when you use it as module? I haven't understood the 
explantaion.

With warm regards,
-Payal
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] opening multiple connections to a port

2006-05-09 Thread Payal Rathod
Hi,
I have to see how many open connection can a particular service handle.
So, I want to similuate something like this but using Python.
telnet  

I will be keeping these connections open for around 60 seconds. Can 
anyone tell me how do I start with this in Python? I read a bit about 
telnetlib, but unable to figure how to open multiple simeltaneous 
connections.

With warm regards,
-Payal

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