Re: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all?

2010-07-30 Thread Gregory Ewing

Steven D'Aprano wrote:

super() is just as explicit as len(), or str.upper(). It says, 
explicitly, that it will call the method belonging to one or more 
superclass of the given class.


That's not strictly true. It will call a method belonging to some
class in the mro of self, but that class is not necessarily in
the base list of the class mentioned in the super() call. It's
possible for a super() call to go sideways in the inheritance
graph.

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


Re: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all?

2010-07-30 Thread Gregory Ewing

Steven D'Aprano wrote:

On Thu, 29 Jul 2010 19:29:24 +0200, Jean-Michel Pichavant wrote:



mro would have been the proper name for super.


That's your opinion. In any case, whether super() was called super() or 
mro() or aardvark() makes no difference to the functionality or whether 
it is useful.


I think the point is that the name is misleading, because it
makes it *sound* like it's going to call a method in a superclass,
when it fact it might not.

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


Re: Newbie question regarding SSL and certificate verification

2010-07-30 Thread Gregory Ewing

David Robinow wrote:

Never
use security software version 1.0 or greater. It was written by an
author insufficiently paranoid.


Hmmm. So to get people to trust your security software, you
should start with version 0.0 and increment by 0.001
for each release. :-)

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


how to build same executabl with and without console output

2010-07-30 Thread Gelonida
Hi,


What I'd like to achieve ideally is to create a py2exe program,
which
will only display a window (so 'compiled' as 'windows'-application) if
called normally.

however if being called with the option --debug it should display the
graphical window plus a debug console where I can print to.



Is there any trick in adding a console window to an application,
that was built as 'windows' application?




If above is not possible:

Is there any way to compile the same python script (myprog.py) from one
py2exe script into once a 'windows' executable (myprog.exe) and once
into a 'console' executable (myprog_debug.exe)?




TIA




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


Re: default behavior

2010-07-30 Thread Peter Otten
wheres pythonmonks wrote:

 How do I build an int1 type that has a default value of 1?
 [Hopefully no speed penalty.]
 I am thinking about applications with collections.defaultdict.

 from collections import defaultdict
 d = defaultdict(1 .conjugate)
 d[x] += 2
 d[x]
3

Isn't that beautiful? Almost like home;)

It is also fast:

$ python -m timeit -sone = lambda: 1 one()
100 loops, best of 3: 0.213 usec per loop
$ python -m timeit -sone = 1 .conjugate one()
1000 loops, best of 3: 0.0972 usec per loop

Micro-optimisation, the best excuse for ugly code...

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


Re: stdout of external program.

2010-07-30 Thread Jean-Michel Pichavant

Paul Lemelle wrote:

HELP! :)

I am trying to output the following program's output to either a file 
or variable, how can this be done?


# Writing the output to a standard argv argument

#1/usr/bin/python

import sys

for arg in sys.argv:
  print arg

#END

Thanks,
Paul


Hi Paul, after reading 4 times your post, I still don't see what you 
want to achieve.

What are you calling a variable ? an os variable ?

import sys

file = open('testfile.txt', 'w')
file.write(str(sys.argv))
file.close()

second hit when googling your question:
http://docs.python.org/tutorial/inputoutput.html

JM






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


Re: [Py2exe-users] how to build same executabl with and without console output

2010-07-30 Thread Jimmy Retzlaff
On Fri, Jul 30, 2010 at 1:10 AM, Gelonida gelon...@gmail.com wrote:
 What I'd like to achieve ideally is to create a py2exe program,
 which
 will only display a window (so 'compiled' as 'windows'-application) if
 called normally.

 however if being called with the option --debug it should display the
 graphical window plus a debug console where I can print to.

 Is there any trick in adding a console window to an application,
 that was built as 'windows' application?

 If above is not possible:

 Is there any way to compile the same python script (myprog.py) from one
 py2exe script into once a 'windows' executable (myprog.exe) and once
 into a 'console' executable (myprog_debug.exe)?

I can't think of an easy way to achieve the first approach - I've
always taken the second approach. The advanced example included with
py2exe has an example of how to do this. Look at all the occurrences
of test_wx in the following link to see all the pieces involved:

http://py2exe.svn.sourceforge.net/viewvc/py2exe/trunk/py2exe/py2exe/samples/advanced/setup.py?view=markup

This uses an alternate form of the windows and console arguments
where each target is an object with specially named member variables
rather than a string that names the .py file (this string is one of
the member variables). This is necessary so you can give different
names to the console version and the windows version.

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


Re: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all?

2010-07-30 Thread Jean-Michel Pichavant

Steven D'Aprano wrote:

On Thu, 29 Jul 2010 19:29:24 +0200, Jean-Michel Pichavant wrote:

  
[snip]

As someone already said in this list, the main problem with super is
that it tends to refer to the superclass method while in fact it calls
the next MRO method.



Why do you think that is a problem? That's what it is supposed to do, 
because that's what is needed to correctly implement multiple inheritance.



  

mro would have been the proper name for super.



That's your opinion. In any case, whether super() was called super() or 
mro() or aardvark() makes no difference to the functionality or whether 
it is useful.




  
I have no problem with dogs nor cats, however I have problem with cats 
called dogs and dogs called cats as I'm dealing with industrial 
programming, not litterature nor poetry.


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


Re: default behavior

2010-07-30 Thread Duncan Booth
Peter Otten __pete...@web.de wrote:

 from collections import defaultdict
 d = defaultdict(1 .conjugate)
 d[x] += 2
 d[x]
 3
 
 Isn't that beautiful? Almost like home;)
 
 It is also fast:
 
 $ python -m timeit -sone = lambda: 1 one()
 100 loops, best of 3: 0.213 usec per loop
 $ python -m timeit -sone = 1 .conjugate one()
 1000 loops, best of 3: 0.0972 usec per loop
 
 Micro-optimisation, the best excuse for ugly code...
 

Nice one, but if you are going to micro-optimise why not save a few 
keystrokes while you're at it and use '1 .real' instead?

-- 
Duncan Booth http://kupuguy.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: default behavior

2010-07-30 Thread Peter Otten
Duncan Booth wrote:

 Peter Otten __pete...@web.de wrote:
 
 from collections import defaultdict
 d = defaultdict(1 .conjugate)
 d[x] += 2
 d[x]
 3
 
 Isn't that beautiful? Almost like home;)
 
 It is also fast:
 
 $ python -m timeit -sone = lambda: 1 one()
 100 loops, best of 3: 0.213 usec per loop
 $ python -m timeit -sone = 1 .conjugate one()
 1000 loops, best of 3: 0.0972 usec per loop
 
 Micro-optimisation, the best excuse for ugly code...
 
 
 Nice one, but if you are going to micro-optimise why not save a few
 keystrokes while you're at it and use '1 .real' instead?

 1 .real
1
 1 .conjugate
built-in method conjugate of int object at 0x1734298
 1 .conjugate()

real is a property, not a method. conjugate() was the first one that worked 
that was not __special__. I think it has the added benefit that it's likely 
to confuse the reader...

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


Re: default behavior

2010-07-30 Thread Duncan Booth
Peter Otten __pete...@web.de wrote:
 real is a property, not a method. conjugate() was the first one that
 worked that was not __special__. I think it has the added benefit that
 it's likely to confuse the reader...
 
Ah, silly me, I should have realised that.

Yes, micro-optimisations that are also micro-obfuscations are always the 
best. :^)

-- 
Duncan Booth http://kupuguy.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python styles: why Use spaces around arithmetic operators?

2010-07-30 Thread Lawrence D'Oliveiro
In message mailman.1246.1280302904.1673.python-l...@python.org, J.B. Brown 
wrote:

 I personally prefer to be slightly excessive in the amount of spacing
 I used, especially when parentheses are involved.
 
 myTuple = ( 1, 2, 3, 4, 5 )

Parentheses are punctuation. Why not leave spaces around the commas as well, 
to be consistent?

myTuple = ( 1 , 2 , 3 , 4 , 5 )

T,FTFY.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Py2exe-users] how to build same executabl with and without console output

2010-07-30 Thread python
 Is there any trick in adding a console window to an application, that was 
 built as 'windows' application?

I was recently wondering the same thing myself. My research indicates
that its not possible to have a single Windows application that can run
in both console and GUI (Windows) modes.

Here are 2 links that explain this in more detail.

http://stackoverflow.com/questions/493536/can-one-executable-be-both-a-console-and-gui-app
http://objectmix.com/delphi/403126-sending-output-stdout-non-console-app.html

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


Normalizing A Vector

2010-07-30 Thread Lawrence D'Oliveiro
Say a vector V is a tuple of 3 numbers, not all zero. You want to normalize 
it (scale all components by the same factor) so its magnitude is 1.

The usual way is something like this:

L = math.sqrt(V[0] * V[0] + V[1] * V[1] + V[2] * V[2])
V = (V[0] / L, V[1] / L, V[2] / L)

What I don’t like is having that intermediate variable L leftover after the 
computation. Here’s how to do it in one step:

V = tuple \
  (
  x
  /
  math.sqrt
(
  reduce(lambda a, b : a + b, (y * y for y in V), 0)
)
  for x in V
  )

which, incidentally, also works for vectors with dimensions other than 3.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all?

2010-07-30 Thread Steven D'Aprano
On Fri, 30 Jul 2010 19:35:52 +1200, Gregory Ewing wrote:

 Steven D'Aprano wrote:
 
 super() is just as explicit as len(), or str.upper(). It says,
 explicitly, that it will call the method belonging to one or more
 superclass of the given class.
 
 That's not strictly true. It will call a method belonging to some class
 in the mro of self, but that class is not necessarily in the base list
 of the class mentioned in the super() call. 

Yes, that's what I said. super() can visit any superclass of the given 
class, not just one of the immediate base class(es). That's why it's 
called super() rather than base() or parent(). It would be rather 
pointless if super() was limited to just the base classes.


 It's possible for a super()
 call to go sideways in the inheritance graph.

I doubt that very much. A class F can't inherit behaviour from a class E 
merely by virtue of them both being subclasses of the same hierarchy. If 
it did, that would be... disturbing.

Example:

E inherits from D.
D inherits from C and B.
C and B both inherit from A.
F also inherits from C.

F and E are sideways to each other (sibling classes?), but they don't 
inherit from each other.

Perhaps you're referring to the angled lines in a diagram such as:

  A
 / \
C   B
 \ /
  D
 / \
E   F

F and E don't inherit from each other, because they are sidewards to each 
other (they are not in each other's MRO). Regardless of the angles we 
draw the lines, all of D, C, B, A are above E (and F). Or downwards if 
you prefer to reverse the diagram. Yes, a super call might jog left from 
C to B, but only when being called from one of the lower classes D-F. 
That's still an upwards call relative to the originator, not sidewards.



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


Re: default behavior

2010-07-30 Thread wheres pythonmonks
Instead of defaultdict for hash of lists, I have seen something like:


m={}; m.setdefault('key', []).append(1)

Would this be preferred in some circumstances?
Also, is there a way to upcast a defaultdict into a dict?  I have also
heard some people use exceptions on dictionaries to catch key
existence, so passing in a defaultdict (I guess) could be hazardous to
health.  Is this true?

W




On Fri, Jul 30, 2010 at 6:56 AM, Duncan Booth
duncan.bo...@invalid.invalid wrote:
 Peter Otten __pete...@web.de wrote:
 real is a property, not a method. conjugate() was the first one that
 worked that was not __special__. I think it has the added benefit that
 it's likely to confuse the reader...

 Ah, silly me, I should have realised that.

 Yes, micro-optimisations that are also micro-obfuscations are always the
 best. :^)

 --
 Duncan Booth http://kupuguy.blogspot.com
 --
 http://mail.python.org/mailman/listinfo/python-list

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


Re: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all?

2010-07-30 Thread Steven D'Aprano
On Fri, 30 Jul 2010 19:37:29 +1200, Gregory Ewing wrote:

 Steven D'Aprano wrote:
 On Thu, 29 Jul 2010 19:29:24 +0200, Jean-Michel Pichavant wrote:
  
mro would have been the proper name for super.
 
 That's your opinion. In any case, whether super() was called super() or
 mro() or aardvark() makes no difference to the functionality or whether
 it is useful.
 
 I think the point is that the name is misleading, because it makes it
 *sound* like it's going to call a method in a superclass, when it fact
 it might not.

I'm not sure I understand your point here. If you call super() from a 
method that doesn't exist in any superclass, then you are correct, it 
won't call a method in a superclass, and will raise AttributeError.

But in the more sensible case that you only call super() when there is 
actually something to inherit, then of course it calls the method in a 
superclass. It certainly doesn't call methods from arbitrary unrelated 
classes, only those which are in the MRO. That is, superclasses.

