Re: Porting PEP 3148 to 2.x series

2010-09-17 Thread Brian Quinlan

On 18 Sep 2010, at 09:57, k3xji wrote:

Hi,

Is there any work on porting PEP 3148 back to 2.x series. That is a
wonderful PEP, any many long-running applications are really in need
of some stable library for handling stuff in async way just as
proposed in this PEP.



I'll probably port 3148 to Python 2.x after its running happily in  
Python 3.2.


But there is no chance that it will be included with the standard  
library in the 2.x series.


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


Re: socket.error: [Errno 98] Address already in use

2010-09-17 Thread Lawrence D'Oliveiro
In message 
<2f830099-4264-47bc-98ee-31950412a...@q21g2000prm.googlegroups.com>, cerr 
wrote:

> I get a socket error "[Errno 98] Address already in use" when i try to
> open a socket that got closed before with close(). How come close()
> doesn't close the socket properly?

The usual case this happens is you have a client connection open at the 
time, that was not properly terminated. Then the TCP stack goes through a 
holdoff period (2 minutes, I believe it is), to make absolutely sure all 
packets destined for the old connection have completely disappeared off the 
entire Internet, before it will let you open a socket on the same port 
again.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: WMI in Python

2010-09-17 Thread Lawrence D'Oliveiro
In message
<210f30c4-22da-405f-ad4b-cc46841ca...@p22g2000pre.googlegroups.com>, alex23 
wrote:

> Lawrence D'Oliveiro  wrote:
>
>> Because machine-generated
>> code has no place in a source file to be maintained by a human.
> 
> Endlessly repeating your bigotry doesn't make it any more true.

The point is that it is machine-generated from an input command, therefore 
it makes sense from a maintenance viewpoint to keep the input command, not 
the machine-generated output, in the source file, and simply generate the 
latter from the former as part of the build process.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [OS X 10.5] hitting TAB inserts ./ in interactive mode ?

2010-09-17 Thread Ned Deily
In article 
<431250b2-391e-4a1f-ba72-08afb7159...@l25g2000prn.googlegroups.com>,
 Nik Krumm  wrote:
> Thanks for your help. I installed python 2.7 on my Mac OS X 10.5.8
> machine:
> 
> 
> nik$ python
> Python 2.7 (r27:82508, Jul  3 2010, 21:12:11)
> [GCC 4.0.1 (Apple Inc. build 5493)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
> 
> and now, when I hit TAB or paste in a code snippet with tabs in them,
> the interpreter tries to autocomplete a path, or inserts "./" if the
> line is blank (just as readline would in the shell environment). It
> does *not* try to autocomplete function (as readline would in python--
> importing readline does turn on this functionality). And it does *not*
> insert a tab, as I would like it to!

See the rlcompleter module in the standard library:
http://docs.python.org/library/rlcompleter.html

In my .bashrc file, I have a line:
[ -f ~/.pythonrc ]  && export PYTHONSTARTUP=~/.pythonrc

and in the .pythonrc file, I include:

try:
import readline
except ImportError:
print("Module readline not available.")
else:
import rlcompleter
readline.parse_and_bind("tab: complete")

Note the print() form which works with either Python 2 or 3.

-- 
 Ned Deily,
 n...@acm.org

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


Why IterableUserDict?

2010-09-17 Thread Steven D'Aprano
I was writing some tests for a mapping class I have made, and I decided 
to run those same tests over dict and UserDict. The built-in dict passed 
all the tests, but UserDict failed one:

class SimpleMappingTest(unittest.TestCase):
type2test = UserDict.UserDict
def test_iter(self):
k, v = [0, 1, 2, 3], 'abcd'
m = self.type2test(zip(k, v))
it = iter(m)
self.assert_(iter(it) is it)
self.assertEquals(sorted(it), k)  # This line fails.
# many more tests

To cut a long story short, the problem is that UserDict doesn't support 
the modern iteration protocol. Python falls back on the old-fashioned 
__getitem__ iteration protocol, but since it expects IndexError rather 
than KeyError, iteration fails for UserDict once it hits key=4.

If I look at the source code for the UserDict module, I discover that 
there's a second mapping class, IterableUserDict, specifically to make 
UserDict iterable. To do this requires a single one-line method:

class IterableUserDict(UserDict):
def __iter__(self):
return iter(self.data)

This class was apparently added to the module in 2.2 -- it doesn't exist 
in 2.1.

Now that boggles my brain. Why was support for iteration added as a 
subclass, instead of simply adding the __iter__ method to UserDict? 
UserDict is supposed to be a drop-in replacement for dict (although the 
use-cases for it are much fewer now that we can inherit from dict), so it 
doesn't make sense to me to have a non-iterable UserDict plus a subclass 
which is iterable.

Can anyone shed any light on this apparently bizarre design decision?



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


Re: Too much code - slicing

2010-09-17 Thread Steven D'Aprano
On Fri, 17 Sep 2010 16:01:54 -0400, Andreas Waldenburger wrote:

> On Thu, 16 Sep 2010 16:20:33 -0400 AK  wrote:
> 
>> I also like this construct that works, I think, since 2.6:
>> 
>> code = dir[int(num):] if side == 'l' else dir[:-1*int(num)]
>> 
> I wonder when this construct will finally start to look good.


It looks good to me. It follows a common English idiom:

"What are you doing tonight?"
"I'll be going to the movies, if I finish work early, otherwise I'll stay 
home and watch a DVD."



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


Re: Porting PEP 3148 to 2.x series

2010-09-17 Thread Ben Finney
k3xji  writes:

> Is there any work on porting PEP 3148 back to 2.x series. That is a
> wonderful PEP, any many long-running applications are really in need
> of some stable library for handling stuff in async way just as
> proposed in this PEP.

Better would be to port those applications that would benefit to Python
3.x.

-- 
 \ “To stay young requires unceasing cultivation of the ability to |
  `\   unlearn old falsehoods.” —Robert Anson Heinlein |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Porting PEP 3148 to 2.x series

2010-09-17 Thread k3xji
Hi,

Is there any work on porting PEP 3148 back to 2.x series. That is a
wonderful PEP, any many long-running applications are really in need
of some stable library for handling stuff in async way just as
proposed in this PEP.

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


Re: Too much code - slicing

2010-09-17 Thread Bas
On Sep 17, 10:01 pm, Andreas Waldenburger 
wrote:
> On Thu, 16 Sep 2010 16:20:33 -0400 AK  wrote:
>
> > I also like this construct that works, I think, since 2.6:
>
> > code = dir[int(num):] if side == 'l' else dir[:-1*int(num)]
>
> I wonder when this construct will finally start to look good.


Using IFs is just plain ugly. Why not go for the much more pythonic

code = (lambda s:dir[slice(*(s*int(num),None)[::s])])(cmp('o',side))

Much easier on the eyes and no code duplication ... ;)

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


[OS X 10.5] hitting TAB inserts ./ in interactive mode ?

2010-09-17 Thread Nik Krumm
Hi all,

Thanks for your help. I installed python 2.7 on my Mac OS X 10.5.8
machine:


nik$ python
Python 2.7 (r27:82508, Jul  3 2010, 21:12:11)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

and now, when I hit TAB or paste in a code snippet with tabs in them,
the interpreter tries to autocomplete a path, or inserts "./" if the
line is blank (just as readline would in the shell environment). It
does *not* try to autocomplete function (as readline would in python--
importing readline does turn on this functionality). And it does *not*
insert a tab, as I would like it to!

If i start my old python 2.5 which came with the OS, this is not a
problem.

I've tried setting a PYTHONIOENCODING, but that doesn't seem to be
doing the job.

Any ideas? Thanks in advance.
~Nik
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SendKeys and Python 2.7

2010-09-17 Thread Jakson A. Aquino
> On Mon, Sep 13, 2010 at 4:02 PM, Michel Claveau - MVP
>  wrote:
>> Sorry for time, but I am very busy...
>>
>> With Python + Pywin32, you can force the activation of a window (before
>> send some keys...)
>> See:
>>  win32gui.SetForegroundWindow(w_handle)
>>
>> or
>>  win32gui.SetActiveWindow(w_handle)
>>
>>
>>
>> For to find a windows (and his handle), see:
>>  win32gui.EnumWindows()
>>  win32gui.GetWindowTex()
>> or
>>  win32gui.FindWindowEx()

I ended up using Dispatch("WScript.Shell") and AppActivate("R
Console") of the win32com.client module because they are higher level
functions. I guess that your code runs faster, but I don't have an old
machine to compare the performance of the two codes. I still may
switch to your code in the future, when I have easy access to a real
machine running Windows to make some tests. The released version of
the plugin is here:
http://www.vim.org/scripts/script.php?script_id=2628

Thanks for your help!

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


Re: How to make a web services in python ???

2010-09-17 Thread Hidura
What kind of web-service you have in mind

2010/9/17, Ariel :
> Hi everybody, I need some help to find documentation about how to implements
> web services in python, could you help me please ???
> Regards
> Thanks in advance
> Ariel
>

-- 
Enviado desde mi dispositivo móvil

Diego I. Hidalgo D.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: self-closing window with wxPython

2010-09-17 Thread Ian Kelly
On Fri, Sep 17, 2010 at 3:00 PM, Jabba Laci  wrote:

> Hi,
>
> > 2) I saw this in the documentation for Destroy() -- "Frames and dialogs
> are not destroyed immediately when this function is called -- they are added
> to a list of windows to be deleted on idle time, when all the window's
> events have been processed." That might be consistent with what you're
> seeing. The window you're trying to destroy has no events in its queue. WHen
> you move the mouse over it, the window processes those mouse events and then
> wx realizes, "Hey, this window has processed all of its events, and it's on
> the list of windows to be destroyed. I'd better get rid of it."
> >
> > If you're interested in experimenting, find a non-mouse way to force that
> window to process an event and I'll bet that would have the same effect as
> moving the mouse over it.
>
> Thanks for the hint, I could solve the problem. After Destroy() I
> added an extra event:
>
> self.parent.Destroy()
> self.parent.dc.SetFocus()
>
> As you suggested, the extra event triggers the queue processing and
> when it becomes empty the window gets destroyed.
>

You could also implement the alarm with a wxTimer instance that triggers a
wxTimerEvent, rather than creating a new thread for no good reason.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The trouble with "dynamic attributes".

2010-09-17 Thread Cameron Simpson
On 17Sep2010 10:53, Ethan Furman  wrote:
| Lie Ryan wrote:
| [snip]
| >And even dict-syntax is not perfect for accessing XML file, e.g.:
| >
| >
| >foo
| >bar
| >
| >
| >should a['b'] be 'foo' or 'bar'?
| 
| Attribute style access would also fail in this instance -- how is
| this worked-around?

I'd be inclined to go for ('foo', 'bar'), though that makes all the
single occurence nodes into sequences too, a bit cumbersome:-(
-- 
Cameron Simpson  DoD#743
http://www.cskk.ezoshosting.com/cs/

alt.skunks  A newsgroup for enthusiasts of skunks and other mustelidae.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: self-closing window with wxPython

2010-09-17 Thread Jabba Laci
Hi,

> 2) I saw this in the documentation for Destroy() -- "Frames and dialogs are 
> not destroyed immediately when this function is called -- they are added to a 
> list of windows to be deleted on idle time, when all the window's events have 
> been processed." That might be consistent with what you're seeing. The window 
> you're trying to destroy has no events in its queue. WHen you move the mouse 
> over it, the window processes those mouse events and then wx realizes, "Hey, 
> this window has processed all of its events, and it's on the list of windows 
> to be destroyed. I'd better get rid of it."
>
> If you're interested in experimenting, find a non-mouse way to force that 
> window to process an event and I'll bet that would have the same effect as 
> moving the mouse over it.

Thanks for the hint, I could solve the problem. After Destroy() I
added an extra event:

self.parent.Destroy()
self.parent.dc.SetFocus()

As you suggested, the extra event triggers the queue processing and
when it becomes empty the window gets destroyed.

Thanks,

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


How to make a web services in python ???

2010-09-17 Thread Ariel
Hi everybody, I need some help to find documentation about how to implements
web services in python, could you help me please ???
Regards
Thanks in advance
Ariel
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: parsing compact index files (*.cdx)

2010-09-17 Thread Ethan Furman

MRAB wrote:

On 17/09/2010 20:16, Ethan Furman wrote:

Greetings!

Does anybody have any pointers, tips, web-pages, already written
routines, etc, on parsing *.cdx files? I have found the pages on MS's
sight for Foxpro, but they neglect to describe the compaction algorithm
used, and my Google-fu has failed to find any sites with that 
information.


Any and all help greatly appreciated!


Have you seen this:

http://www.archive.org/web/researcher/cdx_file_format.php


I had not.  Unfortunately what I need are cdx files that are for dbf files.

Thanks anyway!

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


Re: Too much code - slicing

2010-09-17 Thread Andreas Waldenburger
On Thu, 16 Sep 2010 16:20:33 -0400 AK  wrote:

> I also like this construct that works, I think, since 2.6:
> 
> code = dir[int(num):] if side == 'l' else dir[:-1*int(num)]
> 
I wonder when this construct will finally start to look good.

/W


-- 
INVALID? DE!

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


Re: parsing compact index files (*.cdx)

2010-09-17 Thread Ethan Furman

Ethan Furman wrote:

Greetings!

Does anybody have any pointers, tips, web-pages, already written 
routines, etc, on parsing *.cdx files?  I have found the pages on MS's 
sight for Foxpro, but they neglect to describe the compaction algorithm 
used, and my Google-fu has failed to find any sites with that information.


Any and all help greatly appreciated!

--
~Ethan~


Oops -- compact index files are *.idx; compound index files are *.cdx; 
I believe they use the same algorithm, though, at least for Foxpro.


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


Re: parsing compact index files (*.cdx)

2010-09-17 Thread MRAB

On 17/09/2010 20:16, Ethan Furman wrote:

Greetings!

Does anybody have any pointers, tips, web-pages, already written
routines, etc, on parsing *.cdx files? I have found the pages on MS's
sight for Foxpro, but they neglect to describe the compaction algorithm
used, and my Google-fu has failed to find any sites with that information.

Any and all help greatly appreciated!


Have you seen this:

http://www.archive.org/web/researcher/cdx_file_format.php
--
http://mail.python.org/mailman/listinfo/python-list


parsing compact index files (*.cdx)

2010-09-17 Thread Ethan Furman

Greetings!

Does anybody have any pointers, tips, web-pages, already written 
routines, etc, on parsing *.cdx files?  I have found the pages on MS's 
sight for Foxpro, but they neglect to describe the compaction algorithm 
used, and my Google-fu has failed to find any sites with that information.


Any and all help greatly appreciated!

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


Re: self-closing window with wxPython

2010-09-17 Thread Philip Semanchuk

On Sep 17, 2010, at 12:05 PM, Jabba Laci wrote:

> Hi,
> 
> I'd like to create a simple alarm application that shows an alarm
> window. The application should shut down automatically after 5
> seconds. The problem is the following:
> * If I keep the mouse outside of the window, the application keeps
> running. Somehow self.Destroy() is not taken into account.
> * If the mouse is over the window and I keep moving it, the window closes.
> 
> I'm using Ubuntu Linux with wxPython 2.8. Below you can find what I have so 
> far.

Hi Laszlo,
It's difficult to help without a complete working example. But I have a few 
suggestions.

1) Why not call self.parent.Close()? It seems a bit more polite than .Destroy().

2) I saw this in the documentation for Destroy() -- "Frames and dialogs are not 
destroyed immediately when this function is called -- they are added to a list 
of windows to be deleted on idle time, when all the window's events have been 
processed." That might be consistent with what you're seeing. The window you're 
trying to destroy has no events in its queue. WHen you move the mouse over it, 
the window processes those mouse events and then wx realizes, "Hey, this window 
has processed all of its events, and it's on the list of windows to be 
destroyed. I'd better get rid of it." 

If you're interested in experimenting, find a non-mouse way to force that 
window to process an event and I'll bet that would have the same effect as 
moving the mouse over it.

3) Both the wxPython and wxWidgets mailing lists are probably better places to 
ask for help on wxPython.


Good luck
Philip



> 
> ==
> 
> class MyThread(threading.Thread):
>def __init__(self, parent):
>self.parent = parent
>threading.Thread.__init__(self)
> 
>def run(self):
>print time.time()# appears on stdout
>time.sleep(5)
>print time.time()# appears on stdout
> 
>self.parent.Destroy()# ??? doesn't work if the mouse is
> outside of the application window
> 
> class Alarm(wx.Frame):
>def __init__(self, title, *args):
>wx.Frame.__init__(self, None, -1, title, pos=(0, 0),
> size=(800, 600), *args)
> 
>self.sleepThread = MyThread(self)
>self.sleepThread.start()
> 
>self.Bind(wx.EVT_CLOSE, self.on_close)
> 
>def on_close(self, event):
>self.Destroy()
> 
> ==
> 
> To call it:
> 
> class Main(wx.PySimpleApp):
>def OnInit(self):
>self.frame = alarm.Alarm("Alarm 0.1")
>self.SetTopWindow(self.frame)
>self.SetExitOnFrameDelete(True)
>self.frame.Show()
>return True
> 
>a = Main()
>a.MainLoop()
> 
> =
> -- 
> http://mail.python.org/mailman/listinfo/python-list

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


Re: re.sub: escaping capture group followed by numeric(s)

2010-09-17 Thread Jon Clements
On 17 Sep, 19:59, Peter Otten <__pete...@web.de> wrote:
> Jon Clements wrote:
> > (I reckon this is probably a question for MRAB and is not really
> > Python specific, but anyhow...)
>
> > Absolutely basic example: re.sub(r'(\d+)', r'\1', 'string1')
>
> > I've been searching around and I'm sure it'll be obvious when it's
> > pointed out, but how do I use the above to replace 1 with 11?
> > Obviously I can't use r'\11' because there is no group 11. I know I
> > can use a function to do it, but it seems to me there must be a way
> > without. Can I escape r'\11' somehow so that it's group 1 with a '1'
> > after it (not group 11).
>
> Quoting
>
> http://docs.python.org/library/re.html#re.sub
>
> """
> In addition to character escapes and backreferences as described above,
> \g will use the substring matched by the group named name, as defined
> by the (?P...) syntax. \g uses the corresponding group number;
> \g<2> is therefore equivalent to \2, but isn’t ambiguous in a replacement
> such as \g<2>0. \20 would be interpreted as a reference to group 20, not a
> reference to group 2 followed by the literal character '0'. The
> backreference \g<0> substitutes in the entire substring matched by the RE.
> """
>
> Peter

Thanks Peter and MRAB. I must have been through the docs half a dozen
times and missed that - what a muppet! One of those days I guess...

Cheers,

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


Re: re.sub: escaping capture group followed by numeric(s)

2010-09-17 Thread Peter Otten
Jon Clements wrote:

> (I reckon this is probably a question for MRAB and is not really
> Python specific, but anyhow...)
> 
> Absolutely basic example: re.sub(r'(\d+)', r'\1', 'string1')
> 
> I've been searching around and I'm sure it'll be obvious when it's
> pointed out, but how do I use the above to replace 1 with 11?
> Obviously I can't use r'\11' because there is no group 11. I know I
> can use a function to do it, but it seems to me there must be a way
> without. Can I escape r'\11' somehow so that it's group 1 with a '1'
> after it (not group 11).

Quoting 

http://docs.python.org/library/re.html#re.sub

"""
In addition to character escapes and backreferences as described above, 
\g will use the substring matched by the group named name, as defined 
by the (?P...) syntax. \g uses the corresponding group number; 
\g<2> is therefore equivalent to \2, but isn’t ambiguous in a replacement 
such as \g<2>0. \20 would be interpreted as a reference to group 20, not a 
reference to group 2 followed by the literal character '0'. The 
backreference \g<0> substitutes in the entire substring matched by the RE.
"""

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


Re: re.sub: escaping capture group followed by numeric(s)

2010-09-17 Thread MRAB

On 17/09/2010 19:21, Jon Clements wrote:

Hi All,

(I reckon this is probably a question for MRAB and is not really
Python specific, but anyhow...)

Absolutely basic example: re.sub(r'(\d+)', r'\1', 'string1')

I've been searching around and I'm sure it'll be obvious when it's
pointed out, but how do I use the above to replace 1 with 11?
Obviously I can't use r'\11' because there is no group 11. I know I
can use a function to do it, but it seems to me there must be a way
without. Can I escape r'\11' somehow so that it's group 1 with a '1'
after it (not group 11).


re.sub(r'(\d+)', r'\g<1>', 'string1')
--
http://mail.python.org/mailman/listinfo/python-list


Re: SimpleHTTPServer, external CSS, and Google Chrome

2010-09-17 Thread MrJean1
FWIW,

There is a blue text on a red background in all 4 browsers Google
Chrome 6.0.472.59, Safari 5.0.1 (7533.17.8), FireFox 3.6.9 and IE
6.0.2900.5512 with Python 2.7 serving that page on my Windows XP
SP 3 machine.

/Jean

On Sep 16, 11:59 pm, Justin Ezequiel 
wrote:
> I am running "python -m SimpleHTTPServer 80" on Windows XP Pro SP 3
> (Python 2.5.4)
>
> browsinghttp://localhost/using IE8 and FireFox 3.6, I get blue text
> on red background
> on Google Chrome 6.0 however, I get blue text on white background
> placing index.htm and styles.css (see below) under IIS, I get blue
> text on red background for all browsers,
> including Google Chrome 6.0.
>
> I get exactly the same results when browsing from another machine.
> what's wrong? what do I need to change in SimpleHTTPServer?
>
> index.htm
> --
>     "http://www.w3.org/TR/html4/strict.dtd";>
> 
> 
> your title
> 
> 
> 
> body {
>     color: blue;}
>
> 
> 
> foo bar
> 
> 
> --
>
> styles.css
> --
> body {
>     background-color: red;}
>
> --

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


recording input/outputs, attributes and parameters of modules

2010-09-17 Thread Jojo Mwe
i would like to track all inputs/output to modules/functions -if a
module  retrieved and used files and run some analysis on them and
produced other files in return, i would like to take not of this. i.e
what i
want is to record all input sand outputs to a module. and also to
record all parameters, attribute vaules used by the same module and
also would like to know how one module calls another whether it
instantiates classes from one module etc

Any help will be highly appreciated..

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


re.sub: escaping capture group followed by numeric(s)

2010-09-17 Thread Jon Clements
Hi All,

(I reckon this is probably a question for MRAB and is not really
Python specific, but anyhow...)

Absolutely basic example: re.sub(r'(\d+)', r'\1', 'string1')

I've been searching around and I'm sure it'll be obvious when it's
pointed out, but how do I use the above to replace 1 with 11?
Obviously I can't use r'\11' because there is no group 11. I know I
can use a function to do it, but it seems to me there must be a way
without. Can I escape r'\11' somehow so that it's group 1 with a '1'
after it (not group 11).

Cheers,

Jon.

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


Re: The trouble with "dynamic attributes".

2010-09-17 Thread Ethan Furman

Lie Ryan wrote:
[snip]

And even dict-syntax is not perfect for accessing XML file, e.g.:


foo
bar


should a['b'] be 'foo' or 'bar'?


Attribute style access would also fail in this instance -- how is this 
worked-around?


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


Re: it doesn't work ;) [class recursive function]

2010-09-17 Thread Ethan Furman

MRAB wrote:

On 17/09/2010 17:55, Ethan Furman wrote:

MRAB wrote:

On 16/09/2010 00:23, Ethan Furman wrote:


PS
My apologies if this shows up twice, I haven't seen my other post yet
and it's been 27 hours.


That's probably because you sent it directly to me.


That would explain it -- like I said, it was still early for me!  :)

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


Re: it doesn't work ;) [class recursive function]

2010-09-17 Thread MRAB

On 17/09/2010 17:55, Ethan Furman wrote:

MRAB wrote:

On 16/09/2010 00:23, Ethan Furman wrote:


I need some fresh eyes, or better brains, or both!


'next_item' is a generator, but it's just calling itself and discarding
the result. I think it should be yielding the results to its caller.
That fix gives me 7 sections in total.


Thanks, M!

Some further reading on generators has helped clarify the issue for me.
I had forgotten that the initial call to a generator only sets it up,
and then returns the generator function itself, which then needs to be
iterated through.

Thanks for the reminder!

--
~Ethan~

Still early in the morning for me, so just in case I didn't phrase it
well, my thanks are sincere.

PS
My apologies if this shows up twice, I haven't seen my other post yet
and it's been 27 hours.


That's probably because you sent it directly to me.
--
http://mail.python.org/mailman/listinfo/python-list


Re: The trouble with "dynamic attributes".

2010-09-17 Thread Lie Ryan
On 09/17/10 07:46, John Nagle wrote:
>There's a tendency to use "dynamic attributes" in Python when
> trying to encapsulate objects from other systems.  It almost
> works.  But it's usually a headache in the end, and should be
> discouraged.  Here's why.

I personally love them, they makes XML files looks more like python objects.


foo
bar


being able to say:

if a.b == 'foo':
print a.c

is very convenient.

Yes, it doesn't work if the attribute contains special characters that
python doesn't recognize; but you shouldn't use these syntax if that's
the case. And even dict-syntax is not perfect for accessing XML file, e.g.:


foo
bar


should a['b'] be 'foo' or 'bar'?

So, personally I think both attribute-syntax and dict-syntax should
continue; it should be up to the programmer to determine whether the
limitations imposed by these syntaxes are suitable for their need (e.g.
if the programmer knows he would only use alphabet tag name, then
attr-style syntax is fine; and if he knows that there is no duplicate,
then dict-style syntax is fine as well; and if he can't rely on both,
then and only then, he'd be forced to do it the long way)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Debugger - fails to "continue" with breakpoint set

2010-09-17 Thread Lie Ryan
On 09/16/10 03:38, Ed Greenberg wrote:
> I'm pretty new to Python, but I am really enjoying it as an alternative
> to Perl and PHP.
> 
> When I run the debugger [import pdb; pdb.set_trace()] and then do next
> and step, and evaluate variables, etc, when I hit 'c' for continue, we
> go to the end, just fine.
> 
> As soon as I set a breakpoint down the line, [b ] the
> behavior of 'c' changes. Instead of continuing until the breakpoint, or
> until the end, if the breakpoint is hidden by a conditional, the
> debugger starts to treat 'c' as a step (or a next, I'm not sure which.)
> 
> This behavior is repeatable and consistent.
> 

can you write a test script and post its corresponding gdb session that
demonstrates what you meant?
-- 
http://mail.python.org/mailman/listinfo/python-list


Configuring logging for Web applications

2010-09-17 Thread Vinay Sajip
For those of you writing web applications and having multiple web
applications in the same Python process, if you are interesting in
using Python logging to write to web-application-specific logs, you
may be interested in this link:

http://plumberjack.blogspot.com/2010/09/configuring-logging-for-web.html

If you have any feedback on that post, please comment on that post
itself rather than here ;-)

Thanks and regards,

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


self-closing window with wxPython

2010-09-17 Thread Jabba Laci
Hi,

I'd like to create a simple alarm application that shows an alarm
window. The application should shut down automatically after 5
seconds. The problem is the following:
* If I keep the mouse outside of the window, the application keeps
running. Somehow self.Destroy() is not taken into account.
* If the mouse is over the window and I keep moving it, the window closes.

I'm using Ubuntu Linux with wxPython 2.8. Below you can find what I have so far.

Thanks,

Laszlo

==

class MyThread(threading.Thread):
def __init__(self, parent):
self.parent = parent
threading.Thread.__init__(self)

def run(self):
print time.time()# appears on stdout
time.sleep(5)
print time.time()# appears on stdout

self.parent.Destroy()# ??? doesn't work if the mouse is
outside of the application window

class Alarm(wx.Frame):
def __init__(self, title, *args):
wx.Frame.__init__(self, None, -1, title, pos=(0, 0),
size=(800, 600), *args)

self.sleepThread = MyThread(self)
self.sleepThread.start()

self.Bind(wx.EVT_CLOSE, self.on_close)

def on_close(self, event):
self.Destroy()

==

To call it:

class Main(wx.PySimpleApp):
def OnInit(self):
self.frame = alarm.Alarm("Alarm 0.1")
self.SetTopWindow(self.frame)
self.SetExitOnFrameDelete(True)
self.frame.Show()
return True

a = Main()
a.MainLoop()

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


Re: MySQL Query Problem

2010-09-17 Thread MRAB

On 17/09/2010 15:59, Victor Subervi wrote:

I rebooted MySQL and it now works fine ;)


I recommend that you always list the column names explicitly to be on
the safe side:

cursor.execute('insert into Passengers (flights_id, customer_id, 
name, sex , weight, price, round_trip, confirmation, late_fee, 
late_fee_paid) values (%s, %s, %s, %s, %s, %s, %s, %s, "no", "n/a")', 
(curr_flight, curr_customer, name, curr_sex, curr_weight, price, 
curr_rt, curr_confirmation))


[snip code]
--
http://mail.python.org/mailman/listinfo/python-list


Re: compile Py2.6 on SL

2010-09-17 Thread Aahz
In article <4c934f3c$0$5417$ba4ac...@reader.news.orange.fr>,
Michel Claveau - MVP  wrote:
>
>SL (SilverLight) is a library/techno who give functions.
>You cannot compile Python on SL (SilverLight).

SL (Snow Leopard) is a popular platform for Python development.  I
suppose this is another argument against TLAs.
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"The volume of a pizza of thickness 'a' and radius 'z' is
given by pi*z*z*a"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: MySQL Query Problem

2010-09-17 Thread Victor Subervi
I rebooted MySQL and it now works fine ;)

On Fri, Sep 17, 2010 at 9:26 AM, Victor Subervi wrote:

> Here's some more data:
>
> print 'insert into Passengers values (Null, %s, %s, %s, %s, %s, %s,
> %s, %s, "no", "n/a")' % (curr_flight, curr_customer, name, curr_sex,
> curr_weight, price, curr_rt, curr_confirmation)
>
> cursor.execute('insert into Passengers values (Null, %s, %s, %s,
> %s, %s, %s, %s, %s, "no", "n/a")', (curr_flight, curr_customer, name,
> curr_sex, curr_weight, price, curr_rt, curr_confirmation))
> database.commit()
> cursor.execute('select last_insert_id() from Passengers')
> last_insert_id = cursor.fetchone()[0]
> print 'update Passengers set name=%s, weight=%s where id=%s' %
> (name, curr_weight, last_insert_id)
> cursor.execute('update Passengers set name=%s, weight=%s where
> id=%s', (name, curr_weight, last_insert_id))
> database.commit()
>
> This prints out:
>
> insert into Passengers values (Null, 1, 1, Dr. Mengela, Male, 155, 100,
> 100, 654, "no", "n/a")
> update Passengers set name=Dr. Mengela, weight=155 where id=15
>
> Here's what's in the database:
>
> mysql> select * from Passengers;
>
> +++-+--+--++---++--+--+---+
> | id | flights_id | customer_id | name | sex  | weight | price | round_trip
> | confirmation | late_fee | late_fee_paid |
>
> +++-+--+--++---++--+--+---+
> |  1 |  1 |   1 | ''   | NULL |   NULL |  0.00 |  0
> | 12345| NULL | NULL  |
> | 15 |  1 |   1 | ''   | Male |   NULL |  0.00 |100
> | 654  | no   | n/a   |
>
> +++-+--+--++---++--+--+---+
> 2 rows in set (0.00 sec)
>
> mysql> describe Passengers;
>
> +---+---+--+-+-++
> | Field | Type  | Null | Key | Default |
> Extra  |
>
> +---+---+--+-+-++
> | id| int(11)   | NO   | PRI | NULL|
> auto_increment |
> | flights_id| int(11)   | NO   | MUL | NULL
> ||
> | customer_id   | int(11)   | NO   | MUL | NULL
> ||
> | name  | varchar(40)   | YES  | | NULL
> ||
> | sex   | enum('Male','Female') | YES  | | NULL
> ||
> | weight| int(11)   | YES  | | NULL
> ||
> | price | float(6,2)| NO   | | NULL
> ||
> | round_trip| tinyint(1)| NO   | | 1
> ||
> | confirmation  | varchar(20)   | YES  | | NULL
> ||
> | late_fee  | enum('no','yes')  | YES  | | no
> ||
> | late_fee_paid | enum('n/a','paid','not paid') | YES  | | n/a
> ||
>
> +---+---+--+-+-++
> 11 rows in set (0.00 sec)
>
> and when I run the update:
>
> mysql> select * from Passengers;
>
> +++-+-+--++---++--+--+---+
> | id | flights_id | customer_id | name| sex  | weight | price |
> round_trip | confirmation | late_fee | late_fee_paid |
>
> +++-+-+--++---++--+--+---+
> |  1 |  1 |   1 | ''  | NULL |   NULL |  0.00
> |  0 | 12345| NULL | NULL  |
> | 15 |  1 |   1 | Dr. Mengela | Male |155 |  0.00
> |100 | 654  | no   | n/a   |
>
> +++-+-+--++---++--+--+---+
> 2 rows in set (0.00 sec)
>
> Please explain why it does that!
> TIA,
> beno
>
>
> On Fri, Sep 17, 2010 at 8:51 AM, Victor Subervi 
> wrote:
>
>> Hi;
>> I have this code:
>>
>> cursor.execute('insert into Passengers values (Null, %s, %s, %s,
>> %s, %s, %s, %s, %s, "no", "n/a")', (curr_flight, curr_customer, name,
>> curr_sex, curr_weight, price, curr_rt, curr_confirmation))
>>
>> Now, when I print it out, add quotes where necessary and enter it in at a
>> mysql prompt, all goes well. But when I do it this way, it enters null
>> values for curr_customer and curr_weight! Same darn thing printed out works
>> at the prompt. What gives?
>> TIA,
>> beno
>>
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Compiling SWIG Extensions With VC2008 and VC2010 Both Installed

2010-09-17 Thread ElMariachi

I am attempting to compile a SWIG extension library for QuantLib
(www.quantlib.org) on Windows 7 running Python 2.6. 

2.6 needs VC2008 to compile extensions yet distutils cannot find this
version, is there a way I can specify that this version be used? Currently,
when I attempt a build, I get a lot of the following errors:

python setup.py build 
running build 
running build_py 
running build_ext 
building 'QuantLib._QuantLib' extension 
C:\Python26\Scripts\gcc.exe -mno-cygwin -mdll -O -Wall -IC:\Python26\include
-IC:\Python26\PC -c QuantLib/quantlib_wrap.cpp -o build 
QuantLib/quantlib_wrap.cpp:3423:26: ql/version.hpp: No such file or
directory 
QuantLib/quantlib_wrap.cpp:3424: error: `QL_HEX_VERSION' was not declared in
this scope 
QuantLib/quantlib_wrap.cpp:3425: error: `QL_VERSION' was not declared in
this scope 
QuantLib/quantlib_wrap.cpp:3484:27: ql/quantlib.hpp: No such file or
directory 
QuantLib/quantlib_wrap.cpp:3487:6: #error using an old version of QuantLib,
please update 
QuantLib/quantlib_wrap.cpp:3874:48: boost/algorithm/string/case_conv.hpp: No
such file or directory 
QuantLib/quantlib_wrap.cpp:3878: error: `QuantLib' has not been declared 
QuantLib/quantlib_wrap.cpp:3878: error: expected nested-name-specifier
before "Error" 
QuantLib/quantlib_wrap.cpp:3878: error: `Error' has not been declared 
QuantLib/quantlib_wrap.cpp:3879: error: `QuantLib' has not been declared 
QuantLib/quantlib_wrap.cpp:3879: error: expected nested-name-specifier
before "Handle" 
QuantLib/quantlib_wrap.cpp:3879: error: `Handle' has not been declared 
QuantLib/quantlib_wrap.cpp:3880: error: `QuantLib' has not been declared 
QuantLib/quantlib_wrap.cpp:3880: error: expected nested-name-specifier
before "RelinkableHandle" 
QuantLib/quantlib_wrap.cpp:3880: error: `RelinkableHandle' has not been
declared 
QuantLib/quantlib_wrap.cpp:3883: error: `QuantLib' has not been declared 
QuantLib/quantlib_wrap.cpp:3883: error: expected nested-name-specifier
before "Integer" 
QuantLib/quantlib_wrap.cpp:3883: error: `Integer' has not been declared 
QuantLib/quantlib_wrap.cpp:3884: error: `QuantLib' has not been declared 
QuantLib/quantlib_wrap.cpp:3884: error: expected nested-name-specifier
before "BigInteger" 
QuantLib/quantlib_wrap.cpp:3884: error: `BigInteger' has not been declared
-- 
View this message in context: 
http://old.nabble.com/Compiling-SWIG-Extensions-With-VC2008-and-VC2010-Both-Installed-tp29739343p29739343.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Re: WMI in Python

2010-09-17 Thread alex23
Lawrence D'Oliveiro  wrote:
> Because machine-generated
> code has no place in a source file to be maintained by a human.

Endlessly repeating your bigotry doesn't make it any more true.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Too many threads

2010-09-17 Thread mark . pelletier
On Sep 17, 1:38 am, Ned Deily  wrote:
> In article <20100917052259.ga28...@cskk.homeip.net>,
>  Cameron Simpson  wrote:
>
>
>
>
>
> > On 16Sep2010 22:14, Ned Deily  wrote:
> > | In article <20100917043826.ga21...@cskk.homeip.net>,
> > |  Cameron Simpson  wrote:
> > |
> > | > On 16Sep2010 09:55, mark.pellet...@asrcms.com 
> > 
> > | > wrote:
> > | > | For some reason, the tasks I put into my thread pool occasionally get
> > | > | run more than once.
> > | > |
> > | > | Here's the code:
> > | >
> > | > You need to post your _exact_ code. I had to change:
> > | >   from queue import Queue
> > | > into
> > | >   from Queue import Queue
> > | > So: _do_ you have a "queue" (lowercase) module? Is it buggy?
> > |
> > | The OP is probably using Python 3.
>
> > Ah, that explains the print(). Anyone know if print() is thread safe in
> > python 3?
>
> I vaguely recalled a similar problem and, on the second try, found it:
>
> http://bugs.python.org/issue6750
>
> Looks like that fix should have been in Python 3.1.2.
>
> --
>  Ned Deily,
>  n...@acm.org- Hide quoted text -
>
> - Show quoted text -

I was a little surprised at my problems, as I cribbed the code from

http://docs.python.org/py3k/library/queue.html?highlight=queue#queue.Queue.put

But in the end, yeah it does look like a thread-safe problem with
print.  I tried replacing the print statement by using another queue,
and it worked just fine.  Glad to know that it's fixed in 3.1.2; of
course, I am running 3.1.1.  Doesn't matter, the print statement was
just for demonstration purposes.  I'm actually going to put a
subprocess.getoutput() there.  Wonder if that's thread safe?

Thanks, Cameron and Ned
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: MySQL Query Problem

2010-09-17 Thread Victor Subervi
Here's some more data:

print 'insert into Passengers values (Null, %s, %s, %s, %s, %s, %s,
%s, %s, "no", "n/a")' % (curr_flight, curr_customer, name, curr_sex,
curr_weight, price, curr_rt, curr_confirmation)
cursor.execute('insert into Passengers values (Null, %s, %s, %s, %s,
%s, %s, %s, %s, "no", "n/a")', (curr_flight, curr_customer, name, curr_sex,
curr_weight, price, curr_rt, curr_confirmation))
database.commit()
cursor.execute('select last_insert_id() from Passengers')
last_insert_id = cursor.fetchone()[0]
print 'update Passengers set name=%s, weight=%s where id=%s' %
(name, curr_weight, last_insert_id)
cursor.execute('update Passengers set name=%s, weight=%s where
id=%s', (name, curr_weight, last_insert_id))
database.commit()

This prints out:

insert into Passengers values (Null, 1, 1, Dr. Mengela, Male, 155, 100, 100,
654, "no", "n/a")
update Passengers set name=Dr. Mengela, weight=155 where id=15

Here's what's in the database:

mysql> select * from Passengers;
+++-+--+--++---++--+--+---+
| id | flights_id | customer_id | name | sex  | weight | price | round_trip
| confirmation | late_fee | late_fee_paid |
+++-+--+--++---++--+--+---+
|  1 |  1 |   1 | ''   | NULL |   NULL |  0.00 |  0
| 12345| NULL | NULL  |
| 15 |  1 |   1 | ''   | Male |   NULL |  0.00 |100
| 654  | no   | n/a   |
+++-+--+--++---++--+--+---+
2 rows in set (0.00 sec)

mysql> describe Passengers;
+---+---+--+-+-++
| Field | Type  | Null | Key | Default |
Extra  |
+---+---+--+-+-++
| id| int(11)   | NO   | PRI | NULL|
auto_increment |
| flights_id| int(11)   | NO   | MUL | NULL
||
| customer_id   | int(11)   | NO   | MUL | NULL
||
| name  | varchar(40)   | YES  | | NULL
||
| sex   | enum('Male','Female') | YES  | | NULL
||
| weight| int(11)   | YES  | | NULL
||
| price | float(6,2)| NO   | | NULL
||
| round_trip| tinyint(1)| NO   | | 1
||
| confirmation  | varchar(20)   | YES  | | NULL
||
| late_fee  | enum('no','yes')  | YES  | | no
||
| late_fee_paid | enum('n/a','paid','not paid') | YES  | | n/a
||
+---+---+--+-+-++
11 rows in set (0.00 sec)

and when I run the update:

mysql> select * from Passengers;
+++-+-+--++---++--+--+---+
| id | flights_id | customer_id | name| sex  | weight | price |
round_trip | confirmation | late_fee | late_fee_paid |
+++-+-+--++---++--+--+---+
|  1 |  1 |   1 | ''  | NULL |   NULL |  0.00
|  0 | 12345| NULL | NULL  |
| 15 |  1 |   1 | Dr. Mengela | Male |155 |  0.00
|100 | 654  | no   | n/a   |
+++-+-+--++---++--+--+---+
2 rows in set (0.00 sec)

Please explain why it does that!
TIA,
beno

On Fri, Sep 17, 2010 at 8:51 AM, Victor Subervi wrote:

> Hi;
> I have this code:
>
> cursor.execute('insert into Passengers values (Null, %s, %s, %s,
> %s, %s, %s, %s, %s, "no", "n/a")', (curr_flight, curr_customer, name,
> curr_sex, curr_weight, price, curr_rt, curr_confirmation))
>
> Now, when I print it out, add quotes where necessary and enter it in at a
> mysql prompt, all goes well. But when I do it this way, it enters null
> values for curr_customer and curr_weight! Same darn thing printed out works
> at the prompt. What gives?
> TIA,
> beno
>
-- 
http://mail.python.org/mailman/listinfo/python-list


MySQL Query Problem

2010-09-17 Thread Victor Subervi
Hi;
I have this code:

cursor.execute('insert into Passengers values (Null, %s, %s, %s, %s,
%s, %s, %s, %s, "no", "n/a")', (curr_flight, curr_customer, name, curr_sex,
curr_weight, price, curr_rt, curr_confirmation))

Now, when I print it out, add quotes where necessary and enter it in at a
mysql prompt, all goes well. But when I do it this way, it enters null
values for curr_customer and curr_weight! Same darn thing printed out works
at the prompt. What gives?
TIA,
beno
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: compile Py2.6 on SL

2010-09-17 Thread Jason Swails
On Fri, Sep 17, 2010 at 7:21 AM, Michel Claveau - MVP
 wrote:

> Hello!
>
> SL (SilverLight) is a library/techno who give functions.
> You cannot compile Python on SL (SilverLight).
>

I think the original thread meant Snow Leopard (the latest Mac OS X)


>
> @-salutations
> --
> Michel Claveau
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Jason M. Swails
Quantum Theory Project,
University of Florida
Ph.D. Graduate Student
352-392-4032
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: compile Py2.6 on SL

2010-09-17 Thread Michel Claveau - MVP
Hello!

SL (SilverLight) is a library/techno who give functions.
You cannot compile Python on SL (SilverLight).

@-salutations
-- 
Michel Claveau 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Very stupid question about a % symbol

2010-09-17 Thread Xavier Ho
On 17 September 2010 12:48, Terry Reedy  wrote:

> Doubling an escape char, whatever it is, is a common convention:
> >>> print("Print a {{}} format string line this: {{{}}}".format(2))
> Print a {} format string line this: {2}
>

Wow. That's convoluted. Took me a minute to process.

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


Re: Very stupid question about a % symbol

2010-09-17 Thread Steven D'Aprano
On Thu, 16 Sep 2010 11:25:06 -0400, J wrote:

> OK, this is a very stupid question about a very simple topic, but Google
> is failing me this morning...
[...]

Others have already answered your question, but for future reference, 
many people won't bother to read posts with a meaningless subject line 
like "Very stupid question about ...". 

Very stupid questions invite very stupid answers. I guess you can be 
grateful that this Python group is more friendly than the average tech 
group, otherwise you might have got no answers at all, or a sarcastic 
one. Besides, your actual question isn't stupid at all. It is a sensible, 
although basic, question.

A better subject line would have been:

"How to insert percent sign in % format strings?"

or some variation thereof. This will also be of benefit to others, who 
some day may be Googling for the answer to the same question.


Regards,



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


Re: program organization question for web development with python

2010-09-17 Thread Bruno Desthuilliers

Hans a écrit :
(snip)


Maybe I did not make my question clear. I never tried python web
programing before, so I want to start from CGI.


You can indeed learn quite a few things doing raw CGI - the most 
important one being why frameworks are a good idea !-)



I read something about web framework like django, but seems it's a
little bit complicated.


Not that much IMHO, but being an early django user I'm probably a bit 
biased. Now Python is known as "the language with more web frameworks 
than keywords", so you could probably check some lighter framework like 
 web.py (http://webpy.org/) or flask (http://flask.pocoo.org/).



my task is actually very simple: get search
string from input, and then search database, print search result. I
thought CGI should be good enough to do this.


CGI is "good enough" to do any web stuff - just like assembler is "good 
enough" to write any application !-)



I don't have any idea about how to organize those cgi codes, so what
I'm asking is:

1. do I have to have each single file for each hyper-link? Can I put
them together? how?

>

2. how can I pass a db_cursor to another file?   can I use db_cursor as
a parameter?


Obviously not. FWIW, both questions show a lack of understanding of the 
HTTP protocol, and you can't hope to do anything good in web programming 
if you don't understand at least the basics of the HTTP protocol, 
specially the request/response cycle.


Now for a couple more practical answers:

There are basically two ways to organize your url => code mapping:
1/ have only one cgi script and use querystring params to tell which 
action should be executed.

2/ have one cgi script per action.

The choice is up to you. For a simple app like yours, the first solution 
is probably the most obvious : always display the seach form, if the 
user submitted the form also display the result list. That's how google 
works (wrt/ user interface I mean).


Now if you still need / want to have distinct scripts and want to factor 
out some common code, you just put the common code in a module that you 
import from each script.

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


Re: Embedded Systems development using Python

2010-09-17 Thread VGNU Linux
Hi All,
Appreciate your response.
Now I am going to use Telit Module GE865-QUAD with support for GPS and GPRS
capabilities.
It also has built-in python interpreter for developing application for the
module.
But still I have no idea which microprocessor/microcontroller to use.
Can anyone help me out here ? Is there any microprocessor/microcontroller
which I could use with Python and Telit module?
Any help here will be appreciated.

Regards,
VGNU

On Mon, Sep 6, 2010 at 8:54 PM, Grant Edwards wrote:

> 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
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: data structure suggestion (native python datatypes or sqlite; compound select)

2010-09-17 Thread Vlastimil Brom
2010/9/17 MRAB :
> On 17/09/2010 00:56, Vlastimil Brom wrote:
>>
>> 2010/9/17 MRAB:
>>>
>>> On 16/09/2010 23:11, Vlastimil Brom wrote:

 ...
 I put together some code, which works as expected, but I suspect
 somehow, that there must be better ways of doing it.

 Two things I am not quite clear about are using the placeholders for
 the data identifiers and "chaining" the SELECT parameters.

 I Couldn't find a way to use "?" placeholder for table or column
 names, hence I ended up using string interpolation for them and
 placeholders for the data values, like.
 curs.execute('SELECT * FROM "%s" WHERE "%s"==?' % (text_name,
 index_col), (text_index,))
 is there a better way or is it not supposed to supply these
 identifiers programatically?

>>> You would normally expect the structure of the database to be fixed and
>>> only the contents to vary.
>>>
 For getting the matching text indices given the tags, tag_values
 combination I ended up with a clumsy query:

 combined_query_list = ['SELECT "%s" FROM "%s" WHERE "%s"==?' %
 (index_col, text_name, tag) for tag in tags]
 sql_query = " INTERSECT ".join(combined_query_list)
 curs.execute(sql_query, tag_values)

 which produces e.g.:
 SELECT "ind" FROM "n" WHERE "KC"==? INTERSECT SELECT "ind" FROM "n"
 WHERE "VN"==?

 or alternatively:

 select_begin = 'SELECT "%s" FROM "%s" WHERE ' % (index_col, text_name)
 where_subquery = " AND ".join('"%s"==?' % (tag,) for tag in tags)
 sql_query = select_begin + where_subquery

 with the resulting query string like:
 SELECT "ind" FROM "n" WHERE "KC"==? AND "VN"==? ('12', '1')

 (BTW, are these queries equivalent, as the outputs suggest, or are
 there some distinctions to be aware of?)

 Anyway, I can't really believe, this would be the expected way ...

>>> If you're selecting rows of a table then using 'AND' would seem the
>>> obvious way.
>>>
>>>
>> Thanks for the answer,
>> Well, that may be a part of the problem, the database structure is
>> going to be fixed once I'll have the text sources complete, but I was
>> trying to keep it more general, also allowing the identifiers to be
>> passed programmatically (based on the tagged text in question).
>>
>> yes, I am just selecting rows - based on the combination of the column
>> values (which, I guess, might be an usual database approach(?).
>> However, I was unsure, whether it is usual to construct the query
>> string this way - partly using string interpolation or sequence
>> joining.
>> Or should there normally be no need for construct like the above and I
>> am doing something wrong in a more general sense?
>>
> In general you'd have a fixed database structure and fixed queries.
> You'd design it so that you wouldn't have different columns for
> different tagged texts, forcing you to change the database structure
> when texts were added or removed, but no-one will come around to your
> house to stop you creating queries dynamically. :-)
> --
> http://mail.python.org/mailman/listinfo/python-list
>
Ok, thanks for confirming my suspicion :-),
Now I have to decide whether I shall use my custom data structure,
where I am on my own, or whether using an sql database in such a
non-standard way has some advantages...
The main problem indeed seems to be the fact, that I consider the
tagged texts to be the primary storage format, whereas the database is
only means for accessing it more conveniently.

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


SimpleHTTPServer, external CSS, and Google Chrome

2010-09-17 Thread Justin Ezequiel
I am running "python -m SimpleHTTPServer 80" on Windows XP Pro SP 3
(Python 2.5.4)

browsing http://localhost/ using IE8 and FireFox 3.6, I get blue text
on red background
on Google Chrome 6.0 however, I get blue text on white background
placing index.htm and styles.css (see below) under IIS, I get blue
text on red background for all browsers,
including Google Chrome 6.0.

I get exactly the same results when browsing from another machine.
what's wrong? what do I need to change in SimpleHTTPServer?

index.htm
--
http://www.w3.org/TR/html4/strict.dtd";>


your title



body {
color: blue;
}


foo bar


--

styles.css
--
body {
background-color: red;
}
--
-- 
http://mail.python.org/mailman/listinfo/python-list