Re: Does turtle graphics have the wrong associations?

2009-11-12 Thread Alf P. Steinbach

* Raymond Hettinger:

On Nov 11, 10:21 pm, "Alf P. Steinbach"  wrote:

One reaction to http://preview.tinyurl.com/ProgrammingBookP3> has
been that turtle graphics may be off-putting to some readers because it is
associated with children's learning.

What do you think?


How about calling it Raptor Graphics that will please everyone ;-)


He he. :-)



import turtle as raptor
raptor.shape( "triangle" )

def draw_poison_bush( level, angle, stem_length ):
start_pos = raptor.pos()
raptor.left( angle )
raptor.forward( stem_length )
if level > 0:
draw_poison_bush( level-1, 30, 0.7*stem_length )
draw_poison_bush( level-1, 0, 0.85*stem_length )
draw_poison_bush( level-1, -37, 0.65*stem_length )
raptor.right( angle )
raptor.goto( start_pos )

raptor.title( "A DANGEROUS poison bush!" )

raptor.left( 90 )
raptor.back( 180 )
draw_poison_bush( 6, 0, 80 )

raptor.mainloop()



Cheers,

- Alf
--
http://mail.python.org/mailman/listinfo/python-list


Re: python simply not scaleable enough for google?

2009-11-12 Thread Vincent Manis
On 2009-11-12, at 23:19, Steven D'Aprano wrote:
> On Thu, 12 Nov 2009 22:20:11 -0800, Vincent Manis wrote:
> 
> Vincent, could you please fix your mail client, or news client, so 
> that it follows the standard for mail and news (that is, it has a 
> hard-break after 68 or 72 characters?
My apologies. Will do. 

> Having to scroll horizontally to read your posts is a real pain.
At least you're reading them. :)

-- v-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python simply not scaleable enough for google?

2009-11-12 Thread Steven D'Aprano
On Thu, 12 Nov 2009 22:20:11 -0800, Vincent Manis wrote:

> When I was approximately 5, everybody knew that higher level languages were 
> too slow for high-speed numeric computation (I actually didn't know that 
> then, I was too busy watching Bill and Ben the Flowerpot Men), and therefore 
> assembly languages were mandatory. Then IBM developed Fortran, and 
> higher-level languages were not too slow for numeric computation.

Vincent, could you please fix your mail client, or news client, so 
that it follows the standard for mail and news (that is, it has a 
hard-break after 68 or 72 characters?

Having to scroll horizontally to read your posts is a real pain.


-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does turtle graphics have the wrong associations?

2009-11-12 Thread Vincent Manis
On 2009-11-12, at 19:13, Peter Nilsson wrote:
> My recollection is that many children struggled with Turtle
> graphics because they had very little concept of trigonometry.
> [Why would they? Many wouldn't learn for another 2-10 years.]
> Adults tend to have even less concept since they almost never
> use trig (or much else from school ;-) in the real world.
> 
This paragraph is based upon a complete misunderstanding of turtle geometry. 
You do NOT use trigonometry to teach it, because the goal isn't to replicate 
cartesian geometry. The whole point about turtle geometry is that the student 
viscerally imagines him/herself BEING the turtle, and moving around the room 
according to the succession of FORWARD and TURNRIGHT commands. This is easier 
to visualize when one has an actual robot that draws pictures on butcher paper, 
as the second iteration of the MIT/BBN turtle work did (and they worked in 
middle schools, Grades 4-8, so there was no issue of trigonometry). 

> They can see the patterns and understand there's a logic to
> it, but they struggle replicating it. Get an angle wrong
> and you end up with a mess where it's not clear whether it's
> your algorithm or the maths that's at fault.
Kindly explain to me the difference between `algorithm' and `maths' here. I 
believe you just said that if there's a bug in the design, the program won't 
work. Hmmm.

This reminds me of a well-known anecdote about the original LOGO study done at 
Muzzey High in Lexington, MA, in 1968. A group of NSF funding people was doing 
a tour of the school, and they came across a Grade 5 student who was doing a 
family tree program. The NSF people were impressed by the complexity of the 
program. One of them said in a patronizing tone, `I guess this stuff really 
helps you learn math'. She got quite angry, and responded, `This stuff has 
NOTHING to do with math!'

> The visual aspect might pique interest, but may put just as
> many people off. In any case, it won't relieve the difficulty
> of having to teach what is fundamentally an abstraction that
> doesn't have very good parallels with how people approach
> problems in the real world. Humans simply don't think like
> mathematicians^W computers. :-)
Having taught grade 8 math, I can tell you that cartesian geometry is much LESS 
intuitive to people that are learning it than the relative polar coordinates of 
turtle geometry are. (`Oh, you want to get to the mall food court? Turn left, 
and walk past about 10 stores. The food court is right after the Gap.')

> I've met a lot of mathematics and comp sci teachers who
> honestly believe that you can't teach these subjects without
> a mathematical perspective. That stands in contrast to the
> number of people I see using spreadsheets with a very high
> proficiency who would never dream of saying they were good
> at mathematics or programming.
It is true that you can't teach computer science to children without having a 
strong understanding of the mathematical foundations. It is also true that when 
you teach it to children that you very carefully hide the mathematical 
formalism. 

I might point out that the people who had most to do with the invention of 
turtle geometry were Wally Feurzeig (who was my boss when I worked at BBN in 
the 1970s) and Seymour Papert. Papert had spent a lot of time working with Jean 
Piaget in Switzerland. If you read the original LOGO memos, you will see his 
clear explanations on how this material ought to be taught to people with no 
math background, including children who are too young to do symbolic thinking 
(that kicks in in the early teens). That's why the visceral `I am a turtle' 
approach works well with middle-school kids. 

-- v
> 
> --
> Peter
> -- 
> http://mail.python.org/mailman/listinfo/python-list

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does turtle graphics have the wrong associations?

2009-11-12 Thread Raymond Hettinger
On Nov 11, 10:21 pm, "Alf P. Steinbach"  wrote:
> One reaction to http://preview.tinyurl.com/ProgrammingBookP3> has
> been that turtle graphics may be off-putting to some readers because it is
> associated with children's learning.
>
> What do you think?

How about calling it Raptor Graphics that will please everyone ;-)


Raymond
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New syntax for blocks

2009-11-12 Thread Stephen Hansen
On Thu, Nov 12, 2009 at 8:10 PM, r  wrote:

> On Nov 12, 7:44 pm, Steven D'Aprano  cybersource.com.au> wrote
> > Oh, but those hundreds of thousands of man-hours lost to bugs caused by
> > assignment-as-an-expression is nothing compared to the dozens of man-
> > minutes saved by having one fewer line of code!
>
> OK, what *if* the variable would only be valid in *that* block and
> *that* block only! My first idea was to have the variable avaiable in
> the local scope (if that is correct terminology?) so if the
> conditional was in global space the value would be available in global
> space, alright? You follow me? Now forget all that and observe the
> following. ;-)
>
>
Assignment is a statement and not an expression in Python intentionally; its
not just some random artifact. It was a decision. If you really want to
overcome it, you need to show a SERIOUSLY huge amount of justification that
goes far beyond 'hey, it saves me one line in certain situations'. You keep
mentioning "elegant" and "clean" in the examples you've provided, but those
terms (while often applied to Pythonisms) are very subjective.

What you find elegant and clean, others may find prone to confusion or
misunderstanding.

There's a certain class of languages which treat assignments as
expressions-- the C family most prominently. And some people love them and
will forever seek it, as there is indeed a reduction of lines and/or code to
express certain ideas if you use assignments as expressions. No one is
really arguing against that.

The argument against it is that it is extremely easy to screw up in ways
which are extremely difficult to debug.


> if value=range(10):
>

The problem with this is, its far too easy to type this but mean, "if
value==range(10):" or some such.

And then its far too hard to figure out why your program is wrong when it
starts producing incorrect results. This has been a source of countless bugs
over the years and years of C programming-- true, an excellent programmer
will never make the mistake. But get some group of people together
maintaining some codebase, and someone's gonna miss something, and others
just will fail to see it as they scan over the code trying to figure out
what's wrong.

Granted, you can produce shorter and more concise code if you can make
assignments expressions instead of statements. However, your code isn't
anymore READABLE. And readability is more important then concise in Python,
/on purpose/.

It's true that you can usually produce a program in far fewer lines of
Python code then you can in certain other languages not to be named; but
that isn't the overriding goal. That's not a zen. There's no doctrine of,
"Shorter is better".

Readability counts is, though.

The expression, "x=y" in a statement is far too easy to mess up with "x==y".
You can try to do screwy things with the syntax like your original proposal
of, "if x as y" to make it so a single missed = won't mess it up, but that
doesn't really improve readability. It makes it less likely to accidentally
screw things up, but also makes it very hard to scan code and determine
where names are created and assigned to objects.

Yeah, we use "as" in a few situations for assignment already. But those are
all special constructs which stand on their own. Try/except, with, and
import support it; but when scanning code those stand out on their own
anyways, and none of them support arbitrarily complex expressions. The if
statement does. The "as" can become lost within that expression, and when
looking in the block of code you can easily miss where the binding occurs.

The proposal that the variable exists only within the 'if' block is a
non-starter; Python's namespaces don't work like that, they don't have
arbitrary blocks of private variables. You just have your local, global, and
builtin namespace (and static nested namespaces for closures)... changing
that is a whole other can of worms, and this is not the proposal to
do it.

--S
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does turtle graphics have the wrong associations?

2009-11-12 Thread Vincent Manis
On 2009-11-12, at 11:36, AK Eric wrote:
> On Nov 12, 11:31 am, Terry Reedy  wrote:
>> Alf P. Steinbach wrote:
>>> One reaction to >> http://preview.tinyurl.com/ProgrammingBookP3> has been that turtle
>>> graphics may be off-putting to some readers because it is associated
>>> with children's learning.
Take a look at Abelson and diSessa's _Turtle Geometry: The Computer as a Medium 
for Exploring Mathematics_ (MIT Press, 1986). This is most definitely not a 
kids' book. Chapter titles include `Topology of Turtle Paths', `Piecewise Flat 
Surfaces', and `Curved Space and General Relativity'. 

As well as being a very nice 2D graphics API, turtles let you explore very deep 
math. Of course, they also let you explore cybernetics and feedback; see some 
of the old MIT AI Lab reports on LOGO for that (you can find them at MIT's 
CSAIL lab website). For a lot of that, you actually need a robot turtle, like 
perhaps a LEGO Mindstorms robot. Seymour Papert (who did a lot of the MIT LOGO 
work) was, before his terrible motor accident, in research chair endowed 
by...LEGO. Hmmm... :)

Of course, some people don't like Python itself because they are afraid of 
snakes. 

> I used Turtle back on the Apple in the early 80's... so I personally
> have very positive feelings towards it ;)  To each their own eh?
I did my master's thesis on LOGO about 10 years before that, and I have VERY 
warm and fuzzy feelings about turtles :)

-- v
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 3.x and 2.x on same machine (is this info at Python.org??)

2009-11-12 Thread Dan Bishop
On Nov 12, 1:52 pm, rantingrick  wrote:
> Hello,
>
> Currently i am using 2.6 on Windows and need to start writing code in
> 3.0. I cannot leave 2.x yet because 3rd party modules are still not
> converted. So i want to install 3.0 without disturbing my current
> Python2.x. What i'm afraid of is that some SYSVARIABLE will get
> changed to Python3.0 and when i double click a Python script it will
> try and run Python 3.x instead of 2.x. I only want to run 3.0 scripts
> from the command line... > python3.x myscript.py
>
> So how do i do this? Is my fear unfounded?

Windows determines the double-click action based on the file
extension.  You just have to make sure that *.py files are associated
with 2.x.
http://support.microsoft.com/kb/307859

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 2.6 and sys.exit()

2009-11-12 Thread hetchkay
On Nov 13, 10:28 am, hetchkay  wrote:
> On Nov 13, 9:50 am, John Yeung  wrote:
>
>
>
> > On Nov 12, 11:22 pm, r  wrote:
>
> > > On Nov 12, 10:07 pm, hetchkay  wrote:
> > > > I have the following in exit.py:
> > > > import sys
> > > > sys.exit(0)
>
> > > > I now try 'python -i exit.py':
>
> > > > In 2.5, the script exits as I would expect.
>
> > > > In 2.6, the following error is printed:
>
> > > > Traceback (most recent call last):
> > > >   File "exit.py", line 2, in 
> > > >     sys.exit(0)
> > > > SystemExit: 0
>
> > > > I couldn't find anything related to this in "What's new in 2.6".
>
> > > Look here ;-)
> > >http://docs.python.org/library/exceptions.html#exceptions.SystemExit
>
> > How does that answer the OP's question?  Namely, how to make 2.6
> > behave like 2.5?  (Even saying "You can't make 2.6 behave like 2.5"
> > would have been a better answer.)
>
> > Failing that, how about something that explains why 2.6 behaves
> > differently than 2.5, and why one of them is better or more correct
> > than the other?
>
> > Personally, I think 2.6's is probably the more correct behavior.
> > Specifically, if the point of the -i command line option is to force
> > interactive mode after completion of the script (which in this case
> > completed with sys.exit), then it should go to interactive mode
> > regardless of whether the script terminates "normally" or not.  I
> > think 2.5's behavior of allowing interactive mode to be skipped is
> > against the spirit of -i.  Unless -i meant something different in 2.5.
>
> > Is there some kind of environment variable to set up to control this?
>
> > John
>
> I can understand the behavior from a '-i' point of view. My
> requirement is somewhat different. Consider a geometry tool that can
> be used to create objects, merge objects etc. I have python 'commands'
> for doing any of these operations and for saving the objects to a
> file. The user could write a file containing a set of commands (in
> python format) and load this file in the GUI. Optionally, one of the
> commands could be to exit in which case the GUI should shut down. I am
> using 'execfile' to execute the file, and this does not exit if the
> user has used sys.exit (or even if I expose a command called 'Exit'
> which calls sys.exit).
>
> May be I should not be using execfile but I am not sure what else I
> should use. The user-written file could contain loops and other
> constructs as well.
>
> -Krishnan

Hi,

I had been starting my application with -i option. I have removed this
now and made a few other changes and things work OK now.

Thanks to everyone who helped in this.

Regards,
Krishnan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python simply not scaleable enough for google?

2009-11-12 Thread Vincent Manis
When I was approximately 5, everybody knew that higher level languages were too 
slow for high-speed numeric computation (I actually didn't know that then, I 
was too busy watching Bill and Ben the Flowerpot Men), and therefore assembly 
languages were mandatory. Then IBM developed Fortran, and higher-level 
languages were not too slow for numeric computation. 

