Re: Proposal: === and !=== operators

2014-07-11 Thread Chris Angelico
On Sat, Jul 12, 2014 at 4:11 PM, Ethan Furman  wrote:
> class list:
> def __eq__(self, other):
> if len(self) != len(other):
> return False
> for this, that in zip(self, other):
>  if this is that or this == that:
>  continue
>  break
> else:
> return True
> return False

Seems a little elaborate. Why not just return straight from the loop,
instead of breaking and using else? :)

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


Re: Proposal: === and !=== operators

2014-07-11 Thread Ethan Furman

On 07/11/2014 10:07 PM, Alan Bawden wrote:

Steven D'Aprano  writes:


But perhaps we only care about changes in value, not type. NAN or no NAN,
list equality works fine:

py> data = [1.0, 2.0, float('nan'), 4.0]
py> old = data[:]
py> old == data  # No changes made yet, should return True
True


You lost me right here.  If list equality is determined by comparing
lists element-by-element, and the second element of old is _not_ equal
to the second element of data, then why should old and data be equal?

In fact, I find myself puzzled about exactly how list equality is
actually defined.  Consider:

   >>> a = float('nan')
   >>> x = [1, a, 9]
   >>> y = [1, a, 9.0]
   >>> x == y
   True

So is there some equality predicate where corresponding elements of x
and y are equal?

   >>> map(operator.eq, x, y)
   [True, False, True]

It's not "==".

   >>> map(operator.is_, x, y)
   [True, True, False]

And it's not "is".


class list:
def __eq__(self, other):
if len(self) != len(other):
return False
for this, that in zip(self, other):
 if this is that or this == that:
 continue
 break
else:
return True
return False

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


Re: Error after sympy lambdify function update using vector() dot.class

2014-07-11 Thread Chris Angelico
On Sat, Jul 12, 2014 at 3:33 AM, Niklas Troedsson
 wrote:
> I am new to the forum and programming Python.
>
> Recently I updated both Canopy and its packages, I am now using Canopy
> 1.4.1.1975 and sympy 0.7.5-1.
>

This is a general Python list, not Canopy or Sympy specific. If you
don't get a useful response here, you may want to try looking for
their mailing lists; Canopy appears to be (sorry, I'm not familiar
with it) an Enthought package, so you could ask Enthought for support;
and Sympy doubtless has its own lists, which you could find with a
Google search. I suspect that what you're asking about may be
sufficiently specialized that you'll get better responses there.

But you might get a response here. Never know! We do have some pretty
awesome experts on python-list.

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


Re: Proposal: === and !=== operators

2014-07-11 Thread Torsten Bronger
Hallöchen!

Torsten Bronger writes:

> Alan Bawden writes:
>
>> [...]
>>
>> You lost me right here.  If list equality is determined by
>> comparing lists element-by-element, and the second element of old
>> is _not_ equal to the second element of data, then why should old
>> and data be equal?
>
> I think Python first tests for identity, and falls back to
> equality (or the other way round).  This behaviour is questionable
> in my opinion.

See also
https://mail.python.org/pipermail/python-bugs-list/2006-August/035010.html

Tschö,
Torsten.

-- 
Torsten BrongerJabber ID: torsten.bron...@jabber.rwth-aachen.de
  or http://bronger-jmp.appspot.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Proposal: === and !=== operators

2014-07-11 Thread Torsten Bronger
Hallöchen!

Alan Bawden writes:

> [...]
>
> You lost me right here.  If list equality is determined by
> comparing lists element-by-element, and the second element of old
> is _not_ equal to the second element of data, then why should old
> and data be equal?

I think Python first tests for identity, and falls back to equality
(or the other way round).  This behaviour is questionable in my
opinion.

Tschö,
Torsten.

-- 
Torsten BrongerJabber ID: torsten.bron...@jabber.rwth-aachen.de
  or http://bronger-jmp.appspot.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Proposal: === and !=== operators

2014-07-11 Thread Chris Angelico
On Sat, Jul 12, 2014 at 3:07 PM, Alan Bawden
 wrote:
> Steven D'Aprano  writes:
>
>> But perhaps we only care about changes in value, not type. NAN or no NAN,
>> list equality works fine:
>>
>> py> data = [1.0, 2.0, float('nan'), 4.0]
>> py> old = data[:]
>> py> old == data  # No changes made yet, should return True
>> True
>
> You lost me right here.  If list equality is determined by comparing
> lists element-by-element, and the second element of old is _not_ equal
> to the second element of data, then why should old and data be equal?
>
> In fact, I find myself puzzled about exactly how list equality is
> actually defined.

In the Python 3 docs, it's made a bit clearer, at least as regards the
'in' and 'not in' operators: it's an identity check followed by an
equality check - "x is y or x == y". The same comparison is done for
equality, although it's not strictly described there (at least, I
couldn't find it). There are a lot of these sorts of corner cases that
aren't made really clear in the docs, because the verbosity would be
more of a problem than the omission - I consider them to be like "The
land continues to burn" on Obsidian Fireheart [1] or the reminder text
on Madness [2]; if you go to the Magic: The Gathering Comprehensive
Rulebook, you can find the exact "code-accurate" details on how either
one works, but that takes several pages of verbiage, and it's much
better to just say "you may cast it for its madness cost instead of
putting it into your graveyard".

