Re: how to create a soap enveloppe with python suds for consume a bssv web service

2015-01-08 Thread brice DORA
Le jeudi 8 janvier 2015 07:53:12 UTC, dieter a écrit :
> brice DORA  writes:
> 
> > Hi all I am working on a app in python and I have to call a web service 
> > deployed on JDE (bssv). I use it for the suds lib which seems pretty 
> > friendly. but the problem is the JDE web service that uses bssv technology 
> > necessarily requires sending a soap envelope. as far as I spend my fesais 
> > parameters required in my suds client. My concern then is how to work 
> > around this problem, or is this possible to create a soap envelope with 
> > suds? thank you in advance
> 
> "suds" should generate those required "SOAP envelope".
> 
> "suds" can be set up to log the precise messages sent and received
> (consult the "suds" documentation about logging and the Python
> documentation about its "logging" module). With these messages
> (and a precise description of the encountered problem), you can
> contact someone responsible for the web service to resolve your problems.

okey thanks for your help but can you tell me if it's possible to see the 
content of this soap envelope that's sent by suds? if yes then please how can i 
do it?thanks you in advance
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Announce: PyPrimes 0.2.1a

2015-01-08 Thread Steven D'Aprano
Ben Finney wrote:

> Steven D'Aprano  writes:
> 
>> (Note: pip may have problems downloading the right version if you
>> don't specify a version number.)
>>
>> Or you can access the latest development version:
>>
>> hg clone https://code.google.com/p/pyprimes/
> 
> The source has a ‘CHANGES.txt’ file which has no entry later than
> version 0.2a. Why was the later version made, and when will the change
> log be updated for that?
> 

Ah, I knew I forgot something!

0.2.1a was a version bump to try to work around an issue with PyPI. There
are no functional differences.

I screwed up the upload to PyPI, and it won't allow you to upload the same
version twice. (At least, I don't know of any way to do so.) So I had to
bump the version number to re-upload.



-- 
Steven

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


Re: Announce: PyPrimes 0.2.1a

2015-01-08 Thread Steven D'Aprano
Christian Gollwitzer wrote:

> Hi Steve,
> 
> Am 08.01.15 um 05:35 schrieb Steven D'Aprano:
>> At long last, I am pleased to announce the latest version of PyPrimes, a
>> pure Python package for working with prime numbers.
> 
> Nice.
> 
>> PyPrimes is compatible with Python 2 and 3, and includes multiple
>> algorithms for the generating and testing of prime numbers, including the
>> Sieve of Eratosthenes, Croft Spiral, Miller-Rabin and Fermat
>> probabilistic tests.
>>
>> https://pypi.python.org/pypi/pyprimes/
> 
> I don't want to badmouth your effort, but it seems to me that this is
> still a collectino of rather simple algorithms. What about the AKS test,
> which is O(P) and deterministic for all primes, what about elliptic
> curve factorization or a quadratic sieve?

It's a 0.2 version number, what do you expect? :-)

AKS may be O(P), but the constant factor is quite large. In practice I
expect that it will probably be slower than Miller-Rabin. Nevertheless,
I'll eventually include that.



-- 
Steven

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


Oddity with lambda and yield

2015-01-08 Thread Chris Angelico
As yield is an expression, it's legal in a lambda function, which then
means you have a generator function. But it's not quite the same as
the equivalent function made with def:

$ python3
Python 3.5.0a0 (default:1c51f1650c42+, Dec 29 2014, 02:29:06)
[GCC 4.7.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> f=lambda: (yield 5)
>>> x=f()
>>> next(x)
5
>>> x.send(123)
Traceback (most recent call last):
  File "", line 1, in 
StopIteration
>>> def f(): return (yield 5)
...
>>> x=f()
>>> next(x)
5
>>> x.send(123)
Traceback (most recent call last):
  File "", line 1, in 
StopIteration: 123


Is this a bug? I very much doubt any sane code will ever run into
this; I discovered this purely by chance, after noting that
Python/compile.c had code to create a generator. The same thing
happens with Python 3.4.2 on Debian Jessie, so this isn't a bug I've
introduced in my local fiddling around.

If nothing else, it's an amusing proof that you shouldn't just stuff
every cool thing you can think of into a single line of code :)

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


Re: Hello World

2015-01-08 Thread Albert van der Horst
In article ,
Chris Angelico   wrote:
>On Sun, Dec 21, 2014 at 5:31 PM, Terry Reedy  wrote:
>> Just to be clear, writing to sys.stdout works fine in Idle.
> import sys; sys.stdout.write('hello ')
>> hello  #2.7
>>
>> In 3.4, the number of chars? bytes? is returned and written also.
>>
>> Whether you mean something different by 'stdout' or not, I am not sure.  The
>> error is from writing to a non-existent file descriptor.
>
>That's because sys.stdout is replaced. But stdout itself, file
>descriptor 1, is not available:
>
 os.fdopen(1,"w").write("Hello, world\n")
>Traceback (most recent call last):
>  File "", line 1, in 
>os.fdopen(1,"w").write("Hello, world\n")
>OSError: [Errno 9] Bad file descriptor

I don't trust sudo because it is too complicated.
(To the point that I removed it from my machine.)
I do
su
..
#
su nobody

Who needs sudo?

It's like instead of telling a 4-year old to stay on the
side walk, learning him to read and then give him a 8-page
brochure about "safety in traffic".


>
>This works fine in command-line Python, just not in IDLE. It's not
>Windows vs Unix, it's Idle vs terminal.
>
>ChrisA

Groetjes Albert
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

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


Re: Hello World

2015-01-08 Thread Chris Angelico
On Thu, Jan 8, 2015 at 11:43 PM, Albert van der Horst
 wrote:
> I don't trust sudo because it is too complicated.
> (To the point that I removed it from my machine.)
> I do
> su
> ..
> #
> su nobody
>
> Who needs sudo?

With sudo, you get MUCH finer control. I can grant some user the power
to run "sudo eject sr0", but no other commands. I can permit someone
to execute any of a large number of commands, all individually logged.
I can allow sudo to other users than root, without having to reveal
those accounts' passwords (chances are they don't even have
passwords).

But sure. If you want to cut out complication, dispense with user
accounts altogether and run everything as root. That's WAY simpler!

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


Re: How do I remove/unlink wildcarded files

2015-01-08 Thread Albert van der Horst
In article ,
Rick Johnson   wrote:
>On Saturday, January 3, 2015 4:39:25 AM UTC-6, Mark Lawrence wrote:
>
>> I used to get very confused watching the old westerns.  The child when
>> talking about "more" and "paw" wasn't referring to possibly an
>> adjective, noun or adverb and a part of an animal, but what we would
>> refer to in the UK as "mum" and "dad" :)
>
>Early Americans are easy to satirize since most were
>schooled at home by illiterate parents. I believe the
>"redneck vernacular" substituted "mother" and "father" for
>"maw" and "paw" respectively. Which is not surprising since
>most uneducated folks tend to favor single syllable
>simplifications of words over their multi-syllable
>counterparts.
>
>Widespread centralized free schooling did not exists until
>almost the 1900's. Heck, looking back at American history,
>the world *SHOULD* be in awe. To go from a rag-tag
>illiterate bunch of cowboys, to the worlds most powerful and
>technically advanced society (in roughly one hundred years!)
>has to be the most amazing transformation in the history of
>the human society.

It isn't. The Russian transformation under Stalin from a feodalist
society with wooden plows to atomic bombs and space travel is. Most
capitalist politicians are reluctant to admit this, but e.g. Churchill
recognized this. A comboy on horse back who has ever seen a revolver
is a far cry in backwardness from a feodalist peasant who *expects* to
be flogged by a knut. Feodalism goes to the brain, like slavery does.
(It took generations for the US negroes to shed of their slavery
inheritance. )

Groetjes Albert
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

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


Re: Hello World

2015-01-08 Thread Albert van der Horst
In article ,
Chris Angelico   wrote:
>On Thu, Jan 8, 2015 at 11:43 PM, Albert van der Horst
> wrote:
>> I don't trust sudo because it is too complicated.
>> (To the point that I removed it from my machine.)
>> I do
>> su
>> ..
>> #
>> su nobody
>>
>> Who needs sudo?
>
>With sudo, you get MUCH finer control. I can grant some user the power
>to run "sudo eject sr0", but no other commands. I can permit someone
>to execute any of a large number of commands, all individually logged.
>I can allow sudo to other users than root, without having to reveal
>those accounts' passwords (chances are they don't even have
>passwords).

You've answered   it. sudo works for a system with a very
knowledgeable system administrator and at least one other user.
Not for an electronic engineer who uses Python on his Raspberry Pi.

>
>But sure. If you want to cut out complication, dispense with user
>accounts altogether and run everything as root. That's WAY simpler!

I've no problem explaining to an electronic engineer not to do this,
while not offering him to do the system administration for him.
Having a separate account for system things is a useful distinction
that he can grasp and handle easily. Beyond that he is indeed inclined
to do everything as root, because what he wants is to make a turnkey to
feed his gold fish.

So a separate root account is the best protection for a single user
system. For quite a considerable part of the systems around,
sudo is over the top and stimulates no protection at all, i.e.
what I'd call counter productive.

I can save a 4-years olds life by imprinting on him to
stay on the side walk.

>
>ChrisA

Groetjes Albert
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

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


Re: Hello World

2015-01-08 Thread Marko Rauhamaa
Chris Angelico :

> With sudo, you get MUCH finer control. I can grant some user the power
> to run "sudo eject sr0", but no other commands. I can permit someone
> to execute any of a large number of commands, all individually logged.

I can't remember ever having a need for that. I sometimes use sudo but
most times su is the way.

> I can allow sudo to other users than root, without having to reveal
> those accounts' passwords (chances are they don't even have
> passwords).

An administrator doesn't need the users' passwords for anything but
should be assumed to know them.

> But sure. If you want to cut out complication, dispense with user
> accounts altogether and run everything as root. That's WAY simpler!

In the era of personal computers, the main advantage of the root account
is that you can breathe more easily as an ordinary user, as the
potential for accidental damage is lower.


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


Re: Hello World

2015-01-08 Thread Michael Ströder
Chris Angelico wrote:
> With sudo, you get MUCH finer control.

But it's very hard, almost impossible, to really implement fine-grained
control with sudo. Too many programs provide shell exits.

Well, it's off-topic here.
How about taking this to news:comp.security.unix ?

Ciao, Michael.

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


where in Nan defined

2015-01-08 Thread maurog
I'm running some pandas examples and I canno find in what module NaN is 
defined. Does anyone know what module I have to import in order to have 
it defined?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Hello World

2015-01-08 Thread alister
On Thu, 08 Jan 2015 16:06:16 +0200, Marko Rauhamaa wrote:

> Chris Angelico :
> 
>> With sudo, you get MUCH finer control. I can grant some user the power
>> to run "sudo eject sr0", but no other commands. I can permit someone to
>> execute any of a large number of commands, all individually logged.
> 
> I can't remember ever having a need for that. I sometimes use sudo but
> most times su is the way.
> 
>> I can allow sudo to other users than root, without having to reveal
>> those accounts' passwords (chances are they don't even have passwords).
> 
> An administrator doesn't need the users' passwords for anything but
> should be assumed to know them.

The administrator may be able to change them but he should NEVER know 
them (or need to)!
> 
>> But sure. If you want to cut out complication, dispense with user
>> accounts altogether and run everything as root. That's WAY simpler!
> 
> In the era of personal computers, the main advantage of the root account
> is that you can breathe more easily as an ordinary user, as the
> potential for accidental damage is lower.
> 
> 
> Marko





-- 
Davis' Law of Traffic Density:
The density of rush-hour traffic is directly proportional to
1.5 times the amount of extra time you allow to arrive on time.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: where in Nan defined

2015-01-08 Thread Ian Kelly
On Thu, Jan 8, 2015 at 7:15 AM, maurog  wrote:
> I'm running some pandas examples and I canno find in what module NaN is
> defined. Does anyone know what module I have to import in order to have
> it defined?

It's not defined anywhere. To get nan as a literal just do:

nan = float("nan")
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: where in Nan defined

2015-01-08 Thread Chris Angelico
On Fri, Jan 9, 2015 at 1:15 AM, maurog  wrote:
> I'm running some pandas examples and I canno find in what module NaN is
> defined. Does anyone know what module I have to import in order to have
> it defined?

It's simply float("nan"). If you want a name, you can give it one:

NaN = float("nan")
# or
nan = float("nan")

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


Re: Oddity with lambda and yield

2015-01-08 Thread Ian Kelly
On Thu, Jan 8, 2015 at 5:11 AM, Chris Angelico  wrote:
> As yield is an expression, it's legal in a lambda function, which then
> means you have a generator function. But it's not quite the same as
> the equivalent function made with def:
>
> $ python3
> Python 3.5.0a0 (default:1c51f1650c42+, Dec 29 2014, 02:29:06)
> [GCC 4.7.2] on linux
> Type "help", "copyright", "credits" or "license" for more information.
 f=lambda: (yield 5)
 x=f()
 next(x)
> 5
 x.send(123)
> Traceback (most recent call last):
>   File "", line 1, in 
> StopIteration
 def f(): return (yield 5)
> ...
 x=f()
 next(x)
> 5
 x.send(123)
> Traceback (most recent call last):
>   File "", line 1, in 
> StopIteration: 123
>
>
> Is this a bug? I very much doubt any sane code will ever run into
> this; I discovered this purely by chance, after noting that
> Python/compile.c had code to create a generator. The same thing
> happens with Python 3.4.2 on Debian Jessie, so this isn't a bug I've
> introduced in my local fiddling around.

I don't see anything in PEP 380 suggesting that it shouldn't apply to
lambda functions.

>>> def f(g):
... v = (yield from g)
... yield v
...
>>> g = lambda: (yield 42) or (yield 43) or (yield 44) or "hello world"
>>> list(f(g()))
[42, 43, 44, None]

Seems like a bug to me.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Hello World

2015-01-08 Thread Marko Rauhamaa
alister :

> On Thu, 08 Jan 2015 16:06:16 +0200, Marko Rauhamaa wrote:
>> An administrator doesn't need the users' passwords for anything but
>> should be assumed to know them.
>
> The administrator may be able to change them but he should NEVER know 
> them (or need to)!

When you are under an administrator's dominion, *you* must assume the
they know your password.

(Somewhat in the same vein, if you are running a virtual machine, *you*
must assume the owner of the host computer has root access to your
virtual machine. By extension, *you* must assume the government
officials of the physical jurisdiction of the host computer have root
access to your virtual machine.)


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


Re: where in Nan defined

2015-01-08 Thread Marko Rauhamaa
Ian Kelly :

> To get nan as a literal just do:
>
> nan = float("nan")

True, but that got me thinking: what standard Python math operation
evaluates to NaN?


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


Re: Oddity with lambda and yield

2015-01-08 Thread Chris Angelico
On Fri, Jan 9, 2015 at 1:30 AM, Ian Kelly  wrote:
>
> Seems like a bug to me.

http://bugs.python.org/issue23192 created with a bit more info,
including disassembly.

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


Re: where in Nan defined

2015-01-08 Thread Chris Angelico
On Fri, Jan 9, 2015 at 1:37 AM, Marko Rauhamaa  wrote:
> Ian Kelly :
>
>> To get nan as a literal just do:
>>
>> nan = float("nan")
>
> True, but that got me thinking: what standard Python math operation
> evaluates to NaN?

Subtracting infinity from infinity is one easy way.

>>> 1e309
inf
>>> 1e309-1e309
nan

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


Re: where in Nan defined

2015-01-08 Thread Jussi Piitulainen
Marko Rauhamaa writes:
> Ian Kelly:
> 
> > To get nan as a literal just do:
> >
> > nan = float("nan")
> 
> True, but that got me thinking: what standard Python math operation
> evaluates to NaN?

All manner of arithmetics gives overflow errors ("Numerical result out
of range") but a literal with a large exponent gives an inf, so:

   >>> 0*1e400
   nan

(That's on a Python 3.2.3 ... on linux2.)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: where in Nan defined

2015-01-08 Thread Chris Angelico
On Fri, Jan 9, 2015 at 1:50 AM, Jussi Piitulainen
 wrote:
>>>> 0*1e400
>nan

Nice, that's shorter than mine.

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


Re: where in Nan defined

2015-01-08 Thread Jussi Piitulainen
Chris Angelico writes:
> On Fri, Jan 9, 2015 at 1:37 AM, Marko Rauhamaa wrote:
> >
> > True, but that got me thinking: what standard Python math
> > operation evaluates to NaN?
> 
> Subtracting infinity from infinity is one easy way.
> 
> >>> 1e309
> inf
> >>> 1e309-1e309
> nan

I managed to get inf by arithmetic on finite numbers:

  >>> 1e300/1e-300
  inf

  >>> o = 1e300/1e-300 ; o-o
  nan
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Comparisons and sorting of a numeric class....

2015-01-08 Thread Ian Kelly
On Wed, Jan 7, 2015 at 11:21 PM, Marko Rauhamaa  wrote:
> Steven D'Aprano :
>
>> Marko Rauhamaa wrote:
>>> I prefer the Scheme way:
>>>#f is a falsey object
>>>everything else is a truthy object
>>
>> The Scheme way has no underlying model of what truthiness represents, just
>> an arbitrary choice to make a single value have one truthiness, and
>> everything else the other. It's just as meaningless and just as arbitrary
>> as the opposite would be:
>>
>> #t is True
>> everything else is falsey
>> [...]
>> I'd rather the Pascal way:
>>
>> #t is True
>> #f is False
>> everything else is an error
>
> An advantage of the Scheme way is the chaining of "and" and "or". For
> example, this breaks in Python:
>
>def dir_contents(path):
>if os.path.isdir(path):
>return os.listdir(path)
>return None
>
>def get_choices():
>return dir_contents(PRIMARY) or \
>dir_contents(SECONDARY) or \
>[ BUILTIN_PATH ]

That depends on what the function is intended to do in the first
place. Why would you want to return the contents of an empty directory
rather than the default?

Anyway, to make that work as you want it in Scheme, dir_contents would
have to return #f, not None. Does it really make sense for a
non-predicate function to be returning the value "false"?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Hello World

2015-01-08 Thread alister
On Thu, 08 Jan 2015 16:31:22 +0200, Marko Rauhamaa wrote:

> alister :
> 
>> On Thu, 08 Jan 2015 16:06:16 +0200, Marko Rauhamaa wrote:
>>> An administrator doesn't need the users' passwords for anything but
>>> should be assumed to know them.
>>
>> The administrator may be able to change them but he should NEVER know
>> them (or need to)!
> 
> When you are under an administrator's dominion, *you* must assume the
> they know your password.
> 
> (Somewhat in the same vein, if you are running a virtual machine, *you*
> must assume the owner of the host computer has root access to your
> virtual machine. By extension, *you* must assume the government
> officials of the physical jurisdiction of the host computer have root
> access to your virtual machine.)
> 
> 
> Marko
I will agree with you there. The administrator 'should' never know your 
password but as a user you should never believe that password security 
has been correctly implemented (just ask Sony :-) )



-- 
"The subspace _W inherits the other 8 properties of _V. And there 
aren't
even any property taxes."
-- J. MacKay, Mathematics 134b
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do I remove/unlink wildcarded files

2015-01-08 Thread Rick Johnson
On Thursday, January 8, 2015 7:11:45 AM UTC-6, Albert van der Horst wrote:
> Rick Johnson wrote:
> >Widespread centralized free schooling did not exists until
> >almost the 1900's. Heck, looking back at American history,
> >the world *SHOULD* be in awe. To go from a rag-tag
> >illiterate bunch of cowboys, to the worlds most powerful and
> >technically advanced society (in roughly one hundred years!)
> >has to be the most amazing transformation in the history of
> >the human society.
> 
> It isn't. The Russian transformation under Stalin from a
> feodalist society with wooden plows to atomic bombs and
> space travel is.

Hmm, and i wonder where they got the technology from? Does
it count if the technology was stolen? For instance, if i
steal the source of Python and then proclaim to be the
*true* BDFL of Python, then do i get all the credit for
Python's existence?

I DON'T THINK SO!

You're also ignoring a tiny thing called: "upward mobility".
In the 20th century, the whole of the American people gained
upward mobility. Anyone who dares to claim that a major
transformation of American society has not occurred, must be
blind to history!

Attaining advanced weaponry and scientific achievements is
nothing unless your people are benefiting *POSITIVELY* from
those advancements -- my statement was about transforming
*societies*, not about who popped the most Viagra pills and
achieved the largest erection in finite time!

---> [THUMP CHEST HERE]!

Farms did not vanish after the atomic/space ages, no,
societies still require food. But for the vast majority of
Russians, not a whole lot has changed. Sure, they have the
technology to fight wars on a global stage, but what good is
a strong arm without the guidance of a strong and *FREE*
mind? What good is ultimate power if you cannot improve you
own well being? -- just ask any genie trapped in a bottle!

https://www.youtube.com/watch?v=v57sUtvNa5o

If history has taught us anything, it is that, intelligence
will *ALWAYS* defeat brute strength, and that the *MOST*
intelligent societies are consequently those who possess
both a humbled respect for freedom, and a vile rejection of
oppression.

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


Re: application console with window

2015-01-08 Thread adam
Hej, no właśnie niechodzi o przeniesienie do okienek tylko jeśli znasz taki 
program jak np fk dla dos-a to chodzi mi o taki efekt. Czyli aplikacja 
konsolowa z pseudo okienkami.

Adam

jacek pozniak wrote:

> adam wrote:
> 
>> Is in here maybe someone who speak Polish?
>> 
>> I would like to write application witch looks like this
>> http://linuxiarze.pl/obrazy/internet1/ceni1.png
> Jeśli chodzi Ci o przeniesienie na wersję okienkową to na przykład:
> tkinter.
> 
> jp
> 
>> 
>> I'm looking for some libs, tutorials, or other informations.
>> I'm searching this informations for python3.
>> 
>> adam

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


AssertionError (3.X only) when calling Py_Finalize with threads

2015-01-08 Thread Tom Kent
I'm getting an error output when I call the C-API's Py_Finalize() from a 
different C-thread than I made a python call on.

The error I'm seeing is:
Exception ignored in: 
Traceback (most recent call last):
  File "C:\Python34-32\Lib\threading.py", line 1289, in _shutdown
assert tlock.locked()
AssertionError:


Here's a minimal example that shows it happening when a C-thread is used, but 
not when everything happens on a single c-thread:

--main.cpp--
#include 
#include 
#include 
#include 

#include 

void make_file()
{
   std::fstream file("my_test.py", std::ios::out);
   file << 
  "import threading\n"   << 
  "def my_function():\n" << 
  "pass\n" ;
   file.close();
}

void exec()
{
   PyGILState_STATE gstate = PyGILState_Ensure();
   PyObject* pdict = PyDict_New();
   PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());

   PyRun_String("import my_test", Py_file_input, pdict, pdict);
   PyRun_String("my_test.my_function()", Py_file_input, pdict, pdict);
   assert(!PyErr_Occurred());
   PyGILState_Release(gstate);
}

