Re: turn monitor off and on

2011-05-14 Thread harrismh777

Astan Chee wrote:

import time
import win32gui
import win32con
import win32api

def turnOffMonitor():
   SC_MONITORPOWER = 0xF170
   win32gui.SendMessage(win32con.HWND_BROADCAST,
win32con.WM_SYSCOMMAND, SC_MONITORPOWER, 2)

def turnOnMonitor():
   SC_MONITORPOWER = 0xF170
   win32gui.SendMessage(win32con.HWND_BROADCAST,
win32con.WM_SYSCOMMAND, SC_MONITORPOWER, -1)

if __name__ == "__main__":
   turnOffMonitor()
   time.sleep(5)
   turnOnMonitor()



What we need here is a matching script that turns off WinXP and leaves 
it off too...




...  ouch, :)



lol
m harris

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


Re: turn monitor off and on

2011-05-14 Thread harrismh777

harrismh777 wrote:


def turnOnMonitor():
SC_MONITORPOWER = 0xF170
win32gui.SendMessage(win32con.HWND_BROADCAST,
win32con.WM_SYSCOMMAND, SC_MONITORPOWER, -1)



I've never tried turning my monitor on/off without using my finger... 
gonna have to play with this...  wouldn't that be a great script kiddie 
tool... just turn off all the windows monitors around the world... no 
problem(s) after that...


... what happens if you try to turn it back on with your finger... ?

... I have another idea... while its off, try pushing the alt key on 
your keyboard... or moving your mouse... (come back on ? )








kind regards,
m harris

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


Re: how to install easy_install

2011-05-14 Thread rusi
On May 13, 11:29 pm, Ian Kelly  wrote:
> On Fri, May 13, 2011 at 11:40 AM, rusi  wrote:
> > I tried to install easy_install (This is on windows)
> > I downloaded the executable and ran it. It claimed to have done its
> > job.
>
> > But now when I type easy_install at a cmd prompt I get
> > easy_install is not a command...
>
> > [I guess I am a perennial noob to windows, never being able to
> > comprehend the PATH lookup logic (or lack of it)]
>
> > Another related question: I gather that easy_install is being
> > superseded by pypi or some such but I cant find the link...
>
> easy_install is part of the setuptools or distribute package.  I
> assume that one of these is what you installed.
>
> On Windows, the easy_install command is installed into your Python
> Scripts directory, which should be something like
> "C:\Python27\Tools\Scripts" or "C:\Python25\Scripts" depending on your
> Python version.  You just need to find that directory and add it to
> your PATH.
>
> PyPI is the Python package index.  It's a website athttp://pypi.python.org/-- 
> not a replacement for setuptools or
> easy_install, which uses it to look up package metadata.  Setuptools
> is supposed to be superseded by distribute, which may be what you
> heard.

It seems to be something called pip -- Easy_install and plain setup.py
install cant uninstall whereas pip can.  But to install pip you have
to do easy_install pip.
O well :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: turn monitor off and on

2011-05-14 Thread harrismh777

harrismh777 wrote:


def turnOnMonitor():
SC_MONITORPOWER = 0xF170
win32gui.SendMessage(win32con.HWND_BROADCAST,
win32con.WM_SYSCOMMAND, SC_MONITORPOWER, -1)



Wonder what the equivalent of this is in Linux... ?



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


Re: checking if a list is empty

2011-05-14 Thread Steven D'Aprano
On Thu, 12 May 2011 23:46:12 -0700, rusi wrote:

> Mathematics has existed for millenia. Hindu-arabic numerals (base-10
> numbers) have been known for about one millennium
> The boolean domain is only a 100 years old. Unsurprisingly it is not
> quite 'first-class' yet: See
> http://www.cs.utexas.edu/users/EWD/transcriptions/EWD10xx/EWD1070.html
> [Lifted from http://c2.com/cgi/wiki?EqualVsTrueFalse ]

Th money-quote as regards using arbitrary objects in truth tests:

[quote]
All this changed with the introduction of the two-element 
boolean domain {true, false} which provides the vocabulary 
needed to assign values to boolean expressions: 3<4 is a 
way for writing true, 3>4 is a way for writing false, 
whereas the value of x>0 depends on the value of x ...
[end quote]


In Python, [1, 2, 3] is another way of writing true, and [] is another 
way of writing false. Similarly with any other arbitrary objects. The 
only things that bools True and False are good for are:

* giving functions a canonical way of spelling true/false when they want 
to emit a Boolean value;

* giving documentation writers a canonical way of spelling true/false 
when they want to discuss passing a Boolean value.

Other than those conveniences, there's nothing you can do with True and 
False in Python that you can't do with any other set of objects.


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


Re: unicode by default

2011-05-14 Thread harrismh777

Terry Reedy wrote:

Is there a unix linux package that can be installed that
drops at least 'one' default standard font that will be able to render
all or 'most' (whatever I mean by that) code points in unicode? Is this
a Python issue at all?


Easy, practical use of unicode is still a work in progress.


Apparently...  the good news for me is that SBL provides their unicode 
font here:


 http://www.sbl-site.org/educational/biblicalfonts.aspx

I'm getting much closer here, but now the problem is typing. The pain 
with unicode fonts is that the glyph is tied to the code point for the 
represented character, and not tied to any code point that matches any 
keyboard scan code for typing.   :-}


So, I can now see the ancient text with accents and aparatus in all of 
my editors, but I still cannot type any ancient Greek with my 
keyboard... because I have to make up a keymap first. 


I don't find that SBL (nor Logos Software) has provided keymaps as 
yet...  rats.


I can read the test with Python though... ye.


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


Re: turn monitor off and on

2011-05-14 Thread Steven D'Aprano
On Sat, 14 May 2011 02:20:55 -0500, harrismh777 wrote:

> harrismh777 wrote:
>>
>> def turnOnMonitor():
>> SC_MONITORPOWER = 0xF170
>> win32gui.SendMessage(win32con.HWND_BROADCAST,
>> win32con.WM_SYSCOMMAND, SC_MONITORPOWER, -1)
> 
> 
> I've never tried turning my monitor on/off without using my finger...

You've never had your PC turn your monitor off after X minutes of 
inactivity?


> gonna have to play with this...  wouldn't that be a great script kiddie
> tool... just turn off all the windows monitors around the world... no
> problem(s) after that...
> 
> ... what happens if you try to turn it back on with your finger... ?

Then you actually turn it off, at the power switch, instead of merely off 
in software.


> ... I have another idea... while its off, try pushing the alt key on
> your keyboard... or moving your mouse... (come back on ? )

Presumably you would need to program something to watch for activity and 
turn it back on. It would be somewhat embarrassing if you neglected to so 
this...


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


Re: checking if a list is empty

2011-05-14 Thread rusi
On May 14, 12:39 pm, Steven D'Aprano  wrote:
> On Thu, 12 May 2011 23:46:12 -0700, rusi wrote:
> > Mathematics has existed for millenia. Hindu-arabic numerals (base-10
> > numbers) have been known for about one millennium
> > The boolean domain is only a 100 years old. Unsurprisingly it is not
> > quite 'first-class' yet: See
> >http://www.cs.utexas.edu/users/EWD/transcriptions/EWD10xx/EWD1070.html
> > [Lifted fromhttp://c2.com/cgi/wiki?EqualVsTrueFalse]
>
> Th money-quote as regards using arbitrary objects in truth tests:
>
>     [quote]
>     All this changed with the introduction of the two-element
>     boolean domain {true, false} which provides the vocabulary
>     needed to assign values to boolean expressions: 3<4 is a
>     way for writing true, 3>4 is a way for writing false,
>     whereas the value of x>0 depends on the value of x ...
>     [end quote]
>
> In Python, [1, 2, 3] is another way of writing true, and [] is another
> way of writing false. Similarly with any other arbitrary objects.

Well so is [1,2] another way of writing True

And then we get the interesting result that
(True = True) is False
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: turn monitor off and on

2011-05-14 Thread Alexander Kapps

On 14.05.2011 09:29, harrismh777 wrote:

harrismh777 wrote:


def turnOnMonitor():
SC_MONITORPOWER = 0xF170
win32gui.SendMessage(win32con.HWND_BROADCAST,
win32con.WM_SYSCOMMAND, SC_MONITORPOWER, -1)



Wonder what the equivalent of this is in Linux... ?


Probably xset dpms force {on,off,...}
--
http://mail.python.org/mailman/listinfo/python-list


Re: turn monitor off and on

2011-05-14 Thread harrismh777

Steven D'Aprano wrote:

I've never tried turning my monitor on/off without using my finger...



You've never had your PC turn your monitor off after X minutes of
inactivity?


I know you're being funny, but actually, no-- I don't.


That's a back-in-the-day thing...   all of my monitors (and I only have 
a couple now because I use VNC to get to the rest of my machines) are 
flat panel LED, very low power, cool, and virtually indestructible. I 
just leave them on... with beautiful screen savers running... which 
aren't screen savers these days either... because nothing really 
burns... more like perpetual light-candy eye-pleasers...


Sure, back in the day I configured my system to shutoff the CRT... but 
honestly, I haven't had a CRT for almost a decade...  you can still 
shutdown the flat panel several different ways on the linux platform 
based on timing if you want to... in BIOS, in the OS, in gnome, using 
the xscreensaver, etc...but, no, I have never written a code routine 
to shutoff the monitor (my finger always worked just fine).  :)


I wrote a code routine one time just to open the drive bay door, 
timer(), and then close the door... from across the network...   until 
my wife got wise to it, I would open her drive bay door over the 
network... it was fun for a while, even after she got wise to it...



... till the morning I tried it and she had a cup of cocoa sitting on 
the desk in front of the drive bay...



... there have been better days in my house.   :)






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


Re: unicode by default

2011-05-14 Thread Nobody
On Fri, 13 May 2011 14:53:50 -0500, harrismh777 wrote:

> The unicode consortium is very careful to make sure that thousands
> of symbols have a unique code point (that's great !) but how do these
> thousands of symbols actually get displayed if there is no font
> consortium?   Are there collections of 'standard' fonts for unicode that I
> am not aware?  Is there a unix linux package that can be installed that
> drops at least 'one' default standard font that will be able to render all
> or 'most' (whatever I mean by that) code points in unicode?

Using the original meaning of "font" (US) or "fount" (commonwealth), you
can't have a single font cover the whole of Unicode. A font isn't a random
set of glyphs, but a set of glyphs in a common style, which can only
practically be achieved for a specific alphabet.

You can bundle multiple fonts covering multiple repertoires into a single
TTF (etc) file, but there's not much point.

In software, the term "font" is commonly used to refer to some ad-hoc
mapping between codepoints and glyphs. This typically works by either
associating each specific font with a specific repertoire (set of
codepoints), or by simply trying each font in order until one is found
with the correct glyph.

This is a sufficiently common problem that the FontConfig library exists
to simplify a large part of it.

>   Is this a Python issue at all?

No.

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


Re: How best to convert a string "list" to a python list

2011-05-14 Thread Nobody
On Fri, 13 May 2011 10:15:29 -0700, noydb wrote:

> I want some code to take the items in a semi-colon-delimted string "list"
> and places each in a python list.  I came up with below.  In the name of
> learning how to do things properly, do you experts have a better way of
> doing it?

> x = "red;blue;green;yellow" ## string of semi-colon delimited colors

Provided that a semicolon is *always* a delimiter, just use the .split()
method:

color_list = x.split(";")

For more complex formats, where there are quote and/or escape characters
which allow the delimiter to occur as part of an item, you typically need
to use a regular expression to match everything up to the next delimiter,
and do this in a loop to extract the individual items.

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


Re: Parsing a graph image

2011-05-14 Thread Paul
On May 13, 11:19 pm, Bastian Ballmann  wrote:
> Hi python lovers out there,
>
> I am searching for a library to parse data from a graph in an image file
> something likehttp://pytseries.sourceforge.net/_images/yahoo.png
> Any suggestions, hints, links?
>
> TIA && have a nice day! :)
>
> Basti
>
>  signature.asc
> < 1KViewDownload

Hi,

If you are trying to digitize data from the graph, you could try
Dagra: http://www.BlueLeafSoftware.com/Products/Dagra/

There is a Python library for reading the files it produces.

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


Re: how to install easy_install

2011-05-14 Thread TheSaint
rusi wrote:

>  tried to install easy_install (This is on windows)
> I downloaded the executable and ran it. It claimed to have done its
> job.

Perhaps, the abit to just click is disordering some easy steps like copy the 
script files into the normal place.
Only when there's a particular copy then it's the time to pay attention, 
like some executable and/or framework.
In the README.txt should mention these few easy steps

-- 
goto /dev/null
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: checking if a list is empty

2011-05-14 Thread Hans Mulder

On 07/05/2011 02:43, Jon Clements wrote:

On May 7, 12:51 am, Ian Kelly  wrote:

On Fri, May 6, 2011 at 4:21 PM, Philip Semanchuk  wrote:

What if it's not a list but a tuple or a numpy array? Often I just want to 
iterate through an element's items and I don't care if it's a list, set, etc. 
For instance, given this function definition --



def print_items(an_iterable):
if not an_iterable:
print "The iterable is empty"
else:
for item in an_iterable:
print item



I get the output I want with all of these calls:
print_items( list() )
print_items( tuple() )
print_items( set() )
print_items( numpy.array([]) )


But sadly it fails on iterators:
print_items(xrange(0))
print_items(-x for x in [])
print_items({}.iteritems())


My stab:

from itertools import chain

def print_it(iterable):
 it = iter(iterable)
 try:
 head = next(it)
 except StopIteration:
 print 'Empty'
 return
 for el in chain( (head,), it ):
 print el

Not sure if I'm truly happy with that though.


How about:

def print_items(an_iterable):
found_item = False
for item in an_iterable:
print item
found_item = True
if not found_item:
print "The iterable was empty"

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


Converting a set into list

2011-05-14 Thread TheSaint
Hello

I've stumble to find a solution to get a list from a set



>>> aa= ['a','b','c','f']
>>> aa
['a', 'b', 'c', 'f']
>>> set(aa)
{'a', 'c', 'b', 'f'}
>>> [k for k in aa]
['a', 'b', 'c', 'f']


I repute the comprehension list too expensive, is there another method?

-- 
goto /dev/null
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python enabled gdb on Windows and relocation

2011-05-14 Thread Ruben Van Boxem
2011/5/14 Doug Evans :
> On Thu, May 12, 2011 at 9:19 AM, Ruben Van Boxem
>  wrote:
>> (now in plain-text as required by gdb mailing list)
>>
>> Hi,
>>
>> I am currently trying to integrate Python support into my toolchain
>> build (including GDB of course). It is a sysrooted
>> binutils+GCC+GDB+mingw-w64 toolchain.
>>
>> I currently have the basic setup working: I can link gdb with my
>> manually generated import lib to the python dll from the official
>> Windows install. If there is anything I am missing or a very easy
>> solution to the problems decsribed below, please just say so. I am
>> only suggesting what I would like to happen.
>>
>> Now on to the problems I'd like to discuss:
>>
>> 1. gdb.exe won't start without me having set PYTHONPATH manually.
>
> In a properly configured/built gdb on linux this isn't necessary, even
> if python is installed in some random place.
> I'm not sure about windows though.
> Did you specify --with-python when you configured gdb, and if so did
> you specify a value?
> e.g., --with-python=SOME_VALUE

I was cross-compiling a mingw toolchain+gdb from Linux, so I used
--with-python without a value (because gdb configure tries to find the
Python executabe), and I added -I"/path/to/python/includes" to CFLAGS
and -L"/path/to/pythondll/importlib" to LDFLAGS, which built as it
should. This is hacky though, and gdb configure should provide
--with-python-libs and --with-python-include to make it more
streamlined with any other build prerequisite (like
gmp/mpfr/mpc/cloog/ppl in GCC for example).

>
>> I understand the need for this, but as gdb requires Python 2, and users
>> of my toolchain may have installed Python 3 or a 32-bit version python
>> they want to use from the same environment (without changing their own
>> PYTHONPATH), there is no way to run python-enabled gdb.
>> [...]
>
> Yeah.
> There is a proposal to add GDB_PYTHONPATH (or some such IIRC) and have
> gdb use that instead of PYTHONPATH if it exists, but there's been
> resistance to it.
> I think(!) what would happen is that gdb would set $PYTHONPATH to the
> value of $GDB_PYTHONPATH.
> [Inferiors started by gdb should still get the original value of
> PYTHONPATH though.]

That way would be almost ideal, but a hardcoded *relative* path to the
python scripts (that is standardized within gdb) wouldn't hurt. An
extra environment variable would require a lot of explaining for
Windows, and is not "plug-and-play", like the rest of a sysrooted
toolchain is supposed to be like. I think this should work on all
setups:

1. Check hardcoded path; my suggestion would be "/../lib/python27"
2. If this fails to find the necessary files/scripts, find it like you
described above in Linux, without PYTHONPATH set.
3. Check PYTHONPATH.

I would think only number one would change, and perhaps be only
enabled with a special configure option. Nothing else would have to
change, and Windows users would rejoice :)
Again, this is only my suggestion, if there are problems with it in
way I haven't thought of, please say so, and we can come up with
another solution.

>
>> 2. With PYTHONPATH set as a temporary workaround, gdb starts, but
>> spits out a traceback:
>> Traceback (most recent call last):
>>   File "", line 35, in 
>>   File "m:\development\mingw64\share\gdb/python/gdb/__init__.py", line
>> 18, in 
>>     gdb.command.pretty_printers.register_pretty_printer_commands()
>>   File 
>> "m:\development\mingw64\share\gdb/python/gdb\command\pretty_printers.py",
>> line 368, in register_pretty_printer_commands
>>     InfoPrettyPrinter()
>>   File 
>> "m:\development\mingw64\share\gdb/python/gdb\command\pretty_printers.py",
>> line 100, in __init__
>>     gdb.COMMAND_DATA)
>> RuntimeError: Could not find command prefix info.
>>
>> This is a minor problem I think, as "python import time" "python print
>> time.clock()" works as expected. What is wrong?
>
> I'm not sure.
> The error message is complaining that the "info" command prefix doesn't exist.
> I don't see how that can happen as python is initialized long after
> the info command is created.
>

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


Re: Python enabled gdb on Windows and relocation

