Re: Good use for itertools.dropwhile and itertools.takewhile

2012-12-05 Thread Ian Kelly
On Wed, Dec 5, 2012 at 7:34 AM, Neil Cerutti wrote: > Well, shoot! Then this is a job for groupby, not takewhile. The problem with groupby is that you can't just limit it to two groups. >>> prod_desc("CAPSICUM RED fresh from QLD") ['QLD', 'fresh from'] Once you've got a false key from the group

Re: Good use for itertools.dropwhile and itertools.takewhile

2012-12-05 Thread Ian Kelly
On Wed, Dec 5, 2012 at 6:45 AM, Chris Angelico wrote: > On Wed, Dec 5, 2012 at 12:17 PM, Nick Mellor wrote: >> >> takewhile mines for gold at the start of a sequence, dropwhile drops the >> dross at the start of a sequence. > > When you're using both over the same sequence and with the same > co

Re: why does dead code costs time?

2012-12-05 Thread Ian Kelly
On Wed, Dec 5, 2012 at 10:34 AM, Steven D'Aprano wrote: > The difference is almost certain between the LOAD_CONST and the > LOAD_GLOBAL. > > As to *why* there is such a difference, I believe that's a leftover from > early Python days when None was not a keyword and could be reassigned. I think th

Re: Help "joining" two files delimited with pipe character ("|")

2012-12-05 Thread Ian Kelly
On Wed, Dec 5, 2012 at 11:18 AM, Ian Kelly wrote: > On Wed, Dec 5, 2012 at 10:57 AM, Daniel Doo > wrote: >> I am new to Python. Is there a method to “join” two pipe delimited files >> using a unique key that appears in both files? I would like to implement >> somet

Re: Help "joining" two files delimited with pipe character ("|")

2012-12-05 Thread Ian Kelly
On Wed, Dec 5, 2012 at 10:57 AM, Daniel Doo wrote: > I am new to Python. Is there a method to “join” two pipe delimited files > using a unique key that appears in both files? I would like to implement > something similar to the Unix join command. If the files are small enough to fit in virtual

Re: How does one make argparse print usage when no options are provided on the command line?

2012-12-05 Thread Ian Kelly
On Wed, Dec 5, 2012 at 9:48 AM, rh wrote: > I have argparse working with one exception. I wanted the program to print out > usage when no command line options are given. But I only came across > other examples where people didn't use argparse but instead printed out > a separate usage statement. S

Re: Dict comprehension help

2012-12-05 Thread Ian Kelly
On Wed, Dec 5, 2012 at 8:03 PM, Joseph L. Casale wrote: > I get a list of dicts as output from a source I need to then extract various > dicts > out of. I can easily extract the dict of choice based on it containing a key > with > a certain value using list comp but I was hoping to use dict comp

Re: Is __ne__ method autogenerated?

2012-12-06 Thread Ian Kelly
On Thu, Dec 6, 2012 at 11:03 PM, INADA Naoki wrote: > The reference says: > > The truth of x==y does not imply that x!=y is false. > Accordingly, when defining __eq__(), one should also > define __ne__() so that the operators will behave as expected. > > (http://docs.python.org/3/reference/d

Re: pyodbc utf-8

2012-12-07 Thread Ian Kelly
On Fri, Dec 7, 2012 at 12:41 AM, Markus Christen wrote: > good morning > > i am using pyodbc 3.0.6 for win32 python 2.7.3 > i used it to connect with a MsSql db. Now i have a little problem with the > umlaut. i cant change anything in the db and there are umlauts like "ä", "ö" > and "ü" saved. s

Re: Issue with seeded map generation

2012-12-08 Thread Ian Kelly
On Sat, Dec 8, 2012 at 2:32 PM, Graham Fielding wrote: > Hey, all! > > I've managed to get my project to a semi-playable state (everything > functions, if not precisely the way I'd like it to). One small issue is > that when the player movs from one level to the next, the items and monsters > in

Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes

2012-12-10 Thread Ian Kelly
On Mon, Dec 10, 2012 at 8:48 PM, Dave Cinege wrote: > Thesaurus: A different way to call a dictionary. > > Thesaurus is a new a dictionary subclass which allows calling keys as > if they are class attributes and will search through nested objects > recursively when __getitem__ is called. > > You w

Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes

2012-12-11 Thread Ian Kelly
On Tue, Dec 11, 2012 at 1:57 PM, Dave Cinege wrote: > On Tuesday 11 December 2012 01:41:38 Ian Kelly wrote: >> Second, in __getitem__ you start a loop with "for i in >> range(len(l)):", and then you use i as an index into l several times. >> It would be cleaner

Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes

2012-12-11 Thread Ian Kelly
On Tue, Dec 11, 2012 at 2:53 PM, Ian Kelly wrote: > and then I ran the examples, and the output was unchanged. As Steven > pointed out, I don't see how that first branch could succeed anyway, > since self.data is never defined. It occurs to me that the UserDict class does have a

