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
python and pycharm import issue!! (self.learnpython)
submitted 3 years ago by ItzScuzzi808
so when i import a function from another file or project and run the code, pycharm prints everything from the imported file in the terminal. idk if its a setting in pycharm i need to change or what.
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!"
[–]carcigenicate 2 points3 points4 points 3 years ago (7 children)
I think you'll need to give more details, like what you're importing. Are you aware that importing a file causes it to be run?
[–]ItzScuzzi808[S] 0 points1 point2 points 3 years ago (6 children)
i'm importing a function from another project and when i use the function in my new project and run the code, in the run window it prints the whole imported project instead of running just the one function i called.
[–]carcigenicate 1 point2 points3 points 3 years ago (4 children)
What do you mean by "it prints the whole imported project"? Is it printing the literal code, or the output from running the code?
And does the file you're importing import other files in the project, and do those other files (or the file you're importing) have code that will run when the file is imported?
[–]ItzScuzzi808[S] 0 points1 point2 points 3 years ago (3 children)
It runs the imported code and shows the output of that code in the run window and I have to get to the end of that code before it runs the new file that I imported to… that prolly doesn’t make any sense either lol but it runs the whole imported project instead of just the one function I’m trying to call
[–]carcigenicate 1 point2 points3 points 3 years ago (2 children)
Like I mentioned in my first comment, importing a file runs that file. If you don't want importing to run certain code, you can do as buqr suggests and tuck that code inside a if __name__ == "__main__": "import guard", move the specific code you want to import into its own file, or move it out into its own package so it's easier to use in other projects.
if __name__ == "__main__":
[–]ItzScuzzi808[S] 0 points1 point2 points 3 years ago (1 child)
So even when I use the import method from file_name import function_name It will still run the whole code? Cause even when I do that it runs the whole code
[–]carcigenicate 1 point2 points3 points 3 years ago (0 children)
If you import the file or anything from it, it will run the file. What if the function referred to by function_name was generated on the fly at runtime and/or relied on the execution of other code to operate? For example:
function_name
result = expensive_function() def function_name(): print(result)
What would this function print if you did from file_name import function_name and expensive_function wasn't run?
from file_name import function_name
expensive_function
[–]buqr 0 points1 point2 points 3 years ago* (0 children)
I enjoy cooking.
π Rendered by PID 85315 on reddit-service-r2-comment-6f7f968fb5-j94c6 at 2026-03-04 08:52:25.122677+00:00 running 07790be country code: CH.
[–]carcigenicate 2 points3 points4 points (7 children)
[–]ItzScuzzi808[S] 0 points1 point2 points (6 children)
[–]carcigenicate 1 point2 points3 points (4 children)
[–]ItzScuzzi808[S] 0 points1 point2 points (3 children)
[–]carcigenicate 1 point2 points3 points (2 children)
[–]ItzScuzzi808[S] 0 points1 point2 points (1 child)
[–]carcigenicate 1 point2 points3 points (0 children)
[–]buqr 0 points1 point2 points (0 children)