Skip to content
Sign upLog in
← Back to Community
Is it possible to use open() and use the functions in a python file?
Profile icon
BraylanBB121

I tried to make a chatroom, not live of course, but I tried using the open('file.py', 'r') function to use the functions defined in the other file. But it gave me an error. I don't know how to use functions defined in other files. I know I asked a similar question, but I want to know if I can do it with the open() function.

Answered by PYer [earned 5 cycles]
View Answer
Voters
Profile icon
sylashur
Profile icon
Codemonkey51
Profile icon
BraylanBB121
Comments
hotnewtop
Profile icon
Codemonkey51

You want to use import function instead of opening the file

Profile icon
BraylanBB121

I tried, and it said there was an AttributeError because the module function didn't have an attribute setup_chat() and then I tried to take the function.setup_chat() and replace it with setup_chat() but that didn't work either.

@Codemonkey51

Profile icon
PYer

yeah

@BraylanBB121
. Repl.it is having some problems with custom module importing.

Profile icon
sylashur

@PYer
Alright good to hear because I thought I was wrong when I read
@Codemonkey51
's comment and agreed with it. I've also had some codes that work oddly in other ways too, what are the main functions that you've seen that cause repl to do something wrong?

Profile icon
PYer

@sylashur
Anything involving importing from another module. I have to write the code directly in my main.py file for me to be able to use the functions.

Profile icon
sylashur

@PYer
Ah okay, a code of mine, https://repl.it/@sylashur/Just-Colored-Lines, decides it doesn't want to work if it does too much without updating the screen, the same happens with a lot of my other codes too, I'm fairly certain that this isn't just a computing power issue too, as I've left that code on for a while once.

Profile icon
PYer

yeah

@sylashur
. Maybe file a bug report?

Profile icon
sylashur

@PYer
Alright, I guess it would constitute as a bug. Thanks for the advice.

Profile icon
PYer
Profile icon
BraylanBB121

Thank you

@PYer
I appreciate the help. I guess I will have to wait until replit fixes that. I need ideas though on what to code... maybe you could suggest any?

Profile icon
BraylanBB121

Just asking though, am I supposed to call the function like this: file.function(parameter) or like this: function(parameter)

@PYer

Profile icon
Codemonkey51

Hrmm a python bot I built fully around custom modules is working on repl

@PYer

Profile icon
PYer

the first, unless you import the function directley from the module.

@BraylanBB121

Profile icon
PYer

same,

@Codemonkey51
, it seems to work for only certain things. For example, it seems to work if it is a fully developed package with an __init__.py

Profile icon
Codemonkey51

Mine worked with non fully developed packages

@PYer

Profile icon
PYer

Really? Do you have explorer mode enabled or something?

@Codemonkey51

Profile icon
koage

GAME HACKER