Re: no sign() function ?

2008-12-24 Thread Pierre-Alain Dorange
Steven D'Aprano  wrote:

> > sign_0 : 0.375
> > sign_1 : 0.444 (+18%)
> > sign_2 : 0.661 (+76%)
> > sign_3 : 0.498 (+33%)
> 
> 
> Looking at those results, and remembering that each time is for one 
> million iterations of one thousand calls each,

one million iteration only, that's enough but yes indeed this function
is fast.

> I'd say that there's so 
> little difference in speed between them, that you should choose whichever
> function is easier to understand.

Yes, you're right. I just made those test for pure intellectual reason.

For me sign_0 is the simplest one to understood. 
So in the domain of my little arcade game, this is what i'll use.
I don't need the accuraccy of sign_1, because in the application i just
need to know if the target is right or left or if the speed direction is
right or left.

> At least until you profile your 
> application and discover that the sign() function is the bottleneck 
> keeping your program slow.

In each frame i'll have to use about 10 to 20 sign() call, so it'll not
be the bottleneck.

-- 
Pierre-Alain Dorange

Ce message est sous licence Creative Commons "by-nc-sa-2.0"

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


Re: Strategy for determing difference between 2 very large dictionaries

2008-12-24 Thread Malcolm Greene
Hi Roger,

By very large dictionary, I mean about 25M items per dictionary. Each
item is a simple integer whose value will never exceed 2^15.

I populate these dictionaries by parsing very large ASCII text files
containing detailed manufacturing events. From each line in my log file
I construct one or more keys and increment the numeric values associated
with these keys using timing info also extracted from each line.

Some of our log files are generated by separate monitoring equipment
measuring the same process. In theory, these log files should be
identical, but of course they are not. I'm looking for a way to
determine the differences between the 2 dictionaries I will create from
so-called matching sets of log files.

At this point in time, I don't have concerns about memory as I'm running
my scripts on a dedicated 64-bit server with 32Gb of RAM (but with
budget approval to raise our total RAM to 64Gb if necessary).

My main concern is am I applying a reasonably pythonic approach to my
problem, eg. am I using appropriate python techniques and data
structures? I am also interested in using reasonable techniques that
will provide me with the fastest execution time.

Thank you for sharing your thoughts with me.

Regards,
Malcolm


- Original message -
From: "Roger Binns" 
To: python-list@python.org
Date: Tue, 23 Dec 2008 23:26:49 -0800
Subject: Re: Strategy for determing difference between 2 very large
dictionaries

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

pyt...@bdurham.com wrote:
> Feedback on my proposed strategies (or better strategies) would be
> greatly appreciated.

Both strategies will work but I'd recommend the second approach since it
uses already tested code written by other people - the chances of it
being wrong are far lower than new code.

You also neglected to mention what your concerns are or even what "very
large" is.  Example concerns are memory consumption, cpu consumption,
testability, utility of output (eg as a generator getting each result on
demand or a single list with complete results).  Some people will think
a few hundred entries is large.  My idea of large is a working set
larger than my workstation's 6GB of memory :-)

In general the Pythonic approach is:

1 - Get the correct result
2 - Simple code (developer time is precious)
3 - Optimise for your data and environment

Step 3 is usually not needed.

Roger
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAklR5DUACgkQmOOfHg372QSuWACgp0xrdpW+NSB6qqCM3oBY2e/I
LIEAn080VgNvmEYj47Mm7BtV69J1GwXN
=MKLl
-END PGP SIGNATURE-

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


Re: Most efficient way to build very large dictionaries

2008-12-24 Thread Roger Binns
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

pyt...@bdurham.com wrote:
> I would appreciate your thoughts on whether there are advantages to
> working with a pre-built dictionary and if so, what are the best ways to
> create a pre-loaded dictionary.

Based on this and your other thread, you may want to consider using
SQLite (standard Python module is available for it).  SQL queries are
very similar to set operations and indices take care of performance (by
using more storage).  You also get transactions for free.  If you look
into SQLite pragmas you can get it to use more RAM to improve performance.

And by using a SQL layer you can later switch to another database should
you need really hard core storage.  It also makes the data available to
other programs in a uniform way.

Roger
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAklR8KgACgkQmOOfHg372QSrHQCfVJzueXVKme8QZcxoLf70BL4K
RL8AoM9QOFykOLrr5QXtpmZ5f7CFHm6e
=zAPG
-END PGP SIGNATURE-

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


Re: Strategy for determing difference between 2 very large dictionaries

2008-12-24 Thread python
Hi Gabriel,

Thank you very much for your feedback!

> k1 = set(dict1.iterkeys())

I noticed you suggested .iterkeys() vs. .keys(). Is there any advantage
to using an iterator vs. a list as the basis for creating a set? I
understand that an iterator makes sense if you're working with a large
set of items one at a time, but if you're creating a non-filtered
collection, I don't see the advantage of using an iterator or a list.
I'm sure I'm missing a subtle point here :)

>> can this last step be done via a simple list comprehension?

> Yes; but isn't a dict comprehension more adequate?
>
> [key: (dict1[key], dict2[key]) for key in common_keys if  
> dict1[key]!=dict2[key]}

Cool!! I'm relatively new to Python and totally missed the ability to
work with dictionary comprehensions. Yes, your dictionary comprehension
technique is much better than the list comprehension approach I was
struggling with. Your dictionary comprehension statement describes
exactly what I wanted to write.

Regards,
Malcolm


- Original message -
From: "Gabriel Genellina" 
To: python-list@python.org
Date: Wed, 24 Dec 2008 05:46:04 -0200
Subject: Re: Strategy for determing difference between 2 very large
dictionaries

En Wed, 24 Dec 2008 05:16:36 -0200,  escribió:

> I'm looking for suggestions on the best ('Pythonic') way to
> determine the difference between 2 very large dictionaries
> containing simple key/value pairs.
> By difference, I mean a list of keys that are present in the
> first dictionary, but not the second. And vice versa. And a list
> of keys in common between the 2 dictionaries whose values are
> different.
> The 2 strategies I'm considering are:
> 1. Brute force: Iterate through first dictionary's keys and
> determine which keys it has that are missing from the second
> dictionary. If keys match, then verify that the 2 dictionaries
> have identical values for the same key. Repeat this process for
> the second dictionary.
> 2. Use sets: Create sets from each dictionary's list of keys and
> use Python's set methods to generate a list of keys present in
> one dictionary but not the other (for both dictionaries) as well
> as a set of keys the 2 dictionaries have in common.

I cannot think of any advantage of the first approach - so I'd use sets.

k1 = set(dict1.iterkeys())
k2 = set(dict2.iterkeys())
k1 - k2 # keys in dict1 not in dict2
k2 - k1 # keys in dict2 not in dict1
k1 & k2 # keys in both

> Using the set
> of keys in common, compare values across dictionaries to
> determine which keys have different values (can this last step be
> done via a simple list comprehension?)

Yes; but isn't a dict comprehension more adequate?

[key: (dict1[key], dict2[key]) for key in common_keys if  
dict1[key]!=dict2[key]}

(where common_keys=k1&k2 as above)

-- 
Gabriel Genellina

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


Re: Most efficient way to build very large dictionaries

2008-12-24 Thread Roger Binns
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

pyt...@bdurham.com wrote:
> Can I take advantage of this knowledge to optimize

You do the optimization last :-)  The first thing you need to do is make
sure you have a way of validating you got the correct results.  With 25M
entries it would be very easy for an optimization to get the wrong
results (maybe only one result wrong).  Once you can verify the results
correctness, write the simplest most readable code possible.

Then once your whole program is approaching completion time how long
things take to get an idea of where to optimize.  For example it is
pointless optimizing the loading phase if it only takes 2 minutes out of
a 3 hour runtime.  Finally you can optimize and always have a way of
verifying that the optimizations are correct.  You have the original
code to document what is supposed to be happening as optimized code
tends to get rather obfuscated and unreadable.

Roger
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAklR8mkACgkQmOOfHg372QQvLQCgu6NYNUuhgR06KQunPmIrZ64B
+rsAnAgQOKzMdmonF+zIhsX2r/Xg/72Y
=LFfW
-END PGP SIGNATURE-

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


Re: Strategy for determing difference between 2 very large dictionaries

2008-12-24 Thread Marc 'BlackJack' Rintsch
On Wed, 24 Dec 2008 03:23:00 -0500, python wrote:

> Hi Gabriel,
> 
> Thank you very much for your feedback!
> 
>> k1 = set(dict1.iterkeys())
> 
> I noticed you suggested .iterkeys() vs. .keys(). Is there any advantage
> to using an iterator vs. a list as the basis for creating a set? I
> understand that an iterator makes sense if you're working with a large
> set of items one at a time, but if you're creating a non-filtered
> collection, I don't see the advantage of using an iterator or a list.
> I'm sure I'm missing a subtle point here :)

`keys()` creates a list in memory, `iterkeys()` does not.  With
``set(dict.keys())`` there is a point in time where the dictionary, the 
list, and the set co-exist in memory.  With ``set(dict.iterkeys())`` only 
the set and the dictionary exist in memory.

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


Re: Most efficient way to build very large dictionaries

2008-12-24 Thread python
Hi Roger,

> you may want to consider using SQLite

Thank you for your suggestion about looking at SQLite. I haven't
compared the performance of SQLite to Python dictionaries, but I'm
skeptical that SQLite would be faster than in-memory Python dictionaries
for the type of analysis I'm doing. Prior to my use of Python, my
customer used a very expensive Oracle system to analyze their log files.
My simple Python scripts are 4-20x faster than the Oracle PL/SQL they
are replacing - and run on much cheaper hardware.

Note: Memory is currently not a concern for me so I don't need SQLite's
ability to work with data sets larger than my physical memory.

Regards,
Malcolm


- Original message -
From: "Roger Binns" 
To: python-list@python.org
Date: Wed, 24 Dec 2008 00:19:56 -0800
Subject: Re: Most efficient way to build very large dictionaries

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

pyt...@bdurham.com wrote:
> I would appreciate your thoughts on whether there are advantages to
> working with a pre-built dictionary and if so, what are the best ways to
> create a pre-loaded dictionary.

Based on this and your other thread, you may want to consider using
SQLite (standard Python module is available for it).  SQL queries are
very similar to set operations and indices take care of performance (by
using more storage).  You also get transactions for free.  If you look
into SQLite pragmas you can get it to use more RAM to improve
performance.

And by using a SQL layer you can later switch to another database should
you need really hard core storage.  It also makes the data available to
other programs in a uniform way.

Roger
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAklR8KgACgkQmOOfHg372QSrHQCfVJzueXVKme8QZcxoLf70BL4K
RL8AoM9QOFykOLrr5QXtpmZ5f7CFHm6e
=zAPG
-END PGP SIGNATURE-

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


Re: Strategy for determing difference between 2 very large dictionaries

2008-12-24 Thread python
Hi Marc,

> `keys()` creates a list in memory, `iterkeys()` does not. With
> ``set(dict.keys())`` there is a point in time where the dictionary, the 
> list, and the set co-exist in memory.  With ``set(dict.iterkeys())``
> only the set and the dictionary exist in memory.

Perfect explanation.

Thank you!
Malcolm


- Original message -
From: "Marc 'BlackJack' Rintsch" 
To: python-list@python.org
Date: 24 Dec 2008 08:30:41 GMT
Subject: Re: Strategy for determing difference between 2 very large 
   dictionaries

On Wed, 24 Dec 2008 03:23:00 -0500, python wrote:

> Hi Gabriel,
> 
> Thank you very much for your feedback!
> 
>> k1 = set(dict1.iterkeys())
> 
> I noticed you suggested .iterkeys() vs. .keys(). Is there any advantage
> to using an iterator vs. a list as the basis for creating a set? I
> understand that an iterator makes sense if you're working with a large
> set of items one at a time, but if you're creating a non-filtered
> collection, I don't see the advantage of using an iterator or a list.
> I'm sure I'm missing a subtle point here :)

`keys()` creates a list in memory, `iterkeys()` does not.  With
``set(dict.keys())`` there is a point in time where the dictionary, the 
list, and the set co-exist in memory.  With ``set(dict.iterkeys())``
only 
the set and the dictionary exist in memory.

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


Re: Multi-dimension list

2008-12-24 Thread James Stroud

Steven Woody wrote:

Hi,

In the book Python Essential Reference, Chapter 3, when talking about
extended slicing, it gives an example:  a = m[0:10, 3:20].  But I
don't understand how the 'm' was defined.  What should it looks like?


m could be an instance of the Krayzee class.

py> class Krayzee(object):
...   def __getitem__(self, i):
... try:
...   r = ['WTF?' for j in i]
... except:
...   r = 'WTF?'
... return r
...
py> m = Krayzee()
py> m[1:2:3, 4:5:6]
['WTF?', 'WTF?']
py> m['your moms']
['WTF?', 'WTF?', 'WTF?', 'WTF?', 'WTF?', 'WTF?', 'WTF?', 'WTF?', 'WTF?']


--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

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


Re: Strategy for determing difference between 2 very large dictionaries

2008-12-24 Thread Peter Otten
Gabriel Genellina wrote:

> En Wed, 24 Dec 2008 05:16:36 -0200,  escribió:

[I didn't see the original post]

>> I'm looking for suggestions on the best ('Pythonic') way to
>> determine the difference between 2 very large dictionaries
>> containing simple key/value pairs.
>> By difference, I mean a list of keys that are present in the
>> first dictionary, but not the second. And vice versa. And a list
>> of keys in common between the 2 dictionaries whose values are
>> different.
>> The 2 strategies I'm considering are:
>> 1. Brute force: Iterate through first dictionary's keys and
>> determine which keys it has that are missing from the second
>> dictionary. If keys match, then verify that the 2 dictionaries
>> have identical values for the same key. Repeat this process for
>> the second dictionary.
>> 2. Use sets: Create sets from each dictionary's list of keys and
>> use Python's set methods to generate a list of keys present in
>> one dictionary but not the other (for both dictionaries) as well
>> as a set of keys the 2 dictionaries have in common.
> 
> I cannot think of any advantage of the first approach - so I'd use sets.
> 
> k1 = set(dict1.iterkeys())
> k2 = set(dict2.iterkeys())
> k1 - k2 # keys in dict1 not in dict2
> k2 - k1 # keys in dict2 not in dict1
> k1 & k2 # keys in both
> 
>> Using the set
>> of keys in common, compare values across dictionaries to
>> determine which keys have different values (can this last step be
>> done via a simple list comprehension?)

If you are not interested in the intermediate results and the dictionary
values are hashable you can get the difference by

>>> a = dict(a=1, b=2, c=3)
>>> b = dict(b=2, c=30, d=4)
>>> dict(set(a.iteritems()) ^ set(b.iteritems()))
{'a': 1, 'c': 3, 'd': 4}

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


Re: Most efficient way to build very large dictionaries

2008-12-24 Thread Roger Binns
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

pyt...@bdurham.com wrote:
> Thank you for your suggestion about looking at SQLite. I haven't
> compared the performance of SQLite to Python dictionaries, but I'm
> skeptical that SQLite would be faster than in-memory Python dictionaries
> for the type of analysis I'm doing.

I'd recommend at least trying a test just to see.  As an example SQLite
uses indices which will be faster than Python dicts for some set
operations.  (And if you aren't careful, your various Python based
optimizations will end up duplicating what SQLite does internally anyway :-)

> Prior to my use of Python, my
> customer used a very expensive Oracle system to analyze their log files.
> My simple Python scripts are 4-20x faster than the Oracle PL/SQL they
> are replacing - and run on much cheaper hardware.

SQLite is not like Oracle or any similar database system.  It does not
operate over the network or similar connection. It is a library in your
process that has an optimized disk storage format (single file) and a
SQL parser that generates bytecode for a special purpose virtual machine
in pretty much the same way CPython operates.  The performance
improvements you are seeing with Python over Oracle are exactly the same
range people see with SQLite over Oracle.  One common usage reported on
the SQLite mailing list is people copying data out of Oracle and running
their analysis in SQLite because of the performance advantages.

> Note: Memory is currently not a concern for me so I don't need SQLite's
> ability to work with data sets larger than my physical memory.

The pragmas tune things like cache sizes.  The SQLite default is 2MB,
relying on the operating system for caching beyond that.  Bumping up
that kind of size was my suggestion :-)

Roger

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAklR9+UACgkQmOOfHg372QSMbwCdGS5S2/96fWW8knjfBVqReAfV
AEwAn2Yc+L9BEZgT69OjwtyqxLtifVpU
=mPfy
-END PGP SIGNATURE-

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


Re: Strategy for determing difference between 2 very large dictionaries

2008-12-24 Thread James Stroud

Marc 'BlackJack' Rintsch wrote:

On Wed, 24 Dec 2008 03:23:00 -0500, python wrote:


Hi Gabriel,

Thank you very much for your feedback!


k1 = set(dict1.iterkeys())

I noticed you suggested .iterkeys() vs. .keys(). Is there any advantage
to using an iterator vs. a list as the basis for creating a set? I
understand that an iterator makes sense if you're working with a large
set of items one at a time, but if you're creating a non-filtered
collection, I don't see the advantage of using an iterator or a list.
I'm sure I'm missing a subtle point here :)


`keys()` creates a list in memory, `iterkeys()` does not.  With
``set(dict.keys())`` there is a point in time where the dictionary, the 
list, and the set co-exist in memory.  With ``set(dict.iterkeys())`` only 
the set and the dictionary exist in memory.


For the purpose of perpetuating the annoying pedantry that has made 
usenet great:



http://docs.python.org/dev/3.0/whatsnew/3.0.html#views-and-iterators-instead-of-lists



James


--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

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


Re: Strategy for determing difference between 2 very large dictionaries

2008-12-24 Thread python
Hi James,

> For the purpose of perpetuating the annoying pedantry that has made 
> usenet great:
>
> http://docs.python.org/dev/3.0/whatsnew/3.0.html#views-and-iterators-instead-of-lists

Great tip! Thank you!

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


Re: Strategy for determing difference between 2 very large dictionaries

2008-12-24 Thread Gabriel Genellina

En Wed, 24 Dec 2008 06:23:00 -0200,  escribió:


Hi Gabriel,

Thank you very much for your feedback!


k1 = set(dict1.iterkeys())


I noticed you suggested .iterkeys() vs. .keys(). Is there any advantage
to using an iterator vs. a list as the basis for creating a set? I


You've got an excelent explanation from Marc Rintsch. (Note that in Python  
3.0 keys() behaves as iterkeys() in previous versions, so the above code  
is supposed to be written in Python 2.x)



can this last step be done via a simple list comprehension?



Yes; but isn't a dict comprehension more adequate?

[key: (dict1[key], dict2[key]) for key in common_keys if
dict1[key]!=dict2[key]}


Cool!! I'm relatively new to Python and totally missed the ability to
work with dictionary comprehensions. Yes, your dictionary comprehension
technique is much better than the list comprehension approach I was
struggling with. Your dictionary comprehension statement describes
exactly what I wanted to write.


This time, note that dict comprehensions require Python 3.0 -- so the code  
above won't work in Python 2.x.

(It's not a good idea to mix both versions in the same post, sorry!)
You might use instead:

dict((key,(dict1[key],dict2[key])) for key in ...)

but it's not as readable.

--
Gabriel Genellina

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


Re: Most efficient way to build very large dictionaries

2008-12-24 Thread python
Hi Roger,

> The performance improvements you are seeing with Python over Oracle are 
> exactly the same range people see with SQLite over Oracle. One common usage 
> reported on the SQLite mailing list is people copying data out of Oracle and 
> running their analysis in SQLite because of the performance advantages.

I wasn't aware that SQLite was so fast compared to Oracle. That's great
news. I will definitely take a look at SQLite for my current data
analysis project.

 ... hey, you're the author of
APSW! :)

For those following this thread, see APSW:
http://code.google.com/p/apsw/

> The pragmas tune things like cache sizes. The SQLite default is 2MB, relying 
> on the operating system for caching beyond that. Bumping up that kind of size 
> was my suggestion :-)

I missed that nuance - a side effect of emailing at 4am :)

Thanks again for your help Roger!

Regards,
Malcolm


- Original message -
From: "Roger Binns" 
To: python-list@python.org
Date: Wed, 24 Dec 2008 00:50:49 -0800
Subject: Re: Most efficient way to build very large dictionaries

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

pyt...@bdurham.com wrote:
> Thank you for your suggestion about looking at SQLite. I haven't
> compared the performance of SQLite to Python dictionaries, but I'm
> skeptical that SQLite would be faster than in-memory Python dictionaries
> for the type of analysis I'm doing.

I'd recommend at least trying a test just to see.  As an example SQLite
uses indices which will be faster than Python dicts for some set
operations.  (And if you aren't careful, your various Python based
optimizations will end up duplicating what SQLite does internally anyway
:-)

> Prior to my use of Python, my
> customer used a very expensive Oracle system to analyze their log files.
> My simple Python scripts are 4-20x faster than the Oracle PL/SQL they
> are replacing - and run on much cheaper hardware.

SQLite is not like Oracle or any similar database system.  It does not
operate over the network or similar connection. It is a library in your
process that has an optimized disk storage format (single file) and a
SQL parser that generates bytecode for a special purpose virtual machine
in pretty much the same way CPython operates.  The performance
improvements you are seeing with Python over Oracle are exactly the same
range people see with SQLite over Oracle.  One common usage reported on
the SQLite mailing list is people copying data out of Oracle and running
their analysis in SQLite because of the performance advantages.

> Note: Memory is currently not a concern for me so I don't need SQLite's
> ability to work with data sets larger than my physical memory.

The pragmas tune things like cache sizes.  The SQLite default is 2MB,
relying on the operating system for caching beyond that.  Bumping up
that kind of size was my suggestion :-)

Roger

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAklR9+UACgkQmOOfHg372QSMbwCdGS5S2/96fWW8knjfBVqReAfV
AEwAn2Yc+L9BEZgT69OjwtyqxLtifVpU
=mPfy
-END PGP SIGNATURE-

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


Re: Strategy for determing difference between 2 very large dictionaries

2008-12-24 Thread python
Hi Peter,


If you are not interested in the intermediate results and the dictionary
values are hashable you can get the difference by

>>> a = dict(a=1, b=2, c=3)
>>> b = dict(b=2, c=30, d=4)
>>> dict(set(a.iteritems()) ^ set(b.iteritems()))
{'a': 1, 'c': 3, 'd': 4}


That's very cool! Thanks for sharing that technique.

Regards,
Malcolm


- Original message -
From: "Peter Otten" <__pete...@web.de>
To: python-list@python.org
Date: Wed, 24 Dec 2008 09:46:51 +0100
Subject: Re: Strategy for determing difference between 2 very large
dictionaries

Gabriel Genellina wrote:

> En Wed, 24 Dec 2008 05:16:36 -0200,  escribió:

[I didn't see the original post]

>> I'm looking for suggestions on the best ('Pythonic') way to
>> determine the difference between 2 very large dictionaries
>> containing simple key/value pairs.
>> By difference, I mean a list of keys that are present in the
>> first dictionary, but not the second. And vice versa. And a list
>> of keys in common between the 2 dictionaries whose values are
>> different.
>> The 2 strategies I'm considering are:
>> 1. Brute force: Iterate through first dictionary's keys and
>> determine which keys it has that are missing from the second
>> dictionary. If keys match, then verify that the 2 dictionaries
>> have identical values for the same key. Repeat this process for
>> the second dictionary.
>> 2. Use sets: Create sets from each dictionary's list of keys and
>> use Python's set methods to generate a list of keys present in
>> one dictionary but not the other (for both dictionaries) as well
>> as a set of keys the 2 dictionaries have in common.
> 
> I cannot think of any advantage of the first approach - so I'd use sets.
> 
> k1 = set(dict1.iterkeys())
> k2 = set(dict2.iterkeys())
> k1 - k2 # keys in dict1 not in dict2
> k2 - k1 # keys in dict2 not in dict1
> k1 & k2 # keys in both
> 
>> Using the set
>> of keys in common, compare values across dictionaries to
>> determine which keys have different values (can this last step be
>> done via a simple list comprehension?)

If you are not interested in the intermediate results and the dictionary
values are hashable you can get the difference by

>>> a = dict(a=1, b=2, c=3)
>>> b = dict(b=2, c=30, d=4)
>>> dict(set(a.iteritems()) ^ set(b.iteritems()))
{'a': 1, 'c': 3, 'd': 4}

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


Re: Strategy for determing difference between 2 very large dictionaries

2008-12-24 Thread Malcolm Greene
Hi Gabriel,

> in Python 3.0 keys() behaves as iterkeys() in previous versions, so the above 
> code is supposed to be written in Python 2.x)

I understand. Thank you.

> note that dict comprehensions require Python 3.0

I'm relieved to know that I didn't miss that feature in my reading of
Python's 2.5/2.6 documentation :)

> You might use instead:
>
> dict((key,(dict1[key],dict2[key])) for key in ...)

Excellent. Thank you.

Regards,
Malcolm


- Original message -
From: "Gabriel Genellina" 
To: python-list@python.org
Date: Wed, 24 Dec 2008 07:10:16 -0200
Subject: Re: Strategy for determing difference between 2 very large
dictionaries

En Wed, 24 Dec 2008 06:23:00 -0200,  escribió:

> Hi Gabriel,
>
> Thank you very much for your feedback!
>
>> k1 = set(dict1.iterkeys())
>
> I noticed you suggested .iterkeys() vs. .keys(). Is there any advantage
> to using an iterator vs. a list as the basis for creating a set? I

You've got an excelent explanation from Marc Rintsch. (Note that in
Python  
3.0 keys() behaves as iterkeys() in previous versions, so the above code 
is supposed to be written in Python 2.x)

>>> can this last step be done via a simple list comprehension?
>
>> Yes; but isn't a dict comprehension more adequate?
>>
>> [key: (dict1[key], dict2[key]) for key in common_keys if
>> dict1[key]!=dict2[key]}
>
> Cool!! I'm relatively new to Python and totally missed the ability to
> work with dictionary comprehensions. Yes, your dictionary comprehension
> technique is much better than the list comprehension approach I was
> struggling with. Your dictionary comprehension statement describes
> exactly what I wanted to write.

