licenses

2016-01-09 Thread Martinez, Jorge Alberto (GE Aviation)
Hello
We develop applications here with Python and I want to know if there's issues 
by using.
We use NumPy, PyDaqMx, Py Visa

How can we cover this licensing?

Regards


Jorge Alberto Martinez
GE Aviation Systems
HW Team Manager
GEIQ Power Engineering

T +52 442 456 6446
E [email protected]

Calle Campo Real #1692,
Residencial el Refugio, Querétaro, Qro, CP 76146
Mexico.
GE Imagination at work
I have Feedback for GEIQ




Jorge Alberto Martinez
GE Aviation Systems
HW Team Manager
GEIQ Power Engineering

T +52 442 456 6446
E [email protected]

Calle Campo Real #1692,
Residencial el Refugio, Querétaro, Qro, CP 76146
Mexico.
GE Imagination at work
I have Feedback for GEIQ


-- 
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-09 Thread geraldjuwah
On Friday, 8 January 2016 17:38:11 UTC+1, [email protected]  wrote:
> 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

> could you please share how you bypassed it?

On Friday, 8 January 2016 17:38:11 UTC+1, [email protected]  wrote:
> 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

[no subject]

2016-01-09 Thread tommy roberts
It will not allow my to run python 3.5.1


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


Re: How to remove item from heap efficiently?

2016-01-09 Thread Sven R. Kunze

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: graphs

2016-01-09 Thread Sven R. Kunze

Hi Saski,

Python's dataset processing machine is *pandas*.

Have a look at this cookbook entry here:

http://nbviewer.ipython.org/github/jvns/pandas-cookbook/blob/v0.1/cookbook/Chapter%204%20-%20Find%20out%20on%20which%20weekday%20people%20bike%20the%20most%20with%20groupby%20and%20aggregate.ipynb

Best,
Sven


On 07.01.2016 16: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?
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


Re: How to remove item from heap efficiently?

2016-01-09 Thread Sven R. Kunze

Thanks for your reply.

On 08.01.2016 14:26, Peter Otten wrote:

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.
That is how I do it for now. However, the heap continues to grow which 
needs a periodic clean up.

Another option is to try sorted lists and bisect.

The docs tell me that insertion is not really fast then. :/


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


Problem with 'print'

2016-01-09 Thread pablo gormi
Hello, recently I downloaded python, but when I try to execute one file
with the command 'print' it shows me a error. The error is:

Missing parentheses in call to 'print'

Please help mThank you.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problem with 'print'

2016-01-09 Thread Chris Angelico
On Sat, Jan 9, 2016 at 10:40 PM, pablo gormi  wrote:
> Hello, recently I downloaded python, but when I try to execute one file
> with the command 'print' it shows me a error. The error is:
>
> Missing parentheses in call to 'print'

The error is telling you what you need to do. Put parentheses around
the call to the print() function. :)

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


Re: Problem with 'print'

2016-01-09 Thread Peter Otten
pablo gormi wrote:

> Hello, recently I downloaded python, but when I try to execute one file
> with the command 'print' it shows me a error. The error is:
> 
> Missing parentheses in call to 'print'
> 
> Please help mThank you.

You have downloaded Python 3 and are using Python 2 syntax. 

Learning Python 3 from a book or tutorial that uses Python 2 is no fun; I 
recommend that you use another book that covers Python 3. 

If the book is mandated by your school download Python 2.7 from python.org 
and work through the examples with that interpreter. 

Both Python 2.7 and 3.x can be installed in parallel on the same machine, 
and you can pick up the differences later.

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


Re: Problem with 'print'

2016-01-09 Thread D'Arcy J.M. Cain
On Sat, 9 Jan 2016 12:40:16 +0100
pablo gormi  wrote:
> Hello, recently I downloaded python, but when I try to execute one
> file with the command 'print' it shows me a error. The error is:
> 
> Missing parentheses in call to 'print'

You downloaded Python 3. but your script was written for
Python 2..  You have a few choices.

Remove Python and install Python 2.7.
Edit your script to bring it up to the latest version.
Run 2to3 on your script or even whole directories.

The first may be the easiest but you will have to do one of the others
eventually so I would discourage it.

There are plenty of sites (GIYF) that explain the differences between 2
and 3.  You can manually edit all of your files.

Current Python comes with a program called 2to3 that does 99% of the
work for you.  You should probably review the changes it makes (capture
the output) to see if anything needs to be tweaked.  This is definitely
the best solution IMO.

-- 
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:[email protected] VoIP: sip:[email protected]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: licenses

2016-01-09 Thread Tim Golden

On 08/01/2016 19:41, Martinez, Jorge Alberto (GE Aviation) wrote:

Hello
We develop applications here with Python and I want to know if there's issues 
by using.
We use NumPy, PyDaqMx, Py Visa

How can we cover this licensing?


