Re: Implicit conversion to boolean in if and while statements

2012-07-15 Thread Ian Kelly
On Sun, Jul 15, 2012 at 10:50 AM, Rick Johnson wrote: > I think this issue is not so much a "bool test" vs "type test", but more an > ambiguous syntax issue. Consider this: > > ## EXAMPLE A ## > py> if money: > ... do_something() > > The syntax "if money" implies we are testing/measuring some

Re: Style question: metaclass self vs cls?

2012-07-17 Thread Ian Kelly
On Tue, Jul 17, 2012 at 6:23 AM, Michele Simionato wrote: > The standard is to use `cls`. In the __new__ method you can use `mcl` or > `meta`. I've also seen `mcs` a fair amount. -- http://mail.python.org/mailman/listinfo/python-list

Re: Style question: metaclass self vs cls?

2012-07-17 Thread Ian Kelly
On Tue, Jul 17, 2012 at 12:10 AM, alex23 wrote: > On Jul 17, 1:29 am, Steven D'Aprano +comp.lang.pyt...@pearwood.info> wrote: >> Here's a style question for you: in a metaclass, what should I call the >> instance parameter of methods, "cls" or "self"? > > Maybe portmanteu it as "clasself"? :) Wh

Re: Foxpro goto command and deleted records

2012-07-17 Thread Ian Kelly
On Tue, Jul 17, 2012 at 4:57 PM, Ethan Furman wrote: > In Foxpro if you do a > > GOTO 7 > > with deleted off and record 7 is deleted, the record pointer doesn't > move (at least in version 6). > > I don't like that. > > I see four other options: > > 0) don't move the pointer (listed for completene

Re: FORTH in Python (py4th.py)

2012-07-18 Thread Ian Kelly
On Wed, Jul 18, 2012 at 4:05 PM, wrote: > 7 Aralık 1994 Çarşamba 05:04:22 UTC+2 tarihinde Nick Seidenman yazdı: You realize that you're replying to a post from 1994? This code was written for Python 1.0. I'll be pretty impressed if it still works in 2.7. > Thank you for the code. How can i im

Re: Foxpro goto command and deleted records

2012-07-19 Thread Ian Kelly
On Wed, Jul 18, 2012 at 8:40 AM, Grant Edwards wrote: > On 2012-07-17, Ethan Furman wrote: > >> In Foxpro if you do a > > Foxpro? http://en.wikipedia.org/wiki/Visual_FoxPro -- http://mail.python.org/mailman/listinfo/python-list

Re: Encapsulation, inheritance and polymorphism

2012-07-20 Thread Ian Kelly
On Thu, Jul 19, 2012 at 3:01 PM, John Gordon wrote: > In Dennis Lee Bieber > writes: > >> > Sure it terminates...If you don't run out of RAM to represent the >> > number "i" in question, there's also this "heat death of the >> > universe" limit I keep hearing about ;-) >> > >> Since the c

Re: best way to handle this in Python

2012-07-20 Thread Ian Kelly
On Fri, Jul 20, 2012 at 4:34 AM, Rita wrote: > Thats an interesting data structure Dennis. I will actually be running this > type of query many times preferable in an ad-hoc environment. That makes it > tough for sqlite3 since there will be several hundred thousand tuples. Several hundred thousan

Re: Newbie question on python programming

2012-07-20 Thread Ian Kelly
On Fri, Jul 20, 2012 at 5:38 PM, Chris Williams wrote: > Hello > > I hope this is the right newsgroup for this post. > > I am just starting to learn python programming and it seems very > straightforward so far. It seems, however, geared toward doing the sort of > programming for terminal output.

Re: Converting a list of strings into a list of integers?

2012-07-22 Thread Ian Kelly
On Sun, Jul 22, 2012 at 10:20 AM, Jan Riechers wrote: > Hi, > > I am not sure why everyone is using the for-iterator option over a "map", > but I would do it like that: > > MODUS_LIST= map(int, options.modus_list) > > "map" works on a list and does commandX (here "int" conversion, use "str" > for

Re: Python and Outlook, sendinf an image in the body of email

2012-07-23 Thread Ian Kelly
On Mon, Jul 23, 2012 at 11:19 AM, wrote: > All, > > I am trying to figure out how to send a image in the body of a email when > Making a Meeting Request. You need to use html in the body with an tag that references the attachment. See: http://stackoverflow.com/questions/4312687/how-to-embed-

Re: Python and Outlook, sendinf an image in the body of email

2012-07-23 Thread Ian Kelly
On Mon, Jul 23, 2012 at 12:33 PM, wrote: > I tried something similar to the example at > http://stackoverflow.com/questions/4312687/how-to-embed-images-in-email . > > Problem is, this line is not understood: >mail.BodyFormat = OlBodyFormat.olFormatHTML > > Traceback (most recent call

Re: What's wrong with this code?

2012-07-24 Thread Ian Kelly
On Mon, Jul 23, 2012 at 7:19 PM, Andrew Cooper wrote: > Python is a statically scoped language, whereas the functionality you > are expecting would be an example of dynamically scoped. While it's true that Python is statically scoped, that has nothing at all to do with the code from the OP's ques

Re: the meaning of rユ.......ï¾

2012-07-24 Thread Ian Kelly
On Tue, Jul 24, 2012 at 8:50 AM, Chris Angelico wrote: > Americans celebrate March 14th as 3.14; some Europeans celebrate July > 22nd as 22/7 (which is 3.142857, fairly close to 3.14159). We claim > both, and also June 28th (aka Tau Day or Two Pi Day, 6.28). Hey now, Tau Day is an American invent

Re: no data exclution and unique combination.

2012-07-24 Thread Ian Kelly
On Jul 24, 2012 12:32 PM, wrote: > after i need to calculate unique combination in pairs to count the observations > and obtain > (4,3,2) > (4,5,1) > (5,4,1) > (4,4,2) I don't know about a numpy solution, but this could be achieved by collections.Counter(zip(a, b)).items(). That gives you: ((4,3

Re: Daemon loses __file__ reference after a while.

2012-07-24 Thread Ian Kelly
On Tue, Jul 24, 2012 at 8:59 AM, Dieter Maurer wrote: > "ivdn...@gmail.com" writes: > >> I have a daemon process that runs for a considerable amount of time (weeks >> on end) without any problems. At some point I start getting the exception: >> >> Exception info: Traceback (most recent call last

Re: Daemon loses __file__ reference after a while.

2012-07-24 Thread Ian Kelly
On Tue, Jul 24, 2012 at 1:32 PM, Paul Rubin wrote: > Dieter Maurer writes: >> I have only one vague idea: should something try to terminate the >> process, modules would start to lose their variables during shutdown. > > That happens all the time with multi-threaded programs, because the > shutdo

Re: assert expressions

2012-07-24 Thread Ian Kelly
On Tue, Jul 24, 2012 at 1:57 PM, Wanderer wrote: > If I use the code > > assert False, "unhandled option" > > I get output like: > > option -q not recognized > for help use --help > > What other expressions can I use other than "unhandled option"? Is there a > list somewhere? Are you using argpa

Re: assert expressions

2012-07-24 Thread Ian Kelly
On Tue, Jul 24, 2012 at 2:44 PM, Wanderer wrote: > I'm using getopt but not at that point. I really don't have a problem. > I'm just curious. I've never seen anything else after > assert False, > > Here is some code. It doesn't matter what you put after the assert False, because that line is not

Re: from future import pass_function

2012-07-25 Thread Ian Kelly
On Jul 25, 2012 10:51 AM, "Devin Jeanpierre" wrote: > True. But it might be nice to use pass both in lambdas and regular > functions, or to use pass as a variable name. You can already use pass (or the equivalent) in a lambda. lambda: None -- http://mail.python.org/mailman/listinfo/python-list

Re: the meaning of rユ.......ï¾

2012-07-26 Thread Ian Kelly
On Tue, Jul 24, 2012 at 9:07 PM, Ben Finney wrote: > +1 on celebrating τ day! https://www.youtube.com/watch?v=jG7vhMMXagQ> Also: http://tauday.com/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Generating valid identifiers

2012-07-26 Thread Ian Kelly
On Thu, Jul 26, 2012 at 9:30 AM, Steven D'Aprano wrote: > What happens if you get a collision? > > That is, you have two different long identifiers: > > a.b.c.d...something > a.b.c.d...anotherthing > > which by bad luck both hash to the same value: > > a.b.c.d.$AABB99 > a.b.c.d.$AABB99 > > (or wha

Re: Generating valid identifiers

2012-07-26 Thread Ian Kelly
On Thu, Jul 26, 2012 at 1:28 PM, Ian Kelly wrote: > The odds of a given pair of identifiers having the same digest to 10 > hex digits are 1 in 16^10, or approximately 1 in a trillion. If you > bought one lottery ticket a day at those odds, you would win > approximately once every 3 b

Re: from future import pass_function

2012-07-26 Thread Ian Kelly
On Thu, Jul 26, 2012 at 2:48 PM, John Ladasky wrote: > On Wednesday, July 25, 2012 1:40:45 AM UTC-7, Ulrich Eckhardt wrote: >> Hi! >> >> I just had an idea, it occurred to me that the pass statement is pretty >> similar to the print statement, and similarly to the print() function, >> there could

Re: argparse limitations

2012-07-27 Thread Ian Kelly
On Fri, Jul 27, 2012 at 9:19 AM, Benoist Laurent wrote: > That's the solution I came to. > But I'm not very happy with this since I can definitively not make my > program act as a standard unix tool. > Any other solution? I don't understand; that's pretty much the same way that standard unix tool

Re: argparse limitations

2012-07-27 Thread Ian Kelly
On Fri, Jul 27, 2012 at 10:26 AM, Ian Kelly wrote: > It may be a bit awkward having to type "-i" once per file in the > command line, but it does clear up the ambiguity. Or you could bite the bullet and make the input files argument part of the subparser, which you may find ugl

Re: OT: accessibility (was "Re: simplified Python parsing question")

2012-07-30 Thread Ian Kelly
On Mon, Jul 30, 2012 at 8:54 PM, Tim Chase wrote: > I've tried a similar experiment and am curious on your input device. > Eye-tracking/dwell-clicking? A sip/puff joystick? Of the various > input methods I tried, I found that Dasher[1] was the most > intuitive, had a fairly high input rate and

Re: Why 'Flat is better than nested'

2012-07-31 Thread Ian Kelly
On Tue, Jul 31, 2012 at 3:28 PM, Ifthikhan Nazeem wrote: > as many as (about) 2*N - log2(N) parent child relationships > > I would like to know how did you come up with the above formula? Forgive my > ignorance. I come up with 2N - 2 myself. If there are N leaf nodes and N - 1 non-leaf nodes, th

Re: [OT] Posting under ones full name

2012-08-15 Thread Ian Kelly
On Tue, Aug 14, 2012 at 9:18 PM, Chris Angelico wrote: > On Wed, Aug 15, 2012 at 12:06 PM, Thomas 'PointedEars' Lahn > wrote: >> Please use `[...]' or `[…]' to indicate omission instead. I could have >> written `politeness...' myself. > > Incidentally, how _do_ the square brackets help? The squ

Re: type(None)()

2012-08-16 Thread Ian Kelly
On Thu, Aug 16, 2012 at 6:47 AM, Hans Mulder wrote: > On 8/08/12 04:14:01, Steven D'Aprano wrote: >> NoneType raises an error if you try to create a second instance. bool >> just returns one of the two singletons (doubletons?) again. >> >> py> type(None)() >> Traceback (most recent call last): >>

Re: set and dict iteration

2012-08-16 Thread Ian Kelly
On Thu, Aug 16, 2012 at 12:00 PM, Aaron Brady wrote: > The inconsistency is, if we remove an element from a set and add another > during iteration, the new element might appear later in the iteration, and > might not, depending on the hash code; therefore comparing the size of the > set between

Re: set and dict iteration

2012-08-16 Thread Ian Kelly
On Thu, Aug 16, 2012 at 4:55 PM, Ian Kelly wrote: > On Thu, Aug 16, 2012 at 12:00 PM, Aaron Brady wrote: >> The inconsistency is, if we remove an element from a set and add another >> during iteration, the new element might appear later in the iteration, and >> might not,

Re: set and dict iteration

2012-08-16 Thread Ian Kelly
On Thu, Aug 16, 2012 at 5:11 PM, Dave Angel wrote: > There's an enormous difference between type errors, which affect the low > level dispatch, and checking for whether a dict has changed and may have > invalidated the iterator. If we were really going to keep track of what > iterators are tracki

Re: Crashes always on Windows 7

2012-08-17 Thread Ian Kelly
On Aug 17, 2012 8:58 AM, "Dave Angel" wrote: > > Also, please tell us the versions involved, and in the case of > ActiveSync, where you got it. > > http://sourceforge.net/apps/trac/unattended/wiki/ActiveSync > seems to be perl related, not Python. > > Presumably you mean the Microsoft product

Re: ONLINE SERVER TO STORE AND RUN PYTHON SCRIPTS

2012-08-17 Thread Ian Kelly
On Fri, Aug 17, 2012 at 6:46 AM, coldfire wrote: > I would like to know that where can a python script be stored on-line from > were it keep running and can be called any time when required using internet. > I have used mechanize module which creates a webbroswer instance to open a > website and

Re: How do I display unicode value stored in a string variable using ord()

2012-08-17 Thread Ian Kelly
On Aug 17, 2012 2:58 PM, "Dave Angel" wrote: > > The internal coding described in PEP 393 has nothing to do with latin-1 > encoding. It certainly does. PEP 393 provides for Unicode strings to be represented internally as any of Latin-1, UCS-2, or UCS-4, whichever is smallest and sufficient to con

Re: How do I display unicode value stored in a string variable using ord()

2012-08-18 Thread Ian Kelly
(Resending this to the list because I previously sent it only to Steven by mistake. Also showing off a case where top-posting is reasonable, since this bit requires no context. :-) On Sat, Aug 18, 2012 at 1:41 AM, Ian Kelly wrote: > > On Aug 17, 2012 10:17 PM, "Steven D'

Re: How do I display unicode value stored in a string variable using ord()

2012-08-18 Thread Ian Kelly
On Sat, Aug 18, 2012 at 9:07 AM, wrote: > Le samedi 18 août 2012 14:27:23 UTC+2, Steven D'Aprano a écrit : >> [...] >> The problem with UCS-4 is that every character requires four bytes. >> [...] > > I'm aware of this (and all the blah blah blah you are > explaining). This always the same song. M

Re: How do I display unicode value stored in a string variable using ord()

2012-08-19 Thread Ian Kelly
On Sun, Aug 19, 2012 at 12:33 AM, Steven D'Aprano wrote: > On Sat, 18 Aug 2012 09:51:37 -0600, Ian Kelly wrote about PEP 393: >> There is some additional benefit for Latin-1 users, but this has nothing >> to do with Python. If Python is going to have the option of a 1-byte &g

Re: How do I display unicode value stored in a string variable using ord()

2012-08-19 Thread Ian Kelly
On Sun, Aug 19, 2012 at 12:20 PM, Paul Rubin wrote: > Ian Kelly writes: >>>>> sys.getsizeof(bytes(range(256)).decode('latin1')) >> 329 > > Please try: > >print (type(bytes(range(256)).decode('latin1'))) > > to make sure that wha

Re: How do I display unicode value stored in a string variable using ord()

2012-08-19 Thread Ian Kelly
On Sun, Aug 19, 2012 at 11:50 AM, Ian Kelly wrote: > Note that this only describes the structure of "compact" string > objects, which I have to admit I do not fully understand from the PEP. > The wording suggests that it only uses the PyASCIIObject structure, > not the d

Re: Abuse of Big Oh notation

2012-08-20 Thread Ian Kelly
On Mon, Aug 20, 2012 at 10:09 AM, Chris Angelico wrote: > On Tue, Aug 21, 2012 at 2:01 AM, Paul Rubin wrote: >> Analogy: how big a box is required to hold a pair of shoes? In a purely >> theoretical sense we might say O(S) where S is the shoe size, treating >> shoe size as an arbitrary independe

Re: How to convert base 10 to base 2?

2012-08-20 Thread Ian Kelly
On Mon, Aug 20, 2012 at 11:29 AM, Dennis Lee Bieber wrote: > I think I typically have done this by going through a hex > representation. > > H2B_Lookup = { "0" : "", "1" : "0001", > "2" : "0010", "3" : "0011", >

Re: How to convert base 10 to base 2?

2012-08-20 Thread Ian Kelly
On Mon, Aug 20, 2012 at 11:57 AM, Joel Goldstick wrote: > This may be moving off topic, but since you encode -6 as -0110 I > thought I'd chime in on 'two's complement' > > with binary number, you can represent 0 to 255 in a byte, or you can > represent numbers from 127 to -128. To get the negativ

Re: Class.__class__ magic trick help

2012-08-20 Thread Ian Kelly
On Mon, Aug 20, 2012 at 12:01 PM, Massimo Di Pierro wrote: > I discovered I can do this: > > class A(object): pass > class B(object): > __class__ = A # magic > > b = B() > isinstance(b,A) # returns True (as if B derived from A) > isinstance(b,B) # also returns True

Re: Why does dynamic doc string do not work?

2012-08-21 Thread Ian Kelly
On Tue, Aug 21, 2012 at 10:44 AM, Miki Tebeka wrote: > Greetings, > class A: > ... '''a doc string''' > ... A.__doc__ > 'a doc string' class B: > ... '''a {} string'''.format('doc') > ... B.__doc__ > > Is there's a reason for this? > > I know I can do: class B

Re: Why does dynamic doc string do not work?

2012-08-21 Thread Ian Kelly
On Tue, Aug 21, 2012 at 11:09 AM, Ian Kelly wrote: > On Tue, Aug 21, 2012 at 10:44 AM, Miki Tebeka wrote: >> Greetings, >> >>>>> class A: >> ... '''a doc string''' >> ... >>>>> A.__doc__ >> &#

Re: Objects in Python

2012-08-22 Thread Ian Kelly
In addition to the excellent feedback that Dave gave you: On Wed, Aug 22, 2012 at 9:25 AM, shaun wrote: > def breakuparray(self): > for row in self.array: > mer = row[0].ljust(25, ' ') > merc = row[1].ljust(13, ' ') >

Re: How to properly implement worker processes

2012-08-22 Thread Ian Kelly
On Wed, Aug 22, 2012 at 11:29 AM, Dennis Jacobfeuerborn wrote: > Hi, > I'm trying to implement a system for periodically checking URLs and I've run > into problems with some of the implementation details. The URLs are supposed > to be checked continuously until the config for an URL is explicitl

Re: Objects in Python

2012-08-22 Thread Ian Kelly
On Wed, Aug 22, 2012 at 11:46 AM, lipska the kat wrote: > If, in a language, I find I am able to say > > a = 1 > > then later, in the same scope I can say > > a = "foo" > > then later again in the same scope I can say > > a = ([1,2,3], "xyz", True) > > then, and I may be missing something here, to

Re: How to properly implement worker processes

2012-08-22 Thread Ian Kelly
On Wed, Aug 22, 2012 at 1:40 PM, Dennis Jacobfeuerborn wrote: > I was thinking about something like that but the issue is that this really > only works when you don't do any actual blocking work. I may be able to get > around the sleep() but then I have to fetch the URL or do some other work >

Re: Objects in Python

2012-08-22 Thread Ian Kelly
On Wed, Aug 22, 2012 at 5:58 PM, Ben Finney wrote: > Those people are confused, then. Python is strongly typed: objects > always know their type, the type is always exact, and the type of an > object can't be changed. Except when it can. >>> class A: pass ... >>> class B: pass ... >>> a = A() >>

Re: Flexible string representation, unicode, typography, ...

2012-08-23 Thread Ian Kelly
On Thu, Aug 23, 2012 at 9:11 AM, MRAB wrote: > Perhaps the solution should've been to just switch between 2/4 bytes instead > of 1/2/4 bytes. :-) Why? You don't lose any complexity by doing that. I can see arguments for 1/2/4 or for just 4, but I can't see any advantage of 2/4 over either of th

Re: Objects in Python

2012-08-23 Thread Ian Kelly
On Thu, Aug 23, 2012 at 12:02 PM, Jan Kuiken wrote: > On 8/23/12 06:11 , Steven D'Aprano wrote: > >>> 2) Related to the above, you can infinitely nest scopes. There's nothing >>> wrong with having six variables called 'q'; you always use the innermost >>> one. Yes, this can hurt readability >> >>

Re: Flexible string representation, unicode, typography, ...

2012-08-23 Thread Ian Kelly
On Thu, Aug 23, 2012 at 12:33 PM, wrote: >> >>> sys.getsizeof('a' * 80 * 50) >> >> > 4025 >> >> sys.getsizeof('a' * 80 * 50 + '•') >> >> > 8040 >> >> >> >> This example is still benefiting from shrinking the number of bytes >> >> in half over using 32 bits per character as was the case w

Re: Flexible string representation, unicode, typography, ...

2012-08-25 Thread Ian Kelly
On Sat, Aug 25, 2012 at 9:47 AM, wrote: > For those you do not know, the go language has introduced > the rune type. As far as I know, nobody is complaining, I > have not even seen a discussion related to this subject. Python has that also. We call it "int". More seriously, strings in Go are n

Re: Flexible string representation, unicode, typography, ...

2012-08-26 Thread Ian Kelly
On Sun, Aug 26, 2012 at 5:49 AM, Steven D'Aprano wrote: >> Sorry, you do not get it. >> >> The rune is an alias for int32. A sequence of runes is a sequence of >> int32's. > > It certainly is not. Runes are variable-width. Here, for example, are a > number of Go functions which return a single run

Re: Flexible string representation, unicode, typography, ...

2012-08-26 Thread Ian Kelly
On Sun, Aug 26, 2012 at 12:59 AM, wrote: > Sorry, you do not get it. > > The rune is an alias for int32. A sequence of runes is a > sequence of int32's. Go do not spend its time in using a > machinery to work with, to differentiate, to keep in memory > this sequence according to the *characers* c

Re: Flexible string representation, unicode, typography, ...

2012-08-26 Thread Ian Kelly
On Sun, Aug 26, 2012 at 2:13 PM, Steven D'Aprano wrote: > On Sun, 26 Aug 2012 09:40:13 -0600, Ian Kelly wrote: > >> I think the documentation for those functions is simply badly worded. >> The "width in bytes" it returns is not the width of the rune (which as &g

Re: set and dict iteration

2012-08-27 Thread Ian Kelly
On Thu, Aug 23, 2012 at 10:49 AM, Aaron Brady wrote: > The patch for the above is only 40-60 lines. However it introduces two new > concepts. Is there a link to the patch? > The first is a "linked list", a classic dynamic data structure, first > developed in 1955, cf. http://en.wikipedia.org/

Re: Flexible string representation, unicode, typography, ...

2012-08-27 Thread Ian Kelly
On Mon, Aug 27, 2012 at 1:16 PM, wrote: > - Why int32 and not uint32? No idea, I tried to find an > answer without asking. UCS-4 is technically only a 31-bit encoding. The sign bit is not used, so the choice of int32 vs. uint32 is inconsequential. (In fact, since they made the decision to limit

Re: Flexible string representation, unicode, typography, ...

2012-08-28 Thread Ian Kelly
On Tue, Aug 28, 2012 at 8:42 PM, rusi wrote: > In summary: > 1. The problem is not on jmf's computer > 2. It is not windows-only > 3. It is not directly related to latin-1 encodable or not > > The only question which is not yet clear is this: > Given a typical string operation that is complexity O

Re: Flexible string representation, unicode, typography, ...

2012-08-30 Thread Ian Kelly
On Thu, Aug 30, 2012 at 2:51 AM, wrote: > But as soon as you introduce artificially a "latin-1" > bottleneck, all this machinery just become useless. How is this a bottleneck? If you removed the Latin-1 encoding altogether and limited the flexible representation to just UCS-2 / UCS-4, I doubt v

Re: Flexible string representation, unicode, typography, ...

2012-08-31 Thread Ian Kelly
On Fri, Aug 31, 2012 at 6:32 AM, Steven D'Aprano wrote: > That's one thing that I'm unclear about -- under what circumstances will > a string be in compact versus non-compact form? I understand it to be entirely dependent on which API is used to construct. The legacy API generates legacy strings

Re: how to get character hex number?

2012-08-31 Thread Ian Kelly
On Fri, Aug 31, 2012 at 8:21 PM, contro opinion wrote: for i in "english" : > ... print(hex((ord(i > ... > 0x65 > 0x6e > 0x67 > 0x6c > 0x69 > 0x73 > 0x68 u"english".encode("utf-8") > 'english' u"english".encode("ascii") > 'english' > > how can i get 656e676c697368 in encode me

Re: PipeController v0.1 - experimental tool to simulate simple UNIX-style pipes in Python

2012-09-01 Thread Ian Kelly
Resending to the list... On Sep 1, 2012 12:19 PM, "Ian Kelly" wrote: > On Sep 1, 2012 9:37 AM, "Ramchandra Apte" wrote: > > Doesn't the pipes module already do this? > > No, that deals with actual Unix pipes. This appears to be about pipelined > pro

Re: Flexible string representation, unicode, typography, ...

2012-09-02 Thread Ian Kelly
On Sun, Sep 2, 2012 at 1:36 AM, wrote: > I still remember my thoughts when I read the PEP 393 > discussion: "this is not logical", "they do no understand > typography", "atomic character ???", ... That would indicate one of two possibilities. Either: 1) Everybody in the PEP 393 discussion exce

Re: running Lua in Python

2012-09-02 Thread Ian Kelly
On Sun, Sep 2, 2012 at 3:04 AM, Arnaud Delobelle wrote: > Hi all, > > I'm looking for a way to run Lua scripts in Python, and also send and > receive data between the two. Something like lunatic-python [1] would > be ideal. However, so far I haven't been able to build it on the > machines it's s

Re: Flexible string representation, unicode, typography, ...

2012-09-03 Thread Ian Kelly
On Sun, Sep 2, 2012 at 6:00 AM, Serhiy Storchaka wrote: > On 02.09.12 12:52, Peter Otten wrote: >> >> Ian Kelly wrote: >> >>> Rewriting the example to use locale.strcoll instead: >> >> >>>>>> sorted(li, key=functools.cmp_to_key(locale

Re: set and dict iteration

2012-09-03 Thread Ian Kelly
On Sun, Sep 2, 2012 at 11:43 AM, Aaron Brady wrote: > We could use a Python long object for the version index to prevent overflow. > Combined with P. Rubin's idea to count the number of open iterators, most use > cases still wouldn't exceed a single word comparison; we could reset the > counte

Re: Python Interview Questions

2012-09-05 Thread Ian Kelly
On Wed, Sep 5, 2012 at 8:34 AM, Chris Angelico wrote: > I wouldn't go that far. The 'name' parameter, I would expect, would be > a constant. The 'item' parameter, though, is probably not a constant, and it's interpolated just the same. > However, this strikes me as encouraging some really > inef

Re: Python Interview Questions

2012-09-05 Thread Ian Kelly
On Wed, Sep 5, 2012 at 9:34 AM, Chris Angelico wrote: > On Thu, Sep 6, 2012 at 1:22 AM, Ian Kelly wrote: >> The lack of an ORDER BY is the least of the problems with that SQL. >> He's also using LIMIT without OFFSET, so the only thing that the >> 'item' a

Re: is implemented with id ?

2012-09-05 Thread Ian Kelly
On Wed, Sep 5, 2012 at 8:13 AM, Steven D'Aprano wrote: > You *cannot* replace is with id() except when the objects are guaranteed > to both be alive at the same time, and even then you *shouldn't* replace > is with id() because that is a pessimation (the opposite of an > optimization -- something

Re: os.stat() distorts filenames that end with period (nt.stat())

2012-09-06 Thread Ian Kelly
On Thu, Sep 6, 2012 at 6:55 PM, ruck wrote: > (This with Python 2.7.2 on Windows 7) > > os.stat() won't recognize a filename ending in period. > It will ignore trailing periods. > If you ask it about file 'goo...' it will report on file 'goo' > And if 'goo' doesn't exist, os.stat will complain. D

Re: submit jobs on multi-core

2012-09-11 Thread Ian Kelly
On Mon, Sep 10, 2012 at 11:53 PM, Laszlo Nagy wrote: > On 2012-09-11 06:16, Dhananjay wrote: >> >> Dear all, >> >> I have a python script in which I have a list of files to input one by one >> and for each file I get a number as an output. >> I used for loop to submit the file to script. >> My scr

Re: Single leading dash in member variable names?

2012-09-11 Thread Ian Kelly
On Tue, Sep 11, 2012 at 12:45 PM, wrote: > All > > Python noob here. Trying to understand a particular syntax: > > class stuff: > def __init__(self): > self._bongo = "BongoWorld" > > --- > > What is the significance of the leading underscore in "self._bongo"? I've > seen t

Re: Single leading dash in member variable names?

2012-09-11 Thread Ian Kelly
On Tue, Sep 11, 2012 at 2:53 PM, wrote: > On Tuesday, September 11, 2012 2:06:45 PM UTC-5, Ian wrote: >> Single leading underscore is a convention indicating that the name >> should be considered private and not used externally. It's a softer >> version of the double leading underscore that mean

Re: generators as decorators simple issue

2012-09-12 Thread Ian Kelly
On Wed, Sep 12, 2012 at 4:22 AM, pyjoshsys wrote: > The output is still not what I want. Now runtime error free, however the > output is not what I desire. [SNIP] > class Trial(object): > '''class to demonstrate with''' > def __init__(self): > object.__init__(self) > sel

Re: Single leading dash in member variable names?

2012-09-12 Thread Ian Kelly
On Tue, Sep 11, 2012 at 11:10 PM, Dwight Hutto wrote: > Not to jump in with another question(this seems somewhat relevant to the > conversation, maybe not), but is this similar to a private,public, or > protected class similar to the C type langs? More like "this is an implementation detail and i

Re: Single leading dash in member variable names?

2012-09-12 Thread Ian Kelly
On Wed, Sep 12, 2012 at 9:23 AM, wrote: > > On Tuesday, September 11, 2012 5:02:31 PM UTC-5, Erik Max Francis wrote: > > On 09/11/2012 01:53 PM, me wrote: > > > PEP 8 says this is bad form. What do you think? > > > > > > > > Where does it say that? > > Apologies. It's in David Goodger's "Code Li

Re: datetime

2012-09-13 Thread Ian Kelly
On Thu, Sep 13, 2012 at 9:19 AM, Max wrote: > How do I set the time in Python? On what platform? I don't know of any libraries for this, so it would be a matter of making the necessary system calls (which is all that a library would do anyway). > Also, is there any *direct* way to shift it? On

Re: equiv of perl regexp grammar?

2012-09-13 Thread Ian Kelly
On Thu, Sep 13, 2012 at 5:30 AM, Neal Becker wrote: > I noticed this and thought it looked interesting: > > http://search.cpan.org/~dconway/Regexp- > Grammars-1.021/lib/Regexp/Grammars.pm#DESCRIPTION > > I'm wondering if python has something equivalent? The pyparsing module is a good option for b

Re: hi

2012-09-14 Thread Ian Kelly
On Fri, Sep 14, 2012 at 12:09 AM, alex23 wrote: > On Sep 14, 3:44 pm, Dwight Hutto wrote: >> CEO:http://www.hitwebdevelopment.com > > I don't know what gives more of a negative impression of your > business, your acting like a tedious douchebag or the website itself. Holy cow, that's the website

Re: Decorators not worth the effort

2012-09-14 Thread Ian Kelly
On Fri, Sep 14, 2012 at 2:29 PM, Terry Reedy wrote: > For a simple, unparameterized wrapper, the difficulty is entirely in the > wrapper maker. It must define the final wrapper as a nested function and > return it*. It is irrelevant whether the wrapper maker is used with pre-def > decorator syntax

Re: how to use property?

2012-09-17 Thread Ian Kelly
On Mon, Sep 17, 2012 at 6:26 PM, MRAB wrote: > On 2012-09-18 00:46, Dave Angel wrote: >> An important difference from every other language I've used: The user >> of the attribute does not need to change his code when you decide it >> needs reimplementation as a property. >> >> In C++ and java, fo

Re: 'indent'ing Python in windows bat

2012-09-17 Thread Ian Kelly
On Mon, Sep 17, 2012 at 7:08 PM, David Smith wrote: > How do I "indent" if I have something like: > if (sR=='Cope'): sys.exit(1) elif (sR=='Perform') sys.exit(2) else > sys.exit(3) How about: if sR == 'Cope': sys.exit(1) elif sR == 'Perform': sys.exit(2) else: sys.exit(3) I don't re

Re: sum works in sequences (Python 3)

2012-09-19 Thread Ian Kelly
On Wed, Sep 19, 2012 at 8:41 AM, Franck Ditter wrote: > Hello, > I wonder why sum does not work on the string sequence in Python 3 : > sum((8,5,9,3)) > 25 sum([5,8,3,9,2]) > 27 sum('rtarze') > TypeError: unsupported operand type(s) for +: 'int' and 'str' > > I naively thought that s

Re: A little morning puzzle

2012-09-19 Thread Ian Kelly
On Wed, Sep 19, 2012 at 6:13 AM, Antoon Pardon wrote: > On 19-09-12 13:17, Neal Becker wrote: >> I have a list of dictionaries. They all have the same keys. I want to find >> the >> set of keys where all the dictionaries have the same values. Suggestions? > common_items = reduce(opereator.__an

Re: sum works in sequences (Python 3)

2012-09-19 Thread Ian Kelly
On Wed, Sep 19, 2012 at 9:06 AM, Neil Cerutti wrote: > Are iterables and sequences different enough to warrant posting a > bug report? The glossary is specific about the definitions of both, so I would say yes. http://docs.python.org/dev/glossary.html#term-iterable http://docs.python.org/dev/glo

Re: sum works in sequences (Python 3)

2012-09-19 Thread Ian Kelly
On Wed, Sep 19, 2012 at 9:37 AM, Steve Howell wrote: > Sequences are iterables, so I'd say the docs are technically correct, > but maybe I'm misunderstanding what you would be trying to clarify. The doc string suggests that the argument to sum() must be a sequence, when in fact any iterable will

Re: How to get the list of all my open file(descriptor)s and locks?

2012-09-19 Thread Ian Kelly
On Wed, Sep 19, 2012 at 11:34 AM, Ismael Farfán wrote: > So the question: > * If I execve a python script (from C), how can I retrieve the list of > files, and optionally the list of locks, from within the execve(d) > python process so that I can use them? > > > Some more info: > I'm working with

Re: How to get the list of all my open file(descriptor)s and locks?

2012-09-19 Thread Ian Kelly
On Wed, Sep 19, 2012 at 2:36 PM, Ismael Farfán wrote: > It seems like I can use os.fstat to find out if a fd exists and also > get it's type and mode (I'm getting some pipes too : ) Sure, because files and pipes both use the file descriptor abstraction. If your process does any networking, you'l

Re: looping in array vs looping in a dic

2012-09-20 Thread Ian Kelly
On Thu, Sep 20, 2012 at 1:09 PM, MRAB wrote: > for col in range(cols): > for row in range(rows): > cat = valuesCategory[row, col] > ras = valuesRaster[row, col] > totals[cat] += ras Expanding on what MRAB wrote, since you probably have far fewer categories than pixels,

Re: looping in array vs looping in a dic

2012-09-20 Thread Ian Kelly
On Thu, Sep 20, 2012 at 1:28 PM, Ian Kelly wrote: > Expanding on what MRAB wrote, since you probably have far fewer > categories than pixels, you may be able to take better advantage of > numpy's vectorized operations (which are pretty much the whole point > of using numpy in th

Re: When should I use "development mode"?

2012-09-20 Thread Ian Kelly
On Thu, Sep 20, 2012 at 1:38 PM, py_lrnr wrote: > Can anyone (very briefly) explain to me, in a sentence or two: > > what 'development mode' is? > how 'development mode' differs from other 'modes'? > why/when I would use 'development mode'? > what 'development mode' does or does not allow me to do

Re: portable way of locating an executable (like which)

2012-09-20 Thread Ian Kelly
On Thu, Sep 20, 2012 at 4:21 PM, Chris Angelico wrote: > os.sep is the directory separator, but os.pathsep may be what you > want. Between that and os.getenv('path') you can at least get the > directories. Then on Windows, you also need to check out > os.getenv('pathext') and split _that_ on the s

Re: how to do draw pattern with python?

2012-09-21 Thread Ian Kelly
On Fri, Sep 21, 2012 at 10:50 AM, Ismael Farfán wrote: > 2012/9/21 Peter Otten <__pete...@web.de>: >> echo.hp...@gmail.com wrote: >> >> print "\x1b[2J\x1b[0;0H" # optional > > Nice code : ) > > Could you dissect that weird string for us? > > It isn't returning the cursor to (0,0), it's just li

Re: Exact integer-valued floats

2012-09-21 Thread Ian Kelly
On Fri, Sep 21, 2012 at 11:29 AM, Steven D'Aprano wrote: > The question is, what is the largest integer number N such that every > whole number between -N and N inclusive can be represented as a float? > > If my tests are correct, that value is 9007199254740992.0 = 2**53. > > Have I got this right

Re: Algorithms using Python?

2012-09-21 Thread Ian Kelly
On Fri, Sep 21, 2012 at 1:45 PM, Dennis Lee Bieber wrote: > You can probably implement them, but they're not going to be very > efficient. (And never "remove" an element from the linked-list > implementation because Python would shift all the other elements, hence > your "links" become inv

Re: Functional way to compare things inside a list

2012-09-21 Thread Ian Kelly
On Fri, Sep 21, 2012 at 1:54 PM, 8 Dihedral wrote: > I don't think functional aspects are only marked as lazy > programming. He wrote "lazy evaluation", not "lazy programming". Two entirely different things. > It just means when one is experimenting something > the efficient execution in sp

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