Re: Plot problem.. ?? No sign at all

2010-07-06 Thread Alan G Isaac

On 7/6/2010 8:05 AM, Ritchy lelis wrote:

 1 - import numpy as np
  import matplotlib.pyplot as plt

  In what help's me making the call's of the libraries that way?


http://bytebaker.com/2008/07/30/python-namespaces/


 2 - What's the instruction linspace means/does?


 help(np.linspace)
Help on function linspace in module numpy.core.function_base:

linspace(start, stop, num=50, endpoint=True, retstep=False)
Return evenly spaced numbers over a specified interval.

Returns `num` evenly spaced samples, calculated over the
interval [`start`, `stop` ].



 3 - Last but more important: V0 = ... #create an array if I
 understood, there i'm supposed to introduce the for loop as in my
 initial example. correct?


It is better to create your arrays without looping,
if possible.  But create it however you wish.
(Note than numpy arrays have a fixed length;
create a Python list if you wish to append to it.)

Cheers,
Alan Isaac


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


Re: Plot problem.. ?? No sign at all

2010-07-06 Thread Alan G Isaac

On 7/6/2010 12:11 PM, Ritchy lelis wrote:

My intention with de for loop was to iterate each point of the arrays
Vi and Vref at the math calculations. The V0 it's the result of the
math expressions between the Vi and Vref. I can't just create one V0
by a function set by parametters (i don't see how).



Unfortunately I cannot make sense of the code you posted.
Provide a detailed description in words (or psuedocode)
of what you are trying to accomplish.  Be very careful
and detailed is you want a useful response.

Alan Isaac


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


Re: Plot problem.. ?? No sign at all

2010-07-05 Thread Alan G Isaac

On 7/5/2010 7:45 AM, Ritchy lelis wrote:

from pylab import*

Vref = arange(1, 20, 0.02)
Vi = arange(1, 10,0.1)

for i in Vref:
  for n in Vi:
   if n  i/4:
 V0 = 2*n-i
   elif (-i/4)= n and n= i/4:
 V0 = 2*n
   elif Vi  -i/4:
 V0 = 2*n+i
   else:
 print Try Again
 ##print V0
 plot (V0)



Your data manipulations don't make sense to me,
and plotting one point at a time is probably
not what you want to do.  As a rule, use arange
only with integer arguments. Finally, if you
want to see your plot, you need to show it
(or save it). So create an **array** V0 and
then do  something like the following:

import numpy as np
import matplotlib.pyplot as plt
Vref = np.linspace(1,20, 1000)
Vi = np.linspace(1,10,100)
#replace the next line
V0 = ... #create an array
plt.plot(V0)
plt.show()

hth,
Alan Isaac
--
http://mail.python.org/mailman/listinfo/python-list


Re: best way to increment an IntVar?

2010-06-25 Thread Alan G Isaac

On 6/24/2010 1:59 AM, Dennis Lee Bieber wrote:

It is NOT a numeric variable in Python realms.


Sure, but why does it not behave more like one?
It seems both obvious and desirable, so I'm
guessing there is a good reason not to do it.


So var+=increment can't be used because Python would rebind the name
var to a new object



import Tkinter as tk

class IntVar2(tk.IntVar):

...   def __iadd__(self, val):
... self.set(self.get()+val)
... return self
...

root = tk.Tk()
myintvar2 = IntVar2()
temp = myintvar2
myintvar2 += 5
print(myintvar2.get(),myintvar2 is temp)

(5, True)

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


Re: best way to increment an IntVar?

2010-06-25 Thread Alan G Isaac

On 6/25/2010 1:14 PM, Dave Angel wrote:

the default behavior of += is to assign a new object with the new value,
rather than changing the previous object.



a = []
temp = a
a += [2]
temp

[2]

Alan Isaac

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


Re: best way to increment an IntVar?

2010-06-25 Thread Alan G Isaac

On 6/25/2010 1:24 PM, rantingrick wrote:

the if __name__ == '__main__' tests use
root.quit instead of root.destroy!


Did you open an issue?
http://bugs.python.org/

Alan Isaac

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


value of: None is None is None

2010-06-25 Thread Alan G Isaac

Surprising for a moment, if you don't
immediatelyrecognize it as a chained comparison.
(Just sharing.)
Alan Isaac


None is None is None

True

(None is None) is None

False

None is (None is None)

False

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


Re: best way to increment an IntVar?

2010-06-25 Thread Alan G Isaac

On 6/25/2010 3:52 PM, Dave Angel wrote:

I said default, not only behavior.   I suspect list provides an
__iadd__  method to provide this ability.  Integers do not, and
therefore neither does the object the OP was asking about.



I have no idea what default behavior is supposed to mean.
Mutable objects like a list will generally modify in place.
Immutable objects of course will not.  An IntVar is mutable.
You have given no reason for it not to handle ``+=`` in an
unsurprising fashion.  It is not an int.

Alan Isaac

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


Re: improving IDLE

2010-06-25 Thread Alan G Isaac

On 6/25/2010 1:24 PM, rantingrick wrote:

the if __name__ == '__main__' tests use
root.quit instead of root.destroy!




On Jun 25, 12:46 pm, Alan G Isaacalan.is...@gmail.com  wrote:

Did you open an issue?http://bugs.python.org/
 


On 6/25/2010 4:26 PM, rantingrick wrote:

If *I* open an issue it will be ignored or quickly dismissed because
the people in charge of the Python community hate me.



I bet against that assessment.
For this particular issue.  ;-)

As for the larger issue, I believe DreamPie is under
active development?
http://dreampie.sourceforge.net/

fwiw,
Alan Isaac

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


ttk Scale: missing attributes

2010-06-23 Thread Alan G Isaac

Tkinter's Scale widget had a `label` and a `resolution` attribute.
These appear to be missing from the Ttk Scale widget.
Is there a reason?  These were important attributes.

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


best way to increment an IntVar?

2010-06-23 Thread Alan G Isaac

Of course one can do
myintvar.set(myintvar.get()+1)
but surely there is a better way?

I'm surprsied that
myintvar += 1
is not allowed.

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


Re: [ANNC] pynguin-0.8 python turtle graphics application

2010-06-09 Thread Alan G Isaac

On 6/8/2010 6:59 PM, Lee Harr wrote:

Pynguin is a python-based turtle graphics application.
 It combines an editor, interactive interpreter, and
 graphics display area.



Do you start from scratch or make use of the
very useful new (2.6) turtle module?  I hope
the latter, and that you are working with
Gregor Lingl to make turtle.py even better.

Cheers,
Alan Isaac

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


modify XMP data (Python/Windows)

2010-06-05 Thread Alan G Isaac

I want to modify XMP data for a bunch of JPEG files,
using Python if possible, on Windows.  I expected
PIL would support this.  But no?

I found the Python XMP Toolkit
http://www.spacetelescope.org/static/projects/python-xmp-toolkit/docs/installation.html#requirements
but no reports of successful use on Windows.

I found Chilkat's XMP library
http://www.chilkatsoft.com/python-xmp.asp
but it is not open source and I found no encouraging reviews.

Is there a Python package providing functinonality comparable
to Image::ExifTool (perl)?

Thanks,
Alan Isaac

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


Re: documentation bug? (format spec mini language)

2010-05-12 Thread Alan G Isaac
On 5/11/2010 5:05 PM, Terry Reedy wrote:  

http://bugs.python.org/issue8691


Thanks!

Alan


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


documentation bug? (format spec mini language)

2010-05-11 Thread Alan G Isaac

The documentation at 
http://docs.python.org/py3k/library/string.html#format-specification-mini-language

'' Forces the field to be left-aligned within the available space 
(This is the default.)

The conflicting example::

 format(3.2,'10.5f')
'   3.2'
 format(3.2,'10.5f')
'3.2   '

Am I somehow misreading the documentation?

Thanks,
Alan Isaac


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


Re: documentation bug? (format spec mini language)

2010-05-11 Thread Alan G Isaac

On 5/11/2010 3:19 PM, MRAB wrote:

You usually want numbers to be right-aligned so that the decimal points
line up when writing a columns of them.



Yes.  I'm not questioning the wisdom of the implementation,
just the documentation of it.

Thanks,
Alan

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


Re: change an exception's message and re-raise it

2009-12-31 Thread Alan G Isaac

On 12/31/2009 7:30 PM, Steven D'Aprano wrote:

The message attribute is deprecated from
Python 2.6 and will print a warning if you try to use it.



http://bugs.python.org/issue6844

fwiw,
Alan Isaac

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


Re: Raw string substitution problem

2009-12-18 Thread Alan G Isaac

On 12/17/2009 7:59 PM, Rhodri James wrote:

re.compile('a\\nc') passes a sequence of four characters to
re.compile: 'a', '\', 'n' and 'c'.  re.compile() then does it's own
interpretation: 'a' passes through as is, '\' flags an escape which
combined with 'n' produces the newline character (0x0a), and 'c' passes
through as is.



I got that from MRAB's posts. (Thanks.)
What I'm not getting is why the replacement string
gets this particular interpretation.  What is the payoff?
(Contrast e.g. Vim's substitution syntax.)

Thanks,
Alan

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


Re: Raw string substitution problem

2009-12-18 Thread Alan G Isaac

On 12/18/2009 12:17 PM, MRAB wrote:

In simple cases you might be replacing with the same string every time,
but other cases you might want the replacement to contain substrings
captured by the regex.



Of course that conversion is needed in the replacement.
But e.g. Vim substitutions handle this fine without the
odd (to non perlers) handling of backslashes in replacement.

Alan Isaac

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


Re: Raw string substitution problem

2009-12-17 Thread Alan G Isaac

En Wed, 16 Dec 2009 11:09:32 -0300, Ed Keith e_...@yahoo.com escribió:


I am having a problem when substituting a raw string. When I do the
following:

re.sub('abc', r'a\nb\nc', '123abcdefg')

I get


123a
b
cdefg


what I want is

r'123a\nb\ncdefg'


 
On 12/16/2009 9:35 AM, Gabriel Genellina wrote:

 From http://docs.python.org/library/re.html#re.sub

re.sub(pattern, repl, string[, count])

...repl can be a string or a function; if
it is a string, any backslash escapes in
it are processed. That is, \n is converted
to a single newline character, \r is
converted to a linefeed, and so forth.

So you'll have to double your backslashes:




I'm not persuaded that the docs are clear.  Consider:

 'ab\\ncd' == r'ab\ncd'
True

Naturally enough.  So I think the right answer is:

1. this is a documentation bug (i.e., the documentation
   fails to specify unexpected behavior for raw strings), or
2. this is a bug (i.e., raw strings are not handled correctly
   when used as replacements)

I vote for 2.

Peter's use of a function highlights just how odd this is:
getting the raw string via a function produces a different
result than providing it directly.  If this is really the
way things ought to be, I'd appreciate a clear explanation
of why.

Alan Isaac

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


Re: Raw string substitution problem

2009-12-17 Thread Alan G Isaac

On 12/17/2009 11:24 AM, Richard Brodie wrote:

A raw string is not a distinct type from an ordinary string
in the same way byte strings and Unicode strings are. It
is a merely a notation for constants, like writing integers
in hexadecimal.


(r'\n', u'a', 0x16)

('\\n', u'a', 22)




Yes, that was a mistake.  But the problem remains::

 re.sub('abc', r'a\nb\n.c\a','123abcdefg') == re.sub('abc', 
'a\\nb\\n.c\\a',' 123abcdefg') == re.sub('abc', 'a\nb\n.c\a','123abcdefg')
True
 r'a\nb\n.c\a' == 'a\\nb\\n.c\\a' == 'a\nb\n.c\a'
False

Why are the first two strings being treated as if they are the last one?
That is, why isn't '\\' being processed in the obvious way?
This still seems wrong.  Why isn't it?

More simply, consider::

 re.sub('abc', '\\', '123abcdefg')
Traceback (most recent call last):
  File stdin, line 1, in module
  File C:\Python26\lib\re.py, line 151, in sub
return _compile(pattern, 0).sub(repl, string, count)
  File C:\Python26\lib\re.py, line 273, in _subx
template = _compile_repl(template, pattern)
  File C:\Python26\lib\re.py, line 260, in _compile_repl
raise error, v # invalid expression
sre_constants.error: bogus escape (end of line)

Why is this the proper handling of what one might think would be an
obvious substitution?

Thanks,
Alan Isaac
 
--

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


Re: Raw string substitution problem

2009-12-17 Thread Alan G Isaac

Alan G Isaacalan.is...@gmail.com  wrote:

re.sub('abc', r'a\nb\n.c\a','123abcdefg') == re.sub('abc', 
'a\\nb\\n.c\\a','123abcdefg') == re.sub('abc', 'a\nb\n.c\a','123abcdefg')
  True
Why are the first two strings being treated as if they are the last one?
 


On 12/17/2009 12:19 PM, D'Arcy J.M. Cain wrote:

They aren't.  The last string is different.


Of course it is different.
That is the basis of my question.
Why is it being treated as if it is the same?
(See the end of this post.)



Alan G Isaacalan.is...@gmail.com  wrote:

More simply, consider::

re.sub('abc', '\\', '123abcdefg')
  Traceback (most recent call last):
File stdin, line 1, inmodule
File C:\Python26\lib\re.py, line 151, in sub
  return _compile(pattern, 0).sub(repl, string, count)
File C:\Python26\lib\re.py, line 273, in _subx
  template = _compile_repl(template, pattern)
File C:\Python26\lib\re.py, line 260, in _compile_repl
  raise error, v # invalid expression
  sre_constants.error: bogus escape (end of line)

Why is this the proper handling of what one might think would be an
obvious substitution?



On 12/17/2009 12:19 PM, D'Arcy J.M. Cain wrote:

Is this what you want?  What you have is a re expression consisting of
a single backslash that doesn't escape anything (EOL) so it barfs.

 re.sub('abc', r'\\', '123abcdefg')
 '123\\defg'


Turning again to the documentation:
if it is a string, any backslash escapes in it are processed.
That is, \n is converted to a single newline character, \r is
converted to a linefeed, and so forth.
So why is '\n' converted to a newline but '\\' does not become a literal
backslash?  OK, I don't do much string processing, so perhaps this is where
I am missing the point: how is the replacement being converted?
(As Peter's example shows, if you supply the replacement via
a function, this does not happen.) You suggest it is just a matter of
it being an re, but::

 re.sub('abc', 'a\\nc','1abcd') == re.sub('abc', 'a\nc','1abcd')
True
 re.compile('a\\nc') == re.compile('a\nc')
False

So I have two string that are not the same, nor do they compile
equivalently, yet apparently they are converted to something
equivalent for the substitution. Why? Is my question clearer?

If the answer looks too obvious to state, assume I'm missing it anyway
and please state it.  As I said, I seldom use the re module.

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


Re: Raw string substitution problem

2009-12-17 Thread Alan G Isaac

On 12/17/2009 2:45 PM, MRAB wrote:

re.compile('a\\nc') _does_ compile to the same as regex as
re.compile('a\nc').

However, regex objects never compare equal to each other, so, strictly
speaking, re.compile('a\nc') != re.compile('a\nc').

However, having said that, the re module contains a cache (keyed on the
string and options supplied), so the first re.compile('a\nc') will put
the regex object in the cache and the second re.compile('a\nc') will
return that same regex object from the cache. If you clear the cache in
between the two calls (do re._cache.clear()) you'll get two different
regex objects which won't compare equal even though they are to all
intents identical.



OK, this is helpful.
(I did check equality but did not understand
I got True only because re used caching.)
So is the bottom line the following?
A string replacement is not just converted
as described in the documentation, essentially
it is compiled?

But that cannot quite be right.  E.g., \b will be a back
space not a word boundary.  So then the question arises
again, why isn't '\\' a backslash? Just because?
Why does it not get the obvious conversion?

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


Re: restriction on sum: intentional bug?

2009-10-17 Thread Alan G Isaac

On 10/17/2009 7:06 AM, Carl Banks wrote:

I'm basically saying here is, by shutting out strings from sum,
you don't really lose much in terms of duck typing, because duck
typing wouldn't have been that helpful anyway.


That boils down to an argument for type checking
whenever you cannot imagine my use case.  I hope
you do not write your own code that way...

Here is a use case you might have ruled out with
that approach.  A PyX `path` defines `__add__`
so that paths can be combined as subpaths of a
single path. This is  **VERY USEFUL**.
Now if I have a list of paths, it is useful to
to combine them: sum(pathlst,path()).

Alan Isaac

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


Re: restriction on sum: intentional bug?

2009-10-17 Thread Alan G Isaac

On 10/16/2009 8:16 PM, Terry Reedy wrote:

The fact that two or three people who agree on something agree on the
thing that they agree on confirms nothing.
 
On 10/17/2009 7:03 PM, Terry Reedy wrote:

If you disagree with this, I think *you* are being silly.



Well, ...


Alan G Isaac wrote:

Of course the numbers do not matter.
The *reasons* matter.


But you cut that...

It is a good idea not to quote too selectively if you
want to look like you are actually engaging the argument.
Anything else looks very self-serving.



On 10/17/2009 7:03 PM, Terry Reedy wrote:

Nothing I have said bears on whether I would have voted for or against
the current behavior.


While that certainly provides you with convenient shelter,
it does not move the discussion forward.

Cheers,
Alan Isaac

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


Re: restriction on sum: intentional bug?

2009-10-16 Thread Alan G Isaac

Alan G Isaac schrieb:

I expected this to be fixed in Python 3:


sum(['ab','cd'],'')

Traceback (most recent call last):
File stdin, line 1, inmodule
TypeError: sum() can't sum strings [use ''.join(seq) instead]

Of course it is not a good way to join strings,
but it should work, should it not?  Naturally,




On 10/16/2009 11:58 AM, Christian Heimes wrote:

It's not a bug. sum() doesn't work on strings deliberately. ''.join()
*is* the right and good way to concatenate strings.



You're not responding the the question at all:
the subject says intentional bug? and
the msg already noted that `join` is preferred,
but the part of the msg you cut out
asks why a violation of duck typing
is appropriate.

So of course join is better, as originally noted,
but that does not constitute a reason to intentionally
violate duck typing.

Alan Isaac

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


Re: restriction on sum: intentional bug?

2009-10-16 Thread Alan G Isaac

On 10/16/2009 3:40 PM, Tim Chase wrote:

What's always wrong is giving me an *error* when the semantics are
perfectly valid.



Exactly.
Which is why I expected this to be fixed in Python 3.

Alan Isaac

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


Re: restriction on sum: intentional bug?

2009-10-16 Thread Alan G Isaac

On 10/16/2009 5:03 PM, Christian Heimes wrote:

It's not going to happen.


That's a prediction, not a justification.

As Tim explained in detail, and as Peter
explained with brevity, whether it will
happen or not, it should happen.  This
conversation has confirmed that current
behavior is a wart: an error is raised
despite correct semantics. Ugly!

Alan Isaac

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


Re: restriction on sum: intentional bug?

2009-10-16 Thread Alan G Isaac

On 10/16/2009 8:16 PM, Terry Reedy wrote:

The fact that two or three people who agree on something agree on the
thing that they agree on confirms nothing. One could just as well argue
that summing anything but numbers is semantically incoherent, not
correct. Certainly, my dictionary points in that direction.



Come on now, that is just a silly argument.
And dictionaries are obviously irrelevant;
that is a sophomoric (literally) argument.

Of course the numbers do not matter.
The *reasons* matter.
And by citing Tim and Peter, I was pointing
to their quite specific *reasons*.

The only serious reason that has been offered
for the current behavior is that people who do
not know better will sum strings instead of
joining them, which is more efficient.  That is
a pretty weak argument for breaking expectations
and so refusing to do duck typing that an error
is raise. Especially in a language like Python.
(As Tim and Peter make clear.)

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


Re: restriction on sum: intentional bug?

2009-10-16 Thread Alan G Isaac

Alan G Isaacalan.isaacat  gmail.com  writes:

So of course join is better, as originally noted,
but that does not constitute a reason to intentionally
violate duck typing.



On 10/16/2009 1:03 PM, Benjamin Peterson wrote:

As Stephen pointed out, duck typing is not an absolute.



I do not recall anyone suggesting it was.
Do you?  If so, cite them.

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


Re: Is there a better way to code variable number of return arguments?

2009-10-08 Thread Alan G Isaac

Dr. Phillip M. Feldman writes:

I currently have a function that uses a list internally but then returns the
list items as separate return
values as follows:

if len(result)==1: return result[0]
if len(result)==2: return result[0], result[1]

(and so on).  Is there a cleaner way to accomplish the same thing?



The suggestions to return result
or if needed tuple(result) are good,
if a sequence is expected.

But perhaps better if each element has separate meaning:
return a defaultdict;
document the keys.
http://docs.python.org/library/collections.html#collections.defaultdict

Cheers,
Alan Isaac
--
http://mail.python.org/mailman/listinfo/python-list


Re: Programming ideas?

2009-09-20 Thread Alan G Isaac

You could learn a lot of Python contributing to
docutils or bibstuff, and if you write papers
or presentations, it may pay off directly.

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


Re: Looking for a pure Python chart drawing module

2009-09-16 Thread Alan G Isaac

Alan G Isaac wrote:

There's John Zelle's graphics.py:
http://mcsp.wartburg.edu/zelle/python/
provides basic functionality.



On 9/16/2009 12:33 AM, John Nagle wrote:

The package is a wrapper around Tkinter. It runs Tkinter
in a separate thread and sends commands to it.



Tkinter is part of the Python standard library:
http://docs.python.org/library/tk.html
Are you really ruling out its use for a pure Python
solution?

If you want a Python solution to not just create
the graphs but also to view them, it is hard to
see how you will do without this.  What exactly
are you trying to accomplish?

Alan Isaac

PS I think ReportLab can generate PDF vector graphics
even in the absence of a C compiler (which it will
use if available).

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


Re: Looking for a pure Python chart drawing module

2009-09-15 Thread Alan G Isaac

There's John Zelle's graphics.py:
http://mcsp.wartburg.edu/zelle/python/
provides basic functionality.

Pmw.Blt
http://heim.ifi.uio.no/~hpl/Pmw.Blt/doc/reference.html

pygooglechart
You suggested this needs a browser, but not so,
you can download the PNGs and use the default viewer
to display them.

But really, Matplotlib is both cross platform and great.

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


Re: string interpolation mystery in Python 2.6

2009-09-12 Thread Alan G Isaac

On 9/11/2009 9:42 PM, Steven D'Aprano wrote:

However, I must admit I'm perplexed why the original example is calling
__unicode__() in the first place! Given the line:

raise self.severe('Problems with %s directive path:\n%s: %s.'
 % (self.name, error.__class__.__name__, error))

it looks to me like it should be calling error.__str__() not
error.__unicode(). Making the suggested edit:

raise self.severe('Problems with %s directive path:\n%s: %s.'
 % (self.name, error.__class__.__name__, str(error)))

should have no effect. But it (apparently) does. This brings us back to
Alan's original question:

MYSTERY: how can %s%error be different from %s%str(error) in Python
2.6?



George Brandl explained it to me this way:

It's probably best explained with a bit of code:

  class C(object):
...  def __str__(self): return '[str]'
...  def __unicode__(self): return '[unicode]'
...
 %s %s % ('foo', C())
'foo [str]'
 %s %s % (u'foo', C())
u'foo [unicode]'

I.e., as soon as a Unicode element is interpolated into a string, further

interpolations automatically request Unicode via __unicode__, if it 
exists.

Pretty subtle ...

Cheers,
Alan Isaac

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


string interpolation mystery in Python 2.6

2009-09-11 Thread Alan G Isaac

MYSTERY: how can %s%error be different from %s%str(error) in Python 2.6?

APOLOGY: I tried to strip this down, but could not find a simple way to
reproduce the problem.  This way works, however.  (There is a discussion on
the docutils-develop list.)  Although there are several steps, we are talking
about less than 5 minutes to document the puzzle.  Please use the specific
revision (or earlier) in the directions, as later revisions implement a
work around.

1. Check out revision 6121 from docutils
http://docutils.sourceforge.net/docs/dev/repository.html

2. Install docutils under Python 2.6

3. Process the file below [1]_ using the rst2html.py script
(found in Python26/Scripts on Windows platforms)

4. Note the IOError::

temp.rst:: (SEVERE/4) Problems with include directive path:
IOError: (2, 'No such file or directory').
Exiting due to level-4 (SEVERE) system message.

5. Make the following change and *no other* changes:
In docutils/parsers/rst/directives/misc.py (line 66-67) change ::

raise self.severe('Problems with %s directive path:\n%s: %s.'
  % (self.name, error.__class__.__name__, error))

to ::

raise self.severe('Problems with %s directive path:\n%s: %s.'
  % (self.name, error.__class__.__name__, 
str(error)))

6. Process the same file the same way. Note the change in the IOError::

temp.rst:: (SEVERE/4) Problems with include directive path:
IOError: [Errno 2] No such file or directory: 'doesnotexist.rst'.
Exiting due to level-4 (SEVERE) system message.

7. Try this again in Python 2.5.  The correct (filename reported) error report
is produced both times.  So this is a Python 2.6 change.


Clues?  Bug or feature?

I'm going to hazard a guess that there was an undocumented (in What's New) 
change
to the __unicode__ method of BaseException.

