Re: [Tutor] Question on implmenting __getitem__ on custom classes

2019-04-23 Thread Arup Rakshit
On 23/04/19 10:08 PM, Steven D'Aprano wrote: On Tue, Apr 23, 2019 at 08:27:15PM +0530, Arup Rakshit wrote: You probably want:     def __init__(self, list=None): if list is None:     list = [] self.list = list That is really a new thing to me. I didn't know. Why

Re: [Tutor] Question on implmenting __getitem__ on custom classes

2019-04-23 Thread Steven D'Aprano
On Tue, Apr 23, 2019 at 08:27:15PM +0530, Arup Rakshit wrote: > >You probably want: > > > >     def __init__(self, list=None): > > if list is None: > >     list = [] > > self.list = list > > That is really a new thing to me. I didn't know. Why list=None in the > param

Re: [Tutor] Question on implmenting __getitem__ on custom classes

2019-04-23 Thread Mats Wichmann
On 4/23/19 8:57 AM, Arup Rakshit wrote: > On 23/04/19 3:40 PM, Steven D'Aprano wrote: >> Watch out here, you have a mutable default value, that probably doesn't >> work the way you expect. The default value is created ONCE, and then >> shared, so if you do this: >> >> a = MyCustomList()  # Use the

Re: [Tutor] Question on implmenting __getitem__ on custom classes

2019-04-23 Thread Arup Rakshit
On 23/04/19 3:40 PM, Steven D'Aprano wrote: Watch out here, you have a mutable default value, that probably doesn't work the way you expect. The default value is created ONCE, and then shared, so if you do this: a = MyCustomList() # Use the default list. b = MyCustomList() # Shares the same de

Re: [Tutor] Question on implmenting __getitem__ on custom classes

2019-04-23 Thread Steven D'Aprano
On Tue, Apr 23, 2019 at 11:46:58AM +0530, Arup Rakshit wrote: > Hi, > > I wrote below 2 classes to explore how __getitem__(self,k) works in > conjuection with list subscriptions. Both code works. Now my questions > which way the community encourages more in Python: if isinstance(key, > slice):

Re: [Tutor] Question on implmenting __getitem__ on custom classes

2019-04-23 Thread Alan Gauld via Tutor
On 23/04/2019 07:16, Arup Rakshit wrote: > which way the community encourages more in Python: if isinstance(key, > slice): or if type(key) == slice: ? I think isinstance is usually preferred although I confess that I usually forget and use type()... But isinstance covers you for subclasses too.

Re: [Tutor] Question about the object.__del__(self) method

2019-04-22 Thread Arup Rakshit
On 22/04/19 3:35 PM, Alan Gauld via Tutor wrote: On 22/04/2019 10:18, Arup Rakshit wrote: Consider the below in simple class: class RandomKlass: def __init__(self, x): self.x = x def __del__(self): print("Deleted…") Now when I delete the object created from R

Re: [Tutor] Question about the object.__del__(self) method

2019-04-22 Thread Alan Gauld via Tutor
On 22/04/2019 10:18, Arup Rakshit wrote: > Consider the below in simple class: > > class RandomKlass: > def __init__(self, x): > self.x = x > > def __del__(self): > print("Deleted…") > > Now when I delete the object created from RandomKlass using `del` operator I > s

Re: [Tutor] Question for tutoring page

2019-03-16 Thread Albert-Jan Roskam
On 13 Mar 2019 18:14, Alan Gauld via Tutor wrote: On 11/03/2019 16:10, Diana Katz wrote: > What is the best way to ..program using python - that could recognize > a 3D object and then rank drawings of the object as to which are more > accurate. ===>> check this out: https://pytorch.org/tutor

Re: [Tutor] Question for tutoring page

2019-03-13 Thread Abdur-Rahmaan Janhangeer
I'll outline what you need those types of recognition are done by machine learning, just some maths using computation. You normally give your program some images to train. Instead of letting the program to figure out by itself, you give it some realistic drawings, the best of the bunch and a pic

Re: [Tutor] Question for tutoring page

2019-03-13 Thread Alan Gauld via Tutor
On 11/03/2019 16:10, Diana Katz wrote: > What is the best way to ..program using python - that could recognize > a 3D object and then rank drawings of the object as to which are more > accurate. I notice nobody has responded so I thought I'd let you know your mail was received. Unfortunately w

Re: [Tutor] Question

2018-08-21 Thread Alan Gauld via Tutor
On 21/08/18 12:16, Jacob Braig wrote: > I am just starting out coding and decided on python. It looks like you are using Python v2 (maybe v2.7?) but the latest version is 3.7 and for beginners we normally recommend adopting v3. It doesn't change anything much in this case but it saves you relearn

Re: [Tutor] Question

