Picture of Code
If you look at my code you can see I am trying to use my created function, send(message), to send a message. However, I am unsure how to import my file, which you can see on the left, SMSpy. Can anyone tell me how I can properly import my file, Thanks!
If SMSpy has a class use
One time call:
Call it once with an instant object created.
import SMSpy
SMSPy.<classname>().send()
Multiple Calls:
Create an object and call
import SMSpy
Obj = SMSPy.<classname>()
Obj.send()
If no class:
import SMSpy
SMSpy.send()
Related
I'm using Python inside Pycharm, and wanting to scheduling code to run to open a workbook and save every day at a specified time. The function I've written to open and save the workbook has been working properly, but I'm now running in to two issues.
I cannot Import time, it's greying out and I'm not sure why
I'm receiving error "AttributeError: 'function' object has no attribute 'day'", and I'm not sure why. error occurs at ".day" within schedule function
import schedule
import time
def Date_Table():
from openpyxl import load_workbook
wb = load_workbook(r'file path')
wb.save(r'file path')
schedule.every.day.at("1:00").do(Date_Table)
I reviewed the functions in the "schedule" package. You just need to correct some syntax. Instead of:
schedule.every.day.at("1:00").do(Date_Table)
you probably want:
schedule.every().day.at("01:00").do(Date_Table)
Note the parentheses in the function call.
Hope that helps.
Regards.
I'm trying to import the User class from a file called gui.py into another called snake.py. I want to import the class so that I can use ,a method within the class and an instance of the class called current_user. But when I do:
from gui import User
It imports everything from gui.py. Does anyone know where I've gone wrong and what I can do to fix this?
I'm new to working with multiple files in Python and this is quite confusing to me.
The files for this are available at:
https://github.com/VladRadoi08/Snake-LoginUI
Thanks!
Anything in the file you import will be run. To prevent this, try putting all the code you don't want to run within this conditional:
if __name__ == "__main__":
That will ensure it only runs if you actually run the python file instead of importing it.
I need to import a function classify(par1, par2, par3)
from a module called _Y03_Labeling. Importing does work, but using its functions with more than one extra parameter doesnt work.
Question : How can I import functions with more than one Parameter?
.
What I already tried ( Without Success):
I successfully can run the whole notebook2 from notebook1 with the following code:
import _Y03_Labeling
Labeling =_Y03_Labeling
(Why I know if it is successful? Because its comments are printed out). Whenever I try to run:
X,y = classify(a,b,c)
I get the following error: "TypeError: 'module' object is not callable"
I tried many variations from the import line, including:
import _Y03_Labeling
Labeling =_Y03_Labeling
X,y = Labeling.classify(a,b,c)
# or:
from _Y03_Labeling import classify
# or:
import _Y03_Labeling
X,y = _Y03_Labeling .classify(a,b,c)
Sadly none of them worked for me.
Things i also did so far:
shutting down the _Y03_Labeling notebook before I run the main Notebook
putting the function in the second notebook into a class, importing the class from the notebook and calling the function. (works only if function needs 1 parameter)
also i didnt forgot "self" i the function declaration with the class try.
I am glad, this forum exists and thankful for every possible help.
Sorry for the very silly question. I am a self-study beginner in python and I am having issues with using a function and calling it. I am coming from a MATLAB background so i was trying to do something similar.
Tools used: Python 2 in a Linux environment
As a test, I created a function that i called prthis (for "print this") within a file called also prthis.py. This function just takes a number as an input, and then outputs two numbers, respectively the same one and its square. I defined it like this:
#----------------------------------------
# content of the file prthis.py
#----------------------------------------
def prthis(x):
y=x*x
nb=x
return (y, nb)
#------------------------------------------
then, within the python prompt, I try to call the newly created prthis function, and I do this:
>>> import prthis
>>> g,t = prthis(7)
The import seems to be succesful, but when I try the function on two outputs variable called g and t , like above, i get the following error message:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'module' object is not callable
Perhaps I am too much MATLAB-izing my thinking. Does anyone has a suggestion on how to deal with this?
PS: it's my first question ever on stackexchange, so please could you let me know how to thank/accept valuable answers from other users? I do not wish to look like ungrateful to those who would try to help.
you are importing a module, not the function. If you want to import just the function you could do this:
from prthis import prthis
g,t = prthis(7)
but if you import the full module you have to define the module you are calling the function from as well:
import prthis
g,t = prthis.prthis(7)
you are successfully able to import prthis but this is not the correct way either you should try "from prthis import prthis. Refer this for a better understanding of calling a function.
What does it mean to "call" a function in Python?
Importing inside the function, Python is not able to import this. Outside the function, it works fine. This is actually a Django server and view_page function gets called from outside the file.
So, basically doing this throws up an error "Error : No module named plotting"
My code:
def view_page():
from bokeh.plotting import figure # This throws up an error
pass
This works absolutely fine;
from bokeh.plotting import figure
def view_page():
pass