Re: Matplotlib error: Value Error: x and y must have same first dimension

2015-11-13 Thread Laura Creighton
In a message of Thu, 12 Nov 2015 17:54:28 -0800, Abhishek writes:
>I am trying to run some Python code for the last few hours. How can I achieve 
>the effect of "dot divide" from Matlab, in the following code? I am having 
>trouble working with list comprehension and numpy arrays and getting the 
>following error:
>
>Traceback (most recent call last):
>  File "Thurs.py", line 128, in 
>plt.plot(np.array(range(1,N/2+2)), 
> Splot[alpha][iii,val]/utot[iii,val],color=cmap(iii/50))
>
>ValueError: x and y must have same first dimension

Splot is a list.  matplotlib wants 2 numpy arrays.  You have to cast
it with np.array() too.

no guarantees that the rest of the code works -- it is not plotting for
me -- but that gets rid of that error at any rate.

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


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

2015-11-13 Thread PythonDude
On Thursday, 12 November 2015 17:35:39 UTC+1, Ian  wrote:
> On Thu, Nov 12, 2015 at 8:57 AM, PythonDude  wrote:
> > Hi all,
> > Anyone could please explain or elaborate on exactly this (quote): "Keep in 
> > mind that Python has a reversed definition of rows and columns"???
> >
> > That I don't understand - thank you for any 
> > hints/guidance/explanations/ideas/suggestions etc!
> 
> py> import numpy
> py> p = numpy.reshape(range(5), (5,1))
> py> p
> array([[0],
>[1],
>[2],
>[3],
>[4]])
> py> p.T
> array([[0, 1, 2, 3, 4]])
> py> p.dot(p.T)
> array([[ 0,  0,  0,  0,  0],
>[ 0,  1,  2,  3,  4],
>[ 0,  2,  4,  6,  8],
>[ 0,  3,  6,  9, 12],
>[ 0,  4,  8, 12, 16]])
> py> p.T.dot(p)
> array([[30]])
> py> m = numpy.asmatrix(p)
> py> m
> matrix([[0],
> [1],
> [2],
> [3],
> [4]])
> py> m.T
> matrix([[0, 1, 2, 3, 4]])
> py> m * m.T
> matrix([[ 0,  0,  0,  0,  0],
> [ 0,  1,  2,  3,  4],
> [ 0,  2,  4,  6,  8],
> [ 0,  3,  6,  9, 12],
> [ 0,  4,  8, 12, 16]])
> py> m.T * m
> matrix([[30]])
> 
> Yeah, I don't know what that person is talking about either. It looks
> correct to me.

Thank you very much, Ian - just had to be sure about this - I would also be 
very disappointed in Python, if this author was right about this non-intuitive 
interpretation of how to do matrix multiplication :-)
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2015-11-13 Thread PythonDude
On Thursday, 12 November 2015 22:57:21 UTC+1, Robert Kern  wrote:
> On 2015-11-12 15:57, PythonDude wrote:
> > Hi all,
> >
> > I've come around a webpage with python-tutorial/description for obtaining 
> > something and I'll solve this:
> >
> > R = p^T w
> >
> > where R is a vector and p^T is the transpose of another vector.
> >
> > ...
> > p is a Nx1 column vector, so p^T turns into a 1xN row vector which can be 
> > multiplied with the
> > Nx1 weight (column) vector w to give a scalar result. This is equivalent to 
> > the dot
> > product used in the code. Keep in mind that Python has a reversed 
> > definition of
> > rows and columns and the accurate NumPy version of the previous equation 
> > would
> > be R = w * p.T
> > ...
> >
> > (source: http://blog.quantopian.com/markowitz-portfolio-optimization-2/ )
> >
> > I don't understand this: "Keep in mind that Python has a reversed 
> > definition of
> > rows and columns and the accurate NumPy version of the previous equation 
> > would
> > be R = w * p.T"
> >
> > Not true for numpy, is it? This page: 
> > http://mathesaurus.sourceforge.net/matlab-numpy.html says it python and 
> > matlab looks quite similar...
> >
> > Anyone could please explain or elaborate on exactly this (quote): "Keep in 
> > mind that Python has a reversed definition of rows and columns"???
> 
> He's wrong, simply put. There is no "reversed definition of rows and 
> columns". 

Great, thank...

> He simply instantiated the two vectors as row-vectors instead of 
> column-vectors, 
> which he could have easily done, so he had to flip the matrix expression.

Thank you very much Robert - I just had to be sure about it :-)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question about math.pi is mutable

2015-11-13 Thread Denis McMahon
On Fri, 13 Nov 2015 09:04:54 +1100, Steven D'Aprano wrote:

> On Fri, 13 Nov 2015 07:40 am, Thomas 'PointedEars' Lahn wrote:

> > [crap I expect]

> And you should consider the irony, and hypocrisy, of somebody who signs
> his posts "PointedEars" bitching about supposed "real names".

TPEL has been trolling html, php and javascript newsgroups for years, 
recently he seems to have discovered python newsgroups. :(

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Running latest 32-bit Python on 64-bit system

2015-11-13 Thread Christian Ullrich

Hello,

I have a problem with using the (otherwise nice) Python launcher. How 
can I get it to run the highest 32-bit Python on my 64-bit system? This 
is on Windows, but I think it applies to other OSes as well.


My application runs (unmodified) with Python 3.[345], but only with the 
32-bit version because it loads a DLL that has no 64-bit version 
available. I would like to run it on any system that has *any* suitable 
Python installed.


However, with the shebang syntax supported by the launcher, I can only 
demand a 32-bit version if I also specify the Python minor version I 
want, and I don't necessarily know that in advance.


I can code around that, of course, but I don't want to. If Python can 
select the 64-bit version to run by itself, it should also be able to 
for the 32-bit version, right?


Thanks,

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


Re: Plotting timeseries from a csv file using matplotlib

2015-11-13 Thread Fabien

On 11/13/2015 06:27 AM, Karthik Sharma wrote:

How do I extract all the values in columns


Have a look at pandas: 
http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html

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


Re: Unable to make http request to django server using twisted.web.client.AGENT

2015-11-13 Thread Akshat Tripathi
On Thursday, 5 November 2015 13:06:13 UTC+5:30, Akshat Tripathi  wrote:
> I have written a basic tcp server factory, server client and a service using 
> twisted. The tcp server acts as the middleware between a django server and an 
> another program (let's call it client program).
> 
> What I want to achieve -
> 
> 1.client requests the middleware tcp server;
> 
> 2.it sends a string as the request body;
> 
> 3.the middleware tcp server deserializes information from the request.
> 
> 4.middleware furthers the serialized information to the django server.
> 
> 5.The django server then responds to the middleware server which furthers the 
> response to the client after serializing the response.
> 
> I am able to reach till step 3, but am unable to make any http request to the 
> django server.
> 
> 
> 
> 
> The following is my middleware.py
> 
> from twisted.internet.protocol import ServerFactory
> from twisted.internet.protocol import Protocol
> 
> from test_service import MyService
> 
> 
> class TCPServerProtocol(Protocol):
> data = ''
> 
> def connectionMade(self):
> self.deferred = self.factory.service.deferred
> self.deferred.addCallback(self.factory.service.s)
> self.deferred.addCallback(self.transport.write)
> self.deferred.addBoth(lambda r: self.transport.loseConnection)
> 
> def dataReceived(self, data):
> self.data += data
> 
> def connectionLost(self, reason):
> self.forward(self.data)
> 
> def forward(self, data):
> if self.deferred is not None:
> d, self.deferred = self.deferred, None
> d.callback(data)
> 
> class TCPServerFactory(ServerFactory):
> 
> protocol = TCPServerProtocol
> 
> def __init__(self, service):
> self.service = service
> 
> def runserver(ip, port):
> iface =  {'home': '192.168.0.104', 'work': '127.0.0.1'}
> service = MyService()
> factory = TCPServerFactory(service)
> from twisted.internet import reactor
> reactor.listenTCP(port=port, factory=factory, interface=iface[ip])
> reactor.run()
> 
> if __name__ == '__main__':
> import sys
> ip = sys.argv[1]
> port = int(sys.argv[2])
> runserver(ip, port)
> 
> 
> 
> 
> The following is test_service.py
> 
> from twisted.internet.defer import Deferred
> 
> from test_http_client import HTTPClientFactory
> 
> class MyService(object):
> def __init__(self):
> self.deferred = Deferred()
> 
> def s(self, data):
> kwargs = {}
> kwargs['url'] = b'http://127.0.0.1:8000/some/end/point'
> kwargs['url'] = kwargs['url'].encode('latin-1')
> kwargs['method'] = 'POST'
> kwargs['data'] = data
> 
> client = HTTPClientFactory(**kwargs)
> d = client.deferred
> return d
> 
> 
> The following is test_http_client.py
> 
> from StringIO import StringIO
> import json
> 
> from twisted.internet.protocol import Protocol
> from twisted.internet.defer import Deferred
> from twisted.web.client import Agent, FileBodyProducer
> from twisted.web.http_headers import Headers
> 
> 
> class HTTPClientProtocol(Protocol):
> def __init__(self, finished):
> self.finished = finished
> self.data = ''
> 
> def dataReceived(self, data):
> print '--Data Received by HTTPClientProtocol--'
> print data
> self.data += data
> 
> def connectionLost(self, reason):
> print '--HTTP Client connection Lost--'
> print reason.getErrorMessage()
> if self.finished is not None:
> print 'finished is not None'
> f, self.finished = self.finished, None
> f.callback(self.data)
> 
> class HTTPClientFactory(object):
> 
> """
> Class handling communication with HTTP server.
> """
> 
> def __init__(self, **kwargs):
> data = kwargs['data'] 
> try:
> body = FileBodyProducer(StringIO(json.dumps(data)))
> print '--Request body object created--'
> except Exception as e:
> print '--Request body object creation FAILURE--'
> print e
> return e  
> url = kwargs.get('url', None)
> method = kwargs.get('method', None)
> 
> from twisted.internet import reactor
> agent = Agent(reactor)
> if not data:
> body = None
> 
> self.deferred = agent.request(method,
> url,
> Headers({'Content-Type': 
> ['application/json']}),
> bodyProducer=body)
> 
> self.deferred.addCallback(self.get_response)
> 
> def get_response(self, response):
> print 'Response received'
> finished = Deferred()
> response.deliverBody(HTTPClientProtocol(finished))
> return finished

Found the bug. Below is the corrected code.

class TCPServerProtoc

[no subject]

2015-11-13 Thread Animesh Srivastava
Whenever i install python 3.5.0 compiler
It gives me error 0x07b
Can u please resolve it
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What is the meaning of Py_INCREF a static PyTypeObject?

2015-11-13 Thread Xiang Zhang
Thanks for your reply jason. Your reply does give me hints and then I 
read more code and find maybe you are wrong in some points.


I think the meaning of Py_INCREF a static type object is to prevent it 
from being deallocated when it is Py_DECREFed somehow later. Just as you 
said, it may be somehow deallocated when using.


NoddyType is a static struct so I don't think it lives on Python's heap 
and deallocating it is a wrong action. Just as I mentioned, type_dealloc 
seems to only deallocated HEAPTYPE. And by the way, when NoddyType is 
created, it has a reference count 1 with PyVarObject_HEAD_INIT. So if I 
don't Py_INCREF it, when it is somehow Py_DECREDed later, it will reach 
reference count 0 and fail the assert in type_dealloc. If it is 
Py_INCREFed, just like the module holds a reference to it, it will at 
least have a reference count 1 and never reach 0.


On 11/13/2015 02:52 AM, Jason Swails wrote:



On Thu, Nov 12, 2015 at 3:05 AM, Xiang Zhang <18518281...@126.com 
> wrote:


Recently I am learning Python C API.

When I read the tutorial
,
defining new types, I feel confused. After
PyType_Ready(&noddy_NoddyType) comes Py_INCREF(&noddy_NoddyType).
Actually noddy_NoddyType is a static struct so I don't understand
why I need to Py_INCREF it. Since it's Py_INCREFed, does it mean
sometimes we also need to Py_DECREF it? But then it seems that
type_dealloc will be invoked and it will fail
assert(type->tp_flags & Py_TPFLAGS_HEAPTYPE);


​It is a module attribute, so when the module is imported it has to 
have a single reference (the reference *in* the module).  If you don't 
INCREF it, then it will have a refcount of 0, and immediately be ready 
for garbage collection.  So if you try to use the type from the 
module, you could get a segfault because it's trying to use an object 
(type definition) that was already destroyed.


Note that you don't *always* have to INCREF objects after you create 
them in C.  Some macros and function do that for you. And in some 
cases, all you want or need is a borrowed reference.  In those cases, 
Py_INCREF is unnecessary.


The DECREF will be done when it's normally done in Python.  If you do 
something like


import noddy
del noddy.NoddyType

​All that's really doing is removing NoddyType from the noddy 
namespace and Py_DECREFing it.  Alternatively, doing


import noddy
noddy.NoddyType = 10 # rebind the name

Then the original object NoddyType was pointing to will be DECREFed 
and NoddyType will point to an object taking the value of 10.


HTH,
Jason


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


Re: What is wrong in this example code?

2015-11-13 Thread Nathan Hilterbrand
On Thu, Nov 12, 2015 at 6:59 PM, Larry Hudson via Python-list <
python-list@python.org> wrote:

Nothing to do with your original question, just a trivial suggestion which
> you are free to ignore.  You can shorten this tick() method by using the
> divmod() function.  It does a division and returns both the quotient AND
> the remainder.  IOW, given divmod(x, y) it returns the tuple (x/y, x%y).
> It is a very useful function.  Try this:
>
> def tick(self):
> xtra, self._seconds = divmod(self._seconds + 1, 60)
> xtra, self._minutes = divmod(self._minutes + xtra, 60)
> self._hours += xtra
>
> Explanation:  (to shorten this, I'm leaving off the leading "self._" from
> the actual code.)
> The first divmod() sets xtra = (seconds+1) / 60, which is the 'overflow'
> if any, from the division by 60, and seconds is the updated seconds limited
> to 0-59 (the result of (seconds+1) % 60).  The second divmod() does the
> same thing to update minutes (if xtra != 0) and xtra is set to the
> 'overflow' from that division, which is then added to hours.
>
> More confusing perhaps, but definitely shorter.
> As I said above, use it if you want or ignore it if it's too confusing.
>
>  -=- Larry -=-
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>

Beat me to the punch.  I was about to suggest something similar, but I
thought that since one using this class would probably be "tick()-ing" more
than "str()-ing", It might also be better to store the value in seconds,
and convert to HH:MM:SS upon stringification; again using divmod:

class Clock(object):

def __init__(self,hours=0,minutes=0,seconds=0):
self.set(hours,minutes,seconds)

def tick(self):
self.__secs+=1

def set(self,hours, minutes, seconds):
self.__secs = seconds + (minutes*60) + (hours*60*60)

def __str__(self):
rest, seconds = divmod(self.__secs, 60)
hours, minutes = divmod(rest, 60)

return "%02d:%02d:%02d" % (hours, minutes, seconds)

def display(self):
print(str(self))


if __name__ == "__main__":

x = Clock()
print("Default construction, no parameters, Before ticks: {}".format(x))
for i in range(1):
x.tick()
print("After ticks: {}".format(x))

x = Clock(hours=2, minutes=20, seconds=5)
print("\nConstructor with hours=2, minutes=20, seconds=5: {}".format(x))

print("Test of display() method: ",end=' ')
x.display()


This is my first post here, and I am a Python n00b (coming from that
four-letter word language "p***"), so if I broke some top/bottom posting or
formatting rules, I apologize, and would appreciate any posting pointers

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


Re:

2015-11-13 Thread Chris Angelico
On Fri, Nov 13, 2015 at 8:17 PM, Animesh Srivastava  wrote:
> Whenever i install python 3.5.0 compiler
> It gives me error 0x07b
> Can u please resolve it

Is this Windows XP? You have three options:

1) Install Python 3.4 instead
2) Upgrade to a newer Windows
3) Upgrade to a better operating system

Is this not Windows XP? You have three options:

1) Read about newsgroup postings and subject lines
2) Resolve the issue yourself, with the skills you have
3) Tell us a *lot* more information about what's going on, what OS
you're using (including the version), the error message you're
getting, etc, etc.

In each case, the third option is the best by far, and is recommended.

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


Can Canopy Express (Free) allow install a new package (PyBayes) to it?

2015-11-13 Thread fl
I am using Canopy Express (Free) version. I want to install PyBayes package,
 but I don't see it in Package Manager of Canopy. Can I install PyBayes to
 Canopy?

Now, Canopy is the default Python on my Windows 7 PC. If Canopy does not allow
 to install PyBayes into it, can I install PyBayes to the plain Python 2.7
 (downloaded from Python website, which was installed before I installed
 Canopy), and use Python 2.7 IDLE with PyBayes? (I am concern about  Canopy
 makes the Windows Python 2.7 not the same way as before?

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


Re: Matplotlib error: Value Error: x and y must have same first dimension

2015-11-13 Thread Oscar Benjamin
On 13 November 2015 at 08:34, Laura Creighton  wrote:
> In a message of Thu, 12 Nov 2015 17:54:28 -0800, Abhishek writes:
>>I am trying to run some Python code for the last few hours. How can I achieve 
>>the effect of "dot divide" from Matlab, in the following code? I am having 
>>trouble working with list comprehension and numpy arrays and getting the 
>>following error:
>>
>>Traceback (most recent call last):
>>  File "Thurs.py", line 128, in 
>>plt.plot(np.array(range(1,N/2+2)), 
>> Splot[alpha][iii,val]/utot[iii,val],color=cmap(iii/50))
>>
>>ValueError: x and y must have same first dimension
>
> Splot is a list.  matplotlib wants 2 numpy arrays.  You have to cast
> it with np.array() too.

Actually the plot command is perfectly happy converting lists or lists
of lists etc. to arrays (by calling np.array internally) so you don't
need to convert any of your inputs. By the way: np.arange(1, N/2+2)
would be the usual way to create a numpy array that is a range.

The error here comes because (after both arguments are converted to
arrays) they have incompatible sizes. In other words:

len(range(1,N/2+2)) != len(Splot[alpha][iii,val]/utot[iii,val])

I'm not sure what the solution is as the code is too complex for me to
spend time trying to guess what it's trying to do.

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


Re: Plotting timeseries from a csv file using matplotlib

2015-11-13 Thread Denis McMahon
On Thu, 12 Nov 2015 21:27:58 -0800, Karthik Sharma wrote:

> I have some csv data in the following format. ..

Does the following idea help?

Create a key from the key fields, remove the key fields from the row dic 
(so now it's a dic of just the data fields), and save that in the 
plotdata dict keyed by the key.

import csv

keybits = ["Ln","Dr","Tag","Lab"]

plotdata = {}

with open("lab.csv", 'r') as fin:
reader = csv.DictReader(fin)
for row in reader:
key = tuple([row[k] for k in keybits])
for k in keybits:
del row[k]
plotdata[key] = row

This generates a dictionary (plotdata) keyed by the key tuples where the 
value for each key is a dictionary of 0:0n : value

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What is the meaning of Py_INCREF a static PyTypeObject?

2015-11-13 Thread Oscar Benjamin
On 13 November 2015 at 03:08, Xiang Zhang <18518281...@126.com> wrote:
> I think the meaning of Py_INCREF a static type object is to prevent it from
> being deallocated when it is Py_DECREFed somehow later. Just as you said, it
> may be somehow deallocated when using.
>
> NoddyType is a static struct so I don't think it lives on Python's heap and
> deallocating it is a wrong action. Just as I mentioned, type_dealloc seems
> to only deallocated HEAPTYPE. And by the way, when NoddyType is created, it
> has a reference count 1 with PyVarObject_HEAD_INIT. So if I don't Py_INCREF
> it, when it is somehow Py_DECREDed later, it will reach reference count 0
> and fail the assert in type_dealloc. If it is Py_INCREFed, just like the
> module holds a reference to it, it will at least have a reference count 1
> and never reach 0.

Other code shouldn't Py_DECREF it unless it owns a reference meaning
that it has first called Py_INCREF. The only exception I can think is
possibly that someone would do:

>>> import noddy
>>> del noddy.Noddy

For that to work properly I guess that Noddy needs a reference count
of 2: one for being a module attribute and an extra one to prevent it
from ever being deallocated.

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


numpy column_stack - why does this work?

2015-11-13 Thread PythonDude
Hi all,

Just a quick question about this code-piece (it works, I've tested it):

means, stds = np.column_stack([
getMuSigma_from_PF(return_vec) 
for _ in xrange(n_portfolios) ])


1) I understand column_stack does this (assembles vectors vertically, 
side-by-side):

>>> a = np.array((1,2,3)) # NB: a is row-vector: {1 2 3}
>>> b = np.array((2,3,4)) # NB: b is also a row-vector...
>>> np.column_stack((a,b))
array([[1, 2],
   [2, 3],
   [3, 4]])

2) I understand the underscore is just a "dummy variable" in the last line "for 
_ in xrange(n_portfolios)" - this also looked a bit confusing to me, at first...

3) I DON'T understand why the code doesn't look like this:

means, stds = np.column_stack([
for _ in xrange(n_portfolios):
  getMuSigma_from_PF(return_vec) ])

???

Any comments/advice/hints, I would appreciate from you, thank you!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re:

2015-11-13 Thread Laura Creighton
In a message of Fri, 13 Nov 2015 14:47:12 +0530, Animesh Srivastava writes:
>Whenever i install python 3.5.0 compiler
>It gives me error 0x07b
>Can u please resolve it
>-- 
>https://mail.python.org/mailman/listinfo/python-list

Maybe this is your problem
http://www.bitdefender.com/support/how-to-solve-error-message-%22the-application-was-unable-to-start-correctly-%280x07b%29-click-ok-to-close-the-application%22-1106.html

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


Re: Matplotlib error: Value Error: x and y must have same first dimension

2015-11-13 Thread Laura Creighton
In a message of Fri, 13 Nov 2015 14:04:01 +, Oscar Benjamin writes:
>On 13 November 2015 at 08:34, Laura Creighton  wrote:
>> In a message of Thu, 12 Nov 2015 17:54:28 -0800, Abhishek writes:
>>>I am trying to run some Python code for the last few hours. How can I 
>>>achieve the effect of "dot divide" from Matlab, in the following code? I am 
>>>having trouble working with list comprehension and numpy arrays and getting 
>>>the following error:
>>>
>>>Traceback (most recent call last):
>>>  File "Thurs.py", line 128, in 
>>>plt.plot(np.array(range(1,N/2+2)), 
>>> Splot[alpha][iii,val]/utot[iii,val],color=cmap(iii/50))
>>>
>>>ValueError: x and y must have same first dimension
>>
>> Splot is a list.  matplotlib wants 2 numpy arrays.  You have to cast
>> it with np.array() too.
>
>Actually the plot command is perfectly happy converting lists or lists
>of lists etc. to arrays (by calling np.array internally) so you don't
>need to convert any of your inputs. By the way: np.arange(1, N/2+2)
>would be the usual way to create a numpy array that is a range.
>
>The error here comes because (after both arguments are converted to
>arrays) they have incompatible sizes. In other words:
>
>len(range(1,N/2+2)) != len(Splot[alpha][iii,val]/utot[iii,val])
>
>I'm not sure what the solution is as the code is too complex for me to
>spend time trying to guess what it's trying to do.
>
>--
>Oscar

I am sorry for the bad information.  Thank you Oscar.

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


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

2015-11-13 Thread Dave Farrance
PythonDude  wrote:

>On Thursday, 12 November 2015 22:57:21 UTC+1, Robert Kern  wrote:

>> He simply instantiated the two vectors as row-vectors instead of 
>> column-vectors, 
>> which he could have easily done, so he had to flip the matrix expression.
>
>Thank you very much Robert - I just had to be sure about it :-)

Yep, he's evidently used to the Matlab/Octave way of defining "vectors"
which is somewhat easier for a math-oriented interactive environment.

It's just a *bit* more laborious to append columns in numpy.

>>> from numpy import *
>>> v1=vstack([0,1,2])
>>> v2=vstack([3,4,5])
>>> c_[v1,v2]
array([[0, 3],
   [1, 4],
   [2, 5]])
>>> append(v1,v2,axis=1)
array([[0, 3],
   [1, 4],
   [2, 5]])
>>> v3=mat('4;5;6')
>>> v4=mat('7;8;9')
>>> c_[v3,v4]
matrix([[4, 7],
[5, 8],
[6, 9]])
-- 
https://mail.python.org/mailman/listinfo/python-list


Trying out Kivy

2015-11-13 Thread Cecil Westerhof
I tried out the ‘standard’ Kivy application:

from kivy.app import App
from kivy.uix.button import Button

class TestApp(App):
def build(self):
return Button(text='Hello World')

TestApp().run()


When using python2 I see some exceptions and OSErrors, but it runs.

When using python3 I get:
[CRITICAL  ] [Text] Unable to find any valuable Text 
provider at all!
pygame - ImportError: No module named 'pygame'
  File "/usr/lib64/python3.4/site-packages/kivy/core/__init__.py", line 57, 
in core_select_lib
fromlist=[modulename], level=0)
  File "/usr/lib64/python3.4/site-packages/kivy/core/text/text_pygame.py", 
line 12, in 
import pygame

pil - ImportError: No module named 'PIL'
  File "/usr/lib64/python3.4/site-packages/kivy/core/__init__.py", line 57, 
in core_select_lib
fromlist=[modulename], level=0)
  File "/usr/lib64/python3.4/site-packages/kivy/core/text/text_pil.py", 
line 8, in 
from PIL import Image, ImageFont, ImageDraw

[CRITICAL  ] [App ] Unable to get a Text provider, abort.

I tried to install pygame and PIL with pip3, but that did not find
anything. Is there another way to install those dependencies?

But more importantly: can I develop with python3 for the Android?
Because the primary reason to use Kivy is to develop applications for Android.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: numpy column_stack - why does this work?

2015-11-13 Thread Ian Kelly
On Fri, Nov 13, 2015 at 8:37 AM, PythonDude  wrote:
> Hi all,
>
> Just a quick question about this code-piece (it works, I've tested it):
>
> means, stds = np.column_stack([
> getMuSigma_from_PF(return_vec)
> for _ in xrange(n_portfolios) ])
>
>
> 1) I understand column_stack does this (assembles vectors vertically, 
> side-by-side):
>
 a = np.array((1,2,3)) # NB: a is row-vector: {1 2 3}
 b = np.array((2,3,4)) # NB: b is also a row-vector...
 np.column_stack((a,b))
> array([[1, 2],
>[2, 3],
>[3, 4]])
>
> 2) I understand the underscore is just a "dummy variable" in the last line 
> "for _ in xrange(n_portfolios)" - this also looked a bit confusing to me, at 
> first...
>
> 3) I DON'T understand why the code doesn't look like this:
>
> means, stds = np.column_stack([
> for _ in xrange(n_portfolios):
>   getMuSigma_from_PF(return_vec) ])

Because that would be invalid syntax; you can't put a for loop inside
an expression like that. Your question is not about numpy.column_stack
at all, but about list comprehensions. I suggest you start by reading
this:

https://docs.python.org/3/tutorial/datastructures.html#list-comprehensions

Then if you're still confused, come back and ask further questions.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Trying out Kivy

2015-11-13 Thread Michael Torrie
On 11/13/2015 09:33 AM, Cecil Westerhof wrote:
> I tried to install pygame and PIL with pip3, but that did not find
> anything. 

The replacement for PIL is called Pillow.  I'm not sure if it's a
drop-in replacement or not.  If it's not, then you'd have to modify Kivy
to import from Pillow.  Pillow does support Python3.

> Is there another way to install those dependencies?

Did you do a search to find out a) if PyGame supports Python3 (it does)
and b) where to go to download the source code for it? (their home page)?

PyPi is nice, but it's not the only place you can get useful Python
modules from.

> But more importantly: can I develop with python3 for the Android?
> Because the primary reason to use Kivy is to develop applications for Android.

Again, did you do a quick Google search?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Trying out Kivy

2015-11-13 Thread Terry Reedy

On 11/13/2015 11:33 AM, Cecil Westerhof wrote:

I tried out the ‘standard’ Kivy application:

from kivy.app import App
from kivy.uix.button import Button

class TestApp(App):
 def build(self):
 return Button(text='Hello World')

TestApp().run()


When using python2 I see some exceptions and OSErrors, but it runs.

When using python3 I get:
 [CRITICAL  ] [Text] Unable to find any valuable Text 
provider at all!
 pygame - ImportError: No module named 'pygame'
   File "/usr/lib64/python3.4/site-packages/kivy/core/__init__.py", line 
57, in core_select_lib
 fromlist=[modulename], level=0)
   File "/usr/lib64/python3.4/site-packages/kivy/core/text/text_pygame.py", line 
12, in 
 import pygame

 pil - ImportError: No module named 'PIL'
   File "/usr/lib64/python3.4/site-packages/kivy/core/__init__.py", line 
57, in core_select_lib
 fromlist=[modulename], level=0)
   File "/usr/lib64/python3.4/site-packages/kivy/core/text/text_pil.py", line 8, 
in 
 from PIL import Image, ImageFont, ImageDraw

 [CRITICAL  ] [App ] Unable to get a Text provider, abort.

I tried to install pygame and PIL with pip3, but that did not find


Use pillow rather than PIL.  API is same.  Don't know about rest of your 
question.



anything. Is there another way to install those dependencies?

But more importantly: can I develop with python3 for the Android?
Because the primary reason to use Kivy is to develop applications for Android.




--
Terry Jan Reedy


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


Re: Trying out Kivy

2015-11-13 Thread bayang

Le 13/11/2015 18:23, Terry Reedy a écrit :

On 11/13/2015 11:33 AM, Cecil Westerhof wrote:

I tried out the ‘standard’ Kivy application:

from kivy.app import App
from kivy.uix.button import Button

class TestApp(App):
 def build(self):
 return Button(text='Hello World')

TestApp().run()


When using python2 I see some exceptions and OSErrors, but it runs.

When using python3 I get:
 [CRITICAL  ] [Text] Unable to find any valuable 
Text provider at all!

 pygame - ImportError: No module named 'pygame'
   File 
"/usr/lib64/python3.4/site-packages/kivy/core/__init__.py", line 57, 
in core_select_lib

 fromlist=[modulename], level=0)
   File 
"/usr/lib64/python3.4/site-packages/kivy/core/text/text_pygame.py", 
line 12, in 

 import pygame

 pil - ImportError: No module named 'PIL'
   File 
"/usr/lib64/python3.4/site-packages/kivy/core/__init__.py", line 57, 
in core_select_lib

 fromlist=[modulename], level=0)
   File 
"/usr/lib64/python3.4/site-packages/kivy/core/text/text_pil.py", line 
8, in 

 from PIL import Image, ImageFont, ImageDraw

 [CRITICAL  ] [App ] Unable to get a Text 
provider, abort.


I tried to install pygame and PIL with pip3, but that did not find


Use pillow rather than PIL.  API is same.  Don't know about rest of 
your question.



anything. Is there another way to install those dependencies?

But more importantly: can I develop with python3 for the Android?
Because the primary reason to use Kivy is to develop applications for 
Android.






Got the same issue a few days ago with python3.
Installed pygame dependencies, installed pygame, installed pillow and 
everything went fine (using pip in virtualenv)


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


Re: Trying out Kivy

2015-11-13 Thread Cecil Westerhof
On Friday 13 Nov 2015 18:21 CET, Michael Torrie wrote:

> On 11/13/2015 09:33 AM, Cecil Westerhof wrote:
>> I tried to install pygame and PIL with pip3, but that did not find
>> anything. 
>
> The replacement for PIL is called Pillow. I'm not sure if it's a
> drop-in replacement or not. If it's not, then you'd have to modify
> Kivy to import from Pillow. Pillow does support Python3.

After installing Pillow the error about PIL disappeared, but I got new
errors about bcm and x11.


>> Is there another way to install those dependencies?
>
> Did you do a search to find out a) if PyGame supports Python3 (it
> does) and b) where to go to download the source code for it? (their
> home page)?
>
> PyPi is nice, but it's not the only place you can get useful Python
> modules from.
>
>> But more importantly: can I develop with python3 for the Android?
>> Because the primary reason to use Kivy is to develop applications
>> for Android.
>
> Again, did you do a quick Google search?

I did. But I did not find specifics about the version of Python.

Well, maybe I should first play a bit with Kivy and if it is the way
to go, I delve into the python3 bit.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: More tkinter Madness

2015-11-13 Thread Tim Daneliuk
On 11/13/2015 12:32 AM, Christian Gollwitzer wrote:
> Apfelkiste:Sources chris$

Well, I get window and when I do this:

pack [button .b -text Hello -command exit]

Nothing appears.

tkinter appears borked

I have reinstalled once already, will try again


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


Problems using struct pack/unpack in files, and reading them.

2015-11-13 Thread kent nyberg
Hi there,
Im deeply sorry for yet another question to this list.  I have come across a 
problem to which google seems not 
to eager to supply the anwser.

The problem is the following.
First I do this:

def setup_drive():
test = pack('>HH',  0b1000, 0b10010001)
file = open('drive.bin', 'wb')
for x in range(64):
file.write(test)
file.close()


I have a pack, which I fill the file with. The data is not of interrest right 
now.

This all works great.
Then I do this:


def LoadCommandAndReact(place_to_read):
global RegisterAX

tmp = place_to_read.read()[RegisterAX:calcsize('HH')]
klar = unpack('>HH', tmp)

if place_to_read.closed:
   print("Drive error. Drive closed.")
else:
   pass

if checkfirstbit(klar[RegisterAX]):
   print("First bit is set. Move Cmd.")
   if (klar[0] & 0b0111):
  print("Cmd ERROR: Multiple commands is set.")
  pass
   else:
  #Here something to do with mv command.
  print("Adress to read to, from the offset of the command")
  print(klar[RegisterAX+1])  #Variable is always Offset+1  
else:
   print("First bit is not set.")
#Change RegisterAX offset+2bytes, 
RegisterAX=+2   #We read two bytes per cycle. Becaus command is first, and 
variables are second.




This all works If I run the LoadCommand..  only once.
But when I  run it for the second time,  it complains:

Traceback (most recent call last):
  File "core.py", line 98, in 
LoadCommandAndReact(readfile)
  File "core.py", line 30, in LoadCommandAndReact
klar = unpack('>HH', tmp)
struct.error: unpack requires a string argument of length 4



Im having trouble understanding the error.   unpack requires a string argument 
of length 4.
I have filled the file with data that should be readable, and is readable by 
the function 
when I run it for the first time. And since the file is filled with duplicates; 
should it not be readable the second
time aswell? I change the RegisterAX =+2. The amount I add should not matter, 
Its just my "offset" of where to read in the file.
The problem seems that the second time, unpack doesnt get the size of '>HH' to 
read. But surely 
.read()[RegisterAX:calcsize('HH')]  should assure that its fed with correct 
data?

I have filled the file with data of size '>HH' and first command reads that.  
So next read should read the next
duplicate of that data that has been written to the file?


I understand its hard to read, and a long email. So well, its just a cry out in 
the dark evening.  If some one can
share some light.. I would be much happy about it.

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


Re: Problems using struct pack/unpack in files, and reading them.

2015-11-13 Thread Ian Kelly
On Fri, Nov 13, 2015 at 12:20 PM, kent nyberg  wrote:
> def LoadCommandAndReact(place_to_read):
> global RegisterAX
>
> tmp = place_to_read.read()[RegisterAX:calcsize('HH')]

It looks like you're trying to get a slice of length 4 here, starting
at the value of RegisterAX. What you're actually getting is a slice
starting at the value of RegisterAX and ending at 4. You probably want
this instead:

tmp = place_to_read.read()[RegisterAX:RegisterAX + calcsize('HH')]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problems using struct pack/unpack in files, and reading them.

2015-11-13 Thread Ian Kelly
As long as I'm replying to this, I see a few more issues to comment on:

On Fri, Nov 13, 2015 at 12:20 PM, kent nyberg  wrote:
> if place_to_read.closed:
>print("Drive error. Drive closed.")

You probably also want to break or return here. Even better: raise an
exception instead of printing.

That said, why would this ever be closed here, since you just read
from it two lines prior (which would have raised an exception if the
file were closed), and you haven't closed it in the meantime?

> if checkfirstbit(klar[RegisterAX]):
>print("First bit is set. Move Cmd.")
>if (klar[0] & 0b0111):
>   print("Cmd ERROR: Multiple commands is set.")

Why do you pass the commands in a bit field if you're not going to
allow multiple commands to be set? Also, see above about
break/return/exception.

>   pass

Unnecessary.

> #Change RegisterAX offset+2bytes,
> RegisterAX=+2   #We read two bytes per cycle. Becaus command is first, 
> and variables are second.

This sets RegisterAX to 2. Specifically, positive 2. If you want to
*add* 2, you probably meant to write:

RegisterAX += 2

This also points out a good reason for using spaces around operators,
as "RegisterAX =+ 2" would have caused a SyntaxError and been more
easily detectable.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Trying out Kivy

2015-11-13 Thread Michael Torrie
On 11/13/2015 11:30 AM, Cecil Westerhof wrote:
> On Friday 13 Nov 2015 18:21 CET, Michael Torrie wrote:
> 
>> On 11/13/2015 09:33 AM, Cecil Westerhof wrote:
>>> I tried to install pygame and PIL with pip3, but that did not find
>>> anything. 
>>
>> The replacement for PIL is called Pillow. I'm not sure if it's a
>> drop-in replacement or not. If it's not, then you'd have to modify
>> Kivy to import from Pillow. Pillow does support Python3.
> 
> After installing Pillow the error about PIL disappeared, but I got new
> errors about bcm and x11.

Traceback?

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


Re: More tkinter Madness

2015-11-13 Thread Laura Creighton
In a message of Fri, 13 Nov 2015 13:14:08 -0600, Tim Daneliuk writes:
>On 11/13/2015 12:32 AM, Christian Gollwitzer wrote:
>> Apfelkiste:Sources chris$
>
>Well, I get window and when I do this:
>
>pack [button .b -text Hello -command exit]
>
>Nothing appears.
>
>tkinter appears borked
>
>I have reinstalled once already, will try again

Next idea.

Try to run a basic Tk app and a basic Tcl one.  See if they work or not.

Laura

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


Re: More tkinter Madness

2015-11-13 Thread Michael Torrie
On 11/13/2015 12:14 PM, Tim Daneliuk wrote:
> On 11/13/2015 12:32 AM, Christian Gollwitzer wrote:
>> Apfelkiste:Sources chris$
> 
> Well, I get window and when I do this:
> 
> pack [button .b -text Hello -command exit]
> 
> Nothing appears.
> 
> tkinter appears borked
> 
> I have reinstalled once already, will try again

Tkinter is the name of the Python package for using Tk, but Tk itself is
usually called Tk (package on Fedora and RHEL is tk).

On my CentOS installs, in /usr/share/tk8.5/demos, there are a number of
Tcl/Tk demos you can run.  If Tcl and Tk are working, then I would move
to reinstalling tkinter.

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


Re: Trying out Kivy

2015-11-13 Thread Cecil Westerhof
On Friday 13 Nov 2015 20:53 CET, Michael Torrie wrote:

> On 11/13/2015 11:30 AM, Cecil Westerhof wrote:
>> On Friday 13 Nov 2015 18:21 CET, Michael Torrie wrote:
>>
>>> On 11/13/2015 09:33 AM, Cecil Westerhof wrote:
 I tried to install pygame and PIL with pip3, but that did not
 find anything.
>>>
>>> The replacement for PIL is called Pillow. I'm not sure if it's a
>>> drop-in replacement or not. If it's not, then you'd have to modify
>>> Kivy to import from Pillow. Pillow does support Python3.
>>
>> After installing Pillow the error about PIL disappeared, but I got
>> new errors about bcm and x11.
>
> Traceback?

Purge log fired. Analysing...
Purge finished!
[INFO  ] [Logger  ] Record log in 
/home/cecil/.kivy/logs/kivy_15-11-13_28.txt
[INFO  ] [Kivy] v1.9.0
[INFO  ] [Python  ] v3.4.1 (default, May 23 2014, 17:48:28) 
[GCC]
[INFO  ] [Factory ] 173 symbols loaded
[INFO  ] [Image   ] Providers: img_tex, img_dds, img_gif, 
img_pil (img_pygame, img_ffpyplayer ignored)
[INFO  ] [Text] Provider: pil(['text_pygame'] ignored)
[CRITICAL  ] [Window  ] Unable to find any valuable Window provider 
at all!
egl_rpi - ImportError: cannot import name 'bcm'
  File "/usr/lib64/python3.4/site-packages/kivy/core/__init__.py", line 57, in 
core_select_lib
fromlist=[modulename], level=0)
  File "/usr/lib64/python3.4/site-packages/kivy/core/window/window_egl_rpi.py", 
line 12, in 
from kivy.lib.vidcore_lite import bcm, egl

pygame - ImportError: No module named 'pygame'
  File "/usr/lib64/python3.4/site-packages/kivy/core/__init__.py", line 57, in 
core_select_lib
fromlist=[modulename], level=0)
  File "/usr/lib64/python3.4/site-packages/kivy/core/window/window_pygame.py", 
line 8, in 
import pygame

x11 - ImportError: No module named 'kivy.core.window.window_x11'
  File "/usr/lib64/python3.4/site-packages/kivy/core/__init__.py", line 57, in 
core_select_lib
fromlist=[modulename], level=0)

[CRITICAL  ] [App ] Unable to get a Window, abort.
 Exception ignored in: 'kivy.properties.dpi2px'
 Traceback (most recent call last):
   File "/usr/lib64/python3.4/site-packages/kivy/utils.py", line 360, in __get__
 retval = self.func(inst)
   File "/usr/lib64/python3.4/site-packages/kivy/metrics.py", line 169, in dpi
 EventLoop.ensure_window()
   File "/usr/lib64/python3.4/site-packages/kivy/base.py", line 126, in 
ensure_window
 sys.exit(1)
 SystemExit: 1
[CRITICAL  ] [App ] Unable to get a Window, abort.


I see a difference with python2. (Did not notice it before.) With
python3 v1.9.0 is installed, but with python2 v1.8.0.
[INFO  ] Kivy v1.8.0

Maybe that is the problem?

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problems using struct pack/unpack in files, and reading them.

2015-11-13 Thread Laura Creighton
In a message of Fri, 13 Nov 2015 14:20:45 -0500, kent nyberg writes:
>Hi there,
>Im deeply sorry for yet another question to this list.  I have come across a 
>problem to which google seems not 
>to eager to supply the anwser.
>
>The problem is the following.
>First I do this:
>
>def setup_drive():
>test = pack('>HH',  0b1000, 0b10010001)
>file = open('drive.bin', 'wb')
>for x in range(64):
>file.write(test)
>file.close()
>
>
>I have a pack, which I fill the file with. The data is not of interrest right 
>now.
>
>This all works great.
>Then I do this:
>
>
>def LoadCommandAndReact(place_to_read):
>global RegisterAX
>
>tmp = place_to_read.read()[RegisterAX:calcsize('HH')]
>klar = unpack('>HH', tmp)
>
>if place_to_read.closed:
>   print("Drive error. Drive closed.")
>else:
>   pass
>
>if checkfirstbit(klar[RegisterAX]):
>   print("First bit is set. Move Cmd.")
>   if (klar[0] & 0b0111):
>  print("Cmd ERROR: Multiple commands is set.")
>  pass
>   else:
>  #Here something to do with mv command.
>  print("Adress to read to, from the offset of the command")
>  print(klar[RegisterAX+1])  #Variable is always Offset+1  
>else:
>   print("First bit is not set.")
>#Change RegisterAX offset+2bytes, 
>RegisterAX=+2   #We read two bytes per cycle. Becaus command is first, and 
> variables are second.
>
>
>
>
>This all works If I run the LoadCommand..  only once.
>But when I  run it for the second time,  it complains:
>
>Traceback (most recent call last):
>  File "core.py", line 98, in 
>LoadCommandAndReact(readfile)
>  File "core.py", line 30, in LoadCommandAndReact
>klar = unpack('>HH', tmp)
>struct.error: unpack requires a string argument of length 4
>
>
>
>Im having trouble understanding the error.   unpack requires a string argument 
>of length 4.
>I have filled the file with data that should be readable, and is readable by 
>the function 
>when I run it for the first time. And since the file is filled with 
>duplicates; should it not be readable the second
>time aswell? I change the RegisterAX =+2. The amount I add should not matter, 
>Its just my "offset" of where to read in the file.
>The problem seems that the second time, unpack doesnt get the size of '>HH' to 
>read. But surely 
>.read()[RegisterAX:calcsize('HH')]  should assure that its fed with correct 
>data?
>
>I have filled the file with data of size '>HH' and first command reads that.  
>So next read should read the next
>duplicate of that data that has been written to the file?
>
>
>I understand its hard to read, and a long email. So well, its just a cry out 
>in the dark evening.  If some one can
>share some light.. I would be much happy about it.
>
>/Kent.
>-- 
>https://mail.python.org/mailman/listinfo/python-list

struct wants to know exactly how many of those things you have.
You only told it about one of them  i.e.  If you want to unpack 999 
elements from binary data

data = struct.unpack("999H", B)

Laura


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


Re: Problems using struct pack/unpack in files, and reading them.

2015-11-13 Thread kent nyberg
On Fri, Nov 13, 2015 at 12:36:22PM -0700, Ian Kelly wrote:
> On Fri, Nov 13, 2015 at 12:20 PM, kent nyberg  wrote:
> > def LoadCommandAndReact(place_to_read):
> > global RegisterAX
> >
> > tmp = place_to_read.read()[RegisterAX:calcsize('HH')]
> 
> It looks like you're trying to get a slice of length 4 here, starting
> at the value of RegisterAX. What you're actually getting is a slice
> starting at the value of RegisterAX and ending at 4. You probably want
> this instead:
> 
> tmp = place_to_read.read()[RegisterAX:RegisterAX + calcsize('HH')]
> -- 
> https://mail.python.org/mailman/listinfo/python-list


Even with that, it still gets wrong.
I also tried .read()[RegisterAX:RegisterAX+4]

As for the other suggestions you had in the second reply, I can comment on them 
later.
 For now though, I just want to be able to loop this specific function.

I do appriciate that you took the time. :)

What bothers me, is the error that says 
unpack requires a string argument of 4 bytes.
Im thinking in the line of arguments? Does unpack look at the 4 bytes it has 
read, and tell for some 
reason say that unpacking needs an argument of 4 bytes?  I know that I can set 
the arguments 
for unpack. I have done that.  It is: unpack('>HH', tmp).
So either '>HH' or tmp is wrong. Since '>HH' worked for the first run of the 
function, I assume its correct.
And as far as I know,   doing .read()[RegisterAX:RegisterAX:+4]  should read 
the following
4 bytes.

I have even tried doing .read(4),  since then python should manage where to 
start and  read 4?

Still it complains?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problems using struct pack/unpack in files, and reading them.

2015-11-13 Thread Laura Creighton
I forgot to add.  You get this wretched error message if your data
is shorter than expected, and you ask struct to read more than you
have, as well.  most annoying.

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


Re: Problems using struct pack/unpack in files, and reading them.

2015-11-13 Thread Ian Kelly
On Fri, Nov 13, 2015 at 1:15 PM, kent nyberg  wrote:
> Even with that, it still gets wrong.
> I also tried .read()[RegisterAX:RegisterAX+4]

When you call read for the second time, are you just reading the same
file again without closing or seeking it in the interim? If that's the
case, then you would get an empty string the second time, which would
explain your error.

Either retain the read data between calls, or call seek(0) before
reading it again.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problems using struct pack/unpack in files, and reading them.

2015-11-13 Thread Ian Kelly
On Fri, Nov 13, 2015 at 1:15 PM, kent nyberg  wrote:
> What bothers me, is the error that says
> unpack requires a string argument of 4 bytes.
> Im thinking in the line of arguments? Does unpack look at the 4 bytes it has 
> read, and tell for some
> reason say that unpacking needs an argument of 4 bytes?  I know that I can 
> set the arguments
> for unpack. I have done that.  It is: unpack('>HH', tmp).
> So either '>HH' or tmp is wrong. Since '>HH' worked for the first run of the 
> function, I assume its correct.
> And as far as I know,   doing .read()[RegisterAX:RegisterAX:+4]  should read 
> the following
> 4 bytes.

By the way, I would strongly suggest that you print or log the value
of repr(tmp) so that you *know* what you're passing to unpack rather
than having to speculate about it.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Trying out Kivy

2015-11-13 Thread bayang

Le 13/11/2015 21:10, Cecil Westerhof a écrit :

Purge log fired. Analysing...
Purge finished!
[INFO  ] [Logger  ] Record log in 
/home/cecil/.kivy/logs/kivy_15-11-13_28.txt
[INFO  ] [Kivy] v1.9.0
[INFO  ] [Python  ] v3.4.1 (default, May 23 2014, 17:48:28) 
[GCC]
[INFO  ] [Factory ] 173 symbols loaded
[INFO  ] [Image   ] Providers: img_tex, img_dds, img_gif, 
img_pil (img_pygame, img_ffpyplayer ignored)
[INFO  ] [Text] Provider: pil(['text_pygame'] ignored)
[CRITICAL  ] [Window  ] Unable to find any valuable Window provider 
at all!
egl_rpi - ImportError: cannot import name 'bcm'
   File "/usr/lib64/python3.4/site-packages/kivy/core/__init__.py", line 57, in 
core_select_lib
 fromlist=[modulename], level=0)
   File "/usr/lib64/python3.4/site-packages/kivy/core/window/window_egl_rpi.py", line 
12, in 
 from kivy.lib.vidcore_lite import bcm, egl

pygame - ImportError: No module named 'pygame'
   File "/usr/lib64/python3.4/site-packages/kivy/core/__init__.py", line 57, in 
core_select_lib
 fromlist=[modulename], level=0)
   File "/usr/lib64/python3.4/site-packages/kivy/core/window/window_pygame.py", line 
8, in 
 import pygame

x11 - ImportError: No module named 'kivy.core.window.window_x11'
   File "/usr/lib64/python3.4/site-packages/kivy/core/__init__.py", line 57, in 
core_select_lib
 fromlist=[modulename], level=0)

[CRITICAL  ] [App ] Unable to get a Window, abort.
  Exception ignored in: 'kivy.properties.dpi2px'
  Traceback (most recent call last):
File "/usr/lib64/python3.4/site-packages/kivy/utils.py", line 360, in 
__get__
  retval = self.func(inst)
File "/usr/lib64/python3.4/site-packages/kivy/metrics.py", line 169, in dpi
  EventLoop.ensure_window()
File "/usr/lib64/python3.4/site-packages/kivy/base.py", line 126, in 
ensure_window
  sys.exit(1)
  SystemExit: 1
[CRITICAL  ] [App ] Unable to get a Window, abort.


I see a difference with python2. (Did not notice it before.) With
python3 v1.9.0 is installed, but with python2 v1.8.0.
 [INFO  ] Kivy v1.8.0

Maybe that is the problem?


Pygame doesn't seem to be correctly installed.
check this : http://www.pygame.org/wiki/CompileUbuntu#Python_3.x
in "installing pygame with pip" part.
Install dependencies first, then
pip install hg+http://bitbucket.org/pygame/pygame

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


Re: Problems using struct pack/unpack in files, and reading them.

2015-11-13 Thread Grant Edwards
On 2015-11-13, Ian Kelly  wrote:

> Either retain the read data between calls, or call seek(0) before
> reading it again.

It has always saddened me that Python files don't have a rewind()
method.  On Unix, calling rewind() is the same as calling seek(0), so
it's utterly pointless except as an amusing anachronistic name: it
always made me smile when called rewind() on a file in a filesystem on
a hard-drive.  Interestingly, you can't you can't (and never could)
use rewind() to rewind a tape. You use an ioctl() system call for
that.

-- 
Grant Edwards   grant.b.edwardsYow! HUGH BEAUMONT died
  at   in 1982!!
  gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problems using struct pack/unpack in files, and reading them.

2015-11-13 Thread kent nyberg
The main problem was that I forgot to do seek(0).  Thanks alot people.

Though, as many times before, the problem was due to misunderstanding of how 
python works.
I assumed file.read()[xx:yy] was to be understood as,   in the file, read from 
index xx to place yy.
That is,  [10:20]  was the same as,   read from 10th char to 20th.  Sort of.


Is it true then to say that every .read  of a file, places an index-offset (?) 
from where the next read starts?
That is, I need to rewind the file, or else the read will start from where the 
last read stopped?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: More tkinter Madness

2015-11-13 Thread Christian Gollwitzer

Am 13.11.15 um 20:14 schrieb Tim Daneliuk:

On 11/13/2015 12:32 AM, Christian Gollwitzer wrote:

Apfelkiste:Sources chris$


Well, I get window and when I do this:

pack [button .b -text Hello -command exit]

Nothing appears.


No error, nothing? Just to be sure, you haven't closed the empty window, 
that appeared when you typed "wish"? and copied the command into the 
wish prompt?



tkinter appears borked
I have reinstalled once already, will try again


This is using pure Tcl/Tk. If it is not working, reinstall the 
corresponding packages in your distro. tkinter is merely the Python 
interface to those.


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


Re: Problems using struct pack/unpack in files, and reading them.

2015-11-13 Thread Grant Edwards
On 2015-11-13, kent nyberg  wrote:

> Though, as many times before, the problem was due to misunderstanding
> of how python works. I assumed file.read()[xx:yy] was to be
> understood as, in the file, read from index xx to place yy.

Nope.

   First, the 'file.read()' part is evaluated.  That returns the
   entire contents of the file.

   Next, the '[xx:yy]' slice operation is done on the entire contents
   returned in the first step.  The slice operation retuns bytes xx
   through yy-1 (inclusive), and discards the rest of the data.

> Is it true then to say that every .read of a file, places an
> index-offset (?) from where the next read starts?

Yes.  a file object has a current index.  A read() operation always
starts at that index.  When you open the file, that index is 0.  Each
time you read from the file, the index is advanced past the data that
was read.  The seek() method sets that index to whatever you want.

> That is, I need to rewind the file, or else the read will start from
> where the last read stopped?

Exactly.

-- 
Grant Edwards   grant.b.edwardsYow! Mr and Mrs PED, can I
  at   borrow 26.7% of the RAYON
  gmail.comTEXTILE production of the
   INDONESIAN archipelago?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: More tkinter Madness

2015-11-13 Thread Tim Daneliuk
On 11/13/2015 01:58 PM, Michael Torrie wrote:
> On 11/13/2015 12:14 PM, Tim Daneliuk wrote:
>> On 11/13/2015 12:32 AM, Christian Gollwitzer wrote:
>>> Apfelkiste:Sources chris$
>>
>> Well, I get window and when I do this:
>>
>> pack [button .b -text Hello -command exit]
>>
>> Nothing appears.
>>
>> tkinter appears borked
>>
>> I have reinstalled once already, will try again
> 
> Tkinter is the name of the Python package for using Tk, but Tk itself is
> usually called Tk (package on Fedora and RHEL is tk).
> 
> On my CentOS installs, in /usr/share/tk8.5/demos, there are a number of
> Tcl/Tk demos you can run.  If Tcl and Tk are working, then I would move
> to reinstalling tkinter.
> 

Yep, tcl/tk is borked.  That would explain why pure X apps like xterm work, but 
not tkinter apps.
Reinstalling tcl/tk has not helped at all.  Now I am really curious what the 
interaction is between VPS and tk... Sigh. 


(Thanks)

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


Re: More tkinter Madness

2015-11-13 Thread Tim Daneliuk
On 11/13/2015 03:30 PM, Christian Gollwitzer wrote:
> Am 13.11.15 um 20:14 schrieb Tim Daneliuk:
>> On 11/13/2015 12:32 AM, Christian Gollwitzer wrote:
>>> Apfelkiste:Sources chris$
>>
>> Well, I get window and when I do this:
>>
>> pack [button .b -text Hello -command exit]
>>
>> Nothing appears.
> 
> No error, nothing? Just to be sure, you haven't closed the empty window, that 
> appeared when you typed "wish"? and copied the command into the wish prompt?
> 
>> tkinter appears borked
>> I have reinstalled once already, will try again
> 
> This is using pure Tcl/Tk. If it is not working, reinstall the corresponding 
> packages in your distro. tkinter is merely the Python interface to those.
> 
> Christian

Yep tcl/tk is the culprit, but reinstalling has not helped.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: More tkinter Madness

2015-11-13 Thread Tim Daneliuk
On 11/13/2015 01:56 PM, Laura Creighton wrote:
> In a message of Fri, 13 Nov 2015 13:14:08 -0600, Tim Daneliuk writes:
>> On 11/13/2015 12:32 AM, Christian Gollwitzer wrote:
>>> Apfelkiste:Sources chris$
>>
>> Well, I get window and when I do this:
>>
>> pack [button .b -text Hello -command exit]
>>
>> Nothing appears.
>>
>> tkinter appears borked
>>
>> I have reinstalled once already, will try again
> 
> Next idea.
> 
> Try to run a basic Tk app and a basic Tcl one.  See if they work or not.
> 
> Laura
> 

Looks like tcl/tk is hosed for some reason.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problems using struct pack/unpack in files, and reading them.

