Re: Curious Omission In New-Style Formats

2016-07-14 Thread Robert Kern

On 2016-07-14 15:30, Ian Kelly wrote:

On Jul 14, 2016 1:52 AM, "Steven D'Aprano"
 wrote:


On Thursday 14 July 2016 15:18, Ian Kelly wrote:


Side note, neither do floating point numbers, really; what is often
called the mantissa is more properly known as the significand. But
integers don't have that either.


Er, then what's a mantissa if it's not what people call a float's mantissa?

What makes you say it is "more properly" known as the significand?

I'm not necessarily disputing what you say, I'm wondering what is your
justification for it.


http://mathworld.wolfram.com/Significand.html
http://mathworld.wolfram.com/Mantissa.html

The significand of -3.14159 is the sequence of digits 314159. The
mantissa of -3.14159 is the number 0.85841.

I don't have a copy of the IEEE-754 standard, but I believe that it
also uses the term "significand" and specifically avoids the term
"mantissa".


Confirmed.

--
Robert Kern

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

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


Re: Quick poll: gmean or geometric_mean

2016-07-09 Thread Robert Kern

On 2016-07-09 17:13, Michael Selik wrote:

On Sat, Jul 9, 2016 at 10:17 AM Jason Friedman  wrote:


+1 for consistency


What do other languages use?


R, the most likely candidate, doesn't have them built-in.

scipy.stats uses gmean() and hmean()

--
Robert Kern

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

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


Re: Gzip module does not support Unix compressed .Z files [SEC=UNOFFICIAL]

2016-07-04 Thread Robert Kern

On 2016-07-04 09:00, dieter wrote:

"Owen Brandon"  writes:


I have a query regarding the support of decompression for Unix compressed .Z 
files in Python's gzip module. The gzip system utility supports this using the 
'-d' switch, but the python module does not.


When I am right, then the "zipfile" module handles ".Z" compressed files.


No, that handles PKZIP .zip files. There are third-party modules that handle the 
.Z format, but shelling out to external programs may still be preferable:


  https://github.com/umeat/unlzw

--
Robert Kern

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

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


Re: Well, I finally ran into a Python Unicode problem, sort of

2016-07-03 Thread Robert Kern

On 2016-07-03 08:29, Jussi Piitulainen wrote:

(Hm. Python seems to understand that the character occurs in what is
intended to be an identifier. Perhaps that's a default error message.)


I suspect that "identifier" is the final catch-all token in the lexer. Comments 
and strings are clearly delimited. Keywords, operators, and [{(braces)}] are all 
explicitly whitelisted from finite lists. Well, I guess it could have been 
intended by the user to be a numerical literal, but I suspect that's attempted 
before identifier.


--
Robert Kern

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

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


Re: sympy

2016-03-30 Thread Robert Kern

On 2016-03-30 16:23, Poul Riis wrote:

What I intend to do is to let sympy find the derivative of some welldefined 
function and next define the foundation derivative as a normal function so that 
I can calculate numerical values or even make a graph.


http://docs.sympy.org/dev/modules/utilities/lambdify.html#sympy.utilities.lambdify.lambdify

--
Robert Kern

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

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


Re: How can I get/save Pandas DataFrame help content?

2015-12-17 Thread Robert Kern

On 2015-12-17 04:09, Steven D'Aprano wrote:

On Thursday 17 December 2015 13:48, Robert wrote:


Hi,

When I use Enthought/Canopy, help(DataFrame) has so much content that it
exceeds the display buffer, i.e. its head is cut off as I go up to see it.



Step 1: report this as a bug to Enthought and/or the Python bug tracker.
help(DataFrame) should automatically choose a pager such as `less` on Linux
or equivalent (`more` I think?) on Windows.


I suspect that he is using the embedded IPython console in the Canopy IDE, so 
it's more of an issue that help() knows that it's not in a true terminal so it 
doesn't page. If he had been using python at the terminal, help() would have 
indeed used the appropriate terminal pager.


Robert, in the IPython console, you can also use a special syntax to get the 
content. The IPython console widget does know how to page this:


  In [1]: pandas.DataFrame?

http://ipython.readthedocs.org/en/stable/interactive/reference.html#dynamic-object-information

--
Robert Kern

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

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


Re: Question about figure plot

2015-12-15 Thread Robert Kern

On 2015-12-15 02:43, Robert wrote:

Hi,

When I run the following code, there is no figure shown in the end.


//
import pymc
import numpy as np

n = 5*np.ones(4,dtype=int)
x = np.array([-.86,-.3,-.05,.73])

alpha = pymc.Normal('alpha',mu=0,tau=.01)
beta = pymc.Normal('beta',mu=0,tau=.01)

@pymc.deterministic
def theta(a=alpha, b=beta):
 """theta = logit^{-1}(a+b)"""
 return pymc.invlogit(a+b*x)

d = pymc.Binomial('d', n=n, p=theta, value=np.array([0.,1.,3.,5.]),\
 observed=True)

import pymc
import mymodel

S = pymc.MCMC(mymodel, db='pickle')
S.sample(iter=1, burn=5000, thin=2)
pymc.Matplot.plot(S)



I find that the figures are shown after these two lines by myself:
*
import matplotlib.pyplot as plt
plt.show()

I have searched around and have not found some explanation about it.
The plot function here is different from Matlab's. Is there better ways than
my last two lines? (I am not confident whether my last two lines is the
only choice.


No, that's right. pymc.Matplot.plot() uses matplotlib's pyplot API underneath. 
pyplot can run in two different modes: interactive and non-interactive. When 
used in a standalone script, like I assume here, it defaults to non-interactive. 
That means that it will not raise any plot windows until you call plt.show().


  http://matplotlib.org/faq/usage_faq.html#what-is-interactive-mode

See any of the examples here (note: "pylab" is the essentially the same as 
"pyplot" for these purposes):


  http://matplotlib.org/examples/pylab_examples/index.html

--
Robert Kern

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

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


Re: don't understand matrix-multiplication should be reversed in python?

2015-11-12 Thread Robert Kern

On 2015-11-12 15:57, PythonDude wrote:

Hi all,

I've come around a webpage with python-tutorial/description for obtaining 
something and I'll solve this:

R = p^T w

where R is a vector and p^T is the transpose of another vector.

...
p is a Nx1 column vector, so p^T turns into a 1xN row vector which can be 
multiplied with the
Nx1 weight (column) vector w to give a scalar result. This is equivalent to the 
dot
product used in the code. Keep in mind that Python has a reversed definition of
rows and columns and the accurate NumPy version of the previous equation would
be R = w * p.T
...

(source: http://blog.quantopian.com/markowitz-portfolio-optimization-2/ )

I don't understand this: "Keep in mind that Python has a reversed definition of
rows and columns and the accurate NumPy version of the previous equation would
be R = w * p.T"

Not true for numpy, is it? This page: 
http://mathesaurus.sourceforge.net/matlab-numpy.html says it python and matlab 
looks quite similar...

Anyone could please explain or elaborate on exactly this (quote): "Keep in mind that 
Python has a reversed definition of rows and columns"???


He's wrong, simply put. There is no "reversed definition of rows and columns". 
He simply instantiated the two vectors as row-vectors instead of column-vectors, 
which he could have easily done, so he had to flip the matrix expression.


--
Robert Kern

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

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


Re: (side-)effects and ...

2015-07-05 Thread Robert Kern

On 2015-07-05 21:36, Tim Chase wrote:

On 2015-07-05 20:29, Stefan Ram wrote:

   But why do we not have a common and well-known term for
   the counterpart, that something does not modify the state
   of the world, but that the state of the world does
   influence the value (behaviour) of a call such as
   »datetime.datetime.now().time()«?


I believe the term is "idempotent"

https://en.wikipedia.org/wiki/Idempotent_function#Computer_science_meaning


No, "idempotent" means that if it changes the state, then applying it twice or 
more has the same effect as applying it once. For example, calling 
object.__setattr__(self, attr, y) with the same arguments is idempotent; whether 
you execute that once, twice or N times, afterwards, `getattr(self, attr) is y`. 
But calling it the first time probably did make a change of state. This is 
unlike functions like list.append(self, x) which will give you different results 
depending on the number of times you call it, even if the arguments are the same.


Functions that don't change state at all are naturally idempotent, but many 
idempotent functions do change state.


--
Robert Kern

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

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


Re: calculating entropy of image or alternative?

2015-07-03 Thread Robert Kern

On 2015-07-04 02:17, telmo bacile wrote:

Hi list,   I found a code that calculates entropy of images with
python that can be used for classifying interesting images from
uninteresting ones. Interesting images has more structured patterns
while uninsteresting are more noisy or completely homogeneous.

I was thinking this code (entropy of image) can be used for measuring
the level of disorder of a group of points in the image.
For example:
Imagine that we have 3 images,  each image has 6 dots, the first one
has very ordered dots , the second one have dots a little bit
disordered and the third one has very dissordered dots.
Then entropy of each image should measure the level of
dissorganization of the dots.

But the wierd thing is that when i experimented with this i got resuts
without sense.
The result i get is that  the image with intermedium dissorder has
less entropy that the very ordered image .  Do anybody have an idea
why im getting this result?


There is no single quantity that is "The Entropy" of a given image. Images don't 
have "An Entropy". Probability distributions do. Images aren't probability 
distributions, but there are several distributions of quantities that will be 
associated with an image. The entropy of each of these distributions will each 
tell you something different about the image.


What you are calculating is the entropy of the distribution of intensities of 
the R, G, and B channels. This entropy quantity is related, more or less, to the 
variety of colors that are in the image. This distribution (and thus the entropy 
computed from it) doesn't take into account the spatial layout of the pixels. 
You could take a spatially well-ordered image and rearrange the pixels 
completely randomly; the entropy quantity that your code is computing will be 
exactly the same because the pixels contribute to the histogram in the same way.


--
Robert Kern

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

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


Re: enumerate XML tags (keys that will become headers) along with text (values) and write to CSV in one row (as opposed to "stacked" values with one header)

2015-06-30 Thread Robert Kern

On 2015-06-30 01:54, Denis McMahon wrote:

On Sun, 28 Jun 2015 17:07:00 -0700, Ned Batchelder wrote:


On Sunday, June 28, 2015 at 5:02:19 PM UTC-4, Denis McMahon wrote:




   string 3
   string 2
   string 1




Each  is just a member of the collection things, the xml does
not contain sufficient information to state that  is an ordered
collection containing a specific sequence of .


You are right that XML does not specify that  is an ordered
collection.
But XML does preserve the order of the children.  There are many XML
schema that rely on XML's order-preserving nature.


But what we *don't* know is whether the order of the umpteen identical
tags in the XML has any significance in terms of the original data,
although the OP seems intent on assigning some significance to that order
without any basis for doing so.

Consider the following tuple:

t = (tuplemember_1, tuplemember_2,  tuplemember_n)

Can we safely assume that if the tuple is ever converted to xml, either
now or at some future date using whatever the code implementation is
then, that the order of the items will be preserved:


   tuplemember_1
   tuplemember_2

   tuplemember_n/item>



Barring bugs, yes!


And if we're reading that xml structure at some point in the future, is
it safe to assume that the tuple members are in the same order in the xml
as they were in the original tuple?


Yes! Any conforming XML implementation will preserve the order.


For sanity  should have an attribute specifying the sequence of the
item in it's tuple.


While it may make you more comfortable, it's hardly a requirement for sanity.

I think you had a point in your first paragraph here, but you are obscuring it 
with FUD. The problem is not whether unadorned XML elements can be used to 
represent an ordered collection. They can and are, frequently, without any 
problem because XML elements are intrinsically ordered.


The real problem that you almost get around to articulating is that XML elements 
can *also* be used to represent unordered collections simply by ignoring the 
(preserved) order of the elements. And if you are completely blind as to the 
schema as the OP apparently is, and you are simply given a load of XML and told 
to do "something" with it, you don't know if any given collection is meant to be 
ordered or unordered. Of course, the only sensible thing to do is just preserve 
the order given to you as that is what the semantics of XML requires of you in 
the absence of a schema that says otherwise. You can always disregard the order 
later.


That said, if the data is regular enough to actually be restructured into a 
table (i.e. if  always has the same number of children, etc.), 
then it probably does represent an ordered collection. If it's variable, then 
putting it into a table structure probably doesn't make any sense regardless of 
ordering issues.


--
Robert Kern

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

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


Re: enumerate XML tags (keys that will become headers) along with text (values) and write to CSV in one row (as opposed to "stacked" values with one header)

2015-06-29 Thread Robert Kern

On 2015-06-28 22:00, Denis McMahon wrote:

On Sun, 28 Jun 2015 09:46:36 +0200, Stefan Behnel wrote:


Denis McMahon schrieb am 26.06.2015 um 09:44:

xml data is an unordered list, and are trying to assign an order to it.

If the xml data was ordered, either each tag would be different, or
each tag would have an attribute specifying a sequence number.


XML is not unordered. The document order is well defined and entirely
obvious from the data. Whether this order is relevant and has a meaning
or not is, however, not part of XML itself but is left to the semantics
of the specific document format at hand. Meaning, XML document formats
can choose to ignore that order and define it as irrelevant. That
doesn't mean it's not there for a given document, but it may mean that a
re-transmission of the same document would be allowed to use a different
order without changing the information.

This property applies to pretty much all structured data formats and not
just XML, by the way, also to CSV and other tabular formats.


The point I am trying to make to OP is that the following two XML
fragments define the same data:


   string 1
   string 2
   string 3


and:


   string 3
   string 2
   string 1


Each  is just a member of the collection things, the xml does not
contain sufficient information to state that  is an ordered
collection containing a specific sequence of .


Without reference to a schema that explicitly defines the children of  
to be unordered, this is not true. The XML Information Set defines the children 
of all elements to be an ordered set (in contrast to attributes, which are 
unordered). A particular XML schema may choose to consider the order of children 
of a particular element to be irrelevant, but XML itself keeps them ordered.


http://www.w3.org/TR/xml-infoset/#infoitem.element

If it didn't, then XHTML would have a hell of a time with ordered constructs 
like this:


  
First item
Second item
Third item
  

--
Robert Kern

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

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


Re: Pure Python Data Mangling or Encrypting

2015-06-27 Thread Robert Kern

On 2015-06-27 08:58, Robert Kern wrote:

On 2015-06-27 04:38, Steven D'Aprano wrote:


Maybe you use Python's standard library and the Mersenne Twister. The period
of that is huge, possibly bigger than 256! (or not, I forget, and I'm too
lazy to look it up). So you think that's safe. But it's not: Mersenne
Twister is not a cryptographically secure pseudorandom number generator. If
I can get some small number of values from the Twister (by memory,
something of the order of 100 such values) then I can predict the rest for
ever.


634.


Bah! 624.

--
Robert Kern

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

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


Re: Pure Python Data Mangling or Encrypting

2015-06-27 Thread Robert Kern

On 2015-06-27 04:38, Steven D'Aprano wrote:


Maybe you use Python's standard library and the Mersenne Twister. The period
of that is huge, possibly bigger than 256! (or not, I forget, and I'm too
lazy to look it up). So you think that's safe. But it's not: Mersenne
Twister is not a cryptographically secure pseudorandom number generator. If
I can get some small number of values from the Twister (by memory,
something of the order of 100 such values) then I can predict the rest for
ever.


634.

--
Robert Kern

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

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


Re: enhancement request: make py3 read/write py2 pickle format

2015-06-10 Thread Robert Kern

On 2015-06-10 13:08, Marko Rauhamaa wrote:

Robert Kern :


By the very nature of the stated problem: serializing all language
objects. Being able to construct any object, including instances of
arbitrary classes, means that arbitrary code can be executed. All I
have to do is make a pickle file for an object that claims that its
constructor is shutil.rmtree().


You can't serialize/migrate arbitrary objects. Consider open TCP
connections, open files and other objects that extend outside the Python
VM.


Yes, yes, but that's really beside the point. Yes, there are some objects for 
which it doesn't even make sense to serialize. But my point is that even in this 
slightly smaller set of objects that *can* be serialized (and pickle currently 
does serialize), being able to serialize all of them entails arbitrary code 
execution to deserialize them. To allow people to write their own types that can 
be serialized, you have to let them specify arbitrary callables that will do the 
reconstruction. If you whitelist the possible reconstruction callables, you have 
greatly restricted the types that can participate in the serialization system.



Also objects hold references to each other, leading to a huge
reference mesh.

For example:

a.buddy = b
b.buddy = a
with open("a", "wb") as f: f.write(serialize(a))
with open("b", "wb") as f: f.write(serialize(b))

with open("a", "rb") as f: aa = deserialize(f.read())
with open("b", "rb") as f: bb = deserialize(f.read())
assert aa.buddy is bb


Yeah, no one expects that to work. For example, if I deserialize the same string 
twice, you can't expect to get identical returned objects (as in, 
"deserialize(pickle) is deserialize(pickle)"). However, pickle does correctly 
handle fairly arbitrary reference graphs within the context of a single 
serialization, which is the most that can be asked of a serialization system. 
That isn't really a concern here.


>>> class A(object):
... pass
...
>>> a = A()
>>> b = A()
>>> a.buddy = b
>>> b.buddy = a
>>> data = [a, b]
>>> data[0].buddy is data[1]
True
>>> data[1].buddy is data[0]
True
>>> import cPickle
>>> unpickled = cPickle.loads(cPickle.dumps(data))
>>> unpickled[0].buddy is unpickled[1]
True
>>> unpickled[1].buddy is unpickled[0]
True

--
Robert Kern

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

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


Re: enhancement request: make py3 read/write py2 pickle format

2015-06-10 Thread Robert Kern

On 2015-06-10 12:04, Neal Becker wrote:

Chris Warrick wrote:


On Tue, Jun 9, 2015 at 8:08 PM, Neal Becker  wrote:

One of the most annoying problems with py2/3 interoperability is that the
pickle formats are not compatible.  There must be many who, like myself,
often use pickle format for data storage.

It certainly would be a big help if py3 could read/write py2 pickle
format. You know, backward compatibility?


Don’t use pickle. It’s unsafe — it executes arbitrary code, which
means someone can give you a pickle file that will delete all your
files or eat your cat.

Instead, use a safe format that has no ability to execute code, like
JSON. It will also work with other programming languages and
environments if you ever need to talk to anyone else.

But, FYI: there is backwards compatibility if you ask for it, in the
form of protocol versions. That’s all you should know — again, don’t
use pickle.


I believe a good native serialization system is essential for any modern
programming language.  If pickle isn't it, we need something else that can
serialize all language objects.  Or, are you saying, it's impossible to do
this safely?


By the very nature of the stated problem: serializing all language objects. 
Being able to construct any object, including instances of arbitrary classes, 
means that arbitrary code can be executed. All I have to do is make a pickle 
file for an object that claims that its constructor is shutil.rmtree().


This is fine in some use cases (e.g. wire format for otherwise-secured 
communication between two endpoints under your complete control), but it is 
worrying in others, like your use case of data storage (and presumably sharing).


Python 2/3 is also the least of your compatibility worries there. Refactor a 
class to a different module, or did one of your third-party dependencies do 
this? Poof! Your pickle files no longer work.


--
Robert Kern

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

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


Re: Tit for tat

2015-04-28 Thread Robert Kern

On 2015-04-28 07:58, Steven D'Aprano wrote:

On Tuesday 28 April 2015 13:18, Seymore4Head wrote:


In the past, I have had some measure of success with the Toot for Tail
strategy.


I don't believe that is a standard name for an Iterated Prisoner's Dilemma
strategy. I've googled for it, using two different search engines, and
neither come up with any references for "Toot For Tail" strategies.


I do believe he is trying to make a crude joke.

--
Robert Kern

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

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


Re: [SciPy-User] Is there existing code to log-with-bells-on for runtime algorithm diagnostics?

2015-04-21 Thread Robert Kern
On Tue, Apr 21, 2015 at 8:02 PM, Rob Clewley  wrote:
>
> Hi,
>
> I'm in need of a system for logging the step-wise results and
> diagnostic metadata about a python function implementation of an
> algorithm that I'm developing. The specific algorithm is not of great
> consequence except that it's for scientific computing and may produce
> large (e.g., '00s or maybe '000s, but not "big data" scale) amounts of
> intermediate numerical data that can be complex to understand when
> debugging its progress.
>
> In fact, I'm trying to build a general purpose tool for exploring the
> inner workings of numerical algorithms for teaching and learning
> purposes, e.g. for graduate student training or for figuring out
> parameter choices in difficult applications.

The term you want to search for is "structured logging".

http://www.structlog.org/en/stable/
http://eliot.readthedocs.org/en/stable/
https://twiggy.readthedocs.org/en/latest/logging.html#structured-logging
http://netlogger.lbl.gov/

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


Re: Code critique please

2015-04-08 Thread Robert Kern

On 2015-04-08 01:54, Mark Lawrence wrote:

On 07/04/2015 23:43, kai.pet...@gmail.com wrote:

I just wrote this bit (coming from Pascal) and am wondering how seasoned
Python programmers would have done the same? Anything terribly non-python?

As always, thanks for all input.

import os, sys
from PIL import Image, ImageFont, ImageDraw



As you've had plenty of answers I'll just say that PIL is pretty old now.  Are
you aware of the fork called Pillow? https://pillow.readthedocs.org/


Pillow uses the name "PIL" for its package name too, in the interest of being 
drop-in compatible.


https://pillow.readthedocs.org/porting-pil-to-pillow.html

--
Robert Kern

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

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


Re: PiCxx

2015-03-29 Thread Robert Kern

On 2015-03-25 15:45, π wrote:

Hello Python people,

I've made a C++ wrapper for Python.
I've called it PiCxx and put it up here: https://github.com/p-i-/PiCxx


Please consider using a recognized open source license. Your project looks 
interesting, but I won't touch it with the current license.


http://opensource.org/licenses

--
Robert Kern

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

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


Re: Use à Python 2 module with Python 3

2015-03-11 Thread Robert Kern

On 2015-03-11 18:46, Vincent Vande Vyvre wrote:

Le 11/03/2015 18:06, Ian Kelly a écrit :

On Wed, Mar 11, 2015 at 4:54 AM, Steven D'Aprano
 wrote:

Michael Parchet wrote:


Hello,

The pyside project is ded.

What makes you think that Pyside is dead? It seems to be active to me. The
latest update was just 29 days ago:

https://github.com/PySide

4 days ago, even. Seems that most of the development is still on gitorious:

https://qt.gitorious.org/pyside


In fact, the devel team of PySide has announced the official abandon of the
project at the begin of this year.

The announce was made in this page:

http://qt-project.org/wiki/PySide

... but, now, I see this page was reversed to his old content.


Indeed, because that comment was not placed there by the PySide dev team.


So, have a look at the bug tracker and you'll see some comment as this one:

"PySide is abandoned by the initial development team due to a lack of funding,
so right now the destiny of the bugs such as this is in hands of those who
understand how to debug them."

(Quoted from https://bugreports.qt.io/browse/PYSIDE-164)


Anatoly was wrong.

--
Robert Kern

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

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


Re: Use à Python 2 module with Python 3

2015-03-11 Thread Robert Kern

On 2015-03-11 19:31, Michael Torrie wrote:

On 03/11/2015 01:29 PM, Chris Warrick wrote:

On Wed, Mar 11, 2015 at 8:20 PM, Michael Torrie  wrote:

My biggest complaint with PySide is that for historical reasons (looking
at you, PyQt), it does not use pep8 naming conventions, which makes for
some really ugly function and method names.


This isn’t PyQt’s fault.  Both are more-or-less straight bindings to
the underlying C++ Qt library, which does not follow Python’s naming
conventions.


Yes, but they could have simply converted the native Qt names to pep8.
Particularly when the bindings are automatically generated.


It is *extremely* helpful to have the names be the same in both C++ and PySide 
as the documentation uses the C++ names, as well as every Googleable 
conversation about Qt on the internet. It would be unnecessarily crippling to 
change the names to satisfy a purely optional style guide.


--
Robert Kern

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

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


Re: Question about python package numpy

2015-03-02 Thread Robert Kern

On 2015-03-01 20:32, fl wrote:

Hi,

It is difficult to install numpy package for my PC Windows 7, 64-bit OS. In
the end, I install Enthought Canopy, which is recommended on line because it
does install numpy automatically. Now, I can test it with

import numpy

it succeeds. On http://wiki.scipy.org/Cookbook, it shows some interesting
code example snippet, such as Cookbook / ParticleFilter, Markov chain etc.

I don't know how I can access these code examples, because I don't know where
Enthought Canopy installs these package.

Could you help me on using numpy examples?


None of these examples come prepackaged in any distribution I am aware of. You 
are intended to copy-and-paste them from the wiki if you want to use them.


--
Robert Kern

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

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


Re: Bug in timsort!?

2015-02-25 Thread Robert Kern

On 2015-02-24 22:45, Grant Edwards wrote:

On 2015-02-24, Roy Smith  wrote:


http://envisage-project.eu/proving-android-java-and-python-sorting-algorithm-is-broken-and-how-to-fix-it/


I don't get it.

 3.2 Corrected Python merge_collapse function

 merge_collapse(MergeState *ms)
 {
 struct s_slice *p = ms->pending;

 assert(ms);
 while (ms->n > 1) {
 Py_ssize_t n = ms->n - 2;
 if ( n > 0   && p[n-1].len <= p[n].len + p[n+1].len
 || (n-1 > 0 &&  p[n-2].len <= p[n].len + p[n-1].len)) {
 if (p[n-1].len < p[n+1].len)
 --n;
 if (merge_at(ms, n) < 0)
 return -1;
 }
 else if (p[n].len <= p[n+1].len) {
  if (merge_at(ms, n) < 0)
 return -1;
 }
 else
 break;
 }
 return 0;
 }

Or does "Python function" mean something else in this context?


"Corrected merge_collapse function [from the Python implementation of TimSort]" 
as opposed to the Java implementation which was also discussed.


--
Robert Kern

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

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


Re: line_profiler: what am I doing wrong?

2015-02-16 Thread Robert Kern

On 2015-02-13 13:35, Neal Becker wrote:

Robert Kern wrote:


@profile
def run():
pass

run()


No, this doesn't work either.  Same failure

kernprof -l test_prof.py
Wrote profile results to test_prof.py.lprof
Traceback (most recent call last):
   File "/home/nbecker/.local/bin/kernprof", line 9, in 
 load_entry_point('line-profiler==1.0', 'console_scripts', 'kernprof')()
   File "/home/nbecker/.local/lib/python2.7/site-packages/kernprof.py", line 
221,
in main
 execfile(script_file, ns, ns)
   File "test_prof.py", line 1, in 
 @profile
NameError: name 'profile' is not defined


Ah, do you have the package `future` installed?

https://github.com/rkern/line_profiler/issues/12

--
Robert Kern

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

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


Re: line_profiler: what am I doing wrong?

2015-02-11 Thread Robert Kern

On 2015-02-11 00:06, Neal Becker wrote:

I inserted
@profile
def run(...)

into a module-level global function called 'run'.  Something is very wrong here.
1. profile results were written before anything even ran
2. profile is not defined?

  kernprof -l ./test_unframed.py --lots --of --args ...

Wrote profile results to test_unframed.py.lprof
Traceback (most recent call last):
   File "/home/nbecker/.local/bin/kernprof", line 9, in 
 load_entry_point('line-profiler==1.0', 'console_scripts', 'kernprof')()
   File "/home/nbecker/.local/lib/python2.7/site-packages/kernprof.py", line 
221,
in main
 execfile(script_file, ns, ns)
   File "./test_unframed.py", line 721, in 
 @profile
NameError: name 'profile' is not defined


Can you pare this down to a minimal complete example that fails in this way? 
Does a trivial module work? I.e.


"""
@profile
def run():
pass

run()
"""

--
Robert Kern

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

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


Re: line_profiler: what am I doing wrong?

2015-02-11 Thread Robert Kern

On 2015-02-11 01:17, Steven D'Aprano wrote:

Neal Becker wrote:



To quote from https://pypi.python.org/pypi/line_profiler/

$ kernprof -l script_to_profile.py
kernprof will create an instance of LineProfiler and insert it into the
__builtins__ namespace with the name profile.


Ewww What a Ruby-esque interface, that makes me sad :-(


 This is not a production library. It's a development tool designed to 
help developers shorten the cycle time for investigating these kinds of issues. 
Well, *a* developer; i.e. me. If it helps anyone else, yahtzee!



And what if you
have your own profile global name?


Then you can pull it out from __builtin__ with a different name and use that 
other name.



And *wrong* too. `__builtins__` is a private CPython implementation detail.
The way to monkey-patch the built-ins in Python 2 is to inject the object
into `__builtin__` (no s), or `builtins` in Python 3.


And indeed that is how it is implemented. Referring to that namespace as the 
"`__builtins__` namespace" isn't *wrong*. It may mislead you into thinking I've 
implemented it one particular way, if you are desperate to find a nit to pick.



Seeing as
line_profiler is written in C, perhaps the author (Robert Kern) doesn't
care about supporting Jython or IronPython,  but there may be Python
implementations (PyPy perhaps?) which can run C code but don't have
__builtins__.


Indeed, I do not care about any of them. PyPy does not implement CPython's 
tracing API:


https://bitbucket.org/pypy/pypy/src/2b2163d65ee437646194a1ceb2a3153db24c5f7e/pypy/module/cpyext/stubs.py?at=default#cl-1286

--
Robert Kern

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

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


Re: [OT] Question about Git branches

2014-09-16 Thread Robert Kern

On 2014-09-16 17:25, Chris Angelico wrote:

On Wed, Sep 17, 2014 at 2:08 AM, Robert Kern  wrote:

Yes, but this is due to different design decisions of git and Mercurial. git
prioritized the multiple branches in a single clone use case; Mercurial
prioritized re-cloning. It's natural to do this kind of branching in git,
and more natural to re-clone in Mercurial.


Ah, I wasn't aware of that philosophical difference. Does hg use
hardlinks or something to minimize disk usage when you clone, or does
it actually copy everything? (Or worse, does it make the new directory
actually depend on the old one?)


I haven't kept up with the internals recently, but at least at one point, 
hardlinks were the order of the day, yes.


--
Robert Kern

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

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


Re: [OT] Question about Git branches

2014-09-16 Thread Robert Kern

On 2014-09-16 13:14, Steven D'Aprano wrote:

Chris Angelico wrote:


On Tue, Sep 16, 2014 at 6:21 PM, Marko Rauhamaa  wrote:

"Frank Millman" :


You are encouraged to make liberal use of 'branches',


Personally, I only use forks, IOW, "git clone". I encourage that
practice. Then, there is little need for "git checkout". Instead, I just
cd to a different directory.

Branches and clones are highly analogous processwise; I would go so far
as to say that they are redundant.


But rather than listening to, shall we say, *strange* advice like
this, Frank, you'll do well to pick up a reliable git tutorial, which
should explain branches, commits, the working tree, etc, etc, etc.


Isn't this "strange advice" standard operating procedure in Mercurial? I'm
not an expert on either hg or git, but if I've understood hg correctly, the
way to begin an experimental branch is to use hg clone.


Yes, but this is due to different design decisions of git and Mercurial. git 
prioritized the multiple branches in a single clone use case; Mercurial 
prioritized re-cloning. It's natural to do this kind of branching in git, and 
more natural to re-clone in Mercurial.


--
Robert Kern

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

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


Re: Python vs C++

2014-08-24 Thread Robert Kern

On 2014-08-22 01:26, Chris Angelico wrote:

On Fri, Aug 22, 2014 at 4:05 AM, Joseph Martinot-Lagarde
 wrote:

For information, Cython works with C++ now:
http://docs.cython.org/src/userguide/wrapping_CPlusPlus.html.


Now isn't that cool!

Every time Cython gets discussed, I get a renewed desire to learn it.
Trouble is, I don't have any project that calls for it - there's
nothing I'm desperately wanting to do that involves both Python and
C/C++. Anyone got any suggestions? :)


Class-based, Python 3-compatible bindings for libtcod?

  http://doryen.eptalys.net/libtcod/

--
Robert Kern

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

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


Re: 'is not' or '!='

2014-08-20 Thread Robert Kern

On 2014-08-20 12:26, Tim Chase wrote:

On 2014-08-20 21:17, Chris Angelico wrote:

That's true, but how easy is it to annotate a file with each line's
author (or, at least, to figure out who wrote some particular line
of code)? It's easy enough with 'git blame' or 'hg blame', and it
wouldn't surprise me if bzr had a similar feature; but that's all
the current generation of version control systems. I don't think
cvs or svn offered that kind of feature.


Just for the record, at least SVN has "svn blame" which will annotate
with the committer's name/id.  I use it all the time at $DAYJOB.  I've
managed to avoid CVS, so I can't speak to that.


cvs annotate

http://compbio.soe.ucsc.edu/cvsdoc/cvs-manual/cvs_74.html

--
Robert Kern

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

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


Re: how to get the ordinal number in list

2014-08-11 Thread Robert Kern

On 2014-08-11 03:04, Steven D'Aprano wrote:

Rustom Mody wrote:


Its when we have variables that are assigned in multiple places that
we start seeing mathematical abominations like
x = x+1


That's not a mathematical abomination. It's a perfectly reasonable
mathematical equation, one with no solutions since the line f(x) = x and
the line f(x) = x+1 are parallel.

But what does this have to do with programming? Programming *is not*
mathematics, and x = x+1 has a different meaning in programming than in
mathematics. Perhaps it would help if we wrote it using mathematical
notation? Using [x] for subscripts:

x[n+1] = x[n] + 1

we have a perfectly good mathematical recursive definition. All it needs is
an initial value x[0] and we're good to go.


Or a different operator for assignment (to distinguish it more clearly from 
equality, which it isn't).


  x <- x + 1
  x := x + 1

--
Robert Kern

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

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


Re: Bug with help (was Re: Getting a list of all modules)

2014-08-02 Thread Robert Kern

On 2014-08-02 09:33, Heinz Schmitz wrote:

Akira Li wrote:


Look at how `help('modules')` is implemented. Though it crashes on my
system.



Have you reported this at bugs.python.org or is there already an issue
for the problem that you see?



It is this issue for python2.7:
https://bugs.launchpad.net/ubuntu/+source/python2.7/+bug/896836

python3 doesn't crash with currently installed packages.


Python 2.7 on Windows XP Sp2 doesn't crash with this. So it seems to
be a python<->OS-problem.


Well, it's just that `help('modules')` imports every module in the calling 
process (at least in Python 2.7; I haven't checked Python 3). Some extension 
modules conflict with each other and cause a crash when both are imported 
together. It's possible that you just don't have such modules installed. While 
the proximate cause of the crash is in the 3rd party modules, Python could (and 
maybe Python 3 does) import each module in a separate subprocess and collect the 
information that way.


--
Robert Kern

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

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


Re: Getting a list of all modules

2014-08-01 Thread Robert Kern

On 2014-07-31 11:41, Steven D'Aprano wrote:

On Wed, 30 Jul 2014 21:22:18 +0800, Leo Jay wrote:


On Wed, Jul 30, 2014 at 3:43 PM, Steven D'Aprano 
wrote:

I'm looking for a programmatic way to get a list of all Python modules
and packages. Not just those already imported, but all those which
*could* be imported.



If you don't actually import it, how can you know it could be imported?
Not all .so files are valid python modules. Not all .py files could be
imported by all python interpreters.


You're right, of course, but I'm not concerned by whether or not the
module is error-free and can be imported successfully.

I'm working on tab completion for module names. I have some alpha-quality
code working, so if I hit TAB after typing "import ma" I get this:


py> import ma
macpath  macurl2path  mailbox  mailcap  mangle
markupbase   math

For what it's worth, importing "mangle" fails with a SyntaxError. But
that's okay, I don't expect tab completion to only show *valid*
modules :-)

Over the next few days I'll make an official announcement, but if anyone
wants a sneak-peek, check out:

http://code.google.com/p/tabhistory/source/browse/tabhistory.py


where I have indenting, code completion, filename completion, and module
completion all working to some degree or another.


Take a look at what has already been implemented in IPython:

https://github.com/ipython/ipython/blob/master/IPython/core/completerlib.py#L208

--
Robert Kern

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

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


Re: Getting a list of all modules

2014-07-30 Thread Robert Kern

On 2014-07-30 09:46, Peter Otten wrote:

Steven D'Aprano wrote:


I'm looking for a programmatic way to get a list of all Python modules
and packages. Not just those already imported, but all those which
*could* be imported.

I have a quick-and-dirty function which half does the job:


def get_modules():
 extensions = ('.py', '.pyc', '.pyo', '.so', '.dll')
 matches = set()
 for location in sys.path:
 if location == '': location = '.'
 if os.path.isdir(location):
 for name in os.listdir(location):
 base, ext = os.path.splitext(name)
 if ext in extensions:
 matches.add(base)
 return sorted(matches)



but I know it's wrong (it doesn't handle packages correctly, or zip
files, doesn't follow .pth files, has a very naive understanding of cross-
platform issues, fails to include built-in modules that don't live in the
file system, and probably more).

Is this problem already solved? Can anyone make any suggestions?


$ python3 -m pydoc -b

shows a page with modules that I think is more complete than what you have.
A quick glance at the implementation suggests that the hard work is done by

pkgutil.iter_modules()


There are two niggles to this answer: it omits builtin modules, but those are 
easily discovered through sys.builtin_module_names. It can also include spurious 
script .py files that cannot be imported because their names are not Python 
identifiers: e.g. check-newconfigs.py. Those are easy to filter out, fortunately.


--
Robert Kern

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

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


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

2014-07-09 Thread Robert Kern

On 2014-07-09 08:00, Steven D'Aprano wrote:

At the moment, Python has two (in)equality operators, == and != which
call __eq__ and __ne__ methods. Some problems with those:


* Many people expect == to always be reflexive (that is, x == x for
   every x) but classes which customise __eq__ may not be.

* The == operator requires __eq__ to return True or False
   (or NotImplemented) and raises TypeError if it doesn't, which
   makes it impossible to use == with (say) three-valued or fuzzy
   logic.


No, it doesn't. It can return anything.

[~]
|1> x = np.arange(5)

[~]
|2> x == 3
array([False, False, False,  True, False], dtype=bool)

You can blame Numeric/numpy for that feature getting in. :-)

Now certainly, many uses of __eq__, like containment comparisons, do assume that 
the result is a bool(able).


--
Robert Kern

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

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


Re: Module name does not match file name

2014-07-07 Thread Robert Kern

On 2014-07-07 12:56, Steven D'Aprano wrote:

On Mon, 07 Jul 2014 12:15:51 +0100, Robert Kern wrote:


On 2014-07-07 09:57, Steven D'Aprano wrote:

What I don't understand is how "import pg" gets turned into "run
pgmodule.so"?


This has been standard Python behavior for extension modules since
forever. It's a very old practice and not recommended for new code,
though.


Hmmm. Well, that is very special. Is this documented anywhere?


Not that I can find. Maybe the PEP that removed it for Python 3 might document 
it implicitly.



I know very little about extension modules. If I just rename the source
file from pgmodule.c to pg.c, recompile to pg.so, and use that in place
of pgmodule.so, is anything likely to break?


I don't think so, but why would you bother (assuming you aren't the maintainer 
of pgmodule.so)?


--
Robert Kern

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

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


Re: Module name does not match file name

2014-07-07 Thread Robert Kern

On 2014-07-07 09:57, Steven D'Aprano wrote:

Ah, I think I have a partial answer... but not a complete answer.


On Mon, 07 Jul 2014 07:57:21 +, Steven D'Aprano wrote:


Can anyone explain how "import pg" can end up coming from pgmodule.so?


Sure enough:


import pg
pg.__file__

'/usr/local/lib/python2.6/dist-packages/pgmodule.so'




I've looked inside the pgmodule.c source code, and it includes this
snippet:


extern void
initpg(void)
{
 char *p;
 int i;

 Py_InitModule("pg", pg_methods);


which suggests that the pgmodule.so file creates a module called "pg".
What I don't understand is how "import pg" gets turned into "run
pgmodule.so"?


This has been standard Python behavior for extension modules since forever. It's 
a very old practice and not recommended for new code, though.


[~]
|1> import imp

[~]
|2> imp.get_suffixes()
[('.so', 'rb', 3), ('module.so', 'rb', 3), ('.py', 'U', 1), ('.pyc', 'rb', 2)]

--
Robert Kern

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

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


Re: PEP8 and 4 spaces

2014-07-05 Thread Robert Kern

On 2014-07-05 19:57, Ian Kelly wrote:

On Fri, Jul 4, 2014 at 8:00 PM, Rick Johnson
 wrote:

Strangly, I rather fancy the idea of using tabs in code,,,
which allow each viewer to view the code in his or her level
of indention,,, however, i cannot justify using a tab as a
replacement for a space. Tabs should be used for "tabular"
data (aka: speadsheets), and since code is NOT tabular data,
we would be wise to use the space char for indention.


I find it a little curious that nobody ever seems to advocate the use
of vertical tabs instead of repeated newlines. It should offer the
same benefit as horizontal tabs, namely that one could then
independently configure one's editor to separate adjacent code
elements with the desired number of blank lines. But I suppose that
nobody finds that useful enough to bother with in the vertical case.


I do see the occasional person using form feeds to separate sections of code.

--
Robert Kern

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

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


Re: Single underscore in interactive mode

2014-06-25 Thread Robert Kern

On 2014-06-25 16:20, candide wrote:

According to the official documentation (The Python Language Reference, Release 
3.2):


---
The special identifier _ is used in the interactive interpreter to
store the result of the last evaluation;
---


This description is not very specific. Which evaluation is it about ? Consider 
the following interactive mode session:


z = 42 + 1
_

Traceback (most recent call last):
   File "", line 1, in 
 _
NameError: name '_' is not defined




As explained by the docs, an assignment statement _evaluates_ the expression on the right 
hand side. So we can deduce that at the very beginning of the 2nd prompt, "the 
result of the last evaluation" is 43. Nevertheless, calling _ raises a NameError 
exception!



In fact it seems that underscore returns the value of the last expression 
statement which is different from None :



4*10+2

42

_

42

"hello"

'hello'

_

'hello'

print(42)

42

_

'hello'

None
_

'hello'





Can somebody provide a correct specification of the _ identifier in interactive 
mode ?


See the documentation on `sys.displayhook()`, which is the function that makes 
the assignment:


https://docs.python.org/3/library/sys.html#sys.displayhook

--
Robert Kern

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

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


Re: Python's re module and genealogy problem

2014-06-11 Thread Robert Kern

On 2014-06-11 13:23, BrJohan wrote:

For some genealogical purposes I consider using Python's re module.

Rather many names can be spelled in a number of similar ways, and in order to
match names even if they are spelled differently, I will build regular
expressions, each of which is supposed to match  a number of similar names.

I guess that there will be a few hundred such regular expressions covering most
popular names.

Now, my problem: Is there a way to decide whether any two - or more - of those
regular expressions will match the same string?

Or, stated a little differently:

Can it, for a pair of regular expressions be decided whether at least one string
matching both of those regular expressions, can be constructed?

If it is possible to make such a decision, then how? Anyone aware of an
algorithm for this?


And if that isn't the best straight line for the old saying, I don't know what 
is.

  http://en.wikiquote.org/wiki/Jamie_Zawinski

Anyways, to your new problem, yes it's possible. Search for "regular expression 
intersection" for possible approaches. You will probably have to translate the 
regular expression to a different formalism or at least a different library to 
implement this.


Consider just listing out the different possibilities. All of your regexes 
should be "well-behaved" given the constraints of the domain (tightly bounded, 
at least). There are tools that help generate matching strings from a Python 
regex. This will help you QA your regexes, too, to be sure that they match what 
you expect them to and not match non-names.


  https://github.com/asciimoo/exrex

--
Robert Kern

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

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


Re: Numpy Array of Sets

2014-05-24 Thread Robert Kern

On 2014-05-24 23:05, Luis José Novoa wrote:

Hi All,

Hope you're doing great. One quick question. I am defining an array of sets 
using numpy as:

a=array([set([])]*3)

Now, if I want to add an element to the set in, lets say, a[0], and I use the 
.add(4) operation, which results in:

array([set([4]), set([4]), set([4])], dtype=object)

which I do not want. If I use the union operator

a[0] = a[0] | set([4])

then I obtain what I want:

array([set([4]), set([]), set([])], dtype=object)

Can anyone explain whay this happens?


Same reason why you shouldn't make a list of lists like so: [[]]*3

https://docs.python.org/2/faq/programming.html#how-do-i-create-a-multidimensional-list

--
Robert Kern

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

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


Re: Parallel python in the cloud

2014-05-24 Thread Robert Kern

On 2014-05-24 07:46, Charles Gagnon wrote:

We were happily using PiCloud for several long calculations and we very happy 
with with it. With their realtime cores, we could take really large 
calculations set and run through fairly quickly.

Now that PiCloud is going away, we ran a few tests on Mutlyvac but so far, we 
are struggling to accomplish the same thing we had on PiCloud.

I have several "pieces" of my puzzle but can't seem to be able to put it 
together. I've seen and tried StarCluster and also various parallel python options but 
all options seem challenging to put together.

The goal is to mimic PiCloud, ie. loop through a function:

def some_NP_func(x, y):
...
return z

some_cloud.call(some_NP_func, a1, a2)

Which computes the function on the cloud. We use this often in for loops with 
arrays of arguments. The other scenario is:

some_cloud.map(some_NP_intense_func, [...], [...])

Which iterates through and returns results. We need to run a lot of this in 
batch from a scheduler so I always try to avoid interactive environment (how 
does iPython parallel work in batch?).


IPython parallel works just fine "in batch". As far as your client code (i.e. 
what you wrote above) is concerned, it's just another library. E.g.


https://github.com/ipython/ipython/blob/master/examples/Parallel%20Computing/nwmerge.py
https://github.com/ipython/ipython/blob/master/examples/Parallel%20Computing/itermapresult.py

etc.

--
Robert Kern

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

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


Re: Python and Math

2014-05-21 Thread Robert Kern

On 2014-05-21 01:40, Dennis Lee Bieber wrote:

On Sun, 18 May 2014 14:09:43 -0400, "Bill Cunningham"
 declaimed the following:


linear algebra, expanding and factoring equations of all degrees.
Geometry.


Without significant add-in libraries, probably not...

"Expanding and factoring equations" -- to me -- implies /symbolic
algebra systems/.

Python can compute results of equations, but it won't, natively,
reformulate equations.

Linear algebra tends to turn into matrix manipulation, as I recall...
Again, not a native feature.


But all easily available with well-established open source packages. Just 
because it's not in the standard library doesn't mean that Python isn't a 
suitable language for doing this stuff.


--
Robert Kern

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

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


Re: Python and Math

2014-05-21 Thread Robert Kern

On 2014-05-21 01:59, Tony the Tiger wrote:

On Sun, 18 May 2014 14:09:43 -0400, Bill Cunningham wrote:


 linear algebra, expanding and factoring equations of all degrees.
Geometry.


Sounds to me like you really want something like Maple, Mathematica, or
similar. Try http://www.scilab.org/

Can do heaps of stuff, too. For free.


And with Python!

  http://sagemath.org/

--
Robert Kern

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

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


Re: Python and Math

2014-05-18 Thread Robert Kern

On 2014-05-18 16:40, Grant Edwards wrote:

On 2014-05-18, Bill Cunningham  wrote:


 Does Python have good mathematical capabilities?


No.

It has very good numerical computation capabilities, but it does not
really do "math" (at least not what a mathemetician would consider
"math").


Many mathematicians would disagree.

  http://sagemath.org/

--
Robert Kern

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

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


Re: Everything you did not want to know about Unicode in Python 3

2014-05-17 Thread Robert Kern

On 2014-05-17 13:07, Steven D'Aprano wrote:

On Sat, 17 May 2014 09:57:06 +0100, Robert Kern wrote:


On 2014-05-17 02:07, Steven D'Aprano wrote:

On Fri, 16 May 2014 14:46:23 +, Grant Edwards wrote:


At least in the US, there doesn't seem to be such a thing as "placing
a work into the public domain".  The copyright holder can transfer
ownershipt to soembody else, but there is no "public domain" to which
ownership can be trasferred.


That's factually incorrect. In the US, sufficiently old works, or works
of a certain age that were not explicitly registered for copyright, are
in the public domain. Under a wide range of circumstances, works
created by the federal government go immediately into the public
domain.


There is such a thing as the public domain in the US, and there are
works in it, but there isn't really such a thing as "placing a work"
there voluntarily, as Grant says. A work either is or isn't in the
public domain. The author has no choice in the matter.


That's incorrect.

http://cr.yp.to/publicdomain.html


Thanks for the link. While it has not really changed my opinion (as discussed at 
length in my other reply), I did not know that the 9th Circuit had formalized 
the "overt act" test in their civil procedure rules, so there is at least one 
jurisdiction in the US that does currently work like this. None of the others 
do, to my knowledge, and this is the product of judicial common law, not 
statutory law, so it's still pretty shaky.


--
Robert Kern

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

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


Re: Everything you did not want to know about Unicode in Python 3

2014-05-17 Thread Robert Kern

On 2014-05-17 15:15, Steven D'Aprano wrote:

On Sat, 17 May 2014 10:29:00 +0100, Robert Kern wrote:


One can state many things, but that doesn't mean they have legal effect.
The US Code has provisions for how works become copyrighted
automatically, how they leave copyright automatically at the end of
specific time periods, how some works automatically enter the public
domain on their creation (i.e. works of the US federal government), but
has nothing at all for how a private creator can voluntarily place their
work into the public domain when it would otherwise not be. It used to,
but does not any more.


The case for abandonment was stated as "well settled" in 1998 (Micro-Star
v. Formgen Inc). Unless there has been a major legal change in the years
since then, I don't think it is true that authors cannot abandon
copyright.


Good old Micro-Star v. Formgen Inc. A perennial favorite. No, that case did not 
settle this question. There is a statement in the opinion that would suggest 
this, but (and this seems to be a reoccurring theme) it's inclusion in the 
opinion did not create precedent to that effect. The statement that you refer to 
is, as far as my NAL eyes can tell, what the lawyers call "dictum": a statement 
made by a judicial opinion but is unnecessary to decide the case and therefore 
not precedential. FormGen explicitly registered the copyright to the works in 
question, and the case was decided on whether or not the 
Micro-Star-redistributed works counted as derivative works (yes). Now, if the 
case were about an author that affirmatively dedicated his work to the public 
domain and then sued someone who redistributed it, then such a statement would 
have a precedential effect (because then the judge would decide in favor of the 
defendant on the basis of that statement). The quote that you refer to 
references a previous case, which follows similar lines, and also predates the 
"automatic copyright" regime post-Berne Convention, so it's not even clear to me 
that it should have been precedential to Micro-Star.


Even if this case did so decide (which, I will grant it more or less did later 
by codifying such a rule in their jury instructions for such cases), it would 
only have effect in the 9th Circuit of the US and not even in the rest of the 
US, much less worldwide. Why bother when the CC0 gives you the desired effect 
with more assurance to your audience?



For a private individual to say about a work they just created that
"this work is in the Public Domain" is, under US law, merely an
erroneous statement of fact, not a speech act that effects a change in
the legal status of the work. For another example of this distinction,
saying "I am married" when I have not applied for, received, and
solemnified a valid marriage license is just an erroneous statement of
fact and does not make me legally married.


There may be something to what you say, although I think we're now
arguing fine semantic details.


Sure, it's the law. Fine semantic details are important. However, the difference 
between speech acts and statements of fact is a pretty gross semantic 
distinction and not just splitting semantic hairs. The act of making some 
statements (e.g. declaring that a work you own the copyright to is available 
under a given license) actually makes a change in the legal status of something. 
Most statements don't. Which ones do and don't are defined by statute and (in 
common law countries like the US) court decisions. Deciding which is which is 
often hairy, but that's an epistemological problem, not a semantic one. :-)



See:

https://en.wikipedia.org/wiki/Wikipedia:Granting_work_into_the_public_domain

To play Devil's Advocate in favour of your assertion, it may be that
abandoning copyright does not literally put the work in the public
domain, but merely makes it "quack like the public domain". That is to
say, the author still, in some abstract but legally meaningless sense,
has copyright in the work *but* has given unlimited usage rights. (I
don't actually think that is the case, at least not in the US.)

It's this tiny bit of residual uncertainty that leads some authorities to
say that it is "hard" to release a work into the public domain,
particularly in a world-wide context, and that merely stating "this is in
the public domain" is not sufficient to remove all legal doubt over the
status, and that a more overt and explicit release *may* be required.
Hence the CC0 licence which you refer to. The human readable summary says
in part:

  The person who associated a work with this deed has dedicated
  the work to the public domain by waiving all of his or her
  rights to the work worldwide under copyright law, including
  all related and neighboring rights, to the extent allowed by
  law.

  You can copy, modify, distribute a

Re: Everything you did not want to know about Unicode in Python 3

2014-05-17 Thread Robert Kern

On 2014-05-17 05:19, Marko Rauhamaa wrote:

Steven D'Aprano :


On Fri, 16 May 2014 14:46:23 +, Grant Edwards wrote:


At least in the US, there doesn't seem to be such a thing as "placing
a work into the public domain". The copyright holder can transfer
ownershipt to soembody else, but there is no "public domain" to which
ownership can be trasferred.


That's factually incorrect. In the US, sufficiently old works, or works
of a certain age that were not explicitly registered for copyright, are
in the public domain. Under a wide range of circumstances, works created
by the federal government go immediately into the public domain.


Steven, you're not disputing Grant. I am. The sole copyright holder can
simply state: "this work is in the Public Domain," or: "all rights
relinquished," or some such. Ultimately, everything is decided by the
courts, of course.


One can state many things, but that doesn't mean they have legal effect. The US 
Code has provisions for how works become copyrighted automatically, how they 
leave copyright automatically at the end of specific time periods, how some 
works automatically enter the public domain on their creation (i.e. works of the 
US federal government), but has nothing at all for how a private creator can 
voluntarily place their work into the public domain when it would otherwise not 
be. It used to, but does not any more.


For a private individual to say about a work they just created that "this work 
is in the Public Domain" is, under US law, merely an erroneous statement of 
fact, not a speech act that effects a change in the legal status of the work. 
For another example of this distinction, saying "I am married" when I have not 
applied for, received, and solemnified a valid marriage license is just an 
erroneous statement of fact and does not make me legally married.


Relinquishing your rights can have some effect, but not all rights can be 
relinquished, and this is not the same as putting your work into the public 
domain. Among other things, your heirs can sometimes reclaim those rights in 
some circumstances if you are not careful (and if they are valuable enough to 
bother reclaiming).


If you wish to do something like this, I highly recommend (though IANAL and 
TINLA) using the CC0 Waiver from Creative Commons. It has thorough legalese for 
relinquishing all the rights that one can relinquish for the maximum terms that 
one can do so in as many jurisdictions as possible and acts as a license to 
use/distribute/etc. without restriction even if some rights cannot be 
relinquished. Even if US law were to change to provide for dedicating works to 
the public domain, I would probably still use the CC0 anyways to account for the 
high variability in how different jurisdictions around the world treat their own 
public domains.


  http://creativecommons.org/about/cc0
  http://wiki.creativecommons.org/CC0_FAQ

Note how they distinguish the CC0 Waiver from their Public Domain Mark: the 
Public Domain Mark is just a label for things that are known to be free of 
copyright worldwide but does not make a work so. The CC0 *does* have an 
operative effect that is substantially similar to the work being in the public 
domain.


--
Robert Kern

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

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


Re: Everything you did not want to know about Unicode in Python 3

2014-05-17 Thread Robert Kern

On 2014-05-17 02:07, Steven D'Aprano wrote:

On Fri, 16 May 2014 14:46:23 +, Grant Edwards wrote:


At least in the US, there doesn't seem to be such a thing as "placing a
work into the public domain".  The copyright holder can transfer
ownershipt to soembody else, but there is no "public domain" to which
ownership can be trasferred.


That's factually incorrect. In the US, sufficiently old works, or works
of a certain age that were not explicitly registered for copyright, are
in the public domain. Under a wide range of circumstances, works created
by the federal government go immediately into the public domain.


There is such a thing as the public domain in the US, and there are works in it, 
but there isn't really such a thing as "placing a work" there voluntarily, as 
Grant says. A work either is or isn't in the public domain. The author has no 
choice in the matter.


--
Robert Kern

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

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


Re: First attempt at a Python prog (Chess)

2014-04-30 Thread Robert Kern

On 2014-04-30 16:15, Mark H Harris wrote:

On 4/30/14 8:28 AM, Chris Hinsley wrote:

On 2013-02-15 05:05:27 +, Rick Johnson said:


First of all your naming conventions suck. You've used the "interface"
style for every function in this game so i can't /easily/ eyeball
parse the /real/ interface functions from the helper functions -- and
i'm not going to even try, because i don't read ugly code! Try to
learn the Python style guide as soon as you can (In particular pay
attention to naming conventions):



Wow, such vitriol for such a simple bear to cope with !

Maybe Papa bear would like to try some humility !

This was my very first Python prog, and my first chess prog and my
attempt to learn somthing about Generators ! Do youtself a favour and
leave the Python comunity for the good of the language !

Chris



Chris, you might want to try another list:

https://mail.python.org/mailman/listinfo/tutor


The folks on this list are friendly, but tough. They are not generally arrogant,
but many of them are experts (or core python developers) and most of them are
worth listening to. The list mentioned above is for folks who are learning
python and who have basic questions or want basic clarifications.   (they are
gentler too):)


It's also worth noting that Rick Johnson is a well-known troll here and *not* 
representative of this group. He was deliberately insulting Chris, not being 
"tough" but helpful. He is not worth listening to. He is to be killfiled and 
ignored. Chris, I'm sorry you ran into him on your first introduction to this 
community.


--
Robert Kern

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

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


Re: Simple question

2014-04-15 Thread Robert Kern

On 2014-04-15 19:18, Phil Dobbin wrote:

Hi, all.

I've just started to learn Python (I'm reading Mark Lutz's 'Learning
Python' from O'Reilly) & I'm confused as to this part:

'>>> 0.1 + 0.1 + 0.1 - 0.3
5.55111.'

Using 'import Decimal' you can get a much closer result i.e.
'Decimal('0.0')'

What I'm wondering is why the first calculation that arrives at
'5.55111...' is so far out?


The `...` elides the exponent:

  >>> 0.1 + 0.1 + 0.1 - 0.3
  5.551115123125783e-17

If you copied that verbatim directly out of a book, that's just sloppy editing.

--
Robert Kern

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

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


Re: Examples of modern GUI python programms

2014-04-03 Thread Robert Kern

On 2014-04-02 12:52, Sturla Molden wrote:

Wolfgang Keller  wrote:


Judging from the example screenshots on their website, Kivy might be
adequate.


Kivy depends on PyGame which is GPL, and can only be used to build GPL
software.


It is not.

http://www.pygame.org/LGPL

--
Robert Kern

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

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


Re: pip and distutils2-1.0a4

2014-03-03 Thread Robert Kern

On 2014-03-03 21:37, Mark H. Harris wrote:

On Monday, March 3, 2014 3:32:43 PM UTC-6, Robert Kern wrote:


Probably. If you want us to help, you need to show us what you tried, tell us
what results you expected, and copy-paste the output that you got.



Robert Kern


hi Robert,  well, I finally came up with trying to find setup().  Its a part of
distutils.core. So, I tried:

from distutils.core import setup
from distutils import *

Then I tried to run setup() --help-commands and python3 crashed.

What did I do wrong?   running Py3.3.4


You don't run `setup() --help-commands` in the Python interpreter. 
`--help-commands` is a command-line argument to the setup.py script that you 
will write. It is not Python syntax. Please read the documentation.


  http://docs.python.org/3/distutils/index.html

--
Robert Kern

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

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


Re: pip and distutils2-1.0a4

2014-03-03 Thread Robert Kern

On 2014-03-03 21:20, Mark H. Harris wrote:

On Monday, March 3, 2014 2:53:00 PM UTC-6, Mark Lawrence wrote:


distutils has been part of the standard library for years.


hi Mark, that's fabulous, why can't I import it? Because I'm doing
something wrong of course.   :)


Probably. If you want us to help, you need to show us what you tried, tell us 
what results you expected, and copy-paste the output that you got.


--
Robert Kern

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

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


Re: An example of Python in action!

2014-02-25 Thread Robert Kern

On 2014-02-25 18:47, Skip Montanaro wrote:

On Tue, Feb 25, 2014 at 12:07 PM, Timothy W. Grove  wrote:

Here is an example of Python being used with Maya for animation 
http://vimeo.com/72276442


Maya as in MayaVi, the 3D data visualizer built atop VTK?


Maya as in Maya, the 3D animation software from AutoDesk.

--
Robert Kern

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

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


Re: singleton ... again

2014-02-13 Thread Robert Kern

On 2014-02-13 20:03, Chris Angelico wrote:

On Fri, Feb 14, 2014 at 2:24 AM, Roy Smith  wrote:

In article ,
  Chris Angelico  wrote:


On Thu, Feb 13, 2014 at 10:50 PM, Ned Batchelder 
wrote:

I still don't see it.  To convince me that a singleton class makes sense,
you'd have to explain why by virtue of the class's very nature, it never
makes sense for there ever to be more than one of them.


There's a huge difference, btw, between mutable and immutable
singletons. With immutables like None, True/False, integers, strings,
and tuples thereof, returning a preexisting object is just an
optimization. Do it if you want, don't if you don't, nobody's going to
hugely care.


