By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,571 Members | 949 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,571 IT Pros & Developers. It's quick & easy.

How to search for vector in list of input arguments

P: 3
Hi guys,

I am trying to write a module transfering from MATLAB. In order to avoid unnecessary errors, I do some input arguments checkings before processing. The user is allowed to put in only 3 arguments, that's why the last argument is a list instead of a fixed variable. Nevertheless, user has only 2 possibilities either he gives 3 or 4 inputs.

The point is I'd like to check if there is any vector in the list (last argument). How could I do this? Before when it was the fixed argument, I used "isvector(d)" but it is not possible to use this with a list then I get this error.

AttributeError: 'tuple' object has no attribute 'shape'

Expand|Select|Wrap|Line Numbers
  1. def check(a, b, c, *arg): 
  3. if len(arg) > 1:
  4.             raise TypeError ("Incorrect number of input arguments.")
  6. if not isvector(b) or not isvector(arg):
  7.             raise TypeError ("Transfer function must be specified by two vectors.") 
Could someone please provide me an advice how I could go around this problem?

Thank you very much in advance
Apr 12 '12 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 2.5K+
P: 2,851
You could write a separate function to check the contents of the list. Using isinstance instead of isvector and checking for a str:
Expand|Select|Wrap|Line Numbers
  1. >>> def isstrin(seq):
  2. ...     for item in seq:
  3. ...         if isinstance(item, str):
  4. ...             return True
  5. ...     return False
  6. ... 
  7. >>> seq = [1,2,3,4,['a', 'b', 'c']]
  8. >>> isstrin(seq)
  9. False
  10. >>> seq = [1,2,"this is a str",4,['a', 'b', 'c']]
  11. >>> isstrin(seq)
  12. True
  13. >>> 
Apr 12 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.