Re: OT Re: Math-embarrassment results in CS [was: Should non-security 2.7 bugs be fixed?]

2015-07-23 Thread Gregory Ewing

Rustom Mody wrote:
Ive known good ones) most practicing-mathematicians proceed on the assumption 
that they *discover* math and not that they *invent* it.


For something purely abstract like mathematics, I don't
see how there's any distinction between "discovering" and
"inventing". They're two words for the same thing.

I don't know what kind of -ist that makes me...

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


Re: password authentication failed

2015-07-23 Thread Gary Roach

On 07/16/2015 04:53 PM, Chris Angelico wrote:

On Fri, Jul 17, 2015 at 9:34 AM, Gary Roach  wrote:

On 07/15/2015 11:25 AM, Chris Angelico wrote:


You should then be able to create a regular user, and grant
appropriate permissions:

postgres=# create user archives password
'traded-links-linguistics-informal';
CREATE ROLE
postgres=# grant all on database archivedb to archives;
GRANT

I really appreciate the help Chris. I created a user archive with password
'xx' and changed the settings.py file accordingly. When I tried  python
manage.py migrate I got the following error with it's traceback:

(archivedb)root@supercrunch:~/archivedb# python manage.py migrate
[chomp]
django.db.utils.ProgrammingError: permission denied for relation
django_migrations

This suggests that your new user doesn't have permissions set yet. Did
you do the grant command as listed above? If so, you may have to also
do this:

$ sudo sudo -u postgres psql archivedb
postgres=# grant all on all tables in schema X to archives;

I did the above.

Replace X with the name of the database schema you use - possibly
"public" or some other user name. You can list multiple schema names,
separated by commas, if you need to.

To list all schemas in the database:

select distinct table_schema from information_schema.tables;
I did all of the above. Since I only plan on one datebase - excluding 
the system db's - I'm dumping everything into the public schema.

Hope that helps!

ChrisA

I'm still getting the same migration error.

At this point, I'm confused about a few things. Does the postgresql 
server and my archivedb reside globally or are they inside my archivedb 
virtual environment. I think globally.


To get pgAdmin3 to work, I  have to have it set so that it logs in as 
gary ( no choice with this) and set group to root. Then in application > 
advanced options set run as different user to root. This assumes that 
you are using a KDE4 desktop and have these option by right clicking the 
icons.


pgAdmin3 data:
Server Group > Server(1) > archivedb
|_ Host name - 
127.0.0.1

|_ username - archive
|_ connected - no
Archivedb requires a password to go deeper and takes the xx password 
that is in the django settings.py file. This opens up access to 
archivedb and lists archivedb > Schema(1) > public > tables(10). At this 
point I found that all  of the sequences and all of the tables are owned 
by root. This is probably the root (no pun intended) cause. Now what do 
I do about it. I'm not sure how this came about so don't know how to fix it.


In the OS I have a postgres user in the passwd file and in the group 
file have the following:

gary:x:1000:root,backuppc,sudo,postgres,users
root:x:0:backuppc,gary,staff,postgres,users
postgres:x:117:root,gary

Normally, I don't have to worry too much about security because my two 
user network resides behind a verizon router firewall. I don't have much 
in the way of sensitive data either. This project may be different. So 
maybe I need to tighten things up a bit.


Thanks for your help

Gary R



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


Re: Integers with leading zeroes

2015-07-23 Thread Michael Torrie
On 07/22/2015 07:51 AM, Grant Edwards wrote:
> On 2015-07-22, Ben Finney  wrote:
>> Laura Creighton  writes:
>>
>>> The biggest use I have for decimal numbers that begin with 0 is in
>>> credit card numbers, account numbers and the like where the first
>>> check you do is 'does this thing have the correct number of digits'.
>>
>> The following are examples of types from the real world that people
>> think of, and casually discuss, as “numbers”.
>>
>> * Postal code
>> * Credit card number
>> * Telephone number
>> * Car registration plate number
>> * Personal Identification Number (PIN)
> 
> Those are all strings.  Not numbers.

That depends.  A credit card number is indeed a number, and there are
mathematical formulas for determining if a particular number is a valid
(as in well-formed) credit card number, and possibly to identify what
kind of card it is.

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


Re: OT Re: Math-embarrassment results in CS [was: Should non-security 2.7 bugs be fixed?]

2015-07-23 Thread Marko Rauhamaa
Steven D'Aprano :

> I think that we can equally choose the natural numbers to be
> axiomatic, or sets to be axiomatic and derive natural numbers from
> them. Neither is more correct than the other.

Mathematicians quit trying to define what natural numbers mean and just
chose a standard enumerable sequence as *the* set of natural numbers.
That's analogous to physicists defining the meter as a particular rod in
a vault in Paris. So not even the length of the rod but the rod itself.

To modern mathematicians, the concept "three" simply means the fourth
element in the standard enumeration. When mathematicians need to use
natural numbers to count, they have to escape to predicate logic. For
example, to express that a natural number n has precisely two divisors,
you have to say,

   ∃x∈N ∃y∈N ¬x=y ∧ x|n ∧ y|n

(which avoids counting) or:

   ∃B∈P({x∈N : x|n}×2)
 (∀x∈{x∈N : x|n} ∃y∈2 ((x,y)∈B ∧ ∀z∈2 (x,z)∈B→y=z) ∧
  ∀x∈2 ∃y∈{x∈N : x|n} ((y,x)∈B ∧ ∀z∈{x∈N : x|n} (z,x)∈B→y=z))

This latter clumsy expression captures the notion of counting. However,
in programming terms, you could say counting is not first-class in
mathematics. Counting is done as a "macro" if you will.

If the logicians had managed to define natural numbers the way they
wanted, counting would be first class and simple:

   {x∈N : x|n}∈2


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


Re: OT Re: Math-embarrassment results in CS [was: Should non-security 2.7 bugs be fixed?]

2015-07-23 Thread Rustom Mody
On Thursday, July 23, 2015 at 12:28:19 PM UTC+5:30, Gregory Ewing wrote:
> Rustom Mody wrote:
> > Ive known good ones) most practicing-mathematicians proceed on the 
> > assumption 
> > that they *discover* math and not that they *invent* it.
> 
> For something purely abstract like mathematics, I don't
> see how there's any distinction between "discovering" and
> "inventing". They're two words for the same thing.
> 
> I don't know what kind of -ist that makes me...

Ummm... Clever!
You give few clues... except for 'purely abstract'.
Does that mean entirely in your consciousness?
Or does it mean completely independent of the (physical) world and even time.
Latter is more or less definition of platonist
Former is some kind of combo of intuitionist and formalist (I guess!).

JFTR: I believe that post-Cantor 'platonism' is an abuse of Plato's original
https://en.wikipedia.org/wiki/Allegory_of_the_Cave
-- 
https://mail.python.org/mailman/listinfo/python-list


on keeping things civil (was: Encoding of Python 2 string literals)

2015-07-23 Thread Cameron Simpson

On 22Jul2015 22:26, Mark Lawrence  wrote:

He refuses point blank to contribute to core python because he will not sign 
the CLA.


So? That's his prerogative. There's plenty of work I won't undertake because of 
the conditions attached. Defense/military comes to mind as an example.



Oh, and please do not tell me to back off.  It has been show in recent
days that despite my problems I have contributed to core Python.
Anatoly will contribute to any project, but on his terms, and his
terms only.


Shrug. I'm the same, and I suspect in real terms so are you. It is just where 
the boundaries lie that differ.


He asked a simple, direct, on topic, relevant, clear question, with a clear use 
case. As far as I'm concerned he's entirely welcome, and I'm glad he's received 
what look like informative and somewhat helpful responses. (With the notable 
exception of your response and now, regrettably, mine.)


If you don't want to deal with him, then don't deal with him. That means 
shutting up, not mouthing off.


On a personal basis, I have found the best way to keep discussions civil and on 
point is to simply ignore posts and posters which incite anger in me. I urge 
you to consider this approach.


Venting, I remain,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Optimizing if statement check over a numpy value

2015-07-23 Thread Heli Nix
Dear all, 

I have the following piece of code. I am reading a numpy dataset from an hdf5 
file and I am changing values to a new value if they equal 1. 

 There is 90 percent chance that (if id not in myList:) is true and in 10 
percent of time is false. 

with h5py.File(inputFile, 'r') as f1:
with h5py.File(inputFile2, 'w') as f2:
ds=f1["MyDataset"].value
myList=[list of Indices that must not be given the new_value]

new_value=1e-20
for index,val in np.ndenumerate(ds):
if val==1.0 :
id=index[0]+1
if id not in myList:
ds[index]=new_value
   
dset1 = f2.create_dataset("Cell Ids", data=cellID_ds)  
dset2 = f2.create_dataset("Porosity", data=poros_ds) 

My numpy array has 16M data and it takes 9 hrs to run. If I comment my if 
statement (if id not in myList:) it only takes 5 minutes to run. 

Is there any way that I can optimize this if statement. 

Thank you very much in Advance for your help. 

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


Re: Optimizing if statement check over a numpy value

2015-07-23 Thread MRAB

On 2015-07-23 10:21, Heli Nix wrote:

Dear all,

I have the following piece of code. I am reading a numpy dataset from an hdf5 
file and I am changing values to a new value if they equal 1.

  There is 90 percent chance that (if id not in myList:) is true and in 10 
percent of time is false.

with h5py.File(inputFile, 'r') as f1:
 with h5py.File(inputFile2, 'w') as f2:
 ds=f1["MyDataset"].value
 myList=[list of Indices that must not be given the new_value]

 new_value=1e-20
 for index,val in np.ndenumerate(ds):
 if val==1.0 :
 id=index[0]+1
 if id not in myList:
 ds[index]=new_value

 dset1 = f2.create_dataset("Cell Ids", data=cellID_ds)
 dset2 = f2.create_dataset("Porosity", data=poros_ds)

My numpy array has 16M data and it takes 9 hrs to run. If I comment my if 
statement (if id not in myList:) it only takes 5 minutes to run.

Is there any way that I can optimize this if statement.

Thank you very much in Advance for your help.

Best Regards,


When checking for presence in a list, it has to check every entry. The
time taken is proportional to the length of the list.

The time taken to check for presence in a set, however, is a constant.

Replace the list myList with a set.

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


Re: convert output to list(and nested dictionary)

2015-07-23 Thread Peter Otten
max scalf wrote:

> Hi Peter,
> 
> Could you please explain what i am doing wrong?  I did inspected the
> "get_all_security_groups()" object using dir and i do need the get_data
> function for this to work...as i have to parse the output...just getting
> the rule and grants does not work...as it comes with extra verbiage that i
> do NOT need in my dictionary...see below...
> 
 for sg in sgs:
> for rule in sg.rules:
> print sg, sg.id, rule, rule.grants
> 
> 
> SecurityGroup:wordpress-app-SG sg-99c4befc IPPermissions:-1(None-None)
> [sg-e632d982-995635159130]
...

It's not "extra verbiage", you print the whole sg object, and the author of 
the SecurityGroup class has chosen one way to convert SecurityGroup 
instances into strings, the one that he deems most useful, probably for 
debugging purposes.

But you are only interested in some attributes of the sg object. Instead of

print sg

you should only print

print sg.foo, sg.bar

foo and bar are fictitious attribute names, but you can find candiates for 
these attributes with

print dir(sg)

which will print the actual names.

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


Re: Optimizing if statement check over a numpy value

2015-07-23 Thread Laura Creighton
Take a look at the sorted collection recipe:
http://code.activestate.com/recipes/577197-sortedcollection/

You want myList to be a sorted List.  You want lookups to be fast.

See if that improves things enough for you.  It may be possible to
have better speedups if instead of myList you write myTree and store
the values in a tree, depending on what the values of id are --  it
could be completely useless for you, as well.

Laura


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


global and loop control variable

2015-07-23 Thread candide
About global declarations, Python Language Ref (PLR) explains:

[https://docs.python.org/3.4/reference/simple_stmts.html#the-global-statement]
~
Names listed in a global statement must not be used
in the same code block textually preceding that global statement.
~



What I understand is that the following code is incorrect:

# ---
def f():
x=42
global x

f()
print(x)
# ---

And indeed, executing this piece of code "raises" a warning :

~
test.py:3: SyntaxWarning: name 'x' is assigned to before global declaration
  global x
42
~

Now, global declaration has another restriction, as PLR explains:

[https://docs.python.org/3.4/reference/simple_stmts.html#the-global-statement]
~
Names listed in a global statement must not be defined as formal parameters
or in a for loop control target, 
~

What I understand is that the following is a must-not-code:

# ---
def f():
global i
for i in range(1,3):
print(10*i)

f()
print(i)
# ---

But, the later code executes silently without any warning:

~
10
20
2
~

So my question is: what is the restriction about global as loop control 
variable the docs is referring to?
-- 
https://mail.python.org/mailman/listinfo/python-list


ImportError: No module named site

2015-07-23 Thread [email protected]

hi:
I'm Needing to get python 2.7.10 to cross compile correctly for an ARM 
embedded device. When I execute python using shell, it comes out this 
error:ImportError: No module named site.I have setted environment 
varible:PYTHONHOME and PYTHONPATH. Is there some good idea to sovle this 
issue?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: global and loop control variable

2015-07-23 Thread Lorenzo Sutton



On 23/07/2015 12:24, candide wrote:
[...]



Now, global declaration has another restriction, as PLR explains:

[https://docs.python.org/3.4/reference/simple_stmts.html#the-global-statement]
~
Names listed in a global statement must not be defined as formal parameters
or in a for loop control target,
~

What I understand is that the following is a must-not-code:

# ---
def f():
 global i
 for i in range(1,3):
 print(10*i)

f()
print(i)
# ---

But, the later code executes silently without any warning:

~
10
20
2
~

So my question is: what is the restriction about global as loop control 
variable the docs is referring to?



I think for situations like this one?

# ---
def f():
global temperature
for temperature in range(1,3):
print "In f temperature is:", temperature

temperature = 500
print "temperature is now", temperature
f()
print"temperature is now:", temperature
# temperature is now "broken"
if temperature <= 100:
print "Launching rocket"
else:
# this never happens
print "temperature too high! Aborting launch."
 # ---
--
https://mail.python.org/mailman/listinfo/python-list


Re: problem with selecting remote procedure calls

2015-07-23 Thread Tim Golden
On 23/07/2015 04:10, eric johansson wrote:
> https://docs.google.com/drawings/d/1M-TzfRaSaAhFXQk1OmcmHNOaW31_7W_7q0bf8CAJqSw/edit?usp=sharing
>
>  while this is related to my speech recognition through the next
> project, is actually a good question for RPCs in general.
> Specifically, are there any good-RPCs out there that are fast,
> supported, and easy to use?

It looks like a decent fit for Pyro:

  https://github.com/irmen/Pyro4

  http://pythonhosted.org/Pyro4/

  https://pypi.python.org/pypi/Pyro4

Pyro's certainly actively maintained and I've seen its developer, Irmen
de Jong, pop up on this list fairly recently.

Exactly how good a fit it is would depend on your precise setup. But I
think it's worth exploring. I can't speak as to its speed -- I've only
used it where speed wasn't really an issue.

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


Re: Optimizing if statement check over a numpy value

2015-07-23 Thread Jeremy Sanders
Heli Nix wrote:

> Is there any way that I can optimize this if statement.

Array processing is much faster in numpy. Maybe this is close to what you 
want

import numpy as N
# input data
vals = N.array([42, 1, 5, 3.14, 53, 1, 12, 11, 1])
# list of items to exclude
exclude = [1]
# convert to a boolean array
exclbool = N.zeros(vals.shape, dtype=bool)
exclbool[exclude] = True
# do replacement
ones = vals==1.0
# Note: ~ is numpy.logical_not
vals[ones & (~exclbool)] = 1e-20

I think you'll have to convert your HDF array into a numpy array first, 
using numpy.array().

Jeremy


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


Re: Find Minimum for element in multiple dimensional array

2015-07-23 Thread Robert Davis
On Wednesday, July 22, 2015 at 5:54:30 PM UTC-5, Robert Davis wrote:
> Given a set of arrays within an array how do I find the arrays with the 
> minimum values based on two elements/columns in the array? Those two 
> elements/columns are the destination zip code and distance.
> 
> I have an array of arrays that have a origin zip code, origin latitude, 
> origin longitude, destination zip code, destination latitude, destination 
> longitude, and miles between the two points.
> 
> I need to keep only those combinations that represent the minimum mileage 
> between to the destination zip code. For example a point in New Jersey may 
> have a distance from the Philadelphia Office that is 45 miles, from the 
> Newark Office that is 78 miles and one from the Delaware Office that is 58 
> miles.
> 
> I need to keep the mileage from the Philadelphia Office that is 45 miles and 
> produce a .csv file that has origin zip code, origin latitude, origin 
> longitude, destination zip code, destination latitude, destination longitude, 
> and miles between the two points.
> 
> The array looks like this:
> 
> [['37015', 'TN31', 36.2777, -87.0046, 'NY', 'White Plains', '10629', 
> 41.119008, -73.732996, 77.338920003], 
> ['72202', 'ARB1', 34.739224, -92.27765, 'NY', 'White Plains', '10629', 
> 41.119008, -73.732996, 1099.7837975322097]]
> 
> My code looks like this :
> 
> import csv
> import math
> 
> 
> def calculate_distance(lat1, lon1, lat2, lon2):
> 
> if (not lat1) or (not lon1) or (not lat2) or (not lon2):
> return -1
> 
> lat1 = float(lat1) * math.pi/180
> lon1 = float(lon1) * math.pi/180
> lat2 = float(lat2) * math.pi/180
> lon2 = float(lon2) * math.pi/180
> 
> return 3959.0 * math.acos(math.sin(lat1) * math.sin(lat2) +   
> math.cos(lat1) * math.cos(lat2) * math.cos(lon2-lon1))
> 
> #Above function changed from the following URL: http://iamtgc.com/geocoding- 
> with-python/
> 
> 
> InputPath = "C:\\Users\\jacobs\\Downloads\\ZipCodes\\"
> 
> ZipCodes = "zipcode.csv"
> RptgOfficeFile = "Reporting_Office_2015072001.csv"
> InputFile = InputPath+RptgOfficeFile
> zInputFile = InputPath+ZipCodes
> zOutputFile = InputPath+'Zip_Code_Distance.csv'
> z1OutputFile = InputPath+'Minimum_Distance_Zip_Code_File.csv'
> 
> 
> f = open(InputFile, 'r')
> 
> zO = open(zOutputFile,'w')
> z1 = open(z1OutputFile,'w')
> 
> lines = [ ]
> OfficeZipcodes = []
> ZipRptOffice = {}
> OLatitude = [ ]
> OLongitude = [ ]
> OLocationCode = []
> dzip = []
> dLatitude = []
> dLongitude = []
> dCity = []
> dState = []
> Combined =[]
> Answers = []
> 
> for line in f:
>   l = [i.strip() for i in line.split(',')]
>   OfficeZipcodes.append(l[4])
>   ZipRptOffice[l[4]]= l[3]
>   OLatitude.append(l[5])
>   OLongitude.append(l[6])
>   OLocationCode.append(l[3])
> 
> del OfficeZipcodes[0]
> del OLatitude[0] 
> del OLongitude[0]
> del OLocationCode[0]
> 
> 
> zf = csv.DictReader(open(zInputFile))
> #http://courses.cs.washington.edu/courses/cse140/13wi/csv-parsing.html
> 
> for row in zf:
> dzip.append(row["zip"])
> dLatitude.append(float(row["latitude"]))
> dLongitude.append(float(row["longitude"]))
> dCity.append(row["city"])
> dState.append(row["state"])
> 
> 
> for i in range(len(OfficeZipcodes)):
> for j in range(len(dzip)):
> Distance = calculate_distance(OLatitude[i], 
> OLongitude[i],dLatitude[j],dLongitude[j])
> Combined.append([OfficeZipcodes[i], 
> OLocationCode[i],float(OLatitude[i]),float(OLongitude[i]),dState[j],dCity[j],dzip[j],
>  dLatitude[j],dLongitude[j],Distance])
> for i in range(len(Combined)):
>   
> zO.write(str(Combined[i][0])+","+str(Combined[i][1])+","+str(Combined[i][2])+","+
>  str(Combined[i][3])+","+str(Combined[i][4])+","+ str(Combined[i][5])+","+ 
> str(Combined[i][6])+","+str(Combined[i][7])+","+ 
> str(Combined[i][8])+","+str(Combined[i][9])+"\n")
> 
> zO.close()
> f.close()
> 
> I am using Python 2.7 on a Windows 7 machine.
> 
> Please help me get my head around how to accomplish this task.
> 
> Thank you very much.
> 
> Robert Davis

Emile,

Thank you I will give it a try and see if I can get it to work. 

I really do appreciate your effort.

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


Re: global and loop control variable

2015-07-23 Thread Steven D'Aprano
On Thu, 23 Jul 2015 09:20 pm, Lorenzo Sutton wrote:

> On 23/07/2015 12:24, candide wrote:
>> Now, global declaration has another restriction, as PLR explains:
>>
[https://docs.python.org/3.4/reference/simple_stmts.html#the-global-statement]
>> ~
>> Names listed in a global statement must not be defined as formal
>> parameters or in a for loop control target,
>> ~
>>
>> What I understand is that the following is a must-not-code:
>>
>> def f():
>>  global i
>>  for i in range(1,3):
>>  print(10*i)
[...]
>> So my question is: what is the restriction about global as loop control
>> variable the docs is referring to?

You are correct. The above example is exactly the restriction mentions. The
very next paragraph in the docs says:

"CPython implementation detail: The current implementation does not enforce
the two restrictions, but programs should not abuse this freedom, as future
implementations may enforce them or silently change the meaning of the
program."

In other words, the behaviour of global loop variables is not guaranteed,
and you should not use it even if the compiler/interpreter fails to raise a
syntax error.


> I think for situations like this one?
> 
> def f():
>  global temperature
>  for temperature in range(1,3):
>  print "In f temperature is:", temperature


There's no meaningful difference between the example Candide gave (for i in
range) and the example you give (for temperature in range). They both use a
global for the loop variable. Only the names differ.


-- 
Steven

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


Re: OT Re: Math-embarrassment results in CS [was: Should non-security 2.7 bugs be fixed?]

2015-07-23 Thread Rustom Mody
On Thursday, July 23, 2015 at 12:28:19 PM UTC+5:30, Gregory Ewing wrote:
> Rustom Mody wrote:
> > Ive known good ones) most practicing-mathematicians proceed on the 
> > assumption 
> > that they *discover* math and not that they *invent* it.
> 
> For something purely abstract like mathematics, I don't
> see how there's any distinction between "discovering" and
> "inventing". They're two words for the same thing.
> 
> I don't know what kind of -ist that makes me...

By some strange coincidence, a colleague just sent me this article on the 
mathematician John Horton Conway:
http://www.theguardian.com/science/2015/jul/23/john-horton-conway-the-most-charismatic-mathematician-in-the-world

In which is this paragraph:
--
"Conway is the rare sort of mathematician whose ability to connect his pet
mathematical interests makes one wonder if he isn't, at some level, shaping 
mathematical reality and not just exploring it," James Propp, a professor of 
mathematics at the University of Massachusetts Lowell, once told me. "The 
example of this that I know best is a connection he discovered between sphere 
packing and games. These were two separate areas of study that Conway had 
arrived at by two different paths. So there's no reason for them to be linked. 
But somehow, through the force of his personality, and the intensity of his 
passion, he bent the mathematical universe to his will."
--
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: global and loop control variable

2015-07-23 Thread Lorenzo Sutton



On 23/07/2015 14:31, Steven D'Aprano wrote:

On Thu, 23 Jul 2015 09:20 pm, Lorenzo Sutton wrote:


On 23/07/2015 12:24, candide wrote:

Now, global declaration has another restriction, as PLR explains:


[https://docs.python.org/3.4/reference/simple_stmts.html#the-global-statement]

~
Names listed in a global statement must not be defined as formal
parameters or in a for loop control target,
~

What I understand is that the following is a must-not-code:

def f():
  global i
  for i in range(1,3):
  print(10*i)

[...]

So my question is: what is the restriction about global as loop control
variable the docs is referring to?


You are correct. The above example is exactly the restriction mentions. The
very next paragraph in the docs says:

"CPython implementation detail: The current implementation does not enforce
the two restrictions, but programs should not abuse this freedom, as future
implementations may enforce them or silently change the meaning of the
program."

In other words, the behaviour of global loop variables is not guaranteed,
and you should not use it even if the compiler/interpreter fails to raise a
syntax error.



I think for situations like this one?

def f():
  global temperature
  for temperature in range(1,3):
  print "In f temperature is:", temperature



There's no meaningful difference between the example Candide gave (for i in
range) and the example you give (for temperature in range). They both use a
global for the loop variable. Only the names differ.


Of course... it was just to highlight that it could be potentially, 
especially if your programme is going to launch a rocket - eventually 
(see my entire code example) :-)


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


Re: unexpected output while using list(and nested dictionary)

2015-07-23 Thread max scalf
I am sorry for doing what i did (asking question in Stackoverflow and
pasting the link here).  I will keep this in mind for the future.  I am
very much new to this list, so was not sure.

Do you guys have any suggestion as to what to use if the code is lone, as
the formatting gets lost in an email...

On Thu, Jul 23, 2015 at 12:36 AM, Steven D'Aprano <
[email protected]> wrote:

> On Thursday 23 July 2015 08:09, max scalf wrote:
>
> > Hello List,
> >
> > I have posted a question on stack overflow for better readability ... but
> > is intended for python list Please see question below...
>
> If it's intended for here, please ask it here.
>
> Consider that there may be people here who are willing and able to answer
> your question, but either don't have an account on Stackoverflow, have
> access to SO blocked, or simply don't like the culture and ethos of SO and
> won't use it.
>
>
> --
> Steve
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Search in Flask Restful

2015-07-23 Thread subhabrata . banerji
Dear Group,

I am trying to build one REST framework using Restful Flask. 
To put or get I am trying to use the requests module, as 
given in the following lines.

>>> var2=requests.put('http://127.0.0.1:5000/todos/todo1', data={'task': 'It is 
>>> my challenge'})
>>> var3=requests.get('http://127.0.0.1:5000/todos/todo1')

Now I like to search plain as well as Boolean over this Rest.

If I could understand the problem fine, the exercises are given 
in the following URL.

http://flask-restless.readthedocs.org/en/latest/searchformat.html#examples

But I am looking for examples with requests. I searched for help with requests 
in http://docs.python-requests.org/en/latest/, it did not help much.

If anyone of the esteemed members may kindly suggest.

I am using Python2.7+ on Windows 7. Apology for any indentation error. 


Regards,
Subhabrata Banerjee
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: unexpected output while using list(and nested dictionary)

2015-07-23 Thread Steven D'Aprano
On Fri, 24 Jul 2015 12:04 am, max scalf wrote:

> I am sorry for doing what i did (asking question in Stackoverflow and
> pasting the link here).  I will keep this in mind for the future.  I am
> very much new to this list, so was not sure.
> 
> Do you guys have any suggestion as to what to use if the code is lone, as
> the formatting gets lost in an email...

Use a tool that doesn't break your emails.

If you turn "Rich Text" or "Formatted Text" on, your mail will be sent as
HTML code. That is a poor choice for formatting text, but it's a standard
now, no matter the disadvantages (and there are many). HTML will wreck your
formatting.

If you turn "Rich Text" or "Formatting" off, and send as regular plain text
with no bold, italics, inline pictures, dancing paperclips, embedded music
or whatever other nonsense people like to stick in their emails these days,
then any decent mail client will send *exactly what you type* with no
frills or mangling. So if you type:


def function(a, b):
return a + 2*b  # that's four spaces at the start of the line


then that's exactly what will be sent, including the four spaces. If your
mail program doesn't do that, then it is broken, like a car that can only
turn left or a toaster that sets fire to the bread. Use a better email
program.

Another alternative is to save your code in a .py file, then attach it to
the email as an attachment. Even the most obnoxious email program doesn't
mangle attachments, at least not deliberately. But that can be
inconvenient.

Worst case, you can post your code in a pastebin, or some other website. But
by doing so, understand that (1) you are limiting the usefulness of your
question to others, who might learn from it in the future, and (2) limiting
the number of people who are willing and able to answer.




-- 
Steven

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


Re: unexpected output while using list(and nested dictionary)

2015-07-23 Thread Ben Finney
max scalf  writes:

> I am sorry for doing what i did (asking question in Stackoverflow and
> pasting the link here).

No harm done. The rule isn't special to this forum; it's best to
minimise the fragility of your message by not relying on many sites all
staying the same over a long time.

> Do you guys have any suggestion as to what to use if the code is lone,
> as the formatting gets lost in an email...

First, always post in “plain text”; don't present program code in a
“rich text” or “HTML mail” or any other magical formatting tool.

Second, don't post long code examples. Work up a small, self-contained,
complete compilable example http://sscce.org/> so that there isn't
any extraneous material, only the code that demonstrates the behaviour
that confuses you.

The reason to do that for presentation here is that you want the code to
be short enough that people will find it worth their time to volunteer
to help you.

But an important side benefit is: in stripping the example down so that
it doesn't contain anything not needed to demonstrate the behaviour, you
may end up understanding it well enough to solve the problem yourself —
which is a valuable skill and very much worth your while :-)

-- 
 \   “If you always want the latest and greatest, then you have to |
  `\  buy a new iPod at least once a year.” —Steve Jobs, MSNBC |
_o__) interview 2006-05-25 |
Ben Finney

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


Re: unexpected output while using list(and nested dictionary)

2015-07-23 Thread Laura Creighton
In a message of Thu, 23 Jul 2015 09:04:38 -0500, max scalf writes:
>I am sorry for doing what i did (asking question in Stackoverflow and
>pasting the link here).  I will keep this in mind for the future.  I am
>very much new to this list, so was not sure.
>
>Do you guys have any suggestion as to what to use if the code is lone, as
>the formatting gets lost in an email...

You need to set up your mailer to send "plain text mail".

Since you are using a gmail account, I assume you are using gmail.
Googling for 'gmail plain text email' gives lots of hits -- apparantly
Google has changed how composing email works at least once, and I
cannot tell which of these hits is for current gmail and not
gmail-of-5-years-ago

If you aren't using gmail, you need to google for whatever mailer you are
using and "plain text email".

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


Re: unexpected output while using list(and nested dictionary)

2015-07-23 Thread Laura Creighton
In a message of Fri, 24 Jul 2015 00:57:42 +1000, "Steven D'Aprano" writes:
>On Fri, 24 Jul 2015 12:04 am, max scalf wrote:
>Another alternative is to save your code in a .py file, then attach it to
>the email as an attachment. Even the most obnoxious email program doesn't
>mangle attachments, at least not deliberately. But that can be
>inconvenient.

python.org scrubs all attatchments on some lists.  I am not sure if this
is one of them -- convincing his email client to send plain text
emails is the correct thing to do here.

Laura

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


Re: unexpected output while using list(and nested dictionary)

2015-07-23 Thread Rustom Mody
On Thursday, July 23, 2015 at 9:25:46 PM UTC+5:30, Laura Creighton wrote:
> In a message of Thu, 23 Jul 2015 09:04:38 -0500, max scalf writes:
> >I am sorry for doing what i did (asking question in Stackoverflow and
> >pasting the link here).  I will keep this in mind for the future.  I am
> >very much new to this list, so was not sure.
> >
> >Do you guys have any suggestion as to what to use if the code is lone, as
> >the formatting gets lost in an email...
> 
> You need to set up your mailer to send "plain text mail".
> 
> Since you are using a gmail account, I assume you are using gmail.
> Googling for 'gmail plain text email' gives lots of hits -- apparantly
> Google has changed how composing email works at least once, and I
> cannot tell which of these hits is for current gmail and not
> gmail-of-5-years-ago

gmail → Compose → Tiny downward triangle in right bottom of compose window
→ Select plain text
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How we can send mail with attachment in Python?

2015-07-23 Thread Robert Davis
On Monday, July 20, 2015 at 12:01:49 AM UTC-5, Chris Angelico wrote:
> On Mon, Jul 20, 2015 at 2:54 PM, Kevin Peterson  wrote:
> > How we can send mail with attachment in Python? Is it any prerequisite for 
> > it?
> 
> You could use your favourite search engine to look this up. Or you
> could poke around with the Python standard library and see if anything
> looks promising:
> 
> https://docs.python.org/3/library/
> 
> Hint: There is something there.
> 
> ChrisA

Take a look at an article written by Ashish Jain at the following link:

http://ashishpython.blogspot.com/2014/06/send-email-with-outlook-in-python.html

I use something very similar to automate sending of monthly reports.

HTH

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


Re: unexpected output while using list(and nested dictionary)

2015-07-23 Thread Grant Edwards
On 2015-07-23, Steven D'Aprano  wrote:
> On Fri, 24 Jul 2015 12:04 am, max scalf wrote:

[...]

>> Do you guys have any suggestion as to what to use if the code is
>> lone, as the formatting gets lost in an email...
>
> Use a tool that doesn't break your emails.
>
> If you turn "Rich Text" or "Formatted Text" on, your mail will be
> sent as HTML code. That is a poor choice for formatting text, but
> it's a standard now, no matter the disadvantages (and there are
> many). HTML will wreck your formatting.

In theory, code inside a  tag should be more-or-less OK
(most of the time), but people sending HTML e-mail never seem to know
how to do that.  [Or probably their e-mail client is too broken to
even allow such a thing.]

> If you turn "Rich Text" or "Formatting" off, and send as regular
> plain text with no bold, italics, inline pictures, dancing
> paperclips, embedded music or whatever other nonsense people like to
> stick in their emails these days, then any decent mail client will
> send *exactly what you type* with no frills or mangling. So if you
> type:
>
> def function(a, b):
> return a + 2*b  # that's four spaces at the start of the line
>
> then that's exactly what will be sent, including the four spaces.

That's definitely, by far, the very best option.

> If your mail program doesn't do that, then it is broken, like a car
> that can only turn left or a toaster that sets fire to the bread. Use
> a better email program.

I recomment mutt if you really want to stick with getting everything
e-mailed to you (which I personally don't like).  Better yet (IMO)
point slrn or your favorite NNTP client at comp.lang.python on your
friendly local Usenet server or at gmane's nntp server at
nntp://news.gmane.org/gmane.comp.python.general.

> Another alternative is to save your code in a .py file, then attach
> it to the email as an attachment. Even the most obnoxious email
> program doesn't mangle attachments, at least not deliberately. But
> that can be inconvenient.

A lot of people are not going to open attachments sent by some random
stranger.  Some people might (even though they probably should not),
but it could be the person who knows the answer to your problem won't
bother -- either because of the effor or risk involved.  Especially on
Windows, opening e-mail attachments seems to be a rather dangerous
thing to do.

Do attachments sent to the mailing list make it realiably through
gateways to places like comp.lang.python or into gmane's "view" of the
mailing list?

-- 
Grant Edwards   grant.b.edwardsYow! Let me do my TRIBUTE
  at   to FISHNET STOCKINGS ...
  gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Stripping sRGB profile from PNGs in python

2015-07-23 Thread Ryan Holmes
We're getting this error when trying to load some of out projects images:
   
libpng warning: iCCP: known incorrect sRGB profile

The source files that we have some with incorrect sRGB profiles. We don't have 
control over the source files, but what we normally do is take them and scale 
them down for our own project. To fix this issue, we can use this shell 
one-liner:

find . -type f -name "*.png" -exec convert {} {} \;

Which basically converts the ONGs into themselves, but it strips the profile 
(or maybe overwrites with a correct profile).

We would like to incorporate this functionality into our python script which 
scales the source images, but we haven' found a way to do this. Any thoughts?


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


Re: Stripping sRGB profile from PNGs in python

2015-07-23 Thread Emile van Sebille

On 7/23/2015 10:31 AM, Ryan Holmes wrote:

We're getting this error when trying to load some of out projects images:

 libpng warning: iCCP: known incorrect sRGB profile

The source files that we have some with incorrect sRGB profiles. We don't have 
control over the source files, but what we normally do is take them and scale 
them down for our own project. To fix this issue, we can use this shell 
one-liner:

 find . -type f -name "*.png" -exec convert {} {} \;

Which basically converts the ONGs into themselves, but it strips the profile 
(or maybe overwrites with a correct profile).

We would like to incorporate this functionality into our python script which 
scales the source images, but we haven' found a way to do this. Any thoughts?



Use the appropriate shell out command for your python version.  There've 
been too many over the years -- on the system I'm at today running 
Python 2.5 I'm using the commands module.


For example:

commands.getoutput('for ii in /proc/[0-9]*/environ; do echo $ii; strings 
$ii ; done').split()


Emile



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


Re: unexpected output while using list(and nested dictionary)

2015-07-23 Thread Mark Lawrence

On 23/07/2015 18:08, Grant Edwards wrote:

I recomment mutt if you really want to stick with getting everything
e-mailed to you (which I personally don't like).  Better yet (IMO)
point slrn or your favorite NNTP client at comp.lang.python on your
friendly local Usenet server or at gmane's nntp server at
nntp://news.gmane.org/gmane.comp.python.general.


For those who aren't aware and as a reminder for those who are, there 
are 387 Python related lists at 
http://news.gmane.org/index.php?prefix=gmane.comp.python.


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: Stripping sRGB profile from PNGs in python

2015-07-23 Thread Laura Creighton
To scale images, you should get Pillow, which can construct new images
based on old ones for arbitrary size. see:
http://pillow.readthedocs.org/en/latest/reference/Image.html

Pillow is a fork of PIL.  PIL isn't being maintained, Pillow is.

Note that reading this is a good idea:
http://united-coders.com/christian-harms/image-resizing-tips-every-coder-should-know/

It even has some code that you can probably use, though I haven't tested it.
It just, ah, looks right. :)

Laura

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


Re: problem with selecting remote procedure calls

2015-07-23 Thread Irmen de Jong
On 23-7-2015 13:39, Tim Golden wrote:
> On 23/07/2015 04:10, eric johansson wrote:
>> https://docs.google.com/drawings/d/1M-TzfRaSaAhFXQk1OmcmHNOaW31_7W_7q0bf8CAJqSw/edit?usp=sharing
>>
>>  while this is related to my speech recognition through the next
>> project, is actually a good question for RPCs in general.
>> Specifically, are there any good-RPCs out there that are fast,
>> supported, and easy to use?
> 
> It looks like a decent fit for Pyro:
> 
>   https://github.com/irmen/Pyro4
>   http://pythonhosted.org/Pyro4/
>   https://pypi.python.org/pypi/Pyro4
> 
> Pyro's certainly actively maintained and I've seen its developer, Irmen
> de Jong, pop up on this list fairly recently.

Hi!


> Exactly how good a fit it is would depend on your precise setup. But I
> think it's worth exploring. I can't speak as to its speed -- I've only
> used it where speed wasn't really an issue.

Performance depends on many factors. I used to have a table with numbers in the 
manual
but since replaced it by a more general indication;
http://pythonhosted.org/Pyro4/intro.html#performance

Eric, if you're concerned about performance, Pyro4 (the source distribution) 
comes with
several examples that do simple performance related tests. You could run these 
and see
what figures you get on your setup to see if it's anywhere acceptable, before 
even
building anything with Pyro yourself.

Interesting project btw.
Good luck!

Irmen



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


Re: OT Re: Math-embarrassment results in CS [was: Should non-security 2.7 bugs be fixed?]

2015-07-23 Thread Ian Kelly
On Jul 22, 2015 9:46 PM, "Steven D'Aprano" <
[email protected]> wrote:
>
> On Thursday 23 July 2015 04:09, Rustom Mody wrote:
>
> > tl;dr To me (as unprofessional a musician as mathematician) I find it
> > arbitrary that Newton *discovered* gravity whereas Beethoven *composed*
> > the 9th symphony.
>
> Newton didn't precisely *discover* gravity. I'm pretty sure that people
> before him didn't think that they were floating through the air
> weightless...
>
> *wink*
>
>
> Did gravity exist before Newton? Then he discovered it (in some sense).
>
> Did the 9th Symphony exist before Beethoven? No? Then he composed it.

Gravity existed before Newton, but the *theory* of gravity did not, so he
composed the theory?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: OT Re: Math-embarrassment results in CS [was: Should non-security 2.7 bugs be fixed?]

2015-07-23 Thread Marko Rauhamaa
Ian Kelly :

> Gravity existed before Newton, but the *theory* of gravity did not, so
> he composed the theory?

Ironically, gravity is maybe the least well understood phenomenon in
modern physics.


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


Re: OT Re: Math-embarrassment results in CS [was: Should non-security 2.7 bugs be fixed?]

2015-07-23 Thread Chris Angelico
On Fri, Jul 24, 2015 at 6:59 AM, Marko Rauhamaa  wrote:
> Ian Kelly :
>
>> Gravity existed before Newton, but the *theory* of gravity did not, so
>> he composed the theory?
>
> Ironically, gravity is maybe the least well understood phenomenon in
> modern physics.

Fortunately, we don't need to completely understand it. New Horizons
reached Pluto right on time after a decade of flight that involved
taking a left turn at Jupiter... we can predict exactly what angle to
fire the rockets at in order to get where we want to go, even without
knowing how that gravity yank works.

Practicality beats purity?

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


Re: OT Re: Math-embarrassment results in CS [was: Should non-security 2.7 bugs be fixed?]

2015-07-23 Thread Marko Rauhamaa
Chris Angelico :

> Fortunately, we don't need to completely understand it. New Horizons
> reached Pluto right on time after a decade of flight that involved
> taking a left turn at Jupiter... we can predict exactly what angle to
> fire the rockets at in order to get where we want to go, even without
> knowing how that gravity yank works.
>
> Practicality beats purity?

Engineer!

At the time I was in college I heard topology was very fashionable among
mathematicians. That was because it was one of the last remaining
research topics that didn't yet have an application.


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


Re: OT Re: Math-embarrassment results in CS [was: Should non-security 2.7 bugs be fixed?]

2015-07-23 Thread Mark Lawrence

On 23/07/2015 22:29, Marko Rauhamaa wrote:

Chris Angelico :


Fortunately, we don't need to completely understand it. New Horizons
reached Pluto right on time after a decade of flight that involved
taking a left turn at Jupiter... we can predict exactly what angle to
fire the rockets at in order to get where we want to go, even without
knowing how that gravity yank works.

Practicality beats purity?


Engineer!



Heard the one about the three engineers in the car that breaks down?

The chemical engineer suggests that they could have contaminated fuel. 
They should try and get a sample and get someone to take it to a lab for 
analysis.


The electrical engineer suggests that they check the battery and the 
leads for any problems.


The Microsoft engineer suggests that they close all the windows, get out 
of the car, get back in the car, open all the windows and see what happens.


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: OT Re: Math-embarrassment results in CS [was: Should non-security 2.7 bugs be fixed?]

2015-07-23 Thread Laura Creighton
In a message of Fri, 24 Jul 2015 00:29:28 +0300, Marko Rauhamaa writes:
>Chris Angelico :
>
>> Fortunately, we don't need to completely understand it. New Horizons
>> reached Pluto right on time after a decade of flight that involved
>> taking a left turn at Jupiter... we can predict exactly what angle to
>> fire the rockets at in order to get where we want to go, even without
>> knowing how that gravity yank works.
>>
>> Practicality beats purity?
>
>Engineer!
>
>At the time I was in college I heard topology was very fashionable among
>mathematicians. That was because it was one of the last remaining
>research topics that didn't yet have an application.
>
>
>Marko

I have a very good freind who is a knot-theorist.  (Chad Musick, who
may have proven something wonderful.) see: http://chadmusick.wikidot.com/knots
He says there are lots of applications for this in the field of circuit
board layouts.  And most mathematicians accept knot-theory as part of
topology.

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


Re: Find Minimum for element in multiple dimensional array

2015-07-23 Thread Robert Davis
On Wednesday, July 22, 2015 at 5:54:30 PM UTC-5, Robert Davis wrote:
> Given a set of arrays within an array how do I find the arrays with the 
> minimum values based on two elements/columns in the array? Those two 
> elements/columns are the destination zip code and distance.
> 
> I have an array of arrays that have a origin zip code, origin latitude, 
> origin longitude, destination zip code, destination latitude, destination 
> longitude, and miles between the two points.
> 
> I need to keep only those combinations that represent the minimum mileage 
> between to the destination zip code. For example a point in New Jersey may 
> have a distance from the Philadelphia Office that is 45 miles, from the 
> Newark Office that is 78 miles and one from the Delaware Office that is 58 
> miles.
> 
> I need to keep the mileage from the Philadelphia Office that is 45 miles and 
> produce a .csv file that has origin zip code, origin latitude, origin 
> longitude, destination zip code, destination latitude, destination longitude, 
> and miles between the two points.
> 
> The array looks like this:
> 
> [['37015', 'TN31', 36.2777, -87.0046, 'NY', 'White Plains', '10629', 
> 41.119008, -73.732996, 77.338920003], 
> ['72202', 'ARB1', 34.739224, -92.27765, 'NY', 'White Plains', '10629', 
> 41.119008, -73.732996, 1099.7837975322097]]
> 
> My code looks like this :
> 
> import csv
> import math
> 
> 
> def calculate_distance(lat1, lon1, lat2, lon2):
> 
> if (not lat1) or (not lon1) or (not lat2) or (not lon2):
> return -1
> 
> lat1 = float(lat1) * math.pi/180
> lon1 = float(lon1) * math.pi/180
> lat2 = float(lat2) * math.pi/180
> lon2 = float(lon2) * math.pi/180
> 
> return 3959.0 * math.acos(math.sin(lat1) * math.sin(lat2) +   
> math.cos(lat1) * math.cos(lat2) * math.cos(lon2-lon1))
> 
> #Above function changed from the following URL: http://iamtgc.com/geocoding- 
> with-python/
> 
> 
> InputPath = "C:\\Users\\jacobs\\Downloads\\ZipCodes\\"
> 
> ZipCodes = "zipcode.csv"
> RptgOfficeFile = "Reporting_Office_2015072001.csv"
> InputFile = InputPath+RptgOfficeFile
> zInputFile = InputPath+ZipCodes
> zOutputFile = InputPath+'Zip_Code_Distance.csv'
> z1OutputFile = InputPath+'Minimum_Distance_Zip_Code_File.csv'
> 
> 
> f = open(InputFile, 'r')
> 
> zO = open(zOutputFile,'w')
> z1 = open(z1OutputFile,'w')
> 
> lines = [ ]
> OfficeZipcodes = []
> ZipRptOffice = {}
> OLatitude = [ ]
> OLongitude = [ ]
> OLocationCode = []
> dzip = []
> dLatitude = []
> dLongitude = []
> dCity = []
> dState = []
> Combined =[]
> Answers = []
> 
> for line in f:
>   l = [i.strip() for i in line.split(',')]
>   OfficeZipcodes.append(l[4])
>   ZipRptOffice[l[4]]= l[3]
>   OLatitude.append(l[5])
>   OLongitude.append(l[6])
>   OLocationCode.append(l[3])
> 
> del OfficeZipcodes[0]
> del OLatitude[0] 
> del OLongitude[0]
> del OLocationCode[0]
> 
> 
> zf = csv.DictReader(open(zInputFile))
> #http://courses.cs.washington.edu/courses/cse140/13wi/csv-parsing.html
> 
> for row in zf:
> dzip.append(row["zip"])
> dLatitude.append(float(row["latitude"]))
> dLongitude.append(float(row["longitude"]))
> dCity.append(row["city"])
> dState.append(row["state"])
> 
> 
> for i in range(len(OfficeZipcodes)):
> for j in range(len(dzip)):
> Distance = calculate_distance(OLatitude[i], 
> OLongitude[i],dLatitude[j],dLongitude[j])
> Combined.append([OfficeZipcodes[i], 
> OLocationCode[i],float(OLatitude[i]),float(OLongitude[i]),dState[j],dCity[j],dzip[j],
>  dLatitude[j],dLongitude[j],Distance])
> for i in range(len(Combined)):
>   
> zO.write(str(Combined[i][0])+","+str(Combined[i][1])+","+str(Combined[i][2])+","+
>  str(Combined[i][3])+","+str(Combined[i][4])+","+ str(Combined[i][5])+","+ 
> str(Combined[i][6])+","+str(Combined[i][7])+","+ 
> str(Combined[i][8])+","+str(Combined[i][9])+"\n")
> 
> zO.close()
> f.close()
> 
> I am using Python 2.7 on a Windows 7 machine.
> 
> Please help me get my head around how to accomplish this task.
> 
> Thank you very much.
> 
> Robert Davis

Emile,

Thanks so much works wonderfully. It is certainly a brilliant way of seeing the 
resolution.

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


Re: OT Re: Math-embarrassment results in CS [was: Should non-security 2.7 bugs be fixed?]

2015-07-23 Thread Chris Angelico
On Fri, Jul 24, 2015 at 7:50 AM, Mark Lawrence  wrote:
> Heard the one about the three engineers in the car that breaks down?
>
> The chemical engineer suggests that they could have contaminated fuel. They
> should try and get a sample and get someone to take it to a lab for
> analysis.
>
> The electrical engineer suggests that they check the battery and the leads
> for any problems.
>
> The Microsoft engineer suggests that they close all the windows, get out of
> the car, get back in the car, open all the windows and see what happens.
>

And the data scientist proved that the phenomenon is not wholly
unlikely, given the predicted average reliability of cars; further
studies would require improved sample size.

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


Re: OT Re: Math-embarrassment results in CS [was: Should non-security 2.7 bugs be fixed?]

2015-07-23 Thread Marko Rauhamaa
Laura Creighton :

> In a message of Fri, 24 Jul 2015 00:29:28 +0300, Marko Rauhamaa writes:
>>At the time I was in college I heard topology was very fashionable
>>among mathematicians. That was because it was one of the last
>>remaining research topics that didn't yet have an application.
>
> I have a very good freind who is a knot-theorist. (Chad Musick, who
> may have proven something wonderful.) see:
> http://chadmusick.wikidot.com/knots He says there are lots of
> applications for this in the field of circuit board layouts. And most
> mathematicians accept knot-theory as part of topology.

So topology, too, is lost.


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


Re: OT Re: Math-embarrassment results in CS [was: Should non-security 2.7 bugs be fixed?]

2015-07-23 Thread MRAB

On 2015-07-23 22:50, Mark Lawrence wrote:

On 23/07/2015 22:29, Marko Rauhamaa wrote:

Chris Angelico :


Fortunately, we don't need to completely understand it. New Horizons
reached Pluto right on time after a decade of flight that involved
taking a left turn at Jupiter... we can predict exactly what angle to
fire the rockets at in order to get where we want to go, even without
knowing how that gravity yank works.

Practicality beats purity?


Engineer!



Heard the one about the three engineers in the car that breaks down?

The chemical engineer suggests that they could have contaminated fuel.
They should try and get a sample and get someone to take it to a lab for
analysis.

The electrical engineer suggests that they check the battery and the
leads for any problems.

The Microsoft engineer suggests that they close all the windows, get out
of the car, get back in the car, open all the windows and see what happens.


And an Apple engineer would suggest buying a new car that runs only on
its manufacturer's brand of fuel. :-)

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


Re: OT Re: Math-embarrassment results in CS [was: Should non-security 2.7 bugs be fixed?]

2015-07-23 Thread Chris Angelico
On Fri, Jul 24, 2015 at 7:59 AM, Marko Rauhamaa  wrote:
> Laura Creighton :
>
>> In a message of Fri, 24 Jul 2015 00:29:28 +0300, Marko Rauhamaa writes:
>>>At the time I was in college I heard topology was very fashionable
>>>among mathematicians. That was because it was one of the last
>>>remaining research topics that didn't yet have an application.
>>
>> I have a very good freind who is a knot-theorist. (Chad Musick, who
>> may have proven something wonderful.) see:
>> http://chadmusick.wikidot.com/knots He says there are lots of
>> applications for this in the field of circuit board layouts. And most
>> mathematicians accept knot-theory as part of topology.
>
> So topology, too, is lost.

You remind me of the hipster mathematician cook, who burned himself by
calculating pie before it was cool.

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


Re: OT Re: Math-embarrassment results in CS [was: Should non-security 2.7 bugs be fixed?]

2015-07-23 Thread Laura Creighton
In a message of Thu, 23 Jul 2015 23:01:51 +0100, MRAB writes:

>And an Apple engineer would suggest buying a new car that runs only on
>its manufacturer's brand of fuel. :-)

Before you do that, read this:
http://teslaclubsweden.se/test-drive-of-a-petrol-car/
(ps, if you can read Swedish, the Swedish version is a little more fun.)

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


Re: Should non-security 2.7 bugs be fixed?

2015-07-23 Thread Rick Johnson
On Wednesday, July 22, 2015 at 11:26:50 PM UTC-5, Jason Swails wrote:
> I know my experiences don't hold true for everybody, but I
> also don't think they are uncommon (I know several
> colleagues that share many aspects of them).  And for me,
> the *better* Python 2.7 becomes, and the longer it's kept
> around, the easier (and more fun!) it makes my transition
> to Python 3.  So for me at least, arguments like "don't
> make Python 2.7 too good or people won't switch" are not
> only wrong, but in actuality counter-productive.

Thanks for sharing your story. You offer a compelling
argument for maintaining Py2.x in peak condition for many 
years. 

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


Re: OT Re: Math-embarrassment results in CS [was: Should non-security 2.7 bugs be fixed?]

2015-07-23 Thread Mark Lawrence

On 23/07/2015 23:01, MRAB wrote:

On 2015-07-23 22:50, Mark Lawrence wrote:

On 23/07/2015 22:29, Marko Rauhamaa wrote:

Chris Angelico :


Fortunately, we don't need to completely understand it. New Horizons
reached Pluto right on time after a decade of flight that involved
taking a left turn at Jupiter... we can predict exactly what angle to
fire the rockets at in order to get where we want to go, even without
knowing how that gravity yank works.

Practicality beats purity?


Engineer!



Heard the one about the three engineers in the car that breaks down?

The chemical engineer suggests that they could have contaminated fuel.
They should try and get a sample and get someone to take it to a lab for
analysis.

The electrical engineer suggests that they check the battery and the
leads for any problems.

The Microsoft engineer suggests that they close all the windows, get out
of the car, get back in the car, open all the windows and see what
happens.


And an Apple engineer would suggest buying a new car that runs only on
its manufacturer's brand of fuel. :-)



Like it, marks out of 10, 15 :)

--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: OT Re: Math-embarrassment results in CS [was: Should non-security 2.7 bugs be fixed?]

2015-07-23 Thread Grant Edwards
On 2015-07-23, Marko Rauhamaa  wrote:
> Chris Angelico :
>
>> Fortunately, we don't need to completely understand it. New Horizons
>> reached Pluto right on time after a decade of flight that involved
>> taking a left turn at Jupiter... we can predict exactly what angle to
>> fire the rockets at in order to get where we want to go, even without
>> knowing how that gravity yank works.
>>
>> Practicality beats purity?
>
> Engineer!
>
> At the time I was in college I heard topology was very fashionable among
> mathematicians. That was because it was one of the last remaining
> research topics that didn't yet have an application.

You can always pick out the topologist at a conference: he's the one
trying to dunk his coffee cup in his doughnut.

[Hey, how often do you get to use a topology  joke.]

--
Grant

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


Re: Find Minimum for element in multiple dimensional array

2015-07-23 Thread Denis McMahon
On Wed, 22 Jul 2015 15:54:06 -0700, Robert Davis wrote:

> Given a set of arrays within an array how do I find the arrays with the
> minimum values based on two elements/columns in the array? Those two
> elements/columns are the destination zip code and distance.

create a new dictionary

for each source/destination pair in your list of source destination pairs:

if the destination zip code is not in the new dictionary, copy the entry 
to the new dictionary keyed on the destination zip code.

if the destination zip code is in the new dictionary, copy the entry to 
the new dictionary keyed on the destination zip code only if the distance 
is less than the distance of the current entry in the new dictionary.

convert the values of the new dictionary to a list.

write the list as csv

Here is an example, note that I'm just using 2 bits of data, the first 
bit of data in each sub list simulates the destination area code, and the 
second simulates the distance from the associated source zip code. 
Obviously you need to adjust these to match the actual parameters in your 
list of lists.

import csv

info = [['a',15],['a',17],['a',21],['b',96],['b',45],['b',38],['c',71],
['c',18],['c',54]]

tmp = {}

for thing in info:
if thing[0] in tmp:
if thing[1] < tmp[thing[0]][1]:
tmp[thing[0]] = thing
else:
tmp[thing[0]] = thing

with open("output.csv", "wb") as f:
writer = csv.writer(f)
writer.writerows(tmp.values())

and lo:

$ cat output.csv
a,15
c,18
b,38
$ 


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


Python 3.4 Idle?

2015-07-23 Thread Steve Burrus
Listen I got back the Idle EAditor the other day but I had to install the 
older, version 2.7, version of Python to get it. So naturally I w onder if I 
can get Idle for version 3.4.*?


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


Python 3.4 Idle?

2015-07-23 Thread Steve Burrus
I got Idle the other day biut had to get the older version, 2.7, of python to 
get it. So I wonder if there is an Idle version  that comes with python 3.4.*? 
-- 
https://mail.python.org/mailman/listinfo/python-list


Fwd: ImportError: No module named site

2015-07-23 Thread [email protected]

hi:
I'm Needing to get python 2.7.10 to cross compile correctly for an ARM 
embedded device. When I execute python using shell, it comes out this 
error:ImportError: No module named site.I have setted environment 
varible:PYTHONHOME and PYTHONPATH. Is there some good idea to sovle this 
issue?



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


Re: Python 3.4 Idle?

2015-07-23 Thread Chris Angelico
On Fri, Jul 24, 2015 at 11:34 AM, Steve Burrus  wrote:
> I got Idle the other day biut had to get the older version, 2.7, of python to 
> get it. So I wonder if there is an Idle version  that comes with python 3.4.*?

What system are you on? What did you do to install Python? On Windows,
the python.org installers usually come with IDLE; on some Linuxes,
it's separately distributed; if you got a third-party Python distro,
it's up to them what they put in it. But yes, you most certainly can
get 3.4+ with IDLE.

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


Re: OT Re: Math-embarrassment results in CS [was: Should non-security 2.7 bugs be fixed?]

2015-07-23 Thread Rick Johnson
On Thursday, July 23, 2015 at 7:08:10 PM UTC-5, Grant Edwards wrote:
> You can always pick out the topologist at a conference:
> he's the one trying to dunk his coffee cup in his
> doughnut.
> 
> [Hey, how often do you get to use a topology  joke.]

Don't sale yourself short Grant. You get extra bonus points
here: (1) told a rare joke and (2) perpetuated the off topic
ramblings in an effort to deflect from main subject. Nice
multitasking dude!




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


Re: Python 3.4 Idle?

2015-07-23 Thread Steve Burrus
On Thursday, July 23, 2015 at 8:41:03 PM UTC-5, Chris Angelico wrote:
> On Fri, Jul 24, 2015 at 11:34 AM, Steve Burrus  
> wrote:
> > I got Idle the other day biut had to get the older version, 2.7, of python 
> > to get it. So I wonder if there is an Idle version  that comes with python 
> > 3.4.*?
> 
> What system are you on? What did you do to install Python? On Windows,
> the python.org installers usually come with IDLE; on some Linuxes,
> it's separately distributed; if you got a third-party Python distro,
> it's up to them what they put in it. But yes, you most certainly can
> get 3.4+ with IDLE.
> 
> ChrisA

Well I am exactly on Windows 10 beta preview on a 64 bit system. Idle is on my 
Programs menu but I cannot actually activate it.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: OT Re: Math-embarrassment results in CS [was: Should non-security 2.7 bugs be fixed?]

2015-07-23 Thread Paul Rubin
Grant Edwards  writes:
> You can always pick out the topologist at a conference: he's the one
> trying to dunk his coffee cup in his doughnut.
> [Hey, how often do you get to use a topology  joke.]

Did you hear about the idiot topologist?  He couldn't tell his butt from
a hole in the ground, but he *could* tell his butt from two holes in the
ground.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Fwd: ImportError: No module named site

2015-07-23 Thread Laura Creighton
In a message of Fri, 24 Jul 2015 09:37:35 +0800, "[email protected]" write
s:
>hi:
>I'm Needing to get python 2.7.10 to cross compile correctly for an ARM 
>embedded device. When I execute python using shell, it comes out this 
>error:ImportError: No module named site.I have setted environment 
>varible:PYTHONHOME and PYTHONPATH. Is there some good idea to sovle this 
>issue?

You might want to try that question over here:
https://mail.python.org/mailman/listinfo/mobile-sig

I think you have an issue with dynamic library linking, but I don't
know how to find out for sure.   People there do.

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


Re: OT Re: Math-embarrassment results in CS [was: Should non-security 2.7 bugs be fixed?]

2015-07-23 Thread Rick Johnson
On Thursday, July 23, 2015 at 9:03:15 PM UTC-5, Paul Rubin wrote:
> Did you hear about the idiot topologist?  He couldn't tell his butt from
> a hole in the ground, but he *could* tell his butt from two holes in the
> ground.

This sounds more like a riddle than a joke. So in other
words: the message passing requires himself in one hole and
a clone of himself in another hole speaking the message
simultaneously?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Fwd: ImportError: No module named site

2015-07-23 Thread Christopher Mullins
What did you set those variables to?

Also, output from python -v would be helpful.
On Jul 23, 2015 10:15 PM, "Laura Creighton"  wrote:

> In a message of Fri, 24 Jul 2015 09:37:35 +0800, "[email protected]"
> write
> s:
> >hi:
> >I'm Needing to get python 2.7.10 to cross compile correctly for an ARM
> >embedded device. When I execute python using shell, it comes out this
> >error:ImportError: No module named site.I have setted environment
> >varible:PYTHONHOME and PYTHONPATH. Is there some good idea to sovle this
> >issue?
>
> You might want to try that question over here:
> https://mail.python.org/mailman/listinfo/mobile-sig
>
> I think you have an issue with dynamic library linking, but I don't
> know how to find out for sure.   People there do.
>
> Laura
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Object Pool design pattern

2015-07-23 Thread Abder-Rahman Ali
Hello,

How can we implement the Object Pool design pattern in Python, especially
when the pool consists of array data types?

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


Re: Object Pool design pattern

2015-07-23 Thread Laura Creighton
In a message of Thu, 23 Jul 2015 23:09:38 +0200, Abder-Rahman Ali writes:
>Hello,
>
>How can we implement the Object Pool design pattern in Python, especially
>when the pool consists of array data types?
>
>Thanks.

Is your problem 'I don't know how to implement the Object Pool Design pattern
at all?' -- in which case Googling "python object pool design pattern"
gets you some nice hits -- or you are having some particular problem
related to your use of arrays -- in which case post code (and errors
if you have any) and we will see what we can do.

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


Re: OT Re: Math-embarrassment results in CS [was: Should non-security 2.7 bugs be fixed?]

2015-07-23 Thread Rustom Mody
On Friday, July 24, 2015 at 2:59:41 AM UTC+5:30, Marko Rauhamaa wrote:
> Chris :
> 
> > Fortunately, we don't need to completely understand it. New Horizons
> > reached Pluto right on time after a decade of flight that involved
> > taking a left turn at Jupiter... we can predict exactly what angle to
> > fire the rockets at in order to get where we want to go, even without
> > knowing how that gravity yank works.
> >
> > Practicality beats purity?
> 
> Engineer!
> 
> At the time I was in college I heard topology was very fashionable among
> mathematicians. That was because it was one of the last remaining
> research topics that didn't yet have an application.

Probably shows more than anything else how siloed university depts are:

http://www.amazon.in/Topology-Cambridge-Theoretical-Computer-Science/dp/0521576512
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Integers with leading zeroes

2015-07-23 Thread Gregory Ewing

Michael Torrie wrote:

A credit card number is indeed a number, and there are
mathematical formulas for determining if a particular number is a valid
(as in well-formed) credit card number,


If you're talking about the check-digit algorithm,
that doesn't treat the whole number as an integer,
it works on the individual digits:

http://www.datagenetics.com/blog/july42013/


and possibly to identify what kind of card it is.


That's determined by the leading digits, and can
be done just as well by treating them as characters.

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


Re: Integers with leading zeroes

2015-07-23 Thread Chris Angelico
On Fri, Jul 24, 2015 at 4:23 PM, Gregory Ewing
 wrote:
> Michael Torrie wrote:
>>
>> A credit card number is indeed a number, and there are
>> mathematical formulas for determining if a particular number is a valid
>> (as in well-formed) credit card number,
>
>
> If you're talking about the check-digit algorithm,
> that doesn't treat the whole number as an integer,
> it works on the individual digits:
>
> http://www.datagenetics.com/blog/july42013/
>
>> and possibly to identify what kind of card it is.
>
>
> That's determined by the leading digits, and can
> be done just as well by treating them as characters.

So, the definition of a number is: Something on which you perform
numeric operations. Aside from being circular, wouldn't this mean that
"rope" is a number, since its square root is string?

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


Re: Fwd: ImportError: No module named site

2015-07-23 Thread [email protected]

hi:
   Do you know, where can I download the python2.7.10-xcompile.patch 
file?thanks.


On 07/24/2015 10:20 AM, Christopher Mullins wrote:


What did you set those variables to?

Also, output from python -v would be helpful.

On Jul 23, 2015 10:15 PM, "Laura Creighton" > wrote:


In a message of Fri, 24 Jul 2015 09:37:35 +0800,
"[email protected] " write
s:
>hi:
>I'm Needing to get python 2.7.10 to cross compile correctly for
an ARM
>embedded device. When I execute python using shell, it comes out this
>error:ImportError: No module named site.I have setted environment
>varible:PYTHONHOME and PYTHONPATH. Is there some good idea to
sovle this
>issue?

You might want to try that question over here:
https://mail.python.org/mailman/listinfo/mobile-sig

I think you have an issue with dynamic library linking, but I don't
know how to find out for sure.   People there do.

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



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