People *depend* on None being a singleton (and are encouraged to do so),
when they use "is" as the test-for-Noneness.


Circular argument, though. If None weren't a singleton, people would
use == to test for Noneness. Since it's been guaranteed to be
optimized to a singleton, the comparison can also be optimized, but
it's still just an optimization, as can be seen with integers. In
CPython, you could test for small integer equality using 'is', but
since that optimization isn't guaranteed, neither is that code
pattern.


We don't use `is None` instead of `== None` for the speed. We use it for 
robustness. We don't want arbitrary __eq__()s to interfere with our sentinel 
tests. If None weren't a singleton that we could use as such a sentinel, we'd 
make one.


--
Robert Kern

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

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


Re: [OT] Usage of U+00B6 PILCROW SIGN

2014-02-06 Thread Robert Kern

On 2014-02-06 17:23, Chris Angelico wrote:

On Thu, Feb 6, 2014 at 11:23 PM, Rustom Mody  wrote:

On Tuesday, February 4, 2014 8:51:25 PM UTC+5:30, jmf wrote:


Useless and really ugly.


Evidently one can do worse:

http://www.pip-installer.org/en/latest/installing.html#requirements


Aside from using a little "chain link" icon rather than a
typographer's symbol, that looks exactly the same. How's it worse?


When I looked at it earlier today, I got a default "cannot find this glyph" box 
instead of the chain icon. I assumed that is what Rustom was referring to. It's 
working for me now.


--
Robert Kern

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

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


Re: pytz question: GMT vs. UTC

2014-01-31 Thread Robert Kern

On 2014-01-31 15:04, Roy Smith wrote:

In article ,
  Mark Lawrence  wrote:


On 31/01/2014 10:17, wxjmfa...@gmail.com wrote:

Is the double line spacing that you still use despite being asked not to
ASCII or unicode?


It's not actually double line spacing.  It's single spaced using UNICODE
DOUBLE COMBINING LINEFEED WITH QUOTE MARKER as line terminators.


>>> len('\n\n>')
3

Clearly, the FSR is broken beyond repair.

--
Robert Kern

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

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


Re: data validation when creating an object

2014-01-16 Thread Robert Kern

On 2014-01-16 04:05, Roy Smith wrote:

Rita  writes:

I know its frowned upon to do work in the __init__() method and only
declarations should be there.



In article ,
  Ben Finney  wrote:


Who says it's frowned on to do work in the initialiser? Where are they
saying it? That seems over-broad, I'd like to read the context of that
advice.


Weird, I was just having this conversation at work earlier this week.

There are some people who advocate that C++ constructors should not do a
lot of work and/or should be incapable of throwing exceptions.  The pros
and cons of that argument are largely C++ specific.  Here's a Stack
Overflow thread which covers most of the usual arguments on both sides:

http://stackoverflow.com/questions/293967/how-much-work-should-be-done-in
-a-constructor

But, Python is not C++.  I suspect the people who argue for __init__()
not doing much are extrapolating a C++ pattern to other languages
without fully understanding the reason why.


I'm one of those people who tends to argue this, but my limited experience with 
C++ does not inform my opinion one way or the other.


I prefer to keep my __init__() methods as dumb as possible to retain the 
flexibility to construct my objects in different ways. Sure, it's convenient to, 
say, pass a filename and have the __init__() open() it for me. But then I'm 
stuck with only being able to create this object with a true, named file on 
disk. I can't create it with a StringIO for testing, or by opening a file and 
seeking to a specific spot where the relevant data starts, etc. I can keep the 
flexibility and convenience by keeping __init__() dumb and relegating various 
smarter and more convenient ways to instantiate the object to classmethods.


Which isn't to say that "smart" or "heavy" __init__()s don't have their place 
for some kinds of objects. I just think that dumb __init__()s should be the default.


That said, what the OP asks about, validating data in the __init__() is 
perfectly fine, IMO. My beef isn't so much with the raw *amount* of stuff done 
but how much you can code yourself into a corner by making limiting assumptions. 
So from one of the "do nothing in your __init__()" crowd, I say "well, I didn't 
really mean *nothing*"



That being said, I've been on a tear lately, trying to get our unit test
suite to run faster.  I came across one slow test which had an
interesting twist.  The class being tested had an __init__() method
which read over 900,000 records from a database and took something like
5-10 seconds to run.  Man, talk about heavy-weight constructors :-)


Indeed.

--
Robert Kern

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

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


Re: data validation when creating an object

2014-01-16 Thread Robert Kern

On 2014-01-16 16:18, Roy Smith wrote:

On Thursday, January 16, 2014 10:46:10 AM UTC-5, Robert Kern wrote:


I prefer to keep my __init__() methods as dumb as possible to retain the
flexibility to construct my objects in different ways. Sure, it's convenient to,
say, pass a filename and have the __init__() open() it for me. But then I'm
stuck with only being able to create this object with a true, named file on
disk. I can't create it with a StringIO for testing, or by opening a file and
seeking to a specific spot where the relevant data starts, etc. I can keep the
flexibility and convenience by keeping __init__() dumb and relegating various
smarter and more convenient ways to instantiate the object to classmethods.


There's two distinct things being discussed here.

The idea of passing a file-like object vs. a filename gives you flexibility, 
that's for sure.  But, that's orthogonal to how much work should be done in the 
constructor.  Consider this class:


Where the two get conflated is that both lead to advice that looks the same (or 
at least can get interpreted the same by newbies who are trying to learn and 
don't have the experience to pick out the subtleties): "do nothing in __init__". 
That's why I am trying to clarify where this advice might be coming from and why 
at least one version of it may be valid.



class DataSlurper:
 def __init__(self):
 self.slurpee = None

 def attach_slurpee(self, slurpee):
 self.slurpee = slurpee

 def slurp(self):
 for line in self.slurpee:
 # whatever

This exhibits the nice behavior you describe; you can pass it any iterable, not just a 
file, so you have a lot more flexibility.  But, it's also exhibiting what many people 
call the "two-phase constructor" anti-pattern.  When you construct an instance 
of this class, it's not usable until you call attach_slurpee(), so why not just do that 
in the constructor?


That's where my recommendation of classmethods come in. The result of __init__() 
should always be usable. It's just that its arguments may not be as convenient 
as you like because you pass in objects that are closer to the internal 
representation than you normally want to deal with (e.g. file objects instead of 
filenames). You make additional constructors (initializers, whatever) as 
classmethods to restore convenience.



class DataSlurper:
  def __init__(self, slurpee):
self.slurpee = slurpee

  @classmethod
  def fromfile(cls, filename):
slurpee = open(filename)
return cls(slurpee)

  @classmethod
  def fromurl(cls, url):
slurpee = urllib.urlopen(url)
return cls(slurpee)

--
Robert Kern

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

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


Re: Debugging on the Mac question.

2014-01-03 Thread Robert Kern

On 2014-01-03 04:17, Sean Murphy wrote:

Team,


I am a Vision Impaired programmer on the Mac and Window platforms. I have 
started to learn Python. The biggest road block I have is the ability of 
debugging my simple scripts. The IDLE program does not work with the screen 
readers I use on the Mac or Windows. A screen reader is a program that grabs 
the text on the screen and converts it into speech output, at least this is the 
5 feet explanation.  I cannot see the screen at all.

I have looked at eclipse and it doesn't work with Voice-Over (the screen reader 
on the Mac). I have java issues on my windows machine preventing me running 
this app.