2011-05-14 Thread Eli Zaretskii
> Date: Sat, 14 May 2011 11:09:13 +0200
> From: Ruben Van Boxem 
> Cc: g...@sourceware.org, python-list@python.org
> 
> 1. Check hardcoded path; my suggestion would be " executable>/../lib/python27"
> 2. If this fails to find the necessary files/scripts, find it like you
> described above in Linux, without PYTHONPATH set.
> 3. Check PYTHONPATH.
> 
> I would think only number one would change, and perhaps be only
> enabled with a special configure option. Nothing else would have to
> change, and Windows users would rejoice :)

The problem, I think, is that it's not so easy on Unix to get the
place where the GDB executable leaves.  There isn't a system call to
do that (similar to what Windows gives you).

So I think on Posix platforms, number 2 would be used most of the
time.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Converting a set into list

2011-05-14 Thread Peter Otten
TheSaint wrote:

> I've stumble to find a solution to get a list from a set
> 
> 
> 
 aa= ['a','b','c','f']
 aa
> ['a', 'b', 'c', 'f']
 set(aa)

To clarify: this creates a new object, so aa is still a list.

> {'a', 'c', 'b', 'f'}
 [k for k in aa]
> ['a', 'b', 'c', 'f']

So you are actually converting a list to a (new) list here. Of course it 
would have worked with a set or an arbitrary iterable, too.

> 
> I repute the comprehension list too expensive, is there another method?
 
mylist = list(myset)

Do you notice the similarity to converting a list to a set?

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


Re: Python enabled gdb on Windows and relocation

2011-05-14 Thread Ruben Van Boxem
2011/5/14 Eli Zaretskii :
>> Date: Sat, 14 May 2011 11:09:13 +0200
>> From: Ruben Van Boxem 
>> Cc: g...@sourceware.org, python-list@python.org
>>
>> 1. Check hardcoded path; my suggestion would be "> executable>/../lib/python27"
>> 2. If this fails to find the necessary files/scripts, find it like you
>> described above in Linux, without PYTHONPATH set.
>> 3. Check PYTHONPATH.
>>
>> I would think only number one would change, and perhaps be only
>> enabled with a special configure option. Nothing else would have to
>> change, and Windows users would rejoice :)
>
> The problem, I think, is that it's not so easy on Unix to get the
> place where the GDB executable leaves.  There isn't a system call to
> do that (similar to what Windows gives you).
>
> So I think on Posix platforms, number 2 would be used most of the
> time.
>

I understand. So better/feasible would be:

Windows: Check /../lib/python27 or any configure-time
specified relative path to gdb executable? If that fails, revert to
current behavoir.

POSIX (so pretty much everythin else): Keep current behavior.

Which would come down to a configure option+ a small block of #if
_WIN32 code in the Python part of the code.

Thanks,

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


Re: How best to convert a string "list" to a python list

2011-05-14 Thread Daniel Kluev
On Sat, May 14, 2011 at 7:41 PM, Nobody  wrote:
> to use a regular expression to match everything up to the next delimiter,
> and do this in a loop to extract the individual items.

re.findall() should let you match all items at once, without loop.

-- 
With best regards,
Daniel Kluev
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unicode by default

2011-05-14 Thread jmfauth
On 14 mai, 09:41, harrismh777  wrote:

> ...
> I'm getting much closer here,
> ...

You should really understand, that Unicode is a domain per
se. It is independent from any os's, programming languages
or applications. It is up to these tools to be "unicode"
compliant.

Working in a full unicode mode (at least for texts) is
today practically a solved problem. But you have to ensure
the whole toolchain is unicode compliant (editors,
fonts (OpenType technology), rendering devices, ...).

Tip. This list is certainly not the best place to grab
informations. I suggest you start by getting informations
about XeTeX. XeTeX is the "new" TeX engine working only
in a unicode mode. From this starting point, you will
fall on plenty web sites speaking about the "unicode
world", tools, fonts, ...

A variant is to visit sites speaking about *typography*.

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


Having a problem getting python working...

2011-05-14 Thread Chris Paton
Hey all,

