Re: [Tutor] lists of lists: more Chutes & Ladders!

2013-12-31 Thread spir
On 01/01/2014 07:13 AM, eryksun wrote: >I'm afraid I've lost the context, and don't understand why this is >important. It's true that not all built-in objects are in builtins, and >not all objects in builtins are built-in, but other than for pedantic >correctness, why does this matter? Denis sai

Re: [Tutor] Shelve & immutable objects

2013-12-31 Thread Danny Yoo
On Tue, Dec 31, 2013 at 11:01 PM, Keith Winston wrote: > I'm working my way slowly through Programming Python by Mark Lutz, and as an > example of data persistence, he uses this example: Ooops; the email got cut off a bit early. Can you try again? ___

Re: [Tutor] Shelve & immutable objects

2013-12-31 Thread Danny Yoo
According to: http://docs.python.org/2/library/shelve.html The shelve can be opened in 'writeback' mode, which I think might be relevant to your question. "By default modified objects are written only when assigned to the shelf (see Example). If the optional writebackparameter is set to True,

Re: [Tutor] Shelve & immutable objects

2013-12-31 Thread Keith Winston
So sorry, I hit return: here's the example: import shelve db = shelve.open('class-shelve') sue = db['sue'] sue.giveRaise(.25) db['sue'] = sue tom = db['tom'] tom.giveRaise(.20) db['tom'] = tom db.close() Is it possible to dispense with the assignment/reassignment and just use (open shelve) db[

[Tutor] Shelve & immutable objects

2013-12-31 Thread Keith Winston
I'm working my way slowly through Programming Python by Mark Lutz, and as an example of data persistence, he uses this example: -- Keith ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mail

Re: [Tutor] lists of lists: more Chutes & Ladders!

2013-12-31 Thread eryksun
On Tue, Dec 31, 2013 at 10:53 PM, Steven D'Aprano wrote: > > __builtins__ with-an-s is a crappy hack that has never worked correctly > and has caused more confusion than help: > > https://mail.python.org/pipermail/python-3000/2007-March/006170.html > > "Restricted mode" in CPython has never worked

Re: [Tutor] lists of lists: more Chutes & Ladders!

2013-12-31 Thread Steven D'Aprano
On Tue, Dec 31, 2013 at 10:00:32PM -0500, eryksun wrote: > On Tue, Dec 31, 2013 at 4:27 AM, spir wrote: > > In addition, "iter" is also the name of a builtin function, like "print". > > While iter is a built-in function, it would be clearer if you > referenced the __builtins__ namespace. Don't

Re: [Tutor] lists of lists: more Chutes & Ladders!

2013-12-31 Thread eryksun
On Tue, Dec 31, 2013 at 4:27 AM, spir wrote: > In addition, "iter" is also the name of a builtin function, like "print". While iter is a built-in function, it would be clearer if you referenced the __builtins__ namespace. Built-in objects are linked into the interpreter, either statically or from

Re: [Tutor] subtyping builtin type

2013-12-31 Thread eryksun
On Tue, Dec 31, 2013 at 7:26 PM, Steven D'Aprano wrote: > > from collections import namedtuple > > class Source(namedtuple("Source", "string i n")): > def __new__(cls, string, i=0, n=None): > if n is None: > n = len(string) > return super(Source, cls).__new__(cls, s

Re: [Tutor] subtyping builtin type

2013-12-31 Thread Steven D'Aprano
On Tue, Dec 31, 2013 at 03:35:55PM +0100, spir wrote: > Hello, > > I don't remember exactly how to do that. As an example: > > class Source (str): > __slots__ = ['i', 'n'] > def __init__ (self, string): > self.i = 0 # current matching index in source > sel

Re: [Tutor] lists of lists: more Chutes & Ladders!

2013-12-31 Thread spir
On 12/31/2013 09:46 PM, Keith Winston wrote: Thanks Denis, I found out about the iter builtin last night, a few hours after I'd coded/posted that. Oops. Thanks for your other comments, I am clearer now about the distinction of creating a new, empty list vs. clearing the same list out, and the sub

Re: [Tutor] subtyping builtin type

