Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [01:06:43] <arantes_> hello
- [01:06:52] <plut0> fission6: its a shared host with no root access, i'm installing pysqlite locally
- [01:06:58] <fission6> whats a good site to find freelance gigs
- [01:08:01] <arantes_> guys, how could i, in python 2.6, import a module from a subdirectory of where the module i want to import is ?
- [01:08:21] <KirkMcDonald> arantes_: Configure your module search path correctly.
- [01:08:29] <fission6> hmm plut0 maybe you dont have the rights you need to get some files in the right place? also, again, whats your current working directoring you are in and trying to import pysqlite
- [01:08:48] <arantes_> KirkMcDonald: you mean with sys.path.append ?
- [01:08:49] <fission6> arantes_, you need to make packages
- [01:08:55] <fission6> by adding __init__.py
- [01:08:57] <-> arantes_ es ahora conocido como arantes
- [01:08:58] <-- bgeddy (~bgeddy@cpc3-live19-0-0-cust292.know.cable.virginmedia.com) ha salido (Read error: Connection reset by peer)
- [01:09:01] <plut0> fission6: i have the directory in my PYTHONPATH, i should be able to import the module from anywhere, no?
- [01:09:07] <KirkMcDonald> arantes: No.
- [01:09:08] <arantes> fission6: there already is __init__.py in each directory
- [01:09:40] <-- ineiros_ (~itniemin@cs27065016.pp.htv.fi) ha salido (Ping timeout: 246 seconds)
- [01:09:41] <KirkMcDonald> arantes: I am suggesting that you use absolute imports.
- [01:09:52] <-- hopthrisC (~hop@86.59.119.35) ha salido (Quit: leaving)
- [01:10:01] <KirkMcDonald> arantes: All of these modules are under some top-level package, right?
- [01:10:03] <fission6> plundra, whats the filename of the .py file you are tryin gto execute
- [01:10:10] <arantes> yep
- [01:10:19] <fission6> err plut0
- [01:10:27] <KirkMcDonald> arantes: So it should Just Work if you use absolute imports everywhere.
- [01:10:41] --> kramed (~Mark@bas1-toronto63-1096774567.dsl.bell.ca) se ha unido a #python
- [01:10:55] --> Fandekasp (~Fandekasp@94-194-207-230.zone8.bethere.co.uk) se ha unido a #python
- [01:10:57] <-- krunk- (~krunk-@unaffiliated/krunk-) ha salido (Remote host closed the connection)
- [01:11:21] --> kyrix (~ashley@chello213047159139.33.11.univie.teleweb.at) se ha unido a #python
- [01:11:25] --> krunk- (~krunk-@unaffiliated/krunk-) se ha unido a #python
- [01:11:34] --> roppert (~roppert@62.205.216.81.static.k.siw.siwnet.net) se ha unido a #python
- [01:11:39] <arantes> KirkMcDonald: for example, here is the structure :
- [01:12:18] <arantes> in the directory a, i have a module a, then in a subfolder b of it, i have a module b
- [01:12:20] <-- Luyt (~Luyt@gandhi.xs4all.nl) ha salido (Remote host closed the connection)
- [01:12:29] <arantes> how can i import a from b ?
- [01:12:30] <-- alkama (~alkama@dan75-4-82-239-58-37.fbx.proxad.net) ha salido (Quit: blabla blab....'t was like...ah my gosh !!!)
- [01:12:47] <KirkMcDonald> arantes: And are these directories packages?
- [01:12:50] --> bgeddy (~bgeddy@cpc3-live19-0-0-cust292.know.cable.virginmedia.com) se ha unido a #python
- [01:13:21] <-- wdf (~wdf@ip24-253-145-219.hr.hr.cox.net) ha salido (Read error: Connection reset by peer)
- [01:13:26] <arantes> KirkMcDonald: if you mean by packages that they have a __init__.py, yep they are
- [01:13:31] <-- SecretAgent (sa@quake.nitemare.name) ha salido (Ping timeout: 246 seconds)
- [01:13:37] <KirkMcDonald> arantes: How was the module 'b' imported in the first place?
- [01:13:47] <-- sacho (~sacho@79-100-48-9.btc-net.bg) ha salido (Ping timeout: 265 seconds)
- [01:13:56] --> sn0wflake (~sn0wflake@230.216.121.70.cfl.res.rr.com) se ha unido a #python
- [01:14:05] --> wdf (~wdf@ip24-253-145-219.hr.hr.cox.net) se ha unido a #python
- [01:14:23] <-- Cobalt (~cobalt@unaffiliated/sinnerman) ha salido (Remote host closed the connection)
- [01:14:37] --> AzMoo (~matt@unaffiliated/azmoo) se ha unido a #python
- [01:14:53] --> Jacob- (~jacob@d75-155-159-179.bchsia.telus.net) se ha unido a #python
- [01:14:54] <-- anaconda (~anaconda@unaffiliated/anaconda) ha salido (Ping timeout: 246 seconds)
- [01:15:14] <-- tizbac (~X_X@host15-187-dynamic.35-79-r.retail.telecomitalia.it) ha salido (Read error: Connection reset by peer)
- [01:15:16] --> hopthrisC (~hop@86.59.119.35) se ha unido a #python
- [01:15:34] <arantes> KirkMcDonald: in a.py : from b import *
- [01:15:40] --> jrib (~jrib@upstream/dev/jrib) se ha unido a #python
- [01:15:45] <verte> yuck
- [01:15:45] --> anaconda (~anaconda@unaffiliated/anaconda) se ha unido a #python
- [01:15:46] <-- mny (~berg@pool-71-245-176-177.pitbpa.fios.verizon.net) ha dejado #python
- [01:15:49] <KirkMcDonald> arantes: Hmm.
- [01:16:03] <KirkMcDonald> arantes: This is wrong for at least three reasons.
- [01:16:06] <fission6> dont name after package
- [01:16:14] <fission6> change .py file name
- [01:16:21] <KirkMcDonald> arantes: First, don't use 'from foo import *'.
- [01:16:23] <verte> relative *and* unhygienic
- [01:16:24] <-- rizzuh_laptop (~rizzuh@unaffiliated/rizzuh) ha salido (Quit: What? WAIT noooo don't pull that pl...)
- [01:16:29] <arantes> fission6: it's not, it's just an example
- [01:16:43] <KirkMcDonald> arantes: Second, this is importing the *package* named b, not the submodule of that package.
- [01:16:51] <KirkMcDonald> arantes: Third, it is an implicit relative import.
- [01:17:08] <KirkMcDonald> arantes: Oh! And forth, this implies that you're setting up a circular dependency between these two modules.
- [01:17:24] --> kkszysiu (~kkszysiu@aafo59.neoplus.adsl.tpnet.pl) se ha unido a #python
- [01:17:41] <arantes> KirkMcDonald: why shouldn't i use import * ?
- [01:17:56] <KirkMcDonald> arantes: Namespaces are a good thing.
- [01:18:06] <KirkMcDonald> arantes: import * destroys them.
- [01:18:08] <-- Raptors (~Raptors@66.49.149.139) ha salido (Ping timeout: 265 seconds)
- [01:18:14] <arantes> not wanted here
- [01:18:15] <ivan`> Pyflakes can't check your code for undefined names if you use import *
- [01:18:23] <KirkMcDonald> arantes: It hides where names come from.
- [01:18:40] --> deximer (~anonymous@c-24-60-81-145.hsd1.ma.comcast.net) se ha unido a #python
- [01:18:47] <KirkMcDonald> arantes: 'from foo import blah, blargh' is better.
- [01:19:11] <-- poisonarms (~poisonarm@c-68-57-170-85.hsd1.va.comcast.net) ha salido (Ping timeout: 276 seconds)
- [01:19:59] <arantes> KirkMcDonald: yep, there is a circular dependancy, why would that be bad ?
- [01:20:10] <arantes> and i don't understand what is an implicit relativ import xD
- [01:20:22] <-- gkmngrgn (~gokmen@unaffiliated/gkmngrgn) ha salido (Quit: gkmngrgn)
- [01:20:32] <KirkMcDonald> arantes: Well, your module 'a' is inside of a package.
- [01:20:35] <fission6> it will important everything underneath your module
- [01:20:43] <squigle> a import b, b import a, importing a would import b and then a and then b and then a and then ........
- [01:20:53] <-- Cromulent (~Cromulent@host86-145-21-102.range86-145.btcentralplus.com) ha salido (Quit: Cromulent)
- [01:21:14] <KirkMcDonald> arantes: An implicit relative import is when one submodule imports another submodule by its unqualified name. "import b" as opposed to "import package.b".
- [01:21:19] <arantes> okay ... so there is no way of doing it like it was supposed to ..
- [01:21:29] <KirkMcDonald> squigle: It doesn't really work like that.
- [01:21:45] <squigle> KirkMcDonald, no it doesn't
- [01:21:45] <arantes> oh, so why bad ?
- [01:21:53] <KirkMcDonald> When you have a circular import, one of the modules will see the other module in an unfinished state while it is being executed.
- [01:22:01] --> Zeiris (~Zeiris@d75-154-177-21.bchsia.telus.net) se ha unido a #python
- [01:22:02] <fission6> sounds like something should be refactored
- [01:22:17] --> lagagnon (~larry@207.200.142.55) se ha unido a #python
- [01:22:26] <KirkMcDonald> You can essentially always resolve circular imports by introducing a third module.
- [01:23:52] <-- deximer (~anonymous@c-24-60-81-145.hsd1.ma.comcast.net) ha salido (Quit: deximer)
- [01:23:57] <dpn`> most frequently named "utils.py" ;)
- [01:24:10] <KirkMcDonald> Or something.
- [01:24:26] <dash> hm yeah
- [01:24:38] <dash> exocet oughta handle circular deps, now that i think about it
- [01:25:41] <-- unreal (~unreal@unaffiliated/unreal) ha salido (Ping timeout: 276 seconds)
- [01:25:45] <-- ExtraSpice (~XtraSpice@88.118.32.225) ha salido (Ping timeout: 240 seconds)
- [01:26:11] -*- Jacob- ponders Python 2.7.
- [01:26:31] <squigle> whats exocet dash?
- [01:26:49] <dash> new module system for python i'm workin' on
- [01:26:53] -*- squigle points Jacob- at python 3.x oooh shiny
- [01:27:10] <KirkMcDonald> dash: What does "handle" circular deps mean? Forbid them? :-)
- [01:27:16] <squigle> do you know about the one in hg?
- [01:27:19] <dash> KirkMcDonald: allow them! when they make sense
- [01:27:23] <dash> squigle: the lazy importer?
- [01:27:25] <KirkMcDonald> dash: Hmm.
- [01:27:31] <squigle> dash, ya
- [01:27:32] <dash> squigle: i'm vaguely aware they have a thing
- [01:27:45] <dash> squigle: got a link with some info about it
- [01:27:59] <arantes> ok thank you KirkMcDonald, fission6 , squigle, and everyone else :)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement