Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #102603

Python's import situation has driven me to the brink of imsanity

Newsgroups comp.lang.python
Date 2016-02-06 18:47 -0800
Message-ID <e324ce71-1f90-4727-b7e8-eaa13c4ecc08@googlegroups.com> (permalink)
Subject Python's import situation has driven me to the brink of imsanity
From dimva13@gmail.com

Show all headers | View raw


No, that's not a typo, it's the name of a package I created. :)

The problems I have with python's import system are detailed in the README of my package here: https://github.com/vadimg/imsanity

Basically, relative imports are broken if you like running scripts as executables, so the only real solution is modifying PYTHONPATH every time you switch projects, which is also not ideal.

Some people suggest adding various boilerplate to the beginning of every file to fix this, ranging from the crazy stuff in PEP 0366 to the slightly more sane sys.path.append(os.path.realpath(os.path.join(os.path.dirname(__file__), path_to_root))), where path_to_root is some number of '../'s depending on the file's location. Neither can be used indiscriminately as a macro, which is annoying.

Imsanity allows you to make imports usable (not ideal, but at least usable) for python projects without having to manage PYTHONPATHs or do whacky stuff like running files with python -m or put even whackier boilerplate at the top of every file. And all it requires is 'import imsanity' at the top of every file. You can put it in a macro or even just type it because it's short and easy to remember.

My question is: is this crazy? Please tell me there's a better way and I just wasted my time creating this package. There's nothing I'd like to hear more.

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Python's import situation has driven me to the brink of imsanity dimva13@gmail.com - 2016-02-06 18:47 -0800
  Re: Python's import situation has driven me to the brink of imsanity Chris Angelico <rosuav@gmail.com> - 2016-02-07 13:52 +1100
  Re: Python's import situation has driven me to the brink of imsanity Kevin Conway <kevinjacobconway@gmail.com> - 2016-02-07 06:34 +0000
    Re: Python's import situation has driven me to the brink of imsanity dimva13@gmail.com - 2016-02-07 06:13 -0800
      Re: Python's import situation has driven me to the brink of imsanity Kevin Conway <kevinjacobconway@gmail.com> - 2016-02-07 16:09 +0000
        Re: Python's import situation has driven me to the brink of imsanity dimva13@gmail.com - 2016-02-07 16:38 -0800
          Re: Python's import situation has driven me to the brink of imsanity Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2016-02-10 00:31 +0000
          Re: Python's import situation has driven me to the brink of imsanity Sivan Greenberg <sivan@vitakka.co> - 2016-02-10 21:05 +0200
          Re: Python's import situation has driven me to the brink of imsanity Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-02-10 21:16 +0000
      Re: Python's import situation has driven me to the brink of imsanity Sivan Greenberg <sivan@vitakka.co> - 2016-02-07 18:15 +0200
  Re: Python's import situation has driven me to the brink of imsanity Sivan Greenberg <sivan@vitakka.co> - 2016-02-07 13:43 +0200

csiph-web