[RELEASED] Python 3.2 beta 2

2010-12-22 Thread Georg Brandl
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On behalf of the Python development team, I'm happy to announce the
second beta preview release of Python 3.2.

Python 3.2 is a continuation of the efforts to improve and stabilize the
Python 3.x line.  Since the final release of Python 2.7, the 2.x line
will only receive bugfixes, and new features are developed for 3.x only.

Since PEP 3003, the Moratorium on Language Changes, is in effect, there
are no changes in Python's syntax and built-in types in Python 3.2.
Development efforts concentrated on the standard library and support for
porting code to Python 3.  Highlights are:

* numerous improvements to the unittest module
* PEP 3147, support for .pyc repository directories
* PEP 3149, support for version tagged dynamic libraries
* PEP 3148, a new futures library for concurrent programming
* PEP 384, a stable ABI for extension modules
* PEP 391, dictionary-based logging configuration
* an overhauled GIL implementation that reduces contention
* an extended email package that handles bytes messages
* countless fixes regarding bytes/string issues; among them full
  support for a bytes environment (filenames, environment variables)
* many consistency and behavior fixes for numeric operations
* a sysconfig module to access configuration information
* a pure-Python implementation of the datetime module
* additions to the shutil module, among them archive file support
* improvements to pdb, the Python debugger

For a more extensive list of changes in 3.2, see

http://docs.python.org/3.2/whatsnew/3.2.html

To download Python 3.2 visit:

http://www.python.org/download/releases/3.2/

Please consider trying Python 3.2 with your code and reporting any bugs
you may notice to:

http://bugs.python.org/


Enjoy!

- -- 
Georg Brandl, Release Manager
georg at python.org
(on behalf of the entire python-dev team and 3.2's contributors)

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.11 (GNU/Linux)

iEYEARECAAYFAk0Q/aAACgkQN9GcIYhpnLDf8gCgkLGAsE+T3R505jZc1RxXDYsa
NSsAnRGaFjeTm9o2Z5O8FuIzTUG8t1PT
=hHzz
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations/


compiling Python 2.7.1 with readline module fails on Debian (Virtualbox)

2010-12-22 Thread Benedict Verheyen
Hi,


i'm trying to compile Python 2.7.1 on Debian (Virtual Box).
Compiling end successfully but readline and curses fail to build.

I'm working with virtualenv and I install all my packages in $HOME/local.
I've downloaded readline, compiled and installed it in $HOME/local, same with 
ncurses.
Both were the latest releases.
But somehow, Python isn't able to build them.

I get this message:

Failed to build these modules:
_curses_curses_panelreadline

So it does seems to find the modules.
I'm not used to dealing with configure, and make so i can't debug much.
I first tried this configure line:
./configure --enable-shared --prefix=$HOME/local

Next i tried this one:
env CPPFLAGS=-I$HOME/local/include LDFLAGS=-L$HOME/local/lib ./configure 
--enable-shared --prefix=$HOME/local

But make yields the same error.

Any clues on what I do wrong?

The source of ncurses and readline are placed in $HOME/src.
Both packages are installed in $HOME/local

Thanks for any advice,

Regards,
Benedict

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


Question regarding Higher-Order-Programming in Python

2010-12-22 Thread Mark Fink
I am about to learn Higher-Order-Programming with Lisp, Haskell, and
Python. Some people who have gone completely out of their mind call
this FP.

In Haskell I learned that when I use map on a list it starts nesting
as soon as I start adding elements. If I do not like the nesting I use
ConcatMap.

In Python I have a similar scenario. I have a generator which creates
some combinatorics of a input dictionary. The list starts nesting. Now
I could use reduce(concat, ...) which would be the correct thing from
a functional perspective. But from a resource utilization perspective
it is not a good idea since the reduce is executing the generator.

I tried to illustrate this using a small example (the often in
combinatorics the real thing would be much bigger that is why I need
to use a generator):

 from operator import itemgetter, concat
 import itertools as it
 from functools import partial

 dims = {'number': [1,2,3], 'letter': ['a', 'b'], 'special': ['+', '-']}
 dims
{'special': ['+', '-'], 'number': [1, 2, 3], 'letter': ['a', 'b']}
 def get_products(keys):
... # helper to get products from keys in the following form:
... # [('bold', True), ('color', 'black')]
... values  = itemgetter(*keys)(dims)
... product = it.product(*values)
... return map(partial(zip, keys), product)
...
 comb = it.combinations(dims, 2)
 comb_l = list(comb)
 comb_l
[('special', 'number'), ('special', 'letter'), ('number', 'letter')]
 res = map(get_products, comb_l)
 res
[[[('special', '+'), ('number', 1)], [('special', '+'), ('number',
2)], [('special', '+'), ('number', 3)], [('special', '-'), ('number',
1)], [('special', '-'), ('number', 2)], [('special', '-'), ('number',
3)]], [[('special', '+'), ('letter', 'a')], [('special', '+'),
('letter', 'b')], [('special', '-'), ('letter', 'a')], [('special',
'-'), ('letter', 'b')]], [[('number', 1), ('letter', 'a')],
[('number', 1), ('letter', 'b')], [('number', 2), ('letter', 'a')],
[('number', 2), ('letter', 'b')], [('number', 3), ('letter', 'a')],
[('number', 3), ('letter', 'b')]]]  # the resulting list is nested one
level to deep caused by the map(get_products, ..


My problem is that I want to get single elements from the generator
like [('special', '+'), ('number', 1)]. But this does not work because
the list is now nested to deep.

That is what I expect: (I could get something like that with the
following  res = reduce(concat, res)
[[('special', '+'), ('number', 1)], [('special', '+'), ('number', 2)],
[('special', '+'), ('number', 3)], [('special', '-'), ('number', 1)],
[('special', '-'), ('number', 2)], [('special', '-'), ('number', 3)],
[('special', '+'), ('letter', 'a')], [('special', '+'), ('letter',
'b')], [('special', '-'), ('letter', 'a')], [('special', '-'),
('letter', 'b')], [('number', 1), ('letter', 'a')], [('number', 1),
('letter', 'b')], [('number', 2), ('letter', 'a')], [('number', 2),
('letter', 'b')], [('number', 3), ('letter', 'a')], [('number', 3),
('letter', 'b')]]

I have seen the problem many times but so far I could not google a
solution on the web.

By the way do you know any substantial example using FP in Python
(generators, imap, ifilter, ...)?
-- 
http://mail.python.org/mailman/listinfo/python-list


Mo Better Lisp Jobs

2010-12-22 Thread kenny
Check it out: 
http://lispjobs.wordpress.com/2010/12/22/lisp-developer-mcna-fort-laurderdale-florida/

We already have six splendid folks but business is booming and at
least one contract bid has to happen faster than we thought (potential
client moved it up) so we are looking to take on a couple more.

Lisp wannabe Rails gurus lurking here, plz note the opportunity
described in the listing.

The rest of the cross-posting is to find great coders with light Lisp.
We can talk.

HK

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


Re: Question regarding Higher-Order-Programming in Python

2010-12-22 Thread Peter Otten
Mark Fink wrote:

 I am about to learn Higher-Order-Programming with Lisp, Haskell, and
 Python. Some people who have gone completely out of their mind call
 this FP.
 
 In Haskell I learned that when I use map on a list it starts nesting
 as soon as I start adding elements. If I do not like the nesting I use
 ConcatMap.
 
 In Python I have a similar scenario. I have a generator which creates
 some combinatorics of a input dictionary. The list starts nesting. Now
 I could use reduce(concat, ...) which would be the correct thing from
 a functional perspective. But from a resource utilization perspective
 it is not a good idea since the reduce is executing the generator.
 
 I tried to illustrate this using a small example (the often in
 combinatorics the real thing would be much bigger that is why I need
 to use a generator):
 
 from operator import itemgetter, concat
 import itertools as it
 from functools import partial

 dims = {'number': [1,2,3], 'letter': ['a', 'b'], 'special': ['+', '-']}
 dims
 {'special': ['+', '-'], 'number': [1, 2, 3], 'letter': ['a', 'b']}
 def get_products(keys):
 ... # helper to get products from keys in the following form:
 ... # [('bold', True), ('color', 'black')]
 ... values  = itemgetter(*keys)(dims)
 ... product = it.product(*values)
 ... return map(partial(zip, keys), product)
 ...
 comb = it.combinations(dims, 2)
 comb_l = list(comb)
 comb_l
 [('special', 'number'), ('special', 'letter'), ('number', 'letter')]
 res = map(get_products, comb_l)
 res
 [[[('special', '+'), ('number', 1)], [('special', '+'), ('number',
 2)], [('special', '+'), ('number', 3)], [('special', '-'), ('number',
 1)], [('special', '-'), ('number', 2)], [('special', '-'), ('number',
 3)]], [[('special', '+'), ('letter', 'a')], [('special', '+'),
 ('letter', 'b')], [('special', '-'), ('letter', 'a')], [('special',
 '-'), ('letter', 'b')]], [[('number', 1), ('letter', 'a')],
 [('number', 1), ('letter', 'b')], [('number', 2), ('letter', 'a')],
 [('number', 2), ('letter', 'b')], [('number', 3), ('letter', 'a')],
 [('number', 3), ('letter', 'b')]]]  # the resulting list is nested one
 level to deep caused by the map(get_products, ..

 
 My problem is that I want to get single elements from the generator
 like [('special', '+'), ('number', 1)]. But this does not work because
 the list is now nested to deep.

Like this?

 [(k, v) for k, vv in dims.iteritems() for v in vv]
[('special', '+'), ('special', '-'), ('number', 1), ('number', 2), 
('number', 3), ('letter', 'a'), ('letter', 'b')]

But these are just glorified for-loops, so:

 list(chain.from_iterable(starmap(product, izip(izip(dims.iterkeys()), 
dims.itervalues()
[('special', '+'), ('special', '-'), ('number', 1), ('number', 2), 
('number', 3), ('letter', 'a'), ('letter', 'b')]

Peter

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


issubclass(dict, Mapping)

2010-12-22 Thread kj

In a message (4cf97c94$0$30003$c3e8da3$54964...@news.astraweb.com)
on a different thread, Steven D'Aprano tells me:

I suspect you're trying to make this more complicated than it actually 
is. You keep finding little corner cases that expose implementation 
details (such as the heap-types issue above) and leaping to the erroneous 
conclusion that because you didn't understand this tiny little corner of 
Python's class model, you didn't understand any of it. Python's object 
model is relatively simple, but it does occasionally expose a few messy 
corners.

I disagree with your assessment.  What you call little corner
cases I call fundamental, as in you can't really call yourself
competent with Python if you're ignorant about them.

To use a term I first saw in an article by Joel Spolsky
(http://is.gd/je42O), Python's object model is a rather leaky
abstraction.  This refers to the situation in which a user is not
shielded from the implementation details.  When an abstraction
leaks, implementation details are no longer negligible, they cease
to be little corner cases.

Here's another example, fresh from today's crop of wonders:

(v. 2.7.0)
 from collections import Mapping
 issubclass(dict, Mapping)
True
 dict.__bases__
(type 'object',)
 [issubclass(b, Mapping) for b in dict.__bases__]
[False]


So dict is a subclass of Mapping, even though none of the bases of
dict is either Mapping or a subclass of Mapping.  Great.

I suspect this is another abstraction leak (dict is *supposed* to
be a Python class like all others, but in fact it's not *really*.
You see, once upon a time...).

I conclude that, for me to understand Python's (rather leaky) object
model abstraction, I have to understand its underlying implementation.
Unfortunately, as far as I know, there's no other choice but to
study the source code, since there's no other more readable
description of this implementation.

Maybe there are fewer abstraction leaks in 3.0... 

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


Re: issubclass(dict, Mapping)

2010-12-22 Thread Adam Tauno Williams
On Wed, 2010-12-22 at 14:20 +, kj wrote:
 In a message (4cf97c94$0$30003$c3e8da3$54964...@news.astraweb.com)
 on a different thread, Steven D'Aprano tells me:
 I suspect you're trying to make this more complicated than it actually 
 is. You keep finding little corner cases that expose implementation 
 details (such as the heap-types issue above) and leaping to the erroneous 
 conclusion that because you didn't understand this tiny little corner of 
 Python's class model, you didn't understand any of it. Python's object 
 model is relatively simple, but it does occasionally expose a few messy 
 corners.
 I disagree with your assessment.  What you call little corner
 cases I call fundamental, as in you can't really call yourself
 competent with Python if you're ignorant about them.
 To use a term I first saw in an article by Joel Spolsky
 (http://is.gd/je42O), Python's object model is a rather leaky
 abstraction.  This refers to the situation in which a user is not
 shielded from the implementation details.  When an abstraction
 leaks, implementation details are no longer negligible, they cease
 to be little corner cases.
 Here's another example, fresh from today's crop of wonders:
 (v. 2.7.0)
  from collections import Mapping
  issubclass(dict, Mapping)
 True
  dict.__bases__
 (type 'object',)
  [issubclass(b, Mapping) for b in dict.__bases__]
 [False]
 So dict is a subclass of Mapping, even though none of the bases of
 dict is either Mapping or a subclass of Mapping.  Great.
 I suspect this is another abstraction leak (dict is *supposed* to
 be a Python class like all others, but in fact it's not *really*.
 You see, once upon a time...).
 I conclude that, for me to understand Python's (rather leaky) object
 model abstraction, I have to understand its underlying implementation.
 Unfortunately, as far as I know, there's no other choice but to
 study the source code, since there's no other more readable
 description of this implementation.
 Maybe there are fewer abstraction leaks in 3.0... 

Boy howdy are you going to incite the ire of the Pythonistas! 

IMO, the object model isn't leaky, it is simply adhoc and not
really a model at all [write as many 800 page books as you want: if it
walks like a zombie duck, smells like a zombie duck - it is still a
zombie duck].  Performing introspection in Python is awful and a
veritable land-mine of implementation details.  The short and honest
answer is: avoid doing it whenever possible,  try to figure out how to
accomplish the task some other way.


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


Re: Question regarding Higher-Order-Programming in Python

2010-12-22 Thread Mark Fink
  list(chain.from_iterable(starmap(product, izip(izip(dims.iterkeys()),

 dims.itervalues()
 [('special', '+'), ('special', '-'), ('number', 1), ('number', 2),
 ('number', 3), ('letter', 'a'), ('letter', 'b')]

 Peter

so far I have never noticed chain.from_iterable, but many thanks to
you Peter, I have now a beautiful solution to this problem.
 from itertools import chain
 comb = it.combinations(dims, 2)
 l = chain.from_iterable(it.imap(get_products, comb))
 l.next()
[('special', '+'), ('number', 1)]
 l.next()
[('special', '+'), ('number', 2)]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: issubclass(dict, Mapping)

2010-12-22 Thread Antoine Pitrou
On Wed, 22 Dec 2010 14:20:51 + (UTC)
kj no.em...@please.post wrote:
 
 So dict is a subclass of Mapping, even though none of the bases of
 dict is either Mapping or a subclass of Mapping.  Great.
 
 I suspect this is another abstraction leak (dict is *supposed* to
 be a Python class like all others, but in fact it's not *really*.

It is. You just haven't read about Python's ABCs (abstract base
classes):

http://docs.python.org/library/abc.html#abc.ABCMeta

« You can also register unrelated concrete classes (even built-in
classes) and unrelated ABCs as “virtual subclasses” – these and their
descendants will be considered subclasses of the registering ABC by the
built-in issubclass() function, but the registering ABC won’t show up
in their MRO (Method Resolution Order) nor will method implementations
defined by the registering ABC be callable (not even via super()). »

With a very simple example in the register() doc:

http://docs.python.org/library/abc.html#abc.ABCMeta.register

Regards

Antoine.


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


Re: Google AI challenge: planet war. Lisp won.

2010-12-22 Thread Xah Lee
On Dec 20, 10:06 pm, Jon Harrop use...@ffconsultancy.com wrote:
 Wasn't that the challenge where they wouldn't even accept solutions
 written in many other languages (including both OCaml and F#)?

Ocaml is one of the supported lang. See:

http://ai-contest.com/starter_packages.php

there are 12 teams using OCaml. See:
http://ai-contest.com/rankings.php
(click on the lang to see all teams using that lang)

 Xah

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


Re: issubclass(dict, Mapping)

2010-12-22 Thread Antoine Pitrou
On Wed, 22 Dec 2010 09:35:48 -0500
Adam Tauno Williams awill...@whitemice.org wrote:
 
 IMO, the object model isn't leaky, it is simply adhoc and not
 really a model at all [write as many 800 page books as you want: if it
 walks like a zombie duck, smells like a zombie duck - it is still a
 zombie duck].  Performing introspection in Python is awful and a
 veritable land-mine of implementation details.

Introspection is fine as long as you stick to officially promoted tools
such as isinstance(), issubclass(), dir() or the inspect module.
If you start looking inside the pants of the object model, you can have
surprises :)

Regards

Antoine.


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


Re: issubclass(dict, Mapping)

2010-12-22 Thread Steve Holden
On 12/22/2010 9:20 AM, kj wrote:
[...]
 I suspect this is another abstraction leak (dict is *supposed* to
 be a Python class like all others, but in fact it's not *really*.
 You see, once upon a time...).
 
So your suspicions are to be placed above the knowledge of those who
really do understand Python's object model? That seems like a recipe for
cargo cult programming ...

 I conclude that, for me to understand Python's (rather leaky) object
 model abstraction, I have to understand its underlying implementation.
 Unfortunately, as far as I know, there's no other choice but to
 study the source code, since there's no other more readable
 description of this implementation.
 
You don't have to understand the implementation (there are at least
five different implementations, which one will you choose as your standard?)

 Maybe there are fewer abstraction leaks in 3.0... 
 
Python deliberately exposes introspection interfaces, which you may use
if you wish. As with all introspectable languages (including Java) if
you push the envelope you are likely to hit corner cases. As Steven
d'Aprano has already said, these *are* corner cases and not the whole of
the language.

Don't worry about having a complete knowledge of the language before you
start to use it. That can induce paralysis ...

regards
 Steve
-- 
Steve Holden   +1 571 484 6266   +1 800 494 3119
PyCon 2011 Atlanta March 9-17   http://us.pycon.org/
See Python Video!   http://python.mirocommunity.org/
Holden Web LLC http://www.holdenweb.com/

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


Re: [python-committers] [RELEASED] Python 3.2 beta 2

2010-12-22 Thread Eric Smith

On 12/22/2010 8:46 AM, Georg Brandl wrote:

Am 22.12.2010 02:15, schrieb Nick Coghlan:

On Wed, Dec 22, 2010 at 6:18 AM, Georg Brandlge...@python.org  wrote:

Since PEP 3003, the Moratorium on Language Changes, is in effect, there
are no changes in Python's syntax and built-in types in Python 3.2.


Minor nit - we actually did tweak a few of the builtin types a bit
(mostly the stuff to improve Sequence ABC conformance and to make
range objects more list-like)


Indeed, I'll fix this wording for the next announcement.  (And I will
mention SSL, sorry Antoine).


If you're only going to mention some vague some builtins had minor 
changes, then I'm fine with that. If you're going to enumerate all such 
changes, that will be a bigger job. There were 2 such changes I'm aware 
of: str.format_map (#6081) and the addition of alternate (#) 
formatting to float, complex and decimal (#7094) __format__ methods.


For this announcement I don't think it's necessary to list them all.

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


Re: compiling Python 2.7.1 with readline module fails on Debian (Virtualbox)

2010-12-22 Thread Benedict Verheyen
On 22/12/2010 9:33, Benedict Verheyen wrote:
 Hi,
 
 
 i'm trying to compile Python 2.7.1 on Debian (Virtual Box).
 Compiling end successfully but readline and curses fail to build.
 
 I'm working with virtualenv and I install all my packages in $HOME/local.
 I've downloaded readline, compiled and installed it in $HOME/local, same with 
 ncurses.
 Both were the latest releases.
 But somehow, Python isn't able to build them.
 
 I get this message:
 
 Failed to build these modules:
 _curses_curses_panelreadline
 
 So it does seems to find the modules.
 I'm not used to dealing with configure, and make so i can't debug much.
 I first tried this configure line:
 ./configure --enable-shared --prefix=$HOME/local
 
 Next i tried this one:
 env CPPFLAGS=-I$HOME/local/include LDFLAGS=-L$HOME/local/lib ./configure 
 --enable-shared --prefix=$HOME/local
 
 But make yields the same error.
 
 Any clues on what I do wrong?
 
 The source of ncurses and readline are placed in $HOME/src.
 Both packages are installed in $HOME/local
 
 Thanks for any advice,
 
 Regards,
 Benedict
 

I found some additional info here:
http://www.velocityreviews.com/forums/t733455-problem-building-python-2-7-with-enable-shared.html

The error -collect2: ld returned 1 exit status is the same error as I'm 
getting.

So what happens is that linking to python2.7 during make, doesn't link to the 
freshly build
library, but to the existing in the system.

Is there any solution for this?
Or an option i can add to make/config?

Cheers,
Benedict

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


Regular expression for key = value pairs

2010-12-22 Thread Ciccio

Hi all,
suppose I have:

s='a=b, c=d'

and I want to extract sub-strings a,b,c and d from s (and in general 
from any longer list of such comma separated pairs).

Some failed attempts:

In [12]: re.findall(r'(.+)=(.+)', s)
Out[12]: [('a=b, c', 'd')]

In [13]: re.findall(r'(.+?)=(.+)', s)
Out[13]: [('a', 'b, c=d')]

In [14]: re.findall(r'(.+)=(.+)*', s)
Out[14]: [('a=b, c', 'd')]

In [15]: re.findall(r'(.+)=(.+),', s)
Out[15]: [('a', 'b')]

In [16]: re.findall(r'(.+)=(.+),?', s)
Out[16]: [('a=b, c', 'd')]

Thanks for your help,
francesco.
--
http://mail.python.org/mailman/listinfo/python-list


Re: help with link parsing?

2010-12-22 Thread Colin J. Williams

On 21-Dec-10 12:22 PM, Jon Clements wrote:

import lxml
from urlparse import urlsplit

doc = lxml.html.parse('http://www.google.com')
print map(urlsplit, doc.xpath('//a/@href'))

[SplitResult(scheme='http', netloc='www.google.co.uk', path='/imghp',
query='hl=entab=wi', fragment=''), SplitResult(scheme='http',
netloc='video.google.co.uk', path='/', query='hl=entab=wv',
fragment=''), SplitResult(scheme='http', netloc='maps.google.co.uk',
path='/maps', query='hl=entab=wl', fragment=''),
SplitResult(scheme='http', netloc='news.google.co.uk', path='/nwshp',
query='hl=entab=wn', fragment=''), ...]


Jon,

What version of Python was used to run this?

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


Re: Regular expression for key = value pairs

2010-12-22 Thread André
On Wednesday, December 22, 2010 12:22:22 PM UTC-4, Francesco Napolitano wrote:
 Hi all,
 suppose I have:
 
 s='a=b, c=d'
 
 and I want to extract sub-strings a,b,c and d from s (and in general 
 from any longer list of such comma separated pairs).
 Some failed attempts:
 
 In [12]: re.findall(r'(.+)=(.+)', s)
 Out[12]: [('a=b, c', 'd')]
 
 In [13]: re.findall(r'(.+?)=(.+)', s)
 Out[13]: [('a', 'b, c=d')]
 
 In [14]: re.findall(r'(.+)=(.+)*', s)
 Out[14]: [('a=b, c', 'd')]
 
 In [15]: re.findall(r'(.+)=(.+),', s)
 Out[15]: [('a', 'b')]
 
 In [16]: re.findall(r'(.+)=(.+),?', s)
 Out[16]: [('a=b, c', 'd')]
 

How about the following:

 s = 'a=b,c=d'
 t = []
 for u in s.split(','):
... t.extend(u.split('='))
... 
 t
['a', 'b', 'c', 'd']

HTH,

André
 Thanks for your help,
 francesco.

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


Re: Regular expression for key = value pairs

2010-12-22 Thread Vlastimil Brom
2010/12/22 Ciccio franap...@gmail.com:
 Hi all,
 suppose I have:

 s='a=b, c=d'

 and I want to extract sub-strings a,b,c and d from s (and in general from
 any longer list of such comma separated pairs).
 Some failed attempts:

 In [12]: re.findall(r'(.+)=(.+)', s)
 Out[12]: [('a=b, c', 'd')]

 [...]
 Thanks for your help,
 francesco.
 --
 http://mail.python.org/mailman/listinfo/python-list


Hi,
I am not sure,  the regular expressions are best suited for this task,
but if you have a predictable simple parameter list (with ho
recursion, escaping commas or equal signs etc.), it might be viable;
how about e.g. this pattern?

 re.findall(r'([^=\s,]+)=([^=\s,]+)', s)
[('a', 'b'), ('c', 'd')]


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


simple games w/o pygame

2010-12-22 Thread William Gill
I am teaching an 11 year old who wants to learn programming.  I chose 
Python, and it is working well.  I seem to remember lots of simple 
script games, like quizzes, number games etc. that would be good for his 
tutorial.  However, now all I can find is more complex games using 
Pygame.  Can anyone help me out here?

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


Re: How to pop the interpreter's stack?

2010-12-22 Thread kj
In mailman.65.1292517591.6505.python-l...@python.org Robert Kern 
robert.k...@gmail.com writes:

Obfuscating the location that an exception gets raised prevents a lot of 
debugging...

The Python interpreter does a lot of that obfuscation already, and I
find the resulting tracebacks more useful for it.

An error message is only useful to a given audience if that audience
can use the information in the message to modify what they are
doing to avoid the error.  It is of no use (certainly no *immediate*
use) to this audience to see tracebacks that go deep into code that
they don't know anything about and cannot change.

For example, consider this:

#-
def foo(x, **k): pass

def bar(*a, **k):
if len(a)  1: raise TypeError('too many args')

def baz(*a, **k): _pre_baz(*a, **k)

def _pre_baz(*a, **k):
if len(a)  1: raise TypeError('too many args')

if __name__ == '__main__':
from traceback import print_exc
try: foo(1, 2)
except: print_exc()
try: bar(1, 2)
except: print_exc()
try: baz(1, 2)
except: print_exc()
#-


(The code in the if __name__ == '__main__' section is meant to
simulate the general case in which the functions defined in this file
are called by third-party code.)  When you run this code the output is
this (a few blank lines added for clarity):

Traceback (most recent call last):
  File /tmp/ex2.py, line 5, in module
try: foo(1, 2)
TypeError: foo() takes exactly 1 argument (2 given)

Traceback (most recent call last):
  File /tmp/ex2.py, line 7, in module
try: bar(1, 2)
  File /tmp/example.py, line 4, in bar
if len(a)  1: raise TypeError('too many args')
TypeError: too many args

Traceback (most recent call last):
  File /tmp/ex2.py, line 9, in module
try: baz(1, 2)
  File /tmp/example.py, line 6, in baz
def baz(*a, **k): _pre_baz(*a, **k)
  File /tmp/example.py, line 9, in _pre_baz
if len(a)  1: raise TypeError('too many args')
TypeError: too many args


In all cases, the *programming* errors are identical: functions called
with the wrong arguments.  The traceback from foo(1, 2) tells me this
very clearly, and I'm glad that Python is not also giving me the
traceback down to where the underlying C code throws the exception: I
don't need to see all this machinery.

In contrast, the tracebacks from bar(1, 2) and baz(1, 2) obscure the
fundamental problem with useless detail.  From the point of view of
the programmer that is using these functions, it is of no use to know
that the error resulted from some raise TypeError statement
somewhere, let alone that this happened in some obscure, private
function _pre_baz.

Perhaps I should have made it clearer in my original post that the
tracebacks I want to clean up are those from exceptions *explicitly*
raised by my argument-validating helper function, analogous to
_pre_baz above.  I.e. I want that when my spam function is called
(by code written by someone else) with the wrong arguments, the
traceback looks more like this

Traceback (most recent call last):
  File /some/python/code.py, line 123, in module
spam(some, bad, args)
TypeError: the second argument is bad


than like this:

Traceback (most recent call last):
  File /some/python/code.py, line 123, in module
spam(some, bad, args)
  File /my/niftymodule.py, line 456, in niftymodule
_pre_spam(*a, **k)
  File /my/niftymodule.py, line 789, in __pre_spam
raise TypeError('second argument to spam is bad')
TypeError: the second argument is bad


In my opinion, the idea that more is always better in a traceback
is flat out wrong.  As the example above illustrates, the most
useful traceback is the one that stops at the deepest point where
the *intended audience* for the traceback can take action, and goes
no further.  The intended audience for the errors generated by my
argument-checking functions should see no further than the point
where they called a function incorrectly.

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


Re: help with link parsing?

2010-12-22 Thread Jon Clements
On Dec 22, 4:24 pm, Colin J. Williams cjwilliam...@gmail.com
wrote:
 On 21-Dec-10 12:22 PM, Jon Clements wrote:

  import lxml
  from urlparse import urlsplit

  doc = lxml.html.parse('http://www.google.com')
  print map(urlsplit, doc.xpath('//a/@href'))

  [SplitResult(scheme='http', netloc='www.google.co.uk', path='/imghp',
  query='hl=entab=wi', fragment=''), SplitResult(scheme='http',
  netloc='video.google.co.uk', path='/', query='hl=entab=wv',
  fragment=''), SplitResult(scheme='http', netloc='maps.google.co.uk',
  path='/maps', query='hl=entab=wl', fragment=''),
  SplitResult(scheme='http', netloc='news.google.co.uk', path='/nwshp',
  query='hl=entab=wn', fragment=''), ...]

 Jon,

 What version of Python was used to run this?

 Colin W.

2.6.5 - the lxml library is not a standard module though and needs to
be installed.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Regular expression for key = value pairs

2010-12-22 Thread Mark Wooding
Ciccio franap...@gmail.com writes:

 suppose I have:

 s='a=b, c=d'

 and I want to extract sub-strings a,b,c and d from s (and in general
 from any longer list of such comma separated pairs).
[...]
 In [12]: re.findall(r'(.+)=(.+)', s)
 Out[12]: [('a=b, c', 'd')]

I think there are two logically separate jobs here: firstly, extracting
the comma-separated pairs, and secondly parsing the individual pairs.

If you want the extra problem of dealing with regular expressions, this
seems to be the way to do it.

R_PAIR = re.compile(r'''
^\s*
([^=\s]|[^=\s][^=]*[^=\s])
\s*=\s*
(\S|\S.*\S)
\s*$
''', re.X)

def parse_pair(pair):
  m = R_PAIR.match(pair)
  if not m:
raise ValueError, 'not a `KEY = VALUE\' pair'
  return m.groups([1, 2])

The former is even easier.

R_COMMA = re.compile(r'\s*,\s*')

kvs = [parse_pair(p) for p in R_COMMA.split(string)]

Apply gold-plating to taste.

But actually, it's much easier to avoid messing with regular expressions
at all.

def parse_pair(pair):
  eq = pair.index('=')
  return pair[:eq].strip(), pair[eq + 1:].strip()

kvs = [parse_pair(p) for p in string.split(',')]

-- [mdw]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Regular expression for key = value pairs

2010-12-22 Thread Mark Wooding
André andre.robe...@gmail.com writes:

 How about the following:

  s = 'a=b,c=d'
  t = []
  for u in s.split(','):
 ... t.extend(u.split('='))

s = 'a = b = c, d = e'
= ['a ', ' b ', ' c', ' d ', ' e']

Ugh.

-- [mdw]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: issubclass(dict, Mapping)

2010-12-22 Thread Ethan Furman

kj wrote:

In a message (4cf97c94$0$30003$c3e8da3$54964...@news.astraweb.com)
on a different thread, Steven D'Aprano tells me:

I suspect you're trying to make this more complicated than it actually 
is. You keep finding little corner cases that expose implementation 
details (such as the heap-types issue above) and leaping to the erroneous 
conclusion that because you didn't understand this tiny little corner of 
Python's class model, you didn't understand any of it. Python's object 
model is relatively simple, but it does occasionally expose a few messy 
corners.


I disagree with your assessment.  What you call little corner
cases I call fundamental, as in you can't really call yourself
competent with Python if you're ignorant about them.


So where on the sliding scale do you place 'competent'?  It sounds to me 
like you are looking at 'master'.




Here's another example, fresh from today's crop of wonders:

(v. 2.7.0)

from collections import Mapping
issubclass(dict, Mapping)

True

dict.__bases__

(type 'object',)

[issubclass(b, Mapping) for b in dict.__bases__]

[False]


Firstly, as I'm sure you know, if you don't import Mapping from 
collections the issubclass test fails with a NameError.


Secondly, why do you care?  Did you get bitten by something?  Some 
error, or worse, silently got wrong results?  (Sincere question.)




So dict is a subclass of Mapping, even though none of the bases of
dict is either Mapping or a subclass of Mapping.  Great.

I suspect this is another abstraction leak 


My take on abstraction leaks is when the underlying actuality shows 
through in a non-ignorable way -- so I ask again, how is this 
discrepancy making it so you can't ignore it?


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


Re: simple games w/o pygame

2010-12-22 Thread Andre Alexander Bell
On 22.12.2010 17:40, William Gill wrote:
 I am teaching an 11 year old who wants to learn programming.  I chose
 Python, and it is working well.  I seem to remember lots of simple
 script games, like quizzes, number games etc. that would be good for his
 tutorial.  However, now all I can find is more complex games using
 Pygame.  Can anyone help me out here?

Recently someone posted this link on the list, which might be interesting:

http://inventwithpython.com/index.html

Regards


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


Re: compiling Python 2.7.1 with readline module fails on Debian (Virtualbox)

2010-12-22 Thread Stefan Sonnenberg-Carstens

Am 22.12.2010 09:33, schrieb Benedict Verheyen:

Hi,


i'm trying to compile Python 2.7.1 on Debian (Virtual Box).
Compiling end successfully but readline and curses fail to build.

I'm working with virtualenv and I install all my packages in $HOME/local.
I've downloaded readline, compiled and installed it in $HOME/local, same with 
ncurses.
Both were the latest releases.
But somehow, Python isn't able to build them.

I get this message:

Failed to build these modules:
_curses_curses_panelreadline

So it does seems to find the modules.
I'm not used to dealing with configure, and make so i can't debug much.
I first tried this configure line:
./configure --enable-shared --prefix=$HOME/local

Next i tried this one:
env CPPFLAGS=-I$HOME/local/include LDFLAGS=-L$HOME/local/lib ./configure 
--enable-shared --prefix=$HOME/local

But make yields the same error.

Any clues on what I do wrong?

The source of ncurses and readline are placed in $HOME/src.
Both packages are installed in $HOME/local

Thanks for any advice,

Regards,
Benedict


Did you try

apt-get install build-essential
apt-get build-dep python2.7

before trying to compile ?

Anyway, the config.log file is always of special interest.
Btw, which Debian release are you running ?
If the system is set up correctly it should not be necessary to change 
env vars to get it built.



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


Re: compiling Python 2.7.1 with readline module fails on Debian (Virtualbox)

2010-12-22 Thread Jim Pharis
are you running make clean for good measure?

On Wed, Dec 22, 2010 at 3:33 AM, Benedict Verheyen 
benedict.verhe...@gmail.com wrote:

 Hi,


 i'm trying to compile Python 2.7.1 on Debian (Virtual Box).
 Compiling end successfully but readline and curses fail to build.

 I'm working with virtualenv and I install all my packages in $HOME/local.
 I've downloaded readline, compiled and installed it in $HOME/local, same
 with ncurses.
 Both were the latest releases.
 But somehow, Python isn't able to build them.

 I get this message:

 Failed to build these modules:
 _curses_curses_panelreadline

 So it does seems to find the modules.
 I'm not used to dealing with configure, and make so i can't debug much.
 I first tried this configure line:
 ./configure --enable-shared --prefix=$HOME/local

 Next i tried this one:
 env CPPFLAGS=-I$HOME/local/include LDFLAGS=-L$HOME/local/lib
 ./configure --enable-shared --prefix=$HOME/local

 But make yields the same error.

 Any clues on what I do wrong?

 The source of ncurses and readline are placed in $HOME/src.
 Both packages are installed in $HOME/local

 Thanks for any advice,

 Regards,
 Benedict

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

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


Code review request

2010-12-22 Thread Jason Staudenmayer
Hi All,
I'm a python newbie so please be kind. I've been reading book after book and 
have written a script or two but this is my first real program. Just looking 
for any suggestions and pointers. I've done some work with bash scripts and php 
(not OOP) a while a go. I'm not a programmer but would like to possibly expand 
in to it (right now an IT guy). Am I on the right track so far?

The program should be documented enough to explain.


Created on Tue Dec 21 13:39:41 2010
@author: jason

Usage: cmd_drug_testing.py [options]...
Will select a random employee from the local database (located in the current 
directory)
and display the name by default.

This program (Drug Testing) was written to help select employees for drug 
testing.
Program usage:

-h, --help   Displays this help info
-l, --list-emplysLists all employees in the database
-s, --select Select employee for testing
-r, --remove-emply   Delete employee from database, usage: -d 
employee_name or id
-e, --edit-emply Edit employee data in database, usage: -e 
employee_name or id 
   field_to_change new_value
-i, --insert-emply   Insert new employee in database: 
must fit this format -- id:or '','lastname, 
firstname', 'email',0
-f   Display database name and full path

This program was written by, Jason S. For the use of AA.



# import our needed modules
import sqlite3 as sqlite
import sys, getopt

#set global vars
global cursor
global conn


def usage():
 this just prints the usage in the doc string
print __doc__

def dbconnect(sql):
handel the connction to the sqlite db  
dbConnection = sqlite.connect(drug-test.db)
#set the cursor
cursor = dbConnection.cursor()
try:
#execute the sql passed from the other funtions and return the results
result = cursor.execute(sql)
dbConnection.commit()
except sqlite.Error, e:
result = e.args[0]

return result

  
def listEmployees(sql):
#list all records in the database
listemp = dbconnect(sql)
for lst in listemp:
print %s, %s, %s, %s % (lst[0],lst[1],lst[2],lst[3])

def selectOneEmployee(sql):
#select a random record from the database
listemp = dbconnect(sql)
for empl in listemp:
print empl[0]

def removeOneEmployee(sqlchk,sqldel):
#delete one employee by ID number
chk = dbconnect(sqlchk)

if chk.fetchone() != None:
#check to make sure the ID is valid in the database
emply = dbconnect(sqlchk)
emply = emply.fetchall()
print trying to remove employee %s % (emply)
try:
dbconnect(sqldel)

except sqlite.Error, e:
result = e.args[0]
print result

else:
print Employees ID is invalid, please check the ID number

def insertEmployee(sql):
#insert a new employee into the database
print sql
try:
dbconnect(sql)

except sqlite.Error, e:
result = e.args[0]
print result

def main(argv):
The purpose of this program is to select an empployee from this database 
for random drug
testing. This program can also perform maintainance on same database.
if argv == []:
sql = SELECT name FROM employees ORDER BY RANDOM() LIMIT 1;
print The following employee has been selected\n
selectOneEmployee(sql)

try:
#get the options passed by the user
opts, args = getopt.getopt(argv, 
hlsr:e:i:d,[Help,list-emplys,select,remove-emply=,edit-emply=,insert-emply=])

except getopt.GetoptError:
usage()
sys.exit(2)

#check throught the options and respond accordingly
for opt, arg in opts:
if opt in (-h, --help):
usage()
sys.exit()
elif opt == '-d':
global _debug
_debug = 1
elif opt in (-l, --list-emplys):
sql = select * from employees
listEmployees(sql)
elif opt in (-s,--select):
sql = SELECT name FROM employees ORDER BY RANDOM() LIMIT 1;
print The following employee has been selected\n
selectOneEmployee(sql)
elif opt in (-r,--remove-emply):
if arg == :

sys.exit(You must provice the ID for the employee to remove)
sqlchk = select * from employees where id = \%s\ % (arg)
sqldel = delete from employees where id = \%s\  % (arg)
removeOneEmployee(sqlchk,sqldel)
elif opt in (-i, --insert-emply):
sql = insert into employees values(%s) % (arg)
insertEmployee(sql)

if __name__ == __main__:
main(sys.argv[1:])

## END ###

Thanks everyone.


Jason



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


Re: Catching user switching and getting current active user from root on linux

2010-12-22 Thread mpnordland
ok, I'll give one more chance.
First, to pacify those who hate google groups: What is a good usenet
client?
second, How should I set up this proxy so that when a connection is
made, it request's authentication, and then log's the request, if
authentication is not gotten, how do I have it block (or firewall) the
request? Furthermore, I would like for the proxy to be squid. So all
of the nitty gritty should have to do with squid.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Code review request

2010-12-22 Thread Stefan Sonnenberg-Carstens

Am 22.12.2010 19:34, schrieb Jason Staudenmayer:

Hi All,
I'm a python newbie so please be kind. I've been reading book after book and have written 
a script or two but this is my first real program. Just looking for any 
suggestions and pointers. I've done some work with bash scripts and php (not OOP) a while 
a go. I'm not a programmer but would like to possibly expand in to it (right now an IT 
guy). Am I on the right track so far?

The program should be documented enough to explain.


Created on Tue Dec 21 13:39:41 2010
@author: jason

Usage: cmd_drug_testing.py [options]...
Will select a random employee from the local database (located in the current 
directory)
and display the name by default.

This program (Drug Testing) was written to help select employees for drug 
testing.
Program usage:

 -h, --help   Displays this help info
 -l, --list-emplysLists all employees in the database
 -s, --select Select employee for testing
 -r, --remove-emply   Delete employee from database, usage: -d 
employee_name or id
 -e, --edit-emply Edit employee data in database, usage: -e 
employee_name or id
field_to_change new_value
 -i, --insert-emply   Insert new employee in database:
 must fit this format -- id:or '','lastname, 
firstname', 'email',0
 -f   Display database name and full path

This program was written by, Jason S. For the use of AA.



# import our needed modules
import sqlite3 as sqlite
import sys, getopt

#set global vars
global cursor
global conn


def usage():
  this just prints the usage in the doc string
 print __doc__

def dbconnect(sql):
 handel the connction to the sqlite db  
 dbConnection = sqlite.connect(drug-test.db)
 #set the cursor
 cursor = dbConnection.cursor()
 try:
 #execute the sql passed from the other funtions and return the results
 result = cursor.execute(sql)
 dbConnection.commit()
 except sqlite.Error, e:
 result = e.args[0]

 return result


def listEmployees(sql):
 #list all records in the database
 listemp = dbconnect(sql)
 for lst in listemp:
 print %s, %s, %s, %s % (lst[0],lst[1],lst[2],lst[3])

def selectOneEmployee(sql):
 #select a random record from the database
 listemp = dbconnect(sql)
 for empl in listemp:
 print empl[0]

def removeOneEmployee(sqlchk,sqldel):
 #delete one employee by ID number
 chk = dbconnect(sqlchk)

 if chk.fetchone() != None:
 #check to make sure the ID is valid in the database
 emply = dbconnect(sqlchk)
 emply = emply.fetchall()
 print trying to remove employee %s % (emply)
 try:
 dbconnect(sqldel)

 except sqlite.Error, e:
 result = e.args[0]
 print result

 else:
 print Employees ID is invalid, please check the ID number

def insertEmployee(sql):
 #insert a new employee into the database
 print sql
 try:
 dbconnect(sql)

 except sqlite.Error, e:
 result = e.args[0]
 print result

def main(argv):
 The purpose of this program is to select an empployee from this 
database for random drug
 testing. This program can also perform maintainance on same database.
 if argv == []:
 sql = SELECT name FROM employees ORDER BY RANDOM() LIMIT 1;
 print The following employee has been selected\n
 selectOneEmployee(sql)

 try:
 #get the options passed by the user
 opts, args = getopt.getopt(argv, 
hlsr:e:i:d,[Help,list-emplys,select,remove-emply=,edit-emply=,insert-emply=])

 except getopt.GetoptError:
 usage()
 sys.exit(2)

 #check throught the options and respond accordingly
 for opt, arg in opts:
 if opt in (-h, --help):
 usage()
 sys.exit()
 elif opt == '-d':
 global _debug
 _debug = 1
 elif opt in (-l, --list-emplys):
 sql = select * from employees
 listEmployees(sql)
 elif opt in (-s,--select):
 sql = SELECT name FROM employees ORDER BY RANDOM() LIMIT 1;
 print The following employee has been selected\n
 selectOneEmployee(sql)
 elif opt in (-r,--remove-emply):
 if arg == :

 sys.exit(You must provice the ID for the employee to remove)
 sqlchk = select * from employees where id = \%s\ % (arg)
 sqldel = delete from employees where id = \%s\  % (arg)
 removeOneEmployee(sqlchk,sqldel)
 elif opt in (-i, --insert-emply):
 sql = insert into employees values(%s) % (arg)
 insertEmployee(sql)

if __name__ == __main__:
 main(sys.argv[1:])

## END ###

Thanks everyone.


Jason



..·º

Hi Jason,

the 

RE: Code review request

2010-12-22 Thread Gerald Britton
Hi Jason,

There are a couple of things that I noticed:

1. You might want to check out PEP 8  -- a Python style guide.  Among
other things, some lines are very long and you are not consistent with
putting a space after a comma in a list or between arguments in a
function call.

e.g.

opts, args = getopt.getopt(argv,
hlsr:e:i:d,[Help,list-emplys,select,remove-emply=,edit-emply=,insert-emply=])

That's 125 characters, not including the indentation!  You can break
it up and even make it more readable like this:

opts, args = getopt.getopt(
   argv,
   hlsr:e:i:d,

[Help,list-emplys,select,remove-emply=,edit-emply=,insert-emply=]
   )

but then the embedded list is still too long.  It can also be split like this:

opts, args = getopt.getopt(
   argv,
   hlsr:e:i:d,
   [Help, list-emplys, select, remove-emply=,
edit-emply=, insert-emply=]
   )

Just do it so that it's easy to read and support.  Notice the commas
are followed by spaces in the list.

In the listEmployees function (check out PEP 8 about naming
conventions, while you're at it!) there is one line that could be
simpler:

print %s, %s, %s, %s % (lst[0],lst[1],lst[2],lst[3])

could be:

print %s, %s, %s, %s % tuple(lst[:4])

or if the number of elements could be more or less, you could even do this:

for item in lst:
  print item,

which should do the same thing (the trailing comma suppresses the new
line) and you'll never have to count the number of items in lst.

You also have some statements like:

sqlchk = select * from employees where id = \%s\ % (arg)

Since a Python list can be enclosed in apostrophes as well as
quotations, you can get the same thing without the escapes:

sqlchk = 'select * from employees where id = %s' % (arg)


Anyway -- just some food for thought.

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


Re: Code review request

2010-12-22 Thread MRAB

 
 Created on Tue Dec 21 13:39:41 2010
 @author: jason

 Usage: cmd_drug_testing.py [options]...
 Will select a random employee from the local database (located in the 
current directory)

 and display the name by default.

 This program (Drug Testing) was written to help select employees for 
drug testing.

 Program usage:

 -h, --help   Displays this help info
 -l, --list-emplysLists all employees in the database
 -s, --select Select employee for testing
 -r, --remove-emply   Delete employee from database, usage: -d 
employee_name or id
 -e, --edit-emply Edit employee data in database, usage: 
-e employee_name or id

field_to_change new_value
 -i, --insert-emply   Insert new employee in database:
 must fit this format -- id:or 
'','lastname, firstname', 'email',0

 -f   Display database name and full path

 This program was written by, Jason S. For the use of AA.

 

 # import our needed modules
 import sqlite3 as sqlite
 import sys, getopt

 #set global vars
 global cursor
 global conn


By default, if you bind (assign) to a name inside a function then Python 
assumes that the name is local to the function, unless you tell it 
otherwise with global. Using global outside a function has no effect.


 def usage():
  this just prints the usage in the doc string
 print __doc__

 def dbconnect(sql):
 handel the connction to the sqlite db  

handel the connction - handle the connection

 dbConnection = sqlite.connect(drug-test.db)
 #set the cursor
 cursor = dbConnection.cursor()
 try:
 #execute the sql passed from the other funtions and return 
the results


funtions - functions

 result = cursor.execute(sql)
 dbConnection.commit()
 except sqlite.Error, e:
 result = e.args[0]

 return result

The Pythonic way is to return a result when successful and raise an 
exception when unsuccessful.



 def listEmployees(sql):
 #list all records in the database
 listemp = dbconnect(sql)
 for lst in listemp:
 print %s, %s, %s, %s % (lst[0],lst[1],lst[2],lst[3])

I wouldn't pass in an SQL string. I'd pass in only the parameters (if 
any) and hide the SQL details inside the function, something like this:


def listEmployees():
# list all records in the database
dbConnection = sqlite.connect(DB_NAME)
try:
try:
results = dbConnection.execute(select * from employees)
for lst in results:
print %s, %s, %s, %s % (lst[0], lst[1], lst[2], 
lst[3])

except sqlite.Error, e:
print ERROR:, e.args[0]
finally:
dbConnection.close()

I'd also be explicit about the names of the fields in the database in 
case their order changed in a later version.


 def selectOneEmployee(sql):
 #select a random record from the database
 listemp = dbconnect(sql)
 for empl in listemp:
 print empl[0]


def selectOneEmployee():
# select a random record from the database
dbConnection = sqlite.connect(DB_NAME)
try:
try:
results = dbConnection.execute(SELECT name FROM 
employees ORDER BY RANDOM() LIMIT 1;)

print The following employee has been selected\n
for empl in results:
print empl[0]
except sqlite.Error, e:
print ERROR:, e.args[0]
finally:
dbConnection.close()

 def removeOneEmployee(sqlchk,sqldel):
 #delete one employee by ID number
 chk = dbconnect(sqlchk)

 if chk.fetchone() != None:
 #check to make sure the ID is valid in the database
 emply = dbconnect(sqlchk)
 emply = emply.fetchall()
 print trying to remove employee %s % (emply)
 try:
 dbconnect(sqldel)

 except sqlite.Error, e:
 result = e.args[0]
 print result

 else:
 print Employees ID is invalid, please check the ID number


 sqlchk =
 sqldel = delete from employees where id = \%s\  % (arg)

I'd do:

def removeOneEmployee(emplyId):
# delete one employee by ID number
dbConnection = sqlite.connect(DB_NAME)
try:
try:
# check to make sure the ID is valid in the database
results = dbConnection.execute(select * from employees 
where id = %s, (emplyId, ))

if results.fetchone():
print trying to remove employee %s % emplyId
dbConnection.execute(delete from employees where 
id = %s, (emplyId, ))

dbConnection.commit()
else:
print Employees ID is invalid, please check the ID 
number

except sqlite.Error, e:

RE: [SPAM] - Re: Code review request

2010-12-22 Thread Jason Staudenmayer

-Original Message-
From: python-list-bounces+jasons=adventureaquarium@python.org 
[mailto:python-list-bounces+jasons=adventureaquarium@python.org] On Behalf 
Of Stefan Sonnenberg-Carstens
Sent: Wednesday, December 22, 2010 3:24 PM
To: python-list@python.org
Subject: [SPAM] - Re: Code review request


Am 22.12.2010 19:34, schrieb Jason Staudenmayer: 
Hi All,
snip

Hi Jason,

the program could be more dense.
You have several redundant code in there, too.

For example, all the *Employee functions basically just call dbconnect and let
it execute the sql there.
dbconnect in this respect is not a really straight name, as it does more than 
only
connect to a database.

You should avoid != None, better is is not None.

The program flow is awkward: if argv is empty (better say if not argv),
you show one employee, but then continue to parse opts.
I think the program would be more readable, if you would just handle
the different cases in an if-elseif-else-cascade.
The global statement is not needed,

But you can also try pylint, which will point some things out:


Report
78 statements analysed.
snip

Thanks for the advice, I'll try to rework some of those issues. I did try the 
if-elif-else for the getopts but it didn't flow right for some reason (I'll try 
it again though).

Thanks again.

Jason
 
 
 
..·º

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


Re: Newbie question about importing modules.

2010-12-22 Thread cronoklee
On Wed, Dec 22, 2010 at 7:57 PM, Tim Roberts ti...@probo.com wrote:
cronoklee wrote:

 Thanks Tim - You've certainly shed some light. I presume the PIL
 installer is setup.py and installation is simple a case of running it?

Yes:
   python setup.py install

That scheme is called distutils.  Since it became part of the standard
Python distribution many years ago, it is now ubiquitous.

 Is this usually the case for python 'source distribution' packages?

Yes.  In the Linux world, with a few exceptions, EVERY Python add-on
package is installed that way.  In the Windows world, most smaller
packages come that way.  Larger packages will have an MSI installer that
does essentially the same thing.

Once in a while, you'll download a script that consists only of a single
file.  That would really be the only exception.

 Is there a term for packages that do not need to be installed? This
 might help me search for them in future.

I don't think that's the right answer.  The installation process is
rarely more complicated than copying files to the site-packages
directory of your current Python version.  The installer can verify
dependencies and make sure everything is OK.  It's a Good Thing.

--
Tim Roberts




Thanks a lot Tim - all makes sense. I appreciate the lesson!
cronoklee
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Modifying an existing excel spreadsheet

2010-12-22 Thread John Machin
On Dec 21, 8:56 am, Ed Keith e_...@yahoo.com wrote:
 I have a user supplied 'template' Excel spreadsheet. I need to create a new 
 excel spreadsheet based on the supplied template, with data filled in.

 I found the tools 
 herehttp://www.python-excel.org/, andhttp://sourceforge.net/projects/pyexcelerator/.
  I have been trying to use the former, since the latter seems to be devoid of 
 documentation (not even any docstrings).

pyExcelerator is abandonware. Use xlwt instead; it's a bug-fixed/
maintained/enhanced fork of pyExcelerator

Read the tutorial that you'll find mentioned on http://www.python-excel.org

Join the google group that's also mentioned there; look at past
questions, ask some more, ...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Catching user switching and getting current active user from root on linux

2010-12-22 Thread Emile van Sebille

On 12/22/2010 11:28 AM mpnordland said...

ok, I'll give one more chance.


... which probably won't be enough -- this is potentially a huge 
question you're asking with lots of little bits to put together.  I have 
an installation where I did somthing similar seven-ish years ago using 
squid, squidguard, blacklists from Université Toulouse in France, 
python, iptables, sql, php, zope, bash, and who knows what else.  It 
authenticates, logs, tracks, blocks, unblocks, reports activity on an 
automated In and Out board by user, provides historical stats, automates 
new user setup and invalidation, and probably more.  I put maybe a week 
or two into it initially, and about the same again over the years adding 
to it.



First, to pacify those who hate google groups: What is a good usenet
client?


I use thunderbird to access gmane groups.


second, How should I set up this proxy so that when a connection is
made, it request's authentication, and then log's the request, if
authentication is not gotten, how do I have it block (or firewall) the
request? Furthermore, I would like for the proxy to be squid. So all
of the nitty gritty should have to do with squid.


... and that's where I'd start looking.  Check out the current status of 
Squid to see how much of what you want can be done out of the box.  When 
you hit the limits of what it'll do for you, start writing glue to fill 
in the puzzle.


HTH,

Emile



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


Re: Catching user switching and getting current active user from root on linux

2010-12-22 Thread Steve Holden
On 12/22/2010 2:28 PM, mpnordland wrote:
 ok, I'll give one more chance.
 First, to pacify those who hate google groups: What is a good usenet
 client?

Thunderbird is OK for me (I follow about three groups normally). I
access the comp.lang.python group vie the Gmane (Main) service, where
for some strange resaon best known to the gmane admins it is called
gmane.comp.python.general. Ho, hum.

I seem to remember Outlook Express was a fairly decent NNTP client as
well, and Tim Peters says I'm not just blowing smoke up your ass.

 second, How should I set up this proxy so that when a connection is
 made, it request's authentication, and then log's the request, if
 authentication is not gotten, how do I have it block (or firewall) the
 request? Furthermore, I would like for the proxy to be squid. So all
 of the nitty gritty should have to do with squid.

I would recommend you take a look at the Spambayes code, which does all
that sort of stuff apparently quite reliably.

If you aren't yet proficient enough with Python to understand the code
on your own look for a Python Meetup or a local or regional conference
to meet people who will helpyou answer your questions.

Increasingly there are workspaces like HacDC springing up to give people
access to advanced technologies at everyday prices. You could look for
such a group locally. There's lots of energy from people once they
realise that what gets built can help them.

Squid is a different matter. For that, probably if you go on an IRC
channel (freenode.net is what I use, but others have their favorites).
Maybe #squid?

regards
 Steve
-- 
Steve Holden   +1 571 484 6266   +1 800 494 3119
PyCon 2011 Atlanta March 9-17   http://us.pycon.org/
See Python Video!   http://python.mirocommunity.org/
Holden Web LLC http://www.holdenweb.com/

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


Python Web App

2010-12-22 Thread Sean
Anybody know where I can find a Python Development Environment in the
form of a web app for use with Chrome OS. I have been looking for a
few days and all i have been able to find is some old discussions with
python developers talking about they will want one for the OS to be a
success with them.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question regarding Higher-Order-Programming in Python

2010-12-22 Thread Arnaud Delobelle
Mark Fink m...@mark-fink.de writes:

 so far I have never noticed chain.from_iterable, but many thanks to
 you Peter, I have now a beautiful solution to this problem.
 from itertools import chain
 comb = it.combinations(dims, 2)
 l = chain.from_iterable(it.imap(get_products, comb))

You can also write this as:

l = (p for c in comb for p in get_products(c))

 l.next()
 [('special', '+'), ('number', 1)]
 l.next()
 [('special', '+'), ('number', 2)]

Also in your original post you define get_products:

 def get_products(keys):
 ... # helper to get products from keys in the following form:
 ... # [('bold', True), ('color', 'black')]
 ... values  = itemgetter(*keys)(dims)
 ... product = it.product(*values)
 ... return map(partial(zip, keys), product)
 ...

You could define it as e.g.

def get_products(keys):
key_values = [[(k, v) for v in values] for k in keys]
return it.product(*key_values)

But maybe for some reason you are trying to avoid list comprehensions
and generator expressions?

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


Re: How to pop the interpreter's stack?

2010-12-22 Thread Carl Banks
On Dec 22, 8:52 am, kj no.em...@please.post wrote:
 In mailman.65.1292517591.6505.python-l...@python.org Robert Kern 
 robert.k...@gmail.com writes:

 Obfuscating the location that an exception gets raised prevents a lot of
 debugging...

 The Python interpreter does a lot of that obfuscation already, and I
 find the resulting tracebacks more useful for it.

 An error message is only useful to a given audience if that audience
 can use the information in the message to modify what they are
 doing to avoid the error.

So when the audience files a bug report it's not useful for them to
include the whole traceback?

  It is of no use (certainly no *immediate*
 use) to this audience to see tracebacks that go deep into code that
 they don't know anything about and cannot change.

Seriously, quit trying to do the user favors.  There's nothing that
pisses me off than a self-important developer thinking he knows what
the user wants more than the user does.


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


Re: Catching user switching and getting current active user from root on linux

2010-12-22 Thread Steven D'Aprano
On Mon, 20 Dec 2010 20:35:54 -0500, Steve Holden wrote:

 On 12/20/2010 12:54 PM, mpnordland wrote:
 I give up, I will never try to use a usenet group again. For the ones
 of you who tried to help thank you. You helped to identify some of my
 troubles, as for you @usernet, you are a troll
 
 Don't give up after one experience. Usenet can be really useful as long
 as you know who to listen to and who to ignore ...


More importantly, Usenet can be very useful so long as you know how to 
ask smart questions. If you insist on asking stupid questions, you will 
rapidly get disillusioned: people will either ignore you, abuse you, or 
give you helpful advice that you don't want to hear.




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


Re: Catching user switching and getting current active user from root on linux

2010-12-22 Thread Stefan Sonnenberg-Carstens

Am 22.12.2010 20:28, schrieb mpnordland:

ok, I'll give one more chance.
First, to pacify those who hate google groups: What is a good usenet
client?
second, How should I set up this proxy so that when a connection is
made, it request's authentication, and then log's the request, if
authentication is not gotten, how do I have it block (or firewall) the
request? Furthermore, I would like for the proxy to be squid. So all
of the nitty gritty should have to do with squid.
Just install Squid, enable user authentication and grant access only to 
authenticated people.
Now, configure logrotated and tell to rotate logs every day/week/month 
(your mileage will vary).
After rotating run a program such as webalizer to get stats (even on a 
per user basis).
If you have smart guys under your users, set up a) a transparent proxy 
intercepting http/https requests

or b) set up a iptables firewall with redirection to the squid port.

There are many, many, many how-to documents on the net describing 
exactly what you want to do.


A first starting point could be 
http://www.comfsm.fm/computing/squid/FAQ.html


And your problems are solved a long time ago:

http://www.faqs.org/docs/Linux-mini/TransparentProxy.html

And, the most important thing:

Check your local laws for this intention.
Some, like our german law, require these things to be under clear rules.

Cheers

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


Re: Trying to parse a HUGE(1gb) xml file

2010-12-22 Thread John Nagle

On 12/20/2010 12:33 PM, Adam Tauno Williams wrote:

On Mon, 2010-12-20 at 12:29 -0800, spaceman-spiff wrote:

I need to detect them  then for each 1, i need to copy all the
content b/w the element's start  end tags  create a smaller xml
file.


Yep, do that a lot; via iterparse.


1. Can you point me to some examples/samples of using SAX,
especially , ones dealing with really large XML files.


   I've just subclassed HTMLparser for this.  It's slow, but
100% Python.  Using the SAX parser is essentially equivalent.
I'm processing multi-gigabyte XML files and updating a MySQL
database, so I do need to look at all the entries, but don't
need a parse tree of the XML.


SaX is equivalent to iterparse (iterpase is a way, to essentially, do
SaX-like processing).


   Iterparse does try to build a tree, although you can discard the
parts you don't want.  If you can't decide whether a part of the XML
is of interest until you're deep into it, an iterparse approach
may result in a big junk tree.  You have to keep clearing the root
element to discard that.


I provided an iterparse example already. See the Read_Rows method in
http://coils.hg.sourceforge.net/hgweb/coils/coils/file/62335a211fda/src/coils/foundation/standard_xml.py


   I don't quite see the point of creating a class with only static 
methods.  That's basically a verbose way to create a module.



2.This brings me to another q. which i forgot to ask in my OP(original post).
Is simply opening the file,  using reg ex to look for the element i need, a 
*good* approach ?


No.


   If the XML file has a very predictable structure, that may not be
a bad idea.  It's not very general, but if you have some XML file
that's basically fixed format records using XML to delimit the
fields, pounding on the thing with a regular expression is simple
and fast.

John Nagle


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


Re: issubclass(dict, Mapping)

2010-12-22 Thread Terry Reedy

On 12/22/2010 9:20 AM, kj wrote:


from collections import Mapping


Documented as an *ABSTRACT* base class. ABCs were added in 3.0 and 
backparted to 2.7. One can be quite competant in Python completely 
ignoring ABCs.



issubclass(dict, Mapping)

True


Yes, dict is a concrete Mapping class. I suppose we could have instead 
added a new builtin function 'isconcretetizationof' but is seemed easier 
to reuse issubclass for the test. Most people have no problem with that.



dict.__bases__

(type 'object',)


The one and only *CONCRETE* base class. In 3.x, all classes are 
subclasses of object, which simplifies the class model a bit.



[issubclass(b, Mapping) for b in dict.__bases__]

[False]



So dict is a subclass of Mapping, even though none of the bases of
dict is either Mapping or a subclass of Mapping.  Great.


Right. dict is direct concrete Mapping implementation and not subclassed 
from one.


The main reason for introducing ABCs was to make it easier to test 
whether an object passed to a function is an instance of a possibly 
unknown or yet-to-be-written class in an abstract category, which has a 
certain api or interface. The actual usage of an ABC would be more like 
this:


from collections import Mapping
def f(m):
if not isinstance(m, Mapping):
raise ValueError('input is not a mapping')
else: return True

f(dict())
# True
f([])
# produces
Traceback (most recent call last):
  File pyshell#8, line 1, in module
f([])
  File pyshell#6, line 3, in f
raise ValueError('input is not a mapping')
ValueError: input is not a mapping

--
Terry Jan Reedy

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


Toy http server

2010-12-22 Thread Stefan Sonnenberg-Carstens

Sorry, this one is cross post.
I posted my question below some time ago to then jython ml, because this
hit me first with jython.
Anyway, time passed, problem not solved.

So, I'd like to know if some of you know where my error lies:


Hi all,

I've played around with some code-kata of mine from the past.
It's a toy http server:

import socket
import select
import sys
import time
srv = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
srv.setblocking(0)
srv.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,True) # Not sure if 
this is needed. I only remember I've started once for some reason. 
Commenting out does no change

if srv:
srv.bind(('',8080))
srv.setblocking(0)
srv.listen(5)
conns = [srv]
buffers = {}
while True:
reader,writer,failed = select.select(conns,conns,[],1)
if failed:
sys.exit(1)

if srv in reader:
client,(ip,port) = srv.accept()
client.setblocking(False)
conns += [client]
for r in reader:
if r is not srv:
data = r.recv(1024)
if not data:
conns.remove(r)
else:
if r in buffers:
buffers[r] += data
else:
buffers[r] = data
for w in writer:
if w is not srv:
if w in buffers and buffers[w][-2:] == '\r\n':
msg = 'HTTP/1.0 200 OK\r\nServer: 
Jython/2.5\r\nContent-type: text/plain\r\n\r\nThe answer is: 42\r\n'

w.send(msg)
w.close() # THIS ONLY WORKS WHEN THIS LINE IS PRESENT
conns.remove(w) # AND THEN THIS IS MUST
buffers[w] = ''

But today I was asking myself why I should always close the socket, and 
if wouldn't be more efficient if

I let it open.
To make a long story short: it does not work.
If I comment out the lines with the comment all upper case,
jython consumes one core in my laptop completely and ab.exe from apache 
bails out after a while.


Changing send() to sendall() did not do the trick.

I've searched the web and did not find anything meaningful.

Perhaps someone here can switch the light on.
--
http://mail.python.org/mailman/listinfo/python-list


Re: issubclass(dict, Mapping)

2010-12-22 Thread Steven D'Aprano
On Wed, 22 Dec 2010 14:20:51 +, kj wrote:

 Here's another example, fresh from today's crop of wonders:
 
 (v. 2.7.0)
 from collections import Mapping
 issubclass(dict, Mapping)
 True
 dict.__bases__
 (type 'object',)
 [issubclass(b, Mapping) for b in dict.__bases__]
 [False]
 
 
 So dict is a subclass of Mapping, even though none of the bases of dict
 is either Mapping or a subclass of Mapping.  Great.

Yes. So what?

(1) What *actual* problem does this cause you? 

(2) Do you have an example of code that breaks because of this?

(3) Do you understand that since the introduction of ABC (abstract base 
classes) in Python 2.6 (I think), isinstance and issubclass checks are 
performed cooperatively? The instance or class are asked if they wish to 
be known as an instance/subclass of the second argument. Classes can 
register themselves as subclasses of (say) Mapping without sharing any 
actual code with Mapping.

This is a good thing, and the problem isn't that the abstraction leaks, 
as you believe, but the opposite: you're *ignoring* the abstraction and 
looking for concrete details that may or may not exist.

I fear that you have fundamentally misunderstood the concept of leaky 
abstraction. It does not mean, as you seem to think, that some concrete 
implementation detail differs between two classes (or functions). It 
means that some difference in behaviour is exposed, that difference being 
irrelevant to the abstraction but nevertheless important in some other 
sense. A contrived example:

class MyList(list):
def __len__(self):
import time
time.sleep(360)
return list.__len__(self)

MyList can be used anywhere a regular list can be used. Functionally the 
two are identical. The abstraction is that MyList is the same as list. 
But the leak is that len(MyList()) is *incredibly* slow.


Coming back to Mapping:

Abstraction: issubclass(dict, Mapping)

One possible concrete implementation detail of how issubclass is 
implemented:
any(base is Mapping for base in dict.__bases__)


The statement dict is a subclass of Mapping is about an abstract 
relationship. It's not necessarily a statement about __bases__.

To give an analogy, if you insist on doing DNA testing to determine 
whether a boy is a son of a man, you're going to be confused and 
distressed every time you find fathers whose sons are genetically 
unrelated to them.


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


Re: Code review request

2010-12-22 Thread Steven Howe

On 12/22/2010 10:34 AM, Jason Staudenmayer wrote:

Hi All,
I'm a python newbie so please be kind. I've been reading book after book and have written 
a script or two but this is my first real program. Just looking for any 
suggestions and pointers. I've done some work with bash scripts and php (not OOP) a while 
a go. I'm not a programmer but would like to possibly expand in to it (right now an IT 
guy). Am I on the right track so far?

The program should be documented enough to explain.


Created on Tue Dec 21 13:39:41 2010
@author: jason

Usage: cmd_drug_testing.py [options]...
Will select a random employee from the local database (located in the current 
directory)
and display the name by default.

This program (Drug Testing) was written to help select employees for drug 
testing.
Program usage:

 -h, --help   Displays this help info
 -l, --list-emplysLists all employees in the database
 -s, --select Select employee for testing
 -r, --remove-emply   Delete employee from database, usage: -d 
employee_name or id
 -e, --edit-emply Edit employee data in database, usage: -e 
employee_name or id
field_to_change new_value
 -i, --insert-emply   Insert new employee in database:
 must fit this format -- id:or '','lastname, 
firstname', 'email',0
 -f   Display database name and full path

This program was written by, Jason S. For the use of AA.



# import our needed modules
import sqlite3 as sqlite
import sys, getopt

#set global vars
global cursor
global conn


def usage():
  this just prints the usage in the doc string
 print __doc__

def dbconnect(sql):
 handel the connction to the sqlite db  
 dbConnection = sqlite.connect(drug-test.db)
 #set the cursor
 cursor = dbConnection.cursor()
 try:
 #execute the sql passed from the other funtions and return the results
 result = cursor.execute(sql)
 dbConnection.commit()
 except sqlite.Error, e:
 result = e.args[0]

 return result


def listEmployees(sql):
 #list all records in the database
 listemp = dbconnect(sql)
 for lst in listemp:
 print %s, %s, %s, %s % (lst[0],lst[1],lst[2],lst[3])

def selectOneEmployee(sql):
 #select a random record from the database
 listemp = dbconnect(sql)
 for empl in listemp:
 print empl[0]

def removeOneEmployee(sqlchk,sqldel):
 #delete one employee by ID number
 chk = dbconnect(sqlchk)

 if chk.fetchone() != None:
 #check to make sure the ID is valid in the database
 emply = dbconnect(sqlchk)
 emply = emply.fetchall()
 print trying to remove employee %s % (emply)
 try:
 dbconnect(sqldel)

 except sqlite.Error, e:
 result = e.args[0]
 print result

 else:
 print Employees ID is invalid, please check the ID number

def insertEmployee(sql):
 #insert a new employee into the database
 print sql
 try:
 dbconnect(sql)

 except sqlite.Error, e:
 result = e.args[0]
 print result

def main(argv):
 The purpose of this program is to select an empployee from this 
database for random drug
 testing. This program can also perform maintainance on same database.
 if argv == []:
 sql = SELECT name FROM employees ORDER BY RANDOM() LIMIT 1;
 print The following employee has been selected\n
 selectOneEmployee(sql)

 try:
 #get the options passed by the user
 opts, args = getopt.getopt(argv, 
hlsr:e:i:d,[Help,list-emplys,select,remove-emply=,edit-emply=,insert-emply=])

 except getopt.GetoptError:
 usage()
 sys.exit(2)

 #check throught the options and respond accordingly
 for opt, arg in opts:
 if opt in (-h, --help):
 usage()
 sys.exit()
 elif opt == '-d':
 global _debug
 _debug = 1
 elif opt in (-l, --list-emplys):
 sql = select * from employees
 listEmployees(sql)
 elif opt in (-s,--select):
 sql = SELECT name FROM employees ORDER BY RANDOM() LIMIT 1;
 print The following employee has been selected\n
 selectOneEmployee(sql)
 elif opt in (-r,--remove-emply):
 if arg == :

 sys.exit(You must provice the ID for the employee to remove)
 sqlchk = select * from employees where id = \%s\ % (arg)
 sqldel = delete from employees where id = \%s\  % (arg)
 removeOneEmployee(sqlchk,sqldel)
 elif opt in (-i, --insert-emply):
 sql = insert into employees values(%s) % (arg)
 insertEmployee(sql)

if __name__ == __main__:
 main(sys.argv[1:])

## END ###

Thanks everyone.


Jason



..·º
you might consider 

Re: Trying to parse a HUGE(1gb) xml file

2010-12-22 Thread Stefan Sonnenberg-Carstens

Am 20.12.2010 20:34, schrieb spaceman-spiff:

Hi c.l.p folks

This is a rather long post, but i wanted to include all the details  everything i 
have tried so far myself, so please bear with me  read the entire boringly long 
post.

I am trying to parse a ginormous ( ~ 1gb) xml file.


0. I am a python  xml n00b, s  have been relying on the excellent beginner book 
DIP(Dive_Into_Python3 by MP(Mark Pilgrim) Mark , if u are readng this, you are AWESOME 
 so is your witty  humorous writing style)


1. Almost all exmaples pf parsing xml in python, i have seen, start off with 
these 4 lines of code.

import xml.etree.ElementTree as etree
tree = etree.parse('*path_to_ginormous_xml*')
root = tree.getroot()  #my huge xml has 1 root at the top level
print root

2. In the 2nd line of code above, as Mark explains in DIP, the parse function 
builds  returns a tree object, in-memory(RAM), which represents the entire 
document.
I tried this code, which works fine for a small ( ~ 1MB), but when i run this 
simple 4 line py code in a terminal for my HUGE target file (1GB), nothing 
happens.
In a separate terminal, i run the top command,  i can see a python process, 
with memory (the VIRT column) increasing from 100MB , all the way upto 2100MB.

I am guessing, as this happens (over the course of 20-30 mins), the tree 
representing is being slowly built in memory, but even after 30-40 mins, 
nothing happens.
I dont get an error, seg fault or out_of_memory exception.

My hardware setup : I have a win7 pro box with 8gb of RAM  intel core2 quad 
cpuq9400.
On this i am running sun virtualbox(3.2.12), with ubuntu 10.10 as guest os, with 
23gb disk space  2gb(2048mb) ram, assigned to the guest ubuntu os.

3. I also tried using lxml, but an lxml tree is much more expensive, as it 
retains more info about a node's context, including references to it's parent.
[http://www.ibm.com/developerworks/xml/library/x-hiperfparse/]

When i ran the same 4line code above, but with lxml's elementree ( using the 
import below in line1of the code above)
import lxml.etree as lxml_etree

i can see the memory consumption of the python process(which is running the code) 
shoot upto ~ 2700mb  then, python(or the os ?) kills the process as it nears 
the total system memory(2gb)

I ran the code from 1 terminal window (screenshot :http://imgur.com/ozLkB.png)
  ran top from another terminal (http://imgur.com/HAoHA.png)

4. I then investigated some streaming libraries, but am confused - there is 
SAX[http://en.wikipedia.org/wiki/Simple_API_for_XML] , the iterparse 
interface[http://effbot.org/zone/element-iterparse.htm]

Which one is the best for my situation ?

Any  all code_snippets/wisdom/thoughts/ideas/suggestions/feedback/comments/ of 
the c.l.p community would be greatly appreciated.
Plz feel free to email me directly too.

thanks a ton

cheers
ashish

email :
ashish.makani
domain:gmail.com

p.s.
Other useful links on xml parsing in python
0. http://diveintopython3.org/xml.html
1. 
http://stackoverflow.com/questions/1513592/python-is-there-an-xml-parser-implemented-as-a-generator
2. http://codespeak.net/lxml/tutorial.html
3. 
https://groups.google.com/forum/?hl=enlnk=gstq=parsing+a+huge+xml#!topic/comp.lang.python/CMgToEnjZBk
4. http://www.ibm.com/developerworks/xml/library/x-hiperfparse/
5.http://effbot.org/zone/element-index.htm
http://effbot.org/zone/element-iterparse.htm
6. SAX : http://en.wikipedia.org/wiki/Simple_API_for_XML



Normally (what is normal, anyway?) such files are auto-generated,
and are something that has a apparent similarity with a database query 
result, encapsuled in xml.

Most of the time the structure is same for every row thats in there.
So, a very unpythonic but fast, way would be to let awk resemble the 
records and write them in csv format to stdout.
then pipe that to your python cruncher of choice and let it do the hard 
work.

The awk part can be done in python, anyway, so could skip that.

And take a look at xmlsh.org, they offer tools for the command line, 
like xml2csv. (Need java, btw).


Cheers

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


Re: simple games w/o pygame

2010-12-22 Thread Rhodri James
On Wed, 22 Dec 2010 16:40:21 -, William Gill nore...@domain.invalid  
wrote:


I am teaching an 11 year old who wants to learn programming.  I chose  
Python, and it is working well.  I seem to remember lots of simple  
script games, like quizzes, number games etc. that would be good for his  
tutorial.  However, now all I can find is more complex games using  
Pygame.  Can anyone help me out here?


Try the numbered worksheets from the Livewires course:  
http://www.livewires.org.uk/python/home  They are aimed at 12-15 year  
olds, but an 11 year old should be able to cope.


--
Rhodri James *-* Wildebeest Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list


Generator question

2010-12-22 Thread Victor Eijkhout
So I have a generator, either as a free function or in a class and I
want to generate objects that are initialized from the generated things.

def generator():
for whatever:
yield something
class Object():
def __init__(self):
self.data = # the next thing from generator

I have not been able to implement this elegantly. For external reasons
the following syntax is unacceptable:

for g in generator():
ob = Object(g)

I really want to be able to write Object() in any location and get a
properly initialized object.

Hints appreciated.

Victor.
-- 
Victor Eijkhout -- eijkhout at tacc utexas edu
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to pop the interpreter's stack?

2010-12-22 Thread kj
In 1f47c36d-a509-4d05-ba79-62b4a534b...@j19g2000prh.googlegroups.com Carl 
Banks pavlovevide...@gmail.com writes:

On Dec 22, 8:52=A0am, kj no.em...@please.post wrote:
 In mailman.65.1292517591.6505.python-l...@python.org Robert Kern rober=
t.k...@gmail.com writes:

 Obfuscating the location that an exception gets raised prevents a lot of
 debugging...

 The Python interpreter does a lot of that obfuscation already, and I
 find the resulting tracebacks more useful for it.

 An error message is only useful to a given audience if that audience
 can use the information in the message to modify what they are
 doing to avoid the error.

 =A0It is of no use (certainly no *immediate*
 use) to this audience to see tracebacks that go deep into code that
 they don't know anything about and cannot change.

So when the audience files a bug report it's not useful for them to
include the whole traceback?

Learn to read, buster.  I wrote *immediate* use.

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


Re: Generator question

2010-12-22 Thread Emile van Sebille

On 12/22/2010 3:15 PM Victor Eijkhout said...

So I have a generator, either as a free function or in a class and I
want to generate objects that are initialized from the generated things.

def generator():
 for whatever:
 yield something
class Object():
 def __init__(self):


How about change to

  def __init__(self, data=generator()):


 self.data = # the next thing from generator



then...

  self.data = data.next()# the next thing from generator

HTH,

Emile




I have not been able to implement this elegantly. For external reasons
the following syntax is unacceptable:

for g in generator():
 ob = Object(g)

I really want to be able to write Object() in any location and get a
properly initialized object.

Hints appreciated.

Victor.



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


Re: Generator question

2010-12-22 Thread Dan Stromberg
On Wed, Dec 22, 2010 at 3:15 PM, Victor Eijkhout s...@sig.for.address wrote:
 So I have a generator, either as a free function or in a class and I
 want to generate objects that are initialized from the generated things.

 def generator():
        for whatever:
                yield something
 class Object():
        def __init__(self):
                self.data = # the next thing from generator

 I have not been able to implement this elegantly. For external reasons
 the following syntax is unacceptable:

 for g in generator():
        ob = Object(g)

 I really want to be able to write Object() in any location and get a
 properly initialized object.

 Hints appreciated.

 Victor.
 --
 Victor Eijkhout -- eijkhout at tacc utexas edu
 --
 http://mail.python.org/mailman/listinfo/python-list


You likely want a class variable:

#!/usr/bin/python

def generator():
i = 0
while True:
yield i
i += 1

class Object:
gen = generator()

def __init__(self):
self.data = Object.gen.next()

def __str__(self):
return str(self.data)

o1 = Object()
o2 = Object()
o3 = Object()

print o1
print o2
print o3
-- 
http://mail.python.org/mailman/listinfo/python-list


using python ftp

2010-12-22 Thread Matt Funk
Hi,

i was wondering whether someone can point me whether the following
already exists.

I want to connect to a server , download various files (for whose name i
want to be able to use a wildcard), and store those files in a given
location on the hard drive. If the file already exists i do not want to
download it.

This seems fairly trivial and i would assume that there should be some
sort of implementation that does this easily but i didn't find anything
googling it.

Otherwise i was going to do it by hand using ftplib:
1) connect to server,
2) change to directory on server
3) get listing
4) match the file pattern i want to the listing
5) check if file already exists
6) download file if matched and doesn't exist

Can anyone offer any advice whether this already done somewhere?

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


Re: Python Web App

2010-12-22 Thread Hidura
I am creating one, is on test, what kind of app do you want create?

2010/12/22, Sean secr...@gmail.com:
 Anybody know where I can find a Python Development Environment in the
 form of a web app for use with Chrome OS. I have been looking for a
 few days and all i have been able to find is some old discussions with
 python developers talking about they will want one for the OS to be a
 success with them.
 --
 http://mail.python.org/mailman/listinfo/python-list


-- 
Enviado desde mi dispositivo móvil

Diego I. Hidalgo D.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Web App

2010-12-22 Thread Tim Harig
On 2010-12-22, Sean secr...@gmail.com wrote:
 Anybody know where I can find a Python Development Environment in the
 form of a web app for use with Chrome OS. I have been looking for a
 few days and all i have been able to find is some old discussions with
 python developers talking about they will want one for the OS to be a
 success with them.

Personally, I think a web app based IDE would be ghastly; but, you might
have a look at Mozilla Skywriter (formerly Bespin):

https://mozillalabs.com/skywriter/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Web App

2010-12-22 Thread Hidura
Why grashtly?

2010/12/22, Tim Harig user...@ilthio.net:
 On 2010-12-22, Sean secr...@gmail.com wrote:
 Anybody know where I can find a Python Development Environment in the
 form of a web app for use with Chrome OS. I have been looking for a
 few days and all i have been able to find is some old discussions with
 python developers talking about they will want one for the OS to be a
 success with them.

 Personally, I think a web app based IDE would be ghastly; but, you might
 have a look at Mozilla Skywriter (formerly Bespin):

 https://mozillalabs.com/skywriter/
 --
 http://mail.python.org/mailman/listinfo/python-list


-- 
Enviado desde mi dispositivo móvil

Diego I. Hidalgo D.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to handle output generated after execution of command/script on host unix machine?

2010-12-22 Thread Dan Stromberg
On Sun, Dec 19, 2010 at 11:38 PM, Darshak Bavishi
bavishi.dars...@gmail.com wrote:
 Hi Experts,
 I am still struggling with handling output generated after execution of
  command/script on host unix machine using windows client machine
 ssh code :
 import sys
 import datetime
 import time
 # setup logging
 paramiko.util.log_to_file('darshak_simple.log')
 ssh=paramiko.SSHClient()
 ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
 ssh.connect(*,username=,password=)
 try:
     stdin,stdout,stderr=ssh.exec_command(BsPlSMProbe -f node -d 
 /var/log/Darshak/3.txt ) // output of this command will be store in
 /var/log/Darshak/ in remote machine
 except:
                                                               {Issue is
 files are generating but remaining blank pls pls help me out of this}
     print check
 time.sleep(10)
 print stdout.readlines()
 a=stdout.readlines()
 print 1
 ssh.close()
 #print stdout.readlines()
 Issue is files are generating but remaining blank pls pls help me out of
 this
 --
 BR
 Darshak Bavishi

 --
 BR
 Darshak Bavishi

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

I've never used paramiko, but I have done some python+ssh.

1) Are you wanting the output from BsPlSMProbe to go to
/var/log/Darshak/3.txt or your print stdout.readlines()?  If you need
both, you'd probably better get a tee in there.

2) If /var/log/Darshak/3.txt is coming up empty, it could mean that
BsPlSMProbe simply produces no output.  What if you ssh into the
server interactively (perhaps using openssh or putty), and your
command from there, as the same user, with the same options?

3) If you want errors as well as normal output in the same place, try
a 21 in your shell command, assuming you're using sh/ksh/bash (POSIX
shell).  You can tell what shell you're in with echo $SHELL.

4) If paramiko allows you to access the exit status of the command,
you probably should retrieve that, not just stdout (and stderr).
Conventionally, if the exit status is 0, things are fine, if they're
nonzero, something's wrong - the oppose of what you see in most other
languages that treat integers as booleans, because there are usually
more ways things can fail than succeed.  In fact, strictly speaking,
the presence or absence of text on stderr is not a good indication of
an error, compared to checking the exit status.

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


general problem when subclassing a built-in class

2010-12-22 Thread kj


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?

In my experience, educated guesswork doesn't get one very far with
this question.

Here's a *toy example*, just to illustrate this last point.

Suppose that one wants to implement a subclass of dict, call it
TSDict, to meet these two design requirements:

1. for each one of its keys, an instance of TSDict should keep a
timestamp (as given by time.time, and accessible via the new method
get_timestamp(key)) of the last time that the key had a value
assigned to it;

2. other than the added capability described in (1), an instance
of TSDict should behave *exactly* like a built-in dictionary.

In particular, we should be able to observe behavior like this:

 d = TSDict((('uno', 1), ('dos', 2)), tres=3, cuatro=4)
 d['cinco'] = 5
 d
{'cuatro': 4, 'dos': 2, 'tres': 3, 'cinco': 5, 'uno': 1}
 d.get_timestamp('uno')
1293046586.644436


OK, here's one strategy, right out of OOP 101:

#---
from time import time

class TSDict(dict):
def __setitem__(self, key, value):
# save the value and timestamp for key as a tuple;
# see footnote [2]
dict.__setitem__(self, key, (value, time()))

def __getitem__(self, key):
# extract the value from the value-timestamp pair and return it
return dict.__getitem__(self, key)[0]

def get_timestamp(self, key):
# extract the timestamp from the value-timestamp pair and return it
return dict.__getitem__(self, key)[1]
#---

This implementation *should* work (again, at least according to
OOP 101), but, in fact, it doesn't come *even close*:

 d = TSDict((('uno', 1), ('dos', 2)), tres=3, cuatro=4)
 d['cinco'] = 5
 d
{'cuatro': 4, 'dos': 2, 'tres': 3, 'cinco': (5, 1293059516.942985), 'uno': 1}
 d.get_timestamp('uno')
Traceback (most recent call last):
  File stdin, line 1, in module
  File /tmp/tsdict.py, line 23, in get_timestamp
return dict.__getitem__(self, key)[1]
TypeError: 'int' object is not subscriptable


From the above you can see that TSDict fails at *both* of the design
requirements listed above: it fails to add a timestamp to all keys in
the dictionary (e.g. 'uno', ..., 'cuatro' didn't get a timestamp), and
get_timestamp bombs; and it also fails to behave in every other
respect exactly like a built-in dict (e.g., repr(d) reveals the
timestamps and how they are kept).


So back to the general problem: to implement a subclass of a built-in
class to meet a given set of design specifications.  Where is the
documentation needed to do this without guesswork?

Given results like the one illustrated above, I can think of only two
approaches (other than scrapping the whole idea of subclassing a
built-in class in the first place):

1) Study the Python C source code for the built-in class in the hopes
   of somehow figuring out what API methods need to be overridden;

2) Through blind trial-and-error, keep trying different implementation
   strategies and/or keep overriding additional built-in class methods
   until the behavior of the resulting subclass approximates
   sufficiently the design specs.

IMO, both of these approaches suck.  Approach (1) would take *me*
forever, since I don't know the first thing about Python's internals,
and even if I did, going behind the documented API like that would
make whatever I implement very likely to break with future releases of
Python.  Approach (2) could also take a very long time (probably much
longer than the implementation would take if no guesswork was
involved), but worse than that, one would have little assurance that
one's experimentation has truly uncovered all the necessary details;
IME, programming-by-guesswork leads to numerous and often nasty bugs.

Is there any other way?

TIA!

~kj


[1] The minimal bit in the question statement is just another way of
specifying a maximal reuse of the built-in's class code.

[2] For this example, I've accessed the parent's methods directly
through dict rather than through super(TSDict, self), just to keep
the code as uncluttered as possible, but the results are the same
if one uses super.

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


Python programming

2010-12-22 Thread Maurice Shih
Dear python-list@python.org,
Thank you for taking the time to listen to my request. I#39;m a 
beginner programmer and I se python 2.6. I am making a program that needs a 
command that can check if a value is in a list. For example to check whether 5 
is in [2, 6, 5,]. Thank you for hearing my request. 
Maurice Shih


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


Re: Python programming

2010-12-22 Thread Benjamin Kaplan
If you're just starting out, look at the Python tutorial
http://docs.python.org/tutorial/index.html

This question is answered in the tutorial- specifically in
http://docs.python.org/tutorial/datastructures.html#more-on-conditions

Also, there's a separate list, the tu...@python.org , for people just
learning python. http://www.python.org/mailman/listinfo/tutor

On Wed, Dec 22, 2010 at 8:22 PM, Maurice Shih rockitout...@yahoo.com wrote:

 Dear python-list@python.org,
 Thank you for taking the time to listen to my request. I'm a beginner 
 programmer and I se python 2.6. I am making a program that needs a command 
 that can check if a value is in a list. For example to check whether 5 is in 
 [2, 6, 5,]. Thank you for hearing my request.
 Maurice Shih

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

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


Re: Python programming

2010-12-22 Thread Noah Hall
The most Pythonic ways of checking if a value is within a list is to use the
in keyword, for example, using your data -
5 in [2, 6, 5]
Which will return True, as 5 is in the list. You can then use this in the
following generic way -
if variable in list:

do_things

Where variable is the varible you wish to seek, and the list is the list you
wish to search.

Might I also suggest that you use the *tut...@*python*.org mailing list,
where people are perhaps more ready to handle this sort of question.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: issubclass(dict, Mapping)

2010-12-22 Thread kj
In 4d127d5e$0$29997$c3e8da3$54964...@news.astraweb.com Steven D'Aprano 
steve+comp.lang.pyt...@pearwood.info writes:

On Wed, 22 Dec 2010 14:20:51 +, kj wrote:

 Here's another example, fresh from today's crop of wonders:
 
 (v. 2.7.0)
 from collections import Mapping
 issubclass(dict, Mapping)
 True
 dict.__bases__
 (type 'object',)
 [issubclass(b, Mapping) for b in dict.__bases__]
 [False]
 
 So dict is a subclass of Mapping, even though none of the bases of dict
 is either Mapping or a subclass of Mapping.  Great.


Yes. So what?

That's being deliberately obtuse.  The situation described goes
smack against standard OOP semantics, which would be fine if all
this stuff was documented clearly and reasonably, i.e. in one
(preferably official) place rather than scattered over a bazillion
separate documents, PEP this, module that, GvR musing #42, etc.

Let's just say that I'm looking forward to the end to these surprises.

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


Re: Toy http server

2010-12-22 Thread MRAB

On 22/12/2010 22:34, Stefan Sonnenberg-Carstens wrote:

Sorry, this one is cross post.
I posted my question below some time ago to then jython ml, because this
hit me first with jython.
Anyway, time passed, problem not solved.

So, I'd like to know if some of you know where my error lies:


[snip]
What happens if the conns list contains a writer that's ready?

The select function returns immediately with that writer in the writer
list. If it's not srv then nothing is done with it, so execution just
loops back to the select function with that writer still in the conns
list, and the select function then returns immediately with that writer
in the writer list again.

Infinite loop!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Web App

2010-12-22 Thread Sean
I am wanting to learn python and I am test a Chrome OS notebook at the
same time so I need something that will atleast tell me if I have any
syntax errors. Although the more features the better that way learning
is an easier experience.

On Dec 22, 7:05 pm, Hidura hid...@gmail.com wrote:
 I am creating one, is on test, what kind of app do you want create?

 2010/12/22, Sean secr...@gmail.com:

  Anybody know where I can find a Python Development Environment in the
  form of a web app for use with Chrome OS. I have been looking for a
  few days and all i have been able to find is some old discussions with
  python developers talking about they will want one for the OS to be a
  success with them.
  --
 http://mail.python.org/mailman/listinfo/python-list

 --
 Enviado desde mi dispositivo móvil

 Diego I. Hidalgo D.

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


Re: Python Web App

2010-12-22 Thread Sean
Forgot to point out that Chrome OS has no local storage accessable to
the user. Hence why I need a web based solution.

On Dec 22, 8:51 pm, Sean secr...@gmail.com wrote:
 I am wanting to learn python and I am test a Chrome OS notebook at the
 same time so I need something that will atleast tell me if I have any
 syntax errors. Although the more features the better that way learning
 is an easier experience.

 On Dec 22, 7:05 pm, Hidura hid...@gmail.com wrote:







  I am creating one, is on test, what kind of app do you want create?

  2010/12/22, Sean secr...@gmail.com:

   Anybody know where I can find a Python Development Environment in the
   form of a web app for use with Chrome OS. I have been looking for a
   few days and all i have been able to find is some old discussions with
   python developers talking about they will want one for the OS to be a
   success with them.
   --
  http://mail.python.org/mailman/listinfo/python-list

  --
  Enviado desde mi dispositivo móvil

  Diego I. Hidalgo D.

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


Re: using python ftp

2010-12-22 Thread Anurag Chourasia
Hi Matt,

I have a snippet to upload files (that match a particular search
pattern) to a remote server.

Variable names are self explanatory. You could tweak this a little to
download files instead.

from ftplib import FTP
ftp = FTP(hostname)
ftp.login(user_id,passwd)
ftp.cwd(remote_directory)
files_list=glob.glob(file_search_pattern)
for file in files_list:
try:
ftp.storlines('STOR ' + file, open(file))
except Exception, e:
print ('Failed to FTP file: %s' %(file))
ftp.close()

Regards,
Anurag

On Thu, Dec 23, 2010 at 5:33 AM, Matt Funk maf...@nmsu.edu wrote:
 Hi,

 i was wondering whether someone can point me whether the following
 already exists.

 I want to connect to a server , download various files (for whose name i
 want to be able to use a wildcard), and store those files in a given
 location on the hard drive. If the file already exists i do not want to
 download it.

 This seems fairly trivial and i would assume that there should be some
 sort of implementation that does this easily but i didn't find anything
 googling it.

 Otherwise i was going to do it by hand using ftplib:
 1) connect to server,
 2) change to directory on server
 3) get listing
 4) match the file pattern i want to the listing
 5) check if file already exists
 6) download file if matched and doesn't exist

 Can anyone offer any advice whether this already done somewhere?

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

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


