Re: Unable to execute the script

2012-08-11 Thread Hans Mulder
On 11/08/12 00:48:38, Dennis Lee Bieber wrote:
> On Fri, 10 Aug 2012 12:35:06 -0700, Smaran Harihar
>  declaimed the following in
> gmane.comp.python.general:
> 
>> Hi Tim,
>>
>> this is the output for the ls -lsF filename
>>
>> 8 -rwxr-xr-x 1 root root 5227 Jul 30 13:54 iplantgeo_cgi.py*
>>
>   
> 
>   A CGI script owned by root?

Why not?

It's not setuid, so being owned by root does not give it
any special privileges.

> What "user" does your web server run as?
> I'd recommend setting that user as the owner of the CGI script.

That's definitely a bad idea.  More so if it's writeable by its
owner, as is the case here.  It would mean that if a security
hole allows intruders to write to arbitrary files, then they
can overwrite this script and that would allow them to execute
arbitrary code.

-- HansM

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


Re: [Newbie] How to wait for asyncronous input

2012-08-11 Thread pozz

Il 11/08/2012 01:12, Dennis Lee Bieber ha scritto:

What you apparently missed is that serial.read() BLOCKs until data
is available (unless the port was opened with a read timeout set).
[...]

serial.read() may, there for, be using select() behind the scenes.


Hmm..., so I could open the serial port with timeout=0 so the read(), 
that runs in a different thread, would block forever, so putting the 
thread in a sleep state until some bytes arrive.


When the main thread wants to close the serial port, the receiving 
thread can be killed (I don't know why, but I think it will be possible).


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


Re: [c-api]Transmutation of an extension object into a read-only buffer adding an integer in-place.

2012-08-11 Thread Giacomo Alzetta
Il giorno sabato 11 agosto 2012 08:40:18 UTC+2, Stefan Behnel ha scritto:
> Giacomo Alzetta, 11.08.2012 08:21:
> 
> > I'd prefer to stick to Python and C, without having to put cython
> 
> > sources or cython-generated c modules (which I know are almost
> 
> > completely unreadable from a human point of view. Or at least the ones I
> 
> > saw).
> 
> 
> 
> And the cool thing is: you don't have to read them. :)
> 
> 
> 
> Stefan

Yes, but since all this code will end-up in the hands of some examiner, he'll 
have to read them. :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [c-api]Transmutation of an extension object into a read-only buffer adding an integer in-place.

2012-08-11 Thread Stefan Behnel
Giacomo Alzetta, 11.08.2012 10:55:
> Il giorno sabato 11 agosto 2012 08:40:18 UTC+2, Stefan Behnel ha scritto:
>> Giacomo Alzetta, 11.08.2012 08:21:
>>
>>> I'd prefer to stick to Python and C, without having to put cython
>>> sources or cython-generated c modules (which I know are almost
>>> completely unreadable from a human point of view. Or at least the ones I
>>> saw).
>>
>> And the cool thing is: you don't have to read them. :)
> 
> Yes, but since all this code will end-up in the hands of some examiner, he'll 
> have to read them. :)

I'd just ask him what he prefers: beautiful Python code with a couple of
static type declarations in it, or verbose C code with lots of C-isms and
C-API-isms all over the place. If he's smart enough, he'll force you into
writing the code in Cython.

Stefan


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


Re: [Newbie] How to wait for asyncronous input

2012-08-11 Thread Hans Mulder
On 11/08/12 09:07:51, pozz wrote:
> Il 11/08/2012 01:12, Dennis Lee Bieber ha scritto:
>> What you apparently missed is that serial.read() BLOCKs until data
>> is available (unless the port was opened with a read timeout set).
>> [...]
>>
>> serial.read() may, there for, be using select() behind the scenes.
> 
> Hmm..., so I could open the serial port with timeout=0 so the read(),
> that runs in a different thread, would block forever, so putting the
> thread in a sleep state until some bytes arrive.
> 
> When the main thread wants to close the serial port, the receiving
> thread can be killed


How would you do that?

IFAIK, there is no way in Python to kill a thread.


The usual work-around is to have a global flag that you'd set
to True when the main thread wants to close the port.  The read
would have a timeout of 1 second of so, so that the reading
thread is woken up every second, so it can check that flag and
wind up when the flag is set.


Hope this helps,

-- HansM

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


~~** Unique Floral, Neckline, 4x4 Ornament Embroidery Designs F.R.E.E.!! **~~

2012-08-11 Thread Mohamed Gad
Unique Floral Design .. F.R.E.E

http://www.embroworld.com/embroidery/4x4-floral-design-132/

Unique Neckline Embroidery Design .. F.R.E.E

http://www.theembroidery.com/unique-neckline-embroidery-design-136/

4x4 Ornament Embroidery Design .. F.R.E.E

http://www.embrohome.com/details.php?image_id=74


Enjoy Our New F.R.E.E.B.I.E.S.

SUPPORT ME!!
Nanees
http://www.book-mall.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Xlib: watching key presses without trapping them

2012-08-11 Thread Raffaele Ricciardi

Hello there,

I'm writing a X Windows program to perform some actions when modifier 
keys have

been released.  After looking into the Pykeylogger project
(pykeylogger.sourceforge.net), I've gone as far as detecting all events 
related
to modifiers, but then such events get trapped by the program and do not 
reach

other applications.

I'm using Python 2.7.3.  Thanks for your help.

Here it is the program:

#! /usr/bin/env python

from Xlib.display import Display
from Xlib import X

Control_R  = 64  # Keycode for right Control.
Control_L  = 108 # Keycode for left Control.
# Keycodes we are listening for.  I've left out Right Control
# to be able to stop the program.
keycodes = [Control_L]

# Handle X events.
def handle_event(event):
# Let us know whether this event is about a Key Release of
# one of the keys in which we are interested.
if event.type == X.KeyRelease:
keycode = event.detail
if keycode in keycodes:
print "KeyRelease"

# Objects needed to call Xlib.
display = Display()
root = display.screen().root

# Tell the X server we want to catch KeyRelease events.
root.change_attributes(event_mask = X.KeyReleaseMask)

# Grab those keys.
for keycode in keycodes:
root.grab_key(keycode, X.AnyModifier, 1, X.GrabModeAsync, 
X.GrabModeAsync)


# Event loop.
while 1:
event = root.display.next_event()
handle_event(event)

# End of program.
--
http://mail.python.org/mailman/listinfo/python-list


Re: [Newbie] How to wait for asyncronous input

2012-08-11 Thread Steven D'Aprano
On Sat, 11 Aug 2012 11:24:48 +0200, Hans Mulder wrote:

> On 11/08/12 09:07:51, pozz wrote:

>> When the main thread wants to close the serial port, the receiving
>> thread can be killed
> 
> 
> How would you do that?
> 
> IFAIK, there is no way in Python to kill a thread.

Correct.

> The usual work-around is to have a global flag that you'd set to True
> when the main thread wants to close the port.  The read would have a
> timeout of 1 second of so, so that the reading thread is woken up every
> second, so it can check that flag and wind up when the flag is set.

It doesn't need to be a global flag. You can make the flag an attribute 
of the thread, and then have the thread check self.flag.


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


Re: save dictionary to a file without brackets.

2012-08-11 Thread Steven D'Aprano
On Fri, 10 Aug 2012 08:53:43 +1000, Chris Angelico wrote:

> On Fri, Aug 10, 2012 at 8:26 AM, Dave Angel  wrote:
>> On 08/09/2012 06:03 PM, Andrew Cooper wrote:
>>> O(n) for all other entries in the dict which suffer a hash collision
>>> with the searched entry.
>>>
>>> True, a sensible choice of hash function will reduce n to 1 in common
>>> cases, but it becomes an important consideration for larger datasets.
>>
>> I'm glad you're wrong for CPython's dictionaries.  The only time the
>> lookup would degenerate to O[n] would be if the hash table had only one
>> slot.  CPython sensibly increases the hash table size when it becomes
>> too small for efficiency.
>>
>> Where have you seen dictionaries so poorly implemented?
> 
> In vanilla CPython up to version (I think) 3.3, where it's possible to
> DoS the hash generator. Hash collisions are always possible, just
> ridiculously unlikely unless deliberately exploited.

Not so unlikely actually.

py> hash(3)
3
py> hash(2**64 + 2)
3

py> hash(-1)
-2
py> hash(-2)
-2


By its very nature, a hash function cannot fail to have collisions. The 
problem is that in general you have an essentially unlimited number of 
objects being mapped to a large but still finite number of hash values.



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


Re: Xlib: watching key presses without trapping them

2012-08-11 Thread Steven D'Aprano
On Sat, 11 Aug 2012 10:53:37 +0100, Raffaele Ricciardi wrote:

> Hello there,
> 
> I'm writing a X Windows program to perform some actions when modifier
> keys have
> been released.  After looking into the Pykeylogger project
> (pykeylogger.sourceforge.net), I've gone as far as detecting all events
> related
> to modifiers, but then such events get trapped by the program and do not
> reach
> other applications.


Questions about specialised modules like Pykeylogger will have a much 
better chance of being answered if you ask in a dedicated Pykeylogger 
forum. If there is none, try emailing the author.

If you do get an answer elsewhere, please consider passing it on here so 
others can learn about it too.

Have you looked at how GUIs like wxPython and Tkinter handle key events? 
That might help.


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


in-place exponentiation incongruities

2012-08-11 Thread Giacomo Alzetta
I've noticed some incongruities regarding in-place exponentiation.

On the C side nb_inplace_power is a ternary function, like nb_power (see here: 
http://docs.python.org/c-api/typeobj.html?highlight=numbermethods#PyNumberMethods).

Obviously you can't pass the third argument using the usual in-place syntax 
"**=".
Nevertheless I'd expect to be able to provide the third argument using 
operator.ipow. But the operator module accept only the two parameter variant.

The Number Protocol specify that the ipow operation ""is the equivalent of the 
Python statement o1 **= o2 when o3 is Py_None, or an in-place variant of 
pow(o1, o2, o3) otherwise.""

Since "operator" claims to be contain a "function port" of the operators, I'd 
expect it to implement ipow with three arguments.
I don't see any problem in adding the third argument to it(I mean, sure right 
now any code that calls ipow(a,b,c) [if exists] is broken, because it will just 
raise a TypeError, thus adding the argument will not break any code, and would 
provide more functionality.

Also, I don't think there are many objects in the build-ins or standardlib 
which implement an in-place exponentiation, so this means there wont be much 
code to change.

So my question is: why are there this incongruities?
Is there any chance to see this fixed? (in the operator module, or changing the 
documentation)

By the way: I'm asking this because I'm implementing a C-extension and I'd like 
to implement both pow and ipow. And since it's about polynomials on 
(Z/nZ)[x]/x^r-1, using the third argument always makes sense.
-- 
http://mail.python.org/mailman/listinfo/python-list


Arithmetic with Boolean values

2012-08-11 Thread John Ladasky
I have gotten used to switching back and forth between Boolean algebra and 
numerical values.  Python generally makes this quite easy.  I just found a case 
that surprises me.

Here is what I want to accomplish:  I want to process a list.  If the length of 
the list L is odd, I want to process it once.  If len(L) is even, I want to 
process it twice.  I thought I would set up a loop as follows:

for x in range(1 + not(len(L) % 2)):
# Do stuff

This provoked a SyntaxError.  I investigated this further with my interpreter 
(ipython).

In [1]: L = range(5)

In [2]: L
Out[2]: [0, 1, 2, 3, 4]

In [3]: len(L)
Out[3]: 5

In [4]: len(L) % 2
Out[4]: 1

In [5]: not(1)
Out[5]: False

In [6]: not(len(L) % 2)
Out[6]: False

In [7]: 1 + not(len(L) % 2)

   File "", line 1
 1 + not(len(L) % 2)
   ^
SyntaxError: invalid syntax

So as you can see, every thing is working fine until I attempt to add 1 and 
False.  However:

In [8]: 0 == False
Out[8]: True

In [9]: 1 == True
Out[9]: True

So, 0 and False do pass an equivalency test, as do 1 and True.  Furthermore:

In [10]: 1 + (len(L) % 2 == 0)
Out[10]: 1

Why is using a logical "not" function, as shown in [7], returning a different 
result than the test for equivalency as shown in [10]?

Of course I'm just going to use [10] in my program, but I'd like to understand 
the reason that I'm getting that SyntaxError.  I've been reading Python style 
guides, and at least one of them states a preference for using the "not" syntax 
over the "== 0" syntax.

I'm using Python 2.7, in case it matters.
-- 
http://mail.python.org/mailman/listinfo/python-list


Does anyone have an activate script for portable python?

2012-08-11 Thread Gelonida N

Hi,


In Pythons installed with virtualenv there is on windows an activate.bat 
script, that can be used to setup the cmd-shell such, that the search 
path for python and pythor elated tools (pip / easy_install) is setup 
properly.


Further there is the deactivate script to set the environment back to 
it's state before calling activate.


Do such a scripts also exist for Portable python?


If anybody wrote already such scripts, then couldn't they be added to 
the official portable python release?


I never used portable python so far but can't imagine, that I'm the only 
one who'd like such a script.




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


Idle no longer works

2012-08-11 Thread Opap-OJ
I can no longer open the Idle IDE for Python on Windows 7.

For 3-5 years I used Idle for all my python work.  But in January this happens:

When I right click on a python file and choose "open with Idle" nothing happens.

If I double-click on the file itself, it briefly opens an MS-DOS looking 
window, then closes it immediately.

I tried installing Eclipse with PyDev.  It opens the file, but will not run it 
in Python.

Any idea why?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Arithmetic with Boolean values

2012-08-11 Thread Chris Angelico
On Sun, Aug 12, 2012 at 8:30 AM, John Ladasky
 wrote:
> In [7]: 1 + not(len(L) % 2)
> 
>File "", line 1
>  1 + not(len(L) % 2)
>^
> SyntaxError: invalid syntax

This appears to be a limitation of the parser; it's trying to
interpret "not" as a binary operator.

1 + (not(len(L) % 2))

Works just fine with parentheses to enforce the correct interpretation.

This also works in Python 3.2, fwiw (except that you need
list(range(5)) to create the sample list).

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


Re: Arithmetic with Boolean values

2012-08-11 Thread Chris Rebert
On Sat, Aug 11, 2012 at 3:30 PM, John Ladasky
 wrote:

> for x in range(1 + not(len(L) % 2)):
> # Do stuff
>
> This provoked a SyntaxError.  I investigated this further with my interpreter 
> (ipython).

> In [5]: not(1)
> Out[5]: False
>
> In [6]: not(len(L) % 2)
> Out[6]: False
>
> In [7]: 1 + not(len(L) % 2)
> 
>File "", line 1
>  1 + not(len(L) % 2)
>^
> SyntaxError: invalid syntax

> Why is using a logical "not" function, as shown in [7], returning a different 
> result than the test for equivalency as shown in [10]?

Note that, in Python, `not` is an unary operator (it's a language
keyword in fact), as opposed to a function:
Python 2.7.2 (default, Jun 20 2012, 16:23:33)
>>> len("abc")
3
>>> # functions are first-class entities in Python, so we can reference them
>>> len

>>> not(1)
False
>>> # but `not` isn't a function
>>> not
  File "", line 1
not
  ^
SyntaxError: invalid syntax
>>> # hence why we don't need to call it
>>> not 1
False

The parentheses in `not(foo)` are just grouping the `foo`
subexpression; they're not indicating a function call. Therefore, in
idiomatic Python, such parentheses are omitted whenever possible
(which is the majority of the time), and when they are absolutely
necessary, a space is included before the opening paren, because we're
not making a function call.

Thus, you're simply running into an operator precedence issue, which,
as Chris A. explained, can be remedied by adding grouping parens
around the entire `not` expression; e.g. `(not foo)`

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


Running Python web apps on shared ASO servers?

2012-08-11 Thread Gilles
Hello

I use A Small Orange (ASO) as my web provider. Asking the question in
their forum so far didn't work, so I figured I might have a faster
answer by asking here.

Support replied this in an old thread: "Just a CGI option. We don't
have enough users to justify adding mod_python support."
http://forums.asmallorange.com/topic/4672-python-support/page__hl__python
http://forums.asmallorange.com/topic/4918-python-fcgi-verses-mod-python/

Does it mean that ASO only supports writing Python web apps as
long-running processes (CGI, FCGI, WSGI, SCGI) instead of embedded
Python à la PHP?

If that's the case, which smallest tool would you recomment to write
basic apps, eg. handling forms, etc.?

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


Re: Arithmetic with Boolean values

2012-08-11 Thread Terry Reedy

On 8/11/2012 7:13 PM, Chris Angelico wrote:

On Sun, Aug 12, 2012 at 8:30 AM, John Ladasky
 wrote:

In [7]: 1 + not(len(L) % 2)

File "", line 1
  1 + not(len(L) % 2)
^
SyntaxError: invalid syntax


This appears to be a limitation of the parser; it's trying to
interpret "not" as a binary operator.


I think not. It is lower precedence than all arithmetic operators. The 
following is worth knowing about and occasionally reviewing.

http://docs.python.org/py3k/reference/expressions.html#summary

() around % is not needed; not len(L) % 2 works same. So parser sees

1 + not len(L) % 2

with + given higher precedence than not, So it parses as (1 + not) and 
croaks, as indicated by caret. (We humans see that that is impossible 
and may boost the precedence in context.)



1 + (not(len(L) % 2))


== 1 + (not len(L) % 2)


Works just fine with parentheses to enforce the correct interpretation.

This also works in Python 3.2, fwiw (except that you need
list(range(5)) to create the sample list).


--
Terry Jan Reedy

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


Re: Arithmetic with Boolean values

2012-08-11 Thread Chris Angelico
On Sun, Aug 12, 2012 at 10:25 AM, Terry Reedy  wrote:
> On 8/11/2012 7:13 PM, Chris Angelico wrote:
>> This appears to be a limitation of the parser; it's trying to
>> interpret "not" as a binary operator.
>
> I think not. It is lower precedence than all arithmetic operators.
> (We humans see that that is impossible and
> may boost the precedence in context.)

Ah, I stand corrected. And once again, I kinda expected Python to
follow the rules of my mental parser :)

Anyway, point stands that parens will fix the issue.

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


Re: Idle no longer works

2012-08-11 Thread Benjamin Kaplan
On Sat, Aug 11, 2012 at 4:09 PM, Opap-OJ  wrote:
> I can no longer open the Idle IDE for Python on Windows 7.
>
> For 3-5 years I used Idle for all my python work.  But in January this 
> happens:
>
> When I right click on a python file and choose "open with Idle" nothing 
> happens.
>
> If I double-click on the file itself, it briefly opens an MS-DOS looking 
> window, then closes it immediately.
>
> I tried installing Eclipse with PyDev.  It opens the file, but will not run 
> it in Python.
>
> Any idea why?
> --

Have you tried launching Python from the Command Prompt? Open up
command prompt and run C:\Python32\python.exe or whatever corresponds
to your version of Python.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Arithmetic with Boolean values

2012-08-11 Thread MRAB

On 11/08/2012 23:30, John Ladasky wrote:

I have gotten used to switching back and forth between Boolean algebra and 
numerical values.  Python generally makes this quite easy.  I just found a case 
that surprises me.

Here is what I want to accomplish:  I want to process a list.  If the length of 
the list L is odd, I want to process it once.  If len(L) is even, I want to 
process it twice.  I thought I would set up a loop as follows:

for x in range(1 + not(len(L) % 2)):
 # Do stuff

This provoked a SyntaxError.  I investigated this further with my interpreter 
(ipython).

In [1]: L = range(5)

In [2]: L
Out[2]: [0, 1, 2, 3, 4]

In [3]: len(L)
Out[3]: 5

In [4]: len(L) % 2
Out[4]: 1

In [5]: not(1)
Out[5]: False

In [6]: not(len(L) % 2)
Out[6]: False

In [7]: 1 + not(len(L) % 2)

File "", line 1
  1 + not(len(L) % 2)
^
SyntaxError: invalid syntax

So as you can see, every thing is working fine until I attempt to add 1 and 
False.  However:

In [8]: 0 == False
Out[8]: True

In [9]: 1 == True
Out[9]: True

So, 0 and False do pass an equivalency test, as do 1 and True.  Furthermore:

In [10]: 1 + (len(L) % 2 == 0)
Out[10]: 1

Why is using a logical "not" function, as shown in [7], returning a different 
result than the test for equivalency as shown in [10]?

Of course I'm just going to use [10] in my program, but I'd like to understand the reason that I'm 
getting that SyntaxError.  I've been reading Python style guides, and at least one of them states a 
preference for using the "not" syntax over the "== 0" syntax.

I'm using Python 2.7, in case it matters.

I think the problem is that "not" isn't a function as such - it doesn't 
require parentheses, for example.


The relevant syntax rules are:

a_expr ::= m_expr | a_expr "+" m_expr | a_expr "-" m_expr

m_expr ::= u_expr | m_expr "*" u_expr | m_expr "//" u_expr | m_expr "/"
u_expr | m_expr "%" u_expr

u_expr ::= power | "-" u_expr | "+" u_expr | "~" u_expr

power ::= primary ["**" u_expr]

primary ::= atom | attributeref | subscription | slicing | call

atom ::= identifier | literal | enclosure

enclosure ::= parenth_form | list_display | dict_display | set_display | 
generator_expression | yield_atom


call ::= primary "(" [argument_list [","] | comprehension] ")"

In order for your code to work I think we would need to have something 
like this:


primary ::= atom | attributeref | subscription | slicing | call | not_expr

not_expr ::= "not" parenth_form

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


suggesting a launcher wrapper script for portable python

2012-08-11 Thread Gelonida N
I just started looking at portable Python and was rather surprised, that 
I didn't find any recommended method in the documentation of how to

launch scripts with portable python.
Creating py2exe scripts on ones own USB drive seems to be kind of overkill.

So here my own thoughts / suggestsions.
I'm interestted in feedback of how others use portable pythons
and how they run their scripts from a USB stick.


Let's assume I install portable python on my USB drive and then I'd like 
to store self written python scripts on this drive.


It would of course be greate if I could just click on the script and 
they'd be started.



However under windows this would not be the case.
The python script would either not be started at all or if the PC had 
his own python installed, then the script would be started with the PC's 
version of python.


Thus a tiny wrapper script would be needed.


Suggestion:
--
The current directory structore for portable python (2.7) is (assuming 
that %PP% is the base directory)


%PP%/Python-Portable.exe   # launches the python interactive shell
%PP%/PyScripter-Portable.exe   # launches some IDE
%PP%/App

Let's assume I add two more directories:
%PP%/myscripts# location of all callable scripts
%PP%/launchers# location with icons one can click on
  # to start the scripts in myscripts




if I wrote a script named %PP%/myscripts/test1.py,
and I created an aproprriate  named %PP%/launchers/test1.bat

then I could just click on test1.bat and the Python script test1.py 
would be started. If the wrapper script is written properly, then it can 
look at its own base name and call the related python script.


If I dragged and dropped some filenames on the bat file, then they would 
be passed to sys.argv of the script.


Running the script from command line would also work and the present 
working directory would be preserved (which might be useful in some cases)


If the script name would not be .py, but .pyw then it woudl be started 
with pythonw.

T

Below suggested script:



@echo off
REM 
=

REM script to start a python file with portable python
REM 
=


REM basepath of this .bat file
set basepath=%~dp0

REM create the name of the python file related to this bat file
REM Unfortunately I do not know how to normalyze %pyfile%,
REM so we got stuck with the '..'
set pyfile=%basepath%..\myscripts\%~n0.py

If EXIST "%pyfile%" (
REM a normal console python file with .py suffix
"%basepath%\..\App\python.exe" "%pyfile%"  %*
) ELSE (
If EXIST "%pyfile%w" (
REM a non  console python file with .pyw suffix
start "" "%basepath%\..\App\pythonw.exe" "%pyfile%w"  %*
) ELSE (
REM found neither a .py nor a .pyw file
echo found no python file %pyfile%
)
)
REM 
=

REM end of script
REM 
=



One minor drawback of my suggested script would be, that a console 
window pops up for a few seconds when starting a .pyw file.


This could be avoided by using either a small compiled C-file (which 
sounds like overkill though)

or by writing a windows scripting host .wsf file.
However I don't know this well enough to replicate my batch file.
AN article on SO mentions how to write such a script.
However it does not parse command line arguments nor does it
automatically determine the scripts file name.
So any help for creating a .wsf file starting a .pyw file with command 
line arguments would be appreciated.




An alternativce approach could be to provide a scipt named
mk_wrapper.bat
If one drags and drops a python script on it, then an apropriate wrapper 
file would be created in the launcher directory.


If well done, then this could be implemented such, that the script may 
be located in an arbitrary location on the same USB drive.




I think it would be great if the official portable python release 
contained some upport for launching scripts.

Perhaps it exists alrady and I just didn't find it?

If not,then I wouldn't mind if my script or a similiar sand a related 
README.txt cript were added to the official release









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


Re: Arithmetic with Boolean values

2012-08-11 Thread Paul Rubin
John Ladasky  writes:
> I have gotten used to switching back and forth between Boolean algebra
> and numerical values.  Python generally makes this quite easy. 

Generally ugly though, at least to my tastes.  "Explicit is better
than implicit" as the saying goes.

> If the length of the list L is odd, I want to process it once.  If
> len(L) is even, I want to process it twice
>   for x in range(1 + not(len(L) % 2)):

If you really have to do something like that, I'd say

   for x in range(1 + (len(L) & 1)):

or

   for x in range(2 - len(L) % 2): 

are simpler and avoid those bogus bool conversions.  I'd prefer to
just say the intention:

   for x in range(1 if len(L)%2==1 else 2):

> This provoked a SyntaxError. 

"not" is a syntactic keyword and "1 + not" is syntactically invalid.
You could write "1 + (not ...)" as you discovered, but really, it's
hackish.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Idle no longer works

2012-08-11 Thread Terry Reedy

On 8/11/2012 7:09 PM, Opap-OJ wrote:

I can no longer open the Idle IDE for Python on Windows 7.

For 3-5 years I used Idle for all my python work.  But in January
this happens:

When I right click on a python file and choose "open with Idle"
nothing happens.

If I double-click on the file itself, it briefly opens an MS-DOS
looking window, then closes it immediately.


That should run the file and discard the output. Above is typical


Any idea why?


*Something* very specific to your system changed. Either registry 
associations for .py are screwed, or your Python installation is 
damaged. Easiest fix is to uninstall and re-install Python. But download 
a more recent version first. Uninstall might not be needed, but makes 
process more like to work.


In the regular interactive command prompt interpreter

import idlelib.idle

should start idle.


--
Terry Jan Reedy

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


Re: in-place exponentiation incongruities

2012-08-11 Thread Steven D'Aprano
On Sat, 11 Aug 2012 09:54:56 -0700, Giacomo Alzetta wrote:

> I've noticed some incongruities regarding in-place exponentiation.
> 
> On the C side nb_inplace_power is a ternary function, like nb_power (see
> here:
> http://docs.python.org/c-api/typeobj.html?
highlight=numbermethods#PyNumberMethods).
> 
> Obviously you can't pass the third argument using the usual in-place
> syntax "**=". Nevertheless I'd expect to be able to provide the third
> argument using operator.ipow. But the operator module accept only the
> two parameter variant.

Why? The operator module implements the ** operator, not the pow() 
function. If you want the pow() function, you can just use it directly, 
no need to use operator.pow or operator.ipow.

Since ** is a binary operator, it can only accept two arguments.


> The Number Protocol specify that the ipow operation ""is the equivalent
> of the Python statement o1 **= o2 when o3 is Py_None, or an in-place
> variant of pow(o1, o2, o3) otherwise.""

Where is that from?


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


Re: Running Python web apps on shared ASO servers?

2012-08-11 Thread Dieter Maurer
Gilles  writes:

> ...
> Support replied this in an old thread: "Just a CGI option. We don't
> have enough users to justify adding mod_python support."
> http://forums.asmallorange.com/topic/4672-python-support/page__hl__python
> http://forums.asmallorange.com/topic/4918-python-fcgi-verses-mod-python/
>
> Does it mean that ASO only supports writing Python web apps as
> long-running processes (CGI, FCGI, WSGI, SCGI) instead of embedded
> Python à la PHP?

It looks as if you could use CGI to activate Python scripts.
There seems to be no mod_python" support.

You should probably read the mentioned forum resources to learn
details about the Python support provided by your web site hoster.

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