Re: include a file in a python program

2010-09-06 Thread Niklasro(.appspot)
On Sep 5, 10:57 pm, bussiere bussiere  wrote:
> i've got a python.txt that contain python and it must stay as it (python.txt)
>
> how can i include it in my program ?
> import python.txt doesn't work
> is there a way :
> a) to make an include("python.txt")
> b) tell him to treat .txt as .py file that i can make an import python ?
> i'am using python3
> Regards
> Bussiere
> fan of torchwood
> Google Fan boy

You can do it with tkinter to also enable GUI.
-- 
http://mail.python.org/mailman/listinfo/python-list


GUibuilder evaluation

2010-09-06 Thread Niklasro
Hello
Making a GUI, could you recommend tkinter or any other proposal?
Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: accessing a text file

2010-09-06 Thread Baba
On 6 sep, 00:01, Benjamin Kaplan  wrote:
> On Sun, Sep 5, 2010 at 5:47 PM, Baba  wrote:
> > level: beginner
>
> > how can i access the contents of a text file in Python?
>
> > i would like to compare a string (word) with the content of a text
> > file (word_list). i want to see if word is in word_list. let's assume
> > the TXT file is stored in the same directory as the PY file.
>
> > def is_valid_word(word, word_list)
>
> > thanks
> > Baba
> > --
> >http://mail.python.org/mailman/listinfo/python-list
>
> Please do us a favor and at least try to figure things out on your
> own, rather than coming here every time you have a question. The very
> first result when you try searching "python read text file" is the
> section in the Python tutorial that explains how to do this.
>
> http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-...


Hi Benjamin

I did find that page prior to posting the question but i still wanted
to have a second opinion to complement that info so as to make things
easier The first line of my post clearly states that i am a beginner.
It's nice to provide links which can help answer the question but
please be so polite and keep personal comments for yourself.


To all other respondants: thank you for your kind instructions and
directions.


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


Re: Subclassing by monkey-patching

2010-09-06 Thread Bruno Desthuilliers

Jason a écrit :

On Sep 5, 3:53 pm, Peter Otten <__pete...@web.de> wrote:

m = gio.File(".").monitor_directory()
C = type(m)


'C' will not necessarily be 'gio.FileMonitor' — I think the internals
of the GIO methods might further "subclass" it in some way depending
on what underlying monitors are available.


A possible alternative may be a class that wraps a FileMonitor instead of
subclassing it.


I've been avoiding this because it involves a lot of boilerplate: the
signals needs to be replicated and passed through, same for all
GObject properties, same for the usual methods.


Python is not Java !-)
http://docs.python.org/reference/datamodel.html#object.__getattr__


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


Re: accessing a text file

2010-09-06 Thread Baba
On 6 sep, 00:04, Seth Rees  wrote:
> On 09/05/10 16:47, Baba wrote:
>
> > level: beginner
>
> > how can i access the contents of a text file in Python?
>
> > i would like to compare a string (word) with the content of a text
> > file (word_list). i want to see if word is in word_list. let's assume
> > the TXT file is stored in the same directory as the PY file.
>
> > def is_valid_word(word, word_list)
>
> > thanks
> > Baba
>
>    f = open('text.txt')
>    data = f.read()
>    # You may want to convert it to a list
>    data = data.split()
>    # Returns true if word is in data, false otherwise
>    word in data

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


[RELEASED] Python 3.2 alpha 2

2010-09-06 Thread Georg Brandl
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On behalf of the Python development team, I'm happy to announce
the second alpha preview release of Python 3.2.

Python 3.2 is a continuation of the efforts to improve and stabilize the
Python 3.x line.  Since the final release of Python 2.7, the 2.x line
will only receive bugfixes, and new features are developed for 3.x only.

Since PEP 3003, the Moratorium on Language Changes, is in effect, there
are no changes in Python's syntax and built-in types in Python 3.2.
Development efforts concentrated on the standard library and support for
porting code to Python 3.  Highlights are:

* numerous improvements to the unittest module
* PEP 3147, support for .pyc repository directories
* PEP 3149, support for version tagged dynamic libraries
* an overhauled GIL implementation that reduces contention
* many consistency and behavior fixes for numeric operations
* countless fixes regarding string/unicode issues; among them full
  support for a bytes environment (filenames, environment variables)
* a sysconfig module to access configuration information
* a pure-Python implementation of the datetime module
* additions to the shutil module, among them archive file support
* improvements to pdb, the Python debugger

For an extensive list of changes in 3.2, see Misc/NEWS in the Python
distribution.

To download Python 3.2 visit:

 http://www.python.org/download/releases/3.2/

3.2 documentation can be found at:

 http://docs.python.org/3.2/

Please consider trying Python 3.2 with your code and reporting any bugs
you may notice to:

 http://bugs.python.org/


Enjoy!

- --
Georg Brandl, Release Manager
georg at python.org
(on behalf of the entire python-dev team and 3.2's contributors)
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.16 (GNU/Linux)

iEYEARECAAYFAkyEpLkACgkQN9GcIYhpnLCzSwCdFyPz1dPEehJZmeW8wDltqkqe
/ogAnim1J99qDpeLmcUDTf0YBh1W95vf
=x+ee
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.7 module path problems on OS X

2010-09-06 Thread Nicholas Cole
On Sun, Sep 5, 2010 at 8:57 PM, Ned Deily  wrote:
> In article
> ,
>  Nicholas Cole  wrote:
>
>> On Sun, Sep 5, 2010 at 10:20 AM, Ned Deily  wrote:
>> > I'm not sure why you think it is broken.  The Apple 2.6 and the
>> > python.org 2.7 have different site-package directories in different
>> > locations.  That is to be expected.  The Apple-supplied Python comes
>> > with some additional packages pre-installed, like setuptools, PyObjC,
>> > and wx.  But you would need to install new versions of these for 2.7
>> > anyway.
>> >
>> Sorry. I wasn't clear.  Of course I understand that each version of
>> python needs its own additional packages, and I was expecting to
>> re-install them.  But I don't want to install system-wide --  I'd like
>> to have my own, user-specific, site-packages.  On previous versions of
>> python, I've  installed into
>> ~/Library/Python/$py_version_short/site-packages under my home
>> directory.
>>
>> In my recollection, this has worked in the past for python installed
>> from python.org, but perhaps that recollection is wrong.  At any rate,
>> it doesn't  work with python 2.7.
>
> Ah, my apologies.  I overlooked the "~/Library" part.  So what you have
> been using is the setuptools Mac OS X "User" Installation configuration:
> (http://peak.telecommunity.com/DevCenter/EasyInstall#mac-os-x-user-instal
> lation).   Yes, it seems an incompatibility has been introduced in 2.7
> for OS X.  There has been an on-going and as yet unresolved discussion
> on the python-dev list about the topic of user directory and config file
> locations so things will likely change and get more consistent in the
> future.  But this particular problem is more immediate.  I believe the
> problem here is that the default user directory path was changed between
> 2.6 and 2.7 from:
>
>    ~/Library/Python/m.n/site-packages
>
> to
>
>    ~/Library/Python/m.n/lib/python/site-packages
>
> I will track that down further and open an issue for it, if necessary.
> In the meantime, here's a little snippet that I think should work around
> the problem for the moment without requiring a change to your
> configuration files.  (For simplicity of installation, it uses the
> Distribute fork of setuptools).  The main point is to create a symlink
> between the old and new locations. Let me know if this works for you:

Dear Ned,

Thank you very much for your help and for the code snippet.  I don't
know enough about the background to open an issue myself, so I am
grateful that you might take this on.  Just to throw in my $0.02, I do
think is important to be able to have a distutils configuration that
works across versions (since so many of us have several versions
installed for testing purposes), and so I do view this incompatibility
is a bug!

But thank you very much for solving my immediate problem.

Best wishes,

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


Re: GUibuilder evaluation

2010-09-06 Thread wissem belguidoum
On 6 sep, 09:54, Niklasro  wrote:
> Hello
> Making a GUI, could you recommend tkinter or any other proposal?
> Thanks

Hi,

I am considering to learn Qt, which is a multi-platform widget
liberary and a RAD IDE...,
basically for C++ programing but there is a binding called PyQt for
python.

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


Re: MAKE UPTO $5000 P/M $2000 IN FIRST 30 DAYS! NO INV

2010-09-06 Thread wissem belguidoum
On 6 sep, 06:26, jameser  wrote:
> MAKE UPTO $5000 P/M $2000 IN FIRST 30 DAYS! NO INV
>
> Generate $50 to $100 whenever you
> have a couple of hours free time to spare.
> You could make $50 or more in the next 2 hours.
> Starting right Now!Today!
>
> GET PAID TO:
> Take online surveys and make from $5 to $75, or more
> Participate in focus groups and make up to $150 an hour
> Take phone surveys and you can earn as much as $120 an hour
> Try new products (and keep the free products too)
> Preview new movie trailers for $4 to $25 an hour
>
> http://snipurl.com/11i6lw
>
> Earn from your free website
> Awesome earnings get paid for your honest work
> Join as a free member and get paid to your bank account
> To join the Network follow the link
>
> http://snipurl.com/11i6lw
>
> Get paid for your real work and earn awesome 

Is this a kind of trap to make an email database ?

Reminder : this is a python programming language group.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Speed-up for loops

2010-09-06 Thread BartC
"Stefan Behnel"  wrote in message 
news:mailman.470.1283712666.29448.python-l...@python.org...

BartC, 05.09.2010 19:09:



All those compilers that offer loop unrolling are therefore wasting
their time...


Sometimes they do, yes.


Modifying the OP's code a little:

a = 0
for i in xrange(1):  # 100 million
a = a + 10  # add 10 or 100
print a

Manually unrolling such a loop four times (ie. 4 copies of the body, and 
counting only to 25 million) increased the speed by between 16% and 47% (ie. 
runtime reducing by between 14% and 32%).


This depended on whether I added +10 or +100 (ie. whether long integers are 
needed), whether it was inside or outside a function, and whether I was 
running Python 2 or 3 (BTW why doesn't Python 3 just accept 'xrange' as a 
synonym for 'range'?)


These are just some simple tests on my particular machine and 
implementations, but they bring up some points:


(1) Loop unrolling does seem to have a benefit, when the loop body is small.

(2) Integer arithmetic seems to go straight from 32-bits to long integers; 
why not use 64-bits before needing long integers?


(3) Since the loop variable is never used, why not have a special loop 
statement that repeats code so many times? This can be very fast, since the 
loop counter need not be a Python object, and probably there would be no 
need for unrolling at all:


repeat 1:# for example
   a = a + 10

--
Bartc 


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


Re: Subclassing by monkey-patching

2010-09-06 Thread Glazner
On Sep 6, 11:08 am, Bruno Desthuilliers  wrote:
> Jason a écrit :
>
> > On Sep 5, 3:53 pm, Peter Otten <__pete...@web.de> wrote:
> > m = gio.File(".").monitor_directory()
> > C = type(m)
>
> > 'C' will not necessarily be 'gio.FileMonitor' — I think the internals
> > of the GIO methods might further "subclass" it in some way depending
> > on what underlying monitors are available.
>
> >> A possible alternative may be a class that wraps a FileMonitor instead of
> >> subclassing it.
>
> > I've been avoiding this because it involves a lot of boilerplate: the
> > signals needs to be replicated and passed through, same for all
> > GObject properties, same for the usual methods.
>
> Python is not Java 
> !-)http://docs.python.org/reference/datamodel.html#object.__getattr__

Yep, thats what i do...

def MySubclass(object):
  def __init__(self):
self._ins = SomeObject()
  def __getattr__(self,name):
return getattr(self._ins,name)
-- 
http://mail.python.org/mailman/listinfo/python-list


Embedded Systems development using Python

2010-09-06 Thread VGNU Linux
Hi List,
Can Python be used for embedded systems development ?
If Yes can anyone point me to a tutorial/reference website which explains
about this.

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


Re: Speed-up for loops

2010-09-06 Thread Stefan Behnel

BartC, 06.09.2010 12:38:

why doesn't Python 3 just accept 'xrange' as a synonym for 'range'?


Because Python 3 deliberately breaks backwards compatibility in order to 
clean up the language.




These are just some simple tests on my particular machine and
implementations, but they bring up some points:

(1) Loop unrolling does seem to have a benefit, when the loop body is
small.


Nobody said otherwise. However, "small" is a pretty weak characterisation 
here. And don't expect CPython to do it for you, because doing it 
automatically requires the ability to see that there are no side effects. 
It's a lot more costly to assure that than what you actually gain with the 
optimisation. As your example shows, doing this optimisation manually is 
pretty straight forward, so there isn't really a need to let the runtime do 
it for you.




(2) Integer arithmetic seems to go straight from 32-bits to long
integers; why not use 64-bits before needing long integers?


You are making assumptions based on Python 2, I guess. Try Python 3.1 or 
later instead, where the int and long types are unified. Also, the 
implementation is a bit more complex than you appear to be thinking. Don't 
forget that it has received serious benchmarking based optimisations.




(3) Since the loop variable is never used, why not have a special loop
statement that repeats code so many times?


Because special cases are not special enough to break the rules. As others 
have stated before, you can use itertools to reduce that part of the 
looping overhead, if it really hurts your concrete code. There also were 
lots of examples in this thread on different looping solutions and their 
performance differences. Any of them may fit your needs in a given situation.




This can be very fast, since
the loop counter need not be a Python object


It still has to count, though.

Stefan

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


Re: Embedded Systems development using Python

2010-09-06 Thread Stefan Behnel

VGNU Linux, 06.09.2010 13:02:

Can Python be used for embedded systems development ?


It can and has been.

What kind of embedded system with what set of capabilities are you thinking 
about? TV sets? Mobile phones? Smart dust?


Stefan

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


Re: Speed-up for loops

2010-09-06 Thread Kushal Kumaran
On Mon, Sep 6, 2010 at 4:08 PM, BartC  wrote:
> "Stefan Behnel"  wrote in message
> news:mailman.470.1283712666.29448.python-l...@python.org...
>>
>> BartC, 05.09.2010 19:09:
>
>>> All those compilers that offer loop unrolling are therefore wasting
>>> their time...
>>
>> Sometimes they do, yes.
>
> Modifying the OP's code a little:
>
> a = 0
> for i in xrange(1):      # 100 million
>    a = a + 10                  # add 10 or 100
> print a
>
> Manually unrolling such a loop four times (ie. 4 copies of the body, and
> counting only to 25 million) increased the speed by between 16% and 47% (ie.
> runtime reducing by between 14% and 32%).
>
> This depended on whether I added +10 or +100 (ie. whether long integers are
> needed), whether it was inside or outside a function, and whether I was
> running Python 2 or 3 (BTW why doesn't Python 3 just accept 'xrange' as a
> synonym for 'range'?)
>
> These are just some simple tests on my particular machine and
> implementations, but they bring up some points:
>
> (1) Loop unrolling does seem to have a benefit, when the loop body is small.
>
> (2) Integer arithmetic seems to go straight from 32-bits to long integers;
> why not use 64-bits before needing long integers?
>

On 64-bit systems, integer arithmetic will go from 64-bit native
integers to long.  Will using any emulated 64-bit type on a 32-bit
system actually be better than the python long implementation?

From my 64-bit linux system:

In [1]: n = 2 ** 40

In [2]: type(n)
Out[2]: 

In [3]: n = 2 ** 80

In [4]: type(n)
Out[4]: 


> (3) Since the loop variable is never used, why not have a special loop
> statement that repeats code so many times? This can be very fast, since the
> loop counter need not be a Python object, and probably there would be no
> need for unrolling at all:
>
> repeat 1:        # for example
>   a = a + 10
>

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


Re: Embedded Systems development using Python

2010-09-06 Thread VGNU Linux
Hi,

A small device like a mobile but with only 2 major buttons, with GPS and
GPRS capabilities.
Can anyone tell me from where to start learning about this ?

Regards
Vivek


On Mon, Sep 6, 2010 at 4:52 PM, Stefan Behnel  wrote:

> VGNU Linux, 06.09.2010 13:02:
>
>  Can Python be used for embedded systems development ?
>>
>
> It can and has been.
>
> What kind of embedded system with what set of capabilities are you thinking
> about? TV sets? Mobile phones? Smart dust?
>
> Stefan
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Speed-up for loops

2010-09-06 Thread Antoine Pitrou
On Mon, 06 Sep 2010 13:20:01 +0200
Stefan Behnel  wrote:
> 
> > (2) Integer arithmetic seems to go straight from 32-bits to long
> > integers; why not use 64-bits before needing long integers?
> 
> You are making assumptions based on Python 2, I guess. Try Python 3.1 or 
> later instead, where the int and long types are unified. Also, the 
> implementation is a bit more complex than you appear to be thinking. Don't 
> forget that it has received serious benchmarking based optimisations.

The optimizations are mainly related to big integer arithmetics,
though. For small ints the main cost is interpretation and
unboxing overhead as always.

Regards

Antoine.


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


ctypes and garbage collection

2010-09-06 Thread Joakim Hove
Hello,

I have used ctypes to wrap a C-library - it has been a really painless
experience!

The C-library instantiates a quite large "container-like" structure.
There are then several functions to inspect the content of the
container, get at items and free the whole thing:

/* C - code */
c_container_type * c_container_alloc( const char * filename );
c_node_type   * c_container_get_node( c_container_type *
container , const char * node_id );
void  c_container_free( c_container_type *
container );


Observe that the c_container_get_node() function does _not_ allocate
memory, it just returns a opaque handle to a node structure, still
fully owned by the container structure. I have wrapped this with
Python/ctypes roughly like this (severly trimmed pseudo code):

class Container:
 def __init__(self , filename):
  self.c_ptr = c_container_alloc( filename )

def __del__( self ):
 c_container_free( self.c_ptr )

def get_node( self , node_id):
 Node( c_container_get_node( self , node_id ))


class Node:
 def __init__( self , c_ptr ):
  self.c_ptr = c_ptr

 def __del__( self ):
  pass


Now, a use scenario might be like this:

1. Instantiate a Container() instance.
2. Instantiate a Node() instance with the Container.get_node()
function.
3. Forget about the Container instance and work happily with the Node
instance.
4. Out of the blue comes the gc - and then? Will the Node instance be
enough to protect the Container instance from beeing garbage
collected?

I thought maybe the get_node() function should have something like a
incref() call, and the Node.__del__() function a corresponding
decref()? Or ??


Regards

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


Re: Speed-up for loops

2010-09-06 Thread BartC
"Stefan Behnel"  wrote in message 
news:mailman.485.1283772019.29448.python-l...@python.org...

BartC, 06.09.2010 12:38:



(2) Integer arithmetic seems to go straight from 32-bits to long
integers; why not use 64-bits before needing long integers?


You are making assumptions based on Python 2, I guess. Try Python 3.1 or 
later instead, where the int and long types are unified. Also, the 
implementation is a bit more complex than you appear to be thinking. Don't 
forget that it has received serious benchmarking based optimisations.


That's true; wider arithmetic was less of an overhead in Python 3.

This shows the effect of making several small optimisations which might 
otherwise be dismissed: with the +100 test, the Python 3 faster wider 
arithmetic, *plus* the 4x loop unrolling, resulted in an 85% speed increase 
compared with Python 2 using the original loop. Which is pretty good 
considering Python 3 is generally slower than '2'.



This can be very fast, since
the loop counter need not be a Python object


It still has to count, though.


That might be just a couple of machine instructions. Plus the bytecode 
overhead.


--
Bartc 


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


Re: Embedded Systems development using Python

2010-09-06 Thread Peter Fodrek
On Monday 06 September 2010 13:02:56 VGNU Linux wrote:
> Hi List,
> Can Python be used for embedded systems development ?

It is hard to say yes or no. For hard Real-time systems or hard Real-time 
parts of complex system answer is no, in another type of embedded systems yes 
or maybe

> If Yes can anyone point me to a tutorial/reference website which explains
> about this.

There are no tutorials to do so as I know.


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


Re: ctypes and garbage collection

2010-09-06 Thread Ulrich Eckhardt
Joakim Hove wrote:
> I have used ctypes to wrap a C-library
> [...] 
> Observe that the c_container_get_node() function does _not_ allocate
> memory, it just returns a opaque handle to a node structure, still
> fully owned by the container structure.
[...]
> 
> class Container:
>  def __init__(self , filename):
>   self.c_ptr = c_container_alloc( filename )
> 
> def __del__( self ):
>  c_container_free( self.c_ptr )
> 
> def get_node( self , node_id):
>  Node( c_container_get_node( self , node_id ))
> 
> 
> class Node:
>  def __init__( self , c_ptr ):
>   self.c_ptr = c_ptr
> 
>  def __del__( self ):
>   pass
> 
> 
> Now, a use scenario might be like this:
> 
> 1. Instantiate a Container() instance.
> 2. Instantiate a Node() instance with the Container.get_node()
> function.
> 3. Forget about the Container instance and work happily with the Node
> instance.
> 4. Out of the blue comes the gc - and then? Will the Node instance be
> enough to protect the Container instance from beeing garbage
> collected?

No. You should be able to even see that by logging calls to alloc/free of
your library.

> I thought maybe the get_node() function should have something like a
> incref() call, and the Node.__del__() function a corresponding
> decref()? Or ??

I'd add an "__owner" field to the node, initialised with the owning
container instance.

Uli

-- 
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

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


Re: ctypes and garbage collection

2010-09-06 Thread Joakim Hove
> I'd add an "__owner" field to the node, initialised with the owning
> container instance.

I will - thank you!

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


Re: Embedded Systems development using Python

2010-09-06 Thread Antoine Pitrou
On Mon, 6 Sep 2010 17:22:09 +0530
VGNU Linux  wrote:
> Hi,
> 
> A small device like a mobile but with only 2 major buttons, with GPS and
> GPRS capabilities.
> Can anyone tell me from where to start learning about this ?

Read the official docs for the C API:
http://docs.python.org/extending/embedding.html
http://docs.python.org/extending/index.html
http://docs.python.org/c-api/

You'll probably need at least a 32-bit CPU and some non-negligible
amount of RAM. If not, then you'll want to take a look at alternatve
implementations of Python:
http://wiki.python.org/moin/EmbeddedPython

Regards

Antoine.


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


Re: GUibuilder evaluation

2010-09-06 Thread Denis Gomes
Hello,

   There are really three you can choose from if you are serious about
making GUI applications.  PyQt as already suggested.  wxPython and pyGTK.
 Tkinter is good in my opinion if you are making smaller gui based programs.
 PyQt has an extensive number of additional features, including networking,
OpenGL, Multimedia, Database etc.  It is used for the KDE desktop
environment.   PyQt has a very powerful Designer which you can used to
generate python code very fast for complex guis.  wxPython is only GUI
centric, but it does have a host of widgets you can play with and pre-made
examples you can use to speed up your programming.  It also has a gui
building called Boa Constructor which is functional but not in the same
class as the qt designer (this is my opinion, try it).  As for pyGTK, it is
used for Gnome.  I am not to familiar with it but it looks like a good gui
toolkit as well.  So my advice is to try all three and see which one you
like the best and go from there.

Denis

On Mon, Sep 6, 2010 at 6:15 AM, wissem belguidoum wrote:

> On 6 sep, 09:54, Niklasro  wrote:
> > Hello
> > Making a GUI, could you recommend tkinter or any other proposal?
> > Thanks
>
> Hi,
>
> I am considering to learn Qt, which is a multi-platform widget
> liberary and a RAD IDE...,
> basically for C++ programing but there is a binding called PyQt for
> python.
>
> Good luck.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python [repair_cycorder_mov.py]

2010-09-06 Thread ctops.legal
On Sep 5, 12:23 pm, Albert Hopkins  wrote:
> On Sun, 2010-09-05 at 14:00 +, Steven D'Aprano wrote:
> > By the way, there's no need to send three messages in 10 minutes
> > asking
> > the same question, and adding FORM METHOD links to your post will
> > probably just get it flagged as spam by many people.
>
> Apparently it has, as I only got this response.

Yea I guess I need to get my Forte Agent out and dust it off.
-- 
http://mail.python.org/mailman/listinfo/python-list


redirecting stdout and stderr for a windows service

2010-09-06 Thread Ian Hobson

Hi all,

I am trying to redirect stdout and stderr on a python  windows service, 
so that the service will not stall after 256 chars is written, and so I 
can use print for simple debugging.


I have the following 4 lines (copy/pasted) in the source of my code.

if __name__ == '__main__':
sys.stdout = sys.stderr = open("d:\logfile.txt", "a")
print "Starting up"
win32serviceutil.HandleCommandLine(PythonService)

When I run them as a free standing program, logfile.txt is created
the text placed in it, and it crashed on the last line - no permissions 
to create a service. (Micro-cluless has no sudo command in Win7. :( )


When I start the code as a service, it does not create the log file
does not put anything in it, but the last line is executed and the 
service starts! There are no Events on the event log.


When I stop the service, it stops. Still no log file. Still no events.

I tried running the service with my account and not the system user. 
This gave me "run as service" permissions, but did not alter the results.


What is happening?

And how can I set up logging so that the service can simply restart, 
leaving the trackback in the log file for me to come to later.


All help gratefully received. I've lost most of my remaining hair today 
on this one.


Ian







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


list of tuples with dynamic change in position

2010-09-06 Thread sajuptpm
I have a list of tuples l = [(('s','a'),(5,9)), (('u','w'),(9,2)),
(('y','x'),(3,0))]
some functions using this list and fetch data using index l[0][1], l[1]
[1]
I need to change position of each values in the list and that dont
affect fuctions which are using this list.
I must have to use list of tuples.
Have any way to do it using list of tuples.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: accessing a text file

2010-09-06 Thread Thomas Jollans
On Monday 06 September 2010, it occurred to Baba to exclaim:
> On 6 sep, 00:01, Benjamin Kaplan  wrote:
> > On Sun, Sep 5, 2010 at 5:47 PM, Baba  wrote:
> > > level: beginner
> > > 
> > > how can i access the contents of a text file in Python?
> > > 
> > > i would like to compare a string (word) with the content of a text
> > > file (word_list). i want to see if word is in word_list. let's assume
> > > the TXT file is stored in the same directory as the PY file.
> > > 
> > > def is_valid_word(word, word_list)
> > > 
> > > thanks
> > > Baba
> > > --
> > >
> > >http://mail.python.org/mailman/listinfo/python-list
> > 
> > Please do us a favor and at least try to figure things out on your
> > own, rather than coming here every time you have a question. The very
> > first result when you try searching "python read text file" is the
> > section in the Python tutorial that explains how to do this.
> > 
> > http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-...
> 
> Hi Benjamin
> 
> I did find that page prior to posting the question but i still wanted
> to have a second opinion to complement that info so as to make things
> easier The first line of my post clearly states that i am a beginner.
> It's nice to provide links which can help answer the question but
> please be so polite and keep personal comments for yourself.
> 

That is of course perfectly legitimate. It would however have been polite to 
state that in the question. Show us that you're doing your homework, and not 
just using the list as a cheap path to having to think less yourself. 

Phrasing your post as "I would like to compare a ... I found the open() 
function here: [link]. Is this what I should use of is there any other/better 
way?" makes a completely different impression.

Also, keeping personal comments to one's self is just not how it works. On a 
list like this especially, answers along the lines of "That's the way to do 
what you were asking for, but are you sure the question went into the right 
direction? Have you thought of [...]?" can often be very helpful.

> 
> To all other respondants: thank you for your kind instructions and
> directions.
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: list of tuples with dynamic change in position

2010-09-06 Thread sajuptpm
I have a list of tuples l = [(('s','a'),(5,9)), (('u','w'),(9,2)),
(('y','x'),(3,0))] and postion of values in the tuple change
dynamicaly. I need a way to access correct value even if change in
position.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: list of tuples with dynamic change in position

2010-09-06 Thread Ulrich Eckhardt
sajuptpm wrote:
> I need to change position of each values in the list and that dont
> affect fuctions which are using this list.

So you want to change the list's content but you don't want anyone to be
able to detect the difference? That doesn't make sense.

> I must have to use list of tuples.
> Have any way to do it using list of tuples.

Why don't you explain what you want to achieve instead of asking for a
solution that doesn't make sense?

Uli

-- 
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

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


Re: redirecting stdout and stderr for a windows service

2010-09-06 Thread Ulrich Eckhardt
Ian Hobson wrote:
>  sys.stdout = sys.stderr = open("d:\logfile.txt", "a")

"\l" is probably not what you want. Consider using "\\l" or r"\l" instead.

Uli

-- 
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

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


Re: Embedded Systems development using Python

2010-09-06 Thread Grant Edwards
On 2010-09-06, Stefan Behnel  wrote:
> VGNU Linux, 06.09.2010 13:02:
>> Can Python be used for embedded systems development ?
>
> It can and has been.
>
> What kind of embedded system with what set of capabilities are you thinking 
> about? TV sets? Mobile phones? Smart dust?

[The OP never showed up on my sever for some reason]

If you google for "deeply embedded python", you'll find some raterh
old links:

  http://tucs.fi/magazin/output.php?ID=2000.N2.LilDeEmPy
  
http://groups.google.com/group/python-on-a-chip/web/list-of-small-python-implementations
  http://mail.python.org/pipermail/python-announce-list/1999-August/000157.html

A few years ago I used Python on a prototype for a bicycle computer
with GPS, four buttons, and a small LCD screen.  It was more or less
comparable to a PDA with Linux running on an 200MHz XScale with
something like 16MB of flash and 32MB of SDRAM.

IIRC, that project used OpenEmbedded, and all I had to do was build
the Python package that's already there in OE.  I don't remember if I
was using PySDL or PyQt for the UI -- I remember experimenting with
both on desktop hosts at the time.

I don't think that product ever saw daylight.  There was just now way
they could have competed with Garmin.

-- 
Grant

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


Re: list of tuples with dynamic change in position

2010-09-06 Thread Gerard Flanagan

sajuptpm wrote:

I have a list of tuples l = [(('s','a'),(5,9)), (('u','w'),(9,2)),
(('y','x'),(3,0))] and postion of values in the tuple change
dynamicaly. I need a way to access correct value even if change in
position.


from itertools import starmap, izip, imap
list(imap(dict, starmap(izip, d)))
[{'a': 9, 's': 5}, {'u': 9, 'w': 2}]

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


Arguments from the command line

2010-09-06 Thread aug dawg
I've seen Python programs that can be activated from the command line. For
example:

hg

This displays a list of commands for the Mercurial revision control system.
But another command is this:

hg commit "This is a commit name"

Mercurial is written in Python. I know that commit is a function that
commits to a repo, but what command does the program use in order to get the
commit name, like "This is a commit name" (This would make a commit with
"This is a commit name" as the commit name)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: accessing a text file

2010-09-06 Thread Baba
On 6 sep, 16:58, Thomas Jollans  wrote:
> On Monday 06 September 2010, it occurred to Baba to exclaim:
>
>
>
> > On 6 sep, 00:01, Benjamin Kaplan  wrote:
> > > On Sun, Sep 5, 2010 at 5:47 PM, Baba  wrote:
> > > > level: beginner
>
> > > > how can i access the contents of a text file in Python?
>
> > > > i would like to compare a string (word) with the content of a text
> > > > file (word_list). i want to see if word is in word_list. let's assume
> > > > the TXT file is stored in the same directory as the PY file.
>
> > > > def is_valid_word(word, word_list)
>
> > > > thanks
> > > > Baba
> > > > --
>
> > > >http://mail.python.org/mailman/listinfo/python-list
>
> > > Please do us a favor and at least try to figure things out on your
> > > own, rather than coming here every time you have a question. The very
> > > first result when you try searching "python read text file" is the
> > > section in the Python tutorial that explains how to do this.
>
> > >http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-...
>
> > Hi Benjamin
>
> > I did find that page prior to posting the question but i still wanted
> > to have a second opinion to complement that info so as to make things
> > easier The first line of my post clearly states that i am a beginner.
> > It's nice to provide links which can help answer the question but
> > please be so polite and keep personal comments for yourself.
>
> That is of course perfectly legitimate. It would however have been polite to
> state that in the question. Show us that you're doing your homework, and not
> just using the list as a cheap path to having to think less yourself.
>
> Phrasing your post as "I would like to compare a ... I found the open()
> function here: [link]. Is this what I should use of is there any other/better
> way?" makes a completely different impression.
>
> Also, keeping personal comments to one's self is just not how it works. On a
> list like this especially, answers along the lines of "That's the way to do
> what you were asking for, but are you sure the question went into the right
> direction? Have you thought of [...]?" can often be very helpful.
>
>
>
> > To all other respondants: thank you for your kind instructions and
> > directions.
>
>

Thanks Thomas. Look up some of my questions  this group and read
through them and come back to tell me if a) i use this forum to learn
without making any efforts myself or b) i use this forum to get
started using the expertise of more knowledgeable programmers while at
the same time particiapting. Anyway having this discussion is beside
the point. Any Expert out there who thinks we beginners are some dumb
idiots who are too stupid to think for themselves and are lucky to
have a bunch of geniuses like you to help, get lost or make yourself a
cup of tea but please give me a break from teaching me lessons...

There's lots of nice people out there who are being awsemome by
dedicating a bit of their time to some of our easy questions and it is
them that i wish to send a BIG thanks! Much appreciated. I have made
some good progress since starting to learn Python and this group has
been great help!

tnx
Raoul

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


Re: Arguments from the command line

2010-09-06 Thread Mark Lawrence

On 06/09/2010 16:48, aug dawg wrote:

I've seen Python programs that can be activated from the command line. For
example:

hg

This displays a list of commands for the Mercurial revision control system.
But another command is this:

hg commit "This is a commit name"

Mercurial is written in Python. I know that commit is a function that
commits to a repo, but what command does the program use in order to get the
commit name, like "This is a commit name" (This would make a commit with
"This is a commit name" as the commit name)




See sys.argv at http://docs.python.org/library/sys.html

Cheers.

Mark Lawrence.

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


Re: [Tutor] Arguments from the command line

2010-09-06 Thread Hugo Arts
On Mon, Sep 6, 2010 at 5:48 PM, aug dawg  wrote:
> I've seen Python programs that can be activated from the command line. For
> example:
> hg
>
> This displays a list of commands for the Mercurial revision control system.
> But another command is this:
> hg commit "This is a commit name"
> Mercurial is written in Python. I know that commit is a function that
> commits to a repo, but what command does the program use in order to get the
> commit name, like "This is a commit name" (This would make a commit with
> "This is a commit name" as the commit name)
>

sys.argv is a list of all arguments from the command line. However,
you'll rarely deal with it directly, there's various modules that deal
with handling arguments. I believe the current one is argparse:
http://docs.python.org/library/argparse.html#module-argparse

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


Re: accessing a text file

2010-09-06 Thread geremy condra
On Mon, Sep 6, 2010 at 8:53 AM, Baba  wrote:
> On 6 sep, 16:58, Thomas Jollans  wrote:
>> On Monday 06 September 2010, it occurred to Baba to exclaim:
>>
>>
>>
>> > On 6 sep, 00:01, Benjamin Kaplan  wrote:
>> > > On Sun, Sep 5, 2010 at 5:47 PM, Baba  wrote:
>> > > > level: beginner
>>
>> > > > how can i access the contents of a text file in Python?
>>
>> > > > i would like to compare a string (word) with the content of a text
>> > > > file (word_list). i want to see if word is in word_list. let's assume
>> > > > the TXT file is stored in the same directory as the PY file.
>>
>> > > > def is_valid_word(word, word_list)
>>
>> > > > thanks
>> > > > Baba
>> > > > --
>>
>> > > >http://mail.python.org/mailman/listinfo/python-list
>>
>> > > Please do us a favor and at least try to figure things out on your
>> > > own, rather than coming here every time you have a question. The very
>> > > first result when you try searching "python read text file" is the
>> > > section in the Python tutorial that explains how to do this.
>>
>> > >http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-...
>>
>> > Hi Benjamin
>>
>> > I did find that page prior to posting the question but i still wanted
>> > to have a second opinion to complement that info so as to make things
>> > easier The first line of my post clearly states that i am a beginner.
>> > It's nice to provide links which can help answer the question but
>> > please be so polite and keep personal comments for yourself.
>>
>> That is of course perfectly legitimate. It would however have been polite to
>> state that in the question. Show us that you're doing your homework, and not
>> just using the list as a cheap path to having to think less yourself.
>>
>> Phrasing your post as "I would like to compare a ... I found the open()
>> function here: [link]. Is this what I should use of is there any other/better
>> way?" makes a completely different impression.
>>
>> Also, keeping personal comments to one's self is just not how it works. On a
>> list like this especially, answers along the lines of "That's the way to do
>> what you were asking for, but are you sure the question went into the right
>> direction? Have you thought of [...]?" can often be very helpful.
>>
>>
>>
>> > To all other respondants: thank you for your kind instructions and
>> > directions.
>>
>>
>
> Thanks Thomas. Look up some of my questions  this group and read
> through them and come back to tell me if a) i use this forum to learn
> without making any efforts myself

Just a quick point- when you ask someone for help, it's considered
impolite to tell them what to do.

I'd also point out that you gave no indication that you'd worked on
this at all before posting it. In that regard, Thomas's concern seems
completely justified to me.

> or b) i use this forum to get
> started using the expertise of more knowledgeable programmers while at
> the same time particiapting.

Again, Thomas's concern seems justified to me. Things would probably
go more smoothly if you gave a better indication of what you had done
so far on the problem in the future.

> Anyway having this discussion is beside
> the point. Any Expert out there who thinks we beginners are some dumb
> idiots who are too stupid to think for themselves and are lucky to
> have a bunch of geniuses like you to help, get lost or make yourself a
> cup of tea but please give me a break from teaching me lessons...

I don't think all beginners are idiots, or even most of them- but this
isn't the right attitude to be taking. Both Thomas and myself thought
that this was inappropriate enough to mention it, and if two people
spoke up you can bet a lot more were thinking it quietly. My
suggestion would be to moderate your approach and demonstrate what
you've done so far (if only to increase the signal-to-noise ratio as
your problems become more challenging) when posting. I'd also refrain
from telling people to get lost; it doesn't make people happy to help
you, you know?

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


Re: Iterative vs. Recursive coding

2010-09-06 Thread Aahz
In article <4c6e9de9$0$23142$426a7...@news.free.fr>,
Bruno Desthuilliers   wrote:
>Steven D'Aprano a écrit :
>> On Thu, 19 Aug 2010 22:00:16 +, Martin Gregorie wrote:
>>> 
>>> Recursion can be quite a trick to get your mind round at first
>> 
>> Really? Do people actually find the *concept* of recursion to be tricky?
>
>I onced worked in a shop (Win32 desktop / accouting applications mainly) 
>where I was the only guy that could actually understand recursion. FWIW, 
>I also was the only guy around that understood "hairy" (lol) concepts 
>like callback functions, FSM, polymorphism, hashtables, linked lists, 
>ADTs, algorithm complexity etc...

To some extent, the question here is the definition of "understand" being
used.  It probably would be reasonable to say that I have only a cookbook
level understanding of recursion, and the same would apply to callback
functions, FSM, linked lists, and so on.  (I mostly think I do really
understand polymorphism and hashtables.)
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"...if I were on life-support, I'd rather have it run by a Gameboy than a
Windows box."  --Cliff Wells
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Iterative vs. Recursive coding

2010-09-06 Thread Aahz
In article <4c70344a$0$1659$742ec...@news.sonic.net>,
John Nagle   wrote:
>
>Realistically, recursion isn't that important in Python.  It's
>there if you need it, and sometimes useful, but generally not used
>much without good reason.  In some functional languages, recursion
>is routinely used in place of iteration, but Python isn't built for
>that.  In Python, most of the use cases for trivial recursion
>are better handled with iteration or generators.

Depends how you define "important".  It's certainly a critical feature
for Python that you *can* use recursion; it's usually the simplest way of
walking a tree structure (such as a directory tree).  Python would be an
extraordinarily limited language if recursion were not available.
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"...if I were on life-support, I'd rather have it run by a Gameboy than a
Windows box."  --Cliff Wells
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Tutor] Arguments from the command line

2010-09-06 Thread bob gailer

 On 9/6/2010 11:48 AM, aug dawg wrote:
I've seen Python programs that can be activated from the command line. 
For example:


hg

This displays a list of commands for the Mercurial revision control 
system. But another command is this:


hg commit "This is a commit name"

Mercurial is written in Python. I know that commit is a function that 
commits to a repo, but what command does the program use in order to 
get the commit name, like "This is a commit name" (This would make a 
commit with "This is a commit name" as the commit name)

hg.py:
import sys
print sys.argv

$hg commit "This is a commit name"
['C:\\hg.py', 'commit', 'This is a commit name']

--
Bob Gailer
919-636-4239
Chapel Hill NC

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


Re: accessing a text file

2010-09-06 Thread Baba
On 6 sep, 18:14, geremy condra  wrote:
> On Mon, Sep 6, 2010 at 8:53 AM, Baba  wrote:
> > On 6 sep, 16:58, Thomas Jollans  wrote:
> >> On Monday 06 September 2010, it occurred to Baba to exclaim:
>
> >> > On 6 sep, 00:01, Benjamin Kaplan  wrote:
> >> > > On Sun, Sep 5, 2010 at 5:47 PM, Baba  wrote:
> >> > > > level: beginner
>
> >> > > > how can i access the contents of a text file in Python?
>
> >> > > > i would like to compare a string (word) with the content of a text
> >> > > > file (word_list). i want to see if word is in word_list. let's assume
> >> > > > the TXT file is stored in the same directory as the PY file.
>
> >> > > > def is_valid_word(word, word_list)
>
> >> > > > thanks
> >> > > > Baba
> >> > > > --
>
> >> > > >http://mail.python.org/mailman/listinfo/python-list
>
> >> > > Please do us a favor and at least try to figure things out on your
> >> > > own, rather than coming here every time you have a question. The very
> >> > > first result when you try searching "python read text file" is the
> >> > > section in the Python tutorial that explains how to do this.
>
> >> > >http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-...
>
> >> > Hi Benjamin
>
> >> > I did find that page prior to posting the question but i still wanted
> >> > to have a second opinion to complement that info so as to make things
> >> > easier The first line of my post clearly states that i am a beginner.
> >> > It's nice to provide links which can help answer the question but
> >> > please be so polite and keep personal comments for yourself.
>
> >> That is of course perfectly legitimate. It would however have been polite 
> >> to
> >> state that in the question. Show us that you're doing your homework, and 
> >> not
> >> just using the list as a cheap path to having to think less yourself.
>
> >> Phrasing your post as "I would like to compare a ... I found the open()
> >> function here: [link]. Is this what I should use of is there any 
> >> other/better
> >> way?" makes a completely different impression.
>
> >> Also, keeping personal comments to one's self is just not how it works. On 
> >> a
> >> list like this especially, answers along the lines of "That's the way to do
> >> what you were asking for, but are you sure the question went into the right
> >> direction? Have you thought of [...]?" can often be very helpful.
>
> >> > To all other respondants: thank you for your kind instructions and
> >> > directions.
>
> > Thanks Thomas. Look up some of my questions  this group and read
> > through them and come back to tell me if a) i use this forum to learn
> > without making any efforts myself
>
> Just a quick point- when you ask someone for help, it's considered
> impolite to tell them what to do.
>
> I'd also point out that you gave no indication that you'd worked on
> this at all before posting it. In that regard, Thomas's concern seems
> completely justified to me.
>
> > or b) i use this forum to get
> > started using the expertise of more knowledgeable programmers while at
> > the same time particiapting.
>
> Again, Thomas's concern seems justified to me. Things would probably
> go more smoothly if you gave a better indication of what you had done
> so far on the problem in the future.
>
> > Anyway having this discussion is beside
> > the point. Any Expert out there who thinks we beginners are some dumb
> > idiots who are too stupid to think for themselves and are lucky to
> > have a bunch of geniuses like you to help, get lost or make yourself a
> > cup of tea but please give me a break from teaching me lessons...
>
> I don't think all beginners are idiots, or even most of them- but this
> isn't the right attitude to be taking. Both Thomas and myself thought
> that this was inappropriate enough to mention it, and if two people
> spoke up you can bet a lot more were thinking it quietly. My
> suggestion would be to moderate your approach and demonstrate what
> you've done so far (if only to increase the signal-to-noise ratio as
> your problems become more challenging) when posting. I'd also refrain
> from telling people to get lost; it doesn't make people happy to help
> you, you know?
>
> Geremy Condra

Thanks Jeremy, i will take your advice on board! Noone likes to be
taught lessons i think so it is only normal that i reacted. If i had
received a friendly response from Benjamin (as opposed to "Please do
us a favor and at least try to figure things out on your own") making
me aware of the etiquette that my post should also show that i have
researched my question somehow  and if his tone would have been
mannered then we would not be having this discussion now. Ok now i
need to go back to actual Pythoon learning, i'm getting distracted.

Kind regards,
Baba

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


Re: GUibuilder evaluation

2010-09-06 Thread J.O. Aho
Niklasro wrote:
> Hello
> Making a GUI, could you recommend tkinter or any other proposal?

QT Designer from Nokia, I can run my GUI programs both on my desktop and on my
cellphone without modifications.


-- 

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


using modules

2010-09-06 Thread Sal Lopez
The following code runs OK under 3.1:

@filename=cats_and_dogs.py

#!/usr/bin/python

def make_sound(animal):
print(animal + ' says ' + sounds[animal])

sounds = { "cat": "meow", "dog": "woof" }

for i in sounds.keys():
make_sound(i)

# output:
# dog says woof
# cat says meow

When I move the def to it's own file to create a module, it barfs:

@filename= cats_and_dogs.py
#!/usr/bin/python

import defs

sounds = { "cat": "meow", "dog": "woof" }

for i in sounds.keys():
defs.make_sound(i)

@filename=defs.py
def make_sound(animal):
print(animal + ' says ' + sounds[animal])

Traceback (most recent call last):
File "./cats_and_dogs.py", line 11, in 
defs.make_sound(i)
File "defs.py", line 4, in make_sound
print(animal + ' says ' + sounds[animal])
NameError: global name 'sounds' is not defined


I thought that importing the function(s) made them local to the main program? 
Any assistance is appreciated.  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [RELEASED] Python 3.2 alpha 2

2010-09-06 Thread MRAB

On 06/09/2010 09:22, Georg Brandl wrote:
[snip]

To download Python 3.2 visit:

  http://www.python.org/download/releases/3.2/

3.2 documentation can be found at:

  http://docs.python.org/3.2/


I did notice the spelling mistake "dynmaic" at:

http://docs.python.org/dev/whatsnew/3.2.html
--
http://mail.python.org/mailman/listinfo/python-list


filecmp.cmp() doesn't seem to do what it says in the documentation

2010-09-06 Thread tinnews
I'm using filecmp.cmp() to compare some files (surprise!).

The documentation says:-
Unless shallow is given and is false, files with identical
os.stat() signatures are taken to be equal.

I'm not setting shallow explicitly so it's True, thus the function
should be comparing the os.stat() results.  However this doesn't seem
to be the case as even if I touch one of the files to change it's
access/modification date filecmp.cmp() still returns True.

Here is an example:-

chris$ python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import filecmp
>>> print filecmp.cmp("/media/disk/DCIM/103_FUJI/DSCF3084.JPG", 
"/home/chris/pictures/2010/4/24dscf3084.jpg")
True
>>> 
chris$ ls -l /media/disk/DCIM/103_FUJI/DSCF3084.JPG 
/home/chris/pictures/2010/4/24dscf3084.jpg
-rwxr-xr-x 1 chris chris 1783277 2010-09-06 17:36 
/home/chris/pictures/2010/4/24dscf3084.jpg
-rwxr-xr-x 1 chris root  1783277 2010-09-06 17:53 
/media/disk/DCIM/103_FUJI/DSCF3084.JPG
chris$ 

The file modification times are different, surely filecmp.cmp() should
be returning false.  I actually think the way it's working makes more
sense as I don't care if the modification time has changed if the
files are exactly the same length still.


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


Re: Arguments from the command line

2010-09-06 Thread Alan Gauld


"aug dawg"  wrote

Mercurial is written in Python. I know that commit is a function 
that
commits to a repo, but what command does the program use in order to 
get the
commit name, like "This is a commit name" (This would make a commit 
with

"This is a commit name" as the commit name)


Take a look at the Talking to the User topic in my tutorial which has
a section on reading command line arguments.

Interestingly, most of the queries I get on that section are from GUI 
users

who don't understand the concept of command line arguments! :-)


--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


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


Re: GUibuilder evaluation

2010-09-06 Thread CM
On Sep 6, 3:54 am, Niklasro  wrote:
> Hello
> Making a GUI, could you recommend tkinter or any other proposal?
> Thanks

Your message referred to a GUI *builder*, whereas tkinter is a GUI
*toolkit*
(that is, a collection of widgets).  A builder is an application that
allows you
to make GUI apps more

I assume you want to choose a GUI toolkit.  If you search the archive
of
this list or Google generally (like "GUI toolkits Python") you will
have many
minutes of reading material for you to check out.

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


Re: using modules

2010-09-06 Thread Richard Thomas
On Sep 6, 5:55 pm, Sal Lopez  wrote:
> The following code runs OK under 3.1:
>
> @filename=cats_and_dogs.py
>
> #!/usr/bin/python
>
> def make_sound(animal):
>     print(animal + ' says ' + sounds[animal])
>
> sounds = { "cat": "meow", "dog": "woof" }
>
> for i in sounds.keys():
>     make_sound(i)
>
> # output:
> # dog says woof
> # cat says meow
>
> When I move the def to it's own file to create a module, it barfs:
>
> @filename= cats_and_dogs.py
> #!/usr/bin/python
>
> import defs
>
> sounds = { "cat": "meow", "dog": "woof" }
>
> for i in sounds.keys():
>     defs.make_sound(i)
>
> @filename=defs.py
> def make_sound(animal):
>     print(animal + ' says ' + sounds[animal])
>
> Traceback (most recent call last):
> File "./cats_and_dogs.py", line 11, in 
> defs.make_sound(i)
> File "defs.py", line 4, in make_sound
> print(animal + ' says ' + sounds[animal])
> NameError: global name 'sounds' is not defined
>
> I thought that importing the function(s) made them local to the main program? 
> Any assistance is appreciated.              

The make_sound function has two scopes in which to resolve the name
'sounds' the first is its local scope i.e. the scope of things defined
in the function itself but that just contains 'animal'. The second is
its global scope which is another name for its module's namespace. In
this case that's the namespace of the 'defs' module. The namespace of
the main module (the module that you ran), is separate. You could do
this:

import defs
defs.sounds = {'cat': 'meow', ... }

Or even:

#defs.py
sounds = {}

#main.py
import defs
defs.sounds.update({'cat': 'meow', ... })

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


Re: filecmp.cmp() doesn't seem to do what it says in the documentation

2010-09-06 Thread Terry Reedy

On 9/6/2010 1:18 PM, tinn...@isbd.co.uk wrote:

I'm using filecmp.cmp() to compare some files (surprise!).

The documentation says:-
 Unless shallow is given and is false, files with identical
 os.stat() signatures are taken to be equal.


Reword and read carefully: if shallow == True and signatures are 
identical, then files are taken to be equal.


Here is the corresponding code from Lib/filecmp.py:
if shallow and s1 == s2:
return True

Does not say the result for non-identical signatures ;-).


I'm not setting shallow explicitly so it's True, thus the function
should be comparing the os.stat() results.  However this doesn't seem
to be the case as even if I touch one of the files to change it's
access/modification date filecmp.cmp() still returns True.


Because it goes on to actually compare the files, and they are equal.

...
result = _cache.get((f1, f2))
if result and (s1, s2) == result[:2]:
return result[2]
outcome = _do_cmp(f1, f2)
_cache[f1, f2] = s1, s2, outcome
return outcome

Most of the stdlib files in Python are quite readable. I recommend it 
when you have questions.


--
Terry Jan Reedy

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


Re: Queue cleanup

2010-09-06 Thread Paul Rubin
John Nagle  writes:
> I've argued for an approach in which only synchronized or immutable
> objects can be shared between threads.  Then, only synchronized objects
> have refcounts.  See
> "http://www.animats.com/papers/languages/pythonconcurrency.html";

I'm going to have to read this carefully, but my first reaction is that
doing it right would take substantial changes to the language, to the
point where it wouldn't really be Python any more.  

More generally, if you want to program in Erlang, why not use Erlang for
that?

> I can't think of a time when I've really had to use a finalizer for
> something with dynamic extent.  They've always seemed like a code
> smell to me.

   The problem appears when you have an object that owns something, like
a window or a database connection.  "With" is single-level.

But expecting such an object to be gc'd seems like a code smell in its
own right.  I once implemented something like that in a Lisp system, and
it was just disconcerting as hell to see windows on the screen blink out
of existence unpredictably.  The issue is maybe your function returns
and you expect the window to vanish, but something somewhere has saved
another temporary reference to it so it doesn't go away til later.  If
you want something with external semantics (like a window or file
handle) to be released at a particular time, the program should do that
explicitly.  Don't use a finalizer that you expect storage reclamation
to invoke.  There is just too little control in a Python program over
the creation of references. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Database problems

2010-09-06 Thread Edward Grefenstette
Dear Pythonistas,

For a project I'm working on, I need to store fairly large
dictionaries (several million keys) in some form (obviously not in
memory). The obvious course of action was to use a database of some
sort.

The operation is pretty simple, a function is handed a generator that
gives it keys and values, and it maps the keys to the values in a non-
relational database (simples!).

I wrote some code implementing this using anydbm (which used dbhash on
my system), and it worked fine for about a million entries, but then
crashed raising a DBPageNotFoundError. I did a little digging around
and couldn't figure out what was causing this or how to fix it.

I then quickly swapped anydbm for good ol' fashioned dbm which uses
gdbm, and it ran even faster a little longer, but after a million
entries or so it raised the ever-so-unhelpful "gdbm fatal: write
error".

I then threw caution to the winds and tried simply using cPickle's
dump in the hope of obtaining some data persistence, but it crashed
fairly early with a "IOError: [Errno 122] Disk quota exceeded".

Now the question is: is it something wrong with these dbms? Can they
not deal with very large sets of data? If not, is there a more optimal
tool for my needs? Or is the problem unrelated and has something to do
with my lab computer?

Best,
Edward
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Speed-up for loops

2010-09-06 Thread Terry Reedy

On 9/6/2010 7:20 AM, Stefan Behnel wrote:

BartC, 06.09.2010 12:38:



(3) Since the loop variable is never used, why not have a special loop
statement that repeats code so many times?


There sort-of is, just slightly more general.


Because special cases are not special enough to break the rules. As
others have stated before, you can use itertools to reduce that part of
the looping overhead, if it really hurts your concrete code.


I ran the following test:
>>> from itertools import repeat
>>> n = 10**8
>>> for dummy in repeat(None,n): pass # 7 sec

>>> for dummy in range(n): pass # 11 sec

Times are for my older machine, subjectively counted. The difference is 
subjectively clear. Both functions count in C. I presume the difference 
is the cost of creating and deleting unneeded Python int objects. This 
difference is the reason the timeit module uses itertools.repeat for the 
inner loop that repeats the code to be timed.


--
Terry Jan Reedy

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


Re: Database problems

2010-09-06 Thread Benjamin Kaplan
On Mon, Sep 6, 2010 at 3:01 PM, Edward Grefenstette  wrote:
> Dear Pythonistas,
>
> For a project I'm working on, I need to store fairly large
> dictionaries (several million keys) in some form (obviously not in
> memory). The obvious course of action was to use a database of some
> sort.
>
> The operation is pretty simple, a function is handed a generator that
> gives it keys and values, and it maps the keys to the values in a non-
> relational database (simples!).
>
> I wrote some code implementing this using anydbm (which used dbhash on
> my system), and it worked fine for about a million entries, but then
> crashed raising a DBPageNotFoundError. I did a little digging around
> and couldn't figure out what was causing this or how to fix it.
>
> I then quickly swapped anydbm for good ol' fashioned dbm which uses
> gdbm, and it ran even faster a little longer, but after a million
> entries or so it raised the ever-so-unhelpful "gdbm fatal: write
> error".
>
> I then threw caution to the winds and tried simply using cPickle's
> dump in the hope of obtaining some data persistence, but it crashed
> fairly early with a "IOError: [Errno 122] Disk quota exceeded".
>
> Now the question is: is it something wrong with these dbms? Can they
> not deal with very large sets of data? If not, is there a more optimal
> tool for my needs? Or is the problem unrelated and has something to do
> with my lab computer?
>
> Best,
> Edward
> --

Just as a guess, I'd say that you have a disk quota that you're
hitting with your several million key dbm. You might want to talk to
the lab administrator about raising the quota.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: GUibuilder evaluation

2010-09-06 Thread CM
On Sep 6, 3:54 am, Niklasro  wrote:
> Hello
> Making a GUI, could you recommend tkinter or any other proposal?
> Thanks

Your message referred to a GUI *builder*, whereas
tkinter is a GUI *toolkit* (that is, a collection of
widgets).  A builder is an application that allows
one to make GUI apps more

I assume you want to choose a GUI toolkit.  If
you search the archive of this list or Google
generally (like "GUI toolkits Python") you will
have many minutes of reading material for you
to check out.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Database problems

2010-09-06 Thread Tim Harig
On 2010-09-06, Edward Grefenstette  wrote:
> I then threw caution to the winds and tried simply using cPickle's
> dump in the hope of obtaining some data persistence, but it crashed
> fairly early with a "IOError: [Errno 122] Disk quota exceeded".

The error is telling you that you have attempted to write the file; but, in
the process you exceeded your disk quota (the space you are allowed to use)
and the operating system would not permit you to finish the file.

> Now the question is: is it something wrong with these dbms? Can they
> not deal with very large sets of data? If not, is there a more optimal
> tool for my needs? Or is the problem unrelated and has something to do
> with my lab computer?

The problem is that you are attempting to use more disk space then you are
permitted to use on your account (at least for the selected filesystem).
Possible solutions are to save the data somewhere else where you have a
greater quota, delete some other files from your account to make room for
the new file, or talk to whoever administrates the systems and see if they
will add enough space to your quota to permit you to write this large file.

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


Re: GUibuilder evaluation

2010-09-06 Thread CM
On Sep 6, 3:54 am, Niklasro  wrote:
> Hello
> Making a GUI, could you recommend tkinter or any other proposal?
> Thanks

Your message referred to a GUI *builder*, whereas
tkinter is a GUI *toolkit* (that is, a collection of
widgets).  A GUI builder is an application that allows
one to make GUI apps more easily.

I assume you mean a GUI toolkit.  If
you search the archive of this list or Google
generally (like "GUI toolkits Python") you will
have many minutes of reading material for you
to evaluate which toolkit you'd like to try.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: using modules

2010-09-06 Thread Terry Reedy

On 9/6/2010 12:55 PM, Sal Lopez wrote:

The following code runs OK under 3.1:

@filename=cats_and_dogs.py

#!/usr/bin/python

def make_sound(animal):
 print(animal + ' says ' + sounds[animal])

sounds = { "cat": "meow", "dog": "woof" }

for i in sounds.keys():
 make_sound(i)

# output:
# dog says woof
# cat says meow

When I move the def to it's own file to create a module, it barfs:

@filename= cats_and_dogs.py
#!/usr/bin/python

import defs

sounds = { "cat": "meow", "dog": "woof" }

for i in sounds.keys():
 defs.make_sound(i)

@filename=defs.py
def make_sound(animal):
 print(animal + ' says ' + sounds[animal])

Traceback (most recent call last):
File "./cats_and_dogs.py", line 11, in
defs.make_sound(i)
File "defs.py", line 4, in make_sound
print(animal + ' says ' + sounds[animal])
NameError: global name 'sounds' is not defined


I thought that importing the function(s) made them local to the main program? 
Any assistance is appreciated.


Python code execute within the context of the builtin namespace, a 
module namespace (misleadingly called 'globals'), a local namespace (the 
same as the module namespace for top-level code), and for nested 
functions, intermediate namespaces.


"import defs" binds the name 'defs' to the module object. Code in the 
defs module still executes within the defs context where it is defined. 
This is lexical name resolution. The same is still true if you import 
the function with "from defs import make_sound".


What you were expecting is dynamic name resolution, where names are 
resolved within the calling context rather than the definition context. 
I believe this is dynamic scoping. This has been tried in other 
languages. For more, try

https://secure.wikimedia.org/wikipedia/en/wiki/Dynamic_scoping

--
Terry Jan Reedy

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


The PSF Blog Gets a Transfusion!

2010-09-06 Thread Mike Driscoll
The Python Software Foundation’s Blog staff has been recently expanded
by a new set of top-notch bloggers to bring you the latest in PSF
news, ranging from the scintillating projects that the PSF has its
fingers in to the mundane, but necessary board minutes.

Don’t despair if you hate reading blogs! The blog also has a handy RSS
feed and a mailing list! You can take your pick of these delivery
methods by visiting the blog, at http://pyfound.blogspot.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: filecmp.cmp() doesn't seem to do what it says in the documentation

2010-09-06 Thread tinnews
Terry Reedy  wrote:
> On 9/6/2010 1:18 PM, tinn...@isbd.co.uk wrote:
> > I'm using filecmp.cmp() to compare some files (surprise!).
> >
> > The documentation says:-
> >  Unless shallow is given and is false, files with identical
> >  os.stat() signatures are taken to be equal.
> 
> Reword and read carefully: if shallow == True and signatures are 
> identical, then files are taken to be equal.
> 
> Here is the corresponding code from Lib/filecmp.py:
>  if shallow and s1 == s2:
>  return True
> 
> Does not say the result for non-identical signatures ;-).
> 
> > I'm not setting shallow explicitly so it's True, thus the function
> > should be comparing the os.stat() results.  However this doesn't seem
> > to be the case as even if I touch one of the files to change it's
> > access/modification date filecmp.cmp() still returns True.
> 
> Because it goes on to actually compare the files, and they are equal.
> 
> ...
>  result = _cache.get((f1, f2))
>  if result and (s1, s2) == result[:2]:
>  return result[2]
>  outcome = _do_cmp(f1, f2)
>  _cache[f1, f2] = s1, s2, outcome
>  return outcome
> 
> Most of the stdlib files in Python are quite readable. I recommend it 
> when you have questions.
> 
Well I still don't think it's what the documentation says, it would be
much better if it told you that 'if the os.stat() signatures are not
identical then the file contents are actually compared'.  The
implication to me when I read the documentation was that if shallow
was True and the os.stat() signatures were not identical then False
would be returned.  Where does it say otehrwise?

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


Re: redirecting stdout and stderr for a windows service

2010-09-06 Thread Ian

 On 06/09/2010 15:29, Ian Hobson wrote:

Hi all,


Forget this.

The problem is that it is a Windows Service, so it is not initialised in 
the normal way.


PythonService.exe loads other code (named __main__) that loads the 
service proper, so the

if test was never true!

Regards

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


YOU MUST KNOW THIS MAN

2010-09-06 Thread shahama23
In The Name Of Allaah,

Most Gracious, Most Merciful

YOU MUST KNOW THIS MAN
MUHAMMAD
(May peace and blessings of God Almighty be upon him)
You may be an atheist or an agnostic; or you may belong to anyone of
the religious denominations that exist in the world today. You may be
a Communist or a believer in democracy and freedom. No matter what you
are, and no matter what your religious and political beliefs, personal
and social habits happen to be - YOU MUST STILL KNOW THIS MAN!

He was by far the most remarkable man that ever set foot on this
earth. He preached a religion, founded a state, built a nation, laid
down a moral code, initiated numberless social and political reforms,
established a dynamic and powerful society to practice and represent
his teachings, and completely revolutionized the worlds of human
thought and action for all times to come.

HIS NAME IS MUHAMMAD, peace and blessings of Almighty God be upon him
and he accomplished all these wonders in the unbelievably short span
of twenty-three years.

Muhammad, peace and blessings of God Almighty be upon him was born in
Arabia on the 20th of August, in the year 570 of the Christian era,
and when he died after 63 years, the whole of the Arabian Peninsula
had changed from paganism and idol-worship to the worship of One God;
from tribal quarrels and wars to national solidarity and cohesion;
from drunkenness and debauchery to sobriety and piety; from
lawlessness and anarchy to disciplined living; from utter moral
bankruptcy to the highest standards of moral excellence. Human history
has never known such a complete transformation of a people or a place
before or since!

The Encyclopedia Britannica calls him "the most successful of all
religious personalities of the world". Bernard Shaw said about him
that if Muhammad were alive today he would succeed in solving all
those problems which threaten to destroy human civilization in our
times. Thomas Carlysle was simply amazed as to how one man, single-
handedly, could weld warring tribes and wandering Bedouins into a most
powerful and civilized nation in less than two decades. Napoleon and
Gandhi never tired of dreaming of a society along the lines
established by this man in Arabia fourteen centuries ago.

Indeed no other human being ever accomplished so much, in such diverse
fields of human thought and behavior, in so limited a space of time,
as did Muhammad, peace and blessings of God Almighty be upon him. He
was a religious teacher, a social reformer, a moral guide, a political
thinker, a military genius, an administrative colossus, a faithful
friend, a wonderful companion, a devoted husband, a loving father -
all in one. No other man in history ever excelled or equaled him in
any of these difficult departments of life.

The world has had its share of great personalities. But these were one
sided figures who distinguished themselves in but one or two fields
such as religious thought or military leadership. None of the other
great leaders of the world ever combined in himself so many different
qualities to such an amazing level of perfection as did Muhammad,
peace and blessings of God Almighty be upon him.

The lives and teachings of other great personalities of the world are
shrouded in the mist of time. There is so much speculation about the
time and the place of their birth, the mode and style of their life,
the nature and detail of their teachings and the degree and measure of
their success or failure that it is impossible for humanity today to
reconstruct accurately and precisely the lives and teachings of those
men.

Not so this man Muhammad, peace and blessings of God Almighty be upon
him. Not only was he born in the fullest blaze of recorded history,
but every detail of his private and public life, of his actions and
utterances, has been accurately documented and faithfully preserved to
our day. The authenticity of the information so preserved is vouched
for not only by faithful followers but also by unbiased critics and
open-minded scholars.

At the level of ideas there is no system of thought and belief-secular
or religious, social or political-which could surpass or equal ISLAAM-
the system which Muhammad peace and blessings of God Almighty be upon
him propounded. In a fast changing world, while other systems have
undergone profound transformations, Islaam alone has remained above
all change and mutation, and retained its original form for the past
1400 years. What is more, the positive changes that are taking place
in the world of human thought and behavior, truly and consistently
reflect the healthy influence of Islam in these areas. Further, it is
not given to the best of thinkers to put their ideas completely into
practice, and to see the seeds of their labors grow and bear fruit, in
their own lifetime. Except of course, Muhammad, peace and blessings of
God Almighty be upon him, who not only preached the most wonderful
ideas but also successfully translated each one of them into practice

Re: accessing a text file

2010-09-06 Thread Ben Finney
Baba  writes:

> Thanks Jeremy, i will take your advice on board! Noone likes to be
> taught lessons i think so it is only normal that i reacted.

Please reconsider this response. Many of us use this forum precisely
because we *do* like to be taught lessons. If you don't want to be
taught lessons, this is not the forum to use.

> If i had received a friendly response from Benjamin (as opposed to
> "Please do us a favor and at least try to figure things out on your
> own")

Again, please reconsider your perception of the messages you received.
Those messages are polite; they're even explicit about how you can
improve your future messages. They are polite enough to regard you as a
person who can improve.

We value respect for people here, and that's what you've been shown
consistently. But respect for opinions, or for delicacy about learning,
is not welcome here. In other words, we treat people as adults by
default. I hope you'll continue to participate in that spirit.

-- 
 \ “I was gratified to be able to answer promptly and I did. I |
  `\   said I didn't know.” —Mark Twain, _Life on the Mississippi_ |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Class changes in circular imports when __name__ == '__main__'

2010-09-06 Thread Dave Angel



On 2:59 PM, Carl Banks wrote:

On Sep 5, 5:07 pm, Dave Angel  wrote:

On 2:59 PM, Carl Banks wrote:

All of this gets a lot more complicated when packages are involved.

Perhaps a better answer would be to import __main__ from the second module.

Then what if the module is imported from a different script?  It'll
try to import __main__ but get a different script than expected.


Then the module needs to adjust its expectations.  The point is it 
should never try to import the script by name.


DaveA

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


Re: filecmp.cmp() doesn't seem to do what it says in the documentation

2010-09-06 Thread Carl Banks
On Sep 6, 1:11 pm, tinn...@isbd.co.uk wrote:
> Terry Reedy  wrote:
> > On 9/6/2010 1:18 PM, tinn...@isbd.co.uk wrote:
> > > I'm using filecmp.cmp() to compare some files (surprise!).
>
> > > The documentation says:-
> > >      Unless shallow is given and is false, files with identical
> > >      os.stat() signatures are taken to be equal.
>
> > Reword and read carefully: if shallow == True and signatures are
> > identical, then files are taken to be equal.
>
> > Here is the corresponding code from Lib/filecmp.py:
> >      if shallow and s1 == s2:
> >          return True
>
> > Does not say the result for non-identical signatures ;-).
>
> > > I'm not setting shallow explicitly so it's True, thus the function
> > > should be comparing the os.stat() results.  However this doesn't seem
> > > to be the case as even if I touch one of the files to change it's
> > > access/modification date filecmp.cmp() still returns True.
>
> > Because it goes on to actually compare the files, and they are equal.
>
> > ...
> >      result = _cache.get((f1, f2))
> >      if result and (s1, s2) == result[:2]:
> >          return result[2]
> >      outcome = _do_cmp(f1, f2)
> >      _cache[f1, f2] = s1, s2, outcome
> >      return outcome
>
> > Most of the stdlib files in Python are quite readable. I recommend it
> > when you have questions.
>
> Well I still don't think it's what the documentation says, it would be
> much better if it told you that 'if the os.stat() signatures are not
> identical then the file contents are actually compared'.  The
> implication to me when I read the documentation was that if shallow
> was True and the os.stat() signatures were not identical then False
> would be returned.  Where does it say otehrwise?

To me, "comparing files" means to compare the contents and nothing
else, so when documentation says "Compare the files named f1 and f2" I
think it has that covered.  I understand the os.stat comparison to be
a (non-foolproof) optimization.


Anyway, if you just want to compare the os.stat parameters you should
just use os.stat.

os.stat(filename1) == os.stat(filename2)


Then if you want, you can write a function to compare only the stats
you are interested in.

def mystatcmp(filename1,filename2):
s1 = os.stat(filename1)
s2 = os.stat(filename2)
return s1.st_size == s2.st_size and s1.st_mtime == s2.st_mtime


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


Re: accessing a text file

2010-09-06 Thread Ben Finney
Ben Finney  writes:

> We value respect for people here, and that's what you've been shown
> consistently. But respect for opinions, or for delicacy about
> learning, is not welcome here.

Sloppy wording, I apologise. This should say “… is not respect for a
person”.

> In other words, we treat people as adults by default. I hope you'll
> continue to participate in that spirit.

This is the main thrust of the message.

-- 
 \“What if the Hokey Pokey IS what it's all about?” —anonymous |
  `\   |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Minimum and Maximum of a list containing floating point numbers

2010-09-06 Thread ceycey
I have a list like ['1.1881', '1.1881', '1.1881', '1.1881', '1.1881',
'1.1881', '1.1881', '1.1881', '1.1881', '1.1881', '1.7689',  '1.7689',
'3.4225', '7.7284', '10.24', '9.0601', '9.0601', '9.0601', '9.0601',
'9.0601']. What I want to do is to find minimum  and maximum number in
this list.

I used min function,

s = ['1.1881', '1.1881', '1.1881', '1.1881', '1.1881', '1.1881',
'1.1881', '1.1881', '1.1881', '1.1881', '1.7689',
'1.7689', '3.4225', '7.7284', '10.24', '9.0601', '9.0601', '9.0601',
'9.0601', '9.0601']

print min(s)
print max(s)

these gives me

1.181
9.0601

maximum value is wrong. It must be 10.24.

I know why max function gives wrong number. Because max function
processed elements of list as strings. How can I convert the elements
of list to float so max function finds the correct answer.

I hope I can explain my problem.

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


Re: Minimum and Maximum of a list containing floating point numbers

2010-09-06 Thread Xavier Ho
On 7 September 2010 10:37, ceycey  wrote:

> I have a list like ['1.1881', '1.1881', '1.1881', '1.1881', '1.1881',
> '1.1881', '1.1881', '1.1881', '1.1881', '1.1881', '1.7689',  '1.7689',
> '3.4225', '7.7284', '10.24', '9.0601', '9.0601', '9.0601', '9.0601',
> '9.0601'].



> How can I convert the elements
> of list to float so max function finds the correct answer.
>

 >>> input = ['3.4225', '7.7284', '10.24']
>>> [float(x) for x in input]
[3.4225, 7.7284, 10.24]

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


Re: Minimum and Maximum of a list containing floating point numbers

2010-09-06 Thread MRAB

On 07/09/2010 01:44, Xavier Ho wrote:

On 7 September 2010 10:37, ceycey mailto:cuneyt.er...@gmail.com>> wrote:

I have a list like ['1.1881', '1.1881', '1.1881', '1.1881', '1.1881',
'1.1881', '1.1881', '1.1881', '1.1881', '1.1881', '1.7689', '1.7689',
'3.4225', '7.7284', '10.24', '9.0601', '9.0601', '9.0601', '9.0601',
'9.0601'].

How can I convert the elements
of list to float so max function finds the correct answer.


 >>> input = ['3.4225', '7.7284', '10.24']
 >>> [float(x) for x in input]
[3.4225, 7.7284, 10.24]


If you wanted to find the maximum value without converting the list to
numbers you could do this:

>>> input = ['3.4225', '7.7284', '10.24']
>>> max(input, key=float)
'10.24'

Incidentally, there's a builtin function called 'input' so using it as
a variable name is a discouraged! :-)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Minimum and Maximum of a list containing floating point numbers

2010-09-06 Thread Tim Chase

On 09/06/10 19:37, ceycey wrote:

I have a list like ['1.1881', '1.1881', '1.1881', '1.1881', '1.1881',
'1.1881', '1.1881', '1.1881', '1.1881', '1.1881', '1.7689',  '1.7689',
'3.4225', '7.7284', '10.24', '9.0601', '9.0601', '9.0601', '9.0601',
'9.0601']. What I want to do is to find minimum  and maximum number in
this list.

I used min function,

print min(s)
print max(s)

these gives me

1.181
9.0601

maximum value is wrong. It must be 10.24.

I know why max function gives wrong number. Because max function
processed elements of list as strings. How can I convert the elements
of list to float so max function finds the correct answer.


You can use

  min(float(v) for v in s)
  max(float(v) for v in s)

to return the floating-point number, or in Python2.5+ you can use

  min(s, key=float)
  max(s, key=float)

to get the string source.  If you need the source string in 
pre-2.5, you'd have to do something like


  min((float(v), v) for v in s)[1]   # 2.4
  min([(float(v), v) for v in s])[1] # 2.3 or earlier

and guard against empty input lists.

-tkc




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


Re: Minimum and Maximum of a list containing floating point numbers

2010-09-06 Thread Albert Hopkins
On Mon, 2010-09-06 at 17:37 -0700, ceycey wrote:
> I have a list like ['1.1881', '1.1881', '1.1881', '1.1881', '1.1881',
> '1.1881', '1.1881', '1.1881', '1.1881', '1.1881', '1.7689',  '1.7689',
> '3.4225', '7.7284', '10.24', '9.0601', '9.0601', '9.0601', '9.0601',
> '9.0601']. What I want to do is to find minimum  and maximum number in
> this list.
> 
> I used min function,
> 
> s = ['1.1881', '1.1881', '1.1881', '1.1881', '1.1881', '1.1881',
> '1.1881', '1.1881', '1.1881', '1.1881', '1.7689',
> '1.7689', '3.4225', '7.7284', '10.24', '9.0601', '9.0601', '9.0601',
> '9.0601', '9.0601']
> 
> print min(s)
> print max(s)
> 
> these gives me
> 
> 1.181
> 9.0601
> 
> maximum value is wrong. It must be 10.24.

You are not comparing a list of floats but a list of strings. 

> I know why max function gives wrong number. Because max function
> processed elements of list as strings. How can I convert the elements
> of list to float so max function finds the correct answer.

min/max in these cases are returning strings as well.  So the fact
remains that the max function is not giving you a number at all, but a
string, and as such is correct.  String comparison is not identical to
numerical comparison.

But to answer your question:

>>> s = ['1.1881', '1.1881', '1.1881', '1.1881', '1.1881', '1.1881',
... '1.1881', '1.1881', '1.1881', '1.1881', '1.7689',
... '1.7689', '3.4225', '7.7284', '10.24', '9.0601', '9.0601', '9.0601',
... '9.0601', '9.0601']

>>> [type(x) for x in s]
[, , , , ,
, , , , ,
, , , , ,
, , , , ]


>>> type(max(s))


>>> t = [float(x) for x in s]
>>> [type(x) for x in t]
[, , , , , , , , , , , , , , , , , , , ]
>>> min(t)
1.1880
>>> max(t)
10.24

>>> type(max(s))

>>> type(max(t))



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


Re: Minimum and Maximum of a list containing floating point numbers

2010-09-06 Thread Ben Finney
ceycey  writes:

> I have a list like ['1.1881', '1.1881', '1.1881', '1.1881', '1.1881',
> '1.1881', '1.1881', '1.1881', '1.1881', '1.1881', '1.7689',  '1.7689',
> '3.4225', '7.7284', '10.24', '9.0601', '9.0601', '9.0601', '9.0601',
> '9.0601']. What I want to do is to find minimum  and maximum number in
> this list.

As you correctly describe later, there aren't any numbers in that list;
only strings.

> How can I convert the elements of list to float so max function finds
> the correct answer.

If you're going to use the list of float objects, you can convert them
all with a list comprehension.

>>> numbers_as_str = ['1.1881', '1.1881', '1.1881', '1.1881', '1.1881',
... '1.1881', '1.1881', '1.1881', '1.1881', '1.1881', '1.7689', '1.7689',
... '3.4225', '7.7284', '10.24', '9.0601', '9.0601', '9.0601', '9.0601',
... '9.0601']
>>> numbers_as_float = [float(x) for x in numbers_as_str]
>>> print min(numbers_as_float), max(numbers_as_float)
1.1881 10.24

-- 
 \ “As scarce as truth is, the supply has always been in excess of |
  `\   the demand.” —Josh Billings |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Minimum and Maximum of a list containing floating point numbers

2010-09-06 Thread Steven D'Aprano
On Tue, 07 Sep 2010 11:00:45 +1000, Ben Finney wrote:

> If you're going to use the list of float objects, you can convert them
> all with a list comprehension.
[...]
> >>> numbers_as_float = [float(x) for x in numbers_as_str]

That's awfully verbose. A map is simpler:

numbers_as_float = map(float, numbers_as_str)


-- 
Steven

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


Re: Minimum and Maximum of a list containing floating point numbers

2010-09-06 Thread Ben Finney
Steven D'Aprano  writes:

> On Tue, 07 Sep 2010 11:00:45 +1000, Ben Finney wrote:
>
> > If you're going to use the list of float objects, you can convert them
> > all with a list comprehension.
> [...]
> > >>> numbers_as_float = [float(x) for x in numbers_as_str]
>
> That's awfully verbose. A map is simpler:
>
> numbers_as_float = map(float, numbers_as_str)

I'll pay “verbose”, but not “awfully”. There is little difference in
verbosity between your example and mine. Further, I don't see my example
as excessive, which I assume your “awfully” entails.

-- 
 \ “I call him Governor Bush because that's the only political |
  `\  office he's ever held legally.” —George Carlin, 2008 |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Speed-up for loops

2010-09-06 Thread Steven D'Aprano
On Mon, 06 Sep 2010 11:38:22 +0100, BartC wrote:

> Modifying the OP's code a little:
> 
> a = 0
> for i in xrange(1):  # 100 million
>  a = a + 10  # add 10 or 100
> print a
> 
> Manually unrolling such a loop four times (ie. 4 copies of the body, and
> counting only to 25 million) increased the speed by between 16% and 47%
> (ie. runtime reducing by between 14% and 32%).

Or you could *really* optimize it, as well as simplifying the code, by 
writing:

n = 1
a = 10*n

and doing a single multiplication rather than pointless repeated addition.

(I assume that the number of loops is meant to be a variable rather than 
a constant, otherwise a = 10 would be the correct optimization.)

Of course, if 10 (or 100) is not a constant but is just standing in for 
something which varies each iteration:

for i in xrange(1):
a = a + f(i)


then unrolling the loop is even less useful. The overhead of the loop 
itself is likely to be trivial compared to the cost of calling f() 100 
million times -- the added complexity to shave 3 seconds off a four 
minute calculation simply isn't worth it.

Besides, loop unrolling really only is valuable for small loops, 
otherwise the overhead caused by the increased code size makes it a 
pessimation rather than an optimization. It's very easy for any gains to 
be lost due to increased cache misses, time needed to copy the code into 
memory, etc.

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

There's a lot of subtlety in optimization, and what counts as an 
optimization for low-level operations, and what is an optimization for 
high-level languages like Python, are rarely the same.


 
> This depended on whether I added +10 or +100 (ie. whether long integers
> are needed), whether it was inside or outside a function, and whether I
> was running Python 2 or 3 (BTW why doesn't Python 3 just accept 'xrange'
> as a synonym for 'range'?)

Why should it? But if you want it, you can do it:

xrange = range

There, that wasn't hard, was it?


> These are just some simple tests on my particular machine and
> implementations, but they bring up some points:
> 
> (1) Loop unrolling does seem to have a benefit, when the loop body is
> small.
> 
> (2) Integer arithmetic seems to go straight from 32-bits to long
> integers; why not use 64-bits before needing long integers?

Why? That adds 50% more code, 50% more testing, 50% more places for bugs 
to hide, 50% more effort required to maintain it, for something which *at 
best* will be a trivial optimization which at best is of interest to a 
small minority of Python coders.

There's already code to deal with 32 bit its, code to deal with longints, 
and code to deal with shifting transparently from one to the other. 
Adding code to deal with 64 bit ints doesn't happen for free.

Besides, if you care about the difference between 32 and 64 bit ints, 
chances are you don't want Python blithely swapping from one to the other 
when you least expect it. So you'll be using a library that gives you 
access to whichever ints you want, probably implemented natively rather 
than as objects.

Sounds rather like numpy really :)

http://docs.scipy.org/doc/numpy/user/basics.types.html



> (3) Since the loop variable is never used, why not have a special loop
> statement that repeats code so many times? This can be very fast, since
> the loop counter need not be a Python object, and probably there would
> be no need for unrolling at all:
> 
> repeat 1:# for example
> a = a + 10

Because now both the parser and all Python coders need to care about one 
more reserved word, all so that one Python program in ten thousand can 
save 0.1 ms occasionally.

Optimizations don't happen for free. If the optimization doesn't carry 
it's own weight, it's a pessimation. To me, it's more important to be 
able to be able to use repeat as a name:

connect_to_server("localhost", repeat=10)

than to save a millisecond or so.


Besides, if repeat were to become syntax, then I'd MUCH rather have it 
used for repeat...until (or repeat...while) loops, to avoid the anti-
pattern of:


x = f()
while not condition(x):
x = f(x)


which would be better as:


repeat:
x = f()
until condition(x)





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


The Samurai Principle

2010-09-06 Thread Phlip
Pythonistas:

The "Samurai Principle" says to return victorious, or not at all. This
is why django.db wisely throws an exception, instead of simply
returning None, if it encounters a "record not found".

I illustrated the value of that concept, here:

http://c2.com/cgi/wiki?SamuraiPrinciple
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Minimum and Maximum of a list containing floating point numbers

2010-09-06 Thread Steven D'Aprano
On Tue, 07 Sep 2010 12:40:57 +1000, Ben Finney wrote:

> Steven D'Aprano  writes:
> 
>> On Tue, 07 Sep 2010 11:00:45 +1000, Ben Finney wrote:
>>
>> > If you're going to use the list of float objects, you can convert
>> > them all with a list comprehension.
>> [...]
>> > >>> numbers_as_float = [float(x) for x in numbers_as_str]
>>
>> That's awfully verbose. A map is simpler:
>>
>> numbers_as_float = map(float, numbers_as_str)
> 
> I'll pay “verbose”, but not “awfully”. There is little difference in
> verbosity between your example and mine. Further, I don't see my example
> as excessive, which I assume your “awfully” entails.

Sorry, verbose is not the word I want... I don't know what word I 
*actually* want, so let me explain.

Instead of thinking about a single transformation "change a list of 
strings to a list of floats", the list comp form forces you to think 
about the individual list items and the mechanics of looping, and reduces 
lists to a second-class data type: we can operate on ints without caring 
about individual bits, but we can't operate on lists without caring about 
individual list items.

Why do I need to care about individual items? The list comp even gives 
them a name, "x" in your example, even though that name isn't used 
anywhere else. Why do I need to specify that walking the list must be 
done from left-to-right rather than whatever order the compiler thinks 
best, or even in parallel?

Answer: I don't, and shouldn't need to. With map, such internal details 
of how the transformation is performed is hidden. I shouldn't need to 
specify *how* to convert a list of strings to a list of floats. While a 
list comp is less verbose than a for-loop, which is less again than a 
while-loop, they all specify how to do the transformation, which is 
mental overhead I shouldn't need to care about.

Of course, list comps are so seductively easy, and functional programming 
so conceptually different from what many people are used to, that such 
over-specification is an awfully easy trap to fall into. I'm sure my own 
code is filled with similar examples where I use a list comp where a map 
is more suitable.


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


Bit fields in python?

2010-09-06 Thread Kwan Lai Cheng
Hi,

I'm trying to rewrite a c program in python & encountered several problems. I 
have some data structures in my c program like below:

typedef struct
{
unsigned short size;

unsigned short reserved:8;
unsigned short var_a1:2;
unsigned short var_a2:2;
unsigned short var_a3:2;
unsigned short var_a4:2;

unsigned int var_a5;
}structa;

 typedef struct
{
unsigned short size;

unsigned char reserved:4;
unsigned char var_b1:1;
unsigned char var_b2:1;
unsigned char var_b3:1;
unsigned char var_b4:1;

structa var_structa;
}structb;

I tried to code the above in python but only got this far:

class StructA(object):
def __init__(self, size=0)
self.size = size

class StructB(object):
def __init__(self, size=0)

Any equivalent for c data structures & bit fields in python? And how do I 
define var_structa (in structb) in python?

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


Re: Minimum and Maximum of a list containing floating point numbers

2010-09-06 Thread Ben Finney
Steven D'Aprano  writes:

> Of course, list comps are so seductively easy, and functional
> programming so conceptually different from what many people are used
> to, that such over-specification is an awfully easy trap to fall into.
> I'm sure my own code is filled with similar examples where I use a
> list comp where a map is more suitable.

Right. I find list comprehensions and generator expressions easy both to
write and to read.

So I prefer them, and often don't consider more function-based
approaches. I don't think my code (nor my examples) suffer much as a
result.

-- 
 \  “Rightful liberty is unobstructed action, according to our |
  `\will, within limits drawn around us by the equal rights of |
_o__)   others.” —Thomas Jefferson |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


mail sending -- smtplib

2010-09-06 Thread Kurian Thayil
Hi All,

I am a newbie in python. Just 2-3 days old wanting to learn this amazing
programming language. I was trying to send mails using smtplib module, so
did some google and found a code snippet. The mail gets sent, but doesn't
come in the right format when a for-loop is introduced (Not MIME standard?).
Without the for-loop the script works fine. Can anyone advice?
*
#!/usr/bin/env python

import smtplib

for i in range(1,5):
print "I is ",i
fromaddr='kurianmtha...@gmail.com'
toaddr='kurianmtha...@gmail.com'
print toaddr
mssg="""From: Kurian Thayil 
To: Kurian Thayil 
MIME-Version: 1.0
Content-type: text/html
Subject: 12345 -- Reloaded :)

Hey dude.. how are you


Regards,

Kurian
"""
print "message is ",mssg

smail=smtplib.SMTP('smtp.gmail.com',587)

smail.ehlo()
smail.starttls()
smail.ehlo()
smail.login(fromaddr,'***')

smail.sendmail(fromaddr,toaddr,mssg)
print "Over"
*

Regards,

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


Re: Class changes in circular imports when __name__ == '__main__'

2010-09-06 Thread Carl Banks
On Sep 6, 4:44 pm, Dave Angel  wrote:
> On 2:59 PM, Carl Banks wrote:> On Sep 5, 5:07 pm, Dave Angel  
> wrote:
> >> On 2:59 PM, Carl Banks wrote:
> >>> All of this gets a lot more complicated when packages are involved.
> >> Perhaps a better answer would be to import __main__ from the second module.
> > Then what if the module is imported from a different script?  It'll
> > try to import __main__ but get a different script than expected.
>
> Then the module needs to adjust its expectations.

No, it shouldn't.  It shouldn't have any expectations at all, because
importing __main__ and expecting to get a particular module is a
foolish thing to do.  There are a bunch of reasons why __main__ might
not be the original script.  Example: running the profiler on it.


> The point is it
> should never try to import the script by name.

Importing __main__ directly is worse than the problem it's trying to
solve.

And "never" is too strong a word.  I already in this thread gave a
solution whereby the script can be imported by name safely, by
renaming itself and assigning itself an item in sys.modules.  When you
do that, you can import the main script by name.


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


How to determine if a Python script is being run right after startup on Windows

2010-09-06 Thread Ryan George
Hello!

I'm a newbie to Python (literally just started last Saturday), and I
coded a program that selects a random wallpaper from a directory and
swaps it with your current one (Windows only.)

What I'm looking to do is have it start up with Windows and
automatically swap the wallpapers. This part I have already coded, and
as far as I know, it should work. However, I want the user to be able
to access the GUI after this initial running of the program. The way
it is set up now, enabling "Start Up Mode" will cause the program to
cycle the wallpapers and then immediately exit.

My question is this: is there any way I can determine if the program
is being run directly after a startup on a Windows machine?

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


Re: How to determine if a Python script is being run right after startup on Windows

2010-09-06 Thread Steven D'Aprano
On Mon, 06 Sep 2010 22:19:46 -0700, Ryan George wrote:

> My question is this: is there any way I can determine if the program is
> being run directly after a startup on a Windows machine?

How would you, a human being, determine if the program was being run 
directly after startup?

What counts as "directly"? Within 10 seconds? Before any other program 
with a GUI? Before *any* other program, including background processes? 
Before the Windows desktop loads?

You also said:

"What I'm looking to do is have it start up with Windows and
automatically swap the wallpapers. This part I have already coded, and
as far as I know, it should work."

As far as you know, it SHOULD work? How about trying it and finding out?

In any case, it sounds to me that what you need is two programs, one 
which automatically sets the wallpaper at startup, and a second that is a 
GUI.


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


Re: list of tuples with dynamic change in position

2010-09-06 Thread sajuptpm
More details
I have a list of tuples l = [((cpu_util,mem_util),(disk_util)),
((cpu_util,mem_util),(disk_util))]
ie, l = [((30,50),(70)), ((50,20),(20))]

l.sort(key=lambda x:(-x[0][0], x[1][0])) # sorting cpu_util asc and
disk_util desc

suppose i changed order that is l = [((mem_util,cpu_util),
(disk_util)), ((mem_util,cpu_util),(disk_util))]
So i have to change the sort code to l.sort(key=lambda x:(-x[0][1],
x[1][0])) # sorting cpu_util asc and disk_util desc


I want to use same (common) sort code, that must work even if i
changed tuple order.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Bit fields in python?

2010-09-06 Thread Stefan Behnel

Kwan Lai Cheng, 07.09.2010 06:06:

I'm trying to rewrite a c program in python&  encountered several problems. I 
have some data structures in my c program like below:

typedef struct
{
 unsigned short size;

 unsigned short reserved:8;
 unsigned short var_a1:2;
 unsigned short var_a2:2;
 unsigned short var_a3:2;
 unsigned short var_a4:2;

 unsigned int var_a5;
}structa;

  typedef struct
{
 unsigned short size;

 unsigned char reserved:4;
 unsigned char var_b1:1;
 unsigned char var_b2:1;
 unsigned char var_b3:1;
 unsigned char var_b4:1;

 structa var_structa;
}structb;

I tried to code the above in python but only got this far:

class StructA(object):
 def __init__(self, size=0)
 self.size = size

class StructB(object):
 def __init__(self, size=0)

Any equivalent for c data structures&  bit fields in python?


If you can tell us what these structs are being used for in the original C 
code, we might be able to point you to a suitable way to implement the same 
thing efficiently in Python.


Stefan

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