Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between {str} and {str_} in Python

Tags:

python

string

I am trying to debug a code in Python. When I go to debug mode and look at the variable word in a similar code that works fine, I see the type of this variable is shown as {str}, but in the other code that does not work correctly I see the type of word in the debugger is shown as {str_}. What is the difference between these and how can I convert a variable type {str_} to a type {str}.

Here is part of the code:

cv = CountVectorizer(min_df=1, charset_error="ignore", stop_words="english", max_features=200)
counts = cv.fit_transform([text]).toarray().ravel()
words = np.array(cv.get_feature_names())
...
for word, count in zip(words, counts):

I use PyCharm to debug, and it is in Python 3.3.

I appreciate any help on this.

like image 321
TJ1 Avatar asked Dec 10 '13 05:12

TJ1


People also ask

What is the use of str () in python?

The str() function converts the specified value into a string.

What is the difference between STR and repr in python?

Now if you go by the official python documentation – the __str__ is used to find the “informal”(readable) string representation of an object whereas __repr__ is used to find the “official” string representation of an object.

What is the purpose of defining the functions __ str __ and __ repr __ within a class how are the two functions different?

__str__ is used in to show a string representation of your object to be read easily by others. __repr__ is used to show a string representation of the object.


1 Answers

str is probably the builtin str. str_ is something else. Perhaps a subclass of str? Hard to tell without seeing more

Edit:

Looks like str_ may be numpy.str_ which is what you'll get if you pour a list of str into a numpy array

like image 146
John La Rooy Avatar answered Sep 28 '22 15:09

John La Rooy