Monday, April 5, 2010

comp.lang.python - 26 new messages in 13 topics - digest

comp.lang.python
http://groups.google.com/group/comp.lang.python?hl=en

comp.lang.python@googlegroups.com

Today's topics:

* Python/Django linux build consultant required - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/8677c39561909f49?hl=en
* output from popen - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/b9037022a4dee037?hl=en
* In disGuiodoise? - 3 messages, 3 authors
http://groups.google.com/group/comp.lang.python/t/443f6ab2bb92d063?hl=en
* Translation docstrings with gettext - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/5e5a245d71348c9a?hl=en
* pythonrag - 5 messages, 5 authors
http://groups.google.com/group/comp.lang.python/t/e1c71f09c3fd2d7a?hl=en
* Interfaces - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/addf230ba1eaddd7?hl=en
* Getting Local MAC Address - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/876b51563e5c0ec5?hl=en
* unset TCL_LIBRARY and TK_LIBRARY - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/917ac25e917041df?hl=en
* psycopg2 / psycopg2.ProgrammingError: syntax error at or near "E'mytable'" -
2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/52208bb7a4b2e338?hl=en
* passing command line arguments to executable - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/4f15edabd97830c8?hl=en
* Tkinter inheritance mess? - 2 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/a0146ef7d08ffea0?hl=en
* local variable referenced before assignment - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/e10205bbbbbd4759?hl=en
* case insensitive list ? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/a742ee4f043ca91f?hl=en

==============================================================================
TOPIC: Python/Django linux build consultant required
http://groups.google.com/group/comp.lang.python/t/8677c39561909f49?hl=en
==============================================================================

== 1 of 1 ==
Date: Sun, Apr 4 2010 11:28 pm
From: Si

Hi, we are a San Francisco based startup company and are looking for a
Python/Django person to help us roll out our recently completed. We're
looking for 5 years + Python experience with a knowledge of tools such
as pyinstall (or other build systems). Please contact me directly
interested. Rgds.

==============================================================================
TOPIC: output from popen
http://groups.google.com/group/comp.lang.python/t/b9037022a4dee037?hl=en
==============================================================================

== 1 of 2 ==
Date: Mon, Apr 5 2010 1:03 am
From: hiral


Hi,
I am trying following script...

<script>
import subprocess
cmd=['time', 'myCmd']
p = subprocess.Popen(cmd)
p.communicate()
<script>
Where 'myCmd' is some executable path and combination of arguments.

Now I am observing following output...
<myCmd_output...>
0.00user 0.00system 0:00.00elapsed 0%CPU (0avgtext+0avgdata
0maxresident)k
0inputs+0outputs (167major+23minor)pagefaults 0swaps

As you can observe output of 'time' command got printed as garbage.
Can you please let me know how can I get output of 'time' same as
terminal.

Thank you in advance.
-Hiral


== 2 of 2 ==
Date: Mon, Apr 5 2010 1:31 am
From: Kushal Kumaran


On Mon, Apr 5, 2010 at 1:33 PM, hiral <hiralsmaillist@gmail.com> wrote:
> Hi,
> I am trying following script...
>
> <script>
> import subprocess
> cmd=['time', 'myCmd']
> p = subprocess.Popen(cmd)
> p.communicate()
> <script>
> Where 'myCmd' is some executable path and combination of arguments.
>
> Now I am observing following output...
> <myCmd_output...>
> 0.00user 0.00system 0:00.00elapsed 0%CPU (0avgtext+0avgdata
> 0maxresident)k
> 0inputs+0outputs (167major+23minor)pagefaults 0swaps
>
> As you can observe output of 'time' command got printed as garbage.
> Can you please let me know how can I get output of 'time' same as
> terminal.
>

First, the output of "time" is not actually garbage. It probably has
all the information you need. Second, when you run "time" from the
terminal, you are probably invoking the version of "time" built in to
your shell. You can try explicitly running /usr/bin/time (probably,
could be /bin/time or something else) to get the output you're seeing
from your program.

Passing shell=True to subprocess.Popen invokes a shell to run your
command. You will also need to pass executable="path-to-your-shell"
for exact results. That should give you the same output as you get
from a terminal. You will probably need to change the "cmd" arg to be
a string.

--
regards,
kushal

==============================================================================
TOPIC: In disGuiodoise?
http://groups.google.com/group/comp.lang.python/t/443f6ab2bb92d063?hl=en
==============================================================================

== 1 of 3 ==
Date: Mon, Apr 5 2010 3:20 am
From: "Martin P. Hellwig"


On 04/05/10 00:05, r wrote:
<knip>
> However i have also considered that maybe *all* the "well knowns" are
> in fact the many colorful personalities of Guido.
>
<knip>

De vraag is dan natuurlijk of al zijn persoonlijkheden nog steeds
nederlands machtig zijn.

--
mph


== 2 of 3 ==
Date: Mon, Apr 5 2010 4:48 am
From: News123


Martin P. Hellwig wrote:
> On 04/05/10 00:05, r wrote:
> <knip>
>> However i have also considered that maybe *all* the "well knowns" are
>> in fact the many colorful personalities of Guido.
>>
> <knip>
>
> De vraag is dan natuurlijk of al zijn persoonlijkheden nog steeds
> nederlands machtig zijn.
>

Good sock puppets would at least pretend to understand no Dutch even if
they would.

N


== 3 of 3 ==
Date: Mon, Apr 5 2010 6:39 am
From: Andreas Waldenburger


On Mon, 05 Apr 2010 13:48:15 +0200 News123 <news1234@free.fr> wrote:

> Martin P. Hellwig wrote:
> > On 04/05/10 00:05, r wrote:
> > <knip>
> >> However i have also considered that maybe *all* the "well knowns"
> >> are in fact the many colorful personalities of Guido.
> >>
> > <knip>
> >
> > De vraag is dan natuurlijk of al zijn persoonlijkheden nog steeds
> > nederlands machtig zijn.
> >
>
> Good sock puppets would at least pretend to understand no Dutch even
> if they would.
>
Is that in reference to the contents of Martins comment, in whatever
language that was? Because I, for one, don't understand a word of it.

/W

--
INVALID? DE!


==============================================================================
TOPIC: Translation docstrings with gettext
http://groups.google.com/group/comp.lang.python/t/5e5a245d71348c9a?hl=en
==============================================================================

== 1 of 2 ==
Date: Mon, Apr 5 2010 3:31 am
From: sapient


Hello.

I found several discussions where this question was asked, but was not
answered.

Now I am creating Python-API for my application, and want create it
with translation support, including documentation strings for modules,
classes, methods etc.

It is simple to translate special-marked strings with gettext, but it
is problem with docstrings: if I mark them for translation like
_("""Some documentation string""") then it is not recognized as
docstring. If I omit _() markup, then string is not translated.

Script pygettext.py has key --docstrings that forces extraction
docstrings from module, so I suppose, that it must be way to use thier
translations.

---
I create small example, that demonstrates this problem:
Module with docstrings for translation:
{{{
#!python
"""testmodule docstring"""

class TestClass:
"""testmodule.TestClass docstring"""

def testClassMethod(self):
"""testmodule.TestClass.testClassMethod docstring"""
print _("Call TestClass.testClassMethod()")
}}}

Script for testing translation:
{{{
#!python
import os, gettext

localedir = os.path.join( os.path.dirname(__file__), "locale/" )

t = gettext.translation( 'testmodule', localedir=localedir,
languages=['ru'], codeset="cp1251" )
t.install()

import testmodule

help( testmodule )
testmodule.TestClass().testClassMethod()
}}}

It successfully translates _("Call TestClass.testClassMethod()") but
all docstrings stay untranslated.
Full example exists here:
https://docs.google.com/leaf?id=0B_rE4w6PFDYWODg5ZWJlYjMtYTQ5ZS00MTE3LTgxOWUtNjc5NzEzNzVjYzdh&hl=en

So, question is: How to translate docstrings in my example?


== 2 of 2 ==
Date: Mon, Apr 5 2010 7:27 am
From: Lie Ryan


On 04/05/10 20:31, sapient wrote:
> Hello.
>
> I found several discussions where this question was asked, but was not
> answered.

Why would you want to translate docstring? Docstring is meant for
developers not users. Maintaining a translated docstring is going to be
a maintenance hell and will either hampers your application's agility or
you will be left with obsolete docstrings in various languages you don't
know.

Anyway, my job is to answer questions, not question the economic
feasibility of your decision, so try this:

#!python
__doc__ = _("""testmodule docstring""")

class TestClass:
__doc__ = _("""testmodule.TestClass docstring""")

def testClassMethod(self):
__doc__ = _("""testmodule.TestClass.testClassMethod docstring""")
print _("Call TestClass.testClassMethod()")


If you want to avoid having the explicit assignment to __doc__, you can
also try using some metaclass or decorator magic to automatically wraps
docstring in a _() call.

==============================================================================
TOPIC: pythonrag
http://groups.google.com/group/comp.lang.python/t/e1c71f09c3fd2d7a?hl=en
==============================================================================

== 1 of 5 ==
Date: Mon, Apr 5 2010 4:38 am
From: Jason Friedman


I saw this posted in the July issue but did not see any follow-up there:

$ python
Python 2.6.4 (r264:75706, Dec 7 2009, 18:43:55)
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a = 500
>>> b = 500
>>> a == b
True
>>> a is b
False
>>> p = 50
>>> q = 50
>>> p == q
True
>>> p is q
True
>>>


== 2 of 5 ==
Date: Mon, Apr 5 2010 4:48 am
From: superpollo


Jason Friedman ha scritto:
> I saw this posted in the July issue but did not see any follow-up there:
>
> $ python
> Python 2.6.4 (r264:75706, Dec 7 2009, 18:43:55)
> [GCC 4.4.1] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> a = 500
>>>> b = 500
>>>> a == b
> True
>>>> a is b
> False
>>>> p = 50
>>>> q = 50
>>>> p == q
> True
>>>> p is q
> True

LOL

== 3 of 5 ==
Date: Mon, Apr 5 2010 4:58 am
From: Albert Hopkins


On Mon, 2010-04-05 at 11:38 +0000, Jason Friedman wrote:
> I saw this posted in the July issue but did not see any follow-up there:
>
> $ python
> Python 2.6.4 (r264:75706, Dec 7 2009, 18:43:55)
> [GCC 4.4.1] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> a = 500
> >>> b = 500
> >>> a == b
> True
> >>> a is b
> False
> >>> p = 50
> >>> q = 50
> >>> p == q
> True
> >>> p is q
> True
> >>>

This topic shows here every 3 weeks or so...

The short of it: CPython optimizes small integers. It's a feature.
Don't rely on it (Google for the rest).

-a


== 4 of 5 ==
Date: Mon, Apr 5 2010 5:45 am
From: Irmen de Jong


On 5-4-2010 13:48, superpollo wrote:
> Jason Friedman ha scritto:
>> I saw this posted in the July issue but did not see any follow-up there:
>>
>> $ python
>> Python 2.6.4 (r264:75706, Dec 7 2009, 18:43:55)
>> [GCC 4.4.1] on linux2
>> Type "help", "copyright", "credits" or "license" for more information.
>>>>> a = 500
>>>>> b = 500
>>>>> a == b
>> True
>>>>> a is b
>> False
>>>>> p = 50
>>>>> q = 50
>>>>> p == q
>> True
>>>>> p is q
>> True
>
> LOL
>

I fail to see the fun?
Remember that everything in Python is an object, even integers.
For integers, I believe Python creates the first 100 integer objects and reuses them.
Larger integers are created when needed, and are different objects.
The example also shows why it usually is wrong to use object comparison ('is') when you
really mean equality (==).

-irmen


== 5 of 5 ==
Date: Mon, Apr 5 2010 8:25 am
From: Gary Herron


Jason Friedman wrote:
> I saw this posted in the July issue but did not see any follow-up there:
>
> $ python
> Python 2.6.4 (r264:75706, Dec 7 2009, 18:43:55)
> [GCC 4.4.1] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>
>>>> a = 500
>>>> b = 500
>>>> a == b
>>>>
> True
>
>>>> a is b
>>>>
> False
>
>>>> p = 50
>>>> q = 50
>>>> p == q
>>>>
> True
>
>>>> p is q
>>>>
> True
>

In
a=500
b=500
Python could either:
* create two integers containing 500, one for each variable
* create one integer referred to by both variables
The first option will evaluate "a is b" as False, while the second will
evaluate "a is b" as True.

In other words, the "is" operator asks something about storage
location. *WHY* would you care how the integers are stored? It is
considered a *bug* on your part to write a program that depends on the
particular storage option Python chooses for any particular integer.

The second option is more efficient in memory usage, but requires some
run-time to implement, while the first option does not require the
run-time tracking of already-used integers, but may result in more
memory usage. Python, the language, does not specify which storage
option will be used. Python, the C implementation, does both, choosing
the second option for small integers (those less 100 last time I checked).

Gary Herron


--
Gary Herron, PhD.
Department of Computer Science
DigiPen Institute of Technology
(425) 895-4418


==============================================================================
TOPIC: Interfaces
http://groups.google.com/group/comp.lang.python/t/addf230ba1eaddd7?hl=en
==============================================================================

== 1 of 2 ==
Date: Mon, Apr 5 2010 8:40 am
From: Roald de Vries


Dear all,

PEP 245 and 246 about interfaces for python are both rejected for
'something much better' (GvR in 246's rejection notice). Does anybody
know what this is? I am *very* curious!

Kind regards, Roald


== 2 of 2 ==
Date: Mon, Apr 5 2010 9:25 am
From: Richard Thomas


On Apr 5, 4:40 pm, Roald de Vries <downa...@gmail.com> wrote:
> Dear all,
>
> PEP 245 and 246 about interfaces for python are both rejected for  
> 'something much better' (GvR in 246's rejection notice). Does anybody  
> know what this is? I am *very* curious!
>
> Kind regards, Roald

Given that was in 2001, probably Python 2.2.

==============================================================================
TOPIC: Getting Local MAC Address
http://groups.google.com/group/comp.lang.python/t/876b51563e5c0ec5?hl=en
==============================================================================

== 1 of 1 ==
Date: Mon, Apr 5 2010 9:07 am
From: Booter


All,

Thanks for all of the great solutions! Sorry I wasn't more specific
in my post and will keep that in mind for future posts. Just FYI I
was using a Windows machine and running Python 2.6.

Once again thanks for all of your help!

Gerad

==============================================================================
TOPIC: unset TCL_LIBRARY and TK_LIBRARY
http://groups.google.com/group/comp.lang.python/t/917ac25e917041df?hl=en
==============================================================================

== 1 of 1 ==
Date: Mon, Apr 5 2010 9:15 am
From: Dave Angel


Wolfman wrote:
> Hello- was hoping someone could give me a hand in permanently setting
> my TCL_LIBRARY and TK_LIBRARY.
>
> I downloaded Python2.6 to a ThinkPad that came installed with
> Python2.2, and I can not run IDLE as something automatically sets
> TCL_LIBRARY and TK_LIBRARY to C:\IBMTools\Python22\ each time i open a
> new command line window or reboot the machine.
>
> i have set them to the appropriate Python26 sub-directory via command
> line and IDLE opens just fine and dandy, but as soon as I close the
> command window or reboot computer it sets them back to the
> aforementioned C:\IBMTools\Python22 subdirectory
>
> how can i permanently SET TCL_LIBRARY and TK_LIBRARY?
>
> thanks
>
>
It can be dangerous to change the system-wide default Python that
presumably was used for administration on your Thinkpad. I have a later
Thinkpad (with XP), and it did not come with any Python.

But if you want to change environment variables persistently on Windows,
you can go to the Control Panel. The specifics below are with XP, but
it'll be similar for other versions between Win2k and later.

ControlPanel->System
Advanced tab
Click button labeled Environment Variables

The upper section contains variables specific to your own logon, while
the lower panel has variables that will be set for all users. I believe
in most cases, a variable defined in both places will get the "user"
value. But for PATH, the two are combined into a single, longer
string. And perhaps that's true for some others as well.

If you have trouble finding that page ("Environment Variables"), see if
you can find the System Properties panel. It has an Advanced tab, and
you can continue as above.

Once you've set these, any new copy of CMD.exe will get the new values,
and they are remembered across boot. However, typing start from an
existing DOS box just gets a copy with the same variables you've defined
locally.

DaveA


==============================================================================
TOPIC: psycopg2 / psycopg2.ProgrammingError: syntax error at or near "E'
mytable'"
http://groups.google.com/group/comp.lang.python/t/52208bb7a4b2e338?hl=en
==============================================================================

== 1 of 2 ==
Date: Mon, Apr 5 2010 9:20 am
From: mrdrew


Thanks for the replies. The param style is pyformat. I've tried
using the '%s' style with a set and get exactly the same error.

c.execute('SELECT * FROM %s LIMIT 1',('mytable',))
psycopg2.ProgrammingError: syntax error at or near "E'mytable'"
LINE 1: SELECT * FROM E'mytable' LIMIT 1

MRAB and Steve Holden may be correct, but are at odds with the
psycopg2 documentation (http://initd.org/psycopg/docs/
usage.html#passing-parameters-to-sql-queries
) which shows named
arguments being used with a dictionary.

It appears that the real problem is, as Steve mentioned, that the
device driver may not allow table name substitution. The following
query seems to work...

c.execute('SELECT * FROM mytable WHERE id = %(id)s',{'id':'10'})

(Oddly enough, this one doesn't)
c.execute('SELECT * FROM mytable WHERE id = %(id)d',{'id':int(10)})
TypeError: int argument required


== 2 of 2 ==
Date: Mon, Apr 5 2010 10:27 am
From: Dennis Lee Bieber


On Mon, 5 Apr 2010 09:20:28 -0700 (PDT), mrdrew <afitting@gmail.com>
declaimed the following in gmane.comp.python.general:

> It appears that the real problem is, as Steve mentioned, that the
> device driver may not allow table name substitution. The following
> query seems to work...
>
Pretty much ALL db-api compliant adapters require the schema
entities (table and field names) to be built into the SQL. Schema
entities should never be user-supplied data (the application should, at
best, present a list of the available entities from which a user may
select, but the user never /types/ the entity name itself; the
application converts the selection [checkbox, list index] into the
proper name internally).

ONLY /data/ items can (and should) be parameterized placeholders.

One reason being that the parameter replacement system ensures the
data item is syntactically safe (no SQL injection, special characters
escaped). Don't know about the PostgreSQL adapters, but MySQLdb
internally uses Python string interpolation to build the final SQL that
gets sent (Prior to MySQL 5.x, there was no low-level
prepared/parameterized interface).

> c.execute('SELECT * FROM mytable WHERE id = %(id)s',{'id':'10'})
>
> (Oddly enough, this one doesn't)
> c.execute('SELECT * FROM mytable WHERE id = %(id)d',{'id':int(10)})
> TypeError: int argument required

This would appear to be similar to the MySQLdb behavior. The
parameter (int(10)) will have been stringified, escaped, and quoted
BEFORE being given to the placeholder. So what you have is NOT

>>> 'SELECT * FROM mytable WHERE id = %(id)d' % {"id": int(10)}
'SELECT * FROM mytable WHERE id = 10'

but rather the equivalent of

>>> 'SELECT * FROM mytable WHERE id = %(id)d' % {"id": "'" + str(int(10)) + "'"}
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
TypeError: int argument required
>>>

where your int(10) gets converted to a string, and that string gets
surrounded by SQL quotes (I ignored the part where any quotes /in/ the
string are escaped first).

There is a reason "pyformat" typically means ONLY %s placeholders...
because ALL supplied parameters ARE strings by the time they get to the
placeholder.
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/


==============================================================================
TOPIC: passing command line arguments to executable
http://groups.google.com/group/comp.lang.python/t/4f15edabd97830c8?hl=en
==============================================================================

== 1 of 2 ==
Date: Mon, Apr 5 2010 9:22 am
From: mcanjo


On Apr 4, 6:32 am, Simon Brunning <si...@brunningonline.net> wrote:
> On 3 April 2010 18:20, mcanjo <mca...@gmail.com> wrote:
>
> > I tried doing the following code:
>
> > from subprocess import Popen
> > from subprocess import PIPE, STDOUT
> > exefile = Popen('pmm.exe', stdout = PIPE, stdin = PIPE, stderr =
> > STDOUT)
> > exefile.communicate('MarchScreen.pmm\nMarchScreen.out')[0]
>
> > and the Command Prompt opened and closed, no exceptions were generated
> > but the program didn't run. Am I doing something wrong?
>
> Have you tried running pmm.exe from the command line? What does that
> look like? Does it matter what the current working directory is at the
> time?
>
> --
> Cheers,
> Simon B.

When I run the program from the command line it looks as follows:

Enter the Input filename
(enter in filename here)
Enter the Output filename
(enter in filename here)

If an absolute path is not specified then the output file is located
in the current working directory of the executable. The absolute path
for the output and input files may be specified also.

Chris


== 2 of 2 ==
Date: Mon, Apr 5 2010 9:31 am
From: Patrick Maupin


On Apr 5, 11:22 am, mcanjo <mca...@gmail.com> wrote:
> On Apr 4, 6:32 am, Simon Brunning <si...@brunningonline.net> wrote:
>
>
>
> > On 3 April 2010 18:20, mcanjo <mca...@gmail.com> wrote:
>
> > > I tried doing the following code:
>
> > > from subprocess import Popen
> > > from subprocess import PIPE, STDOUT
> > > exefile = Popen('pmm.exe', stdout = PIPE, stdin = PIPE, stderr =
> > > STDOUT)
> > > exefile.communicate('MarchScreen.pmm\nMarchScreen.out')[0]
>
> > > and the Command Prompt opened and closed, no exceptions were generated
> > > but the program didn't run. Am I doing something wrong?
>
> > Have you tried running pmm.exe from the command line? What does that
> > look like? Does it matter what the current working directory is at the
> > time?
>
> > --
> > Cheers,
> > Simon B.
>
> When I run the program from the command line it looks as follows:
>
> Enter the Input filename
> (enter in filename here)
> Enter the Output filename
> (enter in filename here)
>
> If an absolute path is not specified then the output file is located
> in the current working directory of the executable. The absolute path
> for the output and input files may be specified also.
>
> Chris

One thing you should do if you use pipes is to make sure you are
accepting data from the program. If the program stalls because it
cannot write anything to its stdout, you might have an issue.

Pat

==============================================================================
TOPIC: Tkinter inheritance mess?
http://groups.google.com/group/comp.lang.python/t/a0146ef7d08ffea0?hl=en
==============================================================================

== 1 of 2 ==
Date: Mon, Apr 5 2010 9:36 am
From: ejetzer


For a school project, I'm trying to make a minimalist web browser, and
I chose to use Tk as the rendering toolkit. I made my parser classes
into Tkinter canvases, so that I would only have to call pack and
mainloop functions in order to display the rendering. Right now, two
bugs are affecting the program :
1) When running the full app¹, which fetches a document and then
attempts to display it, I get a TclError :
_tkinter.TclError: bad window path name "{Extensible
Markup Language (XML) 1.0 (Fifth Edition)}"
2) When running only the parsing and rendering test², I get a big
window to open, with nothing displayed. I am not quite familiar with
Tk, so I have no idea of why it acts that way.

1: webbrowser.py
2: xmlparser.py


== 2 of 2 ==
Date: Mon, Apr 5 2010 9:38 am
From: ejetzer


On 5 avr, 12:36, ejetzer <ejet...@gmail.com> wrote:
> For a school project, I'm trying to make a minimalist web browser, and
> I chose to use Tk as the rendering toolkit. I made my parser classes
> into Tkinter canvases, so that I would only have to call pack and
> mainloop functions in order to display the rendering. Right now, two
> bugs are affecting the program :
> 1) When running the full app¹, which fetches a document and then
> attempts to display it, I get a TclError :
>                  _tkinter.TclError: bad window path name "{Extensible
> Markup Language (XML) 1.0 (Fifth Edition)}"
> 2) When running only the parsing and rendering test², I get a big
> window to open, with nothing displayed. I am not quite familiar with
> Tk, so I have no idea of why it acts that way.
>
> 1: webbrowser.py
> 2: xmlparser.py

I just realized I haven't included the Google Code project url :
http://code.google.com/p/smally-browser/source/browse/#svn/trunk

==============================================================================
TOPIC: local variable referenced before assignment
http://groups.google.com/group/comp.lang.python/t/e10205bbbbbd4759?hl=en
==============================================================================

== 1 of 2 ==
Date: Mon, Apr 5 2010 10:08 am
From: John Nagle


Alf P. Steinbach wrote:

> Best is however to recognize that you have some state (your variable)
> and some operations on that state (your callback), and that that is what
> objects are all about. I.e. wrap your logic in a class. Then
> 'lastModifiedTime' becomes an instance attribute, and 'handler' becomes
> a method.
>
> It doesn't matter that there will only ever be one object (instance) of
> that class.
>
> Classes were meant for just this sort of thing, state + operations.

Yes. Functions with persistent state are generally a bad idea.

Unfortunately, the "signal" module requires a callback parameter
which is a plain function. So you have to send it a function,
closure, or lambda. Here, it's being sent a closure - "handler"
bound to the state that existed when "signal.signal" was called.

John Nagle


== 2 of 2 ==
Date: Mon, Apr 5 2010 10:20 am
From: Robert Kern


On 2010-04-05 12:08 PM, John Nagle wrote:
> Alf P. Steinbach wrote:
>
>> Best is however to recognize that you have some state (your variable)
>> and some operations on that state (your callback), and that that is
>> what objects are all about. I.e. wrap your logic in a class. Then
>> 'lastModifiedTime' becomes an instance attribute, and 'handler'
>> becomes a method.
>>
>> It doesn't matter that there will only ever be one object (instance)
>> of that class.
>>
>> Classes were meant for just this sort of thing, state + operations.
>
> Yes. Functions with persistent state are generally a bad idea.
>
> Unfortunately, the "signal" module requires a callback parameter
> which is a plain function. So you have to send it a function,
> closure, or lambda.

Does it? The docs say that it just needs a callable object. An instance with a
__call__() method would suffice.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco


==============================================================================
TOPIC: case insensitive list ?
http://groups.google.com/group/comp.lang.python/t/a742ee4f043ca91f?hl=en
==============================================================================

== 1 of 1 ==
Date: Mon, Apr 5 2010 10:23 am
From: Robert Kern


On 2010-04-05 12:17 PM, Stef Mientki wrote:
> hello,
>
> AFAIK there's no case insensitive list in Python.
> By case insentive I mean that that sort and memebr of is case insensitive.
>
> Does soeone has a implementation of sucha case insensitive list ?

mylist.sort(key=lambda x: x.lower())
any(x.lower() == lowercase_query for x in mylist)

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

==============================================================================

You received this message because you are subscribed to the Google Groups "comp.lang.python"
group.

To post to this group, visit http://groups.google.com/group/comp.lang.python?hl=en

To unsubscribe from this group, send email to comp.lang.python+unsubscribe@googlegroups.com

To change the way you get mail from this group, visit:
http://groups.google.com/group/comp.lang.python/subscribe?hl=en

To report abuse, send email explaining the problem to abuse@googlegroups.com

==============================================================================
Google Groups: http://groups.google.com/?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate