Re: how to convert from Decimal('1.23456789') to Decimal('1.234')

2009-03-24 Thread Steven D'Aprano
On Mon, 23 Mar 2009 17:19:48 -0700, Mensanator wrote:

>> >> And it also gives different results to my function: my function
>> >> rounds to  decimal places, yours to  digits. Very
>> >> different things.
>>
>> > Yeah, I know all about that. I work in Environmental Remediation.
>> > That's real science, where rounding to decimal places is strictly
>> > forbidden, significant digits must be preserved. That means rounding
>> > to digits.
>>
>> Okay, so in other words you solved your problem rather than the OP's
>> problem.
> 
> People other than the OP read these threads. Do you want to give people
> the impression that quantize is the only option?

The only option for what? Solving the OP's problem, or your problem, or 
some other problem? How many different problems are we going to solve in 
this thread?

At the very least, when taking a detour to solve a different problem, say 
so, and point out why your problem is a more interesting/useful problem 
to solve.


>> > Do
>> > you know what kind of hoops I have to jump through to get Access or
>> > Excel to round properly when doing unit conversion?
>>
>> I feel your pain.
> 
> So surely you don't want to give the impression that all Decimal is good
> for is emulating Excel?

That's a non sequitor. It does not follow that just because I sympathize 
with your difficulties with Excel, that I therefore want to give the 
impression that Decimal is only good for emulating Excel.


>> > Surely you're not so maive that you think dividing by 1000 simply
>> > moves the decimal point three places?
>>
>> Of course it does, if you're using real numbers.
> 
> Computers have real numbers?

You don't have to use computers to divide by 1000. As difficult as it is 
to believe, throughout history people have done mathematical calculations 
without the use of computing devices.


>> If you're using floats,
>> no, not quite, there are rounding issues involved, and underflow.
> 
> And that's why we have Decimal, right?

I'm sure that the Decimal standard wasn't invented just so people can 
divide by 1000.



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


Re: file.read() doesn't read the whole file

2009-03-24 Thread Sreejith K
On Mar 24, 7:15 am, "Gabriel Genellina" 
wrote:
> En Mon, 23 Mar 2009 21:37:14 -0300, R. David Murray  
>  escribió:
>
>
>
> > Steve Holden  wrote:
> >> Sreejith K wrote:
> >> >> Try and write an example that shows the problem in fifteen lines or
> >> >> less. Much easier for us to focus on the issue that way.
>
> >> > import os
> >> > def read(length, offset):
> >> >   os.chdir('/mnt/gfs_local/')
> >> >   snap = open('mango.txt_snaps/snap1/0','r')
> >> >   snap.seek(offset)
> >> >   data = snap.read(length)
> >> >   print data
>
> >> > read(4096,0)
>
> >> > This code shows what actually happens inside the code I've written.
> >> > This prints the 4096 bytes from the file '0' which is only 654 bytes.
> >> > When we run the code we get the whole file. That's right. I also get
> >> > it. But when this read() function becomes the file class read()
> >> > function in fuse, the data printed is not the whole but only a few
> >> > lines from the beginning.
>
> >> This is confusing. I presume you to mean that when you make this
> >> function a method of some class it stops operating correctly?
>
> >> But I am not sure.
>
> >> I am still struggling to understand your problem. Sorry,it's just a
> >> language thing. If we take our time we will understand each other in the
> >> end.
>
> > You may be asking this question for pedagogical reasons, Steve, but
> > in case not...the OP is apparently doing a 'less ' where  is
> > the name of a file in a fuse filesystem (that is, a mounted filesystem
> > whose back end is some application code written by the OP).
> [...]
> > There are several steps between that 'snap.read' and less displaying on
> > the terminal whatever bytes it got back from its read call in whatever
> > way it is less chooses to display them
>
> And that's why everyone is asking for a *real* log. Assumptions like "foo  
> must be 0 here" aren't enough. One needs *evidence*: a log file showing  
> the value of "foo" right when it is used. Then, one can begin to infer  
> what happens -- first step would be to determine *which* layer is (or is  
> not) responsible for the misbehavior.
>
> In this case, I'd like to see file.tell(), the requested size and the  
> returned data length, *right*at*the*read()*call*.
>
> --
> Gabriel Genellina

R. David Murray understood the problem very well. As you've said I
logged the data returned and see that it actually the complete file.
But the problem is when 'less'ing only two lines are displayed. So its
not regarding the read() of python. Usually in fuse filesystems (as in
some examples), when some file read occurs fuse catch it and calls the
python-fuse's read(length, offset) function. For small files (when we
read using 'less'), this will be usually the first block i.e 4096 with
offset 0. We return what we read from the read() method of fuse-
python. But when I return the data I read, a 'less' operation in my
fuse filesystem shows some lines only, even if the returned data is
the whole file.

In my implementation of fuse-filesystem when a read is called, instead
of returning the data read from the original file, I return the data
read from another file ('0') which resides in __snaps/
snap1 directory (I use this directory to store the blocks of original
files when write occurs. So each file here would be 4096 bytes). I'm
doing this because I want to make snapshots of files so that I can
restore the older file easily. The problem occurs when reading this
file and returning the read data.

Some flush/release functions are there in fuse to properly close the
opened file. When reading (less) the original file without snapshots,
there is no issue. But when reading the snapshot instead, the problem
occurs. I open the snapshot file with the same modes as the original
file. Is there anything I should do after read() like the flush() as
for the original file ? I tried it, but no success...

Log when reading from snapshot
===
Read length: 4096 offset: 0
Snapshot 0 opened..
Snap read
===Data Begin===
Getting started -- pdb.set_trace()

To start, I'll show you the very simplest way to use the Python
debugger.

   1. Let's start with a simple program, epdb1.py.

  # epdb1.py -- experiment with the Python debugger, pdb
  a = "aaa"
  b = "bbb"
  c = "ccc"
  final = a + b + c
  print final


   2. Insert the following statement at the beginning of your Python
program. This statement imports the Python debugger module, pdb.

  import pdb

   3. Now find a spot where you would like tracing to begin, and
insert the following code:

  pdb.set_trace()
===Data End
snap.tell(): 654
data size : 654
Original file flushed
Original file closed

data is the whole file, but 'less' gives only the two lines...
--
http://mail.python.org/mailman/listinfo/python-list


Re: Does Python have certificate?

2009-03-24 Thread Hendrik van Rooyen
"Kay Schluehr"  wrote:

> On 24 Mrz., 05:30, Steve Holden  wrote:

> > O'Reilly School of Technology have plans to offer a Python
> > certification. But I have to write the courses first :)
> 
> If you're done with it I'd additionally suggest the honory title of a
> VIPP: Very Important Python Programmer. VIPPs receive a sticker with a
> Python logo and are immediately spotted this way by their numerous
> fans.

I like the idea, but I would suggest that the award be
limited to the first 100 participants and that the title be:

Very Important Python Early Responder

- Hendrik

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


Re: Relative Imports, why the hell is it so hard?

2009-03-24 Thread CinnamonDonkey
Thanx Max - your explanation sorted it :-), and a big thank you to
everyone else also!

>From the various posts, Python considers any directory containing the
__init__.py file to be a package. The top level package is the highest
directory (closest to root) with a __init__.py file.

Inter-package communication is not allowed unless the packages
themselves are contained by a parent package.

How does this relate to the site-packages folder? Is it a top level
package for all installed packages?

Let's say I have installed the "Trac" system which uses "Genshi", they
are both packages. They are also both installed at the same level and
I know "Trac" uses "Genshi" to work. \Python25\Lib\site-packages does
not contain a __init__.py file so it is not a package (i.e. not a
parent package to "Trac" and "Genshi") :0.


-=- bearophile -=-

Hi Bearophile,

Thanx for taking the time to post a response but I am afraid I feel
the need to point out that it is exactly this kind of response that I
find un-helpful. It is neither constructive nor educational.

It's a bit like saying "If you don't know what a function is, then
maybe you don't need it. ... have you tried having a single block of
code?"

The point of people coming to these forums is to LEARN and share
knowledge. Perhaps it's not the best solution for me right now but
without trying it I won't know when or how to apply it as a solution.

By the way, my project has about 50 files (modules) in it with a lot
of shared code that could be used across other projects... seems as
good a reason as any to try packages out ;-)

Thanx anyway :)


On 23 Mar, 18:57, bearophileh...@lycos.com wrote:
> CinnamonDonkey:
>
> >what makes something a package?
>
> If you don't know what a package is, then maybe you don't need
> packages.
>
> In your project is it possible to avoid using packages and just use
> modules in the same directory?
>
> Bye,
> bearophile

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


Re: file.read() doesn't read the whole file

2009-03-24 Thread Ant
On Mar 24, 7:59 am, Sreejith K  wrote:
...
> data is the whole file, but 'less' gives only the two lines...

>From this statement (that you are using less), it appears that you are
redirecting sys.stdout to a file or similar - if that is the case, you
may need to flush or close the output file before it picks up any
changes.
--
http://mail.python.org/mailman/listinfo/python-list


Re: udp package header

2009-03-24 Thread Nick Craig-Wood
mete  wrote:
>  I got a problem. İ want to send udp package and get this package (server and 
>  clinet ). it's easy to python but i want to look the udp header how can i 
>  do ?

There is pretty much nothing in a UDP packet header except
from_address, to_address, from_port and to_port.  You should already
know to_address and to_port and socket.recv will give you the
from_address and from_port

socket.recvfrom(bufsize[, flags])

Receive data from the socket. The return value is a pair (string,
address) where string is a string representing the data received
and address is the address of the socket sending the data.

-- 
Nick Craig-Wood  -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list


Re: file.read() doesn't read the whole file

2009-03-24 Thread Sreejith K
On Mar 24, 2:12 pm, Ant  wrote:
> On Mar 24, 7:59 am, Sreejith K  wrote:
> ...
>
> > data is the whole file, but 'less' gives only the two lines...
>
> From this statement (that you are using less), it appears that you are
> redirecting sys.stdout to a file or similar - if that is the case, you
> may need to flush or close the output file before it picks up any
> changes.

Yes, I did try a flush() and close on the file which is read, but the
result is the same. I think when a read comes in fuse redirecting the
actual path (original file) to some other file for reading causes some
issues like this. It would be really helpful if someone help me clear
this issue. The getattr() calls are actually called upon the original
file (doing an os.lstat()). Does this make any effect on the 'less'
output ?
--
http://mail.python.org/mailman/listinfo/python-list


importing modules from alternate path

2009-03-24 Thread Alexandru Moșoi
I'm trying with no succes to load modules from an alternate path. When
installing to default location (no --home specifed) everything works
as expected.

$ python setup.py install --home=~
running install
running build
running build_ext
running install_lib
running install_egg_info
Removing /home/voodoo/lib/python/PackageName-1.0-py2.6.egg-info
Writing /home/voodoo/lib/python/PackageName-1.0-py2.6.egg-info

$ printf "import demo" | PYTHONPATH=~ python
Traceback (most recent call last):
  File "", line 1, in 
ImportError: No module named demo

$ printf "import demo" | PYTHONHOME=~ python
Traceback (most recent call last):
  File "", line 1, in 
ImportError: No module named demo


Any idea why alternate path is not working?


- BEGIN OF setup.py
from distutils.core import setup, Extension

module1 = Extension('demo',
sources = ['demo.c'])

setup (name = 'PackageName',
   version = '1.0',
   description = 'This is a demo package',
   ext_modules = [module1])
- END OF end setup.py

- BEGIN OF demo.c
#include 

static PyObject* demo_bla(PyObject *self) {
return Py_BuildValue("i", 666);
}
- END OF demo.c
--
http://mail.python.org/mailman/listinfo/python-list


Re: Does Python have certificate?

2009-03-24 Thread Paddy3118
On Mar 24, 1:50 am, Johannes Bauer  wrote:
> Sebastian Bassi schrieb:
>
> > No, there is no certification for Python. Maybe in the future...
>
> I'll hand out the "Johannes Bauer Python Certificate of Total
> Awesomeness" for anyone who can write a hello world in python and hands
> me $25000 in cash.
>
> This whole "certified foobar programmer" is complete crap IMHO.
>
> The above offer stands nontheless.
>
> Kind regards,
> Johannes
>
> --
> "Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit,
> verlästerung von Gott, Bibel und mir und bewusster Blasphemie."
>          -- Prophet und Visionär Hans Joss aka HJP in de.sci.physik
>                          <48d8bf1d$0$7510$54022...@news.sunrise.ch>

The Academy of Research into Science Education being a true leader in
the field offers acclaimed accreditation for Python programmers. Those
who pass our strict exams and pay our modest fees will earn our
prestigious certification.

Those who show promise can advance to our Winter Improve Python to
Expert program, for an additional fee, and, be given expert tutoring
to help you gain our exemplary A.R.S.E./W.I.P.E certification which is
guaranteed to attract certain types of employers by its name alone.

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


user site-packages, --prefix, --home and friends