If Z is below A in the hierarchy, then we have no difficulty in 
identifying Z as a subclass of A, and likewise we should have no problem 
with identifying A as *a* (and not the) superclass of Z, no matter how 
distant they are or how tangled the DIG between them. 

The exception would be if you could have loops in the class hierarchy, in 
which case the concepts of super- and sub-classes breaks down completely. 
But even if some other languages allowed that, Python doesn't, so we're 
safe.



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


Re: default behavior

2010-07-30 Thread Steven D'Aprano
On Fri, 30 Jul 2010 07:59:52 -0400, wheres pythonmonks wrote:

 Instead of defaultdict for hash of lists, I have seen something like:
 
 
 m={}; m.setdefault('key', []).append(1)
 
 Would this be preferred in some circumstances? 

Sure, why not? Whichever you prefer.

setdefault() is a venerable old technique, dating back to Python 2.0, and 
not a newcomer like defaultdict.


 Also, is there a way to upcast a defaultdict into a dict?

Upcast? Surely it is downcasting. Or side-casting. Or type-casting. 
Whatever. *wink*

Whatever it is, the answer is Yes:

 from collections import defaultdict as dd
 x = dd(int)
 x[1] = 'a'
 x
defaultdict(type 'int', {1: 'a'})
 dict(x)
{1: 'a'}



 I have also heard some people use
 exceptions on dictionaries to catch key existence, so passing in a
 defaultdict (I guess) could be hazardous to health.  Is this true?

Yes, it is true that some people use exceptions on dicts to catch key 
existence. The most common reason to do so is to catch the non-existence 
of a key so you can add it:

try:
mydict[x] = mydict[x] + 1
except KeyError:
mydict[x] = 1


If mydict is a defaultdict with the appropriate factory, then the change 
is perfectly safe because mydict[x] will not raise an exception when x is 
missing, but merely return 0, so it will continue to work as expected and 
all is good.

Of course, if you pass it an defaultdict with an *inappropriate* factory, 
you'll get an error. So don't do that :) Seriously, you can't expect to 
just randomly replace a variable with some arbitrarily different variable 
and expect it to work. You need to know what the code is expecting, and 
not break those expectations too badly.

And now you have at least three ways of setting missing values in a dict. 
And those wacky Perl people say that Python's motto is only one way to 
do it :)



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


Re: default behavior

2010-07-30 Thread Peter Otten
wheres pythonmonks wrote:

 Instead of defaultdict for hash of lists, I have seen something like:
 
 
 m={}; m.setdefault('key', []).append(1)
 
 Would this be preferred in some circumstances?

In some circumstances, sure. I just can't think of them at the moment. 
Maybe if your code has to work in Python 2.4.

 Also, is there a way to upcast a defaultdict into a dict?  

dict(some_defaultdict)

 I have also
 heard some people use exceptions on dictionaries to catch key
 existence, so passing in a defaultdict (I guess) could be hazardous to
 health.  Is this true?

A problem could arise when you swap a key in dict test with a 
try...except KeyError. This would be an implementation detail for a dict 
but affect the contents of a defaultdict:

 from collections import defaultdict
 def update(d):
... for c in abc:
... try: d[c]
... except KeyError: d[c] = c
...
 d = defaultdict(lambda:-)
 update(d)
 d
defaultdict(function lambda at 0x7fd4ce32a320, {'a': '-', 'c': '-', 'b': 
'-'})
 def update2(d):
... for c in abc:
... if c not in d:
... d[c] = c
...
 d = defaultdict(lambda:-)
 update2(d)
 d
defaultdict(function lambda at 0x7fd4ce32a6e0, {'a': 'a', 'c': 'c', 'b': 
'b'})

Peter

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


Re: default behavior

2010-07-30 Thread wheres pythonmonks
Sorry, doesn't the following make a copy?

 from collections import defaultdict as dd
 x = dd(int)
 x[1] = 'a'
 x
 defaultdict(type 'int', {1: 'a'})
 dict(x)
 {1: 'a'}




I was hoping not to do that -- e.g., actually reuse the same
underlying data.  Maybe dict(x), where x is a defaultdict is smart?  I
agree that a defaultdict is safe to pass to most routines, but I guess
I could imagine that a try/except block is used in a bit of code where
on the key exception (when the value is absent)  populates the value
with a random number.  In that application, a defaultdict would have
no random values.


Besides a slightly different favor, does the following have
applications not covered by defaultdict?

m.setdefault('key', []).append(1)

I think I am unclear on the difference between that and:

m['key'] = m.get('key',[]).append(1)

Except that the latter works for immutable values as well as containers.

On Fri, Jul 30, 2010 at 8:19 AM, Steven D'Aprano
st...@remove-this-cybersource.com.au wrote:
 On Fri, 30 Jul 2010 07:59:52 -0400, wheres pythonmonks wrote:

 Instead of defaultdict for hash of lists, I have seen something like:


 m={}; m.setdefault('key', []).append(1)

 Would this be preferred in some circumstances?

 Sure, why not? Whichever you prefer.

 setdefault() is a venerable old technique, dating back to Python 2.0, and
 not a newcomer like defaultdict.


 Also, is there a way to upcast a defaultdict into a dict?

 Upcast? Surely it is downcasting. Or side-casting. Or type-casting.
 Whatever. *wink*

 Whatever it is, the answer is Yes:

 from collections import defaultdict as dd
 x = dd(int)
 x[1] = 'a'
 x
 defaultdict(type 'int', {1: 'a'})
 dict(x)
 {1: 'a'}



 I have also heard some people use
 exceptions on dictionaries to catch key existence, so passing in a
 defaultdict (I guess) could be hazardous to health.  Is this true?

 Yes, it is true that some people use exceptions on dicts to catch key
 existence. The most common reason to do so is to catch the non-existence
 of a key so you can add it:

 try:
    mydict[x] = mydict[x] + 1
 except KeyError:
    mydict[x] = 1


 If mydict is a defaultdict with the appropriate factory, then the change
 is perfectly safe because mydict[x] will not raise an exception when x is
 missing, but merely return 0, so it will continue to work as expected and
 all is good.

 Of course, if you pass it an defaultdict with an *inappropriate* factory,
 you'll get an error. So don't do that :) Seriously, you can't expect to
 just randomly replace a variable with some arbitrarily different variable
 and expect it to work. You need to know what the code is expecting, and
 not break those expectations too badly.

 And now you have at least three ways of setting missing values in a dict.
 And those wacky Perl people say that Python's motto is only one way to
 do it :)



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

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


The untimely dimise of a weak-reference

2010-07-30 Thread Vincent van Beveren
Hi everyone,

I was working with weak references in Python, and noticed that it was 
impossible to create a weak-reference of bound methods. Here is a little python 
3.0 program to prove my point:

import weakref

print(Creating object...)
class A(object):

def b(self):
print(I am still here)

a = A()

def d(r):
print(Aaah! Weakref lost ref) 

print(Creating weak reference)

r = weakref.ref(a.b, d)

print(Oh, wait, its already gone!)
print(Ref == None, cause of untimely demise: %s % r())
print(Object is still alive: %s % a)
print(Function is still exists: %s % a.b)
print(See:)
a.b()

I also tried this in Python 2.5 and 2.6 (with minor modifications to the syntax 
of course), and it yielded the exact same behavior. Why is this, and is there 
anything I can do about it? I wish to reference these bound functions, but I do 
not want to keep them in memory once the object they belong to is no longer 
referenced.
 
Regards,
Vincent van Beveren

___
Ing. V. van Beveren
Software Engineer, FOM Rijnhuizen
E: v.vanbeve...@rijnhuizen.nl

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


Re: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all?

2010-07-30 Thread Jean-Michel Pichavant

Steven D'Aprano wrote:

On Fri, 30 Jul 2010 19:37:29 +1200, Gregory Ewing wrote:

  

Steven D'Aprano wrote:


On Thu, 29 Jul 2010 19:29:24 +0200, Jean-Michel Pichavant wrote:
  

 


mro would have been the proper name for super.


That's your opinion. In any case, whether super() was called super() or
mro() or aardvark() makes no difference to the functionality or whether
it is useful.
  

I think the point is that the name is misleading, because it makes it
*sound* like it's going to call a method in a superclass, when it fact
it might not.



I'm not sure I understand your point here. If you call super() from a 
method that doesn't exist in any superclass, then you are correct, it 
won't call a method in a superclass, and will raise AttributeError.


But in the more sensible case that you only call super() when there is 
actually something to inherit, then of course it calls the method in a 
superclass. It certainly doesn't call methods from arbitrary unrelated 
classes, only those which are in the MRO. That is, superclasses.


If Z is below A in the hierarchy, then we have no difficulty in 
identifying Z as a subclass of A, and likewise we should have no problem 
with identifying A as *a* (and not the) superclass of Z, no matter how 
distant they are or how tangled the DIG between them. 

The exception would be if you could have loops in the class hierarchy, in 
which case the concepts of super- and sub-classes breaks down completely. 
But even if some other languages allowed that, Python doesn't, so we're 
safe.




  

Quoting Michele's article (I think he's still hanging around this list)

Readers familiar will single inheritance languages, such as Java or 
Smalltalk, will have a clear concept of superclass in mind. This 
concept, however, has /no useful meaning/ in Python or in other multiple 
inheritance languages.



the complete article on super:
http://www.artima.com/weblogs/viewpost.jsp?thread=236275

super is  a strange name for something that makes no sense in python 
(talking about superclass here). It doesn't take away the usefulness of 
super, but it's a proof that you can ruin a good feature with a bad name.


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


Basic Information about Python

2010-07-30 Thread Durga D
Hi All,

  I am new to python based application developement. I am using
Windows XP.

  1. Can I create desktop application (just hello world program) with
Python
language like exe in VC++?

  2. If First statement is Yes, Can I include this application with
my
existing setup(assume 10 MB) for windows?

  3. If Second statement is Yes, What will be the setup size?

  Thank in advance.

Regards,
Durga.

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


RE: Ascii to Unicode.

2010-07-30 Thread Lawrence D'Oliveiro
In message mailman.1309.1280426398.1673.python-l...@python.org, Joe 
Goldthwaite wrote:

 Ascii.csv isn't really a latin-1 encoded file.  It's an ascii file with a
 few characters above the 128 range that are causing Postgresql Unicode
 errors.  Those characters work fine in the Windows world but they're not
 the correct byte representation for Unicode.

In other words, the encoding you want to decode from in this case is 
windows-1252.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Ascii to Unicode.

2010-07-30 Thread Lawrence D'Oliveiro
In message 4c51d3b6$0$1638$742ec...@news.sonic.net, John Nagle wrote:

 UTF-8 is a stream format for Unicode.  It's slightly compressed ...

“Variable-length” is not the same as “compressed”.

Particularly if you’re mainly using non-Roman scripts...

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


RE: Ascii to Unicode.

2010-07-30 Thread Lawrence D'Oliveiro
In message mailman.1307.1280425706.1673.python-l...@python.org, Joe 
Goldthwaite wrote:

 Next I tried to write the unicodestring object to a file thusly;
 
 output.write(unicodestring)
 
 I would have expected the write function to request the byte string from
 the unicodestring object and simply write that byte string to a file.

Encoded according to which encoding?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: solving Tix problem in ubuntu jaunty

2010-07-30 Thread Lawrence D'Oliveiro
In message
7cbe39d0-cac8-41d8-b80a-a148ac4b7...@q21g2000prm.googlegroups.com, 
jimgardener wrote:

 How do I correct the problem?

http://code.google.com/p/metageta/issues/detail?id=33
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Basic Information about Python

2010-07-30 Thread Jean-Michel Pichavant

Durga D wrote:

Hi All,

  I am new to python based application developement. I am using
Windows XP.

  1. Can I create desktop application (just hello world program) with
Python
language like exe in VC++?
  

yes
http://www.py2exe.org/

  2. If First statement is Yes, Can I include this application with
my
existing setup(assume 10 MB) for windows?
  

you mean include it in a windows installer ? If so yes.

  3. If Second statement is Yes, What will be the setup size?

  
  Thank in advance.


Regards,
Durga.

  


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


Re: urllib timeout

2010-07-30 Thread Lawrence D'Oliveiro
In message 
43f464f9-3f8a-4bec-8d06-930092d5a...@g6g2000pro.googlegroups.com, kBob 
wrote:

  The company changed the Internet LAN connections to Accept Automatic
 settings and Use automatic configuration script

Look at that configuration script, figure out what it’s returning for a 
proxy, and put that into your Python script.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The untimely dimise of a weak-reference

