Re: Input() in Python3

2011-04-21 Thread Chris Angelico
On Fri, Apr 22, 2011 at 4:49 PM, Chris Angelico  wrote:
> U NO. NO NO NO. What if someone enters "os.exit()" as their
> number? You shouldn't eval() unchecked user input!

Whoops, I meant sys.exit() - but you probably knew that already.

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


Re: Input() in Python3

2011-04-21 Thread Chris Angelico
On Fri, Apr 22, 2011 at 4:22 PM, harrismh777  wrote:
> now we get this for input():
>
>   raw_input("prompt>") --> string

I would have to say that the 2.x behaviour of input() is a mistake
that's being corrected in 3.x. With a simple name like input(), it
should do something simple and straightforward - not eval() the
expression.

> to:        a = eval(input("enter a number > "))

U NO. NO NO NO. What if someone enters "os.exit()" as their
number? You shouldn't eval() unchecked user input!

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


Re: learnpython.org - an online interactive Python tutorial

2011-04-21 Thread harrismh777

Heiko Wundram wrote:

The difference between strong typing and weak typing is best described by:

Python 2.6.5 (r265:79063, Jun 12 2010, 17:07:01)
[GCC 4.3.4 20090804 (release) 1] on cygwin
Type "help", "copyright", "credits" or "license" for more information.

>>>  1+'2'

Traceback (most recent call last):
   File "", line 1, in
TypeError: unsupported operand type(s) for +: 'int' and 'str'

>>>


Yes. And you have managed to point out a serious flaw in the overall 
logic and consistency of Python, IMHO.


Strings should auto-type-promote to numbers if appropriate.

This behavior should occur in input() as well. If a 'number' string is 
entered and can be converted to a Python number (whatever I mean by that 
at the moment) then the string should be converted to a number (int or 
float as appropriate) and the input() should return a reference to the 
number type  ( a value );  otherwise, input() should return the string 
entered, or throw a type error.


If an operation like (+) is used to add  1 + '1' then the string should 
be converted to int and the addition should take place, returning a 
reference to object int (2).



My feelings about this are strongly influenced by my experiences with 
the REXX language on IBM's SAA systems--- OS/2 and VM/CMS. In REXX 
everything is a string... everything. If a string just happens to be a 
REXX number, then it can be manipulated as you might expect for a 
number.  Neither here, nor there... just that I believe Python could 
take advantage of the "Python Number" concept and provide for auto-type 
casting of string to number (int or float) as appropriate if the string 
meets the Python Number requirements.


Just an idea... again, probably got beat up long before my time, I'm 
guessing...



kind regards,
m harris



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


Re: dictionary size changed during iteration

2011-04-21 Thread John Nagle

On 4/20/2011 5:52 AM, Laszlo Nagy wrote:

Given this iterator:

class SomeIterableObject(object):



def __iter__(self):
ukeys = self.updates.keys()
for key in ukeys:
if self.updates.has_key(key):
yield self.updates[key]
for rec in self.inserts:
yield rec



How can I get this exception:

RuntimeError: dictionary changed size during iteration


It is true that self.updates is being changed during the iteration. But
I have created the "ukeys" variable solely to prevent this kind of
error. Here is a proof of correctness:


   I think we need to see some more code here.

   Also, what version of Python are you running?

http://docs.python.org/library/stdtypes.html

says "keys()
Return a copy of the dictionary’s list of keys."

So "ukeys" should be a unique list, not some part of
self.updates or a generator.

At least in Python 2.6, keys() does return a unique list.  Each
call to "keys()" returns a new list object unconnected to the
dictionary from which the keys were extracted.  But someone may
have decided in a later version to return a generator, as
an optimization.  Did that happen?

John Nagle


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


Input() in Python3

2011-04-21 Thread harrismh777
My interactive scripts are giving errors on the input(). I discovered 
another fairly significant change in Python3, as discussed in PEP 3111.


I was a little flabbergasted to discover that input() was proposed to be 
removed 'totally' from 3000. Of course I agree with PEP 3111 and am 
thankful that input() is still a built-in.  doh.


The problem is that the behavior was significantly changed, again, 
causing existing code to break un-necessarily. So, input() used to be 
equivalent to:


   eval(raw_input("prompt>")) --> value


now we get this for input():


   raw_input("prompt>") --> string


I'm not whining or anything, just wondering why? Could someone enlighten 
me please?


Anyway, it looks like the best fix for 2.x --> 3.x  code changes:

change:a = input("enter a number > ")

to:a = eval(input("enter a number > "))


Again, this is just another example where leaving the advertised 
interface alone would have made more sense... unless of course, I'm 
missing something important here.


kind regards,
m harris

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


Re: Teaching Python

2011-04-21 Thread harrismh777

Westley Martínez wrote:

But really, hack

 >has always been a negative term.  It's original definition is chopping,
 >breaking down, kind of like chopping down the security on someone elses
 >computer.  Now I don't know where the term originally came from, but the
 >definition the media uses is quite a fair use.



Not so much...

... the term hacker was coined at the MIT lab back in the days of the 
PDP-10 /11.   We can thank RMS, and friends.



http://stallman.org/cgi-bin/showpage.cgi?path=/articles/on-hacking.html&term=hacking&type=norm&case=0


RMS coined the term "Cracker" for the pejorative use.

Hackers cause no harm; ever.   Hackers are elegant ethical people who 
love the craft for the sake of the craft and the beauty of their art.


Hackers do have a disdain for "Herbert," (if you're a Trek-ie you know 
what I mean)...and hackers love to taunt Herbert...


Herbert...!  Herbert...!  Herbert...!

 /\
/  \


Hackers are free and insist on freedom. Hackers would rather count on 
their fingers than be forced to use proprietary closed systems and 
software.  Hackers have no use for IBM, nor Microsoft.  (nor google)



I am and forever will be a joyful hacker   :)




PS   The media is clueless...   (Herbert... Herbert... Herbert...)




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


Re: Teaching Python

2011-04-21 Thread harrismh777

MRAB wrote:


A computer hacker doesn't write the requirements of the software or
draw Jackson Structured Programming diagrams, etc, but just thinks
about what's needed and starts writing the code.


Very close...

... hackers don't necessarily care what something was designed to do, 
only what can be done with it...


... hackers love to push the envelope, playfully explore the full range 
of possibilities, and especially they delight to think outside the box 
(outside the frameworks of conformity and mediocrity)...


... hackers are philosophers and poets, and often musicians. Hackers 
write code because its beautiful, not because they're paid for it... 
hackers are can-do people who don't give a flying rip when they're told 
they can't !  ...  yeah, watch me.  :)


kind regards,
m harris

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


Re: Teaching Python

2011-04-21 Thread harrismh777

MRAB wrote:

That's a cowboy coder.


A cowboy coder is someone who's bad at coding, a hacker is someone
who's good at it.


A hacker is someone who loves to code and doesn't really care whether 
anyone else thinks they're really at it or not... although, yes, they 
generally are *very* good at it...


:)



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


Re: Closing generators

2011-04-21 Thread Terry Reedy

On 4/21/2011 9:14 PM, Thomas Rachel wrote:

Hi folks,

it is possible to close a generator. That is (among others) for the
following case:

I run a for loop over the iterator, but then I break it. Now I can leave
the generator to the GC (which is AFAI have been told a thing which I
should not do), or I can clean up myself.


That is very rarely necessary. generator.close was added so that one 
could tell the generator to close anything opened within the generator, 
such as a file, that needs to be explicitly closed.



Example:

for i in g:
if i is not None:
g.close()
return i


When returning from the function, g, if local, should disappear.

--
Terry Jan Reedy

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


Re: Snowball to Python compiler

2011-04-21 Thread Terry Reedy

On 4/21/2011 8:25 PM, Paul Rubin wrote:

Matt Chaput  writes:

I'm looking for some code that will take a Snowball program and
compile it into a Python script. Or, less ideally, a Snowball
interpreter written in Python.

(http://snowball.tartarus.org/)

Anyone heard of such a thing?


I never saw snowball before, it looks kind of interesting, and it
looks like it already has a way to compile to C.  If you're using
it for IR on any scale, you're surely much better off using the C
routines with a C API wrapper,


If the C routines are in a shared library, you should be able to write 
the interface in Python with ctypes.



than translating snowball to
Python, which will be dog slow to interpret.



--
Terry Jan Reedy

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


Re: learnpython.org - an online interactive Python tutorial

2011-04-21 Thread Diego Arias
On Thu, Apr 21, 2011 at 8:20 PM, Dan Stromberg  wrote:

>
> On Thu, Apr 21, 2011 at 9:13 AM, MRAB  wrote:
>
>> On 21/04/2011 15:14, Westley Martínez wrote:
>>
>>> On Thu, Apr 21, 2011 at 05:19:29PM +1000, Chris Angelico wrote:
>>>
 On Thu, Apr 21, 2011 at 5:10 PM, Algis Kabaila
  wrote:

> False: Python IS strongly typed, without doubt (though the
> variables are not explicitly declared.)
>

 Strongly duck-typed though. If I create a class that has all the right
 members, it can simultaneously be a file, an iterable, a database, and
 probably even a web browser if it feels like it. Is that strong typing
 or not?

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

>>>
>>> It's strong typing.  Python does not implicitly convert types.  Weak
>>> typing is
>>> when I can do 1 + "1" and get 2.
>>>
>>
>> It could be argued that it does implicit convert for some numeric
>> types, eg int to float when needed.
>
>
> Yes, it'll silently promote int to float, int to Decimal, and also almost
> anything can be used in a Boolean context.  No other exceptions to strong
> typing come to mind...
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
> Hi:

Really nice site, keep it going


-- 
Still Going Strong!!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A question about Python Classes

2011-04-21 Thread Steven D'Aprano
On Thu, 21 Apr 2011 19:00:08 +0100, MRAB wrote:

>>> How can HomeHandler call foo() when I never created an instance of
>>> BaseHandler?
>>
>> But you created one!
>>
> No, he didn't, he created an instance of HomeHandler.
> 
>> test is an instance of HomeHandler, which is a subclass of BaseHandler,
>> so test is also an instance of BaseHandler.
>>
> test isn't really an instance of BaseHandler, it's an instance of
> HomeHandler, which is a subclass of BaseHandler.

Which *also* makes it an instance of BaseHandler. You are a human being, 
which also makes you a mammal. It would be *wrong* to say that you're not 
a mammal, just because you're a human being.

But to answer the Original Poster's question... you don't need a formal 
BaseHandler instance because that's how inheritance is designed to work. 
Each class knows its own parent classes, and when you call test.foo(), 
Python walks the chain of:

instance
instance's class
each of the parent class(es) (if any)

looking for a match for foo, and then calls it appropriately. This is 
called inheritance: HomeHandler inherits behaviour from BaseHandler.

(The details are a little more complex than the sketch above, but broadly 
equivalent.)



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


Re: Argument count mismatch

2011-04-21 Thread Steven D'Aprano
On Thu, 21 Apr 2011 12:33:09 -0700, RVince wrote:

> I am getting the following:
> 
> Error - : cmseditorlinemethod() takes
> exactly 2 arguments (1 given)
> 
> When I make the following call:
> 
> http://localhost/eligibility/cmseditorlinemethod/474724434

That's not a call, that's a URL. It's also a link to localhost, which is 
*your* computer and not visible to us.

How about actually showing us the *actual call* you make? Cut and paste 
the line of code that calls cmseditorlinemethod, showing the arguments.

My *guess* is that you're calling it without providing any arguments:

instance.cmseditorlinemethod()

Python automatically injects the `self` argument, but it requires two: 
self and ssn:

> def cmseditorlinemethod(self, ssn):
[...]


An alternative explanation: you don't use `self` in the body of 
cmseditorlinemethod. Possibly cmseditorlinemethod is actually a stand-
alone function rather than a method, and you are calling it like this:

cmseditorlinemethod(ssn)

but you have mistakenly declared the function to take two arguments.

Really, the error message is quite explicit in your problem: you have one 
argument given, but two arguments are required. The only subtlety is that 
for method calls, the `self` argument is automatically provided rather 
than manually, but once you've learned that quirk of Python, what else do 
you need to know to solve this problem?

By the way, I know this is unsolicited advice, but I'm going to give it 
anyway. Look at your function:


def cmseditorlinemethod(self, ssn):
c.details = Session.query(MSPResponse).filter(
MSPResponse.beneficiaryssn == ssn).all()
content = render('/cmseditorline.mako')
return content


It looks to me like this function relies on no fewer than three global 
variables, two that you read from and one which you write to:

c
Session
MSPResponse

This is almost certainly poor design. Using global state is almost always 
harmful and should be avoided. 

(I don't include `render` in this, as using global functions is normally 
harmless.)

http://c2.com/cgi/wiki?GlobalVariablesAreBad



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


Re: Vectors

2011-04-21 Thread Gregory Ewing

Algis Kabaila wrote:
the Vector3 class 
is available without any prefix euclid:


import euclid 
v = Vector3(111.., 222.2, 333.3)


Doesn't work that way for me:

Python 2.7 (r27:82500, Oct 15 2010, 21:14:33)
[GCC 4.2.1 (Apple Inc. build 5664)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import euclid
>>> Vector3
Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'Vector3' is not defined

Are you sure you hadn't previously done 'from euclid import
Vector3' or 'from euclid import *' in that session?

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


Re: Teaching Python

2011-04-21 Thread Westley Martínez
On Fri, Apr 22, 2011 at 01:25:00AM +0100, MRAB wrote:
> On 21/04/2011 23:36, Westley Martínez wrote:
> >On Thu, Apr 21, 2011 at 05:11:32PM +0100, MRAB wrote:
> >>On 21/04/2011 14:58, Westley Martínez wrote:
> >>>On Thu, Apr 21, 2011 at 06:02:08AM +0200, Stefan Behnel wrote:
> Ben Finney, 20.04.2011 02:06:
> >Dan Stromberg writes:
> >
> >>On Tue, Apr 19, 2011 at 4:03 PM, geremy condra wrote:
> >>>When you say 'hacking', you mean ?
> >>
> >>Presumably he meant the real meaning of the word, not what the press
> >>made up and ran with.
> >
> >To be fair, the press already had its own pejorative meaning of “hack”
> >before the engineering and computing term
> 
> Not anywhere outside of the English language that I'm aware of,
> though. In German, it's a computing-only term that's used in both
> contexts by those who understand why the pointer is moving over the
> screen when moving the mouse, and almost exclusively in a bad
> context by those who write news paper articles (and, consequently,
> by those who innocently read them).
> 
> Stefan
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
> >>>
> >>>O Lord, I'd hope we'd be speaking for English here.  But really, hack
> >>>has always been a negative term.  It's original definition is chopping,
> >>>breaking down, kind of like chopping down the security on someone elses
> >>>computer.  Now I don't know where the term originally came from, but the
> >>>definition the media uses is quite a fair use.  Why should we call
> >>>ourselves hackers anyways?  I don't smoke.  I'm no different from anyone
> >>>else, I just happen to know a lot about computers.  Should we call
> >>>people who know a lot about the economy hackers, too, or perhaps we
> >>>should call them economists
> >>
> >>As I understand it, "hacking" is about not doing the job "properly".
> >>When trying to make something, a hacker will use the equivalent of duct
> >>tape to hold things together.
> >>
> >>A computer hacker doesn't write the requirements of the software or
> >>draw Jackson Structured Programming diagrams, etc, but just thinks
> >>about what's needed and starts writing the code.
> >
> >That's a cowboy coder.
> 
> A cowboy coder is someone who's bad at coding, a hacker is someone
> who's good at it.

Wrong, sir!  Wrong!  Cowboys are awesome.
-- 
http://mail.python.org/mailman/listinfo/python-list


Closing generators

2011-04-21 Thread Thomas Rachel

Hi folks,

it is possible to close a generator. That is (among others) for the 
following case:


I run a for loop over the iterator, but then I break it. Now I can leave 
the generator to the GC (which is AFAI have been told a thing which I 
should not do), or I can clean up myself.


Example:

for i in g:
  if i is not None:
g.close()
return i

or better

try:
  for i in g:
if i is not None:
  return i
finally:
  g.close()

or even better

with contextlib.closing(g):
  for i in g:
if i is not None:
  return i

How do you do that in this case - do you just drop the generator, or do 
you close it? (Beware of exceptions which could happen!) Till now, I 
used to just drop it, but now I am thinking about if it is good style or 
not...


Another question: AFAICT generator.close() was introduced at about the 
same time as the with statement. Was a matching context manager 
deliberately left away, or just forgotten? It is fine to work with 
"with" on a file or other closable object - why not on a generator, 
without contextlib.closing()?



TIA,

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


Re: learnpython.org - an online interactive Python tutorial

2011-04-21 Thread Dan Stromberg
On Thu, Apr 21, 2011 at 9:13 AM, MRAB  wrote:

> On 21/04/2011 15:14, Westley Martínez wrote:
>
>> On Thu, Apr 21, 2011 at 05:19:29PM +1000, Chris Angelico wrote:
>>
>>> On Thu, Apr 21, 2011 at 5:10 PM, Algis Kabaila
>>>  wrote:
>>>
 False: Python IS strongly typed, without doubt (though the
 variables are not explicitly declared.)

>>>
>>> Strongly duck-typed though. If I create a class that has all the right
>>> members, it can simultaneously be a file, an iterable, a database, and
>>> probably even a web browser if it feels like it. Is that strong typing
>>> or not?
>>>
>>> Chris Angelico
>>> --
>>> http://mail.python.org/mailman/listinfo/python-list
>>>
>>
>> It's strong typing.  Python does not implicitly convert types.  Weak
>> typing is
>> when I can do 1 + "1" and get 2.
>>
>
> It could be argued that it does implicit convert for some numeric
> types, eg int to float when needed.


Yes, it'll silently promote int to float, int to Decimal, and also almost
anything can be used in a Boolean context.  No other exceptions to strong
typing come to mind...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: About threads in python

2011-04-21 Thread Dan Stromberg
On Thu, Apr 21, 2011 at 6:19 AM, dutche  wrote:

> Hi folks, how are ya?
>
> Here's the thing...I had to make a program with threads and after
> finished, I found some posts and articles in Google about Python and
> threads, raising the question about if it really implements thread
> programming or not, because of GIL and the way Python needs to lock
> some objects.
>

http://wiki.python.org/moin/Concurrency

Either all or nearly all Python implementations have threading, but for some
implementations and some workloads, multithreading is not as effective as
multiprocessing.

Don't try to program in Python as though it's whatever other language you're
coming from.  It's better to learn each language's own strengths and
weaknesses, and work with them rather than against them.

EG: You shouldn't do list processing in FORTRAN, even if you were once a
Lisp programmer.  There are equivalent ways of achieving the same goals in
FORTRAN, if you're willing to give up your Lisp influence though.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is there a difference between one line and many lines

2011-04-21 Thread Steven D'Aprano
On Thu, 21 Apr 2011 14:35:25 +0200, Peter Otten wrote:

> Steven D'Aprano wrote:
> 
>> but:
>> 
> a = 1001; b = 10001; a is b
>> False
> 
> I would hope so ;)

Doh!


>> The point is that Python is free to re-use immutable objects, or not
>> re- use them, as it sees fit.
>  
> Indeed, and I even found a Python implementation on my harddisk that
> does what you intended to show:
> 
> $ ipy
> IronPython 1.1.1 (1.1.1) on .NET 2.0.50727.1433 Copyright (c) Microsoft
> Corporation. All rights reserved.
 a = 1001; b = 1001; a is b
> False

Much better, thank you :)




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


