Re: import and package confusion

2009-05-01 Thread alex23
On May 1, 4:24 pm, Arnaud Delobelle wrote: > It's a challenge to do it in a list comprehension, but here it is! > >>> data > 'AAABCDD' > >>> field_sizes > [3, 5, 9, 2] > >>> [data[i:j] for j in [0] for s in field_sizes for i, j in [(j, j+s)]] > ['AAA', 'B', 'C', 'DD'] Ugh.

Re: import and package confusion

2009-04-30 Thread Arnaud Delobelle
Dale Amon writes: > Now I can move on to parsing those pesky Fortran card > images... There wouldn't happen to be a way to take n > continguous slices from a string (card image) where each > slice may be a different length would there? Fortran you > know. No spaces between input fields. :-) > >

Re: import and package confusion

2009-04-30 Thread Terry Reedy
alex23 wrote: On Apr 30, 5:33 pm, "Gabriel Genellina" wrote: (doesn't work as written, because [...] Man, I don't get Python... I can write a program that runs properly on the first try but every time I post untested code to c.l.p I regret it... Which is why I either cut&paste working code

Re: import and package confusion

2009-04-30 Thread Gabriel Genellina
En Thu, 30 Apr 2009 21:10:12 -0300, alex23 escribió: On Apr 30, 5:33 pm, "Gabriel Genellina" wrote: (doesn't work as written, because [...] Man, I don't get Python... I can write a program that runs properly on the first try but every time I post untested code to c.l.p I regret it... Most

Re: import and package confusion

2009-04-30 Thread alex23
On Apr 30, 5:33 pm, "Gabriel Genellina" wrote: > (doesn't work as written, because [...] Man, I don't get Python... I can write a program that runs properly on the first try but every time I post untested code to c.l.p I regret it... Thanks, Gabriel :) -- http://mail.python.org/mailman/listinfo

Re: import and package confusion

2009-04-30 Thread norseman
Terry Reedy wrote: Dale Amon wrote: Now I can move on to parsing those pesky Fortran card images... There wouldn't happen to be a way to take n continguous slices from a string (card image) where each slice may be a different length would there? Fortran you know. No spaces between input field

Re: import and package confusion

2009-04-30 Thread MRAB
Terry Reedy wrote: Dale Amon wrote: Now I can move on to parsing those pesky Fortran card images... There wouldn't happen to be a way to take n continguous slices from a string (card image) where each slice may be a different length would there? Fortran you know. No spaces between input field

Re: import and package confusion

2009-04-30 Thread Terry Reedy
Dale Amon wrote: Now I can move on to parsing those pesky Fortran card images... There wouldn't happen to be a way to take n continguous slices from a string (card image) where each slice may be a different length would there? Fortran you know. No spaces between input fields. :-) I know a wa

Re: import and package confusion

2009-04-30 Thread Dale Amon
Gabriel gave me the key to a fine solution, so just to put a bow tie on this thread: #!/usr/bin/python import sys sys.path.extend (['../lib', '../bin']) from VLMLegacy.CardReader import CardReader rdr = CardReader ("../example/B767.dat","PRINTABLE") iotypes = ["WINGTL","VLMPC","VLM4997"] fo

Re: import and package confusion

2009-04-30 Thread MRAB
Dale Amon wrote: On Thu, Apr 30, 2009 at 08:32:31AM +0200, Jeroen Ruigrok van der Werven wrote: -On [20090430 02:21], Dale Amon (a...@vnl.com) wrote: import sys sys.path.extend (['../lib', '../bin']) >from VLMLegacy.CardReader import CardReader rdr = CardReader ("../example/B767.dat","PRINTAB

Re: import and package confusion

2009-04-30 Thread Dale Amon
On Thu, Apr 30, 2009 at 04:33:57AM -0300, Gabriel Genellina wrote: > En Thu, 30 Apr 2009 03:04:40 -0300, alex23 escribió: >> Are you familiar with __import__? >> >> iotypes = ["WINGTL","VLMPC","VLM4997"] >> for iotype in iotypes: >> packagename = "VLMLegacy." + iotype + ".Conditions" >> classn

Re: import and package confusion

2009-04-30 Thread Dale Amon
On Thu, Apr 30, 2009 at 02:38:03AM -0400, Dave Angel wrote: > As Scott David Daniels says, you have two built-in choices, depending on > Python version. If you can use __import__(), then realize that > mod = __import__("WINGTL") > > will do an import, using a string as the import name. I do

Re: import and package confusion

2009-04-30 Thread Dale Amon
On Thu, Apr 30, 2009 at 08:32:31AM +0200, Jeroen Ruigrok van der Werven wrote: -On [20090430 02:21], Dale Amon (a...@vnl.com) wrote: >>import sys >>sys.path.extend (['../lib', '../bin']) >> >>from VLMLegacy.CardReader import CardReader >>rdr = CardReader ("../example/B767.dat","PRINTABLE") >> >>iot

Re: import and package confusion

2009-04-30 Thread Gabriel Genellina
En Thu, 30 Apr 2009 03:04:40 -0300, alex23 escribió: On Apr 30, 1:10 pm, Dale Amon wrote: I do not really see any other way to do what I want. If there is a way to get rid of the exec in the sample code I have used, I would love to know... but I can't see how to import something where part of

Re: import and package confusion

2009-04-29 Thread Dave Angel
Dale Amon wrote: On Wed, Apr 29, 2009 at 10:02:46PM -0400, Dave Angel wrote: The dot syntax works very predictably, and quite flexibly. The problem was that by using the same name for module and class, you didn't realize you needed to include both. It is one of the hazards of worki

Re: import and package confusion

2009-04-29 Thread Jeroen Ruigrok van der Werven
-On [20090430 02:21], Dale Amon (a...@vnl.com) wrote: >import sys >sys.path.extend (['../lib', '../bin']) > >from VLMLegacy.CardReader import CardReader >rdr = CardReader ("../example/B767.dat","PRINTABLE") > >iotypes = ["WINGTL","VLMPC","VLM4997"] >for iotype in iotypes: >packagename =

Re: import and package confusion

2009-04-29 Thread Arnaud Delobelle
Dale Amon writes: > I do not really see any other way to do what I want. If > there is a way to get rid of the exec in the sample code > I have used, I would love to know... but I can't see how > to import something where part of the name comes from user > command line input without interpreting

Re: import and package confusion

2009-04-29 Thread alex23
On Apr 30, 1:10 pm, Dale Amon wrote: > I do not really see any other way to do what I want. If > there is a way to get rid of the exec in the sample code > I have used, I would love to know... but I can't see how > to import something where part of the name comes from user > command line input wit

Re: import and package confusion

2009-04-29 Thread Scott David Daniels
Dale Amon wrote: On Wed, Apr 29, 2009 at 10:02:46PM -0400, Dave Angel wrote: Please don't sink to exec or eval to solve what is really a straightforward problem. I do not really see any other way to do what I want. If there is a way to get rid of the exec in the sample code I have used, I wou

Re: Re: import and package confusion

2009-04-29 Thread Dale Amon
On Wed, Apr 29, 2009 at 10:02:46PM -0400, Dave Angel wrote: > The dot syntax works very > predictably, and quite flexibly. The problem was that by using the same > name for module and class, you didn't realize you needed to include both. It is one of the hazards of working in many very differ

Re: Re: import and package confusion

2009-04-29 Thread Dave Angel
Dale Amon wrote: The point I take away from this is that packages and modules have dotted names, but Classes do not and there is no way to do exactly what I wanted to do. The dot syntax would have been quite nice (I quite like the "::" syntax in Perl) and would have made the code much clearer.

Re: import and package confusion

2009-04-29 Thread Dale Amon
On Wed, Apr 29, 2009 at 04:06:23PM -0700, Scott David Daniels wrote: > Dale Amon wrote: >> >> The point I take away from this is that packages and >> modules have dotted names, but Classes do not and there >> is no way to do exactly what I wanted to do. > Nope. You have not been clear with w

Re: import and package confusion

2009-04-29 Thread Dale Amon
Well, I've managed to get close to what I want, and just so you can see: #!/usr/bin/python import sys sys.path.extend (['../lib', '../bin']) from VLMLegacy.CardReader import CardReader rdr = CardReader ("../example/B767.dat","PRINTABLE") iotypes = ["WINGTL","VLMPC","VLM4997"] for iotype in

Re: import and package confusion

2009-04-29 Thread Scott David Daniels
Dale Amon wrote: The point I take away from this is that packages and modules have dotted names, but Classes do not and there is no way to do exactly what I wanted to do. Nope. You have not been clear with what you want, and part of the lack of clarity is your imprecision about names. If

Re: import and package confusion

2009-04-29 Thread Dale Amon
On Wed, Apr 29, 2009 at 03:06:13PM -0700, Scott David Daniels wrote: > You did not answer the question above, and I think the answer is the root > of your misunderstanding. A class and a module are _not_the_same_thing_. > sys is not a package, it is a module. >>> Just because you put a class insid

Re: import and package confusion

2009-04-29 Thread Scott David Daniels
Dale Amon wrote: On Wed, Apr 29, 2009 at 01:12:33PM -0700, Scott David Daniels wrote: Dale Amon wrote: I am trying to get to the heart of what it is I am missing. Is it the case that if you have a module C in a package A: A.C that there is no way to load it such that you can use

Re: import and package confusion

2009-04-29 Thread Pascal Chambon
Actually, the parethesis mean "calling" the object. "Callable" objects can be of different types : -functions - in which case they get executed -classes (or metaclasses) - in which case they get "instantiated" (with all the protocol : __new__(), __init__()...) -other objects - in which case the

Re: import and package confusion

2009-04-29 Thread Dale Amon
On Wed, Apr 29, 2009 at 04:34:03PM -0400, Dale Amon wrote: > type = "VLM4997" > type.Header(args) > type.Plan(args) > type.Conditions(args) > Where the type might change from execution to execution > or even on different iterations. Actually let me make that reflect more ac

Re: import and package confusion

2009-04-29 Thread Dale Amon
On Wed, Apr 29, 2009 at 01:12:33PM -0700, Scott David Daniels wrote: > Dale Amon wrote: >> I am trying to get to the heart of what it is I am >> missing. Is it the case that if you have a module C in a package A: >> A.C >> that there is no way to load it such that you can use: >> x = A.C(

Re: import and package confusion

2009-04-29 Thread Scott David Daniels
Dale Amon wrote: I am trying to get to the heart of what it is I am missing. Is it the case that if you have a module C in a package A: A.C that there is no way to load it such that you can use: x = A.C() in your code? OK, here's a simple question. What do you expect from:

Re: import and package confusion

2009-04-29 Thread Dale Amon
I am trying to get to the heart of what it is I am missing. Is it the case that if you have a module C in a package A: A.C that there is no way to load it such that you can use: x = A.C() in your code? This is just a simpler case of what I'm trying to do now, which has a module

Re: import and package confusion

2009-04-29 Thread Scott David Daniels
Dale Amon wrote: I am going around in circles right now and have to admit I do not understand what is going on with import of hierarchical packages/modules. Perhaps someone can get me on the road again. Here is a subset of what I am trying to accomplish: The package directory set up:

import and package confusion

2009-04-29 Thread Dale Amon
I am going around in circles right now and have to admit I do not understand what is going on with import of hierarchical packages/modules. Perhaps someone can get me on the road again. Here is a subset of what I am trying to accomplish: The package directory set up: VLMLegacy/