This time, note that dict comprehensions require Python 3.0 -- so the
code  
above won't work in Python 2.x.
(It's not a good idea to mix both versions in the same post, sorry!)
You might use instead:

dict((key,(dict1[key],dict2[key])) for key in ...)

but it's not as readable.

-- 
Gabriel Genellina

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


SyntaxError: encoding problem: with BOM

2008-12-24 Thread NoName
i have 1.py in cp866 encoding:

# -*- coding: cp866 -*-
print ("ff")



It's not work in Python 3.0
Error:

File "", line 1
SyntaxError: encoding problem: with BOM

what's wrong?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Most efficient way to build very large dictionaries

2008-12-24 Thread Martin
Hi,

2008/12/24  :
> Hi Roger,
>
>> you may want to consider using SQLite
>
> Thank you for your suggestion about looking at SQLite. I haven't
> compared the performance of SQLite to Python dictionaries, but I'm
> skeptical that SQLite would be faster than in-memory Python dictionaries
> for the type of analysis I'm doing.

I'd think he's talking about in memory SQLite Databases, this way you
should be quite fast _and_ could dump all that to a persistent
storage...

regards
martin



-- 
http://soup.alt.delete.co.at
http://www.xing.com/profile/Martin_Marcher
http://www.linkedin.com/in/martinmarcher

You are not free to read this message,
by doing so, you have violated my licence
and are required to urinate publicly. Thank you.

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: Most efficient way to build very large dictionaries

2008-12-24 Thread Roger Binns
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Martin wrote:
> I'd think he's talking about in memory SQLite Databases, this way you
> should be quite fast _and_ could dump all that to a persistent
> storage...

I was just talking about regular on disk SQLite databases.  In terms of
priming the pump, you can just open/read/close the whole database file
which will cause the database to be in the operating system cache
buffers, or just let SQLite do its thing.

For anyone who is curious about what Martin is referring to, SQLite does
support the database file being memory (although it isn't a file at that
point).  It has a fake filename of :memory:.  As an example you can copy
the table 'example' to memory using:

  ATTACH ':memory:' as memdb;
  CREATE TABLE memdb.memexample AS select * from example;

As with Python, all this stuff is premature optimization.  Get it
working right first and then try tweaks to improve performance.

Roger
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAklSEqcACgkQmOOfHg372QTPpgCgvSKGMCJAKhnm5I8qHdmZtRh3
SgMAoI3DVhWCVdUE1TLck9ZEfp/Ln1H5
=5kNT
-END PGP SIGNATURE-

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


Re: Strategy for determing difference between 2 very large dictionaries

2008-12-24 Thread bearophileHUGS
Peter Otten:
> >>> a = dict(a=1, b=2, c=3)
> >>> b = dict(b=2, c=30, d=4)
> >>> dict(set(a.iteritems()) ^ set(b.iteritems()))

For larger sets this may be better, may avoid the creation of the
second set:

dict(set(a.iteritems()).symmetric_difference(b.iteritems()))

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


Re: Multi-dimension list

2008-12-24 Thread Steve Holden
James Stroud wrote:
> Steven Woody wrote:
>> Hi,
>>
>> In the book Python Essential Reference, Chapter 3, when talking about
>> extended slicing, it gives an example:  a = m[0:10, 3:20].  But I
>> don't understand how the 'm' was defined.  What should it looks like?
> 
> m could be an instance of the Krayzee class.
> 
> py> class Krayzee(object):
> ...   def __getitem__(self, i):
> ... try:
> ...   r = ['WTF?' for j in i]
> ... except:
> ...   r = 'WTF?'
> ... return r
> ...
> py> m = Krayzee()
> py> m[1:2:3, 4:5:6]
> ['WTF?', 'WTF?']
> py> m['your moms']
> ['WTF?', 'WTF?', 'WTF?', 'WTF?', 'WTF?', 'WTF?', 'WTF?', 'WTF?', 'WTF?']
> 
> 
I'm not sure what this is supposed to prove. It might be more helpful to
show what's actually going on ...

>>> class k(object):
...   def __getitem__(self, i):
... try:
...   r = [j for j in i]
... except Exception, e:
...   print i, ":", e
...   r = i
... return r
...
>>> m = k()
>>> m[1:2:3, 4:5:6]
[slice(1, 2, 3), slice(4, 5, 6)]
>>> m["help!"]
['h', 'e', 'l', 'p', '!']
>>>

As you can see, no exceptions are raised here, and the x:y:z notation
introduces a slice object, which the code doesn't handle in any way
shape or form.

regards
 Steve

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

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


Re: SyntaxError: encoding problem: with BOM

2008-12-24 Thread Diez B. Roggisch

NoName schrieb:

i have 1.py in cp866 encoding:

# -*- coding: cp866 -*-
print ("ff")



It's not work in Python 3.0
Error:

File "", line 1
SyntaxError: encoding problem: with BOM

what's wrong?


I can only guess, but just because you write the coding-header that 
doesn't mean that the editor you use does actually *use* that encoding. 
What I presume it does is to use utf-8, and write that stupid BOM 
microsoft uses for denoting utf-8-content as first byte. Try using a 
different editor, or alter it's settings to really use your desired 
encoding.


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


python web programming for PHP programmers

2008-12-24 Thread Nikola Skoric
I0m a python newbie with PHP background. I've tried to make a web app
from one of my python scripts (which I haven't done before) and I
ended up with:


which works really nice :-D

For some reason I can't find no "quick and dirty python web
programming tutorial for PHP programmers" on google. :-D I don't need
a general python tutorial, I just need a tutorial on how to make a
hello world server side script with python. Any suggestions?

-- 
"Now the storm has passed over me
I'm left to drift on a dead calm sea
And watch her forever through the cracks in the beams
Nailed across the doorways of the bedrooms of my dreams"
--
http://mail.python.org/mailman/listinfo/python-list


www.iofferkicks.com china cheap wholesale nike shoes,air jordan shoes,air force one shoes.

2008-12-24 Thread www.iofferkicks.com
Get Nike Shoes at Super Cheap Prices
Discount Nike air jordans  (www.iofferkicks.com)
Discount Nike Air Max 90 Sneakers  (www.iofferkicks.com)
Discount Nike Air Max 91 Supplier  (www.iofferkicks.com)
Discount Nike Air Max 95 Shoes Supplier  (www.iofferkicks.com)
Discount Nike Air Max 97 Trainers  (www.iofferkicks.com)
Discount Nike Air Max 2003 Wholesale  (www.iofferkicks.com)
Discount Nike Air Max 2004 Shoes Wholesale
(www.iofferkicks.com)
Discount Nike Air Max 2005 Shop  (www.iofferkicks.com)
Discount Nike Air Max 2006 Shoes Shop  (www.iofferkicks.com)
Discount Nike Air Max 360 Catalogs  (www.iofferkicks.com)
Discount Nike Air Max Ltd Shoes Catalogs  (www.iofferkicks.com)
Discount Nike Air Max Tn Men's Shoes  (www.iofferkicks.com)
Discount Nike Air Max Tn 2 Women's Shoes  (www.iofferkicks.com)
Discount Nike Air Max Tn 3 Customize  (www.iofferkicks.com)
Discount Nike Air Max Tn 4 Shoes Customize
( www.iofferkicks.com)
Discount Nike Air Max Tn 6 Supply  (www.iofferkicks.com)
Discount Nike Shox NZ Shoes Supply  (www.iofferkicks.com)
Discount Nike Shox OZ Sale  (www.iofferkicks.com)
Discount Nike Shox TL Store  (www.iofferkicks.com)
Discount Nike Shox TL 2 Shoes Store (www.iofferkicks.com)
Discount Nike Shox TL 3 Distributor (www.iofferkicks.com)
Discount Nike Shox Bmw Shoes Distributor  (www.iofferkicks.com)
Discount Nike Shox Elite Shoes Manufacturer
(www.iofferkicks.com)
Discount Nike Shox Monster Manufacturer  (www.iofferkicks.com)
Discount Nike Shox R4 Running Shoes  (www.iofferkicks.com)
Discount Nike Shox R5 Mens Shoes  (www.iofferkicks.com)
Discount Nike Shox Ride Womens Shoes (www.iofferkicks.com)
Discount Nike Shox Rival Shoes Wholesaler  (www.iofferkicks.com)
Discount Nike Shox Energia Wholesaler  (www.iofferkicks.com)
Discount Nike Shox LV Sneaker  (www.iofferkicks.com)
Discount Nike Shox Turbo Suppliers  (www.iofferkicks.com)
Discount Nike Shox Classic Shoes Suppliers
(www.iofferkicks.com)
Discount Nike Shox Dendara Trainer  (www.iofferkicks.com)
Discount Nike Air Jordan 1 Seller  (www.iofferkicks.com)
Discount Nike Air Jordan 2 Shoes Seller  (www.iofferkicks.com)
Discount Nike Air Jordan 3 Collection  (www.iofferkicks.com)
Discount Nike Air Jordan 4 Shoes Collection
(www.iofferkicks.com)
Discount Nike Air Jordan 5 Chaussure Shoes
(www.iofferkicks.com)
Discount Nike Air Jordan 6 Catalog  (www.iofferkicks.com)
Discount Nike Air Jordan 7 Shoes Catalog  (www.iofferkicks.com)
Discount Nike Air Jordan 8 Customized  (www.iofferkicks.com)
Discount Nike Air Jordan 9 Shoes Customized
(www.iofferkicks.com)
Discount Nike Air Jordan 10 Wholesalers  (www.iofferkicks.com)
Discount Nike Jordan 11 Shoes Wholesalers (www.iofferkicks.com)
Discount Nike Air Jordan 12 Factory  (www.iofferkicks.com)
Discount Nike Air Jordan 13 Shoes Factory (www.iofferkicks.com)
Discount Nike Air Jordan 14 Shoes Sell  (www.iofferkicks.com)
Discount Nike Air Jordan 16 Exporter  (www.iofferkicks.com)
Discount Nike Air Jordan 17 Shoes Exporter
(www.iofferkicks.com)
Discount Nike Air Jordan 18 Offer  (www.iofferkicks.com)
Discount Nike Air Jordan 19 Shoes Offer  (www.iofferkicks.com)
Discount Nike Air Jordan 20 Manufacture  (www.iofferkicks.com)
Discount Nike Jordan 21 Shoes Manufacture  (www.iofferkicks.com)
EMAIL:iofferki...@gmail.com
MSN :iofferki...@msn.com
--
http://mail.python.org/mailman/listinfo/python-list


Using exceptions in defined in an extension module inside another extension module

2008-12-24 Thread Floris Bruynooghe
Hello

If I have an extension module and want to use an exception I can do by
declaring the exception as "extern PyObject *PyExc_FooError" in the
object files if I then link those together inside a module where the
module has them declared the same (but no extern) and then initialises
them in the PyMODINIT_FUNC using PyErr_NewException.

What I can't work out however is how to then be able to raise this
exception in another extension module.  Just defining it as "extern"
doesn't work, even if I make sure the first module -that creates the
exception- gets loaded first.  Because the symbol is defined in the
first extension module the dynamic linker can't find it as it only
seems to look in the main python executable for symbols used in
dlloaded sofiles.

Does anyone have an idea of how you can do this?

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


Re: python web programming for PHP programmers

2008-12-24 Thread Diez B. Roggisch

Nikola Skoric schrieb:

I0m a python newbie with PHP background. I've tried to make a web app
from one of my python scripts (which I haven't done before) and I
ended up with:


which works really nice :-D

For some reason I can't find no "quick and dirty python web
programming tutorial for PHP programmers" on google. :-D I don't need
a general python tutorial, I just need a tutorial on how to make a
hello world server side script with python. Any suggestions?


Try googling mod_wsgi. While "real" python web-programming is usually 
done a bit different (django, turbogears, pylons and lots of others I 
forgot), I think it comes close to what a PHP-programmer would expect 
how a webapp begins.


It boils down to a python-file saying


def application(environ, start_response):
status = '200 OK'
output = 'Hello World!'

response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)

return [output]


Well, I did the googling - here you have a starter:


http://code.google.com/p/modwsgi/

See the configuration-section.

HTH,

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


Re: SyntaxError: encoding problem: with BOM

2008-12-24 Thread NoName
On 25 дек, 00:37, "Diez B. Roggisch"  wrote:
> NoName schrieb:
>
> > i have 1.py in cp866 encoding:
>
> > # -*- coding: cp866 -*-
> > print ("ff")
>
> > It's not work in Python 3.0
> > Error:
>
> > File "", line 1
> > SyntaxError: encoding problem: with BOM
>
> > what's wrong?
>
> I can only guess, but just because you write the coding-header that
> doesn't mean that the editor you use does actually *use* that encoding.
> What I presume it does is to use utf-8, and write that stupid BOM
> microsoft uses for denoting utf-8-content as first byte. Try using a
> different editor, or alter it's settings to really use your desired
> encoding.
>
> Diez

I used Far Manager editor. and it *really* used cp866
I can print hex dump of source file.
I don't want to use UTF-8 for py-file!
--
http://mail.python.org/mailman/listinfo/python-list


Re: python web programming for PHP programmers

2008-12-24 Thread Federico Moreira
You can try also web2py (http://mdp.cti.depaul.edu/) but i think you may be
interested on http://www.modpython.org/
--
http://mail.python.org/mailman/listinfo/python-list


Custom C Exception Subclasses

2008-12-24 Thread Ross
For a project that I am doing, it would be useful to have an exception
class that stores some additional data along with the message.
However, I want to be able to store a couple pointers to C++ classes,
so I can't just use an exception created with PyExc_NewException.  If
I were to subclass the built-in Exception type, I would need to have
access to the PyExc_ExceptionObject, but the headers only give
PyExc_Exception, the type object.  This seems like a rather
straightforward task, but I can't seem to find any documentation for
it.  Does anyone know how to do this?  Thanks!
--
http://mail.python.org/mailman/listinfo/python-list


Re: python web programming for PHP programmers

2008-12-24 Thread ajaksu
On Dec 24, 12:40 pm, Nikola Skoric  wrote:
> I0m a python newbie with PHP background. I've tried to make a web app
> from one of my python scripts (which I haven't done before) and I
> ended up with:
>
>  echo shell_exec("python foobar.py");
> ?>
> which works really nice :-D

Clever :)

Python can work in a similar way to PHP if your server supports it,
but Python also allows you to create the server itself.


> For some reason I can't find no "quick and dirty python web
> programming tutorial for PHP programmers" on google. :-D I don't need
> a general python tutorial, I just need a tutorial on how to make a
> hello world server side script with python. Any suggestions?

See http://webpython.codepoint.net/cgi_hello_world for a very
primitive way (and docs here: http://docs.python.org/dev/library/cgi.html
).

A better way, that uses a trivial Python-based server:

hello.py
---
from wsgiref.simple_server import make_server
def hello_app(environ, start_response):
start_response("200 OK", [('Content-Type','text/plain')])
return "Hello world!"
httpd = make_server('', 8000, hello_app)
print "Serving HTTP on port 8000..."
httpd.serve_forever()
---

Then:
$ python hello.py
Serving HTTP on port 8000...
localhost - - [24/Dec/2008 13:11:32] "GET / HTTP/1.1" 200 12
(see 
http://docs.python.org/dev/library/wsgiref.html#module-wsgiref.simple_server
)

You can use better Python-based servers with handy features for
testing:
http://projects.wagner-flo.net/wsgi-serve/
http://pypi.python.org/pypi/James/0.7.1


Now, to ease things, you can have Python working more like PHP.

First, server support. What HTTP server are you using? For starting
up, mod_python (http://www.modpython.org/) isn't that bad, but there
are better alternatives: http://code.google.com/p/modwsgi/ ,
http://pypi.python.org/pypi/python-fastcgi/1.1 and http://python.ca/scgi/

Then, there are many ways of getting the PHP feel (embedding in pages,
etc.):
http://www.modpython.org/live/current/doc-html/pyapi-psp.html#pyapi-psp
http://nick.borko.org/pse/examples/php_example.html
http://snakelets.sourceforge.net/ (development stopped)
http://www.webwareforpython.org/PSP/Docs/index.html

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


object oriënted

2008-12-24 Thread Dennis van Oosterhout
I know that python is an Object Oriënted language but I was wondering if it
gets used as a non-OOP also (by a good amount of people).
--
http://mail.python.org/mailman/listinfo/python-list


Re: no sign() function ?

2008-12-24 Thread ajaksu
On Dec 24, 5:59 am, pdora...@pas-de-pub-merci.mac.com (Pierre-Alain
Dorange) wrote:
>
> For me sign_0 is the simplest one to understood.
> So in the domain of my little arcade game, this is what i'll use.
> I don't need the accuraccy of sign_1, because in the application i just
> need to know if the target is right or left or if the speed direction is
> right or left.

If there is a chance of getting bogus input to sign_0 (like a list,
None or other non-numeric types) it might be worth to add a quick
check like:

def sign_0(x):
x + 0
if x==0.0:
...
--
http://mail.python.org/mailman/listinfo/python-list


Re: object oriënted

2008-12-24 Thread skip

Dennis> I know that python is an Object Oriënted language but I was
Dennis> wondering if it gets used as a non-OOP also (by a good amount of
Dennis> people).

Oh yeah.  Works great for writing quick-n-dirty Unix filters which are a bit
more complex than can comfortably be wrangled with Bash, but not so complex
that you need more organization (such as classes).  A function looping over
sys.stdin.  Make a few transformations and away you go.

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


How to change a generator ?

2008-12-24 Thread Barak, Ron
Hi,

I have a generator whose aim is to returns consecutive lines from a file (the 
listing below is a simplified version).
However, as it is written now, the generator method changes the text file 
pointer to end of file after first invocation.
Namely, the file pointer changes from 0 to 6623 on line 24.

Can you suggest how the generator could be changed, so it will allow me to get 
the current location in the file after each yield ?

Thanks,
Ron.

$ cat -n generator.py  # listing without line numbers is below
 1  #!/usr/bin/env python
 2
 3  import gzip
 4  from Debug import _line as line
 5
 6  class LogStream():
 7
 8  def __init__(self, filename):
 9  self.filename = filename
10  self.input_file = self.open_file(filename)
11
12  def open_file(self, in_file):
13  try:
14  f = gzip.GzipFile(in_file, "r")
15  f.readline()
16  except IOError:
17  f = open(in_file, "r")
18  f.readline()
19  f.seek(0)
20  return(f)
21
22  def line_generator(self):
23  print line()+". self.input_file.tell()==",self.input_file.tell()
24  for line_ in self.input_file:
25  print line()+". 
self.input_file.tell()==",self.input_file.tell()
26  yield line_.strip()
27
28
29  if __name__ == "__main__":
30
31  filename = "sac.log.50lines"
32  log_stream = LogStream(filename)
33  log_stream.input_file.seek(0)
34  line_generator = log_stream.line_generator()
35  line_ = line_generator.next()

$ python generator.py
23. self.input_file.tell()== 0
25. self.input_file.tell()== 6623

$ wc -c sac.log.50lines
6623 sac.log.50lines
$ cat generator.py
#!/usr/bin/env python

import gzip
from Debug import _line as line

class LogStream():

def __init__(self, filename):
self.filename = filename
self.input_file = self.open_file(filename)

def open_file(self, in_file):
try:
f = gzip.GzipFile(in_file, "r")
f.readline()
except IOError:
f = open(in_file, "r")
f.readline()
f.seek(0)
return(f)

def line_generator(self):
print line()+". self.input_file.tell()==",self.input_file.tell()
for line_ in self.input_file:
print line()+". self.input_file.tell()==",self.input_file.tell()
yield line_.strip()


if __name__ == "__main__":

filename = "sac.log.50lines"
log_stream = LogStream(filename)
log_stream.input_file.seek(0)
line_generator = log_stream.line_generator()
line_ = line_generator.next()


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


Re: Using exceptions in defined in an extension module inside another extension module

2008-12-24 Thread Christian Heimes
Floris Bruynooghe schrieb:
> What I can't work out however is how to then be able to raise this
> exception in another extension module.  Just defining it as "extern"
> doesn't work, even if I make sure the first module -that creates the
> exception- gets loaded first.  Because the symbol is defined in the
> first extension module the dynamic linker can't find it as it only
> seems to look in the main python executable for symbols used in
> dlloaded sofiles.
> 
> Does anyone have an idea of how you can do this?

The answer is so obvious that you are going to bang your head against
the next wall. You have to do exactly the same as you'd do with a pure
Python module: import it. :)

static PyObject *yourexc = NULL;

PyObject *yourmod = PyImport_ImportModule("yourmod");
if (yourmod == NULL)
return NULL;
*yourexc = PyObject_GetAttrString(yourmod, "YourException");
if (yourexc == NULL)
return NULL;

Christian

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


Python-URL! - weekly Python news and links (Dec 24)

2008-12-24 Thread Gabriel Genellina
QOTW:  "Threads seem to be used only because mediocre programmers don't know
what else to use." - Sturla Molden
http://mail.python.org/pipermail/python-dev/2008-December/084265.html


Python 2.4.6 and 2.5.3 were released this week:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/53901d6dd764d8a8/

What's the difference between __str__ vs. __repr__?

http://groups.google.com/group/comp.lang.python/browse_thread/thread/a0f0b526006fe831/

Unicode problems -- and how RealBasic solves them in a totally different
way:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/f623b434f2ac6d9/

An optimization exercise, involving fileinput and str.split/partition:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/77fc160ee557ae39/

How to modify a program while it is still running:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/95397361600ded28/

A long thread about the new (3.0) string formatting mechanism

http://groups.google.com/group/comp.lang.python/browse_thread/thread/23d63689c0087ebf/

Two apparently trivial tasks are actually challenging to get right:
writing a sign() function, and timing it:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/c726f932f75c23e4/



Everything Python-related you want is probably one or two clicks away in
these pages:

Python.org's Python Language Website is the traditional
center of Pythonia
http://www.python.org
Notice especially the master FAQ
http://www.python.org/doc/FAQ.html

PythonWare complements the digest you're reading with the
marvelous daily python url
 http://www.pythonware.com/daily

Just beginning with Python?  This page is a great place to start:
http://wiki.python.org/moin/BeginnersGuide/Programmers

The Python Papers aims to publish "the efforts of Python enthusiats":
http://pythonpapers.org/
The Python Magazine is a technical monthly devoted to Python:
http://pythonmagazine.com

Readers have recommended the "Planet" sites:
http://planetpython.org
http://planet.python.org

comp.lang.python.announce announces new Python software.  Be
sure to scan this newsgroup weekly.
http://groups.google.com/group/comp.lang.python.announce/topics

Python411 indexes "podcasts ... to help people learn Python ..."
Updates appear more-than-weekly:
http://www.awaretek.com/python/index.html

The Python Package Index catalogues packages.
http://www.python.org/pypi/

The somewhat older Vaults of Parnassus ambitiously collects references
to all sorts of Python resources.
http://www.vex.net/~x/parnassus/

Much of Python's real work takes place on Special-Interest Group
mailing lists
http://www.python.org/sigs/

Python Success Stories--from air-traffic control to on-line
match-making--can inspire you or decision-makers to whom you're
subject with a vision of what the language makes practical.
http://www.pythonology.com/success

The Python Software Foundation (PSF) has replaced the Python
Consortium as an independent nexus of activity.  It has official
responsibility for Python's development and maintenance.
http://www.python.org/psf/
Among the ways you can support PSF is with a donation.
http://www.python.org/psf/donations/

The Summary of Python Tracker Issues is an automatically generated
report summarizing new bugs, closed ones, and patch submissions. 

http://search.gmane.org/?author=status%40bugs.python.org&group=gmane.comp.python.devel&sort=date

Although unmaintained since 2002, the Cetus collection of Python
hyperlinks retains a few gems.
http://www.cetus-links.org/oo_python.html

Python FAQTS
http://python.faqts.com/

The Cookbook is a collaborative effort to capture useful and
interesting recipes.
http://code.activestate.com/recipes/langs/python/

Many Python conferences around the world are in preparation.
Watch this space for links to them.

Among several Python-oriented RSS/RDF feeds available, see:
http://www.python.org/channews.rdf
For more, see:
http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all
The old Python "To-Do List" now lives principally in a
SourceForge reincarnation.
http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse
http://www.python.org/dev/peps/pep-0042/

del.icio.us presents an intriguing approach to reference commentary.
It already aggregates quite a bit of Python intelligence.
http://del.icio.us/tag/python

*Py: the Journal of the Python Language*
http:/

Re: SyntaxError: encoding problem: with BOM

2008-12-24 Thread Diez B. Roggisch

NoName schrieb:

On 25 дек, 00:37, "Diez B. Roggisch"  wrote:

NoName schrieb:


i have 1.py in cp866 encoding:
# -*- coding: cp866 -*-
print ("ff")
It's not work in Python 3.0
Error:
File "", line 1
SyntaxError: encoding problem: with BOM
what's wrong?

I can only guess, but just because you write the coding-header that
doesn't mean that the editor you use does actually *use* that encoding.
What I presume it does is to use utf-8, and write that stupid BOM
microsoft uses for denoting utf-8-content as first byte. Try using a
different editor, or alter it's settings to really use your desired
encoding.

Diez


I used Far Manager editor. and it *really* used cp866
I can print hex dump of source file.
I don't want to use UTF-8 for py-file!


How about you show us the python file in question?

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


Re: python web programming for PHP programmers

2008-12-24 Thread D'Arcy J.M. Cain
On Wed, 24 Dec 2008 14:40:31 + (UTC)
Nikola Skoric  wrote:
> a general python tutorial, I just need a tutorial on how to make a
> hello world server side script with python. Any suggestions?

#! /usr/bin/env python

import sys, re

colour = re.sub('=', '=#', ''.join(sys.argv[1:]))

print """Content-type: text/html





Hello World
mailto:da...@druid.net";>
 


Hello World""" % colour

print """
Hello World
"""

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


Spam???

2008-12-24 Thread Alvin ONeal
What's with all the spam on the list?

I humbly request that recaptcha or some other sort
of captcha be implemented on the registration page.

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


Re: I always wonder ...

2008-12-24 Thread r
220 ratings and 1 star, WH!. I find this all quite amusing :D.
Keep em coming. Oh, and FYI, I will always have 1 star! hahahahahha


 /"\
|\./|
|   |
|   |
|>~<|
|   |
 /'\|   |/'\
 /~\|   |   |   |__
|   |   }   |   |  \
|   |   |   |   |   \
| ~   ~   ~   ~ |`   )
|   /
 \ /
  \   /
   \ /
|--//''`\--|
| (( +==)) |
|--\_|_//--|
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to change a generator ?

2008-12-24 Thread MRAB

Barak, Ron wrote:

Hi,
 
I have a generator whose aim is to returns consecutive lines from a file 
(the listing below is a simplified version).
However, as it is written now, the generator method changes the text 
file pointer to end of file after first invocation.

Namely, the file pointer changes from 0 to 6623 on line 24.
 
It might be that the generator method of self.input_file is reading the 
file a chunk at a time for efficiency even though it's yielding a line 
at a time.


Can you suggest how the generator could be changed, so it will allow me 
to get the current location in the file after each yield ?
 
Thanks,

Ron.
 
$ cat -n generator.py  # listing without line numbers is below

 1  #!/usr/bin/env python
 2
 3  import gzip
 4  from Debug import _line as line
 5
 6  class LogStream():
 7 
 8  def __init__(self, filename):

 9  self.filename = filename
10  self.input_file = self.open_file(filename)
11
12  def open_file(self, in_file):
13  try:
14  f = gzip.GzipFile(in_file, "r")
15  f.readline()
16  except IOError:
17  f = open(in_file, "r")
18  f.readline()
19  f.seek(0)
20  return(f)
21
22  def line_generator(self):
23  print line()+". 
self.input_file.tell()==",self.input_file.tell()

24  for line_ in self.input_file:
25  print line()+". 
self.input_file.tell()==",self.input_file.tell()

26  yield line_.strip()
27
28
29  if __name__ == "__main__":
30
31  filename = "sac.log.50lines"
32  log_stream = LogStream(filename)
33  log_stream.input_file.seek(0)
34  line_generator = log_stream.line_generator()
35  line_ = line_generator.next()
 
$ python generator.py

23. self.input_file.tell()== 0
25. self.input_file.tell()== 6623
 
$ wc -c sac.log.50lines

6623 sac.log.50lines
$ cat generator.py
#!/usr/bin/env python
 
import gzip

from Debug import _line as line
 
class LogStream():
   
def __init__(self, filename):

self.filename = filename
self.input_file = self.open_file(filename)
 
def open_file(self, in_file):

try:
f = gzip.GzipFile(in_file, "r")
f.readline()
except IOError:
f = open(in_file, "r")
f.readline()
f.seek(0)
return(f)
 
def line_generator(self):

print line()+". self.input_file.tell()==",self.input_file.tell()
for line_ in self.input_file:
print line()+". self.input_file.tell()==",self.input_file.tell()
yield line_.strip()
 


if __name__ == "__main__":
 
filename = "sac.log.50lines"

log_stream = LogStream(filename)
log_stream.input_file.seek(0)
line_generator = log_stream.line_generator()
line_ = line_generator.next()
 

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


Re: Custom C Exception Subclasses

2008-12-24 Thread Ivan Illarionov
On Dec 24, 6:42 pm, Ross  wrote:
> For a project that I am doing, it would be useful to have an exception
> class that stores some additional data along with the message.
> However, I want to be able to store a couple pointers to C++ classes,
> so I can't just use an exception created with PyExc_NewException.  If
> I were to subclass the built-in Exception type, I would need to have
> access to the PyExc_ExceptionObject, but the headers only give
> PyExc_Exception, the type object.  This seems like a rather
> straightforward task, but I can't seem to find any documentation for
> it.  Does anyone know how to do this?  Thanks!

When you raise an exception in C++ you can set it to ANY Python object
via PyErr_SetObject and that object could store pointers to C++
classes.

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


Re: Spam???

2008-12-24 Thread skip

Alvin> What's with all the spam on the list?
Alvin> I humbly request that recaptcha or some other sort
Alvin> of captcha be implemented on the registration page.

Known issue.  The spam filters are currently not applied to messages
gatewayed to the mailing list from Usenet.  I have been working on a
solution as I have time, but it's not there yet.

Even if/when the spam filtering on the list gets better you should run your
own spam filter anyway.

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


Re: Custom C Exception Subclasses

2008-12-24 Thread Gabriel Genellina

En Wed, 24 Dec 2008 13:42:38 -0200, Ross  escribió:


For a project that I am doing, it would be useful to have an exception
class that stores some additional data along with the message.
However, I want to be able to store a couple pointers to C++ classes,
so I can't just use an exception created with PyExc_NewException.


In fact you can, you could store those pointers as attributes of the  
exception object, using a PyCObject.
Accessing those attributes isn't as easy as doing exc->field, but I think  
it's easy enough. Inheriting from some exception type requires you to  
define the type structure and fill it right, and IMHO is a lot harder.



If
I were to subclass the built-in Exception type, I would need to have
access to the PyExc_ExceptionObject, but the headers only give
PyExc_Exception, the type object.  This seems like a rather
straightforward task, but I can't seem to find any documentation for
it.  Does anyone know how to do this?  Thanks!


Perhaps there is a misunderstanding here. To subclass a type, you need the  
type, not an instance of such type. The "Exception" class you use in  
Python code is "PyExc_Exception" in C code. Usually one would inherit a  
subclass, RuntimeError by example, so use PyExc_RuntimeError as the base  
type.


--
Gabriel Genellina

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


Re: How to change a generator ?

2008-12-24 Thread Gabriel Genellina
En Wed, 24 Dec 2008 15:03:58 -0200, MRAB   
escribió:


 I have a generator whose aim is to returns consecutive lines from a  
file (the listing below is a simplified version).
However, as it is written now, the generator method changes the text  
file pointer to end of file after first invocation.

Namely, the file pointer changes from 0 to 6623 on line 24.

It might be that the generator method of self.input_file is reading the  
file a chunk at a time for efficiency even though it's yielding a line  
at a time.


I think this is the case too.
I can think of 3 alternatives:

a) open the file unbuffered (bufsize=0). But I think this would greatly  
decrease performance.


b) keep track internally of file position (by adding each line length).  
The file should be opened in binary mode in this case (to avoid any '\n'  
translation).


c) return line numbers only, instead of file positions. Seeking to a  
certain line number requires to re-read the whole file from start;  
depending on how often this is required, and how big is the file, this  
might be acceptable.


--
Gabriel Genellina

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


Iterating over objects of a class

2008-12-24 Thread Kottiyath
Hi,
   How can I iterate over all the objects of a class?
   I wrote the code like following:
class baseClass(object):
__registry = []

def __init__(self, name):
self.__registry.append(self)
self.name = name

def __iter__(self):
baseClass.item = 0
return self.__registry[0]

def next(self):
if baseClass.item >= len(self.__registry):
raise StopIteration
baseClass.item += 1
return self.__registry[baseClass.item - 1]

For testing, create the following objects-
a = baseClass("Test1")
b = baseClass("Test2")

class subClass (baseClass):
   pass
c = subClass("Test3")

>Actual Iteration<
for i in a:
print i.name

Test1
Test2
Test3

---
I see the following problems in the code:
1. I have to iterate over any of the objects. For correctness, I
wanted to iterate over the class, like
for i in baseClass():
   do x
but that will will create one more object - which I do not want.

2. If the subclass wants to do somethings in its constructor, I am not
sure how to update the registry.
class subClass (baseClass):
   def __init__(self, name):
   **do something**
   super.init(self, name)  > This errors out, saying it needs
super, not subClass

Another method I thought of implementing it was using generators -
where-in baseClass.objects() is a generator which will yield the
objects one by one - but even then the second issue remains.
If somebody can help me out, I would be very thankful.

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


Re: Custom C Exception Subclasses

2008-12-24 Thread Gabriel Genellina
En Wed, 24 Dec 2008 15:00:36 -0200, Ivan Illarionov  
 escribió:



On Dec 24, 6:42 pm, Ross  wrote:

For a project that I am doing, it would be useful to have an exception
class that stores some additional data along with the message.
However, I want to be able to store a couple pointers to C++ classes,
so I can't just use an exception created with PyExc_NewException.  If
I were to subclass the built-in Exception type, I would need to have
access to the PyExc_ExceptionObject, but the headers only give
PyExc_Exception, the type object.  This seems like a rather
straightforward task, but I can't seem to find any documentation for
it.  Does anyone know how to do this?  Thanks!


When you raise an exception in C++ you can set it to ANY Python object
via PyErr_SetObject and that object could store pointers to C++
classes.


Remember that exceptions should inherit from BaseException; although this  
rule isn't enforced in Python 2.6, 3.0 doesn't allow that.
It isn't explicitely written in the docs, but I think that PyErr_SetObject  
won't allow you to pass an object which is not an instance of its first  
argument.


--
Gabriel Genellina

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


Re: Iterating over objects of a class

2008-12-24 Thread Diez B. Roggisch

Kottiyath schrieb:

Hi,
   How can I iterate over all the objects of a class?
   I wrote the code like following:
class baseClass(object):


Consider adopting PEP 8  coding conventions.



__registry = []

def __init__(self, name):
self.__registry.append(self)
self.name = name

def __iter__(self):
baseClass.item = 0
return self.__registry[0]

def next(self):
if baseClass.item >= len(self.__registry):
raise StopIteration
baseClass.item += 1
return self.__registry[baseClass.item - 1]

For testing, create the following objects-
a = baseClass("Test1")
b = baseClass("Test2")

class subClass (baseClass):
   pass
c = subClass("Test3")

>Actual Iteration<
for i in a:
print i.name

Test1
Test2
Test3

---
I see the following problems in the code:
1. I have to iterate over any of the objects. For correctness, I
wanted to iterate over the class, like
for i in baseClass():
   do x
but that will will create one more object - which I do not want.

2. If the subclass wants to do somethings in its constructor, I am not
sure how to update the registry.
class subClass (baseClass):
   def __init__(self, name):
   **do something**
   super.init(self, name)  > This errors out, saying it needs
super, not subClass


You don't show the actual traceback, however the idiom for invoking 
super for new-style-classes is



super(subClass, self).__init__(name)

for your case.


Another method I thought of implementing it was using generators -
where-in baseClass.objects() is a generator which will yield the
objects one by one - but even then the second issue remains.
If somebody can help me out, I would be very thankful.



Using a generator or not isn't the issue here.

What you need is a *class*-based access, not instance-based. There are 
various methods to accomplish this. The simplest is to ditch the 
obnoxious __registry as name, and just do


class BaseClass(object):

   REGISTRY = []


Then iterating is a simple matter of

for instance in BaseClass.REGISTRY:
   ...


Case solved. Alternatively, if you insist on the concept of privacy for 
that registry, you can use a classmethod:



class BaseClass(object):


   @classmethod
   def registry(cls):
   for i in cls.__registry:
   yield i





Last but not least you *could* go for a __metaclass__ with an 
__getitem__-method, that makes thinks look fancy because you then can do:



for instance in BaseClass:
...

I leave it as an exercise to you - gotta go christmas dining now :)

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


Re: How to change a generator ?

2008-12-24 Thread MRAB

Gabriel Genellina wrote:
En Wed, 24 Dec 2008 15:03:58 -0200, MRAB  
escribió:


 I have a generator whose aim is to returns consecutive lines from a 
file (the listing below is a simplified version).
However, as it is written now, the generator method changes the text 
file pointer to end of file after first invocation.

Namely, the file pointer changes from 0 to 6623 on line 24.

It might be that the generator method of self.input_file is reading 
the file a chunk at a time for efficiency even though it's yielding a 
line at a time.


I think this is the case too.
I can think of 3 alternatives:

a) open the file unbuffered (bufsize=0). But I think this would greatly 
decrease performance.


b) keep track internally of file position (by adding each line length). 
The file should be opened in binary mode in this case (to avoid any '\n' 
translation).


c) return line numbers only, instead of file positions. Seeking to a 
certain line number requires to re-read the whole file from start; 
depending on how often this is required, and how big is the file, this 
might be acceptable.


readline() appears to work as expected, leaving the file position at the 
start of the next line.

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


Re: Iterating over objects of a class

2008-12-24 Thread MRAB

Diez B. Roggisch wrote:

Kottiyath schrieb:

Hi,
   How can I iterate over all the objects of a class?
   I wrote the code like following:
class baseClass(object):


Consider adopting PEP 8  coding conventions.



__registry = []

def __init__(self, name):
self.__registry.append(self)
self.name = name

def __iter__(self):
baseClass.item = 0
return self.__registry[0]

def next(self):
if baseClass.item >= len(self.__registry):
raise StopIteration
baseClass.item += 1
return self.__registry[baseClass.item - 1]

For testing, create the following objects-
a = baseClass("Test1")
b = baseClass("Test2")

class subClass (baseClass):
   pass
c = subClass("Test3")

>Actual Iteration<
for i in a:
print i.name

Test1
Test2
Test3

---
I see the following problems in the code:
1. I have to iterate over any of the objects. For correctness, I
wanted to iterate over the class, like
for i in baseClass():
   do x
but that will will create one more object - which I do not want.

2. If the subclass wants to do somethings in its constructor, I am not
sure how to update the registry.
class subClass (baseClass):
   def __init__(self, name):
   **do something**
   super.init(self, name)  > This errors out, saying it needs
super, not subClass


You don't show the actual traceback, however the idiom for invoking 
super for new-style-classes is



super(subClass, self).__init__(name)

for your case.


Another method I thought of implementing it was using generators -
where-in baseClass.objects() is a generator which will yield the
objects one by one - but even then the second issue remains.
If somebody can help me out, I would be very thankful.



Using a generator or not isn't the issue here.

What you need is a *class*-based access, not instance-based. There are 
various methods to accomplish this. The simplest is to ditch the 
obnoxious __registry as name, and just do


class BaseClass(object):

   REGISTRY = []


Then iterating is a simple matter of

for instance in BaseClass.REGISTRY:
   ...


Case solved. Alternatively, if you insist on the concept of privacy for 
that registry, you can use a classmethod:



class BaseClass(object):


   @classmethod
   def registry(cls):
   for i in cls.__registry:
   yield i





Last but not least you *could* go for a __metaclass__ with an 
__getitem__-method, that makes thinks look fancy because you then can do:



for instance in BaseClass:
...

I leave it as an exercise to you - gotta go christmas dining now :)

The other thing to remember is that because the 'registry' contains 
references to the instances, they won't be garbage collected.

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


Re: Iterating over objects of a class

2008-12-24 Thread Kottiyath
On Dec 24, 10:52 pm, "Diez B. Roggisch"  wrote:
> Kottiyath schrieb:
>
> > Hi,
> >    How can I iterate over all the objects of a class?
> >    I wrote the code like following:
> > class baseClass(object):
>
> Consider adopting PEP 8  coding conventions.
>
>
>
> >     __registry = []
>
> >     def __init__(self, name):
> >         self.__registry.append(self)
> >         self.name = name
>
> >     def __iter__(self):
> >         baseClass.item = 0
> >         return self.__registry[0]
>
> >     def next(self):
> >         if baseClass.item >= len(self.__registry):
> >             raise StopIteration
> >         baseClass.item += 1
> >         return self.__registry[baseClass.item - 1]
>
> > For testing, create the following objects-
> > a = baseClass("Test1")
> > b = baseClass("Test2")
>
> > class subClass (baseClass):
> >    pass
> > c = subClass("Test3")
>
> > >Actual Iteration<
> > for i in a:
> >     print i.name
>
> > Test1
> > Test2
> > Test3
>
> > ---
> > I see the following problems in the code:
> > 1. I have to iterate over any of the objects. For correctness, I
> > wanted to iterate over the class, like
> > for i in baseClass():
> >    do x
> > but that will will create one more object - which I do not want.
>
> > 2. If the subclass wants to do somethings in its constructor, I am not
> > sure how to update the registry.
> > class subClass (baseClass):
> >    def __init__(self, name):
> >        **do something**
> >        super.init(self, name)  > This errors out, saying it needs
> > super, not subClass
>
> You don't show the actual traceback, however the idiom for invoking
> super for new-style-classes is
>
> super(subClass, self).__init__(name)
>
> for your case.
>
> > Another method I thought of implementing it was using generators -
> > where-in baseClass.objects() is a generator which will yield the
> > objects one by one - but even then the second issue remains.
> > If somebody can help me out, I would be very thankful.
>
> Using a generator or not isn't the issue here.
>
> What you need is a *class*-based access, not instance-based. There are
> various methods to accomplish this. The simplest is to ditch the
> obnoxious __registry as name, and just do
>
> class BaseClass(object):
>
>     REGISTRY = []
>
> Then iterating is a simple matter of
>
> for instance in BaseClass.REGISTRY:
>     ...
>
> Case solved. Alternatively, if you insist on the concept of privacy for
> that registry, you can use a classmethod:
>
> class BaseClass(object):
>
>     @classmethod
>     def registry(cls):
>         for i in cls.__registry:
>             yield i
>
> Last but not least you *could* go for a __metaclass__ with an
> __getitem__-method, that makes thinks look fancy because you then can do:
>
> for instance in BaseClass:
>      ...
>
> I leave it as an exercise to you - gotta go christmas dining now :)
>
> Diez

Thank you Very much, Diez. I was able to do the Generator and the
super part of it, but I never even thought of the metaclass option.
I will try it out. Thank you very much.
Merry Christmas.
P.S - >Also, I will use the PEP 8 coding conventions
--
http://mail.python.org/mailman/listinfo/python-list


Re: Iterating over objects of a class

2008-12-24 Thread Kottiyath
On Dec 24, 11:04 pm, MRAB  wrote:
> Diez B. Roggisch wrote:
> > Kottiyath schrieb:
> >> Hi,
> >>    How can I iterate over all the objects of a class?
> >>    I wrote the code like following:
> >> class baseClass(object):
>
> > Consider adopting PEP 8  coding conventions.
>
> >>     __registry = []
>
> >>     def __init__(self, name):
> >>         self.__registry.append(self)
> >>         self.name = name
>
> >>     def __iter__(self):
> >>         baseClass.item = 0
> >>         return self.__registry[0]
>
> >>     def next(self):
> >>         if baseClass.item >= len(self.__registry):
> >>             raise StopIteration
> >>         baseClass.item += 1
> >>         return self.__registry[baseClass.item - 1]
>
> >> For testing, create the following objects-
> >> a = baseClass("Test1")
> >> b = baseClass("Test2")
>
> >> class subClass (baseClass):
> >>    pass
> >> c = subClass("Test3")
>
> >> >Actual Iteration<
> >> for i in a:
> >>     print i.name
>
> >> Test1
> >> Test2
> >> Test3
>
> >> ---
> >> I see the following problems in the code:
> >> 1. I have to iterate over any of the objects. For correctness, I
> >> wanted to iterate over the class, like
> >> for i in baseClass():
> >>    do x
> >> but that will will create one more object - which I do not want.
>
> >> 2. If the subclass wants to do somethings in its constructor, I am not
> >> sure how to update the registry.
> >> class subClass (baseClass):
> >>    def __init__(self, name):
> >>        **do something**
> >>        super.init(self, name)  > This errors out, saying it needs
> >> super, not subClass
>
> > You don't show the actual traceback, however the idiom for invoking
> > super for new-style-classes is
>
> > super(subClass, self).__init__(name)
>
> > for your case.
>
> >> Another method I thought of implementing it was using generators -
> >> where-in baseClass.objects() is a generator which will yield the
> >> objects one by one - but even then the second issue remains.
> >> If somebody can help me out, I would be very thankful.
>
> > Using a generator or not isn't the issue here.
>
> > What you need is a *class*-based access, not instance-based. There are
> > various methods to accomplish this. The simplest is to ditch the
> > obnoxious __registry as name, and just do
>
> > class BaseClass(object):
>
> >    REGISTRY = []
>
> > Then iterating is a simple matter of
>
> > for instance in BaseClass.REGISTRY:
> >    ...
>
> > Case solved. Alternatively, if you insist on the concept of privacy for
> > that registry, you can use a classmethod:
>
> > class BaseClass(object):
>
> >   �...@classmethod
> >    def registry(cls):
> >        for i in cls.__registry:
> >            yield i
>
> > Last but not least you *could* go for a __metaclass__ with an
> > __getitem__-method, that makes thinks look fancy because you then can do:
>
> > for instance in BaseClass:
> >     ...
>
> > I leave it as an exercise to you - gotta go christmas dining now :)
>
> The other thing to remember is that because the 'registry' contains
> references to the instances, they won't be garbage collected.

Is there any other way out in this case?
I have factory methods - and I have to loop over them - sort of Chain
of Responsibility pattern.
Having a registry inside the class instance and looping through them
was the only clean thing I could think of.
I understand that garbage collection would be an issue - but is there
any way out?
--
http://mail.python.org/mailman/listinfo/python-list


String Comparison Testing

2008-12-24 Thread Brad Causey
Python Version: Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310
32 bit (Intel)] on win32

List,

I am trying to do some basic log parsing, and well, I am absolutely floored
at this seemingly simple problem. I am by no means a novice in python, but
yet this is really stumping me. I have extracted the pertinent code snippets
and modified them to function as a standalone script. Basically I am reading
a log file ( in this case, testlog.log) for entries and comparing them to
entries in a safe list (in this case, safelist.lst). I have spent numerous
hours doing this several ways and this is the most simple way I can come up
with:


import string

safelistfh = file('safelist.lst', 'r')
safelist = safelistfh.readlines()

logfh = file('testlog.log', 'r')
loglines = logfh.readlines()

def safecheck(line):
for entry in safelist:
print 'I am searching for\n'
print entry
print '\n'
print 'to exist in\n'
print line
comp = line.find(entry)
if comp <> -1:
out = 'Failed'
else:
out = 'Passed'
return out

for log in loglines:
finalentry = safecheck(log)
if finalentry == 'Failed':
print 'This is an internal site'
else:
print 'This is an external site'


The contents of the two files are as follows:


http://www.mysite.com



http://www.mysite.com/images/homepage/xmlslideshow-personal.swf


It seems that no matter what I do, I can't get this to fail the " if comp <>
-1:" check. (My goal is for the check to fail so that I know this is just a
URL to a safe[internal] site)
My assumption is that the HTTP:// is somehow affecting the searching
capabilities of the string.find function. But I can't seem to locate any
documentation online that outlines restrictions when using special
characters.

Any thoughts?

Thanks!



-Brad Causey
CISSP, MCSE, C|EH, CIFI

Zero Day Consulting
--
http://mail.python.org/mailman/listinfo/python-list


Re: Custom C Exception Subclasses

2008-12-24 Thread Ross
On Dec 24, 9:24 am, "Gabriel Genellina" 
wrote:
> In fact you can, you could store those pointers as attributes of the
> exception object, using a PyCObject.

Excellent.  I was not aware of the PyCObject type.

> Accessing those attributes isn't as easy as doing exc->field, but I think
> it's easy enough. Inheriting from some exception type requires you to
> define the type structure and fill it right, and IMHO is a lot harder.
>
> Perhaps there is a misunderstanding here. To subclass a type, you need the
> type, not an instance of such type.

Ah yes, I probably should have been more clear.  In the docs about
subclassing, they use a PyListObject as the first field of the Shoddy
struct so that the fields are filled in correctly.

Now, how would I go about adding methods to a custom exception object?
--
http://mail.python.org/mailman/listinfo/python-list


VERY simple string comparison issue

2008-12-24 Thread Brad Causey
Python Version: Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310
32 bit (Intel)] on win32

List,

I am trying to do some basic log parsing, and well, I am absolutely floored
at this seemingly simple problem. I am by no means a novice in python, but
yet this is really stumping me. I have extracted the pertinent code snippets
and modified them to function as a standalone script. Basically I am reading
a log file ( in this case, testlog.log) for entries and comparing them to
entries in a safe list (in this case, safelist.lst). I have spent numerous
hours doing this several ways and this is the most simple way I can come up
with:


import string

safelistfh = file('safelist.lst', 'r')
safelist = safelistfh.readlines()

logfh = file('testlog.log', 'r')
loglines = logfh.readlines()

def safecheck(line):
for entry in safelist:
print 'I am searching for\n'
print entry
print '\n'
print 'to exist in\n'
print line
comp = line.find(entry)
if comp <> -1:
out = 'Failed'
else:
out = 'Passed'
return out

for log in loglines:
finalentry = safecheck(log)
if finalentry == 'Failed':
print 'This is an internal site'
else:
print 'This is an external site'


The contents of the two files are as follows:


http://www.mysite.com



http://www.mysite.com/images/homepage/xmlslideshow-personal.swf


It seems that no matter what I do, I can't get this to fail the " if comp <>
-1:" check. (My goal is for the check to fail so that I know this is just a
URL to a safe[internal] site)
My assumption is that the HTTP:// is somehow affecting the searching
capabilities of the string.find function. But I can't seem to locate any
documentation online that outlines restrictions when using special
characters.

Any thoughts?

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


Re: Iterating over objects of a class

2008-12-24 Thread Gabriel Genellina
En Wed, 24 Dec 2008 16:18:55 -0200, Kottiyath   
escribió:



The other thing to remember is that because the 'registry' contains
references to the instances, they won't be garbage collected.


Is there any other way out in this case?
I have factory methods - and I have to loop over them - sort of Chain
of Responsibility pattern.
Having a registry inside the class instance and looping through them
was the only clean thing I could think of.
I understand that garbage collection would be an issue - but is there
any way out?


You may keep all that structures - just use weak references (see the  
weakref module).
There isn't a WeakList nor WeakSet out-of-the-box but you may use a  
WeakKeyDictionary (set the value to anything, None by example).


--
Gabriel Genellina

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


Re: String Comparison Testing

2008-12-24 Thread Gabriel Genellina
En Wed, 24 Dec 2008 16:20:17 -0200, Brad Causey  
 escribió:


I am trying to do some basic log parsing, and well, I am absolutely  
floored
at this seemingly simple problem. I am by no means a novice in python,  
but
yet this is really stumping me. I have extracted the pertinent code  
snippets
and modified them to function as a standalone script. Basically I am  
reading

a log file ( in this case, testlog.log) for entries and comparing them to
entries in a safe list (in this case, safelist.lst). I have spent  
numerous
hours doing this several ways and this is the most simple way I can come  
up

with:


I'd say the "\n" at the end of each line is the culprit.


safelist = safelistfh.readlines()


safelist = [line.strip() for line in safelistfh]

(or just strip('\n') if spaces are important); same for the other list.


def safecheck(line):
for entry in safelist:
print 'I am searching for\n'
print entry
print '\n'
print 'to exist in\n'
print line


repr() is your friend when debugging these things: print repr(entry) etc.


comp = line.find(entry)
if comp <> -1:
out = 'Failed'
else:
out = 'Passed'


I'd use:
  if entry in line: ...

Are you sure you're interested in the LAST comparison result ONLY?

--
Gabriel Genellina

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


Re: Iterating over objects of a class

2008-12-24 Thread Kottiyath
On Dec 24, 11:48 pm, "Gabriel Genellina" 
wrote:
> En Wed, 24 Dec 2008 16:18:55 -0200, Kottiyath   
> escribió:
>
> >> The other thing to remember is that because the 'registry' contains
> >> references to the instances, they won't be garbage collected.
>
> > Is there any other way out in this case?
> > I have factory methods - and I have to loop over them - sort of Chain
> > of Responsibility pattern.
> > Having a registry inside the class instance and looping through them
> > was the only clean thing I could think of.
> > I understand that garbage collection would be an issue - but is there
> > any way out?
>
> You may keep all that structures - just use weak references (see the  
> weakref module).
> There isn't a WeakList nor WeakSet out-of-the-box but you may use a  
> WeakKeyDictionary (set the value to anything, None by example).
>
> --
> Gabriel Genellina

Thank you very much, Gabriel.
I am very thankful to everyone.
--
http://mail.python.org/mailman/listinfo/python-list


Re: [SPAM] VERY simple string comparison issue

2008-12-24 Thread MRAB

Brad Causey wrote:
Python Version: Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC 
v.1310 32 bit (Intel)] on win32


List,

I am trying to do some basic log parsing, and well, I am absolutely 
floored at this seemingly simple problem. I am by no means a novice in 
python, but yet this is really stumping me. I have extracted the 
pertinent code snippets and modified them to function as a standalone 
script. Basically I am reading a log file ( in this case, testlog.log) 
for entries and comparing them to entries in a safe list (in this case, 
safelist.lst). I have spent numerous hours doing this several ways and 
this is the most simple way I can come up with:



import string

safelistfh = file('safelist.lst', 'r')
safelist = safelistfh.readlines()

logfh = file('testlog.log', 'r')
loglines = logfh.readlines()

def safecheck(line):
for entry in safelist:
print 'I am searching for\n'
print entry
print '\n'
print 'to exist in\n'
print line
comp = line.find(entry)
if comp <> -1:
out = 'Failed'
else:
out = 'Passed'
return out


Unless I've misunderstood what you're doing, wouldn't it be better as:

def safecheck(line):
for entry in safelist:
print 'I am searching for\n'
print entry
print '\n'
print 'to exist in\n'
print line
if entry in line:
return 'Passed'
return 'Failed'


for log in loglines:
finalentry = safecheck(log)
if finalentry == 'Failed':
print 'This is an internal site'
else:
print 'This is an external site'


Actually, I think it would be better to use True and False instead of 
'Passed' and 'Failed.



The contents of the two files are as follows:


http://www.mysite.com 



http://www.mysite.com/images/homepage/xmlslideshow-personal.swf


It seems that no matter what I do, I can't get this to fail the " if 
comp <> -1:" check. (My goal is for the check to fail so that I know 
this is just a URL to a safe[internal] site)
My assumption is that the HTTP:// is somehow affecting the searching 
capabilities of the string.find function. But I can't seem to locate any 
documentation online that outlines restrictions when using special 
characters.


Any thoughts?


You'll still need to strip off the '\n'.
--
http://mail.python.org/mailman/listinfo/python-list


Doing set operation on non-hashable objects

2008-12-24 Thread 5lvqbwl02
Hi,

I'm writing an application which is structured roughly as follows:

"db" is a dict, where the values are also dicts.
A function searches through db and returns a list of values, each of
which is a dict as described above.
I need to perform set operations on these lists (intersection and
union)
However the objects themselves are not hashable, and therefore can't
be in a set, because they are dicts.
I'm not sure how large each set will be, but the point is I'm trying
to avoid anything looking like an O(n^2) algorithm, so I can't just
use naive double-looping to check for intersection/union on a pair of
lists.

The only way I can think of to do this right is to hash the dicts by
freezing them, turning them all into tuples, which can then be
hashed.  But this is a problem because more dicts might be nested
inside.  At any rate, I'd need to thaw them out when I'm done and turn
them back into dicts, which seems complicated and annoying, and all
this leads me to believe there is a better way.

What I really need is a set of pointers, so at the end of the
operation I have the actual objects pointed to.  Can I somehow use the
object IDs as set elements, then recreate a list with the actual
objects they point to?

How do you get the object back from an ID in python?

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


Re: Strategy for determing difference between 2 very large dictionaries

2008-12-24 Thread Scott David Daniels

Gabriel Genellina wrote:

En Wed, 24 Dec 2008 06:23:00 -0200,  escribió:

 ... k1 = set(dict1.iterkeys())
You've got an excelent explanation from Marc Rintsch. (Note that in 
Python 3.0 keys() behaves as iterkeys() in previous versions, so the 
above code is supposed to be written in Python 2.x)

And, in fact, a dictionary iterates its keys, so:
k1 = set(dict1)
works in 2.4, 2.5, 2.6, and 3.0

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


Re: Custom C Exception Subclasses

2008-12-24 Thread Gabriel Genellina
En Wed, 24 Dec 2008 15:48:34 -0200, Gabriel Genellina  
 escribió:


En Wed, 24 Dec 2008 15:00:36 -0200, Ivan Illarionov  
 escribió:



When you raise an exception in C++ you can set it to ANY Python object
via PyErr_SetObject and that object could store pointers to C++
classes.


Remember that exceptions should inherit from BaseException; although  
this rule isn't enforced in Python 2.6, 3.0 doesn't allow that.
It isn't explicitely written in the docs, but I think that  
PyErr_SetObject won't allow you to pass an object which is not an  
instance of its first argument.


Correction: you're right, it is OK to pass any other object as the second  
parameter to PyErr_SetObject; it will be used as the argument to the  
exception constructor.


--
Gabriel Genellina

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


Re: Iterating over objects of a class

2008-12-24 Thread Scott David Daniels

Kottiyath wrote:

...
Having a registry inside the class instance and looping through them
was the only clean thing I could think of.
I understand that garbage collection would be an issue - but is there
any way out?


Search for weakref in the documentatione.
In this case, I'd use a WeakValueDictionary() from id(obj) to obj.
Note id(obj) is guaranteed to be unique for all objects in existance,
but the id of a collected object may match the id of a new object.

>>> import weakref
>>> d = weakref.WeakValueDictionary()
>>> vs = [Int(n) for n in range(3, 500, 70)]
>>> for n in vs:
d[id(n)] = n
v = Int(n+1)
d[id(v)] = v
>>> for obj in d.values(): # values is safer than itervalues
print obj
>>> # note the above was the following, which fails:
>>> for v in d.values(): # values is safer than itervalues
print v


For extra credit, explain why values is better.

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


Re: Doing set operation on non-hashable objects

2008-12-24 Thread Gabriel Genellina

En Wed, 24 Dec 2008 17:16:59 -0200, <5lvqbw...@sneakemail.com> escribió:


I'm writing an application which is structured roughly as follows:

"db" is a dict, where the values are also dicts.
A function searches through db and returns a list of values, each of
which is a dict as described above.
I need to perform set operations on these lists (intersection and
union)
However the objects themselves are not hashable, and therefore can't
be in a set, because they are dicts.


See this thread from last week:
http://groups.google.com/group/comp.lang.python/t/d6818ff713bd4421


What I really need is a set of pointers, so at the end of the
operation I have the actual objects pointed to.  Can I somehow use the
object IDs as set elements, then recreate a list with the actual
objects they point to?


If you *only* care about object identity, you might use a dictionary that  
only compares by identity to anyone else:


class nc_dict(dict):
  "A hashable dictionary that isn't equal to anyone else"

  def __eq__(self, other):
return cmp(id(self),id(other))==0

  def __hash__(self):
return hash(id(self))

d1 = nc_dict(a=1, b=2, c=3)
d2 = nc_dict(b=2, c=0, d=4)
d3 = nc_dict(a=1, c=3, e=5)
dd1 = nc_dict(x=d1, y=d2)
dd2 = nc_dict(x=d1, y=d3)
dd3 = nc_dict(y=d2, z=d3, w=d1)
l1 = [dd1, dd2]
l2 = [dd2, dd3]
s1 = set(l1)
s2 = set(l2)
print s1-s2
print s2-s1
print s1&s2

# instances of nc_dict with the same contents are NOT equal
d4 = nc_dict(a=1, b=2, c=3)
print d1, d4, d1==d4  # output: False

# but we can use this function to compare contents
def cmp_contents(d1, d2):
try: return cmp(sorted(d1.items()), sorted(d2.items()))
except Exception: return 1 # assume they're unequal

print cmp_contents(d1,d4)==0 # output: True


How do you get the object back from an ID in python?


You don't :)

--
Gabriel Genellina

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


Re: Doing set operation on non-hashable objects

2008-12-24 Thread Scott David Daniels

5lvqbw...@sneakemail.com wrote:

... "db" is a dict, where the values are also dicts.
A function searches through db and returns a list of values, each of
which is a dict as described above.
I need to perform set operations on these lists (intersection and
union)
However the objects themselves are not hashable, and therefore can't
be in a set, because they are dicts.
I'm not sure how large each set will be, but the point is I'm trying
to avoid anything looking like an O(n^2) algorithm, so I can't just
use naive double-looping to check for intersection/union on a pair of
lists.


Well, if the lists are ordered, you can do intersection and union
in O(n) time.  If they are orderable, you can sort each first, giving
O(n log n).  Note you can do lst.sort(key=id) which will sort on ids.


What I really need is a set of pointers, so at the end of the
operation I have the actual objects pointed to.  Can I somehow use the
object IDs as set elements, then recreate a list with the actual
objects they point to?
How do you get the object back from an ID in python?


You don't; you remember the mapping in a dictionary and look it up.
If there were a way to go from id to object, the whole idea of garbage
collection and reference counts would fly out the window, leading to
nasty crashes (or you might get to an object that is the re-used id of
an older object).

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


Re: New Python 3.0 string formatting - really necessary?

2008-12-24 Thread Scott David Daniels

Bruno Desthuilliers wrote:
... Now improvements are always welcomes, and if you compare 1.5.2 with 
2.5.1, you'll find out that the core developpers did improve Python's 
perfs.


Cool, palindromic inverses as compatible versions!
--
http://mail.python.org/mailman/listinfo/python-list


electronics

2008-12-24 Thread sony
http://allelectronicss.blogspot.com/2008/12/mobile-phone.html

http://allelectronicss.blogspot.com/2008/12/electric-car.html

http://allelectronicss.blogspot.com/2008/12/electric-vehicles.html

http://allelectronicss.blogspot.com/2008/12/washing-machine.html

http://allelectronicss.blogspot.com/2008/12/microwave-oven.html

http://allelectronicss.blogspot.com/2008/12/fan.html

http://allelectronicss.blogspot.com/2008/12/iron-box.html

http://allelectronicss.blogspot.com/2008/12/refrigerator.html

http://allelectronicss.blogspot.com/2008/12/electric-heater.html

http://allelectronicss.blogspot.com/2008/12/stove.html

http://allelectronicss.blogspot.com/2008/12/bulb.html

http://allelectronicss.blogspot.com/2008/12/tape-recorder.html

http://allelectronicss.blogspot.com/2008/12/plasma.html

http://allelectronicss.blogspot.com/2008/12/television.html

http://allelectronicss.blogspot.com/2008/12/ipod.html

http://allelectronicss.blogspot.com/2008/12/laptop.html

http://allelectronicss.blogspot.com/2008/12/computer.html
--
http://mail.python.org/mailman/listinfo/python-list


mobiles

2008-12-24 Thread sony
Excellent Mobiles(Latest)

http://latestmobii.blogspot.com/2008/11/blackberry-8800.html

http://latestmobii.blogspot.com/2008/11/sony-ericsson-z555i.html

http://latestmobii.blogspot.com/2008/11/motorola.html

http://latestmobii.blogspot.com/2008/11/samsung.html

http://latestmobii.blogspot.com/2008/11/nokia-7380-coming-soon.html

http://latestmobii.blogspot.com/2008/11/sony-ericsson-xperia-x1.html

http://latestmobii.blogspot.com/2008/11/nokia-8800.html

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


music maestro

2008-12-24 Thread sony
develops extraordinary music and heart touching sequences.To know
about him and his works watch

www.arrehmanfan.blogspot.com

http://arrehmanfan.blogspot.com/2008/12/ar-rahman-on-golden-globe-list.html

http://arrehmanfan.blogspot.com/2008/12/listen-to-ar-rahman-ft-mia-from-slumdog.html

http://arrehmanfan.blogspot.com/2008/12/i-was-completely-devastated-after.html

http://arrehmanfan.blogspot.com/2008/12/aishwarya-abhishek-to-croon-for-r.html

http://arrehmanfan.blogspot.com/2008/12/ar-rahman-bags-satellite-award.html

http://arrehmanfan.blogspot.com/2008/12/kylie-minogue-to-sing-for-ar-rahman.html

http://arrehmanfan.blogspot.com/2008/11/rahman-remixes-choli-ke-peechhey.html

http://arrehmanfan.blogspot.com/2008/11/r-rahmans-cricket-connection.html

http://arrehmanfan.blogspot.com/2008/11/ar-rahman-tunes-for-maheshs-movie.html

http://arrehmanfan.blogspot.com/2008/11/r-rahman-inspires-people-to-vote.html

http://arrehmanfan.blogspot.com/2008/11/latest-entries.html

http://arrehmanfan.blogspot.com/2008/10/people-speak.html

http://arrehmanfan.blogspot.com/2008/10/man-behind-music.html

http://arrehmanfan.blogspot.com/2008/10/list-of-r-rahman-awards.html

http://arrehmanfan.blogspot.com/2008/10/social-work.html

http://arrehmanfan.blogspot.com/2008/10/other-works.html

http://arrehmanfan.blogspot.com/2008/10/summary-of-career.html

http://arrehmanfan.blogspot.com/2008/10/biography.html

http://arrehmanfan.blogspot.com/2008/10/archive.html

http://arrehmanfan.blogspot.com/2008/10/r-rahman-phat-phish-launch-big-band.html

http://arrehmanfan.blogspot.com/2008/09/profile.html

http://arrehmanfan.blogspot.com/2008/09/allah-rakkhha-rahman-tamil.html
--
http://mail.python.org/mailman/listinfo/python-list


advt

2008-12-24 Thread sony
http://www.adztel.blogspot.com/

http://adztel.blogspot.com/2008/12/tatoo-niche-ebooks.html

http://adztel.blogspot.com/2008/12/cpa-riches.html

http://adztel.blogspot.com/2008/12/value-scan-profile.html

http://adztel.blogspot.com/2008/12/keyword-elite-software.html

http://adztel.blogspot.com/2008/12/over-1600-nano-technology-companies.html

http://adztel.blogspot.com/2008/12/internet-marketing-wish-list.html

http://adztel.blogspot.com/2008/12/affilorama.html

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


Re: Doing set operation on non-hashable objects

2008-12-24 Thread Carl Banks
On Dec 24, 1:16 pm, 5lvqbw...@sneakemail.com wrote:
> Hi,
>
> I'm writing an application which is structured roughly as follows:
>
> "db" is a dict, where the values are also dicts.
> A function searches through db and returns a list of values, each of
> which is a dict as described above.
> I need to perform set operations on these lists (intersection and
> union)
> However the objects themselves are not hashable, and therefore can't
> be in a set, because they are dicts.
> I'm not sure how large each set will be, but the point is I'm trying
> to avoid anything looking like an O(n^2) algorithm, so I can't just
> use naive double-looping to check for intersection/union on a pair of
> lists.
>
> The only way I can think of to do this right is to hash the dicts by
> freezing them, turning them all into tuples, which can then be
> hashed.  But this is a problem because more dicts might be nested
> inside.  At any rate, I'd need to thaw them out when I'm done and turn
> them back into dicts, which seems complicated and annoying, and all
> this leads me to believe there is a better way.
>
> What I really need is a set of pointers, so at the end of the
> operation I have the actual objects pointed to.  Can I somehow use the
> object IDs as set elements, then recreate a list with the actual
> objects they point to?
>
> How do you get the object back from an ID in python?

Quick and dirty way is to reference the dicts with a lightweight
hashable object that uses the dict's identity.  For instance:


class Identity(object):
def __init__(self,obj):
self.obj = obj
def __hash__(self):
return hash(id(self.obj))
def __eq__(self,other):
return self.obj is other.obj


Then, instead of "s.add(d)" use "s.add(Identity(d))".

Instead of "d = s.pop()" use "d = s.pop().obj".

Instead of "d in s" use "Identity(d) in s".

And so on.


To do it a bit better, you could create an IdentitySet class that
subclasses set and wraps the methods so that they automatically apply
wrap and unwrap the arguments on their way in and out (I'd bet there's
already a cookbook recipe to do that).


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


Re: New Python 3.0 string formatting - really necessary?

2008-12-24 Thread r
On Dec 22, 7:26 pm, Steven D'Aprano
 wrote:
> On Mon, 22 Dec 2008 06:58:06 -0800, walterbyrd wrote:
> > On Dec 21, 12:28 pm, Bruno Desthuilliers
> >  wrote:
> >> Strange enough,
> >> no one seems to complain about PHP or Ruby's performances...
>
> > A few years back, there was a certain amount of chest thumping, when
> > python/django easily beat ror in a benchmark test. Now that ruby is
> > faster, I guess speed is no big issue.
>
> Who was doing this chest-thumping? Fanboys like "r"? Why should you tar
> all of us with their immaturity?

Walter,
Steven would rather live in a bland Utopian society and could care
less for the greatness of competition and he has little respect for
loyalty. He would like to have little league games where there is no
losers, so nobody's "feelings" get hurt(oh NO!). And EOE so that god
forbid weather or not someone is qualified they must be hired just to
keep a equal balance in the workplace. Hey Steven, we should outlaw
individualism too, God forbid someone think outside the box!(damn
heretics!)

 But as they say "ignorance is bliss" ey Stevie?

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


Re: I always wonder ...

2008-12-24 Thread Craig Allen
this is one of the most subtle trolls I've ever read.

you sir, are a master!


On Dec 22, 7:53 am, s...@pobox.com wrote:
> ... shouldn't people who spend all their time trolling be doing something
> else: studying, working, writing patches which solve the problems they
> perceive to exist in the troll subject?  Is there some online troll game
> running where the players earn points for generating responses to their
> posts?
>
> --
> Skip Montanaro - s...@pobox.com -http://smontanaro.dyndns.org/

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


Lesbians cuple USA

2008-12-24 Thread kylefranki
Lesbi cuple want sex right now  http://lesbicouple.pornblink.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: I always wonder ...

2008-12-24 Thread r
On Dec 22, 6:55 pm, John Machin  wrote:
> On Dec 23, 10:24 am, r  wrote:
>
> > Because my balls are so big i walk around bow-legged!
>
> Have you considered that your alleged testicular enormity may in fact
> be an illusion caused by a hernia?

John i see some troll rated your post with one star, so i rated it
myself with 5. I actually thought it was quite amusing, and shows you
yourself have a solid pair, unlike some others around here who's have
not even dropped yet.  :)
--
http://mail.python.org/mailman/listinfo/python-list


Python 3 and my Mac (Leopard)

2008-12-24 Thread Dan
Wanted to learn python, got Mark Summerfield's new book "Programming in 
Python 3".  Having a hard time getting python 3 and IDLE working on my 
Mac with Leopard.  The mac "resources" on the python.org site seem a 
bit out of date, and don't really mention python 3.  Are there any 
resources out there?  Is the python community just not interested in 
Macs?  I've tried googling and the usual search strategies.  Any help 
would be appreciated.


DAN

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


Re: Using exceptions in defined in an extension module inside another extension module

2008-12-24 Thread Floris Bruynooghe


Christian Heimes wrote:

> Floris Bruynooghe schrieb:
> > What I can't work out however is how to then be able to raise this
> > exception in another extension module.  Just defining it as "extern"
> > doesn't work, even if I make sure the first module -that creates the
> > exception- gets loaded first.  Because the symbol is defined in the
> > first extension module the dynamic linker can't find it as it only
> > seems to look in the main python executable for symbols used in
> > dlloaded sofiles.
> >
> > Does anyone have an idea of how you can do this?
>
> The answer is so obvious that you are going to bang your head against
> the next wall. You have to do exactly the same as you'd do with a pure
> Python module: import it. :)

Well, I hope the wall hurts as much as my head...

Great tip, at first I wasn't looking forward to importing the module
in every function where I wanted the exceptions.  But then I realised
they are global variables anyway so I could have them as such again
and just assign them in the module init function.

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


PythonCard timer/thread tutorial

2008-12-24 Thread Sponge Nebson
Hello all,

This is my first post. Nice to meet you all! Could one of you walk me
through this code?

   def myThread(*argtuple):
"""
A little thread we've added
"""
print "myThread: entered"
q = argtuple[0]
print "myThread: starting loop"
x = 10
while True:
time.sleep(10) # time unit is seconds
print "myThread x=%d" % x
q.put(str(x)) # stick something on message queue
wx.WakeUpIdle() # triggers 'idle' handlers
x += 10

It is from David McNab and Alex Tweedly's tutorial on timers and
threads, which can be found here:

 http://pythoncard.sourceforge.net/timers-threads.html

Among my questions are:
""" A little thread we've added""" seems to be an isolated string. It
does not seem to be doing anything there, almost like a comment. Why
is it there?

What is argtuple for? how does it work?

What is the queue for?

Thanks!

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


Re: Strategy for determing difference between 2 very large dictionaries

2008-12-24 Thread Terry Reedy

Marc 'BlackJack' Rintsch wrote:

On Wed, 24 Dec 2008 03:23:00 -0500, python wrote:



collection, I don't see the advantage of using an iterator or a list.
I'm sure I'm missing a subtle point here :)


`keys()` creates a list in memory, `iterkeys()` does not.  With
``set(dict.keys())`` there is a point in time where the dictionary, the 
list, and the set co-exist in memory.  With ``set(dict.iterkeys())`` only 
the set and the dictionary exist in memory.


If you can, consider using 3.0 in which d.keys() is a set-like view of 
the keys of d.  Same for d.values and d.items. The time and space to 
create such is O(1), I believe. since they are just alternate read-only 
interfaces to the internal dict storage.  There is not even a separate 
set until you do something like intersect d1.keys() with d2.keys() or 
d1.keys() - d2.keys().  I think this is an under-appreciated feature of 
3.0 which should be really useful with large dicts.


tjr

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


Re: Python's popularity

2008-12-24 Thread r
On Dec 24, 1:19 am, Steven D'Aprano  wrote:
> On Tue, 23 Dec 2008 08:06:35 -0800, the anonymous troll known only as "r"
> replied to Thorsten Kampe and said:
>
> > Thats "Thurstan", thank you very much! :)
>
> I think Thorsten knows how to spell his own name.
>
> --
> Steven

OK Steven, you caught me fair and square. This is my first mistake and
i will admit it. Sorry "Thorsten"
--
http://mail.python.org/mailman/listinfo/python-list


Easy-to-use Python GUI

2008-12-24 Thread Joel Koltner
Is there an easy-to-use, "function"-based cross-platform GUI toolkit for 
Python out there that's a little more sophisticated than EasyGui?  EasyGui 
looks good, but it's a little more restrictive than what I'd like to have, yet 
I'm (stubbornly :-) ) resistant to stepping up to a "full service" GUI toolkit 
such as pyGTK or wxPython where it's all about event loops and callbacks and 
you need to start planning how the GUI affects the overall program flow rather 
than just using a "forms" (or "Wizard")-type approach where you put up a few 
dialogs, users fill in some variables, and your program just sits around 
waiting until "OK" or "Cancel" is clicked.

One approach that I like comes from SAX BASIC/WinWrap, which is more or less a 
clone of Microsoft's Visual BASIC for Applications, but they (apparently) 
wanted everything to still be human-readable, so they have a simple GUI 
("form") builder that generates code that looks like this:

---

 Begin Dialog UserDialog 850,497,"Export Control" ' %GRID:10,7,1,1

  GroupBox 20,7,360,217,"Drill File Generation",.GroupBox1
  CheckBox 40,35,130,14,"Output drill file(s)",.genDrill
  Text 40,63,270,28,"Identify via layers as any that contain this text in 
their names:",.Text
  TextBox 40,98,220,21,.viaLayerName
  Text 40,140,100,14,"Output method:",.Text8
  DropListBox 160,140,180,21,DrillStyle(),.drillStyle
  Text 40,175,130,28,"Select drill table units:",.Text2
  ListBox 200,175,120,28,unitNames(),.unitName

  OKButton 310,469,90,21
  CancelButton 410,469,90,21

 End Dialog

' GUI builder generates or modifies everything above, but can also be edited 
by hand
' You write the following code...

 Dim dlg As UserDialog

 dlg.genDrill = 1
 ReDim DrillStyle(1)
 DrillStyle(0) = "All Via Layers In One File"
 DrillStyle(1) = "One File Per Via Layer"
 dlg.drillStyle = 1

 func=Dialog(dlg)

---

This is pretty darned easy for me understand and modify either by hand or with 
the GUI builder.  Still, it's quite powerful, since it supports all the common 
GUI elements (text, group boxes, checkboxes, drop-down lists, text boxes, 
buttons, etc.).  This is about the level of sophistication I'm looking for.

Anything like this for Python?

Thanks,
---Joel


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


Re: Custom C Exception Subclasses

2008-12-24 Thread Ivan Illarionov
On Dec 24, 10:43 pm, "Gabriel Genellina" 
wrote:
> En Wed, 24 Dec 2008 15:48:34 -0200, Gabriel Genellina  
>  escribió:
>
> > En Wed, 24 Dec 2008 15:00:36 -0200, Ivan Illarionov  
> >  escribió:
>
> >> When you raise an exception in C++ you can set it to ANY Python object
> >> via PyErr_SetObject and that object could store pointers to C++
> >> classes.
>
> > Remember that exceptions should inherit from BaseException; although  
> > this rule isn't enforced in Python 2.6, 3.0 doesn't allow that.
> > It isn't explicitely written in the docs, but I think that  
> > PyErr_SetObject won't allow you to pass an object which is not an  
> > instance of its first argument.
>
> Correction: you're right, it is OK to pass any other object as the second  
> parameter to PyErr_SetObject; it will be used as the argument to the  
> exception constructor.
>
> --
> Gabriel Genellina

Yes, I was talking about the second argument to PyErr_SetObject.

I probably wasn't clear. I meant OP could create normal exception with
PyErr_NewException and use it as a transport for any data, including
C++ wrappers, not only text messages as he probably assumes.

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


www.iofferkicks.com china cheap wholesale nike shoes,air jordan shoes,air force one shoes.

2008-12-24 Thread www.iofferkicks.com
Get Nike Shoes at Super Cheap Prices
Discount Nike air jordans  (www.iofferkicks.com)
Discount Nike Air Max 90 Sneakers  (www.iofferkicks.com)
Discount Nike Air Max 91 Supplier  (www.iofferkicks.com)
Discount Nike Air Max 95 Shoes Supplier  (www.iofferkicks.com)
Discount Nike Air Max 97 Trainers  (www.iofferkicks.com)
Discount Nike Air Max 2003 Wholesale  (www.iofferkicks.com)
Discount Nike Air Max 2004 Shoes Wholesale
(www.iofferkicks.com)
Discount Nike Air Max 2005 Shop  (www.iofferkicks.com)
Discount Nike Air Max 2006 Shoes Shop  (www.iofferkicks.com)
Discount Nike Air Max 360 Catalogs  (www.iofferkicks.com)
Discount Nike Air Max Ltd Shoes Catalogs  (www.iofferkicks.com)
Discount Nike Air Max Tn Men's Shoes  (www.iofferkicks.com)
Discount Nike Air Max Tn 2 Women's Shoes  (www.iofferkicks.com)
Discount Nike Air Max Tn 3 Customize  (www.iofferkicks.com)
Discount Nike Air Max Tn 4 Shoes Customize
( www.iofferkicks.com)
Discount Nike Air Max Tn 6 Supply  (www.iofferkicks.com)
Discount Nike Shox NZ Shoes Supply  (www.iofferkicks.com)
Discount Nike Shox OZ Sale  (www.iofferkicks.com)
Discount Nike Shox TL Store  (www.iofferkicks.com)
Discount Nike Shox TL 2 Shoes Store (www.iofferkicks.com)
Discount Nike Shox TL 3 Distributor (www.iofferkicks.com)
Discount Nike Shox Bmw Shoes Distributor  (www.iofferkicks.com)
Discount Nike Shox Elite Shoes Manufacturer
(www.iofferkicks.com)
Discount Nike Shox Monster Manufacturer  (www.iofferkicks.com)
Discount Nike Shox R4 Running Shoes  (www.iofferkicks.com)
Discount Nike Shox R5 Mens Shoes  (www.iofferkicks.com)
Discount Nike Shox Ride Womens Shoes (www.iofferkicks.com)
Discount Nike Shox Rival Shoes Wholesaler  (www.iofferkicks.com)
Discount Nike Shox Energia Wholesaler  (www.iofferkicks.com)
Discount Nike Shox LV Sneaker  (www.iofferkicks.com)
Discount Nike Shox Turbo Suppliers  (www.iofferkicks.com)
Discount Nike Shox Classic Shoes Suppliers
(www.iofferkicks.com)
Discount Nike Shox Dendara Trainer  (www.iofferkicks.com)
Discount Nike Air Jordan 1 Seller  (www.iofferkicks.com)
Discount Nike Air Jordan 2 Shoes Seller  (www.iofferkicks.com)
Discount Nike Air Jordan 3 Collection  (www.iofferkicks.com)
Discount Nike Air Jordan 4 Shoes Collection
(www.iofferkicks.com)
Discount Nike Air Jordan 5 Chaussure Shoes
(www.iofferkicks.com)
Discount Nike Air Jordan 6 Catalog  (www.iofferkicks.com)
Discount Nike Air Jordan 7 Shoes Catalog  (www.iofferkicks.com)
Discount Nike Air Jordan 8 Customized  (www.iofferkicks.com)
Discount Nike Air Jordan 9 Shoes Customized
(www.iofferkicks.com)
Discount Nike Air Jordan 10 Wholesalers  (www.iofferkicks.com)
Discount Nike Jordan 11 Shoes Wholesalers (www.iofferkicks.com)
Discount Nike Air Jordan 12 Factory  (www.iofferkicks.com)
Discount Nike Air Jordan 13 Shoes Factory (www.iofferkicks.com)
Discount Nike Air Jordan 14 Shoes Sell  (www.iofferkicks.com)
Discount Nike Air Jordan 16 Exporter  (www.iofferkicks.com)
Discount Nike Air Jordan 17 Shoes Exporter
(www.iofferkicks.com)
Discount Nike Air Jordan 18 Offer  (www.iofferkicks.com)
Discount Nike Air Jordan 19 Shoes Offer  (www.iofferkicks.com)
Discount Nike Air Jordan 20 Manufacture  (www.iofferkicks.com)
Discount Nike Jordan 21 Shoes Manufacture  (www.iofferkicks.com)
EMAIL:iofferki...@gmail.com
MSN :iofferki...@msn.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python's popularity

2008-12-24 Thread Kevin Kelley
On Tue, Dec 23, 2008 at 10:38 AM, r  wrote:

