Re: Problem to calculate the mean in version 3.4

2015-09-25 Thread Peter Otten
Michel Guirguis wrote:

> I have downloaded the version 3.4 and I have a problem to calculate the
> mean. The software does not recognise the function mean(). I am getting
> the following error.
> 
 mean([1, 2, 3, 4, 4])
> Traceback (most recent call last):
>   File "", line 1, in 
> mean([1, 2, 3, 4, 4])
> NameError: name 'mean' is not defined
> 
> Could you please help. Is it possible to send me the version that
> calculate statistics.

The help for the statistics and other modules assumes basic knowledge of 
Python. I recommend you read the tutorial or any other introductory text on 
Python before you proceed.

Regarding your actual question: before you can use a function you have to 
import it. There are two ways:

(1) Recommended: import the module and use the qualified name:

>>> import statistics
>>> statistics.mean([1, 2, 3, 4, 4])
2.8

(2) Import the function. Typically done when you want to use it in the 
interactive interpreter, not in a script.

>>> from statistics import mean
>>> mean([1, 2, 3, 4, 4])
2.8


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


Re: Problem to calculate the mean in version 3.4

2015-09-25 Thread Paul Rubin
Michel Guirguis  writes:
 mean([1, 2, 3, 4, 4])
> Traceback (most recent call last):...
> NameError: name 'mean' is not defined

Before you can use that function, you have to import the statistics
module, e.g.:

>>> import statistics
>>> statistics.mean([1,2,3,4,4])   

or

>>> from statistics import mean
>>> mean([1,2,3,4,4])
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: ConnectionError handling problem

2015-09-25 Thread Cameron Simpson

On 24Sep2015 22:46, shiva upreti  wrote:

On Friday, September 25, 2015 at 10:55:45 AM UTC+5:30, Cameron Simpson wrote:

On 24Sep2015 20:57, shiva upreti  wrote:
>Thank you Cameron.
>I think the problem with my code is that it just hangs without raising any 
>exceptions. And as mentioned by Laura above that when I press CTRL+C, it 
>just catches that exception and prints ConnectionError which is definitely 
>a lie in this case as you mentioned.


Ok. You original code says:

 try:
   r=requests.post(url, data=query_args)
 except:
   print "Connection error"

and presumably we think your code is hanging inside the requests.post call? You 
should probably try to verify that, because if it is elsewhere you need to 
figure out where (lots of print statements is a first start on that).


I would open two terminals. Run your program until it hangs in one.

While it is hung, examine the network status. I'll presume you're on a UNIX 
system of some kind, probably Linux? If not it may be harder (or just require 
someone other than me).


If it is hung in the .post call, quite possibly it has an established connecion 
to the target server - maybe that server is hanging.


The shell command:

 netstat -rn | fgrep 172.16.68.6 | fgrep 8090

will show every connection to your server hosting the URL 
"http://172.16.68.6:8090/login.xml";. That will tell you if you have a 
connection (if you are the only person doing the connecting from your machine).


If you have the "lsof" program (possibly in /usr/sbin, so "/usr/sbin/lsof") you 
can also examine the state of your hung Python program. This:


 lsof -p 12345

will report on the open files and network connections of the process with pid 
12345. Adjust to suit: you can find your program's pid ("process id") with the 
"ps" command, or by backgrounding your program an issuing the "jobs" command, 
which should show the process id more directly.


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


Re: PyInstaller+ Python3.5 (h5py import error)

2015-09-25 Thread Hedieh E
On Thursday, September 24, 2015 at 1:12:31 PM UTC+2, Laura Creighton wrote:
> In a message of Thu, 24 Sep 2015 02:58:35 -0700, Heli Nix writes:
> >Thanks Christian, 
> >
> >It turned out that h5py.defs was not the only hidden import that I needed to 
> >add. 
> >
> >I managed to get it working with the follwoing command adding 4 hidden 
> >imports. 
> >
> >
> >pyinstaller --hidden-import=h5py.defs --hidden-import=h5py.utils  
> >--hidden-import=h5py.h5ac --hidden-import=h5py._proxy  test.py
> >
> >
> >is there anyway that you can use to add all h5py submodules all together?
> >
> >Thanks, 
> >
> 
> Yes.  You can use a hook file.
> see: https://pythonhosted.org/PyInstaller/#using-hook-files
> 
> Laura

