Re: for x,y in word1, word2 ?

2008-08-11 Thread Jon Clements
On Aug 11, 5:40 am, Mensanator <[EMAIL PROTECTED]> wrote:
> On Aug 10, 11:18 pm, ssecorp <[EMAIL PROTECTED]> wrote:
>
> > Is there a syntax for looping through 2 iterables at the same time?
>
> > for x in y:
> > for a in b:
>
> > is not what I want.
>
> > I want:
> > for x in y and for a in b:
>
> Something like this?
>
> >>> a = ['a','b','c']
> >>> b = [1,2,3]
> >>> zip(a,b)
>
> [('a', 1), ('b', 2), ('c', 3)]

I would have thought the difflib library and SequenceMatcher would do
(more than) what you're after.

Just an idea anyway,

Jon.

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


Re: Wildcards for regexps?

2008-08-11 Thread Diez B. Roggisch

ssecorp schrieb:

If I have an expression like "bob marley" and I want to match
everything with one letter wrong, how would I do?
so "bob narely" and "vob marley" should match etc.


Fuzzy matching is better done using Levensthein-distance [1] or 
n-gram-matching [2].



Diez


[1] http://en.wikipedia.org/wiki/Levenshtein_distance
[2] http://en.wikipedia.org/wiki/Ngram#n-grams_for_approximate_matching
--
http://mail.python.org/mailman/listinfo/python-list


Re: for x,y in word1, word2 ?

2008-08-11 Thread [EMAIL PROTECTED]
On Aug 10, 11:14 pm, ssecorp <[EMAIL PROTECTED]> wrote:
> On Aug 11, 6:40 am, Mensanator <[EMAIL PROTECTED]> wrote:
>
>
>
> > On Aug 10, 11:18 pm, ssecorp <[EMAIL PROTECTED]> wrote:
>
> > > Is there a syntax for looping through 2 iterables at the same time?
>
> > > for x in y:
> > > for a in b:
>
> > > is not what I want.
>
> > > I want:
> > > for x in y and for a in b:
>
> > Something like this?
>
> > >>> a = ['a','b','c']
> > >>> b = [1,2,3]
> > >>> zip(a,b)
>
> > [('a', 1), ('b', 2), ('c', 3)]
>
> I know zip but lets say I have a word "painter" and I want to compare
> it to a customer's spelling, he might have written "paintor" and I
> want to check how many letters are the same.
>
> Now I know how I could do this, it is not hard.
> I am just wondering if these is any specific simple syntax for it.

There are two answers: first, if your domain interest is spell-
checking, search for "phonetic algorithm" or "soundex python". If your
interest is iteration, check out itertools - AFAIK this is the closest
you will get to a simple syntax for iterating over the diagonal as
opposed to the Cartesian product.

>>> from itertools import *
>>> for x,y in izip('painter','paintor'):
...   print x == y
...

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


Re: for x,y in word1, word2 ?

2008-08-11 Thread Marc 'BlackJack' Rintsch
On Sun, 10 Aug 2008 23:14:50 -0700, ssecorp wrote:

> I know zip but lets say I have a word "painter" and I want to compare it
> to a customer's spelling, he might have written "paintor" and I want to
> check how many letters are the same.
> 
> Now I know how I could do this, it is not hard. I am just wondering if
> these is any specific simple syntax for it.

No special syntax for that, but you can combine the `sum()` function, a 
generator expression and `zip()`:

In [40]: sum(int(a == b) for a, b in zip('painter', 'paintor'))
Out[40]: 6

Or this way if you think it's more clear:

In [41]: sum(1 for a, b in zip('painter', 'paintor') if a == b)
Out[41]: 6

Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list


Re: adding python libraries (for shared hosting)

2008-08-11 Thread Diez B. Roggisch

Joseph schrieb:

Hi all,
My shared host provides python 2.3. Since it is a shared hosting, he
is not willing to upgrade to a newer version.


He doesn't need to upgrade, he can install in parallel.


I am looking for option to upload 2.5 on my own. Is this possible and
if so, can anyone please provide a pointer to how this can be
achieved?


If you have a compiler available at the shared host & a shell-account, 
download Python and install, as told in the readmes.


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


Re: "shelve" save object

2008-08-11 Thread alex23
hypermonkey2 wrote:
> In any case, I shelve into a file "test.txt". I notice that when i try
> running the program on a different computer (by either emailing or
> transfering the file "test.txt" via USB key), the program is unable to
> load the shelve file.

You might find the 3rd party module 'shove' is more suitable for your
needs here.

http://pypi.python.org/pypi/shove

It provides a lot more backend support than shelve, of particular
interest to you would be filesystem (& maybe sqlite).

>>> from shove import Shove
>>> fsdb = Shove('file://persistent.db')
>>> fsdb['key1'] = 'value1'
>>> fsdb.close()

In this example, using the file protocol will produce a
'persistent.db' folder with the key/value pairs stored within it as
files. This should be cross platform enough for your needs.
--
http://mail.python.org/mailman/listinfo/python-list


updating dictionaries from/to dictionaries

2008-08-11 Thread Brandon
Hi all,

I am not altogether experienced in Python, but I haven't been able to
find a good example of the syntax that I'm looking for in any tutorial
that I've seen.  Hope somebody can point me in the right direction.

