Re: Tkinter button doesn't appear in OS X

2006-12-12 Thread crystalattice
I downloaded your file and got it working.  Thanks for the hint and the
code.  I really appreciate it.

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


Re: Tkinter button doesn't appear in OS X

2006-12-12 Thread crystalattice

Kevin Walzer wrote:
> When you run your program on OS X, there should be a menu item next to
> the Apple menu that says "about Tcl/Tk," which you access from the
> "Python" menu item. That will give you the version number.
>
> Python 2.3.5 and Tcl/Tk 8.4.7 ship with OS X 10.4. Python 2.4.2 is a
> separate installation, but probably accesses the system Tcl/Tk unless
> you have installed a more recent version. Using the official Mac build
> of Python 2.5 will update your Python, but not Tcl/Tk--you'll need to
> install something more recent.
>
> You can install ActiveTcl for a "batteries-included" distro of
> Tcl/Tk--it has the latest and greatest of everything. Or, you can
> install a slightly older (8.4.13) version of Tcl/Tk at
> http://tk-components.sourceforge.net. (This is a version of Tcl/Tk Aqua
> that I use in my own programs and I made the build available for others
> to use.)
>
> Hope that helps,
> Kevin
>
> --
> Kevin Walzer
> Code by Kevin
> http://www.codebykevin.com
Thanks for the info.  It looks like it should work.  I wasn't aware
that OS X is so "compartmentalized"; makes it a pain in the butt to
develop on sometimes.

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


Re: Tkinter button doesn't appear in OS X

2006-12-11 Thread crystalattice

Kevin Walzer wrote:
>
> What version of Tk are you running? I've seen this bug on old versions
> of Tk (i.e. 8.4.7) but not recently.
>
> --
> Kevin Walzer
> Code by Kevin
> http://www.codebykevin.com

I'm using Python 2.4.2, which I believe is the default version for OS
X.  How do I check the Tk version?  Can I force my programs to use a
different version of Python, e.g. if I installed Python 2.5?

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


Re: Advice for a novice on making ambitious cross-platform GUI app

2006-09-27 Thread crystalattice

John Salerno wrote:
> crystalattice wrote:
>
> > I'm working on making an
> > RPG from scratch and I'm the only one doing it, but I'm learning a lot
> > and just keep asking questions.
>
> Intriguing. Any tips on how you are going about learning the game
> programming aspects of doing this? I took a look at PyGame, but it
> seemed a little over my head.
Currently I'm mostly just learning the various aspects of Python and
OOP.  It wasn't until a few months ago that OOP finally "clicked" for
me; before that I only did procedural programming.

My current programming for my game is just character generation, which
is relatively easy.  I'm currently trying to decide on how to best save
the data (pickle, database, standard file, etc.) so it's not like I've
created a game engine or anything real difficult.

Last month I found a book called "Game Programming with Python".  I'm
only in the fourth chapter but it appears to have good insight.  It
discusses the normal parts of game programming, like audio, graphics,
game engine, etc. while also talking about when and where to use
Python, such as just as a game script or how to write the whole thing
in Python.

I'm finding it very interesting, especially since it talks about
various libraries (such as PyGame) to help out your programming chores.
 If you're interesting in using Python in any way with games, I'd
recommend getting it.

On a side note, I found it for "free" at a place called ebrary
(http://shop.ebrary.com).  It only costs $5 to register but you can
"check out" as many books as you want.  The $$ is  in case you want to
copy or print from the books; it's a  deal w/ the publishers so they
can still get some money from the books.

ebrary also has many other game programming books, such as AI
development, "The Indie Game Development Survival Guide", 3d
programming, etc.  It's a good site if you want to look at a book
before you buy it.

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


Re: Advice for a novice on making ambitious cross-platform GUI app

2006-09-26 Thread crystalattice
Chelonian wrote:
> Can Python *alone* produce something like what I've described?  Or
> would I have to have some parts written in C?  Or is Python really not
> best-suited to these needs?

As already mentioned, Python is capable of doing nearly any type of
program.  As long as you don't need low-level functionality (like
manual memory manipulation or device drivers) it should be fine.  With
computers nowadays, I don't think the speed hit will be that bad, but
YMMV.

> Is using SPE with wxGlade a good choice?  What about Boa Constructor?

I use SPE for all of my coding and have very few complaints.  I've
never used Boa so I don't know how well it will do.  One of the reasons
I chose SPE is because of the integrated wxGlade; because it's still in
beta, SPE sometimes crashes when using it so be aware of that.

> Is it something one person could do over the course of a year or so,
> working say 10 hours a week on it?  Or is this really out of reach of
> anyone other than a hardcore programmer or even a team of them?

Given enough time, one person can do nearly any programming task.  If
you have a deadline to complete it, then you probably really want
someone with more experience to help you.  If you don't mind reading
books and learning as you go, then go for it.  I'm working on making an
RPG from scratch and I'm the only one doing it, but I'm learning a lot
and just keep asking questions.

> If I write it using Python 2.5 and wxPython, do I have to use py2app or
> something to create an executable and necessary library files so it
> will run on Mac?  (Because of wxPython's libraries, which the Mac
> won't have?).

If you want to make an executable for the Mac, then you'll need py2app.
 If you want it to run like a normal Python script, then the user can
just call it from the command line.

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


Re: Looking for opinions

2006-09-23 Thread crystalattice

Bruno Desthuilliers wrote:
> I have few experience with RPG softwares, but if your "domain" logic si
> anything more than trivially complex, it's always better to keep it as
> decoupled as possible from the user interface (unless of course the user
> interface actually is the domain !-). FWIW, this doesn't prevent you
> from using a web framework as the front-end...

Sorry, but what exactly do you mean by "domain"?  I've heard of domains
before but I think my interpretation is different from yours in this
respect.  Is this like the back-end code or do you mean something else?

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


Looking for opinions

2006-09-22 Thread crystalattice
I've been working on a game for several months but now I'm thinking I
may be going about it the wrong way.  It's an online RPG designed to
recreate a pen & paper session, kind of like the OpenRPG project.

Originally I planned on doing something like OpenRPG with a Python app
that contained everything.  But I'm thinking that approach may not be
necessary.  Since the game would use the Internet for everyone to play
it, maybe it would be easier/better to just make a web app w/ Python
underpinnings.  That way I wouldn't have to worry about making a Python
GUI and other "standalone" features that would have to be installed on
each players computer; they could just interact via a web browser and
IM.

The code I've made so far is just a text-based "proof-of-concept" for
the character generation to make sure I have the logic correct.  I've
only been designing a GUI for the last few weeks and trying different
things like Tkinter and wxPython, so building a whole web app won't set
me back any.

With that in mind, I'm looking for opinions from more experienced
programmers.  For this project, do you think I should continue w/
building a stand alone program or do you think making something out of
Django/Turbogears would be better?

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


Re: Timeline for Python?

2006-09-01 Thread crystalattice
I'd write for 2.4, even though 2.5 should be coming out "shortly".
There aren't many significant changes to the whole language between 2.4
and 2.5.  Probably the best thing is write for 2.4 and have a sidenote
stating where 2.5 operates differently.

The Python 3 timeline is almost a moving target right now; personally,
I don't think it will be out before next winter.  Maybe a beta but I
doubt the full version.

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


Re: AttributeError: 'Attributes' object has no attribute 'saveFile'

2006-09-01 Thread crystalattice

[EMAIL PROTECTED] wrote:
> Hi
>
> Sounds like you've got a wizard-type interface thing happening.
> I haven't used wxGlade but I have done similar things in GTK several
> times.
>
> Try putting all the windows in a notebook widget with hidden tabs.
> Put the 'Next Page' button and the filename outside the notebook.  This
> makes the filename always available and the 'Next Page' button would
> just switch pages in the notebook widget.
>
> Hope this is helpful
>
> Cheers
> Tim
Sounds simple enough.  Of course, we all know the difference between
theory and practice.  I think I rember seeing a wizard-type interface
in the wxGlade tutorial.  I'll take a look at that to.  Thanks for the
tip.

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


AttributeError: 'Attributes' object has no attribute 'saveFile'

2006-08-31 Thread crystalattice
Not sure how to explain, but I'll try my best.  I'm making a GUI with
wxGlade.  The GUI has windows that open when the "Next Page" button is
pushed; the button also pickles the information that is input into the
frame at the same time.  The saveFile name is autocreated based on the
data entered by the user in the first frame.

Each frame that is created is a new class, e.g. the first frame that
opens is "CharInfo", which opens the frame "Attributes".  The pickling
works for the first frame but doesn't work for the ones after.
Apparently the saveFile attribute I created in the "CharInfo" class
isn't carried through to "Attribures", even though it's supposed to be
a subclass.

I've tried several different ways to get it working, such as expressly
calling CharInfo.saveFile, calling CharInfo.pushedButton.saveFile
(saveFile is part of the pushedButton method), calling
Attributes.saveFile, and calling self.saveFile.  Every time, I get the
AttributeError message stating saveFile is not an attribute of either
the classes or any function.

The reason I want to keep the same saveFile attribute through every
class is because the initial button in CharInfo creates the file save
name and path; I'd like to have it carried through the rest of the
classes so each new frame will save it's information to the same file.

Is there a way to keep the saveFile "live" throughout the entire
program or would it be better to create a "choose a filename" window at
the end of the program?  If the latter, is there anything special I
need to know so the information in each class is pickled correctly?

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


Re: wxGlade and __init__

2006-08-26 Thread crystalattice
Tim N. van der Leeuw wrote:
> crystalattice wrote:
> > I'm making a GUI for a console-based program I just wrote.  I figured
> > it would be mostly straight forward to convert it over in wxPython but
> > now I'm confused.
> >
>
> Hi Crystalattice,
>
> One thing you could do is make your original console-program a subclass
> of the wxGlade-generated GUI.
>
> Another thing you could do is to keep the original console program code
> intact, and to make the GUI program create an instance of your original
> console program, and call it.
>
> You can modify to some extent the code generated by wxGlade, or you can
> subclass it (which is what I do, following advice found on this list).
>
> Good luck,
>
> --Tim

I think I get it.  I'll mess with it and see what happens.  Thanks.

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


wxGlade and __init__

2006-08-25 Thread crystalattice
I'm making a GUI for a console-based program I just wrote.  I figured
it would be mostly straight forward to convert it over in wxPython but
now I'm confused.

In my console program, I have __init__ making the dictionaries et al.
and then my methods will populate them.  However, when I use wxGlade
under SPE to make the GUI, wxGlade makes it's own __init__.  I know not
to add anything to this section because it's written over everytime I
make changes in wxGlade.

How do I reconcile having the auto created __init__ from wxGlade and
the __init__ I want to use from my console version?

Here's an example of my console program:

def __init__(self):
"""Constructor to initialize each data member to zero."""

#---Attribute info
self.attrib = 0
self.attrib_dict = self.default_attribs.copy()  #instance
version
self.setAttribute("str")
self.setAttribute("intel")
self.setAttribute("build")
self.setAttribute("char")
self.setAttribute("will")
self.setAttribute("throw")
self.setAttribute("mass")
self.setAttribute("load")
self.setAttribute("dex")
self.coreInitiative = 0

#---Create attributes---
def setAttribute(self, attr):
"""Generate value for an attribute, between 2 and 20."""

#---Get secondary attributes
if attr == "throw":
   self.attrib_dict[attr] = self.attrib_dict["str"] * 2
#meters
elif attr == "mass":
self.attrib_dict[attr] = (self.attrib_dict["build"] * 5) +
15 #kg
elif attr == "load":
self.attrib_dict[attr] = (self.attrib_dict["str"] +
self.attrib_dict["build"]) #kg
#---Get core attributes
else:
self.attrib_dict[attr] = multiDie(2, 2)   #2d10

Here's the code created by wxGlade:

class Attributes(wx.Frame):
def __init__(self, *args, **kwds):
# begin wxGlade: Attributes.__init__
kwds["style"] = wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
self.panel_2 = wx.Panel(self, -1)
self.btnAttributes = wx.Button(self.panel_2, -1, "Get
Attributes")
self.lblAge = wx.StaticText(self.panel_2, -1, "Age:")
self.txtAge = wx.TextCtrl(self.panel_2, -1, "")
self.lblChar = wx.StaticText(self.panel_2, -1, "Charisma:")
self.txtChar = wx.TextCtrl(self.panel_2, -1, "")
self.lblStr = wx.StaticText(self.panel_2, -1, "Strength:")
self.txtStr = wx.TextCtrl(self.panel_2, -1, "")
self.lblBuild = wx.StaticText(self.panel_2, -1, "Build:")
self.txtBuild = wx.TextCtrl(self.panel_2, -1, "")
self.lblIntel = wx.StaticText(self.panel_2, -1,
"Intelligence:")
self.txtIntel = wx.TextCtrl(self.panel_2, -1, "")
self.lblThrow = wx.StaticText(self.panel_2, -1, "Throw Range:")
self.txtThrow = wx.TextCtrl(self.panel_2, -1, "")
self.lblWill = wx.StaticText(self.panel_2, -1, "Willpower:")
self.txtWill = wx.TextCtrl(self.panel_2, -1, "")
self.lblMass = wx.StaticText(self.panel_2, -1, "Mass:")
self.txtMass = wx.TextCtrl(self.panel_2, -1, "")
self.lblDex = wx.StaticText(self.panel_2, -1, "Dexterity:")
self.txtDex = wx.TextCtrl(self.panel_2, -1, "")
self.lblLoad = wx.StaticText(self.panel_2, -1, "Load:")
self.txtLoad = wx.TextCtrl(self.panel_2, -1, "")
self.lblHP = wx.StaticText(self.panel_2, -1, "Hit Points")
self.lblHead = wx.StaticText(self.panel_2, -1, "Head:")
self.txtHead = wx.TextCtrl(self.panel_2, -1, "")
self.lblTorso = wx.StaticText(self.panel_2, -1, "Torso:")
self.txtTorso = wx.TextCtrl(self.panel_2, -1, "")
self.lblRArm = wx.StaticText(self.panel_2, -1, "Right Arm:")
self.txtRArm = wx.TextCtrl(self.panel_2, -1, "")
self.lblLArm = wx.StaticText(self.panel_2, -1, "Left Arm:")
self.txtLArm = wx.TextCtrl(self.panel_2, -1, "")
self.lblRLeg = wx.StaticText(self.panel_2, -1, "Right Leg:")
self.txtRLeg = wx.TextCtrl(self.panel_2, -1, "")
self.lblLLeg = wx.StaticText(self.panel_2, -1, "Left Leg:")
self.text_ctrl_18 = wx.TextCtrl(self.panel_2, -1, "")
self.btnNext2 = wx.Button(self.panel_2, -1, "Next Page")

self.__set_properties()
self.__do_layout()
# end wxGlade

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


Re: Best Editor

2006-08-25 Thread crystalattice

JAG CHAN wrote:
> Friends, I am trying to learn Python.
> It will be of great help to me if you let me know which one would be best
> editor for learning Python.
> Plese note that I would like to have multiplatform editor which will be
> useful for both LInux and Windows XP.
> Thanks.

My choice is SPE.  It has wxGlade built-in for easy creation of
wxPython GUIs, syntax error highlighting, etc.  It's cross-platform
too.  It does require installing wxPython, though that's not difficult.

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


wxPython default radiobox choice

2006-08-24 Thread crystalattice
In my GUI app, I have a radio box allowing the user to pick his/her
gender.  When I click a button, I'd like the radio box to tell the
program which choice is marked.  I can get it to work when I manually
pick a choice but I get an error when the choice is left at the default
value, which is "Male".

I have the radio box tied to an event to "see" when a choice is made,
but how does it work if the person just leaves the default value?  I've
looked at the wxPython demo but the radio box actions only work for
changing values.

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


Re: wxPython default radiobox choice

2006-08-24 Thread crystalattice

Laszlo Nagy wrote:
> crystalattice írta:
> > In my GUI app, I have a radio box allowing the user to pick his/her
> > gender.  When I click a button, I'd like the radio box to tell the
> > program which choice is marked.  I can get it to work when I manually
> > pick a choice but I get an error when the choice is left at the default
> > value, which is "Male".
> >
> > I have the radio box tied to an event to "see" when a choice is made,
> > but how does it work if the person just leaves the default value?  I've
> > looked at the wxPython demo but the radio box actions only work for
> > changing values.
> >
> >
> I'm not sure if I understood your problem. You can call the
> wxRadioBox.GetSelection method anytime to get the current value.
> If you need that value very often (e.g. thousand times per sec) then you
> can "shadow" the default value in an instance variable.
>
> Example (untested):
>
>
> class MyClass(wx.Frame):
>  """In this frame, you can use the curchoice variable after
> construction."""
> def __init__(self):
># ... create your frame here...
>r =self.radio = wx.RadioBox(self,-1,choiches=['One','Two','Three'])
># Set default value
>r.SetSelection(0) # This does not cause a
> wxEVT_COMMAND_RADIOBOX_SELECTED event to get emitted.
>self.curchoice = 0
># Bind the event
>r.Bind(
> wx.EVT_COMMAND_RADIOBOX_SELECTED,
> self.OnRadioChanged,
> r
> )
>
>
> def OnRadioChanged(self,event):
>self.curchoice = self.radio.GetSelection()
># Do whatever you want here...
>event.Skip()

Thanks for the response.  I got it working now.  I was trying to bind
the radio box to an event, rather than just calling GetSelection().  I
thought I needed to bind it to make it work (based on the wxPython demo
code).

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


Re: do people really complain about significant whitespace?

2006-08-07 Thread crystalattice
infidel wrote:
> Where are they-who-hate-us-for-our-whitespace?  Are "they" really that
> stupid/petty?  Are "they" really out there at all?  "They" almost sound
> like a mythical caste of tasteless heathens that "we" have invented.
> It just sounds like so much trivial nitpickery that it's hard to
> believe it's as common as we've come to believe.

Actually, some of the guys I work with complained about Python when
they first had to learn it for our Zope server.  One of them is an
old-school Unix guy who spent the last 20+ years doing procedural
languages with funky syntax, like C.  The other one is a VB.NET junkie
who I don't think has much experience outside of MS languages, except
maybe Java.

One of the complaints they had for the first few weeks was the white
space issue and the fact Python doesn't have brackets or semicolons.
Obviously they learned to "deal with it" but they sure made it seem
like it was a painful transition.  I think the biggest pain was the
fact that they are forced to indent their code now so they can't be
lazy anymore.

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


Re: Which KDE IDE for Python?

2006-08-06 Thread crystalattice

Bart Ogryczak wrote:
> Hi,
> Rigth now I'm using two IDEs for Python, KDevelop and Eric. Both have
> drawbacks. KDevelop is a multilanguage IDE, and doesn't really have
> anything special for Python. There's no Python debugger, no PyDOC
> integration, it's class browser doesn't display attributes. On the
> other side there's Eric, which is made just for Python. But.. it
> doesn't integrate with KDE, doesn't support remote files (fish://,
> ftp:// etc.). Does anyone know a better IDE for Python, that'll
> integrate nicely with KDE?

You might try SPE (http://stani.be/python/spe/blog/).  I don't know if
it integrates w/ KDE but it's expressly for Python.  From the site:

"Spe is a free python IDE with auto indentation & completion, call
tips, syntax coloring & highlighting, UML diagrams, class explorer,
source index, auto todo list, sticky notes, pycrust shell, file
browsers, drag&drop, context help, Blender support, ... Spe ships with
Python debugger (remote & encrypted), wxGlade (gui designer), PyChecker
(source code doctor) and Kiki (regex console)."

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


Re: OS independent files

2006-08-03 Thread crystalattice

Simon Forman wrote:
> Google groups has a very good search.

That's what I'm using, and it still came up with 600-900 results
depending on my search terms.

> Try os.path.expanduser('~') (in
> http://docs.python.org/lib/module-os.path.html) or you could just look
> up the HOME environment variable in os.environ, but I don't know if
> windows sets this correctly in all cases.
>
> (os.environ is documented in
> http://docs.python.org/lib/os-procinfo.html)
> 
> Peace,
> ~Simon

I'll try that.  Thanks.

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


OS independent files

2006-08-03 Thread crystalattice
I'm sure this has been addressed before but it's difficult to search
through several thousand postings for exactly what I need, so I
apologize if this a redundant question.

I've figured out how to use os.path.join to make a file or directory
location prior to pickling something to it.  But I have a question
about it.  In Windows I can make a file with this:

os.path.join("C:", "myfiles", "myfile.dat")

If I want to make sure the file/directory is made in a user's home
directory (e.g. /home/users/path/to/file) but also compatible w/
Windows, how would I rewrite this (if required)?

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


Re: Pickle vs XML for file I/O

2006-08-02 Thread crystalattice
Marc 'BlackJack' Rintsch wrote:
> In <[EMAIL PROTECTED]>, crystalattice
> wrote:
>
> >> What are the problems you fear when using `shelve` by the way?
> >>
> > The ideas I got about shelve are mostly due to this thread:
> > http://tinyurl.com/lueok.  There weren't any other threads
> > contradicting the information so I figured it has merit.
>
> Main complaint seemed to be that data might be corrupted when the program
> terminates "abnormal" while writing the data.  You have the very same
> problem with pickle or XML serialization.  If the program gets interrupted
> after only half the data is written to disk you lose information.
>
> > Actually, not many people seem to use shelve very much; pickle is used
> > more often so I decided to give it a try and see how it works for me.
>
> They have a slightly different use case.  `pickle` stores single objects
> and `shelve` is a sort of persistent dictionary that maps strings to
> objects.  So if you want to save a party of characters and load them back
> together than pickle a list with those characters.  If you want a database
> of many characters the player can choose from than you might want to store
> them in a `shelve`.
>
> Ciao,
>   Marc 'BlackJack' Rintsch

Okay, that makes sense.  I was able to figure out how to pickle
yesterday.  It's not as hard as I thought (obviously); my confusion
originally came from thinking I needed to pickle each item of the class
separately but I realized that pickling a class instance worked too.

One other question though (hope it doesn't sound silly/stupid).  Your
suggestion to "pickle a party" using a list has me thinking:  can a
list store class instances?  I imagine it can though I don't know if
there may be bad juju if I tried, like data corruption or errors or
something.  I've only been using classes for a few weeks so I don't
know very much about them.

For example, if I wanted to store a party of characters, rather than
pickling each person separately could I put each character instance in
a list then pickle the list?  Like this:

char1 = Character()
char2 = Character()
char3 = Character()
party = [char1, char2, char3]
file = open("partyfile.dat", "w")
pickle.dump(party, file)

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


Re: Programming newbie coming from Ruby: a few Python questions

2006-08-01 Thread crystalattice
[EMAIL PROTECTED] wrote:
> Hi all. I've been try to learn ruby for a few months but I'm about
> ready to give up. The available books either assume a programming
> background, or are out of date. Anyway, I think python may suit me more
> due to its 'theres one way to do it' philosophy (hope the quote is
> right)! Another quote that I liked was:
>
>  'Clever is not considered a compliment in Python.' (don't know where I
> read that...)
>
> In Ruby, there are many ways to do the same thing and cleverness seems
> to be held in high regard. These attitudes are not too helpful for
> beginners in my experience. Anyway, enough waffle.
>
> What books and tutorials are recommended to learn Python? The tutorial
> that comes with Python is great and has given me a good overview but I
> think I'd benefit from some programming projects, now I have a little
> understanding of how Python works.
>
> Ideally, I'd like a whole series of projects where I'm walked through
> how to go about writing real Python. The way I look at it, nobody
> learnt to build a house just from reading about building materials!
>
> Any other tips for getting up to speed with Python fairly quickly will
> be greatly appreciated.
>
> If anyone can help, thanks very much
Of course there's the O'Reilly set:  Learning Python, Programming
Python, Python in a Nutshell, etc.  I found them great for an overview
and capabilities look at the language, but like you I prefer a more
project-oriented approach.  They are good to have on your reference
shelf though.

The best book I've found for "teaching" you the language is from Deitel
and Deitel:  Python, How to Program.  It's outdated in that is uses
Python 2.2 but the vast majority of concepts still apply; it does
mention when certain features are deprecated so you shouldn't have a
problem.

It is a college textbook so it goes into detail in many areas plus it
has the usual quizes, chapter summaries, and tests.  The tests are
usually easy enough to figure out but with enough difficulty to make
them challenging.  It covers a wide range of topics, from CGI and XML
to multithreading and networking.

It's normally $90-$100 but you should be able to find it used for <$40.

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


Re: Pickle vs XML for file I/O

2006-08-01 Thread crystalattice
Simon Hibbs wrote:
> I've recently gone through a similar evaluation of my options for
> persisting data. Object serialization to pickles or XML is a very easy,
> quick way of persisting data but it does have drawbacks. I'm not a
> professional developer, so if there are errors in my analysis, I'd love
> to be corrected.
>
> Suppose you make some changes to the object format - adding some new
> attributes or properties. Suddenly your existing test data is useless.
> At least with XML you can edit the files by hand to add dummy data, but
> with pickles that's not an option and even with XML it's a painful and
> error prone process.
>
> Idealy you need to be able to browse and edit your saved data outside
> the main program, to scan for errors, fix them manualy and easily
> update your data structure as the application data model grows and
> changes.
>
> There are good reasons why relational databases are the default data
> store for many professional applications because you can parse and edit
> the data very easily using external tools. Personaly I'd go with
> SQLite. It's soon to be a part of the Python standard library with 2.5
> and is very compact. It can be a lot more work than just serializing
> automaticaly, but there are toolkits such as SQLObject and SQL Alchemy
> that can automate this as well.
>
> Best regards,
>
> Simon Hibbs
That's a good idea.  I may implement that later.  Right now though I'm
mostly doing this as a hobby and an open-source project, so I don't
want to add too much extra to the project.  I want to see what the base
Python language is capable of before I start using other toolkits and
libraries.  I just barely got comfortable with the OOP "mindset" so
even working w/ classes and objects is still a struggle sometimes.

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


Re: Pickle vs XML for file I/O

2006-08-01 Thread crystalattice

Marc 'BlackJack' Rintsch wrote:
> In <[EMAIL PROTECTED]>, crystalattice wrote:
>
> > On Mon, 31 Jul 2006 14:35:39 -1000, Simon Forman <[EMAIL PROTECTED]>
> > wrote:
> >
> >> What kind of trouble were you having with pickle?
> >
> > It's mostly a combination of things (I hope you can follow my logic).
> > First, to use "good programming practice", I want to implement a
> > try/except block for opening the pickle file.  But I can't figure out if
> > this block should be included outside the classes, included in just the
> > base class, or if the base and subclasses need it; I'm leaning to putting
> > outside the classes as a global method.
>
> That's not a problem with pickle but where you think a potential IO error
> is handled best.  Ask yourself if you can do something sensible at the
> point where you catch an exception.  If you don't know what to do with it,
> don't catch it and just let it propagate.
>
> > When pickling a class instance, is the pickle statement placed within the
> > class (say, at the end of the class) or is it where the instance is
> > created, such as a test() method?
>
> `pickle.dump()` and `pickle.load()` are not statements but just functions.
> And you should place a call where you actually want to save or load
> instances in your program flow.
>
> > Plus, to modify data in a class, do I have to unpickle the whole thing
> > first or is there a way to modify the data while it's pickled?  Actually,
> > I think I can answer that last question:  a character instance, having
> > been created, will stay resident in memory until the player quits,
> > character dies, or otherwise is no longer needed.  At that point the
> > character instance should be pickled (if necessary) to disk; pickle
> > shouldn't be used while data modification is required and the class
> > instance is "active", correct?
>
> Yes that's correct.  It wouldn't be different with XML.
>
> > I also remember reading on a thread here that pickle sometimes has issues
> > when used with classes, which makes me hesitant to pickle an entire class
> > instance.  That's why I thought XML may be safer/better.
>
> You can't pickle everything.  Files for example are unpickleable and you
> can't pickle code so pickling classes is not that useful.
>
> An advantage of `pickle` is that it's in the standard library and ready to
> use for serialization.  To get an XML solution you must either write your
> own serialization code or use a 3rd party library.
>
> What are the problems you fear when using `shelve` by the way?
>
> Ciao,
>   Marc 'BlackJack' Rintsch
The ideas I got about shelve are mostly due to this thread:
http://tinyurl.com/lueok.  There weren't any other threads
contradicting the information so I figured it has merit.  Actually, not
many people seem to use shelve very much; pickle is used more often so
I decided to give it a try and see how it works for me.

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


Re: Pickle vs XML for file I/O

2006-07-31 Thread crystalattice
On Mon, 31 Jul 2006 14:35:39 -1000, Simon Forman <[EMAIL PROTECTED]>  
wrote:

> crystalattice wrote:
>> I'm creating an RPG for experience and practice.  I've finished a
>> character creation module and I'm trying to figure out how to get the
>> file I/O to work.
>>
>> I've read through the python newsgroup and it appears that shelve
>> probably isn't the best option for various reasons.  This lead me to
>> try messing w/ pickle, but I can't figure out how to use it with
>> classes.  I've found many examples of using pickle w/ non-OOP code but
>> nothing that shows how to use it w/ classes, subclasses, etc.  I've
>> read the documentation but it doesn't explain it well enough for me.
>>
>> Then I started thinking perhaps I'm going about it wrong.  My current
>> thought is to save an instance of each character so all the info (name,
>> skills, hit points, etc.) is stored in one place.  But looking at
>> OpenRPG made me think that perhaps using XML to store the information
>> would be better.  Each character could have a separate XML file, though
>> I don't know how it would work if many NPC's are required.
>>
>> I guess my question is, what are the benifits of getting pickle to work
>> w/ my classes vs. converting all the character data into XML and just
>> writing that to a file?  Since most of the data would need to be
>> modified often, e.g. hit points, is one storage format better than the
>> other?  Can you even modify data if it's been pickled w/o having to
>> unpickle it, change the data, then repickle it?
>
> Um, there's nothing tricky to using pickle with classes:
>
> |>> import pickle
> |>> class foo: pass
> |>> f = foo()
> |>> pstr = pickle.dumps(f)
> |>> pstr
> '(i__main__\nfoo\np0\n(dp1\nb.'
> |>> newf = pickle.loads(pstr)
> |>> newf
> <__main__.foo instance at 0xb664690c>
>
> Pickle is simple and should work "out-of-the-box".  I wouldn't mess
> with XML until I was sure I needed it for something.
>
> What kind of trouble were you having with pickle?
>
> Peace,
> ~Simon
>
It's mostly a combination of things (I hope you can follow my logic).   
First, to use "good programming practice", I want to implement a  
try/except block for opening the pickle file.  But I can't figure out if  
this block should be included outside the classes, included in just the  
base class, or if the base and subclasses need it; I'm leaning to putting  
outside the classes as a global method.

When pickling a class instance, is the pickle statement placed within the  
class (say, at the end of the class) or is it where the instance is  
created, such as a test() method?

Do I even need to bother with having the try/except block and pickle  
statements in the character generation module or should I have a separate  
module that does the file I/O, such that it opens the new file, calls the  
character module and makes a new instance, then pickles it?

Plus, to modify data in a class, do I have to unpickle the whole thing  
first or is there a way to modify the data while it's pickled?  Actually,  
I think I can answer that last question:  a character instance, having  
been created, will stay resident in memory until the player quits,  
character dies, or otherwise is no longer needed.  At that point the  
character instance should be pickled (if necessary) to disk; pickle  
shouldn't be used while data modification is required and the class  
instance is "active", correct?

I also remember reading on a thread here that pickle sometimes has issues  
when used with classes, which makes me hesitant to pickle an entire class  
instance.  That's why I thought XML may be safer/better.


-- 
Python-based online RPG in development based on the Colonial Marines from  
"Aliens": http://cmrpg.sourceforge.net

Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
-- 
http://mail.python.org/mailman/listinfo/python-list


Pickle vs XML for file I/O

2006-07-31 Thread crystalattice
I'm creating an RPG for experience and practice.  I've finished a
character creation module and I'm trying to figure out how to get the
file I/O to work.

I've read through the python newsgroup and it appears that shelve
probably isn't the best option for various reasons.  This lead me to
try messing w/ pickle, but I can't figure out how to use it with
classes.  I've found many examples of using pickle w/ non-OOP code but
nothing that shows how to use it w/ classes, subclasses, etc.  I've
read the documentation but it doesn't explain it well enough for me.

Then I started thinking perhaps I'm going about it wrong.  My current
thought is to save an instance of each character so all the info (name,
skills, hit points, etc.) is stored in one place.  But looking at
OpenRPG made me think that perhaps using XML to store the information
would be better.  Each character could have a separate XML file, though
I don't know how it would work if many NPC's are required.

I guess my question is, what are the benifits of getting pickle to work
w/ my classes vs. converting all the character data into XML and just
writing that to a file?  Since most of the data would need to be
modified often, e.g. hit points, is one storage format better than the
other?  Can you even modify data if it's been pickled w/o having to
unpickle it, change the data, then repickle it?

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


Re: Inheritance error: class Foo has no attribute "bar"

2006-07-11 Thread crystalattice
On Sun, 09 Jul 2006 03:51:56 -1000, Steven D'Aprano  
<[EMAIL PROTECTED]> wrote:

> On Sun, 09 Jul 2006 04:24:01 +, crystalattice wrote:
>
>> I've finally figured out the basics of OOP; I've created a basic  
>> character
>> creation class for my game and it works reasonably well. Now that I'm
>> trying to build a subclass that has methods to determine the rank of a
>> character but I keep getting errors.
>>
>> I want to "redefine" some attributes from the base class so I can use  
>> them
>> to help determine the rank. However, I get the error that my base class
>> doesn't have the dictionary that I want to use. I've tried several  
>> things
>> to correct it but they don't work (the base class is called "Character"
>> and the subclass is called "Marine"):
>
> Without seeing your class definitions, it is hard to tell what you are
> doing, but I'm going to take a guess: you're defining attributes in the
> instance instead of the class.
>
> E.g.
>
> class Character():
> def __init__(self):
> self.attrib_dict = {}
>
> attrib_dict is now an instance attribute. Every instance will have one,
> but the class doesn't.
>
> I'm thinking you probably want something like this:
>
> class Character():
> attrib_dict = {}
> def __init__(self):
> pass
>
> Now attrib_dict is an attribute of the class. However, it also means that
> all instances will share the same values! Here's one possible solution to
> that:
>
> class Character():
> default_attribs = {}
> def __init__(self):
> self.attribs = self.default_attribs.copy()
>
> Now there is one copy of default character attributes, shared by the  
> class
> and all it's instances, plus each instance has it's own unique set of
> values which can be modified without affecting the defaults.
>
>
> Hope this clears things up for you.
>
>
Yes, I believe your right (I left my code at work so I can't verify  
directly).  I did initialize attrib_dict in the __init__method, not  
outside it as a class member.  I'll try your suggestion and see what  
happens.  Thanks.


-- 
Python-based online RPG in development based on the Colonial Marines from  
"Aliens": http://www.colonialmarinesrpg.com

Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
-- 
http://mail.python.org/mailman/listinfo/python-list


Inheritance error: class Foo has no attribute "bar"

2006-07-08 Thread crystalattice
I've finally figured out the basics of OOP; I've created a basic character  
creation class for my game and it works reasonably well. Now that I'm  
trying to build a subclass that has methods to determine the rank of a  
character but I keep getting errors.

I want to "redefine" some attributes from the base class so I can use them  
to help determine the rank. However, I get the error that my base class  
doesn't have the dictionary that I want to use. I've tried several things  
to correct it but they don't work (the base class is called "Character"  
and the subclass is called "Marine"):

*explicitly naming the Marine's attribute self.intel =  
Character.attrib_dict["intel"]
*adding Character.__init__(self) to the Marine's __init__(self) method
*changing the self.intel attribute from referencing the Character's  
dictionary to self (based on the assumption that since Marine is a  
subset of Character, it should have it's own attrib_dict being 
created

Nothing seems to work; I still get the error "class Character has no  
attribute "attrib_dict".

I can't see why it's saying this because Character.__init__(self) not only  
has self.attrib_dict = {} but it also calls the setAttribute method  
explicitly for each attribute name. If I do a print out of the dictionary  
just for Character, the attributes are listed.

-- 
Python-based online RPG based on the Colonial Marines from "Aliens" -  
http://www.colonialmarinesrpg.com

Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: first book about python

2006-07-08 Thread crystalattice
On Sat, 08 Jul 2006 14:41:52 -1000, IOANNIS MANOLOUDIS  
<[EMAIL PROTECTED]> wrote:

> I want to learn python.
> I plan to buy a book. I always find printed material more convenient than
> reading on-line tutorials.
> I don't know PERL or any other scripting language. I only know some BASH
> programming. I am looking for a book which will help me get started and
> should contain the foundations. I am not looking for the Python bible.
> Any recommendations?
> Ioannis
>
I started out w/ "Learning Python" from O'Reilly which is good for a nice,  
general overview of the language but I wanted something more detailed.  I  
found the "Python Learn to Program" textbook from Deitel & Deitel to be  
very good.  It's based on v2.2 but it still has practical use.  Since it's  
a text book it has many examples and small problems to try as you develop  
your skills.  If you can find it used online you should be able to get it  
<$40.


-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
-- 
http://mail.python.org/mailman/listinfo/python-list