Re: Hollow square program

2012-12-12 Thread Ian Kelly
On Wed, Dec 12, 2012 at 10:22 AM, wrote: > Well, I did some modifications and got a hollow square, but the columns > aren't perfectly aligned with the rows (at least if input is 5. Thanks for > the help :) > > rows = int(input()) > s1="* "*rows > s2="*"+(rows-2)*" "+"*" > print(s1) > for s in r

Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes

2012-12-12 Thread Ian Kelly
On Wed, Dec 12, 2012 at 12:20 PM, Dave Cinege wrote: > On Tuesday 11 December 2012 01:41:38 Ian Kelly wrote: > >> I have a few critiques on the code. First, you might want to use >> __getattribute__ instead of __getattr__. Otherwise you'll end up > > File

Re: Preventing tread collisions

2012-12-12 Thread Ian Kelly
On Wed, Dec 12, 2012 at 1:53 PM, MRAB wrote: > You could try a non-blocking semaphore: > > def __init__(self): > self.cameraActive = Semaphore() Why a Semaphore and not just a plain old Lock? -- http://mail.python.org/mailman/listinfo/python-list

Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes

2012-12-12 Thread Ian Kelly
On Wed, Dec 12, 2012 at 3:20 PM, Dave Cinege wrote: > On Wednesday 12 December 2012 15:42:36 Ian Kelly wrote: > >> def __getattribute__(self, name): >> if name.startswith('__') and name.endswith('__'): >> return super(Thesaurus, sel

Re: Preventing tread collisions

2012-12-13 Thread Ian Kelly
On Thu, Dec 13, 2012 at 3:26 AM, Alexander Blinne wrote: > I have a general question about this kinds of things. I see that the > above is a common use case for some kind of lock which does this > testing/locking atomically. But the question is: if I know for sure that > there is no other thread t

Re: unpacking first few items of iterable

2012-12-13 Thread Ian Kelly
On Thu, Dec 13, 2012 at 1:39 PM, Daniel Fetchinson wrote: >> If you know the sequence has at least n items, you >> can do a, b, c = seq[:3] > > Yeah, that's probably the simplest, without all the fancy stuff :) That only works for sequences, though. Not all iterables are sequences. The islice v

Pastebin [was: Trying to make a basic Python score counter in a game... will not count.]

2012-12-16 Thread Ian Kelly
On Sun, Dec 16, 2012 at 10:32 AM, Kwpolska wrote: > On Sun, Dec 16, 2012 at 6:25 PM, wrote: >> On Sunday, December 16, 2012 10:09:53 AM UTC-7, Kwpolska wrote: >>>[...] >>> PS. please do not use pastebin.com. >> >> Why? > > http://news.ycombinator.com/item?id=2595066 should answer this very quest

Re: Why Isn't Multiple Inheritance Automatic in Python?

2012-12-17 Thread Ian Kelly
On Sun, Dec 16, 2012 at 9:30 PM, Nick M. Daly wrote: > It's very unlikely that multiple inheritance would go horribly wrong, as > long as classes adopt class-specific argument naming conventions. > However, ever since bug 1683368 [0] was fixed, it's now impossible to > cleanly create arbitrary inh

Re: Py 3.3, unicode / upper()

2012-12-19 Thread Ian Kelly
On Wed, Dec 19, 2012 at 8:40 AM, Chris Angelico wrote: > You may not be familiar with jmf. He's one of our resident trolls, and > he has a bee in his bonnet about PEP 393 strings, on the basis that > they take up more space in memory than a narrow build of Python 3.2 > would, for a string with lot

Re: Py 3.3, unicode / upper()

2012-12-19 Thread Ian Kelly
On Wed, Dec 19, 2012 at 1:55 PM, wrote: > Yes, it is correct (or can be considered as correct). > I do not wish to discuss the typographical problematic > of "Das Grosse Eszett". The web is full of pages on the > subject. However, I never succeeded to find an "official > position" from Unicode. T

Re: Py 3.3, unicode / upper()

2012-12-19 Thread Ian Kelly
On Wed, Dec 19, 2012 at 2:18 PM, wrote: > latin-1 (iso-8859-1) ? are you sure ? Yes. sys.getsizeof('a') > 26 sys.getsizeof('ab') > 27 sys.getsizeof('aé') > 39 Compare to: >>> sys.getsizeof('a\u0100') 42 The reason for the difference you posted is that pure ASCII strings have a

Re: Brython - Python in the browser

2012-12-19 Thread Ian Kelly
On Wed, Dec 19, 2012 at 5:07 PM, Terry Reedy wrote: > That says that my browser, Firefox 17, does not support HTML5. Golly gee. I > don't think any browser support5 all of that moving target, and Gecko > apparently supports about as large a subset as most. > https://en.wikipedia.org/wiki/Compariso

Re: Virtualenv loses context

2012-12-20 Thread Ian Kelly
On Thu, Dec 20, 2012 at 5:50 AM, wrote: > Brought my laptop out of hibernation to do some work this morning. I > attempted to run one of my ETLs and got the following error. I made no > changes since it was running yesterday. > > > > [swright@localhost app]$ python etl_botnet_meta.py --mode dev

Re: Py 3.3, unicode / upper()

2012-12-20 Thread Ian Kelly
On Thu, Dec 20, 2012 at 12:19 PM, wrote: > The first (and it should be quite obvious) consequence is that > you create bloated, unnecessary and useless code. I simplify > the flexible string representation (FSR) and will use an "ascii" / > "non-ascii" model/terminology. > > If you are an "ascii"

Re: Brython - Python in the browser

2012-12-21 Thread Ian Kelly
On Fri, Dec 21, 2012 at 9:16 AM, Pierre Quentel wrote: >> <= is a comparison expression operator, which is completely different. >> It is just wrong for this usage. I am 99.9% sure you will come to regret >> it eventually. Better to make the change now than in Brython2 or Brython3. > > I am 99.99%

Re: Brython - Python in the browser

2012-12-21 Thread Ian Kelly
On Fri, Dec 21, 2012 at 1:59 PM, Pierre Quentel wrote: >> By the way, what is Brython actually doing when you append a child to >> the document itself like that? Usually I would expect a div to be >> appended to the body or to another div. The above looks like it would >> attach the new div as a

Re: Brython - Python in the browser

2012-12-21 Thread Ian Kelly
On Fri, Dec 21, 2012 at 3:52 PM, Chris Angelico wrote: > On Sat, Dec 22, 2012 at 3:36 AM, Pierre Quentel > wrote: >> >>> Hmm. So when that gets added into a DIV, it has to get parsed for >>> tags? How does this work? This seems very odd. I would have expected >>> it to remain as DOM objects. >> >

Re: Brython - Python in the browser

2012-12-21 Thread Ian Kelly
On Fri, Dec 21, 2012 at 4:45 PM, Ian Kelly wrote: > In Brython, the str builtin does not return strings? Oh, and repr is just a synonym of str, which makes it useless. -- http://mail.python.org/mailman/listinfo/python-list

Re: Brython - Python in the browser

2012-12-21 Thread Ian Kelly
On Fri, Dec 21, 2012 at 4:45 PM, Ian Kelly wrote: > In my playing around with it just now, the addition doesn't seem to > actually return a string. >From the code, it appears that adding two nodes together *actually* returns a $AbstractTag object, which seems to be just a container

Re: Brython - Python in the browser

2012-12-22 Thread Ian Kelly
On Sat, Dec 22, 2012 at 1:31 PM, Dan Sommers wrote: > So why are we all so comfortable with using "*" as the operator for > multiplication? I'm sure that a new programming language that dared to > use U+00D7 or U+2715 for multiplication would be instantly rejected on > the grounds that it was con

Re: Custom alphabetical sort

2012-12-24 Thread Ian Kelly
On Dec 24, 2012 9:37 AM, "Pander Musubi" wrote: > > >>> ''.join(sorted(random.sample(cs, 20), key=d.get)) > > > > '5aAàÀåBCçËÉíÎLÖøquùx' > > This doesn't work for words with more than one character: Try this instead: def collate(x): return list(map(d.get, x)) sorted(data, key=collate) I w

Re: Password hash

2012-12-26 Thread Ian Kelly
On Tue, Dec 25, 2012 at 8:40 PM, Ramchandra Apte wrote: > On Monday, 24 December 2012 08:08:12 UTC+5:30, Robert Montgomery wrote: >> I am writing a script that will send an email using an account I set up >> >> in gmail. It is an smtp server using tls on port 587, and I would like >> >> to use a

Re: Can you please help me?

2012-12-26 Thread Ian Kelly
On Wed, Dec 26, 2012 at 4:21 PM, wrote: > Thank you very much for your reply. I actually just deleted this post as you > were replying! I had figured out a few things and then got confused about a > few others :/ If you have a chance, can you look at the other post? Thank > you!! You can'

Re: Creating an iterator in a class

2012-12-27 Thread Ian Kelly
On Thu, Dec 27, 2012 at 7:44 AM, Joseph L. Casale wrote: > I am writing a class to provide a db backed configuration for an application. > > In my programs code, I import the class and pass the ODBC params to the > class for its __init__ to instantiate a connection. > > I would like to create a fu

Re: 3.2 can't extract tarfile produced by 2.7

2012-12-27 Thread Ian Kelly
On Thu, Dec 27, 2012 at 11:50 AM, Steven W. Orr wrote: > Really? I thought that the whole idea of using "rb" or "wb" was something > that was necessitated by WinBlo$e. We're not doing IO on a text file here. > It's a tar file which by definition is binary and it's not clear to me why > unicode has

Re: 3.2 can't extract tarfile produced by 2.7

2012-12-27 Thread Ian Kelly
On Thu, Dec 27, 2012 at 12:25 PM, Ian Kelly wrote: > You're correct that it makes no sense to open a tar file in binary > mode, Of course that should have read: "it makes no sense to open a tar file in text mode." -- http://mail.python.org/mailman/listinfo/python-list

Re: Function Parameters

2012-12-27 Thread Ian Kelly
On Thu, Dec 27, 2012 at 1:16 PM, Joseph L. Casale wrote: > When you use optional named arguments in a function, how do you deal with with > the incorrect assignment when only some args are supplied? > > If I do something like: > > def my_func(self, **kwargs): > > then handle the test cases wit

Re: Function Parameters

2012-12-27 Thread Ian Kelly
On Thu, Dec 27, 2012 at 1:47 PM, Joseph L. Casale wrote: >> Don't use kwargs for this. List out the arguments in the function >> spec and give the optional ones reasonable defaults. > >> I only use kwargs myself when the set of possible arguments is dynamic >> or unknown. > > Gotch ya, but when t

Re: Custom alphabetical sort

2012-12-27 Thread Ian Kelly
On Thu, Dec 27, 2012 at 3:17 PM, Terry Reedy wrote: >> PS Py 3.3 warranty: ~30% slower than Py 3.2 > > > Do you have any actual timing data to back up that claim? > If so, please give specifics, including build, os, system, timing code, and > result. There was another thread about this one a whil

Re: How to get time.strptime()?

2012-12-27 Thread Ian Kelly
On Thu, Dec 27, 2012 at 5:33 PM, Gnarlodious wrote: > Graham Dumpleton has informed me that the the relevant bug reports are: > > http://bugs.python.org/issue8098 > http://bugs.python.org/issue9260 > > To quote: > > All the problems derive from a stupid function in Python internals called > PyImp

Re: pylint, was Re: pygame - importing GL - very bad...

2013-01-02 Thread Ian Kelly
On Wed, Jan 2, 2013 at 7:32 AM, Chris Angelico wrote: > Okay, I have to ask... why? Does it have an exception for names of classes? Yes, and for module-level functions. > I don't like linters that enforce too much style. Catch things that > might be mis-coded (like C's classic "if (x = 1)"), but

Re: pylint, was Re: pygame - importing GL - very bad...

2013-01-02 Thread Ian Kelly
On Wed, Jan 2, 2013 at 10:57 AM, Chris Angelico wrote: > Yeah, same applies to most linters I think. You end up disagreeing > with the author on half the points. Oh well. Doesn't make the tool > useless, just means you need to fiddle with it to get it how you want > it. It's a lot less work to di

Re: pylint, was Re: pygame - importing GL - very bad...

2013-01-02 Thread Ian Kelly
On Wed, Jan 2, 2013 at 4:52 PM, Steven D'Aprano wrote: > If pylint says that global variables should be named like "__variable__", > that is explicitly going against PEP 8. It doesn't say that anywhere. It includes dunder names in the regex so that you don't get spurious warnings from pylint abo

Re: pylint, was Re: pygame - importing GL - very bad...

2013-01-02 Thread Ian Kelly
On Wed, Jan 2, 2013 at 7:24 PM, someone wrote: > 1) class somethingWork: Invalid name "somethingWork" (should match > [A-Z_][a-zA-Z0-9]+$), I'm not that good at regular exps, but I suppose it > wants my class name to start with a capital letter ? Yes, PEP-8 recommends CamelCase for class names.

Re: Important questions about __future__

2013-01-03 Thread Ian Kelly
On Thu, Jan 3, 2013 at 2:27 AM, Andrew Berg wrote: > Does 'from __future__ import barry_as_FLUFL' do anything? Despite PEP > 401, using print as a statement still raises a SyntaxError. I think it only replaces the != operator with <>. > Where is 'from __future__ import braces' implemented in CPy

