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.
The str() function converts the specified value into a string.
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.
__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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With