Re: performance of tight loop

2010-12-14 Thread Ulrich Eckhardt
Thank you for the explanation, Ryan!

Uli

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

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


Fail import with SWIG generated imp.load_module ?

2010-12-14 Thread Hvidberg, Martin

I'm trying to load a module GDAL into a Python script.
The loader/binder that is then called, seems to be generated by SWIG, a project 
with which I'm unfortunately not familiar.
The part of the SWIG generated code that fails on me is as follow:


-- start code snip 1 -
# This file was automatically generated by SWIG (http://www.swig.org).
# Version 1.3.39
#
# Do not make changes to this file unless you know what you are doing--modify
# the SWIG interface file instead.


from sys import version_info
if version_info >= (2,6,0):
def swig_import_helper():
from os.path import dirname
import imp
fp = None
try:
fp, pathname, description = imp.find_module('_gdal', 
[dirname(__file__)])
except ImportError:
import _gdal
return _gdal
if fp is not None:
print "fp:",fp # <- My code ...
print "pn:",pathname # <- My code ...
print "de:",description # <- My code ...
try:
_mod = imp.load_module('_gdal', fp, pathname, description)
finally:
fp.close()
return _mod
_gdal = swig_import_helper()
del swig_import_helper
else:
import _gdal
del version_info

... 
-- end code snip 1 -

I had to redo the indents manually in this mail, I hope I didn't make any 
mistakes.
When I run the script that activates this code, it returns the following:


-- start code snip 2 -
fp: 
pn: C:\gdal\bin\gdal\python\osgeo\_gdal.pyd
de: ('.pyd', 'rb', 3)
Traceback (most recent call last):
File "C:\Martin\Work_Eclipse\Hilfe\src\check_GDAL.py", line 8, in 
import gdal
File "C:\gdal\bin\gdal\python\osgeo\gdal.py", line 27, in 
_gdal = swig_import_helper()
File "C:\gdal\bin\gdal\python\osgeo\gdal.py", line 26, in swig_import_helper
return _mod
UnboundLocalError: local variable '_mod' referenced before assignment
-- end code snip 2 -

It appears to me that the objects returned by imp.find_module, and printed out 
as fp:, pn: and de:, are valid. So why is mp.load_module returning what appears 
to be some flavour of NULL ?

I'm using Python version 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 
32 bit (Intel)]
The GDAL lib is from 
http://download.osgeo.org/gdal/win32/1.6/gdalwin32exe160.zip


All suggestions appreciated ...


Best Regards
Martin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: performance of tight loop

2010-12-14 Thread Paul Rubin
gry  writes:
...
> rest =  ['%d' % randint(1, mx) for i in range(wd - 1)]
> for i in range(i,i+rows): ...

One thing that immediately comes to mind is use xrange instead of range.

Also, instead of 
first = ['%d' % i]
rest =  ['%d' % randint(1, mx) for i in range(wd - 1)]
return first + rest

you might save some copying with:

rest =  ['%d' % randint(1, mx) for i in xrange(wd)]
rest[0] = '%d'%i
return rest

That's uglier than the old-fashioned
  rest = ['%d'%i]
  for i in xrange(wd-1):
 rest.append('%d' % randint(1, mx))

I think a generator would be cleanest, but maybe slowest:

   def row(i, wd, mx):
  yield '%d' % i
  for j in xrange(wd-1):
  yield ('%d' % randint(1, mx))
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: while True or while 1

2010-12-14 Thread Gregory Ewing

Steven D'Aprano wrote:


while True:


... print "Looping"
... True = 0


Just remember that if you use that inside a function, you'll
have to initialise True to True before... er, wait a moment,
that won't work... ah, I know:

  def f(true = True):
True = true
while True:
  ...
  True = False

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


Re: while True or while 1

2010-12-14 Thread Hans-Peter Jansen
On Tuesday 14 December 2010, 10:19:04 Gregory Ewing wrote:
> Steven D'Aprano wrote:
> while True:
> >
> > ... print "Looping"
> > ... True = 0
>
> Just remember that if you use that inside a function, you'll
> have to initialise True to True before... er, wait a moment,
> that won't work... ah, I know:
>
>def f(true = True):
>  True = true
>  while True:
>...
>True = False

Thankfully, with Python 3 this code falls flat on its face. 

If I would have to _consume_ code like that more often, 
it would require me to also use a vomit resistant keyboard cover..

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


Re: optparse/argparse for cgi/wsgi?

2010-12-14 Thread Joost Molenaar
Many people have. :-)

In the context of WSGI you're basically talking about routing
middleware, which solves the problem: "given a request, which
application should be called to construct a response?"

In my case, it turned out as simple as a list of (regex, resource)
tuples, where regex is a regular expression that looks at the
request URI and resource is an object that may or may not
implement GET, POST, PUT, DELETE methods. In the regex
I can capture any arguments that the resource needs. If the
request method is GET and the method GET exists on the
matched resource, it is called, else a 'Method Not Allowed'
response code is returned.

HTH

Joost

On 10 December 2010 17:36, samwyse  wrote:

> Has anyone ever built some sort of optparse/argparse module for cgi/
> wsgi programs?  I can see why a straight port wouldn't work, but a
> module that can organize parameter handling for web pages seems like a
> good idea, especially if it provided a standard collection of both
> client- and server-side validation processes, easy
> internationalization, and a way to create customizable help pages.
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: optparse/argparse for cgi/wsgi?

2010-12-14 Thread Joost Molenaar
To aid your googling, the problem is also commonly called 'Dispatching'
instead of 'Routing'.

Joost

On 14 December 2010 12:19, Joost Molenaar  wrote:

> Many people have. :-)
>
> In the context of WSGI you're basically talking about routing
> middleware, which solves the problem: "given a request, which
> application should be called to construct a response?"
>
> In my case, it turned out as simple as a list of (regex, resource)
> tuples, where regex is a regular expression that looks at the
> request URI and resource is an object that may or may not
> implement GET, POST, PUT, DELETE methods. In the regex
> I can capture any arguments that the resource needs. If the
> request method is GET and the method GET exists on the
> matched resource, it is called, else a 'Method Not Allowed'
> response code is returned.
>
> HTH
>
> Joost
>
>
> On 10 December 2010 17:36, samwyse  wrote:
>
>> Has anyone ever built some sort of optparse/argparse module for cgi/
>> wsgi programs?  I can see why a straight port wouldn't work, but a
>> module that can organize parameter handling for web pages seems like a
>> good idea, especially if it provided a standard collection of both
>> client- and server-side validation processes, easy
>> internationalization, and a way to create customizable help pages.
>>
>