2010-07-30 Thread Peter Otten
Vincent van Beveren wrote:

 Hi everyone,
 
 I was working with weak references in Python, and noticed that it was
 impossible to create a weak-reference of bound methods. Here is a little
 python 3.0 program to prove my point:
 
 import weakref
 
 print(Creating object...)
 class A(object):
 
 def b(self):
 print(I am still here)
 
 a = A()
 
 def d(r):
 print(Aaah! Weakref lost ref)
 
 print(Creating weak reference)
 
 r = weakref.ref(a.b, d)

The instance doesn't keep a reference of its bound method. Rather the bound 
method keeps a reference of its instance. Every time you say

a.b

you get a different bound method. What do you think should keep it alive?

 
 print(Oh, wait, its already gone!)
 print(Ref == None, cause of untimely demise: %s % r())
 print(Object is still alive: %s % a)
 print(Function is still exists: %s % a.b)
 print(See:)
 a.b()
 
 I also tried this in Python 2.5 and 2.6 (with minor modifications to the
 syntax of course), and it yielded the exact same behavior. Why is this,
 and is there anything I can do about it? I wish to reference these bound
 functions, but I do not want to keep them in memory once the object they
 belong to is no longer referenced.

I fear you have to manage the methods' lifetime explicitly.

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


Re: measuring a function time

2010-07-30 Thread Hrvoje Niksic
Steven D'Aprano st...@remove-this-cybersource.com.au writes:

 On Thu, 29 Jul 2010 14:42:58 +0200, Matteo Landi wrote:

 This should be enough
 
import time
tic = time.time()
function()
toc = time.time()
print toc - tic

 You're typing that in the interactive interpreter, which means the
 timer is counting the seconds while you're typing subsequent
 commands. At the very least, you need to put that code into a
 function.

Or, trivially improved as follows:

 t0 = time.time(); function(); t1 = time.time()
 print t1 - t0

This technique, while nowhere nearly as thorough as the timeit module,
still gives useful results for simple measurements.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all?

2010-07-30 Thread Hrvoje Niksic
Gregory Ewing greg.ew...@canterbury.ac.nz writes:

 I think the point is that the name is misleading, because it makes it
 *sound* like it's going to call a method in a superclass, when it fact
 it might not.

That is indeed confusing to some people, especially those who refuse to
to accept the notion that superclass means the same as next in MRO,
maintaining instead that superclass refers to one of the base classes,
their bases, etc. -- IMO a defensible position.

super might have better been called next_in_mro, next_method, or
next_class, except those are harder to type, and way less catchy than
super.  The Dylan and CLOS operator that super is most closely based
on is called (call-)next-method.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: combined functionality of ipython's %whos and pdb's next (without a resource heavy IDE)

2010-07-30 Thread Ed Leafe
On Jul 29, 2010, at 3:39 PM, Benjamin J. Racine wrote:

 I am trying to combine the ability to move line-by-line through the code as 
 is done with pdb's next function with ipython's ability to list all 
 variables at once... without the use of a full-fledged IDE.
 
 I am not seeing how this might be done.  Many thanks for your help...

Check out PuDB - I use it all the time. http://pypi.python.org/pypi/pudb

Intro screencast is at http://vimeo.com/5255125


-- Ed Leafe



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


pylint scores

2010-07-30 Thread wheres pythonmonks
I am starting to use pylint to look at my code and I see that it gives a rating.
What values do experienced python programmers get on code not
targeting the benchmark?

I wrote some code, tried to keep it under 80 characters per line,
reasonable variable names, and I got:

0.12 / 10.

Is this a good score for one not targeting the benchmark?  (pylint
running in default mode)

Somewhat related:  Is the backslash the only way to extend arguments
to statements over multiple lines?  (e.g.)

 def f(x,y,z): return(x+y+z);
...
 f(1,2,
... 3)
6
 assert f(1,2,3)0,
  File stdin, line 1
assert f(1,2,3)0,
 ^
SyntaxError: invalid syntax


In the above, I could split the arguments to f (I guess b/c of the
parens) but not for assert.  I could use a backslash, but I find this
ugly -- it that my only (best?) option?

[I really like to assert my code to correctness and I like using the
second argument to assert, but this resulted in a lot of long lines
that I was unable to break except with an ugly backslash.]

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


Problem with Elementtree and XMLSchem instance type

2010-07-30 Thread Roland Hedberg
Hi!

I have the following XML snippet:

RoleDescriptor
xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance;
xmlns:fed=http://docs.oasis-open.org/wsfed/federation/200706;
xsi:type=fed:SecurityTokenServiceType

/RoleDescriptor

This part after parsing with Elementtree gives me an Element instance
with the following properties:

 tree.tag
{urn:oasis:names:tc:SAML:2.0:metadata}RoleDescriptor
 tree.keys()
['{http://www.w3.org/2001/XMLSchema-instance}type']
 tree['{http://www.w3.org/2001/XMLSchema-instance}type']
fed:SecurityTokenServiceType

And there is the problem, I've lost the coupling between the prefix
'fed' and the namespace
http://docs.oasis-open.org/wsfed/federation/200706;.

Is there any way I can get at the prefix - namespace mapping from an
Element instance ?
I've read the documentation I can find and there is nothing that tells
me how to get at the mapping.

If I print the Element instance the prefix 'fed' is replace by 'ns0' or
something like that.
Definitely something that has no connection to the original 'fed'.

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


Re: pylint scores

2010-07-30 Thread Peter Otten
wheres pythonmonks wrote:

 I am starting to use pylint to look at my code and I see that it gives a
 rating. What values do experienced python programmers get on code not
 targeting the benchmark?
 
 I wrote some code, tried to keep it under 80 characters per line,
 reasonable variable names, and I got:
 
 0.12 / 10.
 
 Is this a good score for one not targeting the benchmark?  (pylint
 running in default mode)

No. About 5 is typically OK for undocumented code. 
I've heard.

Ratings do not always make sense:

$ for f in /usr/lib/python2.6/{glob,csv,doctest,collections}.py; do echo $f; 
pylint 2/dev/null $f | grep Your code has; done
/usr/lib/python2.6/glob.py
Your code has been rated at 8.54/10
/usr/lib/python2.6/csv.py
Your code has been rated at 6.45/10
/usr/lib/python2.6/doctest.py
Your code has been rated at 7.77/10
/usr/lib/python2.6/collections.py
Your code has been rated at -4.71/10
$

For mainstream code you can easily reach 10 by adding bogus docstrings and 
pointless long variable names, i. e. you can get higher scores for lower 
code quality.

Peter

PS: My favourite wtf message is too few public methods

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


Re: Normalizing A Vector

2010-07-30 Thread Alain Ketterlin
Lawrence D'Oliveiro l...@geek-central.gen.new_zealand writes:

 Say a vector V is a tuple of 3 numbers, not all zero. You want to normalize 
 it (scale all components by the same factor) so its magnitude is 1.

 The usual way is something like this:

 L = math.sqrt(V[0] * V[0] + V[1] * V[1] + V[2] * V[2])
 V = (V[0] / L, V[1] / L, V[2] / L)

 What I don’t like is having that intermediate variable L leftover after the 
 computation.

Well, it also guarantees that the square root is computed once.

 Here’s how to do it in one step:

 V = tuple \
   ( x / math.sqrt
 (
   reduce(lambda a, b : a + b, (y * y for y in V), 0)
 )
   for x in V
   )

 which, incidentally, also works for vectors with dimensions other than 3.

And how many times does it call math.sqrt?

(That's actually not easy to test. Does any insider know the answer?
Does the compiler hoist the math.sqrt(...) out of the implicit loop? I
guess not, because it can't assert that reduce has no side effect.)

Your best bet is to define a function that does the normalization. Your
(local) name will disappear at the end of the call. If you want it to
work for any vector size:

def norm(V):
L = math.sqrt( sum( [x**2 for x in V] ) )
return [ x/L for x in V ]

If you do a lot of such computations, have a look at numpy.

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


Re: [Py2exe-users] how to build same executabl with and without console output

2010-07-30 Thread Dave Angel

pyt...@bdurham.com wrote:

Is there any trick in adding a console window to an application, that was built 
as 'windows' application?



I was recently wondering the same thing myself. My research indicates
that its not possible to have a single Windows application that can run
in both console and GUI (Windows) modes.

Here are 2 links that explain this in more detail.

http://stackoverflow.com/questions/493536/can-one-executable-be-both-a-console-and-gui-app
http://objectmix.com/delphi/403126-sending-output-stdout-non-console-app.html

Malcolm

  

Since we're talking MS Windows here, see:

http://msdn.microsoft.com/en-us/library/ms682528(VS.85).aspx

You can access the AllocConsole and related functions with the win32 module:
  win32console

This module is part of the win32 extensions, and also part of 
ActivePython distribution.


DaveA

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


Re: Basic Information about Python

2010-07-30 Thread Durga D
Hi JM,

   Thanks alot for your prompt response.

   If I include into windows setup, what will be setup size (assume
before include 10 MB)? i mean, python supporting dlls/libs size for
python exe.

Regards,
Durga.



On Jul 30, 6:04 pm, Jean-Michel Pichavant jeanmic...@sequans.com
wrote:
 Durga D wrote:
  Hi All,

    I am new to python based application developement. I am using
  Windows XP.

    1. Can I create desktop application (just hello world program) with
  Python
  language like exe in VC++?

 yeshttp://www.py2exe.org/   2. If First statement is Yes, Can I include this 
 application with
  my
  existing setup(assume 10 MB) for windows?

 you mean include it in a windows installer ? If so yes.

    3. If Second statement is Yes, What will be the setup size?

    Thank in advance.

  Regards,
  Durga.

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


RE: The untimely dimise of a weak-reference

2010-07-30 Thread Vincent van Beveren
Hi Peter,

I did not know the object did not keep track of its bound methods. What 
advantage is there in creating a new bound method object each time its 
referenced? It seems kind of expensive.

Regards,
Vincent

-Original Message-
From: Peter Otten [mailto:__pete...@web.de] 
Sent: vrijdag 30 juli 2010 15:06
To: python-list@python.org
Subject: Re: The untimely dimise of a weak-reference

Vincent van Beveren wrote:

 Hi everyone,
 
 I was working with weak references in Python, and noticed that it was
 impossible to create a weak-reference of bound methods. Here is a little
 python 3.0 program to prove my point:
 
 import weakref
 
 print(Creating object...)
 class A(object):
 
 def b(self):
 print(I am still here)
 
 a = A()
 
 def d(r):
 print(Aaah! Weakref lost ref)
 
 print(Creating weak reference)
 
 r = weakref.ref(a.b, d)

The instance doesn't keep a reference of its bound method. Rather the bound 
method keeps a reference of its instance. Every time you say

a.b

you get a different bound method. What do you think should keep it alive?

 
 print(Oh, wait, its already gone!)
 print(Ref == None, cause of untimely demise: %s % r())
 print(Object is still alive: %s % a)
 print(Function is still exists: %s % a.b)
 print(See:)
 a.b()
 
 I also tried this in Python 2.5 and 2.6 (with minor modifications to the
 syntax of course), and it yielded the exact same behavior. Why is this,
 and is there anything I can do about it? I wish to reference these bound
 functions, but I do not want to keep them in memory once the object they
 belong to is no longer referenced.

I fear you have to manage the methods' lifetime explicitly.

Peter

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


RE: The untimely dimise of a weak-reference

2010-07-30 Thread Peter Otten
Vincent van Beveren wrote:

 I did not know the object did not keep track of its bound methods. What
 advantage is there in creating a new bound method object each time its
 referenced? It seems kind of expensive.

While I didn't measure it I suppose that it saves a lot of memory.

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


Re: measuring a function time

2010-07-30 Thread Albert Hopkins
On Fri, 2010-07-30 at 14:28 +0200, Hrvoje Niksic wrote:
 Steven D'Aprano st...@remove-this-cybersource.com.au writes:
 
  On Thu, 29 Jul 2010 14:42:58 +0200, Matteo Landi wrote:
 
  This should be enough
  
 import time
 tic = time.time()
 function()
 toc = time.time()
 print toc - tic
 
  You're typing that in the interactive interpreter, which means the
  timer is counting the seconds while you're typing subsequent
  commands. At the very least, you need to put that code into a
  function.
 
 Or, trivially improved as follows:
 
  t0 = time.time(); function(); t1 = time.time()
  print t1 - t0

I'll just throw this out.  I sometimes use a decorator to keep track of
a functions execution times:


def timed_function(f):
Function decorator that records the execution time of a
function
import time
def funct(*args, **kwargs):
__starttime = time.time()
result = f(*args, **kwargs)
__endtime = time.time()
funct.runtime = __endtime - __starttime

return result
return funct

Then

 from goodies import timed_function
 from time import sleep
 @timed_function
... def test(n):
... sleep(n)
... 
 test(4)
 test.runtime
4.003864049911499

Works for simple stuff anyway.

-a

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


Re: Basic Information about Python

2010-07-30 Thread Eli Bendersky
On Fri, Jul 30, 2010 at 16:55, Durga D durga.d...@gmail.com wrote:

 Hi JM,

   Thanks alot for your prompt response.

   If I include into windows setup, what will be setup size (assume
 before include 10 MB)? i mean, python supporting dlls/libs size for
 python exe.


IIRC, the size of a simple hello world script packed with py2exe or
PyInstaller is around 2-3 MB. If you use large GUI libraries (like PyQt or
wxPython) it goes up to 6-10MB, and so on (more libraries - larger .exe)

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


Re: The untimely dimise of a weak-reference

2010-07-30 Thread Christian Heimes
Am 30.07.2010 16:06, schrieb Vincent van Beveren:
 I did not know the object did not keep track of its bound methods. What 
 advantage is there in creating a new bound method object each time its 
 referenced? It seems kind of expensive.

Instances of a class have no means of storing the bound method object.
The or unbound bound method is a simple and small wrapper that keeps a
reference to the class, self and the function object. Python keeps a
pool of empty method objects in a free list. The creation of a new bound
method just takes a few pointer assignments and three INCREFs.

Christian

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


Re: measuring a function time

2010-07-30 Thread MRAB

Albert Hopkins wrote:

On Fri, 2010-07-30 at 14:28 +0200, Hrvoje Niksic wrote:

Steven D'Aprano st...@remove-this-cybersource.com.au writes:


On Thu, 29 Jul 2010 14:42:58 +0200, Matteo Landi wrote:


This should be enough


import time
tic = time.time()
function()
toc = time.time()
print toc - tic

You're typing that in the interactive interpreter, which means the
timer is counting the seconds while you're typing subsequent
commands. At the very least, you need to put that code into a
function.

Or, trivially improved as follows:


t0 = time.time(); function(); t1 = time.time()
print t1 - t0


I'll just throw this out.  I sometimes use a decorator to keep track of
a functions execution times:


def timed_function(f):
Function decorator that records the execution time of a
function
import time
def funct(*args, **kwargs):
__starttime = time.time()
result = f(*args, **kwargs)
__endtime = time.time()
funct.runtime = __endtime - __starttime

return result

return funct

Then

 from goodies import timed_function
 from time import sleep
 @timed_function
... def test(n):
... sleep(n)
... 
 test(4)

 test.runtime
4.003864049911499

Works for simple stuff anyway.


That won't work very well for functions which don't run for long. You
could fix that by adding a counter for the number of times it's run and
the total time.
--
http://mail.python.org/mailman/listinfo/python-list


RE: Access stdout from external program.

2010-07-30 Thread Paul Lemelle
JM,

Thanks for the response.  

I am trying to capture the stdout of a program from another program. Example, I 
want to launch the below program from a second python script then capture the 
first's program stdout to a file or variable. 

Is this possible?

Thanks again,
Paul




Paul Lemelle wrote:
 HELP! :)

 I am trying to output the following program's output to either a file
 or variable, how can this be done?

 # Writing the output to a standard argv argument

 #1/usr/bin/python

 import sys

 for arg in sys.argv:
   print arg

 #END

 Thanks,
 Paul


Hi Paul, after reading 4 times your post, I still don't see what you
want to achieve.
What are you calling a variable ? an os variable ?

import sys

file = open('testfile.txt', 'w')
file.write(str(sys.argv))
file.close()

second hit when googling your question:
http://docs.python.org/tutorial/inputoutput.html

JM



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


Re: Access stdout from external program.

2010-07-30 Thread Jean-Michel Pichavant

Paul Lemelle wrote:

JM,

Thanks for the response. 

I am trying to capture the stdout of a program from another program. 
Example, I want to launch the below program from a second python 
script then capture the first's program stdout to a file or variable.


Is this possible?

Thanks again,
Paul



use the subprocess module.

import subprocess
proc = subprocess.Popen(['echo', 'Hello World'], stdout=subprocess.PIPE, 
stderr=subprocess.PIPE )

out, err = proc.communicate()
print out
 Hello World


more details here

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



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


Re: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all?

2010-07-30 Thread Raymond Hettinger
On Jul 25, 5:30 pm, Gregory Ewing greg.ew...@canterbury.ac.nz wrote:
 Raymond Hettinger wrote:
  Every class
  in the MRO implementing the target method *must* call super() to give
  the next class in the MRO a chance to run.

 EXCEPT for the last one, which must NOT call super!

 The posted example happens to work because object has
 a default __init__ method that does nothing. But this
 is not generally true of other methods, which means you
 need a terminating class at the end of the MRO whose
 methods don't call super.

That is an important point and it is what Guido does in his examples:
http://www.python.org/download/releases/2.2.3/descrintro/#cooperation

The design options are:

* if overriding a method provided by object() such as __init__(),
__getattribute__() or __setattr__(), then you should call super() in
each class that overrides or extends those methods.

* if you know the whole class structure in advance, you call super()
in every class except the last one -- that is what Guido does in the
save() example.

* if you don't know the whole class structure in advance, then you
can't be sure which is that last class in the mro with the target
method, so you need to wrap the super() call in a try / except
AttributeError

Raymond


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


Re: Basic Information about Python

2010-07-30 Thread kevinlcarlson
On Jul 30, 6:55 am, Durga D durga.d...@gmail.com wrote:
 Hi JM,

    Thanks alot for your prompt response.

    If I include into windows setup, what will be setup size (assume
 before include 10 MB)? i mean, python supporting dlls/libs size for
 python exe.

 Regards,
 Durga.

 On Jul 30, 6:04 pm, Jean-Michel Pichavant jeanmic...@sequans.com
 wrote:

  Durga D wrote:
   Hi All,

     I am new to python based application developement. I am using
   Windows XP.

     1. Can I create desktop application (just hello world program) with
   Python
   language like exe in VC++?

  yeshttp://www.py2exe.org/   2. If First statement is Yes, Can I include 
  this application with
   my
   existing setup(assume 10 MB) for windows?

  you mean include it in a windows installer ? If so yes.

     3. If Second statement is Yes, What will be the setup size?

     Thank in advance.

   Regards,
   Durga.

  JM



I use Pyinstaller with good results.  The Python runtime dll is about
two megs, plus a few others depending on what imports you are using.
For example, using wxPython to create a Windows app will add several
files totaling several megs.  You can then simply copy the
distribution file directory to the target machine, or use any good
installer software.

http://www.pyinstaller.org/

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


Re: Two minor questions on Class

2010-07-30 Thread Peter Otten
joy99 wrote:

 class Person(object):
 def _init_(self,name,age):
 self.name=name
 self.age=age
 
 as i wrote the code using IDLE on WinXP SP2, with Python2.6.5, I am
 getting the following error:
 
  p=Person('Subha',40)
 
 Traceback (most recent call last):
   File pyshell#120, line 1, in module
 p=Person('Subha',40)
 TypeError: object.__new__() takes no parameters
 
 My question is, why the error is coming? Any problem in writing it?

The so-called special methods in Python start with two underscores and end 
with two underscores, i. e. the initializer is called

__init__

not

_init_

 If any one can help, I would be grateful. As I pasted the code from
 GUI to notepad, there may be slight indentation problem, sorry for the
 same.
 
It looks fine here.

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


how python works

2010-07-30 Thread Mahmood Naderan
I want to know how python executes a .py file. Sometimes when I run a file, I 
get an error that there is a syntax error. This shows that the parser read and 
parse the whole file. Sometimes in the middle of the run I get an error 
that another line has problem. So how does it work? if it doesn't compile and 
read line by line them why some times I get error just before run?
 
// Naderan *Mahmood;


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


Re: Two minor questions on Class

2010-07-30 Thread Shashank Singh
On Fri, Jul 30, 2010 at 10:53 PM, joy99 subhakolkata1...@gmail.com wrote:

 class Person(object):
def _init_(self,name,age):
self.name=name
self.age=age

 constructor has double underscores (both as prefix and suffix) __init__

-- 
Regards
Shashank Singh
Senior Undergraduate, Department of Computer Science and Engineering
Indian Institute of Technology Bombay
shashank.sunny.si...@gmail.com
http://www.cse.iitb.ac.in/~shashanksingh
-- 
http://mail.python.org/mailman/listinfo/python-list


Two minor questions on Class

2010-07-30 Thread joy99
Dear Group,

Hope everyone is fine.

I was trying some examples of Python class.
I took the following example from Ubuntu forum[http://ubuntuforums.org/
showthread.php?t=578930]
class Person(object):
def _init_(self,name,age):
self.name=name
self.age=age

as i wrote the code using IDLE on WinXP SP2, with Python2.6.5, I am
getting the following error:

 p=Person('Subha',40)

Traceback (most recent call last):
  File pyshell#120, line 1, in module
p=Person('Subha',40)
TypeError: object.__new__() takes no parameters

My question is, why the error is coming? Any problem in writing it?
Can arguments be passed to class (other than inheritance) directly
like this?

As I was practising some early examples on class, does Python exist
with any built in class, like the rich library of built in functions?
Any good URL to learn examples?

If any one can help, I would be grateful. As I pasted the code from
GUI to notepad, there may be slight indentation problem, sorry for the
same.

Thanks in advance,
Best Regards,
Subhabrata.
-- 
http://mail.python.org/mailman/listinfo/python-list


Use cases for setattr in existing code

2010-07-30 Thread John Nagle

   I've been looking at existing code, using Google Code search,
to see what use cases for setattr are actually used in production
code.  High-performance implementations like Shed Skin try to
avoid dynamic creation of attributes, so it's worth seeing where
this feature is used in production.

1.  Copying

setattr is used by copy and pickle to construct new
objects without calling their constructors.  This is seen only in
code which also uses the CPython feature that the class of an object
can be changed by storing into the __class__ attribute.

2.  Proxying

A local object is being created as a proxy for some remote object.
This shows up in the Python shim for Remember the Milk, in the
wrapper for a restricted execution shell rexec.py

3.  Representation of some other data structure.

This is typically seen where some XML or JSON structure has been
translated into a tree of Python objects, and attribute access is being
used to access the data from the original object.  This can result
in name clashes with existing attributes and keywords.  Used by
BeautifulSoup.

4.  Ordered dictionaries

odict.py uses setattr, but with the comment FIXME, noting
that unrestricted setattr can break the built-in attributes.

5.  Enums

The Google Wave API uses setattr in StringEnum, which creates
an enumeration-like object.

6.  Test platforms

setattr is used in Mocker to insert shim objects for test
purposes.  This is a special case of proxying.


Note that in all the above cases, setattr is being used during
(or even prior to) object construction.  It's rarely used on live
objects.

For the above cases, a mechanism for constructing general objects
would do the job.  Something like

attrdict = { 'a' : 1, 'b' : 2 }
obj = make_object('classname', attrdict)

There are clearly use cases for dynamic object construction, but
modifying the structure of an object after creation is quite rare.

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


Re: how python works

2010-07-30 Thread Burton Samograd
Mahmood Naderan nt_mahm...@yahoo.com writes:

 I want to know how python executes a .py file. Sometimes when I run a
 file, I get an error that there is a syntax error. This shows that the
 parser read and parse the whole file. Sometimes in the middle of the
 run I get an error that another line has problem. So how does it work?
 if it doesn't compile and read line by line them why some times I get
 error just before run?

Python first complies the file, which will find any syntax errors that
you have in your code.  If there are any, then it will stop there before
executing the resulting compiled code.  If the compilation is
successful, it will then run the code, where you might have run-time
errors, which are code with a proper syntax but errors during execution.

--
Burton Samograd

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


Re: how python works

2010-07-30 Thread Mahmood Naderan
So is it a compiler or interpreter?
 
// Naderan *Mahmood;





From: Burton Samograd bur...@userful.com
To: python-list@python.org
Sent: Fri, July 30, 2010 10:36:56 PM
Subject: Re: how python works

Mahmood Naderan nt_mahm...@yahoo.com writes:

 I want to know how python executes a .py file. Sometimes when I run a
 file, I get an error that there is a syntax error. This shows that the
 parser read and parse the whole file. Sometimes in the middle of the
 run I get an error that another line has problem. So how does it work?
 if it doesn't compile and read line by line them why some times I get
 error just before run?

Python first complies the file, which will find any syntax errors that
you have in your code.  If there are any, then it will stop there before
executing the resulting compiled code.  If the compilation is
successful, it will then run the code, where you might have run-time
errors, which are code with a proper syntax but errors during execution.

--
Burton Samograd

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



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


Re: Library versions

2010-07-30 Thread Chris Withers

Peo wrote:

Is there some other smart way to do acheive this?


Just turn them info python packages, and use buildout, pip or some other 
python package management tool to create the versions.


You may, of course, just be able to svn the lot of them...
(then you don't need to worry about numbering them at all)

Chris

--
Simplistix - Content Management, Batch Processing  Python Consulting
   - http://www.simplistix.co.uk
--
http://mail.python.org/mailman/listinfo/python-list


Re: how python works

2010-07-30 Thread Burton Samograd
Mahmood Naderan nt_mahm...@yahoo.com writes:

 So is it a compiler or interpreter?

There's a compiler that compiles python to bytecode which is then
interpreted.  This saves the interpreter from having to re-parse the
code at run time.

So, it's an interpreter that compiles the code first.

--
Burton Samograd


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


Re: Normalizing A Vector

2010-07-30 Thread Chris Rebert
On Fri, Jul 30, 2010 at 4:46 AM, Lawrence D'Oliveiro
l...@geek-central.gen.new_zealand wrote:
 Say a vector V is a tuple of 3 numbers, not all zero. You want to normalize
 it (scale all components by the same factor) so its magnitude is 1.

 The usual way is something like this:

    L = math.sqrt(V[0] * V[0] + V[1] * V[1] + V[2] * V[2])
    V = (V[0] / L, V[1] / L, V[2] / L)

 What I don’t like is having that intermediate variable L leftover after the
 computation. Here’s how to do it in one step:

I suppose you'd be a fan of the proposed given/where statement
then (but its prognosis isn't great):
http://www.python.org/dev/peps/pep-3150/

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how python works

2010-07-30 Thread Stephen Hansen
On 7/30/10 11:16 AM, Mahmood Naderan wrote:
 So is it a compiler or interpreter?

Neither/both, depending on your definition of either word. It does not
compile to machine code: it compiles to byte code (which it then
usually, but not always, stores in a pyc file alongside the py file). It
does not interpret the Python code on the fly, it is a VM which
interprets the byte code.

--

   Stephen Hansen
   ... Also: Ixokai
   ... Mail: me+list/python (AT) ixokai (DOT) io
   ... Blog: http://meh.ixokai.io/



signature.asc
Description: OpenPGP digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how python works

2010-07-30 Thread Mahmood Naderan
Neither/both, depending on your definition of either word. It does not
compile to machine code: it compiles to byte code (which it then
usually, but not always, stores in a pyc file alongside the py file). It
does not interpret the Python code on the fly, it is a VM which
interprets the byte code.


So, it's an interpreter that compiles the code first.

Thanks. I got it.
 
// Naderan *Mahmood;





From: Stephen Hansen me+list/pyt...@ixokai.io
To: python-list@python.org
Sent: Fri, July 30, 2010 11:13:27 PM
Subject: Re: how python works

On 7/30/10 11:16 AM, Mahmood Naderan wrote:
 So is it a compiler or interpreter?

Neither/both, depending on your definition of either word. It does not
compile to machine code: it compiles to byte code (which it then
usually, but not always, stores in a pyc file alongside the py file). It
does not interpret the Python code on the fly, it is a VM which
interprets the byte code.

--

  Stephen Hansen
  ... Also: Ixokai
  ... Mail: me+list/python (AT) ixokai (DOT) io
  ... Blog: http://meh.ixokai.io/


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


ImportError: No module named binascii

2010-07-30 Thread Dieter
Hi there,

I installed python 2.7 from the tar ball on python.org. the
installation was pretty uneventful. However, I need to run someone
elses python code and get the error message

ImportError: No module named binascii

Any recommendations how to correct this? Is there another tar file
somewhere that I can download to install this missing module?

Thanks a lot in advance.

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


Re: pylint scores

2010-07-30 Thread News123
On 07/30/2010 03:12 PM, wheres pythonmonks wrote:
 I am starting to use pylint to look at my code and I see that it gives a 
 rating.
 What values do experienced python programmers get on code not
 targeting the benchmark?
 
 I wrote some code, tried to keep it under 80 characters per line,
 reasonable variable names, and I got:
 
 0.12 / 10.
 
 Is this a good score for one not targeting the benchmark?  (pylint
 running in default mode)
 
It's not a goodf core, but arrives easily if you never ran pylint before.
With very little effort you should be able to be above 5
with a little more effort above 7


 Somewhat related:  Is the backslash the only way to extend arguments
 to statements over multiple lines?  (e.g.)

if you have an opening parenthesis, or bracked, then you don't need a
backslash

so instead of
if longlonglonglonglonglonglonglongvar == \
otherlonglonglonglongvar:

you could also write:

if (longlonglonglonglonglonglonglongvar ==
otherlonglonglonglongvar):


same works of course with asserts.

 
 def f(x,y,z): return(x+y+z);
 ...
 f(1,2,
 ... 3)
 6
 assert f(1,2,3)0,
   File stdin, line 1
 assert f(1,2,3)0,
  ^
 SyntaxError: invalid syntax

 
 In the above, I could split the arguments to f (I guess b/c of the
 parens) but not for assert.  I could use a backslash, but I find this
 ugly -- it that my only (best?) option?
 
 [I really like to assert my code to correctness and I like using the
 second argument to assert, but this resulted in a lot of long lines
 that I was unable to break except with an ugly backslash.]
 
 W

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


Re: [Py2exe-users] how to build same executabl with and without console output

2010-07-30 Thread Gelonida
Hi,

On 07/30/2010 03:51 PM, Dave Angel wrote:
 pyt...@bdurham.com wrote:
 Is there any trick in adding a console window to an application, that
 was built as 'windows' application?
,,,
 Since we're talking MS Windows here, see:
 
 http://msdn.microsoft.com/en-us/library/ms682528(VS.85).aspx
 
 You can access the AllocConsole and related functions with the win32
 module:
   win32console
 
 This module is part of the win32 extensions, and also part of
 ActivePython distribution.
 
Thanks a lot for  your answer
I'll check this out.



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


Re: py2app with weave fails

2010-07-30 Thread Aahz
In article 4f6430e5-31ea-450d-a2b9-56442a714...@k19g2000yqc.googlegroups.com,
Soren  soren.skou.niel...@gmail.com wrote:

I'm trying to create a standalone app using py2app, but it seems no
matter what I do I get this error:

Try pythonmac-...@python.org
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

Normal is what cuts off your sixth finger and your tail...  --Siobhan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Py2exe-users] how to build same executabl with and without console output

2010-07-30 Thread Gelonida
On 07/30/2010 11:00 AM, Jimmy Retzlaff wrote:
 On Fri, Jul 30, 2010 at 1:10 AM, Gelonida gelon...@gmail.com wrote:
 What I'd like to achieve ideally is to create a py2exe program,
 which
 will only display a window (so 'compiled' as 'windows'-application) if
 called normally.

...

 Is there any way to compile the same python script (myprog.py) from one
 py2exe script into once a 'windows' executable (myprog.exe) and once
 into a 'console' executable (myprog_debug.exe)?
 
 I can't think of an easy way to achieve the first approach - I've
 always taken the second approach. The advanced example included with
 py2exe has an example of how to do this. Look at all the occurrences
 of test_wx in the following link to see all the pieces involved:
 
 http://py2exe.svn.sourceforge.net/viewvc/py2exe/trunk/py2exe/py2exe/samples/advanced/setup.py?view=markup
 
 This uses an alternate form of the windows and console arguments
 where each target is an object with specially named member variables
 rather than a string that names the .py file (this string is one of
 the member variables). This is necessary so you can give different
 names to the console version and the windows version.
 

Thanks, I'll read thorugh it.


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


trace of Thermite (tm) at WTC, almost no asbestos: if the main beams had been clad, they mightn't have weakened enough to collapse!

2010-07-30 Thread spudnik
 stuff about Zionosphere, redacted

here are some speeches about the British World Wars,
collected in one book on http://tarpley.net:
How the Venetian System Was Transplanted Into England
New Federalist, June 3, 1996

The British Empire Bid for Undisputed World Domination, 1850-1870
Schiller Institute Food For Peace Conference, Chicago, February 22-23,
1992

Lord Palmerston’s Multicultural Human Zoo
ICLC Conference, February 20, 1994

King Edward VII: Evil Demiurge of the Triple Entente and World War 1
ICLC Conference, February, 1995

Sir Edward Grey Turned Sarajevo Crisis Into War
Printed in The American Almanac, March, 1995

The Versailles Thesis: The Roots of WWI, and WWII
Conference Speech by Webster Tarpley, Schiller Institute Food
For Peace Conference, Chicago, Illinois, February 22-23, 1992.

The Versailles Treaty: The War Guilt Clause
Printed in the American Almanac, March, 1995

British Financial Warfare: 1929; 1931-33;
How The City Of London Created The Great Depression

thus:
we aren't all einsteinians; you are the one,
who insists upon his reification of the corpuscle,
which is just a willy-nilly, mere interpretation of quantum
of light, vis-a-vu Planck's great idea and
the electonic trace in the photo-electrical effect  well,
his and Infeld's acoustic fridge was pretty cool!

thus:
there are two 3d versions of the pythag.thm.,
each with different dimensional attributes.

iff you don't study Fermat's numbertheorie,
you're up Shitz Creek without a paddle; however,
it is better to start with his reconstruction
of Euclid's porisms, although they are just planar
(synthetic geometry: see Geometrical Fragments,
belowsville .-)

 NO!

thus:
and, the other half d'oil evaporates, as has
been shown of late (again) in the newspapers.  Congress and
the Administration are a bit behind, in using Iran Oil's
big blow-out in the Gulf, to leverage BP's captrade nostrum;
eh?

a-yup:
Such microbes have
been found in every ocean of the world sampled, from the Arctic to
Antarctica. But there are reasons to think that the process may occur
more quickly in the Gulf than in other oceans.

--les ducs d'oil!
http://tarpley.net/online-books/

--Light, A History!
http://wlym.com/~animations/fermat/index.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ImportError: No module named binascii

2010-07-30 Thread MRAB

Dieter wrote:

Hi there,

I installed python 2.7 from the tar ball on python.org. the
installation was pretty uneventful. However, I need to run someone
elses python code and get the error message

ImportError: No module named binascii

Any recommendations how to correct this? Is there another tar file
somewhere that I can download to install this missing module?

Thanks a lot in advance.


There isn't a separate binascii module. Have you tried:

 import binascii

at the Python prompt? That works for me (Windows XP) and will show
whether it's missing somehow.
--
http://mail.python.org/mailman/listinfo/python-list


Re: ImportError: No module named binascii

2010-07-30 Thread Dave Angel

Dieter wrote:

Hi there,

I installed python 2.7 from the tar ball on python.org. the
installation was pretty uneventful. However, I need to run someone
elses python code and get the error message

ImportError: No module named binascii

Any recommendations how to correct this? Is there another tar file
somewhere that I can download to install this missing module?

Thanks a lot in advance.


  

You should include the whole error message, including the traceback.

But perhaps first you should try importing binascii yourself, in the 
interpreter.



DaveA

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


os.fork on linux defunct

2010-07-30 Thread Ray
I'm running python 2.4 on linux. I use python os.fork run tcpdump, but
after I kill the forked process (tcpdump) in linux it shows defunct

here is the code:

#!/usr/bin/python
import time, os
class Test:
def fork(self):
self.pid=os.fork()
if self.pid=0:
args=['tcpdump', '-i', 'eth0', 'port', '80' '']
os.execl(/usr/sbin/tcpdump, *args)
os._exit(0)
def kill(self):
os.kill(self.pid, 15)
if __name__=='__main__':
while True:
test=Test()
test.fork()
time.sleep(2)
test.kill()
time.sleep(30)

after I call kill() it will kill tcpdump (capture will stop) but on
linux, ps shows tcpdump as defunct process
what am I missing?

thanks for any help.

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


Re: os.fork on linux defunct

2010-07-30 Thread Ray
On Jul 30, 6:03 pm, Ray rui.va...@gmail.com wrote:
 I'm running python 2.4 on linux. I use python os.fork run tcpdump, but
 after I kill the forked process (tcpdump) in linux it shows defunct

 here is the code:

 #!/usr/bin/python
 import time, os
 class Test:
     def fork(self):
         self.pid=os.fork()
         if self.pid=0:
             args=['tcpdump', '-i', 'eth0', 'port', '80' '']
             os.execl(/usr/sbin/tcpdump, *args)
             os._exit(0)
     def kill(self):
         os.kill(self.pid, 15)
 if __name__=='__main__':
     while True:
         test=Test()
         test.fork()
         time.sleep(2)
         test.kill()
         time.sleep(30)

 after I call kill() it will kill tcpdump (capture will stop) but on
 linux, ps shows tcpdump as defunct process
 what am I missing?

 thanks for any help.

I think I found it. need to call os.wait()

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


Tkinter Label alignment problem using OS 10.6

2010-07-30 Thread AJ
Dear users,

I have written a sample program that ran correctly with earlier than
Mac OS 10.6. The answer field Label does not align correctly. I
downloaded the latest Python 2.7 release but still did not solve the
problem.  Look for line L4.place(relx=0.32,rely=0.56, anchor=W)

#!/usr/bin/env python

from Tkinter import *
from tkMessageBox import *
import sys


win = Tk()
#win.tk.call('console', 'hide')
try:
win.tk.call('after','idle','console','hide')
except TclError:
pass
ScreenX = win.winfo_screenwidth()
ScreenY = win.winfo_screenheight()
ScreenX = (ScreenX/2) - 250
ScreenY = (ScreenY/2) - 200
win.geometry('500x300%+d%+d' %(ScreenX, ScreenY))
win.title('Place' Geometry Test)
win.resizable(width=False, height=False)

FirstN  = StringVar()
SecondN = StringVar()
Answer  = StringVar()

Verd12 = (Verdana,11)
Verd16 = (Verdana,16)
Verd25 = (Verdana,25)
Sys16  = (System ,16)


#- AboutDialog 

class AboutDialog(Toplevel):

def __init__(self, parent):
Toplevel.__init__(self, parent)
self.configure(bg = 'white', borderwidth=3)
self.geometry('200x300%+d%+d' %(ScreenX, ScreenY))
self.title('About...')
self.resizable(height=FALSE, width=FALSE)
self.transient(parent)
self.grab_set()
self.protocol(WM_DELETE_WINDOW, self.OkToExit)
self.parent = parent
self.FillDialog()
self.Btn.focus_set()
self.bind('Return',self.OkToExit)
self.bind('Escape',self.OkToExit)
self.bind('Command-KeyPress-Q', Done)
self.bind('Command-KeyPress-q', Done)

self.wait_window()

def FillDialog(self):

self.AboutText = \n\n\nPlace Geometry Test\n\nBy\n\nAmin
Aljuffali
self.Lbl = Label(self, text=self.AboutText, font=Verd16, bg =
'white')
self.Lbl.pack(side=TOP)
self.Lb2 = Label(self, text=April 1, 2007, height = 1,
font=Verd12, bg = 'white')
self.Lb2.pack(side=TOP)
self.Lb3 = Label(self, text= , height = 3, font=Verd12, bg =
'white')
self.Lb3.pack(side=TOP)
self.Btn = Button(self, text='Done', font=Sys16, width=8,
height=1, command=self.OkToExit)
self.Btn.pack(side=TOP)
self.Lb4 = Label(self, text= , height = 3, font=Verd12, bg =
'white')
self.Lb4.pack(side=BOTTOM)
self.update()

def OkToExit(self, event=None):
self.destroy()

#--

def ShowDialog():
AboutDialog(win)

def done():
win.destroy()
win.quit

def Done(e):
win.destroy()
win.quit


def CheckAlfanumeric(x):

if x == '':
  return False
for ch in x:
  if ch not
in['.','-','+','0','1','2','3','4','5','6','7','8','9','e','E']:
return False
return True


def Multiply():

#global FirstN, SecondN, Answer

try:
  a = FirstN.get().strip()
  if not CheckAlfanumeric(a):
raise ValueError

  b = SecondN.get().strip()
  if not CheckAlfanumeric(b):
raise ValueError

  FirstN.set(a)
  SecondN.set(b)
  Answer.set(str(float(a) * float(b)))

except ValueError:
  showwarning(Warning...,Input Error!)

return

def MakeToplevelMenu(topwin):

top = Menu(topwin)
topwin.config(menu=top)

if sys.platform == 'darwin' and '.app' in sys.executable:
   application = Menu(top, name='apple')
   application.add_command(label='About...', command=ShowDialog,
underline=0)
   top.add_cascade(label='PlaceTest', menu=application,
underline=0)

fileMenu = Menu(top, tearoff=0)
fileMenu.add_command(label='Exit', command=done, underline=0)
top.add_cascade(label='File', menu=fileMenu, underline=0)

helpMenu = Menu(top, tearoff=0)
helpMenu.add_command(label='About...', command=ShowDialog,
underline=0)
top.add_cascade(label='Help', menu=helpMenu, underline=0)

return


MakeToplevelMenu(win)

L1 = Label(win, text='Multiply Two Numbers', font=Verd25, bg =
'white')
L2 = Label(win, text='First Number:', font=Verd16, bg = 'white')
L3 = Label(win, text='Second Number:', font=Verd16, bg = 'white')
L4 = Label(win,  text='', textvariable=Answer, font=Sys16, bg =
'white', bd=1, width=20, height=1, anchor=W, relief=SOLID)
L5 = Label(win,  text='Written by Amin Aljuffali', font=Verd12,padx=2,
bg = 'white', anchor=W, relief=FLAT)
B1 = Button(win, text='Multiply', font=Sys16, width=19, height=1,
command=Multiply)
B2 = Button(win, text='Quit', font=Sys16, width=19, height=1,
command=done)
F1 = Frame(win, relief=FLAT, bd=0, bg='#336699')
F2 = Frame(win, relief=FLAT, bd=0, bg='#336699')
F3 = Frame(win, relief=FLAT, bd=0, bg='#336699')

E1 = Entry(win, textvariable=FirstN, relief=SOLID, font=Sys16, bg =
'white',bd=1)
E2 = Entry(win, textvariable=SecondN, relief=SOLID, font=Sys16, bg =
'white', bd=1)

win.bind('Command-KeyPress-q', Done)
win.bind('Command-KeyPress-Q', Done)

F1.place(relx=0.0,rely=0.01, anchor=NW, width=600, height=5)

Re: Tkinter Label alignment problem using OS 10.6

2010-07-30 Thread rantingrick
On Jul 30, 6:52 pm, AJ ajuff...@yahoo.com wrote:
 Dear users,

 I have written a sample program that ran correctly with earlier than
 Mac OS 10.6. The answer field Label does not align correctly. I
 downloaded the latest Python 2.7 release but still did not solve the
 problem.  Look for line L4.place(relx=0.32,rely=0.56, anchor=W)


DO YOURSELF A HUGE FAVOR AJ... Learn how to use the pack and grid
geometry managers available in Tkinter before it's too late. Well,
unless of course your a sadist. In that case just ignore my post
completely. 8^O

http://effbot.org/tkinterbook/tkinter-index.htm#introduction
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.fork on linux defunct

2010-07-30 Thread Cameron Simpson
On 30Jul2010 15:09, Ray rui.va...@gmail.com wrote:
| On Jul 30, 6:03 pm, Ray rui.va...@gmail.com wrote:
|  I'm running python 2.4 on linux. I use python os.fork run tcpdump, but
|  after I kill the forked process (tcpdump) in linux it shows defunct
[...]
|  after I call kill() it will kill tcpdump (capture will stop) but on
|  linux, ps shows tcpdump as defunct process
|  what am I missing?
|  thanks for any help.
| 
| I think I found it. need to call os.wait()

Yep. defunct == zombie. See:

  http://code.activestate.com/lists/python-list/580569/

Cheers,
-- 
Cameron Simpson c...@zip.com.au DoD#743
http://www.cskk.ezoshosting.com/cs/

Talk is the bastard redheaded stepchild of email and the telephone.
- Geoff Miller, geo...@purplehaze.corp.sun.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pylint scores

2010-07-30 Thread Dan Stromberg
On Fri, Jul 30, 2010 at 12:18 PM, News123 news1...@free.fr wrote:

 On 07/30/2010 03:12 PM, wheres pythonmonks wrote:
  I am starting to use pylint to look at my code and I see that it gives a
 rating.
  What values do experienced python programmers get on code not
  targeting the benchmark?
 
  I wrote some code, tried to keep it under 80 characters per line,
  reasonable variable names, and I got:
 
  0.12 / 10.
 
  Is this a good score for one not targeting the benchmark?  (pylint
  running in default mode)
 
 It's not a goodf core, but arrives easily if you never ran pylint before.
 With very little effort you should be able to be above 5
 with a little more effort above 7


  Somewhat related:  Is the backslash the only way to extend arguments
  to statements over multiple lines?  (e.g.)

 if you have an opening parenthesis, or bracked, then you don't need a
 backslash

 so instead of
 if longlonglonglonglonglonglonglongvar == \
otherlonglonglonglongvar:

 you could also write:

 if (longlonglonglonglonglonglonglongvar ==
otherlonglonglonglongvar):


 same works of course with asserts.

 
  def f(x,y,z): return(x+y+z);
  ...
  f(1,2,
  ... 3)
  6
  assert f(1,2,3)0,
File stdin, line 1
  assert f(1,2,3)0,
   ^
  SyntaxError: invalid syntax
 
 
  In the above, I could split the arguments to f (I guess b/c of the
  parens) but not for assert.  I could use a backslash, but I find this
  ugly -- it that my only (best?) option?
 
  [I really like to assert my code to correctness and I like using the
  second argument to assert, but this resulted in a lot of long lines
  that I was unable to break except with an ugly backslash.]
 
  W

 IMO, the important thing about pylint's scoring is that it's but one way of
many of producing good Python code.  However, it's also one of the easier
ways of producing good python code.

I personally like to get my scores up near 10, by annotating in comments
about the few things that pylint flags that I can't just code around.  This
requires jumping through some slightly silly hoops (EG the previously
mentioned too few public methods, which my various container classes
always trip over), but going through this process is worthwhile for
highlighting the hoops pylint can detect that -aren't- so silly.

The one thing I like to leave unfixed is FIXME's - otherwise my preference
would be to go for a score of 10 for production code.

I also like to create a ./this-pylint script for my various projects, that
have global overrides - things like identifier rules, line length, and...  I
don't get blanks instead of tabs.  Blanks are fine if you don't understand
tabs (or think someone in the future who doesn't understand tabs will need
to work on your code), but tabs allow everyone to see code indented the way
-they- want to see it, not just the way the original author wanted to see
it.

This script (./this-pylint) will also save output from the test in a text
file, for make (or other dependency handling program) to use to avoid
re-pylint'ing unmodified code.  It'll give an error typically, if pytlint
detects any errors other than FIXME's (excluding ones, as I mentioned
before, that have a comment disabling the warning, of course).