If I use $python -d script.py the debugger doesn't seem to trigger on the mac.

So how I can perform a debug on a script so I can step through it, set up break 
points, watch variables, etc.

It is really annoying me, since under Perl I just added the -d switch and had a 
full debugger that worked at the console level.


Python also has a console debugger. -d does not invoke it; -d is for something 
else.

  $ python -m pdb myscript.py

http://docs.python.org/3.3/library/pdb

--
Robert Kern

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

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


Re: how to handle captcha through machanize module or any module

2013-12-18 Thread Robert Kern

On 2013-12-18 12:56, Jai wrote:

please do replay how to handle captcha through machanize module


You've asked the same question twice now. You have received the only answer that 
you are going to get here: we won't help you do this. We may help you learn to 
do other stuff with Python, but not this. Please stop asking this question.


--
Robert Kern

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

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


Re: GUI:-please answer want to learn GUI programming in python , how should i proceed.

2013-12-17 Thread Robert Kern

On 2013-12-17 11:13, Steven D'Aprano wrote:

On Tue, 17 Dec 2013 09:39:06 +, Mark Lawrence wrote:


Personally I am convinced that wxPython can't handle unicode for the
simple reason that it doesn't yet support Python 3 and we all know that
Python 2 and unicode don't mix.


I don't think this is right. The Unicode support in Python 2 isn't as
good as in Python 3, but it is still pretty good. You just have to
remember to use the u prefix on your strings.

If it is true that wxPython cannot handle Unicode -- and I see no
evidence that this is correct --


It most certainly is not. wxPython has handled Unicode (via `unicode` strings) 
for many, many years now.


--
Robert Kern

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

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


Re: smart splitting - how to

2013-12-13 Thread Robert Kern

On 2013-12-13 11:28, Helmut Jarausch wrote:

Hi,

I'd like to read several strings by using 'input'.
These strings are separated by white space but I'd like to allow for
some quoting, e.g.

"Guido van" Rossum

should be split into 2 strings only

Now, a simple split doesn't work since it splits the quoted text as well.
Is there a simple way to do so?
It would be nice if it could handle embedded quotes which are escaped
by a backslash, too.

Is there something simpler then a sophisticated regular expression
or even a parser?


http://docs.python.org/3.3/library/shlex


[~]
|1> import shlex

[~]
|2> shlex.split(r'"Guido \"van\" Rossum" invented Python')
['Guido "van" Rossum', 'invented', 'Python']



--
Robert Kern

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

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


Re: Figuring out what dependencies are needed

2013-12-11 Thread Robert Kern

On 2013-12-11 13:27, Steven D'Aprano wrote:

On Wed, 11 Dec 2013 04:44:53 -0800, sal wrote:


Now I'd like to use the backtesting package from zipline (zipline.io),


".io" is not normally a file extension for Python files. Are you sure
that's Python code?


That's a package name, not a filename.


but while running the test script in iPython, I receive the following
error:

AssertionErrorTraceback (most recent call
last)
 in ()
> 1 data = load_from_yahoo()
   2 dma = DualMovingAverage()
   3 results = dma.run(data)


I think you may be missing one or more lines? Perhaps something like
"AssertionError: blah blah blah" appearing after that?


For those unfamiliar with iPython, rather than a standard Traceback, that
appears to suggest that dma.run(data) is raising AssertionError, but we
can't see what (if any) error message is given by that assert, or how it
fails.


No, the > arrow points to the active line in that frame of the traceback. 
Unfortunately, the OP cut off the remaining frames under `load_from_yahoo()` 
actually has the assert that is failing.


--
Robert Kern

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

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


Re: Does Python optimize low-power functions?

2013-12-06 Thread Robert Kern

On 2013-12-06 19:01, Neil Cerutti wrote:

On 2013-12-06, John Ladasky  wrote:

The following two functions return the same result:

 x**2
 x*x

But they may be computed in different ways.  The first choice
can accommodate non-integer powers and so it would logically
proceed by taking a logarithm, multiplying by the power (in
this case, 2), and then taking the anti-logarithm.  But for a
trivial value for the power like 2, this is clearly a wasteful
choice.  Just multiply x by itself, and skip the expensive log
and anti-log steps.

My question is, what do Python interpreters do with power
operators where the power is a small constant, like 2?  Do they
know to take the shortcut?


It uses a couple of fast algorithms for computing powers. Here's
the excerpt with the comments identifying the algorithms used.
 From longobject.c:

2873 if (Py_SIZE(b) <= FIVEARY_CUTOFF) {
2874 /* Left-to-right binary exponentiation (HAC Algorithm 14.79) */
2875 /* http://www.cacr.math.uwaterloo.ca/hac/about/chap14.pdf*/
...
2886 else {
2887 /* Left-to-right 5-ary exponentiation (HAC Algorithm 14.82) */


It's worth noting that the *interpreter* per se is not doing this. The 
implementation of the `long` object does this in its implementation of the 
`__pow__` method, which the interpreter invokes. Other objects may implement 
this differently and use whatever optimizations they like. They may even (ab)use 
the syntax for things other than numerical exponentiation where `x**2` is not 
equivalent to `x*x`. Since objects are free to do so, the interpreter itself 
cannot choose to optimize that exponentiation down to multiplication.


--
Robert Kern

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

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


Re: Packaging a proprietary Python library for multiple OSs

2013-12-05 Thread Robert Kern

On 2013-12-05 17:50, Zero Piraeus wrote:

:

On Thu, Dec 05, 2013 at 09:12:30AM -0800, Roy Smith wrote:

I keep hearing that I should use gmane as a superior interface.  Well,
I tried that.  I went to http://dir.gmane.org/search.php, where it
asks me to search for a newsgroup.  I type in "comp.lang.python", and
it tells me, "No matching groups".  So, that seems pretty broken to
me.


That's not entirely fair - Gmane presents mailing lists as newsgroups,
not vice versa, so it doesn't know that python-list@python.org is
connected to comp.lang.python (or that comp.lang.python even exists).

A search for the mailing list from the front page works just fine:

   http://gmane.org/find.php?list=python-list%40python.org


Right. GMane is an NNTP service, but it is not part of the USENET network. 
comp.lang.python is a USENET newsgroup and requires a true USENET server (not 
just an NNTP server) to access.


--
Robert Kern

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

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


Re: Extending the 'function' built-in class

2013-12-01 Thread Robert Kern

On 2013-12-01 19:43, Tim Chase wrote:


I'm not quite sure *why* one might want to subclass FunctionType, but
I'm also not sure why you should be *prevented* from subclassing it.


Previously:

http://grokbase.com/t/python/python-list/033r5nks47/type-function-does-not-subtype#20030324rcnwbkfedhzbaf3vmiuer3z4xq

--
Robert Kern

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

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


Re: Got a Doubt ! Wanting for your Help ! Plz make it ASAP !

2013-11-27 Thread Robert Kern

On 2013-11-27 13:29, rusi wrote:

On Wednesday, November 27, 2013 6:27:52 PM UTC+5:30, Robert Kern wrote:

On 2013-11-27 08:16, Antoon Pardon wrote:

Op 26-11-13 22:42, Tim Delaney schreef:

On 27 November 2013 03:57, Antoon Pardon  wrote:
  So I can now ask my questions in dutch and expect others to try and
  understand me instead of me asking them in english? Or can I use
  literal translations of dutch idioms even if I suspect that such
  a literal translation could be misunderstood and even be insulting?
1. No, because this is stated to be an English-speaking list/newsgroup.
It just doesn't specify what dialect of English.

Well so much for this group being an international group with only one
language allowed.
However that second sentence doesn't make much sense to me. Modern
languages contain a subset that is called the standard language.



Linguists would disagree.


Linguists disagree a lot amongst themselves:

Early 20th century there was Fowler and his followers -- unabashedly
laying down the law on what is right and not.  Then there were his
opponents (French school I think, not sure what they were called --
poststructuralists maybe??) who said language was defined by usage and
not the other way.  Until someone (Fowlerite?) pointed out that those
anti-Fowlerites seemingly objectively described all the dialects but
they themselves stuck to pristine Queen's English.

So like in society, all dialects are equal and some are more equal!


Henry Fowler? To my knowledge, he was a dictionary-maker, not a linguist. To be 
fair, back then, the field of linguistics was not terribly well established, so 
he might have qualified for the title at the time. However, linguistics has 
learned a lot and moved on since then. You would be seriously hard-pressed to 
find a prescriptivist linguist these days.


--
Robert Kern

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

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


Re: Got a Doubt ! Wanting for your Help ! Plz make it ASAP !

2013-11-27 Thread Robert Kern

On 2013-11-27 08:16, Antoon Pardon wrote:

Op 26-11-13 22:42, Tim Delaney schreef:

On 27 November 2013 03:57, Antoon Pardon mailto:antoon.par...@rece.vub.ac.be>> wrote:


 So I can now ask my questions in dutch and expect others to try and
 understand me instead of me asking them in english? Or can I use
 literal translations of dutch idioms even if I suspect that such
 a literal translation could be misunderstood and even be insulting?


1. No, because this is stated to be an English-speaking list/newsgroup.
It just doesn't specify what dialect of English.


Well so much for this group being an international group with only one
language allowed.

However that second sentence doesn't make much sense to me. Modern
languages contain a subset that is called the standard language.


Linguists would disagree.


Yes I accept that everyone deviates from this standard language and that
it isn't always easy to know what is and what is not within the standard
language and that we should allow each other some leeway.


Incorrect. No dialect "deviates" from a "standard" form of that language. 
Everyone speaks a dialect. The privilege given to any particular dialect has 
nothing to do with the form of the dialect itself and everything to do with the 
sociopolitical history of its speakers. None of that is relevant to speaking 
comprehensibly in an international environment.


--
Robert Kern

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

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


Re: Got a Doubt ! Wanting for your Help ! Plz make it ASAP !

2013-11-27 Thread Robert Kern

On 2013-11-27 08:31, Antoon Pardon wrote:

Op 27-11-13 09:19, Chris Angelico schreef:

On Wed, Nov 27, 2013 at 7:16 PM, Antoon Pardon
 wrote:

However that second sentence doesn't make much sense to me. Modern
languages contain a subset that is called the standard language. This
is the subset that is generally taught. Especially to those for whom
the language is foreign. So when you define a specific language to
use on an international forum, it is strongly suggested that people
limit themselves to the standard subset and don't use dialects since
"dialect" AFAIU means it is outside this standard.


Do you mean standard British English, standard American English,
standard Australian English, or some other?


Does that significantly matter or are you just looking for details
you can use to disagree? As far as I understand the overlap between
standard British English and standard American English is so large
that it doesn't really matter for those who had to learn the language.
Likewise for the overlap with standard Australian English.


Since the original usage that you are complaining about is "standard" Indian 
English[1], yes, it does significantly matter.


[1] To the extent that there is such a thing as a "standard" form of any 
language. Which there isn't, but I will grant you your premise for the time being.


--
Robert Kern

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

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


Re: Cracking hashes with Python

2013-11-26 Thread Robert Kern

On 2013-11-26 10:30, TheRandomPast wrote:


and I've started the second part, the part to crack them. If anyone could tell 
me where I'd find more information on this subject and how to crack them that 
would be great.


What resources did your teacher give you? What have you been taught in class 
about this subject?


--
Robert Kern

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

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


Re: argparse feature request

2013-11-22 Thread Robert Kern

On 2013-11-22 18:15, Neal Becker wrote:

Robert Kern wrote:


On 2013-11-22 16:52, Neal Becker wrote:

Robert Kern wrote:


On 2013-11-22 14:56, Neal Becker wrote:

I use arparse all the time and find it serves my needs well.  One thing I'd
like
to see.  In the help message, I'd like to automatically add the default
values.



What I'd like to see is:

--size SIZE [2000]  <<< the default value is displayed


Use formatter_class=argparse.ArgumentDefaultsHelpFormatter




http://docs.python.org/2/library/argparse#argparse.ArgumentDefaultsHelpFormatter



Thanks!  Almost perfect.  Problem is, I don't usually bother to add
help='help
me' options.  It seems that ArgumentDefaultsHelpFormatter doesn't do anything
unless help='blah' option is used.  Not sure what to do about that.  Since
python test_freq3.py -h
produces useful messages without my adding help=... everywhere, it'd be nice
if ArgumentDefaultsHelpFormatter would work here.


Patches are welcome, I am sure. Implement a HelpFormatter that does what you
want. _format_action() is where the relevant logic is. Try something like
this, and modify to suit.


class BeckerDefaultFormatter(argparse.ArgumentDefaultsHelpFormatter):

  def _format_action(self, action):
  monkeypatched = False
  if action.default is not None and action.help is None:
  # Trick the default _format_action() method into writing out
  # the defaults.
  action.help = ' '
  monkeypatched = True
  formatted = super(BeckerDefaultFormatter,
  self)._format_action(action) if monkeypatched:
  action.help = None
  return formatted



Thanks!  Seems to work great.  It gave reasonable output for both case where I
include
help=...
and also without.

I have no idea how that above code works, but I guess as long as it works...


Just take a look at the implementation of HelpFormatter._format_action() and 
look for where my monkeypatch would change the logic. It took me just a few 
minutes to figure out how to do it in the first place. There really isn't 
anything tricky going on.


--
Robert Kern

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

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


Re: argparse feature request

2013-11-22 Thread Robert Kern

On 2013-11-22 16:52, Neal Becker wrote:

Robert Kern wrote:


On 2013-11-22 14:56, Neal Becker wrote:

I use arparse all the time and find it serves my needs well.  One thing I'd
like
to see.  In the help message, I'd like to automatically add the default
values.



What I'd like to see is:

--size SIZE [2000]  <<< the default value is displayed


Use formatter_class=argparse.ArgumentDefaultsHelpFormatter


http://docs.python.org/2/library/argparse#argparse.ArgumentDefaultsHelpFormatter



Thanks!  Almost perfect.  Problem is, I don't usually bother to add help='help
me' options.  It seems that ArgumentDefaultsHelpFormatter doesn't do anything
unless help='blah' option is used.  Not sure what to do about that.  Since
python test_freq3.py -h
produces useful messages without my adding help=... everywhere, it'd be nice
if ArgumentDefaultsHelpFormatter would work here.


Patches are welcome, I am sure. Implement a HelpFormatter that does what you 
want. _format_action() is where the relevant logic is. Try something like this, 
and modify to suit.



class BeckerDefaultFormatter(argparse.ArgumentDefaultsHelpFormatter):

def _format_action(self, action):
monkeypatched = False
if action.default is not None and action.help is None:
# Trick the default _format_action() method into writing out
# the defaults.
action.help = ' '
monkeypatched = True
formatted = super(BeckerDefaultFormatter, self)._format_action(action)
if monkeypatched:
    action.help = None
return formatted

--
Robert Kern

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

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


Re: argparse feature request

2013-11-22 Thread Robert Kern

On 2013-11-22 14:56, Neal Becker wrote:

I use arparse all the time and find it serves my needs well.  One thing I'd like
to see.  In the help message, I'd like to automatically add the default values.

For example, here's one of my programs:

  python3 test_freq3.py --help
usage: test_freq3.py [-h] [--size SIZE] [--esnodB ESNODB] [--tau TAU] [--trials
TRIALS]
  [--training TRAINING] [--sps SPS] [--si SI] [--alpha 
ALPHA]
  [--range RANGE] [--dfunc {gradient,delay}]
  [--mod
{gaussian,qpsk,8psk,16apsk,32apsk,32dlr,64apsk,256apsk}]
  [--sym-freq-err SYM_FREQ_ERR] [--calibrate [CALIBRATE]]

optional arguments:
   -h, --helpshow this help message and exit
   --size SIZE
   --esnodB ESNODB, -e ESNODB
   --tau TAU, -t TAU
   --trials TRIALS
   --training TRAINING
   --sps SPS
   --si SI
   --alpha ALPHA
   --range RANGE
   --dfunc {gradient,delay}
   --mod {gaussian,qpsk,8psk,16apsk,32apsk,32dlr,64apsk,256apsk}
   --sym-freq-err SYM_FREQ_ERR
   --calibrate [CALIBRATE], --with-calibrate [CALIBRATE], --enable-calibrate
[CALIBRATE], --no-calibrate [CALIBRATE], --without-calibrate [CALIBRATE], --
disable-calibrate [CALIBRATE]

What I'd like to see is:

--size SIZE [2000]  <<< the default value is displayed


Use formatter_class=argparse.ArgumentDefaultsHelpFormatter

http://docs.python.org/2/library/argparse#argparse.ArgumentDefaultsHelpFormatter

E.g.

[git/mpstack]$ cat print_stacks.py
...
def main():
import argparse
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('-p', '--percent', action='store_true', help='Show 
percentages.')

parser.add_argument('file', help='The sample file.')
...

[git/mpstack]$ python print_stacks.py -h
usage: print_stacks.py [-h] [-p] file

positional arguments:
  file   The sample file.

optional arguments:
  -h, --help show this help message and exit
  -p, --percent  Show percentages. (default: False)

--
Robert Kern

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

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


Re: Question regarding 2 modules installed via 'pip'

2013-11-16 Thread Robert Kern

On 2013-11-16 17:02, Mark Lawrence wrote:

On 16/11/2013 16:51, Ned Batchelder wrote:

On Saturday, November 16, 2013 11:48:19 AM UTC-5, YBM wrote:


Perhaps because this is not a folder. Learn to read.


Nikos is being annoying, but there is no need to contribute to the thread just
to insult him.  It doesn't make the thread stop, it doesn't make the list a
better community, and it doesn't work to improve Nikos' behavior.

http://www.python.org/psf/codeofconduct/

--Ned.



For the record has anybody ever pointed Nikos at the code of conduct? If yes
good.


I believe so, but I can't summon the will to search for it.


If no why not, and why then point it out to someone who to my knowledge
has never posted here before?


Being presented with the community's code of conduct is not a punishment for bad 
behavior. Newcomers are the *primary* audience for the code of conduct. I'm old 
enough to remember moderated listservs (as was the fashion at the time) that 
would automatically reply to each new poster with the listserv's charter and 
expected rules of netiquette (which is what we called it in those halcyon days).


--
Robert Kern

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

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


Re: Question regarding 2 modules installed via 'pip'

2013-11-16 Thread Robert Kern

On 2013-11-16 13:59, Νίκος wrote:

HELP ME


The kind people at http://serverfault.com/ can help you with your system 
administration problems. I'm afraid that we cannot.


--
Robert Kern

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

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


Re: To whoever hacked into my Database

2013-11-14 Thread Robert Kern

On 2013-11-14 13:24, Ferrous Cranus wrote:


But the response wasn't clear to me.
Ia this randomly normal background Internet radiation or some personal directed
attacks?


We don't know. This is not the appropriate forum for such questions. Please find 
a different forum for your server administration questions. Try this one:


  http://serverfault.com/

--
Robert Kern

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

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


Re: 'isimmutable' and 'ImmutableNester'

2013-11-12 Thread Robert Kern

On 2013-11-12 11:14, Steven D'Aprano wrote:

On Tue, 12 Nov 2013 18:12:43 +1100, Chris Angelico wrote:


def isimmutable(x):
 try:
 hash(x)
 return True
 except TypeError:
 return False


I'm afraid that doesn't test for immutability. It tests for hashability,
which is different.


I am going to nitpick below for nitpicking's sake, but I agree with this.


No well-behaved mutable object can be hashable, but that's not to say
that badly-behaved mutable objects won't be hashable.


That's not quite true. A well-behaved mutable may be (well-behaved) hashable as 
long as the allowed mutations do not affect the equality comparison. For 
example, in Python 2, all new classes are mutable by default, but they are also 
well-behaved hashable by default because their equality comparison is identity 
comparison. None of the mutations affect object identity, so the hash based on 
identity remains well-behaved.



And every immutable
object should be hashable, but that's not to say that some immutable
objects might choose, for their own reasons, not to be hashable.


I would also dispute this. A tuple itself is immutable, but it may not be 
hashable because one of its contained objects is unhashable (whether due to 
mutability or something else).



So your function is subject to both false negatives and false positives.


Agreed.

--
Robert Kern

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

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


Re: New user's initial thoughts / criticisms of Python

2013-11-11 Thread Robert Kern

On 2013-11-11 10:39, Chris Angelico wrote:


A 'minor weapon' is based on a roll of a 100-sided dice. If it's 01 to
70, "+1 weapon: 2,000gp [weapon]"; if it's 71 to 85, "+2 weapon:
8,000gp [weapon]"; if 86 to 90, "Specific weapon [minor specific
weapon]"; and if 91 to 100, "Special ability [minor special weapon]
and roll again".

My code to handle that starts out with this array:

"minor weapon":({
 70,"+1 weapon: 2,000gp [weapon]",
 85,"+2 weapon: 8,000gp [weapon]",
 90,"Specific weapon [minor specific weapon]",
 100,"Special ability [minor special weapon] and roll again",
}),

(that's Pike; in Python it'd be a list, or maybe a tuple of tuples),
and denormalizes it into a lookup table by creating 70 entries quoting
the first string, 15 quoting the second, 5, and 10, respectively. So,
with a bit of preprocessing, a lookup table (which in this case is an
array (list), but could just as easily be a dict) can be used to
handle inequalities. But this is because lookup tables can be treated
as data, where if/elif/else blocks have to be code; there are roughly
42 million such lookup tables in the code I snagged that from, and
having code for each one would work out far less manageable. Normally,
you'll want to render inequalities with code as if/elif.


Heh. I've done pretty much exactly the same thing to implement an engine[1] to 
draw from the random tables on Abulafia[2] which have nearly the same structure. 
It scales up reasonably well beyond d100s. It's certainly not a technique I 
would pull out to replace one-off if-elif chains that you literally write, but 
it works well when you write the generic code once to apply to many tables.


[1] http://rollmeup.mechanicalkern.com/
[2] http://www.random-generator.com/index.php?title=Main_Page

--
Robert Kern

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

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


Re: Code with random module faster on the vm than the vm host...

2013-11-10 Thread Robert Kern

On 2013-11-11 00:49, alex23 wrote:

On 9/11/2013 3:48 AM, Pascal Bit wrote:

from random import random

 > [...]


Running on win7 python 2.7 32 bit it uses around 30 seconds avg.
Running on xubuntu, 32 bit, on vmware on windows 7: 20 seconds!
The code runs faster on vm, than the computer itself...
The python version in this case is 1.5 times faster...
I don't understand.

What causes this?


The random module uses os.urandom,


No, it doesn't. random.random() is an alias to the random() method on the 
random.Random class, which uses the Mersenne Twister to generate values. 
os.urandom() gets called in the initial default seeding, but not for each value.


--
Robert Kern

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

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


Re: Adding 'download' column to existing 'visitors' table (as requested)

2013-11-09 Thread Robert Kern

On 2013-11-09 04:27, Piet van Oostrum wrote:

Sibylle Koczian  writes:


Am 07.11.2013 14:14, schrieb Piet van Oostrum:

Nick the Gr33k  writes:


I have decided to take your advice.
I wasn't able to fit those 'lists' of mine into MySQL's varchar()
datatype after converting them to long strings and that sads me.

My implementation is like the following.
I do not use an extra table of downlaods that i asoociate with table
visitors with a foreing key but decided to add an additional 'download'
column into the existant visitors table:


Nikos, you are an excellent member of the Greek society. Listening to you makes 
it so much easier to understand the problems that your country has.


Is there any reason at all to insult all other Greek readers of this
newsgroup?


I was talking about the Greek nation. That doesn't imply that every single 
Greek is like that.


Just a majority of Greeks? How comforting.

Please don't.

--
Robert Kern

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

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


Re: datetime question

2013-11-08 Thread Robert Kern

On 2013-11-08 23:02, Νίκος Αλεξόπουλος wrote:

Στις 9/11/2013 12:49 πμ, ο/η Denis McMahon έγραψε:

On Sat, 09 Nov 2013 00:01:37 +0200, Νίκος Αλεξόπουλος wrote:


I saw the link and i'm wondering if it can be written in 1-liner.


Yes, but you have to rewrite all your code in perl to do this.




Please tell me and as a git i will provide you with 2 good pdfs i just found:

You can see them at my website if you click the blue download button.

The 1st is a Linux Bile and the 2nd is WebHosting for Dummies.


Please do not advertise your piracy site here. It is not welcome in this forum.

--
Robert Kern

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

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


Re: Basic Python Questions - Oct. 31, 2013

2013-10-31 Thread Robert Kern

On 2013-10-31 14:49, Chris Angelico wrote:

On Fri, Nov 1, 2013 at 1:41 AM, Robert Kern  wrote:

On 2013-10-31 14:05, Chris Angelico wrote:


On Fri, Nov 1, 2013 at 12:17 AM, Alain Ketterlin
 wrote:


"E.D.G."  writes:


The calculation speed question just involves relatively simple
math such as multiplications and divisions and trig calculations such
as sin and tan etc.



These are not "simple" computations.

Any compiled language (Fortran, C, C++, typically) will probably go much
faster than any interpreted/bytecode-based language (like python or
perl, anything that does not use a jit).



Well, they may not be simple to do, but chances are you can push the
work down to the CPU/FPU on most modern hardware - that is, if you're
working with IEEE floating point, which I'm pretty sure CPython always
does; not sure about other Pythons. No need to actually calculate trig
functions unless you need arbitrary precision (and even then, I'd bet
the GMP libraries have that all sewn up for you). So the language
doesn't make a lot of difference.



Sure it does. Python boxes floats into a PyObject structure. Both Python and
C will ultimately implement the arithmetic of "a + b" with an FADD
instruction, but Python will do a bunch of pointer dereferencing, hash
lookups, and function calls before it gets down to that. All of that
overhead typically outweighs the floating point computations down at the
bottom, even for the more expensive trig functions.


Of course that's true, but that difference is just as much whether
you're working with addition or trig functions. That overhead is the
same. So if, as I said in the other post, you're doing some heavy
crypto work or something, then yes, all that boxing and unboxing is
expensive.


Yes, Alain was wrong to suggest that these are not "simple calculations" and 
thus will benefit from a lower-level language. In fact, the relationship is 
reversed. These are *such* simple operations that they do benefit from the 
immediate surrounding code being done in C. The amount of time spent on overhead 
doesn't change based on the operation itself but the immediate surrounding code, 
the inner loops. That's where the language (implementation) matters.


> Most programs aren't doing that, so the advantage is far
> less (by proportion).

But we're not talking about most programs. We are talking about the OP's 
programs, which apparently *do* involve lots of iterated floating point 
calculations.


--
Robert Kern

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

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


Re: Basic Python Questions - Oct. 31, 2013

2013-10-31 Thread Robert Kern

On 2013-10-31 14:05, Chris Angelico wrote:

On Fri, Nov 1, 2013 at 12:17 AM, Alain Ketterlin
 wrote:

"E.D.G."  writes:


   The calculation speed question just involves relatively simple
math such as multiplications and divisions and trig calculations such
as sin and tan etc.


These are not "simple" computations.

Any compiled language (Fortran, C, C++, typically) will probably go much
faster than any interpreted/bytecode-based language (like python or
perl, anything that does not use a jit).


Well, they may not be simple to do, but chances are you can push the
work down to the CPU/FPU on most modern hardware - that is, if you're
working with IEEE floating point, which I'm pretty sure CPython always
does; not sure about other Pythons. No need to actually calculate trig
functions unless you need arbitrary precision (and even then, I'd bet
the GMP libraries have that all sewn up for you). So the language
doesn't make a lot of difference.


Sure it does. Python boxes floats into a PyObject structure. Both Python and C 
will ultimately implement the arithmetic of "a + b" with an FADD instruction, 
but Python will do a bunch of pointer dereferencing, hash lookups, and function 
calls before it gets down to that. All of that overhead typically outweighs the 
floating point computations down at the bottom, even for the more expensive trig 
functions.


This is where numpy comes in. If you can arrange your computation on arrays, 
then only the arrays need to be unboxed once, then the rest of the arithmetic 
happens in C.


--
Robert Kern

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

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


Re: skipping __init__ and using exploiting a class member instead

2013-10-19 Thread Robert Kern

On 2013-10-19 22:55, Ned Batchelder wrote:

On 10/19/13 5:44 PM, Peter Cacioppi wrote:

Is the following considered poor Python form?

class Foo (object) :
 _lazy = None
 def foo(self, x) :
 _lazy = _lazy or self.get_something(x)
 def get_something(self, x) :
 # doesn't really matter

I like this idiom for certain situations, just wondering if it will raise the
hackles of other Pythonistas.

I use this idiom sparingly, but sometimes it just fits the task at hand, I
hear Guidos voice saying "use the Force" in my ear, etc.


You present this as a choice between __init__ or a class attribute, but those
two things are very different.  Is your intent to have an instance attribute, or
a class attribute?  Lazily populated instance attributes are fine, I would do it
like this:

class Foo(object):
 def __init__(self):
 self._lazy = None

 def foo(self, x):
 if self._lazy is None:
 self._lazy = self.get_something(x)
 ...


I think he left some important characters out.

class Foo (object) :
_lazy = None
def foo(self, x) :
self._lazy = self._lazy or self.get_something(x)
# Use self._lazy for something

def get_something(self, x) :
# doesn't really matter

The main difference being that he doesn't initialize the instance attribute and 
just relies on the fallback to class attribute lookup. In my experience, using a 
static[1] class attribute as a default for an instance attribute is accepted 
practice, and one that gets touted as a positive feature of Python's namespace 
model when compared against other languages. That said, I have seen it more 
often in the past.


[1] In the general "unchanging" sense rather than the C++ "static" keyword 
sense.

--
Robert Kern

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

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


Re: strange array size problem

2013-10-18 Thread Robert Kern

On 2013-10-18 16:25, chip9m...@gmail.com wrote:

Hello everybody!

One strange problem, please help!

I have the following 2D array: users_elements_matrix
numpy.shape(users_elements_matrix) is (100,43)

and array merged_binary_ratings
numpy.shape(merged_binary_ratings) is (100,)

Now,when I run:
numpy.linalg.lstsq(users_elements_matrix, merged_binary_ratings)
i get some ridiculous numbers for coeficients, all are the same and 
1.38946385e+15.

What is really strange is that if I run
numpy.shape(users_elements_matrix[:,0:42])
i get ok numbers.

I tested several thing and have examined the matrix, everything is ok with the 
data.

how is it possible that one additional row (variable in linear regression)
has such a strange impact?!!?

I am loosing my mind here, please help!


The numpy-discussion mailing list is probably the best place to ask. I recommend 
posting a complete working example (with data) that demonstrates the problem. 
Use pastebin.com or a similar service if necessary.


  http://www.scipy.org/scipylib/mailing-lists.html

--
Robert Kern

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

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


Re: Sexism in the Ruby community: how does the Python community manage it?

2013-10-18 Thread Robert Kern

On 2013-10-18 05:03, Chris Angelico wrote:

On Fri, Oct 18, 2013 at 2:14 PM, Steven D'Aprano
 wrote:

On Thu, 17 Oct 2013 10:16:24 -0700, Roy Smith wrote:


On Thursday, October 17, 2013 11:07:48 AM UTC-4, Chris Angelico wrote:

Module names should be  descriptive, not fancy.


Interesting comment, on a mailing list for a language named after a
snake, especially by a guy who claims to prefer an language named after
a fish :-)


It's not named after a snake, but after a British comedy group, "Monty
Python". And I daresay that Pike is named after a long stick with a spike
and axe on the end. Just 'cos that would be cooler than naming it after
the fish.


I don't know which it was named after (could also be a road, eg
turnpike), but the language's logo is the fish.


Our logo is a snake, so that's obviously not a good guide. :-)

--
Robert Kern

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

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


Re: Sexism in the Ruby community: how does the Python community manage it?

2013-10-18 Thread Robert Kern

On 2013-10-18 04:14, Steven D'Aprano wrote:

On Thu, 17 Oct 2013 10:16:24 -0700, Roy Smith wrote:


On Thursday, October 17, 2013 11:07:48 AM UTC-4, Chris Angelico wrote:

Module names should be  descriptive, not fancy.


Interesting comment, on a mailing list for a language named after a
snake, especially by a guy who claims to prefer an language named after
a fish :-)


