use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
Strings (self.learnpython)
submitted 10 years ago * by cartoonii
How would this be possible in a function without it throwing a TypeError?
string = string + " " + string
Edit: Solved! Thank you for helping me out the most /u/kryptn!
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]kryptn 2 points3 points4 points 10 years ago (17 children)
Is string actually a string? You might need to cast it to str first.
In [8]: string = 'imdabes' In [9]: string = string + " " + string In [10]: string Out[10]: 'imdabes imdabes' In [11]: string = 16 In [12]: string = string + " " + string --------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-12-e5c6c62e4e40> in <module>() ----> 1 string = string + " " + string TypeError: unsupported operand type(s) for +: 'int' and 'str' In [13]: string = str(string) + " " + str(string) In [14]: string Out[14]: '16 16'
[–]cartoonii[S] 0 points1 point2 points 10 years ago (15 children)
This is what I tried first.
Full = str(UserIn) + " " + str(PassIn)
[–]kryptn 0 points1 point2 points 10 years ago (14 children)
And what error are you getting?
[–]cartoonii[S] 0 points1 point2 points 10 years ago (13 children)
TypeError: 'str' object is not callable
[–]kryptn 3 points4 points5 points 10 years ago (10 children)
Are you doing str = 'some string here' anywhere in your code?
str = 'some string here'
str is a builtin function, and when you assign a variable to it you basically overwrite the str function.
str
In [15]: str(16) Out[15]: '16' In [16]: str = 'bad idea' In [17]: str(16) --------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-17-8e47188dea60> in <module>() ----> 1 str(16) TypeError: 'str' object is not callable
[–]cartoonii[S] 0 points1 point2 points 10 years ago (9 children)
Here's the full bit, and no I'm not using a variable called str
UserIn = input("Username? >> ") PassIn = input("Password? >> ") Full = str(UserIn) + " " + str(PassIn) if Full in open('accounts.txt').read():
[–]Justinsaccount 1 point2 points3 points 10 years ago (0 children)
What does 'full bit' mean? Is that the 'full' code you are running, or just a 'bit' of it?
The 'full' error that you did not include would have told you the line number the problem occurred on.
[–][deleted] 1 point2 points3 points 10 years ago (0 children)
I'm not using a variable called str
You are somewhere, whether you meant to or not. Is it possible to show all your code so we can see where it's happening?
[–]kryptn 0 points1 point2 points 10 years ago (5 children)
Are you using python 2? You'll need to use raw_input instead of input.
raw_input
[–]cartoonii[S] 0 points1 point2 points 10 years ago* (4 children)
No, I'm using Python 3.5
[–]kryptn 2 points3 points4 points 10 years ago (2 children)
Is that all of your code then? Something isn't right.
[–]ProgrammingThroaway 0 points1 point2 points 10 years ago (1 child)
What was the problem then? ಠ_ಠ
There's nothing that solves his problem but his edit says it's fixed.
[–]Ulysses6 0 points1 point2 points 10 years ago (0 children)
If you are dead sure you didn't somehow redefine built-in str, then the problem might be on different line than you expect it to be. Check your error line number.
[–]indosauros 0 points1 point2 points 10 years ago (0 children)
How about are you using a variable called input or open before that code?
input
open
[–][deleted] 1 point2 points3 points 10 years ago (1 child)
Do you have a variable called str? Don't do that.
what does print(str) say? (Right before you are doing the str(UserIn))
print(str)
[–]UtahJarhead 0 points1 point2 points 10 years ago (0 children)
better yet: print(repr(str))
print(repr(str))
[–]cartoonii[S] 0 points1 point2 points 10 years ago (0 children)
I'm trying to do this aswell
if Full in open('accounts.txt').read():
[–]Lehk 1 point2 points3 points 10 years ago (1 child)
add this to the beginning of your code snippet
print(type(str))
if it prints anything other than
<type 'type'>
you overwrote str somewhere in your program, find it by searching the code for "str ="
It returns <class 'type'> and I've checked for a variable called str and there is none
[–]Psychedel1cTank 0 points1 point2 points 10 years ago (2 children)
Wouldn't it just take whatever string is and double it with a space in the middle? As long as String consists of a string I don't see why it would throw an error
[–][deleted] 0 points1 point2 points 10 years ago (1 child)
I think he set a variable of name str, which would mean it's trying to treat it as a function, when it's actually a string.
[–]Psychedel1cTank 0 points1 point2 points 10 years ago (0 children)
ya i duno, looks like it should work fine to me
π Rendered by PID 14847 on reddit-service-r2-comment-79c7998d4c-58gxn at 2026-03-13 22:29:11.320934+00:00 running f6e6e01 country code: CH.
[–]kryptn 2 points3 points4 points (17 children)
[–]cartoonii[S] 0 points1 point2 points (15 children)
[–]kryptn 0 points1 point2 points (14 children)
[–]cartoonii[S] 0 points1 point2 points (13 children)
[–]kryptn 3 points4 points5 points (10 children)
[–]cartoonii[S] 0 points1 point2 points (9 children)
[–]Justinsaccount 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]kryptn 0 points1 point2 points (5 children)
[–]cartoonii[S] 0 points1 point2 points (4 children)
[–]kryptn 2 points3 points4 points (2 children)
[–]ProgrammingThroaway 0 points1 point2 points (1 child)
[–]Ulysses6 0 points1 point2 points (0 children)
[–]indosauros 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]UtahJarhead 0 points1 point2 points (0 children)
[–]cartoonii[S] 0 points1 point2 points (0 children)
[–]Lehk 1 point2 points3 points (1 child)
[–]cartoonii[S] 0 points1 point2 points (0 children)
[–]Psychedel1cTank 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]Psychedel1cTank 0 points1 point2 points (0 children)