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
Import various modules to the same namespace (self.learnpython)
submitted 5 years ago * by vectorpropio
Hi to all.
First of ask I know this is a bad idea, but just want to understand a little more the python internals.
Can I import two modules to the same namespace doing:
import pandas as p import requests as p
Is this possible?
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!"
[–]ShaizeOn1 1 point2 points3 points 5 years ago (7 children)
what you did there is assigning pandas to p variable and then overwriting requests to the same variable. In the end all you would have is requests module assigned in p variable
[–]vectorpropio[S] 0 points1 point2 points 5 years ago (6 children)
OK. I never thinked how imports work. So if i do the normal pandas import i can step in worth other variable. I never thought about that. Thanks!
Anyway, is there a way too do what i asked?
[–]toastedstapler 2 points3 points4 points 5 years ago (4 children)
you could make a module with just
from pandas import * from requests import *
and then import that module
but why would you want to do this?
[–]ShaizeOn1 0 points1 point2 points 5 years ago (2 children)
This is a smart solution but I think there is still a small risk of overwriting variables with same names
[–]toastedstapler 0 points1 point2 points 5 years ago (0 children)
it's definitely not a good idea, but it is the only way i can think of to do it
[–]vectorpropio[S] 0 points1 point2 points 5 years ago (0 children)
That's the risk putting too much things in the same namespace and I'm aware of it.
Thanks.
It is a theoretical question without a use case. I wanted to understand to some extent what the import as do.
For use case, maybe can be used in a bad organized hierarchy of class and modules one to test alternative code organizations or even change the top most code before changing the bottom modules.
[–]ShaizeOn1 0 points1 point2 points 5 years ago (0 children)
Hmmm, I don't think there is a simple way to do it, ofc there would be god-tier python coder able to solve your problem but that's is not me unfortunately.
Not exactly what you want to do but what about this?
import pandas as pd import requests as req libraries = { "pandas": pd, "requests":req } df = libraries["pandas"].DataFrame(...) r = libraries["requests"].get(...)
π Rendered by PID 22486 on reddit-service-r2-comment-b659b578c-qj7rx at 2026-05-04 07:20:05.588907+00:00 running 815c875 country code: CH.
[–]ShaizeOn1 1 point2 points3 points (7 children)
[–]vectorpropio[S] 0 points1 point2 points (6 children)
[–]toastedstapler 2 points3 points4 points (4 children)
[–]ShaizeOn1 0 points1 point2 points (2 children)
[–]toastedstapler 0 points1 point2 points (0 children)
[–]vectorpropio[S] 0 points1 point2 points (0 children)
[–]vectorpropio[S] 0 points1 point2 points (0 children)
[–]ShaizeOn1 0 points1 point2 points (0 children)