473,387 Members | 1,303 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to search for vector in list of input arguments

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): 
  2.  
  3. if len(arg) > 1:
  4.             raise TypeError ("Incorrect number of input arguments.")
  5.  
  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
Regards
Apr 12 '12 #1
1 1622
bvdet
2,851 Expert Mod 2GB
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

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

Similar topics

4
by: al | last post by:
When should pick vector, over list or deque to use? Thanks!
9
by: fudmore | last post by:
Hello Everybody. I have a Segmentation fault problem. The code section at the bottom keeps throwing a Segmentation fault when it enters the IF block for the second time. const int...
7
by: MM | last post by:
Hi there, How can I change my code (below) so that I use an "input argument" to specify the file name of the input file? For example, if I compile the code and that the application then gets the...
3
by: Popoxinhxan | last post by:
Hi guys, I would like to have a search function that able to locate specific item in the list view but i don't know which api or methods to do so. The search function similar to the F5 search in...
2
by: George | last post by:
Using VS.NET 2002\Web Form\VB I have a dropdown list that will contain letters of the alphabet. At startup, it has only the letter A in the list. I add letters to the items list, as needed....
1
by: jojowebdev | last post by:
I have been TRYING for a few days to get a *working* search of a select list (about 800 options in list). I have not found one that works for IE6. Here is what I *last* tried. I would appreciate...
2
by: Kaur | last post by:
Hi, I have developed an application in MS Access 2000 where I am trying to highlight a record in the list box in form 2 based on the record selected in form 1. The form 1 lists all the Document...
6
by: Amit Bhatia | last post by:
Hi, I am not sure if this belongs to this group. Anyway, my question is as follows: I have a list (STL list) whose elements are pairs of integers (STL pairs, say objects of class T). When I create...
9
by: Rick | last post by:
I have a large list of objects where each object has a unique (non-overlapping) date range. The list is sorted chronologically. What is the most efficient way to search this list for a single...
0
by: zzapper | last post by:
Hi, I 've just learnt how to configure this go to http://uk2.php.net/ (or whatever) place your mouse cursor in the "Search For" Input Box Right Mouse Click and select "Create Search" Enter...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.