Re: Re: Is python a interpreted or compiled language?

2012-06-20 Thread Evan Driscoll
On 6/20/2012 19:53, Dave Angel wrote: > But since you mention java, I'd like > to point out a few things that are different between the two > environments. He and I are describing CPython; jython and other > implementations don't use .pyc files, and they behave differently. There's one more impo

Re: Þ how can I implement "cd" like shell in Python?

2012-06-28 Thread Evan Driscoll
On 6/28/2012 7:28, Alex chen wrote: > I just want to write a python program,it can be called in the linux > terminal like the command "cd" to change the directory of the shell terminal You "can't" do this; a program the shell runs cannot affect the shell's execution. What you have to do is have s

Re: Re: code review

2012-06-30 Thread Evan Driscoll
On 6/30/2012 19:37, Chris Angelico wrote: > On Sun, Jul 1, 2012 at 10:08 AM, Ben Finney > wrote: >> I know of no programming language that >> would give a newcomer to Python that expectation. So where is the norm >> you're referring to? > > C, SQL, REXX, and many other languages. Some others: L

Re: code review

2012-06-30 Thread Evan Driscoll
On 6/30/2012 23:45, Evan Driscoll wrote: > You may also > want to put Java in there as well, as < is effectively not commutative > in that language. (I didn't try C#.) I guess you could actually put Lua and Ruby into the roughly same category as Java too. But things get a

Re: Re: code review

2012-07-01 Thread Evan Driscoll
On 7/1/2012 4:54, Alister wrote: > On Sat, 30 Jun 2012 23:45:25 -0500, Evan Driscoll wrote: >> If I had seen that in a program, I'd have assumed it was a bug. > > You would? > I have only been using python for 6 - 12 months but in my past I > programmed microcontrollers

Re: 2 + 2 = 5

2012-07-04 Thread Evan Driscoll
On 7/4/2012 14:37, Paul Rubin wrote: > I just came across this (https://gist.github.com/1208215): > > import sys > import ctypes > pyint_p = ctypes.POINTER(ctypes.c_byte*sys.getsizeof(5)) > five = ctypes.cast(id(5), pyint_p) > print(2 + 2 == 5) # False > five.contents[five.

Re: Re: 2 + 2 = 5

2012-07-05 Thread Evan Driscoll
On 01/-10/-28163 01:59 PM, Alexander Blinne wrote: 5+0 is actually 4+0, because 5 == 4, so 5+0 gives 4. 5+1 is actually 4+1, which is 5, but 5 is again 4. 5+2 is 4+2 which is 6. Now all I can think is "Hoory for new math, new-hoo-hoo math" :-) Evan -- http://mail.python.org/mailman/listinfo/py

Re: Re: Gender, Representativeness and Reputation in StackOverflow

2012-07-23 Thread Evan Driscoll
On 01/-10/-28163 01:59 PM, Terry Reedy wrote: This is a deceptive and time-wasting link Leaving aside the point that this is not directly related to Python, my opinion is that if the authors will not make past and future papers freely available, not even an abstract, they should not ask for

Re: Re: Objects in Python

2012-08-22 Thread Evan Driscoll
On 08/22/2012 12:46 PM, lipska the kat wrote: > If you can show me a 'type' that cannot be assigned to > > a > > in the same scope then I would be most interested to know, I haven't > found one yet. As other people have said, you've just pointed out the difference between static typing and dynam

Re: Re: Objects in Python

2012-08-22 Thread Evan Driscoll
On 08/22/2012 02:45 PM, lipska the kat wrote: > On 22/08/12 20:03, Evan Driscoll wrote: >> Second, this concept isn't *so* unfamiliar to you. If I give you the >> following Java code: >> >>void foo(Object o) { ... } >> > looking at this method decla

Re: Re: Objects in Python

2012-08-22 Thread Evan Driscoll
On 8/22/2012 18:58, Ben Finney wrote: > You haven't discovered anything about types; what you have discovered is > that Python name bindings are not variables. > > In fact, Python doesn't have variables – not as C or Java programmers > would understand the term. What it has instead are references

Re: Re: Objects in Python

2012-08-23 Thread Evan Driscoll
On 08/23/2012 04:19 AM, lipska the kat wrote: > Well we don't want to turn this into a language comparison thread do we, > that might upset too many people but I can't remember ever writing a > method that took an Object as argument, you just can't do that much with > an Object. In the pre-Java-1.

Re: Objects in Python

2012-08-23 Thread Evan Driscoll
[I have some things to say to a few people so I'm just putting it all in one rather than clutter up your email box even more.] On 08/23/2012 12:33 AM, Chris Angelico wrote: > [Snip discussion on names vs variables] > > Does that sort things out, or just make things more confusing? > > ChrisA I...

Variables vs names [was: Objects in Python]

2012-08-23 Thread Evan Driscoll
On 08/23/2012 12:56 PM, Steven D'Aprano wrote: > On Thu, 23 Aug 2012 12:17:03 -0500, Evan Driscoll wrote: > >> I definitely *wouldn't* say "Python >> classes aren't really classes" -- even though (I assert) Python classes >> are *far* further

Re: Re: Objects in Python

2012-08-24 Thread Evan Driscoll
On 8/23/2012 22:17, alex23 wrote: > But Roy's point was that referring to 'a' as a 'variable' makes no > sense, as it's not an allocated piece of memory. Does the computer just remember what 'a' refers to by keeping notes about it in Narnia? Put it this way. If C removed the & operator -- and thu

Re: Re: Objects in Python

2012-08-25 Thread Evan Driscoll
On 08/24/2012 10:04 PM, Steven D'Aprano wrote: The fact that the end result is the same is hardly surprising -- Python's VM is built on top of C pointer indirection, so of course you can start with pointers and end up with Python semantics. But the practice of coding are very different: * in C,

Re: Re: Objects in Python

2012-08-25 Thread Evan Driscoll
On 08/24/2012 05:00 AM, Steven D'Aprano wrote: No. The compiler remembers the address of 'a' by keeping notes about it somewhere in memory during the compilation process. When you run the compiled program, there is no longer any reference to the name 'a'. ... The mapping of name:address is part

Re: Re: Algorithms using Python?

2012-09-21 Thread Evan Driscoll
On 09/21/2012 02:45 PM, Dennis Lee Bieber wrote: > On Fri, 21 Sep 2012 14:26:04 +0530, Mayuresh Kathe > declaimed the following in gmane.comp.python.general: > >> Is there a good book on foundational as well as advanced algorithms >> using Python? >> > Depends on what you mean by "foundati

Re: Re: + in regular expression

2012-10-04 Thread Evan Driscoll
On 10/04/2012 04:59 PM, Mark Lawrence wrote: why the "\s{6}+" is not a regular pattern? Why are you too lazy to do any research before posting a question? Errr... what? I'm only somewhat familiar with the extra stuff that languages provide in their regexs beyond true regular expressio

Re: Re: + in regular expression

2012-10-05 Thread Evan Driscoll
On 10/05/2012 04:23 AM, Duncan Booth wrote: A regular expression element may be followed by a quantifier. Quantifiers are '*', '+', '?', '{n}', '{n,m}' (and lazy quantifiers '*?', '+?', '{n,m}?'). There's nothing in the regex language which says you can follow an element with two quantifiers. In

Re: + in regular expression

2012-10-05 Thread Evan Driscoll
On 10/05/2012 10:27 AM, Evan Driscoll wrote: On 10/05/2012 04:23 AM, Duncan Booth wrote: A regular expression element may be followed by a quantifier. Quantifiers are '*', '+', '?', '{n}', '{n,m}' (and lazy quantifiers '*?', '+?&

Re: Re: Providing a Python wrapper to a C++ type.

2012-10-16 Thread Evan Driscoll
[Stefan gave part of an answer here, but I've got an addition too.] On 10/16/2012 6:46 AM, Marco Nawijn wrote: > I never worked with Cython (but I know it is very powerful and interesting) > but in my mind there are slight differences in usage scenario between e.g. > Boost Python and Cython. For

Re: A desperate lunge for on-topic-ness

2012-10-18 Thread Evan Driscoll
Ooo, a good religious war. How could I resist? :-) Bear in mind that what I say is relative to layout issues, which in the grand scheme of things. So even if I say I really disklike something, it's still not so bad in practice. Except for backslash continuations. :-) On 10/18/2012 01:06 AM, Zero

Re: The pty module, reading from a pty, and Python 2/3

2012-10-23 Thread Evan Driscoll
Oh, and a little more information: The log.txt file I create has the message that it's "about to execlp", and the exec() *does* actually happen -- the IOError is raised after the child process quits. Evan On 10/23/2012 09:59 PM, Evan Driscoll wrote: I have the fo

The pty module, reading from a pty, and Python 2/3

2012-10-23 Thread Evan Driscoll
I have the following program. Everything is sunshine and rainbows when I run in in Python 2, but when I run it under Python 3 I get an IOError. 2to3 only reports one dumb suggestion re. a print call (which I can get rid of by importing __future__'s print_function, and then it just suggests remo

Re: The pty module, reading from a pty, and Python 2/3

2012-10-23 Thread Evan Driscoll
rious if anyone know why it worked in 2 though. Evan On 10/23/2012 10:03 PM, Evan Driscoll wrote: Oh, and a little more information: The log.txt file I create has the message that it's "about to execlp", and the exec() *does* actually happen -- the IOError is raised after the c

Re: Re: while expression feature proposal

2012-10-24 Thread Evan Driscoll
On 10/24/2012 05:26 PM, Cameron Simpson wrote: > But I'm still -0 on it, because it supplants the glaringly obvious: > > m = ... > > assignment with the far less in your face: > > possibly-long-expr as m > > and I think it would get quite heavily used, to the detriment of > assignment reada

Re: Re: Simple Python question for some

2012-10-28 Thread Evan Driscoll
On 10/28/2012 7:18 PM, Chris Rebert wrote: > This is fixed in Python 3, where such nonsensical comparisons will > instead raise TypeError. It's worth pointing out that at least one kind of inequality comparison which some people (e.g. me) would consider nonsensical is still allowed in Python 3, wh

Re: Re: Immutability and Python

2012-10-29 Thread Evan Driscoll
On 10/29/2012 12:05 PM, andrea crotti wrote: > I meant how do I create new immutables classes myself, I guess that's > possible writing C extensions but I don't see in pure Python.. The short answer is: you don't, not really, except by using NamedTuple if that gives you what you want. The longer

Managing multiple packages

2012-11-20 Thread Evan Driscoll
I have perhaps a bit of a silly question, but I'm interested in what people do for workflow when actively developing multiple Python modules at once (for a single project). Suppose I have packages A-C. In addition to being modules in the Python sense, they are logically distinct, probably sit in d

Re: Re: 10 sec poll - please reply!

2012-11-20 Thread Evan Driscoll
On 11/20/2012 05:46 PM, Alan Meyer wrote: On 11/20/2012 11:29 AM, mherrmann...@gmail.com wrote: > ... generate_keystrokes? ... Not bad. "gen_keystrokes", or even "keystrokes" might also do. I would emphatically vote "no" for "keystrokes". That's a noun, not a verb. What does it do? Tell you

Re: Re: How to get a "screen" length of a multibyte string?

2012-11-25 Thread Evan Driscoll
On 11/25/2012 07:48 AM, kobayashi wrote: Encoding is utf-8. I use "screen length" means as that; that of ascii character is 1, and that of character having double width than ascii character is 2. It's not bytes, but drawing width. As you say, it depends font. I'll be considering carefully. Do

Re: Re: Managing multiple packages

2012-11-26 Thread Evan Driscoll
On 11/22/2012 06:22 PM, Thomas Bach wrote: I am using virtual environments and do a python setup.py develop on each package. This just creates a symbolic link to the package and all edits show up immediately. That's awesome; I didn't know about the 'develop' command. Thanks! Is that just a s

Re: Re: re.search when used within an if/else fails

2012-11-28 Thread Evan Driscoll
On 11/28/2012 01:57 PM, Ian Kelly wrote: > Yes, it's best to use either tabs-only or spaces-only. Quoting from PEP > 8 on the subject: > > Never mix tabs and spaces. > > The most popular way of indenting Python is with spaces only. The > second-most popular way is with tabs only. Cod

Re: Re: Iterating over files of a huge directory

2012-12-17 Thread Evan Driscoll
On 12/17/2012 09:52 AM, Oscar Benjamin wrote: > In the last couple of months there has been a lot of discussion (on > python-list or python-dev - not sure) about creating a library to more > efficiently iterate over the files in a directory. The result so far > is this library on github: > https://

Re: Iterating over files of a huge directory

2012-12-17 Thread Evan Driscoll
On 12/17/2012 01:50 PM, Oscar Benjamin wrote: > On 17 December 2012 18:40, Evan Driscoll wrote: >> On 12/17/2012 09:52 AM, Oscar Benjamin wrote: >>> https://github.com/benhoyt/betterwalk >> >> This is very useful to know about; thanks. >> >> I actually

Re: Re: Python lists

2012-12-30 Thread Evan Driscoll
On 12/30/2012 4:19 PM, Hans Mulder wrote: > If it's okay to modify the original list, you can simply do: > > l[0] = split(l[0], ", ") > > If modifying the original is not okay, the simple solution would > be to copy it first: > > l2 = l > l2[0] = split(l2[0], ", ") Um, that doesn't copy the lis

Re: wiki.python.org

2013-01-09 Thread Evan Driscoll
On 01/09/2013 10:05 AM, Reed, Kevin wrote: > I have been unable to access wiki.python.org for two days. Is there a > problem with the server, or is it me? I can't speak to why, but it appears down for me as well. I also checked http://www.downforeveryoneorjustme.com/ (which is just about the best

Re: Beginner Tutorials

2013-01-18 Thread Evan Driscoll
On 1/18/2013 7:25 PM, Rick Johnson wrote: > Well anyone who is just blindly copying code to get through a CS > course is obviously not a "natural" problem solver ,and thus, > /incapable/ of becoming a proficient programmer anyhow. Programming > *IS* problem solving. If you don't get any thrill from

Re: Arent these snippets equivalent?

2013-01-23 Thread Evan Driscoll
On 01/23/2013 03:56 PM, Coolgg wrote: > Is this: > > while True: > data = fp.read(4096) > if not data: > break > ... > > not equivalent to this: > > data = fp.read (4096) > while data: > ...{handle the chunk here} > data = fp.read (4096) > > Heres the article that sp

Re: while True or while 1

2012-01-23 Thread Evan Driscoll
On 01/23/2012 11:39 AM, Ian Kelly wrote: "We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil" -- Donald Knuth To play devil's advocate for a moment, if you have the choice between two ways of writing something, A and B, where bo

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

2012-01-23 Thread Evan Driscoll
On 1/23/2012 23:57, Rick Johnson wrote: > Of > course, "used to" and "supposed to" will require people to rethink > there lazy and slothful ways. I'll go repent in the corner, over their. signature.asc Description: OpenPGP digital signature -- http://mail.python.org/mailman/listinfo/python-list

Re: Where to put data

2012-01-25 Thread Evan Driscoll
I would just like to make a strong plea that you make it possible to install in places other than /usr. Bascially, 'python setup.py install --prefix /some/alternative/place' should work. Evan On 01/25/2012 11:26 AM, bvdp wrote: I'm having a disagreement with a buddy on the packaging of a pro

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

2012-01-25 Thread Evan Driscoll
On 1/25/2012 20:24, Devin Jeanpierre wrote: > If all you're going to change is the parser, maybe it'd be easier to > get things to coexist if parsers were pluggable in the re module. > > It's more generally useful, too. Would let re gain a PyParsing/SNOBOL > like expression "syntax", for example. O

Re: copy on write

2012-02-02 Thread Evan Driscoll
On 01/-10/-28163 01:59 PM, 8 Dihedral wrote: If you're working in C++ and overload your operators so that 'a +=' and 'a = + b' have different observable behaviors (besides perhaps time), then either your implementation is buggy or your design is very bad-mannered. Evan Do you mean the resu

frozendict

2012-02-08 Thread Evan Driscoll
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 that I'm probably missing which is why it's not already provided

Re: Re: frozendict

2012-02-08 Thread Evan Driscoll
On 13:59, Nathan Rice wrote: >> Turn the question around: why should there be? >> Python is intentionally parsimonious in adding builtins. > > For the same reason there are frozensets? > > I put dicts in sets all the time. I just tuple the items, but that > means you have to re-dict it on the wa

Re: Re: frozendict

2012-02-08 Thread Evan Driscoll
On 13:59, Ian Kelly wrote: > > Define "doesn't suck". If I were to hack one up, it would look > something like this: > > > from collections import Mapping, Hashable So part of my objection was that I wanted to make sure I got all of the expected functionality, and that takes a bunch of functions.

Re: Re: lang comparison: in-place algorithm for reversing a list in Perl, Python, Lisp

2012-02-29 Thread Evan Driscoll
On 2/29/2012 23:05, Dan Stromberg wrote: > > On Wed, Feb 29, 2012 at 8:07 PM, Xah Lee > wrote: > > This page tells you what's “In-place algorithm”, using {python, perl, > emacs lisp} code to illustrate. > > Aren't in-place reversals rather non-functional? There

Re: RE: What's the best way to write this regular expression?

2012-03-07 Thread Evan Driscoll
On 01/-10/-28163 01:59 PM, Prasad, Ramit wrote: gz stands for gzip and is a form of compression (like rar/zip ). tar stands for a tape archive. It is basically a box that holds the files. So you need to "unzip" and then "open the box". Normally programs like WinZip / WinRar / 7-zip will do both

Re: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct

2012-03-17 Thread Evan Driscoll
On 3/17/2012 9:03, Antti J Ylikoski wrote: > > In his legendary book series The Art of Computer Programming, > Professor Donald E. Knuth presents many of his algorithms in the form > that they have been divided in several individual phases, with > instructions to GOTO to another phase interspersed

Re: Re: Python is readable

2012-03-21 Thread Evan Driscoll
On 01/-10/-28163 01:59 PM, Steve Howell wrote: Code shouldn't necessarily follow the example of English prose, but it seems that English has had some influence: 1 push(stack, item) # Push on the stack the item 2 push(item, stack) # Push the item on the stack 3 stack.push(item) # On the

Re: RE: Advise of programming one of my first programs

2012-03-27 Thread Evan Driscoll
On 01/-10/-28163 01:59 PM, Prasad, Ramit wrote: ### CODE # fileread = open('myfile.txt','r') tbook = eval(fileread.read()) fileread.close() The use of eval is dangerous if you are not *completely* sure what is being passed in. Try using pickle instead: http://docs.python.org/release

Re: Re: "convert" string to bytes without changing data (encoding)

2012-03-28 Thread Evan Driscoll
On 01/-10/-28163 01:59 PM, Ross Ridge wrote: Steven D'Aprano wrote: The right way to convert bytes to strings, and vice versa, is via encoding and decoding operations. If you want to dictate to the original poster the correct way to do things then you don't need to do anything more that. You

Re: Re: Re: "convert" string to bytes without changing data (encoding)

2012-03-28 Thread Evan Driscoll
On 3/28/2012 14:43, Ross Ridge wrote: > Evan Driscoll wrote: >> So yes, you can say that pretending there's not a mapping of strings to >> internal representation is silly, because there is. However, there's >> nothing you can say about that mapping. > >

Re: Re: Re: Re: "convert" string to bytes without changing data (encoding)

2012-03-29 Thread Evan Driscoll
On 01/-10/-28163 01:59 PM, Ross Ridge wrote: Evan Driscoll wrote: People like you -- who write to assumptions which are not even remotely guaranteed by the spec -- are part of the reason software sucks. ... This email is a bit harsher than it deserves -- but I feel not by much. I don'

Re: Re: string interpolation for python

2012-04-02 Thread Evan Driscoll
On 01/-10/-28163 01:59 PM, Yingjie Lan wrote: Because of the d"..." format, it won't affect old ways of doing things one bit. Allowing dynamic string wouldn't hurt a bit to anything that is already there. Why don't you just write a function that does it? I think someone already suggested this.

Re: Re: No os.copy()? Why not?

2012-04-03 Thread Evan Driscoll
On 01/-10/-28163 01:59 PM, Tycho Andersen wrote: Note, though, that this reads the whole file into memory. As many others have said, shutil is the most idiomatic option. * most idiomatic * clearest in terms of showing intent * potentially fastest * hardest to screw up (unlike concatenating file

Re: Re: Python Gotcha's?

2012-04-05 Thread Evan Driscoll
On 4/5/2012 13:24, Chris Angelico wrote: > I think this example highlights a major point about gotchas: the > difference between an obvious language feature and a gotcha depends on > where you come from. To a PHP programmer, 1 and "1" are in many ways > indistinguishable. To a C programmer, they're

Re: Re: Re: Python Gotcha's?

2012-04-05 Thread Evan Driscoll
On 4/5/2012 13:44, Michael Hrivnak wrote: > This is not a gotcha, and it's not surprising. As John described, > you're assigning a new value to an index of a tuple, which tuples > don't support. Um, at least for me personally, yes, it is surprising, and yes, it is a gotcha. This goes back to wh

Re: Python Gotcha's?

2012-04-05 Thread Evan Driscoll
On 4/5/2012 17:11, Evan Driscoll wrote: > In particular, the translation of 'a+=b' to 'temp = a + b; a = temp' is > *not* a very natural one to me. To expand on this point slightly, because of common C++ idioms guided by efficiency, I would be much more likely to thi

Python one-liner?

2012-04-13 Thread Evan Driscoll
I have a function 'f' and a list 'l'. I want a dictionary where the keys are evaluations of 'f(thing from l)' and the values are lists of stuff from 'l' that matches. So for instance, if 'f = lambda x: x%3' and 'l=range(9)', then I want { 0: [0,3,6], 1:[1,4,7], 2:[2,5,8]}. I can do that with an ex

Re: Python one-liner?

2012-04-13 Thread Evan Driscoll
On 4/13/2012 22:33, Evan Driscoll wrote: > d = {} > def appender(e): > d.get(f(e), []).append(e) > map(appender, l) Just in case it isn't clear, the above has at least two problems and won't even come close to working. :-) Though I might as well ask an

Re: Python one-liner?

2012-04-13 Thread Evan Driscoll
On 4/13/2012 22:42, Evan Driscoll wrote: > Though I might as well ask another question... if I have a dict with > values which are lists, what's a good way to say "append x to the list > at key k, creating a list if it's not there"? dict.setdefault seems > potent

Re: Re: How do you refer to an iterator in docs?

2012-04-20 Thread Evan Driscoll
On 4/20/2012 22:01, Roy Smith wrote: > A basket of apples is a basket which contains apples, in the same way a > list contains foos. But an iterator doesn't contain anything. You > wouldn't say, "a spigot of water", because the spigot isn't a container > holding the water. It is simply a mech

Re: Re: why () is () and [] is [] work in other way?

2012-04-26 Thread Evan Driscoll
This thread has already beaten a dead horse enough that the horse came back as a zombie and was re-killed, but I couldn't help but respond to this part: On 01/-10/-28163 01:59 PM, Adam Skutt wrote: Code that relies on the identity of a temporary object is generally incorrect. This is why C++

Re: using identifiers before they are defined

2012-06-12 Thread Evan Driscoll
On 01/-10/-28163 01:59 PM, Julio Sergio wrote: I know that changing the order of the definitions will work, however there are situations in which referring to an identifier before it is defined is necessary, e.g., in crossed recursion. Mutual recursion isn't a problem: the following strange exp

Parsing stream of JSON objects incrementally

2011-12-17 Thread Evan Driscoll
I'm interested in writing two programs, A and B, which communicate using JSON. At a high level, A wants to transfer an array to B. However, I would very much like to make it possible for A and B to run in parallel, so my current plan is to have A output and B read a *sequence* of JSON objects. In

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-17 Thread Evan Driscoll
On 12/17/2011 20:45, Chris Angelico wrote: > I'd go stronger than "usually" there. If "1"+1 results in "11", then > that's not weak typing but rather a convenient syntax for > stringification - if every object can (or must) provide a to-string > method, and concatenating anything to a string causes

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-17 Thread Evan Driscoll
On 12/17/2011 21:03, Evan Driscoll wrote: > Personally I'd put Python even weaker on account of things such as > '[1,2]*2' and '1 < True' being allowed, but on the other hand it > doesn't allow "1"+1. Not to mention duck typing, which under m

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-17 Thread Evan Driscoll
On 12/17/2011 21:42, Chris Angelico wrote: > Welcome to the list! If you're curious as to what's happened, check > the archives: > http://mail.python.org/pipermail/python-list/ Thanks! Incidentally, is there a good way to respond to the original post in this thread, considering it wasn't delivered

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-17 Thread Evan Driscoll
On 12/17/2011 22:52, buck wrote: > Try these on for size. > > head, @tuple tail = sequence > def foo(@list args, @dict kwargs): pass > foo(@args, @kwargs) > > For backward compatibility, we could say that the unary * is identical to > @list and unary ** is identical to @dict. > I

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-17 Thread Evan Driscoll
On 12/17/2011 23:33, Evan Driscoll wrote: > I do have one more thing to point out, which is that currently the > Python vararg syntax is very difficult to Google for. In the first pages > of the four searches matching "python (function)? (star | asterisk)", > there was ju

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-18 Thread Evan Driscoll
On 12/18/2011 2:36, Steven D'Aprano wrote: > The barrier to new keywords in Python is very high. Not going to > happen for something that already has perfectly good syntax already > familiar to Python and Ruby programmers. Might else well try to get C > and Java to stop using "..." (ellipses). I ag

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-18 Thread Evan Driscoll
On 12/18/2011 1:31, Steven D'Aprano wrote: > And rebutted. Modesty[1] prevents me from quoting myself, but here are > some links to searches: > > http://duckduckgo.com/?q=python+asterisk > http://duckduckgo.com/?q=python+* OK, so if you search using the right search engine, you *might* get a link

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-18 Thread Evan Driscoll
On 12/18/2011 8:35, Eelco wrote: > No, its not type *checking*, its type *declaration*. I tried to go to > great lengths to point that out, but it appears I did not do a very > good job :). Type declaration is exactly what I want, and insofar this > syntax has already found adoptation elsewhere, il

Re: .format vs. %

2011-12-31 Thread Evan Driscoll
How 'bout just: >>> s = "{0} {1} {2} {3}" >>> s.format(1, 2, 3, 4) '1 2 3 4' Evan On 12/31/2011 13:44, davidfx wrote: > Thanks for your response. I know the following code is not going to be > correct but I want to show you what I was thinking. > > formatter = "%r %r %r %r" > > print formatte

Re: Python education survey

2012-01-02 Thread Evan Driscoll
On 1/3/2012 0:27, Rick Johnson wrote: > Yes, i used the word "work" improperly here. Just another example of > the corrupting influence of garage verbiage. Thanks for bring this to > my attention! "Diction" would be a far better word than "verbiage" there. Evan signature.asc Description: Open

Re: python philosophical question - strong vs duck typing

2012-01-03 Thread Evan Driscoll
On 1/3/2012 13:13, Sean Wolfe wrote: > What I am driving at is, if we are coding in python but looking for > more performance, what if we had an option to 1) restrict ourselves > somewhat by using strong typing to 2) make it easy to compile or > convert down to C++ and thereby gain more performance

Re: python philosophical question - strong vs duck typing

2012-01-04 Thread Evan Driscoll
On 1/4/2012 12:37 AM, Terry Reedy wrote: > > Using induction, I can prove, for instance, that these two functions > [snip] > are equivalent, assuming enough stack and normal procedural Python > semantics. (And assuming no typos ;-). YOU proved that; your type system didn't. With a powerful enough

Re: help me get excited about python 3

2012-01-04 Thread Evan Driscoll
On 1/4/2012 9:56 AM, Sean Wolfe wrote: > I am still living in the 2.x world because all the things I want to do > right now in python are in 2 (django, pygame). But I want to be > excited about the future of the language. I understand the concept of > needing to break backwards compatibility. But i

Introspecting optparse/argparse objects

2012-01-10 Thread Evan Driscoll
I'd like to be able to be able to define options and then look at the lists. (For a concrete idea of a use case, suppose that it did not directly support the --help option and I wanted to write code that took its place.) Unfortunately, there doesn't seem to be any public API for doing this. Even i

Ctypes compatibility

2012-01-10 Thread Evan Driscoll
Might as well ask another question of the list. I've written a ctypes-based Python wrapper around the 'readdir' function. (I want access to the dt_type field of the result, without calling stat().) However, it feels very... fragile. What happens on a different *nix which uses a different size of

Re: Introspecting optparse/argparse objects

2012-01-11 Thread Evan Driscoll
On 1/11/2012 19:37, alex23 wrote: > On Jan 11, 11:26 am, Evan Driscoll wrote: >> (For a concrete idea of a use case, suppose that it did not >> directly support the --help option and I wanted to write code that took >> its place.) > That's a pretty weird definitio

Re: Ctypes compatibility

2012-01-11 Thread Evan Driscoll
On 1/10/2012 22:42, Alec Taylor wrote: > Use size_t > > http://en.wikipedia.org/wiki/C_data_types#Size_and_pointer_difference_types Um, perhaps you misunderstand. I don't control the C API, I'm calling a function that just exists in libc (unless I do what I said and write a wrapper). If you're sayi

Re: copy on write

2012-01-13 Thread Evan Driscoll
On 01/13/2012 10:54 AM, Neil Cerutti wrote: If you've ever implemented operator=, operator+, and operator+= in C++ you'll know how and why they are different. At the same time, you'd also know that that implementing them in such a way that 'a += b' does *not* perform the same action as 'a = a

Re: copy on write

2012-01-13 Thread Evan Driscoll
On 01/13/2012 03:20 PM, Neil Cerutti wrote: They perform the same action, but their semantics are different. operator+ will always return a new object, thanks to its signature, and operator+= shall never do so. That's the main difference I was getting at. I was talking about the combination of

Re: PyWarts: time, datetime, and calendar modules

2012-01-14 Thread Evan Driscoll
On 01/14/2012 02:11 PM, Devin Jeanpierre wrote: On Sat, Jan 14, 2012 at 2:23 PM, Rick Johnson wrote: THAT PISSES ME OFF!!!>:( We should never be forced to guess if a name is a callable or a variable! So how do we solve this dilemma you ask??? Well, we need to "mark" method OR variable names (

Extension module question

2012-01-14 Thread Evan Driscoll
As I hinted at in an earlier email, I'm working on a module which will allow calling readdir() (and FindFirstFile on Windows, hopefully pretty uniformly) from Python. The responses I got convinced me that it was a good idea to write a C-to-Python bridge as an extension module. What I'm not sure ab

Context manager to temporarily change the variable of a register [aka write swap(a,b)]

2009-08-25 Thread Evan Driscoll
ething up by passing in the variable that i want to change as a *string* and looking up that string in a dictionary somewhere, but I think what I need is the locals () dictionary of the calling function, and I'm not sure how to get that. Thanks, Evan Driscoll -- http://mail.python.org/mailman/listinfo/python-list

Re: Context manager to temporarily change the variable of a register [aka write swap(a,b)]

2009-08-25 Thread Evan Driscoll
On Aug 25, 2:33 pm, Evan Driscoll wrote: > I want to make a context manager that will temporarily change the > value of a variable within the scope of a 'with' that uses it. This is > inspired by a C++ RAII object I've used in a few projects. Ideally, > what I want is s

Re: Context manager to temporarily change the variable of a register [aka write swap(a,b)]

2009-08-25 Thread Evan Driscoll
On Aug 25, 3:07 pm, Evan Driscoll wrote: > Okay, so I think I actually got this with some consultation with a > friend. Critiques? This is wrong; it's not quite working right. It does with the example I posted, but not in a more thorough test. I'm still ignoring the "you c

Re: Context manager to temporarily change the variable of a register [aka write swap(a,b)]

2009-08-25 Thread Evan Driscoll
On Aug 25, 3:25 pm, "Diez B. Roggisch" wrote: > Modifying locals isn't really allowed - it might stop working with > certain implementations of python. > > And to be honest - I don't really see a use-case for your whole > approache. Why don't you want to introduce a new name? Wow, this actually w

Re: Context manager to temporarily change the variable of a register [aka write swap(a,b)]

2009-08-25 Thread Evan Driscoll
On Aug 25, 3:47 pm, Evan Driscoll wrote: > So here is my simplified version that only works for globals: So I think this works if (1) you only use changed_value in the same module as it's defined in (otherwise it picks up the globals from the module it's defined in, which is almost

Re: Context manager to temporarily change the variable of a register [aka write swap(a,b)]

2009-08-26 Thread Evan Driscoll
On Aug 26, 10:15 am, Carl Banks wrote: > Well, it wouldn't be a "can I rebind a variable using a with- > statement" thread if someone didn't post a solution that they thought > worked, but didn't test it on local variables. I'm not going to deny it was pretty stupid... though in my defense, I'm n