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.

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 >

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

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.

[Tutor] Question on implmenting __getitem__ on custom classes

2019-04-23 Thread Arup Rakshit
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): or if type(key) == slice: ? How should I implement this if I follow

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

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 >

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

2019-04-22 Thread Arup Rakshit
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 see the output “Deleted…”. That means `del` operator calls the

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:

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

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

[Tutor] Question for tutoring page

2019-03-11 Thread Diana Katz
Hi, What is the best way to create an artificial intelligence program using python - that could recognize a 3D object and then rank drawings of the object as to which are more accurate. It was suggested to us to use raspberry pi and python and perhaps tweak existing apps. Any help as to how to

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

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.

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

[Tutor] Question

2018-08-21 Thread 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 popping up an error and I don't understand

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

[Tutor] Question Regarding startswith()

2018-06-04 Thread Jeremy Ogorzalek
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 assert line.startswith('1 ') TypeError:

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

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

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,

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

[Tutor] Question about a python finction

2018-05-11 Thread kevin hulshof
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 Sent from my iPhone ___ Tutor maillist - Tutor@python.org To

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

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

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

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

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

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

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

[Tutor] question about metaclasses

2018-01-10 Thread Albert-Jan Roskam
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 illustrates my thought process). Is this a use case to a metaclass? Or

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

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

[Tutor] Question

2017-12-10 Thread Khabbab Zakaria
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? Thank you -- Khabbab Zakaria Dept of Power Engineering Jadavpur University Calcutta India

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

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

[Tutor] question about calendar module in standard libriary

2017-09-11 Thread Айнур Зулькарнаев
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. """ def __init__(self, firstweekday=0):

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

Re: [Tutor] Question to Phyton and XBee

2017-04-12 Thread Daniel Berger
Gesendet: Dienstag, 11. April 2017 um 21:04 Uhr Von: "Marc Tompkins" <marc.tompk...@gmail.com> An: "Daniel Berger" <berg...@gmx.de> Cc: "tutor@python.org" <tutor@python.org> Betreff: Re: [Tutor] Question to Phyton and XBee On Tue,

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. >

[Tutor] Question to Phyton and XBee

2017-04-11 Thread Daniel Berger
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, if the modules are available, I have written the code as

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

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:

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 = >

[Tutor] Question about loop and assigning variables

2017-04-05 Thread Fazal Khan
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 == 'MODULATED': TxTableAngle =

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

[Tutor] QUESTION

2017-03-04 Thread Tasha Burman
Hello python tutors, I am having difficulty with a power function; what is another way I can do 4**9 without using **? Thanks, Tasha ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options:

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: [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

[Tutor] Question About the .format Method.

2016-11-09 Thread Bryon Adams
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 everything left aligned and 20

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

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 <sjeik_ap...@hotmail.com> wr

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', >

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-15 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 >

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

[Tutor] question about __copy__ and __deepcopy__

2016-04-14 Thread Albert-Jan Roskam
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 copying Record objects sometimes failed. So I implemented __copy__ and __deepcopy__,

[Tutor] question

2016-02-12 Thread Brianna Hulbert
Hi, I am new to python and just downloaded it onto my computer. The window comes up however there is no menu bar across the top that says file, edit, format, run, options, etc. I was wondering how to get that to appear. Thank you ___ Tutor maillist -

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

[Tutor] Question about grid layout

2016-01-17 Thread Ricardo Martínez
Hi folks, first thanks to Peter and Alan for the comments about the Interpreter, i really appreciate that. The question that i have in mind is about grid layout, i have the below code and i want to resize every widget when the user resize the main windows. """ START """ import tkinter as tk

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

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 > <sjeik_ap...@hotmail.com>

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

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 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 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. >

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

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

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

[Tutor] Question about the memory manager

2016-01-10 Thread Albert-Jan Roskam
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 freed right after the 'del'

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): >

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

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

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

[Tutor] question about "__main__"

2015-11-16 Thread CUONG LY
Hello, I’m learning Python. I want to know what does the following line represent and why I see some python codes have two of them ? if __name__ == ‘__main__’: Thanks in advance Cuong ___ Tutor maillist - Tutor@python.org To unsubscribe or

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

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

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

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

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.

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

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

2015-09-10 Thread Sarika Shrivastava
Hello pythonistats, I wanted to ready data from excel file which in german Language and onovert to English language ?? -- Thanks Sarika Shrivastava | Software Developer Trainee www.zeomega.com ___ Tutor maillist - Tutor@python.org To unsubscribe

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

[Tutor] Question

2015-08-04 Thread Lulwa Bin Shuker
Dear Python tutor list ... 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 ? Thanks, Lulwa Bin Shuker ___

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

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 matej.tafer...@gmail.com: 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

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?

  1   2   3   4   5   6   7   8   9   10   >