Re: Pythonic way to determine if one char of many in a string

2009-02-18 Thread Steven D'Aprano
On Wed, 18 Feb 2009 07:08:04 +1100, Jervis Whitley wrote:


>> This moves the for-loop out of slow Python into fast C and should be
>> much, much faster for very large input.
>>
>>
> _Should_ be faster.

Yes, Python's timing results are often unintuitive.


> Here is my test on an XP system Python 2.5.4. I had similar results on
> python 2.7 trunk.
...
> **no vowels**
> any: [0.36063678618957751, 0.36116506191682773, 0.36212355395824081]
> for: [0.24044885376801672, 0.2417684017413404, 0.24084797257163482]

I get similar results.

...
> **BIG word vowel 'U' final char**
> any: [8.0007259193539895, 7.9797344140269644, 7.8901742633514012] for:
> [7.6664422372764101, 7.6784683633957584, 7.6683055766498001]

Well, I did say "for very large input". 1 chars isn't "very large" -- 
that's only 9K. Try this instead:

>>> BIGWORD = 'g' * 50 + 'U'  # less than 500K of text
>>>
>>> Timer("for_test(BIGWORD)", setup).repeat(number=1000)
[4.7292280197143555, 4.633030891418457, 4.6327309608459473]
>>> Timer("any_test(BIGWORD)", setup).repeat(number=1000)
[4.7717428207397461, 4.6366970539093018, 4.6367099285125732]

The difference is not significant. What about bigger?


>>> BIGWORD = 'g' * 500 + 'U'  # less than 5MB 
>>>
>>> Timer("for_test(BIGWORD)", setup).repeat(number=100)
[4.8875839710235596, 4.7698030471801758, 4.769787073135376]
>>> Timer("any_test(BIGWORD)", setup).repeat(number=100)
[4.8555209636688232, 4.8139419555664062, 4.7710208892822266]

It seems to me that I was mistaken -- for large enough input, the running 
time of each version converges to approximately the same speed.

What happens when you have hundreds of megabytes, I don't know.


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


Re: Found a very nice, small, cross-platform GUI toolkit for Python.

2009-02-18 Thread Tim Roberts
laplacia...@gmail.com wrote:
>
>> For applications installing the full wxWidgets or Qt toolkits would be
>> less disk space and dependcies than OceanGUI
>
>What? Qt and wX are *huge* compared to OcempGUI.

Well, not compared to OcempGUI + SDL + PyGame.  Note that I'm not trying to
run down the product at all, but if you're going to make comparisons like
this, you really need to be fair about it.

>> and performance would probably be higher.
>
>Probably, but wX and Qt are written in C++. OcempGUI is pure Python,
>which would make it easier for the Python community to help extend,
>optimize, and maintain.

Again, that's hardly fair.  OcempGUI is only pure Python because it
requires the C libraries SDL and PyGame.  wxPython is basically pure
Python, also, if you don't count the C++ wxWidgets library underneath it.

As you say, if you are already using SDL and PyGame, this sounds like a
great solution.  But for someone starting from scratch, it's not yet clear
to me that OcempGUI substantially better than wx.
-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.
--
http://mail.python.org/mailman/listinfo/python-list


urllib confusion

2009-02-18 Thread Tim H
When I attempt to open 2 different pages on the same site I get 2 copies 
of the first page. ??


ie

links = [ 'http://site.org/foo/1/bar',
  'http://site.org/foo/2/bar' ]

for url in links:
print "url:", url
f = urlopen(url, params)
print "Actual url:", f.geturl()
print f.read()
f.close()


results in:

url: http://site.org/foo/1/bar
Actual url: http://site.org/foo/1/bar
page 1 contents
url: http://site.org/foo/2/bar
Actual url: http://site.org/foo/1/bar
page 1 contents

f.getinfo() shows two different session ID's

Any thoughts?

Thanks,
Tim

WinXP-x64
python 2.6.1 x64
--
http://mail.python.org/mailman/listinfo/python-list


2 very interesting python projects - Financial industry

2009-02-18 Thread David Russell
Dear Python experts,

 

First of all sorry for the unsolicited email,

 

I have attached two very interesting long term Python projects in the
Frankfurt area, Financial industry.

 

I am working exclusively with the client on both requirements,
interviews and contracts can be arranged very quickly.

 

You will be involved in a project to develop the next generation of
financial trading systems, this will be the biggest, fastest trading
system of its kind in the world and will be used on a global scale.

 

Financial experience is not a must, they are looking more for technical
skills here.

 

If the projects look interesting to you please feel free to contact me
on the contact details below.

 

Thank you for your help,

 

Best Regards

 

David

 

Large Financial Institution - Frankfurt

 

Senior Python C/C++ Developer  (f/m)

 

Tasks/Responsibilities

Software developer for a complex electronic trading system.

The software developer will work in the implementation team of the
trading

system; tasks include:

- Requirements Analysis

- Development of a Scripting framework based on Python

- Specification

- Implementation

Target platform will be Linux.

 

Qualifications/Required Skills (Mandatory)

Rock Solid Python and C/C++ knowledge

Integration of Python with C/C++ libraries

Automated Testing

Good overview and knowledge of open source software

Experience of software development in large projects

Good communications skills

Ability to work in project teams

A good command of English is a must.

 

Additional Domain & Business Skills

Knowledge of derivatives trading an advantage, in particular U.S.
options.

 

Additional Information:

Frankfurt am Main, Germany

Start ASAP for a minimum of 6 months

Rate - Negotiable

 

This is an urgent requirement please contact me or send me your cv as
soon as possible.

 

Contact: David Russell - Account manager

email: david.russ...@fdmgroup.com

Tel: +49 (0) 69 756 0050

Web: www.fdmgroup.com

 

 


///

 

Large Financial Institution - Frankfurt am Main

 

Performance / High Availability Test Automation Engineer (f/m)

 

Tasks/Responsibilities

Developer of automated test procedures for a high-performance electronic
trading system.

The engineer will work in the Performance and Technical Test team of the
project; tasks include:

- Requirements Analysis

- Development of distributed transaction feed procedures, mostly
in Python

- Implementation of automated result analysis

- Design and implementation of test procedures for
failover/recovery scenarios in a multi-tier environment

- Supervision of regular runs of the automated performance test
suite.

Target platform will be Linux.

 

Qualifications/Required Skills

Python scripting

Deep (>3 years) knowledge of Linux, with a focus in the areas

  - Performance monitoring and tuning

  - Messaging architectures

Performance testing experience, for latency and throughput, incl. data
aggregation and reporting Good communications skills Experience of
software development in large projects Good overview and knowledge of
open source software Ability to work in an international project team.

 

A good command of English is a must.

 

Additional Domain & Business Skills

Knowledge of statistical data analysis methods would be an advantage.

Experience in mechanisms of interfacing C/C++ and Python would also be
advantageous.

Frankfurt am Main, Germany

Start ASAP to 31.12.09 with good extension prospects for 2010

Rate - Negotiable

 

This is an urgent requirement please contact me or send me your cv as
soon as possible.

 

Contact: David Russell - Account manager

email: david.russ...@fdmgroup.com

Tel: +49 (0) 69 756 0050

Web: www.fdmgroup.com

 

 

David Russell

Account Manager

 

FDM Group

 


 

 

Beethoven Strasse 4,

60325 Frankfurt am Main

Germany

david.russ...@fdmgroup.com  

 

Tel:  + 49 (0) 69 756 0050

Cell: + 49 (0) 173 3592288

Fax: + 49 (0) 69 756 00555

 

www.fdmgroup.com    www.fdmacademy.com
  

BRIGHTON, LONDON, MANCHESTER, LUXEMBOURG, FRANKFURT, ZURICH & NEW YORK

 


This message is from FDM Group Plc, and may contain information that is 
confidential or privileged.  If you are not the intended recipient, please 
delete the message and any attachments and notify the sender.  This email is 
not intended to create legally binding commitments on behalf of FDM Group Plc, 
nor do its contents reflect the corporate views or policies of FDM.  Any 
unauthorised disclosure, use or dissemination, either whole or partial, is 
prohibited. FDM Group Plc is a private limited company registered in England 
(Reg. No. 2542980).



This e-mail has been scanned for all viruses by Star Inter

Directory

2009-02-18 Thread gtillmon
Hello.  I am new to the Python language.
I would like to know how to display and store the path of each mondule
that is called.
Similar to the old READY TRACE in COBOL of long ago.

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


Re: Is there something easier than ORM?

2009-02-18 Thread Michele Simionato
On Feb 17, 5:35 pm, Philip Semanchuk  wrote:
>
> I don't intend this as a criticism of SqlAlchemy. On the contrary I am  
> impressed by what it does. But I often see people promoting ORM as the  
> solution to all database access problems, and I certainly don't feel  
> like it is.

I am also not a big fan of ORM, especially in situations where you
have
performance issues and you are using database specific features. In
such situations
you don't care about portability, but you care about having your SQL
explicit,
so that you can run it directly under the profiler.
--
http://mail.python.org/mailman/listinfo/python-list


Re: flexible find and replace ?

2009-02-18 Thread OdarR
Thanks to everybody.
I need to test your propositions now :)

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


Re: urllib confusion

2009-02-18 Thread Steven D'Aprano
On Wed, 18 Feb 2009 01:17:40 -0700, Tim H wrote:

> When I attempt to open 2 different pages on the same site I get 2 copies
> of the first page. ??
...
> Any thoughts?

What does your browser do?

What does your browser do if you turn off cookies, re-directions and/or 
referers?



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


Re: numpy.memmap advice?

2009-02-18 Thread Carl Banks
On Feb 17, 3:08 pm, Lionel  wrote:
> Hello all,
>
> On a previous thread (http://groups.google.com/group/comp.lang.python/
> browse_thread/thread/64da35b811e8f69d/67fa3185798ddd12?
> hl=en&lnk=gst&q=keene#67fa3185798ddd12) I was asking about reading in
> binary data. Briefly, my data consists of complex numbers, 32-bit
> floats for real and imaginary parts. The data is stored as 4 bytes
> Real1, 4 bytes Imaginary1, 4 bytes Real2, 4 bytes Imaginary2, etc. in
> row-major format. I needed to read the data in as two separate numpy
> arrays, one for real values and one for imaginary values.
>
> There were several very helpful performance tips offered, and one in
> particular I've started looking into. The author suggested a
> "numpy.memmap" object may be beneficial. It was suggested I use it as
> follows:
>
> descriptor = dtype([("r", " data = memmap(filename, dtype=descriptor, mode='r').view(recarray)
> print "First 100 real values:", data.r[:100]
>
> I have two questions:
> 1) What is "recarray"?

Let's look:

[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> numpy.recarray

>>> help(numpy.recarray)

Help on class recarray in module numpy.core.records:

class recarray(numpy.ndarray)
 |  recarray(shape, dtype=None, buf=None, **kwds)
 |
 |  Subclass of ndarray that allows field access using attribute
lookup.
 |
 |  Parameters
 |  --
 |  shape : tuple
 |  shape of record array
 |  dtype : data-type or None
 |  The desired data-type.  If this is None, then the data-type is
determine
 |  by the *formats*, *names*, *titles*, *aligned*, and
*byteorder* keywords
 |  buf : [buffer] or None
 |  If this is None, then a new array is created of the given
shape and data
 |  If this is an object exposing the buffer interface, then the
array will
 |  use the memory from an existing buffer.  In this case, the
*offset* and
 |  *strides* keywords can also be used.
...


So there you have it.  It's a subclass of ndarray that allows field
access using attribute lookup.  (IOW, you're creating a view of the
memmap'ed data of type recarray, which is the type numpy uses to
access structures by name.  You need to create the view because
regular numpy arrays, which numpy.memmap creates, can't access fields
by attribute.)

help() is a nice thing to use, and numpy is one of the better
libraries when it comes to docstrings, so learn to use it.


> 2) The documentation for numpy.memmap claims that it is meant to be
> used in situations where it is beneficial to load only segments of a
> file into memory, not the whole thing. This is definately something
> I'd like to be able to do as my files are frequently >1Gb. I don't
> really see in the diocumentation how portions are loaded, however.
> They seem to create small arrays and then assign the entire array
> (i.e. file) to the memmap object. Let's assume I have a binary data
> file of complex numbers in the format described above, and let's
> assume that the size of the complex data array (that is, the entire
> file) is 100x100 (rows x columns). Could someone please post a few
> lines showing how to load the top-left 50 x 50 quadrant, and the lower-
> right 50 x 50 quadrant into memmap objects? Thank you very much in
> advance!


You would memmap the whole region in question (in this case the whole
file), then take a slice.  Actually you could get away with memmapping
just the last 50 rows (bottom half).  The offset into the file would
be 50*100*8, so:

data = memmap(filename, dtype=descriptor, mode='r',offset=
(50*100*8)).view(recarray)
reshaped_data = reshape(data,(50,100))
intersting_data = reshaped_data[:,50:100]


A word of caution: Every instance of numpy.memmap creates its own mmap
of the whole file (even if it only creates an array from part of the
file).  The implications of this are A) you can't use numpy.memmap's
offset parameter to get around file size limitations, and B) you
shouldn't create many numpy.memmaps of the same file.  To work around
B, you should create a single memmap, and dole out views and slices.


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


Building python with sqlite3

2009-02-18 Thread Justin Li

I'm building and installing Ptyhon 2.6.1 on Linux. After configure,
make, make install, to import sqlite3 leads to ImportError. It looks
like I have to build Python with sqlite. I have sqlite3 installed on
my system. How should I build Python with it? I did not find any
options relating with sqlite3 of configure and Makefile.

Thanks in Advance!
Justin
--
http://mail.python.org/mailman/listinfo/python-list


Calling a script requiring user input from another script

2009-02-18 Thread mzagu...@gmail.com
I'm kind of new to this so bear with me.

I have a script made that requires user input (lets call it script A)
while it's running.  However, I would like to create another script
(script B) that can batch process (i.e. run script A over and over
with different user inputs based on script B).  Is this possible?  and
how so?  Thanks in advance.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3D CAD -- need collaborators, or just brave souls :)

2009-02-18 Thread r
Hello Josh,
Blender is a lost cause. It is a powerful app but the UI is horrible.
Even the Blender folks admit only a complete rewrite could solve the
major flaws that plague the design. So maybe i could salvage some code
but for what i have in mind, Blender will look like a piece of
software from the middle ages. And i am absolutly only looking to do
this in 3D, 2D is boring.

So, yes, i have looked at both the applications you offer.

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


PyYaml in standard library?

2009-02-18 Thread Brendan Miller
I'm just curious whether PyYaml is likely to end up in the standard
library at some point?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Building python with sqlite3

2009-02-18 Thread Christian Heimes
Justin Li schrieb:
> I'm building and installing Ptyhon 2.6.1 on Linux. After configure,
> make, make install, to import sqlite3 leads to ImportError. It looks
> like I have to build Python with sqlite. I have sqlite3 installed on
> my system. How should I build Python with it? I did not find any
> options relating with sqlite3 of configure and Makefile.

Do you have the development files installed as well? Run "make" again
and look at the list of missing modules.

Christian

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


Re: Python 3D CAD -- need collaborators, or just brave souls :)

2009-02-18 Thread r
Yes i want linux, windows, and mac support. I think you are good for a
few years though :). Getting something up and working is the easy
part. Adding all the features that are required to compete with
something the likes of SolidWorks or ACAD  takes time.

One way or another i am going to build this, whether or not it takes
off and gets to a professional level -- only time will tell. I know
one thing for sure the need is there, the product is not.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Calling a script requiring user input from another script

2009-02-18 Thread Chris Rebert
On Wed, Feb 18, 2009 at 1:00 AM, mzagu...@gmail.com  wrote:
> I'm kind of new to this so bear with me.
>
> I have a script made that requires user input (lets call it script A)
> while it's running.  However, I would like to create another script
> (script B) that can batch process (i.e. run script A over and over
> with different user inputs based on script B).  Is this possible?  and
> how so?  Thanks in advance.

Define a function in A that lets its functionality be used
programmatically. Then use the `if __name__ == "__main__"` trick to
have A take input from the user and call the function you just defined
 with the user input if it's run as a script.

In B, import A's function and call it repeatedly on the inputs.

Example (assume addition is A's fancy functionality):

#A.py BEFORE:
while True:
input_ = raw_input()
if input_ == "exit":
break
x = int(input_)
y = int(raw_input())
print x + y

#A.py AFTER:
#functionality refactored into a function
def add(x, y):
return x + y

if __name__ == "__main__":
while True:
if input_ == "exit":
break
x = int(input_)
y = int(raw_input())
print add(x, y)#use the function

#B.py
from A import add

for i,j in some_input_pairs:
add(i, j)#use the function


Cheers,
Chris

-- 
Follow the path of the Iguana...
http://rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python-list Digest, Vol 65, Issue 365

2009-02-18 Thread M Kumar
I think the given statement below will give you what you r looking
.__file__print

On Wed, Feb 18, 2009 at 2:43 PM,  wrote:

> Send Python-list mailing list submissions to
>python-list@python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>http://mail.python.org/mailman/listinfo/python-list
> or, via email, send a message with subject or body 'help' to
>python-list-requ...@python.org
>
> You can reach the person managing the list at
>python-list-ow...@python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Python-list digest..."
>
> Today's Topics:
>
>   1. Directory (gtillmon)
>   2. Re: Is there something easier than ORM? (Michele Simionato)
>   3. Re: flexible find and replace ? (OdarR)
>   4. Re: urllib confusion (Steven D'Aprano)
>   5. Re: numpy.memmap advice? (Carl Banks)
>   6. Building python with sqlite3 (Justin Li)
>   7. Calling a script requiring user input from another script
>  (mzagu...@gmail.com)
>   8. Re: Python 3D CAD -- need collaborators, or just brave souls
>  :) (r)
>   9. PyYaml in standard library? (Brendan Miller)
>  10. Re: Building python with sqlite3 (Christian Heimes)
>
>
> -- Forwarded message --
> From: gtillmon 
> To:
> Date: Tue, 17 Feb 2009 17:18:11 -0800 (PST)
> Subject: Directory
> Hello.  I am new to the Python language.
> I would like to know how to display and store the path of each mondule
> that is called.
> Similar to the old READY TRACE in COBOL of long ago.
>
> Thanks,
> George
>
>
>
> -- Forwarded message --
> From: Michele Simionato 
> To:
> Date: Tue, 17 Feb 2009 08:46:02 -0800 (PST)
> Subject: Re: Is there something easier than ORM?
> On Feb 17, 5:35 pm, Philip Semanchuk  wrote:
> >
> > I don't intend this as a criticism of SqlAlchemy. On the contrary I am
> > impressed by what it does. But I often see people promoting ORM as the
> > solution to all database access problems, and I certainly don't feel
> > like it is.
>
> I am also not a big fan of ORM, especially in situations where you
> have
> performance issues and you are using database specific features. In
> such situations
> you don't care about portability, but you care about having your SQL
> explicit,
> so that you can run it directly under the profiler.
>
>
>
> -- Forwarded message --
> From: OdarR 
> To:
> Date: Tue, 17 Feb 2009 11:29:19 -0800 (PST)
> Subject: Re: flexible find and replace ?
> Thanks to everybody.
> I need to test your propositions now :)
>
> Olivier
>
>
>
> -- Forwarded message --
> From: Steven D'Aprano 
> To: python-list@python.org
> Date: 18 Feb 2009 08:33:08 GMT
> Subject: Re: urllib confusion
> On Wed, 18 Feb 2009 01:17:40 -0700, Tim H wrote:
>
> > When I attempt to open 2 different pages on the same site I get 2 copies
> > of the first page. ??
> ...
> > Any thoughts?
>
> What does your browser do?
>
> What does your browser do if you turn off cookies, re-directions and/or
> referers?
>
>
>
> --
> Steven
>
>
>
> -- Forwarded message --
> From: Carl Banks 
> To: python-list@python.org
> Date: Wed, 18 Feb 2009 00:56:10 -0800 (PST)
> Subject: Re: numpy.memmap advice?
> On Feb 17, 3:08 pm, Lionel  wrote:
> > Hello all,
> >
> > On a previous thread (http://groups.google.com/group/comp.lang.python/
> > browse_thread/thread/64da35b811e8f69d/67fa3185798ddd12?
> > hl=en&lnk=gst&q=keene#67fa3185798ddd12) I was asking about reading in
> > binary data. Briefly, my data consists of complex numbers, 32-bit
> > floats for real and imaginary parts. The data is stored as 4 bytes
> > Real1, 4 bytes Imaginary1, 4 bytes Real2, 4 bytes Imaginary2, etc. in
> > row-major format. I needed to read the data in as two separate numpy
> > arrays, one for real values and one for imaginary values.
> >
> > There were several very helpful performance tips offered, and one in
> > particular I've started looking into. The author suggested a
> > "numpy.memmap" object may be beneficial. It was suggested I use it as
> > follows:
> >
> > descriptor = dtype([("r", " > data = memmap(filename, dtype=descriptor, mode='r').view(recarray)
> > print "First 100 real values:", data.r[:100]
> >
> > I have two questions:
> > 1) What is "recarray"?
>
> Let's look:
>
> [GCC 4.3.2] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import numpy
> >>> numpy.recarray
> 
> >>> help(numpy.recarray)
>
> Help on class recarray in module numpy.core.records:
>
> class recarray(numpy.ndarray)
>  |  recarray(shape, dtype=None, buf=None, **kwds)
>  |
>  |  Subclass of ndarray that allows field access using attribute
> lookup.
>  |
>  |  Parameters
>  |  --
>  |  shape : tuple
>  |  shape of record array
>  |  dtype : data-type or None
>  |  The desired data-type.  If this is None, then the data-type is
> determine
>  |  by the *formats*, *names*, *titles*, *aligned*, and
> *byteorder* keywor

Re: PyYaml in standard library?

2009-02-18 Thread Chris Rebert
On Wed, Feb 18, 2009 at 1:11 AM, Brendan Miller  wrote:
> I'm just curious whether PyYaml is likely to end up in the standard
> library at some point?

I don't personally have a direct answer to your question, but I can
point out that JSON and YAML are mostly compatible (JSON is almost a
perfect YAML subset) and the `json` module is already in the Python
std lib.

Cheers,
Chris

-- 
Follow the path of the Iguana...
http://rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: "Maximum recursion depth exceeded"...why?

2009-02-18 Thread rdmurray
alex23  wrote:
> On Feb 18, 11:36=A0am, Paul Rubin  wrote:
> > Thomas Allen  writes:
> > > attempting. Basically, I'm transforming a live site to a local one and
> >
> > Something wrong with wget -R ?
> 
> Did you mean wget -r ?
> 
> That will just grab the entire site, though. I'm guessing that Thomas'
> function absToRel will eventually replace the print with something
> that changes links accordingly so the local version is traversable.

Yeah, but wget -r -k will do that bit of it, too.

--RDM

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


Re: "Maximum recursion depth exceeded"...why?

2009-02-18 Thread alex23
On Feb 18, 7:34 pm, rdmur...@bitdance.com wrote:
> Yeah, but wget -r -k will do that bit of it, too.

Wow, nice, I don't know why I never noticed that. Cheers!

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


Re: Is there something easier than ORM?

2009-02-18 Thread M.-A. Lemburg
On 2009-02-17 13:27, 一首诗 wrote:
> Hi all,
> 
> Recently I am studying some python ORM libraries, such as sqlalchemy.
> 
> These are very powerful technologies to handle database.  But I think
> my project are not complicated to enough to benefit from a complete
> ORM system.
> 
> What I really want, is some easy ways to load data from database, and
> change rows of data to list of named tuple, then I could send these
> data to my client application.
> 
> I don't think I want these subtle behavior such as lazy load, auto
> update, ect. in ORM.
> 
> So is there some libraries like that?

Python has a DB-API standard for direct access to databases using
a very simple cursor-based approach:

http://www.python.org/dev/peps/pep-0249/

All the DB-API compatible modules provide such an interface:

http://wiki.python.org/moin/DatabaseInterfaces

> Or is there some tools that could generate code from database scheme
> as I want?

I am not aware of an automated tool for generating SQL queries
in form of Python functions, but it is certainly possible to write
one by tapping into the system tables of the database of your
choice.

Our database tools mxODBC and mxODBC Connect come with a set of
catalog methods that make such introspection very easy across
databases and platforms:

http://www.egenix.com/products/python/mxODBC/
http://www.egenix.com/products/python/mxODBCConnect/

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Feb 18 2009)
>>> Python/Zope Consulting and Support ...http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/


::: Try our new mxODBC.Connect Python Database Interface for free ! 


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
   Registered at Amtsgericht Duesseldorf: HRB 46611
   http://www.egenix.com/company/contact/
--
http://mail.python.org/mailman/listinfo/python-list


os.popen encoding!

2009-02-18 Thread SMALLp
Hy.
I'm playing with os.popen function.
a = os.popen("somecmd").read()

If one of the lines contains characters like "è", "æ"or any other it loks 
line this "velja\xe8a 2009" with that "\xe8". It prints fine if i go:

for i in a:
print i:

How to solve this and where exectly is problem with print or read! Windows 
XP, Python 2.5.4

Thanks! 


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


Re: memory recycling/garbage collecting problem

2009-02-18 Thread Tim Wintle
On Tue, 2009-02-17 at 17:04 +0100, Christian Heimes wrote:
> Tim Wintle wrote:
> > Basically malloc() and free() are computationally expensive, so Python
> > tries to call them as little as possible - but it's quite clever at
> > knowing what to do - e.g. if a list has already grown large then python
> > assumes it might grow large again and keeps hold of a percentage of the
> > memory.
> 
> You are almost right. Python's mutable container types like have a
> non-linear growth rate.
> 
> >From the file listobject.c
> 
> /*
> This over-allocates proportional to the list size, making room
> for additional growth.  The over-allocation is mild, but is
> enough to give linear-time amortized behavior over a long
> sequence of appends() in the presence of a poorly-performing
> system realloc().
> The growth pattern is:  0, 4, 8, 16, 25, 35, 46, 58, 72, 88, ...
> */
> 
> new_allocated = (newsize >> 3) + (newsize < 9 ? 3 : 6);

Sorry, I think I didn't phrase myself very well - I was trying to
explain that de-allocation of memory follows different scaling behaviour
to allocation - so a large list that's shrunk is likely to take more
memory than a small list that's grown i.e. the part just above your
quote:


/* 
Bypass realloc() when a previous overallocation is large enough
to accommodate the newsize.  If the newsize falls lower than half
the allocated size, then proceed with the realloc() to shrink the list.
*/
if (allocated >= newsize && newsize >= (allocated >> 1)) {
assert(self->ob_item != NULL || newsize == 0);
Py_SIZE(self) = newsize;
return 0;
}


it's all very clever stuff btw.


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


Re: os.popen encoding!

2009-02-18 Thread Gabriel Genellina

En Wed, 18 Feb 2009 10:09:24 -0200, SMALLp  escribió:


Hy.
I'm playing with os.popen function.
a = os.popen("somecmd").read()

If one of the lines contains characters like "è", "æ"or any other it loks
line this "velja\xe8a 2009" with that "\xe8". It prints fine if i go:

for i in a:
print i:



'\xe8' is a *single* byte (not four). It is the 'LATIN SMALL LETTER E WITH  
GRAVE' Unicode code point u'è' encoded in the Windows-1252 encoding (and  
latin-1, and others too). This is the usual Windows encoding (in "Western  
Europe" but seems to cover a much larger part of the world... most of  
America, if not all).


When you *look* at some string in the interpreter, you see its repr()  
(note the surrounding quotes). When you *print* some string, you get its  
contents:


py> s = "ma mère"
py> s
'ma m\x8are'
py> print s
ma mère
py> print repr(s)
'ma m\x8are'

How to solve this and where exectly is problem with print or read!  
Windows

XP, Python 2.5.4


There is *no* problem. You should read the Unicode howto:  


If you still think there is a problem, please provide more details.

--
Gabriel Genellina

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


Re: Searching Google?

2009-02-18 Thread Johannes Bauer
Curt Hash schrieb:

> You just need to change your User-Agent so that Google doesn't know a
> Python script is making the request:

Why would Google not send a response if the User-Agent header field is
not a recognized browser? I doubt that's what's happening and the OP
would just like the convenience of a search API instead of parsing the
web page (like other applications do). Ugly, but it works.

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


Crypto headaches.

2009-02-18 Thread SamG
Hi,

Using the python's Crypto.Cipher.Blowfish is create and encrypted file
in the CBC mode. Now... when try to decrypt it with OpenSSL i get an
error stating "bad magic number".

I tried
$ cat encr-file | openssl bf-cbc -d -pass pass:sam > org-file
or
$ openssl bf-cbc -d -pass pass:sam -in encr-file -out org-file

BTW, decryption using a python code works well. But i m of the
impression a file encry with one program should/can be decrypt with
another program (in my case openssl) using the same parameters.

Pls help.

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


Python/environment problem with char encoding/decoding

2009-02-18 Thread Gabriel Rossetti

Hello everyone,

I originally posted this on the Twisted mailing list, but now it seams 
to be  a more general python/environment problem. If I run the attached 
example in Eclipse, it works, if I run it from a terminal, it doesn't, I 
get :


$ python xml_parser_test.py
Traceback (most recent call last):
 File "xml_parser_test.py", line 30, in 
   res = rawXmlToElement("reçu")
 File "xml_parser_test.py", line 21, in __call__
   tmp.addRawXml(s)
 File "/usr/lib/python2.5/site-packages/twisted/words/xish/domish.py", 
line 538, in addRawXml

   self.children.append(SerializedXML(rawxmlstring))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 5: 
ordinal not in range(128)


Does anyone understand why it doesn't work outside of Eclipse? My OS is 
Linux (Ubuntu 8.04).


Thank you,
Gabriel
# -*- coding: utf-8 -*-
from twisted.web import sux
from twisted.words.xish import domish

class __RawXmlToElement(object):

def __call__(self, s):
self.result = None
def onStart(el):
self.result = el
def onEnd():
pass
def onElement(el):
self.result.addChild(el)

parser = domish.elementStream()
parser.DocumentStartEvent = onStart
parser.ElementEvent = onElement
parser.DocumentEndEvent = onEnd
tmp = domish.Element(("", "s"))
tmp.addRawXml(s)
parser.parse(tmp.toXml().encode("utf-8"))

return self.result.firstChildElement()

rawXmlToElement = __RawXmlToElement()

if(__name__ == "__main__"):

res = rawXmlToElement("reçu")
print "Result : %s" % res.toXml()
--
http://mail.python.org/mailman/listinfo/python-list


Re: os.popen encoding!

2009-02-18 Thread Hrvoje Niksic
"Gabriel Genellina"  writes:

>> I'm playing with os.popen function.
>> a = os.popen("somecmd").read()
>>
>> If one of the lines contains characters like "è", "æ"or any other it loks
>> line this "velja\xe8a 2009" with that "\xe8". It prints fine if i go:
>>
>> for i in a:
>> print i:
>
> '\xe8' is a *single* byte (not four). It is the 'LATIN SMALL LETTER E
> WITH  GRAVE' Unicode code point u'è' encoded in the Windows-1252
> encoding (and  latin-1, and others too).

Note that it is also 'LATIN SMALL LETTER C WITH CARON' (U+010D or
u'č'), encoded in Windows-1250, which is what the OP is likely using.

The rest of your message stands regardless: there is no problem, at
least as long as the OP only prints out the character received from
somecmd to something else that also expects Windows-1250.  The problem
would arise if the OP wanted to store the string in a PyGTK label
(which expects UTF8) or send it to a web browser (which expects
explicit encoding, probably defaulting to UTF8), in which case he'd
have to disambiguate whether '\xe8' refers to U+010D or to U+00E8 or
something else entirely.

That is the problem that Python 3 solves by requiring (or strongly
suggesting) that such disambiguation be performed as early in the
program as possible, preferrably while the characters are being read
from the outside source.  A similar approach is possible using Python
2 and its unicode type, but since the OP never specified exactly which
problem he had (except for the repr/str confusion), it's hard to tell
if using the unicode type would help.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Crypto headaches.

2009-02-18 Thread M.-A. Lemburg
On 2009-02-18 14:23, SamG wrote:
> Hi,
> 
> Using the python's Crypto.Cipher.Blowfish is create and encrypted file
> in the CBC mode. Now... when try to decrypt it with OpenSSL i get an
> error stating "bad magic number".

Are you getting the error message from openssl ? It looks a lot
like an error message from Python.

> I tried
> $ cat encr-file | openssl bf-cbc -d -pass pass:sam > org-file
> or
> $ openssl bf-cbc -d -pass pass:sam -in encr-file -out org-file
> 
> BTW, decryption using a python code works well. But i m of the
> impression a file encry with one program should/can be decrypt with
> another program (in my case openssl) using the same parameters.

Ideally, that should work, but you also have to make sure that
the following two details are the same for both applications:

 1. the way padding is done (Blowfish is a block cipher)

 2. the way the initialization vector is set

Otherwise the two won't interoperate properly.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Feb 18 2009)
>>> Python/Zope Consulting and Support ...http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/


::: Try our new mxODBC.Connect Python Database Interface for free ! 


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
   Registered at Amtsgericht Duesseldorf: HRB 46611
   http://www.egenix.com/company/contact/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python/environment problem with char encoding/decoding

2009-02-18 Thread Benjamin Kaplan
On Wed, Feb 18, 2009 at 8:43 AM, Gabriel Rossetti <
gabriel.rosse...@arimaz.com> wrote:

> Hello everyone,
>
> I originally posted this on the Twisted mailing list, but now it seams to
> be  a more general python/environment problem. If I run the attached example
> in Eclipse, it works, if I run it from a terminal, it doesn't, I get :
>
> $ python xml_parser_test.py
> Traceback (most recent call last):
>  File "xml_parser_test.py", line 30, in 
>   res = rawXmlToElement("reçu")
>  File "xml_parser_test.py", line 21, in __call__
>   tmp.addRawXml(s)
>  File "/usr/lib/python2.5/site-packages/twisted/words/xish/domish.py", line
> 538, in addRawXml
>   self.children.append(SerializedXML(rawxmlstring))
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 5:
> ordinal not in range(128)
>
> Does anyone understand why it doesn't work outside of Eclipse? My OS is
> Linux (Ubuntu 8.04).
>
> Thank you,
> Gabriel
>


It's an encoding problem. My guess is that, in eclipse, the default encoding
is UTF-8 or some other unicode-based encoding. In the console, it seems the
encoding defaults to ascii. When twisted attempts to turn your byte string
into a Unicode string, it sees a character that isn't in the encoding and
choke up. Try using a unicode string instead of a byte string.


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


Re: Python/environment problem with char encoding/decoding

2009-02-18 Thread Peter Otten
Gabriel Rossetti wrote:

> Hello everyone,
> 
> I originally posted this on the Twisted mailing list, but now it seams
> to be  a more general python/environment problem. If I run the attached
> example in Eclipse, it works, if I run it from a terminal, it doesn't, I
> get :
> 
> $ python xml_parser_test.py
> Traceback (most recent call last):
>   File "xml_parser_test.py", line 30, in 
> res = rawXmlToElement("reçu")
>   File "xml_parser_test.py", line 21, in __call__
> tmp.addRawXml(s)
>   File "/usr/lib/python2.5/site-packages/twisted/words/xish/domish.py",
> line 538, in addRawXml
> self.children.append(SerializedXML(rawxmlstring))
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 5:
> ordinal not in range(128)
> 
> Does anyone understand why it doesn't work outside of Eclipse? My OS is
> Linux (Ubuntu 8.04).

On the contrary, I don't understand why it would work in Eclipse ;)

addRawXml(s) seems to be a fancy way to create a unicode string, and
unicode(s) will work either if s is a bytestring that doesn't contain any
non-ascii characters or if s is a unicode string (at least these are the
relevant cases here).

Try changing your program to use a unicode literal:

# -*- coding: utf-8 -*-
...
if ...
res = rawXmlToElement(u"reçu")

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


Re: Directory

2009-02-18 Thread Steve Holden
gtillmon wrote:
> Hello.  I am new to the Python language.
> I would like to know how to display and store the path of each mondule
> that is called.

Modules are imported, not called.

> Similar to the old READY TRACE in COBOL of long ago.
> 
It's certainly possible to trace function calls, if that would help.
sys.settrace allows you to establish a function that gets called
whenever a Python function call is executed. The documentation is a
little sparse, but you can find a rough example under "Crude Python
Debugging" in

  http://www.st.ewi.tudelft.nl/~mol/snippets.php

regards
 Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: Python/environment problem with char encoding/decoding

2009-02-18 Thread Gabriel Rossetti

Peter Otten wrote:

Gabriel Rossetti wrote:

  

Hello everyone,

I originally posted this on the Twisted mailing list, but now it seams
to be  a more general python/environment problem. If I run the attached
example in Eclipse, it works, if I run it from a terminal, it doesn't, I
get :

$ python xml_parser_test.py
Traceback (most recent call last):
  File "xml_parser_test.py", line 30, in 
res = rawXmlToElement("reçu")
  File "xml_parser_test.py", line 21, in __call__
tmp.addRawXml(s)
  File "/usr/lib/python2.5/site-packages/twisted/words/xish/domish.py",
line 538, in addRawXml
self.children.append(SerializedXML(rawxmlstring))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 5:
ordinal not in range(128)

Does anyone understand why it doesn't work outside of Eclipse? My OS is
Linux (Ubuntu 8.04).



On the contrary, I don't understand why it would work in Eclipse ;)

addRawXml(s) seems to be a fancy way to create a unicode string, and
unicode(s) will work either if s is a bytestring that doesn't contain any
non-ascii characters or if s is a unicode string (at least these are the
relevant cases here).

Try changing your program to use a unicode literal:

# -*- coding: utf-8 -*-
...
if ...
res = rawXmlToElement(u"reçu")

Peter
--

  
Hello Peter, that works, thanks! I was sure I had tried that at some 
point, but I must have had another problem that made me remove it. Thank 
you again!

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


Re: _socket.so source?

2009-02-18 Thread mbarry
On Feb 17, 6:47 pm, Christian Heimes  wrote:
> mbarry schrieb:
>
> > Hello,
>
> > The socket module in Python uses_socket.so for most of its behavior.
> > I want to modify the code that generates the_socket.so file.
> > I need the source file and instructions on how tocompileand build
> >_socket.so for Windows.
> > Can anyone point me to where I can find the source and/or
> > documentation for compiling a python shared object on Windows?
>
> You need the Python source tree (download the .tar.gz) and the correct
> compiler in order to build a .dll / .pyd file on Windows. For Python 2.4
> and 2.5 you need Visual Studio 2003 (VC7.1), for Python 2.6 and 3.0 you
> have to install Visual Studio 2008 (VC9).
>
> The code for the_socketextension is in the Modules/ subdirectory of
> the source tree.
>
> Christian

Thanks that was very helpful.  I was browsing the source tree and
found socketmodule.c which I assume is the source for _socket.pyd.  I
also found http://docs.python.org/extending/windows.html which is some
documentation for building python extensions in windows.  The _socket
module is a bit different as there seems to be code imported from the
dll as well as having code written in python in socket.py.  Also the
naming convention is different with the socket module as well.

Thanks
-Mike




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


Re: Python-list Digest, Vol 65, Issue 365

2009-02-18 Thread Steve Holden
M Kumar wrote:
> 
> I think the given statement below will give you what you r looking
> .__file__print
> 
[followed by a whole Python list digest]

When replying to a question from a digest posting, PLEASE change the
subject line and only quote the relevant piece of the original posting.
Thank you.

regards
 Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: Musings: Using decorators to reduce duplicate exception handling

2009-02-18 Thread J Kenneth King
"Gabriel Genellina"  writes:

> En Tue, 17 Feb 2009 21:12:57 -0200, J Kenneth King
>   escribió:
>
>> I recently started a project called TracShell
>> (http://code.google.com/p/tracshell) where I make heavy use of the
>> xmlrpclib core module.
>>
>> When the number of RPC calls was small, wrapping each call in try/except
>> was acceptable. However, this obviously will duplicate code all over the
>> place. There are only ever two exceptions that the module itself will
>> throw: xmlrpclib.ProtocolError and xmlrpclib.Fault -- both very useful,
>> but not show stoppers.
>>
>> To combat the duplication, my clever idea was to use a function
>> decorator to wrap any function that used xmlrpclib calls:
>>
>> def catch_errors(fn):
>> """
>> A decorator to catch typical xmlrpclib exceptions
>> """
>> def wrapped(*args, **kwargs):
>> try:
>> return fn(*args, **kwargs)
>> except xmlrpclib.ProtocolError, e:
>> print "There was a problem communicating with the server."
>> print "URL: %s" % e.url
>> print "Headers: %s" % e.headers
>> print "Error code: %d" % e.errcode
>> print "Error message: %s" % e.errmsg
>> print "Please file a report with the TracShell developers."
>> pass
>> except xmlrpclib.Fault, e:
>> print "A fault ocurred"
>> print "Fault code: %d" % e.faultCode
>> print "Fault string: %s" % e.faultString
>> print "If you think this message is the result of an error,"
>> print "please file a report with the TracShell developers."
>> pass
>> return wrapped
>
> I don't like the idea of "hiding" an exception. The caller code
> doesn't  know an exception occurred, and just continue doing its work,
> with bogus  results... is this what you want? Also, you don't include
> the stack trace  - and usually it contains very valuable
> information. When your users start  "filing a report with the
> TracShell developers" and you feel clueless, a  stack trace is
> important (you don't have to show it on screen - a log file  is even
> better).
>
> If all you want is to customize the error message, use sys.except_hook
>
> Looking into the code, those "pass" statement are useless; and error
> messages are usually written to stderr instead of stdout.

Thanks for the ideas.

I haven't actually used this pattern in any projects before, I was just
looking for a way to reduce the number of common try/except statements I
needed to have in my code; especially when they all looked exactly the
same and were catching every single xml-rpc call littered throughout my
class.

sys.except_hook looks more like what I was aiming for. I like Lisp's
"restarts," where I can define error condition handlers in one place
without having to litter my code with error handling statements.

Cheers.

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


Re: Searching Google?

2009-02-18 Thread Alex
On Feb 18, 1:36 pm, Johannes Bauer  wrote:
> Curt Hash schrieb:
>
> > You just need to change your User-Agent so that Google doesn't know a
> > Python script is making the request:
>
> Why would Google not send a response if the User-Agent header field is
> not a recognized browser?

Because making automated queries to Google is against its TOS so
Google block any client that doesn't seam to be human.
On the other hands Google's API does not return the same exact result
as in a normal web query.
My suggestion is: set a browser like User agent and accept gzipped
content to be as friendly as possible and don't do too many queries in
a small time span.
Parsing Google result page with Beautifulsoup is a piece of cake.

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


Re: Threads in PyGTK: keep typing while ping-ing

2009-02-18 Thread bieffe62
On 17 Feb, 02:53, Mamahita Sela  wrote:
> Dear FB,
>
> > As you have been already told, join() blocks until the
> > thread is
> > terminated. and you should avoid that.
> > A simple fix could by add a timeout to t.join, doing
> > something like :
> >         t.join(JOIN_TIMEOUT);
> >         if not t.isAlive():
> >             print t.result
>
> Thanks for your great sample. And, thank you for your tips on speedup the 
> ping stuff.
>
> However, i still have problem when adding timeout to join().
> - It works, but only print out thread result that is not alive, as we put in 
> the code. So, i never get result from unsuccessful ping action, which might 
> take more time than timeout specified.
> - I still have little delay in GUI. Is it possible to make it smooth in GUI 
> operation? When i put more timeout (say: 0.5 from 0.2), i will have to wait  
> longer.
>
> PS: thanks for pointing out inefficient ping action :) I will follow the 
> tips. But, another time I might need to do something else, like downloading 
> files, or checking for serial devices. So, this thread thing, imho, is very 
> important.
>
> Any help would be very appreciated.
> M.


You could make all_threads an attribute of main instance, and use it
to keep track of thread still alive. Therefore your
do_ping code shoulds be somethiong like this (NOT TESTED):

   for h in range(100, 105):
host = '192.168.0.%d' %(h)
#
worker = PingHost(host)
worker.start()
self.all_threads.append(worker)
#
for t in self.all_threads:
   t.join(JOIN_TIMEOUT);
   if not t.isAlive():
print t.result
self.all_threads.remove(t)

#
return True


In this way, you could use a small value for JOIN_TIMEOUT and make the
GUI more responsive. The thread which are not
found completed when do_ping is called will stay in self.all_threads
and will be tested next time.
I did not check the documentation, but assumed that
gobject.timeout_add installs a _periodic_ timer. If it is not
so, you have to reinstall the timer at the end of do_ping, if
self.all_threads is not empty.
And don't forget to initialize self.all_threads in __init__ ;)

HTH

Ciao
-
FB





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


Re: Best practice for upgrading the version of SQLite bundled with Python 2.6.1

2009-02-18 Thread python
Gabriel,

> At least on Windows, you only have to replace sqlite3.dll (in the DLLs 
> directory) with the new one, and that's all.

That's easy! :)

Thank you,

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


Re: Crypto headaches.

2009-02-18 Thread SamG
On Feb 18, 7:10 pm, "M.-A. Lemburg"  wrote:
> On 2009-02-18 14:23, SamG wrote:
>
> > Hi,
>
> > Using the python's Crypto.Cipher.Blowfish is create and encrypted file
> > in the CBC mode. Now... when try to decrypt it with OpenSSL i get an
> > error stating "bad magic number".
>
> Are you getting the error message from openssl ? It looks a lot
> like an error message from Python.
>
> > I tried
> > $ cat encr-file | openssl bf-cbc -d -pass pass:sam > org-file
> > or
> > $ openssl bf-cbc -d -pass pass:sam -in encr-file -out org-file
>
> > BTW, decryption using a python code works well. But i m of the
> > impression a file encry with one program should/can be decrypt with
> > another program (in my case openssl) using the same parameters.
>
> Ideally, that should work, but you also have to make sure that
> the following two details are the same for both applications:
>
>  1. the way padding is done (Blowfish is a block cipher)
>
>  2. the way the initialization vector is set
>
> Otherwise the two won't interoperate properly.
>
> --
> Marc-Andre Lemburg
> eGenix.com
>
> Professional Python Services directly from the Source  (#1, Feb 18 2009)>>> 
> Python/Zope Consulting and Support ...http://www.egenix.com/
> >>> mxODBC.Zope.Database.Adapter ...http://zope.egenix.com/
> >>> mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/
>
> 
>
> ::: Try our new mxODBC.Connect Python Database Interface for free ! 
>
>eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
> D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
>Registered at Amtsgericht Duesseldorf: HRB 46611
>http://www.egenix.com/company/contact/

That must be it...

But given a password how do i generate a (key, IV) pair???

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


how to list all installed modules

2009-02-18 Thread harryos
hi
Is there a way to list all the installed modules in my python
installation.I recently installed pygame and when i tried to import it
like
>>import pygame
it complained that no such module was found.I can see the pygame
directory in F:\Python25\Lib\site-packages in my machine,but am unable
to import the module.So I was wondering if there is a way to list all
the installed modules

any help much appreciated
thanks
harry
--
http://mail.python.org/mailman/listinfo/python-list


Re: how to list all installed modules

2009-02-18 Thread Peter Otten
harryos wrote:

> Is there a way to list all the installed modules in my python
> installation.I recently installed pygame and when i tried to import it
> like
>>>import pygame
> it complained that no such module was found.I can see the pygame
> directory in F:\Python25\Lib\site-packages in my machine,but am unable
> to import the module.So I was wondering if there is a way to list all
> the installed modules

>>> help("modules")

may help to get a list of modules (if it doesn't fail with an exception as
over here). 

Regarding the original problem, do you have multiple Python installations? 
If so, you may accidentally be running the "wrong" python.

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


Re: Python 3D CAD -- need collaborators, or just brave souls :)

2009-02-18 Thread Zamnedix
On Feb 9, 12:58 pm, rantingrick  wrote:
> Hello all,
>
> It has long been my dream to create an open source 3D CAD program and
> i am starting to crawl my way into the first steps. I now believe i am
> ready to start this endeavor and i am currently looking for fellow
> Python programmers (no matter what skill level) to get started
> brainstorming this design.
>
> I have a real good idea of the UI design and at this point i just want
> to start simple and build this thing. I figure this will be a good
> learning experience for myself and others and in the process i can
> realize my dream. And if all this turns out to be is a learning
> experience, well nobody lost.
>
> Of course Python will limit the speed here, but at this point i want
> to get a template up and running. Speed does not matter at this point,
> and optimizations can come along later as i am sure a few complete re-
> writes are inevitable :)
>
> My initial start will cover a very simple user interface something
> like VPython but much more usable as a CAD modeler. From the start
> just a few simple primitives (faces, lines-segments) that will be the
> building blocks for more complex models like (arcs, rectangles,
> circles, polygons, cubes, spheres, etc..).
>
> There will need to be mouse picking as i see this application as a
> very interactive environment. Of course in the beginning all
> interaction will most likely be in a command line type manner until
> the functionality can be worked out.
>
> There will need to be a hierarchy of instancing and grouping within
> the model to facilitate easy transformation of entities within the
> model.
>
> I am not too worried about any sort of texturing at this point. I want
> to squeeze as much speed as possible and prettiness will come in due
> course. I also have no plans for layering, or multiple scenes at this
> time. Simple functionality is the end game here.
>
> Once the UI is there and the modeling work flow is worked out,
> everything should be a component add-on from there.
>
> So the main points are...
>
> #-- Entities --#
>  face
>  line-segment
>
> #-- Hierarchy --#
>  Entity (one face, or line-segment)
>  Group (contained of multiple entities that can be translated,
> rotated, scaled as one)
>  Instance (component definition)
>
> #-- Tools --#
>  line
>  rect
>  circle
>  arc
>  select
>  rotation
>  translation
>  scale
>  extrusion along path
>  measurement
>
> So there it is. Any takers? :)

I realize this isn't necessarily CAD, but...
http://www.blender.org/
--
http://mail.python.org/mailman/listinfo/python-list


Revision Control

2009-02-18 Thread Sam Clark
Any suggestions for a beginer on what to use for version control?   It's just 
me, the lone person programming.  I've already nailed one "version" of my code 
accidentaly.  MS VSS is too expensive for the stuff I'm doing, plus I really 
don't like MS much...  Any free open source stuff out there?
 
Thank you,
 
Sam Clark
s...@2000soft.com
 
--
http://mail.python.org/mailman/listinfo/python-list


Re: how to list all installed modules

2009-02-18 Thread harryos
On Feb 18, 9:42 pm, Peter Otten <__pete...@web.de> wrote:
> >>> help("modules")

thanks Peter.That helped.
> Regarding the original problem, do you have multiple Python installations?
> If so, you may accidentally be running the "wrong" python.

I have only one installation.It shows all other modules.I will try
reinstalling .
regards,
harry

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


Re: Revision Control

2009-02-18 Thread Chris Rebert
On Wed, Feb 18, 2009 at 9:08 AM, Sam Clark  wrote:
> Any suggestions for a beginer on what to use for version control?   It's
> just me, the lone person programming.  I've already nailed one "version" of
> my code accidentaly.  MS VSS is too expensive for the stuff I'm doing, plus
> I really don't like MS much...  Any free open source stuff out there?

I like Mercurial (hg) personally: http://www.selenic.com/mercurial/wiki/
It's written in Python, works well on Windows, is a modern distributed
VCS, and is simpler than Git.

Cheers,
Chris

-- 
Follow the path of the Iguana...
http://rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


why do I get name not defined error

2009-02-18 Thread zaheer . agadi
Hi,

 I have the following declared in my class, I am trying tp call a
method defined in the same class
I am not sure why I am getting name not defined error

if options.uploadFile != None :
print "This is path", the_rest
filePath = the_rest
UploadFile(None,filePath)

def UploadFile(self,path):
print "I wil upload now"
os.chdir(homeFolder)
config = ConfigParser.ConfigParser()
.

any ideas why the error name UploadFile not defined

Thnaks


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


Re: why do I get name not defined error

2009-02-18 Thread Diez B. Roggisch

zaheer.ag...@gmail.com schrieb:

Hi,

 I have the following declared in my class, I am trying tp call a
method defined in the same class
I am not sure why I am getting name not defined error

if options.uploadFile != None :
print "This is path", the_rest
filePath = the_rest
UploadFile(None,filePath)

def UploadFile(self,path):
print "I wil upload now"
os.chdir(homeFolder)
config = ConfigParser.ConfigParser()
.

any ideas why the error name UploadFile not defined



Because you need to define things *before* you use them the first time. 
This is not to be confused with forward-declarations, as they are needed 
in C for example - in python you can do



def foo():
   bar()

def bar():
   foo()


(resulting in an endless loop of course)

But you can't do


def foo():
   bar()

foo() # this will fail

def bar():
   foo()



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


Re: why do I get name not defined error

2009-02-18 Thread Peter Otten
zaheer.ag...@gmail.com wrote:

>  I have the following declared in my class, I am trying tp call a
> method defined in the same class
> I am not sure why I am getting name not defined error
 
Assuming this is part of a method

def method(self):
> if options.uploadFile != None :
> print "This is path", the_rest
> filePath = the_rest
> UploadFile(None,filePath)

you have to change the above line to

  self.UploadFile(filePath)
 

Now consider reading a tutorial before you proceed.

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


Re: Revision Control

2009-02-18 Thread Benjamin Kaplan
On Wed, Feb 18, 2009 at 12:08 PM, Sam Clark  wrote:

>  Any suggestions for a beginer on what to use for version control?   It's
> just me, the lone person programming.  I've already nailed one "version" of
> my code accidentaly.  MS VSS is too expensive for the stuff I'm doing, plus
> I really don't like MS much...  Any free open source stuff out there?
>

There's actually a lot of them. These are just the ones I can think of off
the top of my head.
-CVS (One of the first RCS, I think most projects are moving away from this
one.)
- Subversion-(pretty popular right now, but it is a client/server model.)
-Git (originally created for Linux and now used by several very large
projects)
-Mercurial (this is a big up and coming RCS)
-Bazaar (written in Python. Also pretty new. I don't know about Windows
support)

I have some experience with both Subversion and Mercurial and like them
both. Since you're working alone, you'll probably want a distributed rcs,
such as Mercurial, Git, and Bazaar, which allow you to do more stuff locally
rather than on a central server. Like Chris, I'd suggest Mercurial
especially if you're using Windows.


Thank you,
>
> Sam Clark
> s...@2000soft.com
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: how to list all installed modules

2009-02-18 Thread Scott David Daniels

harryos wrote:

Is there a way to list all the installed modules in my python
installation.I recently installed pygame and when i tried to import it
like

import pygame

it complained that no such module was found.I can see the pygame
directory in F:\Python25\Lib\site-packages in my machine,but am unable
to import the module.So I was wondering if there is a way to list all
the installed modules


Are you running F:\Python25\python.exe (or F:\Python25\pythonw.exe)?
open a command window (run cmd), and type:
C:\> python
...
>>> import sys
>>> for dirname in  sys.path:
print sys.path

I suspect something you see printed will surprise you.
Either the banner, identifying a Python version you were
not expecting, or perhaps a bunch of C:-based directories.
If this does not help you decipher the problem, try running
 python -v
Python verbose mode (You will get a _lot_ of output).
Then, when you (finally) get a ">>>" prompt, type:
   >>> import pygame
and you will see eaxctly what lookups are tried.

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


Re: "Maximum recursion depth exceeded"...why?

2009-02-18 Thread Thomas Allen
On Feb 18, 4:51 am, alex23  wrote:
> On Feb 18, 7:34 pm, rdmur...@bitdance.com wrote:
>
> > Yeah, but wget -r -k will do that bit of it, too.
>
> Wow, nice, I don't know why I never noticed that. Cheers!

Hm...doesn't do that over here. I thought it may have been because of
absolute links (not to site root), but it even leaves things like . Does it work for you guys?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Revision Control

2009-02-18 Thread skip

>> Any suggestions for a beginer on what to use for version control?

Chris> I like Mercurial (hg) personally...

Me too.  It's perfect for little one-person things.  (It's probably good for
other stuff as well, but I certainly like how easy it is to use for
standalone stuff.)

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


Re: Revision Control

2009-02-18 Thread Tim Chase

-CVS (One of the first RCS, I think most projects are moving away from this
one.)


I wouldn't suggest starting a new project with CVS.  Subversion 
(svn) resolves several of the main issues with it, so using SVN 
instead wins over CVS in just about every possible way.



- Subversion-(pretty popular right now, but it is a client/server model.)


A good solid & popular choice, but the merging capabilities are a 
bit weak (the latest version just added some better capabilities 
for branching/merging, but it's a bit of a hack).  It's also not 
the most efficient storage -- git and mercurial (hg) both have 
very efficient repository structures compared to SVN.  The family 
DVCS tools (git, mercurial, bzr, darcs) are stronger in this 
area.  My employer uses SVN for their primary repository. 
Documentation is outstandingly good (documentation for the others 
is also good, but SVN's is exceptional).



-Git (originally created for Linux and now used by several very large
projects)


I've tried several times to like git -- some folks swear by it. 
The Win32 support has been a bit wanting, but growing.  I find it 
a bit more complex but it's certainly not lacking for power. 
I'll continue to try it occasionally to see if it meets my needs 
better than Mercurial



-Mercurial (this is a big up and coming RCS)


This is currently my favorite:  good branching/merging, fast, 
written mostly in Python (one C extension module, IIRC), and a 
simple interface



-Bazaar (written in Python. Also pretty new. I don't know about Windows
support)


I like Bazaar (bzr), but the last several times I've tried it, 
it's been a little slow.  This has been steadily improving, and I 
like their emphasis on correctness foremost.  It's a lot like 
mercurial, but is pure python (no C extension module) which makes 
it nice to deploy into environments such as my shared web-hosting 
service where I can't build extension C modules or install 
packages such as hg/git/svn from the repository.


All of them have GUI interfaces if you need, but I tend to just 
use them from the command-line.  For most of them, you can get by 
with a handful of commands without needing to learn every last 
corner.


For what you (the OP) describe, I'd suggest SVN, Mercurial, or 
Bazaar as they're a little easier to wrap your head around -- SVN 
wins for documentation, Mercurial wins for speed and merging, and 
Bazaar wins for portability and merging.  Git would win for sheer 
power, but if you're just beginning, I'd skip it for now.


-tkc








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


Re: numpy.memmap advice?

2009-02-18 Thread Lionel
On Feb 18, 12:56 am, Carl Banks  wrote:
> On Feb 17, 3:08 pm, Lionel  wrote:
>
>
>
>
>
> > Hello all,
>
> > On a previous thread (http://groups.google.com/group/comp.lang.python/
> > browse_thread/thread/64da35b811e8f69d/67fa3185798ddd12?
> > hl=en&lnk=gst&q=keene#67fa3185798ddd12) I was asking about reading in
> > binary data. Briefly, my data consists of complex numbers, 32-bit
> > floats for real and imaginary parts. The data is stored as 4 bytes
> > Real1, 4 bytes Imaginary1, 4 bytes Real2, 4 bytes Imaginary2, etc. in
> > row-major format. I needed to read the data in as two separate numpy
> > arrays, one for real values and one for imaginary values.
>
> > There were several very helpful performance tips offered, and one in
> > particular I've started looking into. The author suggested a
> > "numpy.memmap" object may be beneficial. It was suggested I use it as
> > follows:
>
> > descriptor = dtype([("r", " > data = memmap(filename, dtype=descriptor, mode='r').view(recarray)
> > print "First 100 real values:", data.r[:100]
>
> > I have two questions:
> > 1) What is "recarray"?
>
> Let's look:
>
> [GCC 4.3.2] on linux2
> Type "help", "copyright", "credits" or "license" for more information.>>> 
> import numpy
> >>> numpy.recarray
>
> 
>
> >>> help(numpy.recarray)
>
> Help on class recarray in module numpy.core.records:
>
> class recarray(numpy.ndarray)
>  |  recarray(shape, dtype=None, buf=None, **kwds)
>  |
>  |  Subclass of ndarray that allows field access using attribute
> lookup.
>  |
>  |  Parameters
>  |  --
>  |  shape : tuple
>  |      shape of record array
>  |  dtype : data-type or None
>  |      The desired data-type.  If this is None, then the data-type is
> determine
>  |      by the *formats*, *names*, *titles*, *aligned*, and
> *byteorder* keywords
>  |  buf : [buffer] or None
>  |      If this is None, then a new array is created of the given
> shape and data
>  |      If this is an object exposing the buffer interface, then the
> array will
>  |      use the memory from an existing buffer.  In this case, the
> *offset* and
>  |      *strides* keywords can also be used.
> ...
>
> So there you have it.  It's a subclass of ndarray that allows field
> access using attribute lookup.  (IOW, you're creating a view of the
> memmap'ed data of type recarray, which is the type numpy uses to
> access structures by name.  You need to create the view because
> regular numpy arrays, which numpy.memmap creates, can't access fields
> by attribute.)
>
> help() is a nice thing to use, and numpy is one of the better
> libraries when it comes to docstrings, so learn to use it.
>
> > 2) The documentation for numpy.memmap claims that it is meant to be
> > used in situations where it is beneficial to load only segments of a
> > file into memory, not the whole thing. This is definately something
> > I'd like to be able to do as my files are frequently >1Gb. I don't
> > really see in the diocumentation how portions are loaded, however.
> > They seem to create small arrays and then assign the entire array
> > (i.e. file) to the memmap object. Let's assume I have a binary data
> > file of complex numbers in the format described above, and let's
> > assume that the size of the complex data array (that is, the entire
> > file) is 100x100 (rows x columns). Could someone please post a few
> > lines showing how to load the top-left 50 x 50 quadrant, and the lower-
> > right 50 x 50 quadrant into memmap objects? Thank you very much in
> > advance!
>
> You would memmap the whole region in question (in this case the whole
> file), then take a slice.  Actually you could get away with memmapping
> just the last 50 rows (bottom half).  The offset into the file would
> be 50*100*8, so:
>
> data = memmap(filename, dtype=descriptor, mode='r',offset=
> (50*100*8)).view(recarray)
> reshaped_data = reshape(data,(50,100))
> intersting_data = reshaped_data[:,50:100]
>
> A word of caution: Every instance of numpy.memmap creates its own mmap
> of the whole file (even if it only creates an array from part of the
> file).  The implications of this are A) you can't use numpy.memmap's
> offset parameter to get around file size limitations, and B) you
> shouldn't create many numpy.memmaps of the same file.  To work around
> B, you should create a single memmap, and dole out views and slices.
>
> Carl Banks- Hide quoted text -
>
> - Show quoted text -

Thanks Carl, I like your solution. Am I correct in my understanding
that memory is allocated at the slicing step in your example i.e. when
"reshaped_data" is sliced using "interesting_data = reshaped_data[:,
50:100]"? In other words, given a huge (say 1Gb) file, a memmap object
is constructed that memmaps the entire file. Some relatively small
amount of memory is allocated for the memmap operation, but the bulk
memory allocation occurs when I generate my final numpy sub-array by
slicing, and this accounts for the memory efficiency of using memmap?
--
http://mail.python.org/mailman/list

PIL install driving me mad! With solution!

2009-02-18 Thread bleah
I'm trying to get PIL 1.16 installed on a SUSE SLES10 system, and
cannot, for the life of me, get the thing to compile with jpeg
support.

The libjpeg-devel libraries are installed, and are present in /usr/lib
JUST WHERE SPECIFIED in the setup.py file, and the jpeglib.h incliude
file is present  JUST WHERE SPECIFIED in the setup.py file.

The build process proceeds without errors, yet selftest.py fails with
the error:

tonic:~/html2pdf_sources/Imaging-1.1.6 # python selftest.py
*
Failure in example: _info(Image.open("Images/lena.jpg"))
from line #24 of selftest.testimage
Exception raised:
Traceback (most recent call last):
  File "./doctest.py", line 499, in _run_examples_inner
exec compile(source, "", "single") in globs
  File "", line 1, in 
  File "./selftest.py", line 22, in _info
im.load()
  File "PIL/ImageFile.py", line 180, in load
d = Image._getdecoder(self.mode, d, a, self.decoderconfig)
  File "PIL/Image.py", line 375, in _getdecoder
raise IOError("decoder %s not available" % decoder_name)
IOError: decoder jpeg not available
1 items had failures:
   1 of  57 in selftest.testimage
***Test Failed*** 1 failures.
*** 1 tests of 57 failed.


Again and again and again.


I found this post  
http://blog.tlensing.org/2008/12/04/kill-pil-–-the-python-imaging-library-headache
which provided the solution.

When you run selftest.py in the Imaging-1.1.6 directory, python finds
the PIL.pth and PIL file and directory, respectively and uses those
instead of the properly compiled versions in the python directories.

So PIL is installed, it IS working perfectly, it's selftest.py that's
failing...
--
http://mail.python.org/mailman/listinfo/python-list


Re: Pythonic way to determine if one char of many in a string

2009-02-18 Thread Jervis Whitley
>
> What happens when you have hundreds of megabytes, I don't know.
>
>
I hope I never have to test a word that is hundreds of megabytes long
for a vowel :)
--
http://mail.python.org/mailman/listinfo/python-list


PyGTK install

2009-02-18 Thread Lionel
Hello folks, I couldn't find a specific PyGTK forum so I thought I'd
post here and hope someone new the answer. I feel it's a silly
problem, maybe something to do with a path variable? The problem: I've
downloaded the "all-in-one" windows binary installer for PyGTK from
their website. After typing in their first tutorial program and trying
to run from the command line, I get:

"This application has failed to start because libglib-2.0-0.dll was
not found" error dialog.

The traceback indicates this is happening at the "import gtk" line. A
quick search of my install directory for PyGTK indicates that the file
is indeed resident and located in C:\Program files\PyGTK\GTK\bin.

Is there some some sort of path variable for Python I need to modify
and, if so, how is this done? Thanks so much, and my apologies if this
is the wrong forum.

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


Re: Pythonic way to determine if one char of many in a string

2009-02-18 Thread Steve Holden
Jervis Whitley wrote:
>> What happens when you have hundreds of megabytes, I don't know.
>>
>>
> I hope I never have to test a word that is hundreds of megabytes long
> for a vowel :)

I see you don't speak German ;-)
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: Pythonic way to determine if one char of many in a string

2009-02-18 Thread Peter Otten
Steven D'Aprano wrote:

> On Wed, 18 Feb 2009 07:08:04 +1100, Jervis Whitley wrote:
> 
> 
>>> This moves the for-loop out of slow Python into fast C and should be
>>> much, much faster for very large input.
>>>
>>>
>> _Should_ be faster.
> 
> Yes, Python's timing results are often unintuitive.

Indeed.

> It seems to me that I was mistaken -- for large enough input, the running
> time of each version converges to approximately the same speed.

No, you were right. Both any_test() and for_test() use the improvement you 
suggested, i. e. loop over the vowels, not the characters of the word.
Here's the benchmark as it should have been:

$ python -m timeit -s'word = "g"*1' 'any(v in word for v in "aeiouAEIOU")'
1000 loops, best of 3: 314 usec per loop
$ python -m timeit -s'word = "g"*1' 'any(c in "aeiouAEIOU" for c in word)'
100 loops, best of 3: 3.48 msec per loop

Of course this shows only the worst case behaviour. The results will vary 
depending on the actual word e. g. "Ug..." or "g...a".

Peter 

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


number theory libraries / project euler

2009-02-18 Thread eliben
Hello,

What are some good & recommended number theory libs for Python (or
accessible interfaces to C libs), for things like primes,
factorization, etc. Naturally, speed is of utmost importance here.

In other words, which Python libraries and tools to you use to help
you solve Project Euler problems :-) ?

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


Re: Python 3D CAD -- need collaborators, or just brave souls :)

2009-02-18 Thread Josh Dukes
You might also want to look in to open cascade. It supports a bunch of
standard 3d model formats (stl, iges, step) and has python bindings.
Salome is based on open cascade. http://www.pythonocc.org/ However, I'm
not entirely clear on the license for this so that might be an issue. I
know the Debian lawyers had some problems with Salome because it
compiled against open cascade. I believe if you made open cascade an
optional run-time dependency it could still be a valid gpl app.

It's also important to keep in mind that what most people think of as
cad/cam is really multiple things that can be broken up into modules
(cad/cam/fea). Those can also be broken up into modules (fea can be
broken into meshing, pre-processing, analysis, and post-processing). It
seems like attacking things this way might be best. If you're really
serious about this (there are lots of failed Linux cad packages) I'd
suggest setting up a project on sourceforge and get a mailing list.
Post a link to the mailing list and I'll join. I can probably find some
other mailing lists that you should try to recruit from, but having a
sourceforge page and a mailing list really helps your legitimacy. 

Another interesting project is FreeCAD, which is written in C++ but
compiled against python,
http://juergen-riegel.net/FreeCAD/Docu/index.php?title=Main_Page might
be worth looking at. 

I look forward to joining your mailing list. 

On Wed, 18 Feb 2009 01:02:22 -0800 (PST)
r  wrote:

> Hello Josh,
> Blender is a lost cause. It is a powerful app but the UI is horrible.
> Even the Blender folks admit only a complete rewrite could solve the
> major flaws that plague the design. So maybe i could salvage some code
> but for what i have in mind, Blender will look like a piece of
> software from the middle ages. And i am absolutly only looking to do
> this in 3D, 2D is boring.
> 
> So, yes, i have looked at both the applications you offer.
> 
> Thanks
> --
> http://mail.python.org/mailman/listinfo/python-list


-- 

Josh Dukes
MicroVu IT Department
--
http://mail.python.org/mailman/listinfo/python-list


Re: Pythonic way to determine if one char of many in a string

2009-02-18 Thread Peter Otten
Steve Holden wrote:

> Jervis Whitley wrote:
>>> What happens when you have hundreds of megabytes, I don't know.
>>>
>>>
>> I hope I never have to test a word that is hundreds of megabytes long
>> for a vowel :)
> 
> I see you don't speak German ;-)

I tried to come up with a funny way to point out that you're a fool.

But because I'm German I failed.

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


Re: number theory libraries / project euler

2009-02-18 Thread Kurt Smith
On Wed, Feb 18, 2009 at 2:18 PM, eliben  wrote:
>
> Hello,
>
> What are some good & recommended number theory libs for Python (or
> accessible interfaces to C libs), for things like primes,
> factorization, etc. Naturally, speed is of utmost importance here.
>
> In other words, which Python libraries and tools to you use to help
> you solve Project Euler problems :-) ?

There's Sage: http://www.sagemath.org/ -- I believe it aims to do
everything that Mathematica can do and more, and I know it has some
number theory libs, too.  I haven't had the occasion to use it myself.

Much of the fun of project euler problems is 'rolling your own,' or
implementing a classic algorithm from a description of it on
Wikipedia.  A good sieve of eratosthenes in pure Python (that I tend
to use quite often) is here:

http://code.activestate.com/recipes/117119/

You can find some combinatorics in numpy, I believe.

Often the solutions are one-to-five liners, if you've thought the
problem through.  Too much dependence on external libraries robs the
project euler problems of their fun, IMO.

Best,

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


Re: number theory libraries / project euler

2009-02-18 Thread andrew cooke
eliben wrote:
> Hello,
>
> What are some good & recommended number theory libs for Python (or
> accessible interfaces to C libs), for things like primes,
> factorization, etc. Naturally, speed is of utmost importance here.

i just read the project site and one of the things they say on their front
page is that all problems have a solution that should run in "under a
minute".  the emphasis is on finding the right algorithm, not brute force
number crunching.  so i am not sure that speed is of much importance at
all.

> In other words, which Python libraries and tools to you use to help
> you solve Project Euler problems :-) ?

you may want to look at numpy and scipy, but looking at the first dozen
questions i think ordinary python may be sufficient.

andrew


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


Re: numpy.memmap advice?

2009-02-18 Thread Carl Banks
On Feb 18, 10:48 am, Lionel  wrote:
> Thanks Carl, I like your solution. Am I correct in my understanding
> that memory is allocated at the slicing step in your example i.e. when
> "reshaped_data" is sliced using "interesting_data = reshaped_data[:,
> 50:100]"? In other words, given a huge (say 1Gb) file, a memmap object
> is constructed that memmaps the entire file. Some relatively small
> amount of memory is allocated for the memmap operation, but the bulk
> memory allocation occurs when I generate my final numpy sub-array by
> slicing, and this accounts for the memory efficiency of using memmap?

No, what accounts for the memory efficienty is there is no bulk
allocation at all.  The ndarray you have points to the memory that's
in the mmap.  There is no copying data or separate array allocation.

Also, it's not any more memory efficient to use the offset parameter
with numpy.memmap than it is to memmap the whole file and take a
slice.


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


Re: Musings: Using decorators to reduce duplicate exception handling

2009-02-18 Thread Cameron Simpson
On 17Feb2009 15:12, J Kenneth King  wrote:
| I recently started a project called TracShell
| (http://code.google.com/p/tracshell) where I make heavy use of the
| xmlrpclib core module.
| 
| When the number of RPC calls was small, wrapping each call in try/except
| was acceptable. [...]
| To combat the duplication, my clever idea was to use a function
| decorator to wrap any function that used xmlrpclib calls:
| def catch_errors(fn):
[...]
| Maybe I could rename the decorator to something meaningful, but besides
| that it works pretty well. Now any function I write in my class that
| uses RPC calls can be wrapped by this decorator and have the exception
| handling done in a uniform way for these particular exceptions.

My Python fu is still weak, but I had a similar issue last year and
wrote a context manager, used thus:

  with NoExceptions(handler):
  ... do stuff that may break ...

The constructor takes a handleException argument (which may be None, but it
has to be explicit) to tune which exceptions are caught; default is
everything. This was for a daemon thread that did RPC calls, so it was
actually fairly important to never die; normally you'd want to catch only
specific exceptions.

Code:

  class NoExceptions(object):
  ''' A context manager to catch _all_ exceptions and log them.
  Arguably this should be a bare try...except but that's syntacticly
  noisy and separates the catch from the top.
  '''

  def __init__(self, handleException):
  ''' Initialise the NoExceptions context manager.
  The handleException is a callable which
  expects (exc_type, exc_value, traceback)
  and returns True or False for the __exit__
  method of the manager.
  If handleException is None, the __exit__ method
  always returns True, suppressing any exception.
  '''
  self.__handler = handleException

  def __enter__(self):
  pass

  def __exit__(self, exc_type, exc_value, traceback):
  if self.__handler is not None:
  return self.__handler(exc_type, exc_value, traceback)
  if exc_type is not None:
  print >>sys.stderr, "ignore %s" % (exc_type,)
  return True

It doesn't actually solve your duplication issue and is a bit of a niche
application, but it's a lot shorter than an inline try/except and to my eye
reads a little better, and it keeps the exception handling up front at the
calling end where it is visible.

Cheers,
-- 
Cameron Simpson  DoD#743
http://www.cskk.ezoshosting.com/cs/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Directory

2009-02-18 Thread Gabriel Genellina
En Wed, 18 Feb 2009 12:15:25 -0200, Steve Holden   
escribió:

gtillmon wrote:



I would like to know how to display and store the path of each mondule
that is called.

It's certainly possible to trace function calls, if that would help.
sys.settrace allows you to establish a function that gets called


If the OP is only interested in import statements, perhaps the -v flag is  
enough:


python -v script_name.py

It prints a line (on stderr) for each module imported, stating its name  
and source file.


--
Gabriel Genellina

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


Delete lines which contain string in a file

2009-02-18 Thread Rudi Goldman
Hi,
Go easy on me as I am a new to Python and am trying to solve a practical
problem that is driving me bananas.
Basically I have 2 text files, a source and a target. I want to be able to
delete all of the lines in the target file which contain text from any line
in the source file.
i.e.
Source: Target:
111   xxx 111 yyy
222   xxx  333 sss
333   jjj   444 sss

After executing this code the target file should only consist of the line:
  jjj   444 sss
Any help on this one would be greatly appreciated.

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


PyTypeObject subclass

2009-02-18 Thread Aaron Brady
Hi,

Is it ok to subclass PyTypeObject, so that my custom 'tp_' fields can
appear at the bottom of it?  Is there anything like size requirements
going on in its code?  Or is it better to use 'tp_dict' or slots?

Thanks.

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


Can't get the IPYthon ipapi object working

2009-02-18 Thread beetlecube
Hi , I found out from a random google search that I could use IPython
to automatically import modules so that I could test Django views.

I downloaded it (WIN XP), installed it.  I'm able to import it, but I
just can't seem to get the object working.

The code:
---
try:
import IPython.ipapi
ip = IPython.ipapi.get()
a = ip.options
ip.ex('import os')

except Exception,msg:
print "Message: ", msg
---

I get: ' Message:  'NoneType' object has no attribute 'options' '

If I remove the ip.options statement, it will say the same thing about
attribute 'ex'

Does anyone know if there are configuration options necessary?

 I read the docs, and it described a profile module, but I just need
to run this, for this single purpose ( at least, now, later I can see
its usefulness definitely,)

Steve











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


Re: Searching Google?

2009-02-18 Thread Tim Wintle
On Wed, 2009-02-18 at 13:36 +0100, Johannes Bauer wrote:
> Curt Hash schrieb:
> 
> > You just need to change your User-Agent so that Google doesn't know a
> > Python script is making the request:
> 
> Why would Google not send a response if the User-Agent header field is
> not a recognized browser? I doubt that's what's happening and the OP
> would just like the convenience of a search API instead of parsing the
> web page (like other applications do). Ugly, but it works.

I suspect that it's the other way around - Google has black-listed the
standard python user-agent rather than whitelisting useragents.

Think about how much power it takes to do a query on Google - if they
provided a search API they would lose out on advertising on the results
- which at the end of the day is their income-source.

It's a pain not to have a search API, but you've got to understand it!


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


Re: PyGTK install

2009-02-18 Thread Lionel
On Feb 18, 11:43 am, Lionel  wrote:
> Hello folks, I couldn't find a specific PyGTK forum so I thought I'd
> post here and hope someone new the answer. I feel it's a silly
> problem, maybe something to do with a path variable? The problem: I've
> downloaded the "all-in-one" windows binary installer for PyGTK from
> their website. After typing in their first tutorial program and trying
> to run from the command line, I get:
>
> "This application has failed to start because libglib-2.0-0.dll was
> not found" error dialog.
>
> The traceback indicates this is happening at the "import gtk" line. A
> quick search of my install directory for PyGTK indicates that the file
> is indeed resident and located in C:\Program files\PyGTK\GTK\bin.
>
> Is there some some sort of path variable for Python I need to modify
> and, if so, how is this done? Thanks so much, and my apologies if this
> is the wrong forum.
>
> -L

Well, I tried uninstalling / reinstalling PyGTK and now I'm getting a
different traceback error:

"ImportError: no module named pygtk"

I checked and pygtk.py is located in "c:\Python25\Lib\site-packages".
Then I displaye the sys.path:

IDLE 1.2
>>> import sys
>>> sys.path
['C:\\Program Files\\PyGTK\\Python\\Lib\\idlelib', 'C:\\Program Files\
\PyGTK\\Python\\python25.zip', 'C:\\Program Files\\PyGTK\\Python\
\DLLs', 'C:\\Program Files\\PyGTK\\Python\\lib', 'C:\\Program Files\
\PyGTK\\Python\\lib\\plat-win', 'C:\\Program Files\\PyGTK\\Python\\lib\
\lib-tk', 'C:\\Program Files\\PyGTK\\Python', 'C:\\Program Files\\PyGTK
\\Python\\lib\\site-packages']

Every single entry is related to PyGTK and nothing else. Something
seems wrong here but I don't have enough Python experience to know
just what. Anyone?
--
http://mail.python.org/mailman/listinfo/python-list


Newbie Q about Turtle Gfx

2009-02-18 Thread Neil
Hello

Sorry if this is not an appropriate newsgroup for this problem. I am very 
new to Python but not new to programming.

I am hoping to use Python to teach a class and have been looking at the 
online book 'Snake Wrangling for Kids'.

I have followed the example

>>>import turtle
>>>t=turtle.pen()

which works fine and displays a turtle in a window.

However whenever I try to use something like

>>>t.forward(50)   (taken from the book)

i get the error...

Traceback (most recent call last):
  File "", line 1, in 
t.forward(50)
AttributeError: 'dict' object has no attribute 'forward'

I get the same error with t.left(10) etc. etc.

I have tried this with V2.6 and V3

Any ideas would be much appreciated.

Thanks
Neil



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


Re: Newbie Q about Turtle Gfx

2009-02-18 Thread Neil
Forgot to say, that after the error message the turtle window 'hangs' as 
unresponsive ...

"Neil"  wrote in message 
news:ifidnr_gysdmfqhunz2dnekdnzzin...@bt.com...
> Hello
>
> Sorry if this is not an appropriate newsgroup for this problem. I am very 
> new to Python but not new to programming.
>
> I am hoping to use Python to teach a class and have been looking at the 
> online book 'Snake Wrangling for Kids'.
>
> I have followed the example
>
import turtle
t=turtle.pen()
>
> which works fine and displays a turtle in a window.
>
> However whenever I try to use something like
>
t.forward(50)   (taken from the book)
>
> i get the error...
>
> Traceback (most recent call last):
>  File "", line 1, in 
>t.forward(50)
> AttributeError: 'dict' object has no attribute 'forward'
>
> I get the same error with t.left(10) etc. etc.
>
> I have tried this with V2.6 and V3
>
> Any ideas would be much appreciated.
>
> Thanks
> Neil
>
>
> 


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


Re: Delete lines which contain string in a file

2009-02-18 Thread Steve Holden
Rudi Goldman wrote:
> Hi,
> Go easy on me as I am a new to Python and am trying to solve a practical
> problem that is driving me bananas.
> Basically I have 2 text files, a source and a target. I want to be able
> to delete all of the lines in the target file which contain text from
> any line in the source file.
> i.e.
> Source: Target:
> 111   xxx 111 yyy   
> 222   xxx  333 sss 
> 333   jjj   444 sss
> 
> After executing this code the target file should only consist of the
> line: jjj   444 sss
> Any help on this one would be greatly appreciated.
> 
Is this homework?

How far have you got with your design?

regards
 Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: Newbie Q about Turtle Gfx

2009-02-18 Thread sjbrown
It looks like there may be a bug if you were expecting t to be some
object other than a dict.  You can apparently contact the authour
here:

http://www.briggs.net.nz/log/contact/

On Feb 18, 2:16 pm, "Neil"  wrote:
> Hello
>
> Sorry if this is not an appropriate newsgroup for this problem. I am very
> new to Python but not new to programming.
>
> I am hoping to use Python to teach a class and have been looking at the
> online book 'Snake Wrangling for Kids'.
>
> I have followed the example
>
> >>>import turtle
> >>>t=turtle.pen()
>
> which works fine and displays a turtle in a window.
>
> However whenever I try to use something like
>
> >>>t.forward(50)   (taken from the book)
>
> i get the error...
>
> Traceback (most recent call last):
>   File "", line 1, in 
>     t.forward(50)
> AttributeError: 'dict' object has no attribute 'forward'
>
> I get the same error with t.left(10) etc. etc.
>
> I have tried this with V2.6 and V3
>
> Any ideas would be much appreciated.
>
> Thanks
> Neil

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


Re: Directory

2009-02-18 Thread gtillmon
On Feb 18, 3:39 pm, "Gabriel Genellina" 
wrote:
> En Wed, 18 Feb 2009 12:15:25 -0200, Steve Holden   
> escribió:
>
> > gtillmon wrote:
> >> I would like to know how to display and store the path of each mondule
> >> that is called.
> > It's certainly possible to trace function calls, if that would help.
> > sys.settrace allows you to establish a function that gets called
>
> If the OP is only interested in import statements, perhaps the -v flag is  
> enough:
>
> python -v script_name.py
>
> It prints a line (on stderr) for each module imported, stating its name  
> and source file.
>
> --
> Gabriel Genellina

Thanks for the information.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Directory

2009-02-18 Thread gtillmon
On Feb 18, 8:15 am, Steve Holden  wrote:
> gtillmon wrote:
> > Hello.  I am new to the Python language.
> > I would like to know how to display and store the path of each mondule
> > that is called.
>
> Modules are imported, not called.
>
> > Similar to the old READY TRACE in COBOL of long ago.
>
> It's certainly possible to trace function calls, if that would help.
> sys.settrace allows you to establish a function that gets called
> whenever a Python function call is executed. The documentation is a
> little sparse, but you can find a rough example under "Crude Python
> Debugging" in
>
>  http://www.st.ewi.tudelft.nl/~mol/snippets.php
>
> regards
>  Steve
> --
> Steve Holden        +1 571 484 6266   +1 800 494 3119
> Holden Web LLC              http://www.holdenweb.com/


Thanks for the information.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Revision Control

2009-02-18 Thread Tim Wintle
On Wed, 2009-02-18 at 09:08 -0800, Sam Clark wrote:
> Any suggestions for a beginer on what to use for version control?
> It's just me, the lone person programming.  I've already nailed one
> "version" of my code accidentaly.  MS VSS is too expensive for the
> stuff I'm doing, plus I really don't like MS much...  Any free open
> source stuff out there?

I use svn (subversion) at work and it works fine, but I'm using bazaar
 on my own code, and even alongside svn to help
with merging branches, porting code up-stream etc.

bazaar is really great in my experience, although relatively new so you
might prefer to stick to svn. I haven't tried using bazaar on windows.


If you do go with svn, try the latest version, since merging support is
much better in this.


Tim


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


Re: Newbie Q about Turtle Gfx

2009-02-18 Thread Neil
Thanks for the very speedy reply!

Not sure what your reply means but I have emailed the author with the 
problem!

Cheers

Neil

"sjbrown"  wrote in message 
news:9ba48cb7-d32b-40ef-a6a6-d22508863...@l33g2000pri.googlegroups.com...
It looks like there may be a bug if you were expecting t to be some
object other than a dict.  You can apparently contact the authour
here:

http://www.briggs.net.nz/log/contact/

On Feb 18, 2:16 pm, "Neil"  wrote:
> Hello
>
> Sorry if this is not an appropriate newsgroup for this problem. I am very
> new to Python but not new to programming.
>
> I am hoping to use Python to teach a class and have been looking at the
> online book 'Snake Wrangling for Kids'.
>
> I have followed the example
>
> >>>import turtle
> >>>t=turtle.pen()
>
> which works fine and displays a turtle in a window.
>
> However whenever I try to use something like
>
> >>>t.forward(50) (taken from the book)
>
> i get the error...
>
> Traceback (most recent call last):
> File "", line 1, in 
> t.forward(50)
> AttributeError: 'dict' object has no attribute 'forward'
>
> I get the same error with t.left(10) etc. etc.
>
> I have tried this with V2.6 and V3
>
> Any ideas would be much appreciated.
>
> Thanks
> Neil


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


Re: number theory libraries / project euler

2009-02-18 Thread Paul Rubin
eliben  writes:
> What are some good & recommended number theory libs for Python (or
> accessible interfaces to C libs), for things like primes,
> factorization, etc. Naturally, speed is of utmost importance here.

The idea of Project Euler is you are supposed to find clever enough
methods to solve the problems that speed of the software libs is NOT
important.  
--
http://mail.python.org/mailman/listinfo/python-list


Re: PyYaml in standard library?

2009-02-18 Thread Brendan Miller
On Wed, Feb 18, 2009 at 1:34 AM, Chris Rebert  wrote:
> On Wed, Feb 18, 2009 at 1:11 AM, Brendan Miller  wrote:
>> I'm just curious whether PyYaml is likely to end up in the standard
>> library at some point?
>
> I don't personally have a direct answer to your question, but I can
> point out that JSON and YAML are mostly compatible (JSON is almost a
> perfect YAML subset) and the `json` module is already in the Python
> std lib.
>
> Cheers,
> Chris

Yes, JSON is an (I think unintentional) subset of YAML... but a fairly
small subset.

A list in YAML looks like

--- # my list
- Elem 1
- Elem 2

Whereas in JSON you have ["Elem 1", "Elem 2"]. People say JSON is a
subset because YAML will also accept the JSON style syntax if you want
to do something inline for convenience:

--- # my list containing a sublist in the second element.
- Elem 1
- ["Sub elem 1", "Sub elem 2"]

But this is really a special purpose syntax in the context of YAML.

I think the json module sticks everything on the same line, which
isn't readable for large data structures. My impression is YAML is
that is is more readable than JSON, whereas JSON is mostly for browser
interop.
--
http://mail.python.org/mailman/listinfo/python-list


Re: number theory libraries / project euler

2009-02-18 Thread Mensanator
On Feb 18, 2:18 pm, eliben  wrote:
> Hello,
>
> What are some good & recommended number theory libs for Python (or
> accessible interfaces to C libs), for things like primes,
> factorization, etc. Naturally, speed is of utmost importance here.
>
> In other words, which Python libraries and tools to you use to help
> you solve Project Euler problems :-) ?
>
> Eli

Also check out the gmpy library, lots of good number theory stuff
like factorial, gcd, lcm, linear congruence, is_prime, next_prime,
(I even found a use for the legendre function), etc.

(no factorization, I have Python call the MIRACL factor program when
I need that)

gmpy is so vital to my work that if they ever stop supporting it,
I will abandon Python.
--
http://mail.python.org/mailman/listinfo/python-list


SVN/CVS and Branching

2009-02-18 Thread Jeff Dyke
Hello.  I am curious about different ideas on how you handle branching
your python projects.  With some other languages this is trivial, but
since python uses these directories as modules and i have the top
level module starting imports all over the place, i am wondering what
others do.  In the past we had retired the first branch and just moved
towards the new, but that is not possible now.

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


get descriptor from instance

2009-02-18 Thread Alan G Isaac

What is a reliable way to get the
the property object for an instance attribute?
(Or more generally, to get the descriptor
controlling an attribute?)

If class ``A`` defines the property ``x`` and ``a``
in an instance of ``A``, then you can just use
``type(a).__dict__['x']`` to get the property object.
But this will not work if the property is inherited.

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


Re: Newbie Q about Turtle Gfx

2009-02-18 Thread Scott David Daniels

Neil wrote:
Forgot to say, that after the error message the turtle window 'hangs' as 
unresponsive ...


"Neil"  wrote in message 
news:ifidnr_gysdmfqhunz2dnekdnzzin...@bt.com...

Hello
I am hoping to use Python to teach a class and have been looking at the 
online book 'Snake Wrangling for Kids'.


I have followed the example

import turtle
t=turtle.pen()

which works fine and displays a turtle in a window.

However whenever I try to use something like

t.forward(50)   (taken from the book)

i get the error...

Traceback (most recent call last):
 File "", line 1, in 
   t.forward(50)
AttributeError: 'dict' object has no attribute 'forward'



Well, if you
>>> print(turtle.__doc__)
You'll see that this is a re-implemetation, so expect a few hiccups.

I see, from the following:
>>> import turtle
>>> t = turtle.pen()
>>> print(repr(t))

The pen returned (which you named t) is a simple dictionary.
You can, however, follow up with:
>>> turtle.forward(23)
>>> turtle.right(90)
>>> turtle.forward(32)
>>> turtle.right(90)
>>> turtle.forward(23)
>>> turtle.right(90)
>>> turtle.forward(32)


Or, if you prefer, you can go:

>>> t = turtle.Turtle()
>>> t.forward(30)
>>> t.left(120)

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


Re: PyGTK install

2009-02-18 Thread Lionel
On Feb 18, 2:08 pm, Lionel  wrote:
> On Feb 18, 11:43 am, Lionel  wrote:
>
>
>
>
>
> > Hello folks, I couldn't find a specific PyGTK forum so I thought I'd
> > post here and hope someone new the answer. I feel it's a silly
> > problem, maybe something to do with a path variable? The problem: I've
> > downloaded the "all-in-one" windows binary installer for PyGTK from
> > their website. After typing in their first tutorial program and trying
> > to run from the command line, I get:
>
> > "This application has failed to start because libglib-2.0-0.dll was
> > not found" error dialog.
>
> > The traceback indicates this is happening at the "import gtk" line. A
> > quick search of my install directory for PyGTK indicates that the file
> > is indeed resident and located in C:\Program files\PyGTK\GTK\bin.
>
> > Is there some some sort of path variable for Python I need to modify
> > and, if so, how is this done? Thanks so much, and my apologies if this
> > is the wrong forum.
>
> > -L
>
> Well, I tried uninstalling / reinstalling PyGTK and now I'm getting a
> different traceback error:
>
> "ImportError: no module named pygtk"
>
> I checked and pygtk.py is located in "c:\Python25\Lib\site-packages".
> Then I displaye the sys.path:
>
> IDLE 1.2>>> import sys
> >>> sys.path
>
> ['C:\\Program Files\\PyGTK\\Python\\Lib\\idlelib', 'C:\\Program Files\
> \PyGTK\\Python\\python25.zip', 'C:\\Program Files\\PyGTK\\Python\
> \DLLs', 'C:\\Program Files\\PyGTK\\Python\\lib', 'C:\\Program Files\
> \PyGTK\\Python\\lib\\plat-win', 'C:\\Program Files\\PyGTK\\Python\\lib\
> \lib-tk', 'C:\\Program Files\\PyGTK\\Python', 'C:\\Program Files\\PyGTK
> \\Python\\lib\\site-packages']
>
> Every single entry is related to PyGTK and nothing else. Something
> seems wrong here but I don't have enough Python experience to know
> just what. Anyone?- Hide quoted text -
>
> - Show quoted text -

Okay, out of desperation and frustration I've wiped my Python/SciPy/
etc.. setup and reinstalled from scratch. I've tested it with my app
and all the numpy and matplotlib functionality is there and working.
My sys.path seems to be back to normal:

IDLE 1.2.4
>>> import sys
>>> sys.path
['C:\\Python25\\Lib\\idlelib', 'C:\\WINDOWS\\system32\\python25.zip',
'C:\\Python25\\DLLs', 'C:\\Python25\\lib', 'C:\\Python25\\lib\\plat-
win', 'C:\\Python25\\lib\\lib-tk', 'C:\\Python25', 'C:\\Python25\\lib\
\site-packages']

I will now re-install PyGTK and see if it mysteriously decides to work
this time.
--
http://mail.python.org/mailman/listinfo/python-list


fcntl.fcntl breaking on 64bit

2009-02-18 Thread PK
Hello Friends:

I'm running into issues with using fcntl on a 64 bit servers.

Python version: 2.4.3

system Arch: # uname -m
x86_64


code keeps erroring out with:

fcntl.fcntl(fd, rhn_fcntl.F_SETLKW, UNLOCK)
IOError: [Errno 22] Invalid argument

The same python code block runs fine on a i386/686.

Does anyone have any thoughts? Is this a known issue? any workarounds?

Any suggestions appreciated.

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


Re: Can't get the IPYthon ipapi object working

2009-02-18 Thread Robert Kern

On 2009-02-18 15:49, beetlecube wrote:

Hi , I found out from a random google search that I could use IPython
to automatically import modules so that I could test Django views.

I downloaded it (WIN XP), installed it.  I'm able to import it, but I
just can't seem to get the object working.

The code:
---
try:
 import IPython.ipapi
 ip = IPython.ipapi.get()
 a = ip.options
 ip.ex('import os')

except Exception,msg:
 print "Message: ", msg
---

I get: ' Message:  'NoneType' object has no attribute 'options' '

If I remove the ip.options statement, it will say the same thing about
attribute 'ex'


This needs to be run in the context of a running instance IPython, not just any 
other module. That kind of code is usually put into your c:\Documents and 
Settings\username\_ipython\ipy_user_conf.py file.


--
Robert Kern

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

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


Re: PyGTK install

2009-02-18 Thread Lionel
On Feb 18, 3:03 pm, Lionel  wrote:
> On Feb 18, 2:08 pm, Lionel  wrote:
>
>
>
>
>
> > On Feb 18, 11:43 am, Lionel  wrote:
>
> > > Hello folks, I couldn't find a specific PyGTK forum so I thought I'd
> > > post here and hope someone new the answer. I feel it's a silly
> > > problem, maybe something to do with a path variable? The problem: I've
> > > downloaded the "all-in-one" windows binary installer for PyGTK from
> > > their website. After typing in their first tutorial program and trying
> > > to run from the command line, I get:
>
> > > "This application has failed to start because libglib-2.0-0.dll was
> > > not found" error dialog.
>
> > > The traceback indicates this is happening at the "import gtk" line. A
> > > quick search of my install directory for PyGTK indicates that the file
> > > is indeed resident and located in C:\Program files\PyGTK\GTK\bin.
>
> > > Is there some some sort of path variable for Python I need to modify
> > > and, if so, how is this done? Thanks so much, and my apologies if this
> > > is the wrong forum.
>
> > > -L
>
> > Well, I tried uninstalling / reinstalling PyGTK and now I'm getting a
> > different traceback error:
>
> > "ImportError: no module named pygtk"
>
> > I checked and pygtk.py is located in "c:\Python25\Lib\site-packages".
> > Then I displaye the sys.path:
>
> > IDLE 1.2>>> import sys
> > >>> sys.path
>
> > ['C:\\Program Files\\PyGTK\\Python\\Lib\\idlelib', 'C:\\Program Files\
> > \PyGTK\\Python\\python25.zip', 'C:\\Program Files\\PyGTK\\Python\
> > \DLLs', 'C:\\Program Files\\PyGTK\\Python\\lib', 'C:\\Program Files\
> > \PyGTK\\Python\\lib\\plat-win', 'C:\\Program Files\\PyGTK\\Python\\lib\
> > \lib-tk', 'C:\\Program Files\\PyGTK\\Python', 'C:\\Program Files\\PyGTK
> > \\Python\\lib\\site-packages']
>
> > Every single entry is related to PyGTK and nothing else. Something
> > seems wrong here but I don't have enough Python experience to know
> > just what. Anyone?- Hide quoted text -
>
> > - Show quoted text -
>
> Okay, out of desperation and frustration I've wiped my Python/SciPy/
> etc.. setup and reinstalled from scratch. I've tested it with my app
> and all the numpy and matplotlib functionality is there and working.
> My sys.path seems to be back to normal:
>
> IDLE 1.2.4>>> import sys
> >>> sys.path
>
> ['C:\\Python25\\Lib\\idlelib', 'C:\\WINDOWS\\system32\\python25.zip',
> 'C:\\Python25\\DLLs', 'C:\\Python25\\lib', 'C:\\Python25\\lib\\plat-
> win', 'C:\\Python25\\lib\\lib-tk', 'C:\\Python25', 'C:\\Python25\\lib\
> \site-packages']
>
> I will now re-install PyGTK and see if it mysteriously decides to work
> this time.- Hide quoted text -
>
> - Show quoted text -

Nope. Now I'm getting:

"The applciation has failed to start because MSVCR80.dll was not
found."

Don't know what else to try here. Anyone have any ideas?
--
http://mail.python.org/mailman/listinfo/python-list


Re: get descriptor from instance

2009-02-18 Thread Gabriel Genellina
En Wed, 18 Feb 2009 20:48:17 -0200, Alan G Isaac   
escribió:



What is a reliable way to get the
the property object for an instance attribute?
(Or more generally, to get the descriptor
controlling an attribute?)

If class ``A`` defines the property ``x`` and ``a``
in an instance of ``A``, then you can just use
``type(a).__dict__['x']`` to get the property object.
But this will not work if the property is inherited.


type(a).x

py> class A(object):
...   def getx(self): return 1
...   x = property(getx)
...
py> class B(A):
...   pass
...
py> b=B()
py> b.x
1
py> B.x

py> type(b).x

py> getattr(type(b),'x')

py>

--
Gabriel Genellina

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


Re: Newbie Q about Turtle Gfx

2009-02-18 Thread Mensanator
On Feb 18, 4:16 pm, "Neil"  wrote:
> Hello
>
> Sorry if this is not an appropriate newsgroup for this problem. I am very
> new to Python but not new to programming.
>
> I am hoping to use Python to teach a class and have been looking at the
> online book 'Snake Wrangling for Kids'.
>
> I have followed the example
>
> >>>import turtle
> >>>t=turtle.pen()

You defined "t" to be a pen object, not a turtle object.

>
> which works fine and displays a turtle in a window.
>
> However whenever I try to use something like
>
> >>>t.forward(50)   (taken from the book)

Pens don't move, turtles move (and the pen the turtle is
carrying draws a line, if down).

>
> i get the error...
>
> Traceback (most recent call last):
>   File "", line 1, in 
>     t.forward(50)
> AttributeError: 'dict' object has no attribute 'forward'
>
> I get the same error with t.left(10) etc. etc.

Pens can't turn left, turtles turn left.

>
> I have tried this with V2.6 and V3
>
> Any ideas would be much appreciated.
>
> Thanks
> Neil

Here's an example. It draws a Minimal Spanning Tree.

If you don't need an MST, take note of how I use the turtle.

import turtle
import random
import copy

def build_sv(start,stop,limit,C):
  """Sequence Vector Generator

  build_sv(start,stop,limit,C)
  start: start of Collatz sequence (must be odd)
  stop:  sequence termination
  limit: max length of [sv] if stop not found
   limit is sum(sv), not len(sv)
  C: C of 3n+C
  returns [] if invalid
  returns SequenceVector [sv]
  """
  ONE = 1
  TWO = 2
  TWE = 3

  sv = []
  if (start % 2)==0: return sv
  done = 0
  count = 0
  while done==0:
#
# oops, power division may skip past stopping point
# without seeing it
#
start = TWE*start + C
f = 0
t = start
while t%2==0:
  f += 1
  t /= 2
g = 0  # stopping point may occur before f is
reached
while (not done) and g> 1
  if start==stop: done = 1
  count += 1
  g += 1
  if count==limit: done = 1
sv.append(g)
  return sv

def Type12MH(k,i):
  """Find ith, kth Generation Type [1,2] Mersenne Hailstone using the
closed form equation

  Type12MH(k,i)
  k: generation
  i: member of generation
  returns Hailstone (a)
  """
  ONE = 1
  TWO = 2
  SIX = 6
  NIN = 9

  if (k<1) or (i<1): return 0

  a = (i-ONE)*NIN**(k-ONE) + (NIN**(k-ONE) - ONE)/TWO + ONE
  return TWO**(SIX*a - ONE) - ONE



turtle.clear()
turtle.up()

the_window = (turtle.window_width(),turtle.window_height())
print the_window,
turtle.goto(0,0)
tooter = turtle.position()
buffer_L = -((the_window[0]-200)/2)
buffer_R = (the_window[0]-200)/2
buffer_T = (the_window[1]-200)/2
buffer_B = -((the_window[1]-200)/2)
print buffer_L,buffer_R,buffer_T,buffer_B

turtle.tracer(False)
turtle.down()
turtle.speed('fastest')
t = 0
turtle.setheading(t)

for j in range(1):
  p = Type12MH(4,2)  # Type12 Mersenne Hailstone (very big)
  sv = build_sv(p,1,1000,1) # limit to 10 million numbers in
vector


# Minimal Spanning Tree
  stars = []
  turtle.up()
  for d in sv: # random turtle crawl based on
sv
if d>1:  # skip small sv values for
movement
  for r in xrange(1):
turtle.setheading(t+r*90)
turtle.forward(d*4)  # scale of grid
  tooter = turtle.position()
  if d>8:  # create a star at really large sv
values
turtle.down()
turtle.width(3)
turtle.color('black')
turtle.forward(1)# draw a blob
turtle.backward(1)
stars.append((int(tooter[0]),int(tooter[1])))
turtle.up()
turtle.width(1)
turtle.color('red')  # color of MST spans
  whither_tooter = []  # build list of legal next turns
  if tooter[0]>buffer_L:   # test for being too close to
screen edge
whither_tooter.append(180)
  if tooter[0]buffer_B:
whither_tooter.append(270)
  t = random.choice(whither_tooter) # choose random direction from
list of legal moves
  print 'stars:',len(stars)

  star_dist = []  # create list of spans between
stars
  for i,src in enumerate(stars):
for j,dst in enumerate(stars):
  dist = turtle.sqrt((src[0]-dst[0])**2 + (src[1]-dst[1])**2)
  if dist == 0:
star_dist.append([,i,j])
  else:
star_dist.append([dist,i,j])

  star_dist.sort()

  MST = []# spans of MST
  MST2 = []   # only those spans that can
connect to existing MST
  points_used = {}# list of stars that are
currently on MST

  s = copy.deepcopy(star_dist[0]) # going to modify list element,
so deep copy needed
  MST.append(s)   # fist span always smallest
absolute distance
  points_used[s[1]] = 1
  points_used[s[2]] = 1
  star_dist[0][0] =   # overwrite distance so this
span can't be used again
  found = False   # also, overwrite complemen

Re: numpy.memmap advice?

2009-02-18 Thread sturlamolden
On 18 Feb, 00:08, Lionel  wrote:

> 1) What is "recarray"?

An ndarray of what C programmers know as a "struct", in which each
field is accessible by its name.

That is,

struct rgba{
  unsigned char r;
  unsigned char g;
  unsigned char b;
  unsigned char a;
};

struct rgba arr[480][640];

is similar to:

import numpy as np
rbga = np.dtype({'names':list('rgba'), 'formats':[np.uint8]*4})
arr = np.array((480,640), dtype=rgba)

Now you can access the r, g, b and a fields directly using arr['r'],
arr['g'], arr['b'], and arr['a'].
Internally the data will be represented compactly as with the C code
above. If you want to view the data as an 480 x 640 array of 32 bit
integers instead, it is as simple as arr.view(dtype=np.uint32).
Formatted binary data can of course be read from files using
np.fromfile with the specified dtype, and written to files by passing
a recarray as buffer to file.write. You can thus see NumPy's
recarray's as a more powerful alternative to Python's struct module.


> I don't really see in the diocumentation how portions are loaded, however.

Prior to Python 2.6, the mmap object (which numpy.memmap uses
internally) does not take an offset parameter. But when NumPy are
ported to newer version of Python this will be fixed. You should then
be able to memory map with an ndarray from a certain offset. To make
this work now, you must e.g. backport mmap from Python 2.6 and use
that with NumPy. Not difficult, but nobody has bothered to do it (as
far as I know).



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


Re: Newbie Q about Turtle Gfx

2009-02-18 Thread Neil
Thanks everyone!

It appears the info in the book is wrong. Trying what you have all suggested
has got it to work!

Many thanks, and I am sure I will be back here again with other newbie
problems!

Neil

"Neil"  wrote in message 
news:ifidnr_gysdmfqhunz2dnekdnzzin...@bt.com...
> Hello
>
> Sorry if this is not an appropriate newsgroup for this problem. I am very 
> new to Python but not new to programming.
>
> I am hoping to use Python to teach a class and have been looking at the 
> online book 'Snake Wrangling for Kids'.
>
> I have followed the example
>
import turtle
t=turtle.pen()
>
> which works fine and displays a turtle in a window.
>
> However whenever I try to use something like
>
t.forward(50)   (taken from the book)
>
> i get the error...
>
> Traceback (most recent call last):
>  File "", line 1, in 
>t.forward(50)
> AttributeError: 'dict' object has no attribute 'forward'
>
> I get the same error with t.left(10) etc. etc.
>
> I have tried this with V2.6 and V3
>
> Any ideas would be much appreciated.
>
> Thanks
> Neil
>
>
> 


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


Re: Can't get the IPYthon ipapi object working

2009-02-18 Thread beetlecube
On Feb 18, 3:12 pm, Robert Kern  wrote:
> On 2009-02-18 15:49, beetlecube wrote:
>
>
>
> > Hi , I found out from a random google search that I could use IPython
> > to automatically import modules so that I could test Django views.
>
> > I downloaded it (WIN XP), installed it.  I'm able to import it, but I
> > just can't seem to get the object working.
>
> > The code:
> > ---
> > try:
> >      import IPython.ipapi
> >      ip = IPython.ipapi.get()
> >      a = ip.options
> >      ip.ex('import os')
>
> > except Exception,msg:
> >      print "Message: ", msg
> > ---
>
> > I get: ' Message:  'NoneType' object has no attribute 'options' '
>
Shoulda know I was doing something fundamentally wrong.
Thanks a lot!
> > If I remove the ip.options statement, it will say the same thing about
> > attribute 'ex'
>
> This needs to be run in the context of a running instance IPython, not just 
> any
> other module. That kind of code is usually put into your c:\Documents and
> Settings\username\_ipython\ipy_user_conf.py file.
>
> --
> Robert Kern
>
> "I have come to believe that the whole world is an enigma, a harmless enigma
>   that is made terrible by our own mad attempt to interpret it as though it 
> had
>   an underlying truth."
>    -- Umberto Eco

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


Re: Threading and tkinter

2009-02-18 Thread gert
On Feb 18, 8:25 am, "Hendrik van Rooyen"  wrote:
> "gert" wrote:
>
> > After reading the docs and seeing a few examples i think this should
> > work ?
> > Am I forgetting something here or am I doing something stupid ?
> > Anyway I see my yellow screen, that has to count for something :)
>
> > from tkinter import *
> > from threading import Thread
>
> > class Weegbrug(Thread):
> >     def __init__(self,v):
> >         self.v=v
> >         Thread.__init__(self)
> >     def run(self):
> >         while True:
> >             with open('com1','r') as f:
> >                  for line in f:
> >                      self.v.set(line[2:-1])
>
> It is in general not a good idea to directly
> access GUI variables from outside the
> GUI main loop.
> There is a recipe for doing this sort of thing,
> but as usual I have lost the reference.
> What it does is that instead of interfering directly
> as above, you put the data on a queue.
>
> Then, you use the after() call to set up a call
> to a routine that reads the queue, and configures the
> display, and then uses after again to call itself again
> after a time, thereby keeping the GUI stuff in the GUI
> mainloop.
>

from tkinter import *
from threading import Thread

class Weegbrug(Thread):
def __init__(self):
self.display='0'
Thread.__init__(self)
def run(self):
x=0
while True:
x=x+1
self.display=x
#with open('com1','r') as f:
# for l in f:
# self.display=l[2:-1]

root = Tk()
v = StringVar()
v.set('0')
w = Weegbrug()
w.start()
tx = Label(root, textvariable=v, width=800, height=600, bg='yellow',
font=('Helvetica', 300))
tx.pack(expand=YES, fill=BOTH)
root.title('Weegbrug')
root.overrideredirect(1)
root.geometry('%dx%d+0+0' % (root.winfo_screenwidth(),
root.winfo_screenheight()))
root.after(500, v.set(w.display))
root.mainloop()

Why does this not work ?
It only shows one result ?
--
http://mail.python.org/mailman/listinfo/python-list


Calling a class instance like a function

2009-02-18 Thread Uberman
I'm wondering if there's a way to invoke a "function" operator on a Python
class instance.  For example, given a class instance:

myClass = MyClass()

I want to call that instance like a function, with an argument value:

myClass(5.0)

I can override the "()" operator in C++, so I'm wondering if there's a way to
do it in Python as well.

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


Re: SVN/CVS and Branching

2009-02-18 Thread andrew cooke

maybe this is just me, but i don't have a clue what your problem is.  what
does "starting imports all over the place" mean?  what do you mean by
"retired"?

i use svn with python in exactly the same way as with java (and, i
thought, in the same way as anyone uses svn with any language; java uses
the directory structure as a package structure too).

maybe someone else will reply, but if not it might help to explain a
little more detail.

andrew


Jeff Dyke wrote:
> Hello.  I am curious about different ideas on how you handle branching
> your python projects.  With some other languages this is trivial, but
> since python uses these directories as modules and i have the top
> level module starting imports all over the place, i am wondering what
> others do.  In the past we had retired the first branch and just moved
> towards the new, but that is not possible now.


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


Re: Calling a class instance like a function

2009-02-18 Thread Filip Gruszczyński
__call__

2009/2/19 Uberman :
> I'm wondering if there's a way to invoke a "function" operator on a Python
> class instance.  For example, given a class instance:
>
>myClass = MyClass()
>
> I want to call that instance like a function, with an argument value:
>
>myClass(5.0)
>
> I can override the "()" operator in C++, so I'm wondering if there's a way to
> do it in Python as well.
>
> Thanks!
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Filip Gruszczyński
--
http://mail.python.org/mailman/listinfo/python-list


  1   2   >