Advertisement
Guest User

Untitled

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