Writeing new files

Emile van Sebille emile at fenx.com
Fri Aug 31 05:18:34 CEST 2001


Again, you're problem is with Create.  Try this code:

class Create:
    def __init__(self,val):
        self.val = val
    def __repr__(self):
        return repr(self.val)

name= Create('Name')

print '%s' % name

class Create:
    def __init__(self,val):
        self.val = val
    def __str__(self):
       return str(self.val)

name= Create('Name')

print '%s' % name

If Create is coming out of Blender, look in dir(name) to see if the name is
already an attribute.  I don't have Blender so I can't check it for you.  If
there's a Blender mailing list, try it as well.

HTH,

--

Emile van Sebille
emile at fenx.com

---------
"eber kain" <eberkain at earthlink.net> wrote in message
news:b5f84cf8.0108301837.36768171 at posting.google.com...
> andy_todd at spam.free.yahoo.com (Andy Todd) wrote in message
news:<Xns910DA9411E997andytoddspamfreeyaho at 203.109.250.24>...
> > Steve challenged, I had to respond ;-)
> >
> > "Steve Holden" <sholden at holdenweb.com> wrote in
> > <x0cj7.71700$54.3813230 at e420r-atl1.usenetserver.com>:
> >
> > >"eber kain" <eberkain at earthlink.net> wrote in message
> > >news:b5f84cf8.0108291125.1fffe46b at posting.google.com...
> > >> When i run this code
> > >>
> > >> name= Create('Name')
> > >> file= open('%s.btv' % name, "w")
> > >>
> > >> i end up with a file name that has a set of ' ' around the name like
> > >> so
> > >>
> > >> 'Name'.btv
> > >>
> > >> How can i fix this?
> >
> > >>>> name = Create('Name')
> > >Traceback (innermost last):
> > >  File "<interactive input>", line 1, in ?
> > >NameError: There is no variable named 'Create'
> > >
> > >I think we need a little more context before we can be of much help,
> > >despite this newsgroup's famous psychic debugging abilities. That is,
> > >unless someone out there wants to prove me wrong ...
> >
> > My lack of pyschic ability lead me to;
> > >>> filename1='''Name'''
> > >>> print '%s.btv' % filename1
> > Name.btv
> >
> > So that obviously works ... hmmm
> > Then I tried;
> > >>> filename2="'Name'"
> > >>> print '%s.btv' % filename2
> > 'Name'.btv
> >
> > Bingo! This is more than likely causing your problem. Note the
combination
> > of double and single quotes. They are guaranteed to trip up the unwary.
> >
> > Obviously I skipped
> > >>> filename0='Name'
> >  because I new that would give us;
> > >>> print '%s.btv' % filename0
> > Name.btv
> >
> > The moral of the story? Try to avoid encoding quotation marks in you
> > character strings at all costs. If you do need to preserve them, be
very,
> > very careful.
> >
> > For what its worth my rule of thumb is;
> >
> > Use ' for ordinary characters,
> > Use " if you *must* include quotation marks within the string (then
watch
> > out when evaluating these strings)
> >
> > Oh, and test like buggery as well ;-)
> >
> > If you want the total lowdown on string literals (for some reason I only
> > have the 2.0.1 reference but I don't believe it has changed), look in
the
> > manual;
> >
> > http://www.python.org/doc/2.0.1/ref/strings.html
> >
> > >
> > >About all I can tell you is that you are putting quotes in somewhere
> > >they aren't required, but you'd probably wirked that out.
> > >
> > >Eber, please post the whole program, or if it's too long (say, > 100
> > >lines) or a secret then write a shorter program to demonstrate the bug
> > >and post that.
> >
> > Here, here. Although, hopefully the miniscule examples above will lead
you
> > to solve your problem.
> >
> > >
> > >regards
> > > Steve
> > >--
> > >http://www.holdenweb.com/
> > >
> >
> > Regards,
> > Andy
>
> Ok, here is the top part of my code, its working up to 400 lines, so just
the top.
>
> This is being used in blender, a freeware 3d modeling tool.
>
>
>
>
>
>
>
> import Blender
> from Blender import NMesh
> from Blender.Draw import *
> from Blender.BGL import *
>
> # General
>
> name= Create('Name')
> shortname= Create('Short Name')
> type= Create(1)
>
>
> def export():
> file= open('%s.btv' % name,"w")
> # name and short name
> file.write("%s\n" % name)
> file.write("%s\n" % shortname)
>
> # charcteristics
> file.write("%s " % type)
> ............




More information about the Python-list mailing list