Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #52757
| From | Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Basic Python Query |
| Date | 2013-08-21 11:11 +0200 |
| Message-ID | <nqceea-aae.ln1@satorlaser.homedns.org> (permalink) |
| References | <mailman.68.1377067974.19984.python-list@python.org> |
Am 21.08.2013 08:50, schrieb chandan kumar: > class Test(threading.Thread): > def StartThread(self): > Lock = threading.Lock() > self.start() Inconsistently indented code, this is a killer for Python. Please read PEP8 and use four spaces! That said, there is never a need for deriving from the Thread class, you can also use it to run a function without that. That way is IMHO clearer because the threading.Thread instance is not the thread, just like a File instance is not a file. Both just represent handles for manipulating the actual thing. Further, you have a local variable called "Lock" here (should be lowercase, see PEP 8) that you don't use. This is either a bug you missed or at least code that you didn't trim in order to produce a minimal example. > class Test1(threading.Thread): > def __init__(self): > threading.Thread.__init__ ( self ) Check out the "super()" syntax. > 1.Difference between def StartThread(self) and def __init__(self): __init__ is a special function that gets called automatically. Search online for the documentation and or further explanations. > 3. Lets say self is passed explicitly for all the methods Like > def method1(self) > method2() > def method2(self): > method3() > def method(self) > method4() > def method4(self) > What does self holds in method4 ,Is it self argument from method1? > Sorry i'm confused with self argument. "self" is just a name like others, only that it is customarily used for the first parameter of memberfunctions, i.e. for the instance of the according class. That said, above seven lines don't really serve to illustrate anything, because they are far from valid Python code. I think before tackling threading, you should first go through some tutorials and documentation. I'd start with http://docs.python.org and/or do some online searches. Good luck! Uli
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Basic Python Query chandan kumar <chandan_psr@yahoo.co.in> - 2013-08-21 14:50 +0800
Re: Basic Python Query Steven D'Aprano <steve@pearwood.info> - 2013-08-21 08:19 +0000
Re: Basic Python Query Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2013-08-21 11:11 +0200
Re: Basic Python Query Johannes Bauer <dfnsonfsduifb@gmx.de> - 2013-08-21 20:58 +0200
Re: Basic Python Query Fábio Santos <fabiosantosart@gmail.com> - 2013-08-21 23:50 +0100
Re: Basic Python Query Johannes Bauer <dfnsonfsduifb@gmx.de> - 2013-08-22 10:49 +0200
Re: Basic Python Query Ned Batchelder <ned@nedbatchelder.com> - 2013-08-21 20:06 -0400
Re: Basic Python Query Bob Martin <bob.martin@excite.com> - 2013-08-22 06:43 +0100
Re: Basic Python Query Ned Batchelder <ned@nedbatchelder.com> - 2013-08-22 09:45 -0400
Re: Basic Python Query Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-08-23 03:12 +0000
Re: Basic Python Query random832@fastmail.us - 2013-08-22 14:57 -0400
Re: Basic Python Query Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-08-22 18:22 -0400
Re: Basic Python Query random832@fastmail.us - 2013-08-23 01:08 -0400
Re: Basic Python Query Johannes Bauer <dfnsonfsduifb@gmx.de> - 2013-08-22 10:50 +0200
Re: Basic Python Query Fábio Santos <fabiosantosart@gmail.com> - 2013-08-22 09:46 +0100
Re: Basic Python Query Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2013-08-22 13:54 +0200
Re: Basic Python Query Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-08-23 03:28 +0000
Re: Basic Python Query Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2013-08-23 09:12 +0200
Re: Basic Python Query Chris Angelico <rosuav@gmail.com> - 2013-08-24 01:50 +1000
csiph-web