MySQLdb Error

2012-01-11 Thread Emeka
Hello All,

I got the below error why trying to create tables of the fly.

for item in ['CREATE TABLE AddressTables ( AddressTables_id int (9)
unsigned primary key auto_increment not null,  city_name char(40) ,
 state_name varchar,  street_number int,  country_name varchar,
 street_name char(40) , user_name char(40) references usertables(name))',
'CREATE TABLE UserTables ( age int,  UserTables_id int (9) unsigned primary
key auto_increment not null,  name char(40) ,  place_of_birth varchar)']:
cursor.execute(item)


I receive the following errors.
 File "mor.py", line 98, in 
cursor.execute(item)
  File "/usr/lib/pymodules/python2.7/MySQLdb/cursors.py", line 166, in
execute
self.errorhandler(self, exc, value)
  File "/usr/lib/pymodules/python2.7/MySQLdb/connections.py", line 35, in
defaulterrorhandler
raise errorclass, errorvalue
_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL
syntax; check the manual that corresponds to your MySQL server version for
the right syntax to use near '  street_number int,  country_name varchar,
 street_name char(40) , user_name ch' at line 1")
*

Regards,*
*Emeka


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


Re: MySQLdb Error

2012-01-11 Thread Chris Angelico
On Wed, Jan 11, 2012 at 6:57 PM, Emeka  wrote:
> CREATE TABLE AddressTables ( AddressTables_id int (9) unsigned
> primary key auto_increment not null,  city_name char(40) ,  state_name
> varchar,  street_number int,  country_name varchar,  street_name char(40) ,
> user_name char(40) references usertables(name))
>
> _mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL
> syntax; check the manual that corresponds to your MySQL server version for
> the right syntax to use near '  street_number int,  country_name varchar,
>  street_name char(40) , user_name ch' at line 1")

You're getting an error back from the database. The message suggests
that you look around the place cited for some kind of syntactic error.
See if you can find the error; often, in situations like this, the
actual error is a little bit before what's pointed to.

Have a look, I'll wait.







Spoiler alert! Try figuring it out yourself before you scroll down.







You've been warned! There are spoilers ahead.







Okay. The problem is that MySQL requires varchar to be followed by a
length: varchar(255) or varchar(32) or whatever. The use of naked
'varchar' is a PostgreSQL feature only.

Hope that helps!

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


Re: open office in another language?

2012-01-11 Thread Stefan Behnel
Sean Wolfe, 10.01.2012 22:43:
> I'm a somewhat-satisfied openoffice.org user. I mean it works, but if
> it weren't in Java I'd be doing some of my own tweaking. But since
> it's in Java I stay away... no likey.

It's been in C++ ever since the old StarOffice days, others have commented
on that already. Java is only one way of extending it, and it's not even
required by the installation.


> Has there been any talk of doing another similar office suite, or
> maybe just writer + spreadsheet, in a better language eg python? I
> expect it's a huge undertaking but ... thought I'd ask around at
> least.

OOo has been fully scriptable in Python for ages. It even comes with an
embedded Python runtime for that purpose (at least on
non-package-management systems like Windows). So, Python is actually a
standard component in all installations, whereas Java is not, and is
therefore not necessarily available in a deployment. Basically, if you want
your scripts to run in all OpenOffice/LibreOffice installations, you either
have to write it in StarBasic, or use Python.

The OOo extension API is called UNO, so look for the PyUNO bridge.
Admittedly, it's somewhat badly documented, but it basically works the same
way as the other UNO-API incarnations in other languages, so any UNO
documentation will generally apply just fine.

Also look for LibreOffice, as Ben Finney hinted. Since Oracle dropped Sun's
OOo commitment, many regard it as the future of OOo. It's certainly the
place where the development happens these days.

Stefan

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


Re: UnicodeEncodeError in compile

2012-01-11 Thread jmfauth
On 11 jan, 01:56, Terry Reedy  wrote:
> On 1/10/2012 8:43 AM, jmfauth wrote:
>
>
>
> > D:\>c:\python32\python.exe
> > Python 3.2.2 (default, Sep  4 2011, 09:51:08) [MSC v.1500 32 bit
> > (Intel)] on win
> > 32
> > Type "help", "copyright", "credits" or "license" for more information.
>  '\u5de5'.encode('utf-8')
> > b'\xe5\xb7\xa5'
>  '\u5de5'.encode('mbcs')
> > Traceback (most recent call last):
> >    File "", line 1, in
> > UnicodeEncodeError: 'mbcs' codec can't encode characters in position
> > 0--1: inval
> > id character
> > D:\>c:\python27\python.exe
> > Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit
> > (Intel)] on win
> > 32
> > Type "help", "copyright", "credits" or "license" for more information.
>  u'\u5de5'.encode('utf-8')
> > '\xe5\xb7\xa5'
>  u'\u5de5'.encode('mbcs')
> > '?'
>
> mbcs encodes according to the current codepage. Only the chinese
> codepage(s) can encode the chinese char. So the unicode error is correct
> and 2.7 has a bug in that it is doing "errors='replace'" when it
> supposedly is doing "errors='strict'". The Py3 fix was done 
> inhttp://bugs.python.org/issue850997
> 2.7 was intentionally left alone because of back-compatibility
> considerations. (None of this addresses the OP's question.)
>
> --

Ok. I was not aware of this.
PS Prev. post gets lost.

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


Re: UnicodeEncodeError in compile

2012-01-11 Thread jmfauth
On 11 jan, 01:56, Terry Reedy  wrote:
> On 1/10/2012 8:43 AM, jmfauth wrote:
>
> ...
>
> mbcs encodes according to the current codepage. Only the chinese
> codepage(s) can encode the chinese char. So the unicode error is correct
> and 2.7 has a bug in that it is doing "errors='replace'" when it
> supposedly is doing "errors='strict'". The Py3 fix was done 
> inhttp://bugs.python.org/issue850997
> 2.7 was intentionally left alone because of back-compatibility
> considerations. (None of this addresses the OP's question.)
>
> --

win7, cp1252

Ok. I was not aware of this.

>>> '\N{CYRILLIC SMALL LETTER A}'.encode('mbcs')
Traceback (most recent call last):
  File "", line 1, in 
UnicodeEncodeError: 'mbcs' codec can't encode characters in position
0--1: invalid character
>>> '\N{GREEK SMALL LETTER ALPHA}'.encode('mbcs')
Traceback (most recent call last):
  File "", line 1, in 
UnicodeEncodeError: 'mbcs' codec can't encode characters in position
0--1: invalid character

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


ANN: eGenix mx Base Distribution 3.2.2 (mxDateTime, mxTextTools, etc.)

2012-01-11 Thread eGenix Team: M.-A. Lemburg


ANNOUNCING

   eGenix.com mx Base Distribution

  Version 3.2.2 for Python 2.4 - 2.7

   Open Source Python extensions providing
 important and useful services
for Python programmers.

This announcement is also available on our web-site for online reading:
http://www.egenix.com/company/news/eGenix-mx-Base-Distribution-3.2.2-GA.html



ABOUT

The eGenix.com mx Base Distribution for Python is a collection of
professional quality software tools which enhance Python's usability
in many important areas such as fast text searching, date/time
processing and high speed data types.

The tools have a proven record of being portable across many Unix and
Windows platforms. You can write applications which use the tools on
Windows and then run them on Unix platforms without change due to the
consistent platform independent interfaces.

Contents of the distribution:

 * mxDateTime - Easy to use Date/Time Library for Python
 * mxTextTools - Fast Text Parsing and Processing Tools for Python
 * mxProxy - Object Access Control for Python
 * mxBeeBase - On-disk B+Tree Based Database Kit for Python
 * mxURL - Flexible URL Data-Type for Python
 * mxUID - Fast Universal Identifiers for Python
 * mxStack - Fast and Memory-Efficient Stack Type for Python
 * mxQueue - Fast and Memory-Efficient Queue Type for Python
 * mxTools - Fast Everyday Helpers for Python

The package also include a number of helpful smaller modules in the
mx.Misc subpackage, such as mx.Misc.ConfigFile for config file parsing
or mx.Misc.CommandLine to quickly write command line applications in
Python.

All available packages have proven their stability and usefulness in
many mission critical applications and various commercial settings all
around the world.

For more information, please see the distribution page:

http://www.egenix.com/products/python/mxBase/



NEWS

The 3.2.2 release of the eGenix mx Base Distribution is the latest release of 
our open-source Python
extensions.

The new patch-level version includes a few important fixes:

 * mxDateTime seconds rounding is now more careful to not show
   60.00 or 61.00 as second value.
 * mxDateTime will now correctly work with numeric arrays (numpy)
   again. Thanks to Christian Marquardt for reporting the problem.
 * mxDateTime's DateTimeFromAbsDateTime() now accepts leap second
   values (86400.0 - <86401.0) as well. Thanks to Christian Marquardt
   for reporting the problem.
 * Enhanced mx.Misc.ConfigFile. Please see the changelog for details
   (URL listed below).

If you are upgrading from eGenix mx Base 3.1.x, please also see the
eGenix mx Base Distribution 3.2.0 release notes for details on what
has changed and which new features are available:

http://www.egenix.com/company/news/eGenix-mx-Base-Distribution-3.2.0-GA.html

As always, we are providing pre-built binaries for all common
platforms: Windows 32/64-bit, Linux 32/64-bit, FreeBSD 32/64-bit, Mac
OS X 32/64-bit. Source code archives are available for installation on
all other Python platforms, such as Solaris, AIX, HP-UX, etc.

To simplify installation in Zope/Plone and other egg-based systems, we
have also precompiled egg distributions for all platforms. These are
available on our own PyPI-style index server for easy and automatic
download.

Whether you are using a pre-built package or the source distribution,
installation is a simple "python setup.py install" command in all
cases. The only difference is that the pre-built packages do not
require a compiler or the Python development packages to be installed.

For a full list of changes, please refer to the eGenix mx Base Distribution
change log at

http://www.egenix.com/products/python/mxBase/changelog.html

and the change logs of the various included Python packages.



DOWNLOADS

The download archives and instructions for installing the packages can
be found on the eGenix mx Base Distribution page:

http://www.egenix.com/products/python/mxBase/



LICENSE

The eGenix mx Base package is distributed under the eGenix.com Public
License 1.1.0 which is an Open Source license similar to the Python
license. You can use the packages in both commercial and non-commercial
settings without fee or charge.

The package comes with full source code



SUPPORT

Commercial support for this product is available from eGenix.com.
Please see

http://www.egenix.com/services/support/

for details about our support offerings.

Enjoy,
-- 
Marc-Andre Lemburg
eGenix.com

Professional Python 

Re: open office in another language?

2012-01-11 Thread Paul Rudin
Stefan Behnel  writes:


> OOo has been fully scriptable in Python for ages. It even comes with an
> embedded Python runtime for that purpose (at least on
> non-package-management systems like Windows). So, Python is actually a
> standard component in all installations, whereas Java is not, and is
> therefore not necessarily available in a deployment. Basically, if you want
> your scripts to run in all OpenOffice/LibreOffice installations, you either
> have to write it in StarBasic, or use Python.
>
> The OOo extension API is called UNO, so look for the PyUNO bridge.
> Admittedly, it's somewhat badly documented, but it basically works the same
> way as the other UNO-API incarnations in other languages, so any UNO
> documentation will generally apply just fine.
>
> Also look for LibreOffice, as Ben Finney hinted. Since Oracle dropped Sun's
> OOo commitment, many regard it as the future of OOo. It's certainly the
> place where the development happens these days.

I have dabbled with PyUNO in the past. One issue is that the api seems
rather unpythonic (to me, at least).




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


ERROR:root:code for hash md5 was not found

2012-01-11 Thread mike
Hi,

We are running are running Python program on Redhat 5.5.

When executing our program we get the following error ( see below).

Any ideas what this is due to?

br,

//mike

/pysibelius/lib/common/
DataTypes.py
Overwriten ...
ERROR:root:code for hash md5 was not found.
Traceback (most recent call last):
  File "/python/lib/python2.7/hashlib.py", line 139, in 
globals()[__func_name] = __get_hash(__func_name)
  File "/python/lib/python2.7/hashlib.py", line 91, in
__get_builtin_constructor
raise ValueError('unsupported hash type %s' % name)
ValueError: unsupported hash type md5
ERROR:root:code for hash sha1 was not found
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: UnicodeEncodeError in compile

2012-01-11 Thread pyscripter


On Wednesday, January 11, 2012 5:50:51 AM UTC+2, Terry Reedy wrote:
> On 1/10/2012 3:08 AM, Terry Reedy wrote:
> Is this a filename that could be an actual, valid filename on your system?

Yes it is. open works on that file.

> Good question. I believe this holdover from 2.x should be deleted.
> I argued that in http://bugs.python.org/issue10114
> (which was about a different problem) and now, directly, in
> http://bugs.python.org/issue13758
> 
Maybe the example of this question can be added to the issue 13785 as a proof 
that compile fails on valid file names.

But I think the real issue is why on modern Windows systems the file system 
encoding is mbcs.  Shouldn't it be utf-16?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ERROR:root:code for hash md5 was not found

2012-01-11 Thread Laurent Claessens

Le 11/01/2012 12:19, mike a écrit :

Hi,

We are running are running Python program on Redhat 5.5.

When executing our program we get the following error ( see below).

Any ideas what this is due to?


On my computer hashlib has "md5" :



Python 2.6.6 (r266:84292, Sep 15 2010, 16:22:56)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import hashlib
h=hashlib.new("md5")
h.update("Hello")
h.hexdigest()

'd992641f1b2b9c08b569c0a17c4e7cb8'

While if I ask for a hash method that hashlib does not know, I get the 
same error as you :


>>> g=hashlib.new("bla")
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python2.6/hashlib.py", line 101, in __hash_new
return __get_builtin_constructor(name)(string)
  File "/usr/lib/python2.6/hashlib.py", line 80, in 
__get_builtin_constructor

raise ValueError, "unsupported hash type"
ValueError: unsupported hash type


You should give us a more comprehensive example of your problem.

Laurent

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


Re: Newbie: Looking for code review on my first Python project.

2012-01-11 Thread HoneyMonster
On Tue, 10 Jan 2012 18:17:48 -0700, Ian Kelly wrote:

> On Tue, Jan 10, 2012 at 4:44 PM, HoneyMonster
>  wrote:
>> Hi,
>>
>> I'm new to Python and recently completed my first project. I used
>> wxPython with wxGlade to generate the GUI bits.The application seems to
>> work well, but I am entirely self-taught, so have undoubtedly committed
>> a number of howlers in terms of style, design, standards, best practice
>> and so forth.
< snip constructive and helpful advice >

Very many thanks to Ian and to all who responded. I really appreciate the 
guidance. Cheers.

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


Re: UnicodeEncodeError in compile

2012-01-11 Thread Dave Angel

On 01/11/2012 06:27 AM, pyscrip...@gmail.com wrote:


Maybe the example of this question can be added to the issue 13785 as a proof 
that compile fails on valid file names.

But I think the real issue is why on modern Windows systems the file system 
encoding is mbcs.  Shouldn't it be utf-16?
Depends what you mean by modern. The following isn't true for Windows 
95, 98, nor ME.  But they weren't modern when they were first released.


NT systems, (which includes Win2k, XP, Vista, and Win7)  for at least 
the last 15 years, have used Unicode for the file system.  They also 
supply an "ASCII" interface.  If Python is using the latter, then it 
won't be able to access all possible files.


Now, it may be the fault of the C library that CPython uses.  I haven't 
looked at any of the code for CPython.


This is all from memory, as I haven't actively used Windows for some 
time now.  But I think the DLL name is kernel32.dll, and the entry 
points have names like  CreateFileW() for the unicode open, and 
CreateFileA() for the "ASCII" open.


--

DaveA

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


Re: UnicodeEncodeError in compile

2012-01-11 Thread pyscripter
Indeed, on Windows NT the file system encoding should not be mbcs, since it 
creates UnicodeEncodeErrors on perfectly valid file names.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: open office in another language?

2012-01-11 Thread Stefan Behnel
Paul Rudin, 11.01.2012 11:17:
> Stefan Behnel writes:
>> OOo has been fully scriptable in Python for ages. It even comes with an
>> embedded Python runtime for that purpose [...]
> 
> I have dabbled with PyUNO in the past. One issue is that the api seems
> rather unpythonic (to me, at least).

Sure, UNO wasn't designed for Python. It's mostly a 1:1 mapping of the C++
API. I didn't find anything in a quick web search, but I'm pretty sure the
wrapper is auto-generated in some way.

But still: it's there, it's usable and it's even object oriented. And I
estimate that it's much easier to use from Python than from C++ (which I
never tried). If you want something better, feel free to write a pythonic
Cython wrapper of the C++ UNO API. May take a while, though, and you'll
also have to rewrite the entire UNO documentation to match your new
wrapper, so that people can actually start using it effectively.

Stefan

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


import problems.

2012-01-11 Thread Antoon Pardon

I have an import problem I can't figure out.
I am using python 2.6.6 on a debian box

In one directory (pylib) I have a file misc.py and
the file testutil.py.

 testutil.py --

print "in", __name__

from misc import Rec



calling this file in that directory gives me this:

$ python testutil.py
in __main__

In a neighbour directory I have the file ats

 atst 

import sys

from os.path import join as pj, abspath

print abspath("../pylib")

sys.path.append(abspath("../pylib"))

import testutil

---

Now calling this file in its directory gives me the following problem:
$ python atst
/local/home/apardon/src/projecten/pylib
in testutil
Traceback (most recent call last):
  File "atst", line 9, in 
import testutil
  File "/local/home/apardon/src/projecten/pylib/testutil.py", line 4, 
in 

from misc import Rec
ImportError: cannot import name Rec

Why can I import Rec from misc in testutil when I call testutil.py 
directly but not when testutil was imported itself?

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


Re: import problems.

2012-01-11 Thread Dave Angel

On 01/11/2012 08:21 AM, Antoon Pardon wrote:

I have an import problem I can't figure out.
I am using python 2.6.6 on a debian box

In one directory (pylib) I have a file misc.py and
the file testutil.py.

 testutil.py --

print "in", __name__

from misc import Rec



calling this file in that directory gives me this:

$ python testutil.py
in __main__

In a neighbour directory I have the file ats

 atst 

import sys

from os.path import join as pj, abspath

print abspath("../pylib")

sys.path.append(abspath("../pylib"))

import testutil

---

Now calling this file in its directory gives me the following problem:
$ python atst
/local/home/apardon/src/projecten/pylib
in testutil
Traceback (most recent call last):
  File "atst", line 9, in 
import testutil
  File "/local/home/apardon/src/projecten/pylib/testutil.py", line 4, 
in 

from misc import Rec
ImportError: cannot import name Rec

Why can I import Rec from misc in testutil when I call testutil.py 
directly but not when testutil was imported itself?
In your first case, Rec.py was in the current directory, which is one of 
the specs in classpath.  In the second case, your current directory was 
somewhere else.




--

DaveA

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


How do I tell "incomplete input" from "invalid input"?

2012-01-11 Thread Mateusz Loskot
Hi,

I have been trying to figure out a reliable way to determine
incomplete Python script
input using Python C API. (Apology if it is OT here, I'm not sure where my post
belongs, perhaps to cplusplus-sig list.)

Apparently, most pointers lead to the Python FAQ [1] question:
How do I tell "incomplete input" from "invalid input"?

Unfortunately, this FAQ is either old or incomplete thus incorrect.

First, the proposed testcomplete() function uses internal symbols
which are not available to Python C API users. So, "whoever wrote that FAQ
should be given 20 lashes with a short piece of string" [2].

The second solution is incomplete or incorrect. It does not handle correctly
multi-line input longer than two lines with more flow control statements.
For example:

##
>>> n = 10
>>> if n > 0:
...if n < 100:
  File "", line 2
if n < 100:
  ^
IndentationError: expected an indented block
>>>
##

or

##
>>> for n in range(0, 5):
... if n > 2:
  File "", line 2
if n > 2:
^
IndentationError: expected an indented block
>>>
##

I have attached a slightly modified C++ version of the second program
from the FAQ question [1],
file faq_incomplete_input.cpp  which is also available from my GitHub repo [3]
In this program, I added several FIX comments with proposed corrections.
The idea is to additionally check for
PyErr_ExceptionMatches (PyExc_IndentationError)
and
strcmp (msg, "expected an indented block")
and
prompt is sys.ps2, means more code expected.

And, ignore errors until user confirms the input is finished,
so the whole input is eventually sent to the Py_CompileString
and then all exceptions are not ignored, but considered
as real result of compilation.

I simply wanted to achieve similar semantic to codeop._maybe_compile()
(called by codeop.compile_command) which performs some sort of dirty
hack in the following line:

if not code1 and repr(err1) == repr(err2):

So, the test in action for multi-line multi-statement input gives:

##
>>> c = codeop.compile_command("for n in range(0, 3):", "test", "single")
err1 SyntaxError('unexpected EOF while parsing', ('test', 1, 22, 'for
n in range(0, 3):\n'))
err2 IndentationError('expected an indented block', ('test', 2, 1, '\n'))
comparison.err1 SyntaxError('unexpected EOF while parsing', ('test',
1, 22, 'for n in range(0, 3):\n'))
comparison.err2 IndentationError('expected an indented block',
('test', 2, 1, '\n'))
code None
code1 None
>>> c = codeop.compile_command("for n in range(0, 3):\n\tif n > 0:", "test", 
>>> "single")
err1 IndentationError('expected an indented block', ('test', 2, 11,
'\tif n > 0:\n'))
err2 IndentationError('expected an indented block', ('test', 3, 1, '\n'))
comparison.err1 IndentationError('expected an indented block',
('test', 2, 11, '\tif n > 0:\n'))
comparison.err2 IndentationError('expected an indented block',
('test', 3, 1, '\n'))
code None
code1 None
>>>
##

So, I reckon it make sense to use the same logic to when calling
Py_CompileString.

Does it sound as reasonable solution?

Basically, there seem to be no canonical solution anywhere presented
on how to perform incomplete input tests in reliable manner, how to perform
parsing/compilation in subsequent steps against Python code given line-by-line.

The C API used by Python function compile() is not publicly available.

There is PyRun_InteractiveLoop mechanism but it is tightly coupled to
FILE-based I/O which is not always available when Python is embedded,
so the loop is useless in number of situations.

Have I overlooked any other obvious solution?

Finally, it would be helpful if the Python FAQ is up to date.


[1] 
http://docs.python.org/py3k/faq/extending.html#how-do-i-tell-incomplete-input-from-invalid-input
[2] http://mail.python.org/pipermail/python-list/2004-August/887195.html
[3] https://github.com/mloskot/workshop/blob/master/python/

Best regards,
-- 
Mateusz Loskot, http://mateusz.loskot.net
//
// A quick and dirty C++ version of the C program presented in Python FAQ:
// http://docs.python.org/py3k/faq/extending.html#how-do-i-tell-incomplete-input-from-invalid-input
// Modifications:
// - do not use readline library, but 
//
// Tested using Visual C++ 2010 (10.0) and Python 3.2 (custom Debug build)
//
// The "incomplete input" solution presented in the FAQ is incomplete and it does
// not allow multi-line scripts with more than 2 lines of flow control statements:
//
//>>> n = 10
//>>> if n > 0:
//... if n < 100:
//  File "", line 2
//if n < 100:
//  ^
//IndentationError: expected an indented blo

Re: import problems.

2012-01-11 Thread Peter Otten
Antoon Pardon wrote:

> I have an import problem I can't figure out.
> I am using python 2.6.6 on a debian box
> 
> In one directory (pylib) I have a file misc.py and
> the file testutil.py.

>  from misc import Rec
> ImportError: cannot import name Rec
> 
> Why can I import Rec from misc in testutil when I call testutil.py
> directly but not when testutil was imported itself?

Without looking into the details, could it be that you have two misc.py 
files one with and one without Rec?


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


Re: import problems.

2012-01-11 Thread Antoon Pardon

On 01/11/2012 02:57 PM, Peter Otten wrote:

Antoon Pardon wrote:

   

I have an import problem I can't figure out.
I am using python 2.6.6 on a debian box

In one directory (pylib) I have a file misc.py and
the file testutil.py.
 
   

  from misc import Rec
ImportError: cannot import name Rec

Why can I import Rec from misc in testutil when I call testutil.py
directly but not when testutil was imported itself?
 

Without looking into the details, could it be that you have two misc.py
files one with and one without Rec

Well that depends on what you mean with "have".  This is what
turned up when I searched for "misc.py"

$ find /usr/local/lib /usr/lib /local/home/apardon -name misc.py -print 
2> /dev/null

/usr/lib/python2.6/compiler/misc.py
/usr/lib/pymodules/python2.6/PyQt4/uic/Compiler/misc.py
/usr/lib/pymodules/python2.6/numpy/oldnumeric/misc.py
/usr/lib/pymodules/python2.6/docutils/transforms/misc.py
/usr/lib/pymodules/python2.6/docutils/parsers/rst/directives/misc.py
/local/home/apardon/src/projecten/pylib/misc.py

That last one is my file, the rest doesn't seem to be in sys.path so 
they shouldn't interfere
as far as I understand. Changing the name of my file to miscutil.py 
resolves the problem though.


I'll see if I can figure out more.

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


Re: import problems.

2012-01-11 Thread Antoon Pardon

On 01/11/2012 03:45 PM, Antoon Pardon wrote:

On 01/11/2012 02:57 PM, Peter Otten wrote:

Antoon Pardon wrote:


I have an import problem I can't figure out.
I am using python 2.6.6 on a debian box

In one directory (pylib) I have a file misc.py and
the file testutil.py.
  from misc import Rec
ImportError: cannot import name Rec

Why can I import Rec from misc in testutil when I call testutil.py
directly but not when testutil was imported itself?

Without looking into the details, could it be that you have two misc.py
files one with and one without Rec

Well that depends on what you mean with "have".  This is what
turned up when I searched for "misc.py"

$ find /usr/local/lib /usr/lib /local/home/apardon -name misc.py 
-print 2> /dev/null

/usr/lib/python2.6/compiler/misc.py
/usr/lib/pymodules/python2.6/PyQt4/uic/Compiler/misc.py
/usr/lib/pymodules/python2.6/numpy/oldnumeric/misc.py
/usr/lib/pymodules/python2.6/docutils/transforms/misc.py
/usr/lib/pymodules/python2.6/docutils/parsers/rst/directives/misc.py
/local/home/apardon/src/projecten/pylib/misc.py

That last one is my file, the rest doesn't seem to be in sys.path so 
they shouldn't interfere
as far as I understand. Changing the name of my file to miscutil.py 
resolves the problem though.


I'll see if I can figure out more.


It seems there is a directory /usr/lib/pymodules/python2.6/misc in which 
is an empty __init.py__ file.
As far as I understand this makes misc a package on sys.path causing the 
problem.


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


Re: An "alternative" to Learning Perl

2012-01-11 Thread Sean Wolfe
On Tue, Jan 10, 2012 at 8:25 PM, Sebastian Rooks
 wrote:
> On Mon, 9 Jan 2012 00:55:22 -0300, Sean Wolfe 
> wrote:
>
>>kindle? ipad? tablet?
>
> I'm interested in books, not files ...
> (seriously, now ... I don't have any of those devices)
>
>>also there is python programming for the absolute beginner, which is
>>agreat book but it's pretty beginner. But well written. At least
>>Iliked 
>>it.http://www.amazon.com/Python-Programming-Absolute-Beginner-3rd/dp/1435455002
>>Also byte of python ... I think there's a hardcover version you can
>>buyhttp://www.swaroopch.com/buybook/
>
> I think I saw that second one somewhere already. I'll check out the
> first link, also. Thanks!
>

Yeah I hear you, I moved to Argentina from the US this year and my
ipad + kindle app has been great. I can buy lots of books which I
can't get down here and get access to them immediately, and I can
carry a whole library in my backpack. So +1 if you are thinking about
it. I like physical books as well but the portability factor is
awesome.
-- 
http://mail.python.org/mailman/listinfo/python-list


after applicatio​n close MS Visual C++ runtime library error occurs

2012-01-11 Thread Peter Irbizon
Hello, I am using psycopg2 in windows app, example:
import psycopg2
import psycopg2.extras
self.con = psycopg2.connect("dbname= host= user= password= port=");
self.cur = self.con.cursor(cursor_factory=psycopg2.extras.DictCursor)

SELECT = "select something"
self.cur.execute(SELECT)

for row in self.cur:
 ...

self.cur.close()
self.con.close()

But when I click on exit button in application MS Visual C++ runtime
library error occurs: This application has requested the runtime to
terminate it in unusual way.
What am I doing wrong?
-- 
http://mail.python.org/mailman/listinfo/python-list


contextlib.contextmanager and try/finally

2012-01-11 Thread johannh
I'm trying to write a context manager to handle database connections, under the 
principle that I should not rely on CPython's reference-counting semantics to 
clean up scarce resources, like connections.

I wrote:

@contexlib.contextmanager
def ensure_connection(con=None):
con_created = False
if con is None:
con_created, con = True, make_connection()
try:
yield con
finally:
if con_created:
con.close()

However, then I read the following paragraph from PEP-343:

Note that we're not guaranteeing that the finally-clause is
executed immediately after the generator object becomes unused,
even though this is how it will work in CPython.  This is similar
to auto-closing files: while a reference-counting implementation
like CPython deallocates an object as soon as the last reference
to it goes away, implementations that use other GC algorithms do
not make the same guarantee.  This applies to Jython, IronPython,
and probably to Python running on Parrot.

That suggests that I cannot rely on the contextlib.contextmanager decorator to 
ensure that the connection is closed and would have to write my own object with 
__enter__ and __exit__ methods to guarantee this.

Is this understanding accurate?  If so, could someone illustrate why this is 
so? 

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


Re: contextlib.contextmanager and try/finally

2012-01-11 Thread Neil Cerutti
On 2012-01-11, joha...@gmail.com  wrote:
> That suggests that I cannot rely on the
> contextlib.contextmanager decorator to ensure that the
> connection is closed and would have to write my own object with
> __enter__ and __exit__ methods to guarantee this.

contextmanager wraps your generator in an object with __enter__
and __exit__ methods for you.

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


Re: contextlib.contextmanager and try/finally

2012-01-11 Thread Robert Kern

On 1/11/12 3:45 PM, joha...@gmail.com wrote:

I'm trying to write a context manager to handle database connections, under the 
principle that I should not rely on CPython's reference-counting semantics to 
clean up scarce resources, like connections.

I wrote:

@contexlib.contextmanager
def ensure_connection(con=None):
 con_created = False
 if con is None:
 con_created, con = True, make_connection()
 try:
 yield con
 finally:
 if con_created:
 con.close()

However, then I read the following paragraph from PEP-343:

 Note that we're not guaranteeing that the finally-clause is
 executed immediately after the generator object becomes unused,
 even though this is how it will work in CPython.  This is similar
 to auto-closing files: while a reference-counting implementation
 like CPython deallocates an object as soon as the last reference
 to it goes away, implementations that use other GC algorithms do
 not make the same guarantee.  This applies to Jython, IronPython,
 and probably to Python running on Parrot.

That suggests that I cannot rely on the contextlib.contextmanager decorator to 
ensure that the connection is closed and would have to write my own object with 
__enter__ and __exit__ methods to guarantee this.

Is this understanding accurate?  If so, could someone illustrate why this is so?


Looking at the paragraph before this one, it appears that the PEP is talking 
about the .close() method on generators, which is really just a general purpose 
API for closing generators that might not be exhausted yet. It's not really 
related to the context manager stuff except that it came up during the design 
process of the context manager along with the related .send() and .throw() methods.


__enter__() will call .next() once to execute the code up to the yield 
statement. Then __exit__() will call .next() once again to execute the code 
after the yield statement, including the finally: clause. That's the only thing 
you need to rely on. Your connection-closing code will be called if __exit__() 
gets called. That will exhaust your generator, so the .close() method will not 
really do anything helpful or hurtful in such a case.


--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


Re: contextlib.contextmanager and try/finally

2012-01-11 Thread Ian Kelly
On Wed, Jan 11, 2012 at 8:45 AM,   wrote:
> However, then I read the following paragraph from PEP-343:
>
>    Note that we're not guaranteeing that the finally-clause is
>    executed immediately after the generator object becomes unused,
>    even though this is how it will work in CPython.  This is similar
>    to auto-closing files: while a reference-counting implementation
>    like CPython deallocates an object as soon as the last reference
>    to it goes away, implementations that use other GC algorithms do
>    not make the same guarantee.  This applies to Jython, IronPython,
>    and probably to Python running on Parrot.
>
> That suggests that I cannot rely on the contextlib.contextmanager decorator 
> to ensure that the connection is closed and would have to write my own object 
> with __enter__ and __exit__ methods to guarantee this.
>
> Is this understanding accurate?  If so, could someone illustrate why this is 
> so?

First, this is just a timing issue.  There is no guarantee that the
finally clause will be executed immediately, but it is guaranteed to
be executed at some point.  In the other implementations, it would
happen whenever the GC algorithm runs.

Second, I believe that passage is not referring to the contextmanager
decorator specifically, but more generally to the changes that were
made to allow generators to yield from within a try-finally construct
(previously this would have been illegal syntax, since there was no
way to guarantee the finally block would be performed).

Like Neil mentioned, a contextmanager generator is wrapped with an
__exit__ method that is guaranteed to be called and that explicitly
resumes or closes the generator.  So as long as your contextmanager
generator is properly written (i.e. it yields exactly once), the
finally block will execute in a timely fashion.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: contextlib.contextmanager and try/finally

2012-01-11 Thread johannh
On Wednesday, January 11, 2012 11:20:19 AM UTC-6, Ian wrote:
> 
> Second, I believe that passage is not referring to the contextmanager
> decorator specifically, but more generally to the changes that were
> made to allow generators to yield from within a try-finally construct
> (previously this would have been illegal syntax, since there was no
> way to guarantee the finally block would be performed).

Thanks.  You and Robert have shown me the light.  That paragraph was talking 
about the finalization that happens to a suspended generator when it is GC'd.  
Meanwhile, the contextmanager decorator ensures that its generator is run all 
the way through, so it would never be left in a suspended state, so its 
GC/finalization semantics are irrelevant. (Please correct, if wrong.)

(Neil: I understood that it created a context manager object, but I had been 
reading the quoted paragraph to mean that by going through a generator the 
decorator was re-introducing a dependency on GC time.  But I was wrong.)

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


Re: ERROR:root:code for hash md5 was not found

2012-01-11 Thread Terry Reedy

On 1/11/2012 6:19 AM, mike wrote:

Hi,

We are running are running Python program on Redhat 5.5.

When executing our program we get the following error ( see below).

Any ideas what this is due to?

br,

//mike

/pysibelius/lib/common/



DataTypes.py
Overwriten ...
ERROR:root:code for hash md5 was not found.


These 3 lines do not come from the interpreter.
It might come from the hashlib module.


Traceback (most recent call last):
   File "/python/lib/python2.7/hashlib.py", line 139, in
 globals()[__func_name] = __get_hash(__func_name)
   File "/python/lib/python2.7/hashlib.py", line 91, in
__get_builtin_constructor
 raise ValueError('unsupported hash type %s' % name)
ValueError: unsupported hash type md5


This is a standard traceback from the interpreter.
The manual says that md5 should always be available.
On the other hand, hashlib depends on the OpenSSL library on your 
system. Perhaps RedHat removed md5 because it has been broken.
I suggest you ask them or check your OpenSSL doc. The Python manual may 
need to be changed.



ERROR:root:code for hash sha1 was not found


--
Terry Jan Reedy

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


Re: How do I tell "incomplete input" from "invalid input"?

2012-01-11 Thread Terry Reedy

On 1/11/2012 8:50 AM, Mateusz Loskot wrote:


Unfortunately, this FAQ is either old or incomplete thus incorrect.


If you have a suggested change to the current text, please submit it to 
the tracker at bugs.python.org


--
Terry Jan Reedy

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


Re: your feedback to my first project please

2012-01-11 Thread D'Arcy Cain

On 12-01-08 02:46 PM, patr...@bierans.de wrote:

Thanks for the feedback!


You're welcome.


D'Arcy wrote: [code examples]

But I will keep some of my underscores for "private" attributes and methods.
And I googled: "dim" was basic. I know too many languages and start mixing
the keywords - shame on me. ;)


No problem but don't overuse the underscores.  It starts to look like
Perl.  The parameters to the methods and the local variables in the
methods will not pollute your namespace.  The only area you need to
concern yourself with is module level object references.

>>> import mymodule
>>> print dir(mymodule)

that's the list you need to be concerned with.  You will see that a lot
of names are already private.  In the case you present I don't think
that anything there was private that is not already private based on
what it inherits from object.


Good Eye: I wrote the tests after coding - I know that this is the wrong way.
I just wanted to start coding and after some time I decided that I shoud have
some test cases. This is no real TDD - true. ;) I'll do that right next time.


This is the number one lesson you should take to heart from this.


After thinking about it: Yupp. You are right. Having written tests to check
"private" attributes really hurts one's pride. ;)


And you don't want to.  The test cases should make sure that public
objects and methods act as specified.  That's what allows you to
refactor any time you want.

--
D'Arcy J.M. Cain  |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
IM: da...@vex.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: Explanation about for

2012-01-11 Thread Νικόλαος Κούρας
Thank you All for the detailed examples.

I tried them all in IDLE and i finally understood them.

Thanks for your patience with me until i understand!

2012/1/10 Nick Dokos 

> Νικόλαος Κούρας  wrote:
>
> > On 10 Ιαν, 03:11, Ian Kelly  wrote:
> > > 2012/1/9 Íéêüëáïò Êïýñáò :
> > >
> > > > if the MySQL query was:
> > >
> > > > cursor.execute( '''SELECT host, hits, agent, date FROM visitors
> WHERE pin =
> > > > %s ORDER BY date DESC''', pin )
> > >
> > > > can you help me imagine how the mysql database cursor that holds the
> query
> > > > results would look like? I must somehow visualize it in order to
> understand
> > > > it!
> > >
> > > You can think of it as a pointer, traversing over one row of the
> > > result set at a time.  Hopefully this will come out legibly:
> > >
> > > ---
> > > | HOST | HITS | AGENT | DATE |
> > > ---
>  -
> > > | foo | 7   | IE6   | 1/1/11 |   <   | cursor |
> > > ---
>  -
> > > | bar | 42 | Firefox  | 2/2/10 |
> > > ---
> > > | baz| 4   | Chrome | 3/3/09 |
> > > 
> >
> > Database cursor is the pointer that iterates over the result set one
> > row at a time?
> > I though that it was the name we give to the whole mysql result set
> > returned my cursor.execute.
> >
> > >
> > >
> > > > Also what happend if the query was:
> > > > cursor.execute( '''SELECT host FROM visitors") ?
> > >
> > > > the result would have to be something likelike?
> > >
> > > > -
> > > > |somehost1|
> > > > -
> > > > |somehost2|
> > > > -
> > > > |somehost3|
> > > > -
> > > > .
> > > > .
> > > > |somehost n|
> > > > -
> > >
> > > > So what values host, hits, agent, date would have in 'for host,
> hits, agent,
> > > > date in
> > > >  dataset' ? Every row has one string how can that be split in 4?
> > >
> > > Why don't you try it and see what happens?  But to spare you the
> > > suspense, you would get:
> > >
> > > ValueError: need more than 1 value to unpack
> > >
> > > Because you can't unpack a 1-length tuple into four variables.  The
> > > code assumes that the query is selecting exactly 4 columns.
> >
> >
> > ---
> > | HOST| HITS| AGENT | DATE |
> > ---
> > | foo | 7   | IE6   | 1/1/11 |
> > ---
> > | bar | 42  | Firefox   | 2/2/10 |
> > ---
> > | baz | 4   | Chrome| 3/3/09 |
> > ---
> >
> > In this line:
> > for host, hits, agent, date in dataset:
> >
> > 'dataset' is one of the rows of the mysql result or the whole mysql
> > result set like the table above?
> >
> > I still have trouble understanding this line :(
>
> You can think of it as a list of tuples. Forget about cursors and
> databases for now. If l is a list [1, 2, 3, 4] you iterate over it like
> this:
>
> for x in l:
>  print x
>
> and you get each element of the list[fn:1]. Similarly if l is a list of
> tuples
> l = [(1, 2, 3, 4), (5, 6, 7, 8), (9, 10, 11, 12)] you can iterate over the
> list:
>
> for x in l:
>  print x
>
> In this case, x is going to be (1,2,3,4) the first time through the loop,
> (5,6,7,8)
> the second time and so on. You can break each x apart within the loop:
>
> for x in l:
>  t1, t2, t3, t4 = x
>  print x, t1, t2, t3, t4
>
> or you can break it apart like this - it's essentially the same thing:
>
> for t1, t2, t3, t4 in l:
>  print t1, t2, t3, t4
>
> You have been encouraged repeatedly to try these things interactively:
> please do so with the above examples and all will become clear.
>
> Going back to cursors and databases: you *can* think of 'dataset' as
> being a list of tuples - a list of all the query results, but with one
> proviso. The difference when you use a cursor is that `dataset' may
> be a lazy list (an "iterator"): instead of the whole set of results
> being in memory at the same time, the system will take care of doing
> whatever is necessary to get more of the results when it needs them. But
> the behavior is the *same* in the sense that the output that you get is
> the same (you will only see differences if you are keeping an eye on how
> much memory and how much time your program is using).
>
> Nick
>
> Footnotes:
>
> [fn:1] ... and, no, you *can't express* this as
> "the first time it is
>
> for x in 1:
>  ...
>
> and the second time it is
>
> for x in 2:
>  ...
>
> " as you asked in another email. That's arrant nonsense: x takes
> successive values in the list l for every iteration of the for
> loop. This is elementary Python (nay, elementary 

Re: MySQLdb Error

2012-01-11 Thread Emeka
Thanks.

Regards,
Janus

On Wed, Jan 11, 2012 at 7:12 PM, Dennis Lee Bieber wrote:

> On Wed, 11 Jan 2012 09:57:43 +0200, Emeka  wrote:
>
>
> >_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL
> >syntax; check the manual that corresponds to your MySQL server version for
> >the right syntax to use near '  street_number int,  country_name varchar,
> > street_name char(40) , user_name ch' at line 1")
> >*
> >
>
>Per http://dev.mysql.com/doc/refman/5.1/en/create-table.html and
> http://dev.mysql.com/doc/refman/5.1/en/char.html VARCHAR fields
> /require/ the maximum length of the field to be defined. Length appears
> optional for CHAR -- probably defaulting to 1 character.
> --
>Wulfraed Dennis Lee Bieber AF6VN
>wlfr...@ix.netcom.comHTTP://wlfraed.home.netcom.com/
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
*Satajanus  Nig. Ltd


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


Re: Newbie: Looking for code review on my first Python project.

2012-01-11 Thread HoneyMonster
On Wed, 11 Jan 2012 11:39:48 +, HoneyMonster wrote:

> On Tue, 10 Jan 2012 18:17:48 -0700, Ian Kelly wrote:
> 
>> On Tue, Jan 10, 2012 at 4:44 PM, HoneyMonster
>>  wrote:
>>> Hi,
>>>
>>> I'm new to Python and recently completed my first project. I used
>>> wxPython with wxGlade to generate the GUI bits.The application seems
>>> to work well, but I am entirely self-taught, so have undoubtedly
>>> committed a number of howlers in terms of style, design, standards,
>>> best practice and so forth.
> < snip constructive and helpful advice >
> 
> Very many thanks to Ian and to all who responded. I really appreciate
> the guidance. Cheers.


I have taken on board the helpful suggestions offered, and looked though 
the PEP-8 document which has been mentioned.

As a result, there are a number of changes to the code. My second attempt 
is in the same place:



A couple of points:

1) I'm reluctant to try to improve this bit of code:
-
self.add = wx.MenuItem(self.file, wx.NewId(), "&Add to Queue", 
"Add a programme to the queue (for download later)", wx.ITEM_NORMAL)
self.file.AppendItem(self.add)
-
since it is generated by wxGlade and so will be overwritten.

2) I was very unsure about the wx.CallAfter, and suspect that I have put 
it in the wrong place. It seems to pass off well enough in Linux, but on 
Windows it appears to prevent the widgets on the splash frame being drawn 
properly.

If anyone would be kind enough, further comments would be welcomed.

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


stable object serialization to text file

2012-01-11 Thread Máté Koch
Hello All,I'm developing an app which stores the data in file system database. The data in my case consists of large python objects, mostly dicts, containing texts and numbers. The easiest way to dump and load them would be pickle, but I have a problem with it: I want to keep the data in version control, and I would like to use it as efficiently as possible. Is it possible to force pickle to store the otherwise unordered (e.g. dictionary) data in a kind of ordered way, so that if I dump a large dict, then change 1 tiny thing in it and dump again, the diff of the former and the new file will be minimal?If pickle is not the best choice for me, can you suggest anything else? (If there isn't any solution for it so far, I will write the module of course, but first I'd like to look around and make sure it hasn't been created yet.)Thanks,Mate-- 
http://mail.python.org/mailman/listinfo/python-list


Re: open office in another language?

2012-01-11 Thread Martin Manns
On Tue, 10 Jan 2012 18:43:09 -0300
Sean Wolfe  wrote:
 
> Has there been any talk of doing another similar office suite, or
> maybe just writer + spreadsheet, in a better language eg python? I
> expect it's a huge undertaking but ... thought I'd ask around at
> least.

If you are looking for Python based spreadsheets, 
you may be interested in ResolverOne (commercial product)

http://www.resolversystems.com/products/resolver-one/

or in pyspread (GPL, my own effort)

http://manns.github.com/pyspread/

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


Python lib for creating Database tables

2012-01-11 Thread Emeka
Hello All,

I just made something pretty simple that I intend to use while creating
database tables. It is still in the basic form, and much needs to be added.
However, I use introspection to make it a bit easier and less work on the
user.

I would want my code to be reviewed by this great group. I look forward to
your feedback  and comments.
https://github.com/janus/cheeta


Thanks in advance!

Regards,
Emeka


*

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


Re: open office in another language?

2012-01-11 Thread Sean Wolfe
On Wed, Jan 11, 2012 at 6:35 PM, Martin Manns  wrote:
> or in pyspread (GPL, my own effort)
>
> http://manns.github.com/pyspread/
>

Checking this out now. Do you have text boxes? Cause maybe I will add
some ... cool!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie Help

2012-01-11 Thread mixolydian
mixolydian  wrote:
>I want to get into Python progamming for both local database applications and 
>dynamic web pages. Maybe some Q&D scripts.
>There is a ton of excellent language books.
>
>I have downloaded and installed 2.7.2 and got it working by pasting samples 
>into IDLE, and uploading to my web server and doing trial CGI samples. 
>So far, so good.
>
>I would like some advice on:
>  1. IDEs
>  2. GUI tools, tkinter and others
>  3. An integrated web server package for Win Vista for testing web apps 
>before 
>deploying. Uploading to my ISP to run is a PIA. I've installed VertrigoServ to 
>try, but am chasing my tail around the Apache configuration.
>  Is there something easier?
>Just pointers to get me started would be fine.
>
>More info.I will be migrating data base apps from MSAccess 2000. I know, I 
>know, but it was free on my original Win 95 PC.
>I've been programming for 50 years and have had to learn (and unlearn) a lot, 
>and I'm eager to learn new stuff.
>

Thanks to all those who replied.

I am using Notepad++ and WampServer. My hosting service is 
Apache/phpMyAdmin/MySQL and I decided it was best to use the same on my Windoze 
development system.

Right now I'm revising my site HTML (much of it is 15 yrs old!). Later it will 
be upgraded to use server-side scripts. Perhaps then I'll look at Django, 
Cherrpy; etc.

>Thanks.

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


Re: Explanation about for

2012-01-11 Thread RainyDay
On Jan 10, 6:37 am, Νικόλαος Κούρας  wrote:
> On 10 Ιαν, 12:57, Thomas Rachel 
>
>
>
>
>
>
>
>
> a470-7603bd3aa...@spamschutz.glglgl.de> wrote:
> > Am 10.01.2012 10:02 schrieb Νικόλαος Κούρας:
>
> > > ---
> > > | HOST    | HITS    | AGENT     | DATE |
> > > ---
> > > | foo     | 7       | IE6       | 1/1/11 |
> > > ---
> > > | bar     | 42      | Firefox   | 2/2/10 |
> > > ---
> > > | baz     | 4       | Chrome    | 3/3/09 |
> > > ---
>
> > > In this line:
> > > for host, hits, agent, date in dataset:
>
> > > 'dataset' is one of the rows of the mysql result or the whole mysql
> > > result set like the table above?
>
> > dataset is a cursor, representing the whole result set.
>
> > Iterating over it produces one row at each iteration step:
>
> > for row in dataset:
> >      ...
>
> > As each row consists of 4 fields, one iteration result is a tuple of 4
> > elements.
>
> > In this case,
>
> > for host, hits, agent, date in dataset:
>
> So that means that
>
> for host, hits, agent, date in dataset:
>
> is:
>
> for host, hits, agent, date in  (foo,7,IE6,1/1/11)
>
> and then:
>
> for host, hits, agent, date in  (bar,42,Firefox,2/2/10)
>
> and then:
>
> for host, hits, agent, date in  (baz,4,Chrome,3/3/09)
>
> So 'dataset' is one row at each time?
> but we said that 'dataset' represent the whole result set.
> So isnt it wrong iam substituting it with one line per time only?


It maps naturally to a phrase 'for page in a book'. Book refers
to a complete book with all pages, but 'for page in a book' refers
to each page, one by one. 'for each page in book: turn it'. The
meaning is to turn each page, so your question is equivalent
to asking 'so book is one page at each time'? No, it is not
and doesn't have to be (unless it's a really short book!)

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


Re: How do I tell "incomplete input" from "invalid input"?

2012-01-11 Thread mloskot

Terry Reedy wrote
> 
> On 1/11/2012 8:50 AM, Mateusz Loskot wrote:
>> Unfortunately, this FAQ is either old or incomplete thus incorrect.
> 
> If you have a suggested change to the current text, please submit it to 
> the tracker at bugs.python.org
> 

Yes, this is quite obvious procedure to me, but first I wanted to discuss
the problem
and to try to find proper solution worth to be included in the FAQ.

Best regards,

-
-- 
Mateusz Loskot
http://mateusz.loskot.net
--
View this message in context: 
http://python.6.n6.nabble.com/How-do-I-tell-incomplete-input-from-invalid-input-tp3585241p3632798.html
Sent from the Python - python-list mailing list archive at Nabble.com.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ERROR:root:code for hash md5 was not found

2012-01-11 Thread Steven D'Aprano
On Wed, 11 Jan 2012 05:54:29 -0800, mike wrote:

> I did some more digging and found that our class imports a "yacc.py"
> that uses
> 
> import re, types, sys, cStringIO, hashlib, os.path
> 
> so it has hashlib.
> 
> yacc.py seems to be an old version 1.3 ( I found 2.3 -->).
> 
> Reading about hashlib it seems to be dependent on os installation of
> OpenSSL but I cannot find out how.

It shouldn't be. It will use OpenSSL if available, otherwise it will fall 
back on its own code.


> br,
> 
> //mike
> 
> yacc.py
> ===
> 
#-
> # ply: yacc.py
[snip over TWO THOUSAND lines of code]


Mike, what lead you to believe that an error in hashlib could be solved 
by posting the ENTIRE two thousand lines of yacc.py? Please do not post 
such huge chunks of code unless asked. It is unnecessary and annoying.

Try this. Open a terminal window and enter "python" at the prompt to 
start a clean interactive session. Then enter the following commands:

import sys
print(sys.version)
import hashlib
print(hashlib.__file__)
print(hashlib.md5)
import _md5
print(_md5.__file__)

and copy and paste (do not retype) the full output of these commands.




Thank you.




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


Re: Python lib for creating Database tables

2012-01-11 Thread Jason Friedman
> Hello All,
>
> I just made something pretty simple that I intend to use while creating
> database tables. It is still in the basic form, and much needs to be added.
> However, I use introspection to make it a bit easier and less work on the
> user.
>
> I would want my code to be reviewed by this great group. I look forward to
> your feedback  and comments.
> https://github.com/janus/cheeta

Cheeta has similarities to http://www.sqlalchemy.org/.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie: Looking for code review on my first Python project.

2012-01-11 Thread 88888 Dihedral
HoneyMonster於 2012年1月12日星期四UTC+8上午5時09分13秒寫道:
> On Wed, 11 Jan 2012 11:39:48 +, HoneyMonster wrote:
> 
> > On Tue, 10 Jan 2012 18:17:48 -0700, Ian Kelly wrote:
> > 
> >> On Tue, Jan 10, 2012 at 4:44 PM, HoneyMonster
> >>  wrote:
> >>> Hi,
> >>>
> >>> I'm new to Python and recently completed my first project. I used
> >>> wxPython with wxGlade to generate the GUI bits.The application seems
> >>> to work well, but I am entirely self-taught, so have undoubtedly
> >>> committed a number of howlers in terms of style, design, standards,
> >>> best practice and so forth.
> > < snip constructive and helpful advice >
> > 
> > Very many thanks to Ian and to all who responded. I really appreciate
> > the guidance. Cheers.
> 
> 
> I have taken on board the helpful suggestions offered, and looked though 
> the PEP-8 document which has been mentioned.
> 
> As a result, there are a number of changes to the code. My second attempt 
> is in the same place:
> 
> 
> 
> A couple of points:
> 
> 1) I'm reluctant to try to improve this bit of code:
> -
> self.add = wx.MenuItem(self.file, wx.NewId(), "&Add to Queue", 
> "Add a programme to the queue (for download later)", wx.ITEM_NORMAL)
> self.file.AppendItem(self.add)
> -
> since it is generated by wxGlade and so will be overwritten.
> 
> 2) I was very unsure about the wx.CallAfter, and suspect that I have put 
> it in the wrong place. It seems to pass off well enough in Linux, but on 
> Windows it appears to prevent the widgets on the splash frame being drawn 
> properly.
> 
> If anyone would be kind enough, further comments would be welcomed.
> 
> Thanks,
> WH

I haven't tried wxGlade for several years. I checked BOA, WxGlade and  Wxpython 
and pygame 4 years ago. Auto code generators in BOA and WxGlade are more helpful
to python programmers.  

One can develop GUI by  python with  Tcl/tk or Qt, too.   
But the license conditions in software packages are not all the same.  

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


Re: open office in another language?

2012-01-11 Thread 88888 Dihedral
Open Office suite software users are  most non-programmers. 
Software to be used by non-programmers are different from most  free python 
packages shared by programmers. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Introspecting optparse/argparse objects

2012-01-11 Thread alex23
On Jan 11, 11:26 am, Evan Driscoll  wrote:
> (For a concrete idea of a use case, suppose that it did not
> directly support the --help option and I wanted to write code that took
> its place.)

That's a pretty weird definition of 'concrete use case', but anyway...

> This means that either I need to write my own wrappers around options,
> option groups, and perhaps even an option parser, or I have to dig into
> _variables _that _are _not _part _of _the _public _api. Both of those
> choices are distasteful.

If you're wanting to extend the behaviour of the options, won't you
need to wrap them anyway?

But more to the point, you already have the data: you used it to
create the options. Why not just keep a handle on that data and refer
to what you need directly?

> 2) Is there some particular reason that this API *isn't* provided, and
> if I asked for it I might get it in a future version?

Not in optparse, as it's no longer being developed. For argparse, you
might want a better use case: adding functionality to support a
hypothetical "lack" of functionality (which is _actually_ provides)
seems like a pedantic exercise to me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Two questions about logging

2012-01-11 Thread Matthew Pounsett
I'm trying to figure out a couple of things with the logging module,
and I'm hoping someone can provide some pointers.  I've read through
the module docs on python.org, the basic and advanced tutorials, and
the cookbook post, but a couple of things still elude me.

First, I'd like to be able to permit users to do more typical log
rotation, based on their OS's log rotation handler, rather than
rotating logs from inside an application.  This is usually handled by
signalling an application with a HUP, whereupon it closes and then re-
opens all of its logs, getting new file handles (and new inodes).  I
don't see anything in the Handler methods (or anywhere else) that
would let me tell a logger object to refresh the file handles on a log
file.  Is there some standard way to deal with this?

Second, I'm trying to get a handle on how libraries are meant to
integrate with the applications that use them.  The naming advice in
the advanced tutorial is to use __name__ to name loggers, and to allow
log messages to pass back up to the using application's logger for
processing, but these two pieces of advice seem contradictory.. since
log messages only pass back up to the root if the loggers are named
hierarchically.

> cat foo.py
#!/usr/bin/env python

import logging
import bar

logger = logging.getLogger(__name__)
fh = logging.FileHandler('foo.log')
ch = logging.StreamHandler()
logger.addHandler(fh)
logger.addHandler(ch)
logger.warning('from the first')
bar.funct()

> cat bar.py
#!/usr/bin/env python

import logging

def funct():
logger = logging.getLogger(__name__)
logger.warning('from the second')

> ./foo.py
from the first
No handlers could be found for logger "bar"

So, given this state of affairs, how is a library author to use
loggers, given that he or she can't know how authors who use the
library will name their logger objects?  In the above example, what
would the author of bar.py do to hook up bar's logger with foo's,
without knowing in advance what foo's logger will be named?


Thanks very much for any suggestions, or pointers to documentation
that I've missed.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Two questions about logging

2012-01-11 Thread Roy Smith
In article 
<7dabf43f-3814-47b6-966a-1439f5654...@i6g2000vbk.googlegroups.com>,
 Matthew Pounsett  wrote:

> First, I'd like to be able to permit users to do more typical log
> rotation, based on their OS's log rotation handler, rather than
> rotating logs from inside an application.  This is usually handled by
> signalling an application with a HUP, whereupon it closes and then re-
> opens all of its logs, getting new file handles (and new inodes).  I
> don't see anything in the Handler methods (or anywhere else) that
> would let me tell a logger object to refresh the file handles on a log
> file.  Is there some standard way to deal with this?

What I would do is log to syslog (logging.handlers.SysLogHandler) and 
let syslog worry about rotating log files.  Why reinvent the wheel?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Introspecting optparse/argparse objects

2012-01-11 Thread Evan Driscoll
On 1/11/2012 19:37, alex23 wrote:
> On Jan 11, 11:26 am, Evan Driscoll  wrote:
>> (For a concrete idea of a use case, suppose that it did not
>> directly support the --help option and I wanted to write code that took
>> its place.)
> That's a pretty weird definition of 'concrete use case', but anyway...
It's actually closer to the truth than it might seem. I want to feed a
bash-completion-style thing, using the same data structure to both
figure out the possible completions and also do the actual parsing. "Do
the actual parsing" = optparse/argparse, while "figure out the possible
completions" = I need to be able to look at a list.

> If you're wanting to extend the behaviour of the options, won't you
> need to wrap them anyway?
I don't have any need to extend the parsers other than to get the list
of options. (Though now that you've brought that up, perhaps looking at
the _private fields in a subclass would be the best tradeoff? Hmmm.)

> But more to the point, you already have the data: you used it to
> create the options. Why not just keep a handle on that data and refer
> to what you need directly?
But now you're talking about wrapping the parser, because there's no
builtin way (at least that I know of) to store the information in such a
way that you can call the function, because it uses a mix of positional
and keyword arguments. E.g. I can't say just
args = ('-f', '--foo', help='do foo')
...
parser.add_argument(*args)
but would have to say something like
args = ( ('-f', '-foo'), {'help': 'do foo'})
...
parser.add_argument(*args[0], *args[1])
or something like that.

I'd want to add some function like 'make_option' which wraps all that
up, and then provide a nicer interface for add_argument, etc., and it
seems like pretty soon I're reimplementing the optparse API. :-) Or at
least it might be that way.

Evan



signature.asc
Description: OpenPGP digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Ctypes compatibility

2012-01-11 Thread Evan Driscoll
On 1/10/2012 22:42, Alec Taylor wrote:
> Use size_t
>
> http://en.wikipedia.org/wiki/C_data_types#Size_and_pointer_difference_types
Um, perhaps you misunderstand. I don't control the C API, I'm calling a
function that just exists in libc (unless I do what I said and write a
wrapper). If you're saying I should use c_size_t on the Python side, I
think that's outright wrong since I think some of the fields in the
dirent struct are 64 bits even on 32-bit systems. (I might be wrong
about that though.)

And even neglecting that, the types of the fields is only part of the
problem.

Evan




signature.asc
Description: OpenPGP digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Two questions about logging

2012-01-11 Thread Matthew Pounsett
On Jan 11, 9:34 pm, Roy Smith  wrote:
> What I would do is log to syslog (logging.handlers.SysLogHandler) and
> let syslog worry about rotating log files.  Why reinvent the wheel?

Syslog is fine for an application run by an administrator, but isn't
an option for a user.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to install lxml in window xp?

2012-01-11 Thread Tamer Higazi
Use Linux!
Specially Gentoo Linux!


Tamer

Am 09.01.2012 10:18, schrieb 水静流深:
> in my xp ,python26,easy_install  installed.
> i  want  to  install  lxml in window xp
> 1.c:\python26\scripts\easy_install  lxml
> 
> what i get is:
> 
> Reading http://codespeak.net/lxml
> Best match: lxml 2.3.3
> Downloading http://lxml.de/files/lxml-2.3.3.tgz
> Processing lxml-2.3.3.tgz
> Running lxml-2.3.3\setup.py -q bdist_egg --dist-dir
> c:\windows\temp\easy_install
> -58e4ap\lxml-2.3.3\egg-dist-tmp-hyg1bg
> Building lxml version 2.3.3.
> Building with Cython 0.15.1.
> ERROR: 'xslt-config' is not recognized as an internal or external command,
> operable program or batch file.
> 
> ** make sure the development packages of libxml2 and libxslt are
> installed **
> 
> Using build configuration of libxslt
> warning: no files found matching 'lxml.etree.c' under directory 'src\lxml'
> warning: no files found matching 'lxml.objectify.c' under directory
> 'src\lxml'
> warning: no files found matching 'lxml.etree.h' under directory 'src\lxml'
> warning: no files found matching 'lxml.etree_api.h' under directory
> 'src\lxml'
> warning: no files found matching 'etree_defs.h' under directory 'src\lxml'
> 
> 
> Reading http://codespeak.net/lxml
> Best match: lxml 2.3.3
> Downloading http://lxml.de/files/lxml-2.3.3.tgz
> Processing lxml-2.3.3.tgz
> Running lxml-2.3.3\setup.py -q bdist_egg --dist-dir
> c:\windows\temp\easy_install
> -58e4ap\lxml-2.3.3\egg-dist-tmp-hyg1bg
> Building lxml version 2.3.3.
> Building with Cython 0.15.1.
> ERROR: 'xslt-config' is not recognized as an internal or external command,
> operable program or batch file.
> 
> ** make sure the development packages of libxml2 and libxslt are
> installed **
> 
> Using build configuration of libxslt
> warning: no files found matching 'lxml.etree.c' under directory 'src\lxml'
> warning: no files found matching 'lxml.objectify.c' under directory
> 'src\lxml'
> warning: no files found matching 'lxml.etree.h' under directory 'src\lxml'
> warning: no files found matching 'lxml.etree_api.h' under directory
> 'src\lxml'
> warning: no files found matching 'etree_defs.h' under directory 'src\lxml'
> warning: no files found matching 'pubkey.asc' under directory 'doc'
> warning: no files found matching 'tagpython*.png' under directory 'doc'
> warning: no files found matching 'Makefile' under directory 'doc'
> 
> error: Setup script exited with error: None
> 
> how can i install the lxml  in my xp??
> 
> 

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


Re: how to install lxml in window xp?

2012-01-11 Thread Brian Curtin
On Wed, Jan 11, 2012 at 23:01, Tamer Higazi  wrote:
> Use Linux!
> Specially Gentoo Linux!

Not a useful answer.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pipe into preallocated buffer?

2012-01-11 Thread Kushal Kumaran
On Wed, Jan 4, 2012 at 8:05 PM, Mihai Badoiu  wrote:
> is there a way to pipe directly into a preallocated buffer?
>  (subprocessing.pipe.stdout)
>

Does io.StringIO fit your needs?

http://docs.python.org/py3k/library/io.html#io.StringIO

-- 
regards,
kushal
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ERROR:root:code for hash md5 was not found

2012-01-11 Thread mike
On Jan 12, 12:28 am, Steven D'Aprano  wrote:
> On Wed, 11 Jan 2012 05:54:29 -0800, mike wrote:
> > I did some more digging and found that our class imports a "yacc.py"
> > that uses
>
> > import re, types, sys, cStringIO, hashlib, os.path
>
> > so it has hashlib.
>
> > yacc.py seems to be an old version 1.3 ( I found 2.3 -->).
>
> > Reading about hashlib it seems to be dependent on os installation of
> > OpenSSL but I cannot find out how.
>
> It shouldn't be. It will use OpenSSL if available, otherwise it will fall
> back on its own code.
>
> > br,
>
> > //mike
>
> > yacc.py
> > ===
>
> #->
>  # ply: yacc.py
>
> [snip over TWO THOUSAND lines of code]
>
> Mike, what lead you to believe that an error in hashlib could be solved
> by posting the ENTIRE two thousand lines of yacc.py? Please do not post
> such huge chunks of code unless asked. It is unnecessary and annoying.
>
> Try this. Open a terminal window and enter "python" at the prompt to
> start a clean interactive session. Then enter the following commands:
>
> import sys
> print(sys.version)
> import hashlib
> print(hashlib.__file__)
> print(hashlib.md5)
> import _md5
> print(_md5.__file__)
>
> and copy and paste (do not retype) the full output of these commands.
>
> Thank you.
>
> --
> Steven

Hi,

Sorry for posting huge file. I added your copy-paste snippet.

esekilx5030 [7:09am] [roamFroBl/pysibelius/bin] -> python
Python 2.7.2 (default, Jun 16 2011, 15:05:49)
[GCC 4.5.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
print(sys.version)
import hashlib
print(hashlib.__file__)
print(hashlib.md5)
import _md5
print(_md5.__file__) >>> 2.7.2 (default, Jun 16 2011, 15:05:49)
[GCC 4.5.0]
>>> ERROR:root:code for hash md5 was not found.
Traceback (most recent call last):
  File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/
hashlib.py", line 139, in 
globals()[__func_name] = __get_hash(__func_name)
  File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/
hashlib.py", line 91, in __get_builtin_constructor
raise ValueError('unsupported hash type %s' % name)
ValueError: unsupported hash type md5
ERROR:root:code for hash sha1 was not found.
Traceback (most recent call last):
  File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/
hashlib.py", line 139, in 
globals()[__func_name] = __get_hash(__func_name)
  File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/
hashlib.py", line 91, in __get_builtin_constructor
raise ValueError('unsupported hash type %s' % name)
ValueError: unsupported hash type sha1
ERROR:root:code for hash sha224 was not found.
Traceback (most recent call last):
  File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/
hashlib.py", line 139, in 
globals()[__func_name] = __get_hash(__func_name)
  File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/
hashlib.py", line 91, in __get_builtin_constructor
raise ValueError('unsupported hash type %s' % name)
ValueError: unsupported hash type sha224
ERROR:root:code for hash sha256 was not found.
Traceback (most recent call last):
  File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/
hashlib.py", line 139, in 
globals()[__func_name] = __get_hash(__func_name)
  File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/
hashlib.py", line 91, in __get_builtin_constructor
raise ValueError('unsupported hash type %s' % name)
ValueError: unsupported hash type sha256
ERROR:root:code for hash sha384 was not found.
Traceback (most recent call last):
  File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/
hashlib.py", line 139, in 
globals()[__func_name] = __get_hash(__func_name)
  File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/
hashlib.py", line 91, in __get_builtin_constructor
raise ValueError('unsupported hash type %s' % name)
ValueError: unsupported hash type sha384
ERROR:root:code for hash sha512 was not found.
Traceback (most recent call last):
  File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/
hashlib.py", line 139, in 
globals()[__func_name] = __get_hash(__func_name)
  File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/
hashlib.py", line 91, in __get_builtin_constructor
raise ValueError('unsupported hash type %s' % name)
ValueError: unsupported hash type sha512
>>> /vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/hashlib.pyc
>>> Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'module' object has no attribute 'md5'
>>> Traceback (most recent call last):
  File "", line 1, in 
ImportError: No module named _md5

Thanks for support!

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


Re: pipe into preallocated buffer?

2012-01-11 Thread Thomas Rachel

Am 12.01.2012 06:23 schrieb Kushal Kumaran:

On Wed, Jan 4, 2012 at 8:05 PM, Mihai Badoiu  wrote:

is there a way to pipe directly into a preallocated buffer?
  (subprocessing.pipe.stdout)



Does io.StringIO fit your needs?

http://docs.python.org/py3k/library/io.html#io.StringIO


Probably not. A file object used in the subprocess context needs a 
fileno() method. StringIO objects don't have such.


Probably it is necessary to use subprocess.communicate() (for rather 
small data lengths) or to use sp.stdout.read() to read it manually.



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


Bug in logutils package

2012-01-11 Thread Ram

Does anyone have any inkling on how to fix this bug?

http://code.google.com/p/logutils/issues/detail?id=3

Or any good pointers on how to find out whats wrong and how to fix it
would be nice.

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


Re: ERROR:root:code for hash md5 was not found

2012-01-11 Thread mike
On Jan 12, 7:13 am, mike  wrote:
> On Jan 12, 12:28 am, Steven D'Aprano 
>
>
>
>
>
>
>
>
> +comp.lang.pyt...@pearwood.info> wrote:
> > On Wed, 11 Jan 2012 05:54:29 -0800, mike wrote:
> > > I did some more digging and found that our class imports a "yacc.py"
> > > that uses
>
> > > import re, types, sys, cStringIO, hashlib, os.path
>
> > > so it has hashlib.
>
> > > yacc.py seems to be an old version 1.3 ( I found 2.3 -->).
>
> > > Reading about hashlib it seems to be dependent on os installation of
> > > OpenSSL but I cannot find out how.
>
> > It shouldn't be. It will use OpenSSL if available, otherwise it will fall
> > back on its own code.
>
> > > br,
>
> > > //mike
>
> > > yacc.py
> > > ===
>
> > #->
> >  # ply: yacc.py
>
> > [snip over TWO THOUSAND lines of code]
>
> > Mike, what lead you to believe that an error in hashlib could be solved
> > by posting the ENTIRE two thousand lines of yacc.py? Please do not post
> > such huge chunks of code unless asked. It is unnecessary and annoying.
>
> > Try this. Open a terminal window and enter "python" at the prompt to
> > start a clean interactive session. Then enter the following commands:
>
> > import sys
> > print(sys.version)
> > import hashlib
> > print(hashlib.__file__)
> > print(hashlib.md5)
> > import _md5
> > print(_md5.__file__)
>
> > and copy and paste (do not retype) the full output of these commands.
>
> > Thank you.
>
> > --
> > Steven
>
> Hi,
>
> Sorry for posting huge file. I added your copy-paste snippet.
>
> esekilx5030 [7:09am] [roamFroBl/pysibelius/bin] -> python
> Python 2.7.2 (default, Jun 16 2011, 15:05:49)
> [GCC 4.5.0] on linux2
> Type "help", "copyright", "credits" or "license" for more information.>>> 
> import sys
>
> print(sys.version)
> import hashlib
> print(hashlib.__file__)
> print(hashlib.md5)
> import _md5
> print(_md5.__file__) >>> 2.7.2 (default, Jun 16 2011, 15:05:49)
> [GCC 4.5.0]>>> ERROR:root:code for hash md5 was not found.
>
> Traceback (most recent call last):
>   File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/
> hashlib.py", line 139, in 
>     globals()[__func_name] = __get_hash(__func_name)
>   File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/
> hashlib.py", line 91, in __get_builtin_constructor
>     raise ValueError('unsupported hash type %s' % name)
> ValueError: unsupported hash type md5
> ERROR:root:code for hash sha1 was not found.
> Traceback (most recent call last):
>   File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/
> hashlib.py", line 139, in 
>     globals()[__func_name] = __get_hash(__func_name)
>   File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/
> hashlib.py", line 91, in __get_builtin_constructor
>     raise ValueError('unsupported hash type %s' % name)
> ValueError: unsupported hash type sha1
> ERROR:root:code for hash sha224 was not found.
> Traceback (most recent call last):
>   File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/
> hashlib.py", line 139, in 
>     globals()[__func_name] = __get_hash(__func_name)
>   File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/
> hashlib.py", line 91, in __get_builtin_constructor
>     raise ValueError('unsupported hash type %s' % name)
> ValueError: unsupported hash type sha224
> ERROR:root:code for hash sha256 was not found.
> Traceback (most recent call last):
>   File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/
> hashlib.py", line 139, in 
>     globals()[__func_name] = __get_hash(__func_name)
>   File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/
> hashlib.py", line 91, in __get_builtin_constructor
>     raise ValueError('unsupported hash type %s' % name)
> ValueError: unsupported hash type sha256
> ERROR:root:code for hash sha384 was not found.
> Traceback (most recent call last):
>   File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/
> hashlib.py", line 139, in 
>     globals()[__func_name] = __get_hash(__func_name)
>   File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/
> hashlib.py", line 91, in __get_builtin_constructor
>     raise ValueError('unsupported hash type %s' % name)
> ValueError: unsupported hash type sha384
> ERROR:root:code for hash sha512 was not found.
> Traceback (most recent call last):
>   File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/
> hashlib.py", line 139, in 
>     globals()[__func_name] = __get_hash(__func_name)
>   File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/
> hashlib.py", line 91, in __get_builtin_constructor
>     raise ValueError('unsupported hash type %s' % name)
> ValueError: unsupported hash type sha512>>> 
> /vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/hashlib.pyc
> >>> Traceback (most recent call last):
>
>   File "", line 1, in 
> AttributeError: 'module' object has no attribute 'md5'>>> Traceback (most 
> recent call last):
>
>