I’m kind of new with python and there is something troubling me. I’m using pandas to read an excel file. All works well if I have the excel in the same directory as my .py file. What I want to know is what is the best way to get a file that is in a completely different path. I’ve searched
Tag: import
Gtk.Spinner in Python GTK while importing large library
I have a GTK application in C that will spawn a Python GTK process to embed a matplotlib figure into a window in the C process using GtkSocket/GtkPlug (uses XEmbed Protocol). The problem I am having is that the import of the matplotlib library takes about 2.5 seconds and during that time the socket widget is simply transparent. I would
Is it possible to import a function from another script without importing the variables from such file?
I have two scripts 1 and 2, I would need these two script to work independently from one another, but I also need script 2 to be able to use the function in script 1 if needed. I tried to automate as much as possible, so each script has a number of variables inside already defined. Here is an oversimplified
How do i import a function from a file in a parent directory
I have a pycharm project with one python file called main.py on my desktop i have a folder called ‘Python’ inside it looks like this: In my main file i want to import a function from the framework file. for example if my framework file looks like this: how would i import the function into my main file? Answer in
How do you structure python code to avoid long import statements?
example directory structure and code: how would you go about removing the text [inside these square brackets] on the import statements? of course, doing this kind of structure will cause this to not be possible: Answer The simplest is to just use a relative import. For example in utils_one.py you can do You can also use .. to go up
Why cannot I import selenium?
Why can’t I import selenium? My text is looking like this in Visual Studio code: I have not always had this problem. The problem occurred after I switched to Windows 11 where the c-drive was deleted. Do someone out there know how to fix it? I’m using Windows 11. Answer Try C:> py -m ensurepip –upgrade If you install Python
os.rename() function is causing a FileNotFoundError
I was study the import os today, I working with a rename code. and it was error due to: So I was confused with the error cause I don’t know what am I doing wrong. This is the Folder I was working with: Answer Try this: Edit:
Cannot get an absolute import to work with python 3.7.0
I have a root folder called dumdum which contains an init and a folder called foo. Within foo are an ini and two modules, foo1 and foo6. I want foo6 to work when called on its own and when a main module in the root folder dumdum calls it, so I have been trying to work out how to get
How to access a dynamic variable of a Python script from another Python script?
So there’s two scripts: script1.py and script2.py. script1.py has a variable x that stores the string read from a file during runtime. In script2.py, I import script1.py and then run script1.py using the following: script1.main(). I then run a particular function in script1.py that is responsible for reading the file in question. You might wonder why I don’t just run
Python ImportError and ValueError in VSCode/pytest
This is what my project looks like (oversimplified): Whenever I run pytest standing in root/ I get ImportError : Attempted relative import with no known parent package. If I move test_code.py out to root/ everything works fine. But this is not an option since I have many modules and that is why I need to put ALL test modules inside