Not sure if this is the right place to put this (forgive me for my ignorance, 
I'm looking everywhere!). I'm having a problem getting IDLE working. I'm 
working off Mac OSX 10.6.7 with Python 3.2 installed and I installed Activetcl 
8.5.9 as recommended. IDLE is still crashing at random moments - loading, 
saving, typing, compiling... I tried to do a simple 'hello world' but it kept 
crashing. There's no official report; I just get the spinning beach ball then 
have to force quit. I'm quite new to all of this so any help would be extremely 
appreciated. Need to get into this ASAP as I need to do some stuff for my 
thesis project! 

Thanks!

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


threads with gtk gui problem

2011-05-14 Thread Andy Baxter

Hi,

I'm working on adding a Gtk GUI to a python program. Its main function 
is to read raw data from an arduino board over USB, and convert it to 
MIDI note/controller events to be sent to another program. I've had it 
working fine with just a command line interface, but when I replaced the 
command line with a Gtk interface, I started having problems getting the 
thread that reads the USB port to run.


I'm not sure what the custom is on this list for pasting code - It's a 
long program so I don't want to paste the whole thing.


The sequence of events I've coded is:

- the program starts.
- the port reader thread (which is a threading.Thread subclass) is 
initialised.
- the object which controls the interface is initialised (i.e. the glade 
file is loaded.)
- the port reader is started (i.e. the 'start' method is called, which 
calls the 'run' method in a thread).

- then the gtk main loop is run.

The behaviour I'm getting is that the port reader either fails to start, 
or stops running at the point where it tries to initialise the serial 
port. It then does nothing until I close the main window, at which point 
it starts running again.


The port reader's run method begins like this:

   # the method called by the thread superclass to run the main loop of 
the thread.

   def run(self):
  # main loop of thread.
  print "Starting port reader."
  fhan=serial.Serial(port=keeper.config['usbPort'], 
baudrate=keeper.config['usbBaud'], timeout=0.1)

  print "1"
  fhan.open()
  print "2"
  seq=PySeq() # the sequencer library object
  port=seq.createOutPort(keeper.config['midiPortName']) # make a 
midi out port.

  midich=keeper.config['midich']
  print "3"
  while True:
 inbuf=[]
 print ".",
 char=fhan.read(1)
 if self.quit:
fhan.close()
return
 if len(char)==0: continue
 ... (code to process the character read in)

('keeper' is a global object which stores the config data and references 
to a few key objects).


When you start the program, the thread stops either before the first 
print statement, or on the line which initialises the serial port ( 
fhan=serial.Serial(...) ). '1', '2', and '3' only get printed /after/ 
you close the gtk main window.


Can anyone help with this?

cheers,

andy baxter



--

http://highfellow.org

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


Re: checking if a list is empty

2011-05-14 Thread Chris Angelico
On Sat, May 14, 2011 at 5:45 PM, rusi  wrote:
> And then we get the interesting result that
> (True = True) is False

How does this work? In Python, the = sign is illegal there, and if you
mean True == True, then it's True (obviously), which is not False.

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


Re: Converting a set into list

2011-05-14 Thread Ben Finney
TheSaint  writes:

> Hello
>
> I've stumble to find a solution to get a list from a set
>
> 
>
> >>> aa= ['a','b','c','f']

Creates a new list object. Binds the name ‘aa’ to that object.

> >>> aa
> ['a', 'b', 'c', 'f']

Evaluates the object referenced by the name ‘aa’.

> >>> set(aa)
> {'a', 'c', 'b', 'f'}

Creates a new set object, populating it with the contents from the list
object referenced by ‘aa’. Doesn't do anything with the new set object,
which will soon be garbage-collected.

> >>> [k for k in aa]
> ['a', 'b', 'c', 'f']

Creates a new list object by iterating each of the items from the list
referenced by ‘aa’. Does nothing with the new list object, which will
soon be garbage-collected.

> 
> I repute the comprehension list too expensive, is there another method?

Another method to do what?

If you want to bind ‘aa’ to a new object, do so with an assignment
statement. (Your example has exactly one assignment statement; all the
other statements create objects which are never bound to anything.)

But what is it you actually want to do?

-- 
 \  “The fact that I have no remedy for all the sorrows of the |
  `\ world is no reason for my accepting yours. It simply supports |
_o__)  the strong probability that yours is a fake.” —Henry L. Mencken |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Converting a set into list

2011-05-14 Thread TheSaint
Peter Otten wrote:

> mylist = list(myset)
> Do you notice the similarity to converting a list to a set?
> 
There was something confusing me yesterday in doing that, but (for me 
strangely) I got cleared out.

The point was that after a result from:

newset= set(myset1) & set(myset2)
list= [newset]

<< [{'bla', 'alb', 'lab'}]

Probably list(set) is not like [set].

-- 
goto /dev/null
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: checking if a list is empty

2011-05-14 Thread David Robinow
On Fri, May 13, 2011 at 10:34 PM, Gregory Ewing
 wrote:
> rusi wrote:
>
>> Dijkstra's problem (paraphrased) is that python, by choosing the
>> FORTRAN alternative of having a non-first-class boolean type, hinders
>> scientific/mathematical thinking/progress.
>
> Python doesn't have the flaw that Dijkstra was talking about.
> Fortran's flaw wasn't so much the lack of a boolean type, but
> that you couldn't assign the result of a logical expression to
> a variable. Python has always been able to do that, even before
> it had a distinct boolean type.
And Fortran could do it at least 25 years before Python was invented.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Converting a set into list

2011-05-14 Thread TheSaint
Ben Finney wrote:

> Another method to do what?
> 
Sorry, some time we expect to have said it as we thought it.

The example was to show that after having made a set

set(aa)

the need to get that set converted into a list.
My knowledge drove me to use a comprehension list as a converter.
In another post I got to know the simplest way to state

list(aa)
Where aa is a set.

-- 
goto /dev/null
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: checking if a list is empty

2011-05-14 Thread Roy Smith
In article ,
 David Robinow  wrote:

> On Fri, May 13, 2011 at 10:34 PM, Gregory Ewing
>  wrote:
> > rusi wrote:
> >
> >> Dijkstra's problem (paraphrased) is that python, by choosing the
> >> FORTRAN alternative of having a non-first-class boolean type, hinders
> >> scientific/mathematical thinking/progress.
> >
> > Python doesn't have the flaw that Dijkstra was talking about.
> > Fortran's flaw wasn't so much the lack of a boolean type, but
> > that you couldn't assign the result of a logical expression to
> > a variable. Python has always been able to do that, even before
> > it had a distinct boolean type.
> And Fortran could do it at least 25 years before Python was invented.

I vaguely remember that Fortran called the data type LOGICAL, but yes, 
it was exactly what most modern languages call a bool or boolean.  And 
the operators were spelled .NOT., .AND., .OR., etc but that's because 
Fortran was designed for punch cards, which didn't have much in the way 
of special characters.
-- 
http://mail.python.org/mailman/listinfo/python-list


Question about available python lib for a task

2011-05-14 Thread cesium5500

Hello,

I would like to build a database of all the MS-Excel file on a LAN. I 
would like to get the files metadata : filename, summary, location, 
size, etc.


Is there a dedicated python lib for the task? Is pywin32 one of the 
possible lib available?


I would prefer to not building everything from scratch testing, etc.

ETL software could also is a solution maybe...

Thanks


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


Re: checking if a list is empty

2011-05-14 Thread rusi
On May 14, 6:42 pm, Chris Angelico  wrote:
> On Sat, May 14, 2011 at 5:45 PM, rusi  wrote:
> > And then we get the interesting result that
> > (True = True) is False
>
> How does this work? In Python, the = sign is illegal there, and if you
> mean True == True, then it's True (obviously), which is not False.
>
> Chris Angelico

1. = vs ==
Ok to be true to python syntax I should have said (True == True) is
False.
But then the question arises, is the is a python is or an English is?
If its python then that's fine but its just bland code with no
discussion about it.
To say something about it (in English) one would have to say
(True == True) is False is True (where the first is is a python is and
the second an English one).

2. True == True is (obviously) True

Here is the quote (with internal quote from Dijkstra) from Steven that
I was answering:

--
[Dijkstra quote]
All this changed with the introduction of the two-element
boolean domain {true, false} which provides the vocabulary
needed to assign values to boolean expressions: 3<4 is a
way for writing true, 3>4 is a way for writing false,
whereas the value of x>0 depends on the value of x ...
[end quote]

[Steven quote]
In Python, [1, 2, 3] is another way of writing true, and [] is another
way of writing false. Similarly with any other arbitrary objects. The
only things that bools True and False are good for are:

[end Steven quote]


So since
[1,2,3] is one way of writing True (lets call it True3)
and [1,2] is another (call it True2)
then we have True3 == True2 is False

But since according to Steven (according to Python?) True3 *is the
same* as True2
we get
  False
= [1,2,3] == [1,2]
= True3  == True2
= True == True
= True
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: checking if a list is empty

2011-05-14 Thread Chris Angelico
On Sun, May 15, 2011 at 1:47 AM, rusi  wrote:
> So since
> [1,2,3] is one way of writing True (lets call it True3)
> and [1,2] is another (call it True2)
> then we have True3 == True2 is False
>
> But since according to Steven (according to Python?) True3 *is the
> same* as True2
> we get
>  False
> = [1,2,3] == [1,2]
> = True3  == True2
> = True == True
> = True

Okay, I see what you're doing here.

http://www.rinkworks.com/ithink/search.cgi?words=compress

When you condense a whole lot of information down to just two states,
True and False, *obviously* there'll be a huge amount that fits into
one or the other without being identical. It's not an argument for
whether [1,2,3] ought to be True or ought to be False. You could make
the exact same argument if they evaluated to False. You have proven
nothing and just wasted your time proving it.

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


Trace in a class

2011-05-14 Thread TheSaint
Hello,
first of all, I'm a dummy in programming. My methods are just do-it-and-try-
it.
For more convinience I commonly using  and go with step-into 
and breakpoints.
Lately I was setting a class, but it's incomplete and just calling it at the 
pdb prompt line I can't use breakpoints or stop it to check what values are 
coming into the play.

BTW, would it be much difference to use the class functions outside the 
class. I mean I don't declare the class statement just leave funtions alone 
in the module.

-- 
goto /dev/null
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Get IP address of WIFI interface

2011-05-14 Thread Jun Hu
Thanks, is there any other way without using external command?

On Fri, May 13, 2011 at 10:41 PM, Ishwor Gurung wrote:

> Hi.
>
> On 14 May 2011 14:46, Far.Runner  wrote:
> > Hi Python Experts:
> > There are two network interfaces on my laptop, one is
> > 100M Ethernet interface, the other is wifi interface, both are connected
> and
> > has an IP address. then the question is: how to get the ip address of the
> > wifi interface in a python script?
> > OS: Windows or Linux
>
> Detect the OS with os.name and branch out to specific use case.
>
> The specific functionality can be implemented 2 ways:
> 1/ Regular expression pattern match
> 2/ Substring match and splits
>
> The subprocess module will then let you run those commands.
> 1/ posix - (Linux in your case) will use ifconfig
> 2/ nt - (windows in your ase) will use ipconfig.
>
> HTH.
>
>
>
> --
>
> Regards
> Ishwor Gurung
> Key id:0xa98db35e
> Key fingerprint:FBEF 0D69 6DE1 C72B A5A8  35FE 5A9B F3BB 4E5E 17B5
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Recursion or iteration (was Fibonacci series recursion error)

2011-05-14 Thread rusi
On May 14, 2:48 am, Mark Dickinson  wrote:

> I don't see this (or Hans' version) as cheating at all.

Yeah sure -- cheating is a strong word :-)

> This really  *is* the power algorithm, just in a different number system from 
> the
> usual one.

Yes that was my point.  If we take the standard logarithmic power algo
as trivial (in the sense that it is well known) then all these
solutions do heavy-lifting to transform fib to power and then use the
'trivial' algo.

A more direct approach would be to use the identities:

f_2n = f_n ^ 2 + 2*f_n * f_(n-1)
f_(2n-1) = f_n ^ 2 + f_(n-1) ^ 2


The naive python implementation of which is:

def even(n): return n % 2 == 0
def sq(x): return x * x

def fib(n):
if n==1 or n==2:
return 1
elif even(n):
return sq(fib (n//2)) + 2 * fib(n//2) * fib(n//2 - 1)
else:
return sq(fib (n//2 + 1)) + sq(fib(n // 2))

This is a strange algo  -- logarithmic because it halves the n,
exponential because of the double (triple) calls.  [I cannot say I
know how to work out its exact complexity but I would guess its about
linear]

--
BTW How do I parse "the ring Z[x] / (x^2 - x - 1)"?
Is this a division ring?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: checking if a list is empty

2011-05-14 Thread rusi
On May 14, 8:55 pm, Chris Angelico  wrote:
> On Sun, May 15, 2011 at 1:47 AM, rusi  wrote:
> > So since
> > [1,2,3] is one way of writing True (lets call it True3)
> > and [1,2] is another (call it True2)
> > then we have True3 == True2 is False
>
> > But since according to Steven (according to Python?) True3 *is the
> > same* as True2
> > we get
> >  False
> > = [1,2,3] == [1,2]
> > = True3  == True2
> > = True == True
> > = True
>
> Okay, I see what you're doing here.
>
> http://www.rinkworks.com/ithink/search.cgi?words=compress

LOL -- Thanks for that.

But it seems you did not get the moral? Spelt out: "Beware of lossy
compression!"
[Which is also the moral of my 'proof']

>
> When you condense a whole lot of information down to just two states,
> True and False, *obviously* there'll be a huge amount that fits into
> one or the other without being identical. It's not an argument for
> whether [1,2,3] ought to be True or ought to be False. You could make
> the exact same argument if they evaluated to False. You have proven
> nothing and just wasted your time proving it.
>
> Chris Angelico

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


Re: Converting a set into list

2011-05-14 Thread Chris Angelico
On Sun, May 15, 2011 at 12:14 AM, TheSaint  wrote:
> newset= set(myset1) & set(myset2)
> list= [newset]
>
> << [{'bla', 'alb', 'lab'}]
>
> Probably list(set) is not like [set].

list(set) creates a list out of the set. [set] creates a list with one
element, the set itself. It's not a copy of the set, it's another
reference to the same set; change one and you'll see the change in the
other.

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


Re: Python enabled gdb on Windows and relocation

2011-05-14 Thread Doug Evans
On Sat, May 14, 2011 at 2:09 AM, Ruben Van Boxem
 wrote:
> 2011/5/14 Doug Evans :
>> On Thu, May 12, 2011 at 9:19 AM, Ruben Van Boxem
>>  wrote:
>>> (now in plain-text as required by gdb mailing list)
>>>
>>> Hi,
>>>
>>> I am currently trying to integrate Python support into my toolchain
>>> build (including GDB of course). It is a sysrooted
>>> binutils+GCC+GDB+mingw-w64 toolchain.
>>>
>>> I currently have the basic setup working: I can link gdb with my
>>> manually generated import lib to the python dll from the official
>>> Windows install. If there is anything I am missing or a very easy
>>> solution to the problems decsribed below, please just say so. I am
>>> only suggesting what I would like to happen.
>>>
>>> Now on to the problems I'd like to discuss:
>>>
>>> 1. gdb.exe won't start without me having set PYTHONPATH manually.
>>
>> In a properly configured/built gdb on linux this isn't necessary, even
>> if python is installed in some random place.
>> I'm not sure about windows though.
>> Did you specify --with-python when you configured gdb, and if so did
>> you specify a value?
>> e.g., --with-python=SOME_VALUE
>
> I was cross-compiling a mingw toolchain+gdb from Linux, so I used
> --with-python without a value (because gdb configure tries to find the
> Python executabe), and I added -I"/path/to/python/includes" to CFLAGS
> and -L"/path/to/pythondll/importlib" to LDFLAGS, which built as it
> should. This is hacky though, and gdb configure should provide
> --with-python-libs and --with-python-include to make it more
> streamlined with any other build prerequisite (like
> gmp/mpfr/mpc/cloog/ppl in GCC for example).

Ah.
Cross-compiling gdb with python is in need of improvement.
Alas python hasn't been designed with cross-compilation in mind (e.g.
build on linux, run on windows).
AIUI, the way to get the parameters required for compiling with
libpython is to get them from python's "distutils": kinda hard to do
in a cross-compile.  Done correctly there's no need to run python.

I haven't done anything more to support python in gdb's configure.ac
because it's not clear to me what the right thing to do is: distutils
provides more than just --libs and --includes (btw, we don't use
--libs though, we use --ldflags which includes all of: the directory
in which to find libpython, the -l for libpython, and the -l's for all
the other libraries python needs). [Which isn't to say that someone
else isn't free to tackle this.]

In the meantime, what I've been doing is a hack: write a script that
responds to:
--includes
--ldflags
--exec-prefix
and pass that as --with-python.

E.g.
bash$ cat $HOME/my-python-for-config
#! /bin/sh

if [ $# -ne 2 ]
then
echo "Bad # args.  Blech!" >&2
exit 1
fi

# The first argument is the path to python-config.py, ignore it.

case "$2" in
--includes) echo "-I/usr/include/python2.6 -I/usr/include/python2.6" ;;
--ldflags) echo "-L/usr/lib/python2.6/config -lpthread -ldl -lutil -lm
-lpython2.6" ;;
--exec-prefix) echo "/usr" ;;
*) echo "Bad arg $2.  Blech!" >&2 ; exit 1 ;;
esac

exit 0
bash$ ./configure --with-python=$HOME/my-python-for-config [...]
[...]


Note that --exec-prefix is the runtime location of python.
GCC uses this to tell libpython where to find its support files.
[grep for Py_SetProgramName in gdb/python/python.c]

>>> I understand the need for this, but as gdb requires Python 2, and users
>>> of my toolchain may have installed Python 3 or a 32-bit version python
>>> they want to use from the same environment (without changing their own
>>> PYTHONPATH), there is no way to run python-enabled gdb.
>>> [...]
>>
>> Yeah.
>> There is a proposal to add GDB_PYTHONPATH (or some such IIRC) and have
>> gdb use that instead of PYTHONPATH if it exists, but there's been
>> resistance to it.
>> I think(!) what would happen is that gdb would set $PYTHONPATH to the
>> value of $GDB_PYTHONPATH.
>> [Inferiors started by gdb should still get the original value of
>> PYTHONPATH though.]
>
> That way would be almost ideal, but a hardcoded *relative* path to the
> python scripts (that is standardized within gdb) wouldn't hurt.

See above re: --exec-prefix.

> An
> extra environment variable would require a lot of explaining for
> Windows, and is not "plug-and-play", like the rest of a sysrooted
> toolchain is supposed to be like. I think this should work on all
> setups:
>
> 1. Check hardcoded path; my suggestion would be " executable>/../lib/python27"
> 2. If this fails to find the necessary files/scripts, find it like you
> described above in Linux, without PYTHONPATH set.
> 3. Check PYTHONPATH.

The problem being solved by the proposed GDB_PYTHONPATH is "What if
the user has PYTHONPATH set and it points to an incompatible version
of python?".
Leaving such a value for PYTHONPATH set while gdb's python is running
feels wrong (and IIRC has caused some problems).

The problem of telling python where to find itself is already solved
(or at least is intended to be solved) with gdb's

Re: Python enabled gdb on Windows and relocation

2011-05-14 Thread Doug Evans
On Sat, May 14, 2011 at 2:29 AM, Eli Zaretskii  wrote:
>> Date: Sat, 14 May 2011 11:09:13 +0200
>> From: Ruben Van Boxem 
>> Cc: g...@sourceware.org, python-list@python.org
>>
>> 1. Check hardcoded path; my suggestion would be "> executable>/../lib/python27"
>> 2. If this fails to find the necessary files/scripts, find it like you
>> described above in Linux, without PYTHONPATH set.
>> 3. Check PYTHONPATH.
>>
>> I would think only number one would change, and perhaps be only
>> enabled with a special configure option. Nothing else would have to
>> change, and Windows users would rejoice :)
>
> The problem, I think, is that it's not so easy on Unix to get the
> place where the GDB executable leaves.  There isn't a system call to
> do that (similar to what Windows gives you).
>
> So I think on Posix platforms, number 2 would be used most of the
> time.

For reference sake, gdb is "relocatable".
[meaning, if you take a gdb installation and move it, it should
continue to work fine]
And if gdb's python lives inside the gdb tree, that too should
continue to work fine if moved with gdb (the value to pass to
Py_SetProgramName is appropriately (re-)computed when gdb is run).
[For completeness sake, IIRC the calculation of a path being
"relocatable" isn't bulletproof, but it works in practice.]

It's not impossible for gdb to find where it lives, but you're right
it can be moderately difficult (basically, if argv[0] isn't an
absolute path then scan $PATH for it).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python enabled gdb on Windows and relocation

2011-05-14 Thread Doug Evans
On Sat, May 14, 2011 at 11:30 AM, Doug Evans  wrote:
> Note that --exec-prefix is the runtime location of python.
> GCC uses this to tell libpython where to find its support files.
> [grep for Py_SetProgramName in gdb/python/python.c]

Oops.  s/GCC/GDB/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: threads with gtk gui problem

2011-05-14 Thread andy baxter

On 14/05/11 14:12, Andy Baxter wrote:

Hi,

I'm working on adding a Gtk GUI to a python program. Its main function 
is to read raw data from an arduino board over USB, and convert it to 
MIDI note/controller events to be sent to another program. I've had it 
working fine with just a command line interface, but when I replaced 
the command line with a Gtk interface, I started having problems 
getting the thread that reads the USB port to run.


I've solved this by adding 'import gobject' and 'gobject.threads_init()' 
to the start of the program. Looks like if you don't do this then the 
gtk main loop never releases the python threading lock to other threads.


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


Re: threads with gtk gui problem

2011-05-14 Thread andy baxter

On 14/05/11 14:12, Andy Baxter wrote:

Hi,

I'm working on adding a Gtk GUI to a python program. Its main function 
is to read raw data from an arduino board over USB, and convert it to 
MIDI note/controller events to be sent to another program. I've had it 
working fine with just a command line interface, but when I replaced 
the command line with a Gtk interface, I started having problems 
getting the thread that reads the USB port to run.


I'm not sure what the custom is on this list for pasting code - It's a 
long program so I don't want to paste the whole thing.


The sequence of events I've coded is:

- the program starts.
- the port reader thread (which is a threading.Thread subclass) is 
initialised.
- the object which controls the interface is initialised (i.e. the 
glade file is loaded.)
- the port reader is started (i.e. the 'start' method is called, which 
calls the 'run' method in a thread).

- then the gtk main loop is run.

The behaviour I'm getting is that the port reader either fails to 
start, or stops running at the point where it tries to initialise the 
serial port. It then does nothing until I close the main window, at 
which point it starts running again.


The port reader's run method begins like this:

   # the method called by the thread superclass to run the main loop 
of the thread.

   def run(self):
  # main loop of thread.
  print "Starting port reader."
  fhan=serial.Serial(port=keeper.config['usbPort'], 
baudrate=keeper.config['usbBaud'], timeout=0.1)

  print "1"
  fhan.open()
  print "2"
  seq=PySeq() # the sequencer library object
  port=seq.createOutPort(keeper.config['midiPortName']) # make a 
midi out port.

  midich=keeper.config['midich']
  print "3"
  while True:
 inbuf=[]
 print ".",
 char=fhan.read(1)
 if self.quit:
fhan.close()
return
 if len(char)==0: continue
 ... (code to process the character read in)

('keeper' is a global object which stores the config data and 
references to a few key objects).


When you start the program, the thread stops either before the first 
print statement, or on the line which initialises the serial port ( 
fhan=serial.Serial(...) ). '1', '2', and '3' only get printed /after/ 
you close the gtk main window.




I've verified that the problem is due to the gtk main loop interfering 
with the thread I've started. If I use this code:


if __name__ == "__main__":
   print "Starting mapper"
   keeper=Keeper() # initialise the keeper. (A global object which 
holds references to key objects)

   keeper.start() # tell the keeper to start the port reader.
   for n in xrange(10): # wait for 10 seconds.
  time.sleep(1)
  print "x"
   #gtk.main() # start the gtk main loop.
   keeper.stop() # tell the keeper to shut things down.

the program runs correctly. I.e. values are read from the usb port when 
they come in.


if I use this code:

if __name__ == "__main__":
   print "Starting mapper"
   keeper=Keeper() # initialise the keeper. (A global object which 
holds references to key objects)

   keeper.start() # tell the keeper to start the port reader.
   #for n in xrange(10):
   #   time.sleep(1)
   #   print "x"
   gtk.main() # start the gtk main loop.
   keeper.stop() # tell the keeper to shut things down.

The port reader thread blocks at the point it tries to open the serial 
port. I.e. 'Starting port reader' is printed straight away, but '1', 
'2', and '3'  are only printed after you close the gtk main window.


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


Re: turn monitor off and on

2011-05-14 Thread Terry Reedy

On 5/14/2011 3:20 AM, harrismh777 wrote:

harrismh777 wrote:


def turnOnMonitor():
SC_MONITORPOWER = 0xF170
win32gui.SendMessage(win32con.HWND_BROADCAST,
win32con.WM_SYSCOMMAND, SC_MONITORPOWER, -1)



I've never tried turning my monitor on/off without using my finger...


The computer cannot turn off the monitor. It can only tell the graphics 
card to turnoff the signal to the monitor. My monitor then displays 'No 
signal detected' in a box and puts itself into a low-power state 
awaiting a signal. Even if the monitor does not do that, a black screen 
should use less power.


Why the turnon does not work, if indeed it does not (and the monitor is 
not failing to respond to its resumption) is not a Python question. 2 
and -1 as off and on parameters is a bit strange. The OP might try a 
different api reference source or ask on a windows innards list.


--
Terry Jan Reedy

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


Re: How best to convert a string "list" to a python list

2011-05-14 Thread Terry Reedy

On 5/14/2011 4:41 AM, Nobody wrote:

On Fri, 13 May 2011 10:15:29 -0700, noydb wrote:


I want some code to take the items in a semi-colon-delimted string "list"
and places each in a python list.  I came up with below.  In the name of
learning how to do things properly, do you experts have a better way of
doing it?



x = "red;blue;green;yellow" ## string of semi-colon delimited colors


Provided that a semicolon is *always* a delimiter, just use the .split()
method:

color_list = x.split(";")

For more complex formats, where there are quote and/or escape characters
which allow the delimiter to occur as part of an item, you typically need
to use a regular expression to match everything up to the next delimiter,
and do this in a loop to extract the individual items.


Or, for some formats, use the cvs module.


--
Terry Jan Reedy

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


Re: unicode by default

2011-05-14 Thread Terry Reedy

On 5/14/2011 3:41 AM, harrismh777 wrote:

Terry Reedy wrote:



Easy, practical use of unicode is still a work in progress.


Apparently... the good news for me is that SBL provides their unicode
font here:

http://www.sbl-site.org/educational/biblicalfonts.aspx

I'm getting much closer here, but now the problem is typing. The pain
with unicode fonts is that the glyph is tied to the code point for the
represented character, and not tied to any code point that matches any
keyboard scan code for typing. :-}

So, I can now see the ancient text with accents and aparatus in all of
my editors, but I still cannot type any ancient Greek with my
keyboard... because I have to make up a keymap first. 

I don't find that SBL (nor Logos Software) has provided keymaps as
yet... rats.


You need what is called, at least with Windows, an IME -- Input Method 
Editor. These are part of (or associated with) the OS, so they can be 
used with *any* application that will accept unicode chars (in whatever 
encoding) rather than just ascii chars. Windows has about a hundred or 
so, including Greek. I do not know if that includes classical Greek with 
the extra marks.



I can read the test with Python though... ye.


--
Terry Jan Reedy

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


Re: Question about available python lib for a task

2011-05-14 Thread Terry Reedy

On 5/14/2011 11:11 AM, cesium5...@yahoo.ca wrote:


I would like to build a database of all the MS-Excel file on a LAN. I
would like to get the files metadata : filename, summary, location,
size, etc.


You subject line is about a non-specific as can be, which means that the 
person who can answer would not know and would likely skip over it. 
Something like


"Wanted: a module to catalog Excel files on a LAN"

would grab attention better.


Is there a dedicated python lib for the task? Is pywin32 one of the
possible lib available?


Sorry, I have no idea.

--
Terry Jan Reedy

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


Re: checking if a list is empty

2011-05-14 Thread Terry Reedy

On 5/14/2011 3:39 AM, Steven D'Aprano wrote:


Th money-quote as regards using arbitrary objects in truth tests:

 [quote]
 All this changed with the introduction of the two-element
 boolean domain {true, false} which provides the vocabulary
 needed to assign values to boolean expressions: 3<4 is a
 way for writing true, 3>4 is a way for writing false,
 whereas the value of x>0 depends on the value of x ...
 [end quote]


In Python, [1, 2, 3] is another way of writing true, and [] is another
way of writing false. Similarly with any other arbitrary objects.


Another way to look at it is that Python automatically calls bool() on 
every expression in its two boolean or conditional contexts: 'if e:' and 
'while e'. This is a boilerplate-removing, labor-saving convenience. 
Python has many such conveniences.


--
Terry Jan Reedy

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


Re: checking if a list is empty

2011-05-14 Thread Terry Reedy

On 5/14/2011 3:45 AM, rusi wrote:


(True = True) is False


is a syntax error ;-)

and 'True = True' is a (useless) statement,
and statements do not have boolean values,
and 'True == True' *is* True, which is to say,
((True == True) is False) is False.

--
Terry Jan Reedy

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


Re: Recursion or iteration (was Fibonacci series recursion error)

2011-05-14 Thread Ian Kelly
On Sat, May 14, 2011 at 11:24 AM, rusi  wrote:
> def fib(n):
>    if n==1 or n==2:
>        return 1
>    elif even(n):
>        return sq(fib (n//2)) + 2 * fib(n//2) * fib(n//2 - 1)
>    else:
>        return sq(fib (n//2 + 1)) + sq(fib(n // 2))
>
> This is a strange algo  -- logarithmic because it halves the n,
> exponential because of the double (triple) calls.  [I cannot say I
> know how to work out its exact complexity but I would guess its about
> linear]

Yup, linear.  Assuming you optimize the even case so that it doesn't
actually call fib(n//2) twice, the call tree can be approximated as a
balanced binary tree with height log(n).  The total number of nodes in
the tree is thus O(2 ** log(n)) = O(n).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: checking if a list is empty

2011-05-14 Thread Terry Reedy

On 5/14/2011 1:43 PM, rusi wrote:


But it seems you did not get the moral? Spelt out: "Beware of lossy
compression!"
[Which is also the moral of my 'proof']


I get it now. As I suggested in response to Stephen, [] and [1] spell 
False and True only in boolean contexts (if/while headers) where they 
are implicitly wrapped with a bool() call, which is to say, where their 
boolean value is extracted from them. As you point out, there is 
information loss as all other context-irrelevant details are ignored.


--
Terry Jan Reedy

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


Python drawing library?

2011-05-14 Thread OKB (not okblacke)
Is there any Python library for interactive drawing?  I've done 
some googling but most searches for "drawing" lead me to libraries for 
programmatic creation of shapes on some GUI canvas.  I'm looking for GUI 
widgets that allow the user to draw with the mouse, like a paint 
program, and let me get info about the drawing as its made (get color at 
mouse location, etc.).  I'd prefer a wxPython solution, although any 
Python solution would be better than none.

Thanks,
-- 
--OKB (not okblacke)
Brendan Barnwell
"Do not follow where the path may lead.  Go, instead, where there is
no path, and leave a trail."
--author unknown
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Converting a set into list

2011-05-14 Thread Ben Finney
TheSaint  writes:

> The example was to show that after having made a set
>
> set(aa)
>
> the need to get that set converted into a list.

As pointed out: you already know how to create a set from an object;
creating a list from an object is very similar:

list(set(aa))

But why are you doing that? What are you trying to achieve?

-- 
 \ “We are all agreed that your theory is crazy. The question that |
  `\  divides us is whether it is crazy enough to have a chance of |
_o__)being correct.” —Niels Bohr (to Wolfgang Pauli), 1958 |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: checking if a list is empty

2011-05-14 Thread Ben Finney
rusi  writes:

> [Steven quote]
> In Python, [1, 2, 3] is another way of writing true, and [] is another
> way of writing false. Similarly with any other arbitrary objects. The
> only things that bools True and False are good for are:
> 
> [end Steven quote]
> 
>
> So since
> [1,2,3] is one way of writing True (lets call it True3)

No. Steven knew exactly why he was using “true” versus “True”. He's
explained why elsewhere in this thread. The former does not refer to the
Python boolean singleton, the latter does.

The only object that is True is the True singleton. But there are many
objects that are true.

-- 
 \ “I got up the other day, and everything in my apartment has |
  `\   been stolen and replaced with an exact replica.” —Steven Wright |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unicode by default

2011-05-14 Thread Ben Finney
Terry Reedy  writes:

> You need what is called, at least with Windows, an IME -- Input Method
> Editor.

For a GNOME or KDE environment you want an input method framework; I
recommend IBus http://code.google.com/p/ibus/> which comes with the
major GNU+Linux operating systems http://oswatershed.org/pkg/ibus>
http://packages.debian.org/squeeze/ibus> .

Then you have a wide range of input methods available. Many of them are
specific to local writing systems. For writing special characters in
English text, I use either ‘rfc1345’ or ‘latex’ within IBus.

That allows special characters to be typed into any program which
communicates with the desktop environment's input routines. Yay, unified
input of special characters!

Except Emacs :-( which fortunately has ‘ibus-el’ available to work with
IBus http://www.emacswiki.org/emacs/IBusMode> :-).

-- 
 \ 己所不欲、勿施于人。|
  `\(What is undesirable to you, do not do to others.) |
_o__) —孔夫子 Confucius, 551 BCE – 479 BCE |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


I don't understand generator.send()

2011-05-14 Thread Victor Eijkhout
#! /usr/bin/env python

def ints():
i=0
while True:
yield i
i += 1

gen = ints()
while True:
i = gen.next()
print i
if i==5:
r = gen.send(2)
print "return:",r
if i>10:
break

I thought the send call would push the value "2" at the front of the
queue. Instead it coughs up the 2, which seems senseless to me.

1/ How should I view the send call? I'm reading the manual and dont' get
it
2/ Is there a way to push something in the generator object? So that it
becomes the next yield expression? In my code I was hoping to get
0,1,2,3,4,5,2,6,7 as yield expressions.

Victor.


-- 
Victor Eijkhout -- eijkhout at tacc utexas edu
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: turn monitor off and on

2011-05-14 Thread harrismh777

Terry Reedy wrote:

The computer cannot turn off the monitor.


... this was my point   ;-)


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


Re: I don't understand generator.send()

2011-05-14 Thread OKB (not okblacke)
Victor Eijkhout wrote:

> #! /usr/bin/env python
> 
> def ints():
> i=0
> while True:
> yield i
> i += 1
> 
> gen = ints()
> while True:
> i = gen.next()
> print i
> if i==5:
> r = gen.send(2)
> print "return:",r
> if i>10:
> break
> 
> I thought the send call would push the value "2" at the front of
> the queue. Instead it coughs up the 2, which seems senseless to me.
> 
> 1/ How should I view the send call? I'm reading the manual and
> dont' get it
> 2/ Is there a way to push something in the generator object? So
> that it becomes the next yield expression? In my code I was hoping
> to get 0,1,2,3,4,5,2,6,7 as yield expressions.