When I was in university, IBM released a perfectly horrible implementation of 
PL/I, which dynamically allocated and freed stack frames for each procedure 
entry and exit (`Do Not Use Procedures: They Are Inefficient': section heading 
from the IBM PL/I (G) Programmer's Guide, circa 1968). Everyone knew PL/I was 
an abomination of a language, which could not be implemented efficiently. Then 
MIT/Bell Labs/GE/Honeywell wrote Multics in a PL/I subset, and (eventually) it 
ran quite efficiently. 

When Bell Labs pulled out of the Multics effort, some of their researchers 
wrote the first version of Unix in assembly language, but a few years later 
rewrote the kernel in C. Their paper reporting this included a sentence that 
said in effect, `yes, the C version is bigger and slower than the assembler 
version, but it has more functionality, so C isn't so bad'. Everybody knew that 
high-level languages were too inefficient to write an operating system in (in 
spite of the fact that Los Alamos had already written an OS in a Fortran 
dialect). Nobody knew that at about that time, IBM had started writing new OS 
modules in a company-confidential PL/I subset. 

When I was in grad school, everybody knew that an absolute defence to a student 
project running slowly was `I wrote it in Lisp'; we only had a Lisp interpreter 
running on our system. We didn't have MacLisp, which had been demonstrated to 
compile carefully-written numerical programs into code that ran more 
efficiently than comparable programs compiled by DEC's PDP-10 Fortran compiler 
in optimizing mode. 

In an earlier post, I mentioned SBCL and Chez Scheme, highly optimizing 
compiler-based implementations of Common Lisp and Scheme, respectively. I don't 
have numbers for SBCL, but I know that (again with carefully-written Scheme 
code) Chez Scheme can produce code that runs in the same order of magnitude as 
optimized C code. These are both very old systems that, at least in the case of 
Chez Scheme, use techniques that have been reported in the academic literature. 
My point in the earlier post about translating Python into Common Lisp or 
Scheme was essentially saying `look, there's more than 30 years experience 
building high-performance implementations of Lisp languages, and Python isn't 
really that different from Lisp, so we ought to be able to do it too'. 

All of which leads me to summarize the current state of things. 

1. Current Python implementations may or may not be performance-scalable in 
ways we need. 

2. Reorganized interpreters may give us a substantial improvement in 
performance. More significant improvements would require a JIT compiler, and 
there are good projects such as Unladen Swallow that may well deliver a 
substantial improvement. 

3. We might also get improvements from good use of Python 3 annotations, or 
other pragma style constructs that might be added to the language after the 
moratorium, which would give a compiler additional information about the 
programmer's intent. (For example, Scheme has a set of functions that 
essentially allow a programmer to say, `I am doing integer arithmetic with 
values that are limited in range to what can be stored in a machine word'.) 
These annotations wouldn't destroy the dynamic nature of Python, because they 
are purely optional. This type of language feature would allow a programmer to 
exploit the high-performance compilation technologies that are common in the 
Lisp world. 

Even though points (2) and (3) between them offer a great deal of hope for 
future Python implementations, there is much that can be done with our current 
implementations. Just ask the programmer who writes a loop that laboriously 
does what could be done much more quickly with a list comprehension or with 
map. 

-- v


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 2.6 and sys.exit()

2009-11-12 Thread hetchkay
On Nov 13, 9:50 am, John Yeung  wrote:
> On Nov 12, 11:22 pm, r  wrote:
>
>
>
> > On Nov 12, 10:07 pm, hetchkay  wrote:
> > > I have the following in exit.py:
> > > import sys
> > > sys.exit(0)
>
> > > I now try 'python -i exit.py':
>
> > > In 2.5, the script exits as I would expect.
>
> > > In 2.6, the following error is printed:
>
> > > Traceback (most recent call last):
> > >   File "exit.py", line 2, in 
> > >     sys.exit(0)
> > > SystemExit: 0
>
> > > I couldn't find anything related to this in "What's new in 2.6".
>
> > Look here ;-)
> >http://docs.python.org/library/exceptions.html#exceptions.SystemExit
>
> How does that answer the OP's question?  Namely, how to make 2.6
> behave like 2.5?  (Even saying "You can't make 2.6 behave like 2.5"
> would have been a better answer.)
>
> Failing that, how about something that explains why 2.6 behaves
> differently than 2.5, and why one of them is better or more correct
> than the other?
>
> Personally, I think 2.6's is probably the more correct behavior.
> Specifically, if the point of the -i command line option is to force
> interactive mode after completion of the script (which in this case
> completed with sys.exit), then it should go to interactive mode
> regardless of whether the script terminates "normally" or not.  I
> think 2.5's behavior of allowing interactive mode to be skipped is
> against the spirit of -i.  Unless -i meant something different in 2.5.
>
> Is there some kind of environment variable to set up to control this?
>
> John

I can understand the behavior from a '-i' point of view. My
requirement is somewhat different. Consider a geometry tool that can
be used to create objects, merge objects etc. I have python 'commands'
for doing any of these operations and for saving the objects to a
file. The user could write a file containing a set of commands (in
python format) and load this file in the GUI. Optionally, one of the
commands could be to exit in which case the GUI should shut down. I am
using 'execfile' to execute the file, and this does not exit if the
user has used sys.exit (or even if I expose a command called 'Exit'
which calls sys.exit).

May be I should not be using execfile but I am not sure what else I
should use. The user-written file could contain loops and other
constructs as well.

-Krishnan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: regex remove closest tag

2009-11-12 Thread S.Selvam
On Fri, Nov 13, 2009 at 12:47 AM, MRAB  wrote:

> S.Selvam wrote:
>
>> Hi all,
>>
>>
>> 1) I need to remove the  tags which is just before the keyword(i.e
>> some_text2 ) excluding others.
>>
>> 2) input string may or may not contain  tags.
>>
>> 3) Sample input:  inputstr = """start > href="some_url">some_text1 some_text2 keyword anything"""
>>
>> 4) I came up with the following regex,
>>
>>
>> p=re.compile(r'(?P.*?)(\s*keyword|\s*keyword)(?P.*)',re.DOTALL|re.I)
>>   s=p.search(inputstr)
>>  but second group matches both  tags,while  i need to match the recent
>> one only.
>>
>> I would like to get your suggestions.
>>
>> Note:
>>
>>   If i leave group('good1') as greedy, then it matches both the  tag.
>>
>>  ".*?" can match any number of any character, so it can match any
> intervening "" tags. Try "[^<]*?" instead.
>
>
Thanks a lot,

 p=re.compile(r'(?:\s*%s)'%(keyword),re.I|re.S)   has done
it !

-- 
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Yours,
S.Selvam
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Writing an emulator in python - implementation questions (for performance)

2009-11-12 Thread Carl Banks
On Nov 12, 6:29 pm, greg  wrote:
> I would be taking a different approach -- develop a prototype
> in Python, concentrating on clarity rather than speed, and
> later reimplement the core of the emulator as an extension
> module, using Pyrex or Cython or otherwise.

But keep in mind he said he was doing it just for fun.  I don't know
about you, but I find it much more fun to try to write fast Python
than to write the fast stuff in C.  Not as effective, but more fun.


Carl Banks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 2.6 and sys.exit()

2009-11-12 Thread Ned Deily
In article 
<008aa7ef-b945-4f70-b5e4-def66546e...@2g2000prl.googlegroups.com>,
 hetchkay  wrote:
> I have the following in exit.py:
> import sys
> sys.exit(0)
> 
> I now try 'python -i exit.py':
> 
> In 2.5, the script exits as I would expect.
> 
> In 2.6, the following error is printed:
> 
> Traceback (most recent call last):
>   File "exit.py", line 2, in 
> sys.exit(0)
> SystemExit: 0
> >>>
> 
> I couldn't find anything related to this in "What's new in 2.6".
> 
> Is there any way I can get 2.6 to behave like 2.5?

Perhaps you don't want to be using the -i option?

"-i

When a script is passed as first argument or the -c option is used, 
enter interactive mode after executing the script or the command ..."

http://docs.python.org/using/cmdline.html#generic-options

If you don't want the interpreter to gain control on exit, don't use -i 
when you run the script.

-- 
 Ned Deily,
 n...@acm.org

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Writing an emulator in python - implementation questions (for performance)

2009-11-12 Thread Carl Banks
On Nov 12, 6:37 am, Santiago Romero  wrote:
> > >  I'm trying to port (just for fun), my old Sinclair Spectrum emulator,
> > > ASpectrum, from C to Python + pygame.
>
> > The answer to your question is, "Use numpy".  More details below.
>
>  Let's see :-)
>
> > >  How can I implement this in Python, I mean, define a 16 byte variable
> > > so that high and low bytes can be accessed separately and changing W,
> > > H or L affects the entire variable? I would like to avoid doing BIT
> > > masks to get or change HIGH or LOW parts of a variable and let the
> > > compiled code to do it by itself.
>
> > You can do clever memory slicing like this with numpy.  For instance:
>
> > breg = numpy.zeros((16,),numpy.uint8)
> > wreg = numpy.ndarray((8,),numpy.uint16,breg)
>
> > This causes breg and wreg to share the same 16 bytes of memory.  You
> > can define constants to access specific registers:
>
> > R1L = 1
> > R1H = 2
> > R1 = 1
>
> > breg[R1H] = 2
> > print wreg[R1]
>
>  And how about speed?
>
> Assuming a 16 bit register named BC which contains 2 8 bit regiters (B
> and C)...
>
>  Will the above be faster than shifts and bit operations (<<, and,>> ) with 
> new B and C values to "recalculate" BC when reading or
>
> changing either B, C or BC?

I don't know.  Strange thing about Python, the community generally
isn't hellbent on speed so we don't usually memorize a bunch of facts
like "X is faster than Y".  I'm personally aware of only a few general
rules of thumb on speed (like "local variables are much faster than
globals" and "function calls have rather high overhead").

Obviously, given the problem you chose, you know you're going to have
to worry about speed from the beginning.  But since not many of us
know speed details off-hand, you'll probably get a faster answer by
just running the speed tests yourself.

Having said that, I *suspect* the numpy approach I mentioned will be
quite a bit faster than using bit operations and recalculating BC, but
I really don't know.


Carl Banks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 2.6 and sys.exit()

2009-11-12 Thread John Yeung
On Nov 12, 11:32 pm, hetchkay  wrote:
> But I don't understand why the interpreter does not exit in 2.6 but
> does exit in 2.5. Well, I do not need to understand that but I need to
> know how to get the interpreter to exit in 2.6.

Well, taken at face value, I would say the answer is to not use the -i
option. ;)  But I assume you would like to be able to sometimes enter
interactive mode after the script completes but sometimes not?

That I don't know how to do, but I would think it is either very
simple or impossible.  Surely someone more knowledgeable will be able
to say which it is.

Also, if you present your reason for wanting such behavior, maybe
people can suggest alternatives that will serve your needs, even if
not exactly replicating what you had in 2.5.

John
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 2.6 and sys.exit()

2009-11-12 Thread John Yeung
On Nov 12, 11:22 pm, r  wrote:
> On Nov 12, 10:07 pm, hetchkay  wrote:
> > I have the following in exit.py:
> > import sys
> > sys.exit(0)
>
> > I now try 'python -i exit.py':
>
> > In 2.5, the script exits as I would expect.
>
> > In 2.6, the following error is printed:
>
> > Traceback (most recent call last):
> >   File "exit.py", line 2, in 
> > sys.exit(0)
> > SystemExit: 0
>
> > I couldn't find anything related to this in "What's new in 2.6".
>
> Look here ;-)
> http://docs.python.org/library/exceptions.html#exceptions.SystemExit

How does that answer the OP's question?  Namely, how to make 2.6
behave like 2.5?  (Even saying "You can't make 2.6 behave like 2.5"
would have been a better answer.)

Failing that, how about something that explains why 2.6 behaves
differently than 2.5, and why one of them is better or more correct
than the other?

Personally, I think 2.6's is probably the more correct behavior.
Specifically, if the point of the -i command line option is to force
interactive mode after completion of the script (which in this case
completed with sys.exit), then it should go to interactive mode
regardless of whether the script terminates "normally" or not.  I
think 2.5's behavior of allowing interactive mode to be skipped is
against the spirit of -i.  Unless -i meant something different in 2.5.

Is there some kind of environment variable to set up to control this?

John
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 2.6 and sys.exit()

2009-11-12 Thread hetchkay
Hello,

Thanks for your help.

I know what SystemExit is. In 2.5 as well SystemExit is raised when
sys.exit() is called. For example:
try:
  import sys
  sys.exit(0)
except SystemExit:
  print "system exit raised"
  raise

But I don't understand why the interpreter does not exit in 2.6 but
does exit in 2.5. Well, I do not need to understand that but I need to
know how to get the interpreter to exit in 2.6.

Regards,
Krishnan
-- 
http://mail.python.org/mailman/listinfo/python-list


how to install python-spidermonkey on windows

2009-11-12 Thread elca

Hello all,
im making some script with python mechanize,
one of problem is it really hard to find which support javascript supported
web client scraping or crawler.
actually i was found some such as python-spidermonkey and pykhtml and so on.
but most of all only support on linux .
i want to make my python script with exe file.
so definitely i have to install on windows platform.
my question is ..are there any method to can install python-spidermonkey or
pykhtml on windows platform?
i really need to support windows platform.
if anyone can hint or help really appreicate!
thanks in advance
Paul
-- 
View this message in context: 
http://old.nabble.com/how-to-install-python-spidermonkey-on-windows-tp26331307p26331307.html
Sent from the Python - python-list mailing list archive at Nabble.com.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 2.6 and sys.exit()

2009-11-12 Thread r
PS: Python even answers questions:

>>> import sys
>>> help(sys.exit)
Help on built-in function exit in module sys:

exit(...)
exit([status])

Exit the interpreter by raising SystemExit(status).
If the status is omitted or None, it defaults to zero (i.e.,
success).
If the status is numeric, it will be used as the system exit
status.
If it is another kind of object, it will be printed and the system
exit status will be one (i.e., failure).

Just think of Python as a programmers version of the "Magic 8 balls".
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 2.6 and sys.exit()

2009-11-12 Thread r
On Nov 12, 10:07 pm, hetchkay  wrote:
> Hello,
>
> I have the following in exit.py:
> import sys
> sys.exit(0)
>
> I now try 'python -i exit.py':
>
> In 2.5, the script exits as I would expect.
>
> In 2.6, the following error is printed:
>
> Traceback (most recent call last):
>   File "exit.py", line 2, in 
>     sys.exit(0)
> SystemExit: 0
>
>
>
> I couldn't find anything related to this in "What's new in 2.6".


Look here ;-)
http://docs.python.org/library/exceptions.html#exceptions.SystemExit

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New syntax for blocks

2009-11-12 Thread r
On Nov 12, 7:44 pm, Steven D'Aprano  wrote
> Oh, but those hundreds of thousands of man-hours lost to bugs caused by
> assignment-as-an-expression is nothing compared to the dozens of man-
> minutes saved by having one fewer line of code!

OK, what *if* the variable would only be valid in *that* block and
*that* block only! My first idea was to have the variable avaiable in
the local scope (if that is correct terminology?) so if the
conditional was in global space the value would be available in global
space, alright? You follow me? Now forget all that and observe the
following. ;-)

if value=range(10):
#this block *would* execute and "value" would be a valid name
#but only IN this block!!!
value.append(1)
elif value=fetch(0):
#this block would *never* execute
value.append(1)

value.append(1) -> this throws a NameError


Is that different than how other languages handle "assignment-by-
expression"? Will that avoid the cataclysmic downward spiral you speak
of? I can't see any problems with it AND it can still be applied to
myself and Carl's use cases.

Anybody is welcome to comment...?
-- 
http://mail.python.org/mailman/listinfo/python-list


2.6 and sys.exit()

2009-11-12 Thread hetchkay
Hello,

I have the following in exit.py:
import sys
sys.exit(0)

I now try 'python -i exit.py':

In 2.5, the script exits as I would expect.

In 2.6, the following error is printed:

Traceback (most recent call last):
  File "exit.py", line 2, in 
sys.exit(0)
SystemExit: 0
>>>

I couldn't find anything related to this in "What's new in 2.6".

Is there any way I can get 2.6 to behave like 2.5?

Thank you for your help,

Regards,
H. Krishnan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: esky 0.2.1

2009-11-12 Thread Ryan Kelly

> >Esky is an auto-update framework for frozen python apps, built on top of
> >bbfreeze.  It provides a simple API through which apps can find, fetch
> >and install updates, and a bootstrapping mechanism that keeps the app
> >safe in the face of failed or partial updates.
> 
> Recently I was looking into distribution mechanisms, and I passed over
> bbfreeze because I saw no indication that Python 2.6 was supported.

Not sure if it's officially supported, but I do most of my development
on Python 2.6 and bbfreeze hasn't given me any problems as yet.

  Cheers,

 Ryan



-- 
Ryan Kelly
http://www.rfk.id.au  |  This message is digitally signed. Please visit
r...@rfk.id.au|  http://www.rfk.id.au/ramblings/gpg/ for details



signature.asc
Description: This is a digitally signed message part
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python parser overridden by pymol

2009-11-12 Thread Dave Angel



Robert Kern wrote:
Jeremiah 
H. Savage wrote:



To use pymol and numpy together, I now do the following:

To ~/.bashrc add:
PYMOL_PATH=/usr/lib/pymodules/python2.5/pymol
export PYMOL_PATH

Then I can do the following in python:

 import numpy
 numpy.save('123',numpy.array([1,2,3]))
 numpy.load('123.npy')
   array([1, 2, 3])
 import sys
 sys.path.append( "/usr/lib/pymodules/python2.5/pymol")
 import pymol
 pymol.finish_launching()
 pymol.importing.load("/path/to/file.pdb")


No, do not do this. Add /usr/lib/pymodules/python2.5/ to your 
$PYTHONPATH, *not* /usr/lib/pymodules/python2.5/pymol/. You will 
continue to run into problems if you do it this way. You are not 
supposed to put the directory *of* the package onto sys.path but 
rather the directory that *contains* the package directory.


As I said before, I don't know pymol.  But if that is the package name, 
then Robert is certainly right.  You need to read the docs on pymol to 
see what they require.  For example, it's surprising they require a 
separate PYMOL_PATH environment variable, since they can find their own 
directory path with the __file__ attribute of one of the modules.


Anyway, one more generic comment.  Rather than having that directory in 
both the bashrc file  AND in your python source, I'd consider deriving 
the latter from the environment variable, once you determine that it's 
actually necessary.  And of course you could strip the last node from 
the path in the environment variable before appending it to sys.path, if 
that's what's appropriate.


DaveA




--
http://mail.python.org/mailman/listinfo/python-list


Python 2.6 and sys.exit()

2009-11-12 Thread H Krishnan
Hello,

I have the following in exit.py:
import sys
sys.exit(0)

I now try 'python -i exit.py':

In 2.5, the script exits as I would expect.

In 2.6, the following error is printed:

Traceback (most recent call last):
  File "exit.py", line 2, in 
sys.exit(0)
SystemExit: 0
>>>

I couldn't find anything related to this in "What's new in 2.6".

Is there any way I can get 2.6 to behave like 2.5?

Thank you for your help,

Regards,
H. Krishnan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: esky 0.2.1

2009-11-12 Thread Aahz
In article ,
Ryan Kelly   wrote:
>
>Esky is an auto-update framework for frozen python apps, built on top of
>bbfreeze.  It provides a simple API through which apps can find, fetch
>and install updates, and a bootstrapping mechanism that keeps the app
>safe in the face of failed or partial updates.

Recently I was looking into distribution mechanisms, and I passed over
bbfreeze because I saw no indication that Python 2.6 was supported.
Kind of a bummer because esky looks pretty cool.
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

[on old computer technologies and programmers]  "Fancy tail fins on a
brand new '59 Cadillac didn't mean throwing out a whole generation of
mechanics who started with model As."  --Andrew Dalke
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does turtle graphics have the wrong associations?

2009-11-12 Thread Peter Nilsson
"Alf P. Steinbach"  wrote:
> One reaction to http://preview.tinyurl.com/ProgrammingBookP3> has
> been that turtle graphics may be off-putting to some
> readers because it is associated with children's learning.

[I'll be honest and say that I merely glanced at the two
pdf files.]

Who is your target audience? The opening Getting Started
paragraph would probably put off many beginners right from
the get go! You're talking about a 'first language' but
throwing 'syntax', 'windows', 'graphics', 'networking',
'file and database access' and 'standard libraries' at them.

The success of ' for Dummies' is certainly not their
accuracy, but rather that they make far fewer assumptions
that people already know the subject being tought! That
assumption seems almost ingrained in every 'beginner'
programming book I've ever seen!

> What do you think?

Whilst everyone knows children tend to think visually more
than abstractly, the same is precisely true of adults.
However, the ultimate problem with Turtle is that it ends
up teaching a 'mathematical' perspective and it's far from
intuitive how you map that perspective to tackling more
real world issues. It's simply substituting one difficult
abstraction with another.

My recollection is that many children struggled with Turtle
graphics because they had very little concept of trigonometry.
[Why would they? Many wouldn't learn for another 2-10 years.]
Adults tend to have even less concept since they almost never
use trig (or much else from school ;-) in the real world.

They can see the patterns and understand there's a logic to
it, but they struggle replicating it. Get an angle wrong
and you end up with a mess where it's not clear whether it's
your algorithm or the maths that's at fault.

The visual aspect might pique interest, but may put just as
many people off. In any case, it won't relieve the difficulty
of having to teach what is fundamentally an abstraction that
doesn't have very good parallels with how people approach
problems in the real world. Humans simply don't think like
mathematicians^W computers. :-)

I've met a lot of mathematics and comp sci teachers who
honestly believe that you can't teach these subjects without
a mathematical perspective. That stands in contrast to the
number of people I see using spreadsheets with a very high
proficiency who would never dream of saying they were good
at mathematics or programming.

--
Peter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Writing an emulator in python - implementation questions (for performance)

2009-11-12 Thread Steven D'Aprano
On Fri, 13 Nov 2009 15:33:53 +1300, greg wrote:

> Santiago Romero wrote:
>>>How about
>>>page, index = divmod(address, 16384)
>>
>>  Surely, much better and faster :-)
> 
> Not necessarily, because it involves a function call, and constructing
> and deconstructing a result tuple. If you time them, you may well find
> that the explicit shift and mask operations turn out to be faster.

It's easy enough to test:

>>> from timeit import Timer
>>> t1 = Timer('a = n>>14; b = n & 16384', 'n=2137902')
>>> t2 = Timer('a,b = divmod(n, 16384)', 'n=2137902')
>>> min(t1.repeat(repeat=5))
0.32850909233093262
>>> min(t2.repeat(repeat=5))
0.54839301109313965

The shift and mask are a little faster on my machine, but that's 
certainly what I would call a micro-optimization. Unless the divmod call 
is the bottleneck in your code -- and it almost certainly won't be -- I 
don't think it's worth the obfuscation to use shift/mask. What should be 
done is write the code in the clearest way you can, then, only if it is 
it too slow, profile it to see where it actually needs optimizing.


-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python & Go

2009-11-12 Thread Paul Rubin
Duncan Booth  writes:
> > http://scienceblogs.com/goodmath/2009/11/googles_new_language_go.php
> > 
> Thanks for that link. I think it pretty well agrees with my first 
> impressions of Go:

It looks like a not-so-interesting C follow-on, but the article doesn't
describe any of the parallelism stuff.

> The lack of any kind of error handling, whether exceptions or
> anything else is, I think, a killer. When you access a value out of
> a map you have a choice of syntax: one way gives you a boolean flag
> you can test to see whether or not the item was in the map, the
> other either gives you the value or crashes the program (yes, the
> documentation actually says 'crash'). Both of these are wrong: the
> flag is wrong because it forces you to handle every lookup error
> immediately and at the same place in the code; the crash is wrong
> for obvious reasons.

Nah, exceptions are an ugly effect that gets in the way of
parallelism.  Haskell handles lookups through its type system; dealing
with lookup errors (say by chaining the Maybe type) is clean and
elegant.  Erlang handles it by crashing the process, and dealing with
the crash through a supervision tree that cleans up after crashes and
restarts the crashed processes.

> What that article didn't mention, and what is possibly Go's real strong 
> point is that it has built-in support for parallel processing. Again though 
> the implementation looks weak...

I'd like to know more about this; is there a link with a short
write-up?  I haven't gotten around to looking at the reference
materials.

> It has too many special cases: a lot of the builtin types can exist
> only as builtin types: if they weren't part of the language you
> couldn't implement an equivalent.

I'd also like to have seen a more serious type system, like ML's or
better.  But they seemed to really be after a fast, lightweight
compiler.

Anyway, it doesn't like even slightly intended to be in the same space
as Python.  It's more like a de-bureaucratized replacement for Java.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Writing an emulator in python - implementation questions (for performance)

2009-11-12 Thread Steven D'Aprano
On Fri, 13 Nov 2009 15:29:03 +1300, greg wrote:

> Generally, I think you're going to have quite a battle on your hands to
> get a pure Python implementation to run as fast as a real Z80, if it's
> even possible at all. And if you do succeed, the code will be pretty
> awful (due to things such as not being able to use named constants).

I don't know about that... 

Python on a 2GHz processor (which is more or less entry-level for desktop 
PCs these days), emulating something which used to run at 2.5MHz? Even if 
the Python code does 1000 times more work, the modern processor is nearly 
1000 times faster, so your Python code won't be much slower than the 
first generation Z80.

The latest Z80 processors operate at 50MHz. That still gives you a factor 
of 40 to work with. Write your Python carefully, optimizing only the bits 
that *need* optimizing, and perhaps using a few C extensions or Psyco, 
and I think you have a good chance of being close enough to the speed of 
a real Z80.



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python simply not scaleable enough for google?

2009-11-12 Thread Steven D'Aprano
On Thu, 12 Nov 2009 21:02:11 +0100, Alf P. Steinbach wrote:

> Specifically, I reacted to the statement that < talk about "the" speed of an implementation>>, made in response to
> someone upthread, in the context of Google finding CPython overall too
> slow.
> 
> It is quite slow. ;-)

Quite slow to do what? Quite slow compared to what?

I think you'll find using CPython to sort a list of ten million integers 
will be quite a bit faster than using bubblesort written in C, no matter 
how efficient the C compiler.

And why are we limiting ourselves to integers representable by the native 
C int? What if the items in the list were of the order of 2**10? Of 
if they were mixed integers, fractions, fixed-point decimals, and 
floating-point binaries? How fast is your C code going to be now? That's 
going to depend on the C library you use, isn't it? In other words, it is 
an *implementation* issue, not a *language* issue.

Okay, let's keep it simple. Stick to numbers representable by native C 
ints. Around this point, people start complaining that it's not fair, I'm 
not comparing apples with apples. Why am I comparing a highly-optimized, 
incredibly fast sort method in CPython with a lousy O(N**2) algorithm in 
C? To make meaningful comparisons, you have to make sure the algorithms 
are the same, so the two language implementations do the same amount of 
work. (Funnily enough, it's "unfair" to play to Python's strengths, and 
"fair" to play to C's strengths.)

Then people invariable try to compare (say) something in C involving low-
level bit-twiddling or pointer arithmetic with something in CPython 
involving high-level object-oriented programming. Of course CPython is 
"slow" if you use it to do hundreds of times more work in every operation 
-- that's comparing apples with oranges again, but somehow people think 
that's okay when your intention is to prove "Python is slow".

An apples-to-apples comparison would be to use a framework in C which 
offered the equivalent features as Python: readable syntax ("executable 
pseudo-code"), memory management, garbage disposal, high-level objects, 
message passing, exception handling, dynamic strong typing, and no core 
dumps ever.

If you did that, you'd get something that runs much closer to the speed 
of CPython, because that's exactly what CPython is: a framework written 
in C that provides all those extra features.

(That's not to say that Python-like high-level languages can't, in 
theory, be significantly faster than CPython, or that they can't have JIT 
compilers that emit highly efficient -- in space or time -- machine code. 
That's what Psyco does, now, and that's the aim of PyPy.)

However, there is one sense that Python *the language* is slower than 
(say) C the language. Python requires that an implementation treat the 
built-in function (say) int as an object subject to modification by the 
caller, while C requires that it is a reserved word. So when a C compiler 
sees "int", it can optimize the call to a known low-level routine, while 
a Python compiler can't make this optimization. It *must* search the 
entire scope looking for the first object called 'int' it finds, then 
search the object's scope for a method called '__call__', then execute 
that. That's the rules for Python, and an implementation that does 
something else isn't Python. Even though the searching is highly 
optimized, if you call int() one million times, any Python implementation 
*must* perform that search one million times, which adds up. Merely 
identifying what function to call is O(N) at runtime for Python and O(1) 
at compile time for C.

Note though that JIT compilers like Psyco can often take shortcuts and 
speed up code by a factor of 2, or up to 100 in the best cases, which 
brings the combination of CPython + Psyco within shouting distance of the 
speed of the machine code generated by good optimizing C compilers. Or 
you can pass the work onto an optimized library or function call that 
avoids the extra work. Like I said, there is no reason for Python 
*applications* to be slow.


-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: #define (from C) in Python

2009-11-12 Thread greg

TerryP wrote:

If it's such a big hairy deal, just recompile a copy of the C Pre
Processor to use something other then #, and hook it up to your python
scripts in a pipe line from a shell wrapper.


Or use a different preprocessor, such as m4, that
doesn't clash with the # character.

--
Greg
--
http://mail.python.org/mailman/listinfo/python-list


Re: python parser overridden by pymol

2009-11-12 Thread Robert Kern

Jeremiah H. Savage wrote:


To use pymol and numpy together, I now do the following:

To ~/.bashrc add:
PYMOL_PATH=/usr/lib/pymodules/python2.5/pymol
export PYMOL_PATH

Then I can do the following in python:

 import numpy
 numpy.save('123',numpy.array([1,2,3]))
 numpy.load('123.npy')
   array([1, 2, 3])
 import sys
 sys.path.append( "/usr/lib/pymodules/python2.5/pymol")
 import pymol
 pymol.finish_launching()
 pymol.importing.load("/path/to/file.pdb")


No, do not do this. Add /usr/lib/pymodules/python2.5/ to your $PYTHONPATH, *not* 
/usr/lib/pymodules/python2.5/pymol/. You will continue to run into problems if 
you do it this way. You are not supposed to put the directory *of* the package 
onto sys.path but rather the directory that *contains* the package directory.


--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

--
http://mail.python.org/mailman/listinfo/python-list


Re: Writing an emulator in python - implementation questions (for performance)

2009-11-12 Thread greg

Santiago Romero wrote:

How about
   page, index = divmod(address, 16384)


 Surely, much better and faster :-)


Not necessarily, because it involves a function call,
and constructing and deconstructing a result tuple.
If you time them, you may well find that the explicit
shift and mask operations turn out to be faster.

That also goes for any of the other things being
discussed here. Especially if you're used to C, one's
intuitions about speed can go badly astray where
Python is concerned. The only way to be sure is to
measure!

--
Greg
--
http://mail.python.org/mailman/listinfo/python-list


Re: Writing an emulator in python - implementation questions (for performance)

2009-11-12 Thread greg

Carl Banks wrote:

You
can define constants to access specific registers:

R1L = 1
R1H = 2
R1 = 1

breg[R1H] = 2
print wreg[R1]


But keep in mind that named "constants" at the module level
are really global variables, and therefore incur a dictionary
lookup every time they're used.

For maximum speed, nothing beats writing the numeric literals
directly into the code, unfortunately.

Generally, I think you're going to have quite a battle on
your hands to get a pure Python implementation to run as
fast as a real Z80, if it's even possible at all. And if
you do succeed, the code will be pretty awful (due to things
such as not being able to use named constants).

I would be taking a different approach -- develop a prototype
in Python, concentrating on clarity rather than speed, and
later reimplement the core of the emulator as an extension
module, using Pyrex or Cython or otherwise.

--
Greg
--
http://mail.python.org/mailman/listinfo/python-list


Re: python with echo

2009-11-12 Thread MRAB

Steven D'Aprano wrote:

On Thu, 12 Nov 2009 19:30:01 +, MRAB wrote:


I don't understand that. Exit status codes on all systems I'm familiar
with are limited to 0 through 255. What operating system are you using?

Assuming your system allows two-byte exit statuses, you should check
the documentation for echo and the shell to see why it is returning
256.


In some OSs the exit status consists of 2 fields, one being the child
process's exit status and the other being supplied by the OS.


Which OSes?


The reason is simple. What if the child process terminated abnormally?
You'd like an exit status to tell you that, 


Which it does. Anything other than 0 is an error. I see that, for 
example, if I interrupt "sleep 30" with ctrl-C instead of waiting for it 
to exit normally, it returns with an exit status of 130.


[st...@soy ~]$ sleep 3  # no interrupt
[st...@soy ~]$ echo $?
0
[st...@soy ~]$ sleep 3  # interrupt with ctrl-C

[st...@soy ~]$ echo $?
130

I get the same result on a Linux box and a Solaris box, both running bash.




but you wouldn't want it to
be confused with the child process's own exit status, assuming that it
had terminated normally.


I don't understand what you mean here. Why are you assuming it terminated 
normally if it terminated abnormally?



You want to be able to distinguish between a child process terminating
with an exit status, and failing to run a child process for some reason.
--
http://mail.python.org/mailman/listinfo/python-list


Re: QuerySets in Dictionaries

2009-11-12 Thread Steven D'Aprano
On Thu, 12 Nov 2009 10:39:33 -0800, scoopseven wrote:

> I need to create a dictionary of querysets.  I have code that looks
> like:
> 
> query1 = Myobject.objects.filter(status=1) 
> query2 = Myobject.objects.filter(status=2) 
> query3 = Myobject.objects.filter(status=3)
> 
> d={}
> d['a'] = query1
> d['b'] = query2
> d['c'] = query3
> 
> Is there a way to do this that I'm missing?

I don't understand your problem. Assuming Myobject is defined, and has 
the appropriate attribute objects.filter, the above should work exactly 
as you give it.

What is your actual problem? Are you asking for help in defining a 
queryset?



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: open source linux -> windows database connectivity?

2009-11-12 Thread Tony Schmidt
>Note: The client part of this product is free. You only need to
>get a license for the server part.

Yeah, but don't I need the server part to make the connection?

Would it be possible to use Jython and the Pervasive JDBC driver for
this?

On Nov 12, 2:56 pm, "M.-A. Lemburg"  wrote:
> Tony Schmidt wrote:
> > I am trying to read a Pervasive database on a Windows machine from a
> > Python script on a Linux machine.
>
> > I understand that this can be done with a proprietary ODBC-to-ODBC
> > bridge called mxODBC or Easysoft OOB.
>
> The product is called "mxODBC Connect" and allows connecting from
> Python (running on pretty much any major platform) to a Windows
> or Linux server running the database:
>
>    http://www.egenix.com/products/python/mxODBCConnect/
>
> Note: The client part of this product is free. You only need to
> get a license for the server part.
>
> Alternatively, you can also our mxODBC single-tier product with
> the Pervasive ODBC driver available for Linux:
>
>    http://ww1.pervasive.com/developerzone/platforms/linux.asp
>
> Regards,
> --
> Marc-Andre Lemburg
> eGenix.com
>
> Professional Python Services directly from the Source  (#1, Nov 12 2009)>>> 
> Python/Zope Consulting and Support ...        http://www.egenix.com/
> >>> mxODBC.Zope.Database.Adapter ...            http://zope.egenix.com/
> >>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
>
> 
>
> ::: Try our new mxODBC.Connect Python Database Interface for free ! 
>
>    eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
>     D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
>            Registered at Amtsgericht Duesseldorf: HRB 46611
>                http://www.egenix.com/company/contact/

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python with echo

2009-11-12 Thread Steven D'Aprano
On Thu, 12 Nov 2009 19:30:01 +, MRAB wrote:

>> I don't understand that. Exit status codes on all systems I'm familiar
>> with are limited to 0 through 255. What operating system are you using?
>> 
>> Assuming your system allows two-byte exit statuses, you should check
>> the documentation for echo and the shell to see why it is returning
>> 256.
>> 
> In some OSs the exit status consists of 2 fields, one being the child
> process's exit status and the other being supplied by the OS.

Which OSes?

> The reason is simple. What if the child process terminated abnormally?
> You'd like an exit status to tell you that, 

Which it does. Anything other than 0 is an error. I see that, for 
example, if I interrupt "sleep 30" with ctrl-C instead of waiting for it 
to exit normally, it returns with an exit status of 130.

[st...@soy ~]$ sleep 3  # no interrupt
[st...@soy ~]$ echo $?
0
[st...@soy ~]$ sleep 3  # interrupt with ctrl-C

[st...@soy ~]$ echo $?
130

I get the same result on a Linux box and a Solaris box, both running bash.



> but you wouldn't want it to
> be confused with the child process's own exit status, assuming that it
> had terminated normally.

I don't understand what you mean here. Why are you assuming it terminated 
normally if it terminated abnormally?




-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New syntax for blocks

2009-11-12 Thread Steven D'Aprano
On Thu, 12 Nov 2009 21:27:31 +0100, Bruno Desthuilliers wrote:

> Congratulations, you just reinvented one of the most infamous source of
> bugs in C, C++, Java, PHP, javascript and quite a few other languages.
> Believe it or not, but not allowing this in Python was a very deliberate
> design choice.

Oh, but those hundreds of thousands of man-hours lost to bugs caused by 
assignment-as-an-expression is nothing compared to the dozens of man-
minutes saved by having one fewer line of code!


*wink*



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Linux, Python 2.5.2, serverless binding LDAP?

2009-11-12 Thread Kevin Cole
On Nov 12, 8:01 pm, alex23  wrote:
> On Nov 13, 10:47 am, Kevin Cole  wrote:
>
>
>
> > Hi,
>
> > I recently asked our IT department how to gain access to an
> > addressbook.  After carefully explaining that I was on a Linux system
> > using Python, I got the reply:
>
> > "You should use our LDAP. With LDAP you can pull any data you want
> > from Active Directory. On our network, the serverless binding address
> > for our LDAP is ldap://dc=...,dc=...,dc=...,dc=...";
>
> > with the actual "..." filled in.
>
> > I don't know squat about LDAP, but installed the python-ldap deb, and
> > started glancing at the documentation on-line. I didn't see anything
> > obvious for working with the URI above.  Can I work w/ it?  If so, a
> > short example, please?
>
> > Thanx.
>
> http://www.python-ldap.org/doc/html/ldapurl.html#example

On second thought... That didn't help at all.  The example just shows
how to parse a URI.  I'm trying to connect to a service (if I
understand correctly) that is NOT on my Linux box, but somewhere out
in our IT department's ether, and I do not have host/domain to work
with.  I interpreted "serverless binding" to mean that I was
connecting by some means other than host.domain:port.  Yes?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python parser overridden by pymol

2009-11-12 Thread Jeremiah H. Savage
On Wed, Nov 11, 2009 at 7:48 PM, Dave Angel  wrote:
>
>
> Jeremiah wrote:
>>
>> Hello,
>>
>> I'm fairly new to python (version 2.5.4), and am writing a program
>> which uses both pymol (version 1.2r1) and numpy (version 1.3.0) from
>> debian.
>>
>> It appears that when I add pymol to $PYTHONPATH, that parser.expr() is
>> no longer available, and so I am unable to use numpy.load(). I have
>> looked for where parser.expr() is defined in the python system so I
>> could place that directory first in $PYTHONPATH, but I have not been
>> able to find the file that defines expr().
>>
>> My reason for using numpy.load() is that I have a numpy array which
>> takes an hour to generate. Therefore, I'd like to use numpy.save() so
>> I could generate the array one time, and then load it later as needed
>> with numpy.load().
>>
>> I've successfully tested the use of numpy.save() and numpy.load() with
>> a small example when the pymol path is not defined in $PYTHONPATH  :
>>
>>   >>> import numpy
>>   >>> numpy.save('123',numpy.array([1,2,3]))
>>   >>> numpy.load('123.npy')
>>   array([1, 2, 3])
>>
>>
>> However, a problem arises once $PYTHONPATH includes the pymol
>> directory. To use the pymol api, I add the following to ~/.bashrc:
>>
>>   PYMOL_PATH=/usr/lib/pymodules/python2.5/pymol
>>   export PYMOL_PATH
>>   PYTHONPATH=$PYMOL_PATH
>>   export PYTHONPATH
>>
>> Once this is done, numpy.load() no longer works correctly, as pymol
>> contains a file named parser.py ( /usr/lib/pymodules/python2.5/pymol/
>> parser.py ), which apparently prevents python from using its native
>> parser.
>>
>>   >>> numpy.load('123.npy')
>>   Traceback (most recent call last):
>>     File "", line 1, in 
>>     File "/usr/lib/python2.5/site-packages/numpy/lib/io.py", line
>> 195, in load
>>       return format.read_array(fid)
>>     File "/usr/lib/python2.5/site-packages/numpy/lib/format.py",
>> line 353, in read_array
>>       shape, fortran_order, dtype = read_array_header_1_0(fp)
>>     File "/usr/lib/python2.5/site-packages/numpy/lib/format.py",
>> line 250, in read_array_header_1_0
>>       d = safe_eval(header)Thank you. That really helped.

To use pymol and numpy to
>>     File "/usr/lib/python2.5/site-packages/numpy/lib/utils.py", line
>> 840, in safe_eval
>>       ast = compiler.parse(source, "eval")
>>     File "/usr/lib/python2.5/compiler/transformer.py", line 54, in
>> parse
>>       return Transformer().parseexpr(buf)
>>     File "/usr/lib/python2.5/compiler/transformer.py", line 133, in
>> parseexpr
>>       return self.transform(parser.expr(text))
>>   AttributeError: 'module' object has no attribute 'expr'
>>
>> If I understand the problem correctly, can anyone tell me where
>> python.expr() is defined, or suggest a better method to fix this
>> problem?
>>
>> Thanks,
>> Jeremiah
>>
>>
>
> Generic answers, I have no experience with pymol
>
> If pymol really needs that parser.py, you have a problem, as there can only
> be one module by that name in the application.  But assuming it's needed for
> some obscure feature that you don't need, you could try the following
> sequence.
>
> 1) temporarily rename the pymol's  parser.py  file to something else, like
> pymolparser.py, and see what runs.
> 2) rather than changing the PYTHONPATH, fix  up  sys.path during your script
> initialization.
>   In particular, do an    import parser    near the beginning of the script.
>  This gets it loaded, even though you might not need to use it from this
> module.
>   After that import, then add the following line (which could be generalized
> later)
>   sys.path.append( "/usr/lib/pymodules/python2.5/pymol")
>
>
> If this works, then you can experiment a bit more, perhaps you don't need
> the extra import parser, just putting the pymol directory at the end of the
> sys.path rather than the beginning may be good enough.
>
> If the parser.py in the pymol is actually needed, you might need to rename
> its internal references to some other name, like pymolparser.
>
> HTH,
> DaveA
>
>

Thank you. Your second suggestion really helped.

To use pymol and numpy together, I now do the following:

To ~/.bashrc add:
PYMOL_PATH=/usr/lib/pymodules/python2.5/pymol
export PYMOL_PATH

Then I can do the following in python:

 import numpy
 numpy.save('123',numpy.array([1,2,3]))
 numpy.load('123.npy')
   array([1, 2, 3])
 import sys
 sys.path.append( "/usr/lib/pymodules/python2.5/pymol")
 import pymol
 pymol.finish_launching()
 pymol.importing.load("/path/to/file.pdb")

Thanks,
Jeremiah
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Linux, Python 2.5.2, serverless binding LDAP?

2009-11-12 Thread Kevin Cole
On Nov 12, 8:01 pm, alex23  wrote:
> On Nov 13, 10:47 am, Kevin Cole  wrote:
>
>
>
> > Hi,
>
> > I recently asked our IT department how to gain access to an
> > addressbook.  After carefully explaining that I was on a Linux system
> > using Python, I got the reply:
>
> > "You should use our LDAP. With LDAP you can pull any data you want
> > from Active Directory. On our network, the serverless binding address
> > for our LDAP is ldap://dc=...,dc=...,dc=...,dc=...";
>
> > with the actual "..." filled in.
>
> > I don't know squat about LDAP, but installed the python-ldap deb, and
> > started glancing at the documentation on-line. I didn't see anything
> > obvious for working with the URI above.  Can I work w/ it?  If so, a
> > short example, please?
>
> > Thanx.
>
> http://www.python-ldap.org/doc/html/ldapurl.html#example

Ah, it wasn't clear to me that "localhost:1389" meant serverless.
Armed with that, I'm off to experiment.

Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Linux, Python 2.5.2, serverless binding LDAP?

2009-11-12 Thread alex23
On Nov 13, 10:47 am, Kevin Cole  wrote:
> Hi,
>
> I recently asked our IT department how to gain access to an
> addressbook.  After carefully explaining that I was on a Linux system
> using Python, I got the reply:
>
> "You should use our LDAP. With LDAP you can pull any data you want
> from Active Directory. On our network, the serverless binding address
> for our LDAP is ldap://dc=...,dc=...,dc=...,dc=...";
>
> with the actual "..." filled in.
>
> I don't know squat about LDAP, but installed the python-ldap deb, and
> started glancing at the documentation on-line. I didn't see anything
> obvious for working with the URI above.  Can I work w/ it?  If so, a
> short example, please?
>
> Thanx.

http://www.python-ldap.org/doc/html/ldapurl.html#example
-- 
http://mail.python.org/mailman/listinfo/python-list


Linux, Python 2.5.2, serverless binding LDAP?

2009-11-12 Thread Kevin Cole
Hi,

I recently asked our IT department how to gain access to an
addressbook.  After carefully explaining that I was on a Linux system
using Python, I got the reply:

"You should use our LDAP. With LDAP you can pull any data you want
from Active Directory. On our network, the serverless binding address
for our LDAP is ldap://dc=...,dc=...,dc=...,dc=...";

with the actual "..." filled in.

I don't know squat about LDAP, but installed the python-ldap deb, and
started glancing at the documentation on-line. I didn't see anything
obvious for working with the URI above.  Can I work w/ it?  If so, a
short example, please?

Thanx.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New syntax for blocks

2009-11-12 Thread r
On Nov 12, 2:37 pm, Bruno Desthuilliers
 wrote:

> > Oh i get it now! If i assign a valid value to a variable the variable
> > is also valid...thats...thats... GENUIS! *sarcasm*
>
> It's not about "assigning a valid value to a variable", it's about the
> name being created (or not) in the current namespace, whatever it's
> bound to.

And thats what my sarcasm was alluding to. Steven's argument is moot
because it will blow up either way due to the fact that "value" is non-
existent! Every argument that has been brought forth about how this
will break is just False and basically a bunch of FUD! It just garbage
so you can discredit the idea.

It's actually quite funny when someone as small as me can bring down
the iron curtain of c.l.py.
  '''Mr. Gorbachev, Tear down this wall!'''

How about one of you "esteemed" Pythonista's show me a real example
where it will break. Show me (and the world) this H.G Wells
nightmarish scenario you speak of but show no solid proofs. Sorry
chaps, I don't buy snake oil!

Going, Going, Goe, out the park!

PS: And if it were so dangerous why would someone as knowledgeable as
Carl have stepped in and supported it. I think because (like me) Carl
put's the language before sewing circles. I think it's just personal
like all the times before, that's OK, i have very thick skin! If it's
wrong for a good reason i will graciously accept that, but no one has
proven it's non-worth, not yet!







-- 
http://mail.python.org/mailman/listinfo/python-list


Re: open source linux -> windows database connectivity?

2009-11-12 Thread M.-A. Lemburg
Tony Schmidt wrote:
> I am trying to read a Pervasive database on a Windows machine from a
> Python script on a Linux machine.
> 
> I understand that this can be done with a proprietary ODBC-to-ODBC
> bridge called mxODBC or Easysoft OOB.

The product is called "mxODBC Connect" and allows connecting from
Python (running on pretty much any major platform) to a Windows
or Linux server running the database:

http://www.egenix.com/products/python/mxODBCConnect/

Note: The client part of this product is free. You only need to
get a license for the server part.

Alternatively, you can also our mxODBC single-tier product with
the Pervasive ODBC driver available for Linux:

http://ww1.pervasive.com/developerzone/platforms/linux.asp

Regards,
-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Nov 12 2009)
>>> Python/Zope Consulting and Support ...http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/


::: Try our new mxODBC.Connect Python Database Interface for free ! 


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
   Registered at Amtsgericht Duesseldorf: HRB 46611
   http://www.egenix.com/company/contact/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python with echo

2009-11-12 Thread Christian Heimes
Diez B. Roggisch wrote:
> with open("/sys/class/net/wlan1/device/tx_power", "w") as f:
>  f.write("%i" % POWER)

IIRC the sys and proc virtual file system requires new line at the end
of a modifier. At least echo appends \n unless it's told otherwise.

Christian

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 3.x and 2.x on same machine (is this info at Python.org??)

2009-11-12 Thread rantingrick
On Nov 12, 2:51 pm, Terry Reedy  wrote:
> rantingrick wrote:
> > Hello,
>
> > Currently i am using 2.6 on Windows and need to start writing code in
> > 3.0. I cannot leave 2.x yet because 3rd party modules are still not
> > converted. So i want to install 3.0 without disturbing my current
> > Python2.x. What i'm afraid of is that some SYSVARIABLE will get
> > changed to Python3.0 and when i double click a Python script it will
> > try and run Python 3.x instead of 2.x. I only want to run 3.0 scripts
> > from the command line... > python3.x myscript.py
>
> > So how do i do this? Is my fear unfounded?
>
> When you install 3.1 (not 3.0), it asks whether to make 'this' the
> default Python. Make sure the box is unchecked.

Thanks for both of your replies, just to be safe though i'm going to
back up everything ... Python 3000, here i come and i hope your ready
for me!?!?

Later Guy's!
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: ActivePython 2.6.4.8 is now available

2009-11-12 Thread Sridhar Ratnakumar

I'm happy to announce that ActivePython 2.6.4.8 is now available for
download from:

http://www.activestate.com/activepython/

This is a patch release that updates ActivePython to core Python 2.6.4.
We recommend that you try 2.6 version first. See the release
notes for full details:

http://docs.activestate.com/activepython/2.6/relnotes.html#changes


What is ActivePython?
-

ActivePython is ActiveState's binary distribution of Python. Builds
for Windows, Mac OS X, Linux, HP-UX and AIX are made freely available.

ActivePython includes the Python core and the many core extensions:
zlib and bzip2 for data compression, the Berkeley DB (bsddb) and SQLite
(sqlite3) database libraries, OpenSSL bindings for HTTPS
support, the Tix GUI widgets for Tkinter, ElementTree for XML
processing, ctypes (on supported platforms) for low-level library
access, and others. The Windows distribution ships with PyWin32 -- a
suite of Windows tools developed by Mark Hammond, including bindings
to the Win32 API and Windows COM.

Beginning the 2.6.3.7 release, ActivePython includes a binary package
manager for Python (PyPM) that can be used to install packages much
easily.

See this page for full details:

http://docs.activestate.com/activepython/2.6/whatsincluded.html

As well, ActivePython ships with a wealth of documentation for both
new and experienced Python programmers. In addition to the core Python
docs, ActivePython includes the "What's New in Python" series, "Dive
into Python", the Python FAQs & HOWTOs, and the Python Enhancement
Proposals (PEPs).

An online version of the docs can be found here:

http://docs.activestate.com/activepython/2.6/

We would welcome any and all feedback to:

activepython-feedb...@activestate.com

Please file bugs against ActivePython at:

http://bugs.activestate.com/query.cgi?set_product=ActivePython


On what platforms does ActivePython run?


ActivePython includes installers for the following platforms:

- Windows/x86
- Windows/x64 (aka "AMD64")
- Mac OS X
- Linux/x86
- Linux/x86_64 (aka "AMD64")
- Solaris/SPARC
- Solaris/x86
- HP-UX/PA-RISC
- AIX/PowerPC
- AIX/PowerPC 64-bit


Extra Bits
--

ActivePython releases also include the following:

- ActivePython26.chm: An MS compiled help collection of the full
  ActivePython documentation set. Linux users of applications such as
  xCHM might find this useful. This package is installed by default on
  Windows.

Extra bits are available from:

http://downloads.activestate.com/ActivePython/etc/


Thanks, and enjoy!

The Python Team

--
Sridhar Ratnakumar
sridharr at activestate.com

--
http://mail.python.org/mailman/listinfo/python-list


open source linux -> windows database connectivity?

2009-11-12 Thread Tony Schmidt
I am trying to read a Pervasive database on a Windows machine from a
Python script on a Linux machine.

I understand that this can be done with a proprietary ODBC-to-ODBC
bridge called mxODBC or Easysoft OOB.

Is there anyway to do this with existing free/ open source tools?

Thanks in advance for any tips.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python & Go

2009-11-12 Thread Grant Edwards
On 2009-11-12, Patrick Sabin  wrote:
> kj wrote:
>> 
>> I'm just learning about Google's latest: the GO (Go?) language.
>> (e.g. http://golang.org or http://www.youtube.com/watch?v=rKnDgT73v8s).
>> There are some distinctly Pythonoid features to the syntax, such
>> as "import this_or_that", the absence of parentheses at the top of
>> flow control constructs, and quite a few statements without a
>> trailing semicolon.  Then again, there's a lot that looks distinctly
>> un-Pythonlike, such as the curly brackets all over the place.  And
>> among the un-Pythonlike stuff there's a lot that looks like nothing
>> else that I've ever seen...
>
> I don't see many similarities with python,

Same here.  Go syntax is much more like C/Java than Python.

Sematically, I don't see much that's similar either. Go is
statically typed.  Go has no inheritence.  Go has no exceptions
( no practical error handling AFAICT).  Despite all the people
who keep saying it's similar to Python, I don't really see what
they're talking about.  It seems more like C with garbage
collection and interfaces, or maybe cleaned-up Java.

-- 
Grant Edwards   grante Yow! I have a VISION!  It's
  at   a RANCID double-FISHWICH on
   visi.coman ENRICHED BUN!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New syntax for blocks

2009-11-12 Thread Bruno Desthuilliers
r a écrit :
> On Nov 11, 2:37 am, Steven D'Aprano
>  wrote:
>> On Wed, 11 Nov 2009 00:08:58 -0800, r wrote:
> 
>>> Yea it's called a NameError. Would it not also blow up in the current
>>> state of syntax usage?
>> No.
>>
>>> if var:
>>> print 'var'
>>> Traceback (most recent call last):
>>>   File "", line 1, in 
>>> if var:
>>> NameError: name 'var' is not defined
>> You missed a line:
>>
>> var = range(N)
>> if var:
> 
> Oh i get it now! If i assign a valid value to a variable the variable
> is also valid...thats...thats... GENUIS! *sarcasm*

It's not about "assigning a valid value to a variable", it's about the
name being created (or not) in the current namespace, whatever it's
bound to.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New syntax for blocks

2009-11-12 Thread Bruno Desthuilliers
Steven D'Aprano a écrit :
(snip)
> Hint to would-be language designers: if you start off by claiming that a 
> new feature will save an indent level, when in fact it *doesn't* save an 
> indent level, you can save yourself from embarrassment by pressing Close 
> on your post instead of Send.

Mou !-)

Thanks Steven, you made my day

(me ---> go back mouaa)
-- 
http://mail.python.org/mailman/listinfo/python-list


JSR223 Access Python class instances through Java

2009-11-12 Thread Jared Klumpp
I am trying to access (from Java) a python class that extends a Java
interface. The following program runs fine in the jython console (I
can instantiate Tada, call t.getName() and everything prints
correctly.) However, if I invoke test1() from Java using JSR223, the
returned object is inaccessible (proxy type) and none of the "in
init", "in getName" strings will print.

Furthermore, none of the lines print unless I convert ITest to a
concrete class, but then the getName methods return the concrete
implementation's string.

Has anyone successfully had this situation work, and how did you do
it?

Thanks in advance

Code:
===
import ITest

class Tada(ITest):
def __init__(self):
print "In Init"

def getName(self):
print "In getName"
return "Joe Schmoe"


def test1():
t = Tada()
print t.getName()
print "Hello, World"
return t

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New syntax for blocks

2009-11-12 Thread Bruno Desthuilliers
r a écrit :
-snip)
> Just thinking out loud here...what if variable assignments could
> return a value... hmmm? Not to them selfs of course but to a caller,
> like an if statement...
> 
> if a=openfile:
>   # do something with a

Congratulations, you just reinvented one of the most infamous source of
bugs in C, C++, Java, PHP, javascript and quite a few other languages.
Believe it or not, but not allowing this in Python was a very deliberate
design choice.

Now whether it was a good choice is another troll^Mtopic !-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python with echo

2009-11-12 Thread Hans Mulder

Steven D'Aprano wrote:

On Wed, 11 Nov 2009 17:24:37 -0800, hong zhang wrote:


List,

I have a question of python using echo.

POWER = 14
return_value = os.system('echo 14 >
/sys/class/net/wlan1/device/tx_power')

can assign 14 to tx_power

But
return_value = os.system('echo $POWER >
/sys/class/net/wlan1/device/tx_power')


POWER = 14 doesn't create an environment variable visible to echo. It is 
a Python variable.



POWER = 14
import os
return_value = os.system('echo $POWER')



return_value

0


You can set environment variables from within Python using os.putenv:

>>> import os
>>> os.putenv('POWER', '14')
>>> return_value = os.system('echo $POWER')
14
>>> return_value
0

Keep in mind that putenv() only affects processes started by Python
after you call putenv.  It does not, for example, affect the shell
process you used to invoke Python:

$ POWER=14
$ python -c 'import os
os.putenv("POWER", "42")
os.system("echo $POWER")'
42
$ echo $POWER
14
$


return_value is 256 not 0. It cannot assign 14 to tx_power.


I don't understand that. Exit status codes on all systems I'm familiar 
with are limited to 0 through 255. What operating system are you using?


Probably some form of Unix.  The value returned by os.system() is the
exit status shifted left one byte, for example:

>>> os.system("exit 1")
256

Hope this helps,

-- HansM

--
http://mail.python.org/mailman/listinfo/python-list


Re: Python & Go

2009-11-12 Thread Patrick Sabin

kj wrote:


I'm just learning about Google's latest: the GO (Go?) language.
(e.g. http://golang.org or http://www.youtube.com/watch?v=rKnDgT73v8s).
There are some distinctly Pythonoid features to the syntax, such
as "import this_or_that", the absence of parentheses at the top of
flow control constructs, and quite a few statements without a
trailing semicolon.  Then again, there's a lot that looks distinctly
un-Pythonlike, such as the curly brackets all over the place.  And
among the un-Pythonlike stuff there's a lot that looks like nothing
else that I've ever seen...


I don't see many similarities with python, especially it's syntax looks
completely different to me. Google Go introduces many new concepts. 
Interfaces work a little bit like duck typing. You may call that 
python-style. And it has go-routines, which are a bit similar to 
generators (although I haven't look at them in detail). There is no 
exception handling, but channels should be able to substitute them, 
although I haven't checked that.


At a first look it seems, that using Google Go effectively, someone has 
to relinquish many programming habits and adapt lots of new ones.


- Patrick
--
http://mail.python.org/mailman/listinfo/python-list


Re: python simply not scaleable enough for google?

2009-11-12 Thread Rami Chowdhury
On Thu, 12 Nov 2009 12:44:00 -0800, Benjamin Kaplan  
 wrote:



Some one could even write an
interpreter for C++ if they wanted to.


Someone has (http://root.cern.ch/drupal/content/cint)!

--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: (OT) Recommend FTP Client

2009-11-12 Thread David M. Besonen
On 11/12/2009 11:26 AM, Dave Angel wrote:

> Try  http://fireftp.mozdev.org/

in the past i found this to be buggy.  i'd recommend
something different.

what is your OS?


  -- david

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python & Go

2009-11-12 Thread Patrick Sabin

Carl Banks wrote:

Well, it's hard to argue with not being like C++, but the lack of
inheritance is a doozie.


Well it has the concept of embedding, which seems to be similar to 
inheritance.


- Patrick
--
http://mail.python.org/mailman/listinfo/python-list


Re: Computing the 1000th prime

2009-11-12 Thread Dave Angel

Ray Holt wrote:

I have an assigment to find the 1000th. prime using python. What's wrong
with the following code:
PrimeCount = 0
PrimeCandidate = 1
while PrimeCount < 2000:
IsPrime = True
PrimeCandidate = PrimeCandidate + 2
for x in range(2, PrimeCandidate):
if PrimeCandidate % x == 0:
##print PrimeCandidate, 'equals', x, '*', PrimeCandidate/x
  print PrimeCandidate  
  IsPrime = False

  break
if IsPrime:
PrimeCount = PrimeCount + 1
PrimeCandidate = PrimeCandidate + 2
print PrimeCandidate
Thanks

  
There are a bunch of things wrong here.  Did you write this code, or was 
it copied from somewhere else?  Because it looks like there are several 
typos, that you could catch by inspection.


First, at what point in the loop do you decide that you have a prime?  
Why not add a print there, printing the prime, instead of printing a 
value that's already been incremented beyond it.  And put labels on your 
prints, or you'll never be able to decipher the output.  Chnage the 
limit for PrimeCount to something small while you're debugging, because 
you can figure out small primes and composites by hand.


Second, you have a loop which divides by x.  But you change the 
PrimeCandidate within the loop, so it's not dividing the same value each 
time through.  Check your indentation.


Third, your limit value is too high.  You aren't looking for 2000 
primes, but 1000 of them.  Further, your count is off by 1, as this loop 
doesn't identify 2 as a prime.


I'd recommend making this whole thing a function, and have it actually 
build and return a list of primes.  Then the caller can check both the 
size of the list and do a double check of the primality of each member.  
And naturally you'll be able to more readily check it yourself, either 
by eye or by comparing it to one of the standard list of primes you can 
find on the internet.



The function should take a count, and loop until the len(primelist) 
matches the count.  Then just return the primelist.


DaveA

--
http://mail.python.org/mailman/listinfo/python-list


Re: 3.x and 2.x on same machine (is this info at Python.org??)

2009-11-12 Thread Terry Reedy

rantingrick wrote:

Hello,

Currently i am using 2.6 on Windows and need to start writing code in
3.0. I cannot leave 2.x yet because 3rd party modules are still not
converted. So i want to install 3.0 without disturbing my current
Python2.x. What i'm afraid of is that some SYSVARIABLE will get
changed to Python3.0 and when i double click a Python script it will
try and run Python 3.x instead of 2.x. I only want to run 3.0 scripts
from the command line... > python3.x myscript.py

So how do i do this? Is my fear unfounded?


When you install 3.1 (not 3.0), it asks whether to make 'this' the 
default Python. Make sure the box is unchecked.


--
http://mail.python.org/mailman/listinfo/python-list


Re: 3.x and 2.x on same machine (is this info at Python.org??)

2009-11-12 Thread Benjamin Kaplan
On Thu, Nov 12, 2009 at 2:52 PM, rantingrick  wrote:
> Hello,
>
> Currently i am using 2.6 on Windows and need to start writing code in
> 3.0. I cannot leave 2.x yet because 3rd party modules are still not
> converted. So i want to install 3.0 without disturbing my current
> Python2.x. What i'm afraid of is that some SYSVARIABLE will get
> changed to Python3.0 and when i double click a Python script it will
> try and run Python 3.x instead of 2.x. I only want to run 3.0 scripts
> from the command line... > python3.x myscript.py
>
> So how do i do this? Is my fear unfounded?
>

At least on *nix (including OS X), installing Python 3 does exactly
what you want by default. I don't know how it handles it on Windows.

> Thanks
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python simply not scaleable enough for google?

2009-11-12 Thread Benjamin Kaplan
On Thu, Nov 12, 2009 at 2:24 PM, Alf P. Steinbach  wrote:
>
> You'll also find it impossible to rigorously define "dynamic language" in a
> general way so that that definition excludes C++. 
>
> So, to anyone who understands what one is talking about, "interpreted", or
> e.g. "slow language" (as was the case here), conveys the essence.
>
> And to anyone who doesn't understand it trying to be more precise is an
> exercise in futility and pure silliness  --  except for the purpose of
> misleading.

You just made Rami's point. You can't define a language as . You can however describe what features it has - static vs.
dynamic typing, duck-typing, dynamic dispatch, and so on. Those are
features of the language. Other things, like "interpreted" vs
"compiled" are features of the implementation. C++ for instance is
considered language that gets compiled to machine code. However,
Visual Studio can compile C++ programs to run on the .NET framework
which makes them JIT compiled. Some one could even write an
interpreter for C++ if they wanted to.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Psyco on 64-bit machines

2009-11-12 Thread Chris Kaynor
On Thu, Nov 12, 2009 at 12:06 PM, Russ P.  wrote:

> I have a Python program that runs too slow for some inputs. I would
> like to speed it up without rewriting any code. Psyco seemed like
> exactly what I need, until I saw that it only works on a 32-bit
> architecture. I work in an environment of Sun Ultras that are all 64-
> bit. However, the Psyco docs say this:
>
> "Psyco does not support the 64-bit x86 architecture, unless you have a
> Python compiled in 32-bit compatibility mode."
>
> Would it make sense to compile Python in the 32-bit compatibility mode
> so I can use Psyco? What would I lose in that mode, if anything?
> Thanks.
> --
> http://mail.python.org/mailman/listinfo/python-list
>

The only things you should lose by using a 32-bit version of Python is
access to the memory beyond the 4GB limit (approximate - the OS takes some
of that), and any compiled extension modules you cannot find or recompile
for 32-bit (.pyd on Windows - I think .so on Linux).

Chris
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python simply not scaleable enough for google?

2009-11-12 Thread Rami Chowdhury
On Thu, 12 Nov 2009 12:02:11 -0800, Alf P. Steinbach   
wrote:
I think that was in the part you *snipped* here. Just fill in the  
mentioned qualifications and weasel words.


OK, sure. I don't think they're weasel words, because I find them useful,  
but I think I see where you're coming from.


Specifically, I reacted to the statement that >, made in response to  
someone upthread, in the context of Google finding CPython overall too  
slow.


IIRC it was "the speed of a language" that was asserted to be nonsense,  
wasn't it? Which IMO is fair -- a physicist friend of mine works with a  
C++ interpreter which is relatively sluggish, but that doesn't mean C++ is  
slow...


--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Computing the 1000th prime

2009-11-12 Thread Benjamin Kaplan
On Thursday, November 12, 2009, Benjamin Kaplan
 wrote:
> On Thursday, November 12, 2009, Ray Holt  wrote:
>>
>>
>>
>>
>>
>> I have an assigment
>> to find the 1000th. prime using python. What's wrong with the following
>> code:
>> PrimeCount =
>> 0
>> PrimeCandidate = 1
>> while PrimeCount < 2000:
>>
>> IsPrime = True
>>     PrimeCandidate = PrimeCandidate +
>> 2
>>     for x in range(2,
>> PrimeCandidate):
>>     if PrimeCandidate
>> % x ==
>> 0:
>> ##    print
>> PrimeCandidate, 'equals', x, '*',
>> PrimeCandidate/x
>>
>> print PrimeCandidate
>>
>>
>> IsPrime =
>> False
>>
>> break
>>     if
>> IsPrime:
>
> You break on the first composite number, which means you immediately
> exit the loop. Just let it fall through Also, a couple of things to
> speed in up:
>

Nevermind MRAB is right. I missed the indentation error there. I guess
that's what I get for  trying to evaluate code on my iPod touch
instead of getting my computer out and actually seeing what it's
doing.  >.<
> 1) you look at all numbers from 2 to n to check if n is a prime
> number. You only need to check from 2 to int(math.sqrt(n))
>
> 2) to really speed it up, keep a list of all the prime numbers. Then
> you only need to check if a number is divisible by those
>
> By combining the two, you'll only use a fraction of the comparisons.
> For 23, you'd only loop twice (2 and 3) instead of 20 times to
> determine that it's prime. The difference is even more dramatic on
> large numbers.
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Psyco on 64-bit machines

2009-11-12 Thread Russ P.
I have a Python program that runs too slow for some inputs. I would
like to speed it up without rewriting any code. Psyco seemed like
exactly what I need, until I saw that it only works on a 32-bit
architecture. I work in an environment of Sun Ultras that are all 64-
bit. However, the Psyco docs say this:

"Psyco does not support the 64-bit x86 architecture, unless you have a
Python compiled in 32-bit compatibility mode."

Would it make sense to compile Python in the 32-bit compatibility mode
so I can use Psyco? What would I lose in that mode, if anything?
Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Computing the 1000th prime

2009-11-12 Thread Benjamin Kaplan
On Thursday, November 12, 2009, Ray Holt  wrote:
>
>
>
>
>
> I have an assigment
> to find the 1000th. prime using python. What's wrong with the following
> code:
> PrimeCount =
> 0
> PrimeCandidate = 1
> while PrimeCount < 2000:
>
> IsPrime = True
>     PrimeCandidate = PrimeCandidate +
> 2
>     for x in range(2,
> PrimeCandidate):
>     if PrimeCandidate
> % x ==
> 0:
> ##    print
> PrimeCandidate, 'equals', x, '*',
> PrimeCandidate/x
>
> print PrimeCandidate
>
>
> IsPrime =
> False
>
> break
>     if
> IsPrime:
>
> PrimeCount = PrimeCount +
> 1
>
> PrimeCandidate = PrimeCandidate +
> 2
>     print
> PrimeCandidate
> Thanks
>

You break on the first composite number, which means you immediately
exit the loop. Just let it fall through Also, a couple of things to
speed in up:

1) you look at all numbers from 2 to n to check if n is a prime
number. You only need to check from 2 to int(math.sqrt(n))

2) to really speed it up, keep a list of all the prime numbers. Then
you only need to check if a number is divisible by those

By combining the two, you'll only use a fraction of the comparisons.
For 23, you'd only loop twice (2 and 3) instead of 20 times to
determine that it's prime. The difference is even more dramatic on
large numbers.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python simply not scaleable enough for google?

2009-11-12 Thread Alf P. Steinbach

* Rami Chowdhury:
On Thu, 12 Nov 2009 11:24:18 -0800, Alf P. Steinbach  
wrote:



* Rami Chowdhury:
On Thu, 12 Nov 2009 09:32:28 -0800, Alf P. Steinbach  
wrote:


This also seems religious. It's like in Norway it became illegal to 
market lemon soda, since umpteen years ago it's soda with lemon 
flavoring. This has to do with the *origin* of the citric acid, 
whether natural or chemist's concoction, no matter that it's the 
same chemical. So, some people think that it's wrong to talk about 
interpreted languages, hey, it should be a "language designed for 
interpretation", or better yet, "dynamic language", or bestest, 
"language with dynamic flavor". And slow language, oh no, should be 
"language whose current implementations are perceived as somewhat 
slow by some (well, all) people", but of course, that's just silly.
 Perhaps I'm missing the point of what you're saying but I don't see 
why you're conflating interpreted and dynamic here? Javascript is 
unarguably a dynamic language, yet Chrome / Safari 4 / Firefox 3.5 
all typically JIT it. Does that make Javascript non-dynamic, because 
it's compiled? What about Common Lisp, which is a compiled language 
when it's run with CMUCL or SBCL?


Yeah, you missed it.

Blurring and coloring and downright hiding reality by insisting on 
misleading but apparently more precise terminology for some vague 
concept is a popular sport, and chiding others for using more 
practical and real-world oriented terms, can be effective in politics 
and some other arenas.





But in a technical context it's silly. Or dumb. Whatever.

E.g. you'll find it impossible to define interpretation rigorously in 
the sense that you're apparently thinking of.


Well, sure. Can you explain, then, what sense you meant it in?


I think that was in the part you *snipped* here. Just fill in the mentioned 
qualifications and weasel words. And considering that a routine might be an 
intepreter of data produced elsewhere in program, needs some fixing...



You'll also find it impossible to rigorously define "dynamic language" 
in a general way so that that definition excludes C++. 


Or, for that matter, suitably clever assembler. I'm not arguing with you 
there.


So, to anyone who understands what one is talking about, 
"interpreted", or e.g. "slow language" (as was the case here), conveys 
the essence.


Not when the context isn't clear, it doesn't.

And to anyone who doesn't understand it trying to be more precise is 
an exercise in futility and pure silliness  --  except for the purpose 
of misleading.


Or for the purpose of greater understanding, surely - and isn't that the 
point?


I don't think that was the point.

Specifically, I reacted to the statement that >, made in response to someone upthread, 
in the context of Google finding CPython overall too slow.


It is quite slow. ;-)


Cheers,

- Alf
--
http://mail.python.org/mailman/listinfo/python-list


3.x and 2.x on same machine (is this info at Python.org??)

2009-11-12 Thread rantingrick
Hello,

Currently i am using 2.6 on Windows and need to start writing code in
3.0. I cannot leave 2.x yet because 3rd party modules are still not
converted. So i want to install 3.0 without disturbing my current
Python2.x. What i'm afraid of is that some SYSVARIABLE will get
changed to Python3.0 and when i double click a Python script it will
try and run Python 3.x instead of 2.x. I only want to run 3.0 scripts
from the command line... > python3.x myscript.py

So how do i do this? Is my fear unfounded?

Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: (OT) Recommend FTP Client

2009-11-12 Thread Victor Subervi
Thanks.
V

On Thu, Nov 12, 2009 at 2:26 PM, Dave Angel  wrote:

>
>
> Victor Subervi wrote:
>
>> Hi;
>> Someone on this list just recommended I find an ftp client that enables me
>> to change line endings. He indicated that it would be easy, but googling I
>> haven't been able to find one. I would prefer a free client, but whatever.
>> Please send me a recommendation.
>> TIA,
>> Victor
>>
>>
>>
> Try  http://fireftp.mozdev.org/
>
> fireftp is an (free) addon to Firefox.  If you're already using Firefox,
> it's painless to download it, and easy to use.  You can set up account(s)
> complete with passwords and default directories, and then transfer
> individual files or directory trees full just by selecting and pressing the
> Arrow icons (one for upload, one for download).  You can sort by timestamp,
> so it's not hard to just transfer new stuff.
>
>
> One of the Tools->Options tabs is  "Downloads/Uploads".  First box looks
> like:
>
>  When transferring files use:
>  o - Automatic mode
>  o - Binary mode
>  o - ASCII mode
>
>
> According to the help, Automatic mode is very useful for CGI scripts, where
> you specify which extensions will get the line-endings converted.
> http://fireftp.mozdev.org/help.html
>
> But please understand:  I personally use Binary mode in FireFTP because I'm
> a control freak.  Python can handle Unix line-endings just fine, so any
> files that are bound for CGI I just edit in that mode in the first place.
>
>
> DaveA
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Computing the 1000th prime

2009-11-12 Thread MRAB

Ray Holt wrote:
I have an assigment to find the 1000th. prime using python. What's wrong 
with the following code:

PrimeCount = 0
PrimeCandidate = 1
while PrimeCount < 2000:
IsPrime = True
PrimeCandidate = PrimeCandidate + 2
for x in range(2, PrimeCandidate):
if PrimeCandidate % x == 0:
##print PrimeCandidate, 'equals', x, '*', PrimeCandidate/x
  print PrimeCandidate 
  IsPrime = False

  break
if IsPrime:
PrimeCount = PrimeCount + 1
PrimeCandidate = PrimeCandidate + 2
print PrimeCandidate
Thanks


The indentation starting from the second 'if'.

--
http://mail.python.org/mailman/listinfo/python-list


Re: python simply not scaleable enough for google?

2009-11-12 Thread Rami Chowdhury
On Thu, 12 Nov 2009 11:24:18 -0800, Alf P. Steinbach   
wrote:



* Rami Chowdhury:
On Thu, 12 Nov 2009 09:32:28 -0800, Alf P. Steinbach   
wrote:


This also seems religious. It's like in Norway it became illegal to  
market lemon soda, since umpteen years ago it's soda with lemon  
flavoring. This has to do with the *origin* of the citric acid,  
whether natural or chemist's concoction, no matter that it's the same  
chemical. So, some people think that it's wrong to talk about  
interpreted languages, hey, it should be a "language designed for  
interpretation", or better yet, "dynamic language", or bestest,  
"language with dynamic flavor". And slow language, oh no, should be  
"language whose current implementations are perceived as somewhat slow  
by some (well, all) people", but of course, that's just silly.
 Perhaps I'm missing the point of what you're saying but I don't see  
why you're conflating interpreted and dynamic here? Javascript is  
unarguably a dynamic language, yet Chrome / Safari 4 / Firefox 3.5 all  
typically JIT it. Does that make Javascript non-dynamic, because it's  
compiled? What about Common Lisp, which is a compiled language when  
it's run with CMUCL or SBCL?


Yeah, you missed it.

Blurring and coloring and downright hiding reality by insisting on  
misleading but apparently more precise terminology for some vague  
concept is a popular sport, and chiding others for using more practical  
and real-world oriented terms, can be effective in politics and some  
other arenas.





But in a technical context it's silly. Or dumb. Whatever.

E.g. you'll find it impossible to define interpretation rigorously in  
the sense that you're apparently thinking of.


Well, sure. Can you explain, then, what sense you meant it in?

You'll also find it impossible to rigorously define "dynamic language"  
in a general way so that that definition excludes C++. 


Or, for that matter, suitably clever assembler. I'm not arguing with you  
there.


So, to anyone who understands what one is talking about, "interpreted",  
or e.g. "slow language" (as was the case here), conveys the essence.


Not when the context isn't clear, it doesn't.

And to anyone who doesn't understand it trying to be more precise is an  
exercise in futility and pure silliness  --  except for the purpose of  
misleading.


Or for the purpose of greater understanding, surely - and isn't that the  
point?



--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Does turtle graphics have the wrong associations?

2009-11-12 Thread AK Eric
On Nov 12, 11:31 am, Terry Reedy  wrote:
> Alf P. Steinbach wrote:
> > One reaction to  >http://preview.tinyurl.com/ProgrammingBookP3> has been that turtle
> > graphics may be off-putting to some readers because it is associated
> > with children's learning.
>
> > What do you think?
>
> I just started using the module for simple plots.
> I am not a child.
> You cannot please everyone.

I used Turtle back on the Apple in the early 80's... so I personally
have very positive feelings towards it ;)  To each their own eh?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does turtle graphics have the wrong associations?

2009-11-12 Thread Terry Reedy

Alf P. Steinbach wrote:
One reaction to http://preview.tinyurl.com/ProgrammingBookP3> has been that turtle 
graphics may be off-putting to some readers because it is associated 
with children's learning.


What do you think?


I just started using the module for simple plots.
I am not a child.
You cannot please everyone.

--
http://mail.python.org/mailman/listinfo/python-list


Re: python with echo

2009-11-12 Thread MRAB

Steven D'Aprano wrote:

On Wed, 11 Nov 2009 17:24:37 -0800, hong zhang wrote:


List,

I have a question of python using echo.

POWER = 14
return_value = os.system('echo 14 >
/sys/class/net/wlan1/device/tx_power')

can assign 14 to tx_power

But
return_value = os.system('echo $POWER >
/sys/class/net/wlan1/device/tx_power')


POWER = 14 doesn't create an environment variable visible to echo. It is 
a Python variable.




POWER = 14
import os
return_value = os.system('echo $POWER')



return_value

0




return_value is 256 not 0. It cannot assign 14 to tx_power.



I don't understand that. Exit status codes on all systems I'm familiar 
with are limited to 0 through 255. What operating system are you using?


Assuming your system allows two-byte exit statuses, you should check the 
documentation for echo and the shell to see why it is returning 256.



In some OSs the exit status consists of 2 fields, one being the child
process's exit status and the other being supplied by the OS.

The reason is simple. What if the child process terminated abnormally?
You'd like an exit status to tell you that, but you wouldn't want it to
be confused with the child process's own exit status, assuming that it
had terminated normally.

Have you tried this in the shell, without involving Python? I will almost 
guarantee that Python is irrelevant to the problem.




--
http://mail.python.org/mailman/listinfo/python-list


Re: (OT) Recommend FTP Client

2009-11-12 Thread Dave Angel



Victor Subervi wrote:

Hi;
Someone on this list just recommended I find an ftp client that enables me
to change line endings. He indicated that it would be easy, but googling I
haven't been able to find one. I would prefer a free client, but whatever.
Please send me a recommendation.
TIA,
Victor

  

Try  http://fireftp.mozdev.org/

fireftp is an (free) addon to Firefox.  If you're already using Firefox, 
it's painless to download it, and easy to use.  You can set up 
account(s) complete with passwords and default directories, and then 
transfer individual files or directory trees full just by selecting and 
pressing the Arrow icons (one for upload, one for download).  You can 
sort by timestamp, so it's not hard to just transfer new stuff.



One of the Tools->Options tabs is  "Downloads/Uploads".  First box looks 
like:


  When transferring files use:
  o - Automatic mode
  o - Binary mode
  o - ASCII mode


According to the help, Automatic mode is very useful for CGI scripts, 
where you specify which extensions will get the line-endings converted.

 http://fireftp.mozdev.org/help.html

But please understand:  I personally use Binary mode in FireFTP because 
I'm a control freak.  Python can handle Unix line-endings just fine, so 
any files that are bound for CGI I just edit in that mode in the first 
place.



DaveA

--
http://mail.python.org/mailman/listinfo/python-list


Re: python simply not scaleable enough for google?

2009-11-12 Thread Alf P. Steinbach

* Rami Chowdhury:
On Thu, 12 Nov 2009 09:32:28 -0800, Alf P. Steinbach  
wrote:


This also seems religious. It's like in Norway it became illegal to 
market lemon soda, since umpteen years ago it's soda with lemon 
flavoring. This has to do with the *origin* of the citric acid, 
whether natural or chemist's concoction, no matter that it's the same 
chemical. So, some people think that it's wrong to talk about 
interpreted languages, hey, it should be a "language designed for 
interpretation", or better yet, "dynamic language", or bestest, 
"language with dynamic flavor". And slow language, oh no, should be 
"language whose current implementations are perceived as somewhat slow 
by some (well, all) people", but of course, that's just silly.


Perhaps I'm missing the point of what you're saying but I don't see why 
you're conflating interpreted and dynamic here? Javascript is unarguably 
a dynamic language, yet Chrome / Safari 4 / Firefox 3.5 all typically 
JIT it. Does that make Javascript non-dynamic, because it's compiled? 
What about Common Lisp, which is a compiled language when it's run with 
CMUCL or SBCL?


Yeah, you missed it.

Blurring and coloring and downright hiding reality by insisting on misleading 
but apparently more precise terminology for some vague concept is a popular 
sport, and chiding others for using more practical and real-world oriented 
terms, can be effective in politics and some other arenas.


But in a technical context it's silly. Or dumb. Whatever.

E.g. you'll find it impossible to define interpretation rigorously in the sense 
that you're apparently thinking of. It's not that kind of term or concept. The 
nearest you can get is in a different direction, something like "a program whose 
actions are determined by data external to the program (+ x qualifications and 
weasel words)", which works in-practice, conceptually, but try that on as a 
rigorous definition and you'll see that when you get formal about it then it's 
completely meaningless: either anything qualifies or nothing qualifies.


You'll also find it impossible to rigorously define "dynamic language" in a 
general way so that that definition excludes C++. 


So, to anyone who understands what one is talking about, "interpreted", or e.g. 
"slow language" (as was the case here), conveys the essence.


And to anyone who doesn't understand it trying to be more precise is an exercise 
in futility and pure silliness  --  except for the purpose of misleading.



Cheers & hth.,

- Alf
--
http://mail.python.org/mailman/listinfo/python-list


Re: regex remove closest tag

2009-11-12 Thread MRAB

S.Selvam wrote:

Hi all,


1) I need to remove the  tags which is just before the keyword(i.e 
some_text2 ) excluding others.


2) input string may or may not contain  tags.

3) Sample input: 
 
inputstr = """start some_text1 href="">some_text2 keyword anything"""


4) I came up with the following regex,

   
p=re.compile(r'(?P.*?)(\s*keyword|\s*keyword)(?P.*)',re.DOTALL|re.I)

   s=p.search(inputstr)
  but second group matches both  tags,while  i need to match the 
recent one only.


I would like to get your suggestions.

Note:

   If i leave group('good1') as greedy, then it matches both the  tag.


".*?" can match any number of any character, so it can match any
intervening "" tags. Try "[^<]*?" instead.

--
http://mail.python.org/mailman/listinfo/python-list


Computing the 1000th prime

2009-11-12 Thread Ray Holt
I have an assigment to find the 1000th. prime using python. What's wrong
with the following code:
PrimeCount = 0
PrimeCandidate = 1
while PrimeCount < 2000:
IsPrime = True
PrimeCandidate = PrimeCandidate + 2
for x in range(2, PrimeCandidate):
if PrimeCandidate % x == 0:
##print PrimeCandidate, 'equals', x, '*', PrimeCandidate/x
  print PrimeCandidate  
  IsPrime = False
  break
if IsPrime:
PrimeCount = PrimeCount + 1
PrimeCandidate = PrimeCandidate + 2
print PrimeCandidate
Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: QuerySets in Dictionaries

2009-11-12 Thread Diez B. Roggisch

scoopseven schrieb:

I need to create a dictionary of querysets.  I have code that looks
like:

query1 = Myobject.objects.filter(status=1)
query2 = Myobject.objects.filter(status=2)
query3 = Myobject.objects.filter(status=3)

d={}
d['a'] = query1
d['b'] = query2
d['c'] = query3

Is there a way to do this that I'm missing?



d = dict(a=Myobject.objects.filter(status=1),
 b=Myobject.objects.filter(status=2),
 c=Myobject.objects.filter(status=3))

Diez
--
http://mail.python.org/mailman/listinfo/python-list


Re: QuerySets in Dictionaries

2009-11-12 Thread Simon Brunning
2009/11/12 scoopseven :
> I need to create a dictionary of querysets.  I have code that looks
> like:
>
> query1 = Myobject.objects.filter(status=1)
> query2 = Myobject.objects.filter(status=2)
> query3 = Myobject.objects.filter(status=3)
>
> d={}
> d['a'] = query1
> d['b'] = query2
> d['c'] = query3
>
> Is there a way to do this that I'm missing?

Untested:

wanted = (('a', 1), ('b', 2), ('c', 2))
d = dict((key, Myobject.objects.filter(status=number)) for (key,
number) in wanted)


-- 
Cheers,
Simon B.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: #define (from C) in Python

2009-11-12 Thread TerryP
If it's such a big hairy deal, just recompile a copy of the C Pre
Processor to use something other then #, and hook it up to your python
scripts in a pipe line from a shell wrapper.

Personally, I'd rather have Lisps lambda or perls sub then Cs
preprocessor, and even in those cases, Python suffices perfectly
fine ;).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python simply not scaleable enough for google?

2009-11-12 Thread Rami Chowdhury
On Thu, 12 Nov 2009 09:32:28 -0800, Alf P. Steinbach   
wrote:


This also seems religious. It's like in Norway it became illegal to  
market lemon soda, since umpteen years ago it's soda with lemon  
flavoring. This has to do with the *origin* of the citric acid, whether  
natural or chemist's concoction, no matter that it's the same chemical.  
So, some people think that it's wrong to talk about interpreted  
languages, hey, it should be a "language designed for interpretation",  
or better yet, "dynamic language", or bestest, "language with dynamic  
flavor". And slow language, oh no, should be "language whose current  
implementations are perceived as somewhat slow by some (well, all)  
people", but of course, that's just silly.


Perhaps I'm missing the point of what you're saying but I don't see why  
you're conflating interpreted and dynamic here? Javascript is unarguably a  
dynamic language, yet Chrome / Safari 4 / Firefox 3.5 all typically JIT  
it. Does that make Javascript non-dynamic, because it's compiled? What  
about Common Lisp, which is a compiled language when it's run with CMUCL  
or SBCL?



--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: (OT) Recommend FTP Client

2009-11-12 Thread Tim Chase

Someone on this list just recommended I find an ftp client that enables me
to change line endings. He indicated that it would be easy, but googling I
haven't been able to find one. I would prefer a free client, but whatever.
Please send me a recommendation.


How about the command line client that comes with every modern 
OS?  Just use the ASCII (default) and BIN commands to switch 
between line-ending translation.


-tkc





--
http://mail.python.org/mailman/listinfo/python-list


QuerySets in Dictionaries

2009-11-12 Thread scoopseven
I need to create a dictionary of querysets.  I have code that looks
like:

query1 = Myobject.objects.filter(status=1)
query2 = Myobject.objects.filter(status=2)
query3 = Myobject.objects.filter(status=3)

d={}
d['a'] = query1
d['b'] = query2
d['c'] = query3

Is there a way to do this that I'm missing?

Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can a module know the module that imported it?

2009-11-12 Thread AK Eric
On Nov 12, 10:10 am, Ethan Furman  wrote:
> AK Eric wrote:
> > so:
>
> > # moduleA.py
> > import moduleB
>
> > # moduleB.py
> > import sys
> > stuff = sys._getframe(1).f_locals
> > print stuff
>
> > Prints:
>
> > {'__builtins__': ,
> > '__file__': 'C:\\Documents and SettingsMy Documents\
> > \python\\moduleA.py',
> > '__name__': '__main__',
> > '__doc__': None}
>
> > Looks like you could query stuff['__file__'] to pull what you're
> > after.
> > ?
>
> The leading _ in _getframe indicates a private function to sys (aka
> implementation detail); in other words, something that could easily
> change between one Python version and the next.
>
> I'm using the inspect module (for the moment, at least), and my question
> boils down to:  Will it work correctly on all versions of Python in the
> 2.x range?  3.x range?
>

Good point, I totally missed that.  Someone had passed that solution
to me at one point and I was so excited I kind of looked that over :P
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can a module know the module that imported it?

2009-11-12 Thread Ethan Furman

AK Eric wrote:

so:

# moduleA.py
import moduleB

# moduleB.py
import sys
stuff = sys._getframe(1).f_locals
print stuff

Prints:

{'__builtins__': ,
'__file__': 'C:\\Documents and SettingsMy Documents\
\python\\moduleA.py',
'__name__': '__main__',
'__doc__': None}

Looks like you could query stuff['__file__'] to pull what you're
after.
?


The leading _ in _getframe indicates a private function to sys (aka 
implementation detail); in other words, something that could easily 
change between one Python version and the next.


I'm using the inspect module (for the moment, at least), and my question 
boils down to:  Will it work correctly on all versions of Python in the 
2.x range?  3.x range?


~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list


Re: standard libraries don't behave like standard 'libraries'

2009-11-12 Thread Benjamin Kaplan
On Thu, Nov 12, 2009 at 12:05 PM, Sriram Srinivasan
 wrote:
>> So all libraries written have to use the common subset, which - unless
>> things are *removed*, which with python3 actually happened - is always
>> the oldest interpreter. And if a feature goes away, they have to be
>> rewritten with the then common subset.
>
> you see that's the problem with py3. instead of slowly removing the
> features one by one till the end they made a jump. the problem is not
> with the jump but with other libraries/packages that depend on py2.
> what i felt was if the new version was available as soon as it is into
> the stream, developers/users try to use them and get accustomed. now
> they follow this. they have frozen py3 for may be 2-3 years so ppl
> would move slowly to py2.6 ,2.7, 2.8... most. also the corporate
> companies are the most influential.
>

The freeze was put in place so that the other implementations of
Python, like Jython and IronPython, have a chance to catch up with the
reference CPython implementation. It's not so people will slowly move
up. FWIW, people knew for years what was going to change in Python 3.

> also a point to note: if new updates keep on coming (for eg. daily
> antivirus update) developers tend to accept and move on *easily*.
>
> i am not an expert in programming/interpreter design/library writing/
> packaging. i just wanted the standard library *too* to be pluggable,
> not just the applications based on it.
> i am not even experienced in python to make bold accusations so all i
> can say is 'how it would be if?' and i always stick to one thing 'why
> not?'.
>
>> In other words: as a library writer, I can't use shiny, new & better
>> features, I'm stuck with the old stuff, and whenever the interpreter
>> evolves I have to rewrite even the old ones. Not appealing. Why develop
>> the interpreter at all then?
>
> if you are app developer you needn't rewrite anything. that is the
> main point here! just specifying the interpreter and library version
> is enough every thing has to work like magic. as the previous
> library&interpreter wont be removed (unless and until it is your will)
> u can use them. thats how everybody would like it to be.
>

So you're saying that we'd have multiple versions of the interpreter
running at the same time, but they all have access to the same memory.
That wouldn't just require a change to Python, that would require a
change to the way all modern operating systems work.

> as for a library writer is concerned: as you say it depends on certain
> things like other libraries,interpreter,etc. but i would like to say
> that change is inevitable. if some core developer has to change
> something he might change. and if you have to update your library you
> have to. this applies to the interpreter too. what python now does is
> make every update work with the minimal set (giving minimal backward
> compatibility) plus the new features too. which is exactly the right
> thing. what i wanted is the users have to be aware now and then when
> of the modification, deletion, addition stuff not in every release as
> in py3k. then the whole backward incompatibility issue would be
> *dissolved* or what i mean is *diffused* and ppl dont even know that
> they have switched over to a very new thing.
>
>

Actually, that's not entirely true. New versions to break things
Consider these statements

as = ['a','a','a']
with = [1,2,3]
It's legal in Python 2.4 or earlier, a warning in Python 2.5, but
illegal in Python 2.6

>
>> In other words: the problem is solved by somehow solving the problem -
>> but not by a concrete solution you propose?
>
> as i told before i neither know the problem nor the solution. i just
> wrote my ideas/imagination down
>
>> PyPy is cool, but by far not advanced enough to replace external,
>> C-based libraries such as NUMPY and PyQt and whatnot.
>>
>> I don't say that the current situation is by any means ideal. There is a
>> lot to be said about package creation, distribution, installation,
>> removal, dependency handling, and even system-packaging-integration if
>> one likes.
>>
>> You IMHO just add another layer of complexity on top of it, without
>> proposing solutions to any of the layers in between, nor your new one -
>> namely, the interpreter version agnosticism.
>
> yes you are right. python has a lot of bindings to a lot of stuff. but
> it is the strength and weakness. not exactly pythons weakness but with
> the thing on the other side. yes it may be looking complex because
> most of the 'standard library' system was not designed to be adhoc/add-
> on/pluggable from the start.


It is pluggable. The standard library consists of Python modules like
any other. 2.6's multiprocessing module is just an incorporation of
the pyprocessing module for instance. The point of the standard
library is that you can count on it being there, and you can count on
it having certain features, given your interpreter version. You can
also be sure that anytime a new ver

Re: Writing an emulator in python - implementation questions (for performance)

2009-11-12 Thread Santiago Romero

 Oops, numpy arrays start with index=0 :-)


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can a module know the module that imported it?

2009-11-12 Thread AK Eric
so:

# moduleA.py
import moduleB

# moduleB.py
import sys
stuff = sys._getframe(1).f_locals
print stuff

Prints:

{'__builtins__': ,
'__file__': 'C:\\Documents and SettingsMy Documents\
\python\\moduleA.py',
'__name__': '__main__',
'__doc__': None}

Looks like you could query stuff['__file__'] to pull what you're
after.
?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Writing an emulator in python - implementation questions (for performance)

2009-11-12 Thread Santiago Romero
> You can do clever memory slicing like this with numpy.  For instance:
>
> breg = numpy.zeros((16,),numpy.uint8)
> wreg = numpy.ndarray((8,),numpy.uint16,breg)
>
> This causes breg and wreg to share the same 16 bytes of memory.  You
> can define constants to access specific registers:

 What I'm doing wrong?

[srom...@compiler:~]$ cat test.py
#!/usr/bin/python

import numpy

# Register array
breg = numpy.zeros((16,),numpy.uint8)
wreg = numpy.ndarray((8,), numpy.uint16, breg )

reg_A   = 1
reg_F   = 2
reg_AF  = 1
reg_B   = 3
reg_C   = 4
reg_BC  = 3

breg[reg_B] = 5
breg[reg_C] = 10
print breg[reg_B]
print breg[reg_C]
print wreg[reg_BC]


[srom...@compiler:~]$ python test.py
5
10
0

 ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: #define (from C) in Python

2009-11-12 Thread Stefan Behnel
Santiago Romero, 12.11.2009 18:23:
> #define LD_r_n(reg) (reg) = Z80ReadMem(r_PC++)
> 
> #define LD_rr_nn(reg)   r_opl = Z80ReadMem(r_PC); r_PC++; \
> r_oph = Z80ReadMem(r_PC); r_PC++; \
> reg = r_op
> 
> #define LOAD_r(dreg, saddreg)   (dreg)=Z80ReadMem((saddreg))
> 
> #define LOAD_rr_nn(dreg)   r_opl = Z80ReadMem(r_PC); r_PC++; \
>r_oph = Z80ReadMem(r_PC); r_PC++; \
>r_tmpl = Z80ReadMem(r_op); \
>r_tmph = Z80ReadMem((r_op)+1); \
>dreg=r_tmp
> 
> #define STORE_nn_rr(dreg) \
> r_opl = Z80ReadMem(r_PC); r_PC++;\
> r_oph = Z80ReadMem(r_PC); r_PC++; \
> r_tmp = dreg; \
> Z80WriteMem((r_op),r_tmpl, regs); \
> Z80WriteMem((r_op+1),r_tmph, regs)
> 
>  But it seems that is not possible :-(

As Michele said, this is a micro optimisation, likely premature. A function
is usually good enough for this. If you need more speed (and you seem to be
targeting direct memory access or something like that), take a look at Cython.

Stefan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python simply not scaleable enough for google?

2009-11-12 Thread J Kenneth King
mcherm  writes:

> On Nov 11, 7:38 pm, Vincent Manis  wrote:
>> 1. The statement `Python is slow' doesn't make any sense to me.
>> Python is a programming language; it is implementations that have
>> speed or lack thereof.
>[...]
>> 2. A skilled programmer could build an implementation that compiled
>> Python code into Common Lisp or Scheme code, and then used a
>> high-performance Common Lisp compiler...
>
> I think you have a fundamental misunderstanding of the reasons why
> Python is
> slow. Most of the slowness does NOT come from poor implementations:
> the CPython
> implementation is extremely well-optimized; the Jython and Iron Python
> implementations use best-in-the-world JIT runtimes. Most of the speed
> issues
> come from fundamental features of the LANGUAGE itself, mostly ways in
> which
> it is highly dynamic.
>
> In Python, a piece of code like this:
> len(x)
> needs to watch out for the following:
> * Perhaps x is a list OR
>   * Perhaps x is a dict OR
>   * Perhaps x is a user-defined type that declares a __len__
> method OR
>   * Perhaps a superclass of x declares __len__ OR
> * Perhaps we are running the built-in len() function OR
>   * Perhaps there is a global variable 'len' which shadows the
> built-in OR
>   * Perhaps there is a local variable 'len' which shadows the
> built-in OR
>   * Perhaps someone has modified __builtins__
>
> In Python it is possible for other code, outside your module to go in
> and
> modify or replace some methods from your module (a feature called
> "monkey-patching" which is SOMETIMES useful for certain kinds of
> testing).
> There are just so many things that can be dynamic (even if 99% of the
> time
> they are NOT dynamic) that there is very little that the compiler can
> assume.
>
> So whether you implement it in C, compile to CLR bytecode, or
> translate into
> Lisp, the computer is still going to have to to a whole bunch of
> lookups to
> make certain that there isn't some monkey business going on, rather
> than
> simply reading a single memory location that contains the length of
> the list.
> Brett Cannon's thesis is an example: he attempted desperate measures
> to
> perform some inferences that would allow performing these
> optimizations
> safely and, although a few of them could work in special cases, most
> of the
> hoped-for improvements were impossible because of the dynamic nature
> of the
> language.
>
> I have seen a number of attempts to address this, either by placing
> some
> restrictions on the dynamic nature of the code (but that would change
> the
> nature of the Python language) or by having some sort of a JIT
> optimize the
> common path where we don't monkey around. Unladen Swallow and PyPy are
> two
> such efforts that I find particularly promising.
>
> But it isn't NEARLY as simple as you make it out to be.
>
> -- Michael Chermside

You might be right for the wrong reasons in a way.

Python isn't slow because it's a dynamic language.  All the lookups
you're citing are highly optimized hash lookups.  It executes really
fast.

The OP is talking about scale.  Some people say Python is slow at a
certain scale.  I say that's about true for any language.  Large amounts
of IO is a tough problem.

Where Python might get hit *as a language* is that the Python programmer
has to drop into C to implement optimized data-structures for dealing
with the kind of IO that would slow down the Python interpreter.  That's
why we have numpy, scipy, etc.  The special cases it takes to solve
problems with custom types wasn't special enough to alter the language.
Scale is a special case believe it or not.

As an implementation though, the sky really is the limit and Python is
only getting started.  Give it another 40 years and it'll probably
realize that it's just another Lisp. ;)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python simply not scaleable enough for google?

2009-11-12 Thread Alf P. Steinbach

* Steven D'Aprano:

On Thu, 12 Nov 2009 08:35:23 -0800, Joel Davis wrote:

obviously the GIL is a major reason it's so slow. 



http://en.wikipedia.org/wiki/Global_Interpreter_Lock

Uh oh...



No such "obviously" about it.

There have been attempts to remove the GIL, and they lead to CPython 
becoming *slower*, not faster, for the still common case of single-core 
processors.


And neither Jython nor IronPython have the GIL. Jython appears to scale 
slightly better than CPython, but for small data sets, is slower than 
CPython. IronPython varies greatly in performance, ranging from nearly 
twice as fast as CPython on some benchmarks to up to 6000 times slower!


http://www.smallshire.org.uk/sufficientlysmall/2009/05/22/ironpython-2-0-and-jython-2-5-performance-compared-to-python-2-5/

http://ironpython-urls.blogspot.com/2009/05/python-jython-and-ironpython.html


Blaming CPython's supposed slowness


Hm, this seems religious.

Of course Python is slow: if you want speed, pay for it by complexity.

It so happens that I think CPython could have been significantly faster, but (1) 
doing that would amount to creating a new implementation, say, C++Python , 
and (2) what for, really?, since CPU-intensive things should be offloaded to 
other language code anyway.



on the GIL is superficially plausible 
but doesn't stand up to scrutiny. The speed of an implementation depends 
on many factors, and it also depends on *what you measure* -- it is sheer 
nonsense to talk about "the" speed of an implementation. Different tasks 
run at different speeds, and there is no universal benchmark.


This also seems religious. It's like in Norway it became illegal to market lemon 
soda, since umpteen years ago it's soda with lemon flavoring. This has to do 
with the *origin* of the citric acid, whether natural or chemist's concoction, 
no matter that it's the same chemical. So, some people think that it's wrong to 
talk about interpreted languages, hey, it should be a "language designed for 
interpretation", or better yet, "dynamic language", or bestest, "language with 
dynamic flavor". And slow language, oh no, should be "language whose current 
implementations are perceived as somewhat slow by some (well, all) people", but 
of course, that's just silly.



Cheers,

- Alf
--
http://mail.python.org/mailman/listinfo/python-list


Re: #define (from C) in Python

2009-11-12 Thread Santiago Romero
On 12 nov, 18:16, Stefan Behnel  wrote:
> Santiago Romero, 12.11.2009 17:43:
>
> > Is there a Python version of C's language #define statements?
>
> > Example:
>
> > #define ReadMem( (x) )    memory[ (x) ]
>
> Yes:
>
>         ReadMem = memory.__getitem__
>
> Stefan


 Well, In the above concrete example, that would work, but I was
talking for multiple code lines, like:


#define LD_r_n(reg) (reg) = Z80ReadMem(r_PC++)

#define LD_rr_nn(reg)   r_opl = Z80ReadMem(r_PC); r_PC++; \
r_oph = Z80ReadMem(r_PC); r_PC++; \
reg = r_op

#define LOAD_r(dreg, saddreg)   (dreg)=Z80ReadMem((saddreg))

#define LOAD_rr_nn(dreg)   r_opl = Z80ReadMem(r_PC); r_PC++; \
   r_oph = Z80ReadMem(r_PC); r_PC++; \
   r_tmpl = Z80ReadMem(r_op); \
   r_tmph = Z80ReadMem((r_op)+1); \
   dreg=r_tmp

#define STORE_nn_rr(dreg) \
r_opl = Z80ReadMem(r_PC); r_PC++;\
r_oph = Z80ReadMem(r_PC); r_PC++; \
r_tmp = dreg; \
Z80WriteMem((r_op),r_tmpl, regs); \
Z80WriteMem((r_op+1),r_tmph, regs)


 But it seems that is not possible :-(
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ask a question about the module

2009-11-12 Thread Daniel Fetchinson
> Could not import module "Gnuplot" - it is not installed on your
> system. You need to install the Gnuplot.py package.
> \easyviz\gnuplot_.py(41) :
> Traceback (most recent call last):
>   File "E:\study\python\commodity modle 10.23.py", line 3, in 
> import multipleloop as mp
>   File "E:\study\python\multipleloop.py", line 81, in 
> from scitools.misc import str2obj
>   File "C:\Python26\lib\site-packages\scitools\__init__.py", line 67,
> in 
> import sys, std
>   File "C:\Python26\lib\site-packages\scitools\std.py", line 26, in
> 
> from scitools.easyviz import *
>   File "C:\Python26\lib\site-packages\scitools\easyviz\__init__.py",
> line 1819, in 
> exec(cmd)
>   File "", line 1, in 
>   File "C:\Python26\lib\site-packages\scitools\easyviz\gnuplot_.py",
> line 42, in 
> import Gnuplot
> ImportError: No module named Gnuplot
>
>
> the above is the hint from python window, I know Gnuplot is a software
> and it can help us to make graphs, however, after I download Gnuplot
> and run it, the problem still exist. Is there any expert can help me
> solve this problem?
> Thank you very much!


Did you also install the python bindings for gnuplot? If not, you can
get it from
http://gnuplot-py.sourceforge.net/

HTH,
Daniel
-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >