Re: Which non SQL Database ?

2010-12-05 Thread John Nagle

On 12/4/2010 8:44 PM, Monte Milanuk wrote:

On 12/4/10 3:43 PM, Jorge Biquez wrote:


I do not see a good reason for not using Sqlite3 BUT if for some reason
would not be an option what plain schema of files would you use?


Would shelve work?


There are some systems for storing key-value pairs in files.

Underneath "shelve" is some primitive database, dbm, gdbm or bsddb.
"bsddb" is deprecated and was removed from Python 3.x.  "dbm" has
some classic problems.  "gdbm" is an improved version of "dbm".
None of these handle access from multiple processes, or crash
recovery.  We're looking at 1979 technology here.

   SQLite works right when accessed from multiple processes.  SQLite
is the entry-level database technology for Python today.  It handles
the hard cases, like undoing transactions after a crash and
locking against multiple accesses.  Lookup performance is good;
simultaneous update by multiple processes, though, is not so
good.  When you have a web site that has many processes hitting
the same database, it's time to move up to MySQL or Postgres.

   There's a lot of interest in "non-SQL" databases for very
large distributed systems.  You worry about this if you're Facebook
or Google, or are running a big game server farm.

John Nagle

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


Perceived inconsistency in py3k documentation

2010-12-05 Thread Greg
Hello,

This is my first post here, so if this is not the correct place to ask
this, please direct me to the best place.

In looking at the py3k documentation for comparing two classes, two
different view points are expressed (at least it seems so to me).
1) At http://docs.python.org/py3k/reference/datamodel.html:
  "There are no implied relationships among the comparison operators.
The truth of x==y does not imply that x!=y is false. Accordingly, when
defining __eq__(), one should also define __ne__()..."
  -- This seems to support the view that if in our code, we would like
to use comparison operators <, >, =, !=, etc. then we should define a
__lt__(), __gt__(), __eq__(), __ne__(), etc. for each comparison
operator we would like.

This appears to contrast
2) At http://docs.python.org/py3k/library/stdtypes.html:
  "Instances of a class cannot be ordered with respect to other
instances of the same class, or other types of object, unless the
class defines enough of the methods __lt__(), __le__(), __gt__(), and
__ge__() (in general, __lt__() and __eq__() are sufficient, if you
want the conventional meanings of the comparison operators)."
  -- This seems to imply that to get all of the operators, only
__lt__() and __eq__() need to be defined (just __lt__() should suffice
though I thought).

So, which is it supposed to be? Or am I reading the documentation
wrong?

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


Re: Comparison with False - something I don't understand

2010-12-05 Thread Paul Rubin
Tim Harig  writes:
> The fact that I bothered to create classes for the dice and roles, rather
> then simply iterating over a list of numbers,  should tell you that I
> produced was of a far more flexible nature; including the support for
> roles with dice having different numbers of sides.

from itertools import product
def n_sided_die(n): return xrange(1, n+1)

# make one 3-sided die, one 4-sided die, and one 5-sided die
dice = (n_sided_die(3), n_sided_die(4), n_sided_die(5))
for roll in product(*dice):
print roll

> I merely posted a simplied description of the dice-role objects
> because I thought that it demonstrated how exceptions can provide
> eligance of control for situations that don't involve what would
> traditionally be defined as an error.

Exceptions (though sometimes necessary) are messy and I'm having a hard
time trying to envision that code being cleaner with them than without
them.  If you post the actual code maybe that will help me understand.
-- 
http://mail.python.org/mailman/listinfo/python-list


Deditor 0.2.3

2010-12-05 Thread Kruptein
A new version of the python dedicated linux text-editor has been
released!

This editor is python specific offering some features to python users
like code analyzing, code inspecting, syntax highlighting, ...

Information about this project: http://launchpad.net/deditor
Information about the latest release: http://kruptein.alwaysdata.net/blag
-- 
http://mail.python.org/mailman/listinfo/python-list


s;hlhdlhlah

2010-12-05 Thread hollyood
lhdglfhglshglhash
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Perceived inconsistency in py3k documentation

2010-12-05 Thread Peter Otten
Greg wrote:

> This is my first post here, so if this is not the correct place to ask
> this, please direct me to the best place.

This is a good place to get general advice and to discuss potential bugs 
when you are unsure whether they actually are bugs.
If you are sure that you ran into a bug in python or want to suggest an 
improvement of the documentation where it is wrong or unclear or hard to 
understand you can report to http://bugs.python.org .
 
> In looking at the py3k documentation for comparing two classes, two
> different view points are expressed (at least it seems so to me).
> 1) At http://docs.python.org/py3k/reference/datamodel.html:
>   "There are no implied relationships among the comparison operators.
> The truth of x==y does not imply that x!=y is false. Accordingly, when
> defining __eq__(), one should also define __ne__()..."
>   -- This seems to support the view that if in our code, we would like
> to use comparison operators <, >, =, !=, etc. then we should define a
> __lt__(), __gt__(), __eq__(), __ne__(), etc. for each comparison
> operator we would like.
> 
> This appears to contrast
> 2) At http://docs.python.org/py3k/library/stdtypes.html:
>   "Instances of a class cannot be ordered with respect to other
> instances of the same class, or other types of object, unless the
> class defines enough of the methods __lt__(), __le__(), __gt__(), and
> __ge__() (in general, __lt__() and __eq__() are sufficient, if you
> want the conventional meanings of the comparison operators)."
>   -- This seems to imply that to get all of the operators, only
> __lt__() and __eq__() need to be defined (just __lt__() should suffice
> though I thought).
> 
> So, which is it supposed to be? Or am I reading the documentation
> wrong?

I agree with you that the documentation is at least unclear. The following 
experiment suggests that list.sort() works correctly if only __lt__() and 
__eq__() are implemented which in my reading is what your second quote 
intends to convey. But "enough of the methods..." is a fuzzy statement.

The other finding:
(1) a != b is emulated with not (a == b) 
(2) a > b is emulated with b < a
is not something I'd expect after reading your first quote, but technically 
(2) is covered by

"""... __lt__() and __gt__() are each other’s reflection ..."""

$ cat py3compare.py
report = True  

class A:
def __init__(self, key, side="A"):
self.key = key
self.side = side  
def __eq__(self, other):  
result = self.key == other.key
if report:
print(self, "__eq__", other, "-->", result)
return result  
def __lt__(self, other):
result = self.key < other.key
if report:
print(self, "__lt__", other, "-->", result)
return result
def __str__(self):
return "{}({})".format(self.side, self.key)
def __repr__(self):
return str(self.key)

a = A(1, "L")
for k in range(3):
b = A(k, "R")
print("{} != {}: {}\n".format(a, b, a != b))
print("{} > {}: {}\n".format(a, b, a > b))
print()

import random
items = []
for n in 10, 20:
items.extend(map(A, range(n)))
random.shuffle(items)

report = False
items.sort()
print(items)

print(a <= b)
$ python3 py3compare.py
L(1) __eq__ R(0) --> False
L(1) != R(0): True

R(0) __lt__ L(1) --> True
L(1) > R(0): True


L(1) __eq__ R(1) --> True
L(1) != R(1): False

R(1) __lt__ L(1) --> False
L(1) > R(1): False


L(1) __eq__ R(2) --> False
L(1) != R(2): True

R(2) __lt__ L(1) --> False
L(1) > R(2): False


[0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 11, 12, 13, 
14, 15, 16, 17, 18, 19]
Traceback (most recent call last):
  File "py3compare.py", line 39, in 
print(a <= b)
TypeError: unorderable types: A() <= A()
$

Conclusion: If you can come up with a text that is both correct and clear, 
don't hesitate to tell us, here or on the bug tracker.

Peter

PS: The painless way out: always use @functools.total_ordering or the 
equivalent cookbok recipe.
-- 
http://mail.python.org/mailman/listinfo/python-list


[ANN] Pyclewn: Vim as a front end to pdb

2010-12-05 Thread Xavier de Gaye
Pyclewn 1.5 has been released at http://pyclewn.sourceforge.net/

Pyclewn is a python program that allows the use of Vim as a front end
to gdb and pdb.

This release adds support for ``pdb``, the python debugger.

 + A python script may be run under the control of ``pdb``. For
   example the current vim buffer may be started and debugged with
   the vim command ``:Pyclewn pdb %:p``

 + One may also attach to a running python process, interrupt the
   process, manage a debugging session and terminate the debugging
   session by detaching from the process. A new debugging session may
   be conducted later on this same process, possibly from another Vim
   instance.

 + All the ``pdb`` commands are supported except ``list`` and
   ``commands``.  This includes alias expansion and executing a
   python statement in the context of the current frame. The new
   command ``threadstack`` prints the instantaneous backtrace of all
   the threads, including those that are stuck in a deadlock.

* Pdb is currently supported on unix platforms and requires the latest
 Vim version: Vim 7.3. Python3 is not supported yet.

-- 
Xavier

Les Chemins de Lokoti: http://lokoti.alwaysdata.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Comparison with False - something I don't understand

2010-12-05 Thread Tim Harig
On 2010-12-05, Paul Rubin  wrote:
> Tim Harig  writes:
>> The fact that I bothered to create classes for the dice and roles, rather
>> then simply iterating over a list of numbers,  should tell you that I
>> produced was of a far more flexible nature; including the support for
>> roles with dice having different numbers of sides.
>
> from itertools import product
> def n_sided_die(n): return xrange(1, n+1)
>
> # make one 3-sided die, one 4-sided die, and one 5-sided die
> dice = (n_sided_die(3), n_sided_die(4), n_sided_die(5))
> for roll in product(*dice):
> print roll

Notice that you had to change the structure of your program to accomodate
the new possiblity; and, if I throw further requirements at you, you
will have to change them again.  I didn't want that.  What the dice
returned may or may not have returned an easy to compute sequence.
In fact, for all of the rest of the logic cared, the dice could have
computed their value from a previous role of another dice.  All of the
logic of about what the dice may have returned when asked for their
value and how they derived, was encapsilated in the dice themselves.
It did not need to be known anywhere else in the program logic.

The DSL effectively provided a way do define how the dice decided how
to increment themselves, how to choose the value that they returned for
their face, and how to know when they could no longer be incremented.
The DSL parser generated the dice set from the description given.
Creating new dice objects was much easier then attempting to change the
logic of how they were rolled.

>> I merely posted a simplied description of the dice-role objects
>> because I thought that it demonstrated how exceptions can provide
>> eligance of control for situations that don't involve what would
>> traditionally be defined as an error.
>
> Exceptions (though sometimes necessary) are messy and I'm having a hard
> time trying to envision that code being cleaner with them than without
> them.  If you post the actual code maybe that will help me understand.

Let me get this straight, the same person that was trying to tell me
setjmp/longjmp weren't messy thinks exceptions are messy?  I have used
both.  I much prefer the exceptions.  I not have to code here to post.

The cleanliness of using the exception and calling the dice increments
recursively, was that there was no need to figure out which dice needed
to be incremented whenever the first die needed to be reset.  When a dice
needed to be reset, it would raise an exception.  This exception would
rise through the recursion stack, and thus through the dice, resetting
each along the way until it found the one which needed to be incremented
or raised past the top call indicating that all of the combinations has
been exhausted.  There, once the reset condition for the previous dice
had been effectively handled, it would be supprested. 

Had this been done using in band data:

1. The roll object would have needed logic to determine when
a reset condition needed to take place, effectively
leaking some of the logic from the dice object to the
role object.

2. The roll object would have needed logic to determine how to
follow the dice which needed to be reset until it found
which one needed incrementing.  Once again, this logic
was better left to the dice walking the resets was
automatically handled by the progression of the exception.

Even if it wasn't an error, the resets were effectively a exceptional
condition from the normal flow of the role object (the primary flow simply
being to increment the first die).  By using exceptions, I effectively
isolated each into its own separate independent flow; and, because they
where called separatly, neither needed to have control conditions to detect
which was needed.  They simply allowed the dice object to decide.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Comparison with False - something I don't understand

2010-12-05 Thread Tim Harig
On 2010-12-05, Tim Harig  wrote:
> On 2010-12-05, Paul Rubin  wrote:
>> Tim Harig  writes:
>>> The fact that I bothered to create classes for the dice and roles, rather
>>> then simply iterating over a list of numbers,  should tell you that I
>>> produced was of a far more flexible nature; including the support for
>>> roles with dice having different numbers of sides.
>>
>> from itertools import product
>> def n_sided_die(n): return xrange(1, n+1)
>>
>> # make one 3-sided die, one 4-sided die, and one 5-sided die
>> dice = (n_sided_die(3), n_sided_die(4), n_sided_die(5))
>> for roll in product(*dice):
>> print roll
>
> Notice that you had to change the structure of your program to accomodate
> the new possiblity; and, if I throw further requirements at you, you
> will have to change them again.  I didn't want that.  What the dice
> returned may or may not have returned an easy to compute sequence.
> In fact, for all of the rest of the logic cared, the dice could have
> computed their value from a previous role of another dice.  All of the
> logic of about what the dice may have returned when asked for their
> value and how they derived, was encapsilated in the dice themselves.
> It did not need to be known anywhere else in the program logic.
>
> The DSL effectively provided a way do define how the dice decided how
> to increment themselves, how to choose the value that they returned for
> their face, and how to know when they could no longer be incremented.
> The DSL parser generated the dice set from the description given.
> Creating new dice objects was much easier then attempting to change the
> logic of how they were rolled.
>
>>> I merely posted a simplied description of the dice-role objects
>>> because I thought that it demonstrated how exceptions can provide
>>> eligance of control for situations that don't involve what would
>>> traditionally be defined as an error.
>>
>> Exceptions (though sometimes necessary) are messy and I'm having a hard
>> time trying to envision that code being cleaner with them than without
>> them.  If you post the actual code maybe that will help me understand.
>
> Let me get this straight, the same person that was trying to tell me
> setjmp/longjmp weren't messy thinks exceptions are messy?  I have used
> both.  I much prefer the exceptions.  I not have to code here to post.
>
> The cleanliness of using the exception and calling the dice increments
> recursively, was that there was no need to figure out which dice needed
> to be incremented whenever the first die needed to be reset.  When a dice
> needed to be reset, it would raise an exception.  This exception would
> rise through the recursion stack, and thus through the dice, resetting
> each along the way until it found the one which needed to be incremented
> or raised past the top call indicating that all of the combinations has
> been exhausted.  There, once the reset condition for the previous dice
> had been effectively handled, it would be supprested. 
>
> Had this been done using in band data:
>
>   1. The roll object would have needed logic to determine when
>   a reset condition needed to take place, effectively
>   leaking some of the logic from the dice object to the
>   role object.
>
>   2. The roll object would have needed logic to determine how to
>   follow the dice which needed to be reset until it found
>   which one needed incrementing.  Once again, this logic
>   was better left to the dice walking the resets was
>   automatically handled by the progression of the exception.
>
> Even if it wasn't an error, the resets were effectively a exceptional
> condition from the normal flow of the role object (the primary flow simply
> being to increment the first die).  By using exceptions, I effectively
> isolated each into its own separate independent flow; and, because they
> where called separatly, neither needed to have control conditions to detect
> which was needed.  They simply allowed the dice object to decide.

Okay, it occures to me that you don't really need to see much to know what was
going on, here is the basic idea of how the role function of the object would
have looked like:

def role(self, dice):

try:
self.role(dice.previous())
except diceReset:
dice.increment()
except endOfDice:
raise diceReset
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which non SQL Database ?

2010-12-05 Thread Lie Ryan
On 12/05/10 10:43, Jorge Biquez wrote:
> I do not see a good reason for not using Sqlite3 BUT if for some reason
> would not be an option what plain schema of files would you use? 

Assuming you don't want SQL, you can use filesystem-based database. Most
people doesn't realize that a filesystem is essentially a database (of
files) and a file explorer is a (sort of) DBMS. It is relatively easy to
create a robust (as robust as the filesystem) and fast (as fast as the
filesystem) database system by using folders and files (and optionally
hard and symbolic links) to store data in hierarchical topology.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Comparison with False - something I don't understand

2010-12-05 Thread Tim Chase

On 12/04/2010 11:42 PM, Steven D'Aprano wrote:

On Sun, 05 Dec 2010 04:13:02 +, Tim Harig wrote:
str.find is more troublesome, because the sentinel -1 doesn't propagate
and is a common source of errors:

result = string[string.find(delim):]

will return a plausible-looking but incorrect result if delim is missing
from string. But the convenience and familiarity of str.find means it
will probably be around forever.


Fortunately, string objects offer both .find() and .index() so 
you can choose whether you want sentinels or exceptions according 
to your use-case.


-tkc




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


Re: Which non SQL Database ?

2010-12-05 Thread Tim Chase

On 12/05/2010 03:41 AM, Alan Gauld wrote:

Why not use SQL?
SQLlite comes with Python, is small, easy to use and if necessary
can be used in-memory and as such fast.


The only reason I could see using something other than sqlite3 
for such a use-case would be if the OP has to support Python 
before version 2.5 and can't add/install the sqlite libraries to 
his deployment platform(s).  I've got a couple targets still 
running 2.4 and regularly mutter under my breath when I reach for 
sqlite to find it's not there.


-tkc



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


Re: How to add data into exisitng Excel file at next open row?

2010-12-05 Thread Steve Holden
On 12/3/2010 6:21 PM, noydb wrote:
> How can you determine the next open row in an existing Excel file such
> that you can start adding data to the cells in that row?  As in below,
> I want a variable in place of the 6 (row 6 in the four ws1.Cells(x,1)
> lines), but have no other way of knowing what row I am on besides
> looking to the first free cell in column A.  How to do?  Examples I
> see make it seem really complicated - this can't be that hard.
> 
> Thanks for any help.
> 
> worksheet = "C:\\Excel_Reports\\ea" + ea + "report"# + ".xls"
> xlApp = win32com.client.Dispatch("Excel.Application")
> xlApp.Visible = 1
> xlApp.Workbooks.Open(worksheet) ## for existing file
> ##xlApp.SheetsInNewWorkbook = 1
> ##wb = xlApp.Workbooks()
> ws1 = xlApp.Worksheets(1)
> 
> ws1.Cells(6,1).Value = "selection"
> ws1.Cells(6,2).Value = count
> ws1.Cells(6,3).Value = epcFloat
> ws1.Cells(6,8).Value = currentGMT
> 
> wb.SaveAs(worksheet)
> wb.Close(False) ## False/1

You might want to take a look at the xlrd library. This lets you read
Excel spreadsheets even on Unix platforms and without the use of COM
magic. There's also an xlwt module for writing spreadsheets. However I
understand that the two together may not be as convenient as modifying a
spreadsheet in place.

In particular, if sh is a spreadsheet then sh.nrows gives you the number
of rows currently used in the sheet.

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: Which non SQL Database ?

2010-12-05 Thread Roy Smith
In article <4cfb802...@dnews.tpgi.com.au>,
 Lie Ryan  wrote:

> On 12/05/10 10:43, Jorge Biquez wrote:
> > I do not see a good reason for not using Sqlite3 BUT if for some reason
> > would not be an option what plain schema of files would you use? 
> 
> Assuming you don't want SQL, you can use filesystem-based database. Most
> people doesn't realize that a filesystem is essentially a database (of
> files) and a file explorer is a (sort of) DBMS. It is relatively easy to
> create a robust (as robust as the filesystem) and fast (as fast as the
> filesystem) database system by using folders and files (and optionally
> hard and symbolic links) to store data in hierarchical topology.

Another possibility is one of the new breed of non-relational databases.  
We've been using MongoDB (http://www.mongodb.org/) and so far are happy 
with it.  You can find a bunch of other alternatives in Wikipedia's 
NoSQL article.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unknown function operation deciphering, exercise in readability by program reasoning

2010-12-05 Thread rupertlssm...@googlemail.com
On Dec 5, 3:34 am, jvt  wrote:
> On Dec 4, 4:49 pm, Barb Knox  wrote:
>
>
>
>
>
> > In article
> > <46365e1d-42d8-4b3b-8e69-941472467...@u25g2000pra.googlegroups.com>,
> >  small Pox  wrote:
>
> > > Rules :
>
> > No need to add any additional hurdles -- the code as presented is
> > thoroughly unreadable by humans.
>
> > > @1@  No execution of the function, only checking syntax
>
> > What about "desk checking" (a lost art from the oldene dayes)?
>
> > > @2@  No profiling using a debugger or profiler
>
> > > @3@  Editing allowed to make simpler variables
>
> > Maybe if you had done that yourself before posting it then I would have
> > tried to understand it.  As it is, no way.
>
> > > (defun unknown-function (nano-thermite-911-FBI-fat-per-diem-bustards-
> > > kept-their-odious-mouth-shut-on-anthrax-and-911-lie)
> > >   (let (BERNARD-MADOFF-PHILIP-MARKOFF-MIKHAIL-KHODORKOVSKY-NEOCONS-
> > > PAUL-WOLFOWITZ-LEWIS-SCOOTER-LIBBY-MOSHE-KATSEV-MOSSAD-DUBAI-MURDERERS
> > > I-AM-THE-WITNESS-DOT-COM-has-MR-BENJAMIN-FREEDMAN-SPEECH-ON-KHAZARS)
> > >     (while (or I-AM-THE-WITNESS-DOT-COM-has-MR-BENJAMIN-FREEDMAN-
> > > SPEECH-ON-KHAZARS nano-thermite-911-FBI-fat-per-diem-bustards-kept-
> > > their-odious-mouth-shut-on-anthrax-and-911-lie)
> > >       (if nano-thermite-911-FBI-fat-per-diem-bustards-kept-their-
> > > odious-mouth-shut-on-anthrax-and-911-lie
> > >           (if (consp nano-thermite-911-FBI-fat-per-diem-bustards-kept-
> > > their-odious-mouth-shut-on-anthrax-and-911-lie)
> > >               (setq I-AM-THE-WITNESS-DOT-COM-has-MR-BENJAMIN-FREEDMAN-
> > > SPEECH-ON-KHAZARS (cons (cdr nano-thermite-911-FBI-fat-per-diem-
> > > bustards-kept-their-odious-mouth-shut-on-anthrax-and-911-lie)
> > >                                 I-AM-THE-WITNESS-DOT-COM-has-MR-
> > > BENJAMIN-FREEDMAN-SPEECH-ON-KHAZARS)
> > >                     nano-thermite-911-FBI-fat-per-diem-bustards-kept-
> > > their-odious-mouth-shut-on-anthrax-and-911-lie (car nano-thermite-911-
> > > FBI-fat-per-diem-bustards-kept-their-odious-mouth-shut-on-anthrax-
> > > and-911-lie))
> > >             (setq BERNARD-MADOFF-PHILIP-MARKOFF-MIKHAIL-KHODORKOVSKY-
> > > NEOCONS-PAUL-WOLFOWITZ-LEWIS-SCOOTER-LIBBY-MOSHE-KATSEV-MOSSAD-DUBAI-
> > > MURDERERS (cons nano-thermite-911-FBI-fat-per-diem-bustards-kept-their-
> > > odious-mouth-shut-on-anthrax-and-911-lie BERNARD-MADOFF-PHILIP-MARKOFF-
> > > MIKHAIL-KHODORKOVSKY-NEOCONS-PAUL-WOLFOWITZ-LEWIS-SCOOTER-LIBBY-MOSHE-
> > > KATSEV-MOSSAD-DUBAI-MURDERERS)
> > >                   nano-thermite-911-FBI-fat-per-diem-bustards-kept-
> > > their-odious-mouth-shut-on-anthrax-and-911-lie nil))
> > >         (setq nano-thermite-911-FBI-fat-per-diem-bustards-kept-their-
> > > odious-mouth-shut-on-anthrax-and-911-lie (car I-AM-THE-WITNESS-DOT-COM-
> > > has-MR-BENJAMIN-FREEDMAN-SPEECH-ON-KHAZARS)
> > >               I-AM-THE-WITNESS-DOT-COM-has-MR-BENJAMIN-FREEDMAN-SPEECH-
> > > ON-KHAZARS (cdr I-AM-THE-WITNESS-DOT-COM-has-MR-BENJAMIN-FREEDMAN-
> > > SPEECH-ON-KHAZARS
> > >     BERNARD-MADOFF-PHILIP-MARKOFF-MIKHAIL-KHODORKOVSKY-NEOCONS-PAUL-
> > > WOLFOWITZ-LEWIS-SCOOTER-LIBBY-MOSHE-KATSEV-MOSSAD-DUBAI-MURDERERS))
>
> > --
> > ---
> > |  BBB                b    \     Barbara at LivingHistory stop co stop uk
> > |  B  B   aa     rrr  b     |
> > |  BBB   a  a   r     bbb   |    Quidquid latine dictum sit,
> > |  B  B  a  a   r     b  b  |    altum videtur.
> > |  BBB    aa a  r     bbb   |  
> > -
>
> I think this is correct:
>
> (defun unknown-function (sym0)
>   (let (sym1 sym2)
>         (while (or sym2 sym0)
>           (if sym0
>                   (if (consp sym0)
>                           (setq sym2 (cons (cdr sym0) sym2) sym0 (car sym0))
>                         (setq sym3 sym4 (cons sym0 sym1) sym0 nil))
>                 (setq sym0 (car sym2) sym2 (cdr sym2
>         sym1))
> Thank emacs, not me.

Lisp? Still can't read it... ;-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unknown function operation deciphering, exercise in readability by program reasoning

2010-12-05 Thread small Pox
On Dec 5, 9:13 am, "rupertlssm...@googlemail.com"
 wrote:
> On Dec 5, 3:34 am, jvt  wrote:
>

> > I think this is correct:
>
> > (defun unknown-function (sym0)
> >   (let (sym1 sym2)
> >         (while (or sym2 sym0)
> >           (if sym0
> >                   (if (consp sym0)
> >                           (setq sym2 (cons (cdr sym0) sym2) sym0 (car sym0))
> >                         (setq sym3 sym4 (cons sym0 sym1) sym0 nil))
> >                 (setq sym0 (car sym2) sym2 (cdr sym2
> >         sym1))
> > Thank emacs, not me.
>
> Lisp? Still can't read it... ;-)- Hide quoted text -
>

This is because madhu did not explain how he reasoned.

Does it appear to you that she broke first two rules.

its a list flattener that also reverses the operation.

it appears that she took the consp predicate and/or flatten and
started googling ... naughty girl.


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


Re: Unknown function operation deciphering, exercise in readability by program reasoning

2010-12-05 Thread small Pox
On Dec 4, 11:37 pm, Madhu  wrote:
> * jvt <5e1f79ab-5432-4f18-b896-362b7406c...@i18g2000yqn.googlegroups.com> :
> Wrote on Sat, 4 Dec 2010 19:34:53 -0800 (PST):
>
> |
> | I think this is correct:
> |
> |
> | (defun unknown-function (sym0)
> |   (let (sym1 sym2)
> |       (while (or sym2 sym0)
> |         (if sym0
> |                 (if (consp sym0)
> |                         (setq sym2 (cons (cdr sym0) sym2) sym0 (car sym0))
> |                       (setq sym3 sym4 (cons sym0 sym1) sym0 nil))
> |               (setq sym0 (car sym2) sym2 (cdr sym2
> |       sym1))
> | Thank emacs, not me.
>
> Not quite. You didn't account for the original poster's go-
> ogle masters mangling his message.   But your function appears to be a
> list flattener:

explanation

> (defun unknown-function (list)
>   (let (stack ret)
>     (while (or ret list)
>       (if list
>           (if (consp list)
>               (setq ret (cons (cdr list) ret) ;; hint: this is a push 
> followed by
  list (car list))  ;;   pop
>             (setq stack (cons list stack) ;; and so is this
list nil))
>         (setq list (car ret) ret (cdr ret
>     stack))
>
> ---
> Madhu

I will post an explanation in a few days if no one does this before
since its not urgent for anyone and i have some job assignments to
finish.
-- 
http://mail.python.org/mailman/listinfo/python-list


Framework design question

2010-12-05 Thread Alan Harris-Reid


Hi,

When committing data that has originally come from a webpage, sometimes 
data has to be converted to a data type or format which is suitable for 
the back-end database.  For instance, a date in 'dd/mm/' format 
needs to be converted to a Python date-object or '-mm-dd' in order 
to be stored in a SQLite date column (SQLite will accept 'dd/mm/yy', but 
that can cause problems when data is retrieved).


Question - at what point should the data be converted?
a) As part of a generic web_page_save() method (immediately after 
data validation, but before a row.table_update() method is called).
b) As part of row.table_update() (a data-object method called from 
web- or non-web-based applications, and includes construction of a 
field-value parameter list prior to executing the UPDATE command).


In other words, from a framework point-of-view, does the data-conversion 
belong to page-object processing or data-object processing?


Any opinions would be appreciated.

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


Re: Framework design question

2010-12-05 Thread MRAB

On 05/12/2010 18:20, Alan Harris-Reid wrote:


Hi,

When committing data that has originally come from a webpage, sometimes
data has to be converted to a data type or format which is suitable for
the back-end database. For instance, a date in 'dd/mm/' format needs
to be converted to a Python date-object or '-mm-dd' in order to be
stored in a SQLite date column (SQLite will accept 'dd/mm/yy', but that
can cause problems when data is retrieved).

Question - at what point should the data be converted?
a) As part of a generic web_page_save() method (immediately after data
validation, but before a row.table_update() method is called).
b) As part of row.table_update() (a data-object method called from web-
or non-web-based applications, and includes construction of a
field-value parameter list prior to executing the UPDATE command).

In other words, from a framework point-of-view, does the data-conversion
belong to page-object processing or data-object processing?

Any opinions would be appreciated.


I would use a standardised 'international' form as much as possible,
converting to it as early as possible and from it as late as possible.
This applies to dates, text (using Unicode internally), etc.
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to add data into exisitng Excel file at next open row?

2010-12-05 Thread noydb
On Dec 5, 8:42 am, Steve Holden  wrote:
> On 12/3/2010 6:21 PM, noydb wrote:
>
>
>
>
>
> > How can you determine the next open row in an existing Excel file such
> > that you can start adding data to the cells in that row?  As in below,
> > I want a variable in place of the 6 (row 6 in the four ws1.Cells(x,1)
> > lines), but have no other way of knowing what row I am on besides
> > looking to the first free cell in column A.  How to do?  Examples I
> > see make it seem really complicated - this can't be that hard.
>
> > Thanks for any help.
>
> > worksheet = "C:\\Excel_Reports\\ea" + ea + "report"# + ".xls"
> > xlApp = win32com.client.Dispatch("Excel.Application")
> > xlApp.Visible = 1
> > xlApp.Workbooks.Open(worksheet) ## for existing file
> > ##xlApp.SheetsInNewWorkbook = 1
> > ##wb = xlApp.Workbooks()
> > ws1 = xlApp.Worksheets(1)
>
> > ws1.Cells(6,1).Value = "selection"
> > ws1.Cells(6,2).Value = count
> > ws1.Cells(6,3).Value = epcFloat
> > ws1.Cells(6,8).Value = currentGMT
>
> > wb.SaveAs(worksheet)
> > wb.Close(False) ## False/1
>
> You might want to take a look at the xlrd library. This lets you read
> Excel spreadsheets even on Unix platforms and without the use of COM
> magic. There's also an xlwt module for writing spreadsheets. However I
> understand that the two together may not be as convenient as modifying a
> spreadsheet in place.
>
> In particular, if sh is a spreadsheet then sh.nrows gives you the number
> of rows currently used in the sheet.
>
> 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/- Hide quoted text -
>
> - Show quoted text -

Thanks, good to keep in mind.  I have used xlrd before in cases where
i'm not sure if excel is installed on a user's machine.

Someone else helped, provided this>

   NextRow = ws1.Range("A1").SpecialCells(xlLastCell).Row + 1

Although to get it to work for me, I have to use the number code for
some reason, like >

   NextRow = ws1.Range("A1").SpecialCells(11).Row + 1
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Perceived inconsistency in py3k documentation

2010-12-05 Thread Terry Reedy

On 12/5/2010 3:31 AM, Greg wrote:

For future reference,


1) At http://docs.python.org/py3k/reference/datamodel.html:
2) At http://docs.python.org/py3k/library/stdtypes.html:


do not work because of the trailing :s, at least not with FireFox.

> 1) At http://docs.python.org/py3k/reference/datamodel.html :
> 2) At http://docs.python.org/py3k/library/stdtypes.html :

These, with space after the url, should. Other puctuation can be a 
problem too, so it is best to always follow urls with whitespace.


--
Terry Jan Reedy

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


Re: Which non SQL Database ?

2010-12-05 Thread Stef Mientki
On 04-12-2010 23:42, Jorge Biquez wrote:
> Hello all.
>
> Newbie question. Sorry.
>
> As part of my process to learn python I am working on two personal 
> applications. Both will do it
> fine with a simple structure of data stored in files. I now there are lot of 
> databases around I
> can use but I would like to know yoor advice on what other options you would 
> consider for the job
> (it is training so no pressure on performance). One application will run as a 
> desktop one,under
> Windows, Linux, Macintosh, being able to update data, not much, not complex, 
> not many records. The
> second application, running behind  web pages, will do the same, I mean, 
> process simple data,
> updating showing data. not much info, not complex. As an excersice it is more 
> than enough I guess
> and will let me learn what I need for now.
> Talking with a friend about what he will do (he use C only) he suggest to 
> take a look on dBase
> format file since it is a stable format, fast and the index structure will be 
> fine or maybe go
> with BD (Berkley) database file format (I hope I understood this one 
> correctly) . Plain files it
> is not an option since I would like to have option to do rapid searches.
>
> What would do you suggest to take a look? If possible available under the 3 
> plattforms.
>
> Thanks in advance for your comments.
>
> Jorge Biquez
>
You should take a look at one of the database wrappers.
I use the DAL of Web2Py,
the main advantages are
- easy use of database (more easy than SQL)
- easy migration of database structure (is done automatically)
- same interface on desktop and in web applications
- all major database (including SQLite and Postgres) supported and can be 
switched easily

cheers,
Stef
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Comparison with False - something I don't understand

2010-12-05 Thread Martin v. Loewis
> result = myfunction (vars) 
> 
> if not result:
> # error condition
> 
> Now above I first realized that the function can also return an empty 
> list under some conditions and so changed it to

If your function returns a list when successful, it should not return
False in the error case. Instead, it should return None (indicating that
there is no list).

Then the condition changes to

result = myfunction()
if result is None:
  # error condition

Using None for "no result available" is very common in Python. Using
False for the same purpose (i.e. returning either a list or False)
is not. If you return False from a function, the only other possible
result should be True.

Regards,
Martin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which non SQL Database ?

2010-12-05 Thread Dan Stromberg
On Sun, Dec 5, 2010 at 12:01 AM, John Nagle  wrote:
> On 12/4/2010 8:44 PM, Monte Milanuk wrote:
>>
>> On 12/4/10 3:43 PM, Jorge Biquez wrote:
>>
>>> I do not see a good reason for not using Sqlite3 BUT if for some reason
>>> would not be an option what plain schema of files would you use?
>>
>> Would shelve work?
>
>    There are some systems for storing key-value pairs in files.
>
>    Underneath "shelve" is some primitive database, dbm, gdbm or bsddb.
> "bsddb" is deprecated and was removed from Python 3.x.  "dbm" has
> some classic problems.  "gdbm" is an improved version of "dbm".
> None of these handle access from multiple processes, or crash
> recovery.  We're looking at 1979 technology here.
>
>   SQLite works right when accessed from multiple processes.  SQLite
> is the entry-level database technology for Python today.  It handles
> the hard cases, like undoing transactions after a crash and
> locking against multiple accesses.  Lookup performance is good;
> simultaneous update by multiple processes, though, is not so
> good.  When you have a web site that has many processes hitting
> the same database, it's time to move up to MySQL or Postgres.
>
>   There's a lot of interest in "non-SQL" databases for very
> large distributed systems.  You worry about this if you're Facebook
> or Google, or are running a big game server farm.

SQLite isn't exactly no SQL.

I've used the bsddb and gdbm modules quite a bit.  I've found that
bsddb tables tend to get corrupted (whether used from CPython or C),
EG when a filesystem fills up.  I quite like the gdbm module though,
and have been using it in my current project.

If you find that converting your database keys and values to/from
strings is expensive, you could check out
http://stromberg.dnsalias.org/~dstromberg/cachedb.html which is a
caching wrapper around gdbm and other single-table database interfaces
supporting the same API.

As far as multiple processes, IINM, gdbm supports a single writer and
multiple readers.
-- 
http://mail.python.org/mailman/listinfo/python-list


Collision of rotated rectangles without pygame

2010-12-05 Thread Martin Manns
Hello,

I am looking for a Python library for 2D collision checks of rotated
rectangles. Currently, I have found vizier 0.5b that is based on pygame.

Since I do not want to add a pygame dependency to my app, I replaced the
pygame.rect.Rect by a wxPython wx.Rect (see code below).

However, collision checks do not work correctly, i. e. identical rects
are not found to be colliding:

$ python
Python 2.6.6 (r266:84292, Nov 28 2010, 18:42:58) 
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import xrect
>>> r=xrect.RotoRect(10,10,30,20,angle=34)
>>> s=xrect.RotoRect(10,10,30,20,angle=34)
>>> r.rotocollide(s)
False
>>> 


Is my replacement of the rectangle object wrong or is vizier not
working correctly with pygame as well?

Do you know of any other pure Python library for rotated rectangle
collision checks?

Cheers

Martin




from __future__ import division
import math
import wx
##


cos_table = dict([(deg, math.cos(math.radians(deg))) for deg in xrange(360)])
sin_table = dict([(deg, math.sin(math.radians(deg))) for deg in xrange(360)])


class RotoRect(wx.Rect):

def __init__(self, *a, **kw):
self.deg = kw.pop('angle')
wx.Rect.__init__(self, *a, **kw)

# pygame rect compatibility for wx.Rect

def get_center(self):
return self.centerx, self.centery

def set_center(self, center):
self.centerx, self.centery = center

def get_centerx(self):
return self.x + self.width / 2

def set_centerx(self, centerx):
self.SetX(centerx - self.width / 2)

def get_centery(self):
return self.y + self.height / 2

def set_centery(self, centery):
self.SetY(centery - self.height / 2)

def get_topleft(self):
return self.GetTopLeft()

def set_topleft(self, p):
self.SetTopLeft(p)

def get_topright(self):
return self.GetTopRight()

def set_topright(self, p):
self.SetTopRight(p)


center = property(get_center, set_center)
centerx = property(get_centerx, set_centerx)
centery = property(get_centery, set_centery)
topleft = property(get_topleft, set_topleft)
topright = property(get_topright, set_topright)

# Now for the vizier code

def rotate(self, point, origin = 0):
"""Returns coords of point p rotated self.theta radians with 

the rectangle around its center

"""

if not origin: origin = self.center
p_x = point[0]
p_y = point[1]
o_x = origin[0]
o_y = origin[1]
costheta = cos_table[self.deg]
sintheta = sin_table[self.deg]
return ((o_x + costheta * (p_x - o_x)) - (sintheta * (p_y - o_y)),
   (o_y + sintheta * (p_x - o_x)) + (costheta * (p_y - o_y)))

def rotoxt(self, a, b):
"""Returns the y extremity xt of rect between self.rect"""

a_x = a[0]
a_y = a[1]
b_x = b[0]
b_y = b[1]

#calculate difference between self.left and b_x
dxl = self.left - b_x 

#calculate difference between self.right and b_x
dxr = self.right - b_x

#if b_x isn't between self.left and self.right
if (dxl * dxr) > 0:   
#if dxl < 1, b_x is on the right
if (dxl < 0):   
#xt = (m * dxr) + b_y
xt = b_y - (-a_y)) / (b_x - (-a_x))) * dxr) + b_y)
else: 
#else b_x is on the left
#xt = (m * dxl) + b_y
xt = b_y - a_y) / (b_x - a_x)) * dxl) + b_y)
return xt
else: 
#else b_x is between self.left and self.right, and xt = b_y
return b_y

def rotocollide(self, rect):
"""Check for collision between self.rect and rect"""

#initialize collision to False
col = False   

#transforming the plane to set rect's center to the origin
transplane = rect.center  

#set rect's center to the origin
rect.center = (0, 0)  

#transform self.rect's center by the transplane amount
self.center = (self.centerx - transplane[0],
   self.centery - transplane[1]) 

#transforming the plane to set self.rect's the

Re: Collision of rotated rectangles without pygame

2010-12-05 Thread Martin Manns
On Sun, 5 Dec 2010 23:49:36 +0100
Martin Manns  wrote:

> Is my replacement of the rectangle object wrong or is vizier not
> working correctly with pygame as well?

Answering my first question:

Vizier works O.K. with pygame. 
I am unsure what I did wrong in the rect replacement though.

Cheers

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


Re: Comparison with False - something I don't understand

2010-12-05 Thread MRAB

On 05/12/2010 21:01, Martin v. Loewis wrote:

result = myfunction (vars)

if not result:
 # error condition

Now above I first realized that the function can also return an empty
list under some conditions and so changed it to


If your function returns a list when successful, it should not return
False in the error case. Instead, it should return None (indicating that
there is no list).

Then the condition changes to

result = myfunction()
if result is None:
   # error condition

Using None for "no result available" is very common in Python. Using
False for the same purpose (i.e. returning either a list or False)
is not. If you return False from a function, the only other possible
result should be True.


As an example, the re module uses both two approaches.

If you ask it to compile a regex:

rgx = re.compile(regex)

it either returns a PatternObject (if the regex is valid) or raises an
exception (if the regex isn't valid).

If you ask it to search a string:

rgx.search(string)

it returns either a MatchObject (if the match is successful) or None
(if the match isn't successful).
--
http://mail.python.org/mailman/listinfo/python-list


Re: How do I get the email address of the person who clicked the link in the email?

2010-12-05 Thread alex23
On Dec 5, 10:15 am, Zeynel  wrote:
> I am working with Google App Engine python version. The app sends an
> email to the user with a link to a page to upload an image as an
> avatar. It would be nice to have the email so that I can associate the
> avatar with that email. How can I do this? Thank you.

One approach would be to assign a unique identifier to the email
address, then include that identifier as a parameter in the link that
allows for image uploading: http://your.site.tld/avatar/upload/
(for eg)

Then the upload process can get the ID from the path and identify the
email address with which the image is associated.
-- 
http://mail.python.org/mailman/listinfo/python-list


PEP8 compliance and exception messages ?

2010-12-05 Thread shearichard
Hi - PEP8 says lines should not exceed 79 characters in length
( http://www.python.org/dev/peps/pep-0008/ ).

So if you've got some code that looks like this :

raise fooMod.fooException("Some message which is quite long")

... and assuming a certain amount of indenting you're going to break
that guideline.

However there's a way around that ! You can do this ...

raise fooMod.fooException("\
Some message \
which is quite long")

... but the trouble is when that Exception is raised the message is
displayed as :

"Some message which is quite long"


I'm aware that a foolish consistency is the hobgoblin of something or
the other so maybe I should just let the PEP8 verifier complain but
otherwise does anyone have any ideas for how to get around this ?


Thanks

richard

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


Re: PEP8 compliance and exception messages ?

2010-12-05 Thread Chris Rebert
On Sun, Dec 5, 2010 at 7:40 PM, shearichard  wrote:
> Hi - PEP8 says lines should not exceed 79 characters in length
> ( http://www.python.org/dev/peps/pep-0008/ ).
>
> So if you've got some code that looks like this :
>
> raise fooMod.fooException("Some message which is quite long")
>
> ... and assuming a certain amount of indenting you're going to break
> that guideline.
>
> However there's a way around that ! You can do this ...
>
> raise fooMod.fooException("\
>        Some message \
>        which is quite long")
>
> ... but the trouble is when that Exception is raised the message is
> displayed as :
>
> "Some message                     which is quite long"
>
>
> I'm aware that a foolish consistency is the hobgoblin of something or
> the other so maybe I should just let the PEP8 verifier complain but
> otherwise does anyone have any ideas for how to get around this ?

Use implicit string literal concatenation:

raise fooMod.fooException(
"Some message "
"which is quite long")
#) # you could also put the closing paren here instead

Alternatively, you could disregard PEP 8 on this point on the grounds
that the 79/80 characters per line limit is outdated.

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


Re: PEP8 compliance and exception messages ?

2010-12-05 Thread MRAB

On 06/12/2010 03:40, shearichard wrote:

Hi - PEP8 says lines should not exceed 79 characters in length
( http://www.python.org/dev/peps/pep-0008/ ).

So if you've got some code that looks like this :

raise fooMod.fooException("Some message which is quite long")

... and assuming a certain amount of indenting you're going to break
that guideline.

However there's a way around that ! You can do this ...

raise fooMod.fooException("\
 Some message \
 which is quite long")

... but the trouble is when that Exception is raised the message is
displayed as :

"Some message which is quite long"


I'm aware that a foolish consistency is the hobgoblin of something or
the other so maybe I should just let the PEP8 verifier complain but
otherwise does anyone have any ideas for how to get around this ?


You can use implied string concatenation:

>>> "abc" "def"
'abcdef'

so:

raise fooMod.fooException(
  "Some message "
  "which is quite long")
--
http://mail.python.org/mailman/listinfo/python-list


Wanted: slow regexes

2010-12-05 Thread MRAB

I'm looking for examples of regexes which are slow (especially those
which seem never to finish) but whose results are known. I already have
those reported in the bug tracker, but further ones will be welcome.

This is for testing additional modifications to the new regex
implementation (available on PyPI).
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3 encoding question: Read a filename from stdin, subsequently open that filename

2010-12-05 Thread Dan Stromberg
Ultimately I switched to reading the filenames from file descriptor 0
using os.read(); this gave back bytes in 3.x, strings of single-byte
characters in 2.x - which are similar enough for my purposes, and
eliminated the filesystem encoding(s) question nicely.

I rewrote readline0
(http://stromberg.dnsalias.org/cgi-bin/viewvc.cgi/readline0/trunk/?root=svn)
for 2.x and 3.x to facilitate reading null-terminated strings from
stdin.  It's in better shape now anyway - more OOP than functional,
and with a bunch of unit tests.  The module now works on CPython 2.x,
CPython 3.x and PyPy 1.4 from the same code.

On Mon, Nov 29, 2010 at 9:26 PM, Dan Stromberg  wrote:
> I've got a couple of programs that read filenames from stdin, and then
> open those files and do things with them.  These programs sort of do
> the *ix xargs thing, without requiring xargs.
>
> In Python 2, these work well.  Irrespective of how filenames are
> encoded, things are opened OK, because it's all just a stream of
> single byte characters.
>
> In Python 3, I'm finding that I have encoding issues with characters
> with their high bit set.  Things are fine with strictly ASCII
> filenames.  With high-bit-set characters, even if I change stdin's
> encoding with:
>
>       import io
>       STDIN = io.open(sys.stdin.fileno(), 'r', encoding='ISO-8859-1')
>
> ...even with that, when I read a filename from stdin with a
> single-character Spanish n~, the program cannot open that filename
> because the n~ is apparently internally converted to two bytes, but
> remains one byte in the filesystem.  I decided to try ISO-8859-1 with
> Python 3, because I have a Java program that encountered a similar
> problem until I used en_US.ISO-8859-1 in an environment variable to
> set the JVM's encoding for stdin.
>
> Python 2 shows the n~ as 0xf1 in an os.listdir('.').  Python 3 with an
> encoding of ISO-8859-1 wants it to be 0xc3 followed by 0xb1.
>
> Does anyone know what I need to do to read filenames from stdin with
> Python 3.1 and subsequently open them, when some of those filenames
> include characters with their high bit set?
>
> TIA!
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP8 compliance and exception messages ?

2010-12-05 Thread Ben Finney
shearichard  writes:

> Hi - PEP8 says lines should not exceed 79 characters in length
> ( http://www.python.org/dev/peps/pep-0008/ ).
>
> So if you've got some code that looks like this :
>
> raise fooMod.fooException("Some message which is quite long")

PEP 8 also says those names are poorly chosen. Better:

raise foomod.FooException("Some message which is quite long")

> raise fooMod.fooException("\
> Some message \
> which is quite long")

Take advantage of the parsing of string literals and parenthesis:

raise foomod.FooException(
"Some message"
" which is quite long")

and for the sake of my eyes, avoid camelCase.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP8 compliance and exception messages ?

2010-12-05 Thread Andreas Waldenburger
On Sun, 5 Dec 2010 19:52:54 -0800 Chris Rebert  wrote:

> On Sun, Dec 5, 2010 at 7:40 PM, shearichard 
> wrote:
> > Hi - PEP8 says lines should not exceed 79 characters in length
> > ( http://www.python.org/dev/peps/pep-0008/ ).
> >
> > So if you've got some code that looks like this :
> >
> > raise fooMod.fooException("Some message which is quite long")
> >
> > ... and assuming a certain amount of indenting you're going to break
> > that guideline.
> >
> > [etc.]
> 
> Use implicit string literal concatenation:
> 
> [...]
> 
But isn't explicit string literal concatenation better than implicit string 
literal concatenation?

... sorry ...

On a more serious note:

> Alternatively, you could disregard PEP 8 on this point on the grounds
> that the 79/80 characters per line limit is outdated.
> 
Maybe, but it's not outmoded.

/W

-- 
To reach me via email, replace INVALID with the country code of my home 
country.  But if you spam me, I'll be one sour Kraut.

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


Re: PEP8 compliance and exception messages ?

2010-12-05 Thread Tim Harig
On 2010-12-06, Andreas Waldenburger  wrote:
> On Sun, 5 Dec 2010 19:52:54 -0800 Chris Rebert  wrote:
>
>> On Sun, Dec 5, 2010 at 7:40 PM, shearichard 
>> wrote:
>> > Hi - PEP8 says lines should not exceed 79 characters in length
>> > ( http://www.python.org/dev/peps/pep-0008/ ).
>> >
>> > So if you've got some code that looks like this :
>> >
>> > raise fooMod.fooException("Some message which is quite long")
>> >
>> > ... and assuming a certain amount of indenting you're going to break
>> > that guideline.
>> >
>> > [etc.]
>> 
>> Use implicit string literal concatenation:
>> 
>> [...]
>> 
> But isn't explicit string literal concatenation better than implicit
> string literal concatenation?

So add the "+", it really doesn't change it much.

>> Alternatively, you could disregard PEP 8 on this point on the grounds
>> that the 79/80 characters per line limit is outdated.
>> 
> Maybe, but it's not outmoded.

I would say that it is not even outdated.  Just because you happen to enjoy
longer lines doesn't mean that everybody does.  Not all progammers have
20/10 vision and even those who have hardware to handled it don't
necessarily like having a single piece of code take up their entire display
just to be readable.  Many of us like the extra ability that wider screen
technology gives us to actually be able to view more of the file at once
by splitting the display into a couple of columns.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP8 compliance and exception messages ?

2010-12-05 Thread Steven D'Aprano
On Mon, 06 Dec 2010 06:15:06 +, Tim Harig wrote:

>> But isn't explicit string literal concatenation better than implicit
>> string literal concatenation?
> 
> So add the "+", it really doesn't change it much.

Perhaps not *much*, but it *may* change it a bit.

Implicit concatenation of literals is promised to be handled by the 
compiler, at compile time:

>>> from dis import dis
>>> dis(compile("s = 'hello' 'world'", "", "single"))
  1   0 LOAD_CONST   0 ('helloworld')
  3 STORE_NAME   0 (s)
  6 LOAD_CONST   1 (None)
  9 RETURN_VALUE

This holds all the way back to Python 1.5 and probably older.

But explicit concatenation may occur at run-time, depending on the 
implementation and the presence or absence of a keyhole optimizer. E.g. 
in Python 2.4:

>>> dis(compile("s = 'hello' + 'world'", "", "single"))
  1   0 LOAD_CONST   0 ('hello')
  3 LOAD_CONST   1 ('world')
  6 BINARY_ADD
  7 STORE_NAME   0 (s)
 10 LOAD_CONST   2 (None)
 13 RETURN_VALUE



A small difference, but a real one.


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


Re: class attribute confusion

2010-12-05 Thread Steve Holden
On 12/3/2010 11:58 PM, Steven D'Aprano wrote:
> Right. If you define a *class* attribute, it lives in the class, not the 
> instance, and so all instances share the same value.

Unless, of course, an instance binds the same name in its namespace, in
which case it will (usually) mask the class attribute for that instance.

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: Which non SQL Database ?

2010-12-05 Thread Steve Holden
On 12/5/2010 12:59 AM, CM wrote:
> SQlite itself is around 300 kilobytes.  That's negligible.  It is also
> already in Python, so you'd have to purposefully exclude it in
> creating your executable to save those 300 kb and thus the 1/13th of a
> second additional time it would take average (3.9 MB/s) users to
> download your app if it were included.

Just as a matter of interest where do you get the information that the
average user has a 3.9 MB/s path to the Internet?

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