Fun Python Function Discovery

Status
Not open for further replies.

dockeen

Ars Tribunus Militum
1,600
I was playing around with doing some functional work with
a Python program I wrote to look at some infrared image
data, and I made an interesting discovery...or maybe I was
just dim before.

I found that I can pass an array to a function with no fuss
or muss. Just pass it, like any other variable. It appears
to pass by reference.

Interesting.

Wayne
 

dockeen

Ars Tribunus Militum
1,600
Yes, it is. What was a little suprising for me is that
a lot of the support for arrays is pulled in through
the Numerical Python module, it is not really an inherent
part of Python, so I was suprised that I was able to
use the array as an argument in such a straight-foward
fashion. I even did an experiement in which I returned
an array out of the function.

This is a measure of what a boring person I am, discovering
this constitutes big excitement on a weekend.

:rolleyes: :rolleyes: :rolleyes:

Wayne
 

dockeen

Ars Tribunus Militum
1,600
A reccomendation based on my use for the last year or two.
I like VPython. It is an add-on to regular Python. I like
it because

(a) You get a pretty good IDE
(b) It brings Numpy in with it.
(c) The graphics, including neat 3D stuff are easy.

The attribute of VPython / Python have made it my new
"gun to my head, gotta do something quick" language for
most things. I do a LOT of data analysis with it.

Here is the link:
http://www.vpython.org/

One other module you might want to add, again mostly
from the plotting angle is DISLIN

http://www.linmpi.mpg.de/dislin/

Wayne
 
D

Deleted member 5324

Guest
Originally posted by pelican:
Isn't python a "weak"-typed language?

Python is strongly typed, but it's done dynamically, at runtime, rather than at
compile time. If an object is improperly typed, it raises an exception, unlike
in weakly-typed languages, where it would simply "do the best it could" (even if
that was crashing, or corrupting memory, or segfaulting) and move on.

Jeremy
 
D

Deleted member 5324

Guest
Originally posted by dockeen:
Yes, it is. What was a little suprising for me is that
a lot of the support for arrays is pulled in through
the Numerical Python module

Python's lists and the "array" module don't come from NumPy at all.

I even did an experiement in which I returned an array out of the function.

In Python, you can pass anything into a function and return anything else. If
it exists in Python, you can pass it.

Jeremy
 

dockeen

Ars Tribunus Militum
1,600
Actually, a lot of the higher level support for arrays
do in fact come from Numpy. When I was first picking up Python, I remeber what a pain it was to do some of the things that I wanted to do through the regular Python methods. The Numpy stuff in a lot of ways looks like array functions from Matlab, which, again, learning in a screwy order, I learned after the fact.

Its actually sort of funny, a number of my Python books
kind of avoid serious discussion of arrays, but spend a
lot of time of lists. I guess my interests are less...
well..interesting.

I know you can return a variety of data from a function,
I just thought it was a neat contrast in the clean way
you can return an array versus, say C++. Minimum knowlege
and intelligence needed, perfectly suited to an intellectually
challenged physicist.

I definitely fit under the category of easily impressed.

Wayne
 

dockeen

Ars Tribunus Militum
1,600
Actually, I can cross numeric types and not generate an exception. If possible, the language will recast. Try the same thing in Ada and it won't compile. Heck, in Ada, I can have two defined types which are fundamentally the same type, and have the same problem. Now, that is my definition of strong typing. Probably not correct, but that is how a weirdo like me things about it.

In a related unrelated note, I made the classic mistake the other day, I was dividing one integer by another, and was wondering why I was getting zero. Took me a while to realize I was dealing with integers (numerator smaller than denominator). When I did, I hit myself on the head. Still hurts.

Wayne
 
D

Deleted member 5324

Guest
Originally posted by dockeen:
Actually, I can cross numeric types and not generate an exception. If possible, the language will recast. Try the same thing in Ada and it won't compile.
That's because Ada sacrifices a bit of programmer convenience (in this case, the
ability to cross numeric types without explicit casts) for a lot more program
safety. You can cross numeric types in Ada, you just have to explicitly
cast then to the proper type (disclaimer: I don't use Ada itself, but I do write
most of my code in O'Caml, another strictly typed language.)

Now, that is my definition of strong typing. Probably not correct, but that is how a weirdo like me things about it.

Someone formally trained in CS might correct my following definitions, but
here's how I understand, and I'm pretty sure these are adequate definitions:

Strong typing means that the language's behavior is defined in cases of mistyped
programs. It can be defined to either reject the program as a whole (the
decision made by strictly typed languages like Ada, and O'Caml) or to raise an
exception (the decision made by dynamically typed languages like Python and
Lisp.) Weakly typed languages (like C), on the other hand, don't have fully defined
behavior in the presence of mistyped programs.

Strong typing == fully defined behavior
Weak typing == not fully defined behavior

Static typing == type constraints enforced at compile time
Dynamic typing == type constraints enforced at runtime

It's important to realize the difference between "strong" and "strict" typing.
Nearly every high level language you'll use (Python, Lisp, Perl, O'Caml, Ada,
Haskell, etc.) is strongly typed. Python, Lisp, and Perl, though, are
dynamically typed, while O'Caml, Ada, and Haskell are strictly typed.

I'd try to detail the advantages/disadvantages of dynamic and static typing, but
I'm way too much an advocate of static typing to treat the issue in a fair and
unbiased manner :)

Jeremy
 
D

Deleted member 5324

Guest
Originally posted by dockeen:
Actually, a lot of the higher level support for arrays
do in fact come from Numpy. When I was first picking up Python, I remeber what a pain it was to do some of the things that I wanted to do through the regular Python methods. The Numpy stuff in a lot of ways looks like array functions from Matlab, which, again, learning in a screwy order, I learned after the fact.
Its actually sort of funny, a number of my Python books
kind of avoid serious discussion of arrays, but spend a
lot of time of lists. I guess my interests are less...
well..interesting.

Oh, you mean the higher level array/matrix stuff. I'm talking more about
Python's lists. As I'm sure you've noticed, most people aren't physicists, and
don't have much of a need for the higher level stuff you're doing with NumPy --
that's probably why your books mostly ignore it. Lists are far more commonly
used.

I know you can return a variety of data from a function,
I just thought it was a neat contrast in the clean way
you can return an array versus, say C++. Minimum knowlege
and intelligence needed, perfectly suited to an intellectually
challenged physicist.

Yeah, Python is very simple in that regard even when compared to other
high-level scripting languages like Perl. It's nice.

Jeremy
 

EgalitarianBovine

Ars Tribunus Angusticlavius
8,086
I found that I can pass an array to a function with no fuss
or muss. Just pass it, like any other variable. It appears
to pass by reference.

Interesting.

Wayne

Everything in python is passed by reference, including numbers, strings, and any other possible object.

Pass-by-value is simulated by making sure that the core types (int, string, long, tuple, etc.) are immutable (there are no valid methods to modify their internals).

-EB
 
D

Deleted member 5324

Guest
Originally posted by niyogi:
my understanding of python is that you can't distribute your applications in closed source (and therefore be commercially viable with it). I may be completely wrong about this but can somebody verify?

Is closed source required for commercial viability? A properly restrictive
license should be just as effective against protecting your code from abuse as
compiling your source code to native code would be.

That said, it's much more common to find Python used for in-house projects, open
source projects, or as a scripting language for a larger system than it is to
find pure-python commercial projects.

If you seriously need to hide some of the implementation details of a
commercial project, you can implement them in C as a compiled module.

Jeremy
 
my understanding of python is that you can't distribute your applications in closed source (and therefore be commercially viable with it). I may be completely wrong about this but can somebody verify?

Wrong.

There's a copy of Python 1.4 embedded in MS SiteServer 3.

From the Python site Copyright

The gist of it is that Python is absolutely free, even for commercial use (including resale). There is no GNU-like "copyleft" restriction.

A clarification: some very picky lawyers are worried that the notice doesn't explicitly grant permission to distribute modified copies (even though it grants permission to copy, modify, and distribute). This can be considered an oversight in the notice; we have no intention to limit distribution of modified copies (that otherwise play by the rules). Similarly, the words "without fee" are to be read connected to "permission": permission is granted without fee. We are in the process of revising the notice to clarify it, but this is a slow process.

Another clarification: the limitation of the copyright to 1991-1995 in the notice is not a mistake, but rather a deliberate decision. Copyright applies regardless of whether it is explicitly stated or not.

News: The Open Source Initiative board has voted to certify the Python license as Open Source.

And if you had to ask, yes, this license is compatible with the GPL (sez RMS).



--------------------------------------------------------------------------------

Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, The Netherlands.


All Rights Reserved
Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the names of Stichting Mathematisch Centrum or CWI or Corporation for National Research Initiatives or CNRI not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission.

q
 

dockeen

Ars Tribunus Militum
1,600
OK, so you're not saying there's something wrong with Cygwin's Python, just that there are better tools/environments/implementations out there. OK. Cool.

I believe that because, well, you saw my recommendation for VPython.
:). I don't even use the Cygwin version of Python because of it.

I only brought up Cygwin because I have run into people who use it regularly, but don't know that they have Perl and Python with it.

Wayne
 

dockeen

Ars Tribunus Militum
1,600
Biologist...hmmm...my Disseration, among other things, looked at the effects of radiation on single crystals of an analogue of a DNA base, 6MeMPR...work that I'm sure no-one has read except me and my Ph.D committee. I worked in the wrong kind (non-commercial) of magnetic resonance, Electron Spin Resonance...not even smart enough to work with protons...

;-)

So there is a biological connection in there some where...

Good to meet you,

Wayne
 
Status
Not open for further replies.