wxpython - passing arg to wx.app OnInit

2005-10-22 Thread Stuart McGraw
I have a wxPython app, conventionally structured
with a Application class derived from wx.App.
My problem is that the app accepts a command
line argument that must be acted upon within the
OnInit() method of the Application class.  How do
I pass it cleanly from main() into app.OnInit()?  In 
the simplified example below, dbfn is the piece of 
info that is in main() that OnInit() needs to use.
Is a global variable is the only way?  :-(

class Application (wx.App):
def OnInit (self):
oper = Operations (dbfn);
frame = Frame (None, -1, "Title", oper)
self.SetTopWindow (frame)
return True

def main ():
dbfn = sys.args[1]
app = Application (redirect=0)
app.MainLoop ()

Apologies if the answer is (or should be) obvious... this
is my first time using wxWindows and I am still rather new 
to Python.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wxpython - passing arg to wx.app OnInit

2005-10-23 Thread Stuart McGraw

"Peter Hansen" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
> Stuart McGraw wrote:
> > I have a wxPython app, conventionally structured
> > with a Application class derived from wx.App.
> > My problem is that the app accepts a command
> > line argument that must be acted upon within the
> > OnInit() method of the Application class.  How do
> > I pass it cleanly from main() into app.OnInit()?  In 
> > the simplified example below, dbfn is the piece of 
> > info that is in main() that OnInit() needs to use.
> > Is a global variable is the only way?  :-(
> 
> There are various ways, but the simplest is to accept that sys.argv is
> *already* a "global" and just to access it directly from the
> Application's OnInit() method.
> 
> This wiki page demonstrates:
> http://wiki.wxpython.org/index.cgi/UsingCommandLineArguments
> 
> -Peter

I simplied the my code for posting.  In my real program, the
thing being passed is not a command line argument per se,
but the result of signifigant processing dependent on the 
command line argument.  I do not want to repeat that 
processing in the wx.App method.
Would you elaborate on the other ways?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Book

2005-11-13 Thread Stuart McGraw
David Beasley's Essential Python (New Riders).  It's a little dated
now (covers only up to version 2.2) but lucid, consise, well organized.
It restricts itself to Python's syntax and semantics and does not waste
time explaining basic programming concepts.

I made several attempts to learn Python but found the Python docs
pretty poor, and the tutorial books I looked at were incredibly ponderous 
and slow.  It wasn't until I got Beasley's book that I could actual find 
info effectively enough to start actually writing Python code.  I still most
often refer to it in preference to the Python docs.

"David Rasmussen" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
> What is the best book for Python newbies (seasoned programmer in other 
> languages)?
> 
> /David
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Book

2005-11-13 Thread Stuart McGraw
"Stuart McGraw" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
> David Beasley's Essential Python (New Riders).  It's a little dated
> now (covers only up to version 2.2) [...]

Oops, that should be "Beazley", "Python Essential Reference", and 
version 2.1.  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why are there no ordered dictionaries?

2005-11-22 Thread Stuart McGraw

"A.M. Kuchling" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
[...]
> What would improve the Cheese Shop's interface for you?

Getting rid of those damn top level links to old versions.  
Seeing a long list of old versions, when 99% of visitors are
only interested in the current version, is just visual noise, 
and really lame.  Move the old version links onto the page
describing the software.


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


Re: Why are there no ordered dictionaries?

2005-11-22 Thread Stuart McGraw
"Fredrik Lundh" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
> Stuart McGraw wrote
> 
> > > What would improve the Cheese Shop's interface for you?
> >
> > Getting rid of those damn top level links to old versions.
> > Seeing a long list of old versions, when 99% of visitors are
> > only interested in the current version, is just visual noise,
> > and really lame.  Move the old version links onto the page
> > describing the software.
> 
> hmm?  the pypi package automatically hides old versions when
> you post new ones, and it's been that way for ages...
> 
> (which is bloody annoying if you're a package developers, since it
> means that alphas for the next release hides the most recent stable
> version)
> 
> looking at the full index, ZODB seems to be the only package that's
> available in more than just one stable and one development version...

 http://cheeseshop.python.org/pypi?:action=browse&asdf=405
- ClientForm-0.1.17
- ClientForm-0.2.1b
...
- EmPy_3.1
- EmPy_3.1.1
- EmPy_3.2
- EmPy_3.3
...
- FauxIdent-1.1
- FauxIdent-1.2
- FauxIdent-1.2.1
...
Well, it is better than I remember it being a while (year?) ago, my
recollection is that many packages had many, many old versions
listed but now I usualy see only a couple versions.

Hmm, so two versions means one is a development version,
and the other is a stable version?  I did not know that, and did
not see it documented on the site.  I would say documenting 
that would be an interface improvement.

I still think it would be better to have just a package name 
(with current version) listed in the index page(s), and have alternate
versions (old, alpha testing, etc) listed on the package's description
page.

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


Tix example code?

2005-07-13 Thread Stuart McGraw
I am having trouble trying to figure out how to use Tix widgets
in a Python program.  The documentation is scanty and in 
TCL syntax with no examples.  Specifically, I'm trying to use 
a Tix ComboBox widget and haven't been able to figure out 
how to initialize the set of values in the widget's list. 

Does anyone have some (or a pointer to) simple example 
python code that uses TIX widgets (especially the ComboBox)
including subwidgets?  Thanks!...

(And, yes, I looked at the "Mapping Basic Tk into Tkinter "
rosetta stone web page but it did not provide much enlightenment.)
-- 
http://mail.python.org/mailman/listinfo/python-list


bizarre id() results

2005-12-15 Thread Stuart McGraw
The following was cut and pasted exactly (except for the 
# lines which I added after the fact) from an interactive python 
session in a Window 2000 cmd.exe window. 
 
Can somebody please explain to me what the heck is 
going on?!?!  

Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> class A:
...  def m1(self): print "m1"
...  def m2(self): print "m2"
...
>>> a = A()
>>> a.m1()
m1
>>> a.m2()
m2
# ok, both methods work and give the expected results
# so i presume they are different methods.
>>> id(a.m1)
9202984
>>> id(a.m2)
9202984
>>> id(a.m1)==id(a.m2)
True
# Huh? They seem to be the same. 
>>> a.m1 is a.m2
False
# But not the same...
>>> a.m1
>
>>> a.m2
>
# Let's look at them in hex...
>>> hex(id(a.m1))
'0x8c6d28'
>>> hex(id(a.m2))
'0x8e7b48'
# Now they are different.  0x8c6d28->9202984, 0x8e7b48->9337672
>>> id(a.m1)
9337672
>>> id(a.m2)
9337672
# Now they are both equal to the second one.
>>> hex(id(a.m1))
'0x8e7b48'
>>> hex(id(a.m2))
'0x8e7b48'
# in hex too.
>>> id

>>> hex

# just double checking!

Why???  This is so bizarre I'm sure I am doing something
really stupid.


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


Re: bizarre id() results

2005-12-15 Thread Stuart McGraw
"Delaney, Timothy (Tim)" <[EMAIL PROTECTED]> wrote in message news:[EMAIL 
PROTECTED]
and several other people responded with similar information.

[...]
Bound methods are created on the fly. 
[...]

Ahhh!  That was the piece I was missing.  Thank you all!
-- 
http://mail.python.org/mailman/listinfo/python-list


does raw_input() return unicode?

2006-10-09 Thread Stuart McGraw
In the announcement for Python-2.3 
http://groups.google.com/group/comp.lang.python/msg/287e94d9fe25388d?hl=en
it says "raw_input(): can now return Unicode objects".

But I didn't see anything about this in Andrew Kuchling's
"2.3 What's New", nor does the current python docs for 
raw_input() say anything about this.  A test on a MS 
Windows system with a cp932 (japanese) default locale 
shows the object returned by raw_input() is a str() object 
containing cp932 encoded text.  This remained true even
when I set Python's default encoding to cp932 (in 
sitecustomize.py).

So, does raw_input() ever return unicode objects and if
so, under what conditions?

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


Re: does raw_input() return unicode?

2006-10-10 Thread Stuart McGraw

"Martin v. Löwis" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
> Stuart McGraw schrieb:
> > So, does raw_input() ever return unicode objects and if
> > so, under what conditions?
>
> At the moment, it only returns unicode objects when invoked
> in the IDLE shell, and only if the character entered cannot
> be represented in the locale's charset.

Thanks for the answer.

Also, if anyone has a solution for Duncan Booth's attempt
to wrap stdin, I would find it very useful too!

"Duncan Booth" <[EMAIL PROTECTED]> wrote:
> "Stuart McGraw" <[EMAIL PROTECTED]> wrote:
>
> > So, does raw_input() ever return unicode objects and if
> > so, under what conditions?
> >
> It returns unicode if reading from sys.stdin returns unicode.
>
> Unfortunately, I can't tell you how to make sys.stdin return unicode for
> use with raw_input. I tried what I thought should work and as you can see
> it messed up the buffering on stdin. Does anyone else know how to wrap
> sys.stdin so it returns unicode but is still unbuffered?
>
> Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)]
> on win32
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import sys, codecs
> >>> sys.stdin.encoding
> 'cp437'
> >>> sys.stdin = codecs.getreader(sys.stdin.encoding)(sys.stdin)
> >>> raw_input()
> hello world
> still going?
> ^Z
> ^Z
> u'hello world'
> >>>

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

elementtree: line numbers and iterparse

2006-09-12 Thread Stuart McGraw
I have a broad (~200K nodes) but shallow xml file
I want to parse with Elementtree.  There are too many 
nodes to read into memory simultaneously so I use
iterparse() to process each node sequentially.

Now I find i need to get and save the input file line 
number of each node.  Googling turned up a way 
to do it by subclassing FancyTreeBuilder,
(http://groups.google.com/group/comp.lang.python/msg/45f5313409553b4b?hl=en&;)
but that tries to read everything at once.

Is there a way to do something similiar with iterparse()?

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


Re: elementtree: line numbers and iterparse

2006-09-12 Thread Stuart McGraw

"Fredrik Lundh" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
> Stuart McGraw wrote:
> > Now I find i need to get and save the input file line 
> > number of each node.  Googling turned up a way 
> > to do it by subclassing FancyTreeBuilder,
> > (http://groups.google.com/group/comp.lang.python/msg/45f5313409553b4b?hl=en&;)
> > but that tries to read everything at once.
> > 
> > Is there a way to do something similiar with iterparse()?
> 
> something like this could work:
> ...snip...

Indeed it does.  Many thanks!

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


exceptions and unicode

2010-06-16 Thread Stuart McGraw
I am having a problem with exceptions and unicode.

  try: open ('file.txt')
  except IOError, e: pass
  str (e)
  => "[Errno 2] No such file or directory: 'file.txt'"

which is fine but...

  try: open (u'フィイル.txt')
  except IOError, e: pass
  str (e)
  => "[Errno 2] No such file or directory: u'\\u30d5\\u30a3\\u30a4\\u30eb.txt'"

ok, I did ask for a str string so no reason I should expect a unicode
string, but then (in Python 2.6)...

  unicode (e)
  => u"(2, 'No such file or directory')"

i.e. no formatting at all, or in Python 2.6.5

  unicode (e)
  => u"[Errno 2] No such file or directory: u'\\u30d5\\u30a3\\u30a4\\u30eb.txt'"

i.e. the result is a unicode string in name only. :-(

What I was expecting (or at least hoping for) of course was 

  => u"[Errno 2] No such file or directory: '\u30d5\u30a3\u30a4\u30eb.txt'"

which when printed would produce something useful

  => [Errno 2] No such file or directory: 'フィイル.txt'

So how do I get what I want?  (Python 3.x is not an option.)
Note that the exceptions may be anything (I just used IOError 
as an example) and are generated in bowels of an API that I 
can't/won't mess with.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: exceptions and unicode

2010-06-19 Thread Stuart McGraw
On 06/16/2010 03:53 PM, Martin v. Loewis wrote:
>> So how do I get what I want?
> 
> Submit a patch. You would have to explain why this is a bug fix and not 
> a new feature, as new features are not allowed anymore for 2.x.

Thanks.  Actually I have no idea if this is a bug or a feature 
(despite reading bug tracker issues 2517 and 6108, most of which
I did not understand) so I'm not in a position to argue either.  
What I think I'll do is note in my documentation that the unreadable
error messages are from Python and are only temporary for a couple 
years until the app can move to Python 3. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: exceptions and unicode

2010-06-19 Thread Stuart McGraw
On 06/16/2010 03:51 PM, Thomas Jollans wrote:
> On 06/16/2010 10:10 PM, Stuart McGraw wrote:
>> Note that the exceptions may be anything (I just used IOError 
>> as an example) and are generated in bowels of an API that I 
>> can't/won't mess with.
> 
> Yeah, well, you'd have to special-case every single exception type that
> gets unicode arguments, as they probably all treat them in the same
> ungrateful way.

Unfortunate.  In general it does not seem possible to know what 
exceptions could be generated (they could be custom exceptions 
defined in the api) without examining all the code. 

Seems like I'll have to live with it or try some grotesque hack 
like looking for a repr-of-a-unicode-string-like text and converting
back to unicode.

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