Re: SUM only of positive numbers from array

2016-01-08 Thread Peter Otten
Davorin Bajic wrote:

> Hi All,
> 
> I should help...
> 
> I want to calculate the sum of a positive number, for each row:
> 
> 
> x = ((mat_1 / s_1T)-(s_2 / total))
> y = (np.sum(x > 0, axis=1)).reshape(-1, 1).tolist()
> 
> However, this part of the code only calculation count, I need sum.
> 
> Any ideas how to solve this problem?

Use x>0 as "index":

>>> import numpy
>>> x = numpy.array([1, -2, 3])
>>> x>0
array([ True, False,  True], dtype=bool)
>>> x[x>0]
array([1, 3])
>>> x[x>0].sum()
4

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


Re: extract script from executable made by pyinstaller?

2016-01-08 Thread Chris Angelico
On Fri, Jan 8, 2016 at 6:44 PM, Ulli Horlacher
 wrote:
> Is it possible to extract (and view) the Python script from the Windows
> executable which was made by pyinstller?

To some extent, yes. You might only get the .pyc files, rather than
the proper source code, but you should be able to get something that
will run on any system.

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


Re: (Execution) Termination bit, Alternation bit.

2016-01-08 Thread Skybuck Flying

Should be easy to turn that somewhat pseudo code into python code ! :)


If it is so easy, why won't you do it?

Not sure why, I use SikuliX and it's kinda buggy and slow, and I also had 
little time, it's also pretty trivial and I doubt you guys will have a 
solution that will actually work, so it's time wasted most likely.


However I will not let the missing of code be an excuse for you guys and 
gals :) So here is the code.


It may also clearify some things cause some were already confused by the 
simple conditions it seems ! ;) :)


# Begin of Code

Condition1 = True
Condition2 = True
Condition3 = True
Condition4 = True
Condition5 = True
Condition6 = True
Condition7 = True

def Routine2():
print "Entering Routine2()"
global Condition6
global Condition7

while Condition6:
while Condition7:
  print "routine 2: executing"

print "Leaving Routine2()"

def Routine1():
print "Entering Routine1()"
global Condition4
global Condition5

while Condition4:
 while Condition5:
  Routine2()
print "Leaving Routine1()"

# main
print "Entering main loop"

while Condition1:
while Condition2:
 while Condition3:
  Routine1()

print "Leaving main loop"

# End of Code

Bye,
 Skybuck. 


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


Schedule of PythonFOSDEM 2016

2016-01-08 Thread Stephane Wirtel
Hi all,

Just to inform you that there is the PythonFOSDEM on 30th January and
the PythonFOSDEM will have a room of 363 seats for the #python
community.

PythonFOSDEM is the name of the room for the Python community at FOSDEM.
FOSDEM is a free event for software developers to meet, share ideas and
collaborate in Brussels (Belgium). The event is free, no registration
necessary.

More details at these addresses:

* About FOSDEM : https://fosdem.org/2016/
* About Schedule of PythonFOSDEM: https://fosdem.org/2016/schedule/track/python/

See you there,

Stephane

-- 
Stéphane Wirtel - http://wirtel.be - @matrixise
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: SUM only of positive numbers from array

2016-01-08 Thread Davorin Bajic
On Friday, January 8, 2016 at 5:13:06 AM UTC+1, Davorin Bajic wrote:
> Hi All,
> 
> I should help...
> 
> I want to calculate the sum of a positive number, for each row:
> 
> 
> x = ((mat_1 / s_1T)-(s_2 / total))
> y = (np.sum(x > 0, axis=1)).reshape(-1, 1).tolist()
> 
> However, this part of the code only calculation count, I need sum.
> 
> Any ideas how to solve this problem?
> 
> thanks in advance

Tnx Peter,

I solved using mask and filled

x = ((mat_1 / s_1T)-(s_2 / total))
i_bolean = x < 0 
amasked = np.ma.array(x, mask=i_bolean) 
fill_value = 0. 
aunmasked = np.ma.filled(amasked, fill_value) 
y = (aunmasked.sum(axis=1)).reshape(-1, 1).tolist()
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Unable to access module attribute with underscores in class method, Python 3

2016-01-08 Thread Joseph Fox-Rabinovitz
> On Thu, Jan 7, 2016 at 11:14 AM, Joseph Fox-Rabinovitz 
>  wrote:
>
> Hi,
>
> I have a module attribute whose name starts with a pair of underscores. I am 
> apparently unable to access it directly in a class method (within the same 
> module, but that is not relevant as far as I can tell). The following bit of 
> code illustrates the situation:
>
> __a = 3
> class B:
> def __init__(self):
> global __a
> self.a = __a
> b = B()
>
> This results in a NameError because of name-mangling, despite the global 
> declaration:
>
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "", line 4, in __init__
> NameError: name '_B__a' is not defined
>
> Not using global does not make a difference. I posted a similar question on 
> Stack Overflow, where the only reasonable answer given was to wrap __a in a 
> container whose name is not mangled. For example, doing `self.a = 
> globals()['__a']` or manually creating a dictionary with a non-mangled name 
> and accessing that.
>
> I feel that there should be some way of accessing __a within the class 
> directly in Python 3. Clearly my expectation that global would fix the issue 
> is incorrect. I would appreciate either a solution or an explanation of what 
> is going on that would convince me that accessing a module attribute in such 
> a way should be forbidden.
>
> -Joseph Fox-Rabinovitz
>
> P.S. For reference, the Stack Overflow question is here: 
> http://stackoverflow.com/questions/34621484/how-to-access-private-variable-of-python-module-from-class

One more detail that makes me think that name mangling may be getting
greedy to the point of bugginess:

__a = 3
class B:
def __init__(self):
m = sys.modules[__name__]
self.a = m.__a
b = B()

Raises the same exception as all the other way I tried to access __a:
'module' object has no attribute '_B__a'!

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


Unable to access module attribute with underscores in class method, Python 3

2016-01-08 Thread Joseph Fox-Rabinovitz
Hi,

I have a module attribute whose name starts with a pair of underscores. I
am apparently unable to access it directly in a class method (within the
same module, but that is not relevant as far as I can tell). The following
bit of code illustrates the situation:

__a = 3
class B:
def __init__(self):
global __a
self.a = __a
b = B()

This results in a NameError because of name-mangling, despite the global
declaration:

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

Not using global does not make a difference. I posted a similar question on
Stack Overflow, where the only reasonable answer given was to wrap __a in a
container whose name is not mangled. For example, doing `self.a =
globals()['__a']` or manually creating a dictionary with a non-mangled name
and accessing that.

I feel that there should be some way of accessing __a within the class
directly in Python 3. Clearly my expectation that global would fix the
issue is incorrect. I would appreciate either a solution or an explanation
of what is going on that would convince me that accessing a module
attribute in such a way should be forbidden.

-Joseph Fox-Rabinovitz

P.S. For reference, the Stack Overflow question is here:
http://stackoverflow.com/questions/34621484/how-to-access-private-variable-of-python-module-from-class
-- 
https://mail.python.org/mailman/listinfo/python-list


graphs

2016-01-08 Thread Saini, Sakshi
I  have a complex dataset and I wish to write a code to create different graphs 
from it. I was wondering if it is possible for Python/ matplotlib/ seaborn to 
return a cumulative or mean distribution bar graph based on values in your 
dataset?
E.g. I have a certain volume in m3 for each rainfall event in mm, and I wish to 
plot the total volume OR average volume for different rainfall depths; somewhat 
like the following:
[cid:[email protected]]

Any tips please?



Sakshi Saini, BASc, EIT
Water Resources Project Coordinator | Credit Valley Conservation

The information contained in this Credit Valley Conservation electronic message 
is directed in confidence solely to the person(s) named above and may not be 
otherwise distributed, copied or disclosed including attachments.  The message 
may contain information that is privileged, confidential and exempt from 
disclosure under the Municipal Freedom of Information and Protection and 
Privacy Act and by the Personal Information Protection Electronic Documents 
Act. The use of such personal information except in compliance with the Acts, 
is strictly prohibited. If you have received this message in error, please 
notify the sender immediately advising of the error and delete the message 
without making a copy. Thank you.
-- 
https://mail.python.org/mailman/listinfo/python-list


How to remove item from heap efficiently?

2016-01-08 Thread Sven R. Kunze

Hi everybody,

suppose, I need items sorted by two criteria (say timestamp and 
priority). For that purpose, I use two heaps (heapq module):


heapA # items sorted by timestamp
heapB # items sorted by priority

Now my actual problem. When popping an item of heapA (that's the oldest 
item), I need to remove the very same item from heapB, regardlessly 
where it is in heapB. And vice versa.


Is there a datastructure or a simple trick to achieve that in an 
efficient matter?


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


python 3.5.1 winsound bug

2016-01-08 Thread nick mcelwaine
Dear python team,
On my 64bit windows10 the SND_ASYNC flag doesn’t cause the sound to play 
asynchronously.
Nick McElwaine

Sent from Mail for Windows 10

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


Re: How to remove item from heap efficiently?

2016-01-08 Thread srinivas devaki
You can create a single heap with primary key as timestamp and
secondary key as priority, i.e by creating a tuple
insert the elements into the heap as
(timestamp, priority)


If there is any underlying meaning for creating 2 heaps. please mention.


On Fri, Jan 8, 2016 at 4:22 AM, Sven R. Kunze  wrote:
> Hi everybody,
>
> suppose, I need items sorted by two criteria (say timestamp and priority).
> For that purpose, I use two heaps (heapq module):
>
> heapA # items sorted by timestamp
> heapB # items sorted by priority
>
> Now my actual problem. When popping an item of heapA (that's the oldest
> item), I need to remove the very same item from heapB, regardlessly where it
> is in heapB. And vice versa.
>
> Is there a datastructure or a simple trick to achieve that in an efficient
> matter?
>
> Best,
> Sven
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to remove item from heap efficiently?

2016-01-08 Thread Peter Otten
Sven R. Kunze wrote:

> Hi everybody,
> 
> suppose, I need items sorted by two criteria (say timestamp and
> priority). For that purpose, I use two heaps (heapq module):
> 
> heapA # items sorted by timestamp
> heapB # items sorted by priority
> 
> Now my actual problem. When popping an item of heapA (that's the oldest
> item), I need to remove the very same item from heapB, regardlessly
> where it is in heapB. And vice versa.
> 
> Is there a datastructure or a simple trick to achieve that in an
> efficient matter?

The heapq docs mention marking as deleted as an alternative to removing.
Another option is to try sorted lists and bisect.

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


Re: Unable to access module attribute with underscores in class method, Python 3

2016-01-08 Thread Peter Otten
Joseph Fox-Rabinovitz wrote:

> Hi,
> 
> I have a module attribute whose name starts with a pair of underscores. I
> am apparently unable to access it directly in a class method (within the
> same module, but that is not relevant as far as I can tell). The following
> bit of code illustrates the situation:
> 
> __a = 3
> class B:
> def __init__(self):
> global __a
> self.a = __a
> b = B()
> 
> This results in a NameError because of name-mangling, despite the global
> declaration:
> 
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "", line 4, in __init__
> NameError: name '_B__a' is not defined
> 
> Not using global does not make a difference. I posted a similar question
> on Stack Overflow, where the only reasonable answer given was to wrap __a
> in a container whose name is not mangled. For example, doing `self.a =
> globals()['__a']` or manually creating a dictionary with a non-mangled
> name and accessing that.
> 
> I feel that there should be some way of accessing __a within the class
> directly in Python 3. Clearly my expectation that global would fix the
> issue is incorrect. I would appreciate either a solution or an explanation
> of what is going on that would convince me that accessing a module
> attribute in such a way should be forbidden.

The explanation is obvious: the approach taken by the compiler is very 
simple, and all names with two leading underscores (an no two trailing ones 
of course) are mangled. Other than improving the compiler you can wrap 
access to __a in a function defined outside the class

def get_a():
return __a

class B:
def __init__(self):
self.a = get_a()

Or, the horror, you change the name __a to _a.


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


Re: PyFladesk :: create GUI apps by Python and HTML, CSS and Javascript.

2016-01-08 Thread Michael Torrie
On 01/07/2016 08:54 PM, jacob Kruger wrote:
> I would definitely like to try out something like this - I am primarily 
> a web developer, and, partly since am 100% blind, any form of GUI design 
> is at times an issue for me, whereas I have been working with HTML 
> markup layouts for almost 20 years now, but, which versions of python 
> should this work with, and, what does it actually then use to 
> generate/handle GUI interface? Ask since, some of the GUI frameworks are 
> not too accessible themselves.

This project is simply a web browser (qtwebkit) embedded in a bare
window that automatically loads a python-based web application you write
separately.  That's all it is.  It's not a GUI toolkit or even a
web-based GUI toolkit.  It's primary purpose is to allow you to wrap up
a Python-based web app (using Flask, but I have no doubt it could handle
Django) in a little self-contained package so you can run it as if it
were a standalone app. Kind of like how Google Chrome let's you take a
url and make a virtual app out of it.

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


debugging uwsgi

2016-01-08 Thread Robin Becker
I have an unusual bug in a large django project which has appeared when using 
nginx + uwsgi + django. The configuration nginx + flup + django or the django 
runserver don't seem to create the conditions for the error.


Basically I am seeing an error


Traceback (most recent call last):
File "./project/fundfacts/api.py", line 33, in refresh_data
call_command('fe_data_load', month=period_id, datadir=upload_dir)
File 
"/home/rptlab/website/quilter.reportlab.com/quilter_2/lib/python2.7/site-packages/django/core/management/__init__.py",
 line 105, in call_command
command = load_command_class(app_name, name)
File 
"/home/rptlab/website/quilter.reportlab.com/quilter_2/lib/python2.7/site-packages/django/core/management/__init__.py",
 line 40, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named fe_data_load



some hack printouts along the error path seem to indicate that the import should 
be possible as executing


module = import_module('%s.management.commands.%s' % (app_name, 'fe_data_load'))

in the manage.py shell work fine and sys.path looks as expected.

The uwsgi worker process (I'm forking) is corrupted after (or  perhaps because 
of ) this error and causes previously working pages to fail; it looks like the 
python interpreter's gone wrong somehow.


Any good ways forward with debugging this sort of issue? I'm not sure how I 
would remotely debug this using winpdb.

--
Robin Becker

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


Re: graphs

2016-01-08 Thread Oscar Benjamin
On 7 January 2016 at 15:36, Saini, Sakshi  wrote:
> I  have a complex dataset and I wish to write a code to create different 
> graphs from it. I was wondering if it is possible for Python/ matplotlib/ 
> seaborn to return a cumulative or mean distribution bar graph based on values 
> in your dataset?

I'm sure that it is although I don't fully understand what you mean.

> E.g. I have a certain volume in m3 for each rainfall event in mm, and I wish 
> to plot the total volume OR average volume for different rainfall depths; 
> somewhat like the following:

This image didn't come through:

> [cid:[email protected]]

This is a text-based mailing list/newsgroup so images will not generally work.

> Any tips please?

Which part are you unsure about? Do you know how to write and run a
Python script? Do you know how to use matplotlib? If you can show some
code that does something similar to what you want then I'm sure
someone can suggest how to change it to do what you want.

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


Re: extract script from executable made by pyinstaller?

2016-01-08 Thread Oscar Benjamin
On 8 January 2016 at 07:44, Ulli Horlacher
 wrote:
> Is it possible to extract (and view) the Python script from the Windows
> executable which was made by pyinstller?

I may be misremembering but I though that pyinstaller actually stores
the main script uncompressed so that it's just in the raw .exe. In
which case you just need to find the start and stop bytes of the
script. If there are other packages etc. then I'm not sure how to do
that but they are in some sense stored as a compressed archive inside
the .exe file.

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


Re: Unable to access module attribute with underscores in class method, Python 3

2016-01-08 Thread Steven D'Aprano
On Fri, 8 Jan 2016 03:14 am, Joseph Fox-Rabinovitz wrote:

> Hi,
> 
> I have a module attribute whose name starts with a pair of underscores.

Don't do that.

The way to flag a module-level variable as private is with a single leading
underscore. Double-leading underscores are intended for use in classes, to
be name-mangled, and double-leading-and-trailing underscores are reserved
for use by Python.


> I am apparently unable to access it directly in a class method (within the
> same module, but that is not relevant as far as I can tell). The following
> bit of code illustrates the situation:
> 
> __a = 3
> class B:
> def __init__(self):
> global __a
> self.a = __a
> b = B()
> 
> This results in a NameError because of name-mangling, despite the global
> declaration:

The global declaration is name-mangled as well, as can be seen from the
byte-code:


py> from dis import dis
py> class Test:
... def method(self):
... global __a
... x = __a
...
py> dis(Test.method)
  4   0 LOAD_GLOBAL  0 (_Test__a)
  3 STORE_FAST   1 (x)
  6 LOAD_CONST   0 (None)
  9 RETURN_VALUE


That's exactly as described: within a class, ALL references to
double-leading underscore names are mangled.


> Not using global does not make a difference. I posted a similar question
> on Stack Overflow, where the only reasonable answer given was to wrap __a
> in a container whose name is not mangled. 

That's not a reasonable answer. That's adding unreasonable complication to
the code, just to support an unreasonable global name.


> For example, doing `self.a = 
> globals()['__a']` or manually creating a dictionary with a non-mangled
> name and accessing that.
> 
> I feel that there should be some way of accessing __a within the class
> directly in Python 3. Clearly my expectation that global would fix the
> issue is incorrect. I would appreciate either a solution or an explanation
> of what is going on that would convince me that accessing a module
> attribute in such a way should be forbidden.

You are trying to fight the language. __names are intended for a specific
use in Python, and you're ignoring that and trying to use them for
something else. That's fine so long as your use and the intended use don't
clash, but if they do clash (as they are here) then there's only one
reasonable answer: stop abusing name-mangled names.

If you absolutely insist that you must must must continue to use a double
underscore name, you could also try this:

py> __a = 1
py> class Test:
... def method(self):
... x = eval("__a")
... print(x)
...
py> Test().method()
1


But don't do that.



-- 
Steven

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


Re: Unable to access module attribute with underscores in class method, Python 3

2016-01-08 Thread Chris Angelico
On Sat, Jan 9, 2016 at 3:07 AM, Steven D'Aprano  wrote:
> If you absolutely insist that you must must must continue to use a double
> underscore name, you could also try this:
>
> py> __a = 1
> py> class Test:
> ... def method(self):
> ... x = eval("__a")
> ... print(x)
> ...
> py> Test().method()
> 1
>
>
> But don't do that.

Seriously? You consider that less bad than globals()["__a"]?

But all of this is craziness to support craziness. It's not asking
which inmate should run the asylum - it's asking which of my multiple
personalities should be elected fourteen-year-old queen.

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


Strange crash while running a script with a embedded python interpreter

2016-01-08 Thread Rickard Englund
First, some system info
* Windows 7 (also tested on 8 and 10) 
* Python 3.5.1 64bit (previously also tested using several 3.x versions)  (also 
tested with 32 bit, but with 3.4.2) 
* Microsoft Visual Studio 2015 (earlier version of python also tested with 
Visual Studio 2013)  

We have tested with both the debug and release libs for 3.5 and 3.5.1 (those 
available from python installer) with the same problem. 

The following problem has also been tested on Unix and on MacOS where it works 
as expected, the problem is only in Windows. 


Problem description:
We have an application for scientific visualization in which we have enabled 
scripting using embedded python. We have exposed quite some features of our 
application to python using modules, this works perfectly fine. 
The problem we have is that the application crashes as soon as a script is 
trying to import some of python's default libraries, such as os or random. For 
example, running the single line code "import os" produces a crash with the 
following stacktrace:
http://pastebin.com/QpfGrMY0

We initialize the python interpreter using the following: 
http://pastebin.com/uyx6gdMb 

We have tried with and without the Py_NoSiteFlag = 1. When removing that flag 
it works for some modules, for example "import os" works, but other modules, 
for example "import random" crashes. 


In the pastebin link above for the python initialization there are three lines 
commented out, "importModule("os")","importModule("glog")" and 
"importModule("random")", if I uncomment those lines the application will not 
crash when importing those modules. But that is not a viable solution, we can't 
import all possible modules that way. 

The following piece of code is how we execute python code: 
http://pastebin.com/HDUR2LKT


It only crashes for modules that exists , if I try to import a module that does 
not at all exist (eg import unexisting_module) , it fails as expected with a 
nice error message saying it does not exist. 


I don't know if we are doing anything wrong in the initialization of the 
interpreter or when running the script. We can run scripts that are not using 
any modules or are only using the python modules we create in c++ to expose 
functionality of our application.
Everything is working fine on MacOSX and Linux (tested with Ubuntu) which are 
the platforms we support. We had a similar setup before using python 2.x 
instead of 3.x which also worked without any problems. 


The software i am talking about is using QT for gui and and OpenGL for hardware 
accelerated graphics. But I have tested it in a minimal application where all 
QT stuff were omitted and the same issue is still there. 

The software is open source and can be downloaded/clones from 
github.com/inviwo/inviwo. 

The python initialization is done in 
https://github.com/inviwo/inviwo-dev/blob/master/modules/python3/pyinviwo.cpp 
and the script compiling and running is handled in 
https://github.com/inviwo/inviwo-dev/blob/master/modules/python3/pythonscript.cpp


I have searched a lot on google and in the issue tracker for python but found 
nothing that can answer my questions. So I hope that someone here can us solve 
this. 

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


Re: Strange crash while running a script with a embedded python interpreter

2016-01-08 Thread Rickard Englund
On Friday, January 8, 2016 at 5:18:56 PM UTC+1, Rickard Englund wrote:
> First, some system info
> * Windows 7 (also tested on 8 and 10) 
> * Python 3.5.1 64bit (previously also tested using several 3.x versions)  
> (also tested with 32 bit, but with 3.4.2) 
> * Microsoft Visual Studio 2015 (earlier version of python also tested with 
> Visual Studio 2013)  
> 
> We have tested with both the debug and release libs for 3.5 and 3.5.1 (those 
> available from python installer) with the same problem. 
> 
> The following problem has also been tested on Unix and on MacOS where it 
> works as expected, the problem is only in Windows. 
> 
> 
> Problem description:
> We have an application for scientific visualization in which we have enabled 
> scripting using embedded python. We have exposed quite some features of our 
> application to python using modules, this works perfectly fine. 
> The problem we have is that the application crashes as soon as a script is 
> trying to import some of python's default libraries, such as os or random. 
> For example, running the single line code "import os" produces a crash with 
> the following stacktrace:
> http://pastebin.com/QpfGrMY0
> 
> We initialize the python interpreter using the following: 
> http://pastebin.com/uyx6gdMb 
> 
> We have tried with and without the Py_NoSiteFlag = 1. When removing that flag 
> it works for some modules, for example "import os" works, but other modules, 
> for example "import random" crashes. 
> 
> 
> In the pastebin link above for the python initialization there are three 
> lines commented out, "importModule("os")","importModule("glog")" and 
> "importModule("random")", if I uncomment those lines the application will not 
> crash when importing those modules. But that is not a viable solution, we 
> can't import all possible modules that way. 
> 
> The following piece of code is how we execute python code: 
> http://pastebin.com/HDUR2LKT
> 
> 
> It only crashes for modules that exists , if I try to import a module that 
> does not at all exist (eg import unexisting_module) , it fails as expected 
> with a nice error message saying it does not exist. 
> 
> 
> I don't know if we are doing anything wrong in the initialization of the 
> interpreter or when running the script. We can run scripts that are not using 
> any modules or are only using the python modules we create in c++ to expose 
> functionality of our application.
> Everything is working fine on MacOSX and Linux (tested with Ubuntu) which are 
> the platforms we support. We had a similar setup before using python 2.x 
> instead of 3.x which also worked without any problems. 
> 
> 
> The software i am talking about is using QT for gui and and OpenGL for 
> hardware accelerated graphics. But I have tested it in a minimal application 
> where all QT stuff were omitted and the same issue is still there. 
> 
> The software is open source and can be downloaded/clones from 
> github.com/inviwo/inviwo. 
> 
> The python initialization is done in 
> https://github.com/inviwo/inviwo-dev/blob/master/modules/python3/pyinviwo.cpp 
> and the script compiling and running is handled in 
> https://github.com/inviwo/inviwo-dev/blob/master/modules/python3/pythonscript.cpp
> 
> 
> I have searched a lot on google and in the issue tracker for python but found 
> nothing that can answer my questions. So I hope that someone here can us 
> solve this.


I notice now that I have pasted 2 links to our private repository, which will 
not work. 
The correct links are: 
https://github.com/inviwo/inviwo/blob/master/modules/python3/pyinviwo.cpp 
https://github.com/inviwo/inviwo/blob/master/modules/python3/pythonscript.cpp 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Need help on a project To :"Create a class called BankAccount with the following parameters "

2016-01-08 Thread acushla4real
On Wednesday, 30 December 2015 19:21:32 UTC+1, Won Chang  wrote:
> i have these task which i believe i have done well to some level
> 
> Create a function get_algorithm_result to implement the algorithm below
> 
> 1- Get a list of numbers L1, L2, L3LN as argument 2- Assume L1 is the 
> largest, Largest = L1 3- Take next number Li from the list and do the 
> following 4- If Largest is less than Li 5- Largest = Li 6- If Li is last 
> number from the list then 7- return Largest and come out 8- Else repeat same 
> process starting from step 3
> 
> Create a function prime_number that does the following Takes as parameter an 
> integer and Returns boolean value true if the value is prime or Returns 
> boolean value false if the value is not prime
> 
> so i came up with this code below
> 
> def get_algorithm_result(my_list):
> if not any(not type(y) is int for y in my_list):
> largest = 0
> for item in range(0,len(my_list)):
> if largest < my_list[item]:
> largest = my_list[item]
> return largest
> else:
> 
> return(my_list[-1])
> 
> def prime_number(integer):
> if integer%2==0 and 2!=integer:
> return False
> else:
> return True
> 
> get_algorithm_result([1, 78, 34, 12, 10, 3]) 
> get_algorithm_result(["apples", "oranges", "mangoes", "banana", "zoo"]) 
> prime_number(1) 
> prime_number(78) 
> prime_number(11) 
> for the question above, there is a unittes which reads
> 
> import unittest
> 
> class AlgorithmTestCases(unittest.TestCase):
>   def test_maximum_number_one(self):
> result = get_algorithm_result([1, 78, 34, 12, 10, 3])
> self.assertEqual(result, 78, msg="Incorrect number")
> 
>   def test_maximum_number_two(self):
> result = get_algorithm_result(["apples", "oranges", "mangoes", "banana", 
> "zoo"])
> self.assertEqual(result, "zoo", msg="Incorrect number")
> 
>   def test_prime_number_one(self):
> result = prime_number(1)
> self.assertEqual(result, True, msg="Result is invalid")
> 
>   def test_prime_number_two(self):
> result = prime_number(78)
> self.assertEqual(result, False, msg="Result is invalid")
> 
>   def test_prime_number_three(self):
> result = prime_number(11)
> self.assertEqual(result, True, msg="Result is invalid")
> but once i run my code ,it returns error saying Test Spec Failed
> 
> Your solution failed to pass all the tests
> what is actually wrong with my code?

I had to use a hack to bypass it, worked and I moved on to next quiz
-- 
https://mail.python.org/mailman/listinfo/python-list


What use is '__reduce__'?

2016-01-08 Thread Robert
Hi,

When I try to run the following code:



/
from collections import Counter, OrderedDict

class OrderedCounter(Counter, OrderedDict):
 'Counter that remembers the order elements are first seen'
 def __repr__(self):
 return '%s(%r)' % (self.__class__.__name__,
OrderedDict(self))
 def __reduce__(self):
 return self.__class__, (OrderedDict(self),)

oc = OrderedCounter('abracadabra') 
-

I don't know the use of '__reduce__', even I look it up on Python website.
On that website, it explains 'pickle' module:
https://docs.python.org/2/library/pickle.html

But the above example without import that module. Is it from built-in?
Anyhow, I don't find a built-in explanation about '__reduce__'.

What use of the above two new self methods are in class OrderedCounter?

Thanks,


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


Re: debugging uwsgi

2016-01-08 Thread Robin Becker

On 08/01/2016 15:03, Robin Becker wrote:

I have an unusual bug in a large django project which has appeared when using
nginx + uwsgi + django. The configuration nginx + flup + django or the django
runserver don't seem to create the conditions for the error.

Basically I am seeing an error


Traceback (most recent call last):
File "./project/fundfacts/api.py", line 33, in refresh_data
call_command('fe_data_load', month=period_id, datadir=upload_dir)
File
"/home/rptlab/website/quilter.reportlab.com/quilter_2/lib/python2.7/site-packages/django/core/management/__init__.py",
line 105, in call_command
command = load_command_class(app_name, name)
File
"/home/rptlab/website/quilter.reportlab.com/quilter_2/lib/python2.7/site-packages/django/core/management/__init__.py",
line 40, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named fe_data_load

..
I discovered by trial and error that a preceding call_command had caused a 
chdir; that seems to have deleterious effects on the uwsgi process in question.


I'm not sure why the flup server is superior, but I guess something must be 
different about the python startup used by uwsgi compared to python manage.py 
runfcgi.


I'm still interested to find out any sensible way to debug uwsgi + python.
--
Robin Becker

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


Re: What use is '__reduce__'?

2016-01-08 Thread Ian Kelly
As you found by searching, __reduce__ is used to determine how
instances of the class are pickled. If the example you're using
doesn't do any pickling, then it's not really relevant to the example.
It's probably included so that it won't be missed when the code is
copied.

On Fri, Jan 8, 2016 at 9:42 AM, Robert  wrote:
> Hi,
>
> When I try to run the following code:
>
>
>
> /
> from collections import Counter, OrderedDict
>
> class OrderedCounter(Counter, OrderedDict):
>  'Counter that remembers the order elements are first seen'
>  def __repr__(self):
>  return '%s(%r)' % (self.__class__.__name__,
> OrderedDict(self))
>  def __reduce__(self):
>  return self.__class__, (OrderedDict(self),)
>
> oc = OrderedCounter('abracadabra')
> -
>
> I don't know the use of '__reduce__', even I look it up on Python website.
> On that website, it explains 'pickle' module:
> https://docs.python.org/2/library/pickle.html
>
> But the above example without import that module. Is it from built-in?
> Anyhow, I don't find a built-in explanation about '__reduce__'.
>
> What use of the above two new self methods are in class OrderedCounter?
>
> Thanks,
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


What use is '() here?

2016-01-08 Thread Robert
Hi,

Thanks Ian for replying to my previous post. Here is a further question on
the 'return' line below.




import collections
import pickle
class C(collections.defaultdict):
 def __init__(self):
 collections.defaultdict.__init__(self, list)
 def __reduce__(self):
 t = collections.defaultdict.__reduce__(self)
 return (t[0], ()) + t[2:]
 
 
c=C()
print c
print c.__reduce__()
c[1].append(200)
c[2].append(223)
c2 = pickle.loads(pickle.dumps(c))
c2 == c 
///
>From below command, I see 't' should be a tuple:


c.__reduce__()
Out[103]: (__main__.C, (), None, None, )


Then, I cannot get the idea what the two level parenthesis are for.
Its result is a tuple? Then, it can add 't[2:]'. 

 return (t[0], ()) + t[2:]


It is not a tuple because there is no third level parenthesis, i.e. 

((t[0], ()) + t[2:])


Do you have a simple way for me to make it clear? Thanks,
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What use is '__reduce__'?

2016-01-08 Thread Robert
On Friday, January 8, 2016 at 12:04:21 PM UTC-5, Ian wrote:
> As you found by searching, __reduce__ is used to determine how
> instances of the class are pickled. If the example you're using
> doesn't do any pickling, then it's not really relevant to the example.
> It's probably included so that it won't be missed when the code is
> copied.
> 
> On Fri, Jan 8, 2016 at 9:42 AM, Robert  wrote:
> > Hi,
> >
> > When I try to run the following code:
> >
> >
> >
> > /
> > from collections import Counter, OrderedDict
> >
> > class OrderedCounter(Counter, OrderedDict):
> >  'Counter that remembers the order elements are first seen'
> >  def __repr__(self):
> >  return '%s(%r)' % (self.__class__.__name__,
> > OrderedDict(self))
> >  def __reduce__(self):
> >  return self.__class__, (OrderedDict(self),)
> >
> > oc = OrderedCounter('abracadabra')
> > -
> >
> > I don't know the use of '__reduce__', even I look it up on Python website.
> > On that website, it explains 'pickle' module:
> > https://docs.python.org/2/library/pickle.html
> >
> > But the above example without import that module. Is it from built-in?
> > Anyhow, I don't find a built-in explanation about '__reduce__'.
> >
> > What use of the above two new self methods are in class OrderedCounter?
> >
> > Thanks,
> >
> >
> > --
> > https://mail.python.org/mailman/listinfo/python-list

Thanks for your reply.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What use is '() here?

2016-01-08 Thread Robert
On Friday, January 8, 2016 at 12:44:01 PM UTC-5, Robert wrote:
> Hi,
> 
> Thanks Ian for replying to my previous post. Here is a further question on
> the 'return' line below.
> 
> 
> 
> 
> import collections
> import pickle
> class C(collections.defaultdict):
>  def __init__(self):
>  collections.defaultdict.__init__(self, list)
>  def __reduce__(self):
>  t = collections.defaultdict.__reduce__(self)
>  return (t[0], ()) + t[2:]
>  
>  
> c=C()
> print c
> print c.__reduce__()
> c[1].append(200)
> c[2].append(223)
> c2 = pickle.loads(pickle.dumps(c))
> c2 == c 
> ///
> From below command, I see 't' should be a tuple:
> 
> 
> c.__reduce__()
> Out[103]: (__main__.C, (), None, None, )
> 
> 
> Then, I cannot get the idea what the two level parenthesis are for.
> Its result is a tuple? Then, it can add 't[2:]'. 
> 
>  return (t[0], ()) + t[2:]
> 
> 
> It is not a tuple because there is no third level parenthesis, i.e. 
> 
> ((t[0], ()) + t[2:])
> 
> 
> Do you have a simple way for me to make it clear? Thanks,

OK. I get my answer for it. It is a tuple. I should get familiar with the
return line. Thanks,
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: extract script from executable made by pyinstaller?

2016-01-08 Thread Ulli Horlacher
Oscar Benjamin  wrote:
> On 8 January 2016 at 07:44, Ulli Horlacher
>  wrote:
> > Is it possible to extract (and view) the Python script from the Windows
> > executable which was made by pyinstller?
> 
> I may be misremembering but I though that pyinstaller actually stores
> the main script uncompressed so that it's just in the raw .exe.

No. I tested it already with "strings".


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: [email protected]
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Required Python/Backend Engineer, Data in Redwood City, CA -- full time

2016-01-08 Thread naveen . v
Hi ,

 

One of our client seeking Python/Backend Engineer, Data in Redwood City, CA If 
you are interested please send me your updated resume at [email protected]  
along with your expected salary.

Title: Python/Backend Engineer, Data
Location: Redwood City, CA
Full time position

 

Required:

·comfortable in Linux (Ubuntu) environment

·Java, Scala, Python and/or C++ proficiency

·experience using various RDBM and NoSQL dbs and when to use each

·BS or MS in Computer Science, related degree or equivalent experience

·great attitude, team player and ability to thrive and learn in a fast-paced 
environment
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to remove item from heap efficiently?

2016-01-08 Thread srinivas devaki
So you need a task scheduler with expiration and priority on each task.
Interesting Problem..

as peter said about marking the task in heapB to be deleted. but this
needs searching everytime you pop off an old item [complexity:
O(len(heapB))]. you may as well use python del on it as complexity is
same.
But if you already know the where to look in the heapB then you can
avoid searching and thereby reducing the complexity. you can do this
by saving the references of heapB in heapA and viceversa

and if you marking delete on a number of low priority tasks, then it
can increase your heapB enormously because being low priority items
they can stagnate. to resolve this error you have to perform linear
checking iterations at every critical length (this critical length can
be obtained mathmatically), so that your amortized complexity of push,
pop remains log(number_of_valid_tasks_at_any_time);
the number of valid tasks at any time are those tasks which are not
expired at the time.

My Algorithm:
version_a: https://gist.github.com/9ce7a0e534c6e768239e
this version has simple scheduler which has methods for popping high
priority one and popping oldest task.
But this version has a disadvantage, i.e If lets say you are pushed
some 10**5 tasks with priority 2, and then pushed some 10**5 tasks
with priority 1. and then you decided to pop the oldest 10**5 items.
in this version that 10**5 elements will stagnate in priority heap if
in future all priorities are less than 1.
now this is not a big issue but if you are running a webserver and
over a span of 5 days there could be 10**10 tasks, and even if half of
those tasks stagnate your server is going to crash with out of memory.

version_b: https://gist.github.com/99b4d590753ba234eeed
this version resolved that stagnation. this one will run sweeps
whenever there are more than half of useless items, thereby giving us
an amortized complexity of O(log(n)) for push, pop, etc

but this version doesn't have the feature of expiration.

version_c: https://gist.github.com/9dfd0d291672c0ffa5c3
in this one we simply keep a variable expiration, and relieve the
expired tasks on any operation. i have coded it in such a way that
expiration is specific time, you can change it to delta time if you
want to.

Time Complexity: O(log(n)) insertion, O(log(n)) deletion   [amortized]
Space Complexity: O(n)  [amortized]
here n is number of valid items i.e which are not expired.

I hope this helps with your problem

PS:
sorry for posting links, it's just that the code is large for email.
I'm using minimum number has highest priority convention.


On Fri, Jan 8, 2016 at 10:15 PM, Sven R. Kunze  wrote:
> Thanks for your suggestion.
>
> On 08.01.2016 14:21, srinivas devaki wrote:
>>
>> You can create a single heap with primary key as timestamp and
>> secondary key as priority, i.e by creating a tuple
>> insert the elements into the heap as
>> (timestamp, priority)
>
> I think I cannot use that because I need the list sorted by both criteria.
>>
>> If there is any underlying meaning for creating 2 heaps. please mention.
>
>
> I use two heaps because I need to insert arbitrary items fast and remove the
> ones fast which are too old (timestamp) or are next in order (priority).
>
> Basically a task scheduler where tasks can be thrown away once they are too
> long in the queue.
>
>
>> On Fri, Jan 8, 2016 at 4:22 AM, Sven R. Kunze  wrote:
>>>
>>> Hi everybody,
>>>
>>> suppose, I need items sorted by two criteria (say timestamp and
>>> priority).
>>> For that purpose, I use two heaps (heapq module):
>>>
>>> heapA # items sorted by timestamp
>>> heapB # items sorted by priority
>>>
>>> Now my actual problem. When popping an item of heapA (that's the oldest
>>> item), I need to remove the very same item from heapB, regardlessly where
>>> it
>>> is in heapB. And vice versa.
>>>
>>> Is there a datastructure or a simple trick to achieve that in an
>>> efficient
>>> matter?
>>>
>>> Best,
>>> Sven
>>> --
>>> https://mail.python.org/mailman/listinfo/python-list
>
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: EOFError: marshal data too short -- causes?

2016-01-08 Thread Glenn Linderman

On 1/7/2016 7:44 PM, Dennis Lee Bieber wrote:

On Thu, 7 Jan 2016 10:55:38 -0800, Glenn Linderman 
declaimed the following:


But all the touched files are .pyc files (and the directories
__pycache__ directories).  None of the source files were modified. So
why would any .pyc files ever be updated if the source files are not?
Are there _any_  Python-specific reasons?


Two different versions of Python accessing the same modules? That might
induce one to do a rebuild of the .pyc from the .py... Especially if the
variant is something being run (directly or indirectly) from some scheduled
task.


Thanks for the idea, but there is only one version of Python installed 
in that directory structure (and all of my "shared host" portion of the 
server).



Some conflict with a backup process corrupting files?


This seems more possible, simply because I don't understand their backup 
process. Still, if Python only reads shared, and there'd be no reason 
for a backup process to do more than read shared, there shouldn't be a 
conflict...


But it seems clear that there _is_ some conflict or some mysterious bug 
that is triggering something.


The installation happened really fast, when I did it, many many files 
seem to have the same timestamp. Maybe some of the sources are really 
close in touch time to the .pyc? But still, it seems that would have 
been resolved long ago...  But I could go "touch" all the .pyc to give 
them nice new timestamps?


Maybe I should mark all the current .pyc  read-only even to myself? That 
would prevent them from being rebuilt by Python, and maybe when whatever 
goes wrong goes wrong, an error would return to the user, but maybe the 
next access would work that'd be better than letting whatever goes 
wrong modify/corrupt the .pyc, so that _every future_ access fails?


Maybe before launching Python I should do a "find ~/py34 --name *.pyc > 
/dev/null" (or some log file) to cache the directory structure before 
Python looks at it, and give the mysterious bug a chance to happen with 
an irrelevant activity?


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


Re: What use is '__reduce__'?

2016-01-08 Thread Peter Otten
Ian Kelly wrote:

> As you found by searching, __reduce__ is used to determine how
> instances of the class are pickled. If the example you're using
> doesn't do any pickling, then it's not really relevant to the example.
> It's probably included so that it won't be missed when the code is
> copied.

__reduce__() also makes copying work as expected:

>>> class OrderedCounter(Counter, OrderedDict):
...  'Counter that remembers the order elements are first seen'
...  def __repr__(self):
...  return '%s(%r)' % (self.__class__.__name__,
... OrderedDict(self))
...  def __reduce__(self):
...  return self.__class__, (OrderedDict(self),)
... 
>>> oc = OrderedCounter('abracadabra') 
>>> import copy
>>> copy.copy(oc)
OrderedCounter(OrderedDict([('a', 5), ('b', 2), ('r', 2), ('c', 1), ('d', 
1)]))

Now take away the __reduce__ method:

>>> del OrderedCounter.__reduce__
>>> copy.copy(oc)
OrderedCounter(OrderedDict([('b', 2), ('a', 5), ('c', 1), ('r', 2), ('d', 
1)]))


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


Re: Strange crash while running a script with a embedded python interpreter

2016-01-08 Thread Michael Torrie
On 01/08/2016 09:18 AM, Rickard Englund wrote:
> First, some system info
> * Windows 7 (also tested on 8 and 10) 
> * Python 3.5.1 64bit (previously also tested using several 3.x versions)  
> (also tested with 32 bit, but with 3.4.2) 
> * Microsoft Visual Studio 2015 (earlier version of python also tested with 
> Visual Studio 2013)  

Are you using the same version of Visual Studio that Python itself was
compiled with?  If not there can be subtle problems with incompatible
msvcrt dlls.  No idea if this would be contributing to the problem or
not, though.
-- 
https://mail.python.org/mailman/listinfo/python-list


OT, but

2016-01-08 Thread Gene Heskett
Greetings all;

Where can I find the best tut for pyvcp?

Thanks all.

Cheers, Gene Heskett
-- 
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
Genes Web page 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Unable to access module attribute with underscores in class method, Python 3

2016-01-08 Thread Steven D'Aprano
On Sat, 9 Jan 2016 03:16 am, Chris Angelico wrote:

> On Sat, Jan 9, 2016 at 3:07 AM, Steven D'Aprano 
> wrote:
>> If you absolutely insist that you must must must continue to use a double
>> underscore name, you could also try this:
>>
>> py> __a = 1
>> py> class Test:
>> ... def method(self):
>> ... x = eval("__a")
>> ... print(x)
>> ...
>> py> Test().method()
>> 1
>>
>>
>> But don't do that.
> 
> Seriously? You consider that less bad than globals()["__a"]?

No. That's why I said "don't do that" rather than "you should do this" :-)


> But all of this is craziness to support craziness. It's not asking
> which inmate should run the asylum - it's asking which of my multiple
> personalities should be elected fourteen-year-old queen.

Loretta, surely.




-- 
Steven

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