For the most part, the identity check is a pure optimization. Most
Python objects compare equal to themselves. It only VERY occasionally
matters (like when there's a NaN in your list), and for those cases,
you have the interactive interpreter to try things at.

ChrisA

[1] http://gatherer.wizards.com/Pages/Card/Details.aspx?multiverseid=192224
[2] eg http://gatherer.wizards.com/Pages/Card/Details.aspx?multiverseid=118892
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Save/restore breakpoints between pdb runs

2014-07-11 Thread dieter
Ed Blackman  writes:
> I've recently started using Python for my job (as opposed to writing
> smallish scripts for personal use), and so have needed to debug quite
> a bit more.
>
> I've been using pdb mainly via 'python -m pdb script args'.  Perhaps
> it's my Java background, but even when I have permissions to change
> the source, I find editing source to insert 'import pdb;
> pdb.set_trace()' unnatural.  The consequence is that I have to
> recreate my breakpoints when I have to exit pdb.
>
> I've written the following code, which I load from .pdbrc with
> 'execfile(os.path.expanduser('~/.pydb.py'))'

This approach does not seem very robust to me:

  "pdb" resolves all breakpoints to lines (in source files) - and
  any modification to the source may change the lines.
  As a consequence, your breakpoints may no longer be at the
  places where you expect them.


A long time ago, I have developped "dm.pdb" - a slight
extension/improvement over "pdb". One of the extensions
has been to make it possible to set breakpoints from outside
the debugger -- without too many surprises. It looks somehow like that:

  from dm.pdb import Pdb; D = Pdb()
  ...
  from ... import f
  from ... import g
  from ... import C
  ...
  D.do_break("f") # set breakpoint on "f"
  D.do_break("g") # set breakpoint on "g"
  D.do_breack("C.m") # set breakpoint on method "m" of class "C"
  ...
  D.run("...")

It is more robust than breakpoints on line numbers - but, of course,
it cannot be automated but must be targeted to individual programs.
In addition, the robustness is limited to breakpoints on
executable objects; setting breakpoints on line numbers is possible, too --
but has the same problem with moving lines.


In the meantime, "pdb" itself may support this form of external
control (maybe even better then "dm.pdb").

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


Re: context manager based alternative to Re: Proposal: === and !===

2014-07-11 Thread Chris Angelico
On Sat, Jul 12, 2014 at 8:37 AM, Cameron Simpson  wrote:
> On 11Jul2014 14:37, Chris Angelico  wrote:
>>
>> Does C-level code have to check this flag before comparing
>> nans,
>
>
> If you mean:
>
>   float x, y;
>   [...]
>   if (x == y) {
> action...
>   }
>
> then no.
>
>
>> or is this applicable only to the Python float objects and only
>> when compared in Python?
>
>
> The former but not the latter, in my mind. Comparing Python float objects
> should obey the rule, whether in pure Python or extensions using a PyFloat.
> But I'd hope they get that for free by indirecting through PyFloat's
> methods.

Suppose you have some C extension that works with numbers (I have
NumPy in mind as I write this, but I'm not familiar with its inner
workings; certainly it'd be possible for this to be implemented how I
describe). You pack a bunch of Python float objects into an array,
pack another bunch into another array, and then compare them.

>>> from numpy import array
>>> x=array([1.0,2.0])
>>> y=array([1.0,2.1])
>>> x==y
array([ True, False], dtype=bool)

So far, so good. Now let's introduce a NaN.

>>> nan=float("nan")
>>> x=array([1.0,2.0,nan])
>>> y=array([1.0,2.1,nan])
>>> x==y
array([ True, False, False], dtype=bool)

I deliberately used the exact same nan so that an identity or
bit-pattern check would return True; but numpy says False, these are
not the same. Now, if I replace array with this list-like thing, then
your context manager would control that last result:

>>> class array(list):
 def __eq__(self, other):
 if not isinstance(other, type(self)) or len(other)!=len(self):
 return False
 return [self[i] == other[i] for i in range(len(self))]

But if, instead, the array is packed into a C-level array of floats
(which can be done without losing any information other than object
identity), then this would no longer be affected by your context
manager, unless the extension unnecessarily reconstructs two Python
floats to compare them, or else is made specifically aware of the
change.

>> Is isnan() still usable?
>
> Yes.
>
>> (Consider that x!=x == math.isnan(x) normally.)
>
> Can you elaborate on this statement please?

def isnan(x):
return isinstance(x, float) and x!=x

Fairly standard way of defining isnan(). It would be extremely
surprising if that correlation didn't work. Let's suppose you want to
sort a list of floats with all NaNs coming first:

new_list = sorted(old_list, key=lambda x: (x==x, x))
new_list = sorted(old_list, key=lambda x: (not math.isnan(x), x))

The first one is much briefer (and faster, as it doesn't need to look
up math and math.isnan and then call a function), and people will
assume they're equivalent. If this kind of thing happens deep inside a
call tree, it'll be extremely surprising that the two act differently.
So there has to be some other way to implement isnan(), which will
probably involve poking around with the bit pattern, and everyone MUST
use that instead of the simple comparison.

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


Re: Proposal: === and !=== operators

2014-07-11 Thread Alan Bawden
Steven D'Aprano  writes:

> But perhaps we only care about changes in value, not type. NAN or no NAN, 
> list equality works fine:
>
> py> data = [1.0, 2.0, float('nan'), 4.0]
> py> old = data[:]
> py> old == data  # No changes made yet, should return True
> True

You lost me right here.  If list equality is determined by comparing
lists element-by-element, and the second element of old is _not_ equal
to the second element of data, then why should old and data be equal?

In fact, I find myself puzzled about exactly how list equality is
actually defined.  Consider:

  >>> a = float('nan')
  >>> x = [1, a, 9]
  >>> y = [1, a, 9.0]
  >>> x == y
  True

So is there some equality predicate where corresponding elements of x
and y are equal?  

  >>> map(operator.eq, x, y)
  [True, False, True]

It's not "==".

  >>> map(operator.is_, x, y)
  [True, True, False]

And it's not "is".

-- 
Alan Bawden
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Proposal: === and !=== operators

2014-07-11 Thread Steven D'Aprano
Thanks to everyone who has commented. Some responses:

* I was completely mistaken about == enforcing the rule 
  that __eq__ returns True or False. I have no idea where
  I got that idea from, sorry for the noise.

* I disagree that having two equals operators, == and ===, 
  would be confusing. The Javascript/PHP model doesn't apply:

  - In Javascript and PHP, the shorter, more attractive
version == does the wrong thing and is harmful, hence
everyone needs to learn about === immediately.
  - In my proposal, the shorter, more attractive version 
== does what everyone already assumes == will do. It's
only specialists who need to learn about === .

* But having said that, I find myself trying to solve a problem
  reported by Anders which I do not understand, cannot replicate,
  and although I'm willing to give him the good faith benefit of 
  the doubt, I find myself less and less convinced that the 
  problem is what he thinks it is.

To be specific, the one concrete piece of code Anders has posted is a 
completely generic "detect changes" function which he claims is broken by 
the presence of NANs. That may be, but his code is not runnable (it uses 
undefined methods that could do anything) so cannot be tested, and I 
cannot replicate his problem.

NANs or no NANs, a generic "detect changes" function already fails to 
work in some circumstances:

py> data = [1, 2.0, 3.0, 4.0]
py> old = data[:]
py> old == data  # No changes made yet, should return True
True
py> data[0] = 1.0  # Change of type.
py> old == data  # Should return False
True


But perhaps we only care about changes in value, not type. NAN or no NAN, 
list equality works fine:

py> data = [1.0, 2.0, float('nan'), 4.0]
py> old = data[:]
py> old == data  # No changes made yet, should return True
True
py> data[3] = 104.0
py> old == data  # Should return False
False


The only time it may fail, for some definition of "fail", is when the NAN 
is replaced by another NAN of the same payload but different identity. 
But I still fail to understand Ander's use-case here, how a NAN might be 
replaced by another NAN, or why he wants to compare two different NANs as 
equal.

Since I do not understand Ander's problem, I cannot hope to solve it. So 
I withdraw my suggestion. Thanks to everyone who listened.



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


Re: context manager based alternative to Re: Proposal: === and !===

2014-07-11 Thread Cameron Simpson

On 11Jul2014 14:37, Chris Angelico  wrote:

On Fri, Jul 11, 2014 at 11:17 AM, Roy Smith  wrote:

In article ,
 Cameron Simpson  wrote:

[... context manager changing NaN comparisons ...]

I'm a bit wary of anything that makes a global, even if temporary,
change to comparisons' behaviours. What happens if, deep in a call
tree, something utterly unrelated happens to do a comparison of this
nature?


Weirdness, possibly very subtle weirdness. Possibly harmless weirdness. It 
reall depends on what reliance the unrelated (but called) code has on 
nonreflexivity. I would think most code almost never depends on it.


What happens to nontrivial geometric proofs if you switch "parallel" from 
"lines never meet" to "lines meet at infinity"? Do the proofs become invalid?  
(Surely yes in some circumstances.) How do geometers know when validating 
proofs?


I agree this is a risk.

As a matter of interest, in what scenarios do people typically rely on NaN != 
NaN?


The OP (Anders) broadly wanted to be able to compare datasets that included 
real python float NaNs and not have otherwise identical datasets claim to 
differ because they had NaNs (possible the same NaN instance) in the same spot.  

Also, he wasn't doing "blind" data comparison - he still needed to use real 
floats because his code did arithmetic with them, and therefore was not helped 
by suggestions of "casting" floats to integers (bytewise the same in memory) to 
sidestep the NaN specialness.



Does C-level code have to check this flag before comparing
nans,


If you mean:

  float x, y;
  [...]
  if (x == y) {
action...
  }

then no.


or is this applicable only to the Python float objects and only
when compared in Python?


The former but not the latter, in my mind. Comparing Python float objects 
should obey the rule, whether in pure Python or extensions using a PyFloat. But 
I'd hope they get that for free by indirecting through PyFloat's methods.



Is isnan() still usable?


Yes.


(Consider that x!=x == math.isnan(x) normally.)


Can you elaborate on this statement please?

Cheers,
Cameron Simpson 

Automobile: device used to drive slower than motorcycles.
--
https://mail.python.org/mailman/listinfo/python-list


Re: context manager based alternative to Re: Proposal: === and !===

2014-07-11 Thread Cameron Simpson

On 10Jul2014 17:34, Ethan Furman  wrote:

On 07/10/2014 05:20 PM, Cameron Simpson wrote:

Here's an alternative proposal that doesn't involve a new operator.

[snip float-context manager stuff]

Decimal has a context manager like that already (I don't know if it 
supports allowing NaNs to equal each other, though).


Interesting. I did not know that. [...] Ah, 9.4.3 Context Objects. Cool.

Rather than adding the whole thing to float, perhaps extending Decimal's 
context with that option is a possible route.


The OP needed to work with floats. The data storage systems he was using stored 
IEEE floats IIRC, so Decimal may not be suitable and possibly has performance 
effects too - dunno.


I would think he'd need something implemented in the float type.

Cheers,
Cameron Simpson 

Nothing is impossible for the man who doesn't have to do it.
--
https://mail.python.org/mailman/listinfo/python-list


Save/restore breakpoints between pdb runs

2014-07-11 Thread Ed Blackman
I've recently started using Python for my job (as opposed to writing 
smallish scripts for personal use), and so have needed to debug quite a 
bit more.


I've been using pdb mainly via 'python -m pdb script args'.  Perhaps 
it's my Java background, but even when I have permissions to change the 
source, I find editing source to insert 'import pdb; pdb.set_trace()' 
unnatural.  The consequence is that I have to recreate my breakpoints 
when I have to exit pdb.


I've written the following code, which I load from .pdbrc with 
'execfile(os.path.expanduser('~/.pydb.py'))'


