[Tutor] Using my own installed python version in my directory tree.
Hi, I installed pythin on Linux operating system but on my own tree directory. Now I want to get rid (not deleting) the default python installation, which means I want my own python version to be recognized when I use "python" command. PYTHONPATH has nothing to do with that since it just points to modules. I tried to set the PATH to $HOME/python/bin but this didn't work. So in bried I want to use my own installed python version in my directory without the need to type $HOME/python/bin... and I want to use my own installed python libraries and modules, ignoring the default installation. How that could be done? Thank you in advance, Ziad ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] From byte[] to Image
Hi, I convert an Image to bye array in Java (web-services) and send it to a python client. At the client side (python code) i receive the bytes, and then i need to transform them into the image again. Here is what I am doing: #** # fileName is the path of the file stream = service.getFile(fileName) file = open("pic.jpeg", 'w') img = Image.frombuffer("1", (128, 128), stream) img.save(file) file.close() #** The Java method is: "public byte[] getFile(String path)" This is not working. I am not able to get all the data of the image and for sure not able to form the complete image. Any solution for that? Thank you in advance, Ziad ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] From byte[] to Image
Hi Alan, The Library I am using is the PIL. And I read the Docs, they say the following about "frombuffer" operation: (Note that this function decodes pixel data only, not entire images. If you have an entire image file in a string, wrap it in a StringIO object, and use open to load it.) So I guess "frombuffer" must not be used in my case. The java method is working correctly but I am not able to form the picture in the right way at the client side using the PIL library. I am receiving an array of byte from "public byte[] getFile(String path)", but how to form the Image at the client side? By the way that is how I am sending the Image as byte array to the python client: public byte[] getFile(String fileName){ try{ File imgFile = new File(fileName); BufferedImage img = ImageIO.read(imgFile); ByteArrayOutputStream bas = new ByteArrayOutputStream(); ImageIO.write(img, "jpg", bas); data = ""> } catch (Exception e){ e.printStackTrace(); } System.out.println(data[2]); return data; } // end getFile I receive it at the client side in python: buffer = service.getFile(fileName) How to form the Image from here? It is a jpg Image constructed originally from vtk using Mesa library for off-screen rendering. Thank you again, Ziad On 9/16/06, Alan Gauld <[EMAIL PROTECTED]> wrote: Hi Ziad,Can you give us a bit mor4e detail.> #**> # fileName is the path of the file> stream = service.getFile(fileName)> > file = open("pic.jpeg", 'w')>> img = Image.frombuffer("1", (128, 128), stream)> img.save(file)Which library are you using here? Is it the PIL?> The Java method is: "public byte[] getFile(String path)" >> This is not working. I am not able to get all the data of the image> and for sure not able to form the complete image.Are you saying the Java code is not working?Or that the value you get back from the web service is not what you expected? Or that the resultant byte array is whatyou expected but it is not being transformed to an image correctly?I'm not 100% sure what the problem is here.Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] From byte[] to Image
I do the following: file = StringIO.StringIO(buffer) img = Image.open(file) img.save(file, 'JPEG') I get this error: img = Image.open(file) File "/home/rahhal/python/lib/python2.4/site-packages/PIL/Image.py", line 1745, in open raise IOError("cannot identify image file") IOError: cannot identify image file Yes I printed the contents of Buffer but how can I make sure if it is all there since the type I am receiving is different (temporarly, until I form the Image) from the original content of the Image itself. I will attach the buffer I am receiving and the original Image I am sending. On 9/17/06, Alan Gauld <[EMAIL PROTECTED] > wrote: > (Note that this function decodes pixel data only, not entire images.> If you> have an entire image file in a string, wrap it in a *StringIO*> object, and> use> *open*< file:///home/rahhal/Imaging-1.1.5/Docs/pythondoc-PIL.Image.html#PIL.Image.open-function>to> load it.)>> So I guess "frombuffer" must not be used in my case.Looks like it, but did you try what it suggested, namely using a StringIO object and the open method?What happened?> The java method is working correctly but I am not able to form the> picture> in the right way at the client side using the PIL library. > I receive it at the client side in python:> buffer = service.getFile(fileName)I assume you tried printing buffer (or at least its len) to check thatit was all there?Alan G. buffer Description: Binary data <> ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] From byte[] to Image
I do the following: file = StringIO.StringIO(buffer) img = Image.open(file) img.save(file, 'JPEG') I get this error: img = Image.open(file) File "/home/rahhal/python/lib/python2.4/site-packages/PIL/Image.py", line 1745, in open raise IOError("cannot identify image file") IOError: cannot identify image file Yes I printed the contents of Buffer but how can I make sure if it is all there since the type I am receiving is different (temporarly, until I form the Image) from the original content of the Image itself. I tried to attach the original image and the data (in the buffer) but the email bounced as it was too large. So I am sending the email again without attachments Regards, Ziad On 9/17/06, Alan Gauld <[EMAIL PROTECTED]> wrote: > (Note that this function decodes pixel data only, not entire images.> If you> have an entire image file in a string, wrap it in a *StringIO*> object, and> use> *open*< file:///home/rahhal/Imaging-1.1.5/Docs/pythondoc-PIL.Image.html#PIL.Image.open-function>to> load it.)>> So I guess "frombuffer" must not be used in my case.Looks like it, but did you try what it suggested, namely using a StringIO object and the open method?What happened?> The java method is working correctly but I am not able to form the> picture> in the right way at the client side using the PIL library. > I receive it at the client side in python:> buffer = service.getFile(fileName)I assume you tried printing buffer (or at least its len) to check thatit was all there?Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how to check whether a file exists or not??
On 10/12/06, Asrarahmed Kadri <[EMAIL PROTECTED]> wrote: Hello, Sorry, but this is a very basic questions... Can you tell me how to check the existence of a file.. to check if a file exists, you can use os.path.exists(path) or look at http://python.org/doc/current/lib/module-os.path.html for more info Also if a file exists, and we open it in a write mode, it would be truncated to zero length. So what is the way out of this??# Regards, Asrar-- To HIM you shall return. ___Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] extracting numbers from a list
On 10/16/06, kumar s <[EMAIL PROTECTED]> wrote: hi :I have a simple question to ask tutors:list A :a = [10,15,18,20,25,30,40]I want to print10 15 (first two elements)16 18 (16 is last number +1)19 2021 2526 3031 40 >>> fx = a[0]>>> fy = a[1]>>> b = a[2:]>>> ai = iter(b)>>> last = ai.next()>>> for j in ai:... print fy+1,last... last = j ...16 1816 2016 2516 30can any one help please.thank you a = [10,15,18,20,25,30, 40] print a[0], a[1] for i in xrange(2, len(a)): print a[i-1] + 1, a[i] __Do You Yahoo!?Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com___Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] XML-RPC data transfers.
Did you look at SOAPpy? if you are interested in doing what you want to do through web-services, then SOAPpy might be what you are looking for. It does support XML-RPC. I have developed a working example that sends an image from a Java Web-service and receives the image at a SOAPpy client that uses XML-RPC connection style. The image is re-constructed using PIL. let me know. Ziad On 1/1/07, Tim Golden <[EMAIL PROTECTED]> wrote: Chris Hengge wrote: > Going off your thoughts that I'm asking to do something outside the > realm of the readers here, is there a better place to ask this kind of > oddball stuff? I've looked around and haven't been able to find any > support for XML-RPC (might be a good sign to drop it and move to > something else?) I'm on the win32 list, and python-list, but I mostly > just read those since in my mind most of what I have questions about are > noobish things since I'm still trying to get a handle on this language... There's obviously nothing hard-and-fast about what fits on this list and what on the main Python or python-win32 lists. There's not even that clear a distinction between the latter two, and I suspect there's a good overlap of experts reading two or more lists. If I were to suggest something as a *very* broad guideline it would be this: if you're unfamiliar with Python qua *language*, the tutor list is perhaps the better list to ask; if you're having problems with a particular library, whether one that comes with Python or a third-party one, the main list might get you more answers. Obviously there's a sort of middle ground where the problems you're having with a library stem from an unfamiliarity with language concepts... I'm sure many people like myself keep track of several lists as far as time and interest allows, so for a given problem you might find the same level of expertise available to you. If you were to ask, for example, about using WMI under Win32 in Python your best bet would be the python-win32 list. But as it happens, that's my area of modest expertise so as long as I'm watching this list you'd have a reasonable chance of an answer. But that's only because it does happen to be my area. If you haven't already, I'd be inclined to put your XMLRPC-Image question on the main python list. Why not? If no-one can help, you're no worse off than you were! TJG ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor