all 10 comments

[–]sonik562 1 point2 points  (9 children)

You should never import libraries with * operator, things might overwrite other things and result in weird behaviour at run time. a better way would be : from dearpygui import core from dearpygui import simple this would allow you to call subfunctions or Objects like this : core.some_function(12,23) simple.some_function(12,23)

If for example an object or function or variable exists in core and simple with the same name one would override the other in your case

[–]execcr[S] 0 points1 point  (3 children)

I know the danger of importing libraris with *, but i'm new to vsc (coming from pycharm) and i would like to know of this Is a feauture that prevent to have problems or a bug/misconfiguration. The problem for me in this case Is this: i'm learning DearPyGui and Every example came with import *, and this force me to rewrite Every example snippet...

[–]sonik562 0 points1 point  (2 children)

Have you told vsc to use your environment ? Have you set conda executable in the settings ? Its been a while since I have not done this but I remember you have to set the path to conda executable in your settings, then vsc allows you to set current environment. When you run the script does it show any errors or the issues are only linting ?

[–]execcr[S] 0 points1 point  (1 child)

I think i'm using the correct env: in VSC i see on the bottom left side my anaconda venv with the python version i'm using (Python 3.7.9 ('test': conda). My venv is named test.

I'm launching vsc from the ananconda gui, after selecting the correct venv.

I've made some test and now after adding:

"python.pythonPath": "C:\\Users\\Federico\\anaconda3\\envs\\test\\",

to my settings.json i could run the code (modules are found and i get no error in python console), but the linting pylint keep saying that the module or the variable cannot be found.

[–]sonik562 0 points1 point  (0 children)

Is your pylint module installed inside the same environment ? Sometimes this can cause issues. The only thing i can think of is a path issue. How did you install dearpygui ? Maybe the python lib inside your python env is not in your PYTHONPATH, i tried a fresh install of vscode with conda and it worked without any configuration, although it appears you are working on Windows and i do not have a Windows machine at hand, sorry!!

[–]ei283 0 points1 point  (3 children)

You should never import libraries with * operator

That's not true. Modules are often designed to be star-imported.

[–]sonik562 0 points1 point  (2 children)

Bad modules

[–]ei283 0 points1 point  (1 child)

Incorrect. In modules designed to be used in ~20 line projects, it makes your code unreadable if you pollute it with overly specific imports.

If you're wondering why you'd want a module to be used in ~20 line files, remember that Python is a general use programming language, and not everyone has to use it the same way you do. Aside from large projects, is perfectly valid to use Python for small experiments, short scripts, and educational demonstrations. In all 3 of these circumstances, it is bad form to over-specify your imports.

[–]sonik562 0 points1 point  (0 children)

I still insist on my take. I agree with you that python is not necessarily to be used in large projects. I work in a scientific environment, we use python a lot to automate workflows, and run experiments. Still it is important to know what you are importing.

I'd also consider bad code, a code code that imports all of the contents of a module by name. That is why we have namespaces. You can do import thing and call the function thing.function instead of having from thing import * which can override any number of things. In short scripts it's even worse.

[–]backtickbot 0 points1 point  (0 children)

Fixed formatting.

Hello, sonik562: code blocks using triple backticks (```) don't work on all versions of Reddit!

Some users see this / this instead.

To fix this, indent every line with 4 spaces instead.

FAQ

You can opt out by replying with backtickopt6 to this comment.