2018-08-21 Thread Steven D'Aprano
On Tue, Aug 21, 2018 at 05:16:35AM -0600, Jacob Braig wrote: > I am having issues with " ammopleft = ammopistol - ammopused " any idea > where I have gone wrong? What sort of issues? Should we try to guess, or would you like to tell us? I'm reminded of a joke... A man goes to the doctor. Do

Re: [Tutor] Question

2018-08-21 Thread Timo
Op 21-08-18 om 13:16 schreef Jacob Braig: I am just starting out coding and decided on python. I am confused with something I go shooting a lot so i wanted to make some stupid easy calculator for ammo and slowly build the program up when I understand python better but the code I have now keeps po

Re: [Tutor] Question Regarding startswith()

2018-06-04 Thread Peter Otten
Jeremy Ogorzalek wrote: > Not sure this is how this is done, but here goes. > > When I try to run the code in the SGP4 module, I get the following error, > and it originates in the io.py script: > > > File "C:\ProgramData\Anaconda3\lib\site-packages\sgp4\io.py", line 131, > in twoline2rv >

Re: [Tutor] Question Regarding startswith()

2018-06-04 Thread Alan Gauld via Tutor
On 04/06/18 16:57, Jeremy Ogorzalek wrote: > Not sure this is how this is done, but here goes. > > When I try to run the code in the SGP4 module, I get the following error, > and it originates in the io.py script: I have no idea what you are talking about and do not know what the SGP4 or io.py fi

Re: [Tutor] Question about a python finction

2018-05-12 Thread Alan Gauld via Tutor
On 12/05/18 06:40, peter wrote: > range does not work the same for 2.7 and my 3.6.5. Seems they have > changed the nature of range. It is a built in listed along with lists > and tuples You are correct in that it has changed slightly and now returns a range object. but you can convert it to a li

Re: [Tutor] Question about a python finction

2018-05-12 Thread peter
range does not work the same for 2.7 and my 3.6.5. Seems they have changed the nature of range. It is a built in listed along with lists and tuples list(range(10)) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> tuple(range(10)) (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) seems they have changed range for python3.6.

Re: [Tutor] Question about a python finction

2018-05-11 Thread David Rock
> On May 9, 2018, at 07:14, kevin hulshof wrote: > > Hello, > > Is there a function that allows you to grab the numbers between two numbers? > > Eg. If you input the numbers 1 and 4 > To make a list like this [1,2,3,4] One option is range range(1,5) >>> range(1,5) [1, 2, 3, 4] https://docs

Re: [Tutor] Question about a python finction

2018-05-11 Thread Mark Lawrence
On 09/05/18 13:14, kevin hulshof wrote: Hello, Is there a function that allows you to grab the numbers between two numbers? Eg. If you input the numbers 1 and 4 To make a list like this [1,2,3,4] Thank you for you’re time Seems like 'range' should fit your needs https://docs.python.org/3/

Re: [Tutor] question about metaclasses

2018-01-21 Thread Steven D'Aprano
On Thu, Jan 18, 2018 at 05:14:43PM +, Albert-Jan Roskam wrote: > Is a metaclass the best/preferred/only way of doing this? Or is a > class decorator an alternative route? I haven't thought deeply about this, but I suspect a class decorator should do the job too. The general advice is to us

Re: [Tutor] question about metaclasses

2018-01-18 Thread Steven D'Aprano
On Thu, Jan 18, 2018 at 05:31:24PM +, Albert-Jan Roskam wrote: > > Don't make the mistake of doing this: > > > > from collections import namedtuple > > a = namedtuple('Bag', 'yes no dunno')(yes=1, no=0, dunno=42) > > b = namedtuple('Bag', 'yes no dunno')(yes='okay', no='no way', dunno='not a

Re: [Tutor] question about metaclasses

2018-01-18 Thread Albert-Jan Roskam
On Jan 10, 2018 19:32, Peter Otten <__pete...@web.de> wrote: > > Albert-Jan Roskam wrote: > > > Why does following the line (in #3) > > > # 3- > > class Meta(type): > > def __new__(cls, name, bases, attrs): > > for attr, obj in attrs.item

Re: [Tutor] question about metaclasses

2018-01-18 Thread Albert-Jan Roskam
On Jan 10, 2018 18:57, Steven D'Aprano wrote: > > On Wed, Jan 10, 2018 at 04:08:04PM +, Albert-Jan Roskam wrote: > > > In another thread on this list I was reminded of > > types.SimpleNamespace. This is nice, but I wanted to create a bag > > class with constants that are read-only. > > If you

Re: [Tutor] question about metaclasses

2018-01-15 Thread Peter Otten
Steven D'Aprano wrote: > On Wed, Jan 10, 2018 at 07:29:58PM +0100, Peter Otten wrote: > > [...] >> elif not isinstance(obj, property): >> attrs[attr] = property(lambda self, obj=obj: obj) > >> PS: If you don't remember why the obj=obj is necessary: >> Python uses late

Re: [Tutor] question about metaclasses

2018-01-13 Thread Steven D'Aprano
On Wed, Jan 10, 2018 at 07:29:58PM +0100, Peter Otten wrote: [...] > elif not isinstance(obj, property): > attrs[attr] = property(lambda self, obj=obj: obj) > PS: If you don't remember why the obj=obj is necessary: > Python uses late binding; without that trick all lam

Re: [Tutor] question about metaclasses

2018-01-10 Thread Peter Otten
Albert-Jan Roskam wrote: > Why does following the line (in #3) > # 3- > class Meta(type): > def __new__(cls, name, bases, attrs): > for attr, obj in attrs.items(): > if attr.startswith('_'): > continue >

Re: [Tutor] question about metaclasses

2018-01-10 Thread Zachary Ware
On Wed, Jan 10, 2018 at 10:08 AM, Albert-Jan Roskam wrote: > Hi, > > > In another thread on this list I was reminded of types.SimpleNamespace. This > is nice, but I wanted to create a bag class with constants that are > read-only. My main question is about example #3 below (example #2 just > il

Re: [Tutor] question about metaclasses

2018-01-10 Thread Steven D'Aprano
On Wed, Jan 10, 2018 at 04:08:04PM +, Albert-Jan Roskam wrote: > In another thread on this list I was reminded of > types.SimpleNamespace. This is nice, but I wanted to create a bag > class with constants that are read-only. If you expect to specify the names of the constants ahead of time,

Re: [Tutor] Question

2017-12-10 Thread Steven D'Aprano
Hello Khabbab Zakaria, On Sun, Dec 10, 2017 at 11:18:16AM +0530, Khabbab Zakaria wrote: > I am working on a program where I found the line: > x,y,z = np.loadtext('abcabc.txt', unpack= True, skiprows =1) > What does the x, y, z thing mean? "x, y, z = ..." is iterable unpacking. The right hand side

Re: [Tutor] Question

2017-12-10 Thread Alan Gauld via Tutor
On 10/12/17 05:48, Khabbab Zakaria wrote: > I am working on a program where I found the line: > x,y,z = np.loadtext('abcabc.txt', unpack= True, skiprows =1) > What does the x, y, z thing mean? > What does the unpack= True mean? They are related. unpacking is a feature of Python whereby a collect

Re: [Tutor] question about calendar module in standard libriary

2017-09-11 Thread Peter Otten
Айнур Зулькарнаев wrote: > Hello all! > > > There is a class Calendar in calendar.py in standard libriary. > > > class Calendar(object): > """ > Base calendar class. This class doesn't do any formatting. It > simply provides data to subclasses. > """ > >

Re: [Tutor] question about calendar module in standard libriary

2017-09-11 Thread Steven D'Aprano
On Mon, Sep 11, 2017 at 10:58:51AM +, Айнур Зулькарнаев wrote: > class Calendar(object): > def __init__(self, firstweekday=0): > self.firstweekday = firstweekday # 0 = Monday, 6 = Sunday > > def getfirstweekday(self): > return self._firstweekday % 7 > > def setfir

Re: [Tutor] question about calendar module in standard libriary

2017-09-11 Thread Alan Gauld via Tutor
On 11/09/17 11:58, Айнур Зулькарнаев wrote: > So, the question is why not explicitly raise ValueError if > user enters the firstweekday parameter bigger that 6 Its a valid question but you probably need to find the original PEP document to find the answer and that module has been around for a *

Re: [Tutor] Question to Phyton and XBee

2017-04-12 Thread Alan Gauld via Tutor
On 12/04/17 15:32, Daniel Berger wrote: >For me it is not clear what is going wrong and I would be happy to get >some help to solve the problem. This list is for the core language and library, so while we can help with installing third party packages that doesn't mean anyone here will kno

Re: [Tutor] Question to Phyton and XBee

2017-04-12 Thread Daniel Berger
Daniel Berger Gesendet: Dienstag, 11. April 2017 um 21:04 Uhr Von: "Marc Tompkins" An: "Daniel Berger" Cc: "tutor@python.org" Betreff: Re: [Tutor] Question to Phyton and XBee On Tue, Apr 11, 2017 at 9:12 AM, Daniel Berger <[1]berg...@gmx.de&g

Re: [Tutor] Question to Phyton and XBee

2017-04-11 Thread Marc Tompkins
On Tue, Apr 11, 2017 at 9:12 AM, Daniel Berger wrote: >Hello, > >I have installed the modules to control xbee with Python >https://pypi.python.org/pypi/XBee). Afterwards I have set the path >variable on C:\Python27\python-xbee-master and also the subdirectories. > To >check, i

Re: [Tutor] Question about loop and assigning variables

2017-04-06 Thread Mats Wichmann
On 04/05/2017 01:07 PM, Fazal Khan wrote: > Hello, > > Heres another newbie python question: How can I loop through some data and > assign different variables with each loop > > So this is my original code: > > def BeamInfo(x): > for Bnum in x: > if plan1.IonBeamSequence[Bnum].ScanMode

Re: [Tutor] Question about loop and assigning variables

2017-04-05 Thread Steven D'Aprano
On Wed, Apr 05, 2017 at 12:07:05PM -0700, Fazal Khan wrote: > Hello, > > Heres another newbie python question: How can I loop through some data and > assign different variables with each loop You don't. That's a bad idea. Instead, you use a sequence (a tuple, or a list), and use an index: TxTab

Re: [Tutor] Question about loop and assigning variables

2017-04-05 Thread Alan Gauld via Tutor
On 05/04/17 20:07, Fazal Khan wrote: > assign different variables with each loop You can't, but you can fake it... > def BeamInfo(x): > for Bnum in x: > if plan1.IonBeamSequence[Bnum].ScanMode == 'MODULATED': > TxTableAngle = > plan1.IonBeamSequence[Bnum].IonControlPointSeq

Re: [Tutor] QUESTION

2017-03-04 Thread Alan Gauld via Tutor
On 04/03/17 01:37, Tasha Burman wrote: > I am having difficulty with a power function; > what is another way I can do 4**9 without using **? You can use the pow() function. answer = pow(4,9) However, I'm not sure that really answers your question? Do you mean that you want to write your own pow

Re: [Tutor] Question About the .format Method.

2016-11-10 Thread Alan Gauld via Tutor
On 09/11/16 22:30, Bryon Adams wrote: > Hello, > Working on a simple function to get an IP address and make it look > pretty for the PyNet course. I'm wondering if there's way to evenly > space text with the string.format() method similar to how I'm doing it > with the % operator. Yes, re

Re: [Tutor] Question About the .format Method.

2016-11-10 Thread Peter Otten
Bryon Adams wrote: > Hello, > Working on a simple function to get an IP address and make it look > pretty for the PyNet course. I'm wondering if there's way to evenly > space text with the string.format() method similar to how I'm doing it > with the % operator. The last two prints keep every

Re: [Tutor] question about __copy__ and __deepcopy__

2016-04-15 Thread Oscar Benjamin
On 15 April 2016 at 10:48, Albert-Jan Roskam wrote: > What I like about both namedtuple and AttrDict is attribute lookup: that > makes code so, so, s much easier to read. This seems to be a nice > generalization of your code: > > class Point(object): > > def __init__(self, **kwargs): >

Re: [Tutor] question about __copy__ and __deepcopy__

2016-04-15 Thread Albert-Jan Roskam
> From: oscar.j.benja...@gmail.com > Date: Thu, 14 Apr 2016 21:34:39 +0100 > Subject: Re: [Tutor] question about __copy__ and __deepcopy__ > To: sjeik_ap...@hotmail.com > CC: tutor@python.org > > On 14 April 2016 at 20:38, Albert-Jan Roskam wrote: > > Hi, > >

Re: [Tutor] question about __copy__ and __deepcopy__

2016-04-15 Thread Oscar Benjamin
On 15 April 2016 at 09:55, Albert-Jan Roskam wrote: > > Heh, it's my fancy __str__ method that confused me. This is what I get when I > run my code without __copy__ and __deepcopy__ > runfile('/home/albertjan/Downloads/attrdict_tutor.py', > wdir='/home/albertjan/Downloads') > {'x': 1, 'y': 2, 'z

Re: [Tutor] question about __copy__ and __deepcopy__

2016-04-15 Thread Albert-Jan Roskam
> Date: Fri, 15 Apr 2016 16:30:16 +1000 > From: st...@pearwood.info > To: tutor@python.org > Subject: Re: [Tutor] question about __copy__ and __deepcopy__ > > On Thu, Apr 14, 2016 at 07:38:31PM +, Albert-Jan Roskam wrote: > > Hi, > > > > Lately I hav

Re: [Tutor] question about __copy__ and __deepcopy__

2016-04-14 Thread Steven D'Aprano
On Thu, Apr 14, 2016 at 07:38:31PM +, Albert-Jan Roskam wrote: > Hi, > > Lately I have been using the "mutable namedtuple"  shown below a lot. > I found it somewhere on StackOverflow or ActiveState or something. In > its original form, it only had an __init__ method. I noticed that > copyin

Re: [Tutor] question about __copy__ and __deepcopy__

2016-04-14 Thread Oscar Benjamin
On 14 April 2016 at 20:38, Albert-Jan Roskam wrote: > Hi, > > Lately I have been using the "mutable namedtuple" shown below a lot. I found > it somewhere on StackOverflow or ActiveState or something. > In its original form, it only had an __init__ method. I don't know about your copy/deepcopy s

Re: [Tutor] question

2016-02-12 Thread wolfrage8...@gmail.com
When you say "Window" are you referring to the Installer or Idle? Which Operating System are you using and what version of Python did you download? Did you run the installer that you downloaded? ___ Tutor maillist - Tutor@python.org To unsubscribe or ch

Re: [Tutor] Question about grid layout

2016-01-17 Thread Alan Gauld
On 17/01/16 18:27, Ricardo Martínez wrote: > Hi folks, first thanks to Peter and Alan for the comments about the > Interpreter, i really appreciate that. I don't remember giving any comments about the interpreter, but if I did you're welcome! :-) > The question that i have in mind is about grid l

Re: [Tutor] Question about the memory manager

2016-01-17 Thread Albert-Jan Roskam
> From: eryk...@gmail.com > Date: Thu, 14 Jan 2016 04:42:57 -0600 > Subject: Re: [Tutor] Question about the memory manager > To: tutor@python.org > CC: sjeik_ap...@hotmail.com > > On Thu, Jan 14, 2016 at 3:03 AM, Albert-Jan Roskam > wrote: > > > > These two p

Re: [Tutor] Question about the memory manager

2016-01-14 Thread eryk sun
On Thu, Jan 14, 2016 at 3:03 AM, Albert-Jan Roskam wrote: > > These two pages are quite nice. The author says the memory used by small > objects is > never returned to the OS, which may be problematic for long running processes. The article by Evan Jones discusses a patch to enable releasing unu

Re: [Tutor] Question about the memory manager

2016-01-14 Thread Albert-Jan Roskam
D > From: sjeik_ap...@hotmail.com > To: tim.pet...@gmail.com > Date: Wed, 13 Jan 2016 08:11:11 + > Subject: Re: [Tutor] Question about the memory manager > CC: tutor@python.org > > > From: tim.pet...@gmail.com > > Date: Sun, 10 Jan 2016 10:54:10 -0600 > >

Re: [Tutor] Question about the memory manager

2016-01-13 Thread eryk sun
On Wed, Jan 13, 2016 at 2:01 AM, Albert-Jan Roskam wrote: > I sometimes check the Task Manager to see how much RAM is in use. Is there a > Python way to do something similar? Use the psutil module to solve this problem across platforms. For Windows only, you can use ctypes to call GetProcessMemo

Re: [Tutor] Question about the memory manager

2016-01-13 Thread Albert-Jan Roskam
> From: tim.pet...@gmail.com > Date: Sun, 10 Jan 2016 10:54:10 -0600 > Subject: Re: [Tutor] Question about the memory manager > To: sjeik_ap...@hotmail.com > CC: tutor@python.org > > [Albert-Jan Roskam ] > > I just found a neat trick to free up an emergency stash of m

Re: [Tutor] Question about the memory manager

2016-01-13 Thread Albert-Jan Roskam
> To: tutor@python.org > From: __pete...@web.de > Date: Sun, 10 Jan 2016 18:29:06 +0100 > Subject: Re: [Tutor] Question about the memory manager > > Albert-Jan Roskam wrote: > > > Hi, > > > > I just found a neat trick to free up an emergency stash of

Re: [Tutor] Question about the memory manager

2016-01-11 Thread Oscar Benjamin
On 11 January 2016 at 15:40, Peter Otten <__pete...@web.de> wrote: >> I can't even work out how you trigger a MemoryError on Linux (apart >> from just raising one). I've tried a few ways to make the system run >> out of memory and it just borks the system rather than raise any error >> - I can only

Re: [Tutor] Question about the memory manager

2016-01-11 Thread Peter Otten
Oscar Benjamin wrote: > On 11 January 2016 at 12:15, Alan Gauld wrote: >> >> But I think that it definitely is heavily OS dependent. >> It should work in most *nix environments the first time >> you call the function. But on second call I'd expect >> all bets to be off. And in most real-time OS's

Re: [Tutor] Question about the memory manager

2016-01-11 Thread Oscar Benjamin
On 11 January 2016 at 12:15, Alan Gauld wrote: > > But I think that it definitely is heavily OS dependent. > It should work in most *nix environments the first time > you call the function. But on second call I'd expect > all bets to be off. And in most real-time OS's memory > goes right back to t

Re: [Tutor] Question about the memory manager

2016-01-11 Thread Alan Gauld
On 10/01/16 16:16, Steven D'Aprano wrote: >> rainydayfund = [[] for x in xrange(16*1024)] # or however much you need >> def handle_exception(e): >> global rainydayfund >> del rainydayfund >> ... etc, etc ... > > I was going to write a scornful email about how useless this would be. Me too. > st

Re: [Tutor] Question about the memory manager

2016-01-11 Thread James Chapman
If you read the comment that goes with the code snippet pasted in the original email it makes far more sense as the author is talking specifically about out of memory errors... "You already got excellent answers, I just wanted to add one more tip that's served me well over the years in a variety

Re: [Tutor] Question about the memory manager

2016-01-10 Thread Peter Otten
Albert-Jan Roskam wrote: > Hi, > > I just found a neat trick to free up an emergency stash of memory in a > funtion that overrides sys.excepthook. The rationale is that all > exceptions, including MemoryErrors will be logged. The code is below. My > question: is that memory *guaranteed* to be fre

Re: [Tutor] Question about the memory manager

2016-01-10 Thread Tim Peters
[Albert-Jan Roskam ] > I just found a neat trick to free up an emergency stash of memory in > a funtion that overrides sys.excepthook. The rationale is that all > exceptions, including MemoryErrors will be logged. > The code is below. My question: is that memory *guaranteed* to be > freed right aft

Re: [Tutor] Question about the memory manager

2016-01-10 Thread Steven D'Aprano
On Sun, Jan 10, 2016 at 11:53:22AM +, Albert-Jan Roskam wrote: > Hi, > > I just found a neat trick to free up an emergency stash of memory in a > funtion that overrides sys.excepthook. > rainydayfund = [[] for x in xrange(16*1024)] # or however much you need > def handle_exception(e): > glob

Re: [Tutor] question about "__main__"

2015-11-16 Thread Alan Gauld
On 16/11/15 15:30, CUONG LY wrote: Hello, I’m learning Python. Hello, welcome. I want to know what does the following line represent if __name__ == ‘__main__’: The short answer is that it tests whether the file is being imported as a module or executed as a program. If its being imported a

Re: [Tutor] question about descriptors

2015-11-13 Thread Steven D'Aprano
On Thu, Nov 12, 2015 at 12:11:19PM +, Albert-Jan Roskam wrote: > > __getattr__() is only invoked as a fallback when the normal attribute > > lookup > > fails: > > > Aha.. and "normal attributes" live in self.__dict__? Not necessarily. Attributes can live either in "slots" or the instance

Re: [Tutor] question about descriptors

2015-11-13 Thread Albert-Jan Roskam
> To: tutor@python.org > From: __pete...@web.de > Date: Fri, 13 Nov 2015 09:26:55 +0100 > Subject: Re: [Tutor] question about descriptors > > Albert-Jan Roskam wrote: > > >> __getattr__() is only invoked as a fallback when the normal attribute > >> lookup

Re: [Tutor] question about descriptors

2015-11-13 Thread Peter Otten
Albert-Jan Roskam wrote: >> __getattr__() is only invoked as a fallback when the normal attribute >> lookup fails: > > > Aha.. and "normal attributes" live in self.__dict__? I meant "normal (attribute lookup)" rather than "(normal attribute) lookup". __getattr__() works the same (I think) when

Re: [Tutor] question about descriptors

2015-11-12 Thread Albert-Jan Roskam
> To: tutor@python.org > From: __pete...@web.de > Date: Wed, 11 Nov 2015 20:06:20 +0100 > Subject: Re: [Tutor] question about descriptors > > Albert-Jan Roskam wrote: > > >> From: st...@pearwood.info > > >> Fortunately, Python has an mechanism for s

Re: [Tutor] question about descriptors

2015-11-11 Thread Peter Otten
Albert-Jan Roskam wrote: >> From: st...@pearwood.info >> Fortunately, Python has an mechanism for solving this problem: >> the `__getattr__` method and friends. >> >> >> class ColumnView(object): >> _data = {'a': [1, 2, 3, 4, 5, 6], >> 'b': [1, 2, 4, 8, 16, 32], >>

Re: [Tutor] question about descriptors

2015-11-11 Thread Peter Otten
Albert-Jan Roskam wrote: >> class ReadColumn(object): >> def __init__(self, index): >> self._index = index >> def __get__(self, obj, type=None): >> return obj._row[self._index] >> def __set__(self, obj, value): >> raise AttributeError("oops") > > This appears t

Re: [Tutor] question about descriptors

2015-11-11 Thread Albert-Jan Roskam
> Date: Sun, 8 Nov 2015 01:24:58 +1100 > From: st...@pearwood.info > To: tutor@python.org > Subject: Re: [Tutor] question about descriptors > > On Sat, Nov 07, 2015 at 12:53:11PM +, Albert-Jan Roskam wrote: > > [...] > > Ok, now to my question. I want to

Re: [Tutor] question about descriptors

2015-11-11 Thread Albert-Jan Roskam
> I think the basic misunderstandings are that > > (1) the __get__() method has to be implemented by the descriptor class > (2) the descriptor instances should be attributes of the class that is > supposed to invoke __get__(). E. g.: > > class C(object): >x = decriptor() > > c = C() >

Re: [Tutor] question about descriptors

2015-11-07 Thread Steven D'Aprano
On Sat, Nov 07, 2015 at 12:53:11PM +, Albert-Jan Roskam wrote: [...] > Ok, now to my question. I want to create a class with read-only > attribute access to the columns of a .csv file. E.g. when a file has a > column named 'a', that column should be returned as list by using > instance.a. A

Re: [Tutor] question about descriptors

2015-11-07 Thread Peter Otten
Albert-Jan Roskam wrote: > > > p, li { white-space: pre-wrap; } > > Hi, > First, before I forget, emails from hotmail/yahoo etc appear to end up in > the spam folder these days, so apologies in advance if I do not appear to > follow up to your replies. Ok, now to my question. I want to create a

Re: [Tutor] question about descriptors

2015-11-07 Thread Alan Gauld
On 07/11/15 12:53, Albert-Jan Roskam wrote: Ok, now to my question. > I want to create a class with read-only attribute access to the columns of a .csv file. Can you clarify what you mean by that? The csvreader is by definition read only. So is it the in-memory model that you want read-only?

Re: [Tutor] Question how to ready data from excle file and convert the german to english language

2015-09-10 Thread Alan Gauld
On 10/09/15 18:00, Sarika Shrivastava wrote: I wanted to ready data from excel file which in german Language and onovert to English language ?? Those are two completely separate questions. To read Excel there are several options. The simplest is if you can convert the file to csv and use the

Re: [Tutor] question / decision tree

2015-08-05 Thread Laura Creighton
In a message of Mon, 03 Aug 2015 10:38:40 +0100, matej taferner writes: >Or maybe should I go with the tkinter? You have to decide whether what you want is a Stand Alone GUI Application (in which case tkinter could be a fine idea) or a web app. It sounds to me as if you want your customers to nav

Re: [Tutor] Question

2015-08-04 Thread Alan Gauld
On 04/08/15 05:21, Lulwa Bin Shuker wrote: I'm currently learning Python through an online course but after learning the basics of the language I need to apply what I learned on a real project and start practicing it. How can I do that ? Do you have a project in mind but are not sure how to st

Re: [Tutor] question / decision tree

2015-08-03 Thread memilanuk
On 08/03/2015 02:38 AM, matej taferner wrote: Or maybe should I go with the tkinter? As a final product of this decision tree "app" I need a clickable buttons ready to be embedded into the website which will guide customer(s) to desired answer(s). The two aren't exactly compatible. Tkinter

Re: [Tutor] question / decision tree

2015-08-03 Thread matej taferner
Or maybe should I go with the tkinter? 2015-08-03 10:36 GMT+01:00 matej taferner : > thanks for the reply. I'll definitely check the book. > > The back end solution of the problem is more or less clear to me. What I > find difficult is the grasp the idea of o called front end dev. or better > to

Re: [Tutor] question / decision tree

2015-08-03 Thread matej taferner
thanks for the reply. I'll definitely check the book. The back end solution of the problem is more or less clear to me. What I find difficult is the grasp the idea of o called front end dev. or better to say what should I use to make buttons should I dig into django framework or something else?

Re: [Tutor] question / decision tree

2015-08-03 Thread Laura Creighton
In a message of Mon, 03 Aug 2015 08:58:43 +0100, matej taferner writes: >hi guys, > >I am wondering if there is a python solution for the problem I am currently >dealing with. >I need to build a decision tree based questionnaire which helps users to >find the right answer. > >As a final product of

Re: [Tutor] Question About Image Processing in Python

2015-05-28 Thread Sturla Molden
Serge Christian Ibala wrote: > Or what is the recommendation of Python for image processing? Basic setup everyone should have: Python NumPy SciPy (e.g. scipy.ndimage) Cython C and C++ compiler matplotlib scikit-image scikit-learn pillow Also consider: mahotas tifffile (by Christoph Gohlke) Ope

Re: [Tutor] Question About Image Processing in Python

2015-05-28 Thread Todd
On Thu, May 28, 2015 at 1:05 PM, Terry Reedy wrote: > On 5/28/2015 6:34 AM, Serge Christian Ibala wrote: > > > I want to use the following package >> >> “numpy, matplotib, mahotas, ipython OpenCV and SciPy" >> > > opencv seems to be the only one not available for 3.x. > > OpenCV 3 (which is in

Re: [Tutor] Question About Image Processing in Python

2015-05-28 Thread Oscar Benjamin
On 28 May 2015 at 11:34, Serge Christian Ibala wrote: > Hello All, > > I want to know which version of Python is compatible (or can be associated > with which version of which "tools or package" for image processing) > > I am working under Window and it is so complicated to find out which version

Re: [Tutor] Question about why a list variable is apparently global.

2014-11-27 Thread Alan Gauld
On 27/11/14 16:07, boB Stepp wrote: Alan's reference to indentation level had me trying to prove the opposite--unsuccessfully. Yeah, I probably over-simplified there in response to your assumption that it was the order that mattered. It's really whether they are inside a function or class -

Re: [Tutor] Question about why a list variable is apparently global.

2014-11-27 Thread Dave Angel
On 11/27/2014 11:07 AM, boB Stepp wrote: x = "outer" def tricky_func2(): y = x print(x) tricky_func2() outer So why does not print(x) see the global x and instead looks for the local x? The function is compiled during the import (or initial load if it's a

Re: [Tutor] Question about why a list variable is apparently global.

2014-11-27 Thread boB Stepp
On Thu, Nov 27, 2014 at 9:33 AM, Steven D'Aprano wrote: > On Thu, Nov 27, 2014 at 09:00:48AM -0600, boB Stepp wrote: [...] > But there is a subtlety that you may not expect: > > py> class Tricky: > ... print(x) > ... x = "inner" > ... print(x) > ... > outer > inner Actually, this is

Re: [Tutor] Question about why a list variable is apparently global.

2014-11-27 Thread Steven D'Aprano
On Thu, Nov 27, 2014 at 09:13:35AM -0600, boB Stepp wrote: > On Thu, Nov 27, 2014 at 4:56 AM, Steven D'Aprano wrote: > > On Wed, Nov 26, 2014 at 10:18:55PM -0600, boB Stepp wrote: > > > >> So any variables lower in the program are accessible to those above it? > > > > No, that can't be the explana

Re: [Tutor] Question about why a list variable is apparently global.

2014-11-27 Thread Steven D'Aprano
On Thu, Nov 27, 2014 at 09:00:48AM -0600, boB Stepp wrote: > Level of indentation is the key? Can you give me an example, not > involving functions, where a variable is defined at an "inner" level > of indentation, but is not accessible at the outermost level of > indentation? Classes and functi

Re: [Tutor] Question about why a list variable is apparently global.

2014-11-27 Thread boB Stepp
On Thu, Nov 27, 2014 at 4:56 AM, Steven D'Aprano wrote: > On Wed, Nov 26, 2014 at 10:18:55PM -0600, boB Stepp wrote: > >> So any variables lower in the program are accessible to those above it? > > No, that can't be the explanation. Think of this: > > b = a + 1 > a = 2 > > That will fail because w

Re: [Tutor] Question about why a list variable is apparently global.

2014-11-27 Thread boB Stepp
On Thu, Nov 27, 2014 at 4:51 AM, Alan Gauld wrote: > On 27/11/14 04:18, boB Stepp wrote: [...] >> So any variables lower in the program are accessible to those above it? > > > No. > Its not whether they are defined above or below each other its the level of > indentation. Both f and g are define

Re: [Tutor] Question about why a list variable is apparently global.

2014-11-27 Thread Steven D'Aprano
On Wed, Nov 26, 2014 at 10:18:55PM -0600, boB Stepp wrote: > So any variables lower in the program are accessible to those above it? No, that can't be the explanation. Think of this: b = a + 1 a = 2 That will fail because when the "b = a + 1" line is executed, a doesn't exist yet so there is n

Re: [Tutor] Question about why a list variable is apparently global.

2014-11-27 Thread Alan Gauld
On 27/11/14 04:18, boB Stepp wrote: Note that this principle is critical to Python, otherwise functions couldn't call each other, or even built-ins! If you have two functions: def f(): return g() def g(): return "Hello!" "g" is a global "variable" and f() can see it, otherwise it couldn't cal

Re: [Tutor] Question about why a list variable is apparently global.

2014-11-26 Thread boB Stepp
On Wed, Nov 26, 2014 at 6:20 PM, Steven D'Aprano wrote: > On Wed, Nov 26, 2014 at 05:23:40PM -0600, boB Stepp wrote: [...] >> First question: How can the printLabel() function see the list >> variable, l, defined outside of this function? I thought that >> functions only had access to variables lo

Re: [Tutor] Question about why a list variable is apparently global.

2014-11-26 Thread Steven D'Aprano
On Wed, Nov 26, 2014 at 05:23:40PM -0600, boB Stepp wrote: > Python 2.4.4 > Solaris 10 > > #!/usr/bin/env python > > from Tkinter import * > > def printLabel(): > print "Button number ", var.get(), " was pressed." > print "You selected this option:", l[var.get() - 1][0] > > root = Tk()

Re: [Tutor] Question about why a list variable is apparently global.

2014-11-26 Thread Alan Gauld
On 26/11/14 23:23, boB Stepp wrote: def printLabel(): print "Button number ", var.get(), " was pressed." print "You selected this option:", l[var.get() - 1][0] ... buttonNumber = [] l = [("Brain_Partial", 1), ("Brain_Whole", 2), ("Head & Neck", 3), ("Chest",

Re: [Tutor] question on array Operation

2014-10-29 Thread Steven D'Aprano
On Wed, Oct 29, 2014 at 05:08:28PM +0100, jarod...@libero.it wrote: > Dear All, > > I have a long matrix where I have the samples (1to n) and then I have (1to j > )elements. > I would like to count how many times each j element are present on each > samples. Jarod, looking at your email addres

  1   2   3   4   5   6   7   8   >