Rss lib in python?

2005-05-31 Thread Owen
Hi all,

i want to know some rss library in python.For example, some for rss
readers, and some for generator.

Thanks for any information.

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


Re: Rss lib in python?

2005-06-01 Thread Owen
lihui <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>...
> Please use feedparser:
> 
>  http://feedparser.org/
> 
> 2005/6/1, Grant Edwards <[EMAIL PROTECTED]>:
> > On 2005-06-01, Owen <[EMAIL PROTECTED]> wrote:
> >=20
> > > i want to know some rss library in python.For example, some
> > > for rss readers, and some for generator.
> >=20
> > http://www.learnwebskills.com/search/main.html
> > http://www.learnwebskills.com/search/google.html
> >=20
> > Googling for "python rss library" generate a whole page
> > full of useful looking stuff:
> >=20
> >   http://www.google.com/search?q=3Dpython+rss+library
> >=20
> > Here's an RSS aggregator written in Python:
> >=20
> >   http://offog.org/code/rawdog.html
> >=20
> > --
> > Grant Edwards   grante Yow!  HOW could a GLAS=
> S
> >   at   be YELLING??
> >visi.com
> > --
> > http://mail.python.org/mailman/listinfo/python-list
> >=20
> 
> 
> --=20
> my gmail:lihuimail(at)gmail.com

Thank you for your interest in my question.

now i am finding some RSS readers in python(GUI in wxPython).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: compute the double square...... :(

2011-01-09 Thread Owen
On Jan 9, 6:14 pm, Gary Herron  wrote:
> On 01/08/2011 10:10 PM, aregee wrote:
>
> > Double Squares
> > A double-square number is an integer X which can be expressed as the
> > sum of two perfect squares. For example, 10 is a double-square because
> > 10 = 32 + 12. Your task in this problem is, given X, determine the
> > number of ways in which it can be written as the sum of two squares.
> > For example, 10 can only be written as 32 + 12 (we don't count 12 + 32
> > as being different). On the other hand, 25 can be written as 52 + 02
> > or as 42 + 32.
>
> Huh?  In what number system does  10 = 32 + 12?
> And how do either 32 or 12 qualify as perfect squares?
>
> Gary Herron
>
>
>
>
>
>
>
> > Input
> > You should first read an integer N, the number of test cases. The next
> > N lines will contain N values of X.
> > Constraints
> > 0 ≤ X ≤ 2147483647
> > 1 ≤ N ≤ 100
> > Output
> > For each value of X, you should output the number of ways to write X
> > as the sum of two square
>
> > Is the code mention below solution to this question  what is the
> > fault...
> > Error :
> > are...@aregee-laptop:~/Desktop$ python pie.py
> > enter a number::10
> > pie.py:3: Deprecation Warning: integer argument expected, got float
> >    for b in range(0,(x**0.5)/2):
>
> > #Double square
>
> > x = input("enter a number::")
> > for b in range(0,(x**0.5)/2):
> >        a = (x-(b**2))**0.5
> > try:
> >        a = int(a)
> > except:
> >        print("not an integer")
> >        exit(1)
>
> >        count = 0;
> >        count = count + 1;
> > if (x == a**2 + b**2):
>
> >        print "double square"



Well that he means 3(squared)+1(squared) [3 superscript 2 etc]

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


Re: Ideal way to separate GUI and logic?

2013-07-15 Thread Owen Marshall
On 2013-07-16, fronag...@gmail.com  wrote:
> On Tuesday, July 16, 2013 1:06:30 AM UTC+8, asim...@gmail.com wrote:
>> fron...@gmail.com wrote:
>>
>> > So as a general idea, I should at the very least separate the GUI
>> > from the program logic by defining the logic as a function,
>> > correct? And the next level of separation is to define the logic as
>> > a class in one or more separate files, and then import it to the
>> > file with the GUI, correct?
>>
>> >
>>
>> > My next question is, to what degree should I 'slice' my logic into
>> > functions? How small or how large should one function be, as a rule
>> > of thumb?
>>
>>
>>
>> The way I do this is to write unit tests against the class and the
>> functions (take a look at the unittest module). The functions methods
>> (take a look at the unittest module). Each function should contain
>> the smallest bit of testable logic.
>>
>>
>>
>> Another way to think about this is that each function should contain
>> the smallest piece of logic that you can describe as one action.
>>
>>
>>
>> -
>>
>> Asim Jalis
>
> Again, thanks for all the responses. I'm curious, though, what exactly
> is the rationale for making functions so small? (I've heard that the
> function calling of Python has relatively high overhead?)

Small functions are _always_ encouraged for every language. This is best
practice for everything, not just Python. Has nothing to do with
overhead.

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


Re: UTF-EBCDIC encoding?

2013-07-15 Thread Owen Marshall
On 2013-07-12, Joel Goldstick  wrote:
> --047d7bdc8be492d67804e154c580 Content-Type: text/plain; charset=UTF-8
>
> On Fri, Jul 12, 2013 at 2:11 PM, Wayne Werner 
> wrote:
>
>> Is anyone aware of a UTF-EBCDIC[1] decoder?
>>
>> While Python does have a few EBCDIC dialects in the codecs, it does
>> not have the (relatively new?) UTF-EBCDIC one.
>>
>> Additionally, if anyone is aware of a Python tool that can unpack a
>> mainframe PDS file, that would also be worthwhile.
>>
>>
>> Thanks, Wayne
>>
>> [1]:
>> https://en.wikipedia.org/wiki/**UTF-EBCDIC<https://en.wikipedia.org/wiki/UTF-EBCDIC>
>> --
>> http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list>
>>
>
>
> I can't help you.  I'm astonished.  Trying to imagine the work
> environment where this technology would be necessary
>

Ask any poor shmuck who has ever had to consume files created by the
government -- especially stuff from the Social Security Administration
-- and they'll tell horror stories about EBCDIC.

Typically I've seen ``iconv'' used for this task, so I'd love to see a
native solution...

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


Re: What does it take to implement a chat system in Python (Not asking for code just advice before I start my little project)

2013-07-18 Thread Owen Marshall
On 2013-07-18, Grant Edwards  wrote:
> On 2013-07-18, Serhiy Storchaka  wrote:
>> 18.07.13 20:04, Terry Reedy ??():
>>> On 7/18/2013 3:29 AM, Aseem Bansal wrote:
>>>> About reading comp.lang.python can you suggest how to read it and
>>>> reply?
>>>
>>> To read this list as a newsgroup use news.gmane.org. The difference
>>> between the mailing list interface and newsgroup interface is that the
>>> latter automatically segregates messages by group and only downloads the
>>> messages you want to read. Gmane is also a better way to search the
>>> archive.
>>
>> Also newsgroup interface allow you reply to messages that have already
>> been posted before your subscription.
>
> Indeed.  I read about 20 mailing lists by pointing a newsreader (I use
> slrn) at gmane.org.  I find it to take far less effort than actualling
> having all of those messages actually sent to me.  For _some_ of the
> gmane groups/lists you will actually have to subscribe to the mailing
> list in question if you want to be allowed to post messages -- but in
> your account settings for that mailing list server you can turn off
> delivery, so that it doesn't actually send you any of the postings.
>
> I really can't recommend gmane.org highly enough.
>
> [I don't actually read the python list using gmane.org, since I've
> read it from a Usenet news server via the group comp.lang.python since
> long before I discovered gmane.org.]
>

Huh - I (foolishly) didn't realize gmane actually had NNTP, I've always
used it to search mailing lists. If the list dumped to usenet (much like
c.l.python) I'd post through sunsite.dk, which is a very nice usenet
provider. But that still meant several annoying mailing list
subscriptions.

... man, I'm really glad I read your post :-)

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


Re: What does it take to implement a chat system in Python (Not asking for code just advice before I start my little project)

2013-07-18 Thread Owen Marshall
On 2013-07-18, Michael Torrie  wrote:
> On 07/18/2013 12:19 PM, Owen Marshall wrote:
>> Huh - I (foolishly) didn't realize gmane actually had NNTP, I've always
>> used it to search mailing lists. If the list dumped to usenet (much like
>> c.l.python) I'd post through sunsite.dk, which is a very nice usenet
>> provider. But that still meant several annoying mailing list
>> subscriptions.
>>
>> ... man, I'm really glad I read your post :-)
>
> I'm a bit confused.  This list *is* c.l.python (I happen to read via
> e-mail through the mailing list).  So you can reach it from sunsite.dk
> can you not?

Doesn't surprise me, I was confusing ;-)

What I was saying was that my workflow used to be this:

For maliing lists that dump to a newsgroup (c.l.python) I'd post to the
group via usenet (sunsite.dk)

For mailing lists that _do not_ have a direct newsgroup gateway (flask,
etc.) I'd have to subscribe and read them in my mail client.


So I used to think gmane was just a way of reading a bunch of mailing
lists. *But now* I know it is much more - it's an NNTP <==> mail gateway
that also has a web viewer.

Now I can point my slrn to news.gmane.net and see the flask mailing
list, ruby-talk, ... -- which I much prefer to using email.


Again, perfectly obvious stuff had I actually _read_ the gmane FAQ. But
who has time for that ;-)

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


Re: Generator problem: parent class not seen

2012-02-01 Thread Russell Owen
On Feb 1, 2012, at 2:34 PM, Chris Rebert wrote:

> On Wed, Feb 1, 2012 at 1:00 PM, Russell E. Owen  wrote:
>> I have an odd and very intermittent problem in Python script.
>> Occasionally it fails with this error:
>> 
>> Traceback (most recent call last):
>>  File
>> "/Applications/APO/TTUI.app/Contents/Resources/lib/python2.7/TUI/Base/Bas
>> eFocusScript.py", line 884, in run
>>  File
>> "/Applications/APO/TTUI.app/Contents/Resources/lib/python2.7/TUI/Base/Bas
>> eFocusScript.py", line 1690, in initAll
>> TypeError: unbound method initAll() must be called with BaseFocusScript
>> instance as first argument (got ScriptClass instance instead)
> 
>> The code looks like this:
>> 
>>def run(self, sr):
>>try:
>>self.initAll()
> 
>> I am puzzled why Python thinks the class type is wrong, given the output
>> of inspect.getclasstree. Any ideas on what might be wrong and how to
>> track it down (and why it would be so intermittent)?
> 
> What's the offending line of initAll() [#1690 in BaseFocusScript.py]
> look like? The lines preceding it would also be helpful for context.

Here you go. The offending line #169 is marked with ***

-- Russell

class ImagerFocusScript(BaseFocusScript):
   """..."""
def __init__(self,
sr,
instName,
imageViewerTLName = None,
defRadius = 5.0,
defBinFactor = 1,
maxFindAmpl = None,
doWindow = False,
windowOrigin = 1,
windowIsInclusive = True,
doZeroOverscan = False,
helpURL = None,
debug = False,
):
...
BaseFocusScript.__init__(self,
sr = sr,
gcamActor = gcamActor,
instName = instName,
imageViewerTLName = imageViewerTLName,
defRadius = defRadius,
defBinFactor = defBinFactor,
maxFindAmpl = maxFindAmpl,
doWindow = doWindow,
windowOrigin = windowOrigin,
windowIsInclusive = windowIsInclusive,
helpURL = helpURL,
debug = debug,
)
self.doZeroOverscan = bool(doZeroOverscan)


def initAll(self):
"""Override the default initAll to record initial bin factor, if 
relevant
"""
***   BaseFocusScript.initAll(self)
if self.exposeModel.instInfo.numBin > 0:
self.finalBinFactor = self.exposeModel.bin.getInd(0)[0]


Also, here is BaseFocusScript:

class BaseFocusScript(object):
"""Basic focus script object.

This is a virtual base class. The inheritor must:
- Provide widgets
- Provide a "run" method
"""
cmd_Find = "find"
cmd_Measure = "measure"
cmd_Sweep = "sweep"

# constants
#DefRadius = 5.0 # centroid radius, in arcsec
#NewStarRad = 2.0 # amount of star position change to be considered a new 
star
DefFocusNPos = 5  # number of focus positions
DefFocusRange = 200 # default focus range around current focus
FocusWaitMS = 1000 # time to wait after every focus adjustment (ms)
BacklashComp = 0 # amount of backlash compensation, in microns (0 for none)
WinSizeMult = 2.5 # window radius = centroid radius * WinSizeMult
FocGraphMargin = 5 # margin on graph for x axis limits, in um
MaxFocSigmaFac = 0.5 # maximum allowed sigma of best fit focus as a 
multiple of focus range
MinFocusIncr = 10 # minimum focus increment, in um
def __init__(self,
sr,
gcamActor,
instName,
tccInstPrefix = None,
imageViewerTLName = None,
defRadius = 5.0,
defBinFactor = 1,
finalBinFactor = None,
canSetStarPos = True,
maxFindAmpl = None,
doWindow = True,
windowOrigin = 0,
windowIsInclusive = True,
helpURL = None,
debug = False,
):
""""""
self.sr = sr
self.sr.debug = bool(debug)
self.gcamActor = gcamActor


def initAll(self):
"""Initialize variables, table and graph.
"""
# initialize shared variables
self.doTakeFinalImage = False
self.focDir = None
self.currBoreXYDeg = None
self.begBoreXYDeg = None
self.instScale = None
self.arcsecPerPixel = None
self.instCtr = None
self.instLim = None
self.cmdMode = None
self.focPosToRestore = None
self.expTime = None
self.absStarPos = None
self.relStarPos = None
self.binFactor = None
self.window = None # LL pixel is 0, UR pixel is included

self.enableCmdBtns(False)

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


Re: Generator problem: parent class not seen

2012-02-01 Thread Russell Owen
On Feb 1, 2012, at 3:35 PM, Arnaud Delobelle wrote:
> On Feb 1, 2012 9:01 PM, "Russell E. Owen"  wrote:
> >
> > I have an odd and very intermittent problem in Python script.
> > Occasionally it fails with this error:
> >
> > Traceback (most recent call last):
> >  File
> > "/Applications/APO/TTUI.app/Contents/Resources/lib/python2.7/TUI/Base/Bas
> > eFocusScript.py", line 884, in run
> >  File
> > "/Applications/APO/TTUI.app/Contents/Resources/lib/python2.7/TUI/Base/Bas
> > eFocusScript.py", line 1690, in initAll
> > TypeError: unbound method initAll() must be called with BaseFocusScript
> > instance as first argument (got ScriptClass instance instead)
> > self=; class hierarchy=[( > 'TUI.Base.BaseFocusScript.ImagerFocusScript'>, ( > 'TUI.Base.BaseFocusScript.BaseFocusScript'>,)), [(,
> > (,))]]
> >
> 
> Looks like you have loaded the same module twice.  So you have two versions 
> of your class hierarchies. You can check by printing the ids of your classes. 
> You will get classes with the same name but different ids.
> 
> Arnaud
> 

Yes! I was reloading BaseFocusScript. Oops.

In detail: script files are dynamically loaded when first requested and can be 
reloaded for debugging. I think that's safe because script files are 
self-contained (e.g. the classes in them are never subclassed or anything like 
that). But I went too far: I had my focus scripts reload BaseFocusScript, which 
is shared code, so that I could tweak BaseFocusScript while debugging focus 
scripts.

Thank you very much!

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


Re: stackoverflow question

2012-03-10 Thread Owen Jacobson

On 2012-03-09 22:10:18 +, Ethan Furman said:


Hey all!

I posted a question/answer on SO earlier, but there seems to be some 
confusion around either the question or the answer (judging from the 
comments).


http://stackoverflow.com/q/9638921/208880

If anyone here is willing to take a look at it and let me know if I did 
not write it well, I would appreciate the feedback.



Here's the question text:

I'm writing a metaclass to do some cool stuff, and part of its 
processing is to check that certain attributes exist when the class is 
created.  Some of these are mutable, and would normally be set in 
`__init__`, but since `__init__` isn't run until the instance is 
created the metaclass won't know that the attribute *will* be created, 
and raises an error.  I could do something like:


 class Test(meta=Meta):
 mutable = None
 def __init__(self):
 self.mutable = list()

But that isn't very elegant, and also violates DRY.

What I need is some way to have:

 class Test(metaclass=Meta):
 mutable = list()

 t1 = Test()
 t2 = Test()
 t1.mutable.append('one')
 t2.mutable.append('two')
 t1.mutable  # prints ['one']
 t2.mutable  # prints ['two']

Any ideas on how this can be accomplished?

Also, the metaclass doing the checking doesn't care what type of object 
the attribute is, only that it is there.

---


Why check what you can ensure? The __init__ function your metaclass 
passes to type() doesn't have to be the __init__ method your metaclass 
received. Consider the following:



import functools as f

def make_init(real_init):
"""Define an __init__ method that ensures ``self.mutable`` is set. If the
passed ``real_init`` function later replaces ``self.mutable``, that value
is preserved; otherwise, ``self.mutable`` is set to a new, empty list.

Arguments to the generated ``__init__`` method are passed to the original
``real_init`` unchanged.
"""
def __init__(self, *args, **kwargs):
self.mutable = list()
if real_init is not None:
return real_init(self, *args, **kwargs)
if real_init is not None:
f.update_wrapper(__init__, real_init)
return __init__

class Meta(type):
def __new__(meta, name, parents, attributes):
attributes['__init__'] = make_init(attributes.get('__init__', None))
return type.__new__(Meta, name, parents, attributes)

class C(object):
__metaclass__ = Meta

a, b = C(), C()

a.mutable.append(3)
b.mutable.append(5)

a.mutable

[3]

b.mutable

[5]

All instances of classes whose metaclass is Meta will, guaranteed, have 
an instance field named 'mutable'. Its value is a list created at 
instance creation time, unless the instance's __init__ provides a 
different value.


What've I missed?

-o

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


Re: stackoverflow question

2012-03-10 Thread Owen Jacobson

On 2012-03-10 22:21:55 +, Ethan Furman said:


Owen Jacobson wrote:

On 2012-03-09 22:10:18 +, Ethan Furman said:


Hey all!

I posted a question/answer on SO earlier, but there seems to be some 
confusion around either the question or the answer (judging from the 
comments).


http://stackoverflow.com/q/9638921/208880

If anyone here is willing to take a look at it and let me know if I did 
not write it well, I would appreciate the feedback.



Here's the question text:

I'm writing a metaclass to do some cool stuff, and part of its 
processing is to check that certain attributes exist when the class is 
created.  Some of these are mutable, and would normally be set in 
`__init__`, but since `__init__` isn't run until the instance is 
created the metaclass won't know that the attribute *will* be created, 
and raises an error.  I could do something like:


class Test(meta=Meta):
mutable = None
def __init__(self):
self.mutable = list()

But that isn't very elegant, and also violates DRY.

What I need is some way to have:

class Test(metaclass=Meta):
mutable = list()

t1 = Test()
t2 = Test()
t1.mutable.append('one')
t2.mutable.append('two')
t1.mutable  # prints ['one']
t2.mutable  # prints ['two']

Any ideas on how this can be accomplished?

Also, the metaclass doing the checking doesn't care what type of object 
the attribute is, only that it is there.

---


Why check what you can ensure? The __init__ function your metaclass 
passes to type() doesn't have to be the __init__ method your metaclass 
received.


[… __init__-generation technique elided …]

All instances of classes whose metaclass is Meta will, guaranteed, have 
an instance field named 'mutable'. Its value is a list created at 
instance creation time, unless the instance's __init__ provides a 
different value.


The idea is good.  The devil is in the details, as usual.  How is the 
metaclass going to know:


   1) which attributes to replace
   2) what to replace them with?


I can think of at least three techniques; others are certainly possible:

1. As with the example code, the list is hard-coded in the metaclass's 
source code.
2. The list (or, rather, a dictionary) is drawn from a class attribute 
of the class being created:


class Foo(object):
mandatory_fields = {'mutable': list, 'more_stuff': str}
__metaclass__ = IntrospectingMetaclass

3. A metaclass-returning factory produces new metaclasses on demand, 
each of which has a dict of mandatory fields baked into it. (This is a 
hybrid of the two approaches, and can easily have some messy side 
effects on your app's type ecology if used carelessly.)


Of course, you can also treat this the other way around: instead of 
enforcing that instances have specific fields, you could have users of 
those instances be aware that the field might not exist, and wrap 
access to the field in a try/except NameError block or use getattr to 
read the attribute.


What's appropriate really depends on how you plan to use this 
metaclass, and on the nature of the higher-level problem to which "I 
know, I'll use metaclasses" is your answer. How about telling us a 
slightly broader story about your problem?


-o

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


Re: getaddrinfo NXDOMAIN exploit - please test on CentOS 6 64-bit

2012-03-31 Thread Owen Jacobson

On 2012-03-31 22:58:45 +, John Nagle said:


Some versions of CentOS 6 seem to have a potential
getaddrinfo exploit.  See

To test, try this from a command line:

ping example

If it fails, good.  If it returns pings from "example.com", bad.
The getaddrinfo code is adding ".com" to the domain.


There is insufficient information in your diagnosis to make that 
conclusion. For example: what network configuration services (DHCP 
clients and whatnot, along with various desktop-mode configuration 
tools and services) are running? What kernel and libc versions are you 
running? What are the contents of /etc/nsswitch.conf? Of 
/etc/resolv.conf (particularly, the 'search' entries)? What do 
/etc/hosts, LDAP, NIS+, or other hostname services say about the names 
you're resolving? Does a freestanding C program that directly calls 
getaddrinfo and that runs in a known-good loader environment exhibit 
the same surprises? Name resolution is not so simple that you can 
conclude "getaddrinfo is misbehaving" from the behaviour of ping, or of 
your Python sample, alone.


In any case, this seems more appropriate for a Linux or a CentOS 
newsgroup/mailing list than a Python one. Please do not reply to this 
post in comp.lang.python.


-o

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


Re: importing class objects from a pickled file

2011-05-03 Thread Owen Jacobson

On 2011-05-03 20:18:33 -0400, Catherine Moroney said:


Hello,

I have an object of class X that I am writing to a pickled file.  The 
pickling part goes fine, but I am having some problems reading the 
object back out, as I get complaints about "unable to import module X".


The only way I have found around it is to run the read-file code out of 
the same directory that contains the X.py file, but this is obviously 
not a portable way of doing things.


Even when I put statements into the code such as "from Y.X import X"
where Y is the name of the python package that contains the X,py file,
the import statement works, but I am still unable to read the object 
from the pickled file, running into the same "unable to import module X"

error.

Am I explaining myself properly?  Why doesn't the code that loads the
object from the pickled file work unless I am sitting in the same directory?


That's not the actual requirement.

The pickled representation of an instance of a user-defined class contains:

* the name of the class
* the name of the class's module
* the object's attributes, pickled recursively

You can have a look at the representation using protocol zero, which is 
printable and not terribly hard to read. Here's an example, lightly 
annotated:


   >>> import pickle
   >>> class Example(object):
   ...   def __init__(self, x):
   ... self.x = x
   ...
   >>> one = Example(1)
   >>> print pickle.dumps(one, 0)
   ccopy_reg
   _reconstructor
   p0
module name (c__main__
class name  Example
   p1
   c__builtin__
   object
   p2
   Ntp3
   Rp4
   (dp5
field name  S'x'
   p6
field value I1
   sb.
   >>>

Obviously, since the pickled representation only contains the *name and 
location* of the class and not the class itself, you need to have the 
definition of the class handy when unpickling an object. This means 
that the module that defines the class must be on the module search 
path - either because it's in the current directory (or a package in 
the current directory, or..), or because it's in PYTHONPATH, or because 
it's somewhere else on sys.path.



The code that writes the pickled file has the statement
"from Y.X import X" statement" at the top, as does the reading code, but
even though that import statement succeeds, the read still fails with 
the import error.


The unpickle code uses something morally equivalent to __import__ to 
convert the module name in the pickled data stream into a module 
object. The symbols defined in the module you called pickle.load from 
don't matter at all, just like any other function defined in a separate 
module.


Pickle isn't meant for transmitting data between two unrelated 
programs. It's designed to be a low-development-effort way to preserve 
and restore objects for a single program or a group of related programs 
that share libraries. If you want to share data between unrelated 
programs, use something a little more interoperable - json, xml, or 
some other program-agnostic representation.


-o

(And if you were thinking of using pickle over the internet, forget it: 
the pickle encoding is a small stack-based programming language in its 
own right, and can be used to invoke semi-arbitrary module-scoped 
funtions.)


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


Re: What's the best way to minimize the need of run time checks?

2016-08-11 Thread Russell Owen

On 8/10/16 3:44 PM, Juan Pablo Romero Méndez wrote:

As to why I asked that, there are several reasons: I have a very concrete
need right now to find pragmatic ways to increase code quality, reduce
number of defects, etc. in a Python code base. But also I want to
understand better the mind set and culture of Python's community.


I am late to this thread, so my apologies for duplicated answers, but I 
have two concrete suggestions:
- Unit tests. These are a hassle to write, but pay huge dividends in 
robustness of your existing code and making it safer to modify the code 
later. There are also tools to measure test coverage which are worth 
considering. I don't think it is possible to write robust code in any 
language (even compiled languages) without a good test suite.
- Always run a linter such as flake8. Most source code editors can be 
configured to do this automatically. This will not catch everything that 
a compiler would catch in a compiled language, but it will catch many 
common errors.


-- Russell

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


Re: Anaconda with Python 3.7

2018-09-28 Thread Russell Owen
On Sep 3, 2018, gvim wrote
(in article <5b8d0122.1030...@gmail.com>):

> Anyone have any idea when Anaconda might ship a version compatible with
> Python 3.7. I sent them 2 emails but no reply.

I heard a rumor today that it will be a few more months. They are short on 
resources and are also dealing with issues with dependency management.

In any case miniconda is available for 3.7 so it is worth checking to see if 
it has the packages that you need. (And if it’s just missing a few you can 
see if pip will install those).

-- Russell


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


asyncio await different coroutines on the same socket?

2018-10-03 Thread Russell Owen

Using asyncio I am looking for a simple way to await multiple events where 
notification comes over the same socket (or other serial stream) in arbitrary 
order. For example, suppose I am communicating with a remote device that can 
run different commands simultaneously and I don't know which command will 
finish first. I want to do this:

coro1 = start(command1)
coro2 = start(command2)
asyncio.gather(coro1, coro2)

where either command may finish first. I’m hoping for a simple and 
idiomatic way to read the socket and tell each coroutine it is done. So far 
everything I have come up with is ugly, using multiple layers of "async 
def”, keeping a record of Tasks that are waiting and calling "set_result" 
on those Tasks when finished. Also Task isn’t even documented to have the 
set_result method (though "future" is)

Is there a simple, idiomatic way to do this?

-- Russell


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


How to await multiple replies in arbitrary order (one coroutine per reply)?

2018-10-05 Thread Russell Owen


I am using asyncio and am fairly new to it. I have a stream to which I write 
commands and from which I read replies. (In this case the stream is custom 
wrapper around DDS written in C++ and pybind11). Multiple commands can run at 
the same time and I cannot predict which will finish first. I need aa 
different coroutine (or asyncio.Task or other awaitable object) for each 
command that is running.

Is there a simple way to handle this in asyncio? So far the best I have come 
up is the following (greatly simplified), which works but has some 
misfeatures:

import asyncio
from iolib import read_reply, write_command, TIMED_OUT

class RemoteCommand:
def __init__(self):
self._tasks = dict()

def start(self, cmd, timeout):
"""Start a command"""
cmd_id = write_command(cmd)
task = asyncio.ensure_future(self._wait_for_command(cmd_id=cmd_id, 
timeout=timeout))
self._tasks[cmd_id] = task
if len(self._tasks) == 1:
asyncio.ensure_future(self._handle_replies())
return task

async def _wait_for_command(self, cmd_id, timeout):
"""Wait for a command to finish"""
await asyncio.sleep(timeout)
if cmd_id in self._tasks:
del self._tasks[cmd_id]
return TIMED_OUT # our standard end code for timeouts

async def _handle_replies(self):
while True:
cmd_id, end_code = read_reply()
if cmd_id in self._tasks:
task = self._tasks.pop(cmd_id)
task.set_result(end_code)
if not self._tasks:
return
await asyncio.sleep(0.1)

Misfeatures include:
- asyncio.Task is not documented to have a "set_result" method. The 
documentation says that Task is "A Future-like object that runs a Python 
coroutine" and Future does have such a method.
- When "_handle_replies" calls "task.set_result(data)" this does not seem to 
cancel the "await asyncio.sleep(timeout)" in the task, resulting in scary 
messages to stdout. I have tried saving *that* as another task and canceling 
it, but it seems clumsy and I still see scary messages.

I think what I'm looking for is a task-like thing I can create that I can end 
when *I* say it's time to end, and if I'm not quick enough then it will time 
out gracefully. But maybe there's a simpler way to do this. It doesn't seem 
like it should be difficult, but I'm stumped. Any advice would be 
appreciated.

-- Russell


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


Re: asyncio await different coroutines on the same socket?

2018-10-05 Thread Russell Owen
On Oct 3, 2018, Ian Kelly wrote
(in 
article):

> On Wed, Oct 3, 2018 at 7:47 AM Russell Owen  wrote:
> > Using asyncio I am looking for a simple way to await multiple events where
> > notification comes over the same socket (or other serial stream) in
> > arbitrary
> > order. For example, suppose I am communicating with a remote device that can
> > run different commands simultaneously and I don't know which command will
> > finish first. I want to do this:
> >
> > coro1 = start(command1)
> > coro2 = start(command2)
> > asyncio.gather(coro1, coro2)
> >
> > where either command may finish first. I’m hoping for a simple and
> > idiomatic way to read the socket and tell each coroutine it is done. So far
> > everything I have come up with is ugly, using multiple layers of "async
> > def”, keeping a record of Tasks that are waiting and calling "set_result"
> > on those Tasks when finished. Also Task isn’t even documented to have the
> > set_result method (though "future" is)
>
> Because Tasks are used to wrap coroutines, and the result of the Task
> should be determined by the coroutine, not externally.
>
> Instead of tracking tasks (that's what the event loop is for) I would
> suggest tracking futures instead. Have start(command1) return a future
> (or create a future that it will await on itself) that is not a task.
> Whenever a response from the socket is parsed, that code would then
> look up the corresponding future and call set_result on it. It might
> look something like this:
>
> class Client:
> async def open(self, host, port):
> self.reader, self.writer = await asyncio.open_connection(host, port)
> asyncio.create_task(self.read_loop())
>
> async def read_loop(self):
> while not self.reader.at_eof():
> response = self.reader.read()
> id = get_response_id(response)
> self._futures.pop(id).set_result(response)
>
> def start(self, command):
> future = asyncio.Future()
> self._futures[get_command_id(command)] = future
> self.writer.write(command)
> return future
>
> In this case start() is not a coroutine but its result is a future and
> can be awaited.

That is exactly what I was looking for. Thank you very much!

-- Russell

(My apologies for double posting -- I asked this question again today because 
I did not think my original question -- this one -- had gone through).


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


Is it possible to connect an awaitable to a Future, basically turning it into a Task?

2018-10-27 Thread Russell Owen

I’m using asyncio and I’d like to add an item to an object that others 
can wait on immediately and which eventually I will want to use to track a 
coroutine. In other words I want something like:

class Info:
def __init__(self):
self.done_task = asyncio.Future()

info = Info()
# do other stuff, but eventually
coro = ...
asyncio.connect_future(coro, info.done_task)

I can certainly live without this, it simply requires adding an additional 
task made with asyncio.ensure_future and using that to set the result of 
done_task.

But it would be a lot more elegant to just have the one future (especially if 
I have to cancel the wait, as I have to keep the extra task around so I can 
cancel it). So...just wondering if I missed something.

Regards,

Russell


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


Re: log file.

2016-06-14 Thread Paul Owen
I am very inexperienced at programming.!

is there a lot of code needed to use those modules.

regards paul.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: log file.

2016-06-14 Thread Paul Owen
logging please.

my pump programme works but I want to log the time etc. when the pump runs and 
stops.

I am trying to improve the programme 

I am a novice!
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: log file.

2016-06-14 Thread Paul Owen
thanks I will look at them.
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: log file.

2016-06-14 Thread Paul Owen

Gmail

Google+

Calendar

Web

more

Inbox

pump programme

Paul Owen

to me
1 hour ago

Details

from gpiozero import LED,Button

from signal import pause

print ("Pump Programme Running")

led = LED(17)

low = Button (2)

high = Button (3)

high.when_pressed = led.on 

low.when_released = led.off

#as you can see I need a simple way to log when led(pump) runs

hope seeing this helps.

regards Paul.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: log file.

2016-06-14 Thread Paul Owen
Thank you Steven.
that is just what I need.

regards Paul.
-- 
https://mail.python.org/mailman/listinfo/python-list


Gzip module does not support Unix compressed .Z files [SEC=UNOFFICIAL]

2016-07-03 Thread Owen Brandon
Hello,

I have a query regarding the support of decompression for Unix compressed .Z 
files in Python's gzip module. The gzip system utility supports this using the 
'-d' switch, but the python module does not.

Obviously this isn't an actual bug, as the Python module is an implementation 
of the zlib library (which does not actually specify .Z file decompression). 
But I'd rather not have to shell out to decompress files if possible - as there 
currently don't seem to be any core python modules which can decompress .Z 
files.

What are the chances of this functionality being included in a core module at 
some point?

Sorry if this is not the correct forum for questions like this - any help would 
be appreciated.

Kind Regards

Brandon Owen
GNSS Network Operator  |  Geodesy and Seismic Monitoring Group
Community Safety and Earth Monitoring Division  |  GEOSCIENCE AUSTRALIA

Phone:  +61 2 6249 9192Fax:  +61 2 6249 
Email:  brandon.o...@ga.gov.au<mailto:brandon.o...@ga.gov.au>Web:  
www.ga.gov.au<http://www.ga.gov.au/>
Cnr Jerrabomberra Avenue and Hindmarsh Drive Symonston ACT
GPO Box 378 Canberra ACT 2601 Australia
Applying geoscience to Australia's most important challenges


Geoscience Australia Disclaimer: This e-mail (and files transmitted with it) is 
intended only for the person or entity to which it is addressed. If you are not 
the intended recipient, then you have received this e-mail by mistake and any 
use, dissemination, forwarding, printing or copying of this e-mail and its file 
attachments is prohibited. The security of emails transmitted cannot be 
guaranteed; by forwarding or replying to this email, you acknowledge and accept 
these risks.
-

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


RE: Gzip module does not support Unix compressed .Z files [SEC=UNOFFICIAL]

2016-07-04 Thread Owen Brandon
That's actually the module that I wrote for this purpose (adapted Mark Adler's 
C code) - I haven't optimised it very much.

Brandon Owen 
GNSS Network Operator  |  Geodesy and Seismic Monitoring Group
Community Safety and Earth Monitoring Division  |  GEOSCIENCE AUSTRALIA

Phone:  +61 2 6249 9192    Fax:  +61 2 6249 
Email:  brandon.o...@ga.gov.au    Web:  www.ga.gov.au
Cnr Jerrabomberra Avenue and Hindmarsh Drive Symonston ACT
GPO Box 378 Canberra ACT 2601 Australia
Applying geoscience to Australia's most important challenges


-Original Message-
From: Python-list 
[mailto:python-list-bounces+brandon.owen=ga.gov...@python.org] On Behalf Of 
Robert Kern
Sent: Tuesday, 5 July 2016 12:18 AM
To: python-list@python.org
Subject: Re: Gzip module does not support Unix compressed .Z files 
[SEC=UNOFFICIAL]

On 2016-07-04 09:00, dieter wrote:
> "Owen Brandon"  writes:
>
>> I have a query regarding the support of decompression for Unix compressed .Z 
>> files in Python's gzip module. The gzip system utility supports this using 
>> the '-d' switch, but the python module does not.
>
> When I am right, then the "zipfile" module handles ".Z" compressed files.

No, that handles PKZIP .zip files. There are third-party modules that handle 
the .Z format, but shelling out to external programs may still be preferable:

   https://github.com/umeat/unlzw

--
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

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

Geoscience Australia Disclaimer: This e-mail (and files transmitted with it) is 
intended only for the person or entity to which it is addressed. If you are not 
the intended recipient, then you have received this e-mail by mistake and any 
use, dissemination, forwarding, printing or copying of this e-mail and its file 
attachments is prohibited. The security of emails transmitted cannot be 
guaranteed; by forwarding or replying to this email, you acknowledge and accept 
these risks.
-

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


HTTP Header Capitalization in urllib.request.AbstractHTTPHandler (Python 3.3)

2013-11-18 Thread Logan Owen
Hello everyone,

I was hoping for some advice in dealing with an edge case related to
Python's HTTP Header handling.  Python is correctly assuming that the
HTTP header field name (eg Content-Type) is case insensitive, but I have
a webservice I am interacting with that does not follow the standards. 
I am passing in the header "SOAPAction" and do_request of
AbstractHTTPHandler is applying title() to the string, leading to the
field name being "Soapaction", which the server does not recognize.

So my question is, what does everyone suggest is the best solution for
being able to pass a case sensitive header to the server?

Thanks!
Logan
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to install PIL or PILLOW on OS X Yosemite?

2015-02-19 Thread Russell Owen

On 2/15/15 8:17 PM, Ned Deily wrote:

In article ,
  KP  wrote:

just upgraded my Mac Mini to Yosemite and have never dabbled in Python on
this OS.

I see it has Python 2.7.6 installed.

When I do something like

from PIL import ImageFont, ImageDraw

it tells me that it cannot find PIL

How do I install this on Yosemite?


Suggestions: stick with Pillow which is the current, maintained fork of
the venerable PIL. Decide whether you want to use Python 3 or Python 2.
PIL/Pillow installation on OS X is more involved than on some other
platforms because it depends on a number of third-party C libraries that
are not shipped by Apple in OS X so you need to find another source for
them.  Rather than trying to build and install everything yourself or
downloading a Pillow or PIL installer, I suggest picking one of the
several fine distributors of open source packages for OS X and
installing everything you need from them (including an up-to-date Python
2 or 3) and for your future needs beyond Pillow; options include
Homebrew, MacPorts, Anaconda, Fink, and others.  Once you've installed
the base framework for the package manager you choose, installing
something like Pillow and all of its dependencies is often just a
one-line command.  It may take a little while to get used to the quirks
of the package manager you choose but, if you are going to use OS X for
development with Python or many other languages, that time spent will be
repaid many times over.


I agree that Pillow is preferable to PIL and that you may want to 
consider a 3rd party system.


If you are primarily interested in Python (and not unix-based C/C++ 
libraries and utilities then I suggest you try anaconda python.


Homebrew, MacPorts and Fink are mostly aimed at people who want to add 
missing unix libraries and tools.


If you want to stick with python.org python then a binary PIL installer 
is available here:


(I am not aware of any Pillow binaries).

-- Russell

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


Sexism in the Ruby community: how does the Python community manage it?

2013-10-16 Thread Owen Jacobson
Last week, Elad Maidar wrote a fairly short but readable opinion 
piece[0] illustrating some long-standing social problems in the Ruby 
community, ending with a very specific call to action around naming 
conventions for Ruby projects and gems. To save you the trouble of 
scrolling to the bottom of this post and clicking, here's the relevant 
bit:


What is missing you ask? I think that there is no consideration in 
women when it comes to gem naming convention, here are a few gems that 
i found in a 5 mintues search on Rubygems.org to demonstrate why women 
and other groups probably feel uncomfortable when trying to get into 
the Rails community:


* retarded
* bitch
* hoe
* womanizer
* recursive_pimp_slap
* miniskirt
* childlabor
* bj
* sex
* fuck
* rape-me
* therapist - yeah, It passes as a double meaning - but still.
* shag
* db_nazi
* and ass

While some of you may think this is a righteous callout - I think that 
as a community we need to strive to be as appealing as possible, there 
is nothing cool about naming your gem “fuck” or “retarded” and we as a 
community - need to stop this from happening as much as we can.


Read the rest, it's pretty good.

(A number of the named gems have been pulled by their authors.)

It occurred to me to go digging around pypi - arguably[1] the Python 
community's equivalent to gems - to see if I could find similar 
institutionalized sexism.


The good news: the specific examples Elad called out are STRIKINGLY 
absent from pypi. By and large the published python packages are 
inobjectionable. Well done, "us", in as much as there is an "us" to 
congratulate.


There are a few examples of the same sort of bad decision-making that 
are, I think, worth discussing:


* SexMachine (https://pypi.python.org/pypi/SexMachine/0.1.1 - an 
attempt to detect the gender of names, which… well, ask the nearest boy 
named Sue - or girl named Leslie)

* sexytime (https://pypi.python.org/pypi/sexytime/0.1.0)
* pep8nazi (https://pypi.python.org/pypi/pep8nazi/0.1 - do we shove 
non-PEP8-compliant authors into "showers" now?)


So, two questions:

1. What social biases and problems *do* we unwittingly encourage by way 
of community-tolerated behaviour? Where, if not through the conventions 
for naming, do we encourage sexism, racism, and other mindlessly 
exclusionary behaviour?


2. What kind of social pressure can we bring to bear to _keep_ Python's 
package naming conventions as socially neutral as they are, if and when 
some high-profile dirtbag decides this language is the best language? 
How can we apply the same pressures to other parts of the Python 
community?


3. How can we reach out to the Ruby community and help *them* get past 
the current crop of gender issues, and help them as a group to do 
better next time?


I'm very much on the side of education, tolerance, and social 
consequences, not administrative fiat or organized retaliation. I think 
Elad's call for the Rubygems folks to unilaterally drop libraries is 
misguided, but well-intentioned, and I don't think the same sort of 
call towards Pypi to drop "unacceptable" library names is a good idea 
either. However, I think it's hugely important and hugely beneficial 
that we welcome as many folks into the Python community as possible, 
and do our best to foster an environment where people can succeed 
regardless of who or what they are, and recent evidence suggests that 
that requires ongoing conversation and engagement, not just passive 
acceptance.


So, how should we be more awesome?

-o

(For some additional context, and why I think passive acceptance isn't 
good enough, see 
http://iangent.blogspot.ca/2013/10/the-petrie-multiplier-why-attack-on.html 
.)


[0] 
http://devandpencil.herokuapp.com/blog/2013/10/09/being-an-asshole-does-not-make-you-awesome/ 

[1] as in let's not have a packaging or language mudfight over it, 
please? Pretty please?


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


Re: Picking apart a text line

2015-03-02 Thread Russell Owen

On 2/26/15 7:53 PM, memilanuk wrote:

So... okay.  I've got a bunch of PDFs of tournament reports that I want
to sift thru for information.  Ended up using 'pdftotext -layout
file.pdf file.txt' to extract the text from the PDF.  Still have a few
little glitches to iron out there, but I'm getting decent enough results
for the moment to move on.


...

So back to the lines of text I have stored as strings in a list.  I
think I want to convert that to a list of lists, i.e. split each line
up, store that info in another list and ditch the whitespace.  Or would
I be better off using dicts?  Originally I was thinking of how to
process each line and split it them up based on what information was
where - some sort of nested for/if mess.  Now I'm starting to think that
the lines of text are pretty uniform in structure i.e. the same field is
always in the same location, and that list slicing might be the way to
go, if a bit tedious to set up initially...?

Any thoughts or suggestions from people who've gone down this particular
path would be greatly appreciated.  I think I have a general
idea/direction, but I'm open to other ideas if the path I'm on is just
blatantly wrong.


It sounds to me as if the best way to handle all this is keep the 
information it in a database, preferably one available from the network 
and centrally managed, so whoever enters the information in the first 
place enters it there. But I admit that setting such a thing up requires 
some overhead.


Simpler alternatives include using SQLite, a simple file-based database 
system, or numpy structured arrays (arrays with named fields). Python 
includes a standard library module for sqlite and numpy is easy to install.


-- Russell

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


Re: Best way to calculate fraction part of x?

2015-03-26 Thread Russell Owen

On 3/24/15 6:39 PM, Jason Swails wrote:



On Mon, Mar 23, 2015 at 8:38 PM, Emile van Sebille mailto:em...@fenx.com>> wrote:

On 3/23/2015 5:52 AM, Steven D'Aprano wrote:

Are there any other, possibly better, ways to calculate the
fractional part
of a number?


float (("%6.3f" % x)[-4:])


​In general you lose a lot of precision this way...​


I suggest modf in the math library:

math.modf(x)
Return the fractional and integer parts of x. Both results carry the 
sign of x and are floats.




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


Re: Quick question, if you please

2015-03-31 Thread Russell Owen

On 3/31/15 10:09 AM, John Kelly wrote:

Pythonites,

I received Python with another install and my update software keeps
signaling I need to install a newer version, and once I do, the older
version is still there, so I keep getting told I need to update. Should
I be able to uninstall the old version each time?

Thanks for your kind attention,
John Kelly


I would need more information to help. What operating system are you on? 
How and where are you installing Python (and what do you mean by 
"received Python with another install"?).


-- Russell

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


Re: tkinter resize question

2015-07-17 Thread Russell Owen

On 7/17/15 12:17 PM, nickgeova...@gmail.com wrote:

On Friday, July 17, 2015 at 1:53:19 PM UTC-5, nickge...@gmail.com wrote:

Resizing a tkinter window which contains a frame which contains a button 
widget, will not change the current size of the window, frame or button as 
recorded in their height and width attributes (at least not if they are 
resizable). What is the correct way to detect their current size?


Ok, partially answering my own question:
The geometry of the window will change (win.geometry()), but the changes do not appear to 
"propagate" to the retrieved width/height of the child widgets, frames, etc. Or 
am I incorrect with this?


I'm not seeing it. If I try the following script I see that resizing the 
widget does update frame.winfo_width() and winfo_height. (I also see 
that the requested width and height are ignored; you can omit those).


-- Russell


#!/usr/bin/env python
import Tkinter
root = Tkinter.Tk()

frame = Tkinter.Frame(root, width=100, height=50)
frame.pack(expand=True, fill="both")
def doReport(*args):
print "frame actualwidth=%s, height=%s" % (frame.winfo_width(), 
frame.winfo_height())
print "frame requested width=%s, height=%s" % 
(frame.winfo_reqwidth(), frame.winfo_reqheight())

button = Tkinter.Button(frame, text="Report", command=doReport)
button.pack()

root.mainloop()


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


Re: Idiom for shelling out to $EDITOR/$PAGER?

2011-12-23 Thread Owen Jacobson

On 2011-12-23 06:02:18 +, Cameron Simpson said:


MacOSX has "open", though it won't be running a blocking editor, alas.


But it can be. From the man page:

-t  Causes the file to be opened with the default text editor, as deter-
mined via LaunchServices

and

-W  Causes open to wait until the applications it opens (or that were
already open) have exited.  Use with the -n flag to allow open to
function as an appropriate app for the $EDITOR environment variable.

and finally

-n  Open a new instance of the application(s) even if one is already run-
ning.

can be combined to make 'open' (the shell interface to OS X's 
LaunchServices system) into a workable $EDITOR.


-o


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


Re: Perl XML::Simple and Data::Dumper - exists in Python?

2006-06-14 Thread Wallace Owen
Miguel Manso wrote:
> Hi there,
> 
> I'm a Perl programmer trying to get into Python. I've been reading some 
> documentation and I've choosed Python has being the "next step" to give.
> 
> Can you point me out to Python solutions for:
> 
> 1) Perl's Data::Dumper
> 
> It dumps any perl variable to the stdout in a "readable" way.

All Python objects support reflection and can be serialized to a data 
stream.  There's about four ways to do it (Kinda perl-like in that 
regard, but typically for a particular application there's one obvious 
right choice).  You control the way your objects appear as strings, by 
defining a __str__ member function that'll be invoked if the user does:

% print str(yourObject)

You can print any builtin type with just:

 >>> lst = ["one", "two", (3, 4.56), 1]
 >>> print lst
['one', 'two', (3, 4.5596), 1]
 >>>

> 
> 2) Perl's XML::Simple
> 
> It maps a XML file into a Perl data structure.

Python's got a Document Object Model lib that essentially maps an XML 
file to objects that have built-in-type behavior - you can treat a 
NodeList object as a python list, indexing into it, iterating over it's 
contents, etc.

It's also got SAX and expat bindings.

> 
> Does Python have something like these two tools? I've been googling 
> before posting this and didn't find anything.

Do your searches at python.org.


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


Re: static object

2007-01-03 Thread Russell Owen
In article <[EMAIL PROTECTED]>,
 meelab <[EMAIL PROTECTED]> wrote:

> Dear All,
> 
> I am looking for a way to create a "static object" or a "static class" -
> terms might be inappropriate - having for instance:
> 
> class StaticClass:
> .
> .
> 
> and then
> staticObject1 = StaticClass()
> staticObject2 = StaticClass()
> 
> so that staticObject1 and staticObject2 refers exactly to the same
> instance of object.

Personally I do the following (in its own module). There may be a better 
way, but this is simple and it works:

_theSingleton = None

def getSingleton():
   global _theSingleton
   if not _theSingleton:
  _theSingleton = _Singleton()
   return _theSingleton

class _Singleton:
   def __init__(self, ...):
  ...


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


Re: RSA SecurID token authentication?

2007-05-31 Thread Nick Owen
On May 29, 11:22 am, Chris Shenton <[EMAIL PROTECTED]>
wrote:
> Anyone doing python application authentication using RSASecurID
> tokens?  We have a Pylons app that needs this.
>
> I've written code against RSA's API and found the docs terrible and
> the libraries painful to use.   RSA has a RADIUS server fronting their
> server so I expect I could use that instead, might be easier.  This is
> on Solaris10 x86 which supports PAM but I've never accessed PAM from
> Python, any pointers?
>
> I've done RADIUS before (Cistron, Ascend, FreeRADIUS) but not with
> Python. Any suggestions? I see a pyrad library, last updated in March

I'm guessing it's too late to choose a two-factor solution with an
open API and open source python examples?  :) Oh well.

I recommend going with pyrad and using the Radius interface.  This
will allow you to use a third party radius server if you want and
since all the two-factor vendors support radius, you won't have to re-
write the apps if you switch strong authentication vendors.

HTH,

nick

--
Nick Owen
WiKID Systems, Inc.
404.962.8983
http://www.wikidsystems.com
Commercial/Open Source Two-Factor Authentication
irc.freenode.net: #wikid


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


Re: Distributed RVS, Darcs, tech love

2007-10-21 Thread Owen Jacobson
On Oct 21, 3:11 pm, Lew <[EMAIL PROTECTED]> wrote:

> Try using reason, logic and evidence for your points instead of merely
> shouting obscenities, hm?

You're expecting logic from someone who asserts that

> llothar wrote:
> >  only contribution to software development was the theory of
> > "literate" programming.

Good luck, mate.

-o

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


Re: [Python-Dev] RELEASED Python 2.6.2

2009-04-16 Thread Russell Owen
I installed the Mac binary on my Intel 10.5.6 system and it works,  
except it still uses Apple's system Tcl/Tk 8.4.7 instead of my  
ActiveState 8.4.19 (which is in /Library/Frameworks where one would  
expect).


I just built python from source and that version does use ActiveState  
8.4.19.


I wish I knew what's going on. Not being able to use the binary  
distros is a bit of a pain.


Just out of curiosity: which 3rd party Tcl/Tk did you have installed  
when you made the installer? Perhaps if it was 8.5 that would explain  
it. If so I may try updating my Tcl/Tk -- I've been wanting some of  
the bug fixes in 8.5 anyway.


-- Russell

On Apr 16, 2009, at 5:35 AM, Ronald Oussoren wrote:



On 15 Apr, 2009, at 22:47, Russell E. Owen wrote:


Thank you for 2.6.2.

I see the Mac binary installer isn't out yet (at least it is not  
listed
on the downloads page). Any chance that it will be compatible with  
3rd

party Tcl/Tk?


The Mac installer is late because I missed the pre-announcement of  
the 2.6.2 tag. I sent the installer to Barry earlier today.


The installer was build using a 3th-party installation of Tcl/Tk.

Ronald


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


Re: [Python-Dev] RELEASED Python 2.6.2

2009-04-17 Thread Russell Owen

On Apr 16, 2009, at 11:17 PM, Ronald Oussoren wrote:


On 16 Apr, 2009, at 20:58, Russell Owen wrote:

I installed the Mac binary on my Intel 10.5.6 system and it works,  
except it still uses Apple's system Tcl/Tk 8.4.7 instead of my  
ActiveState 8.4.19 (which is in /Library/Frameworks where one would  
expect).


That's very string. I had ActiveState 8.4 installed (whatever was  
current about a month ago).


I agree. (For what it's worth, you probably have Tcl/Tk 8.4.19 -- a  
version I've found to be very robust. 8.4.19 was released awhile ago  
and is probably the last version of 8.4 we will see, since all  
development is happening on 8.5 now).


Could you try a simple experiment (assuming you still have ActiveState  
Tcl/Tk installed): run python from the command line and enter these  
commands:

import Tkinter
root = Tkinter.Tk()

Then go to the application that comes up and select About Tcl/Tk...  
(in the Python menu) and see what version it reports. When I run with  
the Mac binary of 2.6.2 it reports 8.4.7 (Apple's built-in python).  
When I build python 2.6.2 from source it reports 8.4.19 (my  
ActiveState Tclc/Tk).


Just out of curiosity: which 3rd party Tcl/Tk did you have  
installed when you made the installer? Perhaps if it was 8.5 that  
would explain it. If so I may try updating my Tcl/Tk -- I've been  
wanting some of the bug fixes in 8.5 anyway.


Tcl 8.5 won't happen in 2.6, and might not happen in 2.7 either.   
Tkinter needs to work with the system version of Tcl, which is some  
version of 8.4,  Tkinter will not work when the major release of Tcl  
is different than during the compile. That makes it rather hard to  
support both 8.4 and 8.5 in the same installer.


Perfect. I agree.

-- Russell

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


Re: Python-list Digest, Vol 56, Issue 204

2008-05-12 Thread Gareth Owen
On Monday 12 May 2008 14:55:06 [EMAIL PROTECTED] wrote:
> Send Python-list mailing list submissions to
>   python-list@python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>   http://mail.python.org/mailman/listinfo/python-list
> or, via email, send a message with subject or body 'help' to
>   [EMAIL PROTECTED]
>
> You can reach the person managing the list at
>   [EMAIL PROTECTED]
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Python-list digest..."

If timing is critical, try using a semaphore technique.
--
http://mail.python.org/mailman/listinfo/python-list


python xslt library

2008-08-25 Thread Owen Zhang
Can anyone recommand the best performance python xslt library? Have
anyboday used 4Suite? How do you feel about performance?
--
http://mail.python.org/mailman/listinfo/python-list


lxml build error in sun

2008-09-12 Thread Owen Zhang
I am trying to build lxml package in SunOS 5.10. I got the following
errors. Does anybody know why?

$ python setup.py build
Building lxml version 2.1.
NOTE: Trying to build without Cython, pre-generated 'src/lxml/
lxml.etree.c' needs to be available.
Using build configuration of libxslt 1.1.7
Building against libxml2/libxslt in the following directory: /usr/lib
running build
running build_py
running build_ext
building 'lxml.etree' extension
gcc -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -
fPIC -I/opt/swt/install/libxml2-2.6.27/include/libxml2 -I/opt/swt/
install/Python-2.5/include/python2.5 -c src/lxml/lxml.etree.c -o build/
temp.solaris-2.10-sun4u-2.5/src/lxml/lxml.etree.o -w
In file included from /usr/include/sys/wait.h:24,
 from /usr/include/stdlib.h:22,
 from /opt/swt/install/Python-2.5/include/python2.5/
Python.h:41,
 from src/lxml/lxml.etree.c:4:
/usr/include/sys/siginfo.h:259: error: syntax error before "ctid_t"
/usr/include/sys/siginfo.h:292: error: syntax error before '}' token
/usr/include/sys/siginfo.h:294: error: syntax error before '}' token
/usr/include/sys/siginfo.h:390: error: syntax error before "ctid_t"
/usr/include/sys/siginfo.h:398: error: conflicting types for '__fault'
/usr/include/sys/siginfo.h:267: error: previous declaration of
'__fault' was here
--
http://mail.python.org/mailman/listinfo/python-list


Re: List weirdness - what the heck is going on here?

2010-01-27 Thread Owen Jacobson

On 2010-01-27 21:06:28 -0500, Rotwang  said:

Hi all, I've been trying to make a class with which to manipulate sound 
data, and have run into some behaviour I don't understand which I hope 
somebody here can explain. The class has an attribute called data, 
which is a list with two elements, one for each audio channel, each of 
which is a list containing the audio data for that channel. It also has 
various methods to write data such as sine waves and so on, and a 
method to insert data from one sound at the start of data from another. 
Schematically, the relevant bits look like this:


class sound:
 def f(self):
 self.data = [[0]]*2


Consider that this is equivalent to

def f(self):
   x = [0]
   self.data = [x, x]

self.data is now a list containing two references to the list 
referenced by x -- so changes via either of the elements of self.data 
will affect both elements. Your comprehension version creates a list 
containing two distinct list objects, so this doesn't happen.



Can anybody tell me what's going on?


-o

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


Re: general problem when subclassing a built-in class

2010-12-22 Thread Owen Jacobson

On 2010-12-22 20:22:36 -0500, kj said:


Suppose that you want to implement a subclass of built-in class, to
meet some specific design requirements.

Where in the Python documentation can one find the information
required to determine the minimal[1] set of methods that one would
need to override to achieve this goal?


(Rest elided.)

The short answer is that you can't everything you want.

If some behaviour or implementation detail isn't documented, you can't 
make any assumptions about how a class works, even if you really want 
to. Whatever you figure out by "educated guesswork" (or, even better, 
reading the source) is, absent documentation, not guaranteed, and 
behaviour that's not guaranteed can and will change whenever the code's 
maintaners feel like it. This is true for for builtins, for things in 
the standard library, and for things in competently-maintained third 
party libraries.


Requiring that every class document its internals extensively enough to 
permit subclasses to modify behaviour in totally arbitrary ways has to 
be balanced against allowing each class's interface to usefully 
abstract its internal workings. Especially in a duck-typed language 
like Python, there's very little need for subclassing simply to 
intercept one or two method calls, and the resulting composition-based 
system is both more flexible and, being based on documented and stable 
interfaces, easier to maintain and support.


Subclassing is a powerful tool, not suited to every design problem. In 
your case (tracking timestamps in a dict-like container), you're 
probably better off implementing your own dict-like container, with 
support for as much or as little of the protocol you want. You can do 
that without subclassing dict: the protocol for dict is not difficult 
to implement, especially if your backing storage is a real dict.


What forces do you imagine require you to use a subclass for this?

-o

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


Put up or shut up (Was Re: Tkinter: The good, the bad, and the ugly!)

2010-12-30 Thread Owen Jacobson

On 2010-12-30 12:36:05 -0500, rantingrick said:


On Dec 30, 9:51 am, Kevin Walzer  wrote:


Tcl is not a domain-specific language for creating GUI's. Tcl is a
full-featured, general-purpose programming language that is a peer to
Python in its capabilities,


Anybody can gloat and gush about their favorite programming language
however what separates fantasy from reality is evidence of these
"theories". Or rather, Illusions of grandeur!


One: it's "delusions" of grandeur.


and surpasses Python in some respects.


The only thing that Tcl has over Python is building Tk GUI's. Please
post evidence otherwise if you dare! In the meantime i will not be
holding my breath.


Two: were you raised in a barn? How the hell did you get so up on 
yourself that you think this is an okay way to respond to a perfectly 
civil post? Abusing people's opinions and soldiering around demanding 
everyone justify themselves to you is a great way to get people to 
ignore whatever point you were trying to make.


From your other posts, I gather that you have a very clear idea of what 
your ideal Python GUI framework would look like. That puts you in the 
best possible position to implement it. If you're successful, share it 
around; if it's good, it will gain traction on its own merit. You're 
not earning any traction on rhetorical grounds here.


-o

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


Re: Tkinter: The good, the bad, and the ugly!

2010-12-31 Thread Owen Jacobson

On 2010-12-30 19:43:21 -0500, Gerry Reno said:


For those that are lurking, this might provide a little background:

http://journal.dedasys.com/2010/03/30/where-tcl-and-tk-went-wrong



Essentially, there is nothing "wrong" with Tcl and Tkinter.  They are
part of a long evolutionary chain of how we got to where we are today.
They deserve to be respected for the contributions that they have made.

The question now is whether Python needs to evolve its own GUI toolset.


My two cents, given freely: I'd rather have better integration with 
each platform's GUI libraries and desktop services than one 
cross-platform GUI library. There are so many fundamental differences 
in accepted behaviour between each of the major GUI platforms (Gnome, 
KDE, Mac OS, and Windows, at minimum; you could include Blackberry, 
iOS, and Android in here as well, if you wanted something really 
different) that being able to put the same window with the same widgets 
on all of them is of limited value.


Consider Java's Swing toolkit - a passable cross-platform GUI library, 
whether you like its API or not. Swing apps almost *never* feel as 
pleasant to use as a native application, even on modern JVMs where 
performance isn't the problem and even using the native look & feel. 
Little things like keyboard shortcut conventions, mouse button 
conventions, and menu organization guidelines don't quite mesh. Then 
there are more complex issues, like process management, library 
packaging, software updates, and user notification, where the 
conventions on each platform differ more dramatically.


Python's native UI capabilities, on the other hand, give programmers 
the tools they need to write the core of their application using 
portable code while being able to write a UI (or UIs) that actually 
takes advantage of the underlying platform's features and that plays 
nicely with the underlying platform's conventions and interfaces - all 
without switching languages. I don't see having to maintain two or 
three UI codebases as being that much worse than riddling a single UI 
codebase with conditionals or extension points for handling each 
platform's idiosyncracies.


Fortunately for me and my opinions, Python is already shaped like that. 
PyObjC provides bindings for writing OS X applications; PyGTK and PyQt 
support Gnome and KDE respectively (as well as any other X11 desktop); 
PyWin32 provides passable support for Windows UIs, or you can use 
IronPython and .Net's GUI APIs. It is absolutely zero skin off of my 
nose if someone decides I'm utterly out of my tree, figures out that 
cross-platform GUIs are the future, and goes on to write an amazing 
pure-Python GUI stack that works everywhere with a colour monitor.


Cheers,

-o

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


Re: Why Is Escaping Data Considered So Magical?

2010-06-24 Thread Owen Jacobson

On 2010-06-24 21:02:48 -0400, Roy Smith said:


In article ,
 Lawrence D'Oliveiro  wrote:


I construct ad-hoc queries all the time. It really isn’t that hard to do
safely. All you have to do is read the documentation


I get worried when people talk about how easy it is to do something
safely.


First: I agree with this. While it's definitely possible to correctly 
escape a given SQL dialect under controlled conditions, it's not at all 
easy to get it right, and the real world is even more unfriendly than 
most people expect. Furthermore there's no reason to do it that way: 
Python's DB API spec effectively requires that placeholder parameters 
of *some* kind exist. Even if you feel the need to construct SQL, you 
can construct it with parameters almost as easily as you can construct 
it with the values baked in.


With that said...


2) Somebody runs your application with a different PYTHONPATH, which
causes a different (i.e. malicious) urllib module to get loaded, which
makes urllib.quote() do something you didn't expect.


Someone who can manipulate PYTHONPATH or otherwise add code to the 
runtime environment is already in a position to hose your database, 
independently of escaping-related issues. It's up to the sysadmin or 
user to ensure that their environment is sane, and it's on their head 
if they add broken code to a program's runtime environment.


Lawrence D'Oliveiro wrote:


I'€™ve done this sort of thing for MySQL, for HTML and JavaScript (in both
Python and JavaScript itself), and for Bash. It’s not hard to verify you’ve
done it correctly. It lets you easily create table-updating code like the
following, which makes it so easy to update the code to track changes in the
database structure:

 sql.cursor.execute \
  (
"update items set "
+
", ".join
(
tuple
(
"%(name)s = %(value)s"
%
{
"name" : field[0],
"value" : SQLString(Params.getvalue
  (
"%s[%s]" % (field[1], 
urllib.quote(modify_id))

  ))
}
for field in
(
("class_name", "modify_class"),
("make", "modify_make"),
("model", "modify_model"),
("details", "modify_details"),
("serial_nr", "modify_serial"),
("inventory_nr", "modify_invent"),
("when_purchased", "modify_when_purchased"),
... you get the idea ...
("location_name", "modify_location"),
("comment", "modify_comment"),
)
)
+
(
"last_modified = %d" % int(time.time()),
)
)
+
" where inventory_nr = %s" % SQLString(modify_id)
  )


Why would I write this when SQLAlchemy, even without using its ORM 
features, can do it for me? It even uses the placeholder-generating 
strategy I mentioned above, where possible.


Finally, it's worth noting that MySQL is (almost) the only mainstream 
database that uses escaping for parameterization. PostgreSQL, SQL 
Server, Oracle, DB2, and most other databases support parameters 
natively in their communication protocols: parameters aren't injected 
into the query string, but are sent separately and processed separately 
within the DBMS. This neatly avoids encoding-related and 
quoting-related problems entirely, and it means the type of the 
parameter can be preserved if it's useful.


-o

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


Re: Why Is Escaping Data Considered So Magical?

2010-06-25 Thread Owen Jacobson

On 2010-06-25 20:49:09 -0400, Lawrence D'Oliveiro said:


In message , Jorgen Grahn
wrote:


I thought it was well-known that the solution is *not* to try to
sanitize the input -- it's to switch to an interface which doesn't
involve generating an intermediate executable.  In the Python example,
that would be something like os.popen2(['zcat', '-f', '--', untrusted]).


That’s what I mean. Why do people consider input sanitization so hard?


It's not hard. It's just begging for a visit from the fuckup fairy.

-o

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


Re: Why Is Escaping Data Considered So Magical?

2010-06-27 Thread Owen Jacobson

On 2010-06-26 22:33:57 -0400, Lawrence D'Oliveiro said:


In message <2010062522560231540-angrybald...@gmailcom>, Owen Jacobson wrote:


It's not hard. It's just begging for a visit from the fuckup fairy.


That’s the same fallacious argument I pointed out earlier.


In the sense that "using correct manual escaping leads to SQL injection 
vulnerabilities", yes, that's a fallacious argument on its own. 
However, as sites like BUGTRAQ amply demonstrate, generating SQL 
through string manipulation is a risky development practice[0]. You can 
continue to justify your choice to do so however you want, and you may 
even be the One True Developer capable of getting it absolutely right 
under all circumstances, but I'd still reject patches that introduced a 
SQLString-like function and ask that you resubmit them using the 
database API's parameterization tools instead.


Assuming for the sake of discussion that your SQLString function 
perfectly captures the transformation required to turn an arbitrary str 
into a MySQL string literal. How do you address the following issues?


1. Other (possibly inexperienced) developers reading your source who 
may not have the skills to correctly implement the same transform 
correctly learn from your programs that writing your own query munger 
is okay.
1a. Other (possibly inexperienced) developers decide to copy and paste 
your function without fully understanding how it works, in tandem with 
any of the other issues below. (If you think this is rare, I invite you 
to visit stackoverflow or roseindia some time.)


2. MySQL changes the quoting and escaping rules to address a 
bug/feature request/developer whim, introducing a new set of corner 
cases into your function and forcing you to re-learn the escaping and 
quoting rules. (For people using DB API parameters, this is a matter of 
upgrading the DB adapter module to a version that supports the modified 
rules.)


3. You decide to switch from MySQL to a more fully-featured RDBMS, 
which may have different quoting and escaping rules around string 
literals.
3a. *Someone else* decides to port your program to a different RDBMS, 
and may not understand that SQLString implements MySQL's quoting and 
escaping rules only.


4. MySQL AB finally get off their collective duffs and adds real 
parameter separation to the MySQL wire protocol, and implements real 
prepared statements to massive speed gains in scenarios that are 
relevant to your interests; string-based query construction gets left 
out in the cold.
4a. As with case 3, except that instead of the rules changing when you 
move to a new RDBMS, it's the relative performance of submitting new 
queries versus reusing a parameterized query that changes.


On top of the obvious issue of completely avoiding quoting bugs, using 
query parameters rather than escaping and string manipulation neatly 
saves you from having to address any of these problems (and a multitude 
of others) -- the DB API implementation will handle things for you, and 
you are propagating good practice in an easy-to-understand form.


I am honestly at a loss trying to understand your position. There is a 
huge body of documentation out there about the weaknesses of 
string-manipulation-based approaches to query construction, and the use 
of query parameters is so compellingly the Right Thing that I have a 
very hard time comprehending why anyone would opt not to use it except 
out of pure ignorance of their existence. Generating executable code -- 
including SQL -- from untrusted user input introduces an large 
vulnerability surface for very little benefit.


You don't handle function parameters by building up python-language 
strs containing the values as literals and eval'ing them, do you?


-o

[0] If you want to be *really* pedantic, string-manipulation-based 
query construction is strongly correlated with the occurrence of SQL 
injection vulnerabilities and bugs, which is in turn not strongly 
correlated with very many other practices. Happy?


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


Re: Why are String Formatted Queries Considered So Magical?

2010-06-27 Thread Owen Jacobson

On 2010-06-27 22:51:59 -0400, Carl Banks said:


On Jun 27, 3:20 pm, Roy Smith  wrote:

In article
<14e44c9c-04d9-452d-b544-498adfaf7...@d8g2000yqf.googlegroups.com>,
 Carl Banks  wrote:




Seriously, almost every other kind of library uses a binary API. What
makes databases so special that they need a string-command based API?
How about this instead (where this a direct binary interface to the
library):



results = rdb_query(table = model,
                    columns = [model.name, model.number])



results = rdb_inner_join(tables = [records,tags],
                         joins = [(records.id,tags.record_id)]),
                         columns = [record.name, tag.name])



Well, we know the real reason is that C, Java, and friends lack
expressiveness and so constructing a binary query is an ASCII
nightmare.  Still, it hasn't stopped binary APIs in other kinds of
libraries.


Well, the answer to that one is simple.  SQL, in the hands of somebody
like me, can be used to express a few pathetic joins and what I do with
it could probably be handled with the kind of API you're describing.  
But, the language has far more expressivity than that, and a
domain-specific language is really a good fit for what it can do.


I'm not the biggest expert on SQL ever, but the only thing I can think
of is expressions.  Statements don't express anything very complex,
and could straightforwardly be represented by function calls.  But
it's a fair point.


Off the top of my head, I can think of a few things that would be 
tricky to turn into an API:


* Aggregation (GROUP BY, aggregate functions over arbitrary 
expressions, HAVING clauses).

* CASE expressions.
* Subqueries.
* Recursive queries (in DBMSes that support them).
* Window clauses (likewise).
* Set operations between queries (UNION, DIFFERENCE, INTERSECT).
* A surprisingly rich set of JOIN clauses beyond the obvious inner 
natural joins.

* Various DBMS-specific locking hints.
* Computed inserts and updates.
* Updates and deletes that include joins.
* RETURNING lists on modification queries.
* Explicit (DBMS-side) cursors.

This is by no means an exhaustive list.

Of course, it's possible to represent all of this via an API rather 
than a language, and libraries like SQLAlchemy make a reasonable 
attempt at doing just that. However, not every programming language has 
the kind of structural flexibility to do that well: a library similar 
to SQLalchemy would be incredibly clunky (if it worked at all) in, say, 
Java or C#, and it'd be nearly impossible to pull off in C. Even LDAP, 
which is defined more in terms of APIs than languages, forgoes trying 
to define a predicate API and uses a domain-specific filtering language 
instead.


There's certainly a useful subset of SQL that could be trivially 
replaced with an API. Simple by-the-numbers CRUD queries don't exercise 
much of SQL's power. In fact, we can do that already: any ORM can 
handle that level just fine.


-o

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


Re: Why are String Formatted Queries Considered So Magical?

2010-06-27 Thread Owen Jacobson

On 2010-06-27 22:51:59 -0400, Carl Banks said:


On Jun 27, 3:20 pm, Roy Smith  wrote:

In article
<14e44c9c-04d9-452d-b544-498adfaf7...@d8g2000yqf.googlegroups.com>,
 Carl Banks  wrote:




Seriously, almost every other kind of library uses a binary API. What
makes databases so special that they need a string-command based API?
How about this instead (where this a direct binary interface to the
library):



results = rdb_query(table = model,
                    columns = [model.name, model.number])



results = rdb_inner_join(tables = [records,tags],
                         joins = [(records.id,tags.record_id)]),
                         columns = [record.name, tag.name])



Well, we know the real reason is that C, Java, and friends lack
expressiveness and so constructing a binary query is an ASCII
nightmare.  Still, it hasn't stopped binary APIs in other kinds of
libraries.


Well, the answer to that one is simple.  SQL, in the hands of somebody
like me, can be used to express a few pathetic joins and what I do with
it could probably be handled with the kind of API you're describing.  
But, the language has far more expressivity than that, and a
domain-specific language is really a good fit for what it can do.


I'm not the biggest expert on SQL ever, but the only thing I can think
of is expressions.  Statements don't express anything very complex,
and could straightforwardly be represented by function calls.  But
it's a fair point.


Off the top of my head, I can think of a few things that would be 
tricky to turn into an API:


* Aggregation (GROUP BY, aggregate functions over arbitrary 
expressions, HAVING clauses).

* CASE expressions.
* Subqueries.
* Recursive queries (in DBMSes that support them).
* Window clauses (likewise).
* Set operations between queries (UNION, DIFFERENCE, INTERSECT).
* A surprisingly rich set of JOIN clauses beyond the obvious inner 
natural joins.

* Various DBMS-specific locking hints.
* Computed inserts and updates.
* Updates and deletes that include joins.
* RETURNING lists on modification queries.
* Explicit (DBMS-side) cursors.

This is by no means an exhaustive list.

Of course, it's possible to represent all of this via an API rather 
than a language, and libraries like SQLAlchemy make a reasonable 
attempt at doing just that. However, not every programming language has 
the kind of structural flexibility to do that well: a library similar 
to SQLalchemy would be incredibly clunky (if it worked at all) in, say, 
Java or C#, and it'd be nearly impossible to pull off in C. Even LDAP, 
which is defined more in terms of APIs than languages, forgoes trying 
to define a predicate API and uses a domain-specific filtering language 
instead.


There's certainly a useful subset of SQL that could be trivially 
replaced with an API. Simple by-the-numbers CRUD queries don't exercise 
much of SQL's power. In fact, we can do that already: any ORM can 
handle that level just fine.


-o

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


Re: Why are String Formatted Queries Considered So Magical?

2010-06-27 Thread Owen Jacobson

On 2010-06-28 00:02:57 -0400, Stephen Hansen said:


On 6/27/10 8:48 PM, Carl Banks wrote:

I don't know the exact details of all of these, but I'm going to opine
that at least some of these are easily expressible with a function
call API.  Perhaps more naturally than with string queries.  For
instance, set operations:

query1 = rdb_query(...)
query2 = rdb_query(...)

final_query = rdb_union(query1,query2)

or

final_query = query1&  query2


But, see, that's not actually what's going on behind the scenes in the 
database. Unless your "query1" and "query2" objects are opaque 
pseudo-objects which do not actually represent results -- the query 
planners do a *lot* of stuff by looking at the whole query and 
computing just how to go about executing all of the instructions.


I believe that *is* his point: that we can replace the SQL language 
with a "query object model" that lets us specify what we want without 
resorting to string-whacking when our needs are dynamic, without 
changing the rest of the workflow. This is obviously true: each RDBMS 
does something very much like what Carl is proposing, internally. 
However, implementing such an API usefully (never mind comfortably) in 
a cross-language way is... difficult, and an RDBMS that can only be 
used from Python (or even from Python and other Smalltalk-like 
languages) is not terribly useful at all.


-o

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


Trying to run Python 2.7 on Windows 7 and any suggestions on books/websites for "dummies guide to python" type learning

2010-08-02 Thread ben owen

Hi everyone, I'm new to this and was needing help with trying to learn/work 
with Python 2.7 on my computer. I'm running Windows 7 and trying to learn 
python programming from an older book from 1999 by Mark Lutz and David Ascher 
my boss gave me, and for some reason none of my script/modules for the 
exercises are working on my comp. Mostly they give either a syntax error on the 
python command line or something about the file/module not being found on the 
windows command line. Also, does anyone where i can find/get something similar 
to the book for my own?

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


[no subject]

2017-08-19 Thread Owen Berry
I'm new to python and having trouble with the most basic step. I have tried
to install python (Web-based installer) on my home pc to mess around and
attempt to develop a program. when I install the launcher it is fine but
when I try and open the file it launches a modify setup window. I have no
clue how to fix this issue and start using the actual program. how do I go
about fixing this issue? any information would be greatly valued.

Thank you




[image: Inline image 2]

Modify
[image: Inline image 3]

Next
[image: Inline image 4]

Install
[image: Inline image 5]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What's wrong with this code?

2012-07-23 Thread Russell E. Owen
In article 
,
 Chris Angelico  wrote:

> On Tue, Jul 24, 2012 at 12:50 AM, Stone Li  wrote:
> >
> > I'm totally confused by this code:
> >
> > Code:
> 
> Boiling it down to just the bit that matters:
> 
> c = None
> d = None
> x = [c,d]
> e,f = x
> c = 1
> d = 2
> print e,f
> 
> When you assign "e,f = x", you're taking the iterable x and unpacking
> its contents. There's no magical "referenceness" that makes e bind to
> the same thing as c; all that happens is that the objects in x gain
> additional references. When you rebind c and d later, that doesn't
> change x, nor e/f.
> 
> What you've done is just this:
> 
> x = [None, None]
> e,f = x
> c = 1
> d = 2
> print e,f
> 
> It's clear from this version that changing c and d shouldn't have any
> effect on e and f. In Python, any time you use a named variable in an
> expression, you can substitute the object that that name is
> referencing - it's exactly the same. (That's one of the things I love
> about Python. No silly rules about what you can do with a function
> return value - if you have a function that returns a list, you can
> directly subscript or slice it. Yay!)

Good explanation.

Perhaps what the original poster needs is a container of some kind, e.g. 
a class with the value as an instance variable. Then you can pass around 
references to the container and read or modify the value(s) stored in it 
when you need them.

Here is a simple example:

class Container(object):
   def __init__(self, value):
   self.value = value

c = Container(5)
d = Container(6)
x = [c, d]
e, f = x
c.value = None
d.value = "hello"
print e.value, f.value
None "hello"

-- Russell

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


Re: Tkinter bug in Entry widgets on OS X

2012-09-13 Thread Russell E. Owen
In article ,
 Kevin Walzer  wrote:

> On 8/31/12 6:18 AM, Arnaud Delobelle wrote:
> > I'm very inexperienced with Tkinter (I've never used it before).  All
> > I'm looking for is a workaround, i.e. a way to somehow suppress that
> > output.
> 
> What are you trying to do? Navigate the focus to another widget? You 
> should use the tab bar for that, not the arrow key. The entry widget is 
> a single-line widget, and doesn't have up/down as the text widget does.

Based on other replies it looks as if the OP found a way to intercept 
the event with suitable binding.

But I can answer the "why": on Mac OS X in a one-line text box up-arrow 
should move the cursor to the beginning and down-arrow to the end. 
That's standard behavior.

In any case I can't imagine ever wanting to see special chars get added 
when arrow keys are pressed. The default behavior of the Entry widget is 
unfortunate.

-- Russell

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


Re: Keeping a Tkinter GUI alive during a long running process

2012-12-26 Thread Russell E. Owen
In article ,
 Kevin Walzer  wrote:

> I maintain a Tkinter application that's a front-end to to a package 
> manger, and I have never been able to find a way to keep the app from 
> locking up at some point during the piping in of the package manager's 
> build output into a text widget. At some point the buffer is overwhelmed 
> and the app simply can't respond anymore, or writes data to the text 
> widget after locking up for a period.
> 
> I've long used the typical Tkinter design pattern of opening a pipe to 
> the external command, and letting it do its thing. However, after a 
> time, this locks up the app. If I try to throttle the buffer with some 
> combination of "update" or "after" or "update_idletasks," that keeps the 
> data flowing, but it comes in too slowly and keeps flowing in long after 
> the external process has terminated.
> 
> Below is a sample function that illustrates how I approach this issue. 
> Can someone suggest a better approach?
> 
>   #install a fink package
>  def installPackage(self):
> 
>  self.package = self.infotable.getcurselection()
>  if not self.package:
>  showwarning(title='Error', message='Error', detail='Please 
> select a package name.', parent=self)
>  return
>  else:
>  self.clearData()
>  self.packagename = self.package[0][1]
>  self.status.set('Installing %s' % self.packagename)
>  self.setIcon(self.phynchronicity_install)
>  self.playSound('connect')
>  self.showProgress()
>  self.file = Popen('echo %s | sudo -S %s -y install %s' % 
> (self.passtext, self.finkpath.get(), self.packagename), shell=True, 
> bufsize=0, stdout=PIPE).stdout
>  for line in self.file:
>  self.inserturltext(line)
>  self.after(5000, self.update_idletasks)

I suggest you use the threading or multiprocessing module: call 
subprocess.Popen in the spawned thread or process, read stdout in a 
tight loop write the result into a queue. Then have your main process 
asynchronously read the queue using polling.

It sounds a bit complicated, but in lieu of a way to asynchronously read 
the stdout pipe, I don't know what else to do that's safe.

Another option to consider is to use Twisted framework, which has its 
own support for running tasks. However, if you are not using Twisted 
already, it's a big addition.

-- Russell

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


Generator problem: parent class not seen

2012-02-01 Thread Russell E. Owen
I have an odd and very intermittent problem in Python script. 
Occasionally it fails with this error:

Traceback (most recent call last):
 File 
"/Applications/APO/TTUI.app/Contents/Resources/lib/python2.7/TUI/Base/Bas
eFocusScript.py", line 884, in run
 File 
"/Applications/APO/TTUI.app/Contents/Resources/lib/python2.7/TUI/Base/Bas
eFocusScript.py", line 1690, in initAll
TypeError: unbound method initAll() must be called with BaseFocusScript 
instance as first argument (got ScriptClass instance instead)
self=; class hierarchy=[(, (,)), [(, 
(,))]]

The code looks like this:

def run(self, sr):
try:
self.initAll()

except Exception:
traceback.print_exc(file=sys.stderr)
sys.stderr.write("self=%r; class hierarchy=%s\n" % (self, 
inspect.getclasstree([type(self)])))
raise

As a detail that may be important: the code is a generator that is being 
run by a script runner class (an instance of which is passed into the 
run function as argument sr). When the user starts a script the script 
runner calls the script's "run" generator. The script runner calls the 
run generator again later when conditions are right (e.g. data that is 
being waited for arrives, a time limit is reached...). In this case the 
failure occurs at the very start of the script, so a yield has not yet 
executed.

I am puzzled why Python thinks the class type is wrong, given the output 
of inspect.getclasstree. Any ideas on what might be wrong and how to 
track it down (and why it would be so intermittent)?

-- Russell

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


Re: Is it necessary to call Tk() when writing a GUI app with Tkinter?

2012-03-05 Thread Russell E. Owen
In article 
<3d0bf288-fa5d-48e5-9529-db92d420a...@1g2000yqv.googlegroups.com>,
 Rick Johnson  wrote:

> On Feb 29, 11:24 pm, Terry Reedy  wrote:
> > On 2/29/2012 10:22 PM, Rick Johnson wrote:
> 
> > > PS: I would highly suggest against using the "from Tkinter import *".
> > > Instead, use "import Tkinter as tk" and prefix all module contents
> > > with "tk.".
> >
> > I have changed the example to do that. I also showed the alternate to
> > initialize a widget. Here is the current version, tested on Windows 3.2.2.
> >
> > import tkinter as tk
> >
> > class Application(tk.Frame):
> >      def __init__(self, master=None):
> >          tk.Frame.__init__(self, master)
> >          self.pack()
> 
> With all due respect, I would also recommend against "self packing" a
> widget. And i can speak from experience on this issue. There was a
> time when i was self-packing lots of custom compund widgets; then i
> realized later the shortcomings of such action; what if you need to
> use the grid or place geometry mangers instead? So remove the
> self.pack line and add a line to the bottom:
> 
> > root = tk.Tk()
> > app = Application(master=root)
> > app.pack() # <-- added this line
> > app.mainloop()

I agree. Application is simply another widget, like Entry or Canvas. its 
contents should be packed or gridded (as appropriate) into itself, but 
the user should then pack or grid the Application widget as appropriate.

That makes the code much more reusable.

-- Russell

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


pickle question: sequencing of operations

2012-05-04 Thread Russell E. Owen
What is the sequence of calls when unpickling a class with __setstate__?

>From experimentation I see that __setstate__ is called and __init__ is 
not, but I think I need more info.

I'm trying to pickle an instance of a class that is a subclass of 
another class that contains unpickleable objects.

What I'd like to do is basically just pickle the constructor parameters 
and then use those to reconstruct the object on unpickle, but I'm not 
sure how to go about this. Or an example if anyone has one.

-- Russell

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


Re: pickle question: sequencing of operations

2012-05-08 Thread Russell E. Owen
In article ,
 "Russell E. Owen"  wrote:

> What is the sequence of calls when unpickling a class with __setstate__?
> 
> >From experimentation I see that __setstate__ is called and __init__ is 
> not, but I think I need more info.
> 
> I'm trying to pickle an instance of a class that is a subclass of 
> another class that contains unpickleable objects.
> 
> What I'd like to do is basically just pickle the constructor parameters 
> and then use those to reconstruct the object on unpickle, but I'm not 
> sure how to go about this. Or an example if anyone has one.

The following seems to work, but I don't know why:
def __getstate__(self):
   ...return the argument dict needed for __init__

def __setstate__(self, argdict):
   self.__init__(**argdict)

-- Russell

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


Re: pickle question: sequencing of operations

2012-05-09 Thread Russell E. Owen
In article 
,
 Ian Kelly  wrote:

> On Tue, May 8, 2012 at 1:19 PM, Russell E. Owen  wrote:
> > In article ,
> >  "Russell E. Owen"  wrote:
> >
> >> What is the sequence of calls when unpickling a class with __setstate__?
> 
> I believe it just calls object.__new__ followed by
> yourclass.__setstate__.  So at the point __setstate__ is called, you
> have a pristine instance of whatever class you're unpickling.

I was wondering. I override __new__ (and __init__) to print messages and 
was quite surprised to only see __new__being called when the object was 
first created, not when it was being unpickled. But maybe there's 
something funny about my override that caused unpickle to ignore it and 
use the default version. I hope so. I can't see how the object could be 
constructed during unpickle without calling __new__. But that's one 
reason I was curious about the unpickling sequence of operations.

-- Russell

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


Re: Tkinter or Python issue?

2005-10-19 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>,
 "Eric Brunel" <[EMAIL PROTECTED]> wrote:

>You should now see why it works here: your first tkFont.Font is remembered at 
>Python level in a variable. So it is not discarded once the tag_config is 
>over. So the second tkFont.Font is not allocated at the same location, so it 
>doesn't have the same id, and it doesn't have the same name at tcl level. This 
>is the general solution to the problem: keep your fonts in Python variables, 
>so they won't be discarded and their names will never be re-used.

Yes. I consider this dangerous behavior, by the way and submitted a 
patch (that was not accepted) that would prevent this garbage collection.

tkFont is Tkinter's interface to tk named fonts. If you create a tkFont 
instance for a named font and then let it disappear, the named font 
disappears, even if other tkFont instances exist that map the same named 
font.

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


[Ann] RO package 2005-10-31

2005-10-31 Thread Russell E. Owen
RO package 2005-10-31 is now available from


What is it?
A package of python utilities I wrote to support a telescope control 
interface. RO has a strong emphasis on the Tkinter GUI library, 
networking, astronomy and cross-platform support (unix, MacOS X and 
Windows). For more information, follow the link above.

Changes include:
- RO.DS9 is smarter about finding ds9 and xpa and can now handle 
byteswapped arrays.
- RO.Prefs now can map old pref names to new (allowing one to migrate a 
preference name).

For a full version history see:


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


Re: A Tcl/Tk programmer learns Python--any advice?

2005-11-08 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>,
 Kevin Walzer <[EMAIL PROTECTED]> wrote:

>I'm a Tcl/Tk developer who has been dabbling with Python for some time,...
>Well, I have finally found a good reason to learn Python in more depth:...
>
>Any advice, particularly from other programmers with a lot of experience
>in Tcl, is appreciated.

In Tkinter you don't name widgets to specify their hierarchy; instead 
when you create a new widget you specify it's parent. A tk name does get 
generated for you, but you'll never need it.

You can set and get properties on Tkinter widgets using dictionary 
notation:
curr_value = wdg["property_name"]
wdg["property_name"] = new_value
this is very convenient if you don't want to set a lot of properties at 
once.

Grid in Tkinter has less useful defaults than in tk. You should probably 
specify row and column when using Tkinter's gridder.

If you try to mix tk and Tkinter, beware of Tkinter objects that clean 
up after themselves. For instance a tkFont.Font object represents a 
named font in tk, but if you lose all references to it in python, the 
named font in tk is destroyed.

Features of Python that are well integrated and well worth using include:
- objects
- collection classes (including list, dict and set)
- exception handling
- default arguments for functions

tcl is a unusual in its desire to parse every string as a command. It 
has plusses and minuses, but in any case, you'll have to learn to do 
without (as you would when switching to almost any other language).

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


directory bug on linux; workaround?

2005-01-13 Thread Russell E. Owen
I stumbled across a really strange bug involving directories on linux.

os.path.exists(path) can return 0 even after os.path.mkdir(path) 
succeeds (well after; this isn't a timing issue).

For the first file, the directory did not exist, so my code created the 
directory (successfully) using  os.path.mkdir(path). The next file 
failed because os.path.exists(path) returned false, so my code tried to 
create the directory again, which failed with "directory exists".

It seems that the path was to a "fat" file partition and included a 
directory name that was all uppercase. The directory was created, but 
using lowercase. I'm not yet sure the version of python.

The workaround for now is to not use fat file partitions. But I was 
wondering if anyone had a better option?

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


Re: Configuring Python for Tk on Mac

2005-01-24 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] (Martyn Quick) wrote:

>On my desk here at work I have a Mac G4 running Mac OS X v10.2.8.
>
>When I go into a terminal and type "python" up comes a nice python
>interface and all seems great.  However when I type "import Tkinter"
>I'm greeted by the following error

Assuming you are running MacPython from 
...

Install Aqua Tcl/Tk as another poster suggested.

Run Applications/MacPython.../Package Manager and install Tkinter.

Or if your MacPython is out of date, you may just want to download and 
install the current version. If Tcl/Tk is already installed then I think 
it will install Tkinter automatically (but if not, use Package Manager).

If you are running some other python, please tell us more about it. (If 
it's fink python, install the version that includes Tkinter support, but 
this runs on X11 instead of Aqua).

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


Re: tkinter socket client ?

2005-01-24 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>,
 "Tonino" <[EMAIL PROTECTED]> wrote:

>yeah - had a look at createfilehandler() - was a bit confusing - but
>your example helps ;)

Be warned that createfilehandler does not work on Windows, though it 
works well on unix and MacOS X.

So my suggestion is one to try any of these (any of which are preferable 
to threads):
- file handlers for non-Windows code
- use tcl sockets for cross-platform code.
- use Twisted Framework (some work to learn, but supposedly very solid; 
I confess I've never used it myself).

There is a bit of info on the first two options (including a link to the 
RO package that includes a python interface to tcl sockets) here:



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


Re: tkinter socket client ?

2005-01-25 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>,
 "Tonino" <[EMAIL PROTECTED]> wrote:

>thanks for this info - I had to abandon the createfilehandler() method
>as it is not supported in windows and the GUI "might" be used there at
>some time ...
>
>So - I went the threading route - works well - for now - so I will
>stick to it ...
>
>BUT - the next question:
>In the Text() widget - why - when the text scrolls off the screen -
>does the window not follow it ?
>
>I have added a scrollbar to it :
>
>self.center_frame = Frame(self.top_frame, background="tan",
>relief=RIDGE)
>
>self.text=Text(self.center_frame,background='white')
>scroll=Scrollbar(self.center_frame)
>self.text.configure(yscrollcommand=scroll.set)
>
>self.text.pack(side=LEFT, fill=BOTH, expand=YES)
>scroll.pack(side=RIGHT,fill=Y)
>self.center_frame.pack(side=RIGHT, expand=YES, fill=BOTH)
>
>
>but the window does not scroll to follow the text ?
>Any ideas ?

That's just how it works. But when you append text you can easily tell 
the text widget to display it, e.g. using "see". Here is the code I use 
(from RO.Wdg.LogWdg.py), which has these useful features:
- auto-scrolls only if the user is already scrolled to the of text (so 
if a user is staring at some older data, it won't be jerked out from 
under them)
- deletes excess text.

def addOutput(self, astr, category=None):
"""Add a line of data to the log.

Inputs:
- astr: the string to append. If you want a newline, specify the \n 
yourself.
- category: name of category or None if no category
"""
# set auto-scroll flag true if scrollbar is at end
# there are two cases that indicate auto-scrolling is wanted:
# scrollPos[1] = 1.0: scrolled to end
# scrollPos[1] = scrollPos[0]: window has not yet been painted
scrollPos = self.yscroll.get()
doAutoScroll = scrollPos[1] == 1.0 or scrollPos[0] == scrollPos[1]
if category:
self.text.insert("end", astr, (category,))
else:
self.text.insert("end", astr)
extraLines = int(float(self.text.index("end")) - self.maxLineIndex)
if extraLines > 0:
self.text.delete("1.0", str(extraLines) + ".0")
if doAutoScroll:
self.text.see("end")

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


Re: continuous plotting with Tkinter

2005-02-03 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>,
 "Martin Blume" <[EMAIL PROTECTED]> wrote:

>I have a number-crunching application that spits out 
>a lot of numbers. Now I'd like to pipe this into a python
>app and plot them using Tkinter, such as:
>$ number_cruncher | myplot.py
>But with Tkinter once  I call Tkinter's mainloop() I
>give up my control of the app and I can't continue to
>read in data from stdin.  Or can I? If so, how?

One way is to use a thread to read the numbers, then make them available 
to the main thread via a Queue object, which you poll for new values.

Another option is to use a Tk-compatible file or socket of some kind 
which triggers a callback when data comes in. See 
 
some ideas on this.

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


Re: Reinstall python 2.3 on OSX 10.3.5?

2005-02-03 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] wrote:

>Hi there
>
>I started a very long and roundabout process of attempting to install
>python 2.3.4 along side my apple-installed 2.3 system. To make a long
>story short, I have completely confabulated my environment ( i deleted
>the 2.3 binaries and so forth from the system in an attempt to start
>things fresh), and now I cannot figure out how to reinstall the base
>2.3 Apple python distribution.
>Can somebody please point me in the right direction?

Archive and Install of the operating system is the safest.

But if you have some kind a backup or know somebody with a similar Mac, 
you could try reinstalling /System/Library/Frameworks/Python.framework. 
You'd have to do this in a way that preserved ownership and permissions.
That would probably still leave a few unresolved symbolic links and/or 
aliases lying around, but is worth a try (especially if you can examine 
that system and see where the links go). In particular 
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/s
ite-packages" points to "/Library/Python/2.3" and /usr/bin/python and 
/usr/bin/pythonw point somewhere useful.

But...archive and install is really the safest and it's a chance to 
clean up a bit of cruft. (But it messes with /usr/local and your web 
site, so back all that up first).

-- Russell

P.S. I installed a separate unix/x11 Python 2.4 in /usr/local with no 
problem using the default install process. However, I wanted X11 Tk 
support for that, so I first:
- moved the aqua Tk (in /Library/Frameworks/Tk.framework, and 
Tcl.framework) so the installers could not find them
- installed unix/x11 tcl and tk (again using the default install process)
This results in a perfectly workable python that uses the X11 Tk stuff.

It's a minor headache having two pythons -- every package has to be 
installed twice if you want it available in both pythons.
-- 
http://mail.python.org/mailman/listinfo/python-list


How to get a unique id for bound methods?

2005-08-19 Thread Russell E. Owen
I have several situations in my code where I want a unique identifier 
for a method of some object (I think this is called a bound method). I 
want this id to be both unique to that method and also stable (so I can 
regenerate it later if necessary).

I thought the id function was the obvious choice, but it doesn't seem to 
work. The id of two different methods of the same object seems to be the 
same, and it may not be stable either. For instance:

class cls(object):
  def __init__(self):
print id(self.meth1)
print id(self.meth2)
  def meth1(self):
pass
  def meth2(self):
pass

c = cls()
3741536
3741536
print id(c.meth1)
3616240
print id(c.meth2)
3616240

I guess that just means bound methods aren't objects in their own right, 
but it surprised me.

The "hash" function looks promising -- it prints out consistent values 
if I use it instead of "id" in the code above. Is it stable and unique? 
The documentation talks about "objects" again, which given the behavior 
of id makes me pretty nervous.

Any advice would be much appreciated.

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


Re: How to get a unique id for bound methods?

2005-08-19 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>,
 Benji York <[EMAIL PROTECTED]> wrote:

>Russell E. Owen wrote:
>> The id of two different methods of the same object seems to be the 
>> same, and it may not be stable either.
>
>Two facts you're (apparently) unaware of are conspiring against you:
>
>1) the "id" of an object is consistent for the lifetime of the object, 
>but may be reused after the object goes away
>
>2) methods are bound on an as-needed basis and then normally discarded 
>(unless you do something to keep them around)

Thank you and Bengt Richter. You both explained it very well.

The current issue is associated with Tkinter. I'm trying to create a tk 
callback function that calls a python "function" (any python callable 
entity).

To do that, I have to create a name for tk that is unique to my python 
"function". A hash-like name would be perfect, meaning a name that is 
always the same for a particular python "function" and always different 
for a different python "function". That would save a lot of housekeeping.

Does the built-in hash function actually do the job?

If I centralize all tk callback management and keep objects that 
represent the tk callback around then I can avoid the whole issue. I was 
hoping to avoid that, because it complicates housekeeping and adds a 
risk of memory leaks (at least I think so; right now tk deallocates its 
callback functions in the few cases I care about so I don't worry about 
it.)

-- Russell

P.S. Paolino: thank you also for your kind reply. Your suggestion sounds 
very useful if I only want a hash for a bound function, but in this case 
since I want a hash for any callable entity I'm not sure it'll work.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to get a unique id for bound methods?

2005-08-22 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] (Bengt Richter) wrote:

>On Fri, 19 Aug 2005 16:33:22 -0700, "Russell E. Owen" <[EMAIL PROTECTED]> 
>wrote:
>[...]
>>
>>The current issue is associated with Tkinter. I'm trying to create a tk 
>>callback function that calls a python "function" (any python callable 
>>entity).
>>
>>To do that, I have to create a name for tk that is unique to my python 
>>"function". A hash-like name would be perfect, meaning a name that is 
>>always the same for a particular python "function" and always different 
>>for a different python "function". That would save a lot of housekeeping.
>>
>Why do you need a name? Can you post an example snippet that shows
>a callback function being used with Tkinter as you would wish?
>I have a feeling there is a much simpler solution than you are imagining ;-)

Here is an example (simplified from my real code; I may have introduced 
an error in the process). I could switch to the twisted framework, but 
this code has been working very well and it saves my users from having 
to install a 3rd party package.

-- Russell

def addTkCallback(tk, func):
tkName = "cb%d" % hash(func)
tk.createcommand(tkNname, func)
return tkName

class TkSocket(TkBaseSocket):
def __init__(self,
addr,
port,
binary=False,
readCallback = None,
stateCallback = None,
tkSock = None,
):
...
try:
# create the socket and configure it
self._sock = self._tk.call("socket", ...)
self._tk.call("fconfigure", self._sock, ...)

# add callbacks; the write callback is just used to detect 
state
readName =addTkCallback(self._tk, self._doRead)
self._tk.call('fileevent', self._sock, "readable",
readName)
connName = addTkCallback(self._tk, self._doConnect)
self._tk.call('fileevent', self._sock, "writable", connName
except Tkinter.TclError, e:
raise RuntimeError(e)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: High Level FTP library

2005-08-23 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>,
 "Paulo Pinto" <[EMAIL PROTECTED]> wrote:

>Hello,
>
>Is there any Python library similar to NET::FTP from Perl?
>ftplib seems too lowlevel.
>
>I already found a few, but would like to get one that is
>endorsed by the community.

Try urllib or urllib2; these are included with python. urllib2 is newer 
but only works for anonymous ftp. Caveat: I ran into trouble doing 
multiple simultaneous ftp using urllib. I have not used urllib2.

Another possibility is Twisted Framework. It has a bit of a learning 
curve but is well regarded. If you plan to do a lot with networking you 
should definitely check it out.

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


Re: How to get a unique id for bound methods?

2005-08-23 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>,
 "Fredrik Lundh" <[EMAIL PROTECTED]> wrote:

>Russell E. Owen wrote:
>
>>>>The current issue is associated with Tkinter. I'm trying to create a tk
>>>>callback function that calls a python "function" (any python callable
>>>>entity).
>>>>
>>>>To do that, I have to create a name for tk that is unique to my python
>>>>"function". A hash-like name would be perfect, meaning a name that is
>>>>always the same for a particular python "function" and always different
>>>>for a different python "function". That would save a lot of housekeeping.
>
>have you tried Tkinter's built-in _register method?
>
>>>> import Tkinter
>>>> w = Tkinter.Tk()
>>>> help(w._register)
>Help on method _register in module Tkinter:
>
>_register(self, func, subst=None, needcleanup=1) method of Tkinter.Tk 
>instance
>Return a newly created Tcl function. If this
>function is called, the Python function FUNC will
>be executed. An optional function SUBST can
>be given which will be executed before FUNC.

Thanks. That looks like just the thing. I think I had seen it but was 
deterred by the leading underscore (suggesting an internal method whose 
interface might change). Still, I guess if it gets modified I can just 
change my code.

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


Re: How to get a unique id for bound methods?

2005-08-23 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>,
 "Fredrik Lundh" <[EMAIL PROTECTED]> wrote:

>Russell E. Owen wrote:
>
>>>>The current issue is associated with Tkinter. I'm trying to create a tk
>>>>callback function that calls a python "function" (any python callable
>>>>entity).
>>>>
>>>>To do that, I have to create a name for tk that is unique to my python
>>>>"function". A hash-like name would be perfect, meaning a name that is
>>>>always the same for a particular python "function" and always different
>>>>for a different python "function". That would save a lot of housekeeping.
>
>have you tried Tkinter's built-in _register method?
>
>>>> import Tkinter
>>>> w = Tkinter.Tk()
>>>> help(w._register)
>Help on method _register in module Tkinter:
>
>_register(self, func, subst=None, needcleanup=1) method of Tkinter.Tk 
>instance
>Return a newly created Tcl function. If this
>function is called, the Python function FUNC will
>be executed. An optional function SUBST can
>be given which will be executed before FUNC.

Having looked at it again, it is familiar. I copied it when I wrote my 
own code. I avoided using at the time both because the initial 
underscore suggested it was a private method and because it introduces 
an extra function call.

_register has the same weakness that my code had when I used id(func) -- 
it uses the id of the function to generate the unique tk function name, 
but it keeps no reference to that function.

Either Tkinter is clever about keeping a reference to each callable 
around, or else it has the same bug I was seeing and it just doesn't 
show up often enough to have been caught. I should take some time and 
look into that.

It's a frustrating problem. There should be some simple way to get a 
unique hash-like identifier for any callable entity. If one were just 
using functions then id() would be fine. But bound methods are too 
different.

I'll use "hash" for now, but given that I"m not sure what hash is even 
doing, I should recode to something that I know works.

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


Re: Sorta noob question - file vs. open?

2005-08-23 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>,
 Peter A. Schott <[EMAIL PROTECTED]> wrote:

>Been reading the docs saying that file should replace open in our code, but 
>this
>doesn't seem to work:
>
># Open file for writing, write something, close file
>MyFile = file("MyFile.txt", "w")
>MyFile.write("This is a test.")
>MyFile.close()

This should work in a sufficiently recent version of python (I'm hedging 
because I don't recall when file was introduced -- python 2.2? 2.3?). 
What version are you using? What error do you see?

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


Re: How to get a unique id for bound methods?

2005-08-24 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>,
 "Fredrik Lundh" <[EMAIL PROTECTED]> wrote:

>Russell E. Owen wrote:
>
>> Having looked at it again, it is familiar. I copied it when I wrote my
>> own code. I avoided using at the time both because the initial
>> underscore suggested it was a private method and because it introduces
>> an extra function call.
>>
>> _register has the same weakness that my code had when I used id(func) -- 
>> it uses the id of the function to generate the unique tk function name,
>> but it keeps no reference to that function.
>>
>> Either Tkinter is clever about keeping a reference to each callable
>> around, or else it has the same bug I was seeing and it just doesn't
>> show up often enough to have been caught. I should take some time and
>> look into that.
>
>of course it keeps a reference to it; how else do you expect
>the Tcl command to find the right PyObjects?

Right. Of course.

I started out emulating the code for _register but over time made 
various incremental changes. Eventually I messed up and started taking 
the id of the wrong thing. I was able to fix that and all is well -- 
without having to use the mysterious hash function.

I also now keep a reference to the tk function name so I can properly 
delete it when finished. That eliminates a small memory leak.

Thanks for all your help.

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


Re: How to define a window's position (Tkinter)

2005-02-28 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>,
 "Harlin Seritt" <[EMAIL PROTECTED]> wrote:

>I am trying to use the geometry() method with the toplevel window
>called root. I know that one can do the following:
>
>root.geometry('400x400+200+200')
>
>This will put the window in 200, 200 position with a size of 400x400.
>Now, I don't really want to set the size. I simply want to set the
>position of the window. I've tried this:
>
>root.geometry('200+200')
>
>However, this doesn't seem to work. What can I do to set the position
>of the window without actually setting the size?

You were almost there, but you need an initial "+":
root.geometry("+200+200").

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


Re: tkinter shell problem

2004-11-29 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>,
 "Philippe C. Martin" <[EMAIL PROTECTED]> wrote:

>Hi,
>
>I have the following problem:...
>If I trap (an exception), I do not get the stack dump that I which I would 
>show.
>...
>If I don"t trap it, then my clean up code...does not get called...
>
>Yet Idle manages - any clue ?

Use the traceback module. For example:

try:
...code to protect...
except (SystemExit, KeyboardInterrupt):
raise
except Exception, e:
traceback.print_exc(file=sys.stderr)
code to handle exception...

if you are sure none of your code can raise error exceptions that 
inherit directly from Exception, you can simplify this to one except:
except StandardError, e:
Unfortunately, some common modules (including Tkinter) raise exceptions 
that inherit from Exception, not StandardError.

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


Re: PHP vs. Python

2004-12-22 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] wrote:

>Anyone know which is faster?  I'm a PHP programmer but considering
>getting into Python ... did searches on Google but didn't turn much up
>on this.

For web service, the first hurdle is picking which python web interface 
to use, installing it and (if necessary) configuring your web server to 
use it. (All that choice is great in many respects, but it does 
complicate getting started.)

Anyway, once you've done that, i doubt you'll find any speed issues with 
python, and it is a more pleasant language than PHP. (Unfortunately, 
that initial hurdle can be a big one; I am still using PHP on my server 
because I never cleared it.)

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


Re: what would you like to see in a 2nd edition Nutshell?

2004-12-29 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] (Alex Martelli) wrote:

>I'm considering proposing to O'Reilly a 2nd edition of "Python in a
>Nutshell", that I'd write in 2005, essentially to cover Python 2.3 and
>2.4 (the current 1st edition only covers Python up to 2.2).
>...

Since you were kind enough to ask...what I'd really like is a better 
better index and better organization, so I can more quickly and easily 
locate info on a particular topic.

Nutshell has some wonderful in-depth discussions of certain topics and 
I'm glad I own it, but I find it too hard to use for everyday questions 
(which was not at all what I expected for a "nutshell" book). I usually 
start with the html help (if I know the module I need or have a firm 
guess as to which other manual to read) or Python Essential Reference 
(other cases), then go to Nutshell if I'm still lost or if I remember it 
has a good section on the topic of interest.

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


Re: what would you like to see in a 2nd edition Nutshell?

2004-12-29 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] (Alex Martelli) wrote:

>Russell E. Owen <[EMAIL PROTECTED]> wrote:
>
>> In article <[EMAIL PROTECTED]>,
>>  [EMAIL PROTECTED] (Alex Martelli) wrote:
>> 
>> >I'm considering proposing to O'Reilly a 2nd edition of "Python in a
>> >Nutshell", that I'd write in 2005, essentially to cover Python 2.3 and
>> >2.4 (the current 1st edition only covers Python up to 2.2).
>> >...
>> 
>> Since you were kind enough to ask...what I'd really like is a better 
>> better index and better organization, so I can more quickly and easily
>> locate info on a particular topic.
>
>Thanks for the advice!  What I have now is the best organization I was
>able to conceive -- and I have no current ideas on how to enhance it.
>Any _suggestions_ will be truly welcome; somehow, I don't see "make it
>better" as a _suggestion_... if I _knew_ how to organize it better, I
>would, of course.

Fair enough. I was being lazy, but also wanted to be sure the input 
would be considered useful before going into details.

Here are some issues for me:

* A mini table of contents for each major section would be really 
helpful. List the modules, and (if appropriate) sub-modules with maybe a 
one-liner as to what they do, and a page #.

* The discussion of the os module (p171) could especially use such a 
TOC. p171 starts with a nice, thorough explanation of os and all it 
does, but as a quick reference it is tricky; rather than jumping right 
to what I want, I have to get past a discussion of OSError an the errno 
module before any os methods are discussed, and then I have to flip 
through many pages of stuff to find the right section.

* Please cross-reference using page #s, not just chapter #s or "covered 
later in this chapter". For instance the os module text refers one to 
"chapter 14" for a discussion of os's handling of processes. Ouch. I 
hope that modern writing tools make page # references safe and easy.

* Some of the page breaks are awkward. I know it eats paper to fix it 
everywhere, but... for example, it'd help to have the re special 
characters table all on one page (or at least on facing pages).

* Exceptions:
- I beg you to include a ONE-PAGE table of exceptions that shows the 
inheritance hierarchy via indentation (e.g. like Python Essential 
Reference). The detailed info will probably have to follow.

Such a table is a much easier way of figuring out who inherits from who, 
and I usually find such a table sufficient (and very efficient) for 
picking out which exception to use.

Having the detailed info is much appreciated, but it's a poor substitute 
for a quick reference table.

- Some discussion of which standard modules raise errors that inheriit 
directly from Exception instead of StandardError would be helpful.

- (nit-pick) The try statement, bottom of p104. The two basic forms are 
listed, but a page # for the 2nd form would help jump there.

- Exception objects, p109. Using strings as exceptions would make a nice 
footnote instead of cluttering up the main text. They've been deprecated 
for a long time.


Also, two content requests:

* please describe the new subprocess module in gory detail and move 
discussion of the older modules which it can replace to an appendix or 
the back of the same chapter or in some other way keep it from 
cluttering up the main text. (I'm sure popen, etc. still has to be 
discussed, if only for folks dealing with older code, but subprocess is 
clearly the right way to go for new code).

* Please describe numarray instead of Numeric (or both, or discuss 
numarray and list some changes from Numeric?)


I'm looking forward to the next edition!

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


Fast plotting?

2005-04-26 Thread Russell E. Owen
Can anyone recommend a fast cross-platform plotting package for 2-D 
plots?

Our situation:
We are driving an instrument that outputs data at 20Hz. Control is via 
an existing Tkinter application (which is being extended for this new 
instrument) that runs on unix, mac and windows. We wish to update 5-10 
summary plots at approximately 2 Hz and will be offering controls to 
control the instrument and the plots, preferably (but not necessarily) 
mixed in with the plots.

Ideally the package would create plots in the Tkinter application. But 
we realize we're unlikely to get the speed we need that way. So we are 
willing to have the Tkinter app send data to the plotting package  (e.g. 
via a socket) and have it display the plots in a separate process.

We started out with matplotlib, which is a wonderful package (and well 
integrated with most or all GUI toolkits). Unfortunately it is just too 
slow -- at least when driving plots integrated with the Tkinter app. (It  
is getting faster and so are computers, so at some point this will be a 
great way to go. But for now...)

Any suggestions?

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


Running python's own unit tests?

2013-11-14 Thread Russell E. Owen
I'm building python from source and trying to figure out how to test the 
result. I must be overlooking something obvious, but I looked through 
the documentation and source and tried some google searches (which turn 
up plenty about writing unit tests in python, but nothing about testing 
a python distribution).

Any hints?

-- Russell

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


Re: Running python's own unit tests?

2013-11-15 Thread Russell E. Owen
In article <5285223d.50...@timgolden.me.uk>,
 Tim Golden  wrote:

> http://docs.python.org/devguide/

Thank you and the other responders. I was expecting to find the 
information here  under 
Building Python. The developer's guide is a nice resource.

-- Russell

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


Suggested GUI framework for Mac and unix?

2014-01-06 Thread Russell E. Owen
I have a free cross-platform Python GUI application that has to run on 
Mac and linux. It is presently written in Tkinter, but for various 
reasons* it may be time to switch.

I've heard many good things about wxpython and qt, but not used either, 
and am wondering if somebody could tell me if either (or both) would 
meet the following needs:
-  Reliable on mac and linux. (I see that wxpython now runs under Cocoa 
but I've not seen any reports on how well that went.)
- Compatible with matplotlib.
- Able to display (grayscale) images with arbitrary zoom. I currently 
use PIL with Tkinter's Canvas widget for this.
- Compatible with a sound library for playing sound cues. I presently 
use pygame for this and have been considering switching to PySDL.
- Compatible with Twisted Framework.
- Prediction is hard, but indications of a long-term future would be a 
definite bonus.

-- Russell

*I have no wish to disparage Tkinter. I personally like it and am very 
grateful to the developers. However, several issues are driving me to 
look for alternatives:
* There is a known crashing bug in recent versions of Tcl/Tk that keeps 
me at 8.5.11. Unfortunately I've not found a workaround.
* Tcl/Tk 8.5.11 is not compatible with Mavericks unless one runs in 
32-bit mode.
* There are known issues with the Tcl/Tk event loop since the switch to 
Cocoa. These are unlikely to be fixed, though in many cases it is 
practical to work around them. This is more of a long-term worry than a 
concrete problem.

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


Re: Mac python py2app problem

2014-07-17 Thread Russell E. Owen
In article ,
 Gregory Ewing  wrote:

> Nicholas Cannon wrote:
> > I do like the idea of making a .dmg file
> > because i have used them downloading other apps and it works great but i 
> > dont
> > know how to make them!
> 
> In Disk Utility, use File>New>Disk Image from Folder.

Or...open Disk Utility and drop the app onto its dock icon.

-- Russell

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


redirect stderr to syslog?

2014-08-15 Thread Russell E. Owen
We are using the syslog module for logging, and would like to redirect 
stderr to our log. Is there a practical way to do it?

I realize the logging module supports this and has a syslog writer, so 
that's a fallback. But we were hoping to use the syslog module for 
performance.

-- Russell

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


Decorator question: prefer class, but only function works

2011-11-10 Thread Russell E. Owen
I am trying to write a decorator that times an instance method and 
writes the results to a class member variable. For example:

def timeMethod(func):
def wrapper(self, *args, **keyArgs):
t1 = time.time()
res = func(self, *args, **keyArgs)
duration = time.time() - t1
self.timings[func.__name__] = duration
return res
return wrapper

This works, but I'm not very happy with the way self.timings is obtained.


I first tried to write this as a class (for readability), and this did 
NOT work:

class timeMethod(object):
def __init__(self, func):
self.func = func
def __call__(self, *args, **keyArgs):
t1 = time.time()
res = self.func(*args, **keyArgs)
duration = time.time() - t1
args[0].timings.set(self.func.__name__, duration)
return res

In the first case the wrapper is called as an unbound function, so it 
works. But in the second case the wrapper is called as a bound method -- 
thus args[0] is not func's class instance, and I can't get to the 
timings attribute.

Unfortunately they are both pretty ugly. Is there a cleaner way to 
access the the instance of which func is a member? I was very 
disappointed it was not available when timeMethod was 
called/instantiated.

-- Russell

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


Re: Decorator question: prefer class, but only function works

2011-11-14 Thread Russell E. Owen
In article 
,
 Ian Kelly  wrote:

> On Thu, Nov 10, 2011 at 2:52 PM, Russell E. Owen  wrote:
> > I am trying to write a decorator that times an instance method and
> > writes the results to a class member variable. For example:
> >
> > def timeMethod(func):
> >    def wrapper(self, *args, **keyArgs):
> >        t1 = time.time()
> >        res = func(self, *args, **keyArgs)
> >        duration = time.time() - t1
> >        self.timings[func.__name__] = duration
> >        return res
> >    return wrapper
> >
> > This works, but I'm not very happy with the way self.timings is obtained.
> 
> What do you feel is wrong with it? 

Oops, I stripped so much out of my example that I stripped the ugly bit. 
This is closer to the original and demonstrated the issue:

def timeMethod(func):
name = func.__name__ + "Duration"
def wrapper(self, *args, **keyArgs):
       t1 = time.time()
       res = func(self, *args, **keyArgs)
       duration = time.time() - t1
       self.timings[name] = duration
       return res
   return wrapper

I don't like the way name is passed into wrapper. It works, but it looks 
like magic. A class offers an obvious place to save the information. Or 
I could just generate the name each time.

I realize I'm showing the limits of my understanding of python binding 
of variable names, but I also think that if I find it confusing then 
others will, as well.

> sum(os.times()[:2]) instead, which (assuming your script is
> single-threaded) will more accurately count the actual CPU time spent
> in the function rather than real time, which could be quite different
> if the CPU is busy.

Thanks for the suggestion. I decided to use time.clock(), which I 
understand gives basically the same information (at a resolution that is 
sufficient for my needs).

> Also, why do you need this?  If you're just trying to evaluate the
> speed of your code, you should consider using a proper profiler or the
> timeit module. The former will tell you how much time is spent in
> each function, while the latter runs the code a large number of times
> in a loop, which gives you better precision for quick methods.

It is for timing stages of a data processing pipeline. Only long-running 
tasks will be timed. Repeatedly running to get better times is neither 
practical nor necessary to get a good feeling of where the time is being 
spent.

> > I first tried to write this as a class (for readability), and this did
> > NOT work:
> >
> > class timeMethod(object):
> >    def __init__(self, func):
> >        self.func = func
> >    def __call__(self, *args, **keyArgs):
> >        t1 = time.time()
> >        res = self.func(*args, **keyArgs)
> >        duration = time.time() - t1
> >        args[0].timings.set(self.func.__name__, duration)
> >        return res
> >
> > In the first case the wrapper is called as an unbound function, so it
> > works. But in the second case the wrapper is called as a bound method --
> > thus args[0] is not func's class instance, and I can't get to the
> > timings attribute.
> 
> I prefer the function version myself, but to make this work you could
> add something like this (untested) to make your wrapper class a
> descriptor that tacks on the self argument:
> 
> def __get__(self, instance, owner):
> from functools import partial
> if instance is None:
> return self
> return partial(self, instance)

Thank you very much. I'll stick to the function, since it works, but 
it's nice to know how to work around the problem.

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


Re: Why is Ruby on Rails more popular than Django?

2013-03-07 Thread Russell E. Owen
In article 
<3d9fe0b2-7931-4ab6-8929-235460729...@q9g2000pbf.googlegroups.com>,
 rusi  wrote:

> On Mar 6, 11:03 pm, Jason Hsu  wrote:
> > I'm currently in the process of learning Ruby on Rails.  I'm going through 
> > the Rails for Zombies tutorial, and I'm seeing the power of Rails.
> >
> > I still need to get a Ruby on Rails site up and running for the world to 
> > see.  (My first serious RoR site will profile mutual funds from a value 
> > investor's point of view.)
> >
> > I have an existing web site and project called Doppler Value Investing 
> > (dopplervalueinvesting.com) that uses Drupal to display the web pages and 
> > Python web-scraping scripts to create *.csv and *.html files showing 
> > information on individual stocks.  My site has a tacked-on feel to it, and 
> > I definitely want to change the setup.
> >
> > At a future time, I will rebuild my Doppler Value Investing web site in 
> > either Ruby on Rails or Django.  The Ruby on Rails route will require 
> > rewriting my Python script in Ruby.  The Django route will require learning 
> > Django.  (I'm not sure which one will be easier.)
> >
> > My questions:
> > 1.  Why is Ruby on Rails much more popular than Django?
> 
> "Where there is choice there is no freedom"
> http://www.jiddu-krishnamurti.net/en/1954/1954-03-03-jiddu-krishnamurti-8th-pu
> blic-talk
> 
> Python-for-web offered so much choice -- zope, django, turbogears,
> cherrypy, web.py etc etc -- that the newbie was completely drowned.
> With Ruby there is only one choice to make -- choose Ruby and rails
> follows.
> 
> Anyone who's used emacs will know this as the bane of FLOSS software
> -- 100 ways of doing something and none perfect -- IOW too much
> spurious choice.
> 
> GvR understood and rigorously implemented a dictum that Nicklaus Wirth
> formulated decades ago -- "The most important thing about language
> design is what to leave out." Therefore Python is a beautiful
> language.  Unfortunately the same leadership did not carry over to web
> frameworks and so we have a mess.
> 
> I guess the situation is being corrected with google putting its
> artillery behind django.

I strongly agree. The fact that there is no de-facto standard web system 
for Python is a major problem. Consider:
- With too many choice one has no idea which projects will be maintained 
and which will be abandoned.
- Expert knowledge among users is spread more thinly.
- The effort of contributors is diluted.

Years ago when I had some simple web programming to do I looked at the 
choices, gave up and used PHP (which I hated, but got the job done). If 
RoR had been available I would have been much happier using that.

In my opinion the plethora of Python web frameworks is a serious 
detriment to trust and wider acceptance of Python for this use. If  
Django is becoming this standard, that is excellent news.

Some choice is good, but in my opinion too much choice and lack of a 
de-facto standard are very detrimental.

-- Russell

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


Re: Which Python web framework is most like Ruby on Rails?

2005-12-19 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>,
 Paul Rubin  wrote:

>[EMAIL PROTECTED] (Alex Martelli) writes:
>> To put it another way: one reason I love Python is that I strongly
>> subscribe to the idea that there should preferably be only one obvious
>> way to do something.  Unfortunately, this principle is very badly broken
>> by the multiplicity of Python web frameworks.
>
>This also has to be a big part of why PHP is kicking the pants off of
>Python for popularity in web development.

I agree. It's sad to see such a terrible language as PHP so popular, and 
such a complicated mess in python, my language of choice.

I love python and am lucky enough to be able to do almost all my coding 
in it. Yet even I use PHP to serve a database. I loathe PHP, but:
- it came preinstalled on my system (MacOS X 10.3.x).
- I found a nice simple intro to it (a quickstart guide, which taught me 
all I needed to know for my simple needs).
- I started out by looking at the choices in python. Of course. I read 
the shootout. I asked for help. But the results were utterly 
overwhelming.

I wanted (and I am guessing this isn't too far off for most users -- at 
least most non-web-gurus) a framework that was:
- Well designed, robust, "finished" (i.e. not alpha).
- Easy to use, especially for simple, basic tasks. (And not a toy, of 
course -- powerful enough to handle reasonable traffic and tasks.)
- Easy to install.
- Well documented, with a good introduction or tutorial.
- Likely to be around for awhile. The plethora of options on Python do 
NOT inspire confidence in that area.

Some choice is good -- especially if the choices solve obviously 
different problems. But too much choice is paralyzing and fragments the 
community.

Anyway, thanks for holding this discussion. Django and TurboGears were 
both new to me. I hope something finally gets popular enough to be worth 
betting on.

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


Re: Which Python web framework is most like Ruby on Rails?

2005-12-19 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>, Mike Meyer <[EMAIL PROTECTED]> 
wrote:

>"Ben Sizer" <[EMAIL PROTECTED]> writes:
>> I see what you mean, but unfortunately I think there is a lot more
>> fuzziness than that. If the separate parts were clearly delineated
>> things would be a lot better. I look to the Database API Specification
>> as a great example of how this could (should?) be done, allowing for
>> easy interchangeability while still providing a well-documented
>> standard
>
>Constant queries on c.l.python for "Which DB module should I use"
>would indicate that having a standard and to many choices isn't really
>better than having no standard and to many choices.

I disagree. Once you've picked a database (not trivial in itself, of 
course), you typically only have a few options for talking to in in 
Python. Also, typically either:
- One stands out (because others have been abandoned or whatever), so 
there's an easy answer, or
- They all work about the same, so even if you decide to switch for some 
reason it makes little difference.

SQLObject breaks that mold, but for excellent reasons. It's nice to 
start from a standard and then maybe somebody figures out a really nifty 
way to do things. (I haven't used SQLObject yet, but I plan to try it 
out when things calm down a bit).

If we had a standard basic web framework or a standard template language 
it would really help (more folks using it, more folks who can help folks 
learning it, better documentation, more focused development). Something 
better might come along, and then it'd be easier to evaluate and more 
appreciated.

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


Re: Which Python web framework is most like Ruby on Rails?

2005-12-20 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>,
 Benji York <[EMAIL PROTECTED]> wrote:

>Russell E. Owen wrote:
>> I disagree. Once you've picked a database (not trivial in itself, of 
>> course), you typically only have a few options for talking to in in 
>> Python.
>
>Perhaps it's off-topic for this thread, but I think "picking a database" 
>is the first mistake most people make.  It's a form of premature 
>optimization.

I just wanted to point out that I was responding to somebody who 
complained that the database interface situation on python was somewhat 
fragmented.

Also, when I was looking at web frameworks, I was doing so *precisely* 
to serve one or more databases of information (read only to the users, 
but occasionally loaded with more info as it became available). So it 
happened to be the first question I asked (at the same time as "and how 
do I talk to it?").

Anyway, you did warn that your message was possibly off-topic, so I 
guess I'm agreeing with you and perhaps being overly defensive. It was 
an interesting message.

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


Re: Any wing2.0 users here?

2006-01-03 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>,
 "Alvin A. Delagon" <[EMAIL PROTECTED]> wrote:

>Thanks for all the recommendations! I took a look on wingide2.0 on my 
>linux box and it seems pretty good and has a lot of nifty features 
>(which is pretty daunting to use since I've been programming with no IDE 
>at all) and it debugger work pretty well but for a price tag of $179 I 
>think it not worth it.

I've tried various IDEs and like WingIDE by far the best. It is easy to 
use, robust and has great support. The improved productivity is well 
worth the price (especially if your work is buying it for you). I 
qualified for a free license, but would certainly have had my job pay 
for it otherwise. I was tempted to buy it anyway, but felt it would be 
unethical to my employer.

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


Re: How can I test if an argument is a sequence or a scalar?

2006-01-11 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] wrote:

>I want to be able to pass a sequence (tuple, or list) of objects to a
>function, or only one.
>
>It's easy enough to do:
>
>isinstance(var, (tuple, list))
>
>But I would also like to accept generators. How can I do this?
>
>Anything else is assumed to be a single value (my fault if I pass a
>dict or something else to the function) and I make it into a tuple with
>a single value (var, ) in order to simplify the algorithm (wasn't there
>a special name for a one item tuple? Its been a while since I've
>programmed in Python.)
>
>Is there an easy way to do that?

Here is the code I use for that purpose, but it does not handle 
generators or iterators. You could easily combine this with code 
suggested in other replies to accomplish that. (I intentionally excluded 
iterators because I didn't need them and they can be unbounded. Still, 
now that they are so widely used it may be worth reconsidering.)

def isSequence(item):
"""Return True if the input is a non-string sequential collection,
False otherwise. Note: dicts and sets are not sequential.
"""
try:
item[0:0]
except (AttributeError, TypeError):
return False
return not isString(item)

def isString(item):
"""Return True if the input is a string-like sequence.
Strings include str, unicode and UserString objects.

From Python Cookbook, 2nd ed.
"""
return isinstance(item, (basestring, UserString.UserString))

def asSequence(item):
"""Converts one or more items to a sequence,
If item is already a non-string-like sequence, returns it unchanged,
else returns [item].
"""
if isSequence(item):
return item
else:
return [item]

I then use asSequence on each argument that can either be one item or a 
sequence of items (so I can always work on a sequence).

-- Russell

P.S. this code is from RO.SeqUtil 

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


Re: Python/Tkinter crash.

2006-10-04 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>,
 "Hendrik van Rooyen" <[EMAIL PROTECTED]> wrote:

>Hi,
>
>I get the following:
>
>[EMAIL PROTECTED]:~/Controller/lib> python display.py
>UpdateStringProc should not be invoked for type font
>Aborted
>...
>Everything seems to work fine. - there is a thread that runs to move the meter
>values around continuously, and this has been stable for some time now, and I
>can get the various "machine" parts to move around the screen by pushing the
>buttons...

You mention threads several times in your posting. Do you have multiple 
threads talking to Tkinter? If so, try recoding to avoid this (e.g. by 
having the background threads communicate with the main thread via 
Queues).

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


  1   2   >