Thanks,
Alan Isaac

.. [1] Following is the rst file to process:


Test


This is just a test.

.. include:: doesnotexist.rst

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


Re: Use python to execute a windows program

2009-09-11 Thread Alan G Isaac

Does the Windows application offer a COM interface?
http://oreilly.com/catalog/pythonwin32/chapter/ch12.html
http://sourceforge.net/projects/pywin32/

Alan Isaac

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


Re: incorrect DeprecationWarning (patch needed)

2009-09-08 Thread Alan G Isaac

On 9/5/2009 5:50 PM, Alan G Isaac wrote:

I've filed a bug report:
http://bugs.python.org/issue6844



This is now an accepted bug with a patch request.
Can someone on this list please assist with a patch?

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


Re: incorrect DeprecationWarning?

2009-09-05 Thread Alan G Isaac

Alan G Isaac wrote:

Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit
(Intel)] on win32
Type help, copyright, credits or license for more information.

class MyError(Exception):

... def __init__(self, message):
... Exception.__init__(self)
... self.message = message
...

e = MyError('msg')

__main__:4: DeprecationWarning: BaseException.message has been
deprecated as of Python 2.6


So? Why would that mean I cannot add such an attribute
to derived classes?




On 9/4/2009 6:42 PM, Terry Reedy wrote:

It does not mean that. Try printing e.message and you should see 'msg'.
I believe what it does mean is the the special meaning of
exception.message (I have forgotten what it is) is gone in Python 3.

In Py3
class MyError(Exception):
def __init__(self, message):
Exception.__init__(self)
self.message = message

e = MyError('msg')
print(e.message)

# 'msg'

No warning any more.




Exactly!

I think you are missing my point.
I understand it is just a DeprecationWarning.
But **why** should I receive a deprecation warning
when I am **not** using the deprecated practice?
Since I am **not** using the deprecated practice, the
warning is incorrect. (See the class definition above.)
And this incorrect warning affects a lot of people!

What anyone who is **not** using the deprecated practice
should expect in Python 2.6 is the Py3 behavior.  That is
not what we get: we get instead an incorrect deprecation
warning.

Alan Isaac


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


Re: incorrect DeprecationWarning?

2009-09-05 Thread Alan G Isaac

On 9/5/2009 9:07 AM, exar...@twistedmatrix.com wrote:

You are using the deprecated practice.


Clearly not, or it would fail in Python 3,
which it does not.


Attributes are not scoped to a
particular class. There is only one message attribute on your
MyError instance. It does not belong just to MyError. It does not
belong just to Exception. It does not belong just to BaseException.
It is shared by all of them.


No, it does not belong to any of those classes.
It belongs to the instance.


Because BaseException deprecates
instances of it having a message attribute


That is what is is doing, and that is precisely the problem.
The DeprecationError is raised for the wrong thing.
I mean be serious: this is flagging the use of
a new attribute on a subclass.  If you proposed building
a class that way the screams on unPythonic on this
list would be deafening.

I am not sure how best to deprecate dependence on the
Python 2.5 mistake, but this is not it.  And I know at
least one important library that is affected.

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


Re: incorrect DeprecationWarning?

2009-09-05 Thread Alan G Isaac

I've filed a bug report:
http://bugs.python.org/issue6844

Sadly the Twisted developers apparently did not file
a bug report when they were bitten by this ...

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


incorrect DeprecationWarning?

2009-09-04 Thread Alan G Isaac

Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)] on 
win32
Type help, copyright, credits or license for more information.

class MyError(Exception):

... def __init__(self, message):
... Exception.__init__(self)
... self.message = message
...

e = MyError('msg')

__main__:4: DeprecationWarning: BaseException.message has been deprecated as of 
Python 2.6


So?  Why would that mean I cannot add such an attribute
to derived classes?

Contrast:

Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)] on 
win32
Type help, copyright, credits or license for more information.

class MyError(Exception):

... def __init__(self, message):
... Exception.__init__(self)
... self.msg = message
...

e = MyError('msg')


Beyond odd.  A bug?

Alan Isaac

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


Re: Select column from a list

2009-08-28 Thread Alan G Isaac
On 8/28/2009 3:45 AM hoffik wrote:
 I'm quite new in Python and I have one question. I have a 2D matrix of
 values stored in list (3 columns, many rows). I wonder if I can select one
 column without having to go through the list with 'for' command.

Not quite what you asked but ...

 rows = [(1, 5, 9), (2, 6, 10), (3, 7, 11), (4, 8, 12)]
 cols = map(None,*rows)
 cols
[(1, 2, 3, 4), (5, 6, 7, 8), (9, 10, 11, 12)]

Now you can have any column you want.

Alan Isaac

PS You can also use imap if you prefer not to
create the list.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: flatten a list of list

2009-08-16 Thread Alan G Isaac
On 8/16/2009 5:47 AM Terry apparently wrote:
 Is there a simple way (the pythonic way) to flatten a list of list? 
 rather than my current solution:

 new_list=[] 
 for l in list_of_list:
 new_list.extend(l)


new_list = list(xi for lst in list_of_list for xi in lst)

hth,
Alan Isaac
-- 
http://mail.python.org/mailman/listinfo/python-list


random.gauss vs. random.normalvariate

2009-08-15 Thread Alan G Isaac
Quoting http://docs.python.org/3.1/library/random.html#random.gauss:
Gaussian distribution. mu is the mean, and sigma is the
standard deviation. This is slightly faster than the
normalvariate() function defined below.

So since both are offered and gauss is faster, I assume it
must have some offsetting disadvantage.  What is it?

Thank you,
Alan Isaac

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


Re: random.gauss vs. random.normalvariate

2009-08-15 Thread Alan G Isaac
 On Aug 15, 12:49 pm, Alan G Isaac alan.is...@gmail.com wrote:
 Quotinghttp://docs.python.org/3.1/library/random.html#random.gauss:
 Gaussian distribution. mu is the mean, and sigma is the
 standard deviation. This is slightly faster than the
 normalvariate() function defined below.

 So since both are offered and gauss is faster, I assume it
 must have some offsetting disadvantage.  What is it?



On 8/15/2009 4:26 PM Carl Banks apparently wrote:
 random.gauss is not thread safe.
 
 I'm kind of surprised the html docs don't mention this; the docstring
 does.



Thank you,
Alan Isaac
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: csv.DictWriter.write_header()

2009-08-14 Thread Alan G Isaac
 On Aug 13, 1:15 pm, Alan G Isaac alan.is...@gmail.com wrote:
 I do not understand the reason for your silly, sarcastic response.


On 8/13/2009 7:58 AM John Machin apparently wrote:
 Duck typing: ask a silly question, get a silly answer.

Maybe if you learned to be a more generous reader,
fewer questions would look silly to you.


On 8/13/2009 7:58 AM John Machin apparently wrote:
 I can imagine that one might (without reading the source) make do with
 the published APIs:

Now you get it.

 On Aug 13, 1:15 pm, Alan G Isaac alan.is...@gmail.com wrote:
 So my question was, would this improve the class from
 a usability perspective?

On 8/13/2009 7:58 AM John Machin apparently wrote:
 Of course.

Thank you,
Alan
-- 
http://mail.python.org/mailman/listinfo/python-list


retrieve item from nested list given index tuple

2009-08-14 Thread Alan G Isaac
`lst` is a nested list

`tpl` is the indexes for an item in the list

What is the nice way to retrieve the item?
(Speedy access is nice.)

I don't want to use NumPy, but I'd like somehow
to avoid an explicit loop.  I did consider using
eval.  E.g., eval('lst' + '[%d]'*len(tpl)%tpl).
It works but seems rather ugly.  I kind of like
reduce(list.__getitem__, tpl, lst) but the
reliance on reduce remains controversial enough
to see i removed from the Python 3 built-ins ...

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


Re: retrieve item from nested list given index tuple

2009-08-14 Thread Alan G Isaac
On 8/14/2009 1:09 PM Steven D'Aprano apparently wrote:
 Try this instead:
 
 from operator import getitem
 reduce(getitem, (2, 1, 0), lst)
 'aaa'
 reduce(getitem, (2, 1, 0, 0), lst)
 'a'
 
 operator.getitem is less ugly too.


Yes, that's better.
Thanks,
Alan
-- 
http://mail.python.org/mailman/listinfo/python-list


csv.DictWriter.write_header()

2009-08-12 Thread Alan G Isaac
Given a csv.DictWriter instance `dw`
I think it would be nice to be able to
say dw.write_header()
instead of
dw.writer.writerow(dw.fieldnames)

Good idea?

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


Re: csv.DictWriter.write_header()

2009-08-12 Thread Alan G Isaac
 On Aug 13, 6:45 am, Alan G Isaac alan.is...@gmail.com wrote:
 Given a csv.DictWriter instance `dw`
 I think it would be nice to be able to
 say dw.write_header()
 instead of
 dw.writer.writerow(dw.fieldnames)

 Good idea?


On 8/12/2009 10:24 PM John Machin apparently wrote:
 Yes, it's a brilliant idea. All you have to do is insert the following
 lines in your code after importing csv:
 
 csv.DictWriter.write_header = (
 lambda dw: dw.writer.writerow(dw.fieldnames)
 )


I do not understand the reason for your silly, sarcastic response.
I already showed you how to achieve the result, so obviously
I am not just asking for my own personal gain.

I take it you do not realize that many users do not see
a simple way to get this often needed functionality.
(For example, see the gymnatics suggested by Shai Vaingast
in his otherwise excellent and useful book.) And indeed,
there is no reason to expect them to.

So my question was, would this improve the class from
a usability perspective?  Do you have a useful response?

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


Re: invoke method on many instances

2009-07-22 Thread Alan G Isaac
 On Fri, 17 Jul 2009 05:19:50 +, Alan G Isaac wrote:
 def apply2(itr, methodname, *args, **kwargs):
 f = operator.methodcaller(methodname, *args, **kwargs)
 for item in itr:
 f(item)


 On 7/17/2009 3:45 AM Steven D'Aprano apparently wrote:
 for obj in objects:
 getattr(obj, methodname)(*args, **kwargs)


 En Sat, 18 Jul 2009 12:31:46 -0300, Alan G Isaac:
 Are there any obvious considerations in choosing 
 between those two? 


On 7/20/2009 3:29 AM Gabriel Genellina apparently wrote:
 The operator.methodcaller version is faster in my tests for large 
 collections, but slightly slower when you have very few elements. 


So it seems.  Is this easily explained?

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


are user defined classes hashable?

2009-07-19 Thread Alan G Isaac
Are user defined classes hashable?
(The classes; *not* the instances!)

I want to use some classes as dictionary keys.
Python is not objecting,
but I'm not sure how to think about
whether this could be dangerous.
I'm inclined to guess it will be hashed by id
and this is OK.

Thanks for any insights,
Alan Isaac
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: are user defined classes hashable?

2009-07-19 Thread Alan G Isaac
 * Alan G Isaac alan.is...@gmail.com [2009-07-19 13:48:16  +]:
 Are user defined classes hashable? 
 (The classes; *not* the instances!)
 I'm inclined to guess it will be hashed by id and this is 
 OK. 


On 7/19/2009 10:07 AM Nicolas Dandrimont apparently wrote:
 You can check for yourself:

 In [1]: class Foo(object):
...: pass
...:

 In [2]: foo = Foo()

 In [3]: hash(foo)
 Out[3]: 15294992 

 In [4]: id(foo)
 Out[4]: 15294992 



Again, my question is about the class not its instances,
but still, checking as you suggest gives the same answer.

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


Re: invoke method on many instances

2009-07-18 Thread Alan G Isaac
 On Fri, 17 Jul 2009 05:19:50 +, Alan G Isaac wrote:
 def apply2(itr, methodname, *args, **kwargs):
 f = operator.methodcaller(methodname, *args, **kwargs)
 for item in itr:
 f(item)


On 7/17/2009 3:45 AM Steven D'Aprano apparently wrote:
 for obj in objects:
 getattr(obj, methodname)(*args, **kwargs)


Are there any obvious considerations in choosing
between those two?



 See also these recipes from the Python Cookbook: 
 http://code.activestate.com/recipes/52289/
 http://code.activestate.com/recipes/87370/

Interesting.

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


invoke method on many instances

2009-07-16 Thread Alan G Isaac
As a recurrent situation, I need to invoke the same method
on many instances.  Speed matters, but the solution should
be pure Python.  Is the following convenience function
a reasonable approach?

def apply2(itr, methodname, *args, **kwargs):
f = operator.methodcaller(methodname, *args, **kwargs)
for item in itr:
f(item)

(Comment: in the case at hand, the methods return None.)

Thank you,
Alan Isaac


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


Re: Clarity vs. code reuse/generality

2009-07-04 Thread Alan G Isaac
On 7/4/2009 12:30 PM kj apparently wrote:
 I'm beginning to think that the original precept was simply cargo
 cult, i.e. one of those rules that are parroted without being
 fully understood.


Adopting such a view is of course an alternative to
attempting to understand, but perhaps less useful.

Alan Isaac

PS For additional explanation:
http://java.sun.com/j2se/1.4.2/docs/guide/lang/assert.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Clarity vs. code reuse/generality

2009-07-03 Thread Alan G Isaac
 In mgo3m.591$p5...@nwrddc02.gnilink.net Alan G Isaac alan.is...@gmail.com 
 writes:
 1. Don't use assertions to test argument values!


On 7/3/2009 12:19 PM kj apparently wrote:
 Out of curiosity, where does this come from? 


http://docs.python.org/reference/simple_stmts.html#grammar-token-assert_stmt
The current code generator emits no code for an assert statement when 
optimization is requested at compile time.

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


Re: Python 3.0 (pinin' for the fjords)

2009-07-02 Thread Alan G Isaac
Using the 3.1 Windows installer, I chose that I did not
want the extensions registered, and the installer
unregistered the .py and .pyw extensions (which I had wanted
to keep associated with Python 2.6).

Is this intentional?

Alan Isaac

PS I already fixed the problem.  My question
is about intent.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Open source python projects

2009-06-22 Thread Alan G Isaac
On 6/22/2009 3:40 PM saurabh apparently wrote:
 I am an experienced C programmer and recently dived into python,
 I have developed an instant love for it.
 I have been doing some routine scripting for day to day admin tasks,also 
 have done some Tkinter and socket programming using python.
 
 I am looking for some open source python project preferably in one of
 the above areas (not strictly, am open to others too) to contribute.

A one off project ...

If you can help figure out how to produce a Windows installer
of SimpleParse for Python 2.6 and post your experience here,
I believe quite a few projects would profit, not to mention
the SimpleParse users themselves.

Cheers,
Alan Isaac
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Regarding Python is scripting language or not

2009-06-19 Thread Alan G Isaac
On 6/17/2009 8:38 AM Jean-Michel Pichavant apparently wrote:
 I'm pretty sure you'll be able to find OOP scripting 
 language.


URL:http://www.amazon.com/Scripting-Objects-Comparative-Presentation-Object-Oriented/dp/047039725X/ref=sr_1_1?ie=UTF8s=booksqid=1245276357sr=1-1

fwiw,
Alan Isaac
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: please help...writing set to a file

2009-06-18 Thread Alan G Isaac
On 6/18/2009 5:24 AM yadin apparently wrote:
 I got this python program that returns me a set like this..
 Set ([‘A\n’, B\n’, ‘C\n’, ‘D\n’, ‘E\n’, ‘F\n’, ‘G\n’ ])
 And a list pp = [‘100\n’ ‘200\n’ ‘300\n’ ‘400\n’]
 I was reading this from a file….
 How can I transform this to something that looks like this
 Column1 Column 2
 
   100  A
200 B
300 C
 400D
E
F
  G
 And then write this to a file???


http://docs.python.org/library/functions.html#sorted

http://docs.python.org/library/itertools.html#itertools.izip_longest

http://docs.python.org/library/stdtypes.html#str.format

http://docs.python.org/library/functions.html#open

hth,
Alan Isaac
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Perl's @foo[3,7,1,-1] ?

2009-06-17 Thread Alan G Isaac
On 6/17/2009 4:03 PM J. Cliff Dyer apparently wrote:
 example code
 should always include relevant imports.


Agreed. It was a cut and paste failure.
Apologies.

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


Re: Perl's @foo[3,7,1,-1] ?

2009-06-16 Thread Alan G Isaac
On 6/13/2009 2:11 PM kj apparently wrote:
 Switching from Perl here, and having a hard time letting go...
 
 Suppose I have an array foo, and that I'm interested in the 4th, 8th,
 second, and last element in that array.  In Perl I could write:
 
   my @wanted = @foo[3, 7, 1, -1];

 a = np.arange(10)
 a
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
 a[[3,7,1,-1]]
array([3, 7, 1, 9])

hth,
Alan Isaac
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: matplotlib installation

2009-06-12 Thread Alan G Isaac
On 6/12/2009 5:55 AM Virgil Stokes apparently wrote:
 Any suggestions on installing matplotlib for Python 2.6.2 on a Windows 
 Vista platform?


Maintainers for some packages have run into a wall
compiling for 2.6.  Matplotlib is one of these:
http://www.nabble.com/binary-installers-for-python2.6--libpng-segfault%2C-MSVCR90.DLL-and-%09mingw-td23971661.html

Another package I care about is SimpleParse, which also
found compiling for 2.6 to be impossible.  I do not know
if this was the same problem or not, but it means that
SimpleParse is *still* not available as an installer for 2.6.

I assume this is of great concern to the Python community,
but I do not know where the discussion is taking place.

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


Re: trying to understand dictionaries

2009-06-12 Thread Alan G Isaac
On 6/12/2009 7:51 AM khem...@gmail.com apparently wrote:
 d = {'fname': [], 'ename': []}
 name1 = 'ricky'
 name2 = 'martin'
 d['fname'].append(name1)
 d['ename'].append(name2)
 
 name1 = 'britney'
 name2 = 'spears'
 d['fname'].append(name1)
 d['ename'].append(name2)
 
 
 This gives me:
 {'ename': ['martin', 'spears'], 'fname': ['ricky', 'britney']}


Trying to stick close to your example,
reverse the use of lists and dicts.

worst_musicians = list()
entry = dict(fname='ricky',lname='martin')
worst_musicians.append(entry)
entry = dict(fname='britney',lname='spears')
worst_musicians.append(entry)

for musician in worst_musicians:
print %(fname)s %(lname)s%musician

hth,
Alan Isaac
-- 
http://mail.python.org/mailman/listinfo/python-list


define generator (glossary bug?)

2009-05-22 Thread Alan G Isaac

I believe the glossary
http://wiki.python.org/moin/PythonGlossary
is missing the definition for 'generator'
and has used instead the definition for 'generator function',
which term is missing from the glossary.

Standard usage as I understand it is found here:
http://docs.python.org/3.0/reference/simple_stmts.html#the-yield-statement

Cheers,
Alan Isaac
--
http://mail.python.org/mailman/listinfo/python-list


Re: define generator (glossary bug?)

2009-05-22 Thread Alan G Isaac
On Fri, 22 May 2009 16:38:40 GMT, Alan G Isaac alan.is...@gmail.com 
wrote:

I believe the glossary
http://wiki.python.org/moin/PythonGlossary
is missing the definition for 'generator'
and has used instead the definition for 'generator function',
which term is missing from the glossary.

Standard usage as I understand it is found here:
http://docs.python.org/3.0/reference/simple_stmts.html#the-yield-statement 



On 5/22/2009 1:07 PM Jean-Paul Calderone apparently wrote:

Well, it seems someone edited the wiki since you sent your message, since
there is no longer an entry for generator function, but instead one for
generator.

However, I think it was right before. 



Nope, it is still the same, and that is the problem.
(My which term refered to 'generator function'.)

So you agree: it is a documentation bug in the glossary.

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


Re: define generator (glossary bug?)

2009-05-22 Thread Alan G Isaac

On 5/22/2009 1:44 PM s...@pobox.com apparently wrote:

Note that the glossary page is on the wiki.  Feel free to make corrections.


Well, ok, I've done so:
http://wiki.python.org/moin/PythonGlossary

But I'm just a user.  Someone should check it.

Thanks,
Alan Isaac

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


Re: 2d barcode library?

2009-05-20 Thread Alan G Isaac

Christian Heimes wrote:

https://cybernetics.hudora.biz/projects/wiki/huBarcode



Cool.
I have to mention a pure PostScript writer as well:
http://www.terryburton.co.uk/barcodewriter/

Alan Isaac

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


Re: LaTeXing python programs

2009-05-20 Thread Alan G Isaac
On Wednesday 20 May 2009 18:43:21 Edward Grefenstette 
wrote:
is there a LaTeX package out there that works well for 
presenting python code? 



José Matos wrote:
Use the listings package. 
It has a python as one of defined languages and has lots of other options. 
http://www.ctan.org/tex-archive/macros/latex/contrib/listings/ 



The listings package is great and highly configurable.
Note that you can also input entire files of Python code
or pieces of them based on markers.  Really quite great.

Cheers,
Alan Isaac
--
http://mail.python.org/mailman/listinfo/python-list


Re: reseting an iterator

2009-05-20 Thread Alan G Isaac

Jan wrote:

Wouldn't it be easy for Python to implement generating functions so
that the iterators they return are equipped with a __reset__() method?


Use ``send``:
http://docs.python.org/whatsnew/2.5.html#pep-342-new-generator-features

Remember, there may be no underlying sequence object for
an iterator, and if you want one in that case, you should build it.

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


color propagation in tkinter

2009-04-20 Thread Alan G Isaac

I'm a tkinter novice.

If I want to propagate changes to a font,
I can just use a named font.

What if I want to propagate color changes?
(E.g., a change in background color for
a number of widgets.)

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


Re: color propagation in tkinter

2009-04-20 Thread Alan G Isaac

On Apr 20, 12:35 pm, Alan G Isaac alan.is...@gmail.com wrote:

If I want to propagate changes to a font,
I can just use a named font.

What if I want to propagate color changes?
(E.g., a change in background color for
a number of widgets.)




On 4/20/2009 1:59 PM Mike Driscoll apparently wrote:

One way would be to keep a list of the widgets that you want to be
able to change the color of, and then loop over the list and change
their respective colors as needed.



Yes, that's what I am currently doing.
But it seems that that is exactly the kind of thing
we are enabled to avoid with e.g., named fonts.
So I was hoping for an equivalent functionality
for colors.  From your answer, I am guessing there
is none.

This is an example where different behavior by
StringVar could have been put to good use, I think.

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


rectangles, or cavases, or ... ?

2009-04-20 Thread Alan G Isaac

I need to display many (e.e., 2000) small squares whose colors are udpated
each time a computation is complete.

One approach is to put rectangles on a single canvas.
Another approach is to put many canvases in a single frame.
Another approach is to create an image each iteration,
which is placed on a canvas.
Other?

Are there obvious considerations in the choice?
(Right now I do not need to interact with the squares,
but in the future I may need to.)

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


Re: rectangles, or cavases, or ... ?

2009-04-20 Thread Alan G Isaac

On 4/20/2009 5:59 PM Scott David Daniels apparently wrote:

You should have said, but I'll guess you are using Tkinter.


Yes, I should have, sorry.  You are right, I'm using Tkinter.



I'd put the rectangles on a canvas, myself.


That's my current choice, but I'm not seeing into
what the trade-offs are.  That's my question: what's
the basis of your choice?

Thanks,
Alan

PS Am I right that Tkinter does not offer the ability to
draw many rectangles in one go (along the lines of the
PostScript rectfill operator)?
--
http://mail.python.org/mailman/listinfo/python-list


Re: rectangles, or cavases, or ... ?

2009-04-20 Thread Alan G Isaac

On 4/20/2009 7:43 PM John McMonagle apparently wrote:

Approach 1: put many rectangles on a single canvas

This is the most flexible approach.  It allows you to take advantage of
Tkinter canvas tag bindings to interact with individual or groups of
canvas items.   It also allows you to use some pretty handy find methods
for the canvas items (find_closest, find_withtag, etc).  You can
configure properties of the item, such as fill colour, without needing
to redraw all the items.

The downside of this approach is, because each rectangle you draw is a
canvas item, it is also an object.  The implications of this is that
your memory usage increases with the more items you draw.



Great summary, and you clued me into a bunch of
methods I had not explored.
Thanks!
Alan
--
http://mail.python.org/mailman/listinfo/python-list


Re: rectangles, or cavases, or ... ? under Tkinter

2009-04-20 Thread Alan G Isaac

On Apr 20, 5:29 pm, Alan G Isaac alan.is...@gmail.com wrote:

I need to display many (e.e., 2000) small squares whose colors are udpated
each time a computation is complete.

One approach is to put rectangles on a single canvas.
Another approach is to put many canvases in a single frame.
Another approach is to create an image each iteration,
which is placed on a canvas.
Other?

Are there obvious considerations in the choice?
(Right now I do not need to interact with the squares,
but in the future I may need to.)





On 4/20/2009 5:52 PM FogleBird apparently wrote:

First of all, what GUI toolkit are you using?


Tkinter.  (Sorry; I meant to include that in the subject line.




Secondly, in wxPython I would subclass wx.Panel and handle the
EVT_PAINT event to just draw the rectangles.  Generally I render to an
off-screen DC and just blit that in the paint event.


I'm guessing that approach will be fastest.



What kind of frame rate do you need?


20fps or less.
(Actually, at the moment, much less.)

Thanks,
Alan

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


Re: DVCSs wreck tkFileDialog

2009-04-14 Thread Alan G Isaac

More info:
URL:http://sourceforge.net/mailarchive/forum.php?thread_name=A46CBF978138744AAC019E6FF055EAB70F30AE%40apatlelsmail08.elsys.gtri.orgforum_name=tortoisehg-develop

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


Re: Using Python after a few years of Ruby

2009-04-14 Thread Alan G Isaac

On 4/14/2009 3:01 AM blahemailb...@gmail.com apparently wrote:

1) Rake - is there an equivalent of Rake? I've seen a bit about SCons,
and it looks really nice, but it seems geared towards being a Make
replacement for C/C++ rather than something that's used to work with
Python itself. Is there anything like a Python build tool? (Or do I
even need something like that? I haven't worked with any large Python
systems, just little things here and there.)


http://www.scons.org/wiki/SconsVsOtherBuildTools

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


tkFileDialog - ImportError: No module named shell

2009-04-13 Thread Alan G Isaac

Why do I get the ImportError below?
What is the right way to do this?
Thanks,
Alan Isaac



Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] on 
win32
Type help, copyright, credits or license for more information.
 import Tkinter as tk
 root=tk.Tk()
 import tkFileDialog
 fh = tkFileDialog.asksaveasfile()
Traceback (most recent call last):
  File boot_com_servers.py, line 44, in module
  File tbzr.pyo, line 125, in module
  File tbzr.pyo, line 60, in get_all_com_classes
  File contextmenu.pyo, line 9, in module
ImportError: No module named shell
Redirecting output to win32trace remote collector
--
http://mail.python.org/mailman/listinfo/python-list


Re: tkFileDialog - ImportError: No module named shell

2009-04-13 Thread Alan G Isaac
On Apr 13, 11:26 am, Alan G Isaac alan.is...@gmail.com 
wrote:
Why do I get the ImportError below? 
What is the right way to do this? 
Thanks, 
Alan Isaac 


Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC 
v.1310 32 bit (Intel)] on win32 Type help, copyright, 
credits or license for more information. 
  import Tkinter as tk

  root=tk.Tk()
  import tkFileDialog
  fh = tkFileDialog.asksaveasfile()
Traceback (most recent call last):
   File boot_com_servers.py, line 44, in module
   File tbzr.pyo, line 125, in module
   File tbzr.pyo, line 60, in get_all_com_classes
   File contextmenu.pyo, line 9, in module
ImportError: No module named shell 
Redirecting output to win32trace remote collector 




On 4/13/2009 2:28 PM Mike Driscoll apparently wrote:
Well, if you have tortoisehg installed, uninstall it. That was what 
was giving me this exact error with wxPython file dialogs. 




No, I don't have tortoisehg.
But, I do have Bazaar installed,
and that is the only place I see contextmenu.pyo.

And that appears to be the source of the problem:
https://bugs.launchpad.net/bzr/+bug/305085

Can you help me understand how
another application can interfere with Tkinter
in such a fashion?

Thank you!
Alan Isaac

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


Re: possible pairings in a set

2009-04-13 Thread Alan G Isaac

I cannot access this thread right now so my
answer my be rednundant, but anyway:
http://docs.python.org/library/itertools.html#itertools.combinations

 from itertools import combinations
 print(list(combinations(range(4),2)))
[(0, 1), (0, 2), (0, 3), (1, 2), (1, 3), (2, 3)]

hth,
Alan Isaac
--
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter questions: behavior of StringVar, etc

2009-03-30 Thread Alan G Isaac

On 3/30/2009 3:37 AM Eric Brunel apparently wrote:

The object traditionally called root is in fact an instance of the tcl
interpreter that will get the commands generated by the Tkinter module. Due to
tk architecture, creating this interpreter will also create a window, which is
inteneded to be your application's main window. This window is called '.' in
tcl/tk. The root object in Tkinter then represents this '.' window. So the
instance of Tk is actually 2 things:
- The interpreter itself;
- The main window for your application.


OK.


As for when you should create explicitely an instance of Tk, well, I'd say
always ;-) Creating an instance of Frame without creating a Tk instance first
will actually create one, but you'll have no direct access to it.


If I start by creating a frame `f`, then ``f.master`` is the root.
Still, I take your point.


And you
might want an access to it for quite a number of reasons: hiding it, make it
an icon, add menus to it, and so on... All these operations can be done on
actual windows, not on a Frame which is just a container widget.


Useful.  Thanks.