Re: Python Web App

2010-12-22 Thread Hidura
Use editarea, that's the best option if you want something small, but
as i said before i am developing a framework that allows you to create
app's from the web and is much more complete than editarea.

2010/12/22, Sean secr...@gmail.com:
 I am wanting to learn python and I am test a Chrome OS notebook at the
 same time so I need something that will atleast tell me if I have any
 syntax errors. Although the more features the better that way learning
 is an easier experience.

 On Dec 22, 7:05 pm, Hidura hid...@gmail.com wrote:
 I am creating one, is on test, what kind of app do you want create?

 2010/12/22, Sean secr...@gmail.com:

  Anybody know where I can find a Python Development Environment in the
  form of a web app for use with Chrome OS. I have been looking for a
  few days and all i have been able to find is some old discussions with
  python developers talking about they will want one for the OS to be a
  success with them.
  --
 http://mail.python.org/mailman/listinfo/python-list

 --
 Enviado desde mi dispositivo móvil

 Diego I. Hidalgo D.

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


-- 
Enviado desde mi dispositivo móvil

Diego I. Hidalgo D.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Web App

2010-12-22 Thread Hidura
My framework let you store online on a hosting server that the same
framework provide.

2010/12/22, Hidura hid...@gmail.com:
 Use editarea, that's the best option if you want something small, but
 as i said before i am developing a framework that allows you to create
 app's from the web and is much more complete than editarea.

 2010/12/22, Sean secr...@gmail.com:
 I am wanting to learn python and I am test a Chrome OS notebook at the
 same time so I need something that will atleast tell me if I have any
 syntax errors. Although the more features the better that way learning
 is an easier experience.

 On Dec 22, 7:05 pm, Hidura hid...@gmail.com wrote:
 I am creating one, is on test, what kind of app do you want create?

 2010/12/22, Sean secr...@gmail.com:

  Anybody know where I can find a Python Development Environment in the
  form of a web app for use with Chrome OS. I have been looking for a
  few days and all i have been able to find is some old discussions with
  python developers talking about they will want one for the OS to be a
  success with them.
  --
 http://mail.python.org/mailman/listinfo/python-list

 --
 Enviado desde mi dispositivo móvil

 Diego I. Hidalgo D.

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


 --
 Enviado desde mi dispositivo móvil

 Diego I. Hidalgo D.


-- 
Enviado desde mi dispositivo móvil

Diego I. Hidalgo D.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: using python ftp

2010-12-22 Thread MRAB

On 23/12/2010 02:12, Anurag Chourasia wrote:

Hi Matt,

I have a snippet to upload files (that match a particular search
pattern) to a remote server.

Variable names are self explanatory. You could tweak this a little to
download files instead.

from ftplib import FTP
ftp = FTP(hostname)
ftp.login(user_id,passwd)
ftp.cwd(remote_directory)
files_list=glob.glob(file_search_pattern)
for file in files_list:
 try:
 ftp.storlines('STOR ' + file, open(file))


You should open the file in binary mode:

ftp.storlines('STOR ' + file, open(file, 'rb'))

This isn't necessary on *nix, but it's recommended for portability.


 except Exception, e:
 print ('Failed to FTP file: %s' %(file))
ftp.close()


[snip]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python programming

2010-12-22 Thread Max Countryman
 5 in [2, 6, 5]
True

Sent from my iPhone

On Dec 22, 2010, at 20:22, Maurice Shih rockitout...@yahoo.com wrote:

 Dear python-list@python.org,
 Thank you for taking the time to listen to my request. I'm a beginner 
 programmer and I se python 2.6. I am making a program that needs a command 
 that can check if a value is in a list. For example to check whether 5 is in 
 [2, 6, 5,]. Thank you for hearing my request. 
 Maurice Shih
 
 -- 
 http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python programming

2010-12-22 Thread Anurag Chourasia
Here you go.

$ python
Python 2.5.2 (r252:60911, Dec  2 2008, 09:26:14)
[GCC 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)] on cygwin
Type help, copyright, credits or license for more information.
 A=[2,6,5]
 if 5 in A:
... print 'Yes'
... else:
... print 'No'
...
Yes


Regards,
Anurag

On Thu, Dec 23, 2010 at 6:52 AM, Maurice Shih rockitout...@yahoo.comwrote:

 Dear python-list@python.org,
 Thank you for taking the time to listen to my request. I'm a beginner
 programmer and I se python 2.6. I am making a program that needs a command
 that can check if a value is in a list. For example to check whether 5 is in
 [2, 6, 5,]. Thank you for hearing my request.
 Maurice Shih


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


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


Re: Python Web App

2010-12-22 Thread Tim Harig
[Reordered to preserve context in bottom posting]
On 2010-12-23, Hidura hid...@gmail.com wrote:
 2010/12/22, Tim Harig user...@ilthio.net:
 On 2010-12-22, Sean secr...@gmail.com wrote:
 Anybody know where I can find a Python Development Environment in the
 form of a web app for use with Chrome OS. I have been looking for a
 few days and all i have been able to find is some old discussions with
 python developers talking about they will want one for the OS to be a
 success with them.

 Personally, I think a web app based IDE would be ghastly; but, you might
 have a look at Mozilla Skywriter (formerly Bespin):

 Why grashtly?

I don't personally think the web makes a good framework for highly
interactive applications as they must work within the constraints of the
browser and IDEs are highly interactive applications by their very nature.
Perhaps HTML5/CSS3 will change things; but, standard DOM manipulation,
as I am accustomed to seeing it, cannot generate the kind of rendering
that is available from native applications.  Attempts to do so end up being
kludgy.

It also cannot handle the kinds of desktop integrations that are common
for native applications without opening up serious security trust issues.
(Can everybody say ActiveX fiasco?)

Finally, there are difficulties in handling keystrokes without conflicting
with the browser's native key bindings.  I seldom ever touch a mouse
and I am a huge fan of vi, mutt, slrn, screen, ratpoison, etc. where
the primary interface is totally accessable through the keyboard without
having to tab through many options.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Generator question

2010-12-22 Thread Victor Eijkhout
Dan Stromberg drsali...@gmail.com wrote:

 You likely want a class variable:

Sounds like an elegant solution. Thanks!

Victor.
-- 
Victor Eijkhout -- eijkhout at tacc utexas edu
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Web App

2010-12-22 Thread Hidura
Ok, but you are comparing a web-based framework with a native-based
framework that use the components of the system to make all the things
that need, a web-based framewok use the resourses of the browser to
make it all, so the developer that use a framework on the web can't
expect get the same results, in my case i beleive that a web-based
framework adjust better to the needs if you'll make a web-app,
otherwise use eclipse or netbeans.

2010/12/22, Tim Harig user...@ilthio.net:
 [Reordered to preserve context in bottom posting]
 On 2010-12-23, Hidura hid...@gmail.com wrote:
 2010/12/22, Tim Harig user...@ilthio.net:
 On 2010-12-22, Sean secr...@gmail.com wrote:
 Anybody know where I can find a Python Development Environment in the
 form of a web app for use with Chrome OS. I have been looking for a
 few days and all i have been able to find is some old discussions with
 python developers talking about they will want one for the OS to be a
 success with them.

 Personally, I think a web app based IDE would be ghastly; but, you might
 have a look at Mozilla Skywriter (formerly Bespin):

 Why grashtly?

 I don't personally think the web makes a good framework for highly
 interactive applications as they must work within the constraints of the
 browser and IDEs are highly interactive applications by their very nature.
 Perhaps HTML5/CSS3 will change things; but, standard DOM manipulation,
 as I am accustomed to seeing it, cannot generate the kind of rendering
 that is available from native applications.  Attempts to do so end up being
 kludgy.

 It also cannot handle the kinds of desktop integrations that are common
 for native applications without opening up serious security trust issues.
 (Can everybody say ActiveX fiasco?)

 Finally, there are difficulties in handling keystrokes without conflicting
 with the browser's native key bindings.  I seldom ever touch a mouse
 and I am a huge fan of vi, mutt, slrn, screen, ratpoison, etc. where
 the primary interface is totally accessable through the keyboard without
 having to tab through many options.
 --
 http://mail.python.org/mailman/listinfo/python-list


-- 
Enviado desde mi dispositivo móvil

Diego I. Hidalgo D.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to pop the interpreter's stack?

2010-12-22 Thread Steven D'Aprano
On Wed, 22 Dec 2010 13:53:20 -0800, Carl Banks wrote:

 On Dec 22, 8:52 am, kj no.em...@please.post wrote:
 In mailman.65.1292517591.6505.python-l...@python.org Robert Kern
 robert.k...@gmail.com writes:

 Obfuscating the location that an exception gets raised prevents a lot
 of debugging...

 The Python interpreter does a lot of that obfuscation already, and I
 find the resulting tracebacks more useful for it.

 An error message is only useful to a given audience if that audience
 can use the information in the message to modify what they are doing to
 avoid the error.
 
 So when the audience files a bug report it's not useful for them to
 include the whole traceback?


Well, given the type of error KJ has been discussing, no, it isn't useful.

Fault: function raises documented exception when passed input that
is documented as being invalid

What steps will reproduce the problem?
1. call the function with invalid input
2. read the exception that is raised
3. note that it is the same exception as documented

What is the expected output? What do you see instead?

Excepted somebody to hit me on the back of the head and tell me 
not to call the function with invalid input. Instead I just got 
an exception.


You seem to have completely missed that there will be no bug report, 
because this isn't a bug. (Or if it is a bug, the bug is elsewhere, 
external to the function that raises the exception.) It is part of the 
promised API. The fact that the exception is generated deep down some 
chain of function calls is irrelevant.

The analogy is this: imagine a function that delegates processing of the 
return result to different subroutines:

def func(arg):
if arg  0:
return _inner1(arg)
else:
return _inner2(arg)


This is entirely irrelevant to the caller. When they receive the return 
result from calling func(), they have no way of knowing where the result 
came from, and wouldn't care even if they could. Return results hide 
information about where the result was calculated, as they should. Why 
shouldn't deliberate, explicit, documented exceptions be treated the same?

Tracebacks expose the implementation details of where the exception was 
generated. This is the right behaviour if the exception is unexpected -- 
a bug internal to func -- since you need knowledge of the implementation 
of func in order to fix the unexpected exception. So far so good -- we 
accept that Python's behaviour under these circumstances is correct.

But this is not the right behaviour when the exception is expected, e.g. 
an explicitly raised exception in response to an invalid argument. In 
this case, the traceback exposes internal details of no possible use to 
the caller. What does the caller care if func() delegates (e.g.) input 
checking to a subroutine? The subroutine is an irrelevant implementation 
detail. The exception is promised output of the function, just as much so 
as if it were a return value.

Consider the principle that exceptions should be dealt with as close as 
possible to the actual source of the problem:

 f('good input')
Traceback (most recent call last):
  File stdin, line 1, in module
  File stdin, line 2, in f
  File stdin, line 2, in g
  File stdin, line 2, in h
  File stdin, line 2, in i
  File stdin, line 2, in j
  File stdin, line 2, in k=== error occurs here, and shown here
ValueError


But now consider the scenario where the error is not internal to f, but 
external. The deeper down the stack trace you go, the further away from 
the source of the error you get. The stack trace now obscures the source 
of the error, rather than illuminating it:

 f('bad input')=== error occurs here