I'm more than a little sad that pylint doesn't seem to be moving to python 3
in any big hurry.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.fork on linux defunct

2010-07-30 Thread Lawrence D'Oliveiro
In message
77a879cc-94ab-4e2a-a4af-a6945a5b8...@q16g2000prf.googlegroups.com, Ray 
wrote:

 I think I found it. need to call os.wait()

The rule on Unix/Linux systems is: “always remember to gobble your zombie 
children”.
-- 
http://mail.python.org/mailman/listinfo/python-list


Anushka for Shape FX Hot Shot Thigh Gel

2010-07-30 Thread ANUSHKA
Anushka for Shape FX Hot Shot Thigh Gel

**
http://sites.google.com/site/anushkaphotosalert
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python styles: why Use spaces around arithmetic operators?

2010-07-30 Thread Cousin Stanley

 Parentheses are punctuation. Why not leave spaces around the commas as well, 
 to be consistent?

 myTuple = ( 1 , 2 , 3 , 4 , 5 )

  Personally, I do use this particular style with commas
  as I find it more readable to my old and tired eyes 

  Mandate  m o r e  whitespace  :-)


-- 
Stanley C. Kitching
Human Being
Phoenix, Arizona

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


Re: Multiprocessing taking too much time

2010-07-30 Thread Dan Stromberg
On Thu, Jul 29, 2010 at 12:04 PM, John Nagle na...@animats.com wrote:

 On 7/29/2010 11:08 AM, Shailendra wrote:

 Hi All,
 I have a following situation.
 ==PSUDO CODE START==
 class holds_big_array:
 big_array  #has a big array

 def get_some_element(self, cond) # return some data from the array
 from the big array
 ==PSUDO CODE END
 I wanted to use multiprocessing module to parallelise calling
 get_some_element. I used following kind of code

 ==PSUDO CODE START==
 pool = Pool(processes=2)
 holder =holds_big_array() #class instantiation
 def callback_f(result):
  do something with result
 loop many times
pool.apply_async(holder.get_some_element,args,callback=callback_f)
 pool.close()
 pool.join()
 ==PSUDO CODE END
 Note: Had to do something to enable instance method being pickled...

 I tested this with less than realistic size of big_array . My parallel
 version works much slower than than the normal serial version (10-20
 sec vs 7-8 min). I was wonder what could be the possible reason.\


I think the place to start when code is slow, is usually to use a profiler.

However, in this case it's likely as you say, a pickling issue.


It's hard to tell from your PSUDO CODE, but it looks like each
 access to the big array involves calling another process.

Calling a function in another process is done by creating an
 object to contain the request, running it through pickle to convert
 it to a stream of bytes, sending the stream of bytes through a socket or
 pipe to the other process, running the byte stream through unpickle to
 create an object like the original one, but in a different process, and
 calling a function on the newly created object in the receiving process.
  This entire sequence has to be done again in reverse
 to get a reply back.

This is hundreds of times slower than a call to a local function.

The multiprocessing module is not a replacement for thread-level
 parallelism.  It looks like it is, but it isn't.  It's only useful for
 big tasks which require large amounts of computation and little
 interprocess communication.  Appropriately-sized tasks to send out
 to another process are things like parse large web page or
 compress video file, not access element of array.


Well, multiprocessing'll replace threading in many scenarios, including some
where CPython's threading isn't very useful.

The O.P. might look into storing their array in shared memory -
multiprocessing facilitates that pretty well.  Or, as John has suggested,
chunk up the work into larger pieces than individual array accesses.

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


Re: Ascii to Unicode.

2010-07-30 Thread John Machin
On Jul 30, 4:18 am, Carey Tilden carey.til...@gmail.com wrote:
 In this case, you've been able to determine the
 correct encoding (latin-1) for those errant bytes, so the file itself
 is thus known to be in that encoding.

The most probably correct encoding is, as already stated, and agreed
by the OP to be, cp1252.


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


Re: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all?

2010-07-30 Thread Gregory Ewing

Steven D'Aprano wrote:


  A
 / \
C   B
 \ /
  D
 / \
E   F

Yes, a super call might jog left from 
C to B, but only when being called from one of the lower classes D-F. 
That's still an upwards call relative to the originator, not sidewards.


But it's not an upward call relative to the class mentioned
in the super() call, which is why I say it's misleading.

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


Re: The untimely dimise of a weak-reference

2010-07-30 Thread Gregory Ewing

Vincent van Beveren wrote:

I was working with weak references in Python, and noticed that it 

 was impossible to create a weak-reference of bound methods.

 is there anything I can do about it?

You can create your own wrapper that keeps a weak reference to
the underlying object. Here's an example.

import weakref

class weakmethod(object):

  def __init__(self, bm):
self.ref = weakref.ref(bm.im_self)
self.func = bm.im_func

  def __call__(self, *args, **kwds):
obj = self.ref()
if obj is None:
  raise ValueError(Calling dead weak method)
self.func(obj, *args, **kwds)

if __name__ == __main__:

  class A(object):

def foo(self):
  print foo method called on, self

  a = A()
  m = weakmethod(a.foo)
  m()
  del a
  m()
--
http://mail.python.org/mailman/listinfo/python-list


Re: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all?

2010-07-30 Thread Steven D'Aprano
On Sat, 31 Jul 2010 14:25:39 +1200, Gregory Ewing wrote:

 Steven D'Aprano wrote:
 
   A
  / \
 C   B
  \ /
   D
  / \
 E   F
 
 Yes, a super call might jog left from C to B, but only when being
 called from one of the lower classes D-F. That's still an upwards call
 relative to the originator, not sidewards.
 
 But it's not an upward call relative to the class mentioned in the
 super() call, which is why I say it's misleading.

Which class would that be?

I think I'm going to need an example that demonstrates what you mean, 
because I can't make heads or tails of it. Are you suggesting that a call 
to super(C, self).method() from within C might call B.method(self)?


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


Re: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all?

2010-07-30 Thread Steven D'Aprano
On Fri, 30 Jul 2010 14:43:07 +0200, Jean-Michel Pichavant wrote:

 Quoting Michele's article (I think he's still hanging around this list)
 
 Readers familiar will single inheritance languages, such as Java or
 Smalltalk, will have a clear concept of superclass in mind. This
 concept, however, has /no useful meaning/ in Python or in other multiple
 inheritance languages.

I have read Michelle Simionato's articles on super in Python. He has 
taught me a lot. But on that specific matter, I think he is wrong.

Of course, he is right to say that the concept of *the* superclass is 
meaningless in a MI language like Python. If MyClass inherits method 
spam() from class A, and inherits method ham() from class B, which is 
the superclass of MyClass?

But Michelle is wrong to conclude that the problem lies with the concept 
of *superclass*. The problem lies with the idea that there is ONE 
superclass. By dismissing the entire concept, he is throwing out the baby 
with the bathwater.

The useful, and I would argue *correct*, concept of superclass is very 
simple. It is a reflection of subclass: if Z is a subclass of A, then A 
is a superclass of Z. This follows e.g. superset and subset. We don't 
have any problem understanding that a class can have many subclasses. Why 
the resistance to the idea that a class can have many superclasses? 

Even in a single inheritance language, if we had a class hierarchy 

A - B - C - ... - Y - Z 

it makes perfect sense to describe *all* of A-Y as superclasses of Z, 
just as we describe all of B-Z as subclasses of A.



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


Re: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all?

2010-07-30 Thread Ian Kelly
On Fri, Jul 30, 2010 at 6:38 AM, Hrvoje Niksic hnik...@xemacs.org wrote:
 Gregory Ewing greg.ew...@canterbury.ac.nz writes:

 I think the point is that the name is misleading, because it makes it
 *sound* like it's going to call a method in a superclass, when it fact
 it might not.

 That is indeed confusing to some people, especially those who refuse to
 to accept the notion that superclass means the same as next in MRO,
 maintaining instead that superclass refers to one of the base classes,
 their bases, etc. -- IMO a defensible position.

 super might have better been called next_in_mro, next_method, or
 next_class, except those are harder to type, and way less catchy than
 super.  The Dylan and CLOS operator that super is most closely based
 on is called (call-)next-method.

I have to chime in and agree that the name super is problematic.
I'm reading this thread with a sense of alarm because I apparently
never read the super() documentation too closely (why would I?  Oh,
it just accesses an attribute from a superclass.  Moving on.) and
have been writing code for the past four years under the impression
that super() will always refer to a superclass of the current class.
Fortunately, I don't use multiple inheritance often, and when I do I
prefer to write the superclasses explicitly (perhaps because of the
same misconception), so I probably haven't really abused it terribly.

On a tangent, is it just me, or is the super() documentation
incorrect, or at least unclear?  Quoting from the first two
paragraphs:

super(type[, object-or-type])

Return a proxy object that delegates method calls to a parent or
sibling class of type. This is useful for accessing inherited methods
that have been overridden in a class. The search order is same as that
used by getattr() except that the type itself is skipped.

The __mro__ attribute of the type lists the method resolution
search order used by both getattr() and super(). The attribute is
dynamic and can change whenever the inheritance hierarchy is updated.

In the first paragraph, type refers to type, the first parameter
in the function signature.  In the second paragraph, type refers to
the type instance or the type of the object passed as the second
argument.  If it also referred to the first parameter, then super()
would always access a superclass as I initially thought; I wonder if
this might have been partially responsible for my confusion.

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


Re: Tkinter Label alignment problem using OS 10.6

2010-07-30 Thread AJ
On Jul 30, 5:07 pm, rantingrick rantingr...@gmail.com wrote:
 On Jul 30, 6:52 pm, AJ ajuff...@yahoo.com wrote:

  Dear users,

  I have written a sample program that ran correctly with earlier than
  Mac OS 10.6. The answer field Label does not align correctly. I
  downloaded the latest Python 2.7 release but still did not solve the
  problem.  Look for line L4.place(relx=0.32,rely=0.56, anchor=W)

 DO YOURSELF A HUGE FAVOR AJ... Learn how to use the pack and grid
 geometry managers available in Tkinter before it's too late. Well,
 unless of course your a sadist. In that case just ignore my post
 completely. 8^O

 http://effbot.org/tkinterbook/tkinter-index.htm#introduction

I know the pack and grid. They do not allow me to position my widget
the way I want.
You have to go back to first grade and relearn the phrase “If you have
nothing nice to say do not say anything at all”.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: default behavior

2010-07-30 Thread Steven D'Aprano
On Fri, 30 Jul 2010 08:34:52 -0400, wheres pythonmonks wrote:

 Sorry, doesn't the following make a copy?
 
 from collections import defaultdict as dd x = dd(int)
 x[1] = 'a'
 x
 defaultdict(type 'int', {1: 'a'})
 dict(x)
 {1: 'a'}



 
 I was hoping not to do that -- e.g., actually reuse the same underlying
 data.  


It does re-use the same underlying data.

 from collections import defaultdict as dd
 x = dd(list)
 x[1].append(1)
 x
defaultdict(type 'list', {1: [1]})
 y = dict(x)
 x[1].append(42)
 y
{1: [1, 42]}

Both the defaultdict and the dict are referring to the same underlying 
key:value pairs. The data itself isn't duplicated. If they are mutable 
items, a change to one will affect the other (because they are the same 
item). An analogy for C programmers would be that creating dict y from 
dict y merely copies the pointers to the keys and values, it doesn't copy 
the data being pointed to.

(That's pretty much what the CPython implementation does. Other 
implementations may do differently, so long as the visible behaviour 
remains the same.)



 Maybe dict(x), where x is a defaultdict is smart?  I agree that a
 defaultdict is safe to pass to most routines, but I guess I could
 imagine that a try/except block is used in a bit of code where on the
 key exception (when the value is absent)  populates the value with a
 random number.  In that application, a defaultdict would have no random
 values.

If you want a defaultdict with a random default value, it is easy to 
provide:

 import random
 z = dd(random.random)
 z[2] += 0
 z
defaultdict(built-in method random of Random object at 0xa01e4ac, {2: 
0.30707092626033605})


The point which I tried to make, but obviously failed, is that any piece 
of code has certain expectations about the data it accepts. If take a 
function that expects an int between -2 and 99, and instead decide to 
pass a Decimal between 100 and 150, then you'll have problems: if you're 
lucky, you'll get an exception, if you're unlucky, it will silently give 
the wrong results. Changing a dict to a defaultdict is no different.

If you have code that *relies* on getting a KeyError for missing keys:

def who_is_missing(adict):
for person in (Fred, Barney, Wilma, Betty):
try:
adict[person]
except KeyError:
print person, is missing

then changing adict to a defaultdict will cause the function to 
misbehave. That's not unique to dicts and defaultdicts.



 Besides a slightly different favor, does the following have applications
 not covered by defaultdict?
 
 m.setdefault('key', []).append(1)

defaultdict calls a function of no arguments to provide a default value. 
That means, in practice, it almost always uses the same default value for 
any specific dict.

setdefault takes an argument when you call the function. So you can 
provide anything you like at runtime.


 I think I am unclear on the difference between that and:
 
 m['key'] = m.get('key',[]).append(1)

Have you tried it? I guess you haven't, or you wouldn't have thought they 
did the same thing.

Hint -- what does [].append(1) return?


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


Re: Performance ordered dictionary vs normal dictionary

2010-07-30 Thread Dan Stromberg
On Wed, Jul 28, 2010 at 11:11 PM, Chris Rebert c...@rebertia.com wrote:

 On Wed, Jul 28, 2010 at 8:12 PM, Navkirat Singh navkir...@gmail.com
 wrote:
  Sorry, I might have been a bit vague:
  (Also, I am new to pythong)
  I am trying to do construct my own web session tracking algorithm for a
 web
  server (which also I have constructed). The book keeping is for the
 session
  information I track. The dictionary object will do this for me. I was
  initially using a plain dictionary object, but I read this in the
  documentation that made me think about the question I asked :-

 Does your program actually make use of the ordering? If so, then yes,
 using OrderedDict is obviously preferable (Why reimplement something
 needlessly?). If not, then why bother with the extra complication?

 (You are aware that the ordered in OrderedDict means that its keys
 are ordered, and not that, say, a list containing OrderedDicts can be
 sorted, right?)


Actually, a collections.OrderedDict saves things not in key order, but in
chronological order:

$ /usr/local/python27/bin/python
Python 2.7rc1 (r27rc1:81772, Jun 10 2010, 14:28:26)
[GCC 4.4.1] on linux2
Type help, copyright, credits or license for more information.
 import collections
 d = collections.OrderedDict()
 d
OrderedDict()
 d[5] = 'a'
 d[3] = 'b'
 d[8] = 'c'
 print d.keys()
[5, 3, 8]


If you want things saved in key order, you might try my treap or duptreap
module:

http://stromberg.dnsalias.org/~dstromberg/treap/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: default behavior

2010-07-30 Thread wheres pythonmonks

 Hint -- what does [].append(1) return?


Again, apologies from a Python beginner.  It sure seems like one has
to do gymnastics to get good behavior out of the core-python:

Here's my proposed fix:

 m['key'] = (lambda x: x.append(1) or x)(m.get('key',[]))

Yuck!  So I guess I'll use defaultdict with upcasts to dict as needed.

On a side note:  does up-casting always work that way with shared
(common) data from derived to base?  (I mean if the data is part of
base's interface, will  b = base(child) yield a new base object that
shares data with the child?)

Thanks again from a Perl-to-Python convert!

W


On Fri, Jul 30, 2010 at 11:47 PM, Steven D'Aprano
st...@remove-this-cybersource.com.au wrote:
 On Fri, 30 Jul 2010 08:34:52 -0400, wheres pythonmonks wrote:

 Sorry, doesn't the following make a copy?

 from collections import defaultdict as dd x = dd(int)
 x[1] = 'a'
 x
 defaultdict(type 'int', {1: 'a'})
 dict(x)
 {1: 'a'}




 I was hoping not to do that -- e.g., actually reuse the same underlying
 data.


 It does re-use the same underlying data.

 from collections import defaultdict as dd
 x = dd(list)
 x[1].append(1)
 x
 defaultdict(type 'list', {1: [1]})
 y = dict(x)
 x[1].append(42)
 y
 {1: [1, 42]}

 Both the defaultdict and the dict are referring to the same underlying
 key:value pairs. The data itself isn't duplicated. If they are mutable
 items, a change to one will affect the other (because they are the same
 item). An analogy for C programmers would be that creating dict y from
 dict y merely copies the pointers to the keys and values, it doesn't copy
 the data being pointed to.

 (That's pretty much what the CPython implementation does. Other
 implementations may do differently, so long as the visible behaviour
 remains the same.)



 Maybe dict(x), where x is a defaultdict is smart?  I agree that a
 defaultdict is safe to pass to most routines, but I guess I could
 imagine that a try/except block is used in a bit of code where on the
 key exception (when the value is absent)  populates the value with a
 random number.  In that application, a defaultdict would have no random
 values.

 If you want a defaultdict with a random default value, it is easy to
 provide:

 import random
 z = dd(random.random)
 z[2] += 0
 z
 defaultdict(built-in method random of Random object at 0xa01e4ac, {2:
 0.30707092626033605})


 The point which I tried to make, but obviously failed, is that any piece
 of code has certain expectations about the data it accepts. If take a
 function that expects an int between -2 and 99, and instead decide to
 pass a Decimal between 100 and 150, then you'll have problems: if you're
 lucky, you'll get an exception, if you're unlucky, it will silently give
 the wrong results. Changing a dict to a defaultdict is no different.

 If you have code that *relies* on getting a KeyError for missing keys:

 def who_is_missing(adict):
    for person in (Fred, Barney, Wilma, Betty):
        try:
            adict[person]
        except KeyError:
            print person, is missing

 then changing adict to a defaultdict will cause the function to
 misbehave. That's not unique to dicts and defaultdicts.



 Besides a slightly different favor, does the following have applications
 not covered by defaultdict?

 m.setdefault('key', []).append(1)

 defaultdict calls a function of no arguments to provide a default value.
 That means, in practice, it almost always uses the same default value for
 any specific dict.

 setdefault takes an argument when you call the function. So you can
 provide anything you like at runtime.


 I think I am unclear on the difference between that and:

 m['key'] = m.get('key',[]).append(1)

 Have you tried it? I guess you haven't, or you wouldn't have thought they
 did the same thing.

 Hint -- what does [].append(1) return?


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

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


have you read emacs manual cover to cover?; (was Do we need a Stevens book?)

2010-07-30 Thread Xah Lee
cleaned up and extended my previous post. Sentences and ideas made
more precise and detailed.

• Emacs Idolization: Have You Read the Emacs Manual From Cover to
Cover?
  http://xahlee.org/emacs/emacs_manual_cover_to_cover.html

plain text version follows:
--

Thien-Thi Nguyen wrote:

Why does the search start with Google (and continue with other
downstream, non-terminating, whirlpool-shaped, out of date,
referenda)? Why not go to the source?  The Emacs Lisp manual, the
Emacs Lisp code, the Emacs customization facility, the Emacs *scratch*
buffer, the Emacs!

Elena wrote:

Surprisingly enough - or not? - it seems few users do read the
manuals... I'm guilty of this too (and Emacs' manuals will be my
reading on my next vacations).

I always thought of doing this, but it never happened. Not the emacs
manual, nor the elisp manual. Over the past 12 years of using emacs
daily, i have read perhaps 1/3 of the emacs manual and 1/2 elisp
manual, counted in a accumulative way.

However, i have read cover to cover, word for word, systematically in
a continued setting, several programing lang or software manuals. Some
of these software are quite more deeper than emacs. Here they are from
my recollection.

(Note: emacs manual for emacs 22 is 589 pages in printed form, and
elisp manual for emacs 21 is 900 pages.)

-
Microsoft Word Manual

Microsoft Word manual i think i've read most of it in about 1992.
Though, i can't remember i actually read the manual systematically or
just become expert by using and scanning it when needed. (i stopped
using Microsoft Word about 1998.)

-
HP-28S Advanced Scientific Calculator

HP-28S Advanced Scientific Calculator manual. (2 books) I read cover
to cover, twice, in about 1991. In fact this is how i learned
programing, my first computer language, and the first i mastered.

(See: HP-28S Advanced Scientific Calculator and Xah Lee's Computing
Experience Bio. )

-
The Mathematica Book

Mathematica manual (aka the Mathematica Book amazon ). I've read it 3
times in separate years, systematically, from cover to cover. This all
happened in 1990s. Note that Mathematica the language, the subject it
deals with, is inherently a order of magnitude more complex than
emacs. The Mathematica book is 1381 pages, 3 kilograms. Heavy enough
to hit someone to cause concussion.

This 4th edition published in 1999, is the last printed edition. They
no longer print it nor come with the software. Note how commercial
orgs have adopted changes with the changing industry.

-
The Perl Book

The Perl Book. I've read basically cover to cover in about 1998, 1999.
(yes, i own the printed book. The printed book aka The Camel Book is
edited version of Perl's man pages. Actually i've read all major perl
books from 1997 to ~2000. (See: Pathetically Elational Regex Language
(PERL))

-
PHP manual

The PHP manual (online). Roughly read reasonably all of it in about a
week, in 2005. (scanned in detail on parts that do not require
detailed understanding at first.)

-
MySQL manual

MySQL manual, online. Read it at the same time i read PHP manual from
cover to cover, in 2005. Took me about week or two. I've been working
with SQL or variants daily in a day job during 1998 to 2002, but
haven't touched it for 2 years. So this reading is to brush up my SQL,
as well as first time comprehensive reading of MySQL documentation in
particular.

-
Habit of Reading Manuals

Reading manuals systematically is kinda a habit, developed from early
1990s as part of a method to study English, and also somewhat a old-
fashioned and stubburn mindset of wanting to learn everything from
ground up, throughly, and from the original source. Reading manuals,
is also how i learned most of my proprograming. Just about any
software, language, OS, i used from about 1991 to about early 2000s, i
tried to read their manuals systematically from cover to cover, not
missing any word. This mentality and its severity, very gradually
declined over the past 20 years. Today, i do not take the pain to
systematically read their manuals of any new software i have to learn.
(if it exists at all; or isn't some haphazard wiki, or random notes by
student joe (such as Python's docs. See: Python Documentation
Problems).)

(other manuals i've read quite a lot for example: vast unix man pages,
Apache 1.x, Sun Microsystem's Solaris (3 volumes) (2000), Scheme R4RS
(1998), Java, Microsoft's JScript (~2005), Python (~2005), Mac OS X
Server official doc from Apple, ... (See: Examples Of Quality
Documentation In The Computing Industry) )

=
Is Emacs Godsend?

Elena wrote:

Emacs is too much a complex (not difficult) and powerful software
to be used by intuition alone, unlike many softwares we are used to.

This is simply not true.


[issue7330] PyUnicode_FromFormat segfault

2010-07-30 Thread Ray.Allen

Ray.Allen ysj@gmail.com added the comment:

Is this really worthy to fix?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7330
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9399] Provide a 'print' action for argparse

2010-07-30 Thread Steven Bethard

Steven Bethard steven.beth...@gmail.com added the comment:

The equivalent to optparse callback is basically to define __call__ in a 
subclass of Action. Pretty much the same amount of work because they both have 
complicated parameters.

The callable I (not fully confidently) proposed would just be a shorthand for 
defining __call__ in a subclass of Action when you don't care about any of the 
other command line info.

I guess, without further use cases for callable and given that you can 
subclass Action for other use cases, let's just do the action='write' version. 
Feel free to supply a patch, or I will when I get some time for argparse again.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9399
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6612] 'import site' fails when called from an unlinked directory

2010-07-30 Thread Georg Brandl

Georg Brandl ge...@python.org added the comment:

Thanks! Reopening.

--
components: +Library (Lib)
stage:  - patch review
status: languishing - open
type:  - behavior
versions: +Python 3.1, Python 3.2 -Python 2.5, Python 2.6

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6612
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4179] pdb: Allow the list command to return to the currently debugged line

2010-07-30 Thread Georg Brandl

Georg Brandl ge...@python.org added the comment:

Implemented in r83260.  Thanks for the patch!

--
resolution:  - accepted
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue4179
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9230] pdb.Pdb.checkline() throws AttributeError if called before starting a debug session

2010-07-30 Thread Georg Brandl

Georg Brandl ge...@python.org added the comment:

Thanks, fixed in r83261.

--
nosy: +georg.brandl
resolution:  - fixed
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9230
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9214] Most Set methods of KeysView and ItemsView do not work right

2010-07-30 Thread Eli Bendersky

Eli Bendersky eli...@gmail.com added the comment:

Attaching an updated patch, with the trailing whitespace removed. Hope it's 
more acceptable now.

P.S. Please let me know how to detect such issues in future patches.

--
Added file: http://bugs.python.org/file18267/issue9214.2.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9214
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1437051] continue in .pdbrc has no effect

2010-07-30 Thread Georg Brandl

Georg Brandl ge...@python.org added the comment:

Thanks for the patience, this is now fixed in r83262.

I also added a -c option so that you can give the continue on the command 
line, not put it in the .pdbrc file.

--
nosy: +georg.brandl
resolution:  - fixed
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1437051
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9426] Explicitly state lack of support for keyword arguments in builtin functions

2010-07-30 Thread Łukasz Langa

New submission from Łukasz Langa luk...@langa.pl:

Currently it's somewhat surprising that while the documentation often states 
the default values for certain builtins, invoking the builtin with keyword 
arguments as described in the documentation does not work.

Original discussion: #7447

I'm going through all builtins to see how the keyword arg support looks and I'm 
going to present a patch for Doc/library/builtins.rst that explicitly states 
that builtins don't support this kind of invocation.

Expect a patch later today.

--
assignee: d...@python
components: Documentation
messages: 112048
nosy: d...@python, lukasz.langa, tjreedy
priority: normal
severity: normal
status: open
title: Explicitly state lack of support for keyword arguments in builtin 
functions
versions: Python 2.7, Python 3.2

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9426
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8015] pdb commands command throws you into postmortem if you enter an empty command

2010-07-30 Thread Georg Brandl

Georg Brandl ge...@python.org added the comment:

Fixed in r83265. Thanks!

--
nosy: +georg.brandl
resolution:  - fixed
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue8015
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9417] Declaring a class creates circular references

2010-07-30 Thread Ray.Allen

Ray.Allen ysj@gmail.com added the comment:

 However here's a proposed solution:

* for the __mro__: instead of using a tuple, use a new object that inherits 
from it. This new object should use weak reference for the first item and 
should return the real object (if available) only in __getitem__().

* __objclass__ can should become a property based on weak references.



I'm afraid doing so could cause some public C API change. For example, the 
PyDescr_TYPE, if we implemented all the Descriptor object's d_type(that is the 
__objclass__ of all types of descriptors) based on weakref, we could have all 
the callers who call the descriptor functions to check weather the 
weak-referented class object has gone away.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9417
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



  1   2   >