All Tkinter widget actually
reference their interpreter in their tk attribute. The StringVar will probably
just use that.


Yes, I see how this works now.


The Tk instance is registered in a hidden variable in the Tkinter module. When
you don't specify a master, it'll use the latest created Tk instance one by
default. BTW, the latest should be the only one: it is quite unsafe to create
several Tk instances in the same application.


I have no desire to do this, but might you pin down unsafe?


I guess
that having a window automatically created when you just try to instantiate a
variable has been considered weird. But it's just a guess.


Yes, I am making that same guess.

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


Re: tkinter questions: behavior of StringVar, etc

2009-03-30 Thread Alan G Isaac

On 3/30/2009 3:37 AM Eric Brunel apparently wrote:

The string representation of Tkinter objects seems to be a design principle in
this module: it'll always evaluate to the representation this object has at
tcl level. Since a XxxVar is represented by an actual variable at tcl level,
its string representation is the name of this variable. I guess it's quite
easier to build the commands that'll be passed to the tcl interpreter this
way: you don't have to check the type of the objects you handle, but pass them
through str and insert the result directly in the command.



This is a helpful answer: it feels right and can be
explored further.

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


Re: tkinter questions: behavior of StringVar, etc

2009-03-29 Thread Alan G Isaac

On 3/29/2009 3:43 AM Scott David Daniels apparently wrote:

OK, that was plain rude.  a couple of questions is not six questions.
A reply telling you how to get to some of what you are looking for
is assistance.  If you want exact answers to an array of questions,
pay someone to fetch you the answers, or do your own homework.

Clearly I am too grumpy this weekend.



Yes you are too grumpy.  It is *not* rude to point
out that the answers are not where I was pointed.
The available docs are much more focused on how
rather than on why.

Please show me how to use that response to get
even one of the answers.  (Please skip #2, since I
fear a repetition of the kind of answer in all the docs,
which is half an answer.) Or, withdraw your claim.

Btw, I cannot find the answers in Grayson's book either.
It's a big book though, and covers much ground, so I
do not deny the answers might well be in there somewhere.

Let's try just these two:
- Why does a Variable need a master?
- If s is a StringVar instance, why is
  str(s) its name rather than its value?

Thank you,
Alan Isaac
--
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter questions: behavior of StringVar, etc

2009-03-29 Thread Alan G Isaac

On 3/29/2009 7:29 AM Francesco Bochicchio apparently wrote:
1. Tkinter is only a thin wrapper over Tk, a GUI library initially 
developed for Tcl language, so many of the answer to the design choices 
you question (e.g. what is the master) cannot between answered within 
the python documentation but should be searched in the Tcl/Tk 
documentation. So google for tcl/tk. 
Anyway, all GUI libraries I know of build the GUI as a hierarchical 
structure. The master (often called root) ia the root of this 
hierarchy, and you have to build it before building the rest. 


I understand this.  But I do not understand what we get
by having each Variable instance register a master.
(In contrast, e.g., to a container widget, such as a Frame,
where I do not have this question.)


2. Another good source of information is the source of Tkinter itself, 
which is mostly in the Tkinter.py file. 


In Python 3, I'm finding most of the useful stuff to be in
``tkinter/__init__.py``.  It is indeed useful, but not
always transparent.  At least to a new user.


if you for instance look at the __init__ method of the 
Variable class (which is the basic class of StringVar), 
you will easily find the 'magic' to which you refer to.  


What we find is that Variable is initialized with:
if not master:
master = _default_root
which in turn is initialized to None.  I understand this.
Actually, talking this through, I get it now.  I was not
properly thinking about the use of module level globals.
Thanks.


If you don't like the choices which have been made there 
(e.g not automagically creatinga a master for variables 
but doing it for frames ), you could try and submit 
a  patch :-)


I am not so presumptuous.  I just want to understand why a
Variable needs a master.  How is this used?

And, I would like to understand if there is a *reason* that
a StringVar instance, for example, does not behave more like
a string.


3. Usually the changes between one version of python and the next are 
documented (but not in all gory details) in What is new documents you 
can find  in python.org site. I'm not aware of any change 
for Tkinter, in Python 3.0 but go read it yourself.


I did look there, and explicitly got only that the new name
is ``tkinter``.   However, there are other changes, e.g. the
names and location of ``colorchooser`` and ``filedialog``.
I realize now that the statement related modules have been
grouped into packages, and usually the submodule names have
been simplified is supposed to capture all this, but an
explicit list would have been helpful to me.  (And,
I assume, to others.)  I also just assumed that some active
user had made a list of changes, which I had overlooked, but
that someone on this list would be aware of.

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


Re: tkinter questions: behavior of StringVar, etc

2009-03-29 Thread Alan G Isaac

Alan asked:
- Why does a Variable need a master? 
- If s is a StringVar instance, why is 
  str(s) its name rather than its value?


On 3/29/2009 2:46 PM Scott David Daniels apparently wrote:
The answer to that, grasshopper, lies in the answer to the question, 
What are StringVars designed to do?  StringVars, and IntVars, and ... 
are elements to receive, hold, and propagate changes to values that 
will produce effects in the programs behavior or display.  I find 
IntVars easier to explain, since you get values for numbers lots of 
ways.  If a slider updates an IntVar, a signal must reach anything 
interested in the value of that IntVar.  For example, you have a 
rectangle, and a display of its height, width, area, and aspect ratio. 
If you change the height or the width, the area and aspect ratio need 
updating (as well as the value in the height or width).


In short, a Variable can have observers.  My question does
not lie here.  At least, you have not persuaded me that it does.


Rather than building systems where every control maintain 
lists of what to notify and how to communicate the value, 
things like IntVars and StringVars work as data store and 
signal propagation points.  One of the Vars is more Var 
than value: a place to go to look for the current value, 
and a place to register for notification when changes 
happen.  Clearly you cannot signal changes from a variable 
unless the whole event mechanism is running.



I take this to be the core of your argument: that a Variable
cannot signal to a widget until the event mechanism is up
and running.  But of course if you create e.g. a Frame, the
root is automagically created.  So I do not understand
your reasoning.

To elaborate, where could things go wrong if I could
instantiate a Variable without first instantiating a Tk root
object?  You note that the variable would have no work to do
in an event mechanism until that mechanism was created, but
then again, it could not (right?) have an relevant
association under the current architecture until a root was
instantiated.

For example, suppose I want to associate an ``Entry`` with
a ``StringVar``. If I have not already created a root,
I would have to create the ``Entry`` first (which
auotmagically creates the root) and then the ``StringVar``,
but what is the payoff from this restriction?


A StringVar needs to know where to send signals about its 
changes.  Thus two different StringVars containing the 
same text can behave quite differently, as each may be 
hooked into a different network of event propagation. 


Yes of course.  See above.
Just to be clear, I am not so presumptuous as to try to
challenge the design.  I am trying to understand it.

Here's what I think the answer might be (following a hint
from Francesco).  I think that this restriction serves no
direct function in Python, but is used manage communication
between Python and Tk/Tcl.  That is, the current design
simply ensures that *at creation* a Variable has a corresponding
Tcl variable and is named in a way that matches the order of
creation.  (Roughly.  In addition it looks like multiple Variable
instances can share a name and thus reference a single Tcl
variable.)  While this does not explain why a Variable,
unlike a Widget, will not create a root object on an as
needed basis, it does explain why the root object is
required for Variable creation.

Thanks,
Alan Isaac

PS If you were also offering an answer to the second question,
I missed it altogether, but although it is perhaps slightly
less obvious than with a StringVar, I would ask the same
basic question of an IntVar: why does it not behave more
like an int?  E.g., why is ``int(IntVar(value=5))`` an
error, or at least, why is ``str(IntVar(value=5))`` the name
of the IntVar instead of '5'?

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


Re: tkinter questions: behavior of StringVar, etc

2009-03-29 Thread Alan G Isaac

On 3/29/2009 2:46 PM Scott David Daniels apparently wrote:
You ask, What exactly is the role of ..., rather than 
saying something like, I don't understand the role of 
..., and continue to ask why the code is not architected 
the way you first expected it to be architected, calling 
those things you do not understand magic  (not 
magically which would at least invoke a sense of wonder, 
rather than indignation). 



Clearly there are some cultural differences here.  I am not
a CS type.  I would not presume to criticize the
architecture, and in my world, questions are generally
assumed to be what they appear to be: questions.

Additionally, I confess to be completely ignorant of the
nuances you suggest between using the term magic and
saying something happened magically.  I meant it only in
the sense that John has since used it: as suggesting
something not obvious (to me) was taking place.  I had no
intent to communicate indignation with this term and indeed
am startled that it could be so construed.  Is this nuance
really universal on this list?

Cheers,
Alan Isaac
--
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter questions: behavior of StringVar, etc

2009-03-29 Thread Alan G Isaac

On 3/29/2009 6:50 PM Rhodri James apparently wrote:

In this case, your choice of wording
(the nearest thing we have in print to tone of voice) did not
inspire me to go digging around in source that you have just as
easy access to, in order to answer questions that I'm not
particularly interested in.



I certainly was not trying to inspire you to do so.
The question was meant for people who had this
level of understanding already, or who already
knew with some specificity where I might dig.

Since you did not address my question about
the nuance of magic, I'm inclined to treat
you as a no vote.

Thanks,
Alan Isaac

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