2009-03-24 Thread Carl
I am very confused by PEP-370 per-user site-packages. It is not
mentioned at all in the document about installing Python modules :
http://docs.python.org/3.0/install/index.html.

It seems that --home or --prefix already provide per-user site-
packages capability. Can someone explain what are the differences and
what is the best practice in various situations?

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


Re: Does Python have certificate?

2009-03-24 Thread Johannes Bauer
Sebastian Bassi schrieb:

> No, there is no certification for Python. Maybe in the future...

I'll hand out the "Johannes Bauer Python Certificate of Total
Awesomeness" for anyone who can write a hello world in python and hands
me $25000 in cash.

This whole "certified foobar programmer" is complete crap IMHO.

The above offer stands nontheless.

Kind regards,
Johannes

-- 
"Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit,
verlästerung von Gott, Bibel und mir und bewusster Blasphemie."
 -- Prophet und Visionär Hans Joss aka HJP in de.sci.physik
 <48d8bf1d$0$7510$54022...@news.sunrise.ch>
--
http://mail.python.org/mailman/listinfo/python-list


What's the difference between generating a value and returning a value?

2009-03-24 Thread grocery_stocker
Taken from the url

http://openbookproject.net/thinkCSpy/ch05.xhtml#index15

"The built-in functions we have used, such as abs,
pow, and max, have produced results.  Calling each of
these functions generates a value, which we usually assign to a
variable or
use as part of an expression.


biggest = max(3, 7, 2, 5)
x = abs(3 - 11) + 10

But so far, none of the functions we have written has returned a
value.

In this chapter, we are going to write functions that return values,
which
we will call fruitful functions,"

So what's the difference between generating a value and returning a
value?



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


how to get the summarized text from a given URL?

2009-03-24 Thread Rama Vadakattu
Is there any python library to solve the below problem?

FOr the below URL :
--
http://tinyurl.com/dzcwbg

Summarized text is :
---
By Roy Mark With sales plummeting and its smart phones failing to woo
new customers, Sony Ericsson follows its warning that first quarter
sales will be disappointing with the announcement that Najmi Jarwala,
president of Sony Ericsson USA and head of ...

~~
Usually summarized text is a  2 to 3 line description of the URL which
we usually obtain by fetching that html page , examining the  content
and  figuring out short description from that html markup.
~

Are there any python libraries which give summarized text for a given
url ?

It is ok even if the library  just gives  intial two lines of text
from the given URL Instead of summarization.
--
http://mail.python.org/mailman/listinfo/python-list


Re: What's the difference between generating a value and returning a value?

2009-03-24 Thread Daniel Dalton
On Mon, Mar 23, 2009 at 03:12:19PM -0700, grocery_stocker wrote:
> So what's the difference between generating a value and returning a
> value?

Well when you return, you would use the "return" keyword, I would
imagine... I guess generating could mean many things, you can generate a
value by operating on something, but I guess this does imply returning a
value, because the function returning the value is generating a new
value... But, I know for sure that when you return a value it is the
information the function returns to the caller after operating on either
no, or some arguments.

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


importing modules from alternate path

2009-03-24 Thread R. David Murray
=?UTF-8?Q?Alexandru__Mo=C8=99oi?=  wrote:
> I'm trying with no succes to load modules from an alternate path. When
> installing to default location (no --home specifed) everything works
> as expected.
> 
> $ python setup.py install --home=~
> running install
> running build
> running build_ext
> running install_lib
> running install_egg_info
> Removing /home/voodoo/lib/python/PackageName-1.0-py2.6.egg-info
> Writing /home/voodoo/lib/python/PackageName-1.0-py2.6.egg-info
> 
> $ printf "import demo" | PYTHONPATH=~ python
> Traceback (most recent call last):
>   File "", line 1, in 
> ImportError: No module named demo
> 
> $ printf "import demo" | PYTHONHOME=~ python
> Traceback (most recent call last):
>   File "", line 1, in 
> ImportError: No module named demo
> 
> 
> Any idea why alternate path is not working?

Possibly because the package gets installed into ~/lib/python, but
you haven't put that directory onto the PYTHONPATH.

--
R. David Murray   http://www.bitdance.com

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


Re: file.read() doesn't read the whole file

2009-03-24 Thread R. David Murray
Sreejith K  wrote:
> On Mar 24, 2:12 pm, Ant  wrote:
> > On Mar 24, 7:59 am, Sreejith K  wrote:
> > ...
> >
> > > data is the whole file, but 'less' gives only the two lines...
> >
> > From this statement (that you are using less), it appears that you are
> > redirecting sys.stdout to a file or similar - if that is the case, you
> > may need to flush or close the output file before it picks up any
> > changes.

It's not a redirect to a file.  Fuse calls the 'read' function on the
class, the read function does a 'return' of the data, and fuse passes
the data up through the OS layer to be the result of the 'read' call
made by less.

If you don't know what a fuse file system is, this all gets very confusing :)

> Yes, I did try a flush() and close on the file which is read, but the
> result is the same. I think when a read comes in fuse redirecting the
> actual path (original file) to some other file for reading causes some
> issues like this. It would be really helpful if someone help me clear
> this issue. The getattr() calls are actually called upon the original
> file (doing an os.lstat()). Does this make any effect on the 'less'
> output ?

I'm afraid we are getting beyond my level of fuse-foo here.  You'd
probably be better off finding a fuse or even fuse-python mailing list
and trying there.

If it were me, I'd start logging everything I could (take a look at
Python's 'logging' module to help you make that easy), and twidling
things.  What happens if you change what gets returned to lstat?
What happens for various sizes and contents of the '0' file?  What
happens if you use 'cat -v' or hexdump instead of less to read the file?
Run experiments until you gather enough clues to make a guess as to what
is going on, then test your theory.  Repeat until success :)

--
R. David Murray   http://www.bitdance.com

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


Re: What's the difference between generating a value and returning a value?

2009-03-24 Thread Dave Angel
Clearly, there's no difference, from the wording you quoted.  He uses 
three words more or less interchangeably, "produced", "generated" and 
"returned."


The distinction he's making is not between these words, but between the 
built-in functions, which are already returning values, and the ones 
that he has had the user write so far, that do not.


DaveA

grocery_stocker wrote:

Taken from the url

http://openbookproject.net/thinkCSpy/ch05.xhtml#index15

"The built-in functions we have used, such as abs,
pow, and max, have produced results.  Calling each of
these functions generates a value, which we usually assign to a
variable or
use as part of an expression.


biggest = max(3, 7, 2, 5)
x = abs(3 - 11) + 10

But so far, none of the functions we have written has returned a
value.

In this chapter, we are going to write functions that return values,
which
we will call fruitful functions,"

So what's the difference between generating a value and returning a
value?




  

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


Re: how to get the summarized text from a given URL?

2009-03-24 Thread Peter Otten
Rama Vadakattu wrote:

> Is there any python library to solve the below problem?
> 
> FOr the below URL :
> --
> http://tinyurl.com/dzcwbg
> 
> Summarized text is :
> ---
> By Roy Mark With sales plummeting and its smart phones failing to woo
> new customers, Sony Ericsson follows its warning that first quarter
> sales will be disappointing with the announcement that Najmi Jarwala,
> president of Sony Ericsson USA and head of ...
> 
> ~~
> Usually summarized text is a  2 to 3 line description of the URL which
> we usually obtain by fetching that html page , examining the  content
> and  figuring out short description from that html markup.
> ~
> 
> Are there any python libraries which give summarized text for a given
> url ?

BeautifulSoup makes it easy to access parts of a web page. 

import urllib2
from BeautifulSoup import BeautifulSoup

data = urllib2.urlopen("http://tinyurl.com/dzcwbg";).read()
bs = BeautifulSoup(data)
print bs.find("meta", dict(name="description"))["content"]

> It is ok even if the library  just gives  intial two lines of text
> from the given URL Instead of summarization.

The problem is how you identify the summary. Different web sites will put it
in different places using different markup.

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


Re: Relative Imports, why the hell is it so hard?

2009-03-24 Thread Maxim Khitrov
On Tue, Mar 24, 2009 at 5:05 AM, CinnamonDonkey
 wrote:
> Thanx Max - your explanation sorted it :-), and a big thank you to
> everyone else also!
>
> >From the various posts, Python considers any directory containing the
> __init__.py file to be a package. The top level package is the highest
> directory (closest to root) with a __init__.py file.
>
> Inter-package communication is not allowed unless the packages
> themselves are contained by a parent package.
>
> How does this relate to the site-packages folder? Is it a top level
> package for all installed packages?
>
> Let's say I have installed the "Trac" system which uses "Genshi", they
> are both packages. They are also both installed at the same level and
> I know "Trac" uses "Genshi" to work. \Python25\Lib\site-packages does
> not contain a __init__.py file so it is not a package (i.e. not a
> parent package to "Trac" and "Genshi") :0.

Trac does not use relative imports to access genshi. When relative
imports are not used, python goes through sys.path list to find
modules (with a small exception made when absolute_imports are not
enabled, but that should be default in 2.7). The site-packages
directory is added to sys.path, so when trac executes something like
"from genshi import some_module", python will look in site-packages,
among other directories, for a directory called "genshi" that contains
an __init__.py file.

When you execute a script, the directory of that script is
automatically added to sys.path, so with your example you could have
used absolute imports between subpack1 and subpack2, with the \App
directory performing the same function as site-packages (Gabriel's
suggestion). This is for your original version of the code when
main.py was under App.

Once you moved main.py outside of \App, running "import sybpack2"
would no longer work. You can, however, append directories to
sys.path, so by doing the following in main.py you could again allow
non-relative imports between subpack1 and subpack2:

import os
import sys

sys.path.append(os.path.realpath('App'))

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


Re: Relative Imports, why the hell is it so hard?

2009-03-24 Thread R. David Murray
Top posting corrected for clarity.

CinnamonDonkey  wrote:
> On 23 Mar, 18:57, bearophileh...@lycos.com wrote:
> > CinnamonDonkey:
> >
> > >what makes something a package?
> >
> > If you don't know what a package is, then maybe you don't need
> > packages.
> >
> > In your project is it possible to avoid using packages and just use
> > modules in the same directory?
> >
> > Bye,
> > bearophile
>
> Hi Bearophile,
> 
> Thanx for taking the time to post a response but I am afraid I feel
> the need to point out that it is exactly this kind of response that I
> find un-helpful. It is neither constructive nor educational.
> 
> It's a bit like saying "If you don't know what a function is, then
> maybe you don't need it. ... have you tried having a single block of
> code?"
> 
> The point of people coming to these forums is to LEARN and share
> knowledge. Perhaps it's not the best solution for me right now but
> without trying it I won't know when or how to apply it as a solution.
> 
> By the way, my project has about 50 files (modules) in it with a lot
> of shared code that could be used across other projects... seems as
> good a reason as any to try packages out ;-)
> 
> Thanx anyway :)

I think bearophile could have left out the first sentence, but otherwise
his question is perfectly sensible.  If you have a bunch of independent
modules, then you don't need to put them in packages.  Your example
only showed one module file in each package...I understand now that was
just for simplicity of the example, but we had no way of knowing that.
We've had newbies come in and think they _need_ to put a module file into
a subpackage even when they'd only have one module file per subdirectory
and they don't really know what a package is...thus bearophile's (perhaps
poorly phrased) question.

Now that you know what packages are and what the restrictions on relative
imports are, and you've told us that you have '50 modules' with a lot
of shared code that 'could be used across other projects', perhaps you
see why relative imports are generally discouraged.  If you use only
relative imports, the code _can't_ be shared across multiple projects,
because all that project code would have to be in one monster package,
and not be separate projects at all.

So now you'll know better where it makes Pythonic (as opposed to C++)
sense to use it and where not.

--
R. David Murray   http://www.bitdance.com

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


install pyPgSQL on Windows for python 2.5

2009-03-24 Thread someone
Hi,

does anyone know how to install pyPgSQL on Windows? There is no
package for Python 2.5 on Homepage:

http://sourceforge.net/project/showfiles.php?group_id=16528&package_id=20458&release_id=423036

I've tried to install running: python setup.py install
But getting errors python setup.py install ->

running install
running build
running build_py
running build_ext
error: Python was built with Visual Studio 2003;
extensions must be built with a compiler than can generate compatible
binaries.
Visual Studio 2003 was not found on this system. If you have Cygwin
installed,
you can try compiling with MingW32, by passing "-c mingw32" to
setup.py.


I've installed newest Visual C++ Studio 2008 from Microsoft, but still
no luck

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


Unit testing frameworks

2009-03-24 Thread grkuntzmd
I am looking for a unit testing framework for Python. I am aware of
nose, but was wondering if there are any others that will
automatically find and run all tests under a directory hierarchy.

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


Re: file.read() doesn't read the whole file

2009-03-24 Thread Sreejith K
On Mar 24, 4:45 pm, "R. David Murray"  wrote:
> Sreejith K  wrote:
> > On Mar 24, 2:12 pm, Ant  wrote:
> > > On Mar 24, 7:59 am, Sreejith K  wrote:
> > > ...
>
> > > > data is the whole file, but 'less' gives only the two lines...
>
> > > From this statement (that you are using less), it appears that you are
> > > redirecting sys.stdout to a file or similar - if that is the case, you
> > > may need to flush or close the output file before it picks up any
> > > changes.
>
> It's not a redirect to a file.  Fuse calls the 'read' function on the
> class, the read function does a 'return' of the data, and fuse passes
> the data up through the OS layer to be the result of the 'read' call
> made by less.
>
> If you don't know what a fuse file system is, this all gets very confusing :)
>
> > Yes, I did try a flush() and close on the file which is read, but the
> > result is the same. I think when a read comes in fuse redirecting the
> > actual path (original file) to some other file for reading causes some
> > issues like this. It would be really helpful if someone help me clear
> > this issue. The getattr() calls are actually called upon the original
> > file (doing an os.lstat()). Does this make any effect on the 'less'
> > output ?
>
> I'm afraid we are getting beyond my level of fuse-foo here.  You'd
> probably be better off finding a fuse or even fuse-python mailing list
> and trying there.
>
> If it were me, I'd start logging everything I could (take a look at
> Python's 'logging' module to help you make that easy), and twidling
> things.  What happens if you change what gets returned to lstat?
> What happens for various sizes and contents of the '0' file?  What
> happens if you use 'cat -v' or hexdump instead of less to read the file?
> Run experiments until you gather enough clues to make a guess as to what
> is going on, then test your theory.  Repeat until success :)
>
> --
> R. David Murray          http://www.bitdance.com

Thanks Murray, for your valuable opinions and suggestions. I'll try to
log everything from now on and find out what happens inside. :)
Surely I'll let you guys know what happened..
--
http://mail.python.org/mailman/listinfo/python-list


user site-packages, --prefix, --home and friends

2009-03-24 Thread R. David Murray
Carl  wrote:
> I am very confused by PEP-370 per-user site-packages. It is not
> mentioned at all in the document about installing Python modules :
> http://docs.python.org/3.0/install/index.html.
> 
> It seems that --home or --prefix already provide per-user site-
> packages capability. Can someone explain what are the differences and
> what is the best practice in various situations?

I'm by no means an authority, but by my reading of the PEP there are
two major items that differentiate --user from --prefix and --home:
automatic per-python-version installation, and handling of .pth files.

As for best practice, I would say whichever one meets your needs.
The PEP is addressing the needs of users who do not have root privs but
who want to install packages via distutils in such a way that they will
act as if they had been installed in the system site-packages directory.

--
R. David Murray   http://www.bitdance.com

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


Re: file.read() doesn't read the whole file

2009-03-24 Thread Sreejith K
> It's not a redirect to a file.  Fuse calls the 'read' function on the
> class, the read function does a 'return' of the data, and fuse passes
> the data up through the OS layer to be the result of the 'read' call
> made by less.

By redirection I meant reading the snapshot file instead of the
original file :). Sorry for making confusions
--
http://mail.python.org/mailman/listinfo/python-list


Re: Does Python have certificate?

2009-03-24 Thread ajaksu
"Hendrik van Rooyen" wrote:
> I like the idea, but I would suggest that the award be
> limited to the first 100 participants and that the title be:
>
> Very Important Python Early Responder

I'd pay good money for that if the 'I' could be customized to stand
for Ignorant :)

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


Bash-like brace expansion

2009-03-24 Thread Peter Waller
Okay, I got fed up with there not being any (obvious) good examples of
how to do bash-like brace expansion in Python, so I wrote it myself.
Here it is for all to enjoy!

If anyone has any better solutions or any other examples of how to do
this, I'd be glad to hear from them.

#~ BraceExpand.py - Bash-like brace expansion in Python
#~ Copyright (C) 2009 

#~ This program is free software: you can redistribute it and/or
modify
#~ it under the terms of the GNU Affero General Public License as
#~ published by the Free Software Foundation, either version 3 of the
#~ License, or (at your option) any later version.

#~ This program is distributed in the hope that it will be useful,
#~ but WITHOUT ANY WARRANTY; without even the implied warranty of
#~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#~ GNU Affero General Public License for more details.

#~ You should have received a copy of the GNU Affero General Public
License
#~ along with this program.  If not, see .

import re
from itertools import imap

class NoBraces(Exception): pass

def BraceExpand(text, ordering = []):
"""Recursively brace expand text in a bash-like fashion.

See 'man 2 bash' under the heading 'Brace Expansion'

Example: "/data/file{1..10}.root" expands to file1.root ...
file9.root

Ordering allows changing the order of iteration. The rules for
this are
a little complicated. Ordering is a list of boolean values.
If it is possible to expand the postamble, the first value from
the list
is removed, and used to determine whether the postamble should be
iterated
over before iterating over the amble. The list is then passed
down
recursively to the next Brace.

What does this code do?

It is simpler than it looks.

There are three main steps:
  1) Split the string into three parts, consisting of pre-amble,
amble and
 post-amble. (This requires keeping track of nested {}'s.)
  2) In the amble, figure out which commas are not stuck in {}'s,
and
 split the string by those commas.
  3) For each part of this split string, Add together the pre-
amble, the
 string and the post-amble. Call BraceExpand() on this string
to deal
 with nested braces and any expansion required in the
postamble

Other things this code does which make it look more complicated:
  * Expand ranges along the lines of {1..10}
  * Allow for re-arranging the order of iteration

Todo/Not Implemented:
  * Escaping/quoting

Example C implementation from bash (inspiration for this):
http://www.oldlinux.org/Linux.old/bin/old/bash-1.11/braces.c
"""

def FindMatchedBraces(text, position = -1):
"Search for nested start and end brace in text starting from
position"
braceDepth = 0
nextClose = -1
first = True

# Search for a {
# is it closer than the nearest } ?
#   Yes : increase brace depth
#   No  : decrease brace depth
# When we reach braceDepth == 0, we have found our close brace
while braceDepth or first:

nextOpen = text.find("{", position+1)
nextClose = text.find("}", position+1)

if first and nextOpen >= 0:
startBrace = nextOpen
first = False

if nextOpen < nextClose and nextOpen >= 0:
braceDepth += 1
position = nextOpen
elif nextClose >= 0:
braceDepth -= 1
position = nextClose
else:
raise NoBraces()

return startBrace, position

try: start, end = FindMatchedBraces(text)
except NoBraces:
# There are no braces! Nothing to expand!
return [text]

# Split the text into three bits, '{pre,,post}amble'. The 'pre' is
anything
# before expansion, the '' is the bit that needs expanding and
gluing to
# the pre and the post. After gluing together, we can recursively
expand
# again
preamble = text[:start]
amble = text[start+1:end]
postamble = text[end+1:]

def BareCommaSearcher(amble):
"Search for commas which are not encapsulated in {}"

haveBraces = True
try: start, end = FindMatchedBraces(amble)
except NoBraces: haveBraces = False

position = -1
while True:
position = amble.find(",", position+1)

if position < 0:
# We didn't find any comma after 'position', finish
searching.
break

if haveBraces and start < position < end:
# We're inside some braces, skip to the end of them,
find the
# next set.
position = end

haveBraces = True
try: start, end = FindMatchedBraces(amble, position)
except NoBraces: haveBraces = False

continue

yield position

# Reached the end 

Re: Bash-like brace expansion

2009-03-24 Thread Peter Waller
Okay, yuck. I didn't realise that posting would mangle the code so
badly. Is there any better way to attach code? I'm using google
groups.

On Mar 24, 12:28 pm, Peter Waller  wrote:
> Okay, I got fed up with there not being any (obvious) good examples of
> how to do bash-like brace expansion in Python, so I wrote it myself.
> Here it is for all to enjoy!
>
> If anyone has any better solutions or any other examples of how to do
> this, I'd be glad to hear from them.
>
> 
--
http://mail.python.org/mailman/listinfo/python-list


iPython 0.9.1 install under XP -- R6034

2009-03-24 Thread Esmail

Hello all,

I am having problems trying installing iPython under XP.
It works great under Linux and it would be great if I could
also use it when I have to be in Windows.

XP Professional SP2 + SP3 (tried different systems),
iPython-0.9.1, Python 2.6.1

During  "Please wait while running postinstall script .. "
I get the following MS Visual C++ Runtime Error

R6034
An application has made an attempt to load th C runtime library incorrectly.
.

I get this message 4 or 5 times and eventually end up
with this:

*** run_installscript: internal error 0x ***

I've seen this error reported before while searching the web,
so I know I'm not the only one who has run into this problem,
but not seen any solutions.

Can anyone help?

Thanks,
Esmail


PS: I see a ipython users group, but I have been unable to post to
it despite trying for the last few days. Perhaps someone here
who uses iPython under XP can help.

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


Re: Relative Imports, why the hell is it so hard?

2009-03-24 Thread bearophileHUGS
CinnamonDonkey:
> It is neither constructive nor educational.
>
> It's a bit like saying "If you don't know what a function is, then
> maybe you don't need it. ... have you tried having a single block of
> code?"
>
> The point of people coming to these forums is to LEARN and share
> knowledge. Perhaps it's not the best solution for me right now but
> without trying it I won't know when or how to apply it as a solution.
>
> By the way, my project has about 50 files (modules) in it with a lot
> of shared code that could be used across other projects... seems as
> good a reason as any to try packages out ;-)

I don't agree. My answer can be wrong for your situation, but I can't
know much about you from the start, and for most people my answer was
the right one.

When a student asks me how to improve his/her usage of metaclasses I
usually answer that metaclasses aren't required to solve that small
problem.

Generally in engineering the simplest solution is the one you have to
try first (and often second and third), and only later, if practical
experience shows the simple solution doesn't work, you try a more
complex solution.

So I have suggested you a simple solution by "default". If later you
see that you have many modules and you really need packages, then it's
easy to ignore my first answer.

Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list


Re: Bash-like brace expansion

2009-03-24 Thread bearophileHUGS
Peter Waller:
> Is there any better way to attach code?

This is a widely used place (but read the "contract"/disclaimer
first):
http://code.activestate.com/recipes/langs/python/

Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list


Re: Bash-like brace expansion

2009-03-24 Thread Peter Waller
2009/3/24 Tino Wildenhain 
>
>
> The simple {foo} expansion you mention should be quite easily handled
> with re.sub and a function as argument. So not much more then a few
> lines of code.


Could this approach be made to handle recursive expansion? From the example
with the script:

pprint(BraceExpand("electron_{n,{pt,eta,phi}[{1,2}]}", ordering = [True]))

Gives:

['electron_n',
 'electron_pt[1]',
 'electron_eta[1]',
 'electron_phi[1]',
 'electron_pt[2]',
 'electron_eta[2]',
 'electron_phi[2]']

Cheers,

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


Re: Bash-like brace expansion

2009-03-24 Thread Peter Waller
What one really wants is a re option capable of handling recursive
structures, something along the lines of what PHP has:

http://uk2.php.net/manual/en/regexp.reference.php

Under the 'Recursive Patterns' heading. As far as I am aware, no such thing
exists for Python (yet?).

2009/3/24 Peter Waller 
>
>
> Could this approach be made to handle recursive expansion? From the example
> with the script:
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: Query regarding Python sybase module

2009-03-24 Thread skip
Srini> Does Sybase Python driver module implement multiple result sets
Srini> from a single command?

I've used it to get multiple result sets from stored procedures, so I guess
the answer would be "yes".  Something like this:

>>> params = curs.callproc('stored_procedure', params)
>>> while True:
...   rows = curs.fetchall()
...   print rows
...   if not curs.nextset():
... break

-- 
Skip Montanaro - s...@pobox.com - http://www.smontanaro.net/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Bash-like brace expansion

2009-03-24 Thread Tino Wildenhain

Peter Waller wrote:

Okay, I got fed up with there not being any (obvious) good examples of
how to do bash-like brace expansion in Python, so I wrote it myself.
Here it is for all to enjoy!

If anyone has any better solutions or any other examples of how to do
this, I'd be glad to hear from them.



It may be a funny experiment but I really fail to see the value in your
proposal.

The simple {foo} expansion you mention should be quite easily handled
with re.sub and a function as argument. So not much more then a few
lines of code.

Interesting could be to have {foo#bar} and {foo%bar} as well but again
I don't think the whole stuff would be very usefull anyway given the
%(foo)s form works quite well and has a host of options (for aligning
for example).

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


Re: Bash-like brace expansion

2009-03-24 Thread Ben Finney
Peter Waller  writes:

> Okay, yuck. I didn't realise that posting would mangle the code so
> badly. Is there any better way to attach code?

Yes: Use a news client other than Google Groups.

> I'm using google groups.

Fix that, first.

-- 
 \ “Are you pondering what I'm pondering?” “I think so, Brain, but |
  `\why would anyone want a depressed tongue?” —_Pinky and The |
_o__)   Brain_ |
Ben Finney

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


Wiki syntax available when publishing on pypi

2009-03-24 Thread Luca
A non python, but pypi only related question:

Where I can find a reference guide about all what I can do with the
text infos about a pypi egg published?
Looking at others guys code I lear how to make links, bold text,
italic, lists...
For example one time I found how to insert an image in the text, but I
don't remember how.

There is a official refence about this?

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


Re: Wiki syntax available when publishing on pypi

2009-03-24 Thread andrew cooke

it's some form of restructured text, which is described at
http://docutils.sourceforge.net/rst.html

however, there seem to be various implementations; i don't know if pypi
exactly follows what is described there (i know i had a small problem with
some detail being inconsistent with that convention used in sphinx).

also - if there's any kind of syntax error, pypi displays the entire
description literally (and gives no other error feedback that i have
found).

andrew



Luca wrote:
> A non python, but pypi only related question:
>
> Where I can find a reference guide about all what I can do with the
> text infos about a pypi egg published?
> Looking at others guys code I lear how to make links, bold text,
> italic, lists...
> For example one time I found how to insert an image in the text, but I
> don't remember how.
>
> There is a official refence about this?
>
> --
> -- luca
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>


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


Re: Relative Imports, why the hell is it so hard?

2009-03-24 Thread CinnamonDonkey
Top responses guys! This has all helped increadibly.

Bearophile,

My applogies if I have offended you, but:

1. "I can't know much about you from the start" - Is kind of my point.
Perhaps it would be better to avoid jumping to conclusions and pre-
judging someones abilities simply because they are lacking knowledge
in a particular area.

Would it have been better if I had opened my thread with a copy of my
CV? I've got a Degree in Digital Systems Engineering (yes I am also an
Engineer)... I went on to do a Phd in AI and Robotics where I also
developed embedded systems. I bummed out on that after 3 years and
went on to work for a games company where I worked on 6 game titles
across 5 different platforms. I was a Lead Software Engineer for the
last 5 years. Before now moving on again.

2. I am also very much a follower of the K.I.S.S. approach, 9 times
out of 10 the simplest solution is often the best.

As an Engineer though I would also suggest that the best way to learn
is to try solving a problem being sure to constantly assess your
approach and then your final solution. By dismissing a possible avenue
you are dismissing a whole new path of knowledge. Is it not better to
try and fail than never try at all? Surely this is how we gain the
valuable experience we need.

By simply suggesting a "simple default" solution, I may never have
consider the alternatives nor understand why they are or are not
suitable.

3. I get your point about Students, sometimes there is such a thing as
too much knowledge or information overload. Whilst doing a PhD I had
to take labs and teach students... The approach I tried to take was
one off, "You may not need packages, why do you think you need
packages?" or "This is how packages would be used and why they would
be used... do you still think you need packages" or better still, for
a capable student, "This is how packages work, try solving your
problem and then tell me if you think it was a good solution."


Going with R. David Murray, perhaps I also jumped too my own
conclusion too quickly and for that I appologise.

Cheers,
Shaun





On 24 Mar, 12:37, bearophileh...@lycos.com wrote:
> CinnamonDonkey:
>
> > It is neither constructive nor educational.
>
> > It's a bit like saying "If you don't know what a function is, then
> > maybe you don't need it. ... have you tried having a single block of
> > code?"
>
> > The point of people coming to these forums is to LEARN and share
> > knowledge. Perhaps it's not the best solution for me right now but
> > without trying it I won't know when or how to apply it as a solution.
>
> > By the way, my project has about 50 files (modules) in it with a lot
> > of shared code that could be used across other projects... seems as
> > good a reason as any to try packages out ;-)
>
> I don't agree. My answer can be wrong for your situation, but I can't
> know much about you from the start, and for most people my answer was
> the right one.
>
> When a student asks me how to improve his/her usage of metaclasses I
> usually answer that metaclasses aren't required to solve that small
> problem.
>
> Generally in engineering the simplest solution is the one you have to
> try first (and often second and third), and only later, if practical
> experience shows the simple solution doesn't work, you try a more
> complex solution.
>
> So I have suggested you a simple solution by "default". If later you
> see that you have many modules and you really need packages, then it's
> easy to ignore my first answer.
>
> Bye,
> bearophile

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


Re: PEP 3143: Standard daemon process library

2009-03-24 Thread Jean-Paul Calderone

On Tue, 24 Mar 2009 15:42:46 +1100, Ben Finney 
 wrote:

Jean-Paul Calderone  writes:

[snip]


An additional feature which would be useful for the library to
provide, however, would be the setting of euid and egid instead of
uid and gid. This is necessary, for example, to write an SSH daemon
which gives out user shells.


That sounds rather more specific than is needed for the generic
library being proposed here. I'm wary of adding features to an API
that is already quite complex.

Isn't setting the EUID and EGID something that is just as easily done
*after* the program achieves a daemon process?


That depends.

If you mean that one can ignore the uid and gid setting features of the
proposed library so that they are not changed during daemonization and
then make the appropriate calls from the application afterwards, then
yes.

Otherwise, no.  Since this means all of your daemon startup code is forced
to run as a privileged process when it might otherwise have run without
those privileges, I think it's worth the tiny additional complexity it
will bring to the API (and it really is pretty tiny, something on the order
of a new `set_effective=True´ flag).

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


Re: Unit testing frameworks

2009-03-24 Thread Jean-Paul Calderone

On Tue, 24 Mar 2009 05:06:47 -0700 (PDT), grkunt...@gmail.com wrote:

I am looking for a unit testing framework for Python. I am aware of
nose, but was wondering if there are any others that will
automatically find and run all tests under a directory hierarchy.


One such tool is trial, http://twistedmatrix.com/trac/wiki/TwistedTrial

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


Re: Unit testing frameworks

2009-03-24 Thread andrew cooke
grkunt...@gmail.com wrote:
> I am looking for a unit testing framework for Python. I am aware of
> nose, but was wondering if there are any others that will
> automatically find and run all tests under a directory hierarchy.

not exactly a framework, but useful while working on small projects - you
can run tests from inside eclipse (using the pydev plugin for python). 
it's easy to run all tests or some small subset (although it is a bit
buggy for 3.0).

andrew


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


Re: Another of those "is" issues.

2009-03-24 Thread J. Cliff Dyer
On Fri, 2009-03-20 at 11:20 -0700, Emanuele D'Arrigo wrote:
> Hi everybody,
> 
> I was unit testing some code today and I eventually stumbled on one of
> those "is" issues quickly solved replacing the "is" with "==". Still,
> I don't quite see the sense of why these two cases are different:
> 
> >>> def aFunction():
> ... pass
> ...
> >>> f = aFunction
> >>> f is aFunction
> True   <--- Ok, this seems reasonable. Nevertheless, I suspect I
> shouldn't quite rely on it.
> 
> >>> class MyClass(object):
> ... def myMethod(self):
> ... pass
> ...
> >>> c = MyClass()
> >>> m = c.myMethod
> >>> m is c.myMethod
> False  <--- What? Why is that?
> 
> In my mind I was expecting that when the method is assigned to "m" all
> that it happens is that its address is assigned to the name "m" so
> that effectively the same address is now pointed to by two names, like
> in the function case. I googled around for some hint but I wouldn't
> exactly say I'm clear on the issue just yet...
> 
> Can anybody shed some light? Or point to a resource to look at? Or
> what's the bit of python's source code that is responsible for dealing
> with those assignments?
> 
> Manu
> 

So here's a f'rinstance counterexample for you:

class TempAttributeClass(object):
  def __init__(self):
self.temp = True

  def foo(self, x):
return len(x) + 1

  def __getattribute__(self, attr):
attribute = object.__getattribute__(self,attr)
if hasattr(attribute, '__call__'):
  if object.__getattribute__(self, 'temp'):
self.temp = False
return len
  else:
return attribute
else:
  return attribute

The first time a method is accessed from an instance of this class, it
will return len instead.

>>> print TempAttributeClass.foo

>>> c = TempAttributeClass()
>>> l = [1,2,3]
>>> x = c.foo
>>> x(l) 
3
>>> c.foo
4
>>> x == c.foo
False
>>> print x

>>> print y
>

c.foo is a bound attribute, but what has it been bound to?  Well, I
guess it technically, it's bound to the instance c, but what has it been
bound from?  That depends first on what it encounters when traversing
its base classes, and second on how it's accessing its attributes.  As
the example above shows, python is too dynamic to make any guarantees
about any of that.

Another way you could mess with that is by changing the __class__
attribute on c.

class A(object):
x = 4
def __init__(self):
self.y = 5

class B(object):
x = u'cow'
def __init__(self):
self.y = u'goat'

>>> c = A()
>>> c.x
4
>>> c.y
5
>>> c.__class__ = B
>>> # Note that neither c nor x were changed in the last step
... c.x # Class attribute found on B now
u'cow'
>>> c.y # Instance attribute: already initialized from A.__init__
5
>>> c.__init__() # Reinitialize c, now using B.__init__
>>> c.y # Re-initialized instance attribute
u'goat'


Cheers,
Cliff



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


Re: Bash-like brace expansion

2009-03-24 Thread Nick Craig-Wood
Peter Waller  wrote:
>  Okay, I got fed up with there not being any (obvious) good examples of
>  how to do bash-like brace expansion in Python, so I wrote it myself.
>  Here it is for all to enjoy!

Interesting!

Might I suggest some unit tests?  You can then test all the corner
cases (unmatched brackets, empty brackets, etc) and be sure it works
exactly as specified.  doctest is cool for this kind of stuff.

-- 
Nick Craig-Wood  -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list


Re: Does Python have certificate?

2009-03-24 Thread MRAB

Johannes Bauer wrote:

Sebastian Bassi schrieb:


No, there is no certification for Python. Maybe in the future...


I'll hand out the "Johannes Bauer Python Certificate of Total
Awesomeness" for anyone who can write a hello world in python and hands
me $25000 in cash.

This whole "certified foobar programmer" is complete crap IMHO.

The above offer stands nontheless.


The "Johannes Bauer Certificate of Really Awesome Python"? ;-)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Unit testing frameworks

2009-03-24 Thread Maxim Khitrov
On Tue, Mar 24, 2009 at 8:06 AM,   wrote:
> I am looking for a unit testing framework for Python. I am aware of
> nose, but was wondering if there are any others that will
> automatically find and run all tests under a directory hierarchy.

Have you already looked at the unittest module? Below is the code I
use for one of my current projects to load all test cases in package.
This code is sitting in __init__.py, and the test cases are in
separate files (util.py, util_threading.py, etc.). Those files can
contain as many TestCase classes as needed, all are loaded with
loadTestsFromModule. You could easily modify this code to
automatically generate the modules list if you want to.

# repo/pypaq/test/__init__.py
from unittest import TestSuite, defaultTestLoader

import logging
import sys

__all__ = ['all_tests']
modules = ['util', 'util_buffer', 'util_event', 'util_threading']

if not __debug__:
raise RuntimeError('test suite must be executed in debug mode')

all_tests = []

for name in modules:
module = __import__('pypaq.test', globals(), locals(), [name], 0)
tests  = defaultTestLoader.loadTestsFromModule(getattr(module, name))

__all__.append(name)
all_tests.append(tests)
setattr(sys.modules[__name__], name, tests)

logging.getLogger().setLevel(logging.INFO)
all_tests = TestSuite(all_tests)

I then have test_pypaq.py file under repo/, with which I can execute
all_tests or only the tests from a specific module:

# repo/test_pypaq.py
from unittest import TextTestRunner
from pypaq.test import *

TextTestRunner(verbosity=2).run(all_tests)

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


Re: iPython 0.9.1 install under XP -- R6034

2009-03-24 Thread David Cournapeau
On Tue, Mar 24, 2009 at 9:36 PM, Esmail  wrote:
> Hello all,
>
> I am having problems trying installing iPython under XP.
> It works great under Linux and it would be great if I could
> also use it when I have to be in Windows.
>
> XP Professional SP2 + SP3 (tried different systems),
> iPython-0.9.1, Python 2.6.1
>
> During  "Please wait while running postinstall script .. "
> I get the following MS Visual C++ Runtime Error
>
> R6034
> An application has made an attempt to load th C runtime library incorrectly.
> .

I wonder whether this may be due to the python installer being link to
one version of the C runtime and python another (python 2.6 is linked
against the MSVCR 9.0).

If you need ipython quickly, I would simply try building the installer
myself from sources - as ipython does not have dependency and is pure
python, it should be straightfoward to do a python setup.py
bdist_wininst,

cheers,

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


Re: PEP 3143: Standard daemon process library

2009-03-24 Thread Floris Bruynooghe
On Mar 21, 11:06 pm, Ben Finney  wrote:
> Floris Bruynooghe  writes:
> > Had a quick look at the PEP and it looks very nice IMHO.
>
> Thank you. I hope you can try the implementation and report feedback
> on that too.
>
> > One of the things that might be interesting is keeping file
> > descriptors from the logging module open by default.
>
> Hmm. I see that this would be a good idea. but it raises the question
> of how to manage the set of file handles that should not be closed on
> becoming a daemon.
>
> So far, the logic of closing the file descriptors is a little complex:
>
>     * Close all open file descriptors. This excludes those listed in
>       the `files_preserve` attribute, and those that correspond to the
>       `stdin`, `stdout`, or `stderr` attributes.
>
> Extending that by saying “… and also any file descriptors for
> ``logging.FileHandler`` objects” starts to make the description too
> complex. I have a strong instinct that it the description is complex,
> the design might be bad.
>
> Can you suggest an alternative API that will ensure that all file
> descriptors get closed *except* those that should not be closed?

Not an answer yet, but I'll try to find time in the next few days to
play with this and tell you what I think.  logging.FileHandler would
be too narrow in any case I think.


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


Transition from urllibs to browser and keep session alive

2009-03-24 Thread JReed
Hello, I currently have a script that uses httplib2 to navigate through a
website and collect some cookies manually along the way.  It is an https
that requires a logon, then i navigate through a few pages and the end
result is to dump some info into a javascript and i display the returned
html in a browser.

  It works great if you just need to print that one page, but if someone
wants to click further into the page it wont work because it is just a local
copy of the returned html.  I would like to find a way to take the cookie
and session information and open the page in a browser after i have walked
through the pages and collected the cookies by means of a script, etc.  Just
looking for some recomendations on what modules would fit this scenerio
best.  Your responses are greatly appreciated, thanks!

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


Appending to sys.path

2009-03-24 Thread mhearne808[insert-at-sign-here]gmail[insert-dot-here]com
I have an application where I would like to append to the python path
dynamically.  Below is a test script I wrote.  Here's what I thought
would happen:

1) I run this script in a folder that is NOT already in PYTHONPATH
2) The script creates a subfolder called foo.
3) The script creates a file called foo.py, with a foo() method
defined in it.
4) The script attempts to import this module, which fails because the
current folder is not in PYTHONPATH.
5) The script then adds the current folder to the end of sys.path
6) The script again attempts to import foo.foo, and succeeds.

#6 never happens, but I can't figure out why.  I'm running on Mac OS
10.5, with python 2.5.1.

Anybody have any tips?

Thanks,

Mike

Here's the script:
#!/usr/bin/python

import sys
import os.path

txt = 'def foo(): print "Hello world!"\n'
if not os.path.isdir('foo'):
os.mkdir('foo')
f = open('foo/foo.py','wt')
f.write(txt)
f.close()

try:
__import__('foo.foo')
except ImportError:
homedir = os.path.abspath(sys.path[0]) #where is this script?
print 'Adding %s to sys.path' % (homedir)
sys.path.append(homedir)
try:
__import__('foo.foo')
print 'Import now successful'
except ImportError:
print "Why didn't this work?"
sys.exit(1)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Relative Imports, why the hell is it so hard?

2009-03-24 Thread Istvan Albert
On Mar 23, 10:16 am, CinnamonDonkey 
wrote:

> I'm fairly new to Python so I still have a lot to learn. But I'd like
> to know how to correectly use relative imports.

Relative imports are *fundamentally* broken in python. You will soon
see that code using relative import will break if you attempt to run
the module on its own. Yes, it is mindboggling!

Why is it so you ask? It is one of those issue that would be trivial
to implement correctly (it is relative to the current file location,
duh!!!), would be tremendously useful yet  for some reason it is
controversial with those who would need to implement it.

It looks like they think that the expected mode of operation would
greatly confuse the 'rest' of us. So that is the reason you end up
with a broken implementation that is worse than not having it at all.
All I can do is recommend that you avoid relative imports.

The easiest way around the issue is to create a module named
pathfix.py like the one below and import it in all of your modules.
This is the only way to fix this issue in a way that does not come
back and bite you, it is ugly, you are repeating yourself in multiple
places, but it is still better than the alternative.

---

import os, sys

def path_join(*args):
return os.path.abspath(os.path.join(*args))

# adds base directory to import path to allow relative imports
__currdir = os.path.dirname( __file__ )
__basedir = path_join(__currdir, '..' )
if __basedir not in sys.path:
sys.path.append( __basedir )


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


Re: install pyPgSQL on Windows for python 2.5

2009-03-24 Thread Dietmar Schwertberger

someone wrote:

Hi,

does anyone know how to install pyPgSQL on Windows? There is no
package for Python 2.5 on Homepage:



I've installed newest Visual C++ Studio 2008 from Microsoft, but still
no luck


Hello Pet,

you need Visual Studio 2003 to compile extensions for Python 2.5
If you want, I can send you a binary.

Regards,

Dietmar

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


Re: Appending to sys.path

2009-03-24 Thread Peter Otten
mhearne808[insert-at-sign-here]gmail[insert-dot-here]com wrote:

> I have an application where I would like to append to the python path
> dynamically.  Below is a test script I wrote.  Here's what I thought
> would happen:
> 
> 1) I run this script in a folder that is NOT already in PYTHONPATH
> 2) The script creates a subfolder called foo.
> 3) The script creates a file called foo.py, with a foo() method
> defined in it.
> 4) The script attempts to import this module, which fails because the
> current folder is not in PYTHONPATH.
> 5) The script then adds the current folder to the end of sys.path
> 6) The script again attempts to import foo.foo, and succeeds.
> 
> #6 never happens, but I can't figure out why.  I'm running on Mac OS
> 10.5, with python 2.5.1.
> 
> Anybody have any tips?
> 
> Thanks,
> 
> Mike
> 
> Here's the script:
> #!/usr/bin/python
> 
> import sys
> import os.path
> 
> txt = 'def foo(): print "Hello world!"\n'
> if not os.path.isdir('foo'):

Here you add a directory under the current working directory.

> os.mkdir('foo')
> f = open('foo/foo.py','wt')
> f.write(txt)
> f.close()

To turn the foo directory into a package you must also create a file
foo/__init__.py (may be empty).
> 
> try:
> __import__('foo.foo')
> except ImportError:
> homedir = os.path.abspath(sys.path[0]) #where is this script?
> print 'Adding %s to sys.path' % (homedir)
> sys.path.append(homedir)

Here you add the directory to the path were the script is located, not the
cwd. Should be

 sys.path.append(".")

> try:
> __import__('foo.foo')
> print 'Import now successful'
> except ImportError:
> print "Why didn't this work?"
> sys.exit(1)

Peter

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


Re: Translating unicode data

2009-03-24 Thread CaptainMcCrank
On Mar 23, 4:16 pm, Peter Otten <__pete...@web.de> wrote:
> CaptainMcCrank wrote:
> > I'm struggling with a problem analyzing large amounts of unicode data
> > in an http wireshark capture.
> > I've solved the problem with the interpreter, but I'm not sure how to
> > do this in an automated fashion.
>
> > I'd like to grab a line from a text file & translate the unicode
> > sections of it to ascii.  So, for example
> > I'd like to take
> > "\u003cb\u003eMar 17\u003c/b\u003e"
>
> > and turn it into
>
> > "Mar 17"
>
> > I can handle this from the interpreter as follows:
>
>  import unicodedata
>  mystring = u"\u003cb\u003eMar 17\u003c/b\u003e"
>  print mystring
> > Mar 17
>
> > But I don't know what I need to do to automate this!  The data that is
> > in the quotes from line 2 will have to come from a variable.  I am
> > unable to figure out how to do this using a variable rather than a
> > literal string.
>
> If wireshark uses the same escape codes as python you can use str.decode()
> or open the file with codecs.open():
>
> >>> s = "\u003cb\u003eMar 17\u003c/b\u003e"
> >>> s
>
> '\\u003cb\\u003eMar 17\\u003c/b\\u003e'>>> s.decode("unicode-escape")
>
> u'Mar 17'
>
> >>> open("tmp.txt", "w").write(s)
> >>> import codecs
> >>> f = codecs.open("tmp.txt", "r", encoding="unicode-escape")
> >>> f.read()
>
> u'Mar 17'
>
> Peter

This is a workable solution!  Thank you Peter!
--
http://mail.python.org/mailman/listinfo/python-list


Re: parsing tab separated data efficiently into numpy/pylab arrays

2009-03-24 Thread mapb81
You could take a look/use the very handy csv2rec function in
matplotlib.mlab, which creates numpy struct arrays.

Marco

On Mar 13, 10:19 pm, per  wrote:
> hi all,
>
> what's the most efficient / preferred python way ofparsingtab
> separated data intoarrays? for example if i have a file containing
> two columns one corresponding to names the other numbers:
>
> col1    \t     col 2
> joe    \t  12.3
> jane   \t 155.0
>
> i'd like to parse into an array() such that i can do: mydata[:, 0] and
> mydata[:, 1] to easily access all the columns.
>
> right now i can iterate through the file, parse it manually using the
> split('\t') command and construct a list out of it, then convert it toarrays. 
> but there must be a better way?
>
> also, my first column is just a name, and so it is variable in length
> -- is there still a way to store it as an array so i can access: mydata
> [:, 0] to get all the names (as a list)?
>
> thank you.

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


minor revision encoded in SONAME in libpython.so

2009-03-24 Thread szager
I'm wondering why the SONAME in libpython.so has a minor revision
encoded in it; for example (on Linux):

$ readelf -d libpython2.6.so | grep SONAME
 0x000e (SONAME) Library soname:
[libpython2.6.so.1.0]

Because of this, if I compile an app against this library (with '-L/
usr/lib -lpython2.6), the compiled app has a dependency in this
precise minor revision of libpython2.6.so:

$ readelf -d myApp | grep libpython
 0x0001 (NEEDED) Shared library:
[libpython2.6.so.1.0]

So, for example, if I upgrade to libpython2.6.so.1.1, my app will not
be able to run.  I am currently having this problem while integrating
a piece of third-party software that uses an embedded python
interpreter.

This is unusual for libraries of this kind.  Typically, the SONAME
will contain only the major revision, on the assumption that all the
minor revisions conform to the same public API, and are nominally
interchangeable.  Am I to assume that minor version iterations have
incompatible API's?

Thanks in advance for any guidance.

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


Re: install pyPgSQL on Windows for python 2.5

2009-03-24 Thread someon
On Mar 24, 4:57 pm, Dietmar Schwertberger 
wrote:
> someone wrote:
> > Hi,
>
> > does anyone know how to install pyPgSQL on Windows? There is no
> > package for Python 2.5 on Homepage:
> > I've installed newest Visual C++ Studio 2008 from Microsoft, but still
> > no luck
>
> Hello Pet,
>
> you need Visual Studio 2003 to compile extensions for Python 2.5
> If you want, I can send you a binary.

O, thank you very much!
Where should I put hole thing?

>
> Regards,
>
> Dietmar

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


Re: Async serial communication/threads sharing data

2009-03-24 Thread John Nagle

Hendrik van Rooyen wrote:

"Nick Craig-Wood"  wrote:


I wrote a serial port to TCP proxy (with logging) with twisted.  The
problem I had was that twisted serial ports didn't seem to have any
back pressure.  


Not sure if this is Twisted's fault - 
do python sockets have 
automatic back pressure?

Do Linux sockets have back pressure?


   Yes, and yes.

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


Re: Unit testing frameworks

2009-03-24 Thread pruebauno
On Mar 24, 8:06 am, grkunt...@gmail.com wrote:
> I am looking for a unit testing framework for Python. I am aware of
> nose, but was wondering if there are any others that will
> automatically find and run all tests under a directory hierarchy.
>
> Thanks, Ralph

*Nose
*Trial
*py.test
--
http://mail.python.org/mailman/listinfo/python-list


Re: Does Python have certificate?

2009-03-24 Thread Steve Holden
Johannes Bauer wrote:
> Sebastian Bassi schrieb:
> 
>> No, there is no certification for Python. Maybe in the future...
> 
> I'll hand out the "Johannes Bauer Python Certificate of Total
> Awesomeness" for anyone who can write a hello world in python and hands
> me $25000 in cash.
> 
> This whole "certified foobar programmer" is complete crap IMHO.
> 
The certification kind of comes out in the wash from the O'Reilly
development process, it's not a primary goal.

> The above offer stands nontheless.
> 
I'll trade you for a Steve Holden Information Technology certification ...

regards
 Steve
-- 
Steve Holden   +1 571 484 6266   +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
Want to know? Come to PyCon - soon! http://us.pycon.org/

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


Re: Bash-like brace expansion

2009-03-24 Thread Peter Waller
Heh, thanks :)

Unit tests did cross my mind. I was kicking myself for not starting
out with them, there were several regressions during development, and
there could well still be lurking corner cases ;)

I've since heard that a 'better way' would be to use pyparsing. Also,
I saw that python has dropped the idea of having recursive regular
expressions at the moment.

http://bugs.python.org/msg83993

Maybe I might re-implement this with pyparsing and some unit tests.

On Mar 24, 2:30 pm, Nick Craig-Wood  wrote:
> Peter Waller  wrote:
> >  Okay, I got fed up with there not being any (obvious) good examples of
> >  how to do bash-like brace expansion in Python, so I wrote it myself.
> >  Here it is for all to enjoy!
>
> Interesting!
>
> Might I suggest some unit tests?  You can then test all the corner
> cases (unmatched brackets, empty brackets, etc) and be sure it works
> exactly as specified.  doctest is cool for this kind of stuff.
>
> --
> Nick Craig-Wood  --http://www.craig-wood.com/nick

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


Best GUI toolkit with Table support

2009-03-24 Thread deech
Hi all,
I am making a cross-platform frontend to a sqlite3 database. Which
python GUI toolkit has the best table support? Tkinter doesn't seem to
support them (without additional package installation).

The issue is that the application must run off a flash drive with a
vanilla Python install on both Windows and Linux. Or if there is a way
to store additional packages on the flash drive and call them in some
portable way, this would work too.

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


Re: Relative Imports, why the hell is it so hard?

2009-03-24 Thread Gabriel Genellina
En Tue, 24 Mar 2009 12:49:08 -0300, Istvan Albert  
 escribió:

On Mar 23, 10:16 am, CinnamonDonkey 
wrote:


I'm fairly new to Python so I still have a lot to learn. But I'd like
to know how to correectly use relative imports.


Relative imports are *fundamentally* broken in python. You will soon
see that code using relative import will break if you attempt to run
the module on its own. Yes, it is mindboggling!


How import works in general is hard to grasp -- the semantics are rather  
complicated, partly because the import system has grown patch over patch  
over the years, and because it's mostly underdocumented.
But I would not say that relative imports are "fundamentally broken" --  
they're one of the best improvements to the import system!



Why is it so you ask? It is one of those issue that would be trivial
to implement correctly (it is relative to the current file location,
duh!!!), would be tremendously useful yet  for some reason it is
controversial with those who would need to implement it.


A module doesn't *have* to reside in the filesystem - so in the general  
case, there is no such thing as "current file location". Packages provide  
such hierarchical disposition - and relative imports work with packages  
only.



It looks like they think that the expected mode of operation would
greatly confuse the 'rest' of us. So that is the reason you end up
with a broken implementation that is worse than not having it at all.
All I can do is recommend that you avoid relative imports.


I'd recommend the oposite - use relative (intra-package) imports when  
possible. Explicit is better than implicit - and starting with 2.7 -when  
"absolute" import semantics will be enabled by default- you'll *have* to  
use relative imports inside a package, or fail.



The easiest way around the issue is to create a module named
pathfix.py like the one below and import it in all of your modules.
This is the only way to fix this issue in a way that does not come
back and bite you, it is ugly, you are repeating yourself in multiple
places, but it is still better than the alternative.


"import it in all of your modules"?
Did you know, once a module is imported by the first time, subsequent  
imports simply return the same module instance? The initialization code is  
not executed again.



import os, sys

def path_join(*args):
return os.path.abspath(os.path.join(*args))

# adds base directory to import path to allow relative imports
__currdir = os.path.dirname( __file__ )
__basedir = path_join(__currdir, '..' )
if __basedir not in sys.path:
sys.path.append( __basedir )


I don't understand, how is this supposed to help relative imports?
Bindly inserting directories into sys.path can easily confuse the import  
system (and you!)


--
Gabriel Genellina

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


Re: Relative Imports, why the hell is it so hard?

2009-03-24 Thread Gabriel Genellina
En Tue, 24 Mar 2009 09:01:01 -0300, R. David Murray  
 escribió:

CinnamonDonkey  wrote:

On 23 Mar, 18:57, bearophileh...@lycos.com wrote:
> CinnamonDonkey:
>
> >what makes something a package?
>
> If you don't know what a package is, then maybe you don't need
> packages.

Thanx for taking the time to post a response but I am afraid I feel
the need to point out that it is exactly this kind of response that I
find un-helpful. It is neither constructive nor educational.


I think bearophile could have left out the first sentence, but otherwise
his question is perfectly sensible.  If you have a bunch of independent
modules, then you don't need to put them in packages.  Your example
only showed one module file in each package...I understand now that was
just for simplicity of the example, but we had no way of knowing that.


Especially, since people coming from Java:

- think that they *have* to use a package
- think that they *have* to put a single class per file

Neither is true in Python. And from the example alone, one could infer the  
OP was making such mistakes. Glad to see it was not the case.


--
Gabriel Genellina

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


Re: Unit testing frameworks

2009-03-24 Thread Gabriel Genellina

En Tue, 24 Mar 2009 09:06:47 -0300,  escribió:


I am looking for a unit testing framework for Python. I am aware of
nose, but was wondering if there are any others that will
automatically find and run all tests under a directory hierarchy.


All known testing tools (and some unknown too):

http://pycheesecake.org/wiki/PythonTestingToolsTaxonomy

--
Gabriel Genellina

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


Re: Best GUI toolkit with Table support

2009-03-24 Thread Stef Mientki

deech wrote:

Hi all,
I am making a cross-platform frontend to a sqlite3 database. Which
python GUI toolkit has the best table support? Tkinter doesn't seem to
support them (without additional package installation).

The issue is that the application must run off a flash drive with a
vanilla Python install on both Windows and Linux. Or if there is a way
to store additional packages on the flash drive and call them in some
portable way, this would work too.

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

this one is build upon wxPython:

http://mientki.ruhosting.nl/data_www/pylab_works/pw_sqllite.html


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


Re: Bash-like brace expansion

2009-03-24 Thread Paul McGuire
On Mar 24, 12:39 pm, Peter Waller  wrote:
>
> Maybe I might re-implement this with pyparsing and some unit tests.
>

In your pyparsing efforts, you might draw some insights from this
regex inverter (that is, given an re such as "[AB]\d", returns "A0"
through "B9") on the pyparsing wiki: 
http://pyparsing.wikispaces.com/file/view/invRegex.py.

-- Paul

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


setting directory mod date

2009-03-24 Thread jyoung79
I've got some Python code (2.5.1) that's compressing folders 
on a Windows machine.  When the directories get 
compressed, their modification date changes.  Is it possible 
to grab the modification date of the folder before it's 
compressed, and then set it's modification date back to it's 
original state after it's compressed?  I've been reading 
different articles on-line about this, but nothing looks very 
promising.  I haven't tested os.utime() or win32file since 
others have said these won't work correctly with folders on 
Windows XP.

Thanks.

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


debuglevel for a HTTP request

2009-03-24 Thread Carbon Man
#Python 2.5
# from Dive Into Python 11.5

import httplib
httplib.HTTPConnection.debuglevel = 1
import urllib2
request = urllib2.Request('http://localhost/test/atom.xml')
opener = urllib2.build_opener()
feeddata = opener.open(request).read()

It doesn't show the debug output, any ideas? 


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


autocomplete and printing

2009-03-24 Thread vikram moule
Q1. I want to access a database and just by pressing the first alphabet will
showup a dropdown list of all the words starting from that alphabet how can
I do that ?
( I know how to access the database but the further problem is unsolved
hence)
Q2. How can I print a document for example bill or prescription through a
printer or network printer (both) using python ?

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


Re: autocomplete and printing

2009-03-24 Thread Gabriel Genellina
En Tue, 24 Mar 2009 17:56:26 -0300, vikram moule   
escribió:


Q1. I want to access a database and just by pressing the first alphabet  
will
showup a dropdown list of all the words starting from that alphabet how  
can

I do that ?
( I know how to access the database but the further problem is unsolved
hence)


Populate the dropdownlist with results from a query like this: "SELECT XXX  
FROM YYY WHERE XXX LIKE 'A%'"

(all rows where XXX starts with A).
You'll have to provide more info if you want more details (Which database?  
Which adapter? Is it a console application, a GUI application, a web one?  
Which toolkit/framework?)



Q2. How can I print a document for example bill or prescription through a
printer or network printer (both) using python ?


If you tell us how would you do that without Python, maybe someone  
suggests how to do the same thing with Python.


--
Gabriel Genellina

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


Re: minor revision encoded in SONAME in libpython.so

2009-03-24 Thread Martin v. Löwis
> So, for example, if I upgrade to libpython2.6.so.1.1

How do you do that? There won't ever be such a library. They
will always be called libpython2.6.so.1.0.

So no, no minor revision gets encoded into the SONAME.

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


file open fails.

2009-03-24 Thread Atul.
Hi I am using IDLE on Windows Vista and I have a small code.

title = 'C:\Thesis\refined_title.txt'
file = open(title)

I get the following error from Python.


file = open(title)
IOError: [Errno 22] invalid mode ('r') or filename: 'C:\\Thesis
\refined_title.txt'

Now, I can not understand the problem here I have all the permissions
set for the folder, file as well. I can not understand why would it
happen. Is it known on Windows Vista or am I missing something really
simple and stupid? Please help.

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


Re: PEP 3143: Standard daemon process library

2009-03-24 Thread Ben Finney
Jean-Paul Calderone  writes:

> On Tue, 24 Mar 2009 15:42:46 +1100, Ben Finney 
>  wrote:
> >That sounds rather more specific than is needed for the generic
> >library being proposed here. I'm wary of adding features to an API
> >that is already quite complex.
> >
> >Isn't setting the EUID and EGID something that is just as easily
> >done *after* the program achieves a daemon process?
> 
> That depends.
> 
> If you mean that one can ignore the uid and gid setting features of the
> proposed library so that they are not changed during daemonization and
> then make the appropriate calls from the application afterwards, then
> yes.

Yes, that's what I meant.

> Otherwise, no. Since this means all of your daemon startup code is
> forced to run as a privileged process when it might otherwise have
> run without those privileges

Er? You can still set the real UID and GID via the DaemonContext API,
and then also set the EUID and EGID.

> I think it's worth the tiny additional complexity it will bring to
> the API (and it really is pretty tiny, something on the order of a
> new `set_effective=True´ flag).

It leads immediately to the request to set *both* real UID/GID *and*
effective UID/GID to separate values.

Can you describe the use case more, so I can understand better how
common it might be? In what circumstances must one not change the real
UID/GID but instead change the effective UID/GID, *and* must change
them during daemonisation?

-- 
 \  “One thing vampire children have to be taught early on is, |
  `\  don't run with a wooden stake.” —Jack Handey |
_o__)  |
Ben Finney

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


Re: file open fails.

2009-03-24 Thread Scott David Daniels

Atul. wrote:

title = 'C:\Thesis\refined_title.txt'
file = open(title)
I get the following error from Python.
file = open(title)
IOError: [Errno 22] invalid mode ('r') or filename: 'C:\\Thesis
\refined_title.txt'



Now, I can not understand the problem here ...

Repesat to yourself 1e4 tmes: "I shall not put windows file
names in quotes w/o using 'r' (as in raw files).  Either
always use forward slashes, or get used to typing:
  title = r'C:\Thesis\refined_title.txt'

In your case, '\r' is a return (a single character), not two
characters long. I think its sad that 'C:\Thesis' doesn't cause
an error because there is no such character as '\T', but I am
probably excessively pedantic.

--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: setting directory mod date

2009-03-24 Thread MRAB

jyoun...@kc.rr.com wrote:
I've got some Python code (2.5.1) that's compressing folders 
on a Windows machine.  When the directories get 
compressed, their modification date changes.  Is it possible 
to grab the modification date of the folder before it's 
compressed, and then set it's modification date back to it's 
original state after it's compressed?  I've been reading 
different articles on-line about this, but nothing looks very 
promising.  I haven't tested os.utime() or win32file since 
others have said these won't work correctly with folders on 
Windows XP.



I've just tried it. os.utime() _does_ work correctly on folders.
--
http://mail.python.org/mailman/listinfo/python-list


Re: file open fails.

2009-03-24 Thread MRAB

Atul. wrote:

Hi I am using IDLE on Windows Vista and I have a small code.

title = 'C:\Thesis\refined_title.txt'
file = open(title)

I get the following error from Python.


file = open(title)
IOError: [Errno 22] invalid mode ('r') or filename: 'C:\\Thesis
\refined_title.txt'

Now, I can not understand the problem here I have all the permissions
set for the folder, file as well. I can not understand why would it
happen. Is it known on Windows Vista or am I missing something really
simple and stupid? Please help.


Backslash has a special meaning in string literals. Use a raw string
instead or double the backslashes:

title = r'C:\Thesis\refined_title.txt'

or:

title = 'C:\\Thesis\\refined_title.txt'

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


[ANN] mlabwrap-1.0.1 released

2009-03-24 Thread Alexander Schmolck
Mlabwrap allows pythonistas to interface to Matlab(tm) in a very
straightforward fashion:

>>> from mlabwrap import mlab
>>> mlab.eig([[0,1],[1,1]])
array([[-0.61803399],
   [ 1.61803399]])

More at .

Mlabwrap 1.0.1 is just a maintenance release that fixes a few bugs and
simplifies installation (no more LD_LIBRARY_PATH hassles).

'as

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


Re: file open fails.

2009-03-24 Thread Wes James
On Tue, Mar 24, 2009 at 4:04 PM, Scott David Daniels
 wrote:
> Atul. wrote:



> In your case, '\r' is a return (a single character), not two
> characters long. I think its sad that 'C:\Thesis' doesn't cause
> an error because there is no such character as '\T', but I am
> probably excessively pedantic.

\T might mean the same thing as \t (tab), but I thought it would be different...

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


Re: debuglevel for a HTTP request

2009-03-24 Thread cgoldberg
>  It doesn't show the debug output, any ideas?

I think like this:
opener = urllib2.build_opener(urllib2.HTTPHandler(debuglevel=1))

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


Re: file open fails.

2009-03-24 Thread Wes James
On Tue, Mar 24, 2009 at 4:32 PM, Wes James  wrote:
> On Tue, Mar 24, 2009 at 4:04 PM, Scott David Daniels
>  wrote:
>> Atul. wrote:
>
> 
>
>> In your case, '\r' is a return (a single character), not two
>> characters long. I think its sad that 'C:\Thesis' doesn't cause
>> an error because there is no such character as '\T', but I am
>> probably excessively pedantic.
>
> \T might mean the same thing as \t (tab), but I thought it would be 
> different...


I guess not:

http://docs.python.org/reference/lexical_analysis.html#string-literals

Wonder why when I do print "test\Ttest" vs print "test\ttest"  \T just
get printed?

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


Re: Style question - defining immutable class data members

2009-03-24 Thread Aahz
In article ,
Maxim Khitrov   wrote:
>
>Very simple question on the preferred coding style. I frequently write
>classes that have some data members initialized to immutable values.
>For example:
>
>class Test(object):
>def __init__(self):
>self.some_value = 0
>self.another_value = None
>
>Similar effect can be achieved by defining some_value and
>another_value for the entire class, like so:
>
>class Test(object):
>some_value = 0
>another_value = None
>
>The advantage of doing this is that the assignments are evaluated once
>and thus the creation of that class is a bit faster. Access is still
>performed through self.some_value and self.another_value. Is there a
>reason to prefer the first style over the second?

Well, as you can see from reading this whole thread, it can be the source
of some confusion.  Nevertheless, I personally sometimes use the style of
initializing at the class level.  I think it's probably worth creating a
style guide entry for this issue if you're using Python for your
employer.
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"At Resolver we've found it useful to short-circuit any doubt and just
refer to comments in code as 'lies'. :-)"
--Michael Foord paraphrases Christian Muirhead on python-dev, 2009-3-22
--
http://mail.python.org/mailman/listinfo/python-list


Python 3 consistency proposal

2009-03-24 Thread gert
Rename all built in classes with a capital letter
example Str() Int() Object()

Make () optional for a function definition
class Test:
pass

def test:
pass

Any chance Guido would approve this :-)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3 consistency proposal

2009-03-24 Thread Daniel Fetchinson
> Rename all built in classes with a capital letter
> example Str() Int() Object()

Why?

> Make () optional for a function definition
> class Test:
> pass
>
> def test:
> pass

Why?

> Any chance Guido would approve this :-)

In my estimation, the chance that Guido would approve this is less
than 10^(-26).

Cheers,
Daniel

-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown
--
http://mail.python.org/mailman/listinfo/python-list


Re: Best GUI toolkit with Table support

2009-03-24 Thread Todd Whiteman

deech wrote:

Hi all,
I am making a cross-platform frontend to a sqlite3 database. Which
python GUI toolkit has the best table support? Tkinter doesn't seem to
support them (without additional package installation).

The issue is that the application must run off a flash drive with a
vanilla Python install on both Windows and Linux. Or if there is a way
to store additional packages on the flash drive and call them in some
portable way, this would work too.


If you don't need custom sqlite functionality, you could use an existing 
sqlite manager app, such as SQLiteManager, which runs cross-platform as 
a Firefox extension, or can use XULRunner as a standalone (so it could 
run off a flash drive):

http://code.google.com/p/sqlite-manager/wiki/ScreenShots

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


Re: iPython 0.9.1 install under XP -- R6034

2009-03-24 Thread Esmail

Hello David,

David Cournapeau wrote:



If you need ipython quickly, I would simply try building the installer
myself from sources - as ipython does not have dependency and is pure
python, it should be straightfoward to do a 

>

python setup.py bdist_wininst,


Thanks for the suggestion, it seems to have worked, but I don't
think it created any of the .bat files or entries in the startup
menu etc. .. any idea how to those parts set up?

Also, how did you know about the bdist_wininst command line argument?
I looked around for this sort of information, but must have missed
it.

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


Re: Problem Python 2.6.1 vs 2.6 & pyWin32

2009-03-24 Thread John Machin
Martin v. Löwis  v.loewis.de> writes:

> 
> > Sorry for not being explicit. With "installer" I meant the binary
> > Windows installer you create with command "python setup.py
> > bdist_wininst". In the past we've been able to use
> > "package-version.win32.exe" files created with Python 2.5 on older
> > version, but that doesn't seem to be case with 2.6.
> 
> I see. This has nothing to do with the OP's question, then.
> 
> For Python 2.6, we switched to VS 2008. Apparently, the bdist_msi
> installers now get linked with the VS 2008 CRT (msvcr90.dll), which
> must be present on the system (in WinSxS) for the installer to run;
> one way of installing the CRT is to install Python for all users,
> another is to install it "just for me", and put \python26 into PATH
> (so that the installer can find msvcr90.dll).
> 

Hi Martin,

Unfortunately this solution can't be used where the user is not permitted to
upgrade Python to 2.6 or where there appears to be an incompatible version of
msvcr90.dll in C:\windows\winsxs.

For example a user with no admin privileges on his work PC and stuck with Python
2.4.2 on Windows XP SP2 (not SP3) has the following problem when trying to run a
bdist_wininst .exe that was created for a pure-Python package using Python 
2.6.1:
"""
the error message is the same as stated in this article:
http://www.chiark.greenend.org.uk/~sgtatham/putty/wishlist/xp-wont-run.html
"""
presumably (given his locale) the German version of the error message, complete
with MS misspelling.

It would appear that the safest cover-most-bases option for a developer/packager
of pure-Python packages (especially one intended to be runnable on older
versions of Python, some as far back as 2.1) is to use Python 2.5 to make the
bdist_wininst (the exe is linked against msvcr71.dll which is widely available
and doesn't have SxS problems). Do you agree? If so, where is the best place to
propagate this advice?

Cheers,
John



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


Re: setting directory mod date

2009-03-24 Thread Gabriel Genellina
En Tue, 24 Mar 2009 19:10:50 -0300, MRAB   
escribió:



jyoun...@kc.rr.com wrote:
I've got some Python code (2.5.1) that's compressing folders on a  
Windows machine.  When the directories get compressed, their  
modification date changes.  Is it possible to grab the modification  
date of the folder before it's compressed, and then set it's  
modification date back to it's original state after it's compressed?   
I've been reading different articles on-line about this, but nothing  
looks very promising.  I haven't tested os.utime() or win32file since  
others have said these won't work correctly with folders on Windows XP.



I've just tried it. os.utime() _does_ work correctly on folders.


But not on Python 2.5 :(

Using the pywin32 package:

py> os.stat("cuchi")
(16895, 0L, 0, 0, 0, 0, 0L, 1237259905, 1235809285, 1235809278)
py> from win32file import *
py> hFile = CreateFile("cuchi", GENERIC_WRITE, 0,
... None, OPEN_EXISTING,
... FILE_FLAG_BACKUP_SEMANTICS, None)
py> import time
py> import pywintypes
py> t = pywintypes.Time(time.localtime())
py> win32file.SetFileTime(hFile, t, t, t)
py> CloseHandle(hFile)
py> os.stat("cuchi")
(16895, 0L, 0, 0, 0, 0, 0L, 1237940110, 1237940110, 1237940110)

--
Gabriel Genellina

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


Re: Python 3 consistency proposal

2009-03-24 Thread Steven D'Aprano
On Tue, 24 Mar 2009 16:45:26 -0700, gert wrote:

> Rename all built in classes with a capital letter example Str() Int()
> Object()
> 
> Make () optional for a function definition class Test:
> pass
> 
> def test:
> pass
> 
> Any chance Guido would approve this :-)

Unless you're volunteering to produce a patch, the chances are zero.

If you *are* willing to do the work, the chances would still be pretty 
slim. Guido has just rejected a patch adding PEP 8 compliant aliases for 
types like datetime, so I think replacing built-ins have all-but zero 
chance. But if you want to pursue it, the right place is the python-ideas 
mailing list. Go for it ... but be prepared to justify the change, and 
not just "for consistency". As Guido has quoted before, "A foolish 
consistency is the hobgoblin of little minds".



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


Re: setting directory mod date

2009-03-24 Thread MRAB

Gabriel Genellina wrote:
En Tue, 24 Mar 2009 19:10:50 -0300, MRAB  
escribió:



jyoun...@kc.rr.com wrote:
I've got some Python code (2.5.1) that's compressing folders on a 
Windows machine.  When the directories get compressed, their 
modification date changes.  Is it possible to grab the modification 
date of the folder before it's compressed, and then set it's 
modification date back to it's original state after it's compressed?  
I've been reading different articles on-line about this, but nothing 
looks very promising.  I haven't tested os.utime() or win32file since 
others have said these won't work correctly with folders on Windows XP.



I've just tried it. os.utime() _does_ work correctly on folders.


But not on Python 2.5 :(


Ah, missed that bit (I used Python 2.6.1). Sorry!


Using the pywin32 package:

py> os.stat("cuchi")
(16895, 0L, 0, 0, 0, 0, 0L, 1237259905, 1235809285, 1235809278)
py> from win32file import *
py> hFile = CreateFile("cuchi", GENERIC_WRITE, 0,
... None, OPEN_EXISTING,
... FILE_FLAG_BACKUP_SEMANTICS, None)
py> import time
py> import pywintypes
py> t = pywintypes.Time(time.localtime())
py> win32file.SetFileTime(hFile, t, t, t)
py> CloseHandle(hFile)
py> os.stat("cuchi")
(16895, 0L, 0, 0, 0, 0, 0L, 1237940110, 1237940110, 1237940110)



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


Re: file open fails.

2009-03-24 Thread Steven D'Aprano
On Tue, 24 Mar 2009 16:48:30 -0600, Wes James wrote:

> On Tue, Mar 24, 2009 at 4:32 PM, Wes James  wrote:
>> On Tue, Mar 24, 2009 at 4:04 PM, Scott David Daniels
>>  wrote:
>>> Atul. wrote:
>>
>> 
>>
>>> In your case, '\r' is a return (a single character), not two
>>> characters long. I think its sad that 'C:\Thesis' doesn't cause an
>>> error because there is no such character as '\T', but I am probably
>>> excessively pedantic.
>>
>> \T might mean the same thing as \t (tab), but I thought it would be
>> different...
> 
> 
> I guess not:
> 
> http://docs.python.org/reference/lexical_analysis.html#string-literals
> 
> Wonder why when I do print "test\Ttest" vs print "test\ttest"  \T just
> get printed?


Did you read the section you just linked to? It says so right there:

"Unlike Standard C, all unrecognized escape sequences are left in the 
string unchanged, i.e., the backslash is left in the string. (This 
behavior is useful when debugging: if an escape sequence is mistyped, the 
resulting output is more easily recognized as broken.) It is also 
important to note that the escape sequences marked as “(Unicode only)” in 
the table above fall into the category of unrecognized escapes for non-
Unicode string literals."

Since there is no standard escape \T then it gets treated as a literal 
backslash + uppercase t.



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


Re: file open fails.

2009-03-24 Thread Rhodri James

On Tue, 24 Mar 2009 22:48:30 -, Wes James  wrote:


On Tue, Mar 24, 2009 at 4:32 PM, Wes James  wrote:
\T might mean the same thing as \t (tab), but I thought it would be  
different...



I guess not:

http://docs.python.org/reference/lexical_analysis.html#string-literals

Wonder why when I do print "test\Ttest" vs print "test\ttest"  \T just
get printed?


Because "\T" has no special meaning, so is just a two character sequence
like any other in the literal.  'print' just prints the string.

print repr("test\Ttest"), repr("test\ttest")

might be illuminating?


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


Re: Relative Imports, why the hell is it so hard?

2009-03-24 Thread Istvan Albert
On Mar 24, 3:16 pm, "Gabriel Genellina" 
wrote:

> Did you know, once a module is imported by the first time

yeah yeah, could we not get sidetracked with details that are not
relevant? what it obviously means is to import it in all of your
modules that need to access to relative paths

> I don't understand, how is this supposed to help relative imports?

That's only because you have not had to deal with the problem that it
solves.
If you need to have a module that can do both:

1. access relative paths (even other packages)
2. be executable on its own (for example a modules may execute its own
doctests when running them directly)

this is the only way to achieve it.

> I'd recommend the oposite - use relative (intra-package) imports when 
> possible.

Does it not bother you that a module that uses relative imports cannot
be run on its own anymore? To me that is irritating because it forces
me to change a habit (running the doctests when the module is
executed) that I consider a very good practice. It is extremely handy
to be writing a module, press a key and the module is executed and I
can see the tests results. The relative import takes away this from
me. Like I said, it is irritating.

> Bindly inserting directories into sys.path can easily confuse the import 
> systemn

confuse the import system? what the heck does that mean? You either
have a path in the sys.path or not. FWIW it is far cleaner than doing
a relative import that does not work correctly.

Istvan














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


Re: Python 3 consistency proposal

2009-03-24 Thread gert
On Mar 25, 1:23 am, Steven D'Aprano
 wrote:
> On Tue, 24 Mar 2009 16:45:26 -0700, gert wrote:
> > Rename all built in classes with a capital letter example Str() Int()
> > Object()
>
> > Make () optional for a function definition class Test:
> >     pass
>
> > def test:
> >     pass
>
> > Any chance Guido would approve this :-)
>
> Unless you're volunteering to produce a patch, the chances are zero.
>
> If you *are* willing to do the work, the chances would still be pretty
> slim. Guido has just rejected a patch adding PEP 8 compliant aliases for
> types like datetime, so I think replacing built-ins have all-but zero
> chance. But if you want to pursue it, the right place is the python-ideas
> mailing list. Go for it ... but be prepared to justify the change, and
> not just "for consistency". As Guido has quoted before, "A foolish
> consistency is the hobgoblin of little minds".

Its only foolish because it breaks everything, but it would not be
foolish on a syntax level.
Not that I can't live without, but I am just wondering why they did
not do this in the first place?

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


Re: blocked on futex

2009-03-24 Thread msoulier
On Mar 20, 10:22 am, a...@pythoncraft.com (Aahz) wrote:
> How many processes do you have running?  What kind of guarantee do you

One process. No threads, no forking.

> have that there's only one process if you think there should be only one?
> What's on the other side of the socket?  If there's no consistent place,

A preforking daemon.

> is it always the same object type involved or function/method call?  I'm
> not at all familiar with Django, but it might be using threads
> internally.

Django doesn't use threads and neither do I. It doesn't deadlock in
any consistent location that I can find.

> Have you tried dumping core and using gdb to find out more about the
> process state?

Yeah, just did. I need the debuginfo for proper symbols, but here's an
initial backtrace.

#0  0x0084d7a2 in _dl_sysinfo_int80 () from /lib/ld-linux.so.2
#1  0x009dbc1f in sem_w...@glibc_2.0 () from /lib/tls/libpthread.so.0
#2  0x00a7ce1e in PyThread_acquire_lock () from /usr/lib/
libpython2.3.so.1.0
#3  0x00a7ff07 in _PyObject_GC_Del () from /usr/lib/libpython2.3.so.
1.0
#4  0x00a29991 in PyCFunction_Call () from /usr/lib/libpython2.3.so.
1.0
#5  0x00a5c51c in _PyEval_SliceIndex () from /usr/lib/libpython2.3.so.
1.0
#6  0x00a5d98b in _PyEval_SliceIndex () from /usr/lib/libpython2.3.so.
1.0
#7  0x00a5d98b in _PyEval_SliceIndex () from /usr/lib/libpython2.3.so.
1.0
#8  0x00a5d98b in _PyEval_SliceIndex () from /usr/lib/libpython2.3.so.
1.0
#9  0x00a5d98b in _PyEval_SliceIndex () from /usr/lib/libpython2.3.so.
1.0
#10 0x00a5e0a6 in PyEval_EvalCodeEx () from /usr/lib/libpython2.3.so.
1.0
#11 0x00a19e8e in PyFunction_SetClosure () from /usr/lib/
libpython2.3.so.1.0
#12 0x00a06637 in PyObject_Call () from /usr/lib/libpython2.3.so.1.0
#13 0x00a0ddc8 in PyMethod_New () from /usr/lib/libpython2.3.so.1.0
#14 0x00a06637 in PyObject_Call () from /usr/lib/libpython2.3.so.1.0
#15 0x00a581b0 in PyEval_CallObjectWithKeywords ()
   from /usr/lib/libpython2.3.so.1.0
#16 0x00a50dda in _PyUnicodeUCS4_IsAlpha () from /usr/lib/
libpython2.3.so.1.0
#17 0x00a29991 in PyCFunction_Call () from /usr/lib/libpython2.3.so.
1.0
#18 0x00a5c51c in _PyEval_SliceIndex () from /usr/lib/libpython2.3.so.
1.0
#19 0x00a5e0a6 in PyEval_EvalCodeEx () from /usr/lib/libpython2.3.so.
1.0
#20 0x00a5cd99 in _PyEval_SliceIndex () from /usr/lib/libpython2.3.so.
1.0
#21 0x00a5e0a6 in PyEval_EvalCodeEx () from /usr/lib/libpython2.3.so.
1.0
#22 0x00a19e8e in PyFunction_SetClosure () from /usr/lib/
libpython2.3.so.1.0
#23 0x00a06637 in PyObject_Call () from /usr/lib/libpython2.3.so.1.0
#24 0x00a581b0 in PyEval_CallObjectWithKeywords ()
   from /usr/lib/libpython2.3.so.1.0
#25 0x00a8147f in PyErr_CheckSignals () from /usr/lib/libpython2.3.so.
1.0
#26 0x00a81548 in PyErr_CheckSignals () from /usr/lib/libpython2.3.so.
1.0
#27 0x00a57fa1 in Py_MakePendingCalls () from /usr/lib/libpython2.3.so.
1.0
#28 0x00a58f4d in _PyEval_SliceIndex () from /usr/lib/libpython2.3.so.
1.0
#29 0x00a5d98b in _PyEval_SliceIndex () from /usr/lib/libpython2.3.so.
1.0
#30 0x00a5d98b in _PyEval_SliceIndex () from /usr/lib/libpython2.3.so.
1.0
#31 0x00a5d98b in _PyEval_SliceIndex () from /usr/lib/libpython2.3.so.
1.0
#32 0x00a5d98b in _PyEval_SliceIndex () from /usr/lib/libpython2.3.so.
1.0
#33 0x00a5e0a6 in PyEval_EvalCodeEx () from /usr/lib/libpython2.3.so.
1.0
#34 0x00a19e8e in PyFunction_SetClosure () from /usr/lib/
libpython2.3.so.1.0
#35 0x00a06637 in PyObject_Call () from /usr/lib/libpython2.3.so.1.0
#36 0x00a0ddc8 in PyMethod_New () from /usr/lib/libpython2.3.so.1.0
#37 0x00a06637 in PyObject_Call () from /usr/lib/libpython2.3.so.1.0
#38 0x00a581b0 in PyEval_CallObjectWithKeywords ()
   from /usr/lib/libpython2.3.so.1.0
#39 0x00a50dda in _PyUnicodeUCS4_IsAlpha () from /usr/lib/
libpython2.3.so.1.0
#40 0x00a29991 in PyCFunction_Call () from /usr/lib/libpython2.3.so.
1.0
#41 0x00a5c51c in _PyEval_SliceIndex () from /usr/lib/libpython2.3.so.
1.0
#42 0x00a5e0a6 in PyEval_EvalCodeEx () from /usr/lib/libpython2.3.so.
1.0
#43 0x00a5cd99 in _PyEval_SliceIndex () from /usr/lib/libpython2.3.so.
1.0
#44 0x00a5e0a6 in PyEval_EvalCodeEx () from /usr/lib/libpython2.3.so.
1.0
#45 0x00a19e8e in PyFunction_SetClosure () from /usr/lib/
libpython2.3.so.1.0
#46 0x00a06637 in PyObject_Call () from /usr/lib/libpython2.3.so.1.0
#47 0x00a5b998 in _PyEval_SliceIndex () from /usr/lib/libpython2.3.so.
1.0
#48 0x00a5e0a6 in PyEval_EvalCodeEx () from /usr/lib/libpython2.3.so.
1.0
#49 0x00a5cd99 in _PyEval_SliceIndex () from /usr/lib/libpython2.3.so.
1.0
#50 0x00a5d98b in _PyEval_SliceIndex () from /usr/lib/libpython2.3.so.
1.0
#51 0x00a5d98b in _PyEval_SliceIndex () from /usr/lib/libpython2.3.so.
1.0
#52 0x00a5d98b in _PyEval_SliceIndex () from /usr/lib/libpython2.3.so.
1.0
#53 0x00a5d98b in _PyEval_SliceIndex () from /usr/lib/libpython2.3.so.
1.0
#54 0x00a5e0a6 in PyEval_EvalCodeEx () from /usr/lib/libpython2.3.so.
1.0
#55 0x00a5e36d in PyEval_EvalCode () from /usr/lib/libpython2.3.so.1.0
#56 0x00a77827 in PyErr_Display () f

Re: Python 3 consistency proposal

2009-03-24 Thread Ben Finney
Steven D'Aprano  writes:

> If you *are* willing to do the work, the chances would still be
> pretty slim. Guido has just rejected a patch adding PEP 8 compliant
> aliases for types like datetime […] As Guido has quoted before, "A
> foolish consistency is the hobgoblin of little minds".

Indeed, that quote is prominent in PEP 8 itself.


gert  writes:

> Not that I can't live without, but I am just wondering why they did
> not [name built-in types consistently with other classes] in the
> first place?

Because, in the first place, built-in types were disjoint from
user-defined classes. The latter could not derive from the former, and
it was helpful to know the difference.

The reason no longer exists (since built-in types and user types are
now in a unified hierarchy), but the difference is well entrenched now
and I personally see little benefit in changing it.

-- 
 \“The number of UNIX installations has grown to 10, with more |
  `\ expected.” —Unix Programmer's Manual, 2nd Ed., 1972-06-12 |
_o__)  |
Ben Finney

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


Re: Python 3 consistency proposal

2009-03-24 Thread Terry Reedy

gert wrote:

On Mar 25, 1:23 am, Steven D'Aprano
 wrote:

On Tue, 24 Mar 2009 16:45:26 -0700, gert wrote:

Rename all built in classes with a capital letter example Str() Int()
Object()
Make () optional for a function definition class Test:
pass
def test:
pass
Any chance Guido would approve this :-)

Unless you're volunteering to produce a patch, the chances are zero.


No.  He just made clear today that he values stability over 
non-functional consistency changes -- especially now that 3.0 is out.



If you *are* willing to do the work, the chances would still be pretty
slim. Guido has just rejected a patch adding PEP 8 compliant aliases for
types like datetime, so I think replacing built-ins have all-but zero
chance. But if you want to pursue it, the right place is the python-ideas
mailing list. Go for it ... but be prepared to justify the change, and
not just "for consistency". As Guido has quoted before, "A foolish
consistency is the hobgoblin of little minds".


Its only foolish because it breaks everything, but it would not be
foolish on a syntax level.
Not that I can't live without, but I am just wondering why they did
not do this in the first place?


As I remember, int, str, etc, once *were* functions (or at best types) 
rather than callable class objects.  Before 2.2, built-in types and 
user-defined classes were separate categories of entities.


tjr

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


Re: Best GUI toolkit with Table support

2009-03-24 Thread John Fabiani
deech wrote:

> Hi all,
> I am making a cross-platform frontend to a sqlite3 database. Which
> python GUI toolkit has the best table support? Tkinter doesn't seem to
> support them (without additional package installation).
> 
> The issue is that the application must run off a flash drive with a
> vanilla Python install on both Windows and Linux. Or if there is a way
> to store additional packages on the flash drive and call them in some
> portable way, this would work too.
> 
> -deech
Take a look at Dabo (www.dabodev.com) which was developed to deal the with
very thing you are asking for data.

BTW running from a flash drive these days does not present a big deal - 16
gb is plenty of room for an OS and your app.  And there is even bigger 32GB
flash drives.  I'll bet that by the end of the year there will 64GB flash
drives.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Relative Imports, why the hell is it so hard?

2009-03-24 Thread Maxim Khitrov
On Tue, Mar 24, 2009 at 8:57 PM, Istvan Albert  wrote:
> Does it not bother you that a module that uses relative imports cannot
> be run on its own anymore?

$ python --help

-m mod : run library module as a script (terminates option list)

$ python -m some.module.name

Works perfectly fine with relative imports.

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


Why am I getting "[10263 refs]"?

2009-03-24 Thread Russ P.
I am running 2.5.2 on Red Hat 5. I am getting many printouts of
reference counts, such as

[10263 refs]

I do not recall ever seeing this until recently. Why am I getting
this? Thanks.
--
http://mail.python.org/mailman/listinfo/python-list


  1   2   >