Thanks Laura, 
Very Useful, 

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


Re: Learning Modules, Arguments, Parameters (imma noob)

2015-09-25 Thread alister
On Thu, 24 Sep 2015 11:45:06 -0700, codywcox wrote:

> I seem to be having a problem understanding how arguments and parameters
> work, Most likely why my code will not run.
> Can anyone elaborate on what I am doing wrong?
> 
> '''
> Cody Cox 9/16/2015 Programming Exercise 1 - Kilometer Converter Design a
> modular program that asks the user to enter a distance in kilometers and
> then convert it to miles Miles = Kilometers * 0.6214 '''
> 
> def main():
>get_input()
>convert_kilo()
> 
> 
>  def get_input(kilo):
>kilo = float(input('Enter Kilometers: '))
>return kilo
> 
>  def convert_kilo(kilo,miles):
>  miles = float(kilo * 0.6214)
>  print( kilo,' kilometers converts to ',miles,' miles')
> 
>  main()

clearly a homework exercise but you  have asked for help in understanding 
& not just for a solution which is good.

as others have pointed out you are throwing away the data returned from 
get_input

I would also suggest that you return the result form convert_kilo instead 
of printing it in the function & print it in the main loop instead.

kilo=get_input()
miles=convert_kilo(kilo)
print (miles)

it does not matter for this trivial assignment but as you progress 
further you will discovery it is better to keep output seperated from the 
main logic of the program. 



-- 
What is mind?  No matter.  What is matter?  Never mind.
-- Thomas Hewitt Key, 1799-1875
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Learning Modules, Arguments, Parameters (imma noob)

2015-09-25 Thread Cody Cox
Awesome guys! Thank you for helping me understand this material. Parameters and 
Arguments are tricky. Looks like its mainly a game of connect the dots with 
variables. lol.

When you return a variable, it needs somewhere to go, and that's why it goes to 
the next call into the argument area if I need to use that piece of information 
for a calculation, right?

so if I understand correctly, when I create a function and return a variable, 
that variable needs to go in the argument when it is called? or into another 
functions argument for calculation? 
I apologize if I sound dumb. lol. I know this must be very elementary.

Yes this is a homework assignment, but I was trying to figure out how 
parameters and arguments work, not get an answer, this was a huge help. I will 
keep looking over your details over and over to make sure I understand.

Appreciate all the help and understanding! :)

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


Re: Learning Modules, Arguments, Parameters (imma noob)

2015-09-25 Thread Cody Cox
Oh, i also noticed that declaring the variable I was using and setting it =0.0 
helped me out, seems the program had "garbage" in it... (that's what my 
professor said.)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Learning Modules, Arguments, Parameters (imma noob)

2015-09-25 Thread Cody Cox
#Cody Cox
#9/16/2015
#Programming Exercise 1 - Kilometer Converter
#Design a modular program that asks the user to enter a distance in kilometers 
and then covert it to miles
# Miles = Kilometers * 0.6214


def main():
#set the variable to 0.0, makes it a float and creates a place in memory 
for the variable.
kilo = 0.0

'''
this I am not sure about, I set Kilo=get_input(kilo), but why do I need the 
argument when
I am going to pass it to convert_to_kilometers? but the program works so I 
am guessing that is where it is saving
 the variable in order to be passed? so it needs to be returned as an 
argument to be passed as an argument for
 the next call???

'''
kilo = get_input(kilo)

convert_to_kilometers(kilo)

def get_input(kilo):
kilo =float(input('Enter the amount of Kilometers: '))
return kilo

def convert_to_kilometers(kilo):
miles = kilo * .6214
print(kilo,'Kilometers converts to: ',miles, ' Miles.')

main()

'''
This was a great learning experience trying to understand modules
and how parameters & arguments work together.
Thanks for helping me understand
'''
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Learning Modules, Arguments, Parameters (imma noob)

2015-09-25 Thread Ian Kelly
On Fri, Sep 25, 2015 at 1:03 PM, Cody Cox  wrote:
> def main():
> #set the variable to 0.0, makes it a float and creates a place in memory 
> for the variable.
> kilo = 0.0

This is addressing a symptom, not the actual problem. Initializing
kilo here prevents Python from complaining when you try to access the
kilo variable in the "kilo = get_input(kilo)" line below. However, you
don't need it there either.

> '''
> this I am not sure about, I set Kilo=get_input(kilo), but why do I need 
> the argument when
> I am going to pass it to convert_to_kilometers? but the program works so 
> I am guessing that is where it is saving
>  the variable in order to be passed? so it needs to be returned as an 
> argument to be passed as an argument for
>  the next call???
>
> '''
> kilo = get_input(kilo)

No, you don't need the argument at all. You use arguments to pass in
data that the function needs to do its work. In this case you're
passing in the *current* value of kilo, which you set above to be 0.0.
This isn't data that is needed by get_input, so you shouldn't pass it
in (and the get_input function should not require it).

The result of the get_input call is then assigned to kilo, replacing
the 0.0 which you don't need. It's fine for kilo to be initialized
with this line rather than the one above.

> convert_to_kilometers(kilo)

This is okay, but as you get more advanced you will probably want this
function to return a value, which you could store in another variable,
e.g.:

miles = convert_to_miles(kilo)

> def get_input(kilo):
> kilo =float(input('Enter the amount of Kilometers: '))
> return kilo

As noted above, this function should not have kilo as a parameter. It
never uses it. This function needs to return kilo *to* its caller, not
take a value for kilo *from* its caller.

> def convert_to_kilometers(kilo):
> miles = kilo * .6214
> print(kilo,'Kilometers converts to: ',miles, ' Miles.')

This is fine but poorly named. This function converts kilometers to
miles. It doesn't convert anything to kilometers as suggested by the
name.

And again, as you get more advanced you would probably want this to
return the value of miles rather than just print it.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Learning Modules, Arguments, Parameters (imma noob)

2015-09-25 Thread Laura Creighton
In a message of Fri, 25 Sep 2015 11:50:10 -0700, Cody Cox writes:
>Awesome guys! Thank you for helping me understand this material. Parameters 
>and Arguments are tricky. Looks like its mainly a game of connect the dots 
>with variables. lol.
>
>When you return a variable, it needs somewhere to go, and that's why it goes 
>to the next call into the argument area if I need to use that piece of 
>information for a calculation, right?

No.

>so if I understand correctly, when I create a function and return a variable, 
>that variable needs to go in the argument when it is called? or into another 
>functions argument for calculation? 
>I apologize if I sound dumb. lol. I know this must be very elementary.

No.

>Yes this is a homework assignment, but I was trying to figure out how 
>parameters and arguments work, not get an answer, this was a huge help. I will 
>keep looking over your details over and over to make sure I understand.
>
>Appreciate all the help and understanding! :)
>
>-Cody

You have a very basic conceptual misunderstanding.

def main():
count = 0
animals = 'tigers'
change_my_value_to_50_frogs(count, animals)
print ("I fought", count, animals)

def change_my_value_to_50_frogs(count, animals):
count = 50
animals = 'frogs'

main()

-

I am pretty sure you expect this code to print  'I fought 50 frogs'.
It doesn't.  It prints 'I fought 0 tigers'.
You have the idea that when you pass parameters to a function, by name,
you want the values of those parameters to get changed by the function.
(and I sort of cheated by calling the function change_my_value).
This is not what happens.  You cannot change values this way.

so we rewrite change_my_value_to_50_frogs

def fifty_frogs():
count = 50
animals = 'frogs'
return count, animals

Now fifty_frogs is going to happily return the changed values you wanted.
But you have to set up your main program to receive those changed values
you wanted.

so we rewrite main as:

def main():
count = 0
animals = 'tigers'
count, animals = fifty_frogs() 
print ("I fought", count, animals)

now

main()

says 'I fought 50 frogs'.

NOTE: there is nothing, nothing, nothing special about the fact that
in fifty_frogs I used the names 'count' and 'animals'.

Let us try a new version of fifty_frogs()

def fifty_frogs():
experience = 50
monsters = 'frogs'
return experience, monsters

All the same, just different words.
Does that matter?

No.  You are going to return whatever is called 'experience' and
whatever is called 'monsters' and assign them to 'count' and 'monsters'.

Whether you name these things the same thing, or different things
makes no difference.

Does this make sense?

If not, come back with more questions.  And play around with the
python interactive interpreter, or idle -- that is what it is for.
neat little experiements like this. :)

Laura


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


Re: Learning Modules, Arguments, Parameters (imma noob)

2015-09-25 Thread Laura Creighton
In a message of Fri, 25 Sep 2015 22:15:26 +0200, Laura Creighton writes:

>No.  You are going to return whatever is called 'experience' and
>whatever is called 'monsters' and assign them to 'count' and 'monsters'.

ARRGH!  I meant
assign them to 'count' and 'animals'.
(I read that 3 times and _still_ got it wrong!)
I am very sorry for this confusion.
Laura
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Learning Modules, Arguments, Parameters (imma noob)

2015-09-25 Thread Cody Cox
On Friday, September 25, 2015 at 1:26:02 PM UTC-7, Laura Creighton wrote:
> In a message of Fri, 25 Sep 2015 22:15:26 +0200, Laura Creighton writes:
> 
> >No.  You are going to return whatever is called 'experience' and
> >whatever is called 'monsters' and assign them to 'count' and 'monsters'.
> 
> ARRGH!  I meant
> assign them to 'count' and 'animals'.
> (I read that 3 times and _still_ got it wrong!)
> I am very sorry for this confusion.
> Laura

All good, I got the idea, and you explained it very nicly. thank you for this 
example. I shall be back with more questions! haha.

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


Re: Learning Modules, Arguments, Parameters (imma noob)

2015-09-25 Thread Denis McMahon
On Fri, 25 Sep 2015 12:03:43 -0700, Cody Cox wrote:

> #Design a modular program that asks the user to enter a distance in
> kilometers and then covert it to miles # Miles = Kilometers * 0.6214

#!/usr/bin/python

# main calls the input routine to get the km value, then 
# calls the conversion routine to convert the km value
# to miles, then prints the output

def main():
km = get_kms()
mi = convert_km_mi(k)
print "{} Km is {} miles.".format(km, mi)

# get_float_input() reads a float input using the supplied
# prompt.

def get_float_input(prompt):
return float(input(prompt))

# Get kms uses the generic get_float_input to read a km
# value

def get_kms():
return get_float_input("Enter Kms: ")

# generic conversion function

def convert_float_a_b(a, factor):
return float(a * factor)

# convert km_mi uses the generic converter
# to convert km to miles

def convert_km_mi(km):
return convert_float_a_b(km, 0.6214)

# now call main to kick it all off

main()

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


Re: Learning Modules, Arguments, Parameters (imma noob)

2015-09-25 Thread Terry Reedy

On 9/25/2015 2:50 PM, Cody Cox wrote:

Awesome guys! Thank you for helping me understand this material.
Parameters and Arguments are tricky. Looks like its mainly a game of
connect the dots with variables. lol.


If you stick with the convention that parameters are names in the header 
of a function definition, arguments are objects in a function call, and 
calls bind parameter names to argements (or sometimes collected 
arguments), then it is not so tricky.  But also remember that not 
everyone follows this convention, or even any consistent usage.


To reiterate about calling and binding.

def f(x): pass
f(2)

binds the name 'x' to the int object with value 2.  This is essentially 
the same as 'x = 2', except that the binding takes place in the local 
namespace of the function rather than in the local namespace of the call.



--
Terry Jan Reedy

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


Re: Learning Modules, Arguments, Parameters (imma noob)

2015-09-25 Thread Larry Hudson via Python-list

You've already received a lot of answers and guidance, but here is on more 
point...

On 09/25/2015 12:03 PM, Cody Cox wrote:
[snip]

 this I am not sure about, I set Kilo=get_input(kilo), ...


Watch your capitalization!  Kilo is _NOT_ the same as kilo.  Case is significant in Python (as 
well as in many other programming languages).


Also, as has already been pointed out:  what you want here is kilo=get_input().  Along with the 
corresponding change to the get_input() definition.  This function does NOT need a passed parameter.


-=- Larry -=-

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


PY3.5 and nnumpy and scipy installation problem

2015-09-25 Thread Ek Esawi
Hi All—

I am a beginner in Python and new to this list, but I am an experienced
programming in a few other languages.


Last year I installed numpy and scipy for Python3.3 on my computer with
windows 7, 64 bit OS. Today I downloaded Python3.5, but I the installation
for numpy 1.9.2 or 1.9.3 nor scipy 0.16.0 did work on the same computer.
Basically the setup for both numpy and scipy did not work. Any ideas are
greatly appreciated.


Thanks in advance,


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


64 bit python 3.5

2015-09-25 Thread Bill Strum
Is there a 64 bit version of 3.5 and if so where can I get it.

Thanks.

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


ANN: python-ldap 2.4.21

2015-09-25 Thread Michael Ströder
Find a new release of python-ldap:

  http://pypi.python.org/pypi/python-ldap/2.4.21

python-ldap provides an object-oriented API to access LDAP directory
servers from Python programs. It mainly wraps the OpenLDAP 2.x libs for
that purpose. Additionally it contains modules for other LDAP-related
stuff (e.g. processing LDIF, LDAP URLs and LDAPv3 schema).

Project's web site:

  http://www.python-ldap.org/

Checksums:

$ md5sum python-ldap-2.4.21.tar.gz
1ce26617e066f412fd5ba95bfba4ba5a
$ sha1sum python-ldap-2.4.21.tar.gz
35ed5913d804f14e952bec414c569e140feb889d
$ sha256sum python-ldap-2.4.21.tar.gz
2a3ce606465d2d5fbd0a620516b6648ffd85c343d9305d49a2a1f7d338b8bbd4

Ciao, Michael.


Released 2.4.21 2015-09-25

Changes since 2.4.20:

Lib/
* LDAPObject.read_s() now returns None instead of raising
  ldap.NO_SUCH_OBJECT in case the search operation returned emtpy result.
* ldap.resiter.ResultProcessor.allresults() now takes new key-word
  argument add_ctrls which is internally passed to LDAPObject.result4()
  and lets the method also return response control along with the search
  results.
* Added ldap.controls.deref implementing support for dereference control

Tests/
* Unit tests for module ldif (thanks to Petr Viktorin)

--
Michael Ströder
E-Mail: mich...@stroeder.com
http://www.stroeder.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PY3.5 and nnumpy and scipy installation problem

2015-09-25 Thread Steven D'Aprano
Hi Ek, and welcome, 

My responses below your questions.


On Sat, 26 Sep 2015 01:43 pm, Ek Esawi wrote:

> Hi All—
> 
> I am a beginner in Python and new to this list, but I am an experienced
> programming in a few other languages.
> 
> Last year I installed numpy and scipy for Python3.3 on my computer with
> windows 7, 64 bit OS. Today I downloaded Python3.5, but I the installation
> for numpy 1.9.2 or 1.9.3 nor scipy 0.16.0 did work on the same computer.
> Basically the setup for both numpy and scipy did not work. Any ideas are
> greatly appreciated.

While we are very knowledgeable, what we don't know is what went wrong. Can
you describe what you mean by "did not work"?

Preferably, if an error message was printed, please COPY and PASTE (don't
retype, especially not from memory) the error message?

If some other error occurred (Windows crash, computer caught fire...) please
describe it.

It may help if you explain the exact commands you used to install. Did you
use a text-based installer from the command line, or a GUI?

The more information you can give, the better the chances we can help.


Regards,




-- 
Steven

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


Re: PY3.5 and nnumpy and scipy installation problem

2015-09-25 Thread Mark Lawrence

On 26/09/2015 04:43, Ek Esawi wrote:

Hi All—

I am a beginner in Python and new to this list, but I am an experienced
programming in a few other languages.

Last year I installed numpy and scipy for Python3.3 on my computer with
windows 7, 64 bit OS. Today I downloaded Python3.5, but I the
installation for numpy 1.9.2 or 1.9.3 nor scipy 0.16.0 did work on the
same computer. Basically the setup for both numpy and scipy did not
work. Any ideas are greatly appreciated.


You don't have Visual Studio 2015 installed and so couldn't compile the 
code from a .tar.gz file or similar?


Once again the cavalry comes charging over the hill.

http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy
http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy

Gohkle for World Vice President, after the BDFL :)



Thanks in advance,

Sincerely, EKE



--
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: 64 bit python 3.5

2015-09-25 Thread Mark Lawrence

On 25/09/2015 17:55, Bill Strum wrote:

Is there a 64 bit version of 3.5 and if so where can I get it.

Thanks.

--
Bill Strum



https://www.python.org/downloads/release/python-350/

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