Re: absolute path to a file

2019-08-21 Thread tom arnall
Thanks. Hope you found a solution to the problem.

On Tue, Aug 20, 2019, 2:51 AM Cameron Simpson  wrote:

> Please remember to CC the list.
>
> On 19Aug2019 22:06, Paul St George  wrote:
> >On 19/08/2019 14:16, Cameron Simpson wrote:
> [...]
> >>There's a remark on that web page I mentioned that suggests that the
> >>leading '//' indicates the filename is relative to the Blender model,
> >>so the context directory for the '//' is likely
> >>/Users/Lion/Desktop/test8.
> >
> >Yes. That makes sense. The reason I was testing with two images, one
> >at /Users/Lion/Desktop/test8/image01.tif and the other at
> >/Users/Lion/Desktop/images/image02.tif is that I cannot rely on images
> >being in the same folder as the Blender file.
> >
> >So, let's assume the context directory is /Users/Lion/Desktop/test8
> >and see how we get on below.
> [...]
> >>realpath needs a UNIX path. Your //image01.tif isn't a UNIX path, it
> >>is a special Blender path. First you need to convert it. By replacing
> >>'//' with the blend file's directory. Then you can call realpath. If
> >>you still need to.
> >
> >Understood. Now. Thanks!
> >>
> >>[...snip...]
> >
> >Did you just [...snip...] yourself?
>
> Yes. It keeps the surrounding context manageable. In this way you know
> to which text I am referring, without having to wade through paragraphs
> to guess what may be relevant.
>
> >>from os.path import dirname
> >>
> >># Get this from somewhere just hardwiring it for the example.
> >># Maybe from your 'n' object below?
> >>blend_file = '/Users/Lion/Desktop/test8/tifftest8.blend'
> >Is this setting a relative path?
> >>
> >>blender_image_file = n.image.filename
> >>
> >>unix_image_file = unblenderise(blender_image_file,
> dirname(blend_file))
> >>
> >>Now you have a UNIX path. If blend_file is an absolute path,
> >>unix_image_path will also be an absolute path. But if blend_file is
> >>a relative path (eg you opened up "tifftest8.blend") unix_image_path
> >>will be a relative path.
> >
> >Does unix_image_path = unix_image_file?
>
> Yeah, sorry,  my mistake.
>
> >Two possibilities here.
> >blend_file (and so unix_image_file) is an absolute path OR blend_file
> >(and so unix_image_file) is a relative path.
> >
> >I just want to check my understanding. If I supply the path to
> >blend_file then it is absolute, and if I ask Python to generate the
> >path to blend_file from within Blender it is relative. Have I got it?
>
> Not quite. What seems to be the situation is:
>
> You've got some object from Blender called "n.image", which has a
> ".file" attribute which is a Blender reference to the image file of the
> form "//image01.tif".
>
> I presume that Blender has enough state inside "n" or "n.image" to
> locate this in the real filesystem; maybe it has some link to the
> Blender model of your blend file, and thus knows the path to the blend
> file and since //image01.tif is a reference relative to the blend file,
> it can construct the UNIX path to the file.
>
> You want to know the UNIX pathname to the image file (maybe you want to
> pass it to some unrelated application to view the file or something).
>
> So you need to do what Blender would do if it needs a UNIX path (eg to
> open the file).
>
> The formula for that is dirname(path_to_blendfile) with n.image.file[2:]
> appended to it. So that's what we do with unblenderise(): if the
> filename is a "Blender relative name", rip off the "//" and prepend the
> blend file directory path. That gets you a UNIX path which you can hand
> to any function expecting a normal operating system pathname.
>
> Whether that is an absolute path or a relative path is entirely "does
> the resulting path start with a '/'"?
>
> An absolute path starts with a slash and is relative to the root of the
> filesystem. You can use such a path regardless of what your current
> working directory is, because it doesn't use the working directory.
>
> A relative path doesn't start with a slash and is relative to the
> current working directory. It only works if you're in the right working
> directory.
>
> _Because_ a relative path depends on the _your_ working directory,
> usually we pass around absolute paths if we need to tell something else
> about a file, because that will work regardless if what _their_ working
> directory may be.
>
> So, you may well want to turn a relative path into an absolute path...
>
> >If I decided not to supply the path and so ended up with a relative
> >UNIX path, I could now use realpath or abspath to find the absolute
> >path. Have I still got it?
>
> This is correct.
>
> Abspath may even call realpath to do its work, unsure.
>
> >It works very well. So thank you! I tested it with a Blend file that
> >had two images, one in the same folder as the Blend file and the other
> >was in a folder on the Desktop called 'images'.
> >
> >The initial results were:
> >Plane uses image01.tif saved at //image01.tif which is at
> >/Users/Lion/Desktop/test8/image01.tif
> >Plane uses

cross-linked version of the python documentation

2006-10-20 Thread tom arnall
Is there a cross-linked version of the python documentation available? Is
anyone interested in starting a project for such?

tom arnall
north spit, ca
usa

-- 
Posted via a free Usenet account from http://www.teranews.com

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: cross-linked version of the python documentation

2006-10-20 Thread tom arnall
Simon Brunning wrote:

> On 10/20/06, tom arnall <[EMAIL PROTECTED]> wrote:
>> Is there a cross-linked version of the python documentation available? Is
>> anyone interested in starting a project for such?
> 
> What do you mean by cross-linked?

If the term e.g. 'span()' is used in a discussion of 'search()' in the regex
documentation, then there is a hyperlink from that appearance of the term
to the documentation for 'span()'. I think this would be very helpful to
newbies like myself.

Thanks,

tom arnall
north spit, ca
usa

-- 
Posted via a free Usenet account from http://www.teranews.com

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What's the best IDE?

2006-10-25 Thread tom arnall
Ben Finney wrote:

> "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes:
> 
>> After researching Komodo, I found it's not free. The only funds I
>> have are a college fund, and I can't start diping into that until
>> I'm going to college. Any free AND good IDEs?
> 
> Please consider trying Python with a powerful editor, instead of a
> just-for-Python environment. Knowing a powerful editor is a far better
> investment than a complex tool for a single purpose.

Amen. 

As an alternative to the IDE straight-jacket you might consider going the
unit-testing/'live code' route, which obviates the need for a debugger and
other clutter found in all of the IDEs i've seen. Also, you might think
about writing your own unit-tester. It's not difficult in python and will
give you a setup tailored to your own tastes. But whatever you do, keep
things simple and light.


-- 
tom arnall
north spit, ca
usa

-- 
Posted via a free Usenet account from http://www.teranews.com

-- 
http://mail.python.org/mailman/listinfo/python-list


object data member dumper?

2006-11-07 Thread tom arnall
does anyone know of a utility to do a recursive dump of object data members?


-- 
Posted via a free Usenet account from http://www.teranews.com

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: object data member dumper?

2006-11-07 Thread tom arnall
Bruno Desthuilliers wrote:

> tom arnall a écrit :
>> does anyone know of a utility to do a recursive dump of object data
>> members?
>> 
> 
> What are "object data members" ? (hint: in Python, everything is an
> object - even functions and methods).
> 
> What is your real use case ?

something like:

   class A:
  def __init__(self, p1):
 self.p1 = p1

   class B: 
  def __init__(self,p1, p2):
 self.a = A(p1)
 self.p2 = p2
 self.v1 = '3'

   class C:
  def __init__(self):
 self.b = B(3,4)
 self.p3 = 5

   class D:
  def __init__(self):
 self.v2=2
 self.o1 = C()
 self.o2 = B(11,12)


   d = D()
   objectDataDumper(d)


would produce something like:

   object of class D with:
   o1(C)->b(B)->a(A)->p1=3
   o1(C)->b(B)->p2=4
   o1(C)->b(B)->v1=3
   o1(C)->p3=5
   o2(B)->a(A)->p1=11
   o2(B)->p2=12
   o2(B)->v1=3
   v2=2


tom arnall
north spit, ca
usa

-- 
Posted via a free Usenet account from http://www.teranews.com

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: object data member dumper?

2006-11-07 Thread tom arnall
Steve Holden wrote:

> Bruno Desthuilliers wrote:
>> tom arnall a écrit :
>> 
>>>does anyone know of a utility to do a recursive dump of object data
>>>members?
>>>
>> 
>> 
>> What are "object data members" ? (hint: in Python, everything is an
>> object - even functions and methods).
>> 
>> What is your real use case ?
> 
> Basically it sounds like the OP wants to see the attribute values for an
> object (and those objects' attribute values, ...). Presumably the
> recursive descent could be stopped at the built-in types.

Yes, exactly. But what is 'OP'?

> 
> I'm not familiar with any such thing. 

I'm amazed that there is no way to easily look at the fundamental data
structures of a python program. I'm new to python - is there something I
don't know about the territory in this regard?

>The code of the standard library's
> pprint module might be a good place to start 

I played around with this but it seems more targetted to looking at python
objects as opposed to user-defined.

>(and the suggested
> functionality might make a nice addition if we could work out exactly
> what the requirement was).

I would be glad if people would comment on my example as a step in this
direction.

tom arnall
north spit, ca
usa


-- 
Posted via a free Usenet account from http://www.teranews.com

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: object data member dumper?

2006-11-09 Thread tom arnall
Steve Holden wrote:

> tom arnall wrote:
>> Steve Holden wrote:
>> 
>> 
>>>Bruno Desthuilliers wrote:
>>>
>>>>tom arnall a écrit :
>>>>
>>>>
>>>>>does anyone know of a utility to do a recursive dump of object data
>>>>>members?
>>>>>
>>>>
>>>>
>>>>What are "object data members" ? (hint: in Python, everything is an
>>>>object - even functions and methods).
>>>>
>>>>What is your real use case ?
>>>
>>>Basically it sounds like the OP wants to see the attribute values for an
>>>object (and those objects' attribute values, ...). Presumably the
>>>recursive descent could be stopped at the built-in types.
>> 
>> 
>> Yes, exactly. But what is 'OP'?
>> 
> "original poster" (you)
>> 
>>>I'm not familiar with any such thing.
>> 
>> 
>> I'm amazed that there is no way to easily look at the fundamental data
>> structures of a python program. I'm new to python - is there something I
>> don't know about the territory in this regard?
>> 
> Well, new enough to be unaware that Python normally doesn't need such
> drastic measures for debugging. When you are building complex data
> structures such a form of output could get big really quickly. I've
> never come across anything like it in any other language that I have used.

never come across the complexity of data structures or across an object
displayer?

> 
> The most that's usually required is a __repr__() method that dumps the
> values of necessary data attributes.

what about __dict__?


>> 
>>>The code of the standard library's
>>>pprint module might be a good place to start
>> 
>> 
>> I played around with this but it seems more targetted to looking at
>> python objects as opposed to user-defined.
>> 
> It is, but it could be used as a basis for something more to your liking.
>> 
>>>(and the suggested
>>>functionality might make a nice addition if we could work out exactly
>>>what the requirement was).
>> 
>> 
>> I would be glad if people would comment on my example as a step in this
>> direction.
>> 
> I'd suggest you instead consider a mixin object that will add recursive
> data dump functionality to any such classes you require.

have googled a fair amount on 'mixin' but still stumped on it.




-- 
Posted via a free Usenet account from http://www.teranews.com

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: object data member dumper?

2006-12-12 Thread tom arnall
George Sakkis wrote:

> tom arnall wrote:
>> >object data member dumper?
>> >George Sakkis george.sakkis at gmail.com
>> >Wed Nov 8 03:42:47 CET 2006
>>
>> > tom arnall wrote:
>> >
>> > > Bruno Desthuilliers wrote:
>> > >
>> > > > tom arnall a écrit :
>> > > >> does anyone know of a utility to do a recursive dump of object
>> > > >> data members?
>> > > >>
>> > > >
>> > > > What are "object data members" ? (hint: in Python, everything is an
>> > > > object - even functions and methods).
>> > > >
>> > > > What is your real use case ?
>> > >
>> > > something like:
>> > >
>> > >class A:
>> > >   def __init__(self, p1):
>> > >  self.p1 = p1
>> > >
>> > >class B:
>> > >   def __init__(self,p1, p2):
>> > >  self.a = A(p1)
>> > >  self.p2 = p2
>> > >  self.v1 = '3'
>> > >
>> > >class C:
>> > >   def __init__(self):
>> > >  self.b = B(3,4)
>> > >  self.p3 = 5
>> > >
>> > >class D:
>> > >   def __init__(self):
>> > >  self.v2=2
>> > >  self.o1 = C()
>> > >  self.o2 = B(11,12)
>> > >
>> > >
>> > >d = D()
>> > >objectDataDumper(d)
>> > >
>> > >
>> > > would produce something like:
>> > >
>> > >object of class D with:
>> > >o1(C)->b(B)->a(A)->p1=3
>> > >o1(C)->b(B)->p2=4
>> > >o1(C)->b(B)->v1=3
>> > >o1(C)->p3=5
>> > >o2(B)->a(A)->p1=11
>> > >o2(B)->p2=12
>> > >o2(B)->v1=3
>> > >v2=2
>> > >
>> > >
>> > > tom arnall
>> > > north spit, ca
>> > > usa
>> >
>> > At first I thought pickle would be what you're looking for, because
>> > that's exactly what it does; it dumps arbitrary objects, without
>> > choking on recursive references. Only problem is, it's not human
>> > readable (even in its ascii form).If you want it to be human readable,
>> > you may check the gnosis.xml.pickle module
>> > (http://cheeseshop.python.org/pypi/Gnosis_Utils/1.2.1-a). That's the
>> > output of gnosis.xml.pickle.XML_Pickler(d).dumps() on your example:
>> >
>> > 
>> > 
>> > 
>> > 
>> > > > class="B">
>> >   > > class="A">
>> > 
>> >   
>> >   
>> >   
>> > 
>> > > > class="C">
>> >   
>> >   > > class="B">
>> > > > class="A">
>> >  
>> > 
>> > 
>> > 
>> >   
>> > 
>> > 
>> >
>> >
>> > I've also written a similar but less verbose xml dumper. The gnosis.xml
>> > package provides a bidirectional mapping between objects and xml
>> > (objects -> xml and xml->object) and therefore has to be precise; mine
>> > simply generates a nice xml dump of the object which isn't necessarily
>> > reversible. Here's the output for your example:
>> >
>> > 
>> >   
>> > 
>> >   
>> > 3
>> >   
>> >   4
>> >   3
>> > 
>> > 5
>> >   
>> >   
>> > 
>> >   11
>> > 
>> > 12
>> > 3
>> >   
>> >   2
>> > 
>> >
>> >
>> > If you find it suits you better, I'll try to make it available
>> > somewhere (probably in the cookbook).
>> >
>> > George
>> >
>>
>>
>>  George,
>>
>>  did you ever put up your object dumper on the net?
> 
> Here it is: http://rafb.net/paste/results/C0NHBp27.html
> Mostly undocumented but works for most common types. Most methods are
> overridable so you can customize the dumping for a specific type (or
> types) in a subclass.
> 


Superb! Thanks very much.

tom arnall
north spit, ca
usa



Make cyberspace pretty: stamp out curly brackets and semicolons.

Loosen up: the tests extend the compiler.


-- 
Posted via a free Usenet account from http://www.teranews.com

-- 
http://mail.python.org/mailman/listinfo/python-list


working model of a microcoded computer

2007-02-02 Thread tom arnall

This is somewhat off topic, but I think many programmers would be
interested to look at a working model of a microcoded computer at:

        tomspages.com
        
click on the link for 'Hack the Com puter Model.' It conveys among other
things the physical events that underlie execution of a microcode
instruction and, by extension, of machine language.

I would like very much to get people's feedback on the thing.

Thanks,

tom arnall
north spit, ca
usa


-- 
Posted via a free Usenet account from http://www.teranews.com

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to have unittest tests to be executed in the order they appear?

2008-04-15 Thread tom arnall
On Tuesday 15 April 2008 16:23, Ben Finney wrote:
> "Giampaolo Rodola'" <[EMAIL PROTECTED]> writes:
> > Is there a way to force unittest to run test methods in the order
> > they appear?
>
> No, and this is a good thing.
>
> Your test cases should *not* depend on any state from other test
> cases; they should function equally well when executed in any
> arbitrary sequence. Dependencies between separate test cases (e.g.
> "they only work correctly when run in a specific sequence") means
> you're not isolating them properly.
>
> Use the TestCase.setUp and TestCase.tearDown methods to handle any
> fixtures needed by test cases in each class of test cases. That way,
> the fixtures will be set up and torn down between every test case.
> Find out about test fixtures in the documentation for unittest
> http://www.python.org/doc/lib/module-unittest>.
>
> --
>  \ "All my life I've had one dream: to achieve my many goals."  -- |
>   `\ Homer, _The Simpsons_ |
> _o__)  |
> Ben Finney


a better approach maybe is just to write your own test harness. it's trivial 
to write a minimal system, which is then a solid basis for the enhancements 
which are best for you.

tom arnall
arcata


-- 
http://mail.python.org/mailman/listinfo/python-list