Import a python file into another python file on pythonanywhere - pythonanywhere

I am trying to built a web app on pythonanywhere.
I have a file abc.py and another file xyz.py . In the file xyz.py I want to use a function of abc.py so how do I import abc.py into xyz.py given that they are in the same directory. What will be the import statement? I was trying:
import "absolute/path/to/the/file.py" which didnt work.
Also did
from . import abc.py in xyz.py which also didnt work

PythonAnywhere dev here: if they're in the same directory, then you need to use
from abc import functionname
This part of the official Python tutorial explains how import works.

Related

how to import local package files in my main package?

I want to import the about.dart file in my main.dart file. But it is showing error while I'm copying its path. I tried many ways to import it, but all fails. Can anyone please help me in this?
if both the files are in the same folder you can import them using this line
import './dialpad.dart';
if you want to import the file from a folder at the same level of the file in which you want to import you can use this line
import '../widgets/some_file.dart';
To use your local package you have to define package and give a package path inside your pubspec.yaml for the package.
To add local package in pubspec.yaml:
sip_up-0.5.6:
path: ./sip_up-0.5.6

import function from another file in colab not working

I am trying to import a function from another file different directory in Colab, but it's not working.
I have tried:
1)
!pip install kora -q
from kora import drive
drive.link_nbs()
sys.path(0,"path to file")
import name_file
import ipynb

ModuleNotFoundError: No module named 'myfile.py'

So I have trawled through other very similar issues and tried many variations but I cannot get this to work.
I have created code in a separate file under the following structure:
/somefolder/ #this is where my main code resides
/somefolder/src/ this is where my myfile.py resides that I want to import.
My main code starts as follows:
import os.path
import sys
sys.path.append(os.path.join(os.path.dirname(__file__), '../src'))
import myfile as mine
but then I get teh following error:
ModuleNotFoundError: No module named 'myfile'
Any assistance would be very welcome.
Assuming your current directory is PythonApplication1, you can follow these steps to access myfile module.
create __init__.py file in both PythonApplication1 and
PythonApplication1\src directories
Now import myfile as from src import myfile as mine

ImportError: when importing from a local script library

Does importing from a local script lib work in qpython3?
I have a script I created in the Qpython projects3 directory of qpython.
projects3/MPU6502/
I have my main code here in this directory.
main.py
I have a local subdirectory,
projects3/MPU6502/tiny6502lib/
In this sub directory I have the source code,
RAM_8bit_Memory.py
From my main.py source code I load the library,
#-*-coding:utf8;-*-
#qpy:3
#qpy:console
# import 6502 library module
from tiny6502lib.RAM_8bit_Memory import *
when I execute the library import I get the ERRORL:
"ImportError: No module named tiny6502lib.RAM_8bit_Memory"
Is importing local script libraries broken in qpython3?
org.qpython.py/projects/MPU6502/main.py
org.qpython.py/projects/MPU6502/tiny6502lib/RAM_8bit_Memory.py
This code works perfectly on all other flavors of python3 (windows) and pythonista on ipad.
How do I get this import to work? Or does it not work at all?
thank you,
Just try to insert the following code before importing tiny6502lib.RAM_8bit_Memory
import sys
sys.path.append("/sdcard/qpython/projects3/MPU6502")
?

How to import all imports of another .py file

Info
python version: 3
development environment: eclipse luna
Goal
I'm currently developing an addon system for a program. My Idea was to create a file where I import all addons. This file is generated during the addon instalation process (when you click the button: install addon). It looks like that:
import testaddon1
import testaddon2
import bigaddon.startup as bigaddon
When I start my programm I want to import all files/modules to read some properties and automaticly implement the addons in my program.
Question
How can I start import statements that are written in a different file.
file1.py
def test():
print('test')
file2.py
import file1.py.test as test
file3.py
#run the import commands from file2.py
test()
console output after running file3.py:
test
What I want
an answer on how to achieve the previous result
a different idea on how to create an addon system
Yes you can do it.
file.py
def hello():
print('hello')
file2.py
import file
file.hello()
file3.py
from file2 import *
file.hello()
executing file 3. greg#ja python file3.py