-- 
Joost Molenaar
+31 644 015 510
-- 
http://mail.python.org/mailman/listinfo/python-list


International Workshop: DATICS-ISPA'11 (EI Indexed)

2010-12-14 Thread SS DATICS
Dear authors,

=
International Workshop: DATICS-ISPA'11
CALL FOR PAPERS

http://datics.nesea-conference.org/datics-ispa2011
Busan, Korea, 26-28 May, 2011.
=

Aims and Scope of DATICS-ISPA’11 Workshop:

DATICS Workshops were initially created by a network of researchers
and engineers both from academia and industry in the areas of Design,
Analysis and Tools for Integrated Circuits and Systems. Recently,
DATICS has been extended to the fields of Communication, Computer
Science, Software Engineering and Information Technology.
The main target of DATICS-ISPA’11 is to bring together
software/hardware engineering researchers, computer scientists,
practitioners and people from industry to exchange theories, ideas,
techniques and experiences related to all aspects of DATICS.

Topics of interest include, but are not limited to, the following:

Circuits, Systems and Communications:

digital, analog, mixed-signal, VLSI, asynchronous and RF design
processor and memory
DSP and FPGA/ASIC-based design
synthesis and physical design
embedded system hardware/software co-design
CAD/EDA methodologies and tools
statistical timing analysis and low power design methodologies
network/system on-a-chip and applications
hardware description languages, SystemC and SystemVerilog
simulation, verification and test technology
semiconductor devices and solid-state circuits
fuzzy and neural networks
communication signal processing
mobile and wireless communications
peer-to-peer video streaming and multimedia communications
communication channel modeling
antenna
radio-wave propagation

Computer Science, Software Engineering and Information Technology:

equivalence checking, model checking, SAT-based methods, compositional
methods and probabilistic methods
graph theory, process algebras, petri-nets, automaton theory, BDDs and UML
formal methods
distributed, real-time and hybrid systems
reversible computing and biocomputing
software architecture and design
software testing and analysis
software dependability, safety and reliability
programming languages, tools and environments
face detection and recognition
database and data mining
image and video processing
watermarking
artificial intelligence
average-case analysis and worst-case analysis
design and programming methodologies for network protocols and applications
coding, cryptography algorithms and security protocols
evolutionary computation
numerical algorithms
e-commerce



Please note that all accepted papers will be included in IEEE Xplore
and indexed by EI Compendex. After workshop, several special issues of
international journals such as IJDATICS and IJCECS will be arranged
for selected papers.

For more details about DATICS-ISPA'11, please visit
http://datics.nesea-conference.org/datics-ispa2011
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: while True or while 1

2010-12-14 Thread Kurt Mueller
Am 14.12.2010 11:33, schrieb Hans-Peter Jansen:
> On Tuesday 14 December 2010, 10:19:04 Gregory Ewing wrote:
>> Steven D'Aprano wrote:
>> while True:
>>>
>>> ... print "Looping"
>>> ... True = 0
>>
>> Just remember that if you use that inside a function, you'll
>> have to initialise True to True before... er, wait a moment,
>> that won't work... ah, I know:
>>
>> def f(true = True):
>> True = true
>> while True:
>> ...
>> True = False
>
> Thankfully, with Python 3 this code falls flat on its face.
>
> If I would have to _consume_ code like that more often,
> it would require me to also use a vomit resistant keyboard cover..
>
> Pete


True yesterday, today and in the future:


Yesterday:
"Pilate said to him, True? what is true?
 Having said this he went out again to the Jews
 and said to them, I see no wrong in him."

Today:
We are so thankful that today we are free
to define "True" ourselves using Python 2.x.

Future:
Be warned, the future gets darker!


;-)


Grüessli
-- 
Kurt Mueller

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


Re: performance of tight loop

2010-12-14 Thread Peter Otten
gry wrote:

> [python-2.4.3, rh CentOS release 5.5 linux, 24 xeon cpu's, 24GB ram]
> I have a little data generator that I'd like to go faster... any
> suggestions?
> maxint is usually 9223372036854775808(max 64bit int), but could
> occasionally be 99.
> width is usually 500 or 1600, rows ~ 5000.
> 
> from random import randint
> 
> def row(i, wd, mx):
> first = ['%d' % i]
> rest =  ['%d' % randint(1, mx) for i in range(wd - 1)]
> return first + rest
> ...
> while True:
> print "copy %s from stdin direct delimiter ',';" % table_name
> for i in range(i,i+rows):
> print ','.join(row(i, width, maxint))
> print '\.'

I see the biggest potential in inlining randint. Unfortunately you did not 
provide an executable script and I had to make it up:

$ cat gry.py
from random import randint
import sys

def row(i, wd, mx):
first = ['%d' % i]
rest =  ['%d' % randint(1, mx) for i in range(wd - 1)]
return first + rest

def main():
table_name = "unknown"
maxint = sys.maxint
width = 500
rows = 1000
offset = 0

print "copy %s from stdin direct delimiter ',';" % table_name
for i in range(offset, offset+rows):
print ','.join(row(i, width, maxint))
print '\.'

if __name__ == "__main__":
main()
$ time python gry.py > /dev/null

real0m5.280s
user0m5.230s
sys 0m0.050s
$

$ cat gry_inline.py
import random
import math
import sys

def make_rand(n):
if n < 1 << random.BPF:
def rand(random=random.random):
return int(n*random())+1
else:
k = int(1.1 + math.log(n-1, 2.0))
def rand(getrandbits=random.getrandbits):
r = getrandbits(k)
while r >= n:
r = getrandbits(k)
return r+1
return rand

def row(i, wd, rand):
first = ['%d' % i]
rest =  ['%d' % rand() for i in range(wd - 1)]
return first + rest

def main():
table_name = "unknown"
maxint = sys.maxint
width = 500
rows = 1000
offset = 0

rand = make_rand(maxint)

print "copy %s from stdin direct delimiter ',';" % table_name
for i in range(offset, offset+rows):
print ','.join(row(i, width, rand))
print '\.'

if __name__ == "__main__":
main()
$ time python gry_inline.py > /dev/null

real0m2.004s
user0m2.000s
sys 0m0.000s
$

Disclaimer: the code in random.py is complex enough that I cannot guarantee 
I snatched the right pieces.

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


Re: performance of tight loop

2010-12-14 Thread Peter Otten
Peter Otten wrote:

> gry wrote:
> 
>> [python-2.4.3, rh CentOS release 5.5 linux, 24 xeon cpu's, 24GB ram]
>> I have a little data generator that I'd like to go faster... any
>> suggestions?
>> maxint is usually 9223372036854775808(max 64bit int), but could
>> occasionally be 99.
>> width is usually 500 or 1600, rows ~ 5000.
>> 
>> from random import randint
>> 
>> def row(i, wd, mx):
>> first = ['%d' % i]
>> rest =  ['%d' % randint(1, mx) for i in range(wd - 1)]
>> return first + rest
>> ...
>> while True:
>> print "copy %s from stdin direct delimiter ',';" % table_name
>> for i in range(i,i+rows):
>> print ','.join(row(i, width, maxint))
>> print '\.'
> 
> I see the biggest potential in inlining randint. Unfortunately you did not
> provide an executable script and I had to make it up:

> $ time python gry_inline.py > /dev/null
> 
> real0m2.004s
> user0m2.000s
> sys 0m0.000s

On second thought, if you have numpy available:

$ cat gry_numpy.py
from numpy.random import randint
import sys

def row(i, wd, mx):
first = ['%d' % i]
rest =  ['%d' % i for i in randint(1, mx, wd - 1)]
return first + rest

def main():
table_name = "unknown"
maxint = sys.maxint
width = 500
rows = 1000
offset = 0

print "copy %s from stdin direct delimiter ',';" % table_name
for i in range(offset, offset+rows):
print ','.join(row(i, width, maxint))
print '\.'

if __name__ == "__main__":
main()
$ time python gry_numpy.py > /dev/null

real0m1.024s
user0m1.010s
sys 0m0.010s
$

Argh

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


Re: packaging and installing

2010-12-14 Thread Brian Blais
On Dec 13, 2010, at 12:30 PM, Godson Gera wrote:

> 
> 
> On Mon, Dec 13, 2010 at 10:46 PM, Brian Blais  wrote:
>> Hello,
>> 
>> I was wondering if there is any standard or suggested way of installing 
>> packages *without* going to the commandline.  I often have students who, 
>> from there experience in Windows, have never looked at the commandline 
>> before and it is a bit of a challenge to get them to install something (i.e. 
>> go to the commandline, cd over to the proper folder, type python setup.py 
>> install, etc...).  I've never seen a package with something like a 
>> "compileme.bat", but was wondering if there is some suggested way of doing 
>> this or some reasons *not* to do this.  I can always write my own (1-line) 
>> .bat file, but I didn't want to reinvent the wheel.  Perhaps there is a 
>> better way for me to do this, ideally in a platform independent way.
>> 
> You don't even have to write a bat file. Python's distutils package allows 
> you to build exe file which creates generic windows wizard window for 
> installing packages. 
> 
> Take a look at distutils package 
> http://docs.python.org/distutils/builtdist.html
> 

that's very interesting, and I didn't realize that.  it may be useful, and 
solves part of my problem, but the other part is that I am not on a windows 
machine and have to distribute to windows users.  Or perhaps I am on windows, 
and need to distribute to Mac.  It's great that python itself is so 
cross-platform, but the installation process for packages seems a lot less so. 


thanks,

bb


-- 
Brian Blais
bbl...@bryant.edu
http://web.bryant.edu/~bblais
http://bblais.blogspot.com/



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


Re: packaging and installing

2010-12-14 Thread Godson Gera
On Tue, Dec 14, 2010 at 6:59 PM, Brian Blais  wrote:

>  On Dec 13, 2010, at 12:30 PM, Godson Gera wrote:
>
> >
> >
> > On Mon, Dec 13, 2010 at 10:46 PM, Brian Blais  wrote:
> >> Hello,
> >>
> >> I was wondering if there is any standard or suggested way of installing
> packages *without* going to the commandline.  I often have students who,
> from there experience in Windows, have never looked at the commandline
> before and it is a bit of a challenge to get them to install something (i.e.
> go to the commandline, cd over to the proper folder, type python setup.py
> install, etc...).  I've never seen a package with something like a
> "compileme.bat", but was wondering if there is some suggested way of doing
> this or some reasons *not* to do this.  I can always write my own (1-line)
> .bat file, but I didn't want to reinvent the wheel.  Perhaps there is a
> better way for me to do this, ideally in a platform independent way.
> >>
> > You don't even have to write a bat file. Python's distutils package
> allows you to build exe file which creates generic windows wizard window for
> installing packages.
> >
> > Take a look at distutils package
> http://docs.python.org/distutils/builtdist.html
> >
>
> that's very interesting, and I didn't realize that.  it may be useful, and
> solves part of my problem, but the other part is that I am not on a windows
> machine and have to distribute to windows users.  Or perhaps I am on
> windows, and need to distribute to Mac.  It's great that python itself is so
> cross-platform, but the installation process for packages seems a lot less
> so.
>
> Don't blame python for that. command line is least command denominator
across all platforms and you don't wanted your audience to visit command
line. As of 2010 you have to be on specific platform to make distributions
for that platform. This kind of asking for toomuch from a few MB sized
python. You need to make your own python distro to support all platform
specific(exe, msi, ELF, app, rpm, deb  etc etc ) packaing in one
installation whose size may swell over many MBs

or resort back to wiriting batch file on windows and bash and sh scripts on
*nix platforms.
-- 
Thanks & Regards,
Godson Gera
Asterisk Consultant India 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter polling example: file copy with progress bar

2010-12-14 Thread baloan
Unfortunately you use command('cp...') to copy the file instead of
Pythons portable library methods. This choice
effectively makes your program work on Unix only (not Windows).

See http://modcopy.sourceforge.net for a more portable version.

Regards,
bal...@gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter polling example: file copy with progress bar

2010-12-14 Thread D'Arcy J.M. Cain
On Tue, 14 Dec 2010 07:35:45 -0800 (PST)
baloan  wrote:
> Unfortunately you use command('cp...') to copy the file instead of
> Pythons portable library methods. This choice
> effectively makes your program work on Unix only (not Windows).
> 
> See http://modcopy.sourceforge.net for a more portable version.

I guess I missed the beginning of this thread but can someone tell me
why one needs to download a whole other program in order to do this?

  open(out_fn, 'w').write(open(in_fn).read())

-- 
D'Arcy J.M. Cain  |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
-- 
http://mail.python.org/mailman/listinfo/python-list


Sybase module 0.40pre1 released

2010-12-14 Thread Robert Boehne
WHAT IS IT:
The Sybase module provides a Python interface to the Sybase relational
database system.  It supports all of the Python Database API, version
2.0 with extensions.

** This version is a pre-release not intended for production use **

The module is available here:

http://downloads.sourceforge.net/python-sybase/python-sybase-0.40pre1.tar.gz

The module home page is here:

http://python-sybase.sourceforge.net/

MAJOR CHANGES SINCE 0.39:

Modify the DateTimeAsPython output conversion to return None when NULL is
output
support for Python without threads
Ignore additional non-error codes from Sybase (1918 and 11932)
Use outputmap in bulkcopy mode (thanks to patch by Cyrille Froehlich)
Raise exception when opening a cursor on a closed connection
Added unit tests
Added new exception DeadLockError when Sybase is in a deadlock situation
Add command properties CS_STICKY_BINDS and CS_HAVE_BINDS
Added support for inputmap in bulkcopy
reuse command and cursor when calling cursor.execute with same request
Use ct_setparam to define ct_cursor parameters types instead of ct_param
implicit conversion for CS_DATE_TYPE in CS_DATETIME_TYPE DataBuf
Adding ct_cmd_props wrapper
Increase DataBuf maxlength for params of a request when using CS_CHAR_TYPE
params so that the buf can be reused

BUGS CORRECTED SINCE 0.39:

Corrected money type when using CS_MONEY4 (close bug 2615821)
Corrected thread locking in ct_cmd_props (thanks to patch by Cyrille
Froehlich)
Corrected bug in type mapping in callproc (thanks to report by Skip
Montanaro)
Correct passing None in a DataBuf (thanks to patch by Bram Kuijvenhoven)

The full ChangeLog is here:

https://python-sybase.svn.sourceforge.net/svnroot/python-sybase/tags/r0_40pre1/ChangeLog
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter polling example: file copy with progress bar

2010-12-14 Thread Harishankar
On Tue, 14 Dec 2010 10:57:40 -0500, D'Arcy J.M. Cain wrote:
> I guess I missed the beginning of this thread but can someone tell me
> why one needs to download a whole other program in order to do this?
> 
>   open(out_fn, 'w').write(open(in_fn).read())

Or what about shutil? Isn't that the higher level file operation module?

-- 
Harishankar (http://harishankar.org http://lawstudentscommunity.com)

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


Re: Tkinter polling example: file copy with progress bar

2010-12-14 Thread D'Arcy J.M. Cain
On Tue, 14 Dec 2010 16:25:54 + (UTC)
Harishankar  wrote:
> On Tue, 14 Dec 2010 10:57:40 -0500, D'Arcy J.M. Cain wrote:
> >   open(out_fn, 'w').write(open(in_fn).read())
> Or what about shutil? Isn't that the higher level file operation module?

At least that's in the standard library but even then it can be
overkill for a simple copy.  It does do some error checking that the
above doesn't do if you need that.

-- 
D'Arcy J.M. Cain  |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: while True or while 1

2010-12-14 Thread Arnaud Delobelle
Gregory Ewing  writes:

> Steven D'Aprano wrote:
>
>while True:
>>
>> ... print "Looping"
>> ... True = 0
>
> Just remember that if you use that inside a function, you'll
> have to initialise True to True before... er, wait a moment,
> that won't work... ah, I know:
>
>   def f(true = True):
> True = true
> while True:
>   ...
>   True = False

You also need to initialise False to False for it to be really
robust. So something like this will do.

True = not 0
False = not True
while True:
...
True = False

:)

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


Re: Fail import with SWIG generated imp.load_module ?

2010-12-14 Thread MRAB

On 14/12/2010 08:43, Hvidberg, Martin wrote:

I'm trying to load a module GDAL into a Python script.

The loader/binderthat is then called, seems to be generated by SWIG, a
project with which I'm unfortunately not familiar.

The part of the SWIG generated code that fails on me is as follow:


[snip]
It _might_ be that imp.load_module(...) is raising an exception, so it
doesn't assign to '_mod', and then it tries to run the 'finally' block
and return _mod. This raises the exception you see and hides the
original cause.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Sage's Python

2010-12-14 Thread Akand Islam
On Dec 13, 4:33 pm, "Rhodri James" 
wrote:
> On Fri, 10 Dec 2010 17:11:55 -, Akand Islam  wrote:
> > In my system (Ubuntu 10.04) there are sage-4.6, python 2.6.5, tk8.5-
> > dev installed. When I give command from terminal "sage -f
> > python-2.6.5.p8" to get sage's python it shows following message:
>
> >  No command 'sage' found, did you mean:
> >  Command 'save' from package 'atfs' (universe)
> >  Command 'page' from package 'tcllib' (universe)
> >  sage: command not found
>
> > How can I get Sage's python to be worked so that I can import sage.all
> > in python shell?
>
> The fact that you have no executable called "sage" suggests that you  
> haven't actually installed it yet.  Check the Sage website, which has  
> plenty of documentation, and try to figure out where you left the path on  
> whichever method you used.
>
> --
> Rhodri James *-* Wildebeest Herder to the Masses

Dear Rhodri James,
Thanks for your response. But I have installed sage-4.6 as per
instructions. Sage-4.6 folder is in my ~/Desktop, therefore, from ~/
Desktop/sage-4.6 I can initiate ./sage and can work with sage.

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


Re: while True or while 1

2010-12-14 Thread Christian Heimes
Am 14.12.2010 17:52, schrieb Arnaud Delobelle:
> You also need to initialise False to False for it to be really
> robust. So something like this will do.
> 
> True = not 0
> False = not True
> while True:
> ...
> True = False

Tres Seavers once told me a joke like this:

   True = not not "Who's at the door?" # say it out loud!

This was back in the old days of Zope 2.5 and Python 2.1, which didn't
have True and False.

Christian

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


Re: ctypes question

2010-12-14 Thread News Wombat
On Dec 11, 12:59 pm, MrJean1  wrote:

> In general, for shared libraries, you need to define those first as
> prototype using ctypes.CFUNCTYPE() and then instantiate each prototype
> once supplying the necessary parameter flags using
> prototype(func_spec, tuple_of_param_flags).  See sections 15.16.2.3
> and 4 of the ctypes docs*.

I tried the cfuntype and proto steps, and it's not crashing now
(that's good), but now i'm just left with null pointers as a return
object.  I'm still working through all of the examples you sent.  They
were extremely helpful.  Here's where I'm at now...

What is strange is I can actually get smiGetNode to work if I don't
cfunctype/proto it.  If i do, nada.  however, the smiGetNextNode fails
no matter what, usually with a segfault, but depending on how i
construct it, sometimes a null pointer.

constants.py: http://pastebin.com/f3b4Wbf0
libsmi.py: http://pastebin.com/XgtpG6gr
smi.c (the actual function): http://pastebin.com/Pu2vabWM
-- 
http://mail.python.org/mailman/listinfo/python-list


Map Linux locale codes to Windows locale codes?

2010-12-14 Thread python
Is there a way to map Linux locale codes to Windows locale codes?

Windows has locale codes like 'Spanish_Mexico'. We would like to
use the more ISO compliant 'es_MX' locale format under Windows.

Is there a resource or API that might help us with this mapping?

Babel is not an option for us since we're using Python 2.7.

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


Concatenate a string as binary bytes

2010-12-14 Thread Jaime Fernández
Hi

To build a binary packet (for SMPP protocol), we have to concatenate
different types of data: integers, floats, strings.

We are using struct.pack to generate the binary representation of each
integer and float of the packet, and then they are concatenated with the +
operand.
However, for strings we directly concatenate the string with +, without
using struct.

Everything works with python 2 except when string encoding is introduced.
Whenever, a non ASCII char appears in the string, an exception is launched.
In python 3, it's not possible to do this trick because all the strings are
unicode.

What would be the best approach to:
 - Support non-ascii chars (we just want to concatenate the binary
representation of the string without any modification)
 - Compatibility between python 2 and python 3.

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


Re: Sage's Python

2010-12-14 Thread Emile van Sebille

On 12/14/2010 10:27 AM Akand Islam said...

On Dec 13, 4:33 pm, "Rhodri James"
wrote:

On Fri, 10 Dec 2010 17:11:55 -, Akand Islam  wrote:

In my system (Ubuntu 10.04) there are sage-4.6, python 2.6.5, tk8.5-
dev installed. When I give command from terminal "sage -f
python-2.6.5.p8" to get sage's python it shows following message:



  No command 'sage' found, did you mean:


This means that no sage command was found on your path.  Check to be 
sure that ~/Desktop is in your path.


Emile




  Command 'save' from package 'atfs' (universe)
  Command 'page' from package 'tcllib' (universe)
  sage: command not found



How can I get Sage's python to be worked so that I can import sage.all
in python shell?


The fact that you have no executable called "sage" suggests that you
haven't actually installed it yet.  Check the Sage website, which has
plenty of documentation, and try to figure out where you left the path on
whichever method you used.

--
Rhodri James *-* Wildebeest Herder to the Masses


Dear Rhodri James,
Thanks for your response. But I have installed sage-4.6 as per
instructions. Sage-4.6 folder is in my ~/Desktop, therefore, from ~/
Desktop/sage-4.6 I can initiate ./sage and can work with sage.

-- Akand



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


Re: Concatenate a string as binary bytes

2010-12-14 Thread MRAB

On 14/12/2010 19:50, Jaime Fernández wrote:

Hi

To build a binary packet (for SMPP protocol), we have to concatenate
different types of data: integers, floats, strings.

We are using struct.pack to generate the binary representation of each
integer and float of the packet, and then they are concatenated with the
+ operand.
However, for strings we directly concatenate the string with +, without
using struct.

Everything works with python 2 except when string encoding is
introduced. Whenever, a non ASCII char appears in the string, an
exception is launched. In python 3, it's not possible to do this trick
because all the strings are unicode.

What would be the best approach to:
  - Support non-ascii chars (we just want to concatenate the binary
representation of the string without any modification)
  - Compatibility between python 2 and python 3.


I'd say encode to UTF-8.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Concatenate a string as binary bytes

2010-12-14 Thread Benjamin Kaplan
2010/12/14 Jaime Fernández :
> Hi
> To build a binary packet (for SMPP protocol), we have to concatenate
> different types of data: integers, floats, strings.
> We are using struct.pack to generate the binary representation of each
> integer and float of the packet, and then they are concatenated with the +
> operand.
> However, for strings we directly concatenate the string with +, without
> using struct.
> Everything works with python 2 except when string encoding is introduced.
> Whenever, a non ASCII char appears in the string, an exception is launched.
> In python 3, it's not possible to do this trick because all the strings are
> unicode.
> What would be the best approach to:
>  - Support non-ascii chars (we just want to concatenate the binary
> representation of the string without any modification)
>  - Compatibility between python 2 and python 3.
> Thanks,
> Jaime
> --

I don't think you quite understand how encodings and unicode work.You
have two similar, but distinct data types involved: a byte string (""
in python 2.x, b"" in Python 3.x) which is a sequence of bytes, and a
unicode String (u"" in Python 2.x and "" in Python 3.x) which is a
sequence of characters. Neither type of strings has an encoding
associated with it- an encoding is just a function for converting
between these two data types.

You only get those non-ascii character problems when you try
concatenating Unicode strings with byte strings, because Python
defaults to using ASCII as the encoding when you don't specify the
encoding yourself. If you want to avoid those errors (in both Python
2.x and Python 3.x), use the unicode string's encode method to turn
the characters into a sequence of bytes before you concat them.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: while True or while 1

2010-12-14 Thread Arnaud Delobelle
Christian Heimes  writes:
[...]
> Tres Seavers once told me a joke like this:
>
>True = not not "Who's at the door?" # say it out loud!
>
> This was back in the old days of Zope 2.5 and Python 2.1, which didn't
> have True and False.

I almost used:

True = "to be" or not "to be" # that is the question

but didn't dare!

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


Re: PyArg_ParseTuple question

2010-12-14 Thread Mark Wooding
Mark Crispin  writes:

> In a C module, I want to pick up the arguments for a Python call like:
> module.call("string1",["string2a", "string2b", "string2c"], "string3")
> and stash these into:
>   char *arg1;
>   char *arg2[];
>   char *arg3;
> All arguments are required, and we can assume that the arg2 vector is
> terminated with a null pointer.
>
> It doesn't look like PyArg_ParseTuple will do this easily; and that
> instead I have to use either the "O!" format with a PyList prototype,
> or use "O&" and write a converter.

I think the latter is probably your best bet.

> If I use "O!", at what level does it check?  In particular, does it
> just check that the argument is a list, so I can get away with
> something like:

It does the equivalent of `isinstance', so you'll accept a `list' or an
instance of any subclass of `list'.

The `O&' converter is pretty straightforward.  Something like this ought
to do.

static int convertlist(PyObject *o, void *p)
{
  PyObject **v;
  Py_ssize_t i, n;

  /* Could allow general sequences using PySequence_Fast */
  if (!PyList_Check(o)) return (0);

  /* Copy stuff */
  n = PyList_GET_SIZE(o);
  if ((v = PyMem_New(PyObject *, n + 1)) == 0) return (0);
  for (i = 0; i < n; i++) {
v[i] = PyList_GET_ITEM(o, n);
Py_INCREF(v[i]);
  }
  v[n] = 0;

  return (1);
}

If you want to do a more complex conversion (e.g., to the individual
items) there's more work to be done.

I could have used PySequence_* functions to read the size and items, but
that makes error handling more complicated.  One could also borrow the
references from the underlying list, which would leave the underlying
storage for the vector as the only thing to free.

I ended up writing a lot of conversion functions when I was doing Python
library bindings (for a crypto library); they're generally a good thing.
I found that the trickiest thing about PyArg_ParseTuple is in making
sure that you can clean everything up even if it goes wrong half way
through.

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


Re: Map Linux locale codes to Windows locale codes?

2010-12-14 Thread Flávio Lisbôa
You could look into the windows registry, the key
"HKLM\SYSTEM\CurrentControlSet\Control\Nls" has all the supported LCID's
listed. If not, you could simply get the codepage provided by
locale.setlocale(), e.g.:

import locale
print(locale.setlocale(locale.LC_ALL, ""))

prints "Portuguese_Brazil.1252" for me. That codepage part is actually a
LCID, that you can then cross-reference with any LCID list on the net. I
guess there may be a way to look that up entirely from the registry,
including getting a short reference or ANSI codepage from the LCID, but i
doubt it'd be portable at all.

Maybe what you should do is to make up a dict with known LCID's and their
corresponding language codes. I don't know of any way to do this
automatically in python...

Take a look at http://msdn.microsoft.com/en-us/goglobal/bb896001.aspx

2010/12/14 

> Is there a way to map Linux locale codes to Windows locale codes?
>
> Windows has locale codes like 'Spanish_Mexico'. We would like to use the
> more ISO compliant 'es_MX' locale format under Windows.
>
> Is there a resource or API that might help us with this mapping?
>
> Babel is not an option for us since we're using Python 2.7.
>
> Thank you,
> Malcolm
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


How to pop the interpreter's stack?

2010-12-14 Thread kj



Consider this code:


def spam(*args, **kwargs):
args, kwargs = __pre_spam(*args, **kwargs)

# args & kwargs are OK: proceed
# ...


def __pre_spam(*args, **kwargs):
# validate args & kwargs;
# return canonicalized versions of args & kwargs;
# on failure, raise some *informative* exception
# ...
 
return canonicalized_args, canonicalized_kwargs


I write functions like __pre_spam for one reason only: to remove
clutter from a corresponding spam function that has a particularly
complex argument-validation/canonicalization stage.  In effect,
spam "outsources" to __pre_spam the messy business of checking and
conditioning its arguments.

The one thing I don't like about this strategy is that the tracebacks
of exceptions raised during the execution of __pre_spam include one
unwanted stack level (namely, the one corresponding to __pre_spam
itself).

__pre_spam should be completely invisible and unobtrusive, as if
it had been textually "inlined" into spam prior to the code's
interpretation.  And I want to achieve this without in any way
cluttering spam with try/catches, decorators, and whatnot.  (After
all, the whole point of introducing __pre_spam is to declutter
spam.)

It occurs to me, in my innocence (since I don't know the first
thing about the Python internals), that one way to achieve this
would be to have __pre_spam trap any exceptions (with a try/catch
around its entire body), and somehow pop its frame from the
interpreter stack before re-raising the exception.  (Or some
clueful/non-oxymoronic version of this.)  How feasible is this?
And, if it is quite unfeasible, is there some other way to achieve
the same overall design goals described above?

TIA!

~kj


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


Alternative to PIL in Python 3.1

2010-12-14 Thread craf
Hi.

I wonder if anyone knows any alternative to PIL library, as this does
not work with Python 3.1.

Thanks in advance

Regards.

Cristian

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


How to experience python on a handheld, tablet, etc on linux?

2010-12-14 Thread stateslave

Without buying first? 

I'd like to run the front end of all these new devices,
on my PC and program in python, to assess which is the
best on for me. pre-test python scripts before cross
loading onto the device I finally buy.

Is that possible? It would also be nice to have some of
the look and feel on a PC of these devices anyway, with
python of course. 

Has that be done yet? 

Any hints? Cheers in advance.
-- 
http://mail.python.org/mailman/listinfo/python-list


Combing Medusa's Hair... (Design Pattern)

2010-12-14 Thread kirby.ur...@gmail.com

This is an idea I got thinking about COM objects, and getting
some support from Mark Hammond, Python's Win32 wizard.

The goal is to have a host language (not Python) instantiate
an object that runs against the Python interpreter, which lives
as its own process.  The VMs have various ways of implementing
this.  Mono isn't that different right?

In this design pattern, you have something like a dry cleaner's,
where people submit jobs at the counter, and go away right
away with a ticket (Python returns -- but keeps running).  When
they come back is more up to them.  Work has been done in
the meantime (or not, if the queue is backed up).

So Python needs a queue in the front, to accept these job orders,
a facility for issuing tickets, and a way to catalog what tasks
are completed in some urn or receptacle (given this is Python,
we might call it a "holy grail").

The host process has a method from querying the Python object
as to whether such-and-such a job is complete or not.  More
primitively, it could just check an output bin (folder) for the
expected file (perhaps each "hair" creates a PDF in roughly
1 to 4 seconds).

The reason "Medusa" is useful wordplay is it reminds us of the
asynchronous server embedded in early Zope.  How Medusa
relates to Twisted is lore for others to recount.  However, given
we're spawning strands, hairs or threads each time a host process
calls into our object, we're looking at a multi-snaked environment,
so the image could hardly be more apt.

The act of "combing" suggests some synchronization / communication
between threads, but that's not a requirement.

More on tap here:
http://mail.python.org/pipermail/edu-sig/2010-December/010141.html

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


Re: Alternative to PIL in Python 3.1

2010-12-14 Thread Emile van Sebille

On 12/14/2010 3:17 PM craf said...

Hi.

I wonder if anyone knows any alternative to PIL library, as this does
not work with Python 3.1.

Thanks in advance

Regards.

Cristian




You might try the 1.1.6 port referenced here:

http://www.mail-archive.com/image-sig@python.org/msg02404.html

Emile

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


Re: ctypes question

2010-12-14 Thread MrJean1
Try again after changing line 16 to

  sn = SmiGetNode(None, "1.3.6.1.2.1.2.2")

Because, SmiGetNode is a Python function which accepts Python objects
as arguments.  Passing is a ctypes object oid is incorrect.

/Jean


On Dec 14, 10:36 am, News Wombat  wrote:
> On Dec 11, 12:59 pm, MrJean1  wrote:
>
> > In general, for shared libraries, you need to define those first as
> > prototype using ctypes.CFUNCTYPE() and then instantiate each prototype
> > once supplying the necessary parameter flags using
> > prototype(func_spec, tuple_of_param_flags).  See sections 15.16.2.3
> > and 4 of the ctypes docs*.
>
> I tried the cfuntype and proto steps, and it's not crashing now
> (that's good), but now i'm just left with null pointers as a return
> object.  I'm still working through all of the examples you sent.  They
> were extremely helpful.  Here's where I'm at now...
>
> What is strange is I can actually get smiGetNode to work if I don't
> cfunctype/proto it.  If i do, nada.  however, the smiGetNextNode fails
> no matter what, usually with a segfault, but depending on how i
> construct it, sometimes a null pointer.
>
> constants.py:http://pastebin.com/f3b4Wbf0
> libsmi.py:http://pastebin.com/XgtpG6gr
> smi.c (the actual function):http://pastebin.com/Pu2vabWM

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


[Fwd: Re: Alternative to PIL in Python 3.1]

2010-12-14 Thread craf
- Mensaje reenviado 
> De: Emile van Sebille 
> Para: python-list@python.org
> Asunto: Re: Alternative to PIL in Python 3.1
> Fecha: Tue, 14 Dec 2010 16:39:19 -0800
> 
> On 12/14/2010 3:17 PM craf said...
> > Hi.
> >
> > I wonder if anyone knows any alternative to PIL library, as this does
> > not work with Python 3.1.
> >
> > Thanks in advance
> >
> > Regards.
> >
> > Cristian
> >
> 
> 
> You might try the 1.1.6 port referenced here:
> 
> http://www.mail-archive.com/image-sig@python.org/msg02404.html
> 
> Emile
> 
Hi Emile.

Thanks for the info.

I'll try it.

Regards.

Cristian

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


Re: How to experience python on a handheld, tablet, etc on linux?

2010-12-14 Thread Benjamin Kaplan
On Tue, Dec 14, 2010 at 6:30 PM, stateslave  wrote:
>
> Without buying first?
>
> I'd like to run the front end of all these new devices,
> on my PC and program in python, to assess which is the
> best on for me. pre-test python scripts before cross
> loading onto the device I finally buy.
>
> Is that possible? It would also be nice to have some of
> the look and feel on a PC of these devices anyway, with
> python of course.
>
> Has that be done yet?
>
> Any hints? Cheers in advance.
> --

Python on Linux is Python on Linux. Whether you have Ubuntu running on
a tablet or on a desktop, it's going to behave the same. There are
going to be two important things different between running Linux on
your PC and running it on a tablet: the processor and the UI. And
there's really no good way to simulate either one of those.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to pop the interpreter's stack?

2010-12-14 Thread Ethan Furman

kj wrote:

The one thing I don't like about this strategy is that the tracebacks
of exceptions raised during the execution of __pre_spam include one
unwanted stack level (namely, the one corresponding to __pre_spam
itself).

__pre_spam should be completely invisible and unobtrusive


I am unaware of any way to accomplish what you desire.  I also think 
this is one of those things that's not worth fighting -- how often are 
you going to see such a traceback?  When somebody makes a coding 
mistake?  I would say change the name (assuming yours was a real 
example) to something more meaningful like _spam_arg_verifier and call 
it good.


Alternatively, perhaps you could make a more general arg_verifier that 
could be used for all such needs, and then your traceback would have:


caller

spam

arg_verifier

and that seems useful to me (it is, in fact, how I have mine set up).

Hope this helps!

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


Re: Proposed changes to logging defaults

2010-12-14 Thread samwyse
On Dec 9, 6:12 pm, Vinay Sajip  wrote:
> Some changes are being proposed to how logging works in default
> configurations.
>
> Briefly - when a logging event occurs which needs to be output to some
> log, the behaviour of the logging package when no explicit logging
> configuration is provided will change, most likely to log those events
> to sys.stderr with a default format.

I'm in favor of this change.  I've long wished that I could just add
lots of warning/error/info logging to a script and have it just work
without having to spend time configuring the logging system.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Combing Medusa's Hair... (Design Pattern)

2010-12-14 Thread Kushal Kumaran
On Wed, Dec 15, 2010 at 5:04 AM, kirby.ur...@gmail.com
 wrote:
>
> This is an idea I got thinking about COM objects, and getting
> some support from Mark Hammond, Python's Win32 wizard.
>
> The goal is to have a host language (not Python) instantiate
> an object that runs against the Python interpreter, which lives
> as its own process.  The VMs have various ways of implementing
> this.  Mono isn't that different right?
>
> In this design pattern, you have something like a dry cleaner's,
> where people submit jobs at the counter, and go away right
> away with a ticket (Python returns -- but keeps running).  When
> they come back is more up to them.  Work has been done in
> the meantime (or not, if the queue is backed up).
>

Isn't this the way people use queuing systems (ActiveMQ and the like)?
 Or simply multiprocessing + Queue.

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


Re: Tkinter polling example: file copy with progress bar

2010-12-14 Thread JohnWShipman
On Dec 14, 8:57 am, "D'Arcy J.M. Cain"  wrote:
> On Tue, 14 Dec 2010 07:35:45 -0800 (PST)
>
> baloan  wrote:
> > Unfortunately you use command('cp...') to copy the file instead of
> > Pythons portable library methods. This choice
> > effectively makes your program work on Unix only (not Windows).
>
> > Seehttp://modcopy.sourceforge.netfor a more portable version.
>
> I guess I missed the beginning of this thread but can someone tell me
> why one needs to download a whole other program in order to do this?
>
>   open(out_fn, 'w').write(open(in_fn).read())

I posted this example because I got several queries on how to do
polling in Tkinter, specifically how to use the .after() universal
widget method.  The points about using the portable library methods
are all well taken.  I used file copy as the example long-running
process because a reader wanted to know how to do that specifically.
Please forgive me for not thinking about portability and stuff; you
know how us ancient Unix weenies are.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter polling example: file copy with progress bar

2010-12-14 Thread JohnWShipman
On Dec 14, 8:57 am, "D'Arcy J.M. Cain"  wrote:
> On Tue, 14 Dec 2010 07:35:45 -0800 (PST)
>
> baloan  wrote:
> > Unfortunately you use command('cp...') to copy the file instead of
> > Pythons portable library methods. This choice
> > effectively makes your program work on Unix only (not Windows).
>
> > Seehttp://modcopy.sourceforge.netfor a more portable version.
>
> I guess I missed the beginning of this thread but can someone tell me
> why one needs to download a whole other program in order to do this?
>
>   open(out_fn, 'w').write(open(in_fn).read())

I posted this example because I got several queries on how to do
polling in Tkinter, specifically how to use the .after() universal
widget method.  The points about using the portable library methods
are all well taken.  I used file copy as the example long-running
process because a reader wanted to know how to do that specifically.
Please forgive me for not thinking about portability and stuff; you
know how us ancient Unix weenies are.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Combing Medusa's Hair... (Design Pattern)

2010-12-14 Thread kirby urner
On Tue, Dec 14, 2010 at 8:10 PM, Kushal Kumaran
 wrote:

<< snip >>

>>
>> In this design pattern, you have something like a dry cleaner's,
>> where people submit jobs at the counter, and go away right
>> away with a ticket (Python returns -- but keeps running).  When
>> they come back is more up to them.  Work has been done in
>> the meantime (or not, if the queue is backed up).
>>
>
> Isn't this the way people use queuing systems (ActiveMQ and the like)?
>  Or simply multiprocessing + Queue.
>
> --
> regards,
> kushal
>

Yeah, that's probably right.  This is more like a pedagogical
metaphor, a mnemonic.  As the name for a design pattern,
it should probably be confined to Python examples, as that's
where the wordplay on Medusa makes some sense, and
not just because her hair was all snakes.

http://bytes.com/topic/python/answers/26771-twisted-medusa-zope

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


Re: ctypes question

2010-12-14 Thread Mark Tolonen
"News Wombat"  wrote in message 
news:413f5a8f-69a0-4351-acc2-18d7edda8...@j3g2000vbp.googlegroups.com...

On Dec 11, 12:59 pm, MrJean1  wrote:

> In general, for shared libraries, you need to define those first as
> prototype using ctypes.CFUNCTYPE() and then instantiate each prototype
> once supplying the necessary parameter flags using
> prototype(func_spec, tuple_of_param_flags). See sections 15.16.2.3
> and 4 of the ctypes docs*.

I tried the cfuntype and proto steps, and it's not crashing now
(that's good), but now i'm just left with null pointers as a return
object.  I'm still working through all of the examples you sent.  They
were extremely helpful.  Here's where I'm at now...

What is strange is I can actually get smiGetNode to work if I don't
cfunctype/proto it.  If i do, nada.  however, the smiGetNextNode fails
no matter what, usually with a segfault, but depending on how i
construct it, sometimes a null pointer.

constants.py: http://pastebin.com/f3b4Wbf0
libsmi.py: http://pastebin.com/XgtpG6gr
smi.c (the actual function): http://pastebin.com/Pu2vabWM
--
http://mail.python.org/mailman/listinfo/python-list


constants.py, in SmiNode and SmiModule definitions:
  - Any field defined "char*" in C should be "c_char_p" not 
"POINTER(c_char_p)" (which is char**).


The function definition can be simplified, and 2nd argument corrected 
(c_char_p not POINTER(c_char_p)).  Python strings can be passed directly to 
c_char_p arguments.


  SmiGetNode = clibsmi.smiGetNode
  SmiGetNode.argtypes = [POINTER(SmiModule),c_char_p]
  SmiGetNode.restype = POINTER(SmiNode)
  oid = "1.3.6.1.2.1.2.2"
  sn=SmiGetNode(None,oid)

Give these fixes a try...

-Mark


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


how tohandling output generated after execution of command/script on host unix machine?

2010-12-14 Thread Darshak Bavishi
Hi Experts,

I am still struggling with handling output generated after execution of
 command/script on host unix machine using windows client machine

ssh code :

import sys
import datetime
import time
# setup logging
paramiko.util.log_to_file('darshak_simple.log')
ssh=paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect("*",username="",password="")
try:
stdin,stdout,stderr=ssh.exec_command("BsPlSMProbe -f node -d >
/var/log/Darshak/3.txt ") // output of this command will be store in
/var/log/Darshak/ in remote machine
except:
  {Issue is
files are generating but remaining blank pls pls help me out of this}
print "check"
time.sleep(10)
print stdout.readlines()
a=stdout.readlines()
print 1
ssh.close()
#print stdout.readlines()

Issue is files are generating but remaining blank pls pls help me out of
this
-- 
BR
Darshak Bavishi
-- 
http://mail.python.org/mailman/listinfo/python-list