#๐ Import error
104 messages ยท Page 1 of 1 (latest)
@stone moon
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
hello!
Hii
Any reason you can't run discord on your PC and just copy and paste the code?
work with what youve got
Dont know my login sadly
thats not constructive
Its fine dw ๐ญ
But keyMaps isnt being recognised
The functions code works when its in the main code file
So it is purely an importing issue
you don't know your email login? to reset password
hmm
Its an old account and im not on my own pc rn
try doing from keyThingy import keyMaps
its very weird, the only thing i can think of is that its not recognising it as a function
Its recognising it as a function, just isnt importing it
it's because you have a circular import (I believe)
Cant you do that?
ohhhhhh!
Omg that was it
Wait it works without needing the Info class??
Or is it just using the Info class because its called in the main code file
i mean, keysThingy was pretty useless, it could just have been a function
new modules are for enclosed things that only return stuff and stuff
I'm assuming you haven't ran the function yet
Its gonna be a full list of keys
running it will give you a NameError
dont do import *, only import what you need and dont import the function you ran it in
Dont want them cluttering the main file
if you get circular imports, then you need factor out the dependency to another module, so you can import it separately, or put it all in one
Ohhh i see
Understood ๐ซก
Enter key works ๐
Tysm
any import statement runs the whole file that you are importing (but, the code inside the function is not ran until called, same as having the function defined in the file that it is used in)
I was thinking that
The only reason you wouldnt want to import all of it would be name clashes, right?
it makes it unclear what names are available as well
Mhm
either:
import mod
to namespace it, or:
from mod import a, b, c
But yeah this has been running me ragged for the last hour ๐ญ tysm
@lament mortar while youre here can i ask you a question?
ok
I was thinking of just doing an if statement for every individual key when typing
Is there a more efficient way to do that with pygame?
I don't know what you're looking to do
Without using the inbuilt text input, im trying to make a text editor from scratch
how does the code inside the if-statements differ?
Take keyboard inputs
Put whatever character i pressed into the editor
The character im adding to the text editor
that doesn't really answer my question
Itd be something like:
if key == pygame.K_a:
Put an a on the screen
If key == pygame.K_b:
Put a b on the screen
Im sorry ig i js dont fully understand
ok so, how you draw differs
you could define 52ish functions for each letter
then map those functions using a dict to the letters
heh, coulda just used python -m your_filename
there should be some attribute or method which tells you the name of the key from the event, as a string
it resolves like 99% of import issues for me
Wha dat
runs your python file as a module
Pretty sure its just a list of bools
Depending of if the key is pressed or not
that doesn't fix circular import issues
As in the main file?
Yeah that wouldntve fixed the issue
fixes them for me
if the situation gets desperate I end up modifying pythonpath
I feel like you don't understand what a circular import is
module a imports something from module b and vice versa at the same time
From what ive learnt today, i dont think so
i might be wrong
where the files are and how they can be found doesn't change the issues you get with that
so it may just be my machine lol
I swear it just makes all import related errors vanish
circular imports are possible, but they make for confusing code
it's obvious
I did it because i didnt know the imported function could access classes from the main file
well, your function doesn't do that
you have an argument called Info
Yeah that was one of my debugging attempts lol
Initially, thats what i thought
it can't do that
Mhm yeah i get that now
here's a test to see how a circular imports runs.
# a.py
print("a1")
import b
print("a2")
x = 1
print("a3", x)
# b.py
print("b1")
import a
print("b2", a.x)
a.x = 2
print("b3", a.x)
If you have both files, and run a.py, you get this
a1
b1
a1
a2
a3 1
b2 1
b3 2
a2
a3 1
Wait importing just runs the code from the file?
and here's labels for which import they are running at
a1 # original run of `a.py`
b1 # `import b` from a
a1 # `import a` from b
# skip over `import b`
a2 # continue with `import a` from b
a3 1 # finish `import a` from b
b2 1 # continue `import b` from a
b3 2 # finish `import b` from a
a2 # continue original run of `a.py`
a3 1 # finish original run of `a.py`
Omg like a year ago i used to convert my code files to text files and use exec() on them ๐ญ๐ญ
yeah
and then you get a module object which has the variables as attributes
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.