>
> School time son,
> This forum is much more than a question answer session, son. Sure
> people are welcome to ask a Python related question. But this forum is
> really the main highway of Python development and future. If your a
> n00b go to the "Python forum.org", you will feel more comfy over
> there.
>
>
>From python.org (http://www.python.org/community/lists/) -

python-list:
Pretty much anything Python-related is fair game for discussion, and the
group is even fairly tolerant of off-topic digressions; there have been
entertaining discussions of topics such as floating point, good software
design, and other programming languages such as Lisp and Forth.

*Most discussion on comp.lang.python is about developing with Python, not
about development of the Python interpreter itself.*

python-dev:
Note: python-dev is for work on developing Python (fixing bugs and adding
new features to Python itself); if you're having problems writing a Python
program, please post to comp.lang.python.

*python-dev is the heart of Python's development. Practically everyone with
Subversion write privileges is on python-dev, and first drafts of PEPs are
often posted here for initial review and rewriting before their more public
appearance on python-announce.*

I think you are confusing lists r.

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


Re: Easy-to-use Python GUI

2008-12-24 Thread Mike Driscoll
On Dec 24, 5:47 pm, "Joel Koltner" 
wrote:
> Is there an easy-to-use, "function"-based cross-platform GUI toolkit for
> Python out there that's a little more sophisticated than EasyGui?  EasyGui
> looks good, but it's a little more restrictive than what I'd like to have, yet
> I'm (stubbornly :-) ) resistant to stepping up to a "full service" GUI toolkit
> such as pyGTK or wxPython where it's all about event loops and callbacks and
> you need to start planning how the GUI affects the overall program flow rather
> than just using a "forms" (or "Wizard")-type approach where you put up a few
> dialogs, users fill in some variables, and your program just sits around
> waiting until "OK" or "Cancel" is clicked.
>
> One approach that I like comes from SAX BASIC/WinWrap, which is more or less a
> clone of Microsoft's Visual BASIC for Applications, but they (apparently)
> wanted everything to still be human-readable, so they have a simple GUI
> ("form") builder that generates code that looks like this:
>
> ---
>
>  Begin Dialog UserDialog 850,497,"Export Control" ' %GRID:10,7,1,1
>
>   GroupBox 20,7,360,217,"Drill File Generation",.GroupBox1
>   CheckBox 40,35,130,14,"Output drill file(s)",.genDrill
>   Text 40,63,270,28,"Identify via layers as any that contain this text in
> their names:",.Text
>   TextBox 40,98,220,21,.viaLayerName
>   Text 40,140,100,14,"Output method:",.Text8
>   DropListBox 160,140,180,21,DrillStyle(),.drillStyle
>   Text 40,175,130,28,"Select drill table units:",.Text2
>   ListBox 200,175,120,28,unitNames(),.unitName
>
>   OKButton 310,469,90,21
>   CancelButton 410,469,90,21
>
>  End Dialog
>
> ' GUI builder generates or modifies everything above, but can also be edited
> by hand
> ' You write the following code...
>
>  Dim dlg As UserDialog
>
>  dlg.genDrill = 1
>  ReDim DrillStyle(1)
>  DrillStyle(0) = "All Via Layers In One File"
>  DrillStyle(1) = "One File Per Via Layer"
>  dlg.drillStyle = 1
>
>  func=Dialog(dlg)
>
> ---
>
> This is pretty darned easy for me understand and modify either by hand or with
> the GUI builder.  Still, it's quite powerful, since it supports all the common
> GUI elements (text, group boxes, checkboxes, drop-down lists, text boxes,
> buttons, etc.).  This is about the level of sophistication I'm looking for.
>
> Anything like this for Python?
>
> Thanks,
> ---Joel

Some people like Boa Constructor, XRC or wxGlade:

http://boa-constructor.sourceforge.net/
http://wxglade.sourceforge.net/
http://wiki.wxpython.org/XRCTutorial

Technically, you can switch to IronPython and then use Visual Studio
to design your GUIs and IronPython to control it. I think there's
something similar to Jython and Cocoa as well.

Probably not what you wanted though.

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


Re: Easy-to-use Python GUI

2008-12-24 Thread Sponge Nebson
On Dec 24, 3:47 pm, "Joel Koltner" 
wrote:
> Is there an easy-to-use, "function"-based cross-platform GUI toolkit for
> Python out there that's a little more sophisticated than EasyGui?  EasyGui
> looks good, but it's a little more restrictive than what I'd like to have, yet
> I'm (stubbornly :-) ) resistant to stepping up to a "full service" GUI toolkit
> such as pyGTK or wxPython where it's all about event loops and callbacks and
> you need to start planning how the GUI affects the overall program flow rather
> than just using a "forms" (or "Wizard")-type approach where you put up a few
> dialogs, users fill in some variables, and your program just sits around
> waiting until "OK" or "Cancel" is clicked.
>
> One approach that I like comes from SAX BASIC/WinWrap, which is more or less a
> clone of Microsoft's Visual BASIC for Applications, but they (apparently)
> wanted everything to still be human-readable, so they have a simple GUI
> ("form") builder that generates code that looks like this:
>
> ---
>
>  Begin Dialog UserDialog 850,497,"Export Control" ' %GRID:10,7,1,1
>
>   GroupBox 20,7,360,217,"Drill File Generation",.GroupBox1
>   CheckBox 40,35,130,14,"Output drill file(s)",.genDrill
>   Text 40,63,270,28,"Identify via layers as any that contain this text in
> their names:",.Text
>   TextBox 40,98,220,21,.viaLayerName
>   Text 40,140,100,14,"Output method:",.Text8
>   DropListBox 160,140,180,21,DrillStyle(),.drillStyle
>   Text 40,175,130,28,"Select drill table units:",.Text2
>   ListBox 200,175,120,28,unitNames(),.unitName
>
>   OKButton 310,469,90,21
>   CancelButton 410,469,90,21
>
>  End Dialog
>
> ' GUI builder generates or modifies everything above, but can also be edited
> by hand
> ' You write the following code...
>
>  Dim dlg As UserDialog
>
>  dlg.genDrill = 1
>  ReDim DrillStyle(1)
>  DrillStyle(0) = "All Via Layers In One File"
>  DrillStyle(1) = "One File Per Via Layer"
>  dlg.drillStyle = 1
>
>  func=Dialog(dlg)
>
> ---
>
> This is pretty darned easy for me understand and modify either by hand or with
> the GUI builder.  Still, it's quite powerful, since it supports all the common
> GUI elements (text, group boxes, checkboxes, drop-down lists, text boxes,
> buttons, etc.).  This is about the level of sophistication I'm looking for.
>
> Anything like this for Python?
>
> Thanks,
> ---Joel



You may want to try PythonCard. It is a GUI toolkit that runs on
wxPython, but it is much easier to use.

Visit
http://pythoncard.sourceforge.net/
and check out all the samples and screenshots.

You may also want to listen to this podcast:
http://libsyn.com/media/awaretek/Python411_070509_GUItoolkits.mp3
It discusses python GUI toolkits in general.

You should also listen to:
http://media.libsyn.com/media/awaretek/Python411_060730_PythonCard.mp3
which discusses PythonCard in detail.

The python podcast collection can be found at:
http://www.awaretek.com/python/

I just started out with PythonCard and I'm picking it up really fast.
Hope this helps!

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


Re: PythonCard timer/thread tutorial

2008-12-24 Thread Mike Driscoll
On Dec 24, 4:56 pm, Sponge Nebson  wrote:
> Hello all,
>
> This is my first post. Nice to meet you all! Could one of you walk me
> through this code?
>
>    def myThread(*argtuple):
>         """
>         A little thread we've added
>         """
>         print "myThread: entered"
>         q = argtuple[0]
>         print "myThread: starting loop"
>         x = 10
>         while True:
>             time.sleep(10) # time unit is seconds
>             print "myThread x=%d" % x
>             q.put(str(x)) # stick something on message queue
>             wx.WakeUpIdle() # triggers 'idle' handlers
>             x += 10
>
> It is from David McNab and Alex Tweedly's tutorial on timers and
> threads, which can be found here:
>
>  http://pythoncard.sourceforge.net/timers-threads.html
>
> Among my questions are:
> """ A little thread we've added""" seems to be an isolated string. It
> does not seem to be doing anything there, almost like a comment. Why
> is it there?


That's what some people call a doc string. It is like a comment in
that it helps the user know what the function is for. Notice the
triple quotes. If you were to type "help(myFunction)", it would grab
the functions doc string and display it. You can read up on them here:

http://diveintopython.org/getting_to_know_python/documenting_functions.html


>
> What is argtuple for? how does it work?

This allows the programmer to pass an arbitrarily long argument list
to the function. It took a little digging, but I found it in the docs
(scroll down towards the bottom):

http://docs.python.org/tutorial/controlflow.html#SECTION00660


>
> What is the queue for?
>
> Thanks!
>
> -Ben

I haven't messed with queues as yet, but they are one way of dealing
with multiple threads in GUI programming. The idea is to stick
something in the queue for the GUI thread (or potentially some other
thread) to pick up when it's not busy. So one thread sticks something
on the queue and another thread checks the queue periodically to see
if there's something there and if there is, it picks it up. At least,
that's my understanding. You can read up on various methods of messing
with threads in wxPython here:

http://wiki.wxpython.org/LongRunningTasks

And here are the queue docs (for 2.6...): 
http://docs.python.org/library/queue.html

I recommend learning how to use Google effectively. I found about half
the links above using it. You might also find joining the wxPython
mailing list beneficial. I learn a lot there just by reading and
posting to it: http://wxpython.org/maillist.php

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


ctypes & strings

2008-12-24 Thread Red Rackham
Hi friends;
 
I would like to pass a string into a dll function.  I notice that to pass using 
ctypes, it has to be a ctypes type.  Looking at the ctypes doc page I don't see 
a c_string class.  
 
I tried to pass in byref("name of string") and got back "TypeError: byref() 
argument must be a ctypes instance, not 'str'"
 
If I use astr = create_string_buffer( "name of string" ), and try to pass that 
in, I get "ValueError: Procedure probably called with too many arguments (4 
bytes in excess)".
 
If I use astr = (c_char*255)("name of string"), I get "TypeError: one character 
string expected" (on this line).
 
Could some benevolet expert please clue me in on how to accomplish this?
 
Thanks
 
Mark
 
 
 


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


Re: socket send help

2008-12-24 Thread greyw...@gmail.com
Chris & Gabriel,

Thank you so much.  My simple example now works.  It was very
frustrating that even the simple example didn't work, so your help is
most appreciated.

b'hello world' was the key.  As for the error, I do still get it with
3.0 final so I'll go ahead and report it.

John.

On Dec 24, 12:03 am, "Gabriel Genellina" 
wrote:
> En Wed, 24 Dec 2008 03:59:42 -0200, greyw...@gmail.com  
>  escribió:
>
> > New guy here.  I'm trying to figure out sockets in order to one day do
> > a multiplayer game.  Here's my problem:  even the simplest examples
> > don't work on my computer:
>
> > A simple server:
>
> > fromsocketimport *
> > myHost = ''
>
> Try with myHost = '127.0.0.1' instead - a firewall might be blocking your  
> server.
>
> > s.listen(5)                         # allow 5 simultaneous connections
>
> Not exactly: your server program only handles a single connection at a  
> time. The 5 above specifies how many connections may exist "on hold"  
> waiting for you to accept() them.
>
> >             connection.send('echo -> ' + data)
>
> That's fine for Python 2.6, but you must use b'echo -> ' with 3.0
>
> > And a simple client:
>
> > s.send('Hello world')               # send the data
>
> Same as above, should be b'Hello world' with Python 3.0
>
> > If I run testserver.py via the cmd prompt in Windows XP and then the
> > testclient.py program, I get the following error:
>
> > Traceback (most recent call last):
> >   File "C:\Python30\testclient.py", line 12, in 
> >     s.send('Hello world')               # send the data
> > TypeError: send() argument 1 must be string or buffer, not str
>
> The above error message is wrong (and I think it was corrected on the 3.0  
> final release; if you got it with 3.0 final, file a bug report at  
> http://bugs.python.org/)
>
> > This happens in 2.6 or 3.0 and with different example client & server
> > programs from the web.  What am I missing?
>
> The error above surely comes from 3.0; with 2.6 you should get a different  
> error (if it fails at all). Try again with 2.6.1. I didn't run the code  
> but it looks fine -- if you got it from a book or article, unless it  
> explicitely says "Python 3.0", assume it was written for the 2.x series.
>
> --
> Gabriel Genellina

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


Re: Strategy for determing difference between 2 very large dictionaries

2008-12-24 Thread John Machin
On Dec 24, 7:04 pm, "Malcolm Greene"  wrote:
> Hi Roger,
>
> By very large dictionary, I mean about 25M items per dictionary. Each
> item is a simple integer whose value will never exceed 2^15.

In Python-speak about dictionaries, an "item" is a tuple (key, value).
I presume from the gross difference between 25M and 2**15
-- more pedantry: 2^15 is 13 :-) -- that you mean that the values
satisfy 0 <= value <= 2**15.

>
> I populate these dictionaries by parsing very large ASCII text files
> containing detailed manufacturing events. From each line in my log file
> I construct one or more keys and increment the numeric values associated
> with these keys using timing info also extracted from each line.
>
> Some of our log files are generated by separate monitoring equipment
> measuring the same process. In theory, these log files should be
> identical, but of course they are not. I'm looking for a way to
> determine the differences between the 2 dictionaries I will create from
> so-called matching sets of log files.

You seem to refer to the dictionaries as part of your requirements,
not as part of the solution. Do you *need* the two dictionaries after
you have obtained the differences?

Let's start from the beginning: You have two log files, each of which
can be abstracted as containing lots of (k, v) data, where each k
describes an event and each v is a compressed 15-bit timestamp. You
want to know for each datum whether it is (a) in both files (b) only
in file1 (c) only in file2. Is that a fair summary?

If so, there's an alternative that doesn't need to use dictionaries.
Each file can be represented by a *list* of 32768 sets. Each set
contains the ks that happened at the corresponding time... sets[fileno]
[v].add(k). Once you've built that, you trundle through the pairs of
sets doing set differences etc.

Bear in mind that Python dicts and sets grow as required by doubling
(IIRC) in size and rehashing from old to new. Consequently you get
periodical disturbances which are not usually noticed but may be
noticeable with large amounts of data.

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


www.iofferkicks.com china cheap wholesale nike shoes,air jordan shoes,air force one shoes.

2008-12-24 Thread www.iofferkicks.com
Get Nike Shoes at Super Cheap Prices
Discount Nike air jordans  (www.iofferkicks.com)
Discount Nike Air Max 90 Sneakers  (www.iofferkicks.com)
Discount Nike Air Max 91 Supplier  (www.iofferkicks.com)
Discount Nike Air Max 95 Shoes Supplier  (www.iofferkicks.com)
Discount Nike Air Max 97 Trainers  (www.iofferkicks.com)
Discount Nike Air Max 2003 Wholesale  (www.iofferkicks.com)
Discount Nike Air Max 2004 Shoes Wholesale
(www.iofferkicks.com)
Discount Nike Air Max 2005 Shop  (www.iofferkicks.com)
Discount Nike Air Max 2006 Shoes Shop  (www.iofferkicks.com)
Discount Nike Air Max 360 Catalogs  (www.iofferkicks.com)
Discount Nike Air Max Ltd Shoes Catalogs  (www.iofferkicks.com)
Discount Nike Air Max Tn Men's Shoes  (www.iofferkicks.com)
Discount Nike Air Max Tn 2 Women's Shoes  (www.iofferkicks.com)
Discount Nike Air Max Tn 3 Customize  (www.iofferkicks.com)
Discount Nike Air Max Tn 4 Shoes Customize
( www.iofferkicks.com)
Discount Nike Air Max Tn 6 Supply  (www.iofferkicks.com)
Discount Nike Shox NZ Shoes Supply  (www.iofferkicks.com)
Discount Nike Shox OZ Sale  (www.iofferkicks.com)
Discount Nike Shox TL Store  (www.iofferkicks.com)
Discount Nike Shox TL 2 Shoes Store (www.iofferkicks.com)
Discount Nike Shox TL 3 Distributor (www.iofferkicks.com)
Discount Nike Shox Bmw Shoes Distributor  (www.iofferkicks.com)
Discount Nike Shox Elite Shoes Manufacturer
(www.iofferkicks.com)
Discount Nike Shox Monster Manufacturer  (www.iofferkicks.com)
Discount Nike Shox R4 Running Shoes  (www.iofferkicks.com)
Discount Nike Shox R5 Mens Shoes  (www.iofferkicks.com)
Discount Nike Shox Ride Womens Shoes (www.iofferkicks.com)
Discount Nike Shox Rival Shoes Wholesaler  (www.iofferkicks.com)
Discount Nike Shox Energia Wholesaler  (www.iofferkicks.com)
Discount Nike Shox LV Sneaker  (www.iofferkicks.com)
Discount Nike Shox Turbo Suppliers  (www.iofferkicks.com)
Discount Nike Shox Classic Shoes Suppliers
(www.iofferkicks.com)
Discount Nike Shox Dendara Trainer  (www.iofferkicks.com)
Discount Nike Air Jordan 1 Seller  (www.iofferkicks.com)
Discount Nike Air Jordan 2 Shoes Seller  (www.iofferkicks.com)
Discount Nike Air Jordan 3 Collection  (www.iofferkicks.com)
Discount Nike Air Jordan 4 Shoes Collection
(www.iofferkicks.com)
Discount Nike Air Jordan 5 Chaussure Shoes
(www.iofferkicks.com)
Discount Nike Air Jordan 6 Catalog  (www.iofferkicks.com)
Discount Nike Air Jordan 7 Shoes Catalog  (www.iofferkicks.com)
Discount Nike Air Jordan 8 Customized  (www.iofferkicks.com)
Discount Nike Air Jordan 9 Shoes Customized
(www.iofferkicks.com)
Discount Nike Air Jordan 10 Wholesalers  (www.iofferkicks.com)
Discount Nike Jordan 11 Shoes Wholesalers (www.iofferkicks.com)
Discount Nike Air Jordan 12 Factory  (www.iofferkicks.com)
Discount Nike Air Jordan 13 Shoes Factory (www.iofferkicks.com)
Discount Nike Air Jordan 14 Shoes Sell  (www.iofferkicks.com)
Discount Nike Air Jordan 16 Exporter  (www.iofferkicks.com)
Discount Nike Air Jordan 17 Shoes Exporter
(www.iofferkicks.com)
Discount Nike Air Jordan 18 Offer  (www.iofferkicks.com)
Discount Nike Air Jordan 19 Shoes Offer  (www.iofferkicks.com)
Discount Nike Air Jordan 20 Manufacture  (www.iofferkicks.com)
Discount Nike Jordan 21 Shoes Manufacture  (www.iofferkicks.com)
EMAIL:iofferki...@gmail.com
MSN :iofferki...@msn.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Easy-to-use Python GUI

2008-12-24 Thread ajaksu
On Dec 24, 9:47 pm, "Joel Koltner" 
wrote:

>  Dim dlg As UserDialog
>
>  dlg.genDrill = 1
>  ReDim DrillStyle(1)
>  DrillStyle(0) = "All Via Layers In One File"
>  DrillStyle(1) = "One File Per Via Layer"
>  dlg.drillStyle = 1
>
>  func=Dialog(dlg)
>
> ---
>
> This is pretty darned easy for me understand and modify either by hand or with
> the GUI builder.  Still, it's quite powerful, since it supports all the common
> GUI elements (text, group boxes, checkboxes, drop-down lists, text boxes,
> buttons, etc.).  This is about the level of sophistication I'm looking for.
>
> Anything like this for Python?

I have not used it (yet), but Treethon looks like what you want:
---
_import: gtk
view: gtk.Window()
add:
- view: gtk.Button('Hello World')
  on clicked: print view.get_label()
---

Check http://pypi.python.org/pypi/treethon/ and 
http://code.google.com/p/treethon/

If you can report back on treethon, I'd like to hear about it :)

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


Re: Python 3 and my Mac (Leopard)

2008-12-24 Thread Mark
On Wed, Dec 24, 2008 at 5:11 PM, Dan  wrote:
>
> Wanted to learn python, got Mark Summerfield's new book "Programming in 
> Python 3".  Having a hard time getting python 3 and IDLE working on my Mac 
> with Leopard.  The mac "resources" on the python.org site seem a bit out of 
> date, and don't really mention python 3.  Are there any resources out there?  
> Is the python community just not interested in Macs?  I've tried googling and 
> the usual search strategies.  Any help would be appreciated.
>
> DAN


I used the following link when installing Python 3 on my Mac running
Leopard, it worked like a charm:

http://farmdev.com/thoughts/66/python-3-0-on-mac-os-x-alongside-2-6-2-5-etc-/

These instructions are based around installing Python 3 alongside your
existing install, which is what I was looking for.

YMMV, especially concerning IDLE, I haven't used it with 3.0 as of yet.

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


www.iofferkicks.com china cheap wholesale nike shoes,air jordan shoes,air force one shoes.

2008-12-24 Thread www.iofferkicks.com
Get Nike Shoes at Super Cheap Prices
Discount Nike air jordans  (www.iofferkicks.com)
Discount Nike Air Max 90 Sneakers  (www.iofferkicks.com)
Discount Nike Air Max 91 Supplier  (www.iofferkicks.com)
Discount Nike Air Max 95 Shoes Supplier  (www.iofferkicks.com)
Discount Nike Air Max 97 Trainers  (www.iofferkicks.com)
Discount Nike Air Max 2003 Wholesale  (www.iofferkicks.com)
Discount Nike Air Max 2004 Shoes Wholesale
(www.iofferkicks.com)
Discount Nike Air Max 2005 Shop  (www.iofferkicks.com)
Discount Nike Air Max 2006 Shoes Shop  (www.iofferkicks.com)
Discount Nike Air Max 360 Catalogs  (www.iofferkicks.com)
Discount Nike Air Max Ltd Shoes Catalogs  (www.iofferkicks.com)
Discount Nike Air Max Tn Men's Shoes  (www.iofferkicks.com)
Discount Nike Air Max Tn 2 Women's Shoes  (www.iofferkicks.com)
Discount Nike Air Max Tn 3 Customize  (www.iofferkicks.com)
Discount Nike Air Max Tn 4 Shoes Customize
( www.iofferkicks.com)
Discount Nike Air Max Tn 6 Supply  (www.iofferkicks.com)
Discount Nike Shox NZ Shoes Supply  (www.iofferkicks.com)
Discount Nike Shox OZ Sale  (www.iofferkicks.com)
Discount Nike Shox TL Store  (www.iofferkicks.com)
Discount Nike Shox TL 2 Shoes Store (www.iofferkicks.com)
Discount Nike Shox TL 3 Distributor (www.iofferkicks.com)
Discount Nike Shox Bmw Shoes Distributor  (www.iofferkicks.com)
Discount Nike Shox Elite Shoes Manufacturer
(www.iofferkicks.com)
Discount Nike Shox Monster Manufacturer  (www.iofferkicks.com)
Discount Nike Shox R4 Running Shoes  (www.iofferkicks.com)
Discount Nike Shox R5 Mens Shoes  (www.iofferkicks.com)
Discount Nike Shox Ride Womens Shoes (www.iofferkicks.com)
Discount Nike Shox Rival Shoes Wholesaler  (www.iofferkicks.com)
Discount Nike Shox Energia Wholesaler  (www.iofferkicks.com)
Discount Nike Shox LV Sneaker  (www.iofferkicks.com)
Discount Nike Shox Turbo Suppliers  (www.iofferkicks.com)
Discount Nike Shox Classic Shoes Suppliers
(www.iofferkicks.com)
Discount Nike Shox Dendara Trainer  (www.iofferkicks.com)
Discount Nike Air Jordan 1 Seller  (www.iofferkicks.com)
Discount Nike Air Jordan 2 Shoes Seller  (www.iofferkicks.com)
Discount Nike Air Jordan 3 Collection  (www.iofferkicks.com)
Discount Nike Air Jordan 4 Shoes Collection
(www.iofferkicks.com)
Discount Nike Air Jordan 5 Chaussure Shoes
(www.iofferkicks.com)
Discount Nike Air Jordan 6 Catalog  (www.iofferkicks.com)
Discount Nike Air Jordan 7 Shoes Catalog  (www.iofferkicks.com)
Discount Nike Air Jordan 8 Customized  (www.iofferkicks.com)
Discount Nike Air Jordan 9 Shoes Customized
(www.iofferkicks.com)
Discount Nike Air Jordan 10 Wholesalers  (www.iofferkicks.com)
Discount Nike Jordan 11 Shoes Wholesalers (www.iofferkicks.com)
Discount Nike Air Jordan 12 Factory  (www.iofferkicks.com)
Discount Nike Air Jordan 13 Shoes Factory (www.iofferkicks.com)
Discount Nike Air Jordan 14 Shoes Sell  (www.iofferkicks.com)
Discount Nike Air Jordan 16 Exporter  (www.iofferkicks.com)
Discount Nike Air Jordan 17 Shoes Exporter
(www.iofferkicks.com)
Discount Nike Air Jordan 18 Offer  (www.iofferkicks.com)
Discount Nike Air Jordan 19 Shoes Offer  (www.iofferkicks.com)
Discount Nike Air Jordan 20 Manufacture  (www.iofferkicks.com)
Discount Nike Jordan 21 Shoes Manufacture  (www.iofferkicks.com)
EMAIL:iofferki...@gmail.com
MSN :iofferki...@msn.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Easy-to-use Python GUI

2008-12-24 Thread Daniel Fetchinson
> Is there an easy-to-use, "function"-based cross-platform GUI toolkit for
> Python out there that's a little more sophisticated than EasyGui?  EasyGui
> looks good, but it's a little more restrictive than what I'd like to have,
> yet
> I'm (stubbornly :-) ) resistant to stepping up to a "full service" GUI
> toolkit
> such as pyGTK or wxPython where it's all about event loops and callbacks and
> you need to start planning how the GUI affects the overall program flow
> rather
> than just using a "forms" (or "Wizard")-type approach where you put up a few
> dialogs, users fill in some variables, and your program just sits around
> waiting until "OK" or "Cancel" is clicked.
>
> One approach that I like comes from SAX BASIC/WinWrap, which is more or less
> a
> clone of Microsoft's Visual BASIC for Applications, but they (apparently)
> wanted everything to still be human-readable, so they have a simple GUI
> ("form") builder that generates code that looks like this:
>
> ---
>
>  Begin Dialog UserDialog 850,497,"Export Control" ' %GRID:10,7,1,1
>
>   GroupBox 20,7,360,217,"Drill File Generation",.GroupBox1
>   CheckBox 40,35,130,14,"Output drill file(s)",.genDrill
>   Text 40,63,270,28,"Identify via layers as any that contain this text in
> their names:",.Text
>   TextBox 40,98,220,21,.viaLayerName
>   Text 40,140,100,14,"Output method:",.Text8
>   DropListBox 160,140,180,21,DrillStyle(),.drillStyle
>   Text 40,175,130,28,"Select drill table units:",.Text2
>   ListBox 200,175,120,28,unitNames(),.unitName
>
>   OKButton 310,469,90,21
>   CancelButton 410,469,90,21
>
>  End Dialog
>
> ' GUI builder generates or modifies everything above, but can also be edited
> by hand
> ' You write the following code...
>
>  Dim dlg As UserDialog
>
>  dlg.genDrill = 1
>  ReDim DrillStyle(1)
>  DrillStyle(0) = "All Via Layers In One File"
>  DrillStyle(1) = "One File Per Via Layer"
>  dlg.drillStyle = 1
>
>  func=Dialog(dlg)
>
> ---
>
> This is pretty darned easy for me understand and modify either by hand or
> with
> the GUI builder.  Still, it's quite powerful, since it supports all the
> common
> GUI elements (text, group boxes, checkboxes, drop-down lists, text boxes,
> buttons, etc.).  This is about the level of sophistication I'm looking for.
>
> Anything like this for Python?

How about the Tcl/Tk GUI that comes bundled with python?

http://docs.python.org/library/tk.html

Cheers,
Daniel

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


RE: Python advocacy . HELP!

2008-12-24 Thread Sells, Fred
Prof. Kanabar  (kanabar.bu.edu) is planning to offer a python course
there soon.  Perhaps he could help.  Tell him you got his name from me
(Fred Sells).

> -Original Message-
> From: python-list-bounces+frsells=adventistcare@python.org
> [mailto:python-list-bounces+frsells=adventistcare@python.org] On
> Behalf Of Michael_D_G
> Sent: Thursday, December 04, 2008 1:52 AM
> To: python-list@python.org
> Subject: Python advocacy . HELP!
> 
> 
> I am a faculty member of a cs department. We currently teach C++ in
> our intro to programming course. I am teaching this class and it seems
> to me that we would be much better served teaching python in the intro
> course, C++ for Data structures, as we do now, and Java in object
> oriented programming, as we do now.
> Some of my colleagues agree with me but some still see python as a
> niche language and don't understand
> how we could teach anything beyond C, C++ or Java.
> 
> I have looked at several interesting academic papers, on doing just
> this approach. I have also looked through the
> python web page to get examples of industry players using python in a
> non-trivial way. Yes, I know, Google,
> Microsoft, Sun, CIA website running on Plone, NOAA, NASA. If anyone
> has any recent articles,
> or if anyone on the list is at a fortune 500 company, how do I refute
> the notion that Python
> is a "marginal" language because according to TOBIE it only less than
> a  6% market share.
> 
> -michael
> --
> http://mail.python.org/mailman/listinfo/python-list
--
http://mail.python.org/mailman/listinfo/python-list


contour in python

2008-12-24 Thread Ayat Rezaee
 Hello, I need your help,
 I want to make a plot something like this program, 
   import Numeric as N
   from contour import contour
   x = N.arange(25) * 15.0 - 180.0
   y = N.arange(13) * 15.0 - 90.0
    data = N.outerproduct(N.sin(y*N.pi/360.), N.cos(x*N.pi/360.))
contour (data, x, y, title='Example')
 but cant import contour ; so I should install contour or do anythings? send ma 
a link if it should be installed.
 Best regards,
 Ayat.




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


www.iofferkicks.com china cheap wholesale nike shoes,air jordan shoes,air force one shoes.

2008-12-24 Thread www.iofferkicks.com
Get Nike Shoes at Super Cheap Prices
Discount Nike air jordans  (www.iofferkicks.com)
Discount Nike Air Max 90 Sneakers  (www.iofferkicks.com)
Discount Nike Air Max 91 Supplier  (www.iofferkicks.com)
Discount Nike Air Max 95 Shoes Supplier  (www.iofferkicks.com)
Discount Nike Air Max 97 Trainers  (www.iofferkicks.com)
Discount Nike Air Max 2003 Wholesale  (www.iofferkicks.com)
Discount Nike Air Max 2004 Shoes Wholesale
(www.iofferkicks.com)
Discount Nike Air Max 2005 Shop  (www.iofferkicks.com)
Discount Nike Air Max 2006 Shoes Shop  (www.iofferkicks.com)
Discount Nike Air Max 360 Catalogs  (www.iofferkicks.com)
Discount Nike Air Max Ltd Shoes Catalogs  (www.iofferkicks.com)
Discount Nike Air Max Tn Men's Shoes  (www.iofferkicks.com)
Discount Nike Air Max Tn 2 Women's Shoes  (www.iofferkicks.com)
Discount Nike Air Max Tn 3 Customize  (www.iofferkicks.com)
Discount Nike Air Max Tn 4 Shoes Customize
( www.iofferkicks.com)
Discount Nike Air Max Tn 6 Supply  (www.iofferkicks.com)
Discount Nike Shox NZ Shoes Supply  (www.iofferkicks.com)
Discount Nike Shox OZ Sale  (www.iofferkicks.com)
Discount Nike Shox TL Store  (www.iofferkicks.com)
Discount Nike Shox TL 2 Shoes Store (www.iofferkicks.com)
Discount Nike Shox TL 3 Distributor (www.iofferkicks.com)
Discount Nike Shox Bmw Shoes Distributor  (www.iofferkicks.com)
Discount Nike Shox Elite Shoes Manufacturer
(www.iofferkicks.com)
Discount Nike Shox Monster Manufacturer  (www.iofferkicks.com)
Discount Nike Shox R4 Running Shoes  (www.iofferkicks.com)
Discount Nike Shox R5 Mens Shoes  (www.iofferkicks.com)
Discount Nike Shox Ride Womens Shoes (www.iofferkicks.com)
Discount Nike Shox Rival Shoes Wholesaler  (www.iofferkicks.com)
Discount Nike Shox Energia Wholesaler  (www.iofferkicks.com)
Discount Nike Shox LV Sneaker  (www.iofferkicks.com)
Discount Nike Shox Turbo Suppliers  (www.iofferkicks.com)
Discount Nike Shox Classic Shoes Suppliers
(www.iofferkicks.com)
Discount Nike Shox Dendara Trainer  (www.iofferkicks.com)
Discount Nike Air Jordan 1 Seller  (www.iofferkicks.com)
Discount Nike Air Jordan 2 Shoes Seller  (www.iofferkicks.com)
Discount Nike Air Jordan 3 Collection  (www.iofferkicks.com)
Discount Nike Air Jordan 4 Shoes Collection
(www.iofferkicks.com)
Discount Nike Air Jordan 5 Chaussure Shoes
(www.iofferkicks.com)
Discount Nike Air Jordan 6 Catalog  (www.iofferkicks.com)
Discount Nike Air Jordan 7 Shoes Catalog  (www.iofferkicks.com)
Discount Nike Air Jordan 8 Customized  (www.iofferkicks.com)
Discount Nike Air Jordan 9 Shoes Customized
(www.iofferkicks.com)
Discount Nike Air Jordan 10 Wholesalers  (www.iofferkicks.com)
Discount Nike Jordan 11 Shoes Wholesalers (www.iofferkicks.com)
Discount Nike Air Jordan 12 Factory  (www.iofferkicks.com)
Discount Nike Air Jordan 13 Shoes Factory (www.iofferkicks.com)
Discount Nike Air Jordan 14 Shoes Sell  (www.iofferkicks.com)
Discount Nike Air Jordan 16 Exporter  (www.iofferkicks.com)
Discount Nike Air Jordan 17 Shoes Exporter
(www.iofferkicks.com)
Discount Nike Air Jordan 18 Offer  (www.iofferkicks.com)
Discount Nike Air Jordan 19 Shoes Offer  (www.iofferkicks.com)
Discount Nike Air Jordan 20 Manufacture  (www.iofferkicks.com)
Discount Nike Jordan 21 Shoes Manufacture  (www.iofferkicks.com)
EMAIL:iofferki...@gmail.com
MSN :iofferki...@msn.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Easy-to-use Python GUI

2008-12-24 Thread Raven
On 25 дек, 06:47, "Joel Koltner"  wrote:
> Is there an easy-to-use, "function"-based cross-platform GUI toolkit for
> Python out there that's a little more sophisticated than EasyGui?  EasyGui
> looks good, but it's a little more restrictive than what I'd like to have, yet
> I'm (stubbornly :-) ) resistant to stepping up to a "full service" GUI toolkit
> such as pyGTK or wxPython where it's all about event loops and callbacks and
> you need to start planning how the GUI affects the overall program flow rather
> than just using a "forms" (or "Wizard")-type approach where you put up a few
> dialogs, users fill in some variables, and your program just sits around
> waiting until "OK" or "Cancel" is clicked.
>
> One approach that I like comes from SAX BASIC/WinWrap, which is more or less a
> clone of Microsoft's Visual BASIC for Applications, but they (apparently)
> wanted everything to still be human-readable, so they have a simple GUI
> ("form") builder that generates code that looks like this:
>
> ---
>
>  Begin Dialog UserDialog 850,497,"Export Control" ' %GRID:10,7,1,1
>
>   GroupBox 20,7,360,217,"Drill File Generation",.GroupBox1
>   CheckBox 40,35,130,14,"Output drill file(s)",.genDrill
>   Text 40,63,270,28,"Identify via layers as any that contain this text in
> their names:",.Text
>   TextBox 40,98,220,21,.viaLayerName
>   Text 40,140,100,14,"Output method:",.Text8
>   DropListBox 160,140,180,21,DrillStyle(),.drillStyle
>   Text 40,175,130,28,"Select drill table units:",.Text2
>   ListBox 200,175,120,28,unitNames(),.unitName
>
>   OKButton 310,469,90,21
>   CancelButton 410,469,90,21
>
>  End Dialog
>
> ' GUI builder generates or modifies everything above, but can also be edited
> by hand
> ' You write the following code...
>
>  Dim dlg As UserDialog
>
>  dlg.genDrill = 1
>  ReDim DrillStyle(1)
>  DrillStyle(0) = "All Via Layers In One File"
>  DrillStyle(1) = "One File Per Via Layer"
>  dlg.drillStyle = 1
>
>  func=Dialog(dlg)
>
> ---
>
> This is pretty darned easy for me understand and modify either by hand or with
> the GUI builder.  Still, it's quite powerful, since it supports all the common
> GUI elements (text, group boxes, checkboxes, drop-down lists, text boxes,
> buttons, etc.).  This is about the level of sophistication I'm looking for.
>
> Anything like this for Python?
>
> Thanks,
> ---Joel

Try PyScripter :)
http://mmm-experts.com/Products.aspx?ProductId=4
--
http://mail.python.org/mailman/listinfo/python-list


  1   2   >