Re: webapp development in pure python

2011-10-25 Thread alex23
Laszlo Nagy  wrote:
> My Python module would connect to a database server and query
> some data, then display it in a grid. This cannot be compiled into
> javascript because of the database server connection.

So what you want is for everything to happen server-side, with html
output sent to the client?

Perhaps you could build on top of ToscaWidgets. They encapsulate HTML
& JS, so you'll still need to work with them for custom widgets.

> With pyjamas, I
> would have to create the server side part separately, the user interface
> separately, and hand-code the communication between the widets and the
> server side.

That's pretty much true of all non-trivial web development, though.

There's a lot to be said for sucking it up and embracing traditional
methods rather than flying against common wisdom and cobbling together
something that works against web technologies rather than with them.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: webapp development in pure python

2011-10-25 Thread Sells, Fred
Quixote may be what you want, but it's been years since I've used it and
I don't know if it is still alive and kicking.  It was from MEMS if I
remember correctly.

Using django and Flex is one way to avoid html and javascript and it
works great for datagrids.

Fred.

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


Re: How to isolate a constant?

2011-10-25 Thread Mel
Dennis Lee Bieber wrote:

> Where's the line form to split those who'd prefer the first vs the
> second result in this sample :
> 
 unExpected = "What about a string"
 firstToLast = unExpected[:]
 repr(firstToLast)
> "'What about a string'"
 explicitList = list(unExpected)
 repr(explicitList)
> "['W', 'h', 'a', 't', ' ', 'a', 'b', 'o', 'u', 't', ' ', 'a', ' ', 's',
> 't', 'r', 'i', 'n', 'g']"
 

Well, as things stand, there's a way to get whichever result you need.  The 
`list` constructor builds a single list from a single iterable.  The list 
literal enclosed by `[`, `]` makes a list containing a bunch of items.

Strings being iterable introduces a wrinkle, but `list('abcde')` doesn't 
create `['abcde']` just as `list(1)` doesn't create `[1]`.

Mel.

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


Re: spawnl issues with Win 7 access rights

2011-10-25 Thread Terry Reedy

On 10/25/2011 8:19 AM, Tim Golden wrote:

On 25/10/2011 08:01, Propad wrote:

Thnx again for all the answers. As stated before, I'm limited in my
options. One of them just might be to switch to Python 2.5, rewrite
the code that crashes using the subprocess module, and then somehow
patch the library I use (which I'm not suposed to do, but... oh
well :-)). I can just hope subrocess was already mature adn offering
the relevant functionality in 2.5.


I must admit I'm more than slightly surprised by this. My test case
is to use os.spawnl to run c:/windows/notepad.exe. From the docs,
I would expect to use os.spawnl (os.P_WAIT, "c:/windows/notepad.exe").
(I only want to open notepad.exe; there's no need for additional args).

These are my test cases:

(1)

os.spawnl (
os.P_WAIT,
"c:/windows/notepad.exe"
)

(2)

os.spawnl (
os.P_WAIT,
"c:/windows/notepad.exe",
"c:/windows/notepad.exe"
)

(3)

os.spawnl (
os.P_WAIT,
"c:/windows/notepad.exe",
"c:/windows/notepad.exe",
"c:/temp.txt"
)


And the results:

==
Python | Platform | Case | Result
--
2.2.2 | WinXP | 1 | Works (empty notepad)
2.2.2 | WinXP | 2 | Works (empty notepad)
2.2.2 | WinXP | 3 | Works (notepad temp.txt)
--
2.2.2 | Win7 | 1 | OSError
2.2.2 | Win7 | 2 | Works (empty notepad)
2.2.2 | Win7 | 3 | Works (notepad temp.txt)
--
2.7.2 | WinXP | 1 | Crashes
2.7.2 | WinXP | 2 | Works (empty notepad)
2.7.2 | WinXP | 3 | Works (notepad temp.txt)
--
2.7.2 | Win7 | 1 | Crashes
2.7.2 | Win7 | 2 | Works (empty notepad)
2.7.2 | Win7 | 3 | Works (notepad temp.txt)
==


Add to this a look at the mscrt source which ships with VS 2008
and the MSDN docs for spawnl:

http://msdn.microsoft.com/en-us/library/wweek9sc%28v=vs.80%29.aspx

and we see that the first args parameter must be the same as the
path parameter.

FWIW, at no extra cost, I went to the trouble of testing it on some
flavour of Linux with Python 2.6 and got the same results
as per 2.2.2 on WinXP. (Basically: everything works).

Which leaves us with http://bugs.python.org/issue8036 in which recent
versions of Python crash when the (arbitrary) second parameter isn't
passed. And with an inexplicable behaviour change between the same
version of Python running on WinXP and on Win7.


OP reports 2.6 with XP works. Did that use VS 2005? Maybe C runtime 
changed (regressed). Also, could there be a 32 v. 64 bit issue?


--
Terry Jan Reedy

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


Re: How to isolate a constant?

2011-10-25 Thread Ian Kelly
On Tue, Oct 25, 2011 at 6:08 PM, Dennis Lee Bieber
 wrote:
> Where's the line form to split those who'd prefer the first vs the
> second result in this sample :
>
 unExpected = "What about a string"
 firstToLast = unExpected[:]

Strings are immutable.  That doesn't suffice to copy them, even
assuming you would want to do so in the first place.

>>> unExpected is firstToLast
True

If you find yourself needing to make a copy, that usually means that
you plan on modifying either the original or the copy, which in turn
means that you need a type that supports modification operations,
which usually means a list.  If you pass in a string and then copy it
with [:] and then try to modify it, you'll get an exception.  If you
don't try to modify it, then you probably didn't need to copy it in
the first place.

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


Re: Strange classmethod mock behavior

2011-10-25 Thread Fabio Zadrozny
On Tue, Oct 25, 2011 at 10:08 AM, Peter Otten <__pete...@web.de> wrote:
> Fabio Zadrozny wrote:
>
>> I'm trying to mock a classmethod in a superclass but when restoring it
>> a strange behavior happens in subclasses (tested on Python 2.5)
>>
>> Anyone knows why this happens? (see test case below for details)
>> Is there any way to restore that original method to have the original
>> behavior?
>>
>> import unittest
>>
>> class Test(unittest.TestCase):
>>
>>     def testClassmethod(self):
>>         class Super():
>>             @classmethod
>>             def GetCls(cls):
>>                 return cls
>>
>>         class Sub(Super):
>>             pass
>>
>>         self.assertEqual(Sub.GetCls(), Sub)
>>
>>         original = Super.GetCls
>>         #Mock Super.GetCls, and do tests...
>>         Super.GetCls = original #Restore the original classmethod
>>         self.assertEqual(Sub.GetCls(), Sub) #The call to the
>> classmethod subclass returns the cls as Super and not Sub as expected!
>>
>> if __name__ == '__main__':
>>     unittest.main()
>
> [Not related to your problem] When working with descriptors it's a good idea
> to use newstyle classes, i. e. have Super inherit from object.
>
> The Super.GetCls attribute access is roughly equivalent to
>
> Super.__dict___["GetCls"].__get__(classmethod_instance, None, Super)
>
> and returns an object that knows about its class. So when you think you are
> restoring the original method you are actually setting the GetCls attribute
> to something else. You can avoid the problem by accessing the attribute
> explicitly:
>
 class Super(object):
> ...     @classmethod
> ...     def m(cls): return cls
> ...
 bad = Super.m
 good = Super.__dict__["m"]
 class Sub(Super): pass
> ...
 Sub.m()
> 
 Super.m = bad
 Sub.m()
> 
 Super.m = good
 Sub.m()
> 
>

Hi Peter, thanks for the explanation.

Printing it helped me understand it even better...

print(Super.__dict__['GetCls'])
print(Super.GetCls)


>

Cheers,

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


How to pretty-print ctypes composite data types?

2011-10-25 Thread Grant Edwards
I'm using ctypes with a library that requires a handful of structure
definitions.  The actual definitions and usage aren't a problem.  When
it comes time to print out the values in a structure or array, there
doesn't seem to be simple/general way to do that.  Am I missing
something?

I presume one can recursively iterate through the fields in a
structure and elements in an array, recursing on any composite types
and printing the values when one finds a type, but I'm surprised
that's not something that's already in the ctypes library somewhere --
the authors certainly seem to have thought of everything else.

-- 
Grant Edwards   grant.b.edwardsYow! I own seven-eighths of
  at   all the artists in downtown
  gmail.comBurbank!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Data acquisition

2011-10-25 Thread Paul Simon
"spintronic"  wrote in message 
news:362e368f-829e-4477-bcfc-c0650d231...@j7g2000yqi.googlegroups.com...
> Dear friends,
>
> I have a trouble with understanding the following. I have a very short
> script (shown below) which works fine if I "run" step by step (or line
> by line) in Python shell (type the first line/command -> press Enter,
> etc.). I can get all numbers (actually, there are no numbers but a
> long string, but this is not a problem) I need from a device:
>
> '0.3345098119,0.01069121274,0.02111624694,0.03833379529,0.02462816409,0.0774275008,0.06554297421,0.07366750919,0.08122602002,0.004018369318,0.03508462415,0.04829900696,0.06383554085,
>  
> ...'
>
> However, when I start very the same list of commands as a script, it
> gives me the following, which is certainly wrong:
>
> [0.0, 0.0, 0.0, 0.0, 0.0,...]
>
> Any ideas? Why there is a difference when I run the script or do it
> command by command?
>
> ===
> from visa import *
>
> mw = instrument("GPIB0::20::INSTR", timeout = None)
>
> mw.write("*RST")
> mw.write("CALC1:DATA? FDATA")
>
> a=mw.read()
>
> print a
> ===
> (That is really all!)
>
>
> PS In this case I use Python Enthought for Windows, but I am not an
> expert in Windows (I work usually in Linux but now I need to run this
> data acquisition under Windows).

I'm almost certain that there is a turnaround timing issue that is causing 
the problem.  These are common problems in data aquisition systems.  The 
simplest solution is to loop and wait for end of line from the sending end 
and if necessary put in a time delay.  After receiving the data, check the 
received data for correct format, correct first and last characters, and if 
possible, check sum.  I've worked through this problem with rs-485 data 
collection systems where there is no hand shaking and would not be surprised 
to expect the same even with rs-232.

Paul Simon 


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


Re: [wanted] python-ldap for Python 2.3 / Win32

2011-10-25 Thread Gilles Lenfant
So many thanks for your valuable help Waldemar, this is exactly what I needed. 
I have no Windows machine to compile with the source bundle all this, and must 
install this directly in a production server.

I'll keep these precious links and files in a trunk.

Many thanks again
-- 
Gilles Lenfant
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Data acquisition

2011-10-25 Thread Dietmar Schwertberger

Am 25.10.2011 19:22, schrieb spintronic:

On Oct 25, 6:29 pm, Nick Dokos  wrote:

Shot in the dark: could it be that you have to add delays to give the
instrument time to adjust? When you do it from the python shell, line by
line, there is a long delay between one line and the next.

Thanks! You are right but it was the first thing I thought about. So I
have tried to delay using sleep(t) from the time module (I also sent
"*OPC?" or "*WAI" commands to a device for synchronization). However,
it does not help ...


RST is resetting all data and CALC is somehow calculating and returning
data. Without a trigger between RST and CALC, I would not expect any
data...

Maybe the equipment is triggering continuously e.g. every second.
When you were using the shell, you had a good chance to see a trigger
between RST and CALC. With a script, it's not so likely.
OPC won't help, as it would wait for completion of a measurement, but if
you don't trigger, it won't wait.

What kind of instrument are you using? Check for the trigger command.
It may be something like INIT:IMM

Regards,

Dietmar

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


Re: [wanted] python-ldap for Python 2.3 / Win32

2011-10-25 Thread Waldemar Osuch
I did try to build it using my current setup but it failed with some linking 
errors.
Oh well.

Google gods were nicer to me.  Here is a couple alternative links.
Maybe they will work for you.
http://web.archive.org/web/20081101060042/http://www.agescibs.org/mauro/
http://old.zope.org/Members/volkerw/LdapWin32/

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


Python developers interested in local communities, GroupServer

2011-10-25 Thread Steven Clift
My non-profit uses the GPL Python-based http://GroupServer.org
platform to host local neighborhood online communities in the U.S.,
the UK, and New Zealand. We are users of GroupServer and not the owner
of the project.

We are plotting a future new features hackathon (in person in
Minneapolis and perhaps simultaneously elsewhere) and are looking for
python programmers with a particular interest in connecting people in
local places.

If you are interested in learning more, please contact us at
t...@e-democracy.org or http://e-democracy.org/contact

Or join the GroupServer development group -
http://groupserver.org/groups/development - where we will definitely
making an announcement. We will also announce it here on the Local
Labs online group: http://e-democracy.org/labs

Thanks,
Steven Clift
E-Democracy.org

P.S. GroupServer is probably the best open source hybrid e-mail
list/web forum out there. Not the best e-mail list. And not the best
web forum. But the best fully integrated approach. Example use with
some customizations: http://e-democracy.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to isolate a constant?

2011-10-25 Thread Ian Kelly
On Tue, Oct 25, 2011 at 1:50 PM, Alan Meyer  wrote:
>> Python will copy something only when you tell it to copy. A simple way
>> of copying a list is to slice it:
>>
>> someList = self._someList[:]
>
> And another simple way:
>
>    ...
>    someList = list(self._someList)
>    ...

I generally prefer the latter.  It's clearer, and it guarantees that
the result will be a list, which is usually what you want in these
situations, rather than whatever unexpected type was passed in.

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


Re: How to isolate a constant?

2011-10-25 Thread Alan Meyer

On 10/22/2011 8:46 PM, MRAB wrote:

On 23/10/2011 01:26, Gnarlodious wrote:

Say this:

class tester():
_someList = [0, 1]
def __call__(self):
someList = self._someList
someList += "X"
return someList

test = tester()

But guess what, every call adds to the variable that I am trying to
copy each time:
test()

[0, 1, 'X']

test()

[0, 1, 'X', 'X']

...

Python will copy something only when you tell it to copy. A simple way
of copying a list is to slice it:

someList = self._someList[:]


And another simple way:

...
someList = list(self._someList)
...

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


Re: Data acquisition

2011-10-25 Thread John Gordon
In <86e6bfb8-17e1-4544-97ba-7299db8a8...@p16g2000yqj.googlegroups.com> 
spintronic  writes:

> > Are you in the same directory in both cases?
> > Does PYTHONPATH and/or sys.path have the same value in both cases?

> It looks that yes but how can it matter? All I need it is to import
> the visa module and it works well.

If you run the two cases from different directories, and the current
directory is in PYTHONPATH or sys.path, and one of the directories
contains a python file named "visa.py" and the other doesn't, that
culd account for the difference in output.

Do you have access to the visa.py source code?  Can you add a simple
print statement near the top of the module so that we know the same
visa.py module is being imported in both cases?

> > Show us an exact transscript of both executions.

> There is nothing but "numbers". Or do you mean something else? I do
> not receive any errors, only different results ...

I was more interested in the exact commands you used to run both cases,
rather than the output.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Data acquisition

2011-10-25 Thread spintronic
On Oct 25, 6:15 pm, Jean-Michel Pichavant 
wrote:
> spintronic wrote:
> > Dear friends,
>
> > I have a trouble with understanding the following. I have a very short
> > script (shown below) which works fine if I "run" step by step (or line
> > by line) in Python shell (type the first line/command -> press Enter,
> > etc.). I can get all numbers (actually, there are no numbers but a
> > long string, but this is not a problem) I need from a device:
>
> > '0.3345098119,0.01069121274,0.02111624694,0.03833379529,0.02462816409,0.0774275008,0.06554297421,0.07366750919,0.08122602002,0.004018369318,0.03508462415,0.04829900696,0.06383554085,
> >  ...'
>
> > However, when I start very the same list of commands as a script, it
> > gives me the following, which is certainly wrong:
>
> > [0.0, 0.0, 0.0, 0.0, 0.0,...]
>
> > Any ideas? Why there is a difference when I run the script or do it
> > command by command?
>
> > ===
> > from visa import *
>
> > mw = instrument("GPIB0::20::INSTR", timeout = None)
>
> > mw.write("*RST")
> > mw.write("CALC1:DATA? FDATA")
>
> > a=mw.read()
>
> > print a
> > ===
> > (That is really all!)
>
> > PS In this case I use Python Enthought for Windows, but I am not an
> > expert in Windows (I work usually in Linux but now I need to run this
> > data acquisition under Windows).
>
> Just in case you have a local installation of visa and it silently fails
> on some import,
>
> try to add at the begining of your script:
> import sys
> sys.path.append('')
>
> When using the python shell cmd line, '' is added to sys.path by the
> shell, that is one difference that can make relative imports fail in
> your script.
>
> If it's still not working, well, it means the problem is somewhere else.
>
> JM

Hi!

Thanks! I have just tried. Unfortunately, it does not work ...

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


Re: Data acquisition

2011-10-25 Thread spintronic
On Oct 25, 6:43 pm, John Gordon  wrote:

Thanks, John!

> Are you running the same python program in both cases?

Yes, the same.

> Are you in the same directory in both cases?
> Does PYTHONPATH and/or sys.path have the same value in both cases?

It looks that yes but how can it matter? All I need it is to import
the visa module and it works well.

> Show us an exact transscript of both executions.

There is nothing but "numbers". Or do you mean something else? I do
not receive any errors, only different results ...

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


Re: Data acquisition

2011-10-25 Thread spintronic
On Oct 25, 6:29 pm, Nick Dokos  wrote:
> Shot in the dark: could it be that you have to add delays to give the
> instrument time to adjust? When you do it from the python shell, line by
> line, there is a long delay between one line and the next.
>
> Nick

Hi, Nick!

Thanks! You are right but it was the first thing I thought about. So I
have tried to delay using sleep(t) from the time module (I also sent
"*OPC?" or "*WAI" commands to a device for synchronization). However,
it does not help ...

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


Re: Data acquisition

2011-10-25 Thread John Gordon
In <362e368f-829e-4477-bcfc-c0650d231...@j7g2000yqi.googlegroups.com> 
spintronic  writes:

> Any ideas? Why there is a difference when I run the script or do it
> command by command?

Are you running the same python program in both cases?

Are you in the same directory in both cases?

Does PYTHONPATH and/or sys.path have the same value in both cases?

Show us an exact transscript of both executions.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Data acquisition

2011-10-25 Thread Nick Dokos
spintronic  wrote:

> Dear friends,
> 
> I have a trouble with understanding the following. I have a very short
> script (shown below) which works fine if I "run" step by step (or line
> by line) in Python shell (type the first line/command -> press Enter,
> etc.). I can get all numbers (actually, there are no numbers but a
> long string, but this is not a problem) I need from a device:
> 
> '0.3345098119,0.01069121274,0.02111624694,0.03833379529,0.02462816409,0.0774275008,0.06554297421,0.07366750919,0.08122602002,0.004018369318,0.03508462415,0.04829900696,0.06383554085,
>  ...'
> 
> However, when I start very the same list of commands as a script, it
> gives me the following, which is certainly wrong:
> 
> [0.0, 0.0, 0.0, 0.0, 0.0,...]
> 
> Any ideas? Why there is a difference when I run the script or do it
> command by command?
> 
> ===
> from visa import *
> 
> mw = instrument("GPIB0::20::INSTR", timeout = None)
> 
> mw.write("*RST")
> mw.write("CALC1:DATA? FDATA")
> 
> a=mw.read()
> 
> print a
> ===
> (That is really all!)
> 
> 
> PS In this case I use Python Enthought for Windows, but I am not an
> expert in Windows (I work usually in Linux but now I need to run this
> data acquisition under Windows).
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 

Shot in the dark: could it be that you have to add delays to give the
instrument time to adjust? When you do it from the python shell, line by
line, there is a long delay between one line and the next.

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


Re: webapp development in pure python

2011-10-25 Thread Laszlo Nagy



Anyone knows a framework for webapp development? I'm not talking about
javascript/html compilers and ajax frameworks. I need something that 
does

not require javascript knowledge, just pure Python. (So qooxdoo is not
really an option, because it cannot be programmed in Python. You 
cannot even
put out a window on the center of the screen without using 
javascript code,
and you really have to be a javascript expert to write useful 
applications

with qooxdoo.)

What I need is a programmable GUI with windows, event handlers and
extensible widgets, for creating applications that use http/https 
and a web

browser for rendering.


So you're looking for something like Google Web Toolkit but using
Python instead of Java...

Do you know about pyjamas (http://pyjs.org/)?  I've never used it, but
I think it endeavours to be what you are looking for.
As I told, I'm not talking about javascript/html compilers and ajax 
frameworks. Pyjamas is both a javascript compiler and  an ajax 
framework. My Python module would connect to a database server and query 
some data, then display it in a grid. This cannot be compiled into 
javascript because of the database server connection. With pyjamas, I 
would have to create the server side part separately, the user interface 
separately, and hand-code the communication between the widets and the 
server side. I would like to use this theoretical web based framework 
just like pygtk or wxPython: create windows, place widgets on them, 
implement event handlers etc. and access the widgets and other server 
side resources (for example, a database connection) from the same source 
code. Transparently. So the web part would really just be the rendering 
part of the user inferface. This may not be possible at all..


My other idea was to use a freenx server and wxPython. Is it a better 
solution? Have anyone used this combination from an android tablet, for 
example? Would it work?


Thanks,

   Laszlo

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


Re: Data acquisition

2011-10-25 Thread Jean-Michel Pichavant

spintronic wrote:

Dear friends,

I have a trouble with understanding the following. I have a very short
script (shown below) which works fine if I "run" step by step (or line
by line) in Python shell (type the first line/command -> press Enter,
etc.). I can get all numbers (actually, there are no numbers but a
long string, but this is not a problem) I need from a device:

'0.3345098119,0.01069121274,0.02111624694,0.03833379529,0.02462816409,0.0774275008,0.06554297421,0.07366750919,0.08122602002,0.004018369318,0.03508462415,0.04829900696,0.06383554085,
 ...'

However, when I start very the same list of commands as a script, it
gives me the following, which is certainly wrong:

[0.0, 0.0, 0.0, 0.0, 0.0,...]

Any ideas? Why there is a difference when I run the script or do it
command by command?

===
from visa import *

mw = instrument("GPIB0::20::INSTR", timeout = None)

mw.write("*RST")
mw.write("CALC1:DATA? FDATA")

a=mw.read()

print a
===
(That is really all!)


PS In this case I use Python Enthought for Windows, but I am not an
expert in Windows (I work usually in Linux but now I need to run this
data acquisition under Windows).
  


Just in case you have a local installation of visa and it silently fails 
on some import,


try to add at the begining of your script:
import sys
sys.path.append('')

When using the python shell cmd line, '' is added to sys.path by the 
shell, that is one difference that can make relative imports fail in 
your script.


If it's still not working, well, it means the problem is somewhere else.

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


Data acquisition

2011-10-25 Thread spintronic
Dear friends,

I have a trouble with understanding the following. I have a very short
script (shown below) which works fine if I "run" step by step (or line
by line) in Python shell (type the first line/command -> press Enter,
etc.). I can get all numbers (actually, there are no numbers but a
long string, but this is not a problem) I need from a device:

'0.3345098119,0.01069121274,0.02111624694,0.03833379529,0.02462816409,0.0774275008,0.06554297421,0.07366750919,0.08122602002,0.004018369318,0.03508462415,0.04829900696,0.06383554085,
 ...'

However, when I start very the same list of commands as a script, it
gives me the following, which is certainly wrong:

[0.0, 0.0, 0.0, 0.0, 0.0,...]

Any ideas? Why there is a difference when I run the script or do it
command by command?

===
from visa import *

mw = instrument("GPIB0::20::INSTR", timeout = None)

mw.write("*RST")
mw.write("CALC1:DATA? FDATA")

a=mw.read()

print a
===
(That is really all!)


PS In this case I use Python Enthought for Windows, but I am not an
expert in Windows (I work usually in Linux but now I need to run this
data acquisition under Windows).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Creating very similar functions with different parameters

2011-10-25 Thread 88888 Dihedral
Thanks for the debug modes in functional programing! Everything functional is 
true in CS at least in the theroy!   
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Creating very similar functions with different parameters

2011-10-25 Thread Ian Kelly
On Mon, Oct 24, 2011 at 3:29 PM, Andrew Berg  wrote:
> I want to create a decorator with two different (but very similar)
> versions of the wrapper function, but without copying giant chunks of
> similar code. The main difference is that one version takes extra
> parameters.
>
> def test_dec(func, extra=False):
>        if extra:
>                def wrapper(ex_param1, ex_param2, *args, **kwargs):
>                        print('bla bla')
>                        print('more bla')
>                        print(ex_param1)
>                        print(ex_param2)
>                        func(ex_param1, ex_param2, *args, **kwargs)
>        else:
>                def wrapper(*args, **kwargs):
>                        print('bla bla')
>                        print('more bla')
>                        func(*args, **kwargs)
>        return wrapper
>
> If the function I'm wrapping takes ex_param1 and ex_param2 as
> parameters, then the decorator should print them and then execute the
> function, otherwise just execute the function. I'd rather not write
> separate wrappers that are mostly the same.

Others have given more involved suggestions, but in this case you
could just make the wrapper a closure and check the flag there:

def test_dec(func, extra=False):
def wrapper(*args, **kwargs):
print('bla bla')
print('more bla')
if extra:
ex_param1, ex_param2 = args[:2]
print(ex_param1)
print(ex_param2)
func(*args, **kwargs)
return wrapper

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


Re: webapp development in pure python

2011-10-25 Thread Martin P. Hellwig

On 10/25/11 15:13, Arnaud Delobelle wrote:

On 25 October 2011 14:50, Laszlo Nagy  wrote:


  Hi,

Anyone knows a framework for webapp development? I'm not talking about
javascript/html compilers and ajax frameworks. I need something that does
not require javascript knowledge, just pure Python. (So qooxdoo is not
really an option, because it cannot be programmed in Python. You cannot even
put out a window on the center of the screen without using javascript code,
and you really have to be a javascript expert to write useful applications
with qooxdoo.)

What I need is a programmable GUI with windows, event handlers and
extensible widgets, for creating applications that use http/https and a web
browser for rendering.


So you're looking for something like Google Web Toolkit but using
Python instead of Java...

Do you know about pyjamas (http://pyjs.org/)?  I've never used it, but
I think it endeavours to be what you are looking for.

HTH



Second that, I use it for a couple of my projects for exactly that.

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


Re: webapp development in pure python

2011-10-25 Thread Arnaud Delobelle
On 25 October 2011 14:50, Laszlo Nagy  wrote:
>
>  Hi,
>
> Anyone knows a framework for webapp development? I'm not talking about
> javascript/html compilers and ajax frameworks. I need something that does
> not require javascript knowledge, just pure Python. (So qooxdoo is not
> really an option, because it cannot be programmed in Python. You cannot even
> put out a window on the center of the screen without using javascript code,
> and you really have to be a javascript expert to write useful applications
> with qooxdoo.)
>
> What I need is a programmable GUI with windows, event handlers and
> extensible widgets, for creating applications that use http/https and a web
> browser for rendering.

So you're looking for something like Google Web Toolkit but using
Python instead of Java...

Do you know about pyjamas (http://pyjs.org/)?  I've never used it, but
I think it endeavours to be what you are looking for.

HTH

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


Re: webapp development in pure python

2011-10-25 Thread Anurag Chourasia
Have you considered Django ?

http://www.djangoproject.com/ 

Regards,
Anurag

On Tue, Oct 25, 2011 at 7:20 PM, Laszlo Nagy  wrote:

>
>  Hi,
>
> Anyone knows a framework for webapp development? I'm not talking about
> javascript/html compilers and ajax frameworks. I need something that does
> not require javascript knowledge, just pure Python. (So qooxdoo is not
> really an option, because it cannot be programmed in Python. You cannot even
> put out a window on the center of the screen without using javascript code,
> and you really have to be a javascript expert to write useful applications
> with qooxdoo.)
>
> What I need is a programmable GUI with windows, event handlers and
> extensible widgets, for creating applications that use http/https and a web
> browser for rendering.
>
> Is there something like this already available?
>
> Thanks,
>
>   Laszlo
>
>
>
> --
> http://mail.python.org/**mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


webapp development in pure python

2011-10-25 Thread Laszlo Nagy


  Hi,

Anyone knows a framework for webapp development? I'm not talking about 
javascript/html compilers and ajax frameworks. I need something that 
does not require javascript knowledge, just pure Python. (So qooxdoo is 
not really an option, because it cannot be programmed in Python. You 
cannot even put out a window on the center of the screen without using 
javascript code, and you really have to be a javascript expert to write 
useful applications with qooxdoo.)


What I need is a programmable GUI with windows, event handlers and 
extensible widgets, for creating applications that use http/https and a 
web browser for rendering.


Is there something like this already available?

Thanks,

   Laszlo



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


Re: spawnl issues with Win 7 access rights

2011-10-25 Thread Tim Golden

On 25/10/2011 08:01, Propad wrote:

Thnx again for all the answers. As stated before, I'm limited in my
options. One of them just might be to switch to Python 2.5, rewrite
the code that crashes using the subprocess module, and then somehow
patch the library I use (which I'm not suposed to do, but... oh
well :-)). I can just hope subrocess was already mature adn offering
the relevant functionality in 2.5.


I must admit I'm more than slightly surprised by this. My test case
is to use os.spawnl to run c:/windows/notepad.exe. From the docs,
I would expect to use os.spawnl (os.P_WAIT, "c:/windows/notepad.exe").
(I only want to open notepad.exe; there's no need for additional args).

These are my test cases:

(1)

os.spawnl (
  os.P_WAIT,
  "c:/windows/notepad.exe"
)

(2)

os.spawnl (
  os.P_WAIT,
  "c:/windows/notepad.exe",
  "c:/windows/notepad.exe"
)

(3)

os.spawnl (
  os.P_WAIT,
  "c:/windows/notepad.exe",
  "c:/windows/notepad.exe",
  "c:/temp.txt"
)


And the results:

==
Python | Platform | Case | Result
--
2.2.2  | WinXP| 1| Works (empty notepad)
2.2.2  | WinXP| 2| Works (empty notepad)
2.2.2  | WinXP| 3| Works (notepad temp.txt)
--
2.2.2  | Win7 | 1| OSError
2.2.2  | Win7 | 2| Works (empty notepad)
2.2.2  | Win7 | 3| Works (notepad temp.txt)
--
2.7.2  | WinXP| 1| Crashes
2.7.2  | WinXP| 2| Works (empty notepad)
2.7.2  | WinXP| 3| Works (notepad temp.txt)
--
2.7.2  | Win7 | 1| Crashes
2.7.2  | Win7 | 2| Works (empty notepad)
2.7.2  | Win7 | 3| Works (notepad temp.txt)
==


Add to this a look at the mscrt source which ships with VS 2008
and the MSDN docs for spawnl:

http://msdn.microsoft.com/en-us/library/wweek9sc%28v=vs.80%29.aspx

and we see that the first args parameter must be the same as the
path parameter.

FWIW, at no extra cost, I went to the trouble of testing it on some
flavour of Linux with Python 2.6 and got the same results
as per 2.2.2 on WinXP. (Basically: everything works).

Which leaves us with http://bugs.python.org/issue8036 in which recent
versions of Python crash when the (arbitrary) second parameter isn't
passed. And with an inexplicable behaviour change between the same
version of Python running on WinXP and on Win7.

It looks as though the workaround for your problem (or, possibly,
your failure to fulfil some artificial parameter requirements) is
to add the executable again as the third parameter.

issue8036 (which also affects the execl family) has a patch waiting
for review, which hopefully we can get round to fixing. As far as I
can tell, the execl/spawnl family of functions isn't currently
represented in the testsuite.

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


Re: Strange classmethod mock behavior

2011-10-25 Thread Peter Otten
Fabio Zadrozny wrote:

> I'm trying to mock a classmethod in a superclass but when restoring it
> a strange behavior happens in subclasses (tested on Python 2.5)
> 
> Anyone knows why this happens? (see test case below for details)
> Is there any way to restore that original method to have the original
> behavior?
> 
> import unittest
> 
> class Test(unittest.TestCase):
> 
> def testClassmethod(self):
> class Super():
> @classmethod
> def GetCls(cls):
> return cls
> 
> class Sub(Super):
> pass
> 
> self.assertEqual(Sub.GetCls(), Sub)
> 
> original = Super.GetCls
> #Mock Super.GetCls, and do tests...
> Super.GetCls = original #Restore the original classmethod
> self.assertEqual(Sub.GetCls(), Sub) #The call to the
> classmethod subclass returns the cls as Super and not Sub as expected!
> 
> if __name__ == '__main__':
> unittest.main()

[Not related to your problem] When working with descriptors it's a good idea 
to use newstyle classes, i. e. have Super inherit from object.

The Super.GetCls attribute access is roughly equivalent to

Super.__dict___["GetCls"].__get__(classmethod_instance, None, Super) 

and returns an object that knows about its class. So when you think you are 
restoring the original method you are actually setting the GetCls attribute 
to something else. You can avoid the problem by accessing the attribute 
explicitly:

>>> class Super(object):
... @classmethod
... def m(cls): return cls
...
>>> bad = Super.m
>>> good = Super.__dict__["m"]
>>> class Sub(Super): pass
...
>>> Sub.m()

>>> Super.m = bad
>>> Sub.m()

>>> Super.m = good
>>> Sub.m()



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


Strange classmethod mock behavior

2011-10-25 Thread Fabio Zadrozny
I'm trying to mock a classmethod in a superclass but when restoring it
a strange behavior happens in subclasses (tested on Python 2.5)

Anyone knows why this happens? (see test case below for details)
Is there any way to restore that original method to have the original behavior?

import unittest

class Test(unittest.TestCase):

def testClassmethod(self):
class Super():
@classmethod
def GetCls(cls):
return cls

class Sub(Super):
pass

self.assertEqual(Sub.GetCls(), Sub)

original = Super.GetCls
#Mock Super.GetCls, and do tests...
Super.GetCls = original #Restore the original classmethod
self.assertEqual(Sub.GetCls(), Sub) #The call to the
classmethod subclass returns the cls as Super and not Sub as expected!

if __name__ == '__main__':
unittest.main()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Tutor] What is wrong with my code?

2011-10-25 Thread apometron

On 10/25/2011 7:34 AM, Dave Angel wrote:
(Once again, please don't top-post.  It makes your responses out of 
order)


On 10/25/2011 04:24 AM, apometron wrote:

I did it very much times, Anssi.

Beyond of run it on Python 2.7 latest build, what do you suggest?

Do install Python 3.2 along the Python 2.7 installation could give me 
any problems?




Why don't you say publicly that you aren't using cmd ?

If your file manager is not running the equivalent of


python  yourprogram.py filename.txt


then everyone here is chasing a wild goose.

Switch to the command line, issue a sequence of commands that cause 
the failure, and paste them in a message here.  Then if it works, but 
doesn't from your file manager, you/we/they can address the 
differences from the working command line.




I found out what it is.

It is the File Commander giving wrong informations to the script.

In Take Command command line it works sweet.

I will show all this to the File Commander author and ask him some way 
to solve this.


It turns out do the thing in command line every time is not best way. I 
need do it by the file manager.


But the file manager was puting stones in the way.

Take Command has a script language also, but I would like do the things 
in Python, if possible.


And this difficulty with File Commander makes use Python a thing less 
easy to do.


Question solved. It was not Take Command the problem and I was sure it 
was not.


Enter in command line to do things is a pain. =( I mean, e-ve-ry ti-me.

But then, good news, all the three scripts works smoothly in the command 
line.


Do you believe drag and drop in the Windows Explorer can be my salvation?

Cool thing to try.

[]s
Apometron
http://about.me/apometron


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


Re: [Tutor] What is wrong with my code?

2011-10-25 Thread Dave Angel

(Once again, please don't top-post.  It makes your responses out of order)

On 10/25/2011 04:24 AM, apometron wrote:

I did it very much times, Anssi.

Beyond of run it on Python 2.7 latest build, what do you suggest?

Do install Python 3.2 along the Python 2.7 installation could give me 
any problems?




Why don't you say publicly that you aren't using cmd ?

If your file manager is not running the equivalent of


python  yourprogram.py filename.txt


then everyone here is chasing a wild goose.

Switch to the command line, issue a sequence of commands that cause the 
failure, and paste them in a message here.  Then if it works, but 
doesn't from your file manager, you/we/they can address the differences 
from the working command line.




--

DaveA

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


Re: [wanted] python-ldap for Python 2.3 / Win32

2011-10-25 Thread Michael Ströder
Gilles Lenfant wrote:
> I have spent a couple of hours asking google, browsing Pypi, SF, and of
> course the official www.python-ldap.org site searching for a python-ldap
> installer for Python 2.3 on Windows 32 bits. Unsuccessfully :(

In theory even recent python-ldap 2.4.3 should still work with Python 2.3.
Please post your inquiry on the mailing-list python-l...@python.org (subscribe
before post). Maybe you can convince the maintainer of the Win32 packages there.

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


Re: What is wrong with my code?

2011-10-25 Thread apometron

I did it very much times, Anssi.

Beyond of run it on Python 2.7 latest build, what do you suggest?

Do install Python 3.2 along the Python 2.7 installation could give me 
any problems?


cheers,
Apometron
http://about.me/apometron

On 10/25/2011 6:11 AM, Anssi Saari wrote:

apometron  writes:


Now it is another
thing, entirely. Rename1.py and Rename2.py works, but why Rename3.py
dont works?

Well, Rename3.py works for me, even in Windows 7. Maybe you should test
it again?


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


Re: Exception Handling (C - extending python)

2011-10-25 Thread Stefan Behnel

Ulrich Eckhardt, 25.10.2011 08:49:

Am 23.10.2011 14:41, schrieb Stefan Behnel:

That's just fine. If you are interested in the inner mechanics of the
CPython runtime, reading the source is a very good way to start getting
involved with the project.

However, many extension module authors don't care about these inner
mechanics and just use Cython instead. That keeps them from having to
learn the C-API of CPython, and from tying their code too deeply into
the CPython runtime itself.


Could you elaborate a bit? What are the pros and cons of writing an
extension module using the Cython API compared to using the CPyothon API?


No cons. ;)

Cython is not an API, it's a programming language. It's Python, but with 
extended support for talking to C/C++ code (and also Fortran). That means 
that you don't have to use the C-API yourself, because Cython will do it 
for you.




In particular, how portable is it? Can I compile a module in one and use it
in the other?


They both use the CPython C-API internally. It's just that you are not 
using it explicitly in your code, so you (can) keep your own code free of 
CPython-isms.


It's substantially more portable than the "usual" hand-written code, 
because it generates C code for you that compiles and works in CPython 2.4 
up to the latest 3.3 in-development version, and also with all major C/C++ 
compilers, etc. It also generates faster glue code than you would write, 
e.g. for data type conversion and argument unpacking in function calls. So 
it speeds up thin wrappers automatically for you.


That doesn't mean that you can't get the same level of speed and 
portability in hand-written code. It just means that you don't have to do 
it yourself. Saves a lot of time, both during development and later during 
the maintenance cycle. Basically, it allows you to focus on the 
functionality you want to implement, rather than the implementation details 
of CPython, and also keeps the maintenance overhead at that level for you.




Don't I just tie myself to a different API, but tie myself
nonetheless?


There's a port to plain Python+ctypes underways, for example, which you 
could eventually use in PyPy. Try to do that at the C-API level.


Stefan

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


Re: UnicodeError instead of UnicodeWarning

2011-10-25 Thread Peter Otten
Michael Ströder wrote:

> For tracking the cause of a UnicodeWarning I'd like to make the Python
> interpreter to raise an UnicodeError exception with full stack trace. Is
> there a short trick to achieve this?

You can control warning behaviour with the -W commandline option:

$ cat unicodewarning_demo.py
# -*- coding: utf-8 -*-

def g():
"ä" == u"ä"

def f(n=3):
if n:
f(n-1)
else:
g()

if __name__ == "__main__":
f()

$ python unicodewarning_demo.py
unicodewarning_demo.py:4: UnicodeWarning: Unicode equal comparison failed to 
convert both arguments to Unicode - interpreting them as being unequal
  "ä" == u"ä"
$ python -W error::UnicodeWarning unicodewarning_demo.py
Traceback (most recent call last):
  File "unicodewarning_demo.py", line 13, in 
f()
  File "unicodewarning_demo.py", line 8, in f
f(n-1)
  File "unicodewarning_demo.py", line 8, in f
f(n-1)
  File "unicodewarning_demo.py", line 8, in f
f(n-1)
  File "unicodewarning_demo.py", line 10, in f
g()
  File "unicodewarning_demo.py", line 4, in g
"ä" == u"ä"
UnicodeWarning: Unicode equal comparison failed to convert both arguments to 
Unicode - interpreting them as being unequal
$


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


Re: What is wrong with my code?

2011-10-25 Thread Anssi Saari
apometron  writes:

> Now it is another
> thing, entirely. Rename1.py and Rename2.py works, but why Rename3.py
> dont works?

Well, Rename3.py works for me, even in Windows 7. Maybe you should test
it again?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: UnicodeError instead of UnicodeWarning

2011-10-25 Thread Chris Rebert
2011/10/25 Michael Ströder :
> HI!
>
> For tracking the cause of a UnicodeWarning I'd like to make the Python
> interpreter to raise an UnicodeError exception with full stack trace. Is there
> a short trick to achieve this?

from exceptions import UnicodeWarning
from warnings import filterwarnings
filterwarnings(action="error", category=UnicodeWarning)

This will cause UnicodeWarnings to be raised as exceptions when they occur.

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


UnicodeError instead of UnicodeWarning

2011-10-25 Thread Michael Ströder
HI!

For tracking the cause of a UnicodeWarning I'd like to make the Python
interpreter to raise an UnicodeError exception with full stack trace. Is there
a short trick to achieve this?

Many thanks in advance.

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


[wanted] python-ldap for Python 2.3 / Win32

2011-10-25 Thread Gilles Lenfant
Hi,

I have spent a couple of hours asking google, browsing Pypi, SF, and of course 
the official www.python-ldap.org site searching for a python-ldap installer for 
Python 2.3 on Windows 32 bits. Unsuccessfully :(

As I need to add this to an ooold Plone site, it is not easy to upgrade to a 
newer Python version. So, please don't tell me to upgrade ;)

Many thanks by advance to the people who will help me. You can send this 
package via mail to gillesDOTlenfantATgmailDOTcom.

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


Re: spawnl issues with Win 7 access rights

2011-10-25 Thread Propad
On 25 Okt., 02:21, Miki Tebeka  wrote:
> Please use the subprocess module, it's the one who's actively 
> maintained.http://docs.python.org/library/subprocess.html#replacing-the-os-spawn...

Thnx again for all the answers. As stated before, I'm limited in my
options. One of them just might be to switch to Python 2.5, rewrite
the code that crashes using the subprocess module, and then somehow
patch the library I use (which I'm not suposed to do, but... oh
well :-)). I can just hope subrocess was already mature adn offering
the relevant functionality in 2.5.

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


Re: Exception Handling (C - extending python)

2011-10-25 Thread Ulrich Eckhardt

Am 23.10.2011 14:41, schrieb Stefan Behnel:

That's just fine. If you are interested in the inner mechanics of the
CPython runtime, reading the source is a very good way to start getting
involved with the project.

However, many extension module authors don't care about these inner
mechanics and just use Cython instead. That keeps them from having to
learn the C-API of CPython, and from tying their code too deeply into
the CPython runtime itself.


Could you elaborate a bit? What are the pros and cons of writing an 
extension module using the Cython API compared to using the CPyothon 
API? In particular, how portable is it? Can I compile a module in one 
and use it in the other? Don't I just tie myself to a different API, but 
tie myself nonetheless?


Thank you!

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