Re: Need a specific sort of string modification. Can someone help?

2013-01-05 Thread Ian Kelly
On Sat, Jan 5, 2013 at 8:57 AM, Chris Angelico wrote: > You miss my point, though. I went for simple Pythonic code, and never > measured its performance, on the expectation that it's "good enough". > Written in C, the state machine is probably WAY faster than splitting > and then iterating. My C++

Re: help

2013-01-07 Thread Ian Kelly
On Mon, Jan 7, 2013 at 12:37 PM, Chris Angelico wrote: > On Tue, Jan 8, 2013 at 10:35 AM, wrote: >> download wxpython but whenever I try to use it I get this I’m a beginner in >> python pls I need help. >> >> ImportError: DLL load failed: %1 is not a valid Win32 application. > > Did you download

Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes

2013-01-08 Thread Ian Kelly
On Tue, Jan 8, 2013 at 12:16 PM, Neal Becker wrote: > Did you intend to give anyone permission to use the code? I see only a > copyright notice, but no permissions. It also says "Licence: python, Copyright notice may not be altered." Which suggests to me that the intent is that it be licensed u

Re: How to tell how many weeks apart two datetimes are?

2013-01-08 Thread Ian Kelly
On Tue, Jan 8, 2013 at 2:22 PM, Roy Smith wrote: > How do you tell how many weeks apart two datetimes (t1 and t2) are? > The "obvious" solution would be: > > weeks = (t2 - t1) / timedelta(days=7) > > but that doesn't appear to be allowed. Is there some fundamental > reason why timedelta division

