Re: __pycache__, one more good reason to stck with Python 2?

2011-01-21 Thread Steven D'Aprano
On Wed, 19 Jan 2011 14:31:15 -0800, Alice Bevan–McGregor wrote:

> On 2011-01-19 13:01:04 -0800, Steven D'Aprano said:
>> I know I've seen problems executing .pyc files from the shell in the
>> past... perhaps I was conflating details of something else. Ah, I know!
>> 
>> [steve@sylar ~]$ chmod u+x toto.pyc
>> [steve@sylar ~]$ ./toto.pyc
>> : command not found ��
>> ./toto.pyc: line 2: syntax error near unexpected token `(' ./toto.pyc:
>> line 2: `P7Mc@s dGHdS(tfooNs./ toto.pys'
> 
> ... don't do that.  I do not know why that would be expected to work,
> ever.  (Unless you're crafty and wrap a real shell script around the
> .pyc, in which case it's no longer a .pyc.)

I didn't expect it to work, but I have seen others do it and be surprised 
that it doesn't. This is why I was pleasantly surprised to learn that 
`python toto.pyc` does work -- I was conflating the above failure with 
the issue under discussion.



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


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

2011-01-21 Thread Octavian Rasnita
From: "Adam Skutt" > Yet, for some unfathomable reason, 
you keep promoting
I would be glad if you could tell me about a portable solution which is 
accessible with JAWS and Window Eyes, the most used screen readers under 
Windows (real glad).


I did, Qt.  I'm not yournanny and I'm not going to go test it for
you.  There are bugs in the Qt database relating to JAWS
functionality, so it others have plainly gotten it working to some
degree.  But honestly, why should I waste my time replying to you when
you're too damn lazy to even use Google?  I certainly won't be doing
so in the future.  "Lead a ignorant, thirsty horse to water, watch it
die of thirst" and all that.


I have tried more QT-based apps and I couldn't find one to be accessible, 
while most widgets offered by WxPython are accessible out of the box.


QT is really bad, but you hijacked the tread because as you can see even in 
the subject, we are talking about Tkinter, not about QT.


If QT is not included by default in Python, it is not such a big problem 
because only those who care more about the visual aspect than about the 
accessibility use it, but Tkinter is bad because it is promoted and many 
beginners will start using it witout knowing how bad it is and why.


You keep telling that you searched on the web for finding what the others 
say about accessibility but this is a very wrong way. Don't say anything 
about accessibility if you haven't tried personally.


Octavian



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


Re: is it a bug in exec?

2011-01-21 Thread Steven D'Aprano
On Thu, 20 Jan 2011 20:52:15 -0800, longqian9...@gmail.com wrote:

> In pyhton 3.1, I found the following code will succeed with argument 1
> to 4 and fail with argument 5 to 9. It is really strange to me. I
> suspect it may be a buy in exec() function. Does anyone have some idea
> about it? Thanks.

What makes you think it's a bug? Is there anything in the documentation 
of exec that suggests to you that some other behaviour should occur? What 
version of Python are you using?

Without knowing what behaviour you expect and what behaviour you see, how 
are we supposed to know if you've found a bug or not?

I suggest you fire up the interactive interpreter and try this:

t1 = """
class foo:
def fun():
print('foo')

def main():
global foo
foo.fun()

main()
"""

dg = {}
dl = {}

exec(t1, dg, dl)

then inspect the values of dg and dl and see if it helps. If not, write 
back with what you expect to happen, and what you see instead.


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


Re: Part of RFC 822 ignored by email module

2011-01-21 Thread Tim Roberts
Bob Kline  wrote:
>
>I just noticed that the following passage in RFC 822:

For future interest, RFC 822 has LONG since been replaced, first by RFC
2822, then by RFC 5322.  I believe the white space folding requirement is
still there, but something that violates 822 but not 5322 (and there are
several such things) is not all that important.
-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: statement level resumable exception

2011-01-21 Thread ilejn
Arnaud,

it looks like a solution.
Perhaps it is better than plain try/accept and than proxy class with
__getattr__.
It is not for free, e.g. because syntax check such as parentheses
matching is lazy too, though looks
very interesting.

Thanks a lot!

On Jan 21, 10:41 am, Arnaud Delobelle  wrote:
> ilejn  writes:
> > Arnaud,
>
> > these lists are not generated.
>
> > Actually these lists are a sort of interpreted programs and contain
> > some application logic.
>
> > Here is an example
> >         [
> >         [PUSH, [get_modified_interface, req]],
> >         [TIMEOUT, 3],
> >         [PULL, [out_interface, '']],
> >         [PULL, [err_interface, '']],
> >         [PULL, [out_mined_interface, req]],
> >         ]
>
> > If any interface name is unknown the list must not be invoked (in
> > other words, f function
> > call with this list must be somehow bypassed).
>
> > Thanks.
>
> You could still use the same idea and delay evaluation of the lists. E.g.
>
> prg1 = """[
>     [PUSH, [get_modified_interface, req]],
>     [TIMEOUT, 3],
>     ...
> """
>
> prg2 = """[
>     [OPCODE, [arguments, blah]],
>     ...
> """
>
> ...
>
> prgN = """..."""
>
> for prg in prg1, prg2, ..., prgN:
>     try:
>         prg = eval(prg)
>     except NameError:
>         continue
>     f(prg)
>
> --
> Arnaud

Best regards,
Ilja Golshtein
-- 
http://mail.python.org/mailman/listinfo/python-list


Printing RTF file under win32

2011-01-21 Thread Mark Carter
I'm using Python 2.6.5 on win32. I would like to print a batch of RTF
files on a printer. I don't want to use the win32api.ShellExecute
command because that invokes Word, and Word has been configured in a
strange way by one of our admins, making it inconvenient to use.

What should I do?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sending changed parameters into nested generators

2011-01-21 Thread John O'Hagan
On Fri, 21 Jan 2011, cbrown wrote:
> On Nov 12, 10:52 pm, "John O'Hagan"  wrote:
> > On Sat, 13 Nov 2010, Steven D'Aprano wrote:
> > > On Fri, 12 Nov 2010 09:47:26 +, John O'Hagan wrote:
> > > > I have a generator function which takes as arguments another
> > > > generator and a dictionary of other generators like this:
> > > > 
> > > > def modgen(gen, gendict):
> > > > for item in gen():
> > > >   for k, v in gendict:
> > > >   do_something_called_k(item, v.next())
> > > >   
> > > >   yield item
> > > 
> > > [snip]
> > > 
> > > > If anyone's still reading :) , how can I send new values to arbitrary
> > > > sub- generators?
> > > 
> > > I have a headache after reading your problem :(
> > > 
> > > I think it's a good time to point you at the Zen, particularly these
> > > five maxims:
> > > 
> > > Beautiful is better than ugly.
> > > Simple is better than complex.
> > > Complex is better than complicated.
> > > Flat is better than nested.
> > > If the implementation is hard to explain, it's a bad idea.
> > > 
> > > I'm afraid that your nested generators inside another generator idea
> > > fails all of those... it's not elegant (beautiful), it's complicated,
> > > it's nested, and the implementation is hard to explain.
> > > 
> > > You could probably replace generators with full-blown iterators, but I
> > > wonder what you're trying to accomplish that is so complicated that it
> > > needs such complexity to solve it. What are you actually trying to
> > > accomplish? Can you give a simple example of what practical task you
> > > hope to perform? I suspect there's probably a more elegant way to
> > > solve the problem.
> > 
> > I hope there is!
> > 
> > The project not practical but artistic; it's a real-time musical
> > composition program.
> > 
> > A (simplified) description: one module contains number-list generating
> > functions, others contain functions designed to filter and modify the
> > number lists produced, according to various parameters. Each such stream
> > of number lists is assigned a musical meaning (e.g. pitch, rhythm,
> > volume, etc) and they are combined to produce representations of musical 
>>phrases, which are sent to a backend which plays the music 
> >as it is produced, and makes PDF scores.
> 
> >Each such "instrument" runs as a separate thread, so several can play 
>>together in acoordinated fashion.
> > 
> > All the compositional interest lies in the selection of number-list 
>>generators and how their output is modified. For example, if I say "Play 
>>every third note up an octave" it's not very interesting, compared to "Play 
>>every nth note up an interval of m", where n and m vary according to some 
>>pattern. It gets even more interesting when that pattern is a function of x 
>>and y, which also vary according to another pattern, and so on.
> > 
> > To that end, I have each parameter of each modifier set by another
> > generator, such that the value may change with each iteration. This may
> > continue recursively, until at some level we give a parameter a simple
> > value.
> > 
> > That's all working, but I also want it to be interactive. Each thread
> > opens a terminal where new options can be entered, but so far it only 
>>works, as I mentioned, for changing the values in a top-level mutable 
>>object.
> 
> I might first suggest this, although I have some caveats to add:
> 
> def genfilter(evaluator, **param_sources):
> while True:
> params = {}
> for param, gen in param_sources.iteritems():
> params[param] = gen.next()
> yield evaluator(**params)
> 
> You can then do things like:
> >>> def concat(in1, in2):
> >>> return str(in1)+"|"+str(in2)
> >>> 
> >>> a = (i for i in range(1,5))  # generator based on a list
> >>> b = (2*i for i in xrange(1,5))   # 'pure' generator
> >>> c = genfilter(concat, in1=a, in2=b)
[...]
 
> or, more relevant to your original question regarding modifying things
> 
> mid-stream:
> >>> class Mult():
> >>> def __init__(self, multiplier):
> >>> self.mulitplier = multiplier
> >>> 
> >>> def multi(self, val):
> >>> return val*self.multiplier
> >>> 
> >>> m = Mult(2)
> >>> a = (i for i in range(1,10))
> >>> b = (i for i in range(1,10))
> >>> c = genfilter(m.multi, val=b)
> >>> d = genfilter(concat, in1=a, in2=c)
> >>> d.next()
[...]

> But a real problem with this whole strategy is that a generator's
> next() function is called every time it is evaluated. If the
> relationship between your various generators forms a rooted tree,
> that's not a problem, but I would think the relationships form a
> directed acyclic graph, and in that case, you end up 'double
> incrementing' nodes in a way you don't want:
[...]

> To solve that problem, you need a somewhat more complex solution: a
> class that ensures that each previous stage is only invoked once per
> 'pass'. I've got an idea for that, if that is of interest.

Going for the record for pregnant pau

Namespaces

2011-01-21 Thread sl33k_
What is namespace? And what is built-in namespace?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: examples of realistic multiprocessing usage?

2011-01-21 Thread Adam Skutt
On Jan 20, 11:51 pm, Albert van der Horst 
wrote:
> This is what some people want you to believe. Arm twisting by
> GPL-ers when you borrow their ideas? That is really unheard of.

Doesn't matter, you're still legally liable if your work is found to
be derivative and lacking a fair use defense.  It's not borrowing
"ideas" that's problematic, it's proving that's all you did.  For
those of us with legal departments, we have no choice: if they don't
believe we can prove our case, we're not using the code, period.  The
risk simply isn't worth it.

> GPL-ers are not keen on getting the most monetary award by
> setting lawyers on you and go to court only reluctantly to
> enforce the license.

And?  Monetary award is hardly the only issue.

> Stealing code means just that, verbatim copies. When you read this
> carefully, you can see that reimplementing the stolen code is
> an option. Exactly what you say is legally impossible.

No, in the United States it means anything that constitutes a
derivative work, since derivative works of GPL-licensed works must be
released under the GPL.  Merely copying ideas does not make one a
derivative work, but one also must be prepared to show that's all that
happened.  As such, it would have to be a substantially different
implementation, generally with some sort of added or useful value.
Proving that can be difficult and may very well depend on what court
you land in.

>
> So pardon me, but not even looking at code you might learn from
> is pretty hysteric.

Not at all.  Separating ideas from implementation can be difficult,
and convincing a judge of that vastly more so.  It's a legitimate
concern, and people who intend to ship proprietary software should
definitely resort to GPL-licensed software last when looking for
inspiration.

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


Re: getdefaultencoding - how to change this?

2011-01-21 Thread John Pinner
On Jan 20, 4:46 pm, Robert Kern  wrote:



>
> Instead, you want to use an encoding declaration in each file:
>
> http://docs.python.org/reference/lexical_analysis.html#encoding-decla...

All that this does is tell the interpreter how the source file is
encoded, it does not affect default encodings etc.

John
--


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


Re: Namespaces

2011-01-21 Thread Alex Willmer
On Jan 21, 10:39 am, sl33k_  wrote:
> What is namespace? And what is built-in namespace?

A namespace is a container for names, like a directory is a container
for files. Names are the labels we use to refer to python objects
(e.g. int, bool, sys), and each Python object - particularly modules
and classes - provides separate namespace.

The idea of a namespace is to isolate names from one another - so that
if you import module_a and module_b and both have an object called foo
then module_a.foo doesn't interfere with module_b.foo.

The built-in namespace is where the core objects of Python are named.
When you refer to an object such as int Python first searches the
local scope (was it defined in the current function/method, i.e. the
output of locals()), then module scope (was it defined in the
current .py file, i.e. output of globals()) and finally in the object
__builtins__.

Hope that makes sense. I realised as I typed this my understanding of
Python namespaces is not as 100% tight as I thought.

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


Re: Screen readers for Tkinter (was Re: Tkinter: The good, the bad, and the ugly!

2011-01-21 Thread Littlefield, Tyler
>And of course, it should also offer support for Windows, since most of 
the computer users use Windows, especially those who need accessibility 
features.

uh. no, and no.
Plenty of those utilizing screen readers are using macs nowadays, as 
well as vinux or some derivitave there of.


--

Thanks,
Ty

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


Re: getdefaultencoding - how to change this?

2011-01-21 Thread John Pinner
To answer the OP's original question:

On Jan 20, 2:31 pm, Helmut Jarausch  wrote:
> Hi,
> I've searched the net but didn't find the information I need.
> Using Python-2.7.1, I know, I can't modify defaultencoding at run time.

I think you can. There is a function setdefaultencoding in the sys
module, but at startup when site.py runs the function gets deleted
after it has been used, because as others have said it is a *bad* idea
to change the default encoding (although I *think* changing it to utf8
should cause no harm).

so if you reload sys, setdefaultencoding() becomes available again,
and you can use it, with all the caveats mentioned:

import sys
reload(sys)
sys.setdefaultencoding( 'utf-8' )

This works on a Unicode build of Python only.

As has been said, you can change the default encoding in site.py, but
this means that it gets changed for everyone/every Python program on
the system, using setdefaultencoding() as above only changes it for
the running program, and hopefully the change will have been made by
someone who knows what they are doing and is aware of the possible
consequences.

> Python even ignores
> export PYTHONIOENCODING=ISO8859-1
>
> locale.getdefaultlocale()[1]
> returns
> 'ISO8859-1'
>
> still sys.stdout is using the ascii codec.
> How can I recompile Python (itself) to change this to iso8859-1 ?

You don't need to, nor should you.

> (My favourite editor cannot be told to use unicode.)

Maybe you need a new editor. scite works well with Python, and is
cross-platform.

John
--


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


Re: statement level resumable exception

2011-01-21 Thread Jon Clements
On Jan 21, 8:41 am, ilejn  wrote:
> Arnaud,
>
> it looks like a solution.
> Perhaps it is better than plain try/accept and than proxy class with
> __getattr__.
> It is not for free, e.g. because syntax check such as parentheses
> matching is lazy too, though looks
> very interesting.
>
> Thanks a lot!
>
> On Jan 21, 10:41 am, Arnaud Delobelle  wrote:
>
>
>
> > ilejn  writes:
> > > Arnaud,
>
> > > these lists are not generated.
>
> > > Actually these lists are a sort of interpreted programs and contain
> > > some application logic.
>
> > > Here is an example
> > >         [
> > >         [PUSH, [get_modified_interface, req]],
> > >         [TIMEOUT, 3],
> > >         [PULL, [out_interface, '']],
> > >         [PULL, [err_interface, '']],
> > >         [PULL, [out_mined_interface, req]],
> > >         ]
>
> > > If any interface name is unknown the list must not be invoked (in
> > > other words, f function
> > > call with this list must be somehow bypassed).
>
> > > Thanks.
>
> > You could still use the same idea and delay evaluation of the lists. E.g.
>
> > prg1 = """[
> >     [PUSH, [get_modified_interface, req]],
> >     [TIMEOUT, 3],
> >     ...
> > """
>
> > prg2 = """[
> >     [OPCODE, [arguments, blah]],
> >     ...
> > """
>
> > ...
>
> > prgN = """..."""
>
> > for prg in prg1, prg2, ..., prgN:
> >     try:
> >         prg = eval(prg)
> >     except NameError:
> >         continue
> >     f(prg)
>
> > --
> > Arnaud
>
> Best regards,
> Ilja Golshtein

Not sure if a good idea or not, but:

I would probably use pyparsing and create a small grammar to parse
your list data. If parsing an entry with an unknown interface, then
skip to the next list entry. If the entire list parses, then you can
execute your function calls.

hth

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


Re: Namespaces

2011-01-21 Thread Dave Angel

On 01/-10/-28163 02:59 PM, sl33k_ wrote:

What is namespace? And what is built-in namespace?



A namespace is a mapping from names to objects.  When you write a statement
xyz = 42

the system looks up "xyz" in some namespace and associates that 
"variable" with the object int(42).


The key is that there are multiple namespaces defined.  The built-in 
namespace (containing things such as open, help, next, input, and lots 
more) is always available.  The global namespace, for symbols defined 
globally in the current module, is another namespace.  If you're inside 
a function, there's a separate namespace for symbols defined in there 
(and they behave just a little differently).  And you can explicitly 
specify a namespace with a prefix, which is one way you access symbols 
in another module, or within an instance of an object.


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

though I haven't personally studied the whole thing for accuracy.

One other thing:  dir() can be used to show you the names in a 
particular namespace.  For example,  dir(__builtins__) shows you the 
built-in namespace, while dir() shows you the global one.  And after an 
import, dir() can show you those names:

import os
dir(os)

DaveA

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


Re: Namespaces

2011-01-21 Thread Michael Sparks
On Jan 21, 10:39 am, sl33k_  wrote:
> What is namespace? And what is built-in namespace?

tl;dr - Namespaces are sets that contain names. You can think of
namespaces as being /like/ boxes. A namespace is therefore an
organisational tool, forming a similar purpose to human names &
surnames - to identify the right value. (eg "Sparks" is a namespace,
"Smith" is another.) The built-in namespace contains all the values
which python understands which you _don't_ define that don't have dots
in. (eg "int", "True", "None")


Looking at this in more detail...


We can create a simple namespace using an empty class Family:

class Family(object):
   pass

Sparks = Family()
Smith = Family()

Now clearly Sparks is a name, and Smith is a name. Those names are
defined to be two different Family objects/values. (I'm going to
deliberately sidestep which namespace "Sparks" and "Smith" sit inside
for the moment.)

The neat trick is that namespaces are values themselves.

In fact the really neat trick is that every value contains a
namespace.

How do I define a name inside a namespace? Suppose I want to define
the name "Michael" as a person inside the Sparks namespace, I can do
that like this:

class Person(object):
   pass

Sparks.Michael = Person()

I can then define the name Michael inside the Smith namespace as well:

Smith.Michael = Person()

As you can see, I can now refer to two different values with the same
name -  "Michael".

This may look a little like sophistry, so let's suppose the Person
we're referring to as Sparks.Michael has an height of 180cm, and a
favourite colour of green, and Smith.Michael has a height of 120cm and
a favourite colour of 120.

In both cases, it makes sense for use to name the height value
"height", and name the favourite colour value as "favourite_colour".
If we did this though ...

height = 180
favourite_colour = "green"
height = 120
favourite_colour = "purple"

.. python would only remember the most recent value of each. By
recognising that every value is a namespace too, we can define those
names inside their namespace.

Sparks.Michael.height = 180
Sparks.Michael.favourite_colour = "green"
Smith.Michael.height = 120
Smith.Michael.favourite_colour = "purple"

Now the question that might arise is this: Given I can rewrite the
examples above like this...

class Family(object):
   pass

class Person(object):
   pass

Sparks = Family()
Smith = Family()
Sparks_Michael = Person()
Smith_Michael = Person()
Sparks_Michael_height = 180
Sparks_Michael_favourite_colour = "green"
Smith_Michael_height = 120
Smith_Michael_favourite_colour = "purple"

... how is this different from before?

Well in this latter version we're not using namespaces to organise our
names. This means that if I want to write a function that prints a
person's height and favourite colour, it has to look like this:

def describe_person(height, favourite_colour):
   print "The person is", height, "cm tall"
   print "Their favourite colour is", favourite_colour

Then if I want to use this, I have to do this:

describe_person(Sparks_Michael_height,
Sparks_Michael_favourite_colour)
describe_person(Smith_Michael_height, Smith_Michael_favourite_colour)

That's quite messy.

What does it look like for the namespace version?

def describe_person(somePerson):
   print "The person is", somePerson.height, "cm tall"
   print "Their favourite colour is", somePerson.favourite_colour

describe_person(Sparks.Michael)
describe_person(Smith.Michael)

describe_person now expects to recieve a single value. Inside that
value's namespace it expects to find the values "height" and "colour",
and just uses them.

As a result, when we use it, rather than passing in each low level
attribute (height, colour) we can work at a more convenient level of
working with People, and the higher level code becomes clearer.

Not only this, if we decide to add an another name to both People ...

Sparks.Michael.Pythonista = True
Sparks.Michael.Pythonista = False

... we can change describe_person to use this:


def describe_person(somePerson):
   print "The person is", somePerson.height, "cm tall"
   print "Their favourite colour is", somePerson.favourite_colour
   if somePerson.Pythonista:
  print "And they like python!"
   else:
  print "They don't know python"

Then our code for describing them remains the same:

describe_person(Sparks.Michael)
describe_person(Smith.Michael)

So far so good I hope.

Namespaces can contain code as well as basic values.

This means we can have ...

tiggles = Cat()
rover = Dog()
jemima = Duck()

tiggles.name = "tiggles"
rover.name = "rover"
jemima.name = "jemima"

... and we can get them all to have some behaviour called "make_noise"
defined by the call to Cat(), Dog(), Duck() inside their namespace,
which allows us to write:

>>> tiggles.make_noise()
Meow!
>>> rover.make_noise()
Woof!
>>> jemima.make_noise()
Quack!

And again that means we can do things like:

def describe_animal(animal):
print animal.name, "goes", animal.ma

Re: examples of realistic multiprocessing usage?

2011-01-21 Thread Adam Tauno Williams
On Fri, 2011-01-21 at 03:20 -0800, Adam Skutt wrote: 
> On Jan 20, 11:51 pm, Albert van der Horst 
> wrote:
> > This is what some people want you to believe. Arm twisting by
> > GPL-ers when you borrow their ideas? That is really unheard of.
> Doesn't matter, you're still legally liable if your work is found to
> be derivative and lacking a fair use defense.  It's not borrowing
> "ideas" that's problematic, it's proving that's all you did.  For
> those of us with legal departments, we have no choice: if they don't
> believe we can prove our case, we're not using the code, period.  The
> risk simply isn't worth it.

+1, exactly.  "reimplementation" is the defense of GPL is very often
treated as *trivial*.  Changing function names and variable names and
indenting style is not "reimplementation".  Reimplementation can be very
difficult, time consuming, and error-prone.

Anyway, legally define: "reimplementation".  Have fun.

> > So pardon me, but not even looking at code you might learn from
> > is pretty hysteric.
> Not at all.  Separating ideas from implementation can be difficult,

Honestly, IMNSHO, it is borders on *impossible*.  Even statistical
analysis of written prose or off-hand speech will reveal how
pathologically derivative humans are in their use of language.  And as
that language gets forcibly more structured as in programming or
technical documentation even more so.

> and convincing a judge of that vastly more so.  It's a legitimate
> concern, and people who intend to ship proprietary software should
> definitely resort to GPL-licensed software last when looking for
> inspiration.

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


Problems with FTP

2011-01-21 Thread RizlaJ
Hi all, I'm very new to python. I'm using Python 2.7, in a corporate
environment, therefore am behind a proxy server, firewalls etc.

I can ftp to a barclays capital ftp site ok in internet explorer, but
I can't get the FTP from ftplib to work for me. Can someone please
help!

I've tried the following commands from my home personal machine
(thefore no proxies etc) and the commands work fine and I'm able to
enter my username and password and login successfuly - however in teh
corporate environment I can't. I'm wondering if this is soemthing to
do with security permissioning at work etc?

At the shell I'm typing:-
>>> from ftplib import FTP
>>> ftp = FTP('indexftp.barcap.com')

and get the following error:
Traceback (most recent call last):
  File "", line 1, in 
ftp = FTP('indexftp.barcap.com')
  File "C:\Python27\lib\ftplib.py", line 117, in __init__
self.connect(host)
  File "C:\Python27\lib\ftplib.py", line 132, in connect
self.sock = socket.create_connection((self.host, self.port),
self.timeout)
  File "C:\Python27\lib\socket.py", line 571, in create_connection
raise err
error: [Errno 10060] A connection attempt failed because the connected
party did not properly respond after a period of time, or established
connection failed because connected host has failed to respond

I wasn't expecting this error message next, i was expecting to be able
to log on using the followign command :-

>> ftp.login("username","password")

Please help!

thanks!

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


Re: Need advices for mysqldb connection best practice

2011-01-21 Thread Romaric DEFAUX

Le 20/01/2011 18:58, Dennis Lee Bieber a écrit :

On Thu, 20 Jan 2011 10:04:12 +0100, Romaric DEFAUX
declaimed the following in gmane.comp.python.general:



So , I thought about some solutions :
- restarting the server every sometimes (but it's the worst solution in
my mind)
- creating a connection (not only cursor) at each client connection (but
I'm afraid it overloads the mysql server)
- trying to find where I did a mistake, and correct the bug (that why
I'm doing by writing this list :), or send me a link that could help me
(before writing I googled for one hour and found nothing interresting in
my case...)


Do you have multiple clients active at the same time -- using a
common code/process... (does each client connection start a thread)?


import MySQLdb
MySQLdb.threadsafety

1
> From PEP 249:
"""
 threadsafety

 Integer constant stating the level of thread safety the
 interface supports. Possible values are:

 0 Threads may not share the module.
 1 Threads may share the module, but not connections.
 2 Threads may share the module and connections.
 3 Threads may share the module, connections and
   cursors.

 Sharing in the above context means that two threads may
 use a resource without wrapping it using a mutex semaphore
 to implement resource locking. Note that you cannot always
 make external resources thread safe by managing access
 using a mutex: the resource may rely on global variables
 or other external sources that are beyond your control.

"""


Also:


  con.cursor().execute('SET AUTOCOMMIT=1')

Using .execute() for that may set the MySQL side for autocommit, but
the MySQLdb adapter will likely still be in the db-api specified mode of
NO autocommit. There is a low-level (that is, it is part of the DLL/SO
and not Python source) function for connections:

con.autocommit(True)

(the db-api creates connections and invokes con.autocommit(False))

This function should both set MySQL AND the db-api adapter for
autocommit operations.

Personally -- it is better when running multiple clients to ensure
that each client is running as a complete transaction. That means the
each get their own connection and cursor(s), and manually do
con.commit() at the end of the transaction; if any errors happen, one
does a con.rollback() and can inform the user that the sequence failed.

Thanks Dennis for your reply.
I don't use thread. The reason is :
- the time of connection between client and server is really quick, 
around one second
- I've only around 120 clients, updating once an hour, so percent of 
collision is really low, and client can wait few seconds for the connection


Now, I create a new db_connection at each client connection and it seems 
stable (no crash since yesterday vs 1 crash every 2 hours before).
I understand why it's better to commit manually, but if I want to do 
that I have to rewrite lots of things, and it's not my priority at this 
time, because it's stable enough. So I kept the con.autocommit(True).

But I keep your advices in an "improvements list" :)
I know if number of clients increase a lot, I can search in these 
directions :

- using thread
- commiting manually to avoid inconsistents datas
- using a pool of connections to reduce MySQL load

Thanks again

Romaric





smime.p7s
Description: S/MIME Cryptographic Signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Dealing with xml namespaces with ElementTree

2011-01-21 Thread Neil Cerutti
I have to parse many xml documents that senselessly(?) specify a
single namespace for the whole document. After a couple of years,
my approach has boiled down to the following three little
helpers, for use with ElementTree:

def insert_namespace(xpath):
# Enable *simple* xpath searches by inserting the fscking namespace.
return '/'.join('{{{}}}{}'.format(XMLNS, n) for n in xpath.split('/'))

def find(et, xpath):
return et.find(insert_namespace(xpath))

def findall(et, xpath):
return et.findall(insert_namespace(xpath))

Instead of writing, e.g.,
et.find('{{0}}ab/{{0}}cd'.format(XMLNS), et al, I can use
find(et, 'ab/cd').

Is there a better ElemenTree based approach I'm missing out on?
And on the other hand, am I circumventing something important, or
inviting bad limitations of some kind?

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


Re: Screen readers for Tkinter (was Re: Tkinter: The good, the bad, and the ugly!

2011-01-21 Thread Arndt Roger Schneider

Littlefield, Tyler schrieb:
 >And of course, it should also offer support for Windows, since most of 
the computer users use Windows, especially those who need accessibility 
features.

uh. no, and no.
Plenty of those utilizing screen readers are using macs nowadays, as 
well as vinux or some derivitave there of.



Do you have first hand experience with it under AQUA?
I think Tk-aqua (also 8.6) should work out-of-the-box
with brail-lines, text-to-speech and such;
the older carbon built however wont...

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


Re: is it a bug in exec?

2011-01-21 Thread long
Of cause your code runs well. But if you remove the "global foo" in
main(), it will fail. And it will succeed again if you call exec(t1)
directly. I think this behavior is strange. Even I pass a shadow copy
of globals and locals to exec, it still fails. So perhaps there is a
basic difference between exec(t1,dg,dl) and
exec(t1,globals(),locals()). What do you think about it? Thanks.


On Jan 21, 2:14 am, Steven D'Aprano  wrote:
> On Thu, 20 Jan 2011 20:52:15 -0800, longqian9...@gmail.com wrote:
> > In pyhton 3.1, I found the following code will succeed with argument 1
> > to 4 and fail with argument 5 to 9. It is really strange to me. I
> > suspect it may be a buy in exec() function. Does anyone have some idea
> > about it? Thanks.
>
> What makes you think it's a bug? Is there anything in the documentation
> of exec that suggests to you that some other behaviour should occur? What
> version of Python are you using?
>
> Without knowing what behaviour you expect and what behaviour you see, how
> are we supposed to know if you've found a bug or not?
>
> I suggest you fire up the interactive interpreter and try this:
>
> t1 = """
> class foo:
>     def fun():
>         print('foo')
>
> def main():
>     global foo
>     foo.fun()
>
> main()
> """
>
> dg = {}
> dl = {}
>
> exec(t1, dg, dl)
>
> then inspect the values of dg and dl and see if it helps. If not, write
> back with what you expect to happen, and what you see instead.
>
> --
> Steven

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


Line breaks in list causing a small formatting problem while joining the list

2011-01-21 Thread Oltmans
Hi Python gurus, hope you're doing well. I've a small problem.

When I run the following code
___
>>> names = ['oltmans','abramhovic','\n','sal','lee']
>>> print '| ' + ' | '.join(names)
| oltmans | abramhovic |
 | sal | lee
___

I get the output like above. However, I want it to output like below

| oltmans | abramhovic |
| sal | lee


That is, there shouldn't be a space in the beginning of second line.
The list can of course contain more than 5 elements. Any ideas? I will
appreciate any hint. Thanks in advance.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Line breaks in list causing a small formatting problem while joining the list

2011-01-21 Thread Peter Otten
Oltmans wrote:

> Hi Python gurus, hope you're doing well. I've a small problem.
> 
> When I run the following code
> ___
 names = ['oltmans','abramhovic','\n','sal','lee']
 print '| ' + ' | '.join(names)
> | oltmans | abramhovic |
>  | sal | lee
> ___
> 
> I get the output like above. However, I want it to output like below
> 
> | oltmans | abramhovic |
> | sal | lee
> 
> 
> That is, there shouldn't be a space in the beginning of second line.
> The list can of course contain more than 5 elements. Any ideas? I will
> appreciate any hint. Thanks in advance.

>>> print "|%s|" % "|".join(n if n == "\n" else " %s " % n for n in names)
| oltmans | abramhovic |
| sal | lee |

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


Re: getdefaultencoding - how to change this?

2011-01-21 Thread Robert Kern

On 1/21/11 5:43 AM, John Pinner wrote:

On Jan 20, 4:46 pm, Robert Kern  wrote:





Instead, you want to use an encoding declaration in each file:

http://docs.python.org/reference/lexical_analysis.html#encoding-decla...


All that this does is tell the interpreter how the source file is
encoded, it does not affect default encodings etc.


Yes! In the part of the OP's message that you snipped "(My favourite editor 
cannot be told to use unicode.)", that seemed to be part of his actual problem, 
not the default encoding.


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

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


Re: is it a bug in exec?

2011-01-21 Thread Peter Otten
longqian9...@gmail.com wrote:

> In pyhton 3.1, I found the following code will succeed with argument 1
> to 4 and fail with argument 5 to 9. It is really strange to me. I
> suspect it may be a buy in exec() function. Does anyone have some idea
> about it? Thanks.
> 
> 
> t1="""
> class foo:
> def fun():
> print('foo')
> def main():
> global foo
> foo.fun()
> main()
> """
> t2="""
> class foo:
> def fun():
> print('foo')
> def main():
> foo.fun()
> main()
> """
> 
> import sys
> import copy
> if sys.argv[1]=='1':
> exec(t1)
> elif sys.argv[1]=='2':
> exec(t2)
> elif sys.argv[1]=='3':
> exec(t1,{},{})
> elif sys.argv[1]=='4':
> exec(t2,globals(),locals())
> elif sys.argv[1]=='5':
> exec(t2,{},{})
> elif sys.argv[1]=='6':
> exec(t2,globals(),{})
> elif sys.argv[1]=='7':
> exec(t2,{},locals())
> elif sys.argv[1]=='8':
> exec(t2,copy.copy(globals()),locals())
> elif sys.argv[1]=='9':
> exec(t2,globals(),copy.copy(locals()))

There are only two cases that matter: identical local/global namespaces and 
distinct local/global namespaces:

>>> code = """\
... x = 42 # put x into the local namespace
... def f():
... print(x) # look up x in the global namespace
... f()
... """
>>> exec(code, {}, {})
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 4, in 
  File "", line 3, in f
NameError: global name 'x' is not defined
>>> ns = {}
>>> exec(code, ns, ns)
42

Also note that

>>> globals() is locals()
True

on the module level.

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


Re: Problems with FTP

2011-01-21 Thread Thomas Jollans
On Friday 21 January 2011, it occurred to RizlaJ to exclaim:
> Hi all, I'm very new to python. I'm using Python 2.7, in a corporate
> environment, therefore am behind a proxy server, firewalls etc.
> 
> I can ftp to a barclays capital ftp site ok in internet explorer, but
> I can't get the FTP from ftplib to work for me. Can someone please
> help!

It sounds very much like, as you said, you're behind a proxy, and have to use 
that proxy to connect to the FTP server. If you don't know the proxy settings, 
you might be able to find them in the IE configuration, or ask the local 
sysadmin.

http://stackoverflow.com/questions/1293518/proxies-in-python-ftp-application

It looks like you will have to ftp to the proxy server. Depending on the 
application, you might be able to use urllib2 instead.

Thomas

> 
> I've tried the following commands from my home personal machine
> (thefore no proxies etc) and the commands work fine and I'm able to
> enter my username and password and login successfuly - however in teh
> corporate environment I can't. I'm wondering if this is soemthing to
> do with security permissioning at work etc?
> 
> At the shell I'm typing:-
> 
> >>> from ftplib import FTP
> >>> ftp = FTP('indexftp.barcap.com')
> 
> and get the following error:
> Traceback (most recent call last):
>   File "", line 1, in 
> ftp = FTP('indexftp.barcap.com')
>   File "C:\Python27\lib\ftplib.py", line 117, in __init__
> self.connect(host)
>   File "C:\Python27\lib\ftplib.py", line 132, in connect
> self.sock = socket.create_connection((self.host, self.port),
> self.timeout)
>   File "C:\Python27\lib\socket.py", line 571, in create_connection
> raise err
> error: [Errno 10060] A connection attempt failed because the connected
> party did not properly respond after a period of time, or established
> connection failed because connected host has failed to respond
> 
> I wasn't expecting this error message next, i was expecting to be able
> to log on using the followign command :-
> 
> >> ftp.login("username","password")
> 
> Please help!
> 
> thanks!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: difference between python and matlab

2011-01-21 Thread Thomas Jollans
On Thursday 20 January 2011, it occurred to lakshmi to exclaim:
> Is the programming related to image processing in python is advantageous or
> else in MATLAB

Tell us what you want to do, and what you know about doing this in Python and 
in MATLAB, if possible, ask a specific question. Then, somebody might be able 
to give you an educated and useful response.
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2011-01-21 Thread rantingrick
On Jan 20, 8:34 pm, Neil Hodgson  wrote:


This is exactly what Aristotle meant when he said...


""" Tolerance and Apathy are the last virtues of a dying society! """

Specifically no one here has the nerve to question/argue Guido when he
offers such weak arguments like the "tag" argument. Can you really
base the worth of any library on such a limited argument. I would bet
that most people who use Tkinter ARE NOT using the canvas anyway. They
are not interested in drawing simple lines and rects and just looking
at them. No. They are intersted in creating GUIs with frames, buttons,
labels, radiobuttons, checkbuttons, listboxes, textboxes, notebooks,
comboboxes, and dialogs just to name a few.

However in light of such a weak argument presented TEN YEARS AGO not
one person dared to even question the BDFL. If i were Guido i would be
disappointed. The very community he has built has degenerated into
mindless goose stepping "yes" men. AND THAT WAS TEN YEARS AGO!

Congratulations "yes men" you are the genesis of this self
destruction. I think i should find a fiddle...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Printing RTF file under win32

2011-01-21 Thread Chris Rebert
On Fri, Jan 21, 2011 at 2:12 AM, Mark Carter  wrote:
> I'm using Python 2.6.5 on win32. I would like to print a batch of RTF
> files on a printer. I don't want to use the win32api.ShellExecute
> command because that invokes Word, and Word has been configured in a
> strange way by one of our admins, making it inconvenient to use.
>
> What should I do?

Invoke WordPad instead?
http://en.wikipedia.org/wiki/WordPad

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


Re: difference between python and matlab

2011-01-21 Thread Andrea Ambu
On 20 January 2011 15:16, lakshmi  wrote:
> Is the programming related to image processing in python is advantageous or 
> else in MATLAB
>

Matlab comes with a lot of builtins for image processing, pattern
recognition and many other engineering-related things. If it's just a
quick hack and you're familiar with matlab probably you'd get the job
done more easily with it.

But Thomas is right, it depends a lot on what you really need to do.

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


Re: Printing RTF file under win32

2011-01-21 Thread Michel Claveau - MVP
Hi!

Try this line:
"C:\Program Files\Windows NT\Accessories\wordpad.exe" /p D:\data\fil.rtf
(change the path if you have a windows 64 bits)

@-salutations
-- 
Michel Claveau 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Line breaks in list causing a small formatting problem while joining the list

2011-01-21 Thread MRAB

On 21/01/2011 16:25, Peter Otten wrote:

Oltmans wrote:


Hi Python gurus, hope you're doing well. I've a small problem.

When I run the following code
___

names = ['oltmans','abramhovic','\n','sal','lee']
print '| ' + ' | '.join(names)

| oltmans | abramhovic |
  | sal | lee
___

I get the output like above. However, I want it to output like below

| oltmans | abramhovic |
| sal | lee


That is, there shouldn't be a space in the beginning of second line.
The list can of course contain more than 5 elements. Any ideas? I will
appreciate any hint. Thanks in advance.



print "|%s|" % "|".join(n if n == "\n" else " %s " % n for n in names)

| oltmans | abramhovic |
| sal | lee |


Or:

print ('| ' + ' | '.join(names)).replace("\n ", "\n")
--
http://mail.python.org/mailman/listinfo/python-list


Re: Problems with FTP

2011-01-21 Thread Giampaolo Rodolà
The solution proposed on stackoverflow:

from ftplib import FTP
site = FTP('my_proxy')
site.set_debuglevel(1)
msg = site.login('anonymous at ftp.download.com', 'password')
site.cwd('/pub')

...can not work.
The "anonymous at ftp.download.com" part is pure fiction.
Nothing like that has ever been mentioned in any RFC or
implemented/supported by any server, as far as I know.
I'd say the only way to proxy FTP is by using a SOCKS proxy.
By looking at the error message it's likely that the company firewall
is just blocking the FTP traffic.


--- Giampaolo
http://code.google.com/p/pyftpdlib/
http://code.google.com/p/psutil/



2011/1/21 Thomas Jollans :
> On Friday 21 January 2011, it occurred to RizlaJ to exclaim:
>> Hi all, I'm very new to python. I'm using Python 2.7, in a corporate
>> environment, therefore am behind a proxy server, firewalls etc.
>>
>> I can ftp to a barclays capital ftp site ok in internet explorer, but
>> I can't get the FTP from ftplib to work for me. Can someone please
>> help!
>
> It sounds very much like, as you said, you're behind a proxy, and have to use
> that proxy to connect to the FTP server. If you don't know the proxy settings,
> you might be able to find them in the IE configuration, or ask the local
> sysadmin.
>
> http://stackoverflow.com/questions/1293518/proxies-in-python-ftp-application
>
> It looks like you will have to ftp to the proxy server. Depending on the
> application, you might be able to use urllib2 instead.
>
> Thomas
>
>>
>> I've tried the following commands from my home personal machine
>> (thefore no proxies etc) and the commands work fine and I'm able to
>> enter my username and password and login successfuly - however in teh
>> corporate environment I can't. I'm wondering if this is soemthing to
>> do with security permissioning at work etc?
>>
>> At the shell I'm typing:-
>>
>> >>> from ftplib import FTP
>> >>> ftp = FTP('indexftp.barcap.com')
>>
>> and get the following error:
>> Traceback (most recent call last):
>>   File "", line 1, in 
>>     ftp = FTP('indexftp.barcap.com')
>>   File "C:\Python27\lib\ftplib.py", line 117, in __init__
>>     self.connect(host)
>>   File "C:\Python27\lib\ftplib.py", line 132, in connect
>>     self.sock = socket.create_connection((self.host, self.port),
>> self.timeout)
>>   File "C:\Python27\lib\socket.py", line 571, in create_connection
>>     raise err
>> error: [Errno 10060] A connection attempt failed because the connected
>> party did not properly respond after a period of time, or established
>> connection failed because connected host has failed to respond
>>
>> I wasn't expecting this error message next, i was expecting to be able
>> to log on using the followign command :-
>>
>> >> ftp.login("username","password")
>>
>> Please help!
>>
>> thanks!
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


PEP8, line continuations and string formatting operations

2011-01-21 Thread Gerald Britton
Style question:

PEP 8 suggests that line continuations be done by enclosing
expressions in parentheses rather than using the line continuation
character.  In the same paragraph, it states a preference to put
binary operators at the end of the line to be continued, so:

x = (a +
   b)

is preferred over:

x = (a
   + b)

Fair enough.

What about string formatting operations (old style) though?  The %
symbols is a binary operator between a string and the substitution
values.  Strictly reading PEP 8 leads to:

my_string = ("A long string with %s substitutions that %s the line
should be %s." %
   ("many", "suggest", "continued")
  )

However, I often see the % on the continued line, immediately
preceding the substitution variables, like this:

my_string = ("A long string with %s substitutions that %s the line
should be %s."
   % ("many", "suggest", "continued")
  )

This goes against the PEP 8 guidelines, but I prefer it since it makes
the substitution variables "jump out" a bit more -- at least to me.

Sowhat's the general feeling about this? Adhere to the PEP 8
binary operators style, or modify it for string formatting?


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


Re: Problems with FTP

2011-01-21 Thread RizlaJ
Hi Tom, Giampaolo,

Thank you both for your swift replies. I have asked our IT dept to see
if it is the firewall that is blocking the FTP. They are working on
that side of things.

However I would have thought that the following or some version of it
would have worked:-

>>> import urllib
>>> proxies = ({'ftp':proxyserveraddress'})
>>> some_url = ({'ftp':'indexftp.barcap.com'})
>>> filehandle = urllib.urlopen(some_url, proxies=proxies)

Traceback (most recent call last):
  File "", line 1, in 
filehandle = urllib.urlopen(some_url, proxies=proxies)
  File "C:\Python27\lib\urllib.py", line 84, in urlopen
return opener.open(url)
  File "C:\Python27\lib\urllib.py", line 177, in open
fullurl = unwrap(toBytes(fullurl))
  File "C:\Python27\lib\urllib.py", line 1026, in unwrap
url = url.strip()
AttributeError: 'dict' object has no attribute 'strip'

However as you can see there is an error - is this again related to
the firewall do you think?

Sorry for asking stupid questions! and thank you for your help in
advance.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problems with FTP

2011-01-21 Thread Benjamin Kaplan
On Fri, Jan 21, 2011 at 3:01 PM, RizlaJ  wrote:
> Hi Tom, Giampaolo,
>
> Thank you both for your swift replies. I have asked our IT dept to see
> if it is the firewall that is blocking the FTP. They are working on
> that side of things.
>
> However I would have thought that the following or some version of it
> would have worked:-
>
 import urllib
 proxies = ({'ftp':proxyserveraddress'})
 some_url = ({'ftp':'indexftp.barcap.com'})
 filehandle = urllib.urlopen(some_url, proxies=proxies)
>
> Traceback (most recent call last):
>  File "", line 1, in 
>    filehandle = urllib.urlopen(some_url, proxies=proxies)
>  File "C:\Python27\lib\urllib.py", line 84, in urlopen
>    return opener.open(url)
>  File "C:\Python27\lib\urllib.py", line 177, in open
>    fullurl = unwrap(toBytes(fullurl))
>  File "C:\Python27\lib\urllib.py", line 1026, in unwrap
>    url = url.strip()
> AttributeError: 'dict' object has no attribute 'strip'
>
> However as you can see there is an error - is this again related to
> the firewall do you think?
>
> Sorry for asking stupid questions! and thank you for your help in
> advance.


The one has nothing to do with a firewall. It's telling you that the
function is trying to call url.strip(). But url is a dict object which
doesn't have a strip method. Which should tell you that some_url is
being constructed incorrectly- it's supposed to be a string.

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


Re: Problems with FTP

2011-01-21 Thread Giampaolo Rodolà
The standard FTP protocol does not supporty any kind of proxy-ing
feature natively.
The only closest thing to the concept of a "proxy" we can find in the
FTP protocol is the site-to-site transfer feature:
http://code.google.com/p/pyftpdlib/wiki/FAQ#What_is_FXP?
...but it's something different.

By taking a look at your code, though, this is out of question anyway
since you can't even connect to the server, let alone send proxy-like
(non-standard) commands.
I'd focus on investigating whether it's something with the internal
network and forget about proxy-related problems since from here I can
connect to indexftp.barcap.com.
As for urllib's proxy option I'd say it's only valid for HTTP protocol.

--- Giampaolo
http://code.google.com/p/pyftpdlib/
http://code.google.com/p/psutil/


2011/1/21 RizlaJ :
> Hi Tom, Giampaolo,
>
> Thank you both for your swift replies. I have asked our IT dept to see
> if it is the firewall that is blocking the FTP. They are working on
> that side of things.
>
> However I would have thought that the following or some version of it
> would have worked:-
>
 import urllib
 proxies = ({'ftp':proxyserveraddress'})
 some_url = ({'ftp':'indexftp.barcap.com'})
 filehandle = urllib.urlopen(some_url, proxies=proxies)
>
> Traceback (most recent call last):
>  File "", line 1, in 
>    filehandle = urllib.urlopen(some_url, proxies=proxies)
>  File "C:\Python27\lib\urllib.py", line 84, in urlopen
>    return opener.open(url)
>  File "C:\Python27\lib\urllib.py", line 177, in open
>    fullurl = unwrap(toBytes(fullurl))
>  File "C:\Python27\lib\urllib.py", line 1026, in unwrap
>    url = url.strip()
> AttributeError: 'dict' object has no attribute 'strip'
>
> However as you can see there is an error - is this again related to
> the firewall do you think?
>
> Sorry for asking stupid questions! and thank you for your help in
> advance.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problems with FTP

2011-01-21 Thread RizlaJ
Thanks Giampaolo, Benjamin for your responses. You are correct, if I
can connect to the ftp site from home and you can connect too then the
problem (as you state) lies at the firewall or some security issue.

Thanks for your detailed responses, they've been very helpful to me.
Kind Regards
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: examples of realistic multiprocessing usage?

2011-01-21 Thread Dan Stromberg
On Fri, Jan 21, 2011 at 3:20 AM, Adam Skutt  wrote:
> On Jan 20, 11:51 pm, Albert van der Horst 
> wrote:
>> This is what some people want you to believe. Arm twisting by
>> GPL-ers when you borrow their ideas? That is really unheard of.
>
> Doesn't matter, you're still legally liable if your work is found to
> be derivative and lacking a fair use defense.  It's not borrowing
> "ideas" that's problematic, it's proving that's all you did.  For
> those of us with legal departments, we have no choice: if they don't
> believe we can prove our case, we're not using the code, period.  The
> risk simply isn't worth it.

Many legal departments have an overblown sense of risk, I'm afraid.
And I suppose that's somewhat natural, as it's mostly the legal people
who are putting their necks on the line over such issues - though I
wouldn't be surprised to see a disciplinary action or even firing of a
techie over same.

I worked at DATAllegro when it was acquired by Microsoft.  The
DATAllegro product had significant portions that were opensource code;
Microsoft, of course, decided that they needed to "quarantine"
(meaning "eliminate", in a weird, half-way sense) the opensource
portions.

Why did Microsoft do this?  Why knowingly go through with the purchase
of a product that had large opensource parts?  Why was what they did
considered "enough" as part of a complex due diligence process, to
satisfy even Microsoft's copyright-extensionist lawyers?

When I say "copyright extensionist", I mean:
1) Their legal department once told me that a small python module
could not just be rewritten under a different license, legally,
because a small module could not be made different enough to avoid
issues.
2) Their onboarding process literally said "don't look at example code
in programming books - it entails a legal risk for the company."

What made them think DATAllegro's purchase price was still worth it,
despite this perspective on copyright?

I don't know; I have no first-hand knowledge of that process, though
ironically I did help quarantine the "offending" code.  But obviously
Microsoft management, their board and their lawyers felt it was worth
the risk at the price.  I know it had something to do with contracting
out to a 3rd party company to assess the risk and ascertain what
portions "required" excising.

Here's one such company: http://www.blackducksoftware.com/black-duck-suite
A former coworker (not of Microsoft) suggested they were the only
company in this business.  I believe Black Duck has software that
automatically detects opensource code in a body of work.

IOW, it's quite possible to demonstrate that something isn't a
derivative work, enough so to make even Microsoft's lawyers happy,
given adequate funding for the purpose.

So yeah, sometimes a programmer peeking at opensource code might be
more of a risk (== expense) than a closed-source company is willing to
take, but so might studying a book intended to help you learn
programming.  And how many programmers haven't studied a programming
book at some time in their life?

My intuition tells me (I'm not going into details - that feels too
dangerous to me personally) that part of the issue Microsoft was
trying to prevent, wasn't so much a matter of copyright safety, as
trying to avoid being called hypocritical; they've made a lot of noise
about how dangerous opensource is.  If they then turn around and
distribute opensource code artifacts as part of a Microsoft product,
then they'll probably eventually get beaten up in the tech press yet
again over the new matter.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP8, line continuations and string formatting operations

2011-01-21 Thread Chris Rebert
On Fri, Jan 21, 2011 at 11:53 AM, Gerald Britton
 wrote:
> Style question:
>
> PEP 8 suggests that line continuations be done by enclosing
> expressions in parentheses rather than using the line continuation
> character.  In the same paragraph, it states a preference to put
> binary operators at the end of the line to be continued, so:
>
> x = (a +
>       b)
>
> is preferred over:
>
> x = (a
>       + b)
>
> Fair enough.
>
> What about string formatting operations (old style) though?

Fair warning: They're deprecated and liable to possibly be removed:
http://docs.python.org/dev/library/stdtypes.html#old-string-formatting-operations

> The %
> symbols is a binary operator between a string and the substitution
> values.  Strictly reading PEP 8 leads to:
>
> my_string = ("A long string with %s substitutions that %s the line
> should be %s." %
>                   ("many", "suggest", "continued")
>                  )
>
> However, I often see the % on the continued line, immediately
> preceding the substitution variables, like this:
>
> my_string = ("A long string with %s substitutions that %s the line
> should be %s."
>                   % ("many", "suggest", "continued")
>                  )
>
> This goes against the PEP 8 guidelines, but I prefer it since it makes
> the substitution variables "jump out" a bit more -- at least to me.

Remember that PEP 8 itself says:
"A Foolish Consistency is the Hobgoblin of Little Minds
  [...]
  But most importantly: know when to be inconsistent -- sometimes the style
  guide just doesn't apply.  When in doubt, use your best judgment.  Look
  at other examples and decide what looks best."

i.e. Generally, don't read PEP 8 super-strictly.

FWIW, your style seems reasonable and slightly preferable to me.

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP8, line continuations and string formatting operations

2011-01-21 Thread Tim Chase

On 01/21/2011 01:53 PM, Gerald Britton wrote:

What about string formatting operations (old style) though?  The %
symbols is a binary operator between a string and the substitution
values.  Strictly reading PEP 8 leads to:

my_string = ("A long string with %s substitutions that %s the line
should be %s." %
("many", "suggest", "continued")
   )


Depending on whether I have one item to map or multiple, I either 
bite the bullet and leave them all on one line:


  my_string = "A long string with only one %s substitution in 
it" % adjective


if it's one substitution and the string is particularly long, 
I'll occasionally break the string itself:


  my_string = ("A long string with only one %s "
   "substitution in it that suggests "
   "being broken with a newline") % adjective

For multiple parameters (a tuple), I'll usually cram both the "%" 
and the "(" on the same line:


  my_string = "A long %s with %s substitution%s in it" % (
"sentence",
"several",
"s", # plural
)

which makes it a little easier to see all my parameters. 
Finally, a combination of the *really* long string and multiple 
parameters, I usually use a secondary variable for readability, 
something like


  fmt_string = (
"this is a %s %s with %s substitution%s in it "
"and it extends over several %s"
)
  my_string = fmt_string % (
"long",
"string",
"multiple",
"s", # plural
"lines",
)

I like to have the parameters on their own line (and a trailing 
comma) because it makes my diffs uncluttered when things are 
added/removed.


That's just my own personal taste -- I too am interested in the 
perspectives of others on the list.


-tkc



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


Re: examples of realistic multiprocessing usage?

2011-01-21 Thread Philip Semanchuk

On Jan 21, 2011, at 3:36 PM, Dan Stromberg wrote:

> On Fri, Jan 21, 2011 at 3:20 AM, Adam Skutt  wrote:
>> On Jan 20, 11:51 pm, Albert van der Horst 
>> wrote:
>>> This is what some people want you to believe. Arm twisting by
>>> GPL-ers when you borrow their ideas? That is really unheard of.
>> 
>> Doesn't matter, you're still legally liable if your work is found to
>> be derivative and lacking a fair use defense.  It's not borrowing
>> "ideas" that's problematic, it's proving that's all you did.  For
>> those of us with legal departments, we have no choice: if they don't
>> believe we can prove our case, we're not using the code, period.  The
>> risk simply isn't worth it.
> 
> Many legal departments have an overblown sense of risk, I'm afraid.

I carefully avoid GPLed code on our BSD-licensed project not because I need 
fear anyone's legal department, but out of respect for the author(s) of the 
GPL-ed code. The way I see it, the author of GPL-ed code gives away something 
valuable and asks for just one thing in return: respect the license. It strikes 
me as very selfish to deny them the one thing they ask for. 

JMHO,
Philip
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Line breaks in list causing a small formatting problem while joining the list

2011-01-21 Thread GrayShark
On Fri, 21 Jan 2011 07:39:26 -0800, Oltmans wrote:

> Hi Python gurus, hope you're doing well. I've a small problem.
> 
> When I run the following code
> ___
 names = ['oltmans','abramhovic','\n','sal','lee'] print '| ' + ' |
 '.join(names)
> | oltmans | abramhovic |
>  | sal | lee
> ___
> 
> I get the output like above. However, I want it to output like below
> 
> | oltmans | abramhovic |
> | sal | lee
> 
> 
> That is, there shouldn't be a space in the beginning of second line. The
> list can of course contain more than 5 elements. Any ideas? I will
> appreciate any hint. Thanks in advance.

It looks like your trying to print a formatted list. 
With your code you are:
1)  creating a string from a list, with added characters.
2)  printing the new string.

So, look at your string:
names = ['oltmans','abramhovic','\n','sal','lee'] 
newNames = '| ' + ' | '.join( names )
>> newNames 
'| oltmans | abramhovic | \n | sal | lee'

Now you can see your space after the newline (and a missing pipe symbol at 
the end).

When you ask the compiler for newNames, you can see there is a space after 
the newline character. Naturally, the print operator prints out the space.

If this is indeed a formatted list, you should try something else.

Something like:
# first get rid of you formatting element in the list '\n'.
names = [ 'oltmans','abramhovic','sal','lee' ]

# next iterate by twos via the function 'range( start, stop, step )'
range( 0, len( names ), 2 )
[ 0, 2 ]

# now fix up the printing by twos.
>>> for x in range( 0, len( names ), 2 ):
... print '| %s | %s |' % ( names[ x ], names[ x + 1 ] )
... 
| oltmans | abramhovic |
| sal | lee |

Next, make it pretty.
The next step would be to find the longest string in your list.
>>> def max( theList ):
... theMax = 0
... for element in theList:
... if len( element ) > theMax:
... theMax = len( element )
... return theMax

>>> max( names )
10
Now some centering of strings, from you list.
>>> for x in range( 0, len( names ), 2 ):
... print '| %s | %s |' % \
( names[ x ].center(10), \
names[ x +1 ].center(10) )
... 
|  oltmans   | abramhovic |
|sal |lee |

Pretty list.

Now make it obscure, like you are a perl programmer; don't
forget to eat up memory as you go along 

def maxElement( aList ):
lenList = []
for x in aList: lenList.append( len( x ) )
return sorted( lenList, reverse=True )[0]

def formatLine( firstName, secondName, width ):
return '| %s | %s | % \
( firstName.center( width ), \
 secondName.center( width ) )

theWidth = maxElement( names )
for x in range( 0, len( names ), 2 ):
aLine = formatLines( names[x], names[x+1], theWidth )
print aLine

Make sure to create at lest two additions files to store
maxElement and formatLine, create an __init__.py and make a package, 
turn in the project and get expelled for being grandiose.


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


Re: is it a bug in exec?

2011-01-21 Thread long
I see now. Thank you so much.
I think namespace is really a confusing part in Python.

On Friday, January 21, 2011 11:00:32 AM UTC-6, Peter Otten wrote:
> There are only two cases that matter: identical local/global namespaces and 
> distinct local/global namespaces:
> 
> >>> code = """\
> ... x = 42 # put x into the local namespace
> ... def f():
> ... print(x) # look up x in the global namespace
> ... f()
> ... """
> >>> exec(code, {}, {})
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "", line 4, in 
>   File "", line 3, in f
> NameError: global name 'x' is not defined
> >>> ns = {}
> >>> exec(code, ns, ns)
> 42
> 
> Also note that
> 
> >>> globals() is locals()
> True
> 
> on the module level.
> 
> Peter

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


Re: examples of realistic multiprocessing usage?

2011-01-21 Thread Dan Stromberg
On Fri, Jan 21, 2011 at 12:57 PM, Philip Semanchuk  wrote:
> On Jan 21, 2011, at 3:36 PM, Dan Stromberg wrote:
>> On Fri, Jan 21, 2011 at 3:20 AM, Adam Skutt  wrote:
>>> On Jan 20, 11:51 pm, Albert van der Horst 
>>> wrote:
 This is what some people want you to believe. Arm twisting by
 GPL-ers when you borrow their ideas? That is really unheard of.
>>>
>>> Doesn't matter, you're still legally liable if your work is found to
>>> be derivative and lacking a fair use defense.  It's not borrowing
>>> "ideas" that's problematic, it's proving that's all you did.  For
>>> those of us with legal departments, we have no choice: if they don't
>>> believe we can prove our case, we're not using the code, period.  The
>>> risk simply isn't worth it.
>>
>> Many legal departments have an overblown sense of risk, I'm afraid.
>
> I carefully avoid GPLed code on our BSD-licensed project not because I need 
> fear anyone's legal department, but out of respect for the author(s) of the 
> GPL-ed code. The way I see it, the author of GPL-ed code gives away something 
> valuable and asks for just one thing in return: respect the license. It 
> strikes me as very selfish to deny them the one thing they ask for.

That's very considerate, and yet, I think there are multiple senses of
the word "avoid" above.

If you're avoiding inspecting GPL'd code for ideas, I think if you ask
most authors of GPL'd code, they'd be more than happy to allow you to.
 I've released GPL'd code quite a few times, and personally, I'm
flattered when others want to look it over.

If you're avoiding cutting and pasting from (or linking against) GPL'd
code into something that isn't GPL-licensed, then that's very
sensible.
-- 
http://mail.python.org/mailman/listinfo/python-list


HTSQL 2.0 RC1 -- a Query Language for the Accidental Programmer

2011-01-21 Thread Clark C. Evans
Kirill Simonov and myself would like to introduce HTSQL, a novel
approach 
to relational database access which is neither an ORM nor raw SQL.

HTSQL is a URI-based high-level query language for relational databases.
It's implemented as a Python WSGI application.  Currently it supports
PostgreSQL and SQLite (more databases & juicy features forthcoming).

Homepage: http://htsql.org
Download: http://pypi.python.org/pypi/HTSQL/
Source:   http://bitbucket.org/prometheus/htsql

At this point, HTSQL 2.0 may not be mature enough for production use; we
expect to fill in any remaining gaps in the coming months.

We're curious what you think.  Join us in #htsql on freenode [1],
subscribe 
to the mailing list [2] and please come to our PyCon 2011 talk [3].

Clark & Kirill

[1] irc://irc.freenode.net/#htsql
[2] http://lists.htsql.org/mailman/listinfo/htsql-users
[3] http://us.pycon.org/2011/schedule/sessions/264/
-- 
http://mail.python.org/mailman/listinfo/python-list


Best way to administer code updates to server daemon

2011-01-21 Thread Daniel da Silva
Hi,

I am writing a custom IRC server, and I was wondering would be the
best way to administer code updates to the daemon. Am I doomed to have
to restart the server every time I want to do an update (which would
disconnect all clients)? I don't mind doing something a little more
advanced if it means I can keep close to continuous uptime.

Thanks,
Daniel

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


Python, Solaris 10, and Mailman

2011-01-21 Thread McNutt Jr, William R
I am attempting to install Mailman on a Sun Sunfire x4100 box running Solaris 
ten. I keep running into brick walls that the Mailman group looks at, shrugs, 
and says, that's a Python problem.

Has ANYBODY actually made this work?

Currently, I'm attempting to compile Python 2.4.4, which is the recommended 
distro for Mailman, and I'm getting:

gcc   -o python \
Modules/ccpython.o \
libpython2.4.a -lresolv -lsocket -lnsl -lrt -ldl   -lm
Undefined   first referenced
symbol in file
__gxx_personality_v0Modules/ccpython.o
ld: fatal: Symbol referencing errors. No output written to python
collect2: ld returned 1 exit status
*** Error code 1
make: Fatal error: Command failed for target `python'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Best way to administer code updates to server daemon

2011-01-21 Thread MRAB

On 21/01/2011 22:41, Daniel da Silva wrote:

Hi,

I am writing a custom IRC server, and I was wondering would be the
best way to administer code updates to the daemon. Am I doomed to have
to restart the server every time I want to do an update (which would
disconnect all clients)? I don't mind doing something a little more
advanced if it means I can keep close to continuous uptime.


As I see it, the server listens for a new client, starts a handler for
that client (it might be starting the handler in a new thread), and
then tidies up when the client disconnects.

The server code could be split into the core and the handler. The core
of the server might not be updated very often, so it would stay
running, and the handler would be in another module. There could be
more than one version of the handler available.

When the core wanted to start a handler for a new client it would use
the latest version of the handler, and when an old version of the
handler was no longer being used by any client then it could be
discarded.
--
http://mail.python.org/mailman/listinfo/python-list


Short circuting

2011-01-21 Thread Ed Connell
Hi,

Consider the following please:  (re_section, re_name, etc are previously
compiled patterns)

   result1 = re_section.search(line);
   result2 = re_name.search(line);
   result3 = re_data1.search(line);
   result4 = re_data2.search(line);

   if result1:
   last_section = result1.group()[18:-5]
   elif result2:
   last_name = result2.group(0)[6:-1]
   elif result3:
   data[last_section] = {last_name:
result3.group()[13:-5]}
   elif result4:
   data[last_section] = {last_name:
result4.group()[17:-5]}

It gets my goat to have to obtain all resultx when I just want the first
that is not None.  (In theory, the number of results can be much longer.)  I
can think of alternatives (raising exceptions), but they all use deep
indenting.

Ideas?

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


Re: PEP8, line continuations and string formatting operations

2011-01-21 Thread Carl Banks
On Jan 21, 11:53 am, Gerald Britton  wrote:
> Sowhat's the general feeling about this? Adhere to the PEP 8
> binary operators style, or modify it for string formatting?

Well, personally I ignore the "operator at end of first line"
guideline altogether; I think it's much more readable with the
operator on the following line, not even close.

I'm starting to not fold lines with parentheses as much, either.
Sometimes the parentheses break the flow too much, or suggest grouping
where it isn't desirable.


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


Re: Short circuting

2011-01-21 Thread Alexander Kapps

On 22.01.2011 00:33, Ed Connell wrote:

Hi,

Consider the following please:  (re_section, re_name, etc are
previously compiled patterns)

result1 = re_section.search(line);
result2 = re_name.search(line);
result3 = re_data1.search(line);
result4 = re_data2.search(line);

if result1:
last_section = result1.group()[18:-5]
elif result2:
last_name = result2.group(0)[6:-1]
elif result3:
data[last_section] = {last_name:
result3.group()[13:-5]}
elif result4:
data[last_section] = {last_name:
result4.group()[17:-5]}

It gets my goat to have to obtain all resultx when I just want the
first that is not None.  (In theory, the number of results can be
much longer.)  I can think of alternatives (raising exceptions), but
they all use deep indenting.

Ideas?

Ed




Maybe something like this (totally untested and probably wrong, I'm 
already quite tired):



for pattern in (re_section, re_name, re_data1, re_data2):
result = pattern.search(line):
if result:
if pattern == re_section:
last_section = result1.group()[18:-5]
elif pattern == re_name:
last_name = result2.group(0)[6:-1]
elif pattern == re_data1:
data[last_section] = {last_name: result3.group()[13:-5]}
elif pattern == re_data2:
data[last_section] = {last_name: result4.group()[17:-5]}


Also, if you have long if/elif ladders, look if you can apply the 
dictionary dispatch pattern.

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


Re: Short circuting

2011-01-21 Thread Alexander Kapps

On 22.01.2011 01:10, Alexander Kapps wrote:

On 22.01.2011 00:33, Ed Connell wrote:

Hi,

Consider the following please: (re_section, re_name, etc are
previously compiled patterns)

result1 = re_section.search(line);
result2 = re_name.search(line);
result3 = re_data1.search(line);
result4 = re_data2.search(line);

if result1:
last_section = result1.group()[18:-5]
elif result2:
last_name = result2.group(0)[6:-1]
elif result3:
data[last_section] = {last_name:
result3.group()[13:-5]}
elif result4:
data[last_section] = {last_name:
result4.group()[17:-5]}

It gets my goat to have to obtain all resultx when I just want the
first that is not None. (In theory, the number of results can be
much longer.) I can think of alternatives (raising exceptions), but
they all use deep indenting.

Ideas?

Ed




Maybe something like this (totally untested and probably wrong, I'm
already quite tired):


for pattern in (re_section, re_name, re_data1, re_data2):
result = pattern.search(line):
if result:
if pattern == re_section:
last_section = result1.group()[18:-5]
elif pattern == re_name:
last_name = result2.group(0)[6:-1]
elif pattern == re_data1:
data[last_section] = {last_name: result3.group()[13:-5]}
elif pattern == re_data2:
data[last_section] = {last_name: result4.group()[17:-5]}


Also, if you have long if/elif ladders, look if you can apply the
dictionary dispatch pattern.


Correction. Of course you need to break out of the loop as soon as a 
not None result is found:


if result:
if pattern == re_section:
last_section = result1.group()[18:-5]
...
break
...
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python, Solaris 10, and Mailman

2011-01-21 Thread Antoine Pitrou
On Fri, 21 Jan 2011 22:59:33 +
"McNutt Jr, William R"  wrote:
> I am attempting to install Mailman on a Sun Sunfire x4100 box running Solaris 
> ten. I keep running into brick walls that the Mailman group looks at, shrugs, 
> and says, that's a Python problem.
> 
> Has ANYBODY actually made this work?
> 
> Currently, I'm attempting to compile Python 2.4.4, which is the recommended 
> distro for Mailman,

2.4.4?? Do yourself a favour and choose a modern release.
2.4 hasn't been supported for years, and besides, the latest in that
branch in 2.4.6.
You can probably use whatever version of Python comes with Solaris, no
need to build your own.
Oh, and tell the Mailman guys that their recommendations are totally
obsolete.

Regards

Antoine.


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


Krippendorff's alpha

2011-01-21 Thread OKB (not okblacke)
Does anyone know of a Python implementation of calculating 
Krippendorff's alpha?  ( 
http://en.wikipedia.org/wiki/Krippendorff%27s_Alpha )

Thanks,
-- 
--OKB (not okblacke)
Brendan Barnwell
"Do not follow where the path may lead.  Go, instead, where there is
no path, and leave a trail."
--author unknown
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Krippendorff's alpha

2011-01-21 Thread geremy condra
On Fri, Jan 21, 2011 at 5:48 PM, OKB (not okblacke)
 wrote:
>        Does anyone know of a Python implementation of calculating
> Krippendorff's alpha?  (
> http://en.wikipedia.org/wiki/Krippendorff%27s_Alpha )

First hit on google is [0], which has a full implementation, worked
out example of how to use it, and a link to an excellent description
of how it works and when to use it.

Geremy Condra

[0]: http://cswww.essex.ac.uk/Research/nle/arrau/alpha.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Krippendorff's alpha

2011-01-21 Thread Steven D'Aprano
On Sat, 22 Jan 2011 01:48:01 +, OKB (not okblacke) wrote:

> Does anyone know of a Python implementation of calculating
> Krippendorff's alpha?  (
> http://en.wikipedia.org/wiki/Krippendorff%27s_Alpha )

Google is your friend. Search for "Krippendorff's alpha python" and the 
very first link takes you to one.

http://www.google.co.uk/search?q=Krippendorff%27s+alpha+python&ie=UTF-8&oe=UTF-8



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


Re: Short circuting

2011-01-21 Thread Tim Chase

On 01/21/2011 05:33 PM, Ed Connell wrote:

Consider the following please:  (re_section, re_name, etc are previously
compiled patterns)

result1 = re_section.search(line);
result2 = re_name.search(line);
result3 = re_data1.search(line);
result4 = re_data2.search(line);

if result1:
last_section = result1.group()[18:-5]
elif result2:
last_name = result2.group(0)[6:-1]
elif result3:
data[last_section] = {last_name:
result3.group()[13:-5]}
elif result4:
data[last_section] = {last_name:
result4.group()[17:-5]}

It gets my goat to have to obtain all resultx when I just want the first
that is not None.  (In theory, the number of results can be much longer.)


The problem isn't so much the elif structure, but that you're 
doing different things with each result.  If they were attributes 
of a class and value assignments (instead of top-level variables, 
sometimes calling .group() with no params & sometimes with "0", 
and a mix of strings/dicts), you could do something like


  line = "..."
  info = object() # some class with attributes to update
  for name, r, slc in (
  ("section", re_section, slice(18,-5)),
  ("name", re_name, slice(6,-1)),
  ("data1", re_data1, slice(13,-5)),
  ("data2", re_data2, slice(17,-5)),
  ):
result = r.search(line)
if result:
  setattr(info, name, result.group(0)[slc])
  break
  else:
woah_none_matched(fail, fail, fail, do_I_care)

So if you're doing predictable things with each, it's not too bad.

-tkc



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


Re: Short circuting

2011-01-21 Thread Robert Kern

On 1/21/11 5:33 PM, Ed Connell wrote:

Hi,

Consider the following please:  (re_section, re_name, etc are previously
compiled patterns)

result1 = re_section.search(line);
result2 = re_name.search(line);
result3 = re_data1.search(line);
result4 = re_data2.search(line);

if result1:
last_section = result1.group()[18:-5]
elif result2:
last_name = result2.group(0)[6:-1]
elif result3:
data[last_section] = {last_name:
result3.group()[13:-5]}
elif result4:
data[last_section] = {last_name:
result4.group()[17:-5]}

It gets my goat to have to obtain all resultx when I just want the first that is
not None.  (In theory, the number of results can be much longer.)  I can think
of alternatives (raising exceptions), but they all use deep indenting.


parsers = [
  ('section', re_section, lambda r: r.group()[18:-5]),
  ('name', re_name, lambda r: r.group()[6:-1]),
  ('data1', re_data1, lambda r: r.group()[13:-5]),
  ('data2', re_data2, lambda r: r.group()[17:-5]),
]

data = {}

for line in lines:
values = {}
for key, regex, extract in parsers:
m = regex.search(line)
if m is not None:
values[key] = extract(m)
break
if 'data1' in values:
data[values['section']] = {values['name']: values['data1']}
elif 'data2' in values:
data[values['section']] = {values['name']: values['data2']}

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

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


Re: Krippendorff's alpha

2011-01-21 Thread OKB (not okblacke)
Steven D'Aprano wrote:

> On Sat, 22 Jan 2011 01:48:01 +, OKB (not okblacke) wrote:
> 
>> Does anyone know of a Python implementation of calculating
>> Krippendorff's alpha?  (
>> http://en.wikipedia.org/wiki/Krippendorff%27s_Alpha )
> 
> Google is your friend. Search for "Krippendorff's alpha python" and
> the very first link takes you to one.
> 
> http://www.google.co.uk/search?q=Krippendorff%27s+alpha+python&ie=UT
> F-8&oe=UTF-8 

Thanks to you and Geremy Condra for pointing me at this.  I had 
done a search but somehow did not come upon that page.  Perhaps I 
mistyped something.


-- 
--OKB (not okblacke)
Brendan Barnwell
"Do not follow where the path may lead.  Go, instead, where there is
no path, and leave a trail."
--author unknown
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: HTSQL 2.0 RC1 -- a Query Language for the Accidental Programmer

2011-01-21 Thread rusi
On Jan 22, 2:45 am, "Clark C. Evans"  wrote:
> Kirill Simonov and myself would like to introduce HTSQL, a novel
> approach to relational database access which is neither an ORM nor raw SQL.
:
> We're curious what you think.

Thanks -- looks interesting.

Given the claim htsql is higher level than sql I am interested in
bill-of-materials type (recursive) queries.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Best way to administer code updates to server daemon

2011-01-21 Thread Paul Rubin
Daniel da Silva  writes:
> I am writing a custom IRC server, and I was wondering would be the
> best way to administer code updates to the daemon. Am I doomed to have
> to restart the server every time I want to do an update (which would
> disconnect all clients)? I don't mind doing something a little more
> advanced if it means I can keep close to continuous uptime.

There are several possible approaches:

1) load new code into the server with the import function, being careful
about what data structures you can mess with etc.

2) have a simple front end proxy that maintains the inbound tcp
connections to clients, and uses a connectionless or restartable
protocol to pass the info to the server.  Of course now you have the
issue of how to update the proxy.  But for a serious HA system you have
to do stuff like this anyway.

3) Start the new server in a new process, and use the Linux SCM_RIGHTS
message that lets you pass open file descriptors through Unix domain
sockets, to hand off any open TCP connections from the old server to the
new one.

Maybe there are other ideas possible too.
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2011-01-21 Thread Michael Torrie
On 01/20/2011 11:17 AM, Emile van Sebille wrote:
> The problem with QT is the license.

PyQT indeed is licensed poorly for anything that's not GPL.  But Qt
itself is dual-licensed under GPL and the LGPL, as of version 4.6 I
think.  The LGPL license would seem to be quite acceptable even for
commercial, closed-source programs.  Is this not so?  The license is at
parity with GTK+.

Eventually PySide will be stable and fast, and so the licensing issues
involving PyQt won't matter.
-- 
http://mail.python.org/mailman/listinfo/python-list