The isinstance
built-in is the preferred way if you really must, but even better is to remember Python’s motto: “it’s easier to ask forgiveness than permission”!-) (It was actually Grace Murray Hopper’s favorite motto;-). I.e.:
def my_print(text, begin, end): "Print 'text' in UPPER between 'begin' and 'end' in lower" try: print begin.lower() + text.upper() + end.lower() except (AttributeError, TypeError): raise AssertionError('Input variables should be strings')
This, BTW, lets the function work just fine on Unicode strings — without any extra effort!-)
Related Posts:
- How can I time a code segment for testing performance with Pythons timeit?
- How do you change the size of figures drawn with Matplotlib?
- PermissionError: [Errno 13] Permission denied
- How to find if directory exists in Python
- What is setup.py?
- JSONDecodeError: Expecting value: line 1 column 1 (char 0)
- Cannot find module cv2 when using OpenCV
- What is the purpose and use of **kwargs? [duplicate]
- What does random.sample() method in python do?
- (Python) TypeError: ‘float’ object is not subscriptable
- ValueError: Unknown label type: ‘continuous’
- Transpose/Unzip Function (inverse of zip)?
- TypeError: unhashable type: ‘numpy.ndarray’
- python base64 to hex
- pygame.error: video system not initialized
- TypeError: ‘numpy.float64’ object is not callable
- ValueError: Length of values does not match length of index | Pandas DataFrame.unique()
- ‘str’ object has no attribute ‘decode’. Python 3 error?
- How to find all the indexes of a recurring item in a list?
- Is there a way to delete created variables, functions, etc from the memory of the interpreter?
- Code for Greatest Common Divisor in Python
- ‘DataFrame’ object has no attribute ‘sort’
- How to check Django version
- How to change the font size on a matplotlib plot
- How can I create a dropdown menu from a List in Tkinter?
- How to find all occurrences of a substring?
- Does “\d” in regex mean a digit?
- How do you use subprocess.check_output() in Python?
- filename.whl is not a supported wheel on this platform
- How to use torch.stack function
- (Help) TypeError: ‘str’ object cannot be interpreted as an integer
- ‘builtin_function_or_method’ object is not iterable
- Why KeyError: 0
- How do I change the figure size for a seaborn plot?
- How to use pyinstaller?
- Contains of HashSet
in Python - How to take column-slices of dataframe in pandas
- Python: Get the first character of the first string in a list?
- How to convert string to binary?
- Python error load JSON code of google API
- How do I find the duplicates in a list and create another list with them?
- Get ZeroDivisionError: float division in python
- How do I detect collision in pygame?
- ImportError: libSM.so.6: cannot open shared object file: No such file or directory
- explain arguments meaning in res = cv2.bitwise_and(img,img,mask = mask)
- How to normalize a 2-dimensional numpy array in python less verbose?
- Remove xticks in a matplotlib plot?
- “for line in…” results in UnicodeDecodeError: ‘utf-8’ codec can’t decode byte
- TypeError: string argument without an encoding
- ValueError: cannot index with vector containing NA / NaN values
- How to append multiple values to a list in Python
- How do I do a case-insensitive string comparison?
- How to copy files?
- Why does PyQt crashes without information? (exit code 0xC0000409)
- How can I check if character in a string is a letter? (Python)
- raise LinAlgError(“SVD did not converge”) LinAlgError: SVD did not converge in matplotlib pca determination
- How to multiply all integers inside list
- How can I get the named parameters from a URL using Flask?
- How can I from bs4 import BeautifulSoup?
- Pandas OR statement ending in series contains
- TypeError: Invalid dimensions for image data when plotting array with imshow()
- “getaddrinfo failed”, what does that mean?
- pythonw.exe or python.exe?
- How to convert an XML string to a dictionary?
- matplotlib does not show my drawings although I call pyplot.show()
- RuntimeWarning: overflow encountered in ubyte_scalars
- Pandas – Drop function error (label not contained in axis)
- Python Requests – No connection adapters
- WindowsError: [Error 126] The specified module could not be found
- No module named ‘openpyxl’ – Python 3.4 – Ubuntu
- How to easily print ascii-art text?
- Using Tkinter in python to edit the title bar
- Split string using a newline delimiter with Python
- Why am I getting ImportError: No module named pip ‘ right after installing pip?
- No module named urllib3
- How to convert index of a pandas dataframe into a column
- Python requests SSL error – certificate verify failed
- How to know/change current directory in Python shell?
- Trying to run Flask app gives “Address already in use”
- What is a unicode string?
- Remove specific characters from a string in Python
- pandas replace multiple values one column
- How can I make one python file run another? [duplicate]
- Error: No module named ‘fcntl’
- “Can’t convert ‘float’ object to str implicitly”
- Python can’t find file
- Plotting graphs in C++
- ‘MyClass’ object has no attribute ‘__getitem__’
- Can’t install Scipy through pip
- How to run python code in Sublime Text 3?
- Random word generator- Python
- How can I install the Beautiful Soup module on the Mac?
- What is python’s site-packages directory?
- How do I get Flask to run on port 80?
- optional arguments in initializer of python class
- How can I check if a string contains ANY letters from the alphabet?
- How do I calculate the MD5 checksum of a file in Python?
- Does Python have an immutable list?
- __init__() got an unexpected keyword argument ‘user’
- Create dynamic URLs in Flask with url_for()