You can't usefully use send() unless the generator is set up to 
make use of the sent values.  You can't just push values into any old 
generator.  For it to do anything, you need to use assign the result of 
the yield to something within your generator and make use of it.  See 
http://docs.python.org/whatsnew/2.5.html#pep-342-new-generator-features 
for an example.

-- 
--OKB (not okblacke)
Brendan Barnwell
"Do not follow where the path may lead.  Go, instead, where there is
no path, and leave a trail."
--author unknown
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I don't understand generator.send()

2011-05-14 Thread Chris Angelico
On Sun, May 15, 2011 at 10:08 AM, Victor Eijkhout  wrote:
>        yield i

>        r = gen.send(2)

When you send() something to a generator, it becomes the return value
of the yield expression. See the example here:
http://docs.python.org/whatsnew/2.5.html#pep-342-new-generator-features

For what you're doing, there's a little complexity. If I understand,
you want send() to be like an ungetc call... you could do that like
this:


def ints():
   i=0
   while True:
   sent=(yield i)
   if sent is not None:
  yield None  # This becomes the return value from gen.send()
  yield sent  # This is the next value yielded
   i += 1

This lets you insert at most one value per iteration. Supporting more
than one insertion is more complicated, but changing the loop
structure entirely may help:

def ints():
i=0
queue=[]
while True:
if queue:  # see other thread, this IS legal and pythonic and
quite sensible
sent=(yield queue.pop(0))
else:
sent=(yield i)
i+=1
if sent is not None:
yield None  # This is the return value from gen.send()
queue.append(sent)

With this generator, you maintain a queue of sent values (if you want
it to be a LIFO stack rather than a FIFO queue, just change the pop(0)
to just pop()), and if the queue's empty, it produces sequential
integers. (Incidentally, the sent values don't have to be integers. I
leave it to you to decide whether that's any use or not.)

Hope that helps!

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


Re: I don't understand generator.send()

2011-05-14 Thread Chris Rebert
On Sat, May 14, 2011 at 5:08 PM, Victor Eijkhout  wrote:
> #! /usr/bin/env python
>
> def ints():
>    i=0
>    while True:
>        yield i
>        i += 1
>
> gen = ints()
> while True:
>    i = gen.next()
>    print i
>    if i==5:
>        r = gen.send(2)
>        print "return:",r
>    if i>10:
>        break
>
> I thought the send call would push the value "2" at the front of the
> queue. Instead it coughs up the 2, which seems senseless to me.
>
> 1/ How should I view the send call? I'm reading the manual and dont' get
> it

`yield` is an expression. Within the generator, the result of that
expression is [, ignoring the complications of .throw() etc.,] the
argument to .send(). You're currently using `yield` only as a
statement, so it's no wonder you're not quite understanding .send(). I
think this example should clarify things somewhat:

>>> def example(start):
... i = ord(start)
... while True:
... sent = (yield chr(i)) # Note use of yield as expression
... print('was sent', sent)
... i += 1
...
>>> g = example('a')
>>> g.send(3)
Traceback (most recent call last):
  File "", line 1, in 
TypeError: can't send non-None value to a just-started generator
>>> # Ok, so we can't send something back to `yield`
>>> # until we hit the first `yield`.
>>> g.send(None) # Follow the error message's advice
'a'
>>> g.send(3) # Let's try again now.
was sent 3
'b'
>>> g.send(5)
was sent 5
'c'
>>> g.send(9)
was sent 9
'd'
>>>

Cheers,
Chris
--
http://rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I don't understand generator.send()

2011-05-14 Thread Ian Kelly
On Sat, May 14, 2011 at 6:08 PM, Victor Eijkhout  wrote:
> I thought the send call would push the value "2" at the front of the
> queue. Instead it coughs up the 2, which seems senseless to me.
>
> 1/ How should I view the send call? I'm reading the manual and dont' get
> it

There is no queue unless you create one inside the generator.  The
generator by itself behaves more like a coroutine.

> 2/ Is there a way to push something in the generator object? So that it
> becomes the next yield expression? In my code I was hoping to get
> 0,1,2,3,4,5,2,6,7 as yield expressions.

This will do what you're asking for:

def ints():
i=0
while True:
next_yield = (yield i)
while next_yield is not None:
next_yield = (yield next_yield)
i += 1

However, I don't think this is what you want.  The send call returns a
yield expression, which will then be the value that you just passed
in, which seems a bit silly.  Probably you want something more like
this:

def ints():
i=0
while True:
next_yield = (yield i)
while next_yield is not None:
yield None
next_yield = (yield next_yield)
i += 1

Then the send() call will return None, and the next next() call will
return the value you passed in.  Note though that this is too simple
to work correctly if you call send() more than once before calling
next() again.

In general, I think it is a bad idea to mix calling next() and send()
on the same generator.  It makes the generator logic too complicated,
and I think it's better just to create a stateful iterator class
instead, where send() and next() are two entirely separate methods.

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


Re: I don't understand generator.send()

2011-05-14 Thread Ian Kelly
On Sat, May 14, 2011 at 6:47 PM, Chris Angelico  wrote:
> def ints():
>    i=0
>    queue=[]
>    while True:
>        if queue:  # see other thread, this IS legal and pythonic and
> quite sensible
>            sent=(yield queue.pop(0))
>        else:
>            sent=(yield i)
>            i+=1
>        if sent is not None:
>            yield None  # This is the return value from gen.send()
>            queue.append(sent)
>
> With this generator, you maintain a queue of sent values (if you want
> it to be a LIFO stack rather than a FIFO queue, just change the pop(0)
> to just pop()), and if the queue's empty, it produces sequential
> integers. (Incidentally, the sent values don't have to be integers. I
> leave it to you to decide whether that's any use or not.)

Actually, this won't work, because the value of the "yield None" gets
ignored.  Thus if you try to call send() twice in a row, the generator
the treats second send() as if it were a next(), and it is not
possible to have more than one item in the queue.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I don't understand generator.send()

2011-05-14 Thread Chris Angelico
On Sun, May 15, 2011 at 11:05 AM, Ian Kelly  wrote:
> Actually, this won't work, because the value of the "yield None" gets
> ignored.  Thus if you try to call send() twice in a row, the generator
> the treats second send() as if it were a next(), and it is not
> possible to have more than one item in the queue.

You're right. It needs a while loop instead of the if (and some slight
reordering):

def ints():
   i=0
   queue=[]
   while True:
   if queue:  # see other thread, this IS legal and pythonic and
quite sensible
   sent=(yield queue.pop(0))
   else:
   sent=(yield i)
   i+=1
   while sent is not None:
   queue.append(sent)
   sent=(yield None)  # This is the return value from gen.send()

That should work.

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


Re: I don't understand generator.send()

2011-05-14 Thread Victor Eijkhout
Chris Angelico  wrote:

> For what you're doing, there's a little complexity. If I understand,
> you want send() to be like an ungetc call... you could do that like
> this:
> 
> 
> def ints():
>i=0
>while True:
>sent=(yield i)
>if sent is not None:
>   yield None  # This becomes the return value from gen.send()
>   yield sent  # This is the next value yielded
>i += 1

I think this will serve my purposes.

Thanks everyone for broadening my understanding of generators.

Victor.
-- 
Victor Eijkhout -- eijkhout at tacc utexas edu
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Converting a set into list

2011-05-14 Thread Chris Torek
In article <871v00j2bh@benfinney.id.au>
Ben Finney   wrote:
>As pointed out: you already know how to create a set from an object;
>creating a list from an object is very similar:
>
>list(set(aa))
>
>But why are you doing that? What are you trying to achieve?

I have no idea why someone *else* is doing that, but I have used
this very expression to unique-ize a list:

>>> x = [3, 1, 4, 1, 5, 9, 2, 6]
>>> x
[3, 1, 4, 1, 5, 9, 2, 6]
>>> list(set(x))
[1, 2, 3, 4, 5, 6, 9]
>>>

Of course, this trick only works if all the list elements are
hashable.

This might not be the best example since the result is sorted
"by accident", while other list(set(...)) results are not.  Add
sorted() or .sort() if needed:

>>> x = ['three', 'one', 'four', 'one', 'five']
>>> x
['three', 'one', 'four', 'one', 'five']
>>> list(set(x))
['four', 'five', 'three', 'one']
>>> sorted(list(set(x)))
['five', 'four', 'one', 'three']
>>> 
-- 
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W)  +1 801 277 2603
email: gmail (figure it out)  http://web.torek.net/torek/index.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: checking if a list is empty