2013-12-31 Thread Mark Lawrence
On 31/12/2013 21:11, Mark Lawrence wrote: On 31/12/2013 17:53, eryksun wrote: Refer to the language reference: http://docs.python.org/3/reference/datamodel.html#notes-on-using-slots Not found on the windows CHM file. Looks like another bug report to keep our lazy, bone idle core developers

Re: [Tutor] ValueError: could not convert string to float: '13,2'

2013-12-31 Thread Keith Winston
Hi PierreD, I think if you iterate over your strings with something like this, it will do what you want, if I understand correctly (snum is your string number, like "123,321"): fnum = float(snum.replace(",", ".") keith: rank beginner, take everything with a grain of salt!

Re: [Tutor] ValueError: could not convert string to float: '13,2'

2013-12-31 Thread Keith Winston
Playing with this, a list comprehension is perfect: fnumlist = [float(num.replace(",", ".")) for num in snumlist] ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] subtyping builtin type

2013-12-31 Thread Mark Lawrence
On 31/12/2013 17:53, eryksun wrote: On Tue, Dec 31, 2013 at 11:21 AM, Mark Lawrence wrote: The glossary entry for __slots__ states "A declaration inside a class that saves memory by pre-declaring space for instance attributes and eliminating instance dictionaries. Though popular, the technique

Re: [Tutor] ValueError: could not convert string to float: '13,2'

2013-12-31 Thread Mark Lawrence
On 31/12/2013 13:53, Pierre Dagenais wrote: Hi, I'm trying to convert a list of strings to float. Unfortunately the numbers are written with a decimal comma instead of a decimal point. What is the best way to replace these commas with decimal points? Do I need to write a function that will itera

Re: [Tutor] lists of lists: more Chutes & Ladders!

2013-12-31 Thread Keith Winston
Thanks Denis, I found out about the iter builtin last night, a few hours after I'd coded/posted that. Oops. Thanks for your other comments, I am clearer now about the distinction of creating a new, empty list vs. clearing the same list out, and the subsequent implications on other symbols bound to

[Tutor] ValueError: could not convert string to float: '13,2'

2013-12-31 Thread Pierre Dagenais
Hi, I'm trying to convert a list of strings to float. Unfortunately the numbers are written with a decimal comma instead of a decimal point. What is the best way to replace these commas with decimal points? Do I need to write a function that will iterate over every alphanumeric, replace the comma

Re: [Tutor] subtyping builtin type

2013-12-31 Thread spir
On 12/31/2013 06:53 PM, eryksun wrote: On Tue, Dec 31, 2013 at 11:21 AM, Mark Lawrence wrote: The glossary entry for __slots__ states "A declaration inside a class that saves memory by pre-declaring space for instance attributes and eliminating instance dictionaries. Though popular, the techniq

Re: [Tutor] subtyping builtin type

2013-12-31 Thread Zachary Ware
On Tue, Dec 31, 2013 at 11:53 AM, eryksun wrote: > Minor correction: > > It says str requires empty __slots__, but that's a bug in the docs. > It's referring to 2.x str. Else this thread wouldn't exist. In 3.x, > str is basically the unicode type from 2.x. Its __itemsize__ is 0 > because the char

Re: [Tutor] subtyping builtin type

2013-12-31 Thread eryksun
On Tue, Dec 31, 2013 at 11:21 AM, Mark Lawrence wrote: > The glossary entry for __slots__ states "A declaration inside a class that > saves memory by pre-declaring space for instance attributes and eliminating > instance dictionaries. Though popular, the technique is somewhat tricky to > get right

Re: [Tutor] subtyping builtin type

2013-12-31 Thread Zachary Ware
On Tue, Dec 31, 2013 at 10:21 AM, Mark Lawrence wrote: > The glossary entry for __slots__ states "A declaration inside a class that > saves memory by pre-declaring space for instance attributes and eliminating > instance dictionaries. Though popular, the technique is somewhat tricky to > get right

Re: [Tutor] subtyping builtin type

2013-12-31 Thread Mark Lawrence
On 31/12/2013 15:54, Zachary Ware wrote: On Tue, Dec 31, 2013 at 9:22 AM, spir wrote: Thank you, Oscar & Zachary. I guess thus the way it is done is correct (for my case), is it? Seems your last remark shows the source of my confusion: probably, in past times, I subtyped builtin types and overr

Re: [Tutor] subtyping builtin type

2013-12-31 Thread Zachary Ware
On Tue, Dec 31, 2013 at 9:22 AM, spir wrote: > Thank you, Oscar & Zachary. I guess thus the way it is done is correct (for > my case), is it? Seems your last remark shows the source of my confusion: > probably, in past times, I subtyped builtin types and overrided their > __new__, thus had to call

Re: [Tutor] subtyping builtin type

2013-12-31 Thread eryksun
On Tue, Dec 31, 2013 at 9:35 AM, spir wrote: > > I[n] particular, how does python know which param to take as > source string? (There could be other params to __init__.) You override __new__, and you might also have to override __init__, but not in this case. object.__init__ ignores the extra arg

Re: [Tutor] subtyping builtin type

2013-12-31 Thread spir
On 12/31/2013 04:03 PM, Zachary Ware wrote: On Tue, Dec 31, 2013 at 8:35 AM, spir wrote: Hello, I don't remember exactly how to do that. As an example: class Source (str): __slots__ = ['i', 'n'] def __init__ (self, string): self.i = 0 # current matching ind

Re: [Tutor] subtyping builtin type

2013-12-31 Thread Zachary Ware
On Tue, Dec 31, 2013 at 8:35 AM, spir wrote: > Hello, > > I don't remember exactly how to do that. As an example: > > class Source (str): > __slots__ = ['i', 'n'] > def __init__ (self, string): > self.i = 0 # current matching index in source > self.n = len(

Re: [Tutor] subtyping builtin type

2013-12-31 Thread Oscar Benjamin
On Dec 31, 2013 2:37 PM, "spir" wrote: > > Hello, > > I don't remember exactly how to do that. As an example: > > class Source (str): > __slots__ = ['i', 'n'] > def __init__ (self, string): > self.i = 0 # current matching index in source > self.n = len(stri

[Tutor] subtyping builtin type

2013-12-31 Thread spir
Hello, I don't remember exactly how to do that. As an example: class Source (str): __slots__ = ['i', 'n'] def __init__ (self, string): self.i = 0 # current matching index in source self.n = len(string)# number of ucodes (Unicode code points)

Re: [Tutor] same python script now running much slower

2013-12-31 Thread Oscar Benjamin
On Dec 31, 2013 12:43 PM, "Protas, Meredith" wrote: > > Thanks for all of your comments! I am working with human genome information which is in the form of many very short DNA sequence reads. I am using a script that sorts through all of these sequences and picks out ones that contain a particul

Re: [Tutor] same python script now running much slower

2013-12-31 Thread Protas, Meredith
Thanks for all of your comments! I am working with human genome information which is in the form of many very short DNA sequence reads. I am using a script that sorts through all of these sequences and picks out ones that contain a particular sequence I'm interested in. Because my data set is

Re: [Tutor] can't install

2013-12-31 Thread Lolo Lolo
On Sunday, December 29, 2013 9:11 PM, Tobias M. wrote: /bin/pyvenv ~/my_venv source ~/my_venv/bin/activate wget python-distribute.org/distribute_setup.py python distribute_setup.py Hi, can i ask why the name ~/my_venv/  .. is that just to indicate ~ as the home directory? so pyvenv alre

Re: [Tutor] lists of lists: more Chutes & Ladders!

2013-12-31 Thread spir
On 12/31/2013 06:59 AM, Keith Winston wrote: I resolved a problem I was having with lists, but I don't understand how! I caught my code inadvertently resetting/zeroing two lists TWICE at the invocation of the game method, and it was leading to all the (gamechutes & gameladders) lists returned by

Re: [Tutor] lists of lists: more Chutes & Ladders!

2013-12-31 Thread Mark Lawrence
On 31/12/2013 07:30, Keith Winston wrote: Never mind, I figured out that the slice assignment is emptying the previous lists, before the .reset() statements are creating new lists that I then populate and pass on. It makes sense. On Tue, Dec 31, 2013 at 12:59 AM, Keith Winston mailto:keithw...@g