[copying the answer I've just given over at webmaster@]

I'm not sure we're best placed to answer that, Jorge.

You can see current details for the Python licensing here:

https://docs.python.org/3.6/license.html

The other packages you mention are third-party and you'll have to 
consult their websites / source code for licence details.


TJG

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


Re: Python launcher options

2016-01-09 Thread Tim Golden

On 06/01/2016 00:48, Edward Diener wrote:

The Python launcher in Windows is a neat tool for running multiple
versions of Python 2 and Python 3 at different times. It allows as
options the ability to specify the latest version of either Python 2 or
Python 3 defaulting to the 64-bit version if both exist, or a specific
32-bit or 64-bit version of Python 2 or Python 3. What is missing is the
ability to specify the latest 32-bit version of Python 2 or Python 3.
The equivalent syntax would be '-2-32' or '-3-32'. Is there some reason
why this option has been disallowed ?


As far as I can remember, it's not so much a question of "disallowed" as 
just "not thought of by anyone". If you wanted this to go anywhere, 
could I suggest you create an issue on the Python issue tracker:


  http://bugs.python.org

and mark it as "Windows" in the [Components] field (that makes sure that 
some relevant people get to see it). It's got a much better chance of 
achieving traction if you can actually provide a code patch to implement 
the behaviour. Failing that, at least make a good case which might 
convince one of the developers that it would it be worth their while 
implementing the change.


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


Re: How to remove item from heap efficiently?

2016-01-09 Thread Paul Rubin
"Sven R. Kunze"  writes:
> Basically a task scheduler where tasks can be thrown away once they
> are too long in the queue.

I don't think there's a real nice way to do this with heapq.  The
computer-sciencey way would involve separate balanced tree structures
for the two sorting keys (think of a database table with indexes on two
different columns).

You could look up "timing wheels" for a simpler practical approach that
the Linux kernel scheduler used to use (I think it changed a few years
ago).
-- 
https://mail.python.org/mailman/listinfo/python-list


Understanding how to quote XML string in order to serialize using Python's ElementTree

2016-01-09 Thread kbtyo
My specs:

Python 3.4.3
Windows 7
IDE is Jupyter Notebooks

What I have referenced:

1) 
http://stackoverflow.com/questions/1546717/python-escaping-strings-for-use-in-xml

2)
http://stackoverflow.com/questions/7802418/how-to-properly-escape-single-and-double-quotes

3)http://stackoverflow.com/questions/4972210/escaping-characters-in-a-xml-file-with-python


Here is the data (in CSV format) and script, respectively, (I have tried 
variations on serializing Column 'E' using both Sax and ElementTree):

i)

A,B,C,D,E,F,G,H,I,J
"3","8","1","2312285SChecking10","',0001,0070,","1967-12-25
 22:18:13.471000","2005-12-25 22:18:13.768000","2","70","0"

ii)

#!/usr/bin/python
# -*-  coding: utf-8 -*-
import os.path
import sys
import csv
from io import StringIO 
import xml.etree.cElementTree as ElementTree
from xml.etree.ElementTree import XMLParser
import xml
import xml.sax
from xml.sax import ContentHandler

class MyHandler(xml.sax.handler.ContentHandler):
def __init__(self):
self._charBuffer = []
self._result = []

def _getCharacterData(self):
data = ''.join(self._charBuffer).strip()
self._charBuffer = []
return data.strip() #remove strip() if whitespace is important

def parse(self, f):
xml.sax.parse(f, self)
return self._result


def characters(self, data):
self._charBuffer.append(data)

def startElement(self, name, attrs):
if name == 'Response':
self._result.append({})

def endElement(self, name):
if not name == 'Response': self._result[-1][name] = 
self._getCharacterData()

def read_data(path):
with open(path, 'rU', encoding='utf-8') as data:
reader = csv.DictReader(data, delimiter =',', quotechar="'", 
skipinitialspace=True)
for row in reader:
yield row

if __name__ == "__main__":
empty = ''
Response = 'sample.csv'
for idx, row in enumerate(read_data(Response)):
if idx > 10: break
data = row['E']
print(data) # The before
data = data[1:-1]
data = ""'{}'"".format(data)
print(data) # Sanity check 
# data = '',0001,0070,'
try:
root = ElementTree.XML(data)
# print(root)
except StopIteration:
raise
pass
# xmlstring = StringIO(data)
# print(xmlstring)
# Handler = MyHandler().parse(xmlstring)


Specifically, due to the quoting in the CSV file (which is beyond my control), 
I have had to resort to slicing the string (line 51) and then formatting it 
(line 52).

However the print out from the above attempt is as follows:

"'


  File "", line unknown
ParseError: no element found: line 1, column 69
Interestingly - if I assign the variable "data" (as in line 54) I receive this:

  File "", line 56
data = '',0001,0070,'
 ^
SyntaxError: invalid token

I seek feedback and information on how to address utilizing the most Pythonic 
means to do so. Ideally, is there a method that can leverage ElementTree. Thank 
you, in advance, for your feedback and guidance.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: licenses

2016-01-09 Thread Ben Finney
"Martinez, Jorge Alberto (GE Aviation)" 
writes:

> We develop applications here with Python and I want to know if there's
> issues by using. We use NumPy, PyDaqMx, Py Visa

Those are all free software: meaning, every recipient has freedom to
execute, modify, and/or redistribute the work. So long as the code base
you derive from them is also free software, you will not need to take
special care.

If you intend to make a proprietary work (restricting the freedom of
recipients further), you should consult your lawyer about how to go
about that legally.

> How can we cover this licensing?

The simplest way – no need to get lawyers involved – to comply is to
grant a free-software license (e.g. GNU GPL) to all recipients of your
work.

When you want to derive from an existing work but restrict freedom of
your recipients, that's when you need to pay a lawyer for advice. So I
advise you don't make such a restrictive work.

-- 
 \  “The way to build large Python applications is to componentize |
  `\ and loosely-couple the hell out of everything.” —Aahz |
_o__)  |
Ben Finney

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


Re: Understanding how to quote XML string in order to serialize using Python's ElementTree

2016-01-09 Thread Karim



On 09/01/2016 21:54, kbtyo wrote:

My specs:

Python 3.4.3
Windows 7
IDE is Jupyter Notebooks

What I have referenced:

1) 
http://stackoverflow.com/questions/1546717/python-escaping-strings-for-use-in-xml

2)
http://stackoverflow.com/questions/7802418/how-to-properly-escape-single-and-double-quotes

3)http://stackoverflow.com/questions/4972210/escaping-characters-in-a-xml-file-with-python


Here is the data (in CSV format) and script, respectively, (I have tried 
variations on serializing Column 'E' using both Sax and ElementTree):

i)

A,B,C,D,E,F,G,H,I,J
"3","8","1","2312285SChecking10","',0001,0070,","1967-12-25 22:18:13.471000","2005-12-25 22:18:13.768000","2","70","0"

ii)

#!/usr/bin/python
# -*-  coding: utf-8 -*-
import os.path
import sys
import csv
from io import StringIO
import xml.etree.cElementTree as ElementTree
from xml.etree.ElementTree import XMLParser
import xml
import xml.sax
from xml.sax import ContentHandler

class MyHandler(xml.sax.handler.ContentHandler):
 def __init__(self):
 self._charBuffer = []
 self._result = []

 def _getCharacterData(self):
 data = ''.join(self._charBuffer).strip()
 self._charBuffer = []
 return data.strip() #remove strip() if whitespace is important

 def parse(self, f):
 xml.sax.parse(f, self)
 return self._result
 


 def characters(self, data):
 self._charBuffer.append(data)

 def startElement(self, name, attrs):
 if name == 'Response':
 self._result.append({})

 def endElement(self, name):
 if not name == 'Response': self._result[-1][name] = 
self._getCharacterData()

def read_data(path):
 with open(path, 'rU', encoding='utf-8') as data:
 reader = csv.DictReader(data, delimiter =',', quotechar="'", 
skipinitialspace=True)
 for row in reader:
 yield row

if __name__ == "__main__":
 empty = ''
 Response = 'sample.csv'
 for idx, row in enumerate(read_data(Response)):
 if idx > 10: break
 data = row['E']
 print(data) # The before
 data = data[1:-1]
 data = ""'{}'"".format(data)
 print(data) # Sanity check
# data = '',0001,0070,'
 try:
 root = ElementTree.XML(data)
# print(root)
 except StopIteration:
 raise
 pass
# xmlstring = StringIO(data)
# print(xmlstring)
# Handler = MyHandler().parse(xmlstring)


Specifically, due to the quoting in the CSV file (which is beyond my control), 
I have had to resort to slicing the string (line 51) and then formatting it 
(line 52).

However the print out from the above attempt is as follows:

"'


   File "", line unknown
ParseError: no element found: line 1, column 69
Interestingly - if I assign the variable "data" (as in line 54) I receive this:

   File "", line 56
data = '',0001,0070,'
  ^
SyntaxError: invalid token

I seek feedback and information on how to address utilizing the most Pythonic 
means to do so. Ideally, is there a method that can leverage ElementTree. Thank 
you, in advance, for your feedback and guidance.


I don't understand because this line 54 gives:

>>> import xml.etree.cElementTree as ElementTree
>>> data = 'RequestType="HoldInquiry">',0001,0070,'

  File "", line 1
data = 'RequestType="HoldInquiry">',0001,0070,'

^
SyntaxError: invalid syntax


BUT IF you correct the string and remove the inner quote after  
everything's fine:
>>> data = 'RequestType="HoldInquiry">,0001,0070, 
'

>>> root = ElementTree.XML(data)
>>> root

Karim

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


Re: Understanding how to quote XML string in order to serialize using Python's ElementTree

2016-01-09 Thread Karim



On 09/01/2016 21:54, kbtyo wrote:

My specs:

Python 3.4.3
Windows 7
IDE is Jupyter Notebooks

What I have referenced:

1) 
http://stackoverflow.com/questions/1546717/python-escaping-strings-for-use-in-xml

2)
http://stackoverflow.com/questions/7802418/how-to-properly-escape-single-and-double-quotes

3)http://stackoverflow.com/questions/4972210/escaping-characters-in-a-xml-file-with-python


Here is the data (in CSV format) and script, respectively, (I have tried 
variations on serializing Column 'E' using both Sax and ElementTree):

i)

A,B,C,D,E,F,G,H,I,J
"3","8","1","2312285SChecking10","',0001,0070,","1967-12-25 22:18:13.471000","2005-12-25 22:18:13.768000","2","70","0"

ii)

#!/usr/bin/python
# -*-  coding: utf-8 -*-
import os.path
import sys
import csv
from io import StringIO
import xml.etree.cElementTree as ElementTree
from xml.etree.ElementTree import XMLParser
import xml
import xml.sax
from xml.sax import ContentHandler

class MyHandler(xml.sax.handler.ContentHandler):
 def __init__(self):
 self._charBuffer = []
 self._result = []

 def _getCharacterData(self):
 data = ''.join(self._charBuffer).strip()
 self._charBuffer = []
 return data.strip() #remove strip() if whitespace is important

 def parse(self, f):
 xml.sax.parse(f, self)
 return self._result
 


 def characters(self, data):
 self._charBuffer.append(data)

 def startElement(self, name, attrs):
 if name == 'Response':
 self._result.append({})

 def endElement(self, name):
 if not name == 'Response': self._result[-1][name] = 
self._getCharacterData()

def read_data(path):
 with open(path, 'rU', encoding='utf-8') as data:
 reader = csv.DictReader(data, delimiter =',', quotechar="'", 
skipinitialspace=True)
 for row in reader:
 yield row

if __name__ == "__main__":
 empty = ''
 Response = 'sample.csv'
 for idx, row in enumerate(read_data(Response)):
 if idx > 10: break
 data = row['E']
 print(data) # The before
 data = data[1:-1]
 data = ""'{}'"".format(data)
 print(data) # Sanity check
# data = '',0001,0070,'
 try:
 root = ElementTree.XML(data)
# print(root)
 except StopIteration:
 raise
 pass
# xmlstring = StringIO(data)
# print(xmlstring)
# Handler = MyHandler().parse(xmlstring)


Specifically, due to the quoting in the CSV file (which is beyond my control), 
I have had to resort to slicing the string (line 51) and then formatting it 
(line 52).

However the print out from the above attempt is as follows:

"'


   File "", line unknown
ParseError: no element found: line 1, column 69
Interestingly - if I assign the variable "data" (as in line 54) I receive this:

   File "", line 56
data = '',0001,0070,'
  ^
SyntaxError: invalid token

I seek feedback and information on how to address utilizing the most Pythonic 
means to do so. Ideally, is there a method that can leverage ElementTree. Thank 
you, in advance, for your feedback and guidance.


In  fact to get rid of double quote simply create your csv reader like that:

reader = csv.DictReader(data, dialect='excel', skipinitialspace=True)

You should then don't need to slice data variable and reformat it.

Karim


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


Python 3.4.4 Install

2016-01-09 Thread Colin J. Williams
The reponse is not understood.

*** Python 3.4.4rc1 (v3.4.4rc1:04f3f725896c, Dec  6 2015, 17:06:10) [MSC v.1600 
64 bit (AMD64)] on win32. ***
>>>   File "C:\Users\Adm\AppData\Roaming\PyScripter\python_init.py", line 1
Öü:Vt‡Ö{ZðN)’ƒ2%hóýL"®ÁwÇ,”¿ƾJ
 ^
SyntaxError: invalid syntax
  File "C:\Users\Adm\AppData\Roaming\PyScripter\pyscripter_init.py", line 1
Öü:Vt‡Ö{ZðN)’t—œ2¢í.Tûôø«ÄØ´Õ7l‰ˆ(°¢äßÅ
 ^
SyntaxError: invalid syntax

Help!

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


Re: Python 3.4.4 Install

2016-01-09 Thread Terry Reedy

On 1/9/2016 5:25 PM, Colin J. Williams wrote:

The reponse is not understood.


What part of 'SyntaxError: invalid syntax' do you not understand?


*** Python 3.4.4rc1 (v3.4.4rc1:04f3f725896c, Dec  6 2015, 17:06:10) [MSC v.1600 
64 bit (AMD64)] on win32. ***


Consider replacing with 3.4.4, though not essential.


File "C:\Users\Adm\AppData\Roaming\PyScripter\python_init.py", line 1


This issue seems to be about PyScriptor, not 3.4.


 Öü:Vt‡Ö{ZðN)’ƒ2%hóýL"®ÁwÇ,”¿ƾJ
  ^


This is obviously gibberish as interpreted.  Perhaps you should 
re-install PyScriptor.  Make sure you have a version meant to run with 
3.x rather than 2.x.



SyntaxError: invalid syntax


'ab:' will give the same error in the same place. A colon cannot follow 
an identifier at the beginning of a line.


--
Terry Jan Reedy


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


Re: Understanding how to quote XML string in order to serialize using Python's ElementTree

2016-01-09 Thread Saran Ahluwalia
As mentioned previously, I assigned the variable *data *to the string
''',0001,0070,". When any utility that
attempts to parse this string (this is one example of millions found in my
actual data source) you receive that error. You would need to comment out
the following:

data = row['E']
print(data) # The before
data = data[1:-1]
data = ""'{}'"".format(data)
print(data) # Sanity check

to achieve the readout.

Unfortunately, I am wondering if there is a scalable solution to the above
issue (perhaps using some form of escape character or regex?). I have ideas
and have tried many but to no avail. There always seems to be an edge case
that escapes me. Thanks.

On Sat, Jan 9, 2016 at 5:08 PM, Karim  wrote:

>
>
> On 09/01/2016 21:54, kbtyo wrote:
>
>> My specs:
>>
>> Python 3.4.3
>> Windows 7
>> IDE is Jupyter Notebooks
>>
>> What I have referenced:
>>
>> 1)
>> http://stackoverflow.com/questions/1546717/python-escaping-strings-for-use-in-xml
>>
>> 2)
>>
>> http://stackoverflow.com/questions/7802418/how-to-properly-escape-single-and-double-quotes
>>
>> 3)
>> http://stackoverflow.com/questions/4972210/escaping-characters-in-a-xml-file-with-python
>>
>>
>> Here is the data (in CSV format) and script, respectively, (I have tried
>> variations on serializing Column 'E' using both Sax and ElementTree):
>>
>> i)
>>
>> A,B,C,D,E,F,G,H,I,J
>> "3","8","1","> />2312> />285SChecking10","> TransactionID="2"
>> RequestType="HoldInquiry">',0001,0070,","1967-12-25
>> 22:18:13.471000","2005-12-25 22:18:13.768000","2","70","0"
>>
>> ii)
>>
>> #!/usr/bin/python
>> # -*-  coding: utf-8 -*-
>> import os.path
>> import sys
>> import csv
>> from io import StringIO
>> import xml.etree.cElementTree as ElementTree
>> from xml.etree.ElementTree import XMLParser
>> import xml
>> import xml.sax
>> from xml.sax import ContentHandler
>>
>> class MyHandler(xml.sax.handler.ContentHandler):
>>  def __init__(self):
>>  self._charBuffer = []
>>  self._result = []
>>
>>  def _getCharacterData(self):
>>  data = ''.join(self._charBuffer).strip()
>>  self._charBuffer = []
>>  return data.strip() #remove strip() if whitespace is important
>>
>>  def parse(self, f):
>>  xml.sax.parse(f, self)
>>  return self._result
>>
>>  def characters(self, data):
>>  self._charBuffer.append(data)
>>
>>  def startElement(self, name, attrs):
>>  if name == 'Response':
>>  self._result.append({})
>>
>>  def endElement(self, name):
>>  if not name == 'Response': self._result[-1][name] =
>> self._getCharacterData()
>>
>> def read_data(path):
>>  with open(path, 'rU', encoding='utf-8') as data:
>>  reader = csv.DictReader(data, delimiter =',', quotechar="'",
>> skipinitialspace=True)
>>  for row in reader:
>>  yield row
>>
>> if __name__ == "__main__":
>>  empty = ''
>>  Response = 'sample.csv'
>>  for idx, row in enumerate(read_data(Response)):
>>  if idx > 10: break
>>  data = row['E']
>>  print(data) # The before
>>  data = data[1:-1]
>>  data = ""'{}'"".format(data)
>>  print(data) # Sanity check
>> # data = '> RequestType="HoldInquiry">',0001,0070,'
>>  try:
>>  root = ElementTree.XML(data)
>> # print(root)
>>  except StopIteration:
>>  raise
>>  pass
>> # xmlstring = StringIO(data)
>> # print(xmlstring)
>> # Handler = MyHandler().parse(xmlstring)
>>
>>
>> Specifically, due to the quoting in the CSV file (which is beyond my
>> control), I have had to resort to slicing the string (line 51) and then
>> formatting it (line 52).
>>
>> However the print out from the above attempt is as follows:
>>
>> "'
>> 
>>
>>File "", line unknown
>> ParseError: no element found: line 1, column 69
>> Interestingly - if I assign the variable "data" (as in line 54) I receive
>> this:
>>
>>File "", line 56
>> data = '> RequestType="HoldInquiry">',0001,0070,'
>>   ^
>> SyntaxError: invalid token
>>
>> I seek feedback and information on how to address utilizing the most
>> Pythonic means to do so. Ideally, is there a method that can leverage
>> ElementTree. Thank you, in advance, for your feedback and guidance.
>>
>
> I don't understand because this line 54 gives:
>
> >>> import xml.etree.cElementTree as ElementTree
> >>> data = ' RequestType="HoldInquiry">',0001,0070,'
>   File "", line 1
> data = ' RequestType="HoldInquiry">',0001,0070,'
> ^
> SyntaxError: invalid syntax
>
>
> BUT IF you correct the string and remove the inner quote after 
> everything's fine:
> >>> data = ' RequestType="HoldInquiry">,0001,0070,
> '
> >>> root = ElementTree.XML(data)
> >>> root
> 
> Karim
>
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Understanding how to quote XML string in order to serialize using Python's ElementTree

2016-01-09 Thread Saran Ahluwalia
Thank you for the feedback on this. I believe that the excel dialect
includes just that:

class excel(Dialect):
delimiter = ','
quotechar = '"'
doublequote = True
skipinitialspace = False
lineterminator = '\r\n'
quoting = QUOTE_MINIMAL


On Sat, Jan 9, 2016 at 5:23 PM, Karim  wrote:

>
>
> On 09/01/2016 21:54, kbtyo wrote:
>
>> My specs:
>>
>> Python 3.4.3
>> Windows 7
>> IDE is Jupyter Notebooks
>>
>> What I have referenced:
>>
>> 1)
>> http://stackoverflow.com/questions/1546717/python-escaping-strings-for-use-in-xml
>>
>> 2)
>>
>> http://stackoverflow.com/questions/7802418/how-to-properly-escape-single-and-double-quotes
>>
>> 3)
>> http://stackoverflow.com/questions/4972210/escaping-characters-in-a-xml-file-with-python
>>
>>
>> Here is the data (in CSV format) and script, respectively, (I have tried
>> variations on serializing Column 'E' using both Sax and ElementTree):
>>
>> i)
>>
>> A,B,C,D,E,F,G,H,I,J
>> "3","8","1","> />2312> />285SChecking10","> TransactionID="2"
>> RequestType="HoldInquiry">',0001,0070,","1967-12-25
>> 22:18:13.471000","2005-12-25 22:18:13.768000","2","70","0"
>>
>> ii)
>>
>> #!/usr/bin/python
>> # -*-  coding: utf-8 -*-
>> import os.path
>> import sys
>> import csv
>> from io import StringIO
>> import xml.etree.cElementTree as ElementTree
>> from xml.etree.ElementTree import XMLParser
>> import xml
>> import xml.sax
>> from xml.sax import ContentHandler
>>
>> class MyHandler(xml.sax.handler.ContentHandler):
>>  def __init__(self):
>>  self._charBuffer = []
>>  self._result = []
>>
>>  def _getCharacterData(self):
>>  data = ''.join(self._charBuffer).strip()
>>  self._charBuffer = []
>>  return data.strip() #remove strip() if whitespace is important
>>
>>  def parse(self, f):
>>  xml.sax.parse(f, self)
>>  return self._result
>>
>>  def characters(self, data):
>>  self._charBuffer.append(data)
>>
>>  def startElement(self, name, attrs):
>>  if name == 'Response':
>>  self._result.append({})
>>
>>  def endElement(self, name):
>>  if not name == 'Response': self._result[-1][name] =
>> self._getCharacterData()
>>
>> def read_data(path):
>>  with open(path, 'rU', encoding='utf-8') as data:
>>  reader = csv.DictReader(data, delimiter =',', quotechar="'",
>> skipinitialspace=True)
>>  for row in reader:
>>  yield row
>>
>> if __name__ == "__main__":
>>  empty = ''
>>  Response = 'sample.csv'
>>  for idx, row in enumerate(read_data(Response)):
>>  if idx > 10: break
>>  data = row['E']
>>  print(data) # The before
>>  data = data[1:-1]
>>  data = ""'{}'"".format(data)
>>  print(data) # Sanity check
>> # data = '> RequestType="HoldInquiry">',0001,0070,'
>>  try:
>>  root = ElementTree.XML(data)
>> # print(root)
>>  except StopIteration:
>>  raise
>>  pass
>> # xmlstring = StringIO(data)
>> # print(xmlstring)
>> # Handler = MyHandler().parse(xmlstring)
>>
>>
>> Specifically, due to the quoting in the CSV file (which is beyond my
>> control), I have had to resort to slicing the string (line 51) and then
>> formatting it (line 52).
>>
>> However the print out from the above attempt is as follows:
>>
>> "'
>> 
>>
>>File "", line unknown
>> ParseError: no element found: line 1, column 69
>> Interestingly - if I assign the variable "data" (as in line 54) I receive
>> this:
>>
>>File "", line 56
>> data = '> RequestType="HoldInquiry">',0001,0070,'
>>   ^
>> SyntaxError: invalid token
>>
>> I seek feedback and information on how to address utilizing the most
>> Pythonic means to do so. Ideally, is there a method that can leverage
>> ElementTree. Thank you, in advance, for your feedback and guidance.
>>
>
> In  fact to get rid of double quote simply create your csv reader like
> that:
>
> reader = csv.DictReader(data, dialect='excel', skipinitialspace=True)
>
> You should then don't need to slice data variable and reformat it.
>
> Karim
>
>
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Understanding how to quote XML string in order to serialize using Python's ElementTree

2016-01-09 Thread Karim


Yes it changes your quotechar = "'" into quotechar = '"'

You should no more get the double quoting of the data string and no more 
slicing step.


Karim

On 10/01/2016 00:15, Saran Ahluwalia wrote:
Thank you for the feedback on this. I believe that the excel dialect 
includes just that:


class excel(Dialect):
 delimiter = ','
 quotechar = '"'
 doublequote = True
 skipinitialspace = False
 lineterminator = '\r\n'
 quoting = QUOTE_MINIMAL

On Sat, Jan 9, 2016 at 5:23 PM, Karim > wrote:




On 09/01/2016 21:54, kbtyo wrote:

My specs:

Python 3.4.3
Windows 7
IDE is Jupyter Notebooks

What I have referenced:

1)

http://stackoverflow.com/questions/1546717/python-escaping-strings-for-use-in-xml

2)

http://stackoverflow.com/questions/7802418/how-to-properly-escape-single-and-double-quotes


3)http://stackoverflow.com/questions/4972210/escaping-characters-in-a-xml-file-with-python


Here is the data (in CSV format) and script, respectively, (I
have tried variations on serializing Column 'E' using both Sax
and ElementTree):

i)

A,B,C,D,E,F,G,H,I,J
"3","8","1","2312285SChecking10","',0001,0070,","1967-12-25
22:18:13.471000","2005-12-25 22:18:13.768000","2","70","0"

ii)

#!/usr/bin/python
# -*-  coding: utf-8 -*-
import os.path
import sys
import csv
from io import StringIO
import xml.etree.cElementTree as ElementTree
from xml.etree.ElementTree import XMLParser
import xml
import xml.sax
from xml.sax import ContentHandler

class MyHandler(xml.sax.handler.ContentHandler):
 def __init__(self):
 self._charBuffer = []
 self._result = []

 def _getCharacterData(self):
 data = ''.join(self._charBuffer).strip()
 self._charBuffer = []
 return data.strip() #remove strip() if whitespace is
important

 def parse(self, f):
 xml.sax.parse(f, self)
 return self._result

 def characters(self, data):
 self._charBuffer.append(data)

 def startElement(self, name, attrs):
 if name == 'Response':
 self._result.append({})

 def endElement(self, name):
 if not name == 'Response': self._result[-1][name] =
self._getCharacterData()

def read_data(path):
 with open(path, 'rU', encoding='utf-8') as data:
 reader = csv.DictReader(data, delimiter =',',
quotechar="'", skipinitialspace=True)
 for row in reader:
 yield row

if __name__ == "__main__":
 empty = ''
 Response = 'sample.csv'
 for idx, row in enumerate(read_data(Response)):
 if idx > 10: break
 data = row['E']
 print(data) # The before
 data = data[1:-1]
 data = ""'{}'"".format(data)
 print(data) # Sanity check
# data = '',0001,0070,'
 try:
 root = ElementTree.XML(data)
# print(root)
 except StopIteration:
 raise
 pass
# xmlstring = StringIO(data)
# print(xmlstring)
# Handler = MyHandler().parse(xmlstring)


Specifically, due to the quoting in the CSV file (which is
beyond my control), I have had to resort to slicing the string
(line 51) and then formatting it (line 52).

However the print out from the above attempt is as follows:

"'


   File "", line unknown
ParseError: no element found: line 1, column 69
Interestingly - if I assign the variable "data" (as in line
54) I receive this:

   File "", line 56
data = '',0001,0070,'
  ^
SyntaxError: invalid token

I seek feedback and information on how to address utilizing
the most Pythonic means to do so. Ideally, is there a method
that can leverage ElementTree. Thank you, in advance, for your
feedback and guidance.


In  fact to get rid of double quote simply create your csv reader
like that:

reader = csv.DictReader(data, dialect='excel', skipinitialspace=True)

You should then don't need to slice data variable and reformat it.

Karim





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


Re:

2016-01-09 Thread paul.hermeneutic
On Jan 9, 2016 7:56 AM, "tommy roberts"  wrote:
>
> It will not allow my to run python 3.5.1

Python 3.4 is the last version that will run on Windows XP.

If this is not your problem, please provide more information.
-- 
https://mail.python.org/mailman/listinfo/python-list


Help on return type(?)

2016-01-09 Thread Robert
Hi,

I see below code snippet. The return line is not as the usual type.



def make_cov(cov_type, n_comp, n_fea):
mincv = 0.1
rand = np.random.random
return {
'spherical': (mincv + mincv * np.dot(rand((n_components, 1)),
 np.ones((1, n_features ** 2,
'tied': (make_spd_matrix(n_features)
 + mincv * np.eye(n_features)),
'diag': (mincv + mincv * rand((n_components, n_features))) ** 2,
'full': np.array([(make_spd_matrix(n_features)
   + mincv * np.eye(n_features))
  for x in range(n_components)])
}[cov_type]

Specifically, could you explain the meaning of 

{
...}[cov_type]

to me?


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


Re: licenses

2016-01-09 Thread Steven D'Aprano
On Sat, 9 Jan 2016 06:41 am, Martinez, Jorge Alberto (GE Aviation) wrote:

> Hello
> We develop applications here with Python and I want to know if there's
> issues by using. We use NumPy, PyDaqMx, Py Visa
> 
> How can we cover this licensing?


What do you do with those applications? Do you use them in-house, for
customers, or for sale?

Do you distribute NumPy, PyDaqMx and PyVisa? If you do, then you have to
abide by the terms of their licences. Have you read their licences? If not,
you need to read them.

Then you need to talk to your company's lawyer and get their advice.

*** I AM NOT A LAWYER AND THIS IS NOT LEGAL ADVICE ***

Seriously, talk to your lawyer. She or he is the only person who can SAFELY
and ACCURATELY advise you.

But, I would expect that you *probably* can legally distribute Numpy, since
there are other companies which already do this. Numpy is distributed under
the BSD licence, which is very liberal, and is compatible with most
software licences (either free, copyleft, or proprietary/closed). It allows
re-use with very few restrictions, so you shouldn't have any trouble
obeying their terms in your own software.

http://www.numpy.org/license.html

The licence is in English, but it is very simple, less than one page. If you
include Numpy in your software, all you need to do is include a copy of the
Numpy licence. Read the licence for details.

I do not know about PyDaqMx and PyVisa, but my recommendation is the same:

- start by reading their licences;
- if they use a well-known Open Source licence, such as BSD, MIT or GPL, 
  you must obey the terms of the licence;

- If they use a rare or unknown open source licence, you probably should
  not trust that the licence gives you enough protection. You should 
  contact the project owner and ask him or her to give you a licence to 
  the work using an approved open source licence:

  http://opensource.org/licenses/

- If they use a proprietary, closed-source licence, you probably will 
  not be allowed to distribute their software, or you may have to pay
  them money. You still have to obey the licence.

- But if there are special conditions that apply to you, it doesn't 
  hurt for you to ask for a special licence. The worst that will happen
  is that they will ignore you, or say no.


And finally:

- Check with your lawyer.




-- 
Steven

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


Re: Help on return type(?)

2016-01-09 Thread Steven D'Aprano
On Sun, 10 Jan 2016 12:45 pm, Robert wrote:

> Hi,
> 
> I see below code snippet. The return line is not as the usual type.
> 
> 
> 
> def make_cov(cov_type, n_comp, n_fea):
> mincv = 0.1
> rand = np.random.random
> return {
> 'spherical': (mincv + mincv * np.dot(rand((n_components, 1)),
>  np.ones((1, n_features **
>  2,
> 'tied': (make_spd_matrix(n_features)
>  + mincv * np.eye(n_features)),
> 'diag': (mincv + mincv * rand((n_components, n_features))) ** 2,
> 'full': np.array([(make_spd_matrix(n_features)
>+ mincv * np.eye(n_features))
>   for x in range(n_components)])
> }[cov_type]
> 
> Specifically, could you explain the meaning of
> 
> {
> ...}[cov_type]
> 
> to me?

It is a dictionary lookup. { ... } sets up a dictionary with keys

'spherical'
'tied'
'diag'
'full'

then { ... }[cov_type] extracts one of the values depending on whether
cov_type is 'spherical', 'tied', 'diag', or 'full'.




-- 
Steven

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


Re: Python 3.4.4 Install

2016-01-09 Thread Steven D'Aprano
On Sun, 10 Jan 2016 09:25 am, Colin J. Williams wrote:

> The reponse is not understood.
> 
> *** Python 3.4.4rc1 (v3.4.4rc1:04f3f725896c, Dec  6 2015, 17:06:10) [MSC
> v.1600 64 bit (AMD64)] on win32. ***
   File "C:\Users\Adm\AppData\Roaming\PyScripter\python_init.py", line 1
> Öü:Vt‡Ö{ZðN)’ƒ2%hóýL"®ÁwÇ,”¿ƾJ
>  ^
> SyntaxError: invalid syntax

That doesn't look anything like Python code to me. It looks like you have
corrupted files. Who knows how they have been corrupted. Try re-installing
Pyscripter, or revert from backup. Also, you should make sure you scan your
system for viruses (possibly you have a randsomware virus encrypting files
behind your back) and do a disk check in case the disk is dying.




-- 
Steven

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


Re: Help on return type(?)

2016-01-09 Thread Martin A. Brown

Hello there,

>> def make_cov(cov_type, n_comp, n_fea):
>> mincv = 0.1
>> rand = np.random.random
>> return {
>> 'spherical': (mincv + mincv * np.dot(rand((n_components, 1)),
>>  np.ones((1, n_features **
>>  2,
>> 'tied': (make_spd_matrix(n_features)
>>  + mincv * np.eye(n_features)),
>> 'diag': (mincv + mincv * rand((n_components, n_features))) ** 2,
>> 'full': np.array([(make_spd_matrix(n_features)
>>+ mincv * np.eye(n_features))
>>   for x in range(n_components)])
>> }[cov_type]
>> 
>> Specifically, could you explain the meaning of
>> 
>> {
>> ...}[cov_type]
>> 
>> to me?
>
>It is a dictionary lookup. { ... } sets up a dictionary with keys
>
>'spherical'
>'tied'
>'diag'
>'full'
>
>then { ... }[cov_type] extracts one of the values depending on 
>whether cov_type is 'spherical', 'tied', 'diag', or 'full'.

You will see that Steven has answered your question.  I will add to 
his answer.

Your original function could be improved many ways, but especially 
in terms of readability.  Here's how I might go at improving the 
readability, without understanding anything about the actual 
computation.
  
  def make_cov_spherical(mincv, n_components, n_features):
  return (mincv + mincv * np.dot(np.random.random((n_components, 1)), 
np.ones((1, n_features ** 2
 
  def make_cov_diag(mincv, n_components, n_features):
  return (mincv + mincv * np.random.random((n_components, n_features))) ** 2
 
  def make_cov_tied(mincv, n_components, n_features):
  return make_spd_matrix(n_features) + mincv * np.eye(n_features)
 
  def make_cov_full(mincv, n_components, n_features):
  return np.array([(make_spd_matrix(n_features) + mincv * 
np.eye(n_features)) for x in range(n_components)])
 
  def make_cov(cov_type, n_comp, n_fea):
  mincv = 0.1
  dispatch_table = {
  'spherical': make_cov_spherical,
  'tied': make_cov_tied,
  'diag': make_cov_diag,
  'full': make_cov_full,
  }
  func = dispatch_table[cov_type]
  return func(mincv, n_comp, n_fea)

Some thoughts (and reaction to the prior code):

  * Your originally posted code referred to n_comp and n_fea in the 
signature, but then used n_components and n_features in the 
processing lines.  Did this function ever work?

  * Individual functions are easier to read and understand.  I would
find it easier to write testing code (and docstrings) for these 
functions, also.

  * The assignment of a name (rand = np.random.random) can make 
sense, but I think it simply shows that the original function 
was trying to do too many things and was hoping to save space
with this shorter name for the np.random.random.  Not bad, but I 
dropped it anyway for the sake of clarity.

  * Each of the above functions (which I copied nearly verbatim) 
could probably now be broken into one or two lines.  That would 
make the computation even clearer.

  * There may be a better way to make a function dispatch table than 
the one I demonstrate above, but I think it makes the point 
nicely.

  * If you break the individual computations into functions, then 
you only run the specific computation when it's needed.  In the 
original example, all of the computations were run AND then, one 
of the results was selected.  It may not matter, since computers 
are so fast, but, practicing basic parsimony can avoid little 
obvious performance hazards like this.

  * In short, longer, but much much clearer.

Good luck,

-Martin

-- 
Martin A. Brown
http://linux-ip.net/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help on return type(?)

2016-01-09 Thread Rustom Mody
On Sunday, January 10, 2016 at 7:16:23 AM UTC+5:30, Robert wrote:
> Hi,
> 
> I see below code snippet. The return line is not as the usual type.
> 
> 
> 
> def make_cov(cov_type, n_comp, n_fea):
> mincv = 0.1
> rand = np.random.random
> return {
> 'spherical': (mincv + mincv * np.dot(rand((n_components, 1)),
>  np.ones((1, n_features ** 2,
> 'tied': (make_spd_matrix(n_features)
>  + mincv * np.eye(n_features)),
> 'diag': (mincv + mincv * rand((n_components, n_features))) ** 2,
> 'full': np.array([(make_spd_matrix(n_features)
>+ mincv * np.eye(n_features))
>   for x in range(n_components)])
> }[cov_type]
> 
> Specifically, could you explain the meaning of 
> 
> {
> ...}[cov_type]
> 
> to me?
> 
> 
> Thanks,

May help if you see it in pseudo-C like this

 switch (cov_type)

   case 'spherical': return (mincv + mincv * np.dot(rand((n_components, 1)),
  np.ones((1, n_features ** 2,
   case 'tied': return (make_spd_matrix(n_features)
  + mincv * np.eye(n_features)),
   case 'diag': return (mincv + mincv * rand((n_components, n_features))) 
** 2,
   case  'full': return np.array([(make_spd_matrix(n_features)
+ mincv * np.eye(n_features))
   for x in range(n_components)])
 

Yeah looks backward in python compared to the C-ish
The python is more powerful however because its *data-driven* 
ie what is code in C is data in python.

BTW this is one of the motley components collected together under the somewhat
inept moniker of 'functional programming':
http://blog.languager.org/2012/10/functional-programming-lost-booty.html

Also you can make the python look less backward by naming the dictionary,
separate from the lookup:

d = {'spherical' : ..., 'tied' :..., 'diag' : ...}
return d[cov_type]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python launcher options

2016-01-09 Thread Edward Diener

On 1/9/2016 11:03 AM, Tim Golden wrote:

On 06/01/2016 00:48, Edward Diener wrote:

The Python launcher in Windows is a neat tool for running multiple
versions of Python 2 and Python 3 at different times. It allows as
options the ability to specify the latest version of either Python 2 or
Python 3 defaulting to the 64-bit version if both exist, or a specific
32-bit or 64-bit version of Python 2 or Python 3. What is missing is the
ability to specify the latest 32-bit version of Python 2 or Python 3.
The equivalent syntax would be '-2-32' or '-3-32'. Is there some reason
why this option has been disallowed ?


As far as I can remember, it's not so much a question of "disallowed" as
just "not thought of by anyone". If you wanted this to go anywhere,
could I suggest you create an issue on the Python issue tracker:

   http://bugs.python.org

and mark it as "Windows" in the [Components] field (that makes sure that
some relevant people get to see it). It's got a much better chance of
achieving traction if you can actually provide a code patch to implement
the behaviour. Failing that, at least make a good case which might
convince one of the developers that it would it be worth their while
implementing the change.


I have tried to register with the link above so I can an issue with the 
Python Issue tracker but all attempts fail with:


"Failed issue tracker submission

An unexpected error occurred during the processing
of your message. The tracker administrator is being
notified."


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


pyd file for python package using cython

2016-01-09 Thread Palpandi
Hi All,

I have a package structure,

A ( uses files from B and C)
B ( init.py, a,py, b.py)
C ( init.py, c.py, d.py)

How to create a pyd file structure for above package structure?
Is it possible to create a single pyd file?
Do I need cython to run pyd file?

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


When I need classes?

2016-01-09 Thread Arshpreet Singh
Hello Friends, I am quite new to OOP(object oriented Programming), I did some 
projects with python which includes Data-Analysis, Flask Web Development and 
some simple scripts. 

I have only one question which is bothering me most of the time, When I will 
get the need to use Classes in Python? Or in other way is there any real-life 
example where you can tell me this problem/solution is kind of impossible in 
Python without Classes?
-- 
https://mail.python.org/mailman/listinfo/python-list