It's not named after a snake, but after a British comedy group, "Monty
Python". And I daresay that Pike is named after a long stick with a spike
and axe on the end. Just 'cos that would be cooler than naming it after
the fish.

(I'm not sure whether the fish was named after the weapon, or the weapon
after the fish. But I'm pretty sure one was named after the other.)


Common parent more like. "pike" or "pick" or any number of similar variants was 
a more general term applied to things with a pointed tip. The fish name is a 
shortening of "pike-fish", so it's obviously not the source of the word. The 
weapon only really comes into fashion a couple of centuries after the fish's 
name is first recorded, so it's not the source either.


P.S. It's nice to have access to an electronic copy of the OED.

--
Robert Kern

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

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


Re: Handling 3 operands in an expression without raising an exception

2013-09-28 Thread Robert Kern

On 2013-09-27 11:43, Dave Angel wrote:


You should study APL.  Many functions were written in one line, with
twenty lines of explanation.  The function itself was considered
unreadable nonsense. And if a function stopped working, general wisdom
was to throw it out, and re-implement the explanation. I studied it
briefly in class in 1970, and have no idea if there are current
implementations.


You are in luck! GNU APL 1.0 was just released!

  http://www.gnu.org/software/apl/

--
Robert Kern

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

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


Re: Referrer key missing form os.environ dictionary?

2013-09-26 Thread Robert Kern

On 2013-09-26 04:25, Chris Angelico wrote:

On Thu, Sep 26, 2013 at 11:32 AM, Terry Reedy  wrote:

Since CGI uses stdout for the finished product, it could have used stdin for
the input.


Haven't used CGI in years, but I thought POST data came on stdin?


You could just put the whole HTTP request, headers and body, through stdin and 
just make the program parse them apart.


--
Robert Kern

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

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


Re: Referrer key missing form os.environ dictionary?

2013-09-25 Thread Robert Kern

On 2013-09-25 15:07, Νίκος wrote:

Στις 25/9/2013 5:01 μμ, ο/η Chris “Kwpolska” Warrick έγραψε:

On Wed, Sep 25, 2013 at 2:45 PM, Νίκος  wrote:

Hello, i decided am ong other os.environ variables to also grab the
'HTTP_REFERER' fiel but when i try to run my script i was seeing a KeyError
complaining that 'HTTP_REFERER' didnt exist.

So, to see what existed in the os.environ dictionary i issues a print(
os.environ ) to see all available keys and their values:


The Referer header is not mandatory by any means.  Your client
probably does not send it.


But one other problem appeared too:

ni...@superhost.gr [~/www/cgi-bin]# python metrites.py
   File "metrites.py", line 27
 host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or 'UnKnown 
Host'
^
SyntaxError: invalid syntax


i dont see anything wrong with that line, and the carret is actually pointing to
the "host".


As has been explained to you before, SyntaxErrors just point to the place where 
the parser saw something unexpected, not the exact point where you made the 
error. It is not omniscient. If you don't see the problem on the reported line, 
you have probably left off a closing bracket or something similar in a previous 
line. Look back a few lines.


--
Robert Kern

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

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


Re: Possibilities of Building "Stacked Neural Networks"

2013-09-25 Thread Robert Kern

On 2013-09-24 19:03, Michael Lamport Commons wrote:

Dear Members of this list-serve:

Would it be possible to build “stacked neural networks” like the one 
shown in the attached document?

You may have a few questions about the stacked neural network. For 
example, what is a stacked neural network? What is the difference between 
stacked neural networks and the existing neural network? A brief description is 
provided in the attached document.

Based on this brief description, I would like to know how would one go 
about building such stacked neural networks cheaply and easily?  Is there any 
software available that can do this?  How much would it cost?

Please feel free to contact me if you think that it would be possible 
or easier to apply stacked neural network into a more practical field? 
Suggestions are welcome as well.


The term of art for these kind of architectures is "deep learning" (and 
associated terms like "deep architecture", "deep networks", etc.). It's an 
active field of research that is showing promising preliminary results, and we 
are beginning to see its limits as well. Google and other big machine learning 
players are putting a lot of resources into building these systems.


  http://arxiv.org/pdf/1112.6209v3.pdf

A good resource would be the Deep Learning Tutorial which shows you how to build 
these systems using Theano, a Python package for computing with GPUs, one that 
is particularly well-suited to building deep neural networks.


  http://deeplearning.net/tutorial/

Unfortunately, there is nothing cheap or easy about deep networks. They are 
*very* computationally expensive. You will probably need a small cluster of GPUs 
to solve interesting problems, and training one will probably take a couple of 
days of computation (for the final run, *after* you have debugged your code and 
done the initial experiments to find all of the right hyperparameters for your 
problem).


Good luck!

--
Robert Kern

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

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


Re: Python GUI?

2013-09-20 Thread Robert Kern

On 2013-09-20 19:34, Metallicow wrote:


I prefer wx over qt for these reasons.
Robin works for qt now. *Funny isn't it...*


Lying about someone's employment is not very funny. Robin does not work for "Qt" 
or even Digia, the nearest thing to a corporate "owner" of Qt these days.


  https://www.enthought.com/company/team/devs/


Basically, To change qt(PySide) you need to pretty much need to be employed by 
qt,


This is emphatically incorrect, by your own example. Robin does indeed 
contribute to the PySide project. Both Qt and PySide are both open to and 
*driven by* contributions from the community.


  http://qt-project.org/contribute
  http://qt-project.org/wiki/PySideContributors

--
Robert Kern

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

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


Re: What minimum should a person know before saying "I know Python"

2013-09-20 Thread Robert Kern

On 2013-09-20 12:43, rusi wrote:

On Friday, September 20, 2013 3:28:00 PM UTC+5:30, Aseem Bansal wrote:

I started Python 4 months ago. Largely self-study with use of Python 
documentation, stackoverflow and google. I was thinking what is the minimum 
that I must know before I can say that I know Python?

I come from a C background which is comparatively smaller. But as Python is 
comparatively much larger what minimum should I know?

Just a general question not for a specific purpose.


Stroustrup says he is still learning C++ and I know kids who have no qualms 
saying they know programming language L (for various values of L) after hardly 
an hour or two of mostly advertising and pep-talk exposure.
So without knowing what you mean my 'knowing' I am not going to try answering 
q-1


I think that's his actual question: "What do *you* mean by 'I know Python'?" At 
what point in your Python career did you feel comfortable claiming that?


--
Robert Kern

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

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


Re: Tryign to send mail via a python script by using the local MTA

2013-09-20 Thread Robert Kern

On 2013-09-20 04:56, Jake Angulo wrote:

Up Robert Kern's reply!

I was waiting for smtplib <http://docs.python.org/2/library/smtplib> to be
mentioned... finally!  Instead people simply answer philosophically.  I dont
want to judge whether OP is a troll or not - but i found a lot of arrogant
replies here.  I have also worked on an antispam project before, and see through
the intents of the OP, but I do not pretend to be a moralist. I was hoping we
would strictly discuss code or software architecture here, not morality. Simple
question, simple answer pls, in the interest of the Python list.


Please don't valorize my message. I did neither Nikos nor the group any favors. 
I can only plead dizziness from the whooshing of Tim's sarcasm flying over 
Nikos' head.


--
Robert Kern

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

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


Re: Having both if() and for() statements in one liner

2013-09-17 Thread Robert Kern

On 2013-09-17 13:02, Ferrous Cranus wrote:

o want to avoid having to type somehting like this:

if person="George":
 times in range(0, 5):


Why it gives me an error when i'm trying to write it like this:


if person="George" for times in range(0, 5):

Can't i ahve both if and for in a one liner?


Not in Python, no.

--
Robert Kern

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

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


Re: Tryign to send mail via a python script by using the local MTA

2013-09-17 Thread Robert Kern

On 2013-09-17 13:11, Ferrous Cranus wrote:


There are members here like Tim Chase who said that they find it interesting to
be able to do what i proposed.


No, he didn't. He was using sarcasm in a vain attempt to inspire you to search 
the Python documentation where you could easily find the standard SMTP library.


  http://docs.python.org/2/library/smtplib

--
Robert Kern

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

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


Re: Python GUI?

2013-09-12 Thread Robert Kern

On 2013-09-12 17:03, eamonn...@gmail.com wrote:

On Thursday, September 12, 2013 6:05:14 AM UTC+1, Michael Torrie wrote:

On 09/11/2013 02:55 PM, eamonn...@gmail.com wrote:



Possibly.  I know Qt and Gtk both can flip the button orders, etc to
look more native.  And all good toolkits give you layout managers so you
never have to resort to fixed layouts.  Qt's layout system is very
different than Gtk's, but once you get the feel of it (use the Qt
Designer program!), it makes a lot of sense.


I didn't realise GTK has a GUI designer too :(

I don't like it when you can D&D to position things. I don't understand why someone 
wouldn't want to write the positioning code, and have fun with the debugging. That's 
the best part about writing a program, in my opinion. I'm against D&D with 
programming, and I'm not sure why.


There is nothing forcing you to use the GUI designers if you don't want to.

--
Robert Kern

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

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


  1   2   3   4   5   6   7   8   9   10   >