void basic()
{
   std::cout << "--Starting Basic--" << std::endl;

   Py_Initialize();
   PyEval_InitThreads();
   PyThreadState* threadState = PyEval_SaveThread();

   exec();

   PyEval_RestoreThread(threadState);
   Py_Finalize();

   std::cout << "--Basic Complete--" << std::endl;
}

void with_thread()
{
   std::cout << "--Starting With Thread--" << std::endl;

   Py_Initialize();
   PyEval_InitThreads();
   PyThreadState* threadState = PyEval_SaveThread();

   std::thread t(exec);
   t.join();

   PyEval_RestoreThread(threadState);
   Py_Finalize();

   std::cout << "--With Thread Complete--" << std::endl;
}

int main(int argc, char* argv[])
{
   make_file();
   basic();
   with_thread();

   return 0;
}
--main.cpp--

--output--
--Starting Basic--
--Basic Complete--
--Starting With Thread--
Exception ignored in: 
Traceback (most recent call last):
  File "C:\Python34-32\Lib\threading.py", line 1289, in _shutdown
assert tlock.locked()
AssertionError:
--With Thread Complete--
--output--

The order of the basic()/with_thread() calls in main does not matter, I can 
even include those lines multiple times with no affect, each with_thread() call 
results in the error output.

Thanks,
Tom Kent
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: application console with window

2015-01-08 Thread adam
Dennis Lee Bieber wrote:

> On Wed, 07 Jan 2015 22:17:09 +0100, adam 
> declaimed the following:
> 
>>Is in here maybe someone who speak Polish?
>>
>>I would like to write application witch looks like this
>>http://linuxiarze.pl/obrazy/internet1/ceni1.png
>>
> Based upon the image, that is mainly an addressable console application
> with a line-draw character set. Something maybe possible using MS-DOS 3.x
> 
> What OS are you using?
Linux, fedora, debian, centOS, maybe windows 7 or 8.1
> 
>>I'm looking for some libs, tutorials, or other informations.
> 
> Check the documentation for the Python curses library.
> 
Thank you

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


Re: application console with window

2015-01-08 Thread adam
Emil Oppeln-Bronikowski wrote:

> On Wed, Jan 07, 2015 at 10:17:09PM +0100, adam wrote:
>> Is in here maybe someone who speak Polish?
> 
> Mówię, a raczej piszę.
> 
>> I'm looking for some libs, tutorials, or other informations.
> 
> This is terminal application using (n)curses or smilar library that helps
> you draw & interact with windows, forms and other widgets.
> 
> You can use curses library, but it's a little big hairy. There are a few
> extra libraries that make writing "full-screen" terminal application a
> breeze.
> 
> The most popular one (…and complete?) is urwid, and there are pages of
> tutorial once you google for it.
> 
> PS. if you need some help feel free to e-mail me off-list.
> 
thank you,

I just learn python. If you write in Polish it will be easier for me to 
explain any problem, because my English is very thin.

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


Re: application console with window

2015-01-08 Thread Emil Oppeln-Bronikowski
On Thu, Jan 08, 2015 at 05:18:07PM +0100, adam wrote:

> I just learn python.

We all do. It's a constant process.

> If you write in Polish it will be easier for me to 
> explain any problem, because my English is very thin.

I don't really want to force others to read Polish, hit me private if you have 
any questions.

-- 
vag·a·bond adjective \ˈva-gə-ˌbänd\
 a :  of, relating to, or characteristic of a wanderer 
 b :  leading an unsettled, irresponsible, or disreputable life

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


Re: application console with window

2015-01-08 Thread adam
Emil Oppeln-Bronikowski wrote:

> On Thu, Jan 08, 2015 at 05:18:07PM +0100, adam wrote:
> 
>> I just learn python.
> 
> We all do. It's a constant process.
> 
>> If you write in Polish it will be easier for me to
>> explain any problem, because my English is very thin.
> 
> I don't really want to force others to read Polish, hit me private if you
> have any questions.
> 

Ok no problem
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: application console with window

2015-01-08 Thread Chris Warrick
On Thu, Jan 8, 2015 at 5:18 PM, adam  wrote:
> I just learn python. If you write in Polish it will be easier for me to
> explain any problem, because my English is very thin.

You cannot really learn to program without speaking English well.  If
you can’t speak English, you will have lots of issues: it will be
harder to memorize things, you will be writing function/… names
brainlessly and, most importantly, you won’t be able to communicate
with other programmers (as demonstrated here).  English IS the
official language of technology, period. You should improve your
English first if you want to succeed in the industry (or create
anything advanced).

This Usenet newsgroup/mailing list is for English-language discussion
only.  Polish-language communities exist, you can search around if you
want.

As Emil said, urwid is the package to use to create a CLI
(command-line interface).  However, the list of OSes you provided
includes Windows, which makes it very problematic (you would have to
install Cygwin).  You could also switch to a GUI (graphical user
interface) with eg. Tkinter or something else that looks much better
than ugly old Tkinter (eg. PyQT).

---

Nie możesz się nauczyć programować bez dobrej znajomości angielskiego.
Jeśli nie umiesz mówić po angielsku, będziesz miał wiele problemów:
trudniej będzie Ci zapamiętać wszystko, będziesz zapisywał nazwy
funkcji/… bezmyślnie i, co najważniejsze, nie będziesz mógł się
komunikować z innymi programistami (co zostało tu zademonstrowane).
Angielski JEST językiem oficjalnym technologii.  Powinieneś
podszlifować swój angielski jeśli chcesz odnieść sukces w branży (lub
nawet napisać coś bardziej zaawansowanego)

Ta grupa Usenetowa/lista dyskusyjna jest przeznaczona tylko do
dyskusji w języku angielskim.  Grupy w języku polskim na pewno
istnieją, możesz poszukać.

Jak powiedział Emil, powinienieś użyć pakietu urwid jeśli chcesz
utworzyć CLI (interfejs wiersza poleceń).  Na liście systemów
operacyjnych jest Windows, co bardzo utrudnia sprawę (musiałbyś
zainstalować Cygwina).  Możesz też przejść na GUI (graficzny interfejs
użytkownika), np. przy użyciu biblioteki Tkinter lub czegoś innego co
wygląda lepiej niż stary brzydki Tkinter (np. PyQT)

-- 
Chris Warrick 
PGP: 5EAAEA16
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Hello World

2015-01-08 Thread Steve Hayes
On 08 Jan 2015 12:43:33 GMT, [email protected] (Albert van der Horst)
wrote:

>I don't trust sudo because it is too complicated.
>(To the point that I removed it from my machine.)
>I do

How do you do that?

I avoided Ubuntu because it had sudo, and then discovered that Fedora had it
as well. 


-- 
Steve Hayes from Tshwane, South Africa
Web:  http://www.khanya.org.za/stevesig.htm
Blog: http://khanya.wordpress.com
E-mail - see web page, or parse: shayes at dunelm full stop org full stop uk
-- 
https://mail.python.org/mailman/listinfo/python-list


Generate jpg files using line length (pixels) and orientation (degrees)

2015-01-08 Thread semeon . risom
Hello - 

Simple question. I hope.

I have 600 images (jpg) I am trying to generate. Each image will be made up of 
a line, with specific orientation (degrees) and length values (pixel). The 
background will be white (rgb: 255,255,255). I'm hoping each will have a name 
that corresponds to these values (i.e. 500px_600.jpg).

I was wondering if anyone had a piece of code, or at least point me to an 
example that might help.

Thanks,

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


Re: Hello World

2015-01-08 Thread Chris Angelico
On Fri, Jan 9, 2015 at 4:02 AM, Steve Hayes  wrote:
> On 08 Jan 2015 12:43:33 GMT, [email protected] (Albert van der Horst)
> wrote:
>
>>I don't trust sudo because it is too complicated.
>>(To the point that I removed it from my machine.)
>>I do
>
> How do you do that?
>
> I avoided Ubuntu because it had sudo, and then discovered that Fedora had it
> as well.

Uhh, 'apt-get remove sudo'? That ought to work on any Debian-based
system. With Debian itself, you get the option during installation of
setting a root password, in which case it won't install sudo by
default.

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


Re: Hello World

2015-01-08 Thread Michael Torrie
On 01/08/2015 10:02 AM, Steve Hayes wrote:
> On 08 Jan 2015 12:43:33 GMT, [email protected] (Albert van der Horst)
> wrote:
> 
>> I don't trust sudo because it is too complicated.
>> (To the point that I removed it from my machine.)
>> I do
> 
> How do you do that?
> 
> I avoided Ubuntu because it had sudo, and then discovered that Fedora had it
> as well. 

Of all the distro choosing criteria, this has to be one of the more
bizarre ones I've heard.  You could at least choose something
fashionable to avoid, like systemd.

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


Can numpy do better than this?

2015-01-08 Thread Rustom Mody
Given a matrix I want to shift the 1st column 0 (ie leave as is)
2nd by one place, 3rd by 2 places etc.

This code works.
But I wonder if numpy can do it shorter and simpler.

-
def transpose(mat):
 return([[l[i] for l in mat]for i in range(0,len(mat[0]))])
def rotate(mat):
 return([mat[i][i:]+mat[i][:i] for i in range(0, len(mat))])
def shiftcols(mat):
return ( transpose(rotate(transpose(mat

>>> mat = [[1,2,3,4,5,6],
[7,8,9,10,11,12],
[13,14,15,16,17,18],
[19,20,21,22,23,24],
[25,26,27,28,29,30],
[31,32,33,34,35,36],
[37,38,39,40,41,42]]

>>> shiftcols(mat)

[[1, 8, 15, 22, 29, 36],
[7, 14, 21, 28, 35, 42], 
[13, 20, 27, 34, 41, 6], 
[19, 26, 33, 40, 5, 12], 
[25, 32, 39, 4, 11, 18], 
[31, 38, 3, 10, 17, 24], 
[37, 2, 9, 16, 23, 30]]


I was hoping for something like the following APL operator

>>>   mat
 1  2  3  4  5  6
 7  8  9 10 11 12
13 14 15 16 17 18
19 20 21 22 23 24
25 26 27 28 29 30
31 32 33 34 35 36
>>>   0 1 2 3 4 5 ⊖ mat
 1  8 15 22 29 36
 7 14 21 28 35  6
13 20 27 34  5 12
19 26 33  4 11 18
25 32  3 10 17 24
31  2  9 16 23 30
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do I remove/unlink wildcarded files

2015-01-08 Thread Marko Rauhamaa
Rick Johnson :

> If history has taught us anything, it is that, intelligence will
> *ALWAYS* defeat brute strength, and that the *MOST* intelligent
> societies are consequently those who possess both a humbled respect
> for freedom, and a vile rejection of oppression.

Impressive. With such a high percentage of the regular participants
falling for you, I think you have passed the Turing test.

Were you programmed in Python?


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


Re: Comparisons and sorting of a numeric class....

2015-01-08 Thread Chris Kaynor
On Thu, Jan 8, 2015 at 6:57 AM, Ian Kelly  wrote:

> On Wed, Jan 7, 2015 at 11:21 PM, Marko Rauhamaa  wrote:
> > Steven D'Aprano :
> >
> >> Marko Rauhamaa wrote:
> >>> I prefer the Scheme way:
> >>>#f is a falsey object
> >>>everything else is a truthy object
> >>
> >> The Scheme way has no underlying model of what truthiness represents,
> just
> >> an arbitrary choice to make a single value have one truthiness, and
> >> everything else the other. It's just as meaningless and just as
> arbitrary
> >> as the opposite would be:
> >>
> >> #t is True
> >> everything else is falsey
> >> [...]
> >> I'd rather the Pascal way:
> >>
> >> #t is True
> >> #f is False
> >> everything else is an error
> >
> > An advantage of the Scheme way is the chaining of "and" and "or". For
> > example, this breaks in Python:
> >
> >def dir_contents(path):
> >if os.path.isdir(path):
> >return os.listdir(path)
> >return None
> >
> >def get_choices():
> >return dir_contents(PRIMARY) or \
> >dir_contents(SECONDARY) or \
> >[ BUILTIN_PATH ]
>
> That depends on what the function is intended to do in the first
> place. Why would you want to return the contents of an empty directory
> rather than the default?
>
> Anyway, to make that work as you want it in Scheme, dir_contents would
> have to return #f, not None. Does it really make sense for a
> non-predicate function to be returning the value "false"?


I'd like to second this. I don't believe either way is inherently superior
to the other.

Lately, I've been doing quite a bit of work in lua, and many times have
wished that empty strings, tables, and 0 acted "falsey", but at the same
time, previously working in Python, there were plenty of times I wished
they acted "truthy". It merely depends on what algorithm I am using at the
time...
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Hello World

2015-01-08 Thread Grant Edwards
On 2015-01-08, Michael Torrie  wrote:
> On 01/08/2015 10:02 AM, Steve Hayes wrote:
>> On 08 Jan 2015 12:43:33 GMT, [email protected] (Albert van der Horst)
>> wrote:
>> 
>>> I don't trust sudo because it is too complicated. (To the point that
>>> I removed it from my machine.) I do
>> 
>> How do you do that?
>> 
>> I avoided Ubuntu because it had sudo, and then discovered that Fedora
>> had it as well. 
>
> Of all the distro choosing criteria, this has to be one of the more
> bizarre ones I've heard.

That's what I thought.  Especially since it's trivial to remove sudo.

Some system admin stuff on *buntu may require some extra thought since
the standard pointy-clicky recipes might not work exactly as described
in various fora, but anybody worried about security to the extent that
they refuse to use sudo probably shouldn't be using pointy-clicky
admin tools to start with.

> You could at least choose something fashionable to avoid, like
> systemd.

Or whatever the "desktop du jour" is for .

-- 
Grant Edwards   grant.b.edwardsYow! Didn't I buy a 1951
  at   Packard from you last March
  gmail.comin Cairo?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Can numpy do better than this?

2015-01-08 Thread Ian Kelly
On Thu, Jan 8, 2015 at 10:56 AM, Rustom Mody  wrote:
> Given a matrix I want to shift the 1st column 0 (ie leave as is)
> 2nd by one place, 3rd by 2 places etc.
>
> This code works.
> But I wonder if numpy can do it shorter and simpler.
>
> -
> def transpose(mat):
>  return([[l[i] for l in mat]for i in range(0,len(mat[0]))])
> def rotate(mat):
>  return([mat[i][i:]+mat[i][:i] for i in range(0, len(mat))])
> def shiftcols(mat):
> return ( transpose(rotate(transpose(mat

Without using numpy, your transpose function could be:

def transpose(mat):
return list(zip(*mat))

numpy provides the roll function, but it doesn't allow for a varying
shift per index. I don't see a way to do it other than to roll each
column separately:

>>> mat = np.array([[1,2,3,4,5,6],
... [7,8,9,10,11,12],
... [13,14,15,16,17,18],
... [19,20,21,22,23,24],
... [25,26,27,28,29,30],
... [31,32,33,34,35,36],
... [37,38,39,40,41,42]])
>>> res = np.empty_like(mat)
>>> for i in range(mat.shape[1]):
... res[:,i] = np.roll(mat[:,i], -i, 0)
...
>>> res
array([[ 1,  8, 15, 22, 29, 36],
   [ 7, 14, 21, 28, 35, 42],
   [13, 20, 27, 34, 41,  6],
   [19, 26, 33, 40,  5, 12],
   [25, 32, 39,  4, 11, 18],
   [31, 38,  3, 10, 17, 24],
   [37,  2,  9, 16, 23, 30]])
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Comparisons and sorting of a numeric class....

2015-01-08 Thread Marko Rauhamaa
Ian Kelly :

>> An advantage of the Scheme way is the chaining of "and" and "or". For
>> example, this breaks in Python:
>>
>>def dir_contents(path):
>>if os.path.isdir(path):
>>return os.listdir(path)
>>return None
>>
>>def get_choices():
>>return dir_contents(PRIMARY) or \
>>dir_contents(SECONDARY) or \
>>[ BUILTIN_PATH ]
>
> That depends on what the function is intended to do in the first
> place. Why would you want to return the contents of an empty directory
> rather than the default?

To demonstrate the principle. Such short-circuited expressions have
spread to numerous high-level programming languages. Python has them,
too, but you have to be extra careful not to be hit by the surprising
false interpretations.

> Anyway, to make that work as you want it in Scheme, dir_contents would
> have to return #f, not None. Does it really make sense for a
> non-predicate function to be returning the value "false"?

By custom, #f acts as the de-facto None of Scheme for that very reason.
In classic Lisp, nil takes the roles of None, False and [], leading to
the confusion I mentioned.

Of course, Scheme now has to deal with distinguishing None (#f) and
False (#f as well). Luckily, that confusion rarely comes to play.


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


exporting c_variable to embedded python module

2015-01-08 Thread kenakahn
I'm running a python script loaded via PyImport_Import in my C++ program on 
Linux.  Is there any way I can pass a value from the c-code to the loaded 
python module?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Generate jpg files using line length (pixels) and orientation (degrees)

2015-01-08 Thread Denis McMahon
On Thu, 08 Jan 2015 09:09:18 -0800, semeon.risom wrote:

> Simple question. I hope. .

We just covered this in the PHP newsgroup where you were trying to use a 
PHP library to generate these images.

As your library code is written in PHP, I suggest you return to the 
discussion there unless you plan to rewrite your library in Python, and 
I'd point out now that the level of programming ability you've 
demonstrated so far in the PHP group does not bode well for you 
attempting to rewrite the PHP library code as Python!

You were given a complete PHP solution to your problem, showing different 
ways to loop through your variables.

-- 
Denis McMahon, [email protected]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Announce: PyPrimes 0.2.1a

2015-01-08 Thread Irmen de Jong
On 8-1-2015 12:16, Steven D'Aprano wrote:

> I screwed up the upload to PyPI, and it won't allow you to upload the same
> version twice. (At least, I don't know of any way to do so.) So I had to
> bump the version number to re-upload.

You can manually log into PyPI and fix the uploaded files using the web 
interface.

There also seems to be an issue with the version number, if I pip install 
pyprimes, I
get the 0.1 version. I have to tell pip to allow prerelease versions to get 
your new
version. I think it is because of the 'a' after the version number.


Irmen

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


Re: application console with window

2015-01-08 Thread jacek pozniak
adam wrote:

> Hej, no właśnie niechodzi o przeniesienie do okienek tylko jeśli znasz
> taki program jak np fk dla dos-a to chodzi mi o taki efekt. Czyli
> aplikacja konsolowa z pseudo okienkami.
Napisz sobie w bashu z wykorzystaniem programu dialog (man dialog) i 
ewntualnym wołaniem skryptów pythona o ile zajdzie taka potrzeba.


jp

> 
> Adam
> 
> jacek pozniak wrote:
> 
>> adam wrote:
>> 
>>> Is in here maybe someone who speak Polish?
>>> 
>>> I would like to write application witch looks like this
>>> http://linuxiarze.pl/obrazy/internet1/ceni1.png
>> Jeśli chodzi Ci o przeniesienie na wersję okienkową to na przykład:
>> tkinter.
>> 
>> jp
>> 
>>> 
>>> I'm looking for some libs, tutorials, or other informations.
>>> I'm searching this informations for python3.
>>> 
>>> adam

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


PyDev 3.9.1 Released

2015-01-08 Thread Fabio Zadrozny
What is PyDev?
---

PyDev is an open-source Python IDE on top of Eclipse for Python, Jython and
IronPython development.

It comes with goodies such as code completion, syntax highlighting, syntax
analysis, code analysis, refactor, debug, interactive console, etc.

Details on PyDev: http://pydev.org
Details on its development: http://pydev.blogspot.com


What is LiClipse?
---

LiClipse is a PyDev standalone with goodies such as support for Multiple
cursors, theming and a number of other languages such as Django Templates,
Kivy Language, Mako Templates, Html, Javascript, etc.

It's also a commercial counterpart which helps supporting the development
of PyDev.

Details on LiClipse: http://www.liclipse.com/


Release Highlights:
---

* **Important**: PyDev requires Eclipse 3.8 or 4.3 onwards and Java 7! For
older versions, keep using PyDev 2.x (use LiClipse: http://www.liclipse.com
for a PyDev standalone with all requirements bundled).

* **Preferences**

  * PyDev preferences may now be saved and persisted for each project or in
the user settings (not just in the workspace).
  * Currently Save actions, Code Formatter, Typing and Imports are
supported (more to come in upcoming releases).
  * The same pages in the preferences are used to save settings to
(multiple) projects or user settings.
  * Configuration files are saved in Yaml format and are meant to be saved
in version control.

* **Editor**

  * The option to apply auto-formating was changed to apply any save
actions in non-workspace files.
  * Editor icon improved for dark theme (patch by Fathony Luthfillah).
  * When running the pep8 code analysis, the markers shown are no longer 1
character off.

* **Django**

  * Improved Django 1.7 support (patch by David Lehrian).

* **Profiling**

  * Integration with PyVmMonitor: http://pyvmmonitor.github.io/ (currently
only available for backers of the effort).

* A profiling view was created where the location of PyVmMonitor should
be specified.
* Just turning the option on will make all runs from that point on run
with the selected profile backend enabled.

* **Debugger**

  * Connecting to subprocesses working in Python 3.4.
  * Attach to running process is now supported on Mac OS.

* **Others**

  * Unset VIRTUAL_ENV before running external Python to protect the
sys.path (patch by James Blackburn).
  * pytest: Expected failure is no longer marked as a failure.
  * pytest: The working dir is changed so that conftests are loaded
properly (to workaround issue in pytest:
https://bitbucket.org/hpk42/pytest/issue/639/conftest-being-loaded-twice-giving
).
  * Fixed issue where an unused import would not be properly removed if it
was not a from import.
  * Fixed exception when drawing minimap overview ruler.


Cheers,

--
Fabio Zadrozny
--
Software Developer

LiClipse
http://www.liclipse.com

PyDev - Python Development Environment for Eclipse
http://pydev.org
http://pydev.blogspot.com

PyVmMonitor - Python Profiler
http://pyvmmonitor.github.io/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: exporting c_variable to embedded python module

2015-01-08 Thread Chris Angelico
On Fri, Jan 9, 2015 at 8:03 AM,   wrote:
> I'm running a python script loaded via PyImport_Import in my C++ program on 
> Linux.  Is there any way I can pass a value from the c-code to the loaded 
> python module?

To answer this question, first think about how you would like to see
that value on the Python side. Does your C code call a function in
that module? If so, it can pass it a parameter. Or do you want the
top-level import to be aware of something? It might be best to put
something into another module, maybe even builtins. What makes sense
from the Python end? Pretty much anything can be done.

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


PyPI files should not change their payload (was: Announce: PyPrimes 0.2.1a)

2015-01-08 Thread Ben Finney
Steven D'Aprano  writes:

> I screwed up the upload to PyPI, and it won't allow you to upload the
> same version twice. (At least, I don't know of any way to do so.) So I
> had to bump the version number to re-upload.

There is currently a hack that can be done (I won't say what it is) to
upload a different payload with the same filename. Please don't do it.

This is widely regarded, and I agree, as a bug: once PyPI has a file of
a particular name (including the package version), that filename should
only ever refer to that same content and never anything else.

Over at ‘distutils-sig’, way back in 2014-09, a discussion reached the
consensus that the current undocumented ability to change the payload of
an existing file from PyPI is an oversight that needs to be closed
https://mail.python.org/pipermail/distutils-sig/2014-September/024890.html>,
with the Python Packaging Authority making its position known at
https://mail.python.org/pipermail/distutils-sig/2014-September/024921.html>:

Silently changing released artefacts is actively user hostile. It
breaks mirroring, it breaks redistribution, it breaks security
audits, and it can even break installation for security conscious
users that are using peep rather than pip.
[…]

I am thoroughly *against* retaining a general capability to silently
substitute the contents of previously released files with a
different payload solely to handle the case of packaging errors that
aren't otherwise severe enough to warrant bumping the version number
[…].

So, it seems you did the right thing in uploading different package
source content with a later version string.

The issue of remembering to update the Changelog document is another
matter, which I'll address in a different message.

-- 
 \ “Capitalism has destroyed our belief in any effective power but |
  `\  that of self interest backed by force.” —George Bernard Shaw |
_o__)  |
Ben Finney

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


Using a ChangeLog as a canonical source of package metadata (was: Announce: PyPrimes 0.2.1a)

2015-01-08 Thread Ben Finney
Steven D'Aprano  writes:

> Ben Finney wrote:
> > The source has a ‘CHANGES.txt’ file which has no entry later than
> > version 0.2a. Why was the later version made, and when will the
> > change log be updated for that?
>
> Ah, I knew I forgot something!

The perils of duplicate sources of information: a Changelog makes claims
about which version is latest, but the packaging metadata comes from
somewhere else.

This problem is addressed quite well, in my opinion, by the Debian
packaging tools. The tools by default read the following information:

* release version string
* maintainer name
* maintainer email address
* target suite (a conceptual “which Debian version should this go into”)

from the Changelog document, automatically. This means that the
Changelog document, as well as being directly useful to the recipient as
a text document, becomes the canonical place to record all those fields
for the packaging tools to read. No need to maintain duplicate records.


I would like Python's packaging tools to have the same capability.

This requires recording the Changelog document in a machine-parseable
format, with specified locations for each of the fields to be read for
each version.

I have recently gone through a process of converting the Changelog for a
package I maintain (‘python-daemon’) to reStructuredText [0]. This has
all the above features: machine-parseable, a well-defined way to attach
fields to a section, etc.

[0] reStructuredText: http://docutils.sourceforge.net/rst.html>

I've now produced a small Python library which knows how to transform a
reST Changelog to package metadata; and how to get that package metadata
into and out of a Python distribution with Distutils.

The result is that I will never again upload the package with a mismatch
between what the Changelog claims is the latest version, and what the
package metadata says.


This may be generally useful to others. I'm interested to know how
people would expect to use this. As an extension to Distutils? As a
third-party library? Something else?

-- 
 \  “Nullius in verba” (“Take no-one's word for it”) —motto of the |
  `\   Royal Society, since 1663-06-30 |
_o__)  |
Ben Finney

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


Re: Using a ChangeLog as a canonical source of package metadata (was: Announce: PyPrimes 0.2.1a)

2015-01-08 Thread Chris Angelico
On Fri, Jan 9, 2015 at 11:06 AM, Ben Finney  wrote:
> I've now produced a small Python library which knows how to transform a
> reST Changelog to package metadata; and how to get that package metadata
> into and out of a Python distribution with Distutils.
>
> The result is that I will never again upload the package with a mismatch
> between what the Changelog claims is the latest version, and what the
> package metadata says.
>
>
> This may be generally useful to others. I'm interested to know how
> people would expect to use this. As an extension to Distutils? As a
> third-party library? Something else?

I can't speak as a package maintainer (because I'm not one), but
speaking as an end user, I'm in favour of anything that guarantees
consistency like that. It's only occasionally an issue, but for
instance, if I clone someone's source code repository and then install
a package from there, it's not necessarily obvious from 'pip freeze'
that I have something that can't so easily be downloaded. If the
Changelog were guaranteed to show that, then I could easily see what's
going on (eg if a new entry is created, immediately after the version
release, adding an alpha version tag).

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


Re: PyPI files should not change their payload (was: Announce: PyPrimes 0.2.1a)

2015-01-08 Thread Steven D'Aprano
Ben Finney wrote:

> Steven D'Aprano  writes:
> 
>> I screwed up the upload to PyPI, and it won't allow you to upload the
>> same version twice. (At least, I don't know of any way to do so.) So I
>> had to bump the version number to re-upload.
> 
> There is currently a hack that can be done (I won't say what it is) to
> upload a different payload with the same filename. Please don't do it.

I had thought that I screwed up the metadata, but it turns out I didn't.
When I discovered pip was picking the wrong version number, selecting a
four year old 0.1 version instead of the newly uploaded 0.2 version,
googling suggested that the problem might have been that I had not run

python setup.py register

before the upload:

python setup.py sdist bdist_wininst upload

and that re-uploading would fix the problem. So I ended up bumping the
version number so I could re-register and re-upload, but that didn't fix
the problem with pip. (Oh Google, why hast thou failed me???)

 
> This is widely regarded, and I agree, as a bug: once PyPI has a file of
> a particular name (including the package version), that filename should
> only ever refer to that same content and never anything else.

If "content" means source code and related program data, I agree, but we
should be able to adjust incorrect metadata without a version bump.

[...]
> The issue of remembering to update the Changelog document is another
> matter, which I'll address in a different message.

Yes please.



-- 
Steven

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


Re: Announce: PyPrimes 0.2.1a

2015-01-08 Thread Steven D'Aprano
Irmen de Jong wrote:

> On 8-1-2015 12:16, Steven D'Aprano wrote:
> 
>> I screwed up the upload to PyPI, and it won't allow you to upload the
>> same version twice. (At least, I don't know of any way to do so.) So I
>> had to bump the version number to re-upload.
> 
> You can manually log into PyPI and fix the uploaded files using the web
> interface.

Thanks.

 
> There also seems to be an issue with the version number, if I pip install
> pyprimes, I get the 0.1 version. I have to tell pip to allow prerelease
> versions to get your new version. I think it is because of the 'a' after
> the version number.

Yes, I mentioned this in my announcement here.

Is there a good tutorial to learn about pip? Everything I've seen so far
seems to be of one of two extremes, either:

"pip is awesome, just run 'pip install packagename' and it cannot fail!!!1!"

or 

"oh, pip did the wrong thing again? you can fix that by standing on one leg,
sacrificing a goat to the Great Old Dark Ones, deleting these files, or
possibly some other ones, and if the phase of the moon is exactly right it
will behave as you want..."

I know that pip is Officially The Best Thing Evar, but my experience so far
has been less than satisfactory.



-- 
Steven

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


Re: Announce: PyPrimes 0.2.1a

2015-01-08 Thread Chris Angelico
On Fri, Jan 9, 2015 at 11:41 AM, Steven D'Aprano
 wrote:
> "oh, pip did the wrong thing again? you can fix that by standing on one leg,
> sacrificing a goat to the Great Old Dark Ones, deleting these files, or
> possibly some other ones, and if the phase of the moon is exactly right it
> will behave as you want..."

Replacing an existing package, without changing the version number,
*is* messy. It's not pip's fault that it's hard. That's like saying
"Oops, I committed this to source control and pushed it out to all
users, but there's a big file in it and I want to delete it so they
don't have to download it". Sure, that's possible, but it's not a
normal action, so you'll have to jump through some hoops to make it
all work properly.

Or have you been having this whole sacrificing a goat thing with a
normal workflow?

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


Where to learn current best Python packaging practices (was: Announce: PyPrimes 0.2.1a)

2015-01-08 Thread Ben Finney
Steven D'Aprano  writes:

> Is there a good tutorial to learn about pip?

I'll answer what I think is the correct question: where to learn about
the current best Python packaging practices.

We have recently gained an official body whose explicit job is to
direct, and be opinionated about, packaging Python software: the Python
Packaging Authority https://www.pypa.io/>.

One of their many beneficial outputs is the Python Packaging User Guide
https://python-packaging-user-guide.readthedocs.org/>.

> I know that pip is Officially The Best Thing Evar, but my experience
> so far has been less than satisfactory.

For a very long time, Python packaging was in a truly awful state, and
seemed to get even worse with time. That is now reversed though (IMO),
and ‘pip’ does indeed represent the Best Thing So Far™ for Python
package installation.

That does not contradict the position that it's an ornery beast full of
hidden traps and compromises though; it just means that everything that
came before it (in Python) is worse :-)

Seriously, even those who believe they know a lot about Python packaging
will benefit greatly from learning about the sweeping improvements that
have been made in the past handful of years. Get thee to the Python
Packaging Authority resources and learn where we're at, and how far we
have to go.

-- 
 \   “You can stand tall without standing on someone. You can be a |
  `\ victor without having victims.” —Harriet Woods, 1927–2007 |
_o__)  |
Ben Finney

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


Re: Can numpy do better than this?

2015-01-08 Thread Rustom Mody
On Friday, January 9, 2015 at 12:58:52 AM UTC+5:30, Ian wrote:
> On Thu, Jan 8, 2015 at 10:56 AM, Rustom Mody wrote:
> > Given a matrix I want to shift the 1st column 0 (ie leave as is)
> > 2nd by one place, 3rd by 2 places etc.
> >
> > This code works.
> > But I wonder if numpy can do it shorter and simpler.
> >
> > -
> > def transpose(mat):
> >  return([[l[i] for l in mat]for i in range(0,len(mat[0]))])
> > def rotate(mat):
> >  return([mat[i][i:]+mat[i][:i] for i in range(0, len(mat))])
> > def shiftcols(mat):
> > return ( transpose(rotate(transpose(mat
> 
> Without using numpy, your transpose function could be:
> 
> def transpose(mat):
> return list(zip(*mat))
> 
> numpy provides the roll function, but it doesn't allow for a varying
> shift per index. I don't see a way to do it other than to roll each
> column separately:
> 
> >>> mat = np.array([[1,2,3,4,5,6],
> ... [7,8,9,10,11,12],
> ... [13,14,15,16,17,18],
> ... [19,20,21,22,23,24],
> ... [25,26,27,28,29,30],
> ... [31,32,33,34,35,36],
> ... [37,38,39,40,41,42]])
> >>> res = np.empty_like(mat)
> >>> for i in range(mat.shape[1]):
> ... res[:,i] = np.roll(mat[:,i], -i, 0)
> ...
> >>> res
> array([[ 1,  8, 15, 22, 29, 36],
>[ 7, 14, 21, 28, 35, 42],
>[13, 20, 27, 34, 41,  6],
>[19, 26, 33, 40,  5, 12],
>[25, 32, 39,  4, 11, 18],
>[31, 38,  3, 10, 17, 24],
>[37,  2,  9, 16, 23, 30]])

Thanks Ian!
With that I came up with the expression

transpose(array([list(roll(mat[:,i],i,0)) for i in range(mat.shape[1])]))

Not exactly pretty.
My hunch is it can be improved??...
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Can numpy do better than this?

2015-01-08 Thread Rustom Mody
On Friday, January 9, 2015 at 6:43:45 AM UTC+5:30, Rustom Mody wrote:
> On Friday, January 9, 2015 at 12:58:52 AM UTC+5:30, Ian wrote:
> > On Thu, Jan 8, 2015 at 10:56 AM, Rustom Mody wrote:
> > > Given a matrix I want to shift the 1st column 0 (ie leave as is)
> > > 2nd by one place, 3rd by 2 places etc.
> > >
> > > This code works.
> > > But I wonder if numpy can do it shorter and simpler.
> > >
> > > -
> > > def transpose(mat):
> > >  return([[l[i] for l in mat]for i in range(0,len(mat[0]))])
> > > def rotate(mat):
> > >  return([mat[i][i:]+mat[i][:i] for i in range(0, len(mat))])
> > > def shiftcols(mat):
> > > return ( transpose(rotate(transpose(mat
> > 
> > Without using numpy, your transpose function could be:
> > 
> > def transpose(mat):
> > return list(zip(*mat))
> > 
> > numpy provides the roll function, but it doesn't allow for a varying
> > shift per index. I don't see a way to do it other than to roll each
> > column separately:
> > 
> > >>> mat = np.array([[1,2,3,4,5,6],
> > ... [7,8,9,10,11,12],
> > ... [13,14,15,16,17,18],
> > ... [19,20,21,22,23,24],
> > ... [25,26,27,28,29,30],
> > ... [31,32,33,34,35,36],
> > ... [37,38,39,40,41,42]])
> > >>> res = np.empty_like(mat)
> > >>> for i in range(mat.shape[1]):
> > ... res[:,i] = np.roll(mat[:,i], -i, 0)
> > ...
> > >>> res
> > array([[ 1,  8, 15, 22, 29, 36],
> >[ 7, 14, 21, 28, 35, 42],
> >[13, 20, 27, 34, 41,  6],
> >[19, 26, 33, 40,  5, 12],
> >[25, 32, 39,  4, 11, 18],
> >[31, 38,  3, 10, 17, 24],
> >[37,  2,  9, 16, 23, 30]])
> 
> Thanks Ian!
> With that I came up with the expression
> 
> transpose(array([list(roll(mat[:,i],i,0)) for i in range(mat.shape[1])]))

That is numpy transpose of course (following a 'from numpy import *')
Not a vanilla (list) transpose
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Can numpy do better than this?

2015-01-08 Thread Ian Kelly
On Thu, Jan 8, 2015 at 6:13 PM, Rustom Mody  wrote:
> With that I came up with the expression
>
> transpose(array([list(roll(mat[:,i],i,0)) for i in range(mat.shape[1])]))
>
> Not exactly pretty.
> My hunch is it can be improved??...

Hmm, you could use the column_stack constructor to avoid having to
transpose the array.

>>> np.column_stack(np.roll(mat[:,i],i,0) for i in range(mat.shape[1]))
array([[ 1, 38, 33, 28, 23, 18],
   [ 7,  2, 39, 34, 29, 24],
   [13,  8,  3, 40, 35, 30],
   [19, 14,  9,  4, 41, 36],
   [25, 20, 15, 10,  5, 42],
   [31, 26, 21, 16, 11,  6],
   [37, 32, 27, 22, 17, 12]])
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Where to learn current best Python packaging practices (was: Announce: PyPrimes 0.2.1a)

2015-01-08 Thread Rustom Mody
On Friday, January 9, 2015 at 6:42:18 AM UTC+5:30, Ben Finney wrote:
> Steven D'Aprano writes:
> 
> > Is there a good tutorial to learn about pip?
> 
> I'll answer what I think is the correct question: where to learn about
> the current best Python packaging practices.

In order to attain to full ISO 9000 buzzword compliance, how about calling it 
python-devops?
> 
> We have recently gained an official body whose explicit job is to
> direct, and be opinionated about, packaging Python software: the Python
> Packaging Authority https://www.pypa.io/>.
> 
> One of their many beneficial outputs is the Python Packaging User Guide
> https://python-packaging-user-guide.readthedocs.org/>.

Thanks
I need to look at that

Maybe good to also have something linking 'pure' python packaging with
debian python packaging
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Where to learn current best Python packaging practices (was: Announce: PyPrimes 0.2.1a)

2015-01-08 Thread Rick Johnson
On Thursday, January 8, 2015 at 7:12:18 PM UTC-6, Ben Finney wrote:

> That does not contradict the position that [python
> packaging] is an ornery beast full of hidden traps and
> compromises though; it just means that everything that
> came before it (in Python) is worse

Ben, you've just proven the old truism of: 

"When you're at the bottom, the only way you can go is up!"


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


Re: where in Nan defined

2015-01-08 Thread Steven D'Aprano
Chris Angelico wrote:

> On Fri, Jan 9, 2015 at 1:50 AM, Jussi Piitulainen
>  wrote:
>>>>> 0*1e400
>>nan
> 
> Nice, that's shorter than mine.

o_O

Is that really the sort of thing you should be revealing here?

Oh wait, you're talking about code...

I'm not entirely sure, but I suspect that 0*1e400 may not be quite as
portable as your inf-inf. By the rules of IEEE-754 arithmetic, inf-inf has
to return a NAN, but if your floats have sufficient precision available to
represent 1e400, 0*1e400 might return 0.

The fallback rule I use when float('nan') fails is

INF = 1e3000  # Hopefully, this should overflow to INF.
NAN = INF-INF  # And this hopefully will give a NaN.



-- 
Steven

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


Re: Can numpy do better than this?

2015-01-08 Thread Rustom Mody
On Friday, January 9, 2015 at 7:07:26 AM UTC+5:30, Ian wrote:
> On Thu, Jan 8, 2015 at 6:13 PM, Rustom Mody wrote:
> > With that I came up with the expression
> >
> > transpose(array([list(roll(mat[:,i],i,0)) for i in range(mat.shape[1])]))
> >
> > Not exactly pretty.
> > My hunch is it can be improved??...
> 
> Hmm, you could use the column_stack constructor to avoid having to
> transpose the array.
> 
> >>> np.column_stack(np.roll(mat[:,i],i,0) for i in range(mat.shape[1]))
> array([[ 1, 38, 33, 28, 23, 18],
>[ 7,  2, 39, 34, 29, 24],
>[13,  8,  3, 40, 35, 30],
>[19, 14,  9,  4, 41, 36],
>[25, 20, 15, 10,  5, 42],
>[31, 26, 21, 16, 11,  6],
>[37, 32, 27, 22, 17, 12]])

You are my sweetheart!

Removing Javaish-dot-noise:

column_stack(roll(mat[:,i],i,0) for i in range(mat.shape[1]))
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: where in Nan defined

2015-01-08 Thread Chris Angelico
On Fri, Jan 9, 2015 at 12:46 PM, Steven D'Aprano
 wrote:
> Chris Angelico wrote:
>
>> On Fri, Jan 9, 2015 at 1:50 AM, Jussi Piitulainen
>>  wrote:
>>>>>> 0*1e400
>>>nan
>>
>> Nice, that's shorter than mine.
>
> I'm not entirely sure, but I suspect that 0*1e400 may not be quite as
> portable as your inf-inf. By the rules of IEEE-754 arithmetic, inf-inf has
> to return a NAN, but if your floats have sufficient precision available to
> represent 1e400, 0*1e400 might return 0.
>
> The fallback rule I use when float('nan') fails is
>
> INF = 1e3000  # Hopefully, this should overflow to INF.
> NAN = INF-INF  # And this hopefully will give a NaN.

The first question is "will 1eN overflow to inf?". I'm fairly sure
Python guarantees that an unrepresentable float constant will be
treated as infinity, so all you have to do is crank up the exponent
any time you suspect it'll be representable. The second is "will 0*inf
result in nan?", and I would expect that to be as reliable as INF-INF.

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


Re: application console with window

2015-01-08 Thread Rick Johnson
On Thursday, January 8, 2015 at 10:54:22 AM UTC-6, Chris Warrick wrote:
> On Thu, Jan 8, 2015 at 5:18 PM, adam wrote:
> > I just learn python. If you write in Polish it will be easier for me to
> > explain any problem, because my English is very thin.
> 
> You cannot really learn to program without speaking English well.  If
> you can't speak English, you will have lots of issues: it will be
> harder to memorize things, you will be writing function/... names
> brainlessly and, most importantly, you won't be able to communicate
> with other programmers (as demonstrated here).  English IS the
> official language of technology, period. You should improve your
> English first if you want to succeed in the industry (or create
> anything advanced).

Although your response will most likely illicit rebukes from
the bleeding-heart emotional little whine bags, i must say i
agree 100%, and i'm overjoyed to witness someone besides
myself who has the testicular fortitude to speak the truth!

YOU SIR, ARE MY "HERO OF THE YEAR"!

Listen folks, we are not trying to be imperialist here, we
did not "personally" choose for English to be the "lingua
franca" of the world, but that *IS* the reality in which we
live.

If the Chinese or Russians had set up colonies around the
would, instead of the western Europeans, we'd all be
speaking Chinese or Russian today. The whining about who won
is just a waste of time. Instead of being sore losers, we
need to intelligently play the hand we were dealt. Besides,
there is an old Chinese proverb that goes something like:

"If you wait long enough on the river bank, 
the bodies of your enemies will float by"

What does that mean? It means that those who win today will
eventually lose -- this is the way of the universe. The
universe is using all of us as pawns, we are all in this
*together*, and all we can do is do our best with what we
are given. So stop whining and start communicating! All we
need to do is keep talking...

https://www.youtube.com/watch?v=tS-qsh6eTik 

Anytime we can break down barriers to communication, we will
*ALL* benefit from the synergy of ideas.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: where in Nan defined

2015-01-08 Thread Ian Kelly
On Thu, Jan 8, 2015 at 7:07 PM, Chris Angelico  wrote:
> On Fri, Jan 9, 2015 at 12:46 PM, Steven D'Aprano
>> The fallback rule I use when float('nan') fails is
>>
>> INF = 1e3000  # Hopefully, this should overflow to INF.
>> NAN = INF-INF  # And this hopefully will give a NaN.
>
> The first question is "will 1eN overflow to inf?". I'm fairly sure
> Python guarantees that an unrepresentable float constant will be
> treated as infinity, so all you have to do is crank up the exponent
> any time you suspect it'll be representable.

Or to never have to worry about it:

INF = 1e400
while not math.isinf(INF):
INF *= INF
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: exporting c_variable to embedded python module

2015-01-08 Thread kenakahn
I want to access c-side global variables from the python side.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: where in Nan defined

2015-01-08 Thread Chris Angelico
On Fri, Jan 9, 2015 at 1:12 PM, Ian Kelly  wrote:
> Or to never have to worry about it:
>
> INF = 1e400
> while not math.isinf(INF):
> INF *= INF

With no imports whatsoever:

inf = 1e400
nan = inf-inf
while nan == nan:
inf *= inf
nan = inf-inf

But now we're getting stupid :)

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


Decimals and other numbers

2015-01-08 Thread Devin Jeanpierre
I noticed some very PHP-ish behavior today:

>>> import decimal
>>> x = 0
>>> y = float(x)
>>> z = decimal.Decimal(x)
>>> x == y == z == x
True
>>> x ** x
1
>>> y**y
1.0
>>> z**z
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python2.7/decimal.py", line 2216, in __pow__
return context._raise_error(InvalidOperation, '0 ** 0')
  File "/usr/lib/python2.7/decimal.py", line 3872, in _raise_error
raise error(explanation)
decimal.InvalidOperation: 0 ** 0


I'd file a bug report but I'm anticipating some rational (heh)
explanation. Any ideas?

Python 3.4 also raises this exception, but the error message is less
informative. ("decimal.InvalidOperation: []").

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


Re: Where to learn current best Python packaging practices

2015-01-08 Thread Ben Finney
Rick Johnson  writes:

> On Thursday, January 8, 2015 at 7:12:18 PM UTC-6, Ben Finney wrote:
>
> > That does not contradict the position that [python packaging] is an
> > ornery beast full of hidden traps and compromises though; it just
> > means that everything that came before it (in Python) is worse

That's a mis-quoting of what I said. I was referring specifically to
‘pip’ there (i.e. that ‘pip’ is both an ornery beast, and that
everything which came before it in Python is worse). I did not say, and
do not claim, that for Python's packaging.

> Ben, you've just proven the old truism of: 
> "When you're at the bottom, the only way you can go is up!"

And you've just proven the truism that it is easy to interpret someone
as supporting a position if you're willing to change what they actually
wrote.

-- 
 \ “I call him Governor Bush because that's the only political |
  `\  office he's ever held legally.” —George Carlin, 2008 |
_o__)  |
Ben Finney

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


Re: Decimals and other numbers

2015-01-08 Thread Ben Finney
Devin Jeanpierre  writes:

> decimal.InvalidOperation: 0 ** 0
>
> I'd file a bug report but I'm anticipating some rational (heh)
> explanation. Any ideas?

First note that it's explicitly documented as an invalid operation
.
So someone has at least thought about it and deliberately decided it
should be so.

Why that should be, I don't know; I think the correct behaviour is for
‘0 ** 0 == 1’. But perhaps someone else has a better explanation for why
Decimal should behave differently from ‘int’ and ‘float’ here.

-- 
 \  “I bought a self learning record to learn Spanish. I turned it |
  `\on and went to sleep; the record got stuck. The next day I |
_o__)   could only stutter in Spanish.” —Steven Wright |
Ben Finney

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


Re: Decimals and other numbers

2015-01-08 Thread Dave Angel

On 01/08/2015 09:33 PM, Devin Jeanpierre wrote:

I noticed some very PHP-ish behavior today:


import decimal
x = 0
y = float(x)
z = decimal.Decimal(x)
x == y == z == x

True

x ** x

1

y**y

1.0

z**z

Traceback (most recent call last):
   File "", line 1, in 
   File "/usr/lib/python2.7/decimal.py", line 2216, in __pow__
 return context._raise_error(InvalidOperation, '0 ** 0')
   File "/usr/lib/python2.7/decimal.py", line 3872, in _raise_error
 raise error(explanation)
decimal.InvalidOperation: 0 ** 0


I'd file a bug report but I'm anticipating some rational (heh)
explanation. Any ideas?

Python 3.4 also raises this exception, but the error message is less
informative. ("decimal.InvalidOperation: []").



What you don't say is which behavior you actually expected.  Since 0**0 
is undefined mathematically, I'd expect either an exception or a NAN result.



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


Re: Decimals and other numbers

2015-01-08 Thread Chris Rebert
On Thu, Jan 8, 2015 at 6:33 PM, Devin Jeanpierre  wrote:
> I noticed some very PHP-ish behavior today:
>
 import decimal
 x = 0
 y = float(x)
 z = decimal.Decimal(x)
 x == y == z == x
> True
 x ** x
> 1
 y**y
> 1.0
 z**z
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "/usr/lib/python2.7/decimal.py", line 2216, in __pow__
> return context._raise_error(InvalidOperation, '0 ** 0')
>   File "/usr/lib/python2.7/decimal.py", line 3872, in _raise_error
> raise error(explanation)
> decimal.InvalidOperation: 0 ** 0
>
> I'd file a bug report but I'm anticipating some rational (heh)
> explanation. Any ideas?

The `decimal` std lib module implements the General Decimal Arithmetic
Specification (http://speleotrove.com/decimal/decarith.html ).
In the "Exceptional conditions" section
(http://speleotrove.com/decimal/daexcep.html ), it specifies the
following:
Invalid operation
This occurs and signals invalid-operation if:
[...]
* both operands of the power operation are zero

No idea why it chose to differ from IEEE-754.

Cheers,
Chris
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Generate jpg files using line length (pixels) and orientation (degrees)

2015-01-08 Thread Denis McMahon
On Thu, 08 Jan 2015 22:07:03 +, Denis McMahon wrote:

> On Thu, 08 Jan 2015 09:09:18 -0800, semeon.risom wrote:
> 
>> Simple question. I hope. .

To follow up, below is a solution to the problem you stated.

#!/usr/bin/python

import Image, ImageDraw, math

def makeimg(length, orientation):
"""
Make an image file of a black 4 pixel wide line of defined length 
crossing and centered on a white background of 800 px square, save
as a png file identifying line length and orientation in the file 
name.
param length - pixels, length of the line
param orientation - degrees, orientation ccw of the line from +ve x 
axis
Files are saved in imgs subdir, this must already exist.
File name is image_lll_ooo.jpg
lll = length, ooo = orientation, both 0 padded to 3 digits
"""

# check length is +ve and not greater than 800
if length < 0:
length = length * -1
if length > 800:
length = 800

# check orientation is positive in range 0 .. 179
while orientation < 0:
orientation = orientation + 360
if orientation > 179:
orientation = orientation % 180

# calculate radius in pixels and orientation in radians
radius = length / 2
orient = math.radians(orientation)

# calculate xy coords in image space of line end points
x1 = int(400 + (radius * math.cos(orient)))
y1 = int(400 - (radius * math.sin(orient)))
x2 = int(400 + (-radius * math.cos(orient)))
y2 = int(400 - (-radius * math.sin(orient)))

# create an image
img = Image.new('RGB', (800,800), 'rgb(255, 255, 255)')
# create a draw interface
draw = ImageDraw.Draw(img)

# draw the line on the image
draw.line([(x1, y1), (x2, y2)], fill='rgb(0, 0, 0)', width=4)

# determine file name, save image file
fn = 'imgs/image_{:03d}_{:03d}.jpg'.format(length,orientation)
img.save(fn)

# stepping through ranges of values
for length in range(100, 601, 100):
for orientation in range(0, 171, 10):
makeimg(length, orientation)

# using lists of values
for length in [50, 150, 250, 350, 450, 550, 650]:
for orientation in [0, 15, 40, 45, 60, 75, 90, 105, 120, 135, 150, 
165]:
makeimg(length, orientation)




-- 
Denis McMahon, [email protected]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Decimals and other numbers

2015-01-08 Thread Devin Jeanpierre
On Thu, Jan 8, 2015 at 6:43 PM, Dave Angel  wrote:
> What you don't say is which behavior you actually expected.  Since 0**0 is
> undefined mathematically, I'd expect either an exception or a NAN result.

It can be undefined, if you choose for it to be. You can also choose
to not define 0**1, of course. If 0**0 is defined, it must be 1. I
Googled around to find a mathematician to back me up, here:
http://arxiv.org/abs/math/9205211 (page 6, "ripples").

I expected 1, nan, or an exception, but more importantly, I expected
it to be the same for floats and decimals.

BTW, Ben, you linked to a file on your hard drive. You meant
https://docs.python.org/2/library/decimal.html#decimal.InvalidOperation

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


Re: Decimals and other numbers

2015-01-08 Thread Ben Finney
Dave Angel  writes:

> What you don't say is which behavior you actually expected.  Since
> 0**0 is undefined mathematically, I'd expect either an exception or a
> NAN result.

Do you think that the ‘int’ and ‘float’ types, which do produce a number
result for ‘0 ** 0’, are buggy and should be fixed?

I think the inconsistency is unnecessarily confusing. Perhaps the
consistency is in standards outside Python, but I think there is cause
here either for a change of behaviour or, if ther eis a good rationale
for the incompatible behaviours, to document the rationale. In either
case, a bug report is warranted IMO.

-- 
 \ “We are all agreed that your theory is crazy. The question that |
  `\  divides us is whether it is crazy enough to have a chance of |
_o__)being correct.” —Niels Bohr (to Wolfgang Pauli), 1958 |
Ben Finney

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


Re: Decimals and other numbers

2015-01-08 Thread Devin Jeanpierre
Thanks Ben, with your encouragement I have filed
http://bugs.python.org/issue23201

-- Devin

On Thu, Jan 8, 2015 at 7:03 PM, Ben Finney  wrote:
> Dave Angel  writes:
>
>> What you don't say is which behavior you actually expected.  Since
>> 0**0 is undefined mathematically, I'd expect either an exception or a
>> NAN result.
>
> Do you think that the ‘int’ and ‘float’ types, which do produce a number
> result for ‘0 ** 0’, are buggy and should be fixed?
>
> I think the inconsistency is unnecessarily confusing. Perhaps the
> consistency is in standards outside Python, but I think there is cause
> here either for a change of behaviour or, if ther eis a good rationale
> for the incompatible behaviours, to document the rationale. In either
> case, a bug report is warranted IMO.
>
> --
>  \ “We are all agreed that your theory is crazy. The question that |
>   `\  divides us is whether it is crazy enough to have a chance of |
> _o__)being correct.” —Niels Bohr (to Wolfgang Pauli), 1958 |
> Ben Finney
>
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


what is Jython?

2015-01-08 Thread Brian
I tried to find out more on the internet but didn't have much success. All
I know is that its a combination of Python and Java.
Is it more Java than Python or the other way around?
Is Jython free like Python?
Is the programming language for Jython similar to Python or similar to
Java?
Are there pros and cons then switching from Python to Jython?


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


Re: what is Jython?

2015-01-08 Thread Chris Angelico
On Fri, Jan 9, 2015 at 3:10 PM, Brian  wrote:
> I tried to find out more on the internet but didn't have much success. All
> I know is that its a combination of Python and Java.
> Is it more Java than Python or the other way around?
> Is Jython free like Python?
> Is the programming language for Jython similar to Python or similar to
> Java?
> Are there pros and cons then switching from Python to Jython?

The most common Python interpreter is "CPython", which is the one you
get when you go to the main downloads page on python.org. But Python,
the language, is quite separate from CPython, the implementation, and
there are a number of other implementations of the same language. In
theory, a Python script should run on any Python interpreter. Jython
is a Python interpreter written in Java; IronPython is a Python
interpreter written in C# (I think; uses .NET or Mono, anyway). PyPy
is a Python interpreter written in Python. MicroPython or uPy is a
cut-down Python interpreter designed for embedded systems. Brython is
a Python interpreter designed to go in a web browser.

Jython is free software, just as CPython is. I don't know the details
of the licenses, and IANAL, but I know the intention is that it's free
software. The code you run in Jython will be broadly the same as the
code you'd run in CPython, but some of the modules available in
CPython aren't available in Jython, and vice versa. The main reason
for choosing Jython is that you can load up a Java class and call on
its methods; you can either use an existing Java module and write your
application in Jython, or you can write a module in Jython, compile it
to a .class file, and then load that up from a Java program. With
CPython, on the other hand, it's really easy to interface with C code
(or other languages that compile to machine code), so it's easy to
make use of a typical Unix library.

Jython isn't a combination of Python and Java; it's Python,
implemented in Java. Does that answer your question?

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


Re: Decimals and other numbers

2015-01-08 Thread Marko Rauhamaa
Dave Angel :

> What you don't say is which behavior you actually expected. Since 0**0
> is undefined mathematically, I'd expect either an exception or a NAN
> result.

IEEE 754 mandates that 0**0 should evaluate to 1:

   http://en.wikipedia.org/wiki/NaN#Operations_generating_NaN>

The standard pow function and the integer exponent pown function
define 0**0, 1**∞, and ∞**0 as 1.

The powr function defines all three indeterminate forms as invalid
operations and so returns NaN.

Should IEEE 754's anomalies spill over to decimal, is a different
question.


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


Re: how to create a soap enveloppe with python suds for consume a bssv web service

2015-01-08 Thread dieter
brice DORA  writes:
> ...
>> "suds" should generate those required "SOAP envelope".
>> 
>> "suds" can be set up to log the precise messages sent and received
>> (consult the "suds" documentation about logging and the Python
>> documentation about its "logging" module). With these messages
>> (and a precise description of the encountered problem), you can
>> contact someone responsible for the web service to resolve your problems.
>
> okey thanks for your help but can you tell me if it's possible to see the 
> content of this soap envelope that's sent by suds?

It is (as I wrote)

>if yes then please how can i do it?thanks you in advance

Read the "suds" documentation
("https://fedorahosted.org/suds/wiki/Documentation";), the
section about logging! It is on the first page, immediately following
the "OVERVIEW" section!

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


Array of hash table

2015-01-08 Thread jyoti690saini
Hello,

   Can any one tell me how to create 
   graph={
  "nodes": [
{
  "id": "n0",
  "label": "A node",
  "x": 0,
  "y": 0,
  "size": 3
},
{
  "id": "n1",
  "label": "Another node",
  "x": 3,
  "y": 1,
  "size": 2
},
{
  "id": "n2",
  "label": "And a last one",
  "x": 1,
  "y": 3,
  "size": 1
}
  ],
  "edges": [
{
  "id": "e0",
  "source": "n0",
  "target": "n1",
  "label" : "dfghujikoi"
},
{
  "id": "e1",
  "label" : "dfghujikoi",
  "source": "n1",
  "target": "n2"
  
},
{
  "id": "e2",
  "source": "n2",
  "target": "n0",
  "label" : "dfghujikoi"
}
  ]
}

using python?

its like a hash table and value is an array of hash table ?
I tried but it was giving error of "List out of index" .
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Decimals and other numbers

2015-01-08 Thread Marko Rauhamaa
Devin Jeanpierre :

> If 0**0 is defined, it must be 1.

You can "justify" any value a within [0, 1]. For example, choose

   y(a, x) = log(a, x)

Then,

limy(a, x) = 0
   x -> 0+

and:

   lim[x -> 0+] x**y(a, x) = a

For example,

   >>> a = 0.5
   >>> x = 1e-100
   >>> y = math.log(a, x)
   >>> y
   0.0030102999566398118
   >>> x**y
   0.5


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


Re: Array of hash table

2015-01-08 Thread Dave Angel

On 01/09/2015 02:17 AM, [email protected] wrote:

Hello,

Can any one tell me how to create
graph={
   "nodes": [
 {
   "id": "n0",
   "label": "A node",
   "x": 0,
   "y": 0,
   "size": 3
 },
 {
   "id": "n1",
   "label": "Another node",
   "x": 3,
   "y": 1,
   "size": 2
 },
 {
   "id": "n2",
   "label": "And a last one",
   "x": 1,
   "y": 3,
   "size": 1
 }
   ],
   "edges": [
 {
   "id": "e0",
   "source": "n0",
   "target": "n1",
   "label" : "dfghujikoi"
 },
 {
   "id": "e1",
   "label" : "dfghujikoi",
   "source": "n1",
   "target": "n2"

 },
 {
   "id": "e2",
   "source": "n2",
   "target": "n0",
   "label" : "dfghujikoi"
 }
   ]
}

using python?

its like a hash table and value is an array of hash table ?
I tried but it was giving error of "List out of index" .



You just did.  If you'd like to see it, add a print(graph) .  What's 
your real question?


BTW, in Python, it's called a dict, not a hash table.  But you did it 
correctly.


And if you want to fetch a particular element, use:

print(graph["edges"][1]["id"])

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


Re: Decimals and other numbers

2015-01-08 Thread Chris Angelico
On Fri, Jan 9, 2015 at 6:28 PM, Marko Rauhamaa  wrote:
> Devin Jeanpierre :
>
>> If 0**0 is defined, it must be 1.
>
> You can "justify" any value a within [0, 1]. For example, choose
>
>y(a, x) = log(a, x)
>
> Then,
>
> limy(a, x) = 0
>x -> 0+
>
> and:
>
>lim[x -> 0+] x**y(a, x) = a
>
> For example,
>
>>>> a = 0.5
>>>> x = 1e-100
>>>> y = math.log(a, x)
>>>> y
>0.0030102999566398118
>>>> x**y
>0.5

I'm not a mathematical expert, so I don't quite 'get' this. How does
this justify 0**0 being equal to 0.5?

I know how to justify 0 and 1, and NaN (on the basis that both 0 and 1
can be justified). I don't follow how other values can be used.

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


Re: Decimals and other numbers

2015-01-08 Thread Dave Angel

On 01/09/2015 02:37 AM, Chris Angelico wrote:

On Fri, Jan 9, 2015 at 6:28 PM, Marko Rauhamaa  wrote:

Devin Jeanpierre :


If 0**0 is defined, it must be 1.


You can "justify" any value a within [0, 1]. For example, choose

y(a, x) = log(a, x)

Then,

 limy(a, x) = 0
x -> 0+

and:

lim[x -> 0+] x**y(a, x) = a

For example,

>>> a = 0.5
>>> x = 1e-100
>>> y = math.log(a, x)
>>> y
0.0030102999566398118
>>> x**y
0.5


I'm not a mathematical expert, so I don't quite 'get' this. How does
this justify 0**0 being equal to 0.5?

I know how to justify 0 and 1, and NaN (on the basis that both 0 and 1
can be justified). I don't follow how other values can be used.


Roughly speaking, the idea is to have a relationship between x and y, 
such that even though they each get arbitrarily close to zero, the 
formula x**y is a constant 5.


So he plugged in 1e-100.  But if you plugged in 1e-5  and could 
handle the precision, the result x**y  would still be 0.5





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