Re: tkinter questions: behavior of StringVar, etc

2009-03-29 Thread Alan G Isaac

On 3/29/2009 6:49 PM Scott David Daniels apparently wrote:
Right.  Tkinter could have been built to make a root at 
the first instantiation of a StringVar or IntVar, but it 
wasn't.  Answering your why is a bit like answering the 
Why did Picasso choose primarily blue in his Blue Period, 
rather than green?


But this is a fine answer: a choice had to be made, and
nothing much seemed to be at issue, so this was the simpler
(or whatever) choice.  I did not ask for a deeper answer,
but if that is the correct answer, it cannot be expected to
be obvious to those who are new to the code.


Hmmm -- where cvould things go wrong --- segment fault? 
what happens when you call code that hasn't had the setup run? 


Again, I do not understand, and I think I explained why.
Of course if the Variable is not registered with Tcl/Tk at
*creation*, it will have to be registered when first
associated with a widget (or in any way with the event
mechanism).  But of course my question was why a Variable
cannot exist independently of the event mechanism.  Since
you did not critique the answer I proposed in my previous
post, I assume you do not have a big problem with it.  If it
is correct, it is the kind of answer I was looking for.


What happens to your TV when you change the channel before 
turning it on? 


I think we can agree this is a safe action, but the result
depends  on the kind of TV (and on what turning it on means).
So I think your analogy makes my point: allowing
the state of the variable to be registered at use rather than
creation is feasible, although it would perhaps not be best.
(E.g., it would not be simplest.)


Printing a StrVar is not the same as printing the contents 
of a StrVar.  Having magic conversions happen for you 
when they can be useful simply allows you to make mistakes 
about what things are what.


This sounds like an argument against duck typing, and maybe
even an argument for eliminating most of the special method
names, although I'm sure you did not mean it to be this.  ;-)

Thanks for the discussion.  Your willingness to converse
with someone whose initial tone irritated you has helped
me to improve my understanding, and hopefully some future
user will find this thread of some use.

Cheers,
Alan Isaac
--
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter questions: behavior of StringVar, etc

2009-03-29 Thread Alan G Isaac
On Mon, 30 Mar 2009 00:13:46 +0100, Alan G Isaac alan.is...@gmail.com 
wrote:

Since you did not address my question about
the nuance of magic, I'm inclined to treat
you as a no vote.



On 3/29/2009 7:19 PM Rhodri James apparently wrote:

And you'd be wrong.



So seriously, you'd read e.g. John's usage
of the term magic (in this thread)
to suggest indignation?

Curious.  But I recognize that cultures differ.

Alan Isaac



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


Re: email from windows

2009-03-29 Thread Alan G Isaac

2009/3/29 prakash jp prakash.st...@gmail.com:

In windows environment, how to send email from one gmail address to another
gmail (or another mail) addrress



On 3/29/2009 10:20 PM Chris Rebert apparently wrote:

Use the `smtplib` and `email` standard libraries (which, as a bonus,
are cross-platform):
http://docs.python.org/library/smtplib.html
http://docs.python.org/library/email.html



Also see:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/67083

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


tkinter questions: behavior of StringVar, etc

2009-03-28 Thread Alan G Isaac

I'm a complete newbie to GUI.
I have a couple questions about tkinter.

1. Where is the list of changes
   in Python 3's tkinter?

2. What exactly is the role of the root object,
   traditionally created as ``root=tk.Tk()``?
   What is an example where one should create this
   before creating a Frame instance (which will
   otherwise implicitly create one as its master)?

2. Suppose I ``import tkinter as tk`` and
   then try ``s1=tk.StringVar()``.  This fails
   because no master is set. Why does a
   Variable need a master?

3. Now suppose I set ``root = tk.TK()`` and
   then try ``s1=tk.StringVar()``.  This
   works fine but now seems a bit magical:
   how has the value of the master been
   set?

4. Another bit of magic:
   Suppose I ``import tkinter as tk`` and
   then try ``f1=tk.Frame()``.  This works
   fine: apparently calling Frame also
   leads to implicit creation of a master.
   Why is what is good for the gander (i.e.,
   implicit master creation for a Frame) not
   good for the goose (i.e., a Variable)?
   (Here I assume that there has been an
   answer to 2. above.)

5. Reading around a bit,
   it seems common to recommend setting
   the values of Variables rather than initializing
   them.  Why?  I cannot see the reason to avoid
   ``s1=tk.StringVar(value=this works fine)``
   and it looks like ``tk.StringVar(()`` is in any
   case initialized (to an empty string).

6. Why is str(s1) not its value?  More generally,
   why does a StringVar not behave more like a string?

Thanks for any insights,
Alan Isaac
--
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter questions: behavior of StringVar, etc

2009-03-28 Thread Alan G Isaac
On Mar 28, 2:15 pm, Alan G Isaac alan.is...@gmail.com 
wrote:
I'm a complete newbie to GUI. 
I have a couple questions about tkinter. 


1. Where is the list of changes 
in Python 3's tkinter?


2. What exactly is the role of the root object, 
traditionally created as ``root=tk.Tk()``?

What is an example where one should create this
before creating a Frame instance (which will
otherwise implicitly create one as its master)?


2'. Suppose I ``import tkinter as tk`` and 
then try ``s1=tk.StringVar()``.  This fails

because no master is set. Why does a
Variable need a master?


3. Now suppose I set ``root = tk.TK()`` and 
then try ``s1=tk.StringVar()``.  This

works fine but now seems a bit magical:
how has the value of the master been
set?



4. Another bit of magic:
Suppose I ``import tkinter as tk`` and
then try ``f1=tk.Frame()``.  This works
fine: apparently calling Frame also
leads to implicit creation of a master.
Why is what is good for the gander (i.e.,
implicit master creation for a Frame) not
good for the goose (i.e., a Variable)?
(Here I assume that there has been an
answer to 2. above.)


5. Reading around a bit, 
it seems common to recommend setting

the values of Variables rather than initializing
them.  Why?  I cannot see the reason to avoid
``s1=tk.StringVar(value=this works fine)``
and it looks like ``tk.StringVar(()`` is in any
case initialized (to an empty string).


6. Why is str(s1) not its value?  More generally, 
why does a StringVar not behave more like a string?




On 3/28/2009 6:19 PM Mike Driscoll apparently wrote:
Try Google and the Python website. There is tons of info on the Python 
wiki:
http://wiki.python.org/moin/TkInter 
There are also some books that walk you through Tkinter application 
creation, for example,Lutz's Programming Python. 



Sorry, but I do not see the answers to any of the above
questions, not even the first one.  Do you?  (One might
believe question 2 is answered, but if you read it, I
think you will see why I do not.)

Cheers,
Alan Isaac
--
http://mail.python.org/mailman/listinfo/python-list


Re: Using python 3 for scripting?

2009-03-23 Thread Alan G Isaac

On 3/22/2009 12:41 PM Chris Rebert apparently wrote:

2.6.1, the latest non-3.x release is probably best. Most libraries
haven't been ported to 3.x yet, so Python 3 has yet to become
widespread.



This seems slightly optimistic to me.
Until a week ago, there was not a NumPy release for 2.6.
There is still not a SciPy release for 2.6.
Most dismaying, the SimpleParse guys need a little
help compiling SimpleParse for 2.6 and have not yet
gotten that help.  (Is anyone listening?)

So 2.5.4 is still perhaps the safest bet, even
though it is more awkward for writing code close
to Python 3 syntax.

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


Re: script files with python (instead of tcsh/bash)?

2009-03-23 Thread Alan G Isaac

On 3/21/2009 9:26 AM Esmail apparently wrote:

I also write out some gnuplot scripts
that later get executed to generate .jpg images.



See Gnuplot.py

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


Re: What's the difference between generating a value and returning a value?

2009-03-23 Thread Alan G Isaac

On 3/23/2009 6:12 PM grocery_stocker apparently wrote:

http://openbookproject.net/thinkCSpy/ch05.xhtml#index15

The built-in functions we have used, such as abs,
pow, and max, have produced results.  Calling each of
these functions generates a value, which we usually assign to a
variable or
use as part of an expression.


biggest = max(3, 7, 2, 5)
x = abs(3 - 11) + 10

But so far, none of the functions we have written has returned a
value.




I do not think this distinction is intended.
The key point is that the user-*written* functions
up to then do not include and explicit return statement.
(Actually, they still return None, which can in fact
be bound to a name.)

However it might (?) be that they are trying to
allow that some callable objects are not function types.
(E.g., creating an instance by calling the class,
which some of the builtins do.)  If so, this terminology
would not be a standard way of making that distinction.

Alan Isaac
(*not* a CS type)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python alternatives to Text::SimpleTable?

2009-03-09 Thread Alan G Isaac


http://code.google.com/p/econpy/source/browse/trunk/utilities/text.py
--
http://mail.python.org/mailman/listinfo/python-list


Re: Set Frozenset?

2009-03-09 Thread Alan G Isaac

Hans Larsen schrieb:
How could I take an elemment from a set or a frozenset 



On 3/8/2009 2:06 PM Diez B. Roggisch apparently wrote:

You iterate over them. If you only want one value, use
iter(the_set).next()



I recall a claim that

for result in myset: break

is the most efficient way to get one result.
Is this right? (It seems nearly the same.)

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


  1   2   >