2015-11-13 Thread Chris Angelico
On Sat, Nov 14, 2015 at 6:45 AM, Ian Kelly  wrote:
> This sets RegisterAX to 2. Specifically, positive 2. If you want to
> *add* 2, you probably meant to write:
>
> RegisterAX += 2
>
> This also points out a good reason for using spaces around operators,
> as "RegisterAX =+ 2" would have caused a SyntaxError and been more
> easily detectable.

Err, no. Even with spaces, it works just fine, because unary plus is
allowed to be separated from its operand with spaces:

>>> x=1
>>> x =+ 2
>>> x = + 3
>>> x
3

However, this is a reasonable call for the abolition of unary plus...

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


What is '@' for

2015-11-13 Thread fl
Hi,

I read the following code snippet. A question is here about '@'.
I don't find the answer online yet.

What function is it here?

BTW, below is for printing out?
"""theta = logit^{-1}(a+b)"""

but I don't see it is printed when the following could have been called.

Are you sure it would be printed out?


Thanks,





.
import pymc
import numpy as np

n = 5*np.ones(4,dtype=int)
x = np.array([-.86,-.3,-.05,.73])
alpha = pymc.Normal('alpha',mu=0,tau=.01)
beta = pymc.Normal('beta',mu=0,tau=.01)

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

d = pymc.Binomial('d', n=n, p=theta, value=np.array([0.,1.,3.,5.]),\
observed=True)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What is '@' for

2015-11-13 Thread Chris Angelico
On Sat, Nov 14, 2015 at 10:04 AM, fl  wrote:
> I read the following code snippet. A question is here about '@'.
> I don't find the answer online yet.
>
> What function is it here?
>
>
> @pymc.deterministic
> def theta(a=alpha, b=beta):
> """theta = logit^{-1}(a+b)"""
> return pymc.invlogit(a+b*x)

That's called a "function decorator". And now that you know the name,
you'll be able to find what it is online; as well as the Python docs,
there are a number of blog posts and other articles about it.

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


Re: What is '@' for

2015-11-13 Thread Terry Reedy

On 11/13/2015 6:04 PM, fl wrote:


I read the following code snippet. A question is here about '@'.
I don't find the answer online yet.


Start with the index of the fine docs, which includes symbols.
https://docs.python.org/3/genindex-Symbols.html
'@' is near the end of the page.


@pymc.deterministic
def theta(a=alpha, b=beta):



--
Terry Jan Reedy

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


Re: What is '@' for

2015-11-13 Thread Tim Daneliuk
On 11/13/2015 05:14 PM, Chris Angelico wrote:
> On Sat, Nov 14, 2015 at 10:04 AM, fl  wrote:
>> I read the following code snippet. A question is here about '@'.
>> I don't find the answer online yet.
>>
>> What function is it here?
>>
>>
>> @pymc.deterministic
>> def theta(a=alpha, b=beta):
>> """theta = logit^{-1}(a+b)"""
>> return pymc.invlogit(a+b*x)
> 
> That's called a "function decorator". And now that you know the name,
> you'll be able to find what it is online; as well as the Python docs,
> there are a number of blog posts and other articles about it.
> 
> ChrisA
> 


One small point of order ... if you want to be precise, "@pymc.deterministic" 
is a *function decoration*.  The "decorator" is the function 
pymc.deterministic().

I know this is a fussy point, but this distinction is helpful when first 
learning the concept.
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2015-11-13 Thread Gregory Ewing

Dave Farrance wrote:

Yep, he's evidently used to the Matlab/Octave way of defining "vectors"
which is somewhat easier for a math-oriented interactive environment.

It's just a *bit* more laborious to append columns in numpy.


Yes, that's probably the main reason to do things that way.
A collection of vectors is most conveniently represented as
a 2D array where the first index selects one of the vectors.
But then to apply a transformation matrix to all the vectors,
you need to transpose the matrix and multiply it on the
right.

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


Jython standalone

2015-11-13 Thread vjp2 . at
I click jython.org standalone jar and it just does a wait cycle.

What does it need to give me a prompt?


- = -
 Vasos Panagiotopoulos, Columbia'81+, Reagan, Mozart, Pindus, BioStrategist
http://www.panix.com/~vjp2/vasos.htm
  ---{Nothing herein constitutes advice.  Everything fully disclaimed.}---
   [Homeland Security means private firearms not lazy obstructive guards]
 [Urb sprawl confounds terror] [Phooey on GUI: Windows for subprime Bimbos]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question about math.pi is mutable

2015-11-13 Thread Larry Hudson via Python-list

On 11/13/2015 01:19 AM, Denis McMahon wrote:

On Fri, 13 Nov 2015 09:04:54 +1100, Steven D'Aprano wrote:


On Fri, 13 Nov 2015 07:40 am, Thomas 'PointedEars' Lahn wrote:



[crap I expect]



And you should consider the irony, and hypocrisy, of somebody who signs
his posts "PointedEars" bitching about supposed "real names".


TPEL has been trolling html, php and javascript newsgroups for years,
recently he seems to have discovered python newsgroups. :(

I found that TPEL post to be particularly amusing/ironic (hilarious, really) when he continued 
by talking about a group that ignores posts by people who don't use real names!   :-)

I generally ignore his posts as well.

 -=- Larry -=- <-- My real name, which is NOT Lawrence (or anything 
similar)!

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


Re: Jython standalone

2015-11-13 Thread Steven D'Aprano
On Sat, 14 Nov 2015 12:35 pm, vjp2...@at.biostrategist.dot.dot.com wrote:

> I click jython.org standalone jar and it just does a wait cycle.

I'm afraid I can't completely understand the problem you are having, since
you haven't really described it with sufficient detail. But my *guess* (and
this really is just a wild guess) is that you have clicked on a program
icon, and then nothing happens, so you think it is waiting. In most
operating systems, you need to *double-click*, not just click, to run the
program. Try double-clicking instead of single-clicking, and see if that
solves your problem.

If this is not your problem, please try explaining your problem. Help us to
help you, by giving us more information about your situation. Otherwise
we're just guessing.

What is "jython.org standalone jar", and where did it come from? Is this
code you wrote yourself, or code you downloaded? Where did you download it
from?

What is it supposed to do? What does it actually do?

What's a "wait cycle"? How long does it wait, and then what happens?

What operating system are you using? Windows, OS X, Linux, something else?
Version number?

Do you have Java installed? Are .jar files associated with the correct Java
executable?

 
> What does it need to give me a prompt?

What sort of prompt to you expect? A Python prompt, DOS prompt, something
else?



-- 
Steven

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


Re: Problems using struct pack/unpack in files, and reading them.

2015-11-13 Thread Steven D'Aprano
On Sat, 14 Nov 2015 09:42 am, Chris Angelico wrote:

> However, this is a reasonable call for the abolition of unary plus...

The only way you'll take unary plus out of Python is by prying it from my
cold, dead hands.


BTW, unary minus suffers from the same "problem":

x =- y  # oops, meant x -= y

If anything, this is an argument against the augmented assignment
short-cuts, rather than the operators.


-- 
Steven

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


Re: Problems using struct pack/unpack in files, and reading them.

2015-11-13 Thread Chris Angelico
On Sat, Nov 14, 2015 at 1:40 PM, Steven D'Aprano  wrote:
> On Sat, 14 Nov 2015 09:42 am, Chris Angelico wrote:
>
>> However, this is a reasonable call for the abolition of unary plus...
>
> The only way you'll take unary plus out of Python is by prying it from my
> cold, dead hands.
>
>
> BTW, unary minus suffers from the same "problem":
>
> x =- y  # oops, meant x -= y
>
> If anything, this is an argument against the augmented assignment
> short-cuts, rather than the operators.

Yes, unary minus has the same issue - but it's a lot more important
than unary plus is. In ECMAScript, unary plus means "force this to be
a number"; what's its purpose in Python?

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


Re: Question about math.pi is mutable

2015-11-13 Thread Michael Torrie
On 11/10/2015 03:03 AM, Antoon Pardon wrote:
> Op 10-11-15 om 00:29 schreef Ben Finney:
>>
>> Who is doing what to whom? The user of the library isn't doing anything
>> to the library author, so what is it the library author would consent
>> to? Instead, you seem to be trying to assert a *power* of the library
>> author to restrict the library user. Such a power is not granted by
>> Python.
> 
> Python is not at liberty to grant or deny such a power. Python is just
> a vehicle in which code is written. The author of a library can restrict
> its use anyway he sees fit.

No he cannot, outside the bounds of copyright law.  Why would you think
otherwise?  The only document that binds the end user in any way is the
copyright license, unless some other formal contract has been arranged.

>> Instead, the library author is obliged to treat the library user as an
>> adult who consents to the freedoms inherent to Python's design, and to
>> not restrict their use of the library needlessly.
> 
> There is no such obligation. And if it was an obligation, you can hardly
> talk about consenting. Consenting adults mean that either party can
> decide on conditions. Once one party is obligated it is no longer consenting.

You are correct there is no obligation, but nor does Python empower the
library developer.   He may attempt obfuscation or other means to
control the use of his library of course, but only copyright grants him
legal authority of any kind.

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


Re: Problems using struct pack/unpack in files, and reading them.

2015-11-13 Thread Ian Kelly
On Nov 13, 2015 8:03 PM, "Chris Angelico"  wrote:
>
> On Sat, Nov 14, 2015 at 1:40 PM, Steven D'Aprano 
wrote:
> > On Sat, 14 Nov 2015 09:42 am, Chris Angelico wrote:
> >
> >> However, this is a reasonable call for the abolition of unary plus...
> >
> > The only way you'll take unary plus out of Python is by prying it from
my
> > cold, dead hands.
> >
> >
> > BTW, unary minus suffers from the same "problem":
> >
> > x =- y  # oops, meant x -= y
> >
> > If anything, this is an argument against the augmented assignment
> > short-cuts, rather than the operators.
>
> Yes, unary minus has the same issue - but it's a lot more important
> than unary plus is. In ECMAScript, unary plus means "force this to be
> a number"; what's its purpose in Python?

