There are two things that are annoying about Python's import system. Number one is that relative imports are weird. My intuition about imports is good enough that I never bothered to learn all the rules explicitly, but sometimes something simple is just not possible and it bites me. I think the case is importing files relative to a script (and not running with python -m ...). Number two is, in order to do package man…
How the Python import system works
91–100 of 209 posts
Re: How the Python import system works
#92Earlier quoted context omitted.
Suppose you have two classes, A and B. They are sufficiently complex to merit their own modules. Suppose you have some method of A which does something special if it gets an instance of B, and vice versa. Now you have a circular import problem; glhf
IMHO that's code smell. Modules shouldn't depend on each other, because that creates a web of tangled dependency where you have to understand everything before you can understand one of them. Circular dependency is to modules what goto is to control flow. Besides, if you are in a "well, fuck it, deadline is tomorrow" mode, you can always do something horrible like: if 'classB' in type(obj).__name__: ...
But the truth is sometimes it has happened to me and the only solution I found was creating an small module with maybe one or two functions which is not exactly ideal.
Re: How the Python import system works
#93Earlier quoted context omitted.
Can I just say that the introduction to Lisp you made in your README.md is really good! I keep trying to get into Lisp (and JavaScript, and TypeScript, etc etc) but I've been a sysadmin my whole professional life and also a chronic pain sufferer. That translates into mostly having energy only for work and that's it, not much motivation to learn after work or on the weekend. In my DevOps job, I write Terraform, plus r…
Not mine! That was all Scott Bell. It's forked from Lumen: https://github.com/sctb/lumen But, I did make an interactive tutorial here: https://docs.ycombinator.lol/ If you have any questions about it, I'd be happy to answer. This stuff is pure fun mixed with a shot of professionalism. For what it's worth, as someone with narcolepsy, I relate quite a lot to your chronic pain. ( https://twitter.com/theshawwn/status/139…
Re: How the Python import system works
#94Probably half of the commenters here know this, but since we're here, this is my go-to boilerplate for starting a python script. (Probably won't work on Windows.) #!/bin/sh # Run the interpreter with -u so that stdout isn't buffered. "exec" "python3" "-u" "$0" "$@" import os import sys curdir = os.path.dirname(os.path.realpath(sys.argv[0])) # Add enough .. to point to the top-level project directory. sys.path.insert(…
Re: How the Python import system works
#95Years ago, I thought I'd try learning Python, I'd heard it was supposed to be easy, good for beginners and everything. I read one of those beginner Python type books and followed along with a roguelike tutorial. Everything was going pretty alright, until I started trying to split everything into different files and use imports. I ended up just giving up. I read programming in lua, and rewrote my entire project in lua…
Strange, Python’s import is not very difficult to use.
Re: How the Python import system works
#96Earlier quoted context omitted.
Strange, Python’s import is not very difficult to use.
It was probably something I did. The original tutorial I followed had everything in one file and didn't get into anything about imports. I started splitting everything up arbitrarily and started tossing imports into the files that complained about missing dependencies and ended up getting overwhelmed because nothing worked. I'm sure if I'd taken the time to try and fix it I eventually could have and at this point i'v…
Re: How the Python import system works
#97Re: How the Python import system works
#98Earlier quoted context omitted.
The purpose is you want to use code in other modules. If you keep doing that for a while, a circular dependency will happen. This is the dumbest thing thing in Python. All other languages I know have solved it.
> The purpose is you want to use code in other modules. So put them in the same module? Circular modules don’t give you the benefits of modules, do they? Not an expert in modularity.
In case you didn't know, each source code file is a module in Python.
Re: How the Python import system works
#99Earlier quoted context omitted.
Can I just say that the introduction to Lisp you made in your README.md is really good! I keep trying to get into Lisp (and JavaScript, and TypeScript, etc etc) but I've been a sysadmin my whole professional life and also a chronic pain sufferer. That translates into mostly having energy only for work and that's it, not much motivation to learn after work or on the weekend. In my DevOps job, I write Terraform, plus r…
Not mine! That was all Scott Bell. It's forked from Lumen: https://github.com/sctb/lumen But, I did make an interactive tutorial here: https://docs.ycombinator.lol/ If you have any questions about it, I'd be happy to answer. This stuff is pure fun mixed with a shot of professionalism. For what it's worth, as someone with narcolepsy, I relate quite a lot to your chronic pain. ( https://twitter.com/theshawwn/status/139…
Re: How the Python import system works
#100Earlier quoted context omitted.
Not mine! That was all Scott Bell. It's forked from Lumen: https://github.com/sctb/lumen But, I did make an interactive tutorial here: https://docs.ycombinator.lol/ If you have any questions about it, I'd be happy to answer. This stuff is pure fun mixed with a shot of professionalism. For what it's worth, as someone with narcolepsy, I relate quite a lot to your chronic pain. ( https://twitter.com/theshawwn/status/139…
Does "-5e4" really evaluate to "-5000" in this language?
It evaluates to -500000, as you’d expect.
(Just kidding, it’s -50000. Amusingly, the https://docs.ycombinator.lol version gets it right, since it has to; every expression is actually evaluated in the browser.)