[Tutor] a code question, but don't know question's name

Kent Johnson kent37 at tds.net
Sun Oct 7 22:25:47 CEST 2007


Happy Deer wrote:
> I am writing a function getdata for other people, and I want others can 
> use the function as follows.
> 
> var1,var2, var3=getdata(..., ['var1','var2','var3'],...)

There is no need to pass the variable names to getdata.

Have you read any Python tutorials? There are several good ones listed here:
http://wiki.python.org/moin/BeginnersGuide/NonProgrammers

> If I can not return data column by column, I can not get the above, right?

You can just return the columns:

def getdata(data):
   return data[:,0], data[:,1], data[:,2]

Kent
> 
> On 10/7/07, *Eric Brunson* <brunson at brunson.com 
> <mailto:brunson at brunson.com>> wrote:
> 
>     Happy Deer wrote:
>      > Thank all for the discussion.
>      > Maybe I can separate my question into two.
>      >
>      > First, I have experience in Matlab, where I can use "eval". I wonder
>      > whether someone knows about it.
>      >
>      > Second, if I just want to return data[:,1], ...data[:,-1] separately
>      > without knowing ahead how many columns data has. What should I do?
> 
>     I'm still unsure if you even need extended slicing.
> 
>     Given:
> 
>     data = [ 1, 2, 3, 4, 5, 6 ]
> 
>     What do you expect data[:,1] and data[:,-1] to return?
> 
> 
>      >
>      >
>      >
>      > On 10/7/07, *Kent Johnson* <kent37 at tds.net
>     <mailto:kent37 at tds.net> <mailto:kent37 at tds.net <mailto:kent37 at tds.net>>>
>      > wrote:
>      >
>      >     Kent Johnson wrote:
>      >     > Alan Gauld wrote:
>      >     >> "Kent Johnson" < kent37 at tds.net <mailto:kent37 at tds.net>
>     <mailto:kent37 at tds.net <mailto:kent37 at tds.net>>> wrote
>      >     >>
>      >     >>>> The notation data[;,0] doesn't make sense and is an error in
>      >     >>>> Python.
>      >     >>> [:,0] is an extended slice, not an error:
>      >     >>> http://docs.python.org/ref/slicings.html
>      >
>      >     We discussed this quite a bit last July:
>      >     http://mail.python.org/pipermail/tutor/2007-July/055814.html
>      >
>      >     Kent
>      >     _______________________________________________
>      >     Tutor maillist  -   Tutor at python.org
>     <mailto:Tutor at python.org> <mailto:Tutor at python.org
>     <mailto:Tutor at python.org>>
>      >     http://mail.python.org/mailman/listinfo/tutor
>      >
>      >
>      >
>     ------------------------------------------------------------------------
>      >
>      > _______________________________________________
>      > Tutor maillist  -   Tutor at python.org <mailto:Tutor at python.org>
>      > http://mail.python.org/mailman/listinfo/tutor
>      >
> 
> 



More information about the Tutor mailing list