It forces a Counter to contain only positive counts?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problems using struct pack/unpack in files, and reading them.

2015-11-13 Thread Ian Kelly
On Nov 13, 2015 8:03 PM, "Chris Angelico"  wrote:
>
> On Sat, Nov 14, 2015 at 1:40 PM, Steven D'Aprano 
wrote:
> > On Sat, 14 Nov 2015 09:42 am, Chris Angelico wrote:
> >
> >> However, this is a reasonable call for the abolition of unary plus...
> >
> > The only way you'll take unary plus out of Python is by prying it from
my
> > cold, dead hands.
> >
> >
> > BTW, unary minus suffers from the same "problem":
> >
> > x =- y  # oops, meant x -= y
> >
> > If anything, this is an argument against the augmented assignment
> > short-cuts, rather than the operators.
>
> Yes, unary minus has the same issue - but it's a lot more important
> than unary plus is. In ECMAScript, unary plus means "force this to be
> a number"; what's its purpose in Python?

I'm not sure "force this to be a number" is really a justification. Without
it you could just use - - (but be careful not to write that as --) in the
manner of using !! as "force to boolean". Or just call Number().
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problems using struct pack/unpack in files, and reading them.

2015-11-13 Thread Chris Angelico
On Sat, Nov 14, 2015 at 2:45 PM, Ian Kelly  wrote:
>> Yes, unary minus has the same issue - but it's a lot more important
>> than unary plus is. In ECMAScript, unary plus means "force this to be
>> a number"; what's its purpose in Python?
>
> It forces a Counter to contain only positive counts?

Did not know that, and would not have gone looking for it. If Python
hadn't had a unary plus operator, Counter would have managed in some
other way, without being materially impacted by it.

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


Re: find which Python libraries are most influential in scientific research

2015-11-13 Thread Ian Kelly
On Nov 9, 2015 7:41 PM, "Heather Piwowar"  wrote:
>
> Today's scientists often turn to Python to run analysis, simulation, and
other sciency tasks.
>
> That makes us wonder: which Python libraries are most influential in
scientific research?
>
> We just released a tool (built in Python, of course) to answer that
question. It's called Depsy [1], it's funded by the US National Science
Foundation, and we'd love your comments.
>
> For more information, see our blog post [2] and paper [3].  The
scientific/engineering tag is a great place to start exploring [4].
>
> Heather Piwowar and Jason Priem
>
> 1. http://depsy.org
> 2. http://blog.impactstory.org/introducing-depsy
> 3.
https://github.com/Impactstory/depsy-research/blob/master/introducing_depsy.md
> 4. http://depsy.org/tag/scientific%252Fengineering

FYI, the depsy.org site is completely unusable on my Android phone.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problems using struct pack/unpack in files, and reading them.

2015-11-13 Thread Chris Angelico
On Sat, Nov 14, 2015 at 2:48 PM, Ian Kelly  wrote:
>> Yes, unary minus has the same issue - but it's a lot more important
>> than unary plus is. In ECMAScript, unary plus means "force this to be
>> a number"; what's its purpose in Python?
>
> I'm not sure "force this to be a number" is really a justification. Without
> it you could just use - - (but be careful not to write that as --) in the
> manner of using !! as "force to boolean". Or just call Number().

I don't use it myself, but I saw something about asm.js that
demonstrated the use of "x = +x;" to mean "x is a number", and "x =
x|0;" to mean "x is an integer".

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


Re: find which Python libraries are most influential in scientific research

2015-11-13 Thread Terry Reedy

On 11/13/2015 10:58 PM, Ian Kelly wrote:

On Nov 9, 2015 7:41 PM, "Heather Piwowar"  wrote:


Today's scientists often turn to Python to run analysis, simulation, and

other sciency tasks.


That makes us wonder: which Python libraries are most influential in

scientific research?


Numpy, scipy, ?, ?, ?, ...


We just released a tool (built in Python, of course) to answer that

question. It's called Depsy [1], it's funded by the US National Science
Foundation, and we'd love your comments.


For more information, see our blog post [2] and paper [3].  The

scientific/engineering tag is a great place to start exploring [4].


Heather Piwowar and Jason Priem

1. http://depsy.org
2. http://blog.impactstory.org/introducing-depsy
3.

https://github.com/Impactstory/depsy-research/blob/master/introducing_depsy.md

4. http://depsy.org/tag/scientific%252Fengineering


FYI, the depsy.org site is completely unusable on my Android phone.


Ditto Win10, Firefox.


--
Terry Jan Reedy

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


Re: Problems using struct pack/unpack in files, and reading them.

2015-11-13 Thread Steven D'Aprano
On Sat, 14 Nov 2015 02:01 pm, Chris Angelico wrote:

> On Sat, Nov 14, 2015 at 1:40 PM, Steven D'Aprano 
> wrote:
>> On Sat, 14 Nov 2015 09:42 am, Chris Angelico wrote:
>>
>>> However, this is a reasonable call for the abolition of unary plus...
>>
>> The only way you'll take unary plus out of Python is by prying it from my
>> cold, dead hands.
>>
>>
>> BTW, unary minus suffers from the same "problem":
>>
>> x =- y  # oops, meant x -= y
>>
>> If anything, this is an argument against the augmented assignment
>> short-cuts, rather than the operators.
> 
> Yes, unary minus has the same issue - but it's a lot more important
> than unary plus is. In ECMAScript, unary plus means "force this to be
> a number"; what's its purpose in Python?


Python has operator overloading, so it can be anything you want it to be.
E.g. you might have a DSL where +feature turns something on and -feature
turns it off.


Decimal uses it to force the current precision and rounding, regardless of
what the number was initiated to:


py> from decimal import *
py> setcontext(Context(prec=5))
py> d = Decimal("12.34567890")
py> print(d, +d)
12.34567890 12.346


Counter uses it to strip zero and negative counts:


py> from collections import Counter
py> d = Counter(a=3, b=-3)
py> print(d)
Counter({'a': 3, 'b': -3})
py> print(+d)
Counter({'a': 3})


I would expect that symbolic maths software like Sympy probably has use of a
unary plus operator, but I'm not sure.


It's probably too late now, but if I had designed the Fraction class, I
would have made it inherit from a pure Rational class that didn't
automatically normalise (there are interesting operations that rely on
distinguishing fractions like 1/2 and 2/4), and have + perform
normalisation:

x = Rational(2, 4)
print(x, +x)
=> prints 2/4 1/2


Likewise one might use unary plus to normalise polar or cylindrical
coordinates, etc.

I might consider stealing an idea from Perl and Javascript, and have unary
plus convert strings to a number:

+"123" 
=> returns int 123
+"1.23"
=> returns float 1.23



-- 
Steven

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


Re: find which Python libraries are most influential in scientific research

2015-11-13 Thread Steven D'Aprano
On Sat, 14 Nov 2015 02:58 pm, Ian Kelly wrote:

> FYI, the depsy.org site is completely unusable on my Android phone.

On Firefox under Linux, the page comes up blank.

If I use the NoScript plugin to allow Javascript from the despy.org site,
the page now takes twice as long to load, and still comes up blank.

If I then tell NoScript to allow Javascript from angular-io.github.io, it
eventually loads an extremely garish, multi-coloured page with no dynamic
content. As far as I can see, everything is static text and links, with a
very few GIANT icons, which makes the dependency on Javascript *completely*
unnecessary and quite obnoxious.

For the record, the page contains just under 350 words, and loading it
requires 21 web requests for 947.40 KB of data, or equivalent to
approximately 2700 bytes per word.

Between the difficulty of getting the page to display, and the unfortunate
look of the page once it actually does (it looks like it was designed for
an audience of five year olds, with brightly coloured purple, red, blue,
green, yellow backgrounds and giant-sized text), I wouldn't be in a rush to
explore the project any further.

I wish the authors good luck with the project, but they're not doing
themselves (or us) any favours with the design of the webpage.



-- 
Steven

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


Re: find which Python libraries are most influential in scientific research

2015-11-13 Thread Laura Creighton
In a message of Sat, 14 Nov 2015 00:38:41 -0500, Terry Reedy writes:
>On 11/13/2015 10:58 PM, Ian Kelly wrote:
>> On Nov 9, 2015 7:41 PM, "Heather Piwowar"  wrote:
>>>
>>> Today's scientists often turn to Python to run analysis, simulation, and
>> other sciency tasks.
>>>
>>> That makes us wonder: which Python libraries are most influential in
>> scientific research?
>
>Numpy, scipy, ?, ?, ?, ...

I'd put money on

matplotlib
pandas


>>> We just released a tool (built in Python, of course) to answer that
>> question. It's called Depsy [1], it's funded by the US National Science
>> Foundation, and we'd love your comments.
>>>
>>> For more information, see our blog post [2] and paper [3].  The
>> scientific/engineering tag is a great place to start exploring [4].
>>>
>>> Heather Piwowar and Jason Priem
>>>
>>> 1. http://depsy.org
>>> 2. http://blog.impactstory.org/introducing-depsy
>>> 3.
>> https://github.com/Impactstory/depsy-research/blob/master/introducing_depsy.md
>>> 4. http://depsy.org/tag/scientific%252Fengineering
>>
>> FYI, the depsy.org site is completely unusable on my Android phone.
>
>Ditto Win10, Firefox.

Not looking good under FF here with debian unstable and a smallish
laptop screen, either.

Laura

>-- 
>Terry Jan Reedy

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