Re: Snowball to Python compiler

2011-04-21 Thread Paul Rubin
Matt Chaput  writes:
> I'm looking for some code that will take a Snowball program and
> compile it into a Python script. Or, less ideally, a Snowball
> interpreter written in Python.
>
> (http://snowball.tartarus.org/)
>
> Anyone heard of such a thing?

I never saw snowball before, it looks kind of interesting, and it
looks like it already has a way to compile to C.  If you're using
it for IR on any scale, you're surely much better off using the C
routines with a C API wrapper, than translating snowball to
Python, which will be dog slow to interpret.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Teaching Python

2011-04-21 Thread MRAB

On 21/04/2011 23:36, Westley Martínez wrote:

On Thu, Apr 21, 2011 at 05:11:32PM +0100, MRAB wrote:

On 21/04/2011 14:58, Westley Martínez wrote:

On Thu, Apr 21, 2011 at 06:02:08AM +0200, Stefan Behnel wrote:

Ben Finney, 20.04.2011 02:06:

Dan Stromberg writes:


On Tue, Apr 19, 2011 at 4:03 PM, geremy condra wrote:

When you say 'hacking', you mean ?


Presumably he meant the real meaning of the word, not what the press
made up and ran with.


To be fair, the press already had its own pejorative meaning of “hack”
before the engineering and computing term


Not anywhere outside of the English language that I'm aware of,
though. In German, it's a computing-only term that's used in both
contexts by those who understand why the pointer is moving over the
screen when moving the mouse, and almost exclusively in a bad
context by those who write news paper articles (and, consequently,
by those who innocently read them).

Stefan

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


O Lord, I'd hope we'd be speaking for English here.  But really, hack
has always been a negative term.  It's original definition is chopping,
breaking down, kind of like chopping down the security on someone elses
computer.  Now I don't know where the term originally came from, but the
definition the media uses is quite a fair use.  Why should we call
ourselves hackers anyways?  I don't smoke.  I'm no different from anyone
else, I just happen to know a lot about computers.  Should we call
people who know a lot about the economy hackers, too, or perhaps we
should call them economists


As I understand it, "hacking" is about not doing the job "properly".
When trying to make something, a hacker will use the equivalent of duct
tape to hold things together.

A computer hacker doesn't write the requirements of the software or
draw Jackson Structured Programming diagrams, etc, but just thinks
about what's needed and starts writing the code.


That's a cowboy coder.


A cowboy coder is someone who's bad at coding, a hacker is someone
who's good at it.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Snowball to Python compiler

2011-04-21 Thread Matt Chaput

A third (more-than-) possible solution: google("python snowball");
the first page of results has at least 3 hits referring to Python
wrappers for Snowball.


There are quite a few wrappers for the C-compiled snowball stemmers, but 
I'm looking for a pure-Python solution. It doesn't seem like there is 
such a thing, but I figured I'd take a shot here before I think about 
doing it myself :/


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


Re: Snowball to Python compiler

2011-04-21 Thread John Machin

On Friday, April 22, 2011 8:05:37 AM UTC+10, Matt Chaput wrote:

> I'm looking for some code that will take a Snowball program and compile 
> it into a Python script. Or, less ideally, a Snowball interpreter 
> written in Python.
> 
> (http://snowball.tartarus.org/)

If anyone has done such things they are not advertising them in the usual 
places.

A third (more-than-) possible solution: google("python snowball"); the first 
page of results has at least 3 hits referring to Python wrappers for Snowball.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Argument count mismatch

2011-04-21 Thread Westley Martínez
On Thu, Apr 21, 2011 at 12:33:09PM -0700, RVince wrote:
> I am getting the following:
> 
> Error - : cmseditorlinemethod() takes
> exactly 2 arguments (1 given)
> 
> When I make the following call:
> 
> http://localhost/eligibility/cmseditorlinemethod/474724434
> 
> Which invokes:
> 
> def cmseditorlinemethod(self, ssn):
> c.details =
> Session.query(MSPResponse).filter(MSPResponse.beneficiaryssn ==
> ssn).all()
> content = render('/cmseditorline.mako')
> return content
> 
> Can anyone tell me what the mismatch is in the number of my parameters
> based on this? Thanks, RVince

There's no way to see that link without knowing a domainname or IP.
localhost only works locally, go figure, but regardless I'd suspect that
you need to give two arguments instead of one, considering that's what
the error message said.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Teaching Python

2011-04-21 Thread Westley Martínez
On Thu, Apr 21, 2011 at 05:11:32PM +0100, MRAB wrote:
> On 21/04/2011 14:58, Westley Martínez wrote:
> >On Thu, Apr 21, 2011 at 06:02:08AM +0200, Stefan Behnel wrote:
> >>Ben Finney, 20.04.2011 02:06:
> >>>Dan Stromberg writes:
> >>>
> On Tue, Apr 19, 2011 at 4:03 PM, geremy condra wrote:
> >When you say 'hacking', you mean ?
> 
> Presumably he meant the real meaning of the word, not what the press
> made up and ran with.
> >>>
> >>>To be fair, the press already had its own pejorative meaning of “hack”
> >>>before the engineering and computing term
> >>
> >>Not anywhere outside of the English language that I'm aware of,
> >>though. In German, it's a computing-only term that's used in both
> >>contexts by those who understand why the pointer is moving over the
> >>screen when moving the mouse, and almost exclusively in a bad
> >>context by those who write news paper articles (and, consequently,
> >>by those who innocently read them).
> >>
> >>Stefan
> >>
> >>--
> >>http://mail.python.org/mailman/listinfo/python-list
> >
> >O Lord, I'd hope we'd be speaking for English here.  But really, hack
> >has always been a negative term.  It's original definition is chopping,
> >breaking down, kind of like chopping down the security on someone elses
> >computer.  Now I don't know where the term originally came from, but the
> >definition the media uses is quite a fair use.  Why should we call
> >ourselves hackers anyways?  I don't smoke.  I'm no different from anyone
> >else, I just happen to know a lot about computers.  Should we call
> >people who know a lot about the economy hackers, too, or perhaps we
> >should call them economists
> 
> As I understand it, "hacking" is about not doing the job "properly".
> When trying to make something, a hacker will use the equivalent of duct
> tape to hold things together.
> 
> A computer hacker doesn't write the requirements of the software or
> draw Jackson Structured Programming diagrams, etc, but just thinks
> about what's needed and starts writing the code.

That's a cowboy coder.
-- 
http://mail.python.org/mailman/listinfo/python-list


Snowball to Python compiler

2011-04-21 Thread Matt Chaput
On the slim chance that (a) somebody worked on something like this but 
never uploaded it to PyPI, and (b) the person who did (a) or heard about 
it is reading this list ;) --


I'm looking for some code that will take a Snowball program and compile 
it into a Python script. Or, less ideally, a Snowball interpreter 
written in Python.


(http://snowball.tartarus.org/)

Anyone heard of such a thing?

Thanks!

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


Re: Argument count mismatch

2011-04-21 Thread John Gordon
In  RVince 
 writes:

> def cmseditorlinemethod(self, ssn):
> c.details =
> Session.query(MSPResponse).filter(MSPResponse.beneficiaryssn ==
> ssn).all()
> content = render('/cmseditorline.mako')
> return content

Is cmseditorlinemethod() a member of a class?  The presence of the "self"
parameter suggests that it is, but your code omits this detail.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Finding empty columns. Is there a faster way?

2011-04-21 Thread Jon Clements
On Apr 21, 5:40 pm, nn  wrote:
> time head -100 myfile  >/dev/null
>
> real    0m4.57s
> user    0m3.81s
> sys     0m0.74s
>
> time ./repnullsalt.py '|' myfile
> 0 1 Null columns:
> 11, 20, 21, 22, 23, 24, 25, 26, 27, 30, 31, 33, 45, 50, 68
>
> real    1m28.94s
> user    1m28.11s
> sys     0m0.72s
>
> import sys
> def main():
>     with open(sys.argv[2],'rb') as inf:
>         limit = sys.argv[3] if len(sys.argv)>3 else 1
>         dlm = sys.argv[1].encode('latin1')
>         nulls = [x==b'' for x in next(inf)[:-1].split(dlm)]
>         enum = enumerate
>         split = bytes.split
>         out = sys.stdout
>         prn = print
>         for j, r in enum(inf):
>             if j%100==0:
>                 prn(j//100,end=' ')
>                 out.flush()
>                 if j//100>=limit:
>                     break
>             for i, cur in enum(split(r[:-1],dlm)):
>                 nulls[i] |= cur==b''
>     print('Null columns:')
>     print(', '.join(str(i+1) for i,val in enumerate(nulls) if val))
>
> if not (len(sys.argv)>2):
>     sys.exit("Usage: "+sys.argv[0]+
>          "   ")
>
> main()


What's with the aliasing enumerate and print??? And on heavy disk IO I
can hardly see that name lookups are going to be any problem at all?
And why the time stats with /dev/null ???


I'd probably go for something like:

import csv

with open('somefile') as fin:
nulls = set()
for row in csv.reader(fin, delimiter='|'):
nulls.update(idx for idx,val in enumerate(row, start=1) if not
val)
print 'nulls =', sorted(nulls)

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


Re: Argument count mismatch

2011-04-21 Thread Chris Angelico
On Fri, Apr 22, 2011 at 5:33 AM, RVince  wrote:
> I am getting the following:
>
> Error - : cmseditorlinemethod() takes
> exactly 2 arguments (1 given)
>
> When I make the following call:
>
> http://localhost/eligibility/cmseditorlinemethod/474724434
>
> Which invokes:
>
> def cmseditorlinemethod(self, ssn):

You're doing an HTTP request that ultimately is supposed to translate
into a method call. The problem appears to be somewhere in between
those; what system are you using to handle HTTP (web) requests, and
how does it translate a URL into a method call?

As a side point, if it takes a piece of the URL and looks it up,
unchecked, as a member name, this is a rather dodgy practice. I hope
you have a whitelist of legal method names.

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


Re: Argument count mismatch

2011-04-21 Thread Wolfgang Rohdewald
On Donnerstag 21 April 2011, RVince wrote:
> When I make the following call:
> 
> http://localhost/eligibility/cmseditorlinemethod/474724434

broken link - I have no /eligilibity on my localhost

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


Argument count mismatch

2011-04-21 Thread RVince
I am getting the following:

Error - : cmseditorlinemethod() takes
exactly 2 arguments (1 given)

When I make the following call:

http://localhost/eligibility/cmseditorlinemethod/474724434

Which invokes:

def cmseditorlinemethod(self, ssn):
c.details =
Session.query(MSPResponse).filter(MSPResponse.beneficiaryssn ==
ssn).all()
content = render('/cmseditorline.mako')
return content

Can anyone tell me what the mismatch is in the number of my parameters
based on this? Thanks, RVince
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Remote Connection

2011-04-21 Thread Irmen de Jong

On 20-04-11 05:26, ray wrote:


The speech commands will scripted in Python.  Dragonfly is the Python
project to coordinate this but does not address connectivity.

So I am wondering if there have been any Python projects to address
the connectivity.

ray


I'm not quite sure what you want exactly, but maybe one or more of the 
available Python rpc modules/libraries can be used to your needs?


They offer communication between Python processes on separate machines, 
but may not be entirely suitable for your needs of audio data transfer.
Still, they should be able to transfer chunks of audio data in some way 
to a remote machine. Some protocols are better suited for this than others.


Some libraries that may be useful perhaps:
Pyro (see http://pypi.python.org/pypi/Pyro4/ )
xmlrpclib (part of the standard library)
or perhaps even httplib or ftplib ?

Hth,
Irmen.

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


Re: Groups in regular expressions don't repeat as expected

2011-04-21 Thread Vlastimil Brom
2011/4/20 MRAB :
> On 20/04/2011 20:20, John Nagle wrote:
>>
>> Here's something that surprised me about Python regular expressions.
>>
>> ...
> You should take a look at the regex module on PyPI. :-)
> --
>

Ah well...
sorry for possibly destroying the point and the aha! effect ...
vbr
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A question about Python Classes

2011-04-21 Thread Ethan Furman

chad wrote:

Let's say I have the following

class BaseHandler:
def foo(self):
print "Hello"

class HomeHandler(BaseHandler):
pass


Then I do the following...

test = HomeHandler()
test.foo()

How can HomeHandler call foo() when I never created an instance of
BaseHandler?


You don't need to create an instance of BaseHandler.  You have the
class, Python knows you have the class -- Python will look there if the
subclasses lack an attribute.

~Ethan~

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


Re: A question about Python Classes

2011-04-21 Thread MRAB

On 21/04/2011 18:12, Pascal J. Bourguignon wrote:

chad  writes:


Let's say I have the following

class BaseHandler:
 def foo(self):
 print "Hello"

class HomeHandler(BaseHandler):
 pass


Then I do the following...

test = HomeHandler()
test.foo()

How can HomeHandler call foo() when I never created an instance of
BaseHandler?


But you created one!


No, he didn't, he created an instance of HomeHandler.


test is an instance of HomeHandler, which is a subclass of BaseHandler,
so test is also an instance of BaseHandler.


test isn't really an instance of BaseHandler, it's an instance of
HomeHandler, which is a subclass of BaseHandler.

If you do this:

class BaseHandler(object):
def foo(self):
print "Hello"

class HomeHandler(BaseHandler):
pass

test = HomeHandler()

then you'll find:

>>> isinstance(test, BaseHandler)
True

but:

>>> type(test)

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


Re: A question about Python Classes

2011-04-21 Thread Terry Reedy

On 4/21/2011 11:43 AM, chad wrote:

Let's say I have the following

class BaseHandler:
 def foo(self):
 print "Hello"

class HomeHandler(BaseHandler):
 pass


Then I do the following...

test = HomeHandler()
test.foo()

How can HomeHandler call foo() when I never created an instance of
BaseHandler?


When you ask for an attribute of an instance of a class, the attribute 
lookup first looks at the instance; if not there, then the class; if not 
there, then superclass(es); and so on back to class 'object'.


>>> class C(): pass

>>> c=C()
>>> c.__hash__


# how does this happen when C has no __hash__ method?

>>> C.__hash__


# C inherits __hash__ and other special methods from 'object'

>>> hash(c)
1035101

# uses the default, inherited method.

Most syntactic operations and builtins are ultimately converted to a 
special method call, often inherited like this. In fact, c.x is 
converted to object.__getattribute__(c, 'x').


>>> object.__getattribute__(c, '__hash__')


You do need to understand inheritance. On the other hand, do not worry 
about behind-the-scenes implementation details like 'method_wrapper' and 
'slot_wrapper' classes, which may be CPython specific.


--
Terry Jan Reedy

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


Re: Python 3.2 on CentOS 5.6 & compatibility concerns

2011-04-21 Thread Terry Reedy

On 4/21/2011 8:02 AM, Rob McGillivray wrote:

Hi All,

Does anyone know if it is ‘safe’ to install Python 3.2 on CentOS? By
‘safe’ I mean not breaking the existing base Python 2.4.x installation
upon which various CentOS/RHEL services (like yum) depend. Will the
‘make install’ install 3.2 in parallel with the existing 2.x
installation, or break it? I’m new to Python and OSS, but the little
I’ve read indicates that this could be a major risk.


I have read on this list that there is a 'make altinstall' for *nix to 
avoid problems with the 'base' install. (2.4, really? that is ancient!).


--
Terry Jan Reedy


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


Re: A question about Python Classes

2011-04-21 Thread Pascal J. Bourguignon
chad  writes:

> Let's say I have the following
>
> class BaseHandler:
> def foo(self):
> print "Hello"
>
> class HomeHandler(BaseHandler):
> pass
>
>
> Then I do the following...
>
> test = HomeHandler()
> test.foo()
>
> How can HomeHandler call foo() when I never created an instance of
> BaseHandler?

But you created one!

test is an instance of HomeHandler, which is a subclass of BaseHandler,
so test is also an instance of BaseHandler.

A subclass represents a subset of the instances of its super class.

-- 
__Pascal Bourguignon__ http://www.informatimago.com/
A bad day in () is better than a good day in {}.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A question about Python Classes

2011-04-21 Thread Benjamin Kaplan
On Apr 21, 2011 12:55 PM, "chad"  wrote:
>
> On Apr 21, 9:30 am, Jean-Michel Pichavant 
> wrote:
> > chad wrote:
> > > Let's say I have the following
> >
> > > class BaseHandler:
> > > def foo(self):
> > > print "Hello"
> >
> > > class HomeHandler(BaseHandler):
> > > pass
> >
> > > Then I do the following...
> >
> > > test = HomeHandler()
> > > test.foo()
> >
> > > How can HomeHandler call foo() when I never created an instance of
> > > BaseHandler?
> >
> > > Chad
> >
> > you did, test is an instance of BaseHandler.
> >
> >  > isinstance(test, HomeHandler)
> > < True
> >
> >  > isinstance(test, BaseHandler)
> > < True
> >
>
> So it just just creates an instance of every class that it inherits?
>
> Chad

No. it is an instance of every class it inherits. It's called inheritance
because it inherits the attributes and methods of the parent class
> --
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A question about Python Classes

2011-04-21 Thread chad
On Apr 21, 9:30 am, Jean-Michel Pichavant 
wrote:
> chad wrote:
> > Let's say I have the following
>
> > class BaseHandler:
> >     def foo(self):
> >         print "Hello"
>
> > class HomeHandler(BaseHandler):
> >     pass
>
> > Then I do the following...
>
> > test = HomeHandler()
> > test.foo()
>
> > How can HomeHandler call foo() when I never created an instance of
> > BaseHandler?
>
> > Chad
>
> you did, test is an instance of BaseHandler.
>
>  > isinstance(test, HomeHandler)
> < True
>
>  > isinstance(test, BaseHandler)
> < True
>

So it just just creates an instance of every class that it inherits?

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


Finding empty columns. Is there a faster way?

2011-04-21 Thread nn
time head -100 myfile  >/dev/null

real0m4.57s
user0m3.81s
sys 0m0.74s

time ./repnullsalt.py '|' myfile
0 1 Null columns:
11, 20, 21, 22, 23, 24, 25, 26, 27, 30, 31, 33, 45, 50, 68

real1m28.94s
user1m28.11s
sys 0m0.72s



import sys
def main():
with open(sys.argv[2],'rb') as inf:
limit = sys.argv[3] if len(sys.argv)>3 else 1
dlm = sys.argv[1].encode('latin1')
nulls = [x==b'' for x in next(inf)[:-1].split(dlm)]
enum = enumerate
split = bytes.split
out = sys.stdout
prn = print
for j, r in enum(inf):
if j%100==0:
prn(j//100,end=' ')
out.flush()
if j//100>=limit:
break
for i, cur in enum(split(r[:-1],dlm)):
nulls[i] |= cur==b''
print('Null columns:')
print(', '.join(str(i+1) for i,val in enumerate(nulls) if val))

if not (len(sys.argv)>2):
sys.exit("Usage: "+sys.argv[0]+
 "   ")

main()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A question about Python Classes

2011-04-21 Thread Jean-Michel Pichavant

chad wrote:

Let's say I have the following

class BaseHandler:
def foo(self):
print "Hello"

class HomeHandler(BaseHandler):
pass


Then I do the following...

test = HomeHandler()
test.foo()

How can HomeHandler call foo() when I never created an instance of
BaseHandler?

Chad
  

you did, test is an instance of BaseHandler.

> isinstance(test, HomeHandler)
< True

> isinstance(test, BaseHandler)
< True

JM

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


shared dictionary of dictionaries with Manager

2011-04-21 Thread Darío Suárez Gracia

Hi all,
I was trying to share a dictionary of dictionaries of arrays with  
Manager from multiprocessing. Without multiprocessing the code works  
perfectly, but with the current example the last print does not show  
the correct result.


Any hint?

Thanks,
Darío Suárez#!/usr/local/bin/python2.7
import sys
import warnings
from multiprocessing import Pool, Value, Array, Manager


N_PROCESSES = 8


def f(results, key):

results[key]['d'][3].append(1)

def main():
  
pool = Pool(processes=N_PROCESSES)
manager = Manager()

results = manager.dict()

for key in ['k', 'kk']:
results[key] = dict([(key2, [[] for i in range(4)]) for key2 in ['d', 'dd']])


res = [ pool.apply_async(f, key) for key in ['k'] ]
map(lambda x: x.wait(), res)

print results['k']
print results['k']['d']
print results['k']['d'][3]


if __name__ == "__main__":
main()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A question about Python Classes

2011-04-21 Thread Rafael Durán Castañeda
You did:

>>> class BaseHandler:
... def foo(self):
... print "Hello"
...
>>> class HomerHandler(BaseHandler):
... pass
...
>>> test = HomerHandler()
>>> test.foo()
Hello
>>> isinstance(test, BaseHandler)
True
>>> isinstance(test, HomerHandler)
True
>>>

You could say test is a "BaseHandler of type HomerHandler"



2011/4/21 chad 

> Let's say I have the following
>
> class BaseHandler:
>def foo(self):
>print "Hello"
>
> class HomeHandler(BaseHandler):
>pass
>
>
> Then I do the following...
>
> test = HomeHandler()
> test.foo()
>
> How can HomeHandler call foo() when I never created an instance of
> BaseHandler?
>
> Chad
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: learnpython.org - an online interactive Python tutorial

2011-04-21 Thread MRAB

On 21/04/2011 15:14, Westley Martínez wrote:

On Thu, Apr 21, 2011 at 05:19:29PM +1000, Chris Angelico wrote:

On Thu, Apr 21, 2011 at 5:10 PM, Algis Kabaila  wrote:

False: Python IS strongly typed, without doubt (though the
variables are not explicitly declared.)


Strongly duck-typed though. If I create a class that has all the right
members, it can simultaneously be a file, an iterable, a database, and
probably even a web browser if it feels like it. Is that strong typing
or not?

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


It's strong typing.  Python does not implicitly convert types.  Weak typing is
when I can do 1 + "1" and get 2.


It could be argued that it does implicit convert for some numeric
types, eg int to float when needed.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Teaching Python

2011-04-21 Thread MRAB

On 21/04/2011 14:58, Westley Martínez wrote:

On Thu, Apr 21, 2011 at 06:02:08AM +0200, Stefan Behnel wrote:

Ben Finney, 20.04.2011 02:06:

Dan Stromberg writes:


On Tue, Apr 19, 2011 at 4:03 PM, geremy condra wrote:

When you say 'hacking', you mean ?


Presumably he meant the real meaning of the word, not what the press
made up and ran with.


To be fair, the press already had its own pejorative meaning of “hack”
before the engineering and computing term


Not anywhere outside of the English language that I'm aware of,
though. In German, it's a computing-only term that's used in both
contexts by those who understand why the pointer is moving over the
screen when moving the mouse, and almost exclusively in a bad
context by those who write news paper articles (and, consequently,
by those who innocently read them).

Stefan

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


O Lord, I'd hope we'd be speaking for English here.  But really, hack
has always been a negative term.  It's original definition is chopping,
breaking down, kind of like chopping down the security on someone elses
computer.  Now I don't know where the term originally came from, but the
definition the media uses is quite a fair use.  Why should we call
ourselves hackers anyways?  I don't smoke.  I'm no different from anyone
else, I just happen to know a lot about computers.  Should we call
people who know a lot about the economy hackers, too, or perhaps we
should call them economists


As I understand it, "hacking" is about not doing the job "properly".
When trying to make something, a hacker will use the equivalent of duct
tape to hold things together.

A computer hacker doesn't write the requirements of the software or
draw Jackson Structured Programming diagrams, etc, but just thinks
about what's needed and starts writing the code.
--
http://mail.python.org/mailman/listinfo/python-list


Re: How deal with the coding

2011-04-21 Thread MRAB

On 21/04/2011 07:27, 1011_wxy wrote:

Dear All:
I got a coding problem when I use python to read html from web which is
encode with gb2312,
ater I insert the data I read from web into Oracle DB with coding gbk, I
found messy code by select from PL/SQL.
I tried the way ".encode('gbk','ignore')" before insert Oracle by using
cx_Oracle,but not effective.
How can I deal with the coding?


It's probably better to use UTF-8 wherever possible.

Decode to Unicode and work with Unicode strings.

Use UTF-8 when you want to store or transmit data.

Use another encoding _only_ if it's required by a legacy application (an 
old application which requires that encoding.).
-- 
http://mail.python.org/mailman/listinfo/python-list


A question about Python Classes

2011-04-21 Thread chad
Let's say I have the following

class BaseHandler:
def foo(self):
print "Hello"

class HomeHandler(BaseHandler):
pass


Then I do the following...

test = HomeHandler()
test.foo()

How can HomeHandler call foo() when I never created an instance of
BaseHandler?

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


Python-URL! - weekly Python news and links (Apr 21)

2011-04-21 Thread Cameron Laird
QOTW:  "Python is a pragmatic language, so all the rules come pre-
broken." - Mel
   http://groups.google.com/group/comp.lang.python/msg/208face4a8e00062


   Look!  In the sky!  It's a SciPy demonstration!  It's a business!
   No, it's ForecastWatch:
http://goo.gl/AvzqZ

EuroPython 2011:  Firenze, 20-26 June 2011:
http://ep2011.europython.eu/

Python Software Foundation is collecting for a special project:
http://tinyurl.com/PSF-donation

   Jesse Noller explains the PSF:
   http://bit.ly/e1j7JE

   Do you *realize* how much you get with Plone, for free?
   http://goo.gl/fb/KRodb
   [Django and many other Python outposts also are wonderful, in
   their own ways, of course.]



Everything Python-related you want is probably one or two clicks away
in
these pages:

   Python.org's Python Language Website is the traditional
   center of Pythonia
   http://www.python.org
   Notice especially the master FAQ
   http://www.python.org/doc/FAQ.html

   Just beginning with Python?  This page is a great place to start:
   http://wiki.python.org/moin/BeginnersGuide/Programmers

   Planet Python:  you want to visit there:
   http://planet.python.org
   But don't confuse it with Planet SciPy:
   http://planet.scipy.org
   And don't confuse *that* with SciPyTip, a high-quality daily (!)
tip
   for the numerically-inclined:
   http://twitter.com/SciPyTip

   Python Insider is the official blog of the Python core development
   team:
   
http://pyfound.blogspot.com/2011/03/python-dev-launches-python-insider-blog.html

   The Python Software Foundation (PSF) has replaced the Python
   Consortium as an independent nexus of activity.  It has official
   responsibility for Python's development and maintenance.
   http://www.python.org/psf/
   Among the ways you can support PSF is with a donation.
   http://www.python.org/psf/donations/
   Keep up with the PSF at "Python Software Foundation News":
   http://pyfound.blogspot.com

   The Python Papers aims to publish "the efforts of Python
enthusiasts":
   http://pythonpapers.org/

   Doug Hellman's "Module of the week" is essential reading:
   http://www.doughellmann.com/PyMOTW/

   comp.lang.python.announce announces new Python software.  Be
   sure to scan this newsgroup weekly.
   http://groups.google.com/group/comp.lang.python.announce/topics

   Python411 indexes "podcasts ... to help people learn Python ..."
   Updates appear more-than-weekly:
   http://www.awaretek.com/python/index.html

   The Python Package Index catalogues packages.
   http://www.python.org/pypi/

   Much of Python's real work takes place on Special-Interest Group
   mailing lists
   http://www.python.org/sigs/

   Python Success Stories--from air-traffic control to on-line
   match-making--can inspire you or decision-makers to whom you're
   subject with a vision of what the language makes practical.
   http://www.pythonology.com/success

   The Summary of Python Tracker Issues is an automatically generated
   report summarizing new bugs, closed ones, and patch submissions.
   
http://search.gmane.org/?author=status%40bugs.python.org&group=gmane.comp.python.devel&sort=date

   nullege is an interesting search Web application, with the
intelligence
   to distinguish between Python code and comments.  It provides what
   appear to be relevant results, and demands neither Java nor CSS be
   enabled:
   http://www.nullege.com

   Although unmaintained since 2002, the Cetus collection of Python
   hyperlinks retains a few gems.
   http://www.cetus-links.org/oo_python.html

   Python FAQTS
   http://python.faqts.com/

   The Cookbook is a collaborative effort to capture useful and
   interesting recipes:
   http://code.activestate.com/recipes/langs/python/

   Many Python conferences around the world are in preparation.
   Watch this space for links to them.

   Among several Python-oriented RSS/RDF feeds available, see:
   http://www.python.org/channews.rdf
   For more, see:
   http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all
   The old Python "To-Do List" now lives principally in a
   SourceForge reincarnation.
   http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse
   http://www.python.org/dev/peps/pep-0042/

   del.icio.us presents an intriguing approach to reference
commentary.
   It already aggregates quite a bit of Python intelligence.
   http://del.icio.us/tag/python

   At least one of the Python magazines is explicitly multilingual:
   http://www.python.org/ar/

   PythonWare complemented the digest you're reading with the
   marvelous daily python url.  While it's now ... dormant, it still
   has plenty of interesting reading.
http://www.pythonware.com/daily

   Python articles regularly appear at IBM DeveloperWorks:
   
http://w

Re: Problem receiving UDP broadcast packets.

2011-04-21 Thread Grant Edwards
On 2011-04-21, Dan Stromberg  wrote:
> On Wed, Apr 20, 2011 at 7:21 AM, Grant Edwards  
> wrote:
>> On 2011-04-20, Dan Stromberg  wrote:
>>> On Tue, Apr 19, 2011 at 8:12 PM, Dan Stromberg  wrote:
 I agree though that you're kind of pushing IP in a direction it wasn't
 intended to go.
>>>
>>> It just occurred to me: You might get some additional mileage out of
>>> popping the network adapter into promiscuous mode. ?In fact, it Might
>>> be necessary irrespective of the rest of your approach.
>>
>> The network adapter is already receiving all the packets I want to
>> receive, so putting it into promiscuous mode would only increase the
>> number of unwanted packets.
>
> I think tcpdump and tshark (was tethereal) will put the interface into
> promiscuous mode so it can see more traffic;

It can (and by default does).  I was using "-p" so it didn't.

> on OSF/1 (Tru64), we had
> to do this manually for said programs to see all that was possible
> (barring the presence of a switch not repeating packets the way
> routers and hubs would).

 * The packets were being sent to MAC address ff:ff:ff:ff:ff:ff, so the
   NIC does not have to be in promiscuous mode to receive them.

 * tcpdump saw them even when it doesn't put the NIC in promiscuous
   mode.

 * The kernel was seeing the packets because it was logging them as
   martians and discarding them (something I didn't notice until later).

 * Turning off reverse-path filtering in the TCP stack allowed the
   packets to be received as expected.

-- 
Grant Edwards   grant.b.edwardsYow! I was making donuts
  at   and now I'm on a bus!
  gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is there a difference between one line and many lines

2011-04-21 Thread Westley Martínez
On Thu, Apr 21, 2011 at 02:38:52AM -0700, vino19 wrote:
> Hello, I'm a newbie.
> What's the defference between
> 
> >>>a=-6; b=-6; a is b
> >>>True
> 
> and
> 
> >>>a=-6
> >>>b=-6
> >>>a is b
> >>>False
> 
> ?
> -- 
> http://mail.python.org/mailman/listinfo/python-list

Depends on how the interpreter was implemented.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: learnpython.org - an online interactive Python tutorial

2011-04-21 Thread Westley Martínez
On Thu, Apr 21, 2011 at 05:19:29PM +1000, Chris Angelico wrote:
> On Thu, Apr 21, 2011 at 5:10 PM, Algis Kabaila  wrote:
> > False: Python IS strongly typed, without doubt (though the
> > variables are not explicitly declared.)
> 
> Strongly duck-typed though. If I create a class that has all the right
> members, it can simultaneously be a file, an iterable, a database, and
> probably even a web browser if it feels like it. Is that strong typing
> or not?
> 
> Chris Angelico
> -- 
> http://mail.python.org/mailman/listinfo/python-list

It's strong typing.  Python does not implicitly convert types.  Weak typing is
when I can do 1 + "1" and get 2.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Vectors

2011-04-21 Thread Anssi Saari
Andreas Tawn  writes:

> You might also want to consider http://code.google.com/p/pyeuclid/

Thanks, I was studying quaternions recently and had to use two
packages to get some stuff done. And of course one of them used
ass-backwards declaration for a quaternion and one didn't...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: About threads in python

2011-04-21 Thread Stefan Behnel

dutche, 21.04.2011 15:19:

Here's the thing...I had to make a program with threads and after
finished, I found some posts and articles in Google about Python and
threads, raising the question about if it really implements thread
programming or not, because of GIL and the way Python needs to lock
some objects.

I have now in my program something about 8 threads and each of them
runs different code based on some directives, these codes relies
sometimes in C api, using classes like zipfile and tarfile, and others
relies only in python code.


What do you mean by "relies sometimes on C api"? Do you mean that it uses 
binary modules, as opposed to Python modules?




My question is about the efficiency of threads in python, does anybody
has something to share?


From your (rather unspecific) description, I gather that you are doing 
mostly I/O operations. Threading is an acceptable programming model for 
that, and Python supports it just fine. The GIL is usually released for I/O 
operations by the runtime, so if your program is I/O bound, you will get 
full threading concurrency.


Stefan

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


Re: Teaching Python

2011-04-21 Thread Westley Martínez
On Thu, Apr 21, 2011 at 06:02:08AM +0200, Stefan Behnel wrote:
> Ben Finney, 20.04.2011 02:06:
> >Dan Stromberg writes:
> >
> >>On Tue, Apr 19, 2011 at 4:03 PM, geremy condra wrote:
> >>>When you say 'hacking', you mean ?
> >>
> >>Presumably he meant the real meaning of the word, not what the press
> >>made up and ran with.
> >
> >To be fair, the press already had its own pejorative meaning of “hack”
> >before the engineering and computing term
> 
> Not anywhere outside of the English language that I'm aware of,
> though. In German, it's a computing-only term that's used in both
> contexts by those who understand why the pointer is moving over the
> screen when moving the mouse, and almost exclusively in a bad
> context by those who write news paper articles (and, consequently,
> by those who innocently read them).
> 
> Stefan
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list

O Lord, I'd hope we'd be speaking for English here.  But really, hack
has always been a negative term.  It's original definition is chopping,
breaking down, kind of like chopping down the security on someone elses
computer.  Now I don't know where the term originally came from, but the
definition the media uses is quite a fair use.  Why should we call
ourselves hackers anyways?  I don't smoke.  I'm no different from anyone
else, I just happen to know a lot about computers.  Should we call
people who know a lot about the economy hackers, too, or perhaps we
should call them economists
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Groups in regular expressions don't repeat as expected

2011-04-21 Thread Vlastimil Brom
2011/4/20 John Nagle :
> Here's something that surprised me about Python regular expressions.
>
 krex = re.compile(r"^([a-z])+$")
 s = "abcdef"
 ms = krex.match(s)
 ms.groups()
> ('f',)
>
>...

> "If a group is contained in a part of the pattern that matched multiple
> times, the last match is returned."
>
> That's kind of lame, though. I'd expect that there would be some way
> to retrieve all matches.
>
>                                        John Nagle
> --
> http://mail.python.org/mailman/listinfo/python-list

Hi,
do you mean something like:

>>> import regex
>>> ms = regex.match(r"^([a-z])+$", "abcdef")
>>> ms.captures(1)
['a', 'b', 'c', 'd', 'e', 'f']
>>>

>>> help(ms.captures)
Help on built-in function captures:

captures(...)
captures([group1, ...]) --> list of strings or tuple of list of strings.
Return the captures of one or more subgroups of the match.  If there is a
single argument, the result is a list of strings; if there are multiple
arguments, the result is a tuple of lists with one item per argument; if
there are no arguments, the captures of the whole match is returned.  Group
0 is the whole match.

>>>

cf.
http://pypi.python.org/pypi/regex

hth,
  vbr
-- 
http://mail.python.org/mailman/listinfo/python-list


About threads in python

2011-04-21 Thread dutche
Hi folks, how are ya?

Here's the thing...I had to make a program with threads and after
finished, I found some posts and articles in Google about Python and
threads, raising the question about if it really implements thread
programming or not, because of GIL and the way Python needs to lock
some objects.

I have now in my program something about 8 threads and each of them
runs different code based on some directives, these codes relies
sometimes in C api, using classes like zipfile and tarfile, and others
relies only in python code.

My question is about the efficiency of threads in python, does anybody
has something to share?

Thanks in advance

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


Re: Groups in regular expressions don't repeat as expected

2011-04-21 Thread Neil Cerutti
On 2011-04-20, John Nagle  wrote:
>  Findall does something a bit different. It returns a list of
> matches of the entire pattern, not repeats of groups within
> the pattern.
>
>  Consider a regular expression for matching domain names:
>
> >>> kre = re.compile(r'^([a-zA-Z0-9\-]+)(?:\.([a-zA-Z0-9\-]+))+$')
> >>> s = 'www.example.com'
> >>> ms = kre.match(s)
> >>> ms.groups()
> ('www', 'com')
> >>> msall = kre.findall(s)
> >>> msall
> [('www', 'com')]
>
> This is just a simple example.  But it illustrates an unnecessary
> limitation.  The matcher can do the repeated matching; you just can't
> get the results out.

Thanks for the further explantion.

Assuming a fake API that returned multiple group matches as a
tuple:

>>? print(re.match(r"^([a-z])+$", "abcdef").groups())
(('a', 'b', 'c', 'd', 'e', 'f'),)

I was thinking of applying findall something like this, but you
have to make multiple calls:

>>> m = re.match(r"^[a-z]+$", s)
>>> if m:
...   print(re.findall(r"[a-z]", m.group()))
...
['a', 'b', 'c', 'd', 'e', 'f']

I can see that getting really annoying. Is there a better way to
make multiple group matches accessible without adding a third
element type as a group element?

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


Re: is there a difference between one line and many lines

2011-04-21 Thread Peter Otten
Steven D'Aprano wrote:

> but:
> 
 a = 1001; b = 10001; a is b
> False

I would hope so ;)

> The point is that Python is free to re-use immutable objects, or not re-
> use them, as it sees fit.
 
Indeed, and I even found a Python implementation on my harddisk that does 
what you intended to show:

$ ipy
IronPython 1.1.1 (1.1.1) on .NET 2.0.50727.1433
Copyright (c) Microsoft Corporation. All rights reserved.
>>> a = 1001; b = 1001; a is b
False


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


Re: is there a difference between one line and many lines

2011-04-21 Thread Steven D'Aprano
On Thu, 21 Apr 2011 02:55:52 -0700, vino19 wrote:

> Sure, I understand that "is" is not "==", cause "is" just compares
> id(a)==id(b).
> 
> I have a win32 CPython and the range of "singletons" is from -5 to 256
> on my machine.
> 
> I am asking about what happens in Python interpreter? Why is there a
> difference between running one line like "a=1;b=1" and two lines like
> "a=1 \n b=1"? Does it decide to locate memory in different types depend
> on a code?

It's an implementation detail which is free to change from one version to 
the next. You can't rely on that behaviour, it could change at any time. 
You would have to study the source code of the exact version you are 
running, including any IDE if you are using an IDE, and see what it is 
doing.

The point is that Python is free to re-use immutable objects, or not re-
use them, as it sees fit.

>>> sys.version
'2.6.4 (r264:75706, Feb  1 2010, 13:33:07) \n[GCC 4.1.2 20070925 (Red Hat 
4.1.2-27)]'
>>>
>>>
>>> a = 1.23; b = 1.23; a is b
True
>>> c = 1.23
>>> c is a
False


but:

>>> a = 1001; b = 10001; a is b
False



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


Python 3.2 on CentOS 5.6 & compatibility concerns

2011-04-21 Thread Rob McGillivray
Hi All,
 
Does anyone know if it is 'safe' to install Python 3.2 on CentOS? By 'safe' I 
mean not breaking the existing base Python 2.4.x installation upon which 
various CentOS/RHEL services (like yum) depend. Will the 'make install' install 
3.2 in parallel with the existing 2.x installation, or break it? I'm new to 
Python and OSS, but the little I've read indicates that this could be a major 
risk.
 
My goal is to setup a dev platform (currently CentOS/Wing IDE/Python 3.2) and 
learn Python 3.x (as apparently this is the future of the language), but at the 
same time I'm looking to use CentOS as the server platform for deployment, and 
so want to understand what's involved in managing Python installations/upgrades 
on this platform. 
 
Thanks in advance,
 
Rob-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Hello Sweet Friends

2011-04-21 Thread Krzysztof Bieniasz
Dnia Thu, 21 Apr 2011 01:11:34 -0600, Ian Kelly napisał(a):

> On Thu, Apr 21, 2011 at 12:28 AM, harrismh777 
> wrote:
>>   I don't like SPAM with my eggs and ham...
> 
> Nor do the rest of us, so please don't help it circumvent our spam
> filters by reposting it.

Hey, this is comp.lang.python, it's supposed to have at least some degree 
of Monty Python humour. 

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


Reposting meat-like products [was Re: Hello Sweet Friends]

2011-04-21 Thread Steven D'Aprano
On Thu, 21 Apr 2011 01:11:34 -0600, Ian Kelly wrote:

> On Thu, Apr 21, 2011 at 12:28 AM, harrismh777 
> wrote:
>>   I don't like SPAM with my eggs and ham...
> 
> Nor do the rest of us, so please don't help it circumvent our spam
> filters by reposting it.

Harris did cut out the URL though, so he gets credit for that.


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


Re: is there a difference between one line and many lines

2011-04-21 Thread Jean-Michel Pichavant

vino19 wrote:

Sure, I understand that "is" is not "==", cause "is" just compares id(a)==id(b).

I have a win32 CPython and the range of "singletons" is from -5 to 256 on my machine. 


I am asking about what happens in Python interpreter? Why is there a difference between running one 
line like "a=1;b=1" and two lines like "a=1 \n b=1"? Does it decide to locate 
memory in different types depend on a code?

Thanks
  
Probably, for optimisation purpose I guess. This is very implementation 
specific and as a newby, you should not care about such trivial details. 
The worst thing on earth you could do would be to code knowing that some 
values are singleton and take profit from it. Well, maybe coding in perl 
would be worse...


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


Re: is there a difference between one line and many lines

2011-04-21 Thread Peter Otten
vino19 wrote:

> Hello, I'm a newbie.
> What's the defference between
> 
a=-6; b=-6; a is b
True
> 
> and
> 
a=-6
b=-6
a is b
False
> 
> ?

When you write it as a single line the assignments to a and b are part of 
the same compilation process, and as an optimization CPython's bytecode 
compiler looks for identical (integer, float, string) constants and uses the 
same object to represent them. To show that it's really the compilation not 
the number of lines:

>>> exec """a = -6
... b = -6
... """
>>> a is b
True


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


Re: is there a difference between one line and many lines

2011-04-21 Thread vino19
Python 2.7.1 (downloaded from python.org a week ago)

You see, if I save this to a file and then run from CMD: "python test1.py" the 
result will be the same: "True"

When I use IDLE or IPython or DreamPie or maybe something else then result is 
not the same. So maybe as Chris Angelico said it is the IDLE(or Ipython) makes 
some optimization depend on a code style. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Feature suggestion -- return if true

2011-04-21 Thread Thomas Rachel

Am 13.04.2011 01:06, schrieb Ethan Furman:


--> def func():
--> var1 = something()
--> var2 = something_else('this')
--> return? var1.hobgle(var2)
--> var3 = last_resort(var1)
--> return var3.wiglat(var2)


This makes me think of a decorator which can mimic the wantend behaviour:

def getfirst(f):
from functools import wraps
@wraps(f)
def func(*a, **k):
for i in f(*a, **k):
if i: return i
return func

# [BTW: a kind of "return decorator" would be nice here ;-)]

@getfirst
def func():
var1 = something()
var2 = something_else('this')
yield var1.hobgle(var2)
var3 = last_resort(var1)
yield var3.wiglat(var2)
yield "Even that did not work."

This has the advantage of being flexible about which condition to 
evaluate: maybe the func does return tuples of which only the 2nd part 
is relevant concerning the check. Then just do



def getfirst(f):
from functools import wraps
@wraps(f)
def func(*a, **k):
for i in f(*a, **k):
if i[1]: return i
return func

@getfirst
def func():
var1 = something()
var2 = something_else('this')
yield "first try", var1.hobgle(var2)
var3 = last_resort(var1)
yield "second try", var3.wiglat(var2)
yield "default value", "Even that did not work."


Disclaimer: Untested, but you should get the idea.

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


Re: is there a difference between one line and many lines

2011-04-21 Thread Heiko Wundram
Am 21.04.2011 11:59, schrieb Heiko Wundram:
> Am 21.04.2011 11:55, schrieb vino19:
>> I am asking about what happens in Python interpreter? Why is there a 
>> difference between running one line like "a=1;b=1" and two lines like "a=1 
>> \n b=1"? Does it decide to locate memory in different types depend on a code?
> 
> There is no difference between the two.
> ...

Erm, sorry, forget my post. I misread a=-6 as a-=6, etc... So: what
Chris said. Anyway, there is semantically no difference between the two,
and that stands.

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


Re: is there a difference between one line and many lines

2011-04-21 Thread Daniel Kluev
On Thu, Apr 21, 2011 at 8:38 PM, vino19  wrote:
> Hello, I'm a newbie.
> What's the defference between
>*skip*

What is version of CPython?
In 2.7.1 and 3.1.3 both versions return True, and moreover, are
compiled to identical bytecode.

>>> def test1():
... a=-6; b=-6; c = a is b
... return c
>>> def test3():
... a=-6
... b=-6
... c = a is b
... return c
>>> test1()
True
>>> test3()
True
>>> dis.dis(test1)
  2   0 LOAD_CONST   1 (-6)
  3 STORE_FAST   0 (a)
  6 LOAD_CONST   1 (-6)
  9 STORE_FAST   1 (b)
 12 LOAD_FAST0 (a)
 15 LOAD_FAST1 (b)
 18 COMPARE_OP   8 (is)
 21 STORE_FAST   2 (c)
  3  24 LOAD_FAST2 (c)
 27 RETURN_VALUE
>>> dis.dis(test3)
  2   0 LOAD_CONST   1 (-6)
  3 STORE_FAST   0 (a)
  3   6 LOAD_CONST   1 (-6)
  9 STORE_FAST   1 (b)
  4  12 LOAD_FAST0 (a)
 15 LOAD_FAST1 (b)
 18 COMPARE_OP   8 (is)
 21 STORE_FAST   2 (c)
  5  24 LOAD_FAST2 (c)
 27 RETURN_VALUE

So AFAIK, there is no difference for interpreter itself, its purely
syntactic, and is compiled to exactly same bytecode.

-- 
With best regards,
Daniel Kluev
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is there a difference between one line and many lines

2011-04-21 Thread Chris Angelico
On Thu, Apr 21, 2011 at 7:55 PM, vino19  wrote:
> Sure, I understand that "is" is not "==", cause "is" just compares 
> id(a)==id(b).
>
> I have a win32 CPython and the range of "singletons" is from -5 to 256 on my 
> machine.
>
> I am asking about what happens in Python interpreter? Why is there a 
> difference between running one line like "a=1;b=1" and two lines like "a=1 \n 
> b=1"? Does it decide to locate memory in different types depend on a code?

Ah okay! In that case, I'm guessing this is going to be an oddity of
the IDLE system, because it's compiling each line separately. When you
put it on a single line, it's saving some trouble by sharing the
constant; when you do them separately, it doesn't optimize like that.

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


Re: is there a difference between one line and many lines

2011-04-21 Thread Heiko Wundram
Am 21.04.2011 11:55, schrieb vino19:
> I am asking about what happens in Python interpreter? Why is there a 
> difference between running one line like "a=1;b=1" and two lines like "a=1 \n 
> b=1"? Does it decide to locate memory in different types depend on a code?

There is no difference between the two.

You've not given the initializers for a/b in the two statement groups
you showed, so that what Chris Angelico said is probably what's
happening here (i.e.: in the first case, you stay in the singleton
range, in the second case which builds on the first, you don't).

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


Re: is there a difference between one line and many lines

2011-04-21 Thread vino19
Sure, I understand that "is" is not "==", cause "is" just compares id(a)==id(b).

I have a win32 CPython and the range of "singletons" is from -5 to 256 on my 
machine. 

I am asking about what happens in Python interpreter? Why is there a difference 
between running one line like "a=1;b=1" and two lines like "a=1 \n b=1"? Does 
it decide to locate memory in different types depend on a code?

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


Re: is there a difference between one line and many lines

2011-04-21 Thread Chris Angelico
On Thu, Apr 21, 2011 at 7:38 PM, vino19  wrote:
> Hello, I'm a newbie.
> What's the defference between
>
a=-6; b=-6; a is b
True
>
> and
>
a=-6
b=-6
a is b
False

You may want to use the == operator rather than "is". When you use
"is", you're asking Python if the two variables are referencing the
exact same object, but with ==, you're asking if they're equivalent.
With integers from -1 to 99, Python keeps singletons, which means that
your test would work if you used 6 instead of -6; but there's no
guarantee of anything with the negatives. However, it doesn't matter
whether the variables are pointing to the same object or not, if you
use ==, because two different objects holding the number -6 will
compare equal.

Hope that clarifies it!

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


is there a difference between one line and many lines

2011-04-21 Thread vino19
Hello, I'm a newbie.
What's the defference between

>>>a=-6; b=-6; a is b
>>>True

and

>>>a=-6
>>>b=-6
>>>a is b
>>>False

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


How deal with the coding

2011-04-21 Thread 1011_wxy
Dear All:
I got a coding problem when I use python to read html from web which is encode 
with gb2312,
ater I insert the data I read from web into Oracle DB with coding gbk, I found 
messy code by select from PL/SQL.
I tried the way ".encode('gbk','ignore')" before insert Oracle by using 
cx_Oracle,but not effective.
How can I deal with the coding?
 
Thanks a lot
Best Regards
 
Kerry
2011-04-21-- 
http://mail.python.org/mailman/listinfo/python-list


Re: learnpython.org - an online interactive Python tutorial

2011-04-21 Thread Heiko Wundram
Am 21.04.2011 09:19, schrieb Chris Angelico:
> On Thu, Apr 21, 2011 at 5:10 PM, Algis Kabaila  wrote:
>> False: Python IS strongly typed, without doubt (though the
>> variables are not explicitly declared.)
> 
> Strongly duck-typed though. If I create a class that has all the right
> members, it can simultaneously be a file, an iterable, a database, and
> probably even a web browser if it feels like it. Is that strong typing
> or not?

Yes, that's strong typing, because your class only works in those
contexts that you "explicitly" allow it to work in (through implementing
an interface, be it an iterator, a file, etc.), independent of
"duck-typing" (which is pretty much described by the term
interface-based typing IMHO).

The difference between strong typing and weak typing is best described by:

Python 2.6.5 (r265:79063, Jun 12 2010, 17:07:01)
[GCC 4.3.4 20090804 (release) 1] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 1+'2'
Traceback (most recent call last):
  File "", line 1, in 
TypeError: unsupported operand type(s) for +: 'int' and 'str'
>>>

which means that the interface for implementing "+" on the input types
"int" and "str" isn't implemented (i.e., TypeError). Weakly typed
languages allow this to work:

modelnine@gj-celle ~ $ php

3
modelnine@gj-celle ~ $

through all kinds of type-casting magic, which isn't explicitly
specified as interfaces on the objects (PHP also has integer and string
objects) themselves.

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


Re: learnpython.org - an online interactive Python tutorial

2011-04-21 Thread harrismh777

Algis Kabaila wrote:

[quote]
Python is completely object oriented, and not "strongly typed"
[/quote]

False: Python IS strongly typed, without doubt (though the
variables are not explicitly declared.)




Playing the advocate for a moment here, this is something that I was 
confused about early on also... and frankly, you are both correct, but 
from different vantage points.


Python IS strongly typed in that operations may only be applied to 
objects that support 'that' operation... numbers support (+) and also 
strings support (+) ,  although, the (+) does 'different' things 
depending on the object type. You might look at this as STRONGLY typed 
and you would be correct...  however, you might look on this as weakly 
typed and you would still be correct... because why?


Because, the programmer doesn't have to worry about the 'types' she is 
using ... the object based nature of the language and polymorphism come 
together so that the 'right thing' happens with (+) regardless of 
type...   see?  weakly typed...


In C the programmer is always considering what 'type' is this thing... 
even testing for it... and C is considered by those programmers (yes, me 
) as STRONGLY typed. The types must be declared ahead of time for sure, 
but that's not the point...  the point is that the 'type' matters and 
must always be on the front lobes in thinking about logic.


In Python much of the thinking about types is not even necessary.. for 
the most part... and by design. In this way of thinking the language is 
weakly typed...  on the other hand, because the objects may be only 
manipulated by operations they support, this makes Python STRONGLY 
typed.   Confused yet???


How one thinks about this depends on programming background, what is 
meant by 'type' and how the programmer differentiates thinking about 
types as variables versus objects.


Having said all of that, I agree that Python should be classified as 
STRONGLY typed... and this classification should always come with an 
explanation ... especially to new advocates writing tutorials...


kind regards,
m harris
--
http://mail.python.org/mailman/listinfo/python-list


Re: Vectors

2011-04-21 Thread Algis Kabaila
On Thursday 21 April 2011 01:49:57 Andreas Tawn wrote:
> > On Apr 20, 6:43 am, Andreas Tawn  
wrote:
> > > > Algis Kabaila  writes:
> > > > > Are there any modules for vector algebra (three
> > > > > dimensional vectors, vector addition, subtraction,
> > > > > multiplication [scalar and vector]. Could you give
> > > > > me a reference to such module?
> > > > 
> > > > NumPy has array (and matrix) types with support for
> > > > these basic operations you mention. See the tutorial
> > > > athttp://numpy.scipy.org/
> > > 
> > > You might also want to
> > > considerhttp://code.google.com/p/pyeuclid/
> > > 
> > > Cheers,
> > > 
> > > Drea
> > 
> > Pyeuclid docs don't mention dot or cross products.
> > RJB
> 
> http://partiallydisassembled.net/euclid/vector-classes.html#S
> ECTION00222
> 
> Bottom of the page.
> 
> Cheers,
> 
> Drea

Yes, pyeuclid had "cross" and "dot" product of vectors. I am 
impressed with it and curious how it works:  the Vector3 class 
is available without any prefix euclid:

import euclid 
v = Vector3(111.., 222.2, 333.3)

works without  requiring as in:
v = euclid.Vector3( etc...)

I am really intrigued by that. OTOH, I also am somewhat 
aprehensive about using something that affects the program 
writing after importing "euclid", without any need to explicitly 
refer to euclid.  Looks rather risky to me.  What does that do 
to the namespace?

Thanks for bringing this to my attention.  I confess that I 
would be hapier if euclid was accessible in a "standard" manner 
with prefix of module name for classes in the module.

OldAl.

-- 
Algis
http://akabaila.pcug.org.au/StructuralAnalysis.pdf
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: learnpython.org - an online interactive Python tutorial

2011-04-21 Thread Chris Angelico
On Thu, Apr 21, 2011 at 5:10 PM, Algis Kabaila  wrote:
> False: Python IS strongly typed, without doubt (though the
> variables are not explicitly declared.)

Strongly duck-typed though. If I create a class that has all the right
members, it can simultaneously be a file, an iterable, a database, and
probably even a web browser if it feels like it. Is that strong typing
or not?

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


Re: Hello Sweet Friends

2011-04-21 Thread Ian Kelly
On Thu, Apr 21, 2011 at 12:28 AM, harrismh777  wrote:
>   I don't like SPAM with my eggs and ham...

Nor do the rest of us, so please don't help it circumvent our spam
filters by reposting it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: learnpython.org - an online interactive Python tutorial

2011-04-21 Thread Algis Kabaila
On Thursday 21 April 2011 03:15:50 Ron wrote:
> Hey everyone.
> 
> I've written an online interactive Python tutorial atop
> Google App Engine: http://www.learnpython.org.
> 
> All you need to do is log in using your Google account and
> edit the wiki to add your tutorials.
> 
> Read more on the website.
> 
> Thanks for your help, and I would appreciate if you help me
> spread the word, and give me feedback on the website.

[quote]
Python is completely object oriented, and not "strongly typed"
[/quote]

False: Python IS strongly typed, without doubt (though the 
variables are not explicitly declared.)

Explicit declaration and strong typing are two completely 
differen things.  If you are going to teach (and that is what 
tutorials are for), it is obligatory to learn first...

OldAl.
-- 
Algis
http://akabaila.pcug.org.au/StructuralAnalysis.pdf
-- 
http://mail.python.org/mailman/listinfo/python-list