This should be pretty simple:  I have two dictionaries, foo and bar.
I am certain that all keys in bar belong to foo as well, but I also
know that not all keys in foo exist in bar.  All the keys in both foo
and bar are tuples (in the bigram form ('word1', 'word2)).  I have to
prime foo so that each key has a value of 1.  The values for the keys
in bar are variable integers.  All I want to do is run a loop through
foo, match any of its keys that also exist in bar, and add those key's
values in bar to the preexisting value of 1 for the corresponding key
in foo.  So in the end the key,value pairs in foo won't necessarily
be, for example, 'tuple1: 1', but also 'tuple2: 31' if tuple2 had a
value of 30 in bar.

I *think* the get method might work, but I'm not sure that it can work
on two dictionaries the way that I'm getting at.  I thought that
converting the dictionaries to lists might work, but I can't see a way
yet to match the tuple key as x[0][0] in one list for all y in the
other list.  There's just got to be a better way!

Thanks for any help,
Brandon
(trying hard to be Pythonic but isn't there yet)
--
http://mail.python.org/mailman/listinfo/python-list


Re: updating dictionaries from/to dictionaries

2008-08-11 Thread Calvin Spealman
for k in foo:
  foo[k] += bar.get(k, 0)

On Mon, Aug 11, 2008 at 3:27 AM, Brandon <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I am not altogether experienced in Python, but I haven't been able to
> find a good example of the syntax that I'm looking for in any tutorial
> that I've seen.  Hope somebody can point me in the right direction.
>
> This should be pretty simple:  I have two dictionaries, foo and bar.
> I am certain that all keys in bar belong to foo as well, but I also
> know that not all keys in foo exist in bar.  All the keys in both foo
> and bar are tuples (in the bigram form ('word1', 'word2)).  I have to
> prime foo so that each key has a value of 1.  The values for the keys
> in bar are variable integers.  All I want to do is run a loop through
> foo, match any of its keys that also exist in bar, and add those key's
> values in bar to the preexisting value of 1 for the corresponding key
> in foo.  So in the end the key,value pairs in foo won't necessarily
> be, for example, 'tuple1: 1', but also 'tuple2: 31' if tuple2 had a
> value of 30 in bar.
>
> I *think* the get method might work, but I'm not sure that it can work
> on two dictionaries the way that I'm getting at.  I thought that
> converting the dictionaries to lists might work, but I can't see a way
> yet to match the tuple key as x[0][0] in one list for all y in the
> other list.  There's just got to be a better way!
>
> Thanks for any help,
> Brandon
> (trying hard to be Pythonic but isn't there yet)
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Read my blog! I depend on your acceptance of my opinion! I am interesting!
http://ironfroggy-code.blogspot.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Second python program: classes, sorting

2008-08-11 Thread Eric Brunel
Others have replied to your original question. As an aside, just a few  
stylistic notes:



class Score:
 def __init__(self, name_, score_):
 self.name = name_
 self.score = score_


These trailing underscores look like a habit from another language. They  
are unneeded in Python; you can write:

class Score:
 def __init__(self, name, score):
 self.name = name
 self.score = score
That's an advantage of the explicit self: no ambiguity between local  
variables and attributes.



try:
 infile = open(filename, "r")
except IOError, (errno, strerror):
 print "IOError caught when attempting to open file %s. errno = %d,  
strerror = %s" % (filename, errno, strerror)

 exit(1)


This try/except block is unneeded too: what you do with the exception is  
more or less the same as the regular behaviour (print an error message and  
exit), except your error message is far less informative than the default  
one, and printed to stdout instead of stderr. I would remove the entire  
try/except block and just write:

infile = open(filename, "r")

HTH
--
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"

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


Re: Eclipse, Python, wxPython and code completion

2008-08-11 Thread leon . domingo
On 11 ago, 04:34, "SPE - Stani's Python Editor"
<[EMAIL PROTECTED]> wrote:
> On 10 aug, 20:42, [EMAIL PROTECTED] wrote:
>
>
>
> > Hello,
>
> > I've installed Eclipse, Python 2.5 and wxPython on Ubuntu 8.04. The
> > problem is that I can't get code completion for wx module. I don't
> > know if it occurs the same with other libraries outside the python
> > "core".
>
> > If I compile/run my code containing the wx library, I get an
> > application running correctly, so it looks that definition works fine.
> > Obviously, the obstacle is that I don't know (I don't want to either)
> > the name of every method of every wxPython class so it's difficult to
> > develop anything within this environment.
>
> > Thanks a lot
>
> > Note: I'm a newbie-coming-from-"Billy's"-WindowsXP
>
> You can try SPE which is written in wxPython itself and has very good
> code completion for wxPython. It also includes some wxPython GUI
> builders such as wxGlade and XRCed. I improved it a lot for Hardy,
> which I use myself:
> sudo apt-get install spe
>
> Stani

Thanks, Stani

I will check this out
--
http://mail.python.org/mailman/listinfo/python-list


Re: benchmark

2008-08-11 Thread M8R-n7vorv
On Aug 10, 10:10 pm, Kris Kennaway <[EMAIL PROTECTED]> wrote:
> jlist wrote:
> > I think what makes more sense is to compare the code one most
> > typically writes. In my case, I always use range() and never use psyco.
> > But I guess for most of my work with Python performance hasn't been
> > a issue. I haven't got to write any large systems with Python yet, where
> > performance starts to matter.
>
> Hopefully when you do you will improve your programming practices to not
> make poor choices - there are few excuses for not using xrange ;)
>
> Kris

And can you shed some light on how that relates with one of the zens
of python ?

There should be one-- and preferably only one --obvious way to do it.

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


Re: updating dictionaries from/to dictionaries

2008-08-11 Thread John Machin
On Aug 11, 6:24 pm, "Calvin Spealman" <[EMAIL PROTECTED]> wrote:
> for k in foo:
>   foo[k] += bar.get(k, 0)

An alternative:

for k in bar:
   foo[k] += bar[k]

The OP asserts that foo keys are a superset of bar keys. If that
assertion is not true (i.e. there are keys in bar that are not in foo,
your code will silently ignore them whereas mine will cause an
exception to be raised (better behaviour IMHO). If the assertion is
true, mine runs faster (even when len(foo) == len(bar).
--
http://mail.python.org/mailman/listinfo/python-list


Re: benchmark

2008-08-11 Thread cokofreedom
On Aug 11, 10:55 am, [EMAIL PROTECTED] wrote:
> On Aug 10, 10:10 pm, Kris Kennaway <[EMAIL PROTECTED]> wrote:
>
> > jlist wrote:
> > > I think what makes more sense is to compare the code one most
> > > typically writes. In my case, I always use range() and never use psyco.
> > > But I guess for most of my work with Python performance hasn't been
> > > a issue. I haven't got to write any large systems with Python yet, where
> > > performance starts to matter.
>
> > Hopefully when you do you will improve your programming practices to not
> > make poor choices - there are few excuses for not using xrange ;)
>
> > Kris
>
> And can you shed some light on how that relates with one of the zens
> of python ?
>
> There should be one-- and preferably only one --obvious way to do it.
>
> Dhananjay

And that is xrange, but if you need a list range is better :P
--
http://mail.python.org/mailman/listinfo/python-list


Printing a text file using Python

2008-08-11 Thread Robin Lee
Serge:
in your code i believe that you did one read of your whole input file, and then 
you emitted that to the dc with textout. textout's use  is actually 
(x,y,string).
hence one line got printed (actually the whole file got printed but 
truncated)
you will have to detect all the end of lines and loop a whole lot of dc.textouts

Robin

your code:

dc = win32ui.CreateDC()
  dc.CreatePrinterDC()
dc.SetMapMode(4)# This is UI_MM_LOENGLISH
# With this map mode, 12 points is 12*100/72 units = 16
font = win32ui.CreateFont({'name' : 'Arial', 'height' : 16})
dc.SelectObject(font)
f=open("./Reports/Report.txt","r")
memory=f.read()
f.close
memory.split('\n')
dc.StartDoc("./Reports/Report.txt")
dc.StartPage()
dc.TextOut(10,10,memory)
dc.EndPage()
dc.EndDoc()
--
http://mail.python.org/mailman/listinfo/python-list

Digitally sign PDF files

2008-08-11 Thread haxier
Hi all

I'm developing an application with some reports and we're looking for
advice. This reports should be openoffice.org .odf files, pdf files,
and perhaps microsoft word files (.doc, .docx?) and must be digitally
signed. Is out there some kind of libraries to ease this tasks?

* Access to the local user certificate store, and read PEM or PKCS12
certificate files.
* Read, parse and validate user certificates
* Sign documents: as a binary stream, within an specific document
(pdf, odt, doc)

I've been googling and found very few documentation about this --
except some examples using jython and ironpython.

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


Re: ANN: P4D 1.2

2008-08-11 Thread Gerhard Häring

Kay Schluehr wrote:

P4D = E4X style embedded DSL for Python but without E and X.
The main feature of P4D 1.2 are *Bytelets*. While the primary purpose
of P4D 1.1 was the support textual data which can be considered as
isomorphic to XML the new release is focussed on binary data. Bytelets
are P4D objects that are assembled from hexcode which is reified as a
Hex object. [...]


I am not supposed to understand any of this, right?

-- Gerhard

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


Re: benchmark

2008-08-11 Thread Peter Otten
[EMAIL PROTECTED] wrote:

> On Aug 10, 10:10 pm, Kris Kennaway <[EMAIL PROTECTED]> wrote:
>> jlist wrote:
>> > I think what makes more sense is to compare the code one most
>> > typically writes. In my case, I always use range() and never use psyco.
>> > But I guess for most of my work with Python performance hasn't been
>> > a issue. I haven't got to write any large systems with Python yet,
>> > where performance starts to matter.
>>
>> Hopefully when you do you will improve your programming practices to not
>> make poor choices - there are few excuses for not using xrange ;)
>>
>> Kris
> 
> And can you shed some light on how that relates with one of the zens
> of python ?
> 
> There should be one-- and preferably only one --obvious way to do it.

For the record, the impact of range() versus xrange() is negligable -- on my
machine the xrange() variant even runs a tad slower. So it's not clear
whether Kris actually knows what he's doing.

For the cases where xrange() is an improvement over range() "Practicality
beats purity" applies. But you should really care more about the spirit
than the letter of the "zen".

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

Re: benchmark

2008-08-11 Thread M8R-n7vorv
On Aug 11, 2:09 pm, [EMAIL PROTECTED] wrote:
> On Aug 11, 10:55 am, [EMAIL PROTECTED] wrote:
>
>
>
> > On Aug 10, 10:10 pm, Kris Kennaway <[EMAIL PROTECTED]> wrote:
>
> > > jlist wrote:
> > > > I think what makes more sense is to compare the code one most
> > > > typically writes. In my case, I always use range() and never use psyco.
> > > > But I guess for most of my work with Python performance hasn't been
> > > > a issue. I haven't got to write any large systems with Python yet, where
> > > > performance starts to matter.
>
> > > Hopefully when you do you will improve your programming practices to not
> > > make poor choices - there are few excuses for not using xrange ;)
>
> > > Kris
>
> > And can you shed some light on how that relates with one of the zens
> > of python ?
>
> > There should be one-- and preferably only one --obvious way to do it.
>
> > Dhananjay
>
> And that is xrange, but if you need a list range is better :P

Interesting to read from PEP-3000 : "Python 2.6 will support forward
compatibility in the following two ways:

* It will support a "Py3k warnings mode" which will warn
dynamically (i.e. at runtime) about features that will stop working in
Python 3.0, e.g. assuming that range() returns a list."
--
http://mail.python.org/mailman/listinfo/python-list


How to execute commands in internal zones of solaris using python running from the global zone ?

2008-08-11 Thread Hishaam
How to execute commands in internal zones of solaris using python
running from the global zone ?

i tried --
1> os.popen("zlogin ")
2> os.popen("zonename")

the 2nd command executes back into the global zone and not into the
internal zone
can anyone help?


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


DATICS'09 - Call For Papers

2008-08-11 Thread SS DATICS
Apologies for any multiple copies received. We would appreciate it if
you could distribute the following call for papers to any relevant mailing
lists you know
of.
--

DATICS: Design, Analysis and Tools for Integrated Circuits and
Systems event was created by a network of researchers and engineers
both from academia and industry. The first edition took place in Crete
Island, Greece, July 22-24, 2008 (
http://digilander.libero.it/systemcfl/datics).

Main target of DATICS'09 is to bring together
software/hardware engineering researchers, computer scientists,
practitioners and people from industry to exchange theories, ideas,
techniques and experiences related to all areas of design, analysis
and tools for integrated circuits (e.g. digital, analog and
mixed-signal circuits) and systems (e.g. real-time, hybrid and
embedded systems).

DATICS'09 also focuses on the field of formal methods, wireless sensor
networks (WSNs) and low power design methodologies for integrated circuits
and systems.


Topics of interest include, but are not limited to, the following:

* digital, analog, mixed-signal designs and test
* RF design and test
* design-for-testability and built-in self test methodologies
* reconfigurable system design
* high-level synthesis
* EDA tools for design, testing and verification
* low power design methodologies
* network and system on-a-chip
* application-specific SoCs
* wireless sensor networks (WSNs)
* specification languages: SystemC, SystemVerilog and UML
* all areas of modelling, simulation and verification
* formal methods and formalisms (e.g. process algebras, petri-nets,
automaton theory and BDDs)
* real-time, hybrid and embedded systems
* software engineering (including real-time Java, real-time UML and
performance metrics)


DATICS'09 has been organised into two special sessions:

* DATICS-IMECS'09
  (http://digilander.libero.it/systemcfl/datics09-imecs) will
  be hosted by the International MultiConference of Engineers and
  Computer Scientists 2009 (IMECS'09) which will take place in Hong
Kong, 18-20 March, 2009.

* DATICS-ICIEA'09
  (http://digilander.libero.it/systemcfl/datics09-iciea) will
  be hosted by the 4th IEEE Conference on
  Industrial Electronics and Applications (ICIEA'09) which will
  take place in Xi'an, China, 25-27 May, 2009.


Please visit the DATICS-IMECS'09 and  DATICS-ICIEA'09 websites for
paper submission guidelines, proceedings, publication indexing,
submission deadlines, International Program Committee and sponsors.

For any additional information, please contact

Dr. K.L. Man
University College Cork (UCC), Ireland
Email: [EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list

paretovariate

2008-08-11 Thread zhjchen

I want to realize a list of numbers. They follow pareto distribution.
For instance, the average value is 10 and alpha is 1.0
I do not know how to use the function of paretovariate(alpha). It only provides
alpha parameter. How should I set the average value?


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


Re: SSH utility

2008-08-11 Thread Alan Franzoni
James Brady was kind enough to say:

> Hi all,
> I'm looking for a python library that lets me execute shell commands
> on remote machines.
> 
> I've tried a few SSH utilities so far: paramiko, PySSH and pssh;
> unfortunately all been unreliable, and repeated questions on their
> respective mailing lists haven't been answered...

Twisted conch seems to be your last chance :-) 

-- 
Alan Franzoni <[EMAIL PROTECTED]>
-
Remove .xyz from my email in order to contact me.
-
GPG Key Fingerprint:
5C77 9DC3 BD5B 3A28 E7BC 921A 0255 42AA FE06 8F3E
--
http://mail.python.org/mailman/listinfo/python-list


Re: benchmark

2008-08-11 Thread Kris Kennaway

Peter Otten wrote:

[EMAIL PROTECTED] wrote:


On Aug 10, 10:10 pm, Kris Kennaway <[EMAIL PROTECTED]> wrote:

jlist wrote:

I think what makes more sense is to compare the code one most
typically writes. In my case, I always use range() and never use psyco.
But I guess for most of my work with Python performance hasn't been
a issue. I haven't got to write any large systems with Python yet,
where performance starts to matter.

Hopefully when you do you will improve your programming practices to not
make poor choices - there are few excuses for not using xrange ;)

Kris

And can you shed some light on how that relates with one of the zens
of python ?

There should be one-- and preferably only one --obvious way to do it.


For the record, the impact of range() versus xrange() is negligable -- on my
machine the xrange() variant even runs a tad slower. So it's not clear
whether Kris actually knows what he's doing.


You are only thinking in terms of execution speed.  Now think about 
memory use.  Using iterators instead of constructing lists is something 
that needs to permeate your thinking about python or you will forever be 
writing code that wastes memory, sometimes to a large extent.


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


Re: SSH utility

2008-08-11 Thread Kris Kennaway

James Brady wrote:

Hi all,
I'm looking for a python library that lets me execute shell commands
on remote machines.

I've tried a few SSH utilities so far: paramiko, PySSH and pssh;
unfortunately all been unreliable, and repeated questions on their
respective mailing lists haven't been answered...

It seems like the sort of commodity task that there should be a pretty
robust library for. Are there any suggestions for alternative
libraries or approaches?


Personally I just Popen ssh directly.  Things like paramiko make me 
concerned; getting the SSH protocol right is tricky and not something I 
want to trust to projects that have not had significant experience and 
auditing.


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


Jordan 3 paypal payment $28/pairs www.mall-aol.com ( http://photo.163.com/photos/huayuexiehang/106616893/ )

2008-08-11 Thread micahel
 Please chat with me by www.mall-aol.comto get the price and more
photos,  we take paypal payment $28/pairs as payment. please see the
photo album below for our product list.

jordan shoes paypal payment $28/pairs  www.mall-aol.com (
http://photo.163.com/photos/huayuexiehang/118447112/  )

jordan kicks paypal payment $28/pairs   www.mall-aol.com (
http://photo.163.com/photos/huayuexiehang/118447112/  )


jordan kicks paypal payment $28/pairs   www.mall-aol.com (
http://photo.163.com/photos/huayuexiehang/118447112/  )


retro jordan  paypal payment $28/pairs   www.mall-aol.com (
http://photo.163.com/photos/huayuexiehang/118447112/  )

jordan black  paypal payment $28/pairs   www.mall-aol.com (
http://photo.163.com/photos/huayuexiehang/118447112/  )


Jordan 1  paypal payment $28/pairs   www.mall-aol.com (
http://photo.163.com/photos/huayuexiehang/118447112/  )

Jordan 2  paypal payment $28/pairs   www.mall-aol.com (
http://photo.163.com/photos/xyxwaaa/41471283/  )

 Jordan 3  paypal payment $28/pairs   www.mall-aol.com (
http://photo.163.com/photos/huayuexiehang/106616893/ )

 Jordan 3.5 paypal payment $28/pairs   www.mall-aol.com (
http://photo.163.com/photos/huayuexiehang/130017375/ )

 Jordan 4  paypal payment $28/pairs   www.mall-aol.com (
http://photo.163.com/photos/huayuexiehang/106615439/ )

 Jordan 4.5  paypal payment $28/pairs   www.mall-aol.com (
http://photo.163.com/photos/huayuexiehang/108452846/ )

 Jordan 5 paypal payment $28/pairs   www.mall-aol.com (
http://photo.163.com/photos/huayuexiehang/107411680/ )

 fusion shoes paypal payment $28/pairs   www.mall-aol.com (
http://photo.163.com/photos/huayuexiehang/107411680/ )

 Jordan 6 paypal payment $28/pairs   www.mall-aol.com (
http://photo.163.com/photos/huayuexiehang/126072873/  )

air Jordan 7   paypal payment $28/pairs   www.mall-aol.com (
http://photo.163.com/photos/huayuexiehang/106615001/ )

 Jordan 8 paypal payment $28/pairs   www.mall-aol.com (
http://photo.163.com/photos/xyxwaaa/41471374/  )

 Jordan 9  paypal payment $28/pairs   www.mall-aol.com (
http://photo.163.com/photos/huayuexiehang/108159189/  )

 Jordan 10 paypal payment $28/pairs   www.mall-aol.com (
http://photo.163.com/photos/huayuexiehang/106616833/ )

 Jordan 11   paypal payment $28/pairs   www.mall-aol.com (
http://photo.163.com/photos/huayuexiehang/106616015/ )

 Jordan 12 paypal payment $28/pairs   www.mall-aol.com (
http://photo.163.com/photos/huayuexiehang/106616947/)

 Jordan 13  paypal payment $28/pairs   www.mall-aol.com (
http://photo.163.com/photos/huayuexiehang/137841084/ )

 Jordan 14 paypal payment $28/pairs   www.mall-aol.com (
http://photo.163.com/photos/pt2295568/72660611/ )

 Jordan 15 paypal payment $28/pairs   www.mall-aol.com (
http://photo.163.com/photos/mh2599/127077013/  )

 Jordan 15.5  paypal payment $28/pairs   www.mall-aol.com (
http://photo.163.com/photos/xyxwaaa/155861899/)

 Jordan 16  paypal payment $28/pairs   www.mall-aol.com (
http://photo.163.com/photos/xyxwaaa/41471480/  )

 Jordan 17  paypal payment $28/pairs   www.mall-aol.com (
http://photo.163.com/photos/xyxwaaa/41471492/ )

 Jordan 18 paypal payment $28/pairs   www.mall-aol.com (
http://photo.163.com/photos/xyxwaaa/41471504/ )

Jordan 19 paypal payment $28/pairs   www.mall-aol.com (
http://photo.163.com/photos/pt2295568/106295465/ )

 Jordan 20  paypal payment $28/pairs   www.mall-aol.com (
http://photo.163.com/photos/pt2295568/104392538/  )

 Jordan 21  paypal payment $28/pairs   www.mall-aol.com (
http://photo.163.com/photos/pt2295568/103674751/ )

 Jordan 22  paypal payment $28/pairs   www.mall-aol.com (
http://photo.163.com/photos/pt2295568/105245722/ )

 Jordan 23  paypal payment $28/pairs   www.mall-aol.com (
http://photo.163.com/photos/xyxwaaa/143716593/)

air Jordan 1  paypal payment $28/pairs wholesaler   www.mall-aol.com
(  http://photo.163.com/photos/huayuexiehang/ )

air Jordan 2 paypal payment $28/pairs wholesaler   www.mall-aol.com
(  http://photo.163.com/photos/huayuexiehang/ )

trainers  paypal payment $28/pairs wholesaler   www.mall-aol.com
(  http://photo.163.com/photos/huayuexiehang/ )

air Jordan 3  paypal payment $28/pairs wholesaler   www.mall-aol.com
(  http://photo.163.com/photos/huayuexiehang/ )

air Jordan 4  paypal payment $28/pairs wholesaler   www.mall-aol.com
(  http://photo.163.com/photos/huayuexiehang/ )

air Jordan 5  paypal payment $28/pairs wholesaler   www.mall-aol.com
(  http://photo.163.com/photos/huayuexiehang/ )

air Jordan 6  paypal payment $28/pairs wholesaler   www.mall-aol.com
(  http://photo.163.com/photos/huayuexiehang/ )

air Jordan 7   paypal payment $28/pairs wholesaler   www.mall-aol.com
(  http://photo.163.com/photos/huayuexiehang/ )


air Jordan 9  paypal payment $28/pairs wholesaler   www.mall-aol.com
(  http://photo.163.com/photos/huayuexiehang/ )

air Jordan 10  paypal payment $28/pairs wholesaler   www.mall-aol.com
(  http://photo.163.com/photos/huayuexiehang/ )

vJordan 8 paypal payment $28/pairs wholesaler   www.mall-aol.com

Re: paretovariate

2008-08-11 Thread Casey
On Aug 11, 3:14 am, "zhjchen" <[EMAIL PROTECTED]> wrote:
> I want to realize a list of numbers. They follow pareto distribution.
> For instance, the average value is 10 and alpha is 1.0
> I do not know how to use the function of paretovariate(alpha). It only 
> provides
> alpha parameter. How should I set the average value?

I'm guessing that paretovalue(alpha) treats alpha as the shape
parameter and assumes a mode of 1.0, in which case you would multiply
by 10 for your example.

Alternatively, you could define your own Pareto function:

# pareto for mode, shape > 0.0
def pareto(mode, shape): return mode * pow(1.0 - random.random(),
-1.0 / shape)
--
http://mail.python.org/mailman/listinfo/python-list


Re: SSH utility

2008-08-11 Thread Edwin . Madari
for similar tasks, I use pexpect http://pypi.python.org/pypi/pexpect.

spawning bash process and simulate an interactive session. Here sending ls 
command, retrieving results and exiting. In the spawned process ssh or any 
other command, is just another command. 

actual session--
$ python
Python 2.5.1 (r251:54863, May 18 2007, 16:56:43) 
[GCC 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pexpect
>>> c = pexpect.spawn('/bin/bash')
>>> c.expect([pexpect.TIMEOUT, pexpect.EOF, '\$ '])
2
>>> c.before, c.after
('[EMAIL PROTECTED]:~\r\n', '$ ')
>>> c.sendline('ls')
3
>>> c.expect([pexpect.TIMEOUT, pexpect.EOF, '\$ '])
2
>>> c.before, c.after
('ls\r\x.txt  xx.txt  xy.txt  [EMAIL PROTECTED]:~\r\n', '$ ')
>>> c.sendline('exit')
5
>>> c.expect([pexpect.TIMEOUT, pexpect.EOF, '\$ '])
1
>>> c.before, c.after
('exit\r\nexit\r\n', )
>>> exit()
[EMAIL PROTECTED]:~
$ 
---

hope that helps.

regards.
Edwin


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of James Brady
Sent: Monday, August 11, 2008 12:26 AM
To: python-list@python.org
Subject: SSH utility


Hi all,
I'm looking for a python library that lets me execute shell commands
on remote machines.

I've tried a few SSH utilities so far: paramiko, PySSH and pssh;
unfortunately all been unreliable, and repeated questions on their
respective mailing lists haven't been answered...

It seems like the sort of commodity task that there should be a pretty
robust library for. Are there any suggestions for alternative
libraries or approaches?

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



The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.


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


Re: SSH utility

2008-08-11 Thread Jean-Paul Calderone

On Sun, 10 Aug 2008 21:25:38 -0700 (PDT), James Brady <[EMAIL PROTECTED]> wrote:

Hi all,
I'm looking for a python library that lets me execute shell commands
on remote machines.

I've tried a few SSH utilities so far: paramiko, PySSH and pssh;
unfortunately all been unreliable, and repeated questions on their
respective mailing lists haven't been answered...

It seems like the sort of commodity task that there should be a pretty
robust library for. Are there any suggestions for alternative
libraries or approaches?


You can find an example of running commands over SSH with Twisted online:

 http://twistedmatrix.com/projects/conch/documentation/examples/

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


Re: for x,y in word1, word2 ?

2008-08-11 Thread Edwin . Madari
sounds like *soundex* is what you are looking for.  google soundex

regards
Edwin

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of Marc 'BlackJack' Rintsch
Sent: Monday, August 11, 2008 3:09 AM
To: python-list@python.org
Subject: Re: for x,y in word1, word2 ?


On Sun, 10 Aug 2008 23:14:50 -0700, ssecorp wrote:

> I know zip but lets say I have a word "painter" and I want to compare it
> to a customer's spelling, he might have written "paintor" and I want to
> check how many letters are the same.
> 
> Now I know how I could do this, it is not hard. I am just wondering if
> these is any specific simple syntax for it.

No special syntax for that, but you can combine the `sum()` function, a 
generator expression and `zip()`:

In [40]: sum(int(a == b) for a, b in zip('painter', 'paintor'))
Out[40]: 6

Or this way if you think it's more clear:

In [41]: sum(1 for a, b in zip('painter', 'paintor') if a == b)
Out[41]: 6

Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list



The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.


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


Beta testing website

2008-08-11 Thread mike222
Hi All,
  This is a bit off-topic but may be of interest to some
people. I have just found a website that looks interesting. It lets
companies register their products for beta testing, and testers
specify what sort of products that they would like to test.

Sort of a beta testing dating service - Membership is free.

It look like it is just starting out, but is a promising concept.

Betatestnow.com

Cheers

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


Suggestion for converting PDF files to HTML/txt files

2008-08-11 Thread srinivasan srinivas
Could someone suggest me ways to convert PDF files to HTML files??
Does Python have any modules to do that job??

Thanks,
Srini


  Unlimited freedom, unlimited storage. Get it now, on 
http://help.yahoo.com/l/in/yahoo/mail/yahoomail/tools/tools-08.html/
--
http://mail.python.org/mailman/listinfo/python-list


Re: SSH utility

2008-08-11 Thread Michael Mabin
I use pexpect.

On Mon, Aug 11, 2008 at 7:22 AM, Jean-Paul Calderone <[EMAIL PROTECTED]>wrote:

> On Sun, 10 Aug 2008 21:25:38 -0700 (PDT), James Brady <
> [EMAIL PROTECTED]> wrote:
>
>> Hi all,
>> I'm looking for a python library that lets me execute shell commands
>> on remote machines.
>>
>> I've tried a few SSH utilities so far: paramiko, PySSH and pssh;
>> unfortunately all been unreliable, and repeated questions on their
>> respective mailing lists haven't been answered...
>>
>> It seems like the sort of commodity task that there should be a pretty
>> robust library for. Are there any suggestions for alternative
>> libraries or approaches?
>>
>
> You can find an example of running commands over SSH with Twisted online:
>
>  http://twistedmatrix.com/projects/conch/documentation/examples/
>
> Jean-Paul
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



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

if len(str(a)) == len(str(r)) and isMult(a, r): faster if isMult is slow?

2008-08-11 Thread maestro
If isMult is slow then:

if len(str(a)) == len(str(r)) and isMult(a, r):
trues.append((a, r))

will be much faster than:

if isMult(a, r) and len(str(a)) == len(str(r)):
trues.append((a, r))

right? seems obvious  but there is no magic going on that wouldn't
make this true right?
--
http://mail.python.org/mailman/listinfo/python-list


Re: if len(str(a)) == len(str(r)) and isMult(a, r): faster if isMult is slow?

2008-08-11 Thread Chris
On Aug 11, 3:03 pm, maestro <[EMAIL PROTECTED]> wrote:
> If isMult is slow then:
>
> if len(str(a)) == len(str(r)) and isMult(a, r):
>                 trues.append((a, r))
>
> will be much faster than:
>
> if isMult(a, r) and len(str(a)) == len(str(r)):
>                 trues.append((a, r))
>
> right? seems obvious  but there is no magic going on that wouldn't
> make this true right?

Once a failed condition is met the rest are skipped for evaluation.
Whether or not that saves you any reasonable amount of time would be
up to the various tests being used with your conditions.

If your function isMult is just doing the same work as "if not a % r"
then that would be faster than casting your integers/floats to a
string and testing their length imo.

You could always go through the trouble of profiling your code with
separate if statements to see how much time is spent on each, also
note your mean failure rate for each conditional test and then decide
for yourself which to place first.

Hope that helps,
Chris
--
http://mail.python.org/mailman/listinfo/python-list


Re: Video information

2008-08-11 Thread Geoffrey Clements
"Bill McClain" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> On 2008-08-09, dusans <[EMAIL PROTECTED]> wrote:
>> Is there a py module, which would get me information of a movie file:
>> - resolution
>> - fps
>
> I don't know of one. I use the transcode utilities for this and parse 
> their
> output.
>

Something like:
from subprocess import Popen, PIPE
probe = Popen(("tcprobe", "-i", ip_file), stdout=PIPE, 
stderr=PIPE).communicate()[0]

or
from subprocess import Popen, PIPE
probe = Popen(("mplayer", "-identify", "-frames", "0", "-ao", "null", 
ip_file), stdout=PIPE, stderr=PIPE).communicate()[0]

First one uses transcode the second one uses mplayer. I normally follow 
these with a regexp search on "probe" for the data I want.
I have found mplayer to be more accurate than transcode which seems to have 
a problem with some files notably MPEG program streams although it seems to 
work fine for elementary streams.

-- 
Geoff 


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


dynamically creating html code with python...

2008-08-11 Thread anartz
Hi,

how can I combine some dynamically generated html code (using python) with the 
output of a urllib.openurl() call?

I have tried to use the StringIO() class with .write functions, but it did not 
work. Below is the code that does not work.

[CODE]
f=StringIO.StringIO()
f.write('data analysis')
f.write(urllib.urlopen("http://localhost/path2Libs/myLibs.py";, 
urllib.urlencode(TheData)))
f.write("")

print "Content-type: text/html\n"
print f.read()
f.close()
[/CODE]

What is wrong with this approach/code? Is there an easier way of doing it?

Thanks.



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


Re: dynamically creating html code with python...

2008-08-11 Thread Carsten Haese

[EMAIL PROTECTED] wrote:

Hi,

how can I combine some dynamically generated html code (using python) with the 
output of a urllib.openurl() call?

I have tried to use the StringIO() class with .write functions, but it did not 
work. Below is the code that does not work.


Help us help you. "Does not work" is not a helpful description. Do you 
get an error message? If so, what is the error message? Do you get an 
unexpected result? If so, what is the unexpected result, and what is the 
result you expected?



Is there an easier way of doing it?


Probably. You seem to be invoking a python program that's local to your 
computer, so it's not quite clear why you're going the roundabout way of 
serving it up through a web server. Then again, you're not telling us 
the actual problem you're trying to solve, so we have no idea what the 
best solution to that problem might be.


--
Carsten Haese
http://informixdb.sourceforge.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: dynamically creating html code with python...

2008-08-11 Thread Jerry Hill
On Mon, Aug 11, 2008 at 9:15 AM,  <[EMAIL PROTECTED]> wrote:
> [CODE]
> f=StringIO.StringIO()
> f.write('data analysis')
> f.write(urllib.urlopen("http://localhost/path2Libs/myLibs.py";, 
> urllib.urlencode(TheData)))
> f.write("")
>
> print "Content-type: text/html\n"
> print f.read()
> f.close()
> [/CODE]
>
> What is wrong with this approach/code? Is there an easier way of doing it?

A StringIO object works a lot like a file.  When you write to it, it
keeps track of the current position in the file.  When you read from
it, it reads from the current position to the end of the file.  Once
you're done writing to the StringIO object, you can rewind the
position to the beggining and then read to the end, like this:

f = StringIO.StringIO()
f.write('This is some data')
f.seek(0)
print f.read()

StringIO objects also have a special getvalue() method, which allows
you to get the entire contents without changing the current position.
You can replace your f.read() with f.getvalue() without having to mess
with seek(), but then your code won't work with real files, if that's
important.

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


Re: Suggestion for converting PDF files to HTML/txt files

2008-08-11 Thread brad

srinivasan srinivas wrote:

Could someone suggest me ways to convert PDF files to HTML files??
Does Python have any modules to do that job??

Thanks,
Srini


Unless there is some recent development, the answer is no, it's not 
possible. Getting text out of PDF is difficult (to say the least) and at 
times impossible... i.e. a PDF can be an image that contains some text, etc.

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


RE: internet searching program

2008-08-11 Thread Support Desk
Google does'nt allow use of their API's anymore, I belive Yahoo has one  or
you could do something like below. 

searchstring = 'stuff here'

x = os.popen('lynx -dump http://www.google.com/search?q=%s' %
searchstring).readlines()


-Original Message-
From: Steven D'Aprano [mailto:[EMAIL PROTECTED] 
Sent: Friday, August 08, 2008 11:22 PM
To: python-list@python.org
Subject: Re: internet searching program

On Fri, 08 Aug 2008 19:59:02 -0700, KillSwitch wrote:

> Is it possible to make a program to search a site on the internet, then
> get certain information from the web pages that match and display them?
> Like, you would put in keywords to be searched for on youtube.com, then
> it would search youtube.com, get the names of the videos, the links, and
> the embed information? Or something like that.

Search the Internet? Hmmm... I'm not sure, but I think Google does 
something quite like that, but I don't know if they do it with a computer 
program or an army of trained monkeys.



-- 
Steven


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


Unable to read data from transport connection

2008-08-11 Thread abhishek
Hello group,

  i am running a web server on cherrypy 2.2.0 using python2.5 and
turbogears1.0. I have a client application in C#.NET which uploads
the
data on to web server over HTTP.


Very frequently i encounter error logs on my client application which
says -- "Unable to read data from transport connection. The
connection
was forcibly closed by the remote host."


since the data that is being sent from C# app is being encrypted
using
standard AES implementaion in C#. thus to decrypt the same on server
side i am forking a C# executable with decryption code using
--
 "os.spawnv(os.P_WAIT,exePath, )".


I would like to know is this a client side problem(C#) or a server
side problem(Cherrypy, Python).


if someone needs any piece of code to help me please cantact me@
[EMAIL PROTECTED]


Thanks Group.

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


Re: Second python program: classes, sorting

2008-08-11 Thread Bruno Desthuilliers

WP a écrit :
Hello, here are some new things I've problems with. I've made a program 
that opens and reads a text file. Each line in the file contains a name 
and a score. I'm assuming the file has the correct format. Each 
name-score pair is used to instantiate a class Score I've written. This 
works fine, but here's my problem: After reading the file I have list of 
Score objects. Now I want to sort them in descending order. But no 
matter how I write my __cmp__ the order remains unchanged. 


You fixed this, so I'll just comment on the rest of the code...

(snip)



Complete program:
class Score:


Unless you have a compelling reason (mostly: compat with ages old Python 
versions), better to use new-style classes:


class Score(object):


def __init__(self, name_, score_):
self.name = name_
self.score = score_


cf Eric Brunel's comments here about the trailing underscores.


def __str__(self):
return "Name = %s, score = %d" % (self.name, self.score)


(snip)


name  = ""
score = 0


Do you have any reason to have these as class attributes too ?



# End class Score

filename = "../foo.txt";

try:
infile = open(filename, "r")
except IOError, (errno, strerror):
print "IOError caught when attempting to open file %s. errno = %d, 
strerror = %s" % (filename, errno, strerror)

exit(1)


cf Eric Brunel's comment wrt/ why this try/except clause is worse than 
useless here.



lines = infile.readlines()


File objects are their own iterators. You don't need to read the whole 
file in memory.



infile.close()



lines = [l.strip() for l in lines] # Strip away trailing newlines.

scores = []

for a_line in lines:



splitstuff = a_line.split()

scores.append(Score(splitstuff[0], int(splitstuff[1])))



scores = []
mk_score = lambda name, score : Score(name, int(score))

infile = open(filename)
for line in infile:
line = line.strip()
if not line:
continue
scores.append(mk_score(*line.split()))

infile.close()


As a side note : I understand that this is a learning exercice,  but in 
real life, if that's all there is to your Score class, it's not really 
useful - I'd personnally use a much simpler representation, like a list 
of score / name pairs (which is easy to sort, reverse, update, turn into 
a name=>scores or scores=>names dict, etc).


My 2 cents.
--
http://mail.python.org/mailman/listinfo/python-list


at_most: search "dictionary" for less than or equal

2008-08-11 Thread slais-www

Before I set out to reinvent the wheel.

I want a dictionary-like structure for which most lookups will be on a 
key that is not in the "dictionary"; in which case I want a key/value 
returned which is the closest key that is less than the search term.



The batch solution of matching the values in two sorted sequences is 
efficient but a random lookup would be more convenient. A solution based 
on AVL trees seems possible.



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


Re: at_most: search "dictionary" for less than or equal

2008-08-11 Thread bearophileHUGS
slais-www, a BK-tree maybe isn't right what you need but it may be
enough:
http://code.activestate.com/recipes/572156/

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


Re: How to execute commands in internal zones of solaris using python running from the global zone ?

2008-08-11 Thread Calvin Spealman
You might try subprocess, first of all. Use it to launch zlogin and
then treat it like a shell and write 'zonename\n' to its stdin, to
simulate running it as a user. This is a good bet, but I don't have
either available to try it. The subprocess documentation covers
invoking a process and writing to its input.

What you are doing now doesn't work, because you just invoke the two
processes and dont do anything with either of them. zlogin may not
have even completely initialized when you start the second command.
The technique you need is to start zlogin and then tell it to run the
next.

On Mon, Aug 11, 2008 at 6:39 AM, Hishaam <[EMAIL PROTECTED]> wrote:
> How to execute commands in internal zones of solaris using python
> running from the global zone ?
>
> i tried --
> 1> os.popen("zlogin ")
> 2> os.popen("zonename")
>
> the 2nd command executes back into the global zone and not into the
> internal zone
> can anyone help?
>
>
> Hishaam
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Read my blog! I depend on your acceptance of my opinion! I am interesting!
http://ironfroggy-code.blogspot.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: at_most: search "dictionary" for less than or equal

2008-08-11 Thread Paul McGuire
On Aug 11, 9:18 am, slais-www <[EMAIL PROTECTED]> wrote:
> Before I set out to reinvent the wheel.
>
> I want a dictionary-like structure for which most lookups will be on a
> key that is not in the "dictionary"; in which case I want a key/value
> returned which is the closest key that is less than the search term.
>
> The batch solution of matching the values in two sorted sequences is
> efficient but a random lookup would be more convenient. A solution based
> on AVL trees seems possible.
>
> --
> djc

Sounds like you have very long lists to work with.  Maybe a solution
using bisect would combine simplest structure with best performance.

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


eval or execute, is this the (most) correct way ?

2008-08-11 Thread Stef Mientki

hello,

I'm trying to make an editor with an integrated Shell.

>>So when type:
2+5
>>I want the answer on the next line:
7

>>When I type:
myvar = 55
myvar
>>I want the value of myvar:
55

So AFAIK, sometimes I've to use eval and sometimes I need exec,
so I use the following code (global / local dictionary parameters are 
left out in this example):


   try:
   print eval ( line )
   except :
   exec ( line )

Is this the (most) correct / elegant way, or are there better solutions ?

I read somewhere that exec is going to disappear,
and noticed that in 2.5 (I just updated to) the doc is already disapeared,
is this no longer possible in Python 3 ?

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


Re: dynamically creating html code with python...

2008-08-11 Thread anartz
Sorry, my fault...

I am trying to build a web application for data analysis. Basically some data 
will be read from a database and passed to a python script (myLibs.py) to build 
an image as follows.

[CODE]
f=urllib.urlopen("http://localhost/path2Libs/myLibs.py",urllib.urlencode(TheData))
print "Content-type: image/png\n"
print f.read()
f.close()
[/CODE]

This section behaves as expected, and I can see the chart on the web-page.

Now, I would like to add some text and possibly more charts (generated in the 
same way) to my web-page. This is what I need help with.

I tried to add some html code to the f variable (file-type variable) before and 
after the plot generated (see first post). When I load the page in a browser, I 
get a blank page, not even the chart (that I used to get) appears any more.

There is no error messages in the server's error log, and when I run it as a 
python script I get the following output:

Content-type: image/png\n

My question:
How can I use python to dynamically add descriptive comments (text), and 
possibly more charts to the web-page?

Hope this is more explanatory.

Thanks

[EMAIL PROTECTED] wrote :

> Hi,
> 
> how can I combine some dynamically generated html code (using python) with 
> the output of a urllib.openurl() call?
> 
> I have tried to use the StringIO() class with .write functions, but it did 
> not work. Below is the code that does not work.
> 
> [CODE]
> f=StringIO.StringIO()
> f.write('data analysis')
> f.write(urllib.urlopen("http://localhost/path2Libs/myLibs.py";, 
> urllib.urlencode(TheData)))
> f.write("")
> 
> print "Content-type: text/html\n"
> print f.read()
> f.close()
> [/CODE]
> 
> What is wrong with this approach/code? Is there an easier way of doing it?
> 
> Thanks.
> 
> 
> 
> --
> http://mail.python.org/mailman/listinfo/python-list



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


Re: Python for Blackberry mobile phones

2008-08-11 Thread Timothy Grant
On Sun, Aug 10, 2008 at 9:54 PM,  <[EMAIL PROTECTED]> wrote:
> I'm looking for a version of Python for Blackberry mobile phones - has
> anyone heard of such a thing? I've been googling this topic without success.
>
> Thanks,
> Malcolm

My understanding is that the BB's run Java, so there *may* be some
chance that it might be possible to get Jython running on it.


-- 
Stand Fast,
tjg.  [Timothy Grant]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Wildcards for regexps?

2008-08-11 Thread Timothy Grant
On Sun, Aug 10, 2008 at 9:10 PM, ssecorp <[EMAIL PROTECTED]> wrote:
> If I have an expression like "bob marley" and I want to match
> everything with one letter wrong, how would I do?
> so "bob narely" and "vob marley" should match etc.

At one point I needed something like this so did a straight port of
the double-metaphone code to python.

It's horrible, it's ugly, it's non-pythonic in ways that make me
cringe, it has no unit tests, but it does work.

-- 
Stand Fast,
tjg.  [Timothy Grant]
--
http://mail.python.org/mailman/listinfo/python-list


Re: for x,y in word1, word2 ?

2008-08-11 Thread Casey
My first thought is that you should be looking at implementations of
Hamming Distance.  If you are actually looking for something like
SOUNDEX you might also want to look at the double metaphor algorithm,
which is significantly harder to implement but provides better
matching and is less susceptible to differences based on name origins.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Eclipse, Python, wxPython and code completion

2008-08-11 Thread azrael
if you need a good python ide with great code completition, then why
don't you try WingIde.



On 11 kol, 10:49, [EMAIL PROTECTED] wrote:
> On 11 ago, 04:34, "SPE - Stani's Python Editor"
>
>
>
>
>
> <[EMAIL PROTECTED]> wrote:
> > On 10 aug, 20:42, [EMAIL PROTECTED] wrote:
>
> > > Hello,
>
> > > I've installed Eclipse, Python 2.5 and wxPython on Ubuntu 8.04. The
> > > problem is that I can't get code completion for wx module. I don't
> > > know if it occurs the same with other libraries outside the python
> > > "core".
>
> > > If I compile/run my code containing the wx library, I get an
> > > application running correctly, so it looks that definition works fine.
> > > Obviously, the obstacle is that I don't know (I don't want to either)
> > > the name of every method of every wxPython class so it's difficult to
> > > develop anything within this environment.
>
> > > Thanks a lot
>
> > > Note: I'm a newbie-coming-from-"Billy's"-WindowsXP
>
> > You can try SPE which is written in wxPython itself and has very good
> > code completion for wxPython. It also includes some wxPython GUI
> > builders such as wxGlade and XRCed. I improved it a lot for Hardy,
> > which I use myself:
> > sudo apt-get install spe
>
> > Stani
>
> Thanks, Stani
>
> I will check this out

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


Problems returning data from embedded Python

2008-08-11 Thread Cromulent
Okay I'm having a few issues with this and I can't seem to get it 
sorted out (most likely due to my inexperience with Python).


Here is my Python code:

def fileInput():

data = []

	s = raw_input("Please enter the filename to process (enter full path 
if not in current directory): ")


fd = open(s, "r")

fd.readline()
line = fd.readlines()

for record in line:
record = record.strip()
items = record.split(',')

for i in range(1, 5):
items[i] = float(items[i])

items[5] = int(items[5])
data.append(items)

fd.close()

return items

It works perfectly and does exactly what I want it to do. The problem 
comes when I try and convert the data I returned from the Python script 
and turn it into something useable in C.


I have no idea. The C functions that seem most use deal with Tuples, 
when this is a list and I can't see any specific functions for dealing 
with lists in the C API. Can anyone give me some pointers in the right 
direction at all please? I know the C program has received the data 
correctly, I just need to put it in C types.


Thank you.

--
"I disapprove of what you say, but I'll defend to the death your right 
to say it." - Voltaire


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


Re: Psycho question

2008-08-11 Thread David C. Ullrich
In article 
<[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] wrote:

> John Krukoff:
> > One possibility for the performance difference, is that as I understand
> > it the psyco developer has moved on to working on pypy, and probably
> > isn't interested in keeping psyco updated and optimized for new python
> > syntax.
> > Somebody correct me if I'm wrong, but last I heard there's no
> > expectation of a python 3.0 compatible version of psyco, either.
> 
> But for me on the short term Python 3 is probably more important than
> pypy, and I'd like to keep using Psyco...

I feel the same way. Maybe someone will do it...

(I wonder how much work it would be to make something
like Psyco that only accepts a small subset of the language.)

> Bye,
> bearophile

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


Re: dynamically creating html code with python...

2008-08-11 Thread anartz
I have tried calling a script containing the code below from a web browser and 
it did not get the text.

[CODE]
#!c:/Python25/python.exe -u

import StringIO

f=StringIO.StringIO()
f.write('data analysis site')
f.write("This is a trial test")
f.write("")

print "Content-type: text/html\n"
print f.read()
f.close()
[/CODE]

So, I assume this is not the way to create web pages any links that can 
help me take the right way? 

Thanks!


Jerry Hill <[EMAIL PROTECTED]> wrote :

> On Mon, Aug 11, 2008 at 9:15 AM,  <[EMAIL PROTECTED]> wrote:
> > [CODE]
> > f=StringIO.StringIO()
> > f.write('data analysis')
> > f.write(urllib.urlopen("http://localhost/path2Libs/myLibs.py";, 
> > urllib.urlencode(TheData)))
> > f.write("")
> >
> > print "Content-type: text/html\n"
> > print f.read()
> > f.close()
> > [/CODE]
> >
> > What is wrong with this approach/code? Is there an easier way of doing it?
> 
> A StringIO object works a lot like a file.  When you write to it, it
> keeps track of the current position in the file.  When you read from
> it, it reads from the current position to the end of the file.  Once
> you're done writing to the StringIO object, you can rewind the
> position to the beggining and then read to the end, like this:
> 
> f = StringIO.StringIO()
> f.write('This is some data')
> f.seek(0)
> print f.read()
> 
> StringIO objects also have a special getvalue() method, which allows
> you to get the entire contents without changing the current position.
> You can replace your f.read() with f.getvalue() without having to mess
> with seek(), but then your code won't work with real files, if that's
> important.
> 
> -- 
> Jerry
> --
> http://mail.python.org/mailman/listinfo/python-list



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


Re: eval or execute, is this the (most) correct way ?

2008-08-11 Thread Steven D'Aprano
On Mon, 11 Aug 2008 17:26:56 +0200, Stef Mientki wrote:

> I'm trying to make an editor with an integrated Shell.
...
> Is this the (most) correct / elegant way, or are there better solutions
> ?


The best solution is not to re-invent the wheel: "import code" is the way 
to emulate Python's interactive interpreter. Try running "python -m code" 
at a regular shell (not the Python shell, your operating system's shell).

Doing a search of the file code.py, I don't find the string "eval" at 
all. My guess is that your approach is probably not the best way.



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


Re: New python module to simulate arbitrary fixed and infinite precision binary floating point

2008-08-11 Thread Steven D'Aprano
On Sun, 10 Aug 2008 16:34:34 -0400, Rob Clewley wrote:

> Dear Pythonistas,
> 
> How many times have we seen posts recently along the lines of "why is it
> that 0.1 appears as 0.10001 in python?" that lead to posters
> being sent to the definition of the IEEE 754 standard and the decimal.py
> module? I am teaching an introductory numerical analysis class this
> fall, and I realized that the best way to teach this stuff is to be able
> to play with the representations directly
...
> Consequently, I have written a module to simulate the machine
> representation of binary floating point numbers and their arithmetic.
> Values can be of arbitrary fixed precision or infinite precision, along
> the same lines as python's in-built decimal class. The code is here: 
> http://www2.gsu.edu/~matrhc/binary.html


I would be interested to look at that, if I can find the time.

Is this related to minifloats?

http://en.wikipedia.org/wiki/Minifloat


-- 
Steven

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


Re: ANN: P4D 1.2

2008-08-11 Thread Kay Schluehr
On 11 Aug., 11:41, Gerhard Häring <[EMAIL PROTECTED]> wrote:
> Kay Schluehr wrote:
> > P4D = E4X style embedded DSL for Python but without E and X.
> > The main feature of P4D 1.2 are *Bytelets*. While the primary purpose
> > of P4D 1.1 was the support textual data which can be considered as
> > isomorphic to XML the new release is focussed on binary data. Bytelets
> > are P4D objects that are assembled from hexcode which is reified as a
> > Hex object. [...]
>
> I am not supposed to understand any of this, right?
>
> -- Gerhard

Then forget this "Abstract" if it just produces noise and take a look
at the examples and testcases. I'll release P4D 1.3 soon and will
update the introduction written in the PyPI which might be helpful to
get a first impression.
--
http://mail.python.org/mailman/listinfo/python-list


Re: dynamically creating html code with python...

2008-08-11 Thread Jerry Hill
On Mon, Aug 11, 2008 at 12:26 PM,  <[EMAIL PROTECTED]> wrote:
> I have tried calling a script containing the code below from a web browser 
> and it did not get the text.

You quoted my post that answered this question, but did not implement
either of the two solutions I suggested.  I continue to suggest that
you either: f.seek(0) before you f.read(), or that you replace
f.read() with f.getvalue().

Also, you may want to read the docs on
StringIO - http://docs.python.org/lib/module-StringIO.html
File objects - http://docs.python.org/lib/bltin-file-objects.html

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


pympi and threading in python

2008-08-11 Thread Dina Ali
Hello there

I am confused in the usage/differences of pympi and threading in python.
What I want to do it to run multiple MCMC simulations by dividing the number
of the chains I want to run on number of the processors available. Some
methods need to be synchronized/locked until some addition operation is
finished.

I will be very grateful if some one could help.

Thanks very much

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

Re: benchmark

2008-08-11 Thread Peter Otten
Kris Kennaway wrote:

> Peter Otten wrote:
>> [EMAIL PROTECTED] wrote:
>> 
>>> On Aug 10, 10:10 pm, Kris Kennaway <[EMAIL PROTECTED]> wrote:
 jlist wrote:
> I think what makes more sense is to compare the code one most
> typically writes. In my case, I always use range() and never use
> psyco. But I guess for most of my work with Python performance hasn't
> been a issue. I haven't got to write any large systems with Python
> yet, where performance starts to matter.
 Hopefully when you do you will improve your programming practices to
 not make poor choices - there are few excuses for not using xrange ;)

 Kris
>>> And can you shed some light on how that relates with one of the zens
>>> of python ?
>>>
>>> There should be one-- and preferably only one --obvious way to do it.
>> 
>> For the record, the impact of range() versus xrange() is negligable -- on
>> my machine the xrange() variant even runs a tad slower. So it's not clear
>> whether Kris actually knows what he's doing.
> 
> You are only thinking in terms of execution speed.  

Yes, because my remark was made in the context of the particular benchmark
supposed to be the topic of this thread.

> Now think about memory use.  

Now you are moving the goal posts, But still, try to increase the chain
length. I guess you'll find that the impact of range() -- in
Chain.__init__() at least -- on the memory footprint is also negligable
because the Person objects consume much more memory than the tempory list.

> Using iterators instead of constructing lists is something 
> that needs to permeate your thinking about python or you will forever be
> writing code that wastes memory, sometimes to a large extent.

I like and use an iterator/generator/itertools-based idiom myself, but
for "small" sequences lists are quite competitive, and the notion of what a
small list might be is constantly growing.

In general I think that if you want to promote a particular coding style you
should pick an example where you can demonstrate actual benefits.

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


Re: updating dictionaries from/to dictionaries

2008-08-11 Thread Steven D'Aprano
On Mon, 11 Aug 2008 00:27:46 -0700, Brandon wrote:

> This should be pretty simple:  I have two dictionaries, foo and bar. I
> am certain that all keys in bar belong to foo as well, but I also know
> that not all keys in foo exist in bar.  All the keys in both foo and bar
> are tuples (in the bigram form ('word1', 'word2)).  I have to prime foo
> so that each key has a value of 1.

The old way:

foo = {}
for key in all_the_keys:
foo[key] = 1


The new way:

foo = dict.fromkeys(all_the_keys, 1)


> The values for the keys in bar are
> variable integers.  All I want to do is run a loop through foo, match
> any of its keys that also exist in bar, and add those key's values in
> bar to the preexisting value of 1 for the corresponding key in foo.  So
> in the end the key,value pairs in foo won't necessarily be, for example,
> 'tuple1: 1', but also 'tuple2: 31' if tuple2 had a value of 30 in bar.

Harder to say what you want to do than to just do it.

The long way:

for key in foo:
if bar.has_key(key):
foo[key] = foo[key] + bar[key]



Probably a better way:

for key, value in foo.iteritems():
foo[key] = value + bar.get(key, 0)



You should also investigate the update method of dictionaries. From an 
interactive session, type:

help({}.update)

then the Enter key.



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


Re: dynamically creating html code with python...

2008-08-11 Thread anartz
Hi,

Thanks for your patience.

I got the text displayed in the web browser with the following code:

[CODE]
f=StringIO.StringIO()
f.write('data analysis site')
f.write("This is a trial test")
f.write("")

print "Content-type: text/html\n"
print f.getvalue()
f.close()
[/CODE]

Now I am trying to put both the image and the text together, but the following 
lines do not create the text with the chart that I expected.

[CODE]
f=StringIO.StringIO()
f.write('data analysis site')
f.write("This is a trial test")
f.write(urllib.urlopen("http://localhost/myLibs/ChartLib.py",urllib.urlencode(TheData)))
f.write("")

print "Content-type: text/html\n"
print f.getvalue()
f.close()
[/CODE]

I am wondering if urllib.urlopen is the command I need to revise.

Thanks for the pointers as well. I will look into them.




Jerry Hill <[EMAIL PROTECTED]> wrote :

> On Mon, Aug 11, 2008 at 12:26 PM,  <[EMAIL PROTECTED]> wrote:
> > I have tried calling a script containing the code below from a web browser 
> > and it did not get the text.
> 
> You quoted my post that answered this question, but did not implement
> either of the two solutions I suggested.  I continue to suggest that
> you either: f.seek(0) before you f.read(), or that you replace
> f.read() with f.getvalue().
> 
> Also, you may want to read the docs on
> StringIO - http://docs.python.org/lib/module-StringIO.html
> File objects - http://docs.python.org/lib/bltin-file-objects.html
> 
> -- 
> Jerry
> --
> http://mail.python.org/mailman/listinfo/python-list



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


Re: benchmark

2008-08-11 Thread bearophileHUGS
Peter Otten:
> In general I think that if you want to promote a particular coding style you
> should pick an example where you can demonstrate actual benefits.

That good thing is that Python 3 has only xrange (named range), so
this discussion will be mostly over ;-)

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


Re: New python module to simulate arbitrary fixed and infinite precision binary floating point

2008-08-11 Thread Rob Clewley
>
> Is this related to minifloats?
>
> http://en.wikipedia.org/wiki/Minifloat
>

Strictly speaking, yes, although after a brief introduction to the
general idea, the entry on that page focuses entirely on the
interpretation of the values as integers. My code *only* represents
the values in the same way as the regular-sized IEEE 754 formats, i.e.
the smallest representable number is a fraction < 1, not the integer
1. I haven't supplied a way to use my classes to encode integers in
this way, but it wouldn't be hard for someone to add that
functionality in a sub-class of my ContextClass.

Thanks for pointing out that page, anyway. I didn't know the smaller
formats had been given their own name.

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


Re: benchmark

2008-08-11 Thread Kris Kennaway

Peter Otten wrote:

Kris Kennaway wrote:


Peter Otten wrote:

[EMAIL PROTECTED] wrote:


On Aug 10, 10:10 pm, Kris Kennaway <[EMAIL PROTECTED]> wrote:

jlist wrote:

I think what makes more sense is to compare the code one most
typically writes. In my case, I always use range() and never use
psyco. But I guess for most of my work with Python performance hasn't
been a issue. I haven't got to write any large systems with Python
yet, where performance starts to matter.

Hopefully when you do you will improve your programming practices to
not make poor choices - there are few excuses for not using xrange ;)

Kris

And can you shed some light on how that relates with one of the zens
of python ?

There should be one-- and preferably only one --obvious way to do it.

For the record, the impact of range() versus xrange() is negligable -- on
my machine the xrange() variant even runs a tad slower. So it's not clear
whether Kris actually knows what he's doing.
You are only thinking in terms of execution speed.  


Yes, because my remark was made in the context of the particular benchmark
supposed to be the topic of this thread.


No, you may notice that the above text has moved off onto another 
discussion.


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


dict.update() useful or not?

2008-08-11 Thread Steven D'Aprano
dict1.update(dict2) is of course equivalent to this code:

for key, value in dict2.iteritems():
dict1[key] = value

Note that it replaces values in dict1 with the value taken from dict2. I 
don't know about other people, but I more often want to keep the values 
in dict1 regardless of what's in dict2, and only add items from dict2 if 
it is new key. Like this:

for key, value in dict2.iteritems():
if not dict1.has_key(key):
dict1[key] = value


Here's some code modified from something I wrote the other day:

import urllib2
def create_request(url, headers):
tmp = DEFAULT_HEADERS.copy()
tmp.update(headers)
req = urllib2.Request(url, None, tmp)
# ... 
return req


There's the faintest of code smells to me. I would prefer to write 
something like this:

def create_request(url, headers):
headers.update(DEFAULT_HEADERS)
req = urllib2.Request(url, None, headers)
# ... 
return req

but of course this second example does the Wrong Thing, replacing 
explicit headers with default values.

What do other people find? Do you find use for dict.update()? What other 
idioms do you use for combining dictionaries?



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


Re: eval or execute, is this the (most) correct way ?

2008-08-11 Thread Stef Mientki

Steven D'Aprano wrote:

On Mon, 11 Aug 2008 17:26:56 +0200, Stef Mientki wrote:

  

I'm trying to make an editor with an integrated Shell.


...
  

Is this the (most) correct / elegant way, or are there better solutions
?




The best solution is not to re-invent the wheel: "import code" is the way 
to emulate Python's interactive interpreter.

sorry, but that confuses me even more,
I don;t have a file / module,
just a workspace and one or more lines of code in memory.
 Try running "python -m code" 
at a regular shell (not the Python shell, your operating system's shell).
  

I might have been not clear enough,
I'm trying to build an python-IDE,
so I definitely want to run code from memory.

cheers,
Stef
Doing a search of the file code.py, I don't find the string "eval" at 
all. My guess is that your approach is probably not the best way.




  


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


Re: dict.update() useful or not?

2008-08-11 Thread Duncan Booth
Steven D'Aprano <[EMAIL PROTECTED]> wrote:

> dict1.update(dict2) is of course equivalent to this code:
> 
> for key, value in dict2.iteritems():
> dict1[key] = value
> 
> Note that it replaces values in dict1 with the value taken from dict2. I 
> don't know about other people, but I more often want to keep the values 
> in dict1 regardless of what's in dict2, and only add items from dict2 if 
> it is new key. Like this:
> 
> for key, value in dict2.iteritems():
> if not dict1.has_key(key):
> dict1[key] = value
> 

If you don't actually need to mutate dict1 in-place then just use update 
for this:

d = dict(dict2)
d.update(dict1)
dict1 = d

> There's the faintest of code smells to me. I would prefer to write 
> something like this:
> 
> def create_request(url, headers):
> headers.update(DEFAULT_HEADERS)
> req = urllib2.Request(url, None, headers)
> # ... 
> return req
> 
> but of course this second example does the Wrong Thing, replacing 
> explicit headers with default values.

There's a second code smell with that: even if it did what you want it 
isn't nice to mutate the parameter passed in as headers. What if the caller 
wants to reuse the headers again for another call? Much nicer just to do:

def create_request(url, headers):
hdrs = dict(DEFAULT_HEADERS)
hdrs.update(headers)
req = urllib2.Request(url, None, hdrs)
# ... 
return req
--
http://mail.python.org/mailman/listinfo/python-list


Re: dynamically creating html code with python...

2008-08-11 Thread Timothy Grant
On Mon, Aug 11, 2008 at 10:05 AM,  <[EMAIL PROTECTED]> wrote:
> Hi,
>
> Thanks for your patience.
>
> I got the text displayed in the web browser with the following code:
>
> [CODE]
> f=StringIO.StringIO()
> f.write('data analysis site')
> f.write("This is a trial test")
> f.write("")
>
> print "Content-type: text/html\n"
> print f.getvalue()
> f.close()
> [/CODE]
>
> Now I am trying to put both the image and the text together, but the 
> following lines do not create the text with the chart that I expected.
>
> [CODE]
> f=StringIO.StringIO()
> f.write('data analysis site')
> f.write("This is a trial test")
> f.write(urllib.urlopen("http://localhost/myLibs/ChartLib.py",urllib.urlencode(TheData)))
> f.write("")
>
> print "Content-type: text/html\n"
> print f.getvalue()
> f.close()
> [/CODE]
>
> I am wondering if urllib.urlopen is the command I need to revise.
>
> Thanks for the pointers as well. I will look into them.
>
>
>
>
> Jerry Hill <[EMAIL PROTECTED]> wrote :
>
>> On Mon, Aug 11, 2008 at 12:26 PM,  <[EMAIL PROTECTED]> wrote:
>> > I have tried calling a script containing the code below from a web browser 
>> > and it did not get the text.
>>
>> You quoted my post that answered this question, but did not implement
>> either of the two solutions I suggested.  I continue to suggest that
>> you either: f.seek(0) before you f.read(), or that you replace
>> f.read() with f.getvalue().
>>
>> Also, you may want to read the docs on
>> StringIO - http://docs.python.org/lib/module-StringIO.html
>> File objects - http://docs.python.org/lib/bltin-file-objects.html
>>
>> --
>> Jerry


It looks to me like you are opening the url, but never retrieving the
content of the url.

I think you may have better luck with urllib2 which has a read() method.

http://docs.python.org/lib/urllib2-examples.html

-- 
Stand Fast,
tjg. [Timothy Grant]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Missing exceptions in PEP 3107

2008-08-11 Thread Matimus
> Maybe the following syntax would be even more intuitive:
>
> def foo(a: "a info", b: "b info") return "ret info" raise "exc info":
>         return "hello world"
>
> I don't know how determined the "->" syntax is already.

That seems much more intuitive and extensible. The "->" syntax has
always bothered me. The main issue I see with it though is that it
might be confusing. Consider:

def foo(a, b) return 0:

return a + b

A person reading the code might be tempted to read the annotation and
think that it is the body. Maybe not a huge problem, but definitely
something that will come up occasionally.

> Consider the syntax set in concrete.

Why? Python syntax is always changing. If we can think of a better way
to do something, then there is no better time than today to bring it
up.

Having said that, I like the decorator idea too:

> @raises("exc info")
> def foo(a: "a info", b: "b info") -> "ret info":
> return "hello world"

And to this:

> Well, yes, but wasn't the whole point of PEP 3107 to get rid of such
> decorators and provide a single standard way of specifying this kind of
> info instead?

Maybe, but I think it also does two more things: 1. creates a standard
location for storing annotations, and 2. Keeps you from violating DRY
(http://en.wikipedia.org/wiki/DRY).

For instance:

@parameters(a="a info", b="b info")
@raises("exception info")
@returns("return info")
def foo(a, b):
   pass

a and b are mentioned in both the definition and the "parameters"
decorator. This violates DRY since a change to the definition will
also require a change to the parameters decorator call. One could
argue that you could make the parameters decorator inspect the
function and apply the annotations positionally. That doesn't really
eliminate the problem, just muddles it. Moving or changing parameters
is still going to result in the need to change code in multiple
locations. The positional case is almost worse in that it will usually
result in the same amount of work, while being less explicit.

Using a single decorator for exception info (or even return info) does
not violate either of the two stated benefits. The exception
information would go into the standard annotations dictionary. The
raises decorator does not violate DRY any more or less than it would
if added to the language syntax.

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


Re: Video information

2008-08-11 Thread Peter Otten
dusans wrote:

> Is there a py module, which would get me information of a movie file:
> - resolution
> - fps

http://doc.freevo.org/2.0/Kaa#head-919960011a3523a465d1cacc57f2f8e7b0e8ad00

(I haven't used it myself)

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


Re: for x,y in word1, word2 ?

2008-08-11 Thread Timothy Grant
On Mon, Aug 11, 2008 at 8:44 AM, Casey <[EMAIL PROTECTED]> wrote:
> My first thought is that you should be looking at implementations of
> Hamming Distance.  If you are actually looking for something like
> SOUNDEX you might also want to look at the double metaphor algorithm,
> which is significantly harder to implement but provides better
> matching and is less susceptible to differences based on name origins.
> --
> http://mail.python.org/mailman/listinfo/python-list
>

I responded in the thread of the poster's original message on this
subject, but will do the same here. I have a horribly ugly version of
the double-metaphone algorithm in python that does work, and may be of
some use in solving this problem.

-- 
Stand Fast,
tjg. [Timothy Grant]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Eclipse, Python, wxPython and code completion

2008-08-11 Thread Stef Mientki

[EMAIL PROTECTED] wrote:

Hello,

I've installed Eclipse, Python 2.5 and wxPython on Ubuntu 8.04. The
problem is that I can't get code completion for wx module. I don't
know if it occurs the same with other libraries outside the python
"core".

If I compile/run my code containing the wx library, I get an
application running correctly, so it looks that definition works fine.
Obviously, the obstacle is that I don't know (I don't want to either)
the name of every method of every wxPython class so it's difficult to
develop anything within this environment.

  

In the IDE I use (under winXP),
sometimes the wx dictionairy is available,
sometimes it's not.
It's totally unclear to me why this happens,
but I noticed that it helps, to import the wx library as one of the very 
first import statements.


cheers,
Stef

Thanks a lot

Note: I'm a newbie-coming-from-"Billy's"-WindowsXP
--
http://mail.python.org/mailman/listinfo/python-list
  


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


Re: dynamically creating html code with python...

2008-08-11 Thread Diez B. Roggisch
[EMAIL PROTECTED] wrote:

> Hi,
> 
> Thanks for your patience.
> 
> I got the text displayed in the web browser with the following code:
> 
> [CODE]
> f=StringIO.StringIO()
> f.write('data analysis site')
> f.write("This is a trial test")
> f.write("")
> 
> print "Content-type: text/html\n"
> print f.getvalue()
> f.close()
> [/CODE]
> 
> Now I am trying to put both the image and the text together, but the
> following lines do not create the text with the chart that I expected.
> 
> [CODE]
> f=StringIO.StringIO()
> f.write('data analysis site')
> f.write("This is a trial test")
>
f.write(urllib.urlopen("http://localhost/myLibs/ChartLib.py",urllib.urlencode(TheData)))
> f.write("")
> 
> print "Content-type: text/html\n"
> print f.getvalue()
> f.close()
> [/CODE]
> 
> I am wondering if urllib.urlopen is the command I need to revise.
> 
> Thanks for the pointers as well. I will look into them.

That's bogus. instead of the urllib-stuff, you need to write out a -tag
with the src pointing to your image - most probably like this:



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


Re: Video information

2008-08-11 Thread Tobias Billep
2008/8/9 dusans <[EMAIL PROTECTED]>

> Is there a py module, which would get me information of a movie file:
> - resolution
> - fps
> --
> http://mail.python.org/mailman/listinfo/python-list
>

if you have linux installed you can use gstreamer and the bindings pygst

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

Inheritance crossover packages

2008-08-11 Thread Johannes Bauer

Hello group,

I'm having a seemingly simple problem. I want to generate a hierarchy of 
modules, like this one:


GenerationScripts/
GenerationScripts/dhcp
GenerationScripts/bind9

And the files:

GenerationScripts/dhcp/__init__.py
GenerationScripts/bind9/generator.py
GenerationScripts/bind9/__init__.py
GenerationScripts/mastergen.py
GenerationScripts/__init__.py

All packages (bind9, dhcp) should inherit from the master generator 
"mastergen".


I'm at the very beginning:

$ cat GenerationScripts/__init__.py
import bind9
#import dhcpd

$ cat GenerationScripts/bind9/__init__.py
import GenerationScripts.bind9.generator

$ cat GenerationScripts/bind9/generator.py
from GenerationScripts import mastergen

class generator(mastergen):
def __init__(self):
print "init bind9 generator"

Now what happens when I import GenerationScripts and try to create a 
instance of GenerationScripts.bind9.generator is the following:


Traceback (most recent call last):
  File "./Generate.py", line 3, in 
import GenerationScripts
  File "/home/joe/x/GenerationScripts/__init__.py", line 3, in 
import bind9
  File "/home/joe/x/GenerationScripts/bind9/__init__.py", line 4, in 


import GenerationScripts.bind9.generator
  File "/home/joe/x/GenerationScripts/bind9/generator.py", line 7, in 


class generator(mastergen):
TypeError: Error when calling the metaclass bases
module.__init__() takes at most 2 arguments (3 given)

I really don't get it - and I've searched and found the same problem, 
read the descirption - but still don't get it. What's happening here?


Regards,
Johannes

--
"Wer etwas kritisiert muss es noch lange nicht selber besser können. Es
reicht zu wissen, daß andere es besser können und andere es auch
besser machen um einen Vergleich zu bringen." - Wolfgang Gerber
  in de.sci.electronics <[EMAIL PROTECTED]>
--
http://mail.python.org/mailman/listinfo/python-list


A Question about ctypes and a function f(void **)

2008-08-11 Thread sapsi
Hello,
I have a C function f(void**,int *), in which it writes some
information (it is a RGB32 image).

Here is what i do
rowlength=c_int()
data=c_void_p()
d=pointer(data)
f(d,byref(rowlength)
The call works (no segmentation fault), now how do i access the data
in d? Because i need to pass it to a another function  QImage that
takes void* as its first parameter.

If i do d.contents i get c_void_p(3067478024L)

All suggestions welcome.
Regards
Saptarshi
--
http://mail.python.org/mailman/listinfo/python-list


Re: for x,y in word1, word2 ?

2008-08-11 Thread Dave Webster
Thanks, Timothy.  I'm pretty sure that there is no such thing as a "beautiful"
implementation of double-metaphone but I would personally like to have a copy
of your python implementation.  I have a fairly elegant version of the original
metaphone algorithm I wrote myself (in PERL, many years ago) but I've
never found
the time to reverse-engineer the original C++ code for double-metaphone and
"pythonize" it.

On Mon, Aug 11, 2008 at 2:08 PM, Timothy Grant <[EMAIL PROTECTED]> wrote:
> On Mon, Aug 11, 2008 at 8:44 AM, Casey <[EMAIL PROTECTED]> wrote:
>> My first thought is that you should be looking at implementations of
>> Hamming Distance.  If you are actually looking for something like
>> SOUNDEX you might also want to look at the double metaphor algorithm,
>> which is significantly harder to implement but provides better
>> matching and is less susceptible to differences based on name origins.
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>
> I responded in the thread of the poster's original message on this
> subject, but will do the same here. I have a horribly ugly version of
> the double-metaphone algorithm in python that does work, and may be of
> some use in solving this problem.
>
> --
> Stand Fast,
> tjg. [Timothy Grant]
>
--
http://mail.python.org/mailman/listinfo/python-list


Professional Grant Proposal Writing Workshop (August 2008: Boston, Massachusetts - University of Phoenix Campus)

2008-08-11 Thread Anthony Jones


The Grant Institute: Certificate in Professional Program Development and Grant Communication 
will be held at the University of Phoenix - Burlington Campus, August 18 - 22, 2008.  Interested development professionals, researchers, faculty, and graduate students should register as soon as possible, as demand means that seats will fill up quickly. Please forward, post, and distribute this e-mail to your colleagues and listservs.
 
All participants will receive certification in professional grant writing from the Institute, as well as 3.5 CEU units. For more information call (888) 824 - 4424 or visit The Grant Institute at www.thegrantinstitute.com
 
Please find the program description below:
 
The Grant Institute
Certificate in Professional Program Development and Grant Communication
will be held at the
University of Phoenix - Burlington Campus
Burlington, Massachusetts
August 18 - 22, 2008
8:00 AM - 5:00 PM
 
The Grant Institute: Certificate in Professional Program Development and Grant Communication is a five-day intensive and interactive experience in which participants will be led through the program development, grant writing, and funding acquisition processes through the completion of four courses.  
The Grant Institute is not a seminar.  Participants will actively engage in exercises and activities designed to strengthen their mastery of grant acquisition.   Through the completion of varying assignments, students will leave The Grant Institute with a real grant proposal outline complete with quality research, solid content, and expert review.  The Grant Institute 
focuses on combining the fundamentals of grant proposal writing with expert knowledge of communication principles such as Strategic Research, Persuasion, Argumentation, and Framing.   
 
The Grant Institute
 trainers and consultants do not merely lecture participants, but act as personal consultants and coaches dedicated to encouraging participants to succeed beyond their own expectations.  While The Grant Institute uses collaboration and small groups for many exercises, each participant will work on their organization's pro ject.  Participants are not overwhelmed with negativity or discouragement, but will be given the highest level of expertise to generate confidence in pursuing any 
funding project. 
 
At The Grant Institute
 , participants don't j ust learn to write grant proposals from top to bottom.   Participants become specialists in our unique area of expertise: Grant Communication.  Simply put, this is not your grandfather's grantwriting workshop.  Our graduates are strategic, innovative, and confident.   Whether you are new to professional grantwriting, or an experienced professional, you will not want to miss The Grant Institute.
 
 
The Grant Institute consists of four (4) courses that will be completed during the five-day workshop.
 
(1) Program Development and Evaluation
 

This course is centered around the belief that "it's all about the program."    This intensive course will teach professional program development essentials and program evaluation.  While most grantwriting "workshops" treat program development and evaluation as separate from the writing of a proposal, this class will teach students the relationship between overall program planning and all strategic communication, including grantwriting.  Consistent in our belief in 
grant communication, this class encourages students to understand successful program development and to think strategically about funding as an integral part of the overall program planning process.  This class turns students into experts by teaching how to take ideas and concepts and turn them into professionally developed programs. 
 
(2) Advanced Grant Writing
 

Designed for both the novice and experienced grantwriter, this course will make each student an overall fundraising communication specialist.  In addition to teaching the basic components of a grant proposal, successful approaches, and the do's and don'ts of grantwriting, this course is infused with expert principles that will lead to a mastery of the process.  Strategy resides at the forefront of this course's intent to illustrate grantwriting as an integrated, multidimensional, and 
dynamic endeavor.  Each student will learn to stop writing the grant and to start writing the story.  Ultimately, this class will illustrate how each component of the grant proposal represents an opportunity to use proven techniques for generating support.   
 
(3) Strategic Grant Research
 

At its foundation, this course will address the basics of foundation, corporation, and government grant research.  However, this course will teach a strategic funding research approach that encourages students to see research not as something they do before they write a proposal, but as an integrated part of the grant seeking process.  Students will be exposed to online and database research tools, as well as publications and directories which contain information

Re: for x,y in word1, word2 ?

2008-08-11 Thread Timothy Grant
On Mon, Aug 11, 2008 at 12:13 PM, Dave Webster <[EMAIL PROTECTED]> wrote:
> Thanks, Timothy.  I'm pretty sure that there is no such thing as a "beautiful"
> implementation of double-metaphone but I would personally like to have a copy
> of your python implementation.  I have a fairly elegant version of the 
> original
> metaphone algorithm I wrote myself (in PERL, many years ago) but I've
> never found
> the time to reverse-engineer the original C++ code for double-metaphone and
> "pythonize" it.
>
> On Mon, Aug 11, 2008 at 2:08 PM, Timothy Grant <[EMAIL PROTECTED]> wrote:
>> On Mon, Aug 11, 2008 at 8:44 AM, Casey <[EMAIL PROTECTED]> wrote:
>>> My first thought is that you should be looking at implementations of
>>> Hamming Distance.  If you are actually looking for something like
>>> SOUNDEX you might also want to look at the double metaphor algorithm,
>>> which is significantly harder to implement but provides better
>>> matching and is less susceptible to differences based on name origins.
>>> --
>>> http://mail.python.org/mailman/listinfo/python-list
>>>
>>
>> I responded in the thread of the poster's original message on this
>> subject, but will do the same here. I have a horribly ugly version of
>> the double-metaphone algorithm in python that does work, and may be of
>> some use in solving this problem.
>>
>> --
>> Stand Fast,
>> tjg. [Timothy Grant]
>>
>
This is truly cringe-worthy, and pretty much a direct port of the C++
code. It need unit tests (which are on my "to-do someday" list) but
even though it's ugly it does work and I have managed to do real work
with it.


-- 
Stand Fast,
tjg. [Timothy Grant]
#
# DMetaph.py
#
# Copyright 2006 by Timothy (rhacer) Grant
#
# Based on an algorithm and code by Lawrence Philips
# 
# This code is licensed under the terms of the GNU Public License v2
#

import re

DEBUG = False

class DMetaph(str):
"""
DMetaph() creates a Double Metaphone encoding of the word passed in.


"""
def __init__(self, s):
self.s = s.upper() + ' '  # Padding allows safe indexing beyond the end
self.length = len(s)
self.last = self.length - 1

self.current = 0
self.primary = ""
self.secondary = ""
self.alternate = False

if self.StringAt(0, 2, 'GN', 'KN', 'PN', 'WR', 'PS'):
self.current += 1

if self.s[0] == 'X':
self.MetaphAdd('S')
self.current += 1

while len(self.primary) < 4 or len(self.secondary) < 4:
if DEBUG: print "processing character: %s current: %s length: %s" % (
self.s[self.current], self.current, self.length)

if self.current >= self.length:
break

self.ProcessString()

self.metaph = self.primary
self.metaph2 = ''
if len(self.metaph) > 4:
self.metaph = self.metaph[:4]

if self.alternate:
self.metaph2 = self.secondary
if len(self.metaph2) > 4:
self.metaph2 = self.metaph2[:4]


def SlavoGermanic(self):
if ('W' in self.s or 'K' in self.s 
or 'CZ' in self.s or 'WITZ' in self.s):
return True
return False

def MetaphAdd(self, main, alt=None):
if main:
self.primary += main

if alt:
self.alternate = True

if (alt[0] <> ' '):
self.secondary += alt
else:
if (main[0] <> ' '):
self.secondary += main

def IsVowel(self, at):
if (at < 0) or (at > self.length):
return False

if self.s[at] in 'AEIOUY':
return True

return False

def StringAt(self, start, length, *sub_strings):
if self.s[start:start + length] in sub_strings:
return True

return False

def print_diags(self, section):
print"section: %s current: %s" % (section, self.current)

def ProcessString(self):
if self.IsVowel(self.current):
if DEBUG: self.print_diags('VOWEL')

if self.current == 0:
self.MetaphAdd('A')

self.current += 1
return

elif self.s[self.current] == 'B':
if DEBUG: self.print_diags('B')

self.MetaphAdd('P')

if self.s[self.current + 1] == 'B':
self.current += 2
else:
self.current += 1

return

elif self.s[self.current] == 'C':
if DEBUG: self.print_diags('C')

if (self.current > 1
and not self.IsVowel(self.current - 2)
and self.StringAt(self.current - 1, 3, 'ACH')
and self.s[self.current + 2] <> 'I' 
 

RE: SSH utility

2008-08-11 Thread Support Desk
What about pexpect?


http://www.noah.org/wiki/Pexpect


-Original Message-
From: Alan Franzoni [mailto:[EMAIL PROTECTED] 
Sent: Monday, August 11, 2008 5:41 AM
To: python-list@python.org
Subject: Re: SSH utility

James Brady was kind enough to say:

> Hi all,
> I'm looking for a python library that lets me execute shell commands
> on remote machines.
> 
> I've tried a few SSH utilities so far: paramiko, PySSH and pssh;
> unfortunately all been unreliable, and repeated questions on their
> respective mailing lists haven't been answered...

Twisted conch seems to be your last chance :-) 

-- 
Alan Franzoni <[EMAIL PROTECTED]>
-
Remove .xyz from my email in order to contact me.
-
GPG Key Fingerprint:
5C77 9DC3 BD5B 3A28 E7BC 921A 0255 42AA FE06 8F3E


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


Re: Inheritance crossover packages

2008-08-11 Thread Bruno Desthuilliers

Johannes Bauer a écrit :

Hello group,

I'm having a seemingly simple problem. I want to generate a hierarchy of 
modules, like this one:


GenerationScripts/
GenerationScripts/dhcp
GenerationScripts/bind9

And the files:

GenerationScripts/dhcp/__init__.py
GenerationScripts/bind9/generator.py
GenerationScripts/bind9/__init__.py
GenerationScripts/mastergen.py
GenerationScripts/__init__.py

All packages (bind9, dhcp) should inherit from the master generator 
"mastergen".


Sorry but this makes no sense. inheritance is a class feature - packages 
and modules don't 'inherit'.



I'm at the very beginning:

$ cat GenerationScripts/__init__.py
import bind9
#import dhcpd

$ cat GenerationScripts/bind9/__init__.py
import GenerationScripts.bind9.generator

$ cat GenerationScripts/bind9/generator.py
from GenerationScripts import mastergen

class generator(mastergen):


pep08 : class identifiers should be in CamelCase


def __init__(self):
print "init bind9 generator"


here, mastergen is a module object, not a class object. This just can't 
work. What are you trying to do exactly ???


Now what happens when I import GenerationScripts and try to create a 
instance of GenerationScripts.bind9.generator is the following:


Traceback (most recent call last):
  File "./Generate.py", line 3, in 
import GenerationScripts
  File "/home/joe/x/GenerationScripts/__init__.py", line 3, in 
import bind9
  File "/home/joe/x/GenerationScripts/bind9/__init__.py", line 4, in 


import GenerationScripts.bind9.generator
  File "/home/joe/x/GenerationScripts/bind9/generator.py", line 7, in 


class generator(mastergen):
TypeError: Error when calling the metaclass bases
module.__init__() takes at most 2 arguments (3 given)

>
I really don't get it - and I've searched and found the same problem, 
read the descirption - but still don't get it. What's happening here?


What's happening is that you try to use a module instance (really: an 
instance of class 'module') as a base class - and, as a result, the 
'module' class as a metaclass. But 1/ the 'module' class initializer's 
signature is not compatible with a metaclass signature, and 2/ anyway, 
the 'module' class constructor doesn't return a class object anyway.


I don't know what you trying to do, but I suggest you (re)read the 
FineManual(tm)'s relevant sections, that is, sections about modules and 
packages, and sections about Python's 'new-style' object model.


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


Re: Python for Blackberry mobile phones

2008-08-11 Thread James Matthews
It would be also nice to see python on an iPhone

On Mon, Aug 11, 2008 at 8:29 AM, Timothy Grant <[EMAIL PROTECTED]>wrote:

> On Sun, Aug 10, 2008 at 9:54 PM,  <[EMAIL PROTECTED]> wrote:
> > I'm looking for a version of Python for Blackberry mobile phones - has
> > anyone heard of such a thing? I've been googling this topic without
> success.
> >
> > Thanks,
> > Malcolm
>
> My understanding is that the BB's run Java, so there *may* be some
> chance that it might be possible to get Jython running on it.
>
>
> --
> Stand Fast,
> tjg.  [Timothy Grant]
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
http://www.goldwatches.com/
--
http://mail.python.org/mailman/listinfo/python-list

Re: dynamically creating html code with python...

2008-08-11 Thread Bruno Desthuilliers

[EMAIL PROTECTED] a écrit :

Sorry, my fault...

I am trying to build a web application for data analysis. Basically
some data will be read from a database and passed to a python script
(myLibs.py) to build an image as follows.

[CODE] 
f=urllib.urlopen("http://localhost/path2Libs/myLibs.py",urllib.urlencode(TheData))
 print "Content-type: image/png\n" 

> print f.read()
> f.close()
> [/CODE]


This section behaves as expected, and I can see the chart on the
web-page.


Indeed. Using an http request to call a local script is totally 
braindead, but this is another problem.



Now, I would like to add some text and possibly more charts
(generated in the same way) to my web-page.


Which one ? What you showed is a way to generate an image resource (with 
mime-type 'image/png'), not an html page resource (mime-type : 
text/html). Images resources are not directly embedded in html pages - 
they are *referenced* from web pages (using an  tag), then it's up 
to the user-agent (usually, the browser) to emit another http request to 
get the image.




This is what I need help
with.


Not tested (obviously), but what you want is something like:

print "Content-type: text/html\n"
print """

  
data analysis site
  
  
This is a trial test
http://localhost/myLibs/ChartLib.py?%s"; />
  

""" % urllib.urlencode(TheData)



My question: How can I use python to dynamically add descriptive
comments (text), and possibly more charts to the web-page?


The code you showed so far either tried to add text/html to an image 
(that is, binary data), or to embed the image's binary data into 
text/html. None of this makes sense. Period.  The problem is not with 
Python. The problem is that you can't seriously hope to do web 
programming without any knowledge of the http protocol.


Also and FWIW, you'd be better using a decent templating system (mako, 
cheetah, genshi, tal, whatever fits your brain) instead of generating 
html that way.

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

Re: Digitally sign PDF files

2008-08-11 Thread Hartmut Goebel

Hi,


I'm developing an application with some reports and we're looking for
advice. This reports should be openoffice.org .odf files, pdf files,
and perhaps microsoft word files (.doc, .docx?) and must be digitally
signed. Is out there some kind of libraries to ease this tasks?


For signing you can use OpenSSL or the more complete M2crypto modules. 
But this is only the crypto part of the task.


> * Access to the local user certificate store, and read PEM or PKCS12
> certificate files.

If the certificate store is just a file, both packages can to this. If 
the store is some otehr format or maybe the Windows registry, some 
additional functions are required, but should be easy to implement.


> * Read, parse and validate user certificates

This can be easily done with both.


* Sign documents: as a binary stream, within an specific document
(pdf, odt, doc)


This is the hardest part of the task, since the signature has to be 
embedded into the document.



--
Schönen Gruß - Regards
Hartmut Goebel

Goebel Consult
Spezialist für IT-Sicherheit in komplexen Umgebungen
http://www.goebel-consult.de
--
http://mail.python.org/mailman/listinfo/python-list


Full Time Python developer position in Dallas TX

2008-08-11 Thread Bhavani
please respond with resume. Candidates must be in the USA.
--
http://mail.python.org/mailman/listinfo/python-list


Re: A Question about ctypes and a function f(void **)

2008-08-11 Thread Nick Craig-Wood
sapsi <[EMAIL PROTECTED]> wrote:
>  I have a C function f(void**,int *), in which it writes some
>  information (it is a RGB32 image).
> 
>  Here is what i do
>  rowlength=c_int()
>  data=c_void_p()
>  d=pointer(data)
>  f(d,byref(rowlength)
>  The call works (no segmentation fault), now how do i access the data
>  in d? Because i need to pass it to a another function  QImage that
>  takes void* as its first parameter.
> 
>  If i do d.contents i get c_void_p(3067478024L)

You almost answered your own question!

d.contents is a c_void_p ie a (void *) so you can pass d.contents to
QImage directly I would have thought.

If you want to actually read the data from python then you'll need to
cast it to some other pointer type than c_void_p first, eg

  >>> d
  c_void_p(136692916)
  >>> s = c_char_p(d.value)
  >>> s
  c_char_p(136692916)
  >>> s.value
  'hello'
  >>>

or use ctypes.memmove to copy the data out to somewhere else.

-- 
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list


Custom PyQt4 Slots

2008-08-11 Thread ff
Is it possible to create custom PyQt4 Slots, i have searched high and
low to no avail;

I have an application that can set animation speed to different
levels, i want the user to alter this, now quite clearly i can write a
single function to control setting any speed with something like:

def setSpeed(self, speed):
 some code in here to set speed

but if i have mutiple option for speed do i have to connect them all
to seperate callables for each individual speed which each in turn
call setSpeed with their respective speeds or can i create a slot that
can simply pass an integer to setSpeed in much the same way as the
built-in SIGNAL from something like a combo box can pass its current
index??

i realise this could be impossibly, knowing that would be equally
useful and i will just work around it, albeit with more verbose code!!

thanks

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


Re: list question... unique values in all possible unique spots

2008-08-11 Thread Tobiah
On Sat, 09 Aug 2008 08:07:26 -0700, Mensanator wrote:

> 40329146112660563558400

I think it's only 4 septillion.

Perfectly manageable.

** Posted from http://www.teranews.com **
--
http://mail.python.org/mailman/listinfo/python-list


Re: Custom PyQt4 Slots

2008-08-11 Thread Diez B. Roggisch

ff schrieb:

Is it possible to create custom PyQt4 Slots, i have searched high and
low to no avail;

I have an application that can set animation speed to different
levels, i want the user to alter this, now quite clearly i can write a
single function to control setting any speed with something like:

def setSpeed(self, speed):
 some code in here to set speed

but if i have mutiple option for speed do i have to connect them all
to seperate callables for each individual speed which each in turn
call setSpeed with their respective speeds or can i create a slot that
can simply pass an integer to setSpeed in much the same way as the
built-in SIGNAL from something like a combo box can pass its current
index??

i realise this could be impossibly, knowing that would be equally
useful and i will just work around it, albeit with more verbose code!!


http://docs.huihoo.com/pyqt/pyqt4.html#pyqt-signals-and-qt-signals

"""
PyQt allows new signals to be defined dynamically. The act of emitting a 
PyQt signal implicitly defines it. PyQt v4 signals are also referenced 
using the QtCore.SIGNAL() function.

"""

Work on your google-fu...

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


Re: list question... unique values in all possible unique spots

2008-08-11 Thread Tobiah
On Mon, 11 Aug 2008 13:46:10 -0700, Tobiah wrote:

> On Sat, 09 Aug 2008 08:07:26 -0700, Mensanator wrote:
> 
>> 40329146112660563558400
> 
> I think it's only 4 septillion.

I meant 403.



** Posted from http://www.teranews.com **
--
http://mail.python.org/mailman/listinfo/python-list


Re: list question... unique values in all possible unique spots

2008-08-11 Thread Tobiah
On Mon, 11 Aug 2008 13:46:10 -0700, Tobiah wrote:

> On Sat, 09 Aug 2008 08:07:26 -0700, Mensanator wrote:
> 
>> 40329146112660563558400
> 
> I think it's only 4 septillion.

I meant to say 403.
** Posted from http://www.teranews.com **
--
http://mail.python.org/mailman/listinfo/python-list


Re: Custom PyQt4 Slots

2008-08-11 Thread Diez B. Roggisch

Diez B. Roggisch schrieb:

ff schrieb:

Is it possible to create custom PyQt4 Slots, i have searched high and
low to no avail;

I have an application that can set animation speed to different
levels, i want the user to alter this, now quite clearly i can write a
single function to control setting any speed with something like:

def setSpeed(self, speed):
 some code in here to set speed

but if i have mutiple option for speed do i have to connect them all
to seperate callables for each individual speed which each in turn
call setSpeed with their respective speeds or can i create a slot that
can simply pass an integer to setSpeed in much the same way as the
built-in SIGNAL from something like a combo box can pass its current
index??

i realise this could be impossibly, knowing that would be equally
useful and i will just work around it, albeit with more verbose code!!


http://docs.huihoo.com/pyqt/pyqt4.html#pyqt-signals-and-qt-signals

"""
PyQt allows new signals to be defined dynamically. The act of emitting a 
PyQt signal implicitly defines it. PyQt v4 signals are also referenced 
using the QtCore.SIGNAL() function.

"""


And not to forget:

"""
A slot is a function (in PyQt a slot is any Python callable).
"""

It's as easy as it can get.

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


Re: Digitally sign PDF files

2008-08-11 Thread haxier
On 11 ago, 22:29, Hartmut Goebel <[EMAIL PROTECTED]> wrote:

> > I'm developing an application with some reports and we're looking for
> > advice. This reports should be openoffice.org .odf files, pdf files,
> > and perhaps microsoft word files (.doc, .docx?) and must be digitally
> > signed. Is out there some kind of libraries to ease this tasks?
>
> For signing you can use OpenSSL or the more complete M2crypto modules.
> But this is only the crypto part of the task.

M2Crypto? I didn't know of it... surely I must check it.

It's a very delicate component (security and reliability is a must)
and don't know how openssl works in windows environments.

>  > * Access to the local user certificate store, and read PEM or PKCS12
>  > certificate files.
>
> If the certificate store is just a file, both packages can to this. If
> the store is some otehr format or maybe the Windows registry, some
> additional functions are required, but should be easy to implement.

Certificates can be both: PKCS12 (.p12) files and under the windows
certificate store.

The best option could be some kind of thin wrapper around windows
CryotoAPI, so access to hardware tokens and smartcard readers should
be easy because under Linux everything seems tied to Mozilla NSS
libraries.

> > * Sign documents: as a binary stream, within an specific document
> > (pdf, odt, doc)
>
> This is the hardest part of the task, since the signature has to be
> embedded into the document.

OpenOffice.org uses XML DSIG (libxmlsec, libxml2) as stated here[1]
but I can't find more than this[2] implementation/wrapper of libxmlsec

PDF signing... I can't find something like iText for Python... I've
finded examples like this[3] based on Jython... perhaps I should look
at jython because java 1.6 has full access to Windows CryptoAPI and
full XML-DSIG support[4]

IronPython could also be an interesting option for obvious reasons and
there's and iText port for .NET

Thanks

[1] 
http://marketing.openoffice.org/ooocon2004/presentations/friday/timmermann_digital_signatures.pdf
[2] http://xmlsig.sourceforge.net/build.html
[3] http://kelpi.com/script/00cd7c
[4] 
http://java.sun.com/javase/6/docs/technotes/guides/security/xmldsig/XMLDigitalSignature.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: eval or execute, is this the (most) correct way ?

2008-08-11 Thread Martin v. Löwis
> So AFAIK, sometimes I've to use eval and sometimes I need exec,
> so I use the following code (global / local dictionary parameters are
> left out in this example):
> 
> 
> Is this the (most) correct / elegant way, or are there better solutions ?

You should be using compile with the "single" start symbol, and then
use eval on the resulting code option.

> I read somewhere that exec is going to disappear,

That's not true. exec stops being a statement, and becomes a function
(like print).

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


Re: dict.update() useful or not?

2008-08-11 Thread Martin v. Löwis
>> def create_request(url, headers):
>> headers.update(DEFAULT_HEADERS)
>> req = urllib2.Request(url, None, headers)
>> # ... 
>> return req
>>
>> but of course this second example does the Wrong Thing, replacing 
>> explicit headers with default values.
> 
> There's a second code smell with that: even if it did what you want it 
> isn't nice to mutate the parameter passed in as headers. What if the caller 
> wants to reuse the headers again for another call? 

Just in case it isn't clear what the problem with that code is:
create_request is a function, ie. it returns a value. As such,
it shouldn't have any side effects. If it has side effects, it
should be considered a procedure, and return None.

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


Re: Custom PyQt4 Slots

2008-08-11 Thread ff
On Aug 11, 9:56 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> Diez B. Roggisch schrieb:
>
>
>
> > ff schrieb:
> >> Is it possible to create custom PyQt4 Slots, i have searched high and
> >> low to no avail;
>
> >> I have an application that can set animation speed to different
> >> levels, i want the user to alter this, now quite clearly i can write a
> >> single function to control setting any speed with something like:
>
> >> def setSpeed(self, speed):
> >>      some code in here to set speed
>
> >> but if i have mutiple option for speed do i have to connect them all
> >> to seperate callables for each individual speed which each in turn
> >> call setSpeed with their respective speeds or can i create a slot that
> >> can simply pass an integer to setSpeed in much the same way as the
> >> built-in SIGNAL from something like a combo box can pass its current
> >> index??
>
> >> i realise this could be impossibly, knowing that would be equally
> >> useful and i will just work around it, albeit with more verbose code!!
>
> >http://docs.huihoo.com/pyqt/pyqt4.html#pyqt-signals-and-qt-signals
>
> > """
> > PyQt allows new signals to be defined dynamically. The act of emitting a
> > PyQt signal implicitly defines it. PyQt v4 signals are also referenced
> > using the QtCore.SIGNAL() function.
> > """
>
> And not to forget:
>
> """
> A slot is a function (in PyQt a slot is any Python callable).
> """
>
> It's as easy as it can get.
>
> Diez

Sorry, yeah getting confused between SIGNALS and SLOTS, thanks
--
http://mail.python.org/mailman/listinfo/python-list


Re: dynamically creating html code with python...

2008-08-11 Thread anartz
This makes sense. Thanks!

I managed to get what I wanted with something similar to what you suggested:

[CODE]
print "Content-Type: text/html\n\n"
html="""



data analysis site



This is a test

After image text

"""

print html % myChartsLib.myPlotType(TheData)
[/CODE]

and the script returns

[CODE]
f = StringIO.StringIO()
pylab.savefig(f)
return 'data:image/png,' + urllib.quote(f.getvalue())
[/CODE]

This works fine in Firefox, but not in IE7. Any ideas why?

BTW, you are right about me not having a clue about http. It's the first time I 
try to do something with it. May be you could point me out to some good links 
where I can learn.

I will take a look into Mako too.

Thanks again.

Bruno Desthuilliers <[EMAIL PROTECTED]> wrote :

> [EMAIL PROTECTED] a écrit :
> > Sorry, my fault...
> > 
> > I am trying to build a web application for data analysis. Basically
> > some data will be read from a database and passed to a python script
> > (myLibs.py) to build an image as follows.
> > 
> > [CODE] 
> > f=urllib.urlopen("http://localhost/path2Libs/myLibs.py",urllib.urlencode(TheData))
> >  print "Content-type: image/png\n" 
>  > print f.read()
>  > f.close()
>  > [/CODE]
> > 
> > This section behaves as expected, and I can see the chart on the
> > web-page.
> 
> Indeed. Using an http request to call a local script is totally 
> braindead, but this is another problem.
> 
> > Now, I would like to add some text and possibly more charts
> > (generated in the same way) to my web-page.
> 
> Which one ? What you showed is a way to generate an image resource (with 
> mime-type 'image/png'), not an html page resource (mime-type : 
> text/html). Images resources are not directly embedded in html pages - 
> they are *referenced* from web pages (using an  tag), then it's up 
> to the user-agent (usually, the browser) to emit another http request to 
> get the image.
> 
> 
> > This is what I need help
> > with.
> 
> Not tested (obviously), but what you want is something like:
> 
> print "Content-type: text/html\n"
> print """
> 
>
>  data analysis site
>
>
>  This is a trial test
>  http://localhost/myLibs/ChartLib.py?%s"; />
>
> 
> """ % urllib.urlencode(TheData)
> 
> 
> > My question: How can I use python to dynamically add descriptive
> > comments (text), and possibly more charts to the web-page?
> 
> The code you showed so far either tried to add text/html to an image 
> (that is, binary data), or to embed the image's binary data into 
> text/html. None of this makes sense. Period.  The problem is not with 
> Python. The problem is that you can't seriously hope to do web 
> programming without any knowledge of the http protocol.
> 
> Also and FWIW, you'd be better using a decent templating system (mako, 
> cheetah, genshi, tal, whatever fits your brain) instead of generating 
> html that way.
> --
> http://mail.python.org/mailman/listinfo/python-list



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

Re: eval or execute, is this the (most) correct way ?

2008-08-11 Thread Stef Mientki

Martin v. Löwis wrote:

So AFAIK, sometimes I've to use eval and sometimes I need exec,
so I use the following code (global / local dictionary parameters are
left out in this example):


Is this the (most) correct / elegant way, or are there better solutions ?



You should be using compile with the "single" start symbol, and then
use eval on the resulting code option.

  

thanks Martin,
but when I read the doc (of one of the many) "compile" functions,
I see 2 problems:
- I still have to provide "kind" as exec or eval
- I can not specify the global and local namespace (which is essential 
for me)

I read somewhere that exec is going to disappear,



That's not true. exec stops being a statement, and becomes a function
(like print).

  

That's good to hear,
as I already didn't realize it could also be used as a statement ;-)

cheers,
Stef


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


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


  1   2   >