Re: Why is there no functional xml?
Rustom Mody wrote: >> To generalize that to handle arbitrarily nested lists and namedtuples a >> bit more effort is needed, but I can't see where lxml.objectify could >> make that much easier. > > You really mean that?? > Well sure in the programming world and even more so in the python world > “Flat is better than nested” is a maxim > > But equally programmers need to satisfy requirements… > > And right now I am seeing things like this > --- > http://schemas.xmlsoap.org/soap/envelope/";> Hm, what happens if you throw a dedicated library at the problem? Google found zeep http://docs.python-zeep.org/en/master/datastructures.html -- https://mail.python.org/mailman/listinfo/python-list
xpath prob, was Re: Why is there no functional xml?
Rustom Mody wrote: > With > # Read above xml with open('soap_response.xml') as f: inp = etree.parse(f) > # namespace dict nsd = {'soap': "http://schemas.xmlsoap.org/soap/envelope/";, 'locns': "http://example.com/"} > > The following behavior is observed — actual responses elided in the > interest of brevity > inp.xpath('//soap:Body', namespaces = nsd) > finds/reaches the node > inp.xpath('//locns:blobRetrieveResponse', namespaces = nsd) > finds > inp.xpath('//locns:dtCreationDate', namespaces = nsd) > does not find > inp.xpath('//dtCreationDate', namespaces = nsd) > finds > inp.xpath('//dtCreationDate') > also finds > > > Doesnt this contradict the fact that dtCreationDate is under the locns > namespace?? > > Any explanations?? Can you rewrite that question as a simple self-contained demo, similar to the snippet shown under http://lxml.de/xpathxslt.html#namespaces-and-prefixes ? -- https://mail.python.org/mailman/listinfo/python-list
Read satellite images
Hi, I have some gridded 4Km satellite images. I don't have experience with Python. The size of my image is (9896,3298) and I use this to read f = open('merg_2018011100_4km-pixel', "r") # reopen the file x = f.read() print (x[0]) I have this value for x = � This is the information for this data from where I did the ftp: the data is 1-byte. Please, what can I do to get the value in ascii. Thanks, Conrado -- https://mail.python.org/mailman/listinfo/python-list
Re: Read satellite images
On 01/24/2018 02:06 PM, jorge.conr...@cptec.inpe.br wrote: Hi, I have some gridded 4Km satellite images. I don't have experience with Python. The size of my image is (9896,3298) and I use this to read f = open('merg_2018011100_4km-pixel', "r") # reopen the file x = f.read() print (x[0]) Hello, What are you trying to accomplish? Do you want the first byte? Do you want data in a specific format (maybe a hex string like "FFABE6", etc)? Also, when dealing with "binary" files, you may want to append a "b" to "r". Assuming you are using Python 2 (from your print): import binascii with open('merg_2018011100_4km-pixel', 'rb') as f: data = f.read() hex_data = binascii.hexlify(data) first_byte = hex_data[0:2] print first_byte -- ~ Jugurtha Hadjar, -- https://mail.python.org/mailman/listinfo/python-list
Re: Processing a key pressed in Python 3.6
Yes, I am aware of this Dennis. However, but, on my system I actually had it running without the msvcrt.kbhit() This occurred during testing while trying different options. And I was able to reproduce this several times. Why? I do not have an answer. This is one reason why I posted the code. It would be interesting to know if anyone else has obtained the same results. Note: 1) 3.6.2 (v3.6.2:5fd33b5, Jul 8 2017, 04:57:36) [MSC v.1900 64 bit (AMD64)] 2) msvcrt is built-in (at least on my system) On 2018-01-24 18:28, Dennis Lee Bieber wrote: On Wed, 24 Jan 2018 02:13:35 +0100, Virgil Stokes *declaimed* ? the following: key = msvcrt.getwch() NOTE: per documentation, that is a blocking read... It won't return unless a key (any key) has been pressed. That means your "more work to do" loop requires a key press for each loop. Recommendation would be to use kbhit() first. if msvcrt.kbhit(): key = msvcrt.getwch() ... Consider -=-=-=-=- import msvcrt as ms import time ESCAPE = chr(27) workPending = True cycle = 0 while workPending: print("Getting imaginary data %s..." % cycle) time.sleep(1.5) print("\tSaving imaginary data %s..." % cycle) time.sleep(1.5) if ms.kbhit(): key = ms.getwch() if key == ESCAPE: print("Pre-termination on cycle %s..." % cycle) break else: print("Random keypress %r found on cycle %s..." % (key, cycle)) cycle += 1 time.sleep(1.5) print("Termination") -=-=-=-=- C:\Users\Wulfraed\Documents\Python Progs>kbhit Getting imaginary data 0... Saving imaginary data 0... Getting imaginary data 1... Saving imaginary data 1... Random keypress u'd' found on cycle 1... Getting imaginary data 2... Saving imaginary data 2... Getting imaginary data 3... Saving imaginary data 3... Random keypress u'a' found on cycle 3... Getting imaginary data 4... Saving imaginary data 4... Pre-termination on cycle 4... Termination C:\Users\Wulfraed\Documents\Python Progs> -- https://mail.python.org/mailman/listinfo/python-list
How to diagnose this, fails on 3.6.3, works on 3.5.2?
I have a fairly simple little python program to automate starting an editor on a wiki page. It works fine on the system where I wrote it (xubuntu 16.04, python 3 version 3.5.2) but it comes up with the following error on a newer system (xubuntu 17.10, python 3 version 3.6.3). Here is the error:- chris$ no Traceback (most recent call last): File "/home/chris/bin/no", line 59, in os.execvp("vi", ("", monthFile,)) File "/usr/lib/python3.6/os.py", line 559, in execvp _execvpe(file, args) File "/usr/lib/python3.6/os.py", line 594, in _execvpe exec_func(fullname, *argrest) ValueError: execv() arg 2 first element cannot be empty Has execvp() become stricter in 3.6.3 or what? ... and here is the program:- #!/usr/bin/python3 # # # Create Dokuwiki journal month pages # import sys import os import time import calendar jdir = "/home/chris/wiki/data/pages/journal" # # # Default month and year is 'now' # month = time.localtime().tm_mon year = time.localtime().tm_year # # # If one parameter is given then it's the month # if len(sys.argv) == 2: month = int(sys.argv[1]) # # # If two parameters are given they are month and year # if len(sys.argv) == 3: year = int(sys.argv[2]) month = int(sys.argv[1]) # # # # # # # Check if the year directory exists and create it if it doesn't # yearDir = os.path.join(jdir, str(year)) if not os.path.exists(yearDir): os.mkdir(yearDir) # # # Check if month file exists, create it if it doesn't and write heading and links # if month < 10: monthFile = os.path.join(yearDir, '0' + str(month) + '.txt') else: monthFile = os.path.join(yearDir, str(month) + '.txt') if not os.path.exists(monthFile): monthName = calendar.month_name[month] f = open(monthFile, 'w') f.write(monthName + " " + str(year) + "\n") for i in range(len(monthName) + 5): f.write("=") f.write("\n") f.close() os.execvp("vi", ("", monthFile,)) -- Chris Green · -- https://mail.python.org/mailman/listinfo/python-list
Re: How to diagnose this, fails on 3.6.3, works on 3.5.2?
Chris Green wrote: > I have a fairly simple little python program to automate starting an > editor on a wiki page. It works fine on the system where I wrote it > (xubuntu 16.04, python 3 version 3.5.2) but it comes up with the > following error on a newer system (xubuntu 17.10, python 3 version > 3.6.3). > > Here is the error:- > > chris$ no > Traceback (most recent call last): > File "/home/chris/bin/no", line 59, in > os.execvp("vi", ("", monthFile,)) > File "/usr/lib/python3.6/os.py", line 559, in execvp > _execvpe(file, args) > File "/usr/lib/python3.6/os.py", line 594, in _execvpe > exec_func(fullname, *argrest) > ValueError: execv() arg 2 first element cannot be empty > > Has execvp() become stricter in 3.6.3 or what? Yes; the relevant issue on the bug tracker seems to be https://bugs.python.org/issue28732 > ... and here is the program:- [snip] A smaller demo is $ cat demo.py import os os.execvp("ls", ("",)) $ python3.5 demo.py demo.py $ python3.6 demo.py Traceback (most recent call last): File "demo.py", line 2, in os.execvp("ls", ("",)) File "/usr/local/lib/python3.6/os.py", line 559, in execvp _execvpe(file, args) File "/usr/local/lib/python3.6/os.py", line 594, in _execvpe exec_func(fullname, *argrest) ValueError: execv() arg 2 first element cannot be empty -- https://mail.python.org/mailman/listinfo/python-list
Re: Help: 64bit python call c and got OSError: exception: access violation writing 0xFFFFFFFF99222A60
Again, thanks for the help. Everything is working fine after the changes. Here is one more new issue needs some help. On c side, The createService function can pass a callback handler as second parameter. Without callback handler, it works fine. But if we add the callback handler, the application will give a exception due to the pointer of callback handler = NULL; Not sure, why the callback handler missed up, when the app calling from python. Thanks -- python lib.createService.argtypes=[ctypes.c_void_p,ctypes.c_char_p] lib.createService.restype=ctypes.c_int def create_services(self,servicename): result=lib.createService(self.obj,servicename) return result --c -- __declspec(dllexport) int createService(void* obj, const char* serviceName) { return ((myPythonAPI*)obj)->createService(serviceName); } int myPythonAPI::createService(const char* serviceName) { //case 1 : //This works fine createService(methodname); //case 2 //This will not working, InvocationCallback serviceCallback; createService(methodname, &serviceCallback); } On Mon, Jan 22, 2018 at 5:58 PM, Jason Qian wrote: > Thanks you very much, fixed the problem :) > > On Mon, Jan 22, 2018 at 4:28 PM, Random832 wrote: > >> On Mon, Jan 22, 2018, at 16:00, Jason Qian via Python-list wrote: >> > Hello! >> > >> > I am using ctypes on Windows to interface with a dll and it works >> fine >> > on Linux and windows 32-bit python. But, when using 64-bit python, we >> got >> > error "exception: access violation writing 0x99222A60". >> >> You are treating the obj type (myPythonAPI *) as c_int, which is only 32 >> bits. You should be using a pointer type instead (ideally you should be >> using void * and c_void_p, so Python doesn't need the class definition.) >> Don't forget to set lib.loadInstance.restype as well. >> >> > __declspec(dllexport) myPythonAPI* loadInstance(){ return new >> > myPythonAPI(); } >> > __declspec(dllexport) int createService(myPythonAPI* obj, const char* >> > serviceName) { eturn obj->createService(serviceName); >> >> > lib = cdll.LoadLibrary('xxx.dll') >> > >> > lib.createService.argtypes=[c_int,ctypes.c_char_p] >> > lib.createService.restype=ctypes.c_int >> > >> > class myDriver(object): >> > def init(self): >> > self.obj = lib.loadInstance() >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > > -- https://mail.python.org/mailman/listinfo/python-list
Re: Processing a key pressed in Python 3.6
On Wed, Jan 24, 2018 at 8:02 PM, Virgil Stokes wrote: > Yes, I am aware of this Dennis. However, but, on my system I actually had it > running without the msvcrt.kbhit() _getwch loops calling ReadConsoleInput until a key event is read. The key can be typed manually in the console, or posted (i.e. PostMessage, not SendMessage) to the console window as a WM_KEYDOWN message, or the key event can be written directly to the input buffer via WriteConsoleInput. _kbhit calls PeekConsoleInput to scan for key events without removing them from the input buffer. This call does not block. -- https://mail.python.org/mailman/listinfo/python-list
Python call c pass a callback function on Linux
Hi, I have following code that works fine on windows. InvocationCB=WINFUNCTYPE(None, c_char_p, c_int) submit = lib.submit submit.argtypes = [ctypes.c_void_p, c_void_p,InvocationCB] submit.restype = ctypes.c_int def handleResponse(message, code): print('--- handleResponse ---') print(message) print(code) class GSPythonDriver(object): def submif(self,methodname) invm_fn = InvocationCB(handleResponse) lib.submit(self.obj,methodname,invm_fn) How can I do this on the Linux ? Thanks for the help Jason -- https://mail.python.org/mailman/listinfo/python-list
Re: Python call c pass a callback function on Linux
On Thu, Jan 25, 2018 at 9:16 AM, Jason Qian via Python-list wrote: > Hi, > > I have following code that works fine on windows. > > InvocationCB=WINFUNCTYPE(None, c_char_p, c_int) > submit = lib.submit > submit.argtypes = [ctypes.c_void_p, c_void_p,InvocationCB] > submit.restype = ctypes.c_int > > def handleResponse(message, code): > print('--- handleResponse ---') > print(message) > print(code) > > class GSPythonDriver(object): > def submif(self,methodname) > invm_fn = InvocationCB(handleResponse) > lib.submit(self.obj,methodname,invm_fn) > > How can I do this on the Linux ? If you're doing a lot of "got this C code, wanna call it from Python", I recommend looking into Cython and building a wrapper. Should be a lot less fiddly - and a lot less fragile - than playing with ctypes for every call you want to make. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Python call c pass a callback function on Linux
HI Dennis, Thanks for the help, After changing WINFUNCTYPE to CFUNCTYPE, the call back function works on the Linux :) Thanks again, Jason On Wed, Jan 24, 2018 at 6:15 PM, Dennis Lee Bieber wrote: > On Wed, 24 Jan 2018 17:16:22 -0500, Jason Qian via Python-list > declaimed the following: > > >Hi, > > > > I have following code that works fine on windows. > > > You have not provided a minimal functional example... > > >InvocationCB=WINFUNCTYPE(None, c_char_p, c_int) > >submit = lib.submit > > Where did lib.submit come from? No import statements are shown. > > >submit.argtypes = [ctypes.c_void_p, c_void_p,InvocationCB] > >submit.restype = ctypes.c_int > > > > You are setting things on the name submit yet... > > >def handleResponse(message, code): > > print('--- handleResponse ---') > > print(message) > > print(code) > > > >class GSPythonDriver(object): > > def submif(self,methodname) > > Is that a typo for submit? > > >invm_fn = InvocationCB(handleResponse) > >lib.submit(self.obj,methodname,invm_fn) > > ... down here you are referring back to the full lib.submit (which may be > the same object) > > > No example instance of GSPythonDriver is created, and thereby > nothing > defined within it is invoked... > > However, the one thing that stands out is that WINFUNCTYPE is > Windows > "stdcall" specific, and ctypes defines CFUNCTYPE for the more global C > calling conventions. But from there? You have to specify the proper library > containing the functions you are invoking... Is that library (or > equivalent) even available on your proposed target OS? > > > -- > Wulfraed Dennis Lee Bieber AF6VN > wlfr...@ix.netcom.comHTTP://wlfraed.home.netcom.com/ > > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: Help: 64bit python call c and got OSError: exception: access violation writing 0xFFFFFFFF99222A60
Figured it out, Thanks On Wed, Jan 24, 2018 at 4:25 PM, Jason Qian wrote: > Again, thanks for the help. Everything is working fine after the changes. > > Here is one more new issue needs some help. > > On c side, > >The createService function can pass a callback handler as second > parameter. >Without callback handler, it works fine. But if we add the callback > handler, the application will give a exception due to the pointer of > callback handler = NULL; > >Not sure, why the callback handler missed up, when the app calling from > python. > > Thanks > > -- python > > lib.createService.argtypes=[ctypes.c_void_p,ctypes.c_char_p] > lib.createService.restype=ctypes.c_int > > def create_services(self,servicename): > result=lib.createService(self.obj,servicename) > return result > > --c -- > > __declspec(dllexport) int createService(void* obj, const char* > serviceName) > { > return ((myPythonAPI*)obj)->createService(serviceName); > } > > int myPythonAPI::createService(const char* serviceName) > { > //case 1 : > //This works fine > createService(methodname); > > //case 2 > //This will not working, > InvocationCallback serviceCallback; > createService(methodname, &serviceCallback); > } > > > > > > > > > > > > On Mon, Jan 22, 2018 at 5:58 PM, Jason Qian wrote: > >> Thanks you very much, fixed the problem :) >> >> On Mon, Jan 22, 2018 at 4:28 PM, Random832 >> wrote: >> >>> On Mon, Jan 22, 2018, at 16:00, Jason Qian via Python-list wrote: >>> > Hello! >>> > >>> > I am using ctypes on Windows to interface with a dll and it works >>> fine >>> > on Linux and windows 32-bit python. But, when using 64-bit python, we >>> got >>> > error "exception: access violation writing 0x99222A60". >>> >>> You are treating the obj type (myPythonAPI *) as c_int, which is only 32 >>> bits. You should be using a pointer type instead (ideally you should be >>> using void * and c_void_p, so Python doesn't need the class definition.) >>> Don't forget to set lib.loadInstance.restype as well. >>> >>> > __declspec(dllexport) myPythonAPI* loadInstance(){ return new >>> > myPythonAPI(); } >>> > __declspec(dllexport) int createService(myPythonAPI* obj, const char* >>> > serviceName) { eturn obj->createService(serviceName); >>> >>> > lib = cdll.LoadLibrary('xxx.dll') >>> > >>> > lib.createService.argtypes=[c_int,ctypes.c_char_p] >>> > lib.createService.restype=ctypes.c_int >>> > >>> > class myDriver(object): >>> > def init(self): >>> > self.obj = lib.loadInstance() >>> -- >>> https://mail.python.org/mailman/listinfo/python-list >>> >> >> > -- https://mail.python.org/mailman/listinfo/python-list
Re: xpath prob, was Re: Why is there no functional xml?
> Rustom Mody wrote: > >> With >> # Read above xml > with open('soap_response.xml') as f: inp = etree.parse(f) >> # namespace dict > nsd = {'soap': "http://schemas.xmlsoap.org/soap/envelope/";, 'locns': > "http://example.com/"} >> >> The following behavior is observed $(G!7(B actual responses elided in the >> interest of brevity >> > inp.xpath('//soap:Body', namespaces = nsd) >> finds/reaches the node >> > inp.xpath('//locns:blobRetrieveResponse', namespaces = nsd) >> finds >> > inp.xpath('//locns:dtCreationDate', namespaces = nsd) >> does not find >> > inp.xpath('//dtCreationDate', namespaces = nsd) >> finds >> > inp.xpath('//dtCreationDate') >> also finds >> >> >> Doesnt this contradict the fact that dtCreationDate is under the locns >> namespace?? Apparently, "dtCreationDate" is not associated with the namespace corresponding to the "locns" namespace. Note, that the namespace association is not by default inherited by child elements -- as least not with stand alone XML. Thus, if you have e.g. then the element "child" does not belong to the namespace indicated by "nspref" but to the "default namespace". An XML schema can change this default. However, to get such an XML schema effective, you must specify this wish when you are parsing your XML document. Otherwise, your XML document is parsed as a "stand alone" XML and the rules of the XML-namespace standard apply -- which means, that the namespace association is not inherited to child elements. -- https://mail.python.org/mailman/listinfo/python-list