Traceback (most recent call last):
  File stdin, line 1, in module
  File stdin, line 2, in f
  File stdin, line 2, in g
  File stdin, line 2, in h
  File stdin, line 2, in i
  File stdin, line 2, in j
  File stdin, line 2, in k=== far from the source of error
ValueError


There's no point in inspecting function k for a bug when the problem has 
nothing to do with k. The problem is that the input fails to match the 
pre-conditions for f. From the perspective of the caller, the error has 
nothing to do with k, k is a meaningless implementation detail, and the 
source of the error is the mismatch between the input and what f expects. 
And so by the principle of dealing with exceptions as close as possible 
to the source of the error, we should desire this traceback instead:


 f('bad input')=== error occurs here
Traceback (most recent call last):
  File stdin, line 1, in module
  File stdin, line 2, in f=== matches where the error occurs
ValueError


In the absence of any practical way for function f to know whether an 
arbitrary exception in a subroutine is a bug or not, the least-worst 
decision is Python's current behaviour: take the conservative, risk-
adverse path and assume the worst, treat the exception as a bug in the 
subroutine, and 

Re: issubclass(dict, Mapping)

2010-12-22 Thread Steven D'Aprano
On Thu, 23 Dec 2010 01:41:08 +, kj wrote:

 In 4d127d5e$0$29997$c3e8da3$54964...@news.astraweb.com Steven D'Aprano
 steve+comp.lang.pyt...@pearwood.info writes:
 
On Wed, 22 Dec 2010 14:20:51 +, kj wrote:
 
 Here's another example, fresh from today's crop of wonders:
 
 (v. 2.7.0)
 from collections import Mapping
 issubclass(dict, Mapping)
 True
 dict.__bases__
 (type 'object',)
 [issubclass(b, Mapping) for b in dict.__bases__]
 [False]
 
 So dict is a subclass of Mapping, even though none of the bases of
 dict is either Mapping or a subclass of Mapping.  Great.
 
 
Yes. So what?
 
 That's being deliberately obtuse.  The situation described goes smack
 against standard OOP semantics, 


What are these standard OOP semantics you're referring to, and who made 
them standard? If people can't even decide whether multiple inheritance 
should be allowed or not, what makes you think that there is any such 
thing as standard OOP?

I think you are confusing concrete implementation details with the 
interface. The interface for subclass testing in Python is as follows:

A class K is a subclass of class C if, and only if, 
issubclass(C, K) returns a true result.


That's it. Everything else is implementation. __bases__ is 
implementation. __subclasscheck__ is implementation. If Python adds a 
third mechanism for implementing subclass checks in version 3.3 or 3.4, 
the interface will just continue to work correctly.



 which would be fine if all this stuff
 was documented clearly and reasonably, i.e. in one (preferably
 official) place rather than scattered over a bazillion separate
 documents, PEP this, module that, GvR musing #42, etc.

This is documented, in the docs.

http://docs.python.org/reference/datamodel.html#customizing-instance-and-subclass-checks

Nobody says the Python docs are perfect, but most things you ask are in 
there. Patches for the docs to improve them are welcome.



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


Re: Python Web App

2010-12-22 Thread Tim Harig
On 2010-12-23, Hidura hid...@gmail.com wrote:
 Ok, but you are comparing a web-based framework with a native-based
 framework that use the components of the system to make all the things
 that need, a web-based framewok use the resourses of the browser to

Right.  That is exactly what I am comparing.

 make it all, so the developer that use a framework on the web can't
 expect get the same results, in my case i beleive that a web-based

Which is exactly the problem with web apps that are highly interactive.  My
suggestion, is not to develope a web based IDE or use one.  It just isn't
something that the web was designed to do well.

 expect get the same results, in my case i beleive that a web-based
 framework adjust better to the needs if you'll make a web-app,

Most IDEs that are targeted at web developement have a built in web browser
or strong integration with one to run the web app as you are developing it.
I don't see any advantage or the necessity of actually running the IDE code
itself in the browser.

 otherwise use eclipse or netbeans.

I would; but then, I wouldn't purchase an operating system that is entirely
based on a web browser.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Re: Python Web App

2010-12-22 Thread hidura

Which is exactly the problem with web apps that are highly interactive. My
suggestion, is not to develope a web based IDE or use one. It just isn't
something that the web was designed to do well.


Is not a problem of the IDE, the problem is on what the developer expect
as i said i you want something to the desktop well use an IDE that creates
apps for desktop, but if you need something for the web you can try on a
web-based IDE.

Most IDEs that are targeted at web developement have a built in web  
browser
or strong integration with one to run the web app as you are developing  
it.
I don't see any advantage or the necessity of actually running the IDE  
code

itself in the browser.


That's the problem an integration with one, my IDE works on all of them and
the result is the same in IE and Chrome or FF, a web page cannot be designed
to one browser it has to be designed to all the browser and have to be  
same. On
the visualization is more difficult but nobody could control perfectly that  
but on

the results of the data is has to be the same.

I would; but then, I wouldn't purchase an operating system that is  
entirely

based on a web browser.


I support that, but the target of those OS are use the share resources of  
the pc,

smartphone, etc and the server.


On Dec 22, 2010 11:54pm, Tim Harig user...@ilthio.net wrote:

On 2010-12-23, Hidura hid...@gmail.com wrote:



 Ok, but you are comparing a web-based framework with a native-based



 framework that use the components of the system to make all the things



 that need, a web-based framewok use the resourses of the browser to





Right. That is exactly what I am comparing.





 make it all, so the developer that use a framework on the web can't



 expect get the same results, in my case i beleive that a web-based





Which is exactly the problem with web apps that are highly interactive. My



suggestion, is not to develope a web based IDE or use one. It just isn't



something that the web was designed to do well.





 expect get the same results, in my case i beleive that a web-based



 framework adjust better to the needs if you'll make a web-app,




Most IDEs that are targeted at web developement have a built in web  
browser


or strong integration with one to run the web app as you are developing  
it.


I don't see any advantage or the necessity of actually running the IDE  
code



itself in the browser.





 otherwise use eclipse or netbeans.




I would; but then, I wouldn't purchase an operating system that is  
entirely



based on a web browser.



--



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


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


Re: Python programming

2010-12-22 Thread Dan Stromberg
If it's a big list and you're checking multiple times, you're probably
better off converting the list to a set, and using in on the set.  Once
you have your list converted to a set, you can update both quickly.

On Wed, Dec 22, 2010 at 5:22 PM, Maurice Shih rockitout...@yahoo.comwrote:

 Dear python-list@python.org,
 Thank you for taking the time to listen to my request. I'm a beginner
 programmer and I se python 2.6. I am making a program that needs a command
 that can check if a value is in a list. For example to check whether 5 is in
 [2, 6, 5,]. Thank you for hearing my request.
 Maurice Shih


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


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


Re: simple games w/o pygame

2010-12-22 Thread scattered
On Dec 22, 11:40 am, William Gill nore...@domain.invalid wrote:
 I am teaching an 11 year old who wants to learn programming.  I chose
 Python, and it is working well.  I seem to remember lots of simple
 script games, like quizzes, number games etc. that would be good for his
 tutorial.  However, now all I can find is more complex games using
 Pygame.  Can anyone help me out here?

Maybe you can check out the book Python Programming for the Absolute
Beginner, 3rd Edition by Michael Dawson. Its emphasis is on simple
games. My son is (who is older - just turned 17) is working through it
now and finding it easy going.

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


Re: compiling Python 2.7.1 with readline module fails on Debian (Virtualbox)

2010-12-22 Thread Benedict Verheyen
On 22/12/2010 18:57, Jim Pharis wrote:
 are you running make clean for good measure?

Yes, i am.

I am gong to try and uninstall Python2.7 from $HOME/local and see
if that makes a difference. Maybe it interferes with the build process?

Regards,
Benedict

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


[issue9017] doctest option flag to enable/disable some chunk of doctests?

2010-12-22 Thread Éric Araujo

Changes by Éric Araujo mer...@netwok.org:


--
nosy: +eric.araujo
stage: unit test needed - needs patch
versions: +Python 3.3 -Python 3.2

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9017
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10755] Add posix.fdlistdir

2010-12-22 Thread Martin v . Löwis

Martin v. Löwis mar...@v.loewis.de added the comment:

What's the use case for this function?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue10755
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9085] Version number inconsistency in email package

2010-12-22 Thread Éric Araujo

Éric Araujo mer...@netwok.org added the comment:

If there is no further discussion, I’d say the original bug is fixed anc this 
report should be closed.

--
nosy: +eric.araujo

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9085
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8847] crash appending list and namedtuple

2010-12-22 Thread Éric Araujo

Changes by Éric Araujo mer...@netwok.org:


--
nosy: +eric.araujo

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue8847
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10755] Add posix.fdlistdir

2010-12-22 Thread Ross Lagerwall

Ross Lagerwall rosslagerw...@gmail.com added the comment:

When maintaining an fd to implement a per thread current directory, you can use 
it to get a list of files in the directory.

For security reasons, instead of a named path, you can keep an fd to a 
directory so that if the path is changed externally while performing an 
operation, the open fd still points to the original directory. This function 
then allows you to list the contents of that fd. I think this is needed for 
#4489.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue10755
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8885] markupbase declaration errors aren't recoverable

2010-12-22 Thread Éric Araujo

Changes by Éric Araujo mer...@netwok.org:


--
nosy: +eric.araujo
resolution: invalid - 
stage:  - needs patch
title: markerbase declaration errors aren't recoverable - markupbase 
declaration errors aren't recoverable
versions: +Python 2.7 -Python 2.6

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue8885
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8964] platform._sys_version does not parse correctly IronPython 2.x version

2010-12-22 Thread Éric Araujo

Éric Araujo mer...@netwok.org added the comment:

Do you want to work on a patch?

--
nosy: +eric.araujo
stage:  - needs patch
title: Method _sys_version() module Lib\platform.py does not parse  
correctly IronPython 2.x version - platform._sys_version does not parse 
correctly IronPython 2.x version
versions: +Python 2.7, Python 3.1, Python 3.2 -Python 2.6

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue8964
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9074] subprocess closes standard file descriptors when it should not

2010-12-22 Thread Éric Araujo

Changes by Éric Araujo mer...@netwok.org:


--
keywords: +needs review
nosy: +astrand
stage:  - patch review
title: [includes patch] subprocess module closes standard file descriptors when 
it should not - subprocess closes standard file descriptors when it should not
versions: +Python 2.7, Python 3.1, Python 3.2 -Python 2.6

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9074
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4489] shutil.rmtree is vulnerable to a symlink attack

2010-12-22 Thread Éric Araujo

Changes by Éric Araujo mer...@netwok.org:


--
nosy: +eric.araujo
stage:  - needs patch
versions: +Python 2.5

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue4489
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9399] Provide a 'print' action for argparse

2010-12-22 Thread Éric Araujo

Éric Araujo mer...@netwok.org added the comment:

Thinking again about that, what’s wrong with argparse replacing \n with spaces 
and doing its own line wrapping?

--
versions: +Python 3.3 -Python 3.2

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9399
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8754] ImportError: quote bad module name in message

2010-12-22 Thread Georg Brandl

Georg Brandl ge...@python.org added the comment:

I suppose it's not a good test, since your non-ascii name presumably was 
encoded in UTF-8, which is the encoding that PyUnicode_FromString uses.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue8754
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4761] create Python wrappers for openat() and others

2010-12-22 Thread Georg Brandl

Georg Brandl ge...@python.org added the comment:

Reference counting is not always correct.  For example, in unlinkat

if (res  0)
return posix_error();
Py_DECREF(opath);
(return None)

the DECREF should be before the error check.  (Note that you can use the 
Py_RETURN_NONE macro to save INCREF'ing Py_None explicitly.)

Sometimes you use posix_error, sometimes posix_error_with_allocated_filename; 
is that deliberate?

Also, the documentation for each function should get .. versionadded:: 3.3 
tags.

Otherwise, this looks good and ready for inclusion when py3k is open for new 
features again.

--
nosy: +georg.brandl

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue4761
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4761] create Python wrappers for openat() and others

2010-12-22 Thread Ross Lagerwall

Ross Lagerwall rosslagerw...@gmail.com added the comment:

New patch *should* have fixed up reference counting and version tags.

I standardized all the error calls to posix_error.

--
Added file: http://bugs.python.org/file20137/i4761_v4.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue4761
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10757] zipfile.write, arcname should be bytestring

2010-12-22 Thread Jacek Jabłoński

New submission from Jacek Jabłoński conexion2...@gmail.com:

file = 'somefile.dat'
filename = ółśąśółąś.dat
zip = zipfile.ZipFile('archive.zip', 'w', zipfile.ZIP_DEFLATED)
zip.write(file, filename)

above produces very nasty filename in zip archive.
*
file = 'somefile.dat'
filename = ółśąśółąś.dat
zip = zipfile.ZipFile('archive.zip', 'w', zipfile.ZIP_DEFLATED)
zip.write(file, filename.encode('cp852'))

this produces TypeError: expected an object with the buffer interface

Documentation says that:
There is no official file name encoding for ZIP files. If you have unicode file 
names, you must convert them to byte strings in your desired encoding before 
passing them to write().

I convert them to byte string but it ends with an error.
If it is documentation bug, what is the proper way to have filenames like 
ółśąśółąś in zip archive?

--
components: Library (Lib)
messages: 124499
nosy: connexion2000
priority: normal
severity: normal
status: open
title: zipfile.write, arcname should be bytestring
type: compile error
versions: Python 3.1

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue10757
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10758] posix_access swallows all errors

2010-12-22 Thread Georg Brandl

New submission from Georg Brandl ge...@python.org:

access(2) can return errnos that correspond to input errors or general system 
faults, such as EINVAL, EIO or ENOMEM.  In this case, an exception should be 
raised instead of returning False.

It is probably best to whitelist those errnos that indicate missing access -- 
it needs to be discussed whether that is just EACCES, or also e.g. ENOENT.

--
components: Library (Lib)
messages: 124500
nosy: georg.brandl
priority: normal
severity: normal
stage: needs patch
status: open
title: posix_access swallows all errors
type: behavior
versions: Python 2.7, Python 3.1, Python 3.2

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue10758
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4761] create Python wrappers for openat() and others

2010-12-22 Thread Georg Brandl

Georg Brandl ge...@python.org added the comment:

Thanks for the update! Three more comments:

* the new constants doc should also get a versionadded

* faccessat should check for EBADF, EINVAL and ENOTDIR and raise an error if 
they are returned, since these are input errors 

  Or, alternately, a range of errnos should be whitelisted for both access and 
faccessat.

  However, this problem should be handled in a separate issue, I've opened 
#10758 for that.

* The octal modes in docstrings and docs should be specified in Python 3 octal 
syntax, e.g. 0o777.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue4761
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9990] PyMemoryView_FromObject alters the Py_buffer after calling PyObject_GetBuffer when ndim 1

2010-12-22 Thread Mark Dickinson

Mark Dickinson dicki...@gmail.com added the comment:

Antoine, a couple of questions:

(1) Is there documentation for the 'smalltable' field of the Py_buffer struct 
anywhere?  What are the requirements for the exporter here?  E.g., is it / 
should it be a requirement that shape, strides and suboffsets are all NULL 
whenever 'smalltable' is used?

(2) Same question for the 'obj' field:  what's the purpose of this field, from 
the POV of 3rd party buffer exporters?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9990
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



  1   2   >