I have the following folder structure.
check_site
- test_site
-- views.py
- app2
- app3
- modules
-- url.py
-- usability.py
module ulr.py contains one class inside - Url.py
class URL:
...
module usability.py contains one class that inherit URL class
from url import URL
class Usability(URL):
...
And then I have a view.py where I neen to import class Usability
from modules.url import URL
from modules.usability import Usability
And here is a problem. It gives me an error
from url import URL
ModuleNotFoundError: No module named 'url'
I've tried to change the import in usability.py to
from modules.url import URL but in this case it gives the error in the usability.py
Unable to import modules.url
I've also tried
from .url import URL and from check_site.modules.url import URL But these also don't work
If someone knows how to fix it, please help
Well, the problem lies here because by default Python searches for the file in the current directory but the file u want to import is not in the same directory as your program.
You should try sys.path
# some_file.py
import sys
# insert at 1, 0 is the script path (or '' in REPL)
sys.path.insert(1, '/path/to/application/app/folder')
import file
This should work in most cases.
from django.template.base import TagHelperNode, VariableNode
ImportError: cannot import name TagHelperNode
I had upgrade Django from 1.8.14 to 1.11.17
It should be:
from django.template.library import TagHelperNode
Reference can be found here.
I am importing some views to the urls.py file, here is what I have
from views.home import HomeView
from views.list_player import PlayerList
from views.list_game import GameList
from views.create_player import PlayerCreate
from views.create_game import GameCreate
from views.detail_player import PlayerDetail
from views.detail_game import GameDetail
from views.update_player import PlayerUpdate
from views.update_game import GameUpdate
from views.delete_player import PlayerDelete
from views.delete_game import GameDelete
However, is there a way to import them like this?
from .views import(
Home,
GameList,
PlayerList,
PlayerDetail,
GameDetail,
PlayerCreate,
GameCreate,
PlayerUpdate,
PlayerDelete,
GameUpdate,
GameDelete
)
which looks much more cleaner.
The statements are functionally equivalent.
From http://legacy.python.org/dev/peps/pep-0328/, the use of parentheses was approved for enclosing long lists of imports in a pythonic way, for Tkinter:
from Tkinter import (Tk, Frame, Button, Entry, Canvas, Text,
LEFT, DISABLED, NORMAL, RIDGE, END)
It seems that parentheses were added for the second statement because the import list was too long.
However, you see you have varied package imports from different folders of the package. So I guess due to the intermediate folders like home, list_player, list_game you won't be able to do direct imports. So the best way I can see is doing this:
from .views import (
home,
list_player,
list_game,
create_player,
create_game,
...
)
:D
it easier to import like this:
from <appname> import views #in urls.py
and inside url patterns you can use:
path(<regex>, views.<viewname>) #url patterns
Hello I've followed these steps:
on my code folder
pip install recurly
Create code:
import recurly
from recurly import Account
recurly.SUBDOMAIN = 'mi-domain'
recurly.API_KEY = 'abdcdddd1d7445fba86b5ca35eef00d5'
recurly.DEFAULT_CURRENCY = 'USD'
account = Account.get('id45')
account.delete()
and when I try to execute code above
I get
ImportError: cannot import name Account
Why is it that imports recurly with no problem but cannot import resources?
You'll have to call recurly.Account.get('id45') to get the account you'd like. You can find an example with correct syntax here: https://github.com/recurly/recurly-js-examples/blob/master/api/python/app.py#L70
i want to publish an update on bufferapp.com with python.
I installed the python buffer modul: https://github.com/bufferapp/buffer-python
I managed to connect to their api with python3.
But if i use the update.publish() command it gives me the following error:
nameerror: "update" is not defined.
Im using this code:
from pprint import pprint as pp
from colorama import Fore
from buffpy.models.update import Update
from buffpy.managers.profiles import Profiles
from buffpy.managers.updates import Updates
from buffpy.api import API
token = 'awesome_token'
api = API(client_id='client_id',
client_secret='client_secret',
access_token=token)
# publish now
update.publish()
What am i doing wrong?
Thank you for your help.