Is there an alternate solution to keeping persistant breakpoints that 
works much better?  My python editing happens on a lot of different 
machines/VMs, so I prefer alternate solutions that allow me to sync over 
a couple of files, not install new binaries.


If not:
1) If is there a way in pdb to set a breakpoint on a function that isn't 
in the current file?  I can see the .funcname property of the 
breakpoint, and would prefer restoring breakpoints on functions so they 
don't break if I change line numbers.  "b func_name" works in the 
current file, but "b file:func_name" doesn't.
2) Is there a way to list the commands for each breakpoint, so that they 
can be restored as well?


Any other comments or suggestions for improvement would be welcome.

def savebps():
   import pdb

   bp_num = 0
   for bp in pdb.bdb.Breakpoint.bpbynumber:
   # pdb commands operate on breakpoint number, so keep track of
   # the number the recreated breakpoint would have
   if bp is None:
   continue
   else:
   bp_num += 1

   command = 'tbreak' if bp.temporary else 'b'
   cond = '' if bp.cond is None else ', ' + bp.cond

   print("%s %s:%d%s" % (command, bp.file, bp.line, cond))

   if not bp.enabled:
   print("disable %d" % (bp_num))

   if bp.ignore > 0:
   print("ignore %d %d" % (bp_num, bp.ignore))

   print('')

--
Ed Blackman
--
https://mail.python.org/mailman/listinfo/python-list


Error after sympy lambdify function update using vector() dot.class

2014-07-11 Thread Niklas Troedsson
I am new to the forum and programming Python.

Recently I updated both Canopy and its packages, I am now using Canopy 
1.4.1.1975 and sympy 0.7.5-1.

In an earlier version my code to solve algebra and substitute a lot of 
constants and transfer functions with more than 1001 frequency points worked. 
But after the package update to the versions above, lambdify function stopped 
working and shows an invalid syntax error, pointing to the "dot" in alg.const1.

Can anybody help to get around this without changing the original code of using 
alg.const1, instead of the cumbersome fix of renaming all variables and make 
them single variable names such as alg_const1.

%run testofdotclasslambdify.py
  File "", line 1
    lambda alg.npnt1,alg.npnt2,alg.ntf1,alg.const1: (alg.const1*(alg.npnt2 + 
alg.ntf1)/(alg.const1 + alg.npnt2 + alg.ntf1))
  ^
SyntaxError: invalid syntax
 
I have attached the *.py code and copied in below.

Thank you!

testofdotclasslambdify.py
.

import numpy as np
import pylab as pl
import sympy as sy

# empty class for variables
class vector:
pass
#

# frequency, radians and Laplace representation
fqaxst = 1.0e2
fqaxsp = 100.0e6
fqnop  = 1001
fq = np.logspace(np.log10(fqaxst),np.log10(fqaxsp),fqnop)
wq = 2*np.pi*fq
s  = 1.0j*wq

ntf1   = np.exp(-s*1.0/10e6)

npnt1  = 1
npnt2  = 1
const1 = 1

### solve #1 with lambdify 
#   set equation, variables and constants to solve
alg_phiout, alg_npnt1, alg_npnt2 = sy.symbols('alg_phiout, alg_npnt1, 
alg_npnt2')
alg_ntf1, alg_const1 = sy.symbols('alg_ntf1, alg_const1', complex = 
True)

subst1   = (alg_npnt1, alg_npnt2, alg_ntf1, alg_const1)

sol  = vector() 
sol.algnpnt1 = (alg_npnt1-alg_phiout/alg_const1)*(alg_ntf1+alg_npnt2)-alg_phiout
sol.solnpnt1 = sy.simplify(sy.diff(sy.solve(sol.algnpnt1, alg_phiout)[0], 
alg_npnt1,1))
sol.refnum1  = sy.lambdify(subst1, sol.solnpnt1)
tf1  = sol.refnum1(npnt1, npnt2, ntf1, const1)

# plot
pl.figure(1)
pl.semilogx(fq,10*np.log10(np.abs(tf1)**2),label='tf1')
pl.legend(loc='lower right')
pl.title('TF')
pl.xlabel('Frequency, Hz')
pl.ylabel('Spectrum, dB')
pl.grid(b='on')
pl.show()

### solve #2 with lambdify using vector as dot-class variables
#   problem with code below, which wasn't a probelm before updating Canopy 
package manager 2014-July-01
#   I do not want all variables as signle variables but bundled in a vector 
dot.class

# set equation, variables and constants to solve
alg = vector()

alg.phiout, alg.npnt1, alg.npnt2 = sy.symbols('alg.phiout, alg.npnt1, 
alg.npnt2')
alg.ntf1, alg.const1 = sy.symbols('alg.ntf1, alg.const1', complex = 
True)

subst2   = (alg.npnt1, alg.npnt2, alg.ntf1, alg.const1)
sol.algnpnt2 = (alg.npnt1-alg.phiout/alg.const1)*(alg.ntf1+alg.npnt2)-alg.phiout
sol.solnpnt2 = sy.simplify(sy.diff(sy.solve(sol.algnpnt2, alg.phiout)[0], 
alg.npnt1,1))
sol.refnum2  = sy.lambdify(subst2, sol.solnpnt2)

# problem with new version of lambdify in new sympy, old version of 
lambdify/sympy worked
# Gives the following error code:
tf2  = sol.refnum2(npnt1, npnt2, ntf1, const1)
# tf2= sol.refnum2(npnt1, npnt2, ntf1, const1)
#   In [10]: %run testofdotclasslambdify.py
#File "", line 1
#  lambda alg.npnt1,alg.npnt2,alg.ntf1,alg.const1: (alg.const1*(alg.npnt2 + 
alg.ntf1)/(alg.const1 + alg.npnt2 + alg.ntf1))
#   ^
#   SyntaxError: invalid syntax
# In [11]:

# plot
pl.figure(2)
pl.semilogx(fq,10*np.log10(np.abs(tf1)**2),label='tf1')
pl.legend(loc='lower right')
pl.title('TF')
pl.xlabel('Frequency, Hz')
pl.ylabel('Spectrum, dB')
pl.grid(b='on')
pl.show()import numpy as np
import pylab as pl
import sympy as sy

# empty class for variables
class vector:
pass
#

# frequency, radians and Laplace representation
fqaxst = 1.0e2
fqaxsp = 100.0e6
fqnop  = 1001
fq = np.logspace(np.log10(fqaxst),np.log10(fqaxsp),fqnop)
wq = 2*np.pi*fq
s  = 1.0j*wq

ntf1   = np.exp(-s*1.0/10e6)

npnt1  = 1
npnt2  = 1
const1 = 1

### solve #1 with lambdify 
#   set equation, variables and constants to solve
alg_phiout, alg_npnt1, alg_npnt2 = sy.symbols('alg_phiout, alg_npnt1, 
alg_npnt2')
alg_ntf1, alg_const1 = sy.symbols('alg_ntf1, alg_const1', complex = 
True)

subst1   = (alg_npnt1, alg_npnt2, alg_ntf1, alg_const1)

sol  = vector()
sol.algnpnt1 = (alg_npnt1-alg_phiout/alg_const1)*(alg_ntf1+alg_npnt2)-alg_phiout
sol.solnpnt1 = sy.simplify(sy.diff(sy.solve(sol.algnpnt1, alg_phiout)[0], 
alg_npnt1,1))
sol.refnum1  = sy.lambdify(subst1, sol.solnpnt1)
tf1  = sol.refnum1(npnt1, npnt2, ntf1, const1)

# plot
pl.figure(1)
pl.semilogx(fq,10*np.log10(np.abs(tf1)**2),label='tf1')
pl.legend(loc='lower right')
pl.title('TF')
pl.xlabel('Frequency, Hz')
pl.ylabel('Spectrum, dB')
pl.grid(b='on')
pl.show()

### solve #2 with lambdify using vector as dot-class variables
#   problem with code below, which wasn't a probelm before updating Canopy 
package manager 2014-July-01
#   I do not want all variabl

Re: Hello. I'm new here...

2014-07-11 Thread Chris Angelico
On Fri, Jul 11, 2014 at 9:00 PM, Antonio Dalvit
 wrote:
> Im Antonio, from Italy. I'm new here and i'd like to introduce myself: i'm 
> learning python language after years working in ICT sector. I decided to 
> study python after fortran basic, c++, java and php for fun and because i'm 
> tired to spend lines and lines of code to make something working as I want.
>
> I'll lurk and sometimes i wall ask something that i cannot understand. I'm 
> sorry if my questions can sound simple or trivial...

Welcome! Glad to have you here, and I'm sure you'll love Python after
experience with those languages!

One thing though. There's a saying "Never offend people with style
when you can offend them with substance", which applies to ... well,
pretty much every form of communication, and I know someone who's
fluent in over six million of them. So feel free to spout crazy
theories about what Python ought to be like, because we'll happily
debate with you on that, but please consider avoiding Google Groups,
which has a strong tendency to make your posts extremely annoying in a
few ways, including double-spacing all quoted text, and making your
paragraphs into single long lines instead of properly wrapping them.
There are ways around this, but they're quite manual; personally, I
recommend either getting an actual news reader (something like Mozilla
Thunderbird), or signing up for the mailing list, which is what I do:

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

Either of those options will also make it easier for you to follow the
generally-recommended quoting style on these sorts of lists -
interleaved.

https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

So, let's get started on offending each other with substance :)

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


Re: How to decipher :re.split(r"(\(\([^)]+\)\))" in the example

2014-07-11 Thread Albert-Jan Roskam


- Original Message -

> From: Steven D'Aprano 
> To: python-list@python.org
> Cc: 
> Sent: Friday, July 11, 2014 11:04 AM
> Subject: Re: How to decipher :re.split(r"(\(\([^)]+\)\))" in the example
> 
> On Thu, 10 Jul 2014 23:33:27 -0400, Roy Smith wrote:
> 
>>  In article ,
>>   Tim Chase  wrote:
>> 
>>>  On 2014-07-10 22:18, Roy Smith wrote:
>>>  > > Outside this are \( and \): these are literal opening 
> and closing
>>>  > > bracket characters. So:
>>>  > > 
>>>  > >    \(\([^)]+\)\)
>>>  >
>>>  > although, even better would be to use to utterly awesome
>>>  >> re.VERBOSE
>>>  > flag, and write it as:
>>>  > 
>>>  >      \({2} [^)]+ \){2}
>>> 
>>>  Or heck, use a multi-line verbose expression and comment it for
>>>  clarity:
>>> 
>>>    r = re.compile(r"""
>>>      (            # begin a capture group
>>>       \({2}       # two literal "(" characters [^)]+  
>      # one or more
>>>       non-close-paren characters \){2}       # two literal 
> ")"
>>>       characters
>>>      )            # close the capture group """, 
> re.VERBOSE)
>>> 
>>>  -tkc
>> 
>>  Ugh.  That reminds me of the classic commenting anti-pattern:
> 
> The sort of dead-simple commenting shown below is not just harmless but 
> can be *critically important* for beginners, who otherwise may not know 
> what "l = []" means.
> 
>>  l = []                  # create an empty list 
>>  for i in range(10):     # iterate over the first 10 integers
>>      l.append(i)         # append each one to the list
> 

Anything better than this hideous type of commenting: (?#...), e.g
>>> re.match("(19|20)[0-9]{2}(?#year)-[0-9]{2}(?#month)", "2010-12")
Same thing for the 'limsux' modifiers, although *maybe* they can be useful.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Standard library Help

2014-07-11 Thread Neil D. Cerutti

On 7/11/2014 4:53 AM, Wolfgang Maier wrote:

On 07/11/2014 10:32 AM, Nicholas Cannon wrote:

Hey i would like to know alot more about the standard library and all
of its functions and so on and i know it is huge and i would basically
like to learn only the useful stuff that i could use and all of those
features. i have been looking around and i cant really find anything
so i wondering if you guys would know any places to learn it.



Consult the documentation:

https://docs.python.org/3/library/index.html

It's probably the only place that has everything documented.
Instead of reading everything from A-Z though, the more typical approach
is to skim through it to know what is available, then read in-depth the
parts that seem useful for a concrete problem you're trying to solve
currently. In my experience, a thorough understanding of most chapters
doesn't come with reading alone, but with practice.


I recommend reading and becoming familiar with the first five sections 
first. You won't get far without the Built-in types and functions. list, 
dict, set, open, etc., are not in a "library", per se, as other 
languages usually define it, but that's where they're described in 
Python's docs.


--
Neil Cerutti

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


Re:Hello. I'm new here...

2014-07-11 Thread Dave Angel
Antonio Dalvit  Wrote in message:
> Hello!
> 
> Im Antonio, from Italy. I'm new here and i'd like to introduce myself: i'm 
> learning python language after years working in ICT sector. I decided to 
> study python after fortran basic, c++, java and php for fun and because i'm 
> tired to spend lines and lines of code to make something working as I want.
> 
> I'll lurk and sometimes i wall ask something that i cannot understand. I'm 
> sorry if my questions can sound simple or trivial... 
> 
> 

Welcome to tutor list.  Thanks for posting in text format. 

Don't worry about whether a question might sound trivial.  If it's
 an honest question,  it's welcome.  And frequently what seems
 simple can have lots of subtlety. 

Just try to keep each new question self-contained.  Tell us python
 version,  OS version, and use copy/paste on source code and error
 tracebacks.  Try to narrow the code to a minimal case that
 demonstrates the problem,  state what you expected,  and paste
 what actually happened.

Assume that people can refer back to that first message,  so you
 don't need to repeat that stuff as the thread unfolds.  And when
 you have a new question, start a new thread,  starting over with
 python version, os ver..


-- 
DaveA

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


Hello. I'm new here...

2014-07-11 Thread Antonio Dalvit
Hello!

Im Antonio, from Italy. I'm new here and i'd like to introduce myself: i'm 
learning python language after years working in ICT sector. I decided to study 
python after fortran basic, c++, java and php for fun and because i'm tired to 
spend lines and lines of code to make something working as I want.

I'll lurk and sometimes i wall ask something that i cannot understand. I'm 
sorry if my questions can sound simple or trivial... 


good day!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how can i get "body" values?

2014-07-11 Thread marco . nawijn
On Friday, July 11, 2014 11:37:17 AM UTC+2, Frank Liou wrote:
> how can i get body values use variable to Separate catch?
> 
> 
> 
> https://lh3.googleusercontent.com/-6Ywp4GukuCM/U7-vhF0nzuI/Bv4/Ovcr1O2FScs/s1600/321.jpg
> 
> 
> 
> i want to catch name and key values
> 
> 
> 
> now i use request.data
> 
> 
> 
> i can catch all the body 
> 
> 
> 
> but how can i use variable to separate and catch?

Hi Frank,

In general, you will get better response from the
group if you post the code that you have so far and
ask questions on why it doesn't work or how to proceed.

In case of your particular problem, the answer is 
"it depends". Do you use the Python standard library, 
or a webserver framework like tornado or cherrypy? 

If you still have a choice, I would recommend to use
a framework like cherrypy. It makes your life a lot 
easier.

Regards,

Marco
 
-- 
https://mail.python.org/mailman/listinfo/python-list


how can i get "body" values?

2014-07-11 Thread Frank Liou
how can i get body values use variable to Separate catch?

https://lh3.googleusercontent.com/-6Ywp4GukuCM/U7-vhF0nzuI/Bv4/Ovcr1O2FScs/s1600/321.jpg

i want to catch name and key values

now i use request.data

i can catch all the body 

but how can i use variable to separate and catch?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re:base64 convert to binary by binascii is that right?

2014-07-11 Thread Dave Angel
Frank Liou  Wrote in message:
> conn = engine.connect()
> encoded = base64.b64encode(getbody)
> binary_string = binascii.a2b_base64(encoded)
> puresql = sqla.text("INSERT INTO friends(name) VALUES(:binary_string)")
> conn.execute(puresql,binary_string = binary_string)
> 
> 

Start by specifying Python version. 

Since you're only asking about two lines,  replace the rest with
 something that people can actually run. And instead of just
 printing binary_string,  show its type as well. 


-- 
DaveA

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


Re: How to decipher :re.split(r"(\(\([^)]+\)\))" in the example

2014-07-11 Thread Steven D'Aprano
On Thu, 10 Jul 2014 23:33:27 -0400, Roy Smith wrote:

> In article ,
>  Tim Chase  wrote:
> 
>> On 2014-07-10 22:18, Roy Smith wrote:
>> > > Outside this are \( and \): these are literal opening and closing
>> > > bracket characters. So:
>> > > 
>> > >\(\([^)]+\)\)
>> >
>> > although, even better would be to use to utterly awesome
>> >> re.VERBOSE
>> > flag, and write it as:
>> > 
>> >  \({2} [^)]+ \){2}
>> 
>> Or heck, use a multi-line verbose expression and comment it for
>> clarity:
>> 
>>   r = re.compile(r"""
>> (# begin a capture group
>>  \({2}   # two literal "(" characters [^)]+   # one or more
>>  non-close-paren characters \){2}   # two literal ")"
>>  characters
>> )# close the capture group """, re.VERBOSE)
>> 
>> -tkc
> 
> Ugh.  That reminds me of the classic commenting anti-pattern:

The sort of dead-simple commenting shown below is not just harmless but 
can be *critically important* for beginners, who otherwise may not know 
what "l = []" means.

> l = []  # create an empty list 
> for i in range(10): # iterate over the first 10 integers
> l.append(i) # append each one to the list


The difference is, most people get beyond that level of competence in a 
matter of a few weeks or months, whereas regexes are a different story. 

(1) It's possible to have spent a decade programming in Python without 
ever developing more than a basic understanding of regexes. Regular 
expressions are a specialist mini-language for a specialist task, and one 
might go months or even *years* between needing to use them.

(2) We're *Python* programmers, not *Regex* programmers, so regular 
expressions are as much a foreign language to us as Perl or Lisp or C 
might be. (And if you personally read any of those languages, 
congratulations. How about APL, J, REBOL, Smalltalk, Forth, or PL/I?)

(3) The syntax for regexes is painfully terse and violates a number of 
import rules of good design. Larry Wall has listed no fewer than 19 
problems with regex syntax/culture:

http://perl6.org/archive/doc/design/apo/A05.html


So all things considered, for the average Python programmer who has a 
basic understanding of regexes but has to keep turning to the manual to 
find out how to do even simple things, comments explaining what the regex 
does is an excellent idea.



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


Re: Standard library Help

2014-07-11 Thread Wolfgang Maier

On 07/11/2014 10:32 AM, Nicholas Cannon wrote:

Hey i would like to know alot more about the standard library and all of its 
functions and so on and i know it is huge and i would basically like to learn 
only the useful stuff that i could use and all of those features. i have been 
looking around and i cant really find anything so i wondering if you guys would 
know any places to learn it.



Consult the documentation:

https://docs.python.org/3/library/index.html

It's probably the only place that has everything documented.
Instead of reading everything from A-Z though, the more typical approach 
is to skim through it to know what is available, then read in-depth the 
parts that seem useful for a concrete problem you're trying to solve 
currently. In my experience, a thorough understanding of most chapters 
doesn't come with reading alone, but with practice.


Best,
Wolfgang
--
https://mail.python.org/mailman/listinfo/python-list


Re: Standard library Help

2014-07-11 Thread Ben Finney
Nicholas Cannon  writes:

> Hey i would like to know alot more about the standard library and all
> of its functions and so on

Welcome! This is a good goal, familiarity with the standard library is a
very important way to save yourself time in programming.

> and i know it is huge and i would basically like to learn only the
> useful stuff that i could use and all of those features. i have been
> looking around and i cant really find anything so i wondering if you
> guys would know any places to learn it.

Doug Hellman has impressive groundwork, with his “Python Module of the
Week” series. The Python 3 version http://pymotw.com/3/> is a work
in progress, but the Python 2 version is still an excellent resource
http://pymotw.com/2/> with the caveat that, as a Python newcomer,
you need to know Python 3 primarily.

-- 
 \  “The shortest distance between two points is under |
  `\  construction.” —Noelie Alito |
_o__)  |
Ben Finney

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


python app hosting

2014-07-11 Thread Jorge Alberto Díaz Orozco
Hi, I'm looking for some server to host an xmlrpc server app I've made.
Can someone help me find any?

VII Escuela Internacional de Verano en la UCI del 30 de junio al 11 de julio de 
2014. Ver www.uci.cu
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Standard library Help

2014-07-11 Thread Steven D'Aprano
On Fri, 11 Jul 2014 01:32:32 -0700, Nicholas Cannon wrote:

> Hey i would like to know alot more about the standard library and all of
> its functions and so on and i know it is huge and i would basically like
> to learn only the useful stuff that i could use and all of those
> features. i have been looking around and i cant really find anything so
> i wondering if you guys would know any places to learn it.

All of the standard library is useful to *somebody*. If you tell us what 
you want to do, we'll tell us which parts will be useful to you.

You can start by reading, or at least skimming, the docs:

# For Python 2:
https://docs.python.org/2/library/index.html

# For Python 3:
https://docs.python.org/3/library/index.html

You can also read the Python Module Of the Week:

http://pymotw.com/2/



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


Re: Standard library Help

2014-07-11 Thread marco . nawijn
On Friday, July 11, 2014 10:32:32 AM UTC+2, Nicholas Cannon wrote:
> Hey i would like to know alot more about the standard library and all of its 
> functions and so on and i know it is huge and i would basically like to learn 
> only the useful stuff that i could use and all of those features. i have been 
> looking around and i cant really find anything so i wondering if you guys 
> would know any places to learn it.

Hi Nicholas,

Have you tried the library reference [1]? If so, can you
explain why it is not sufficient for your needs?


[1] https://docs.python.org/3/library/index.html
-- 
https://mail.python.org/mailman/listinfo/python-list


Standard library Help

2014-07-11 Thread Nicholas Cannon
Hey i would like to know alot more about the standard library and all of its 
functions and so on and i know it is huge and i would basically like to learn 
only the useful stuff that i could use and all of those features. i have been 
looking around and i cant really find anything so i wondering if you guys would 
know any places to learn it.
-- 
https://mail.python.org/mailman/listinfo/python-list


ANN: eGenix mx Base Distribution 3.2.8 (mxDateTime, mxTextTools, etc.)

2014-07-11 Thread eGenix Team: M.-A. Lemburg


ANNOUNCING

   eGenix.com mx Base Distribution

 mxDateTime, mxTextTools, mxProxy, mxURL, mxUID,
  mxBeeBase, mxStack, mxQueue, mxTools

Version 3.2.8


Open Source Python extensions providing
 important and useful services
for Python programmers.

This announcement is also available on our web-site for online reading:
http://www.egenix.com/company/news/eGenix-mx-Base-Distribution-3.2.8-GA.html



ABOUT

The eGenix.com mx Base Distribution for Python is a collection of
professional quality software tools which enhance Python's usability
in many important areas such as fast text searching, date/time
processing and high speed data types.

The tools have a proven track record of being portable across many
Unix and Windows platforms. You can write applications which use the
tools on Windows and then run them on Unix platforms without change
due to the consistent platform independent interfaces.

Contents of the distribution:

 * mxDateTime - Easy to use Date/Time Library for Python
 * mxTextTools - Fast Text Parsing and Processing Tools for Python
 * mxProxy - Object Access Control for Python
 * mxBeeBase - On-disk B+Tree Based Database Kit for Python
 * mxURL - Flexible URL Data-Type for Python
 * mxUID - Fast Universal Identifiers for Python
 * mxStack - Fast and Memory-Efficient Stack Type for Python
 * mxQueue - Fast and Memory-Efficient Queue Type for Python
 * mxTools - Fast Everyday Helpers for Python

The package also include a number of helpful smaller modules in the
mx.Misc subpackage, such as mx.Misc.ConfigFile for config file parsing
or mx.Misc.CommandLine to quickly write command line applications in
Python.

All available packages have proven their stability and usefulness in
many mission critical applications and various commercial settings all
around the world.

For more information, please see the distribution page:

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



NEWS

The 3.2.8 release of the eGenix mx Base Distribution is the latest
release of our open-source Python extensions. It includes these fixes
and enhancements:

Installation Enhancements
-

 * Added web installer support to mxSetup, the distutils extension
   module which drives all our product installations.

   Uploaded web installer package to PyPI which simplifies installation.

   In addition to the usual ways of installing eGenix mx Base, we have
   uploaded a web installer to PyPI, so that it is now also possible
   to use one of these installation methods on all supported platforms
   (Windows, Linux, FreeBSD, Mac OS X):

- easy_install egenix-mx-base via PyPI
- pip install egenix-mx-base via PyPI
- egenix-mx-base egg reference in zc.buildout via PyPI
- running "python setup.py install" in the unzipped web installer
  archive directory

The web installer will automatically detect the platform and
choose the right binary download package for you. All downloads
are verified before installation.

Fixes
-

 * mxDateTime: Protected delta.strftime() against segfaults on
   Windows, which only allows day values <= 31 and segfaults for
   higher values. Thanks to Frank Boje for reporting this problem.

 * mxTextTools: Fixed a double decref in the tagging engine that
   surfaced when using custom tag objects and appending the results to
   them. Thanks to Richard Moseley for the report.

Compatibility Enhancements
--

 * Prepared eGenix mx Base for two digit Python patch level numbers
   such as Python 2.7.10

eGenix mx Base Distribution 3.2.0 was release on 2012-08-28. Please
see the announcement for new features in the 3.2 major release
compared to earlier releases:

http://www.egenix.com/company/news/eGenix-mx-Base-Distribution-3.2.0-GA.html

For a full list of changes, please refer to the eGenix mx Base
Distribution change log and the change logs of the various included
Python packages.

http://www.egenix.com/products/python/mxBase/changelog.html



UPGRADING

We encourage all users to upgrade to this latest eGenix mx Base
Distribution release.

If you are upgrading from eGenix mx Base 3.1.x, please see the eGenix
mx Base Distribution 3.2.0 release notes for details on what has
changed since the 3.1 major release.

http://www.egenix.com/company/news/eGenix-mx-Base-Distribution-3.2.0-GA.html



LICENSE

The eGenix mx Base package is distributed under the eGenix.com Public
License 1.1.0 which is an Open Source license similar to the Python
license. You can

Re: How to decipher :re.split(r"(\(\([^)]+\)\))" in the example

2014-07-11 Thread alister
On Thu, 10 Jul 2014 23:33:27 -0400, Roy Smith wrote:

> In article ,
>  Tim Chase  wrote:
> 
>> On 2014-07-10 22:18, Roy Smith wrote:
>> > > Outside this are \( and \): these are literal opening and closing
>> > > bracket characters. So:
>> > > 
>> > >\(\([^)]+\)\)
>> >
>> > although, even better would be to use to utterly awesome
>> >> re.VERBOSE
>> > flag, and write it as:
>> > 
>> >  \({2} [^)]+ \){2}
>> 
>> Or heck, use a multi-line verbose expression and comment it for
>> clarity:
>> 
>>   r = re.compile(r"""
>> (# begin a capture group
>>  \({2}   # two literal "(" characters [^)]+   # one or more
>>  non-close-paren characters \){2}   # two literal ")"
>>  characters
>> )# close the capture group """, re.VERBOSE)
>> 
>> -tkc
> 
> Ugh.  That reminds me of the classic commenting anti-pattern:
> 
> l = []  # create an empty list for i in range(10): #
> iterate over the first 10 integers
> l.append(i) # append each one to the list


to some extent yes, but when it comes to regexs stating "The bleedin 
obvious" can be useful because as this whole thread shows it is not 
always "bleedin obvious" especially after a nights sleep


-- 
"The identical is equal to itself, since it is different."
-- Franco Spisani
-- 
https://mail.python.org/mailman/listinfo/python-list


base64 convert to binary by binascii is that right?

2014-07-11 Thread Frank Liou
conn = engine.connect()
encoded = base64.b64encode(getbody)
binary_string = binascii.a2b_base64(encoded)
puresql = sqla.text("INSERT INTO friends(name) VALUES(:binary_string)")
conn.execute(puresql,binary_string = binary_string)

first 

getbody trans to base64

then i convert to binary

is that right?

getbody is '123AAA!!中文'


this is my result 123AAA\357\274\201\357\274\201\344\270\255\346\226\207



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