Re: How to tell how many weeks apart two datetimes are?

2013-01-08 Thread Ian Kelly
On Tue, Jan 8, 2013 at 2:33 PM, Ian Kelly wrote: > On Tue, Jan 8, 2013 at 2:22 PM, Roy Smith wrote: >> How do you tell how many weeks apart two datetimes (t1 and t2) are? >> The "obvious" solution would be: >> >> weeks = (t2 - t1) / timedelta(days=7) >&g

Re: average time calculation??

2013-01-10 Thread Ian Kelly
On Thu, Jan 10, 2013 at 1:31 PM, pmec wrote: > Hi Oscar, again I do apologize for my beginner mistakes, I've changed the > code taking in consideration some of your and MRAB suggestions. > > Could you give me an example on how could I use the datetime.timedelta > function in this particular case

Re: String concatenation benchmarking weirdness

2013-01-11 Thread Ian Kelly
On Fri, Jan 11, 2013 at 12:03 PM, Rotwang wrote: > Hi all, > > the other day I 2to3'ed some code and found it ran much slower in 3.3.0 than > 2.7.2. I fixed the problem but in the process of trying to diagnose it I've > stumbled upon something weird that I hope someone here can explain to me. In >

Re: PyWart: Module access syntax

2013-01-11 Thread Ian Kelly
On Fri, Jan 11, 2013 at 9:34 PM, Rick Johnson wrote: > No the rules are: > * "Colon" must be used to access a "module" (or a package). > * "Dot" must be used to access a "module member". What about module a that does not natively contain module b, but imports it as a member like so? a.py

Re: PyWart: Import resolution order

2013-01-11 Thread Ian Kelly
On Fri, Jan 11, 2013 at 10:28 PM, Rick Johnson wrote: > On Friday, January 11, 2013 12:30:27 AM UTC-6, Chris Angelico wrote: >> Why is it better to import from the current directory first? > > Opps. I was not explicit enough with my explanation :). I meant, "look in the > current directory FIRST

Re: String concatenation benchmarking weirdness

2013-01-12 Thread Ian Kelly
On Sat, Jan 12, 2013 at 1:38 AM, wrote: > The difference between a correct (coherent) unicode handling and ... This thread was about byte string concatenation, not unicode, so your rant is not even on-topic here. -- http://mail.python.org/mailman/listinfo/python-list

Re: PyWart: Module access syntax

2013-01-14 Thread Ian Kelly
On Sun, Jan 13, 2013 at 10:22 PM, Rick Johnson wrote: > You are missing the point of this syntax. The colon is to access MODULE > NAMESPACE. The dot is to access MODULE MEMBERS. A module CAN BE another > module's MEMBER. > > You are also unable to grasp this simple logical fact: Once you arrive

Re: PyWart: Module access syntax

2013-01-14 Thread Ian Kelly
On Mon, Jan 14, 2013 at 11:51 AM, Ian Kelly wrote: >> Because modules and objects are not the same and someone who is reading the >> source code NEEDS to know which "path members" are /modules/ and which "path >> members" are /objects/. And he needs to kn

Re: PyWart: Module access syntax

2013-01-14 Thread Ian Kelly
On Mon, Jan 14, 2013 at 12:35 PM, D'Arcy J.M. Cain wrote: > On Mon, 14 Jan 2013 11:51:50 -0700 > Ian Kelly wrote: >> On Sun, Jan 13, 2013 at 10:22 PM, Rick Johnson >> wrote: > ...Whatever > >> If you want us to understand the syntax, then you need to defi

Re: code explanation

2013-01-14 Thread Ian Kelly
On Mon, Jan 14, 2013 at 9:51 PM, Rodrick Brown wrote: > import sys > > PY3K = sys.version_info >= (3,) > > > methods = set([ > "__iter__", > "__len__", > "__contains__", > > "__lt__", > "__le__", > "__eq__", > "__ne__", > "__gt__", > "__ge__", > > "__add__",

Re: Is there a more elegant way to handle determing fail status?

2013-01-15 Thread Ian Kelly
On Tue, Jan 15, 2013 at 4:24 PM, J wrote: > The exit code determination above works, but it just feels inelegant. > It feels like there's a better way of implementing that, but I can't > come up with one that still honors the fail level properly (e.g. other > solutions will fail on medium, but won

Re: finding abc's

2013-01-25 Thread Ian Kelly
On Fri, Jan 25, 2013 at 10:40 AM, lars van gemerden wrote: > Hi all, > > i was writing a function to determine the common base class of a number > classes: > [...] > > and ran common_base(int, float), hoping to get numbers.Number. > > this did not work because abstract base classes are not always

Re: Retrieving an object from a set

2013-01-25 Thread Ian Kelly
On Fri, Jan 25, 2013 at 4:14 PM, Arnaud Delobelle wrote: > Dear Pythoneers, > > I've got a seemingly simple problem, but for which I cannot find a > simple solution. > > I have a set of objects (say S) containing an object which is equal to > a given object (say x). So > > x in S > > is true.

Re: Retrieving an object from a set

2013-01-25 Thread Ian Kelly
On Fri, Jan 25, 2013 at 4:30 PM, Ian Kelly wrote: > On Fri, Jan 25, 2013 at 4:14 PM, Arnaud Delobelle wrote: >> Dear Pythoneers, >> >> I've got a seemingly simple problem, but for which I cannot find a >> simple solution. >> >> I have a set of objects

Re: Retrieving an object from a set

2013-01-25 Thread Ian Kelly
On Fri, Jan 25, 2013 at 4:45 PM, MRAB wrote: > You could first limit the search to only those which it could be: > > S & set([y]) > > A search would be: > f = [m for m in S & set([y]) if m is y][0] f is y > True But in practice he won't have y, only x. So that would have to be: >>

Re: A new script which creates Python 3.3 venvs with Distribute and pip installed in them

2013-01-30 Thread Ian Kelly
On Wed, Jan 30, 2013 at 1:09 PM, Vinay Sajip wrote: > Python 3.3 includes a script, pyvenv, which is used to create virtual > environments. However, Distribute and pip are not installed in such > environments - because, though they are popular, they are third-party > packages - not part of Pyth

Re: help

2013-01-30 Thread Ian Kelly
On Wed, Jan 30, 2013 at 2:16 PM, wrote: > Hi everyone! I don't mean to intrude, but ive heard great things about this > group and ive stumped myself with my python code. > > heres my code: It would be helpful if you would also include the error that you get when trying to run the code. > globa

Re: while True or while 1

2012-01-23 Thread Ian Kelly
On Mon, Jan 23, 2012 at 9:41 AM, Giampaolo Rodolà wrote: > > Il 21 gennaio 2012 22:13, Erik Max Francis ha scritto: > > The real reason people still use the `while 1` construct, I would imagine, > > is just inertia or habit, rather than a conscious, defensive decision.  If > > it's the latter, it

Re: Using an object inside a class

2012-01-23 Thread Ian Kelly
On Mon, Jan 23, 2012 at 12:44 PM, Jonno wrote: > I have a pretty complicated bit of code that I'm trying to convert to more > clean OOP. Then you probably should not be using globals. > Without getting too heavy into the details I have an object which I am > trying to make available inside anoth

Re: Using an object inside a class

2012-01-23 Thread Ian Kelly
On Mon, Jan 23, 2012 at 1:58 PM, MRAB wrote: >> Either way would work but the main issue is I can't seem to use foo or >> foo.bar or foo.bar.object anywhere in __init__ or even before that in >> the main class area. >> > This line: > > foo = MyApp(0) > > will create a 'MyApp' instance and then bin

Re: Using an object inside a class

2012-01-23 Thread Ian Kelly
On Mon, Jan 23, 2012 at 2:22 PM, Jonno wrote: >> References inside functions are resolved when the function is called. So >> purely from what you have presented above, it would seem that 'foo' is >> defined between the call to __init__ and a later call to method1. > > > I have a strong suspicion t

Re: Using an object inside a class

2012-01-23 Thread Ian Kelly
On Mon, Jan 23, 2012 at 2:52 PM, Jonno wrote: > On Mon, Jan 23, 2012 at 3:42 PM, Ian Kelly wrote: >> >> Exactly.  The line "app = MyApp(0)" creates a MyApp instance and then >> assigns it to "app".  As part of the MyApp creation process, it >>

Re: Using an object inside a class

2012-01-23 Thread Ian Kelly
On Mon, Jan 23, 2012 at 3:45 PM, Jonno wrote: > I see, so that would get me access to the app instance during init of Class1 > but if I can't access frame or the object as they still aren't created yet. > I can only do that in attributes that I know won't be called until the app > is created. Yea

Re: The devolution of English language and slothful c.l.p behaviors exposed!

2012-01-23 Thread Ian Kelly
On Mon, Jan 23, 2012 at 10:57 PM, Rick Johnson wrote: > > Here is a grep A grep? What is a grep? That word is not in any of my dictionaries. Are you perhaps carelessly invoking the neologism of referring to an execution of the "grep" UNIX program as "a grep"? > from the month of September 2011

Re: PyWart: Python regular expression syntax is not intuitive.

2012-01-25 Thread Ian Kelly
On Wed, Jan 25, 2012 at 10:16 AM, Rick Johnson wrote: > (?...)  # Base Extension Syntax > All extensions are wrapped in parenthesis and start with a question > mark, but i believe the question mark was a very bad choice, since the > question mark is already specific to "zero or one repetitions of

Re: The devolution of English language and slothful c.l.p behaviors exposed!

2012-01-25 Thread Ian Kelly
On Wed, Jan 25, 2012 at 1:14 PM, Rick Johnson wrote: > Wow, why i am not surprised! Let's pick one usage at random and try to > understand it. "I think XYZ is pretty easy." You don't even need > "pretty" to get your point across. You could simply say "I think XYZ > is easy". But "easy" and "prett

Re: PyWart: Python regular expression syntax is not intuitive.

2012-01-25 Thread Ian Kelly
On Wed, Jan 25, 2012 at 2:19 PM, Rick Johnson wrote: > I disagree here. > Whist some people may be "die-hard" fans of the un-intuitive perl > regex syntax, i believe many, if not exponentially MORE people would > like to have a better alternative. Do i want to remove the current > "well establishe

Re: The devolution of English language and slothful c.l.p behaviors exposed!

2012-01-25 Thread Ian Kelly
On Wed, Jan 25, 2012 at 4:23 PM, Rick Johnson wrote: > Only to you. In my world, the "pleasurable aspects of a tangible > object" can have no effect on my opinion of the difficulty of a task. Then your world is not the real world, that being the one that is actually described by every dictionary

Re: The devolution of English language and slothful c.l.p behaviors exposed!

2012-01-25 Thread Ian Kelly
On Wed, Jan 25, 2012 at 6:00 PM, Rick Johnson wrote: > On Jan 25, 6:20 pm, Ian Kelly wrote: >> On Wed, Jan 25, 2012 at 4:23 PM, Rick Johnson > >> > """I was frightened that the finals might be difficult this year, >> > however to my surprise, they

Re: The devolution of English language and slothful c.l.p behaviors exposed!

2012-01-25 Thread Ian Kelly
On Wed, Jan 25, 2012 at 10:25 PM, rusi wrote: > The contents of this thread ostensibly argues about the word 'pretty' > Actually it seems to be arguing about the word 'troll' > > Every other post calls the OP a troll and then outdoes his post in > length. I just grepped, and it's hardly "every ot

Re: contextlib.contextmanager and try/finally

2012-01-31 Thread Ian Kelly
On Tue, Jan 31, 2012 at 2:07 PM, Prasad, Ramit wrote: >>Like Neil mentioned, a contextmanager generator is wrapped with an >>__exit__ method that is guaranteed to be called and that explicitly >>resumes or closes the generator.  So as long as your contextmanager >>generator is properly written (i.

Re: except clause syntax question

2012-01-31 Thread Ian Kelly
On Tue, Jan 31, 2012 at 5:53 PM, Chris Angelico wrote: > On Wed, Feb 1, 2012 at 9:03 AM, Duncan Booth > wrote: >> Abitrarily nested tuples of exceptions cannot contain loops so the code >> simply needs to walk through the tuples until it finds a match. > > Is this absolutely guaranteed? The C API

Re: except clause syntax question

2012-01-31 Thread Ian Kelly
On Tue, Jan 31, 2012 at 6:09 PM, Ian Kelly wrote: > On Tue, Jan 31, 2012 at 5:53 PM, Chris Angelico wrote: >> On Wed, Feb 1, 2012 at 9:03 AM, Duncan Booth >> wrote: >>> Abitrarily nested tuples of exceptions cannot contain loops so the code >>> simply needs to

Re: 'class' named tuple

2012-01-31 Thread Ian Kelly
On Tue, Jan 31, 2012 at 5:54 PM, Emmanuel Mayssat wrote: > I have the following program. > I am trying to have index the attributes of an object using __getitem__. > Reading them this way works great, but assigning them a value doesn't > Is there a way to do such a thing? For assignment, use __se

Re: Question about name scope

2012-02-01 Thread Ian Kelly
On Wed, Feb 1, 2012 at 11:47 AM, Mel Wilson wrote: > I guess they want local symbols in functions to be pre-compiled.  Similar to > the way you can't usefully update the dict returned by locals().  Strangely, > I notice that > > Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) > [GCC 4.4.3] on lin

Re: Question about name scope

2012-02-01 Thread Ian Kelly
On Wed, Feb 1, 2012 at 3:24 PM, Ethan Furman wrote: > Definitely should rely on it, because in CPython 3 exec does not un-optimize > the function and assigning to locals() will not actually change the > functions variables. Well, the former is not surprising, since exec was changed from a stateme

Re: Question about name scope

2012-02-01 Thread Ian Kelly
On Wed, Feb 1, 2012 at 3:53 PM, Ethan Furman wrote: > --> def f(x, y): > > ...     locals()[x] = y > ...     print(vars()) > ...     exec('print (' + x + ')') > ...     print(x) > ... > --> f('a', 42) > > {'y': 42, 'x': 'a', 'a': 42} > 42 > a > > Indeed -- the point to keep in mind is that locals(

Re: Question about name scope

2012-02-01 Thread Ian Kelly
On Wed, Feb 1, 2012 at 4:41 PM, Ethan Furman wrote: > I'm not sure what you mean by temporary: > > --> def f(x, y): > > ...     frob = None > ...     loc = locals() > ...     loc[x] = y > ...     print(loc) > ...     print(locals()) > ...     print(loc) > ...     print(locals()) > ... > --> > -->

Re: SnakeScript? (CoffeeScript for Python)

2012-02-02 Thread Ian Kelly
On Thu, Feb 2, 2012 at 3:53 PM, andrea crotti wrote: > 2012/2/2 Amirouche Boubekki : >> They are solution to write Python code that translates to javascript see >> this thread >> http://mail.python.org/pipermail/python-list/2011-November/1283110.html >> > > Mm I don't think it's what the OP is ask

Re: Common LISP-style closures with Python

2012-02-05 Thread Ian Kelly
On Sat, Feb 4, 2012 at 9:19 PM, Antti J Ylikoski wrote: >> I'm not sure how naughty this is, but the same thing can be done without >> using >> nonlocal by storing the local state as an attribute of the enclosed >> function >> object: >> >> ... > > Yes, I do know that, but then it would not be a c

Re: iterating over list with one mising value

2012-02-07 Thread Ian Kelly
On Tue, Feb 7, 2012 at 5:27 AM, Sammy Danso wrote: > > Hello experts, > I am having trouble accessing the content of my list. > my list content has 2-pair value with the exception of one which has single > value. here is an example  ['a', 1, 'b', 1, 'c', 3, 'd'] > > I am unable to iterate through

Re: frozendict

2012-02-08 Thread Ian Kelly
On Wed, Feb 8, 2012 at 6:23 PM, Evan Driscoll wrote: > Hi all, > > I've been trying for a few days (only a little bit at a time) to come up > with a way of implementing a frozendict that doesn't suck. I'm gradually > converging to a solution, but I can't help but think that there's some > subtlety

Re: frozendict

2012-02-09 Thread Ian Kelly
On Thu, Feb 9, 2012 at 8:19 AM, Nathan Rice wrote: > As I said, two dictionaries created from the same input will be the > same... That's an implementation detail, not a guarantee. It will hold for current versions of CPython but not necessarily for other Python implementations. -- http://mail.

Re: Apparent "double imports" (was: Naming convention for in-house modules (Newbie question))

2012-02-09 Thread Ian Kelly
On Thu, Feb 9, 2012 at 11:53 AM, HoneyMonster wrote: > One issue I have run into, which may or may not be a problem: I am > finding that modules in the in-house "library" package sometimes have to > import modules like sys and os, which are also imported by the "calling" > module. Is this a proble

Re: round down to nearest number

2012-02-09 Thread Ian Kelly
On Thu, Feb 9, 2012 at 5:30 PM, noydb wrote: > How do you round down ALWAYS to nearest 100?  Like, if I have number > 3268, I want that rounded down to 3200.  I'm doing my rounding like round(3268, -2) > But, how to round DOWN? >>> 3268 // 100 * 100 3200 For more complicated cases, Decimal

Re: round down to nearest number

2012-02-09 Thread Ian Kelly
On Thu, Feb 9, 2012 at 6:43 PM, Chris Rebert wrote: > On Thu, Feb 9, 2012 at 5:23 PM, noydb wrote: >> hmmm, okay. >> >> So how would you round UP always?  Say the number is 3219, so you want >> 3300 returned. > > http://stackoverflow.com/questions/17944/how-to-round-up-the-result-of-integer-divis

Re: round down to nearest number

2012-02-09 Thread Ian Kelly
On Thu, Feb 9, 2012 at 8:36 PM, MRAB wrote: > On 10/02/2012 02:25, noydb wrote: >> >> That {>>>  (3219 + 99) // 100} doesnt work if the number is other then >> 4 digits. >> >> >> (for rounding up to nearest 100): > >  (3219 + 99)//100 >> >> 33 > >  (3289 + 99)//100 >> >> 33 > >

Re: Removing items from a list

2012-02-10 Thread Ian Kelly
On Fri, Feb 10, 2012 at 1:04 PM, Thomas Philips wrote: > In the past, when deleting items from a list, I looped through the > list in reverse to avoid accidentally deleting items I wanted to keep. > I tried something different today, and, to my surprise, was able to > delete items correctly, regar

<    1   2   3   4   5   6   7   8   9   10   >