Error in Plex 1.1.4.1
Hello,
I got the following error while using Plex 1.1.4.1
D:\Python24\myfiles>python plex1.py
Traceback (most recent call last):
File "plex1.py", line 1, in ?
from Plex import *
File "D:\python24\lib\site-packages\Plex\__init__.py", line 34, in ?
from Lexicons import Lexicon, State
File "D:\python24\lib\site-packages\Plex\Lexicons.py", line 12, in ?
import DFA
File "D:\python24\lib\site-packages\Plex\DFA.py", line 9, in ?
import Machines
File "D:\python24\lib\site-packages\Plex\Machines.py", line 14, in ?
from Transitions import TransitionMap
File "D:\python24\lib\site-packages\Plex\Transitions.py", line 85
def get_epsilon(self,
SyntaxError: Invalid syntax. Assignment to None.
The corresponding source code :
#file plex1.py
from Plex import *
lexicon = Lexicon([
(Str("Python"), "my_favourite_language"),
(Str("Perl"),"the_other_language"),
(Str("rocks"), "is_excellent"),
(Str("sucks"), "is_differently_good"),
(Rep1(Any(" \t\n")), IGNORE)
])
filename = "plex1.txt"
f = open(filename, "r")
scanner = Scanner(lexicon, f, filename)
while 1:
token = scanner.read()
print token
if token[0] is None:
break
The error was removed when I used the following code in Transitions.py
def get_epsilon(self,
none = None):
"""
Return the mapping for epsilon, or None.
"""
return self.special.get('', None)
Regards,
Srijit
--
http://mail.python.org/mailman/listinfo/python-list
Re: FTPLIB & FTPS or SFTP?
To the best of my knowledge ftplib does not support SFTP or FTPS. I hope Paramiko (http://www.lag.net/paramiko/) serves your purpose. Paramiko supports POSIX, Windows and MacOSX Regards, /Srijit Peter A. Schott wrote: > Does the ftplib support SFTP or FTPS? Is that part of a different module? We > have a handful of partners who use FTPS or SFTP and I need to pull/push files > to/from them. > > > Thank you for all of your help. > > -Pete Schott -- http://mail.python.org/mailman/listinfo/python-list
Memory mapped File (Python win32 extensions)
Hello, I see that it is possible to use mmapfile.pyd of win32all. The same is mentioned in http://www.python.org/windows/win32/#mmapfile. Unfortunately I could not trace any example using mmapfile. Any example or link to an example will be of help. I am interested to learn how to achieve efficient sharing of data between separate processes using mmapfile. Regards, /Srijit -- http://mail.python.org/mailman/listinfo/python-list
Shared Memory Example (Python, ctypes, VC++)
Hello,
Here are code snippets to create and access shared memory in Python
with and without ctypes module.
With regards,
Srijit
Filename : SharedMemCreate.py
import msvcrt, mmap
from ctypes import *
FILE_MAP_ALL_ACCESS = 0xF001F
INVALID_HANDLE_VALUE = 0x
SHMEMSIZE = 256
PAGE_READWRITE = 0x04
szName = c_char_p("MyFileMappingObject_ctypes")
szMsg = "Message from Python(ctypes) process"
hMapObject = windll.kernel32.CreateFileMappingA(INVALID_HANDLE_VALUE,
None, PAGE_READWRITE, 0, SHMEMSIZE, szName)
if (hMapObject == 0):
print "Could not open file mapping object"
raise WinError()
pBuf = windll.kernel32.MapViewOfFile(hMapObject, FILE_MAP_ALL_ACCESS,
0, 0, SHMEMSIZE)
if (pBuf == 0):
print "Could not map view of file"
raise WinError()
else:
memcpy = cdll.msvcrt.memcpy
memcpy(pBuf, szMsg, len(szMsg))
shmem = mmap.mmap(0, 256, "MyFileMappingObject", mmap.ACCESS_WRITE)
shmem.write("Message from Python process")
msvcrt.getch()
windll.kernel32.UnmapViewOfFile(pBuf)
windll.kernel32.CloseHandle(hMapObject)
shmem.close()
Filename : SharedMemAccess.py
from ctypes import *
import mmap
FILE_MAP_ALL_ACCESS = 0xF001F
INVALID_HANDLE_VALUE = 0x
FALSE = 0
TRUE = 1
SHMEMSIZE = 256
szName = c_char_p("MyFileMappingObject")
hMapObject = windll.kernel32.OpenFileMappingA(FILE_MAP_ALL_ACCESS,
FALSE, szName)
if (hMapObject == 0):
print "Could not open file mapping object"
raise WinError()
pBuf = windll.kernel32.MapViewOfFile(hMapObject, FILE_MAP_ALL_ACCESS,
0, 0, 0)
if (pBuf == 0):
print "Could not map view of file"
raise WinError()
else:
pBuf_str = cast(pBuf, c_char_p)
print pBuf_str.value
windll.kernel32.UnmapViewOfFile(pBuf)
windll.kernel32.CloseHandle(hMapObject)
shmem = mmap.mmap(0, 256, "MyFileMappingObject_ctypes",
mmap.ACCESS_READ)
print shmem.read(64)
shmem.close()
Source code to access shared memory, created in Python, from VC++
program
// Cplusplus_SharedMemoryAccess.cpp : Defines the entry point for the
console application.
//
#include "stdafx.h"
using namespace std;
#include
#include
#include
#include
#define SHMEMSIZE 256
HANDLE hMapObject = NULL; // handle to file mapping
LPCTSTR pBuf;
TCHAR szName[]= TEXT("MyFileMappingObject");
int _tmain(int argc, _TCHAR* argv[])
{
hMapObject = OpenFileMapping(
FILE_MAP_ALL_ACCESS, // read/write access
FALSE, // do not inherit the name
szName // name of mapping object
);
if (hMapObject == NULL || hMapObject == INVALID_HANDLE_VALUE) {
cout << "Could not open file mapping object " << GetLastError()
<< endl;
return 0;
}
pBuf = (LPTSTR) MapViewOfFile(hMapObject,// handle to mapping
object
FILE_MAP_ALL_ACCESS, // read/write
permission
0,
0,
SHMEMSIZE
);
if (pBuf == NULL)
{
cout << "Could not map view of file " << GetLastError() << endl;
return 0;
}
cout << "pBuf = " << pBuf << endl;
MessageBox(NULL, pBuf, TEXT("Process2"), MB_OK);
UnmapViewOfFile(pBuf);
CloseHandle(hMapObject);
return 0;
}
--
http://mail.python.org/mailman/listinfo/python-list
Python 2.4 (Windows) Binaries of SciPy
Hello, I have posted a similar message in SciPy mailing list. I hope it is ok to also post it here. I am looking for Python 2.4 Binaries (Windows)of SciPy. Are there any plans to upload Python 2.4 binaries? Best Regards, /Srijit -- http://mail.python.org/mailman/listinfo/python-list
Example Code - Named Pipes (Python 2.4 + ctypes on Windows)
Hello, Here is an example of Multithreaded Pipe Server and Client using the excellent ctypes library (Windows). Reference - MSDN: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ipc/base/multithreaded_pipe_server.asp and http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ipc/base/named_pipe_client.asp Best Regards, Srijit Named Pipe Server Source Code: from ctypes import * PIPE_ACCESS_DUPLEX = 0x3 PIPE_TYPE_MESSAGE = 0x4 PIPE_READMODE_MESSAGE = 0x2 PIPE_WAIT = 0 PIPE_UNLIMITED_INSTANCES = 255 BUFSIZE = 4096 NMPWAIT_USE_DEFAULT_WAIT = 0 INVALID_HANDLE_VALUE = -1 ERROR_PIPE_CONNECTED = 535 MESSAGE = "Default answer from server\0" szPipename = ".\\pipe\\mynamedpipe" def ReadWrite_ClientPipe_Thread(hPipe): chBuf = create_string_buffer(BUFSIZE) cbRead = c_ulong(0) while 1: fSuccess = windll.kernel32.ReadFile(hPipe, chBuf, BUFSIZE, byref(cbRead), None) if ((fSuccess ==1) or (cbRead.value != 0)): print chBuf.value cbWritten = c_ulong(0) fSuccess = windll.kernel32.WriteFile(hPipe, c_char_p(MESSAGE), len(MESSAGE), byref(cbWritten), None ) else: break if ( (not fSuccess) or (len(MESSAGE) != cbWritten.value)): print "Could not reply to the client's request from the pipe" break else: print "Number of bytes written:", cbWritten.value windll.kernel32.FlushFileBuffers(hPipe) windll.kernel32.DisconnectNamedPipe(hPipe) windll.kernel32.CloseHandle(hPipe) return 0 def main(): THREADFUNC = CFUNCTYPE(c_int, c_int) thread_func = THREADFUNC(ReadWrite_ClientPipe_Thread) while 1: hPipe = windll.kernel32.CreateNamedPipeA(szPipename, PIPE_ACCESS_DUPLEX, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, BUFSIZE, BUFSIZE, NMPWAIT_USE_DEFAULT_WAIT, None ) if (hPipe == INVALID_HANDLE_VALUE): print "Error in creating Named Pipe" return 0 fConnected = windll.kernel32.ConnectNamedPipe(hPipe, None) if ((fConnected == 0) and (windll.kernel32.GetLastError() == ERROR_PIPE_CONNECTED)): fConnected = 1 if (fConnected == 1): dwThreadId = c_ulong(0) hThread = windll.kernel32.CreateThread(None, 0, thread_func, hPipe, 0, byref(dwThreadId)) if (hThread == -1): print "Create Thread failed" return 0 else: windll.kernel32.CloseHandle(hThread) else: print "Could not connect to the Named Pipe" windll.kernel32.CloseHandle(hPipe) return 0 if __name__ == "__main__": main() Named Pipe Client Source Code: from ctypes import * GENERIC_READ = 0x8000 GENERIC_WRITE = 0x4000 OPEN_EXISTING = 0x3 INVALID_HANDLE_VALUE = -1 PIPE_READMODE_MESSAGE = 0x2 ERROR_PIPE_BUSY = 231 ERROR_MORE_DATA = 234 BUFSIZE = 512 MESSAGE = "Default message from client\0" szPipename = ".\\pipe\\mynamedpipe" def main(): while 1: hPipe = windll.kernel32.CreateFileA(szPipename, GENERIC_READ | GENERIC_WRITE, 0, None, OPEN_EXISTING, 0, None) if (hPipe != INVALID_HANDLE_VALUE): break else: print "Invalid Handle Value" if (windll.kernel32.GetLastError() != ERROR_PIPE_BUSY): print "Could not open pipe" return elif ((windll.kernel32.WaitNamedPipeA(szPipename, 2)) == 0): print "Could not open pipe\n" return dwMode = c_ulong(PIPE_READMODE_MESSAGE) fSuccess = windll.kernel32.SetNamedPipeHandleState(hPipe, byref(dwMode), None, None); if (not fSuccess): print "SetNamedPipeHandleState failed" cbWritten = c_ulong(0) fSuccess = windll.kernel32.WriteFile(hPipe, c_char_p(MESSAGE), len(MESSAGE), byref(cbWritten), None) if ((not fSuccess) or (len(MESSAGE) != cbWritten.value)): print "Write File failed" return else: print "Number of bytes written:", cbWritten.value fSuccess = 0 chBuf = create_string_buffer(BUFSIZE) cbRead = c_ulong(0) while (not fSuccess): # repeat loop if ERROR_MORE_DATA fSuccess = windl
Re: Example Code - Named Pipes (Python 2.4 + ctypes on Windows)
Hello, I am quite familiar with Mark Hammond's win32all. It is excellent. However, I wish that there was more documentation of win32all beyond existing PyWin32.chm. I am aware of "Python Programming on Win32" but I do not have access to it at present. Best Regards, /Srijit -- http://mail.python.org/mailman/listinfo/python-list
Example Code : Shared Memory with Mutex (pywin32 and ctypes)
Hello,
Here is some sample code with pywin32 build 203 and ctypes 0.9.6.
Best regards,
/Srijit
File: SharedMemCreate_Mutex_win32all.py
# This application should be used with SharedMemAccess_Mutex_ctypes.py
or SharedMemAccess_Mutex_win32all.py
#~ a) Creates a shared memory
#~ b) Creates or Opens a mutex
#~ c) Reads the contents (null terminated string) of shared memory
#~ d) Acquires a mutex and then writes a null terminated string to the
shared memory
#~ e) Sleeps upto 2 seconds. Sleep time is generated by a random number
#~ f) Repeats steps (c), (d) and (e) indefintely
import mmap, random, time
import win32event, pywintypes, win32api
def main():
SHMEMSIZE = 256
ERROR_ALREADY_EXISTS = 183
szName = "MyFileMappingObject"
szMsg1 = "Message from first process using win32all and mmap - "
szMutex = "MyMutexObject"
shmem = mmap.mmap(0, SHMEMSIZE, szName, mmap.ACCESS_WRITE)
try:
hMutex = win32event.CreateMutex(None, pywintypes.FALSE,
szMutex)
if (win32api.GetLastError() == ERROR_ALREADY_EXISTS):
print"Opened existing mutex object", szMutex
else:
print "Created new mutex"
i=0
random.seed()
while 1:
szMsg1 = szMsg1 + hex(i) + "\0"
if (len(szMsg1) > SHMEMSIZE):
print "Current size of string message is", len(szMsg1),
"and greater than", SHMEMSIZE
break
shmem_read = shmem.read(SHMEMSIZE)
shmem_read = shmem_read.rstrip(chr(0))
shmem_read = shmem_read.rstrip(" ")
print "RECEIVED from SECOND Process: ", shmem_read
shmem.seek(0)
wait_result = win32event.WaitForSingleObject(hMutex, 1000)
if (wait_result == win32event.WAIT_OBJECT_0):
shmem.write(szMsg1)
while (shmem.tell() != SHMEMSIZE):
shmem.write_byte(" ")
shmem.seek(0)
print "WROTE in FIRST process: ", szMsg1
win32event.ReleaseMutex(hMutex)
elif(wait_result == win32event.WAIT_TIMEOUT):
print "COULD NOT ACQUIRE MUTEX. TIMEOUT OCCURED"
elif (wait_result == win32event.WAIT_ABONDONED):
print "WAIT ABANDONED"
i = i + 1
szMsg1 = "Message from first process using win32all and
mmap - "
time.sleep(random.random()*2)
except pywintypes.error, (errno, object, strerror):
print "Error in", object, ":", strerror
if __name__ == "__main__":
main()
File: SharedMemCreate_Mutex_ctypes.py
# This application should be used with SharedMemAccess_Mutex_ctypes.py
or SharedMemAccess_Mutex_win32all.py
#~ a) Creates a shared memory
#~ b) Creates or Opens a mutex
#~ c) Reads the contents (null terminated string) of shared memory
#~ d) Acquires a mutex and then writes a null terminated string to the
shared memory
#~ e) Sleeps upto 2 seconds. Sleep time is generated by a random number
#~ f) Repeats steps (c), (d) and (e) indefintely
# There are two options to implement this code - Option A or Option B.
If Option B(A) is chosen then
# Option A(B) should be commented.
import random, time
from ctypes import *
def main():
try:
SHMEMSIZE = 256
TRUE = 1
FALSE = 0
ERROR_ALREADY_EXISTS = 183
FILE_MAP_ALL_ACCESS = 0xF001F
WAIT_OBJECT_0 = 0
WAIT_TIMEOUT = 0x102
WAIT_ABANDONED = 0x80
PAGE_READWRITE = 0x04
INVALID_HANDLE_VALUE = 0x
szName = "MyFileMappingObject"
szMsg1 = "Message from first process using ctypes - "
szMutex = "MyMutexObject"
hMutex = windll.kernel32.CreateMutexA(None, FALSE, szMutex)
if (hMutex == 0):
raise WinError()
elif (windll.kernel32.GetLastError() == ERROR_ALREADY_EXISTS):
print"Opened existing mutex object", szMutex
else:
print "Created new mutex"
hMap = windll.kernel32.CreateFileMappingA(INVALID_HANDLE_VALUE,
None, PAGE_READWRITE, 0, SHMEMSIZE, szName)
if (hMap == 0):
print "Could not open file mapping object"
raise WinError()
MapViewOfFile = windll.kernel32.MapViewOfFile
MapViewOfFile.restype = POINTER(c_char) # Option A
pBuf = MapViewOfFile(hMap, FILE_MAP_ALL_ACCESS, 0, 0, 0)
if (pBuf == 0):
raise WinError()
i=0
random.seed()
while 1:
szMsg1 = szMsg1 + hex(i) + "\0"
pBuf_str = cast(pBuf, c_char_p) # Option A
if (len(szMsg1) > SHMEMSIZE):
print "Current size of string message is", len(szMsg1),
"and greater th
Modelica
I am looking for possible options to interface Modelica (http://www.modelica.org/) with Python (scipy and numpy). Any suggestions? Best Regards, Srijit -- http://mail.python.org/mailman/listinfo/python-list
Re: Modelica
Is it possible to process Modelica models with Python? I found one possible approach: (a) Use ModelicaXML (http://www.ida.liu.se/~adrpo/ModelicaXML) to represent Modelica code as XML (b) Generate Python code (using numpy and scipy) from this XML file. Is there any better approach? Best Regards, Srijit [EMAIL PROTECTED] wrote: > Srijit Kumar Bhadra wrote: > > I am looking for possible options to interface Modelica > > (http://www.modelica.org/) with Python (scipy and numpy). Any > > suggestions? > > When you say "interface", what do you mean? > > Do you want to be able to process Modelica models or do you simply want > to be able to communicate with a Modelica tool. > > > Best Regards, > > Srijit > > -- > Mike -- http://mail.python.org/mailman/listinfo/python-list
lxml and SimpleXMLWriter
I am new to lxml. I am interested to know the equivalent code using
lxml (http://cheeseshop.python.org/pypi/lxml/1.1alpha). The code is
taken from http://effbot.org/zone/xml-writer.htm
from elementtree.SimpleXMLWriter import XMLWriter
import sys
w = XMLWriter(sys.stdout)
html = w.start("html")
w.start("head")
w.element("title", "my document")
w.element("meta", name="generator", value="my application 1.0")
w.end()
w.start("body")
w.element("h1", "this is a heading")
w.element("p", "this is a paragraph")
w.start("p")
w.data("this is ")
w.element("b", "bold")
w.data(" and ")
w.element("i", "italic")
w.data(".")
w.end("p")
w.close(html)
Best Regards,
Srijit
--
http://mail.python.org/mailman/listinfo/python-list
Python *eggs* on Win32
I have browsed the following links 1) http://peak.telecommunity.com/DevCenter/EasyInstall 2) When Python *Eggs* better than Python *distutils*?? What's Eggs? (http://tinyurl.com/m8dyd) But I am still not clear what to do with an .egg file. For example, if I have a basic Python installation (http://www.python.org/ftp/python/2.4.3/python-2.4.3.msi) what should I do with a typical .egg file (e.g. http://cheeseshop.python.org/packages/2.4/l/lxml/lxml-1.1alpha-py2.4-static-win32.egg)? I have only MinGW GCC compiler on my Win XP machine. Is it mandatory to have Internet connection during installation of .egg files? Best Regards, Srijit -- http://mail.python.org/mailman/listinfo/python-list
Re: Python *Eggs* on Win32
I got the answers myself. Thanks to http://tinyurl.com/ld2c9. With just basic installation of Python on Win32 (i.e. http://www.python.org/ftp/python/2.4.3/python-2.4.3.msi) it is possible to install .egg files (Python Eggs). 1) download http://peak.telecommunity.com/dist/ez_setup.py 2) run ez_setup.py 3) download http://cheeseshop.python.org/packages/2.4/l/lxml/lxml-1.1alpha-py2.4-static-win32.egg 4) In dos command line go to the same directory where lxml-1.1alpha-py2.4-static-win32.egg has been downloaded 5) From dos command line type d:\python24\scripts\easy_install lxml-1.1alpha.win32-static-py2.4.exe That's all. But Note: a) for running ez_setup.py (which is a bootstrap module) unrestricted Internet connection is necessary. http://peak.telecommunity.com/DevCenter/EasyInstall?action=highlight&value=EasyInstall has all the answers. I am still not sure: a) Whether it is always sufficient to have only MinGW GCC installation on my Win XP machine and not MS Visual Studio. Best Regards, Srijit Srijit Kumar Bhadra wrote: > I have browsed the following links > 1) http://peak.telecommunity.com/DevCenter/EasyInstall > 2) When Python *Eggs* better than Python *distutils*?? What's Eggs? > (http://tinyurl.com/m8dyd) > > But I am still not clear what to do with an .egg file. For example, if > I have a basic Python installation > (http://www.python.org/ftp/python/2.4.3/python-2.4.3.msi) what should I > do with a typical .egg file (e.g. > http://cheeseshop.python.org/packages/2.4/l/lxml/lxml-1.1alpha-py2.4-static-win32.egg)? > > I have only MinGW GCC compiler on my Win XP machine. Is it mandatory to > have Internet connection during installation of .egg files? > > Best Regards, > Srijit -- http://mail.python.org/mailman/listinfo/python-list
Re: Python at MS Event!
Was it IronPython 0.7.x or standard Python 2.4.1? Regards, /Srijit -- http://mail.python.org/mailman/listinfo/python-list
SIP examples
I am trying to learn SIP (http://www.riverbankcomputing.co.uk/sip/) these days. I do not see any examples similar to SWIG. http://www.swig.org/doc.html has lots of examples. But for SIP, all I see is a reference guide (http://www.riverbankcomputing.com/Docs/sip4/sipref.html). Examples help. Where can I get examples for SIP 4.7? Regards, /Srijit -- http://mail.python.org/mailman/listinfo/python-list
MinGW and Python
Is there any specific reason for not using MinGW to build the official distribution of Python for Win32? A quick Google search did not reveal the answer to my question. If a link is available, please post it. Best Regards, Srijit -- http://mail.python.org/mailman/listinfo/python-list
Python Wrapper Tools; a Performance Study
I am looking for the file Python Wrapper Tools; a Performance Study (http://people.web.psi.ch/geus/talks/europython2004_geus.pdf). The link seems to be no longer valid. If someone has a local copy, I request him/her to share it. /Srijit -- http://mail.python.org/mailman/listinfo/python-list
Cython Installation on Windows
Cython Installation on Windows documentation (http://wiki.cython.org/ InstallingOnWindows) needs a minor but important change. Under section "MinGW Compiler" [build] compiler = mingw32 should be replaced by the following lines (i.e. disutils.cfg should have the following lines) [build] compiler=mingw32 /Srijit -- http://mail.python.org/mailman/listinfo/python-list
lxml 2.2.4 for Python 2.6
Is there any reason why lxml-2.2.4-py2.6-win32.egg (md5) or lxml-2.2.4.win32-py2.6.exe is not available? Best regards, /Srijit -- http://mail.python.org/mailman/listinfo/python-list