2011-05-14 Thread rusi
On May 15, 4:26 am, Ben Finney  wrote:
> rusi  writes:
> > [Steven quote]
> > In Python, [1, 2, 3] is another way of writing true, and [] is another
> > way of writing false. Similarly with any other arbitrary objects. The
> > only things that bools True and False are good for are:
> > 
> > [end Steven quote]
> > 
>
> > So since
> > [1,2,3] is one way of writing True (lets call it True3)
>
> No. Steven knew exactly why he was using “true” versus “True”. He's
> explained why elsewhere in this thread. The former does not refer to the
> Python boolean singleton, the latter does.
>
> The only object that is True is the True singleton. But there are many
> objects that are true.

Yes.
The python entities: {True, False} are not an exact (isomorphic) model
for the semantic boolean domain {true, false} (which is needed for
example to explicate the semantics of if while etc)  Which is to say
the boolean type in python is not first class.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyPad 2.7.1 (Update 2)

2011-05-14 Thread Bill Allen
Jon,

Looks very promising.  Seems to be an issue with interactive mode.  The
following code behaves as thus:

testvar=raw_input("enter value: ")
print testvar


When run, the prompt from raw_input does print to the output screen as:
enter value:


But when you tap in the lower window to enter the value for the input, the
app closes unexpected.  When I reopen it, what I was working on is still
present.

However, if I tap into the lower window and do this one line at a time from
the interactive prompt >>>, the above code works ok.

A problem?   Or am I missing something?

Anyway, I love this little Python app.   Been wanting something like this
for a long time.  I installed this on my iPhone running iOS 4.3.3 (8J2).

Congrats on a great app!

Bill Allen












On Thu, May 12, 2011 at 02:06, Jon D  wrote:

> Hi All,
>
> PyPad 2.7.1 Update 2 is now available on the AppStore. This is mainly
> a bug fix release addressing a number of issues with the interactive
> mode, but does also add some colour highlighting of output.
>
> PyPad is a port of the standard python code base to the iPad. It
> includes most of the standard python modules and can be used for
> testing small scripts or interactively for simple computation.
>
> Regards,
>
> Jon
> --
> http://mail.python.org/mailman/listinfo/python-announce-list
>
>Support the Python Software Foundation:
>http://www.python.org/psf/donations/
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I don't understand generator.send()

2011-05-14 Thread Ian Kelly
On Sat, May 14, 2011 at 7:17 PM, Chris Angelico  wrote:
> You're right. It needs a while loop instead of the if (and some slight
> reordering):
>
> def ints():
>   i=0
>   queue=[]
>   while True:
>       if queue:  # see other thread, this IS legal and pythonic and
> quite sensible
>           sent=(yield queue.pop(0))
>       else:
>           sent=(yield i)
>           i+=1
>       while sent is not None:
>           queue.append(sent)
>           sent=(yield None)  # This is the return value from gen.send()
>
> That should work.

Yeah, that should do it.  But this is so much easier to get right and
to understand:

import itertools

class Ints(object):

def __init__(self):
self.ints = itertools.count()
self.queue = []

def __iter__(self):
return self

def next(self):
if self.queue:
return self.queue.pop(0)
else:
return self.ints.next()

def insert(self, x):
self.queue.append(x)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Recursion or iteration (was Fibonacci series recursion error)

2011-05-14 Thread rusi
On May 15, 2:19 am, Ian Kelly  wrote:
> On Sat, May 14, 2011 at 11:24 AM, rusi  wrote:
> > def fib(n):
> >    if n==1 or n==2:
> >        return 1
> >    elif even(n):
> >        return sq(fib (n//2)) + 2 * fib(n//2) * fib(n//2 - 1)
> >    else:
> >        return sq(fib (n//2 + 1)) + sq(fib(n // 2))
>
> > This is a strange algo  -- logarithmic because it halves the n,
> > exponential because of the double (triple) calls.  [I cannot say I
> > know how to work out its exact complexity but I would guess its about
> > linear]
>
> Yup, linear.  Assuming you optimize the even case so that it doesn't
> actually call fib(n//2) twice, the call tree can be approximated as a
> balanced binary tree with height log(n).  The total number of nodes in
> the tree is thus O(2 ** log(n)) = O(n).

It would be linear if the base of the log were 2.
I am not sure it is.
You see the naive fib has a complexity which is fib itself. [Earlier
discussion with Steven]
fib is exponential but with radix < 2 [phi = (1 + sqrt(5))/2 ]
This would suggest that this algo is slightly better than linear.

But I have no idea of the exact complexity.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: checking if a list is empty

2011-05-14 Thread Steven D'Aprano
On Sat, 14 May 2011 00:45:29 -0700, rusi wrote:

> On May 14, 12:39 pm, Steven D'Aprano  +comp.lang.pyt...@pearwood.info> wrote:
>> On Thu, 12 May 2011 23:46:12 -0700, rusi wrote:
>> > Mathematics has existed for millenia. Hindu-arabic numerals (base-10
>> > numbers) have been known for about one millennium The boolean domain
>> > is only a 100 years old. Unsurprisingly it is not quite 'first-class'
>> > yet: See
>> >http://www.cs.utexas.edu/users/EWD/transcriptions/EWD10xx/EWD1070.html
>> > [Lifted fromhttp://c2.com/cgi/wiki?EqualVsTrueFalse]
>>
>> Th money-quote as regards using arbitrary objects in truth tests:
>>
>>     [quote]
>>     All this changed with the introduction of the two-element boolean
>>     domain {true, false} which provides the vocabulary needed to
>>     assign values to boolean expressions: 3<4 is a way for writing
>>     true, 3>4 is a way for writing false, whereas the value of x>0
>>     depends on the value of x ... [end quote]
>>
>> In Python, [1, 2, 3] is another way of writing true, and [] is another
>> way of writing false. Similarly with any other arbitrary objects.
> 
> Well so is [1,2] another way of writing True
> 
> And then we get the interesting result that (True = True) is False

I presume you mean to say:

([1, 2] == True) is False

that is, that one true value is not equal to another true value.

That is correct. However, Python's == operator is not a Boolean Algebra 
operator. If it were, it would probably be called "material 
biconditional", or XNOR, and written ↔ or <-> and would be smart enough 
to recognise that both [1, 2] and True are true.

Or possibly dumb enough... the difficulty is that the equality operator 
knows more about the objects than just their truth value.

And furthermore:

([1, 2] and True) == (True and [1, 2])

is also False, again because == is too smart to recognise that the left 
hand side (True) and the right hand side ([1, 2]) are both true values.

It's not that Python bools aren't first class objects, but that Python 
doesn't have a full set of all 16 possible boolean algebra operators.


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


Re: checking if a list is empty

2011-05-14 Thread Steven D'Aprano
On Sat, 14 May 2011 19:41:32 -0700, rusi wrote:

> The python entities: {True, False} are not an exact (isomorphic) model
> for the semantic boolean domain {true, false} (which is needed for
> example to explicate the semantics of if while etc)  Which is to say the
> boolean type in python is not first class.

I'm afraid I don't understand what you mean. Can you explain please, what 
properties of "first class booleans" do you think are missing from Python?



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