Python 3 read() function
Good day. I have installed Python 3 and i have a problem with the builtin read() function. [code] huge = open ( 'C:/HUGE_FILE.pcl', 'rb', 0 ) import io vContent = io.StringIO() vContent = huge.read() # This line takes hours to process !!! vSplitContent = vContent.split ( 'BIN;SP1;PW0.3,1;PA100,700;PD625,700;PU;' ) # This one i have neve tried... [/code] The same thing, in Python 2.5 : [code] huge = open ( 'C:/HUGE_FILE.pcl', 'rb', 0 ) import StringIO vContent = StringIO.StringIO() vContent = huge.read() # This line takes 2 seconds !!! vSplitContent = vContent.split ( 'BIN;SP1;PW0.3,1;PA100,700;PD625,700;PU;' ) # This takes a few seconds... [/code] My "HUGE_FILE" has about 900 MB ... I know this is not the best method to open the file and split the content by that code... Can anyone please suggest a good method to split the file with that code very fast, in Python 3 ? The memory is not important for me, i have 4GB of RAM and i rarely use more than 300 MB of it. Thank you very very much. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3 read() function
> Do you really mean io.StringIO? I guess you want io.BytesIO() ..
>
> Christian
Mmm... i don't know.
I also tried :
[code]
IDLE 3.0
>>> import io
>>> vContent = io.BytesIO()
>>> huge = io.open("C:\HUGE_FILE.pcl",'r+b',0)
>>> vContent = huge.read()
[/code]
It still waits a lot... i don't have the patience to wait for the file
to load completely... it takes a lot!
Thank you for your reply.
--
http://mail.python.org/mailman/listinfo/python-list
HGE and Python (again)
Good day.
I've been trying to port HGE (http://hge.relishgames.com) to Python
for more than 4 months now...
HGE is a hardware accelerated 2D game engine.
It comes with the source and examples. In the folder "include", you
can find "hge.h", the file that i am talking about in all the post.
#
I tried to load the DLL functions with Python Ctypes like this :
[code]
>>> from ctypes import *
>>> HGE = cdll.LoadLibrary("C:/hge181/hge")
>>> HGE.hgeCreate(0x180)
[/code]
But i get this error : "Procedure called with not enough arguments (4
bytes missing) or wrong calling convention".
The call should be done with hgeCreate(HGE_VERSION) and the constant
is defined as "#define HGE_VERSION 0x180"...
Number 0x180 means 384 in Python. I don't mean what it means in C.
So i am stuck.
I also tried to modify the "hge.h" file on line 408, and export the
rest of the classes...
[code]
__declspec (dllexport) hgeVertex;
__declspec (dllexport) hgeTriple;
__declspec (dllexport) hgeQuad;
__declspec (dllexport) hgeInputEvent;
[/code]
But after compilation, i am not able to access them from Python
"ctypes". They seem to remain invisible. Perhaps i am not doing it
right?...
#
I tried Cython.
I tried to load "hge.h" in Cython and use the structures.
The first error i get is at line 173: "typedef bool (*hgeCallback)
();". I am not that good in C/C++ to understand what it means. So i
commented it...
The second big error is at line 408: "extern "C" { EXPORT HGE * CALL
hgeCreate(int ver); }". This should be the DLL export. I comented that
too...
I used this code in Cython, loading from "hge.h":
[code]
# file HGE.pyx
cdef extern from "windows.h":
pass
cdef extern from "hge.h":
pass
[/code]
And i get this errors:
[code]
..\hge.h(215) : error C2061: syntax error : identifier 'hgeVertex'
..\hge.h(218) : error C2059: syntax error : '}'
..\hge.h(226) : error C2061: syntax error : identifier 'hgeVertex'
..\hge.h(229) : error C2059: syntax error : '}'
..\hge.h(274) : error C2061: syntax error : identifier 'HGE'
..\hge.h(274) : error C2059: syntax error : ';'
..\hge.h(275) : error C2449: found '{' at file scope (missing function
header?)
..\hge.h(407) : error C2059: syntax error : '}'
[/code]
Then i tried to define hgeVertex in Cython like:
[code]
struct hgeVertex:
float x, y # screen position
float z # Z-buffer depth 0..1
DWORD col # color
float tx, ty # texture coordinates
[/code]
But i get the exact same errors.
If i comment all the structures hgeVertex and Triple and Quad and the
HGE class, the Cython file compiles !... But it's not useful at all.
My Cython is okay, i compiled a few programs before, so that's not a
problem...
#
Then i tried Swig (and it worked with the examples )... But the
problems with "hge,h" seem to be somewhat similar.
I call swig like this : "swig -c++ -python hge.i"
And the file "hge.i" contains:
[code]
/* File : hge.i */
%module hge
%{
#include "hge.h"
%}
/* Let's just grab the original header file here */
%include "hge.h"
[/code]
And the error i get after commenting the HGE callback and DLL export
is this : "hge.h(276): Error: Syntax error in input(3)." Line 276 is
exactly the first call of HGE class : "virtual void CALL Release() =
0;".
#
I tried Boost.Python (and it works with embedding and extending
examples), but i could't compile "hge.h" even after commenting the
structures and classes. I have to write some wrapper code in "hge.h"
and i am probably doing it completely wrong.
[code]
BOOST_PYTHON_MODULE(hge)
{
using namespace boost::python;
class_ base("hgeVertex");
}
[/code]
So i am stuck again...
I am not that good in neither C or Python.
Can anyone suggest any ideas? Please?
I really really really want to port HGE in Python. It's the greatest
game engine i have ever seen. The particle engine is EXCELLENT and i
need it.
Thank you in advance.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Why optimization mode is slower than normal mode?
Not-optimised: Pystone(1.1) time for 100 passes = 12.8366 This machine benchmarks at 77902 pystones/second Optimised: Pystone(1.1) time for 100 passes = 13.0574 This machine benchmarks at 76584.8 pystones/second It is probably the way it should be. :) -- http://mail.python.org/mailman/listinfo/python-list
Re: HGE and Python (again)
Good day.
Thank you so much for your answer Diez!
I managed to call HGE dll the way you told:
>>> HGE = windll.LoadLibrary("C:/hge181/hge")
>>> HGE.hgeCreate(0x180)
But it's not helpful. It would mean that i have to re-create all the
header files from "include" directory in python, and all helper
functions from the "libs" to be able to use hge in the same way as the
original.
So ctypes is not what i need. It's a big step!
I also tried swig, a lot.
A lot, a lot, a lot of examples. Hacking examples and stuff.
And i managed to compile "hge.h" header and call the structs and HGE
main class. I don't seem to be able to acces the "enums", but that's
not a big problem.
How i did that, if anyone wants to know: There are 4 files.
- There is "example.cxx", that includes "hge.h" in the proper C++ way
and defines a HGE* hge=0 just like in the tutorials.
- Then is "hge.h", the original file, with ONE line commented: line
408 with the DLL EXPORT. Ah, and one more thing. I had to delete ALL
"CALL" keywords from HGE class, because if one CALL appears, the swig
compiler flags the line as error. So, for now, no stdcall.
- Then is "example.i", with "#include "hge.h"" and "%include "hge.h"".
Simple as that.
- And then, there is setup.py. "example_module = Extension('_example',
sources=['example_wrap.cxx', 'example.cxx'],)"
That's it. I compile it all like this:
swig -c++ -python example.i
setup build_ext --inplace
So it's a huge step for me. The compiler i have in my system is
mingw-3.4.5. I don't know if it's good for this. Maybe i should try a
MS compiler instead?
Next things i want to do:
- try to compile the project with a MS compiles. Visual studio 7.1 or
somethin.
- learn if i can do stdcalls from swig !!! This is the most important.
- try to compile one normal hge tutorial WITHOUT including "hge.lib"
and "hgehelp.lib". All functions defined there can be included just
like normal headers, the source is there and i compiled the libs
myself. I need this step because i don't think i can include lib files
in a swig project.
- try to do all i did in swig, with Cython. It's pretty easy to use
and faster from what i know.
So i must learn to to stdcalls from swig.
Can anyone suggest how to do that?
I mean, i have lines like:
virtual void CALL Release(); // in HGE class.
And:
void CALL HGE_Impl::Release()
{
//... // In the "c" file.
}
, where CALL is defined as "#define CALL __stdcall".
I simply can't make this kind of classes so work in swig.
Thank you very much.
--
http://mail.python.org/mailman/listinfo/python-list
Get pixel colors from images in Python 3
Good day. As the title sais, i am trying to extract pixel colors from images, in Python 3. I know that for python 2.x, PIL (Python image library) can do that, via Image > getpixel((x,y)). It returns the colors as a list with 3 parameters, Red, Green and Blue. This is exactly what i want. Now, the problem is that PIL doesn't work in Python 3. Can anyone suggest how to do that ? The bigger problem is that i need to extract pixel colors for many types of images : JPEG, PNG, BMP, GIF. For this, i might need different codecs... I am not good at image formats and codecs. I just want to know if i can do this in the simple way, or i have to beg PIL to implement support for Python 3... -- http://mail.python.org/mailman/listinfo/python-list
Re: Get pixel colors from images in Python 3
I've noticed that Pygame has some similar implementation. It's a little harder to use, but efficient. And i think it depends on PIL too. And Pygame is Python 2.x too... So, not good. -- http://mail.python.org/mailman/listinfo/python-list
External code and functions integration
Good day.
I am using python for quite some time now and i decided to advance a
little. I want to write a little extension, or add some C modules for
my python. I use Active version.
What i want to do is write some wrappers for a game library, called
HGE. See "hge.relishgames.com".
I wrote some applications with HGE, in C++ and i like it pretty much.
In order to make a HGE application in C++, i need to include "hge.h",
include "hge.lib" and "hgelehper.lib", and have "hge.dll" in the same
directory. So it's 3 things i must have for the program to work.
This game library is open source, so i have the source for the libs
and the dll.
Now, what i was thinking was to make some wrapping code like "hge.h"
to call all the functions in the "libs", that (i guess) call the
functions from "hge.dll", that (blah blah) calls DirectX and so on.
I guess that if i write all that "hge.h" includes and wariables in
python, will be okay... even if i still don't have the skill.
I tried to call "hge.lib" like this:
"
from ctypes import *
cdll.LoadLibrary("D:/HGE18/lib/bc/hge.lib")
"
But i get "WindowsError: [Error 193] %1 is not a valid Win32
application".
I tried with windll.LoadLibrary ... and i get the same error.
I tried with the other lib versions, there are 3 versions: BorlandC,
GCC, VisualC, callind "cdll" or "windll". All lib versions report the
same error.
Recently i discovered PyInline and SciPy Weave. They say that Weave
can run C code on the fly, inline... I really dobt that it can parse
things like:
"
#ifndef HGE_H
#define HGE_H
"
or:
"
#include
#define HGE_VERSION 0x180
#ifdef HGEDLL
#define EXPORT __declspec(dllexport)
#else
#define EXPORT
#endif
#define CALL __stdcall
"
Has anyone ever encountered a problem like this ?
Any, ANY advice or idea would be useful !
Thank you very much.
--
http://mail.python.org/mailman/listinfo/python-list
Python script setup
Hi all, When I want setup my script: I write: from distutils.core import setup setup(name="myscript", version='1.0', scripts=["myscripts.py"]) or some else example,error is Traceback (most recent call last): File "", line 1, in -toplevel- setup(name="myscript", version='1.0', scripts=["myscripts.py"]) File "C:\Python24\distutils\core.py", line 101, in setup _setup_distribution = dist = klass(attrs) File "C:\Python24\distutils\dist.py", line 130, in __init__ setattr(self, method_name, getattr(self.metadata, method_name)) AttributeError: DistributionMetadata instance has no attribute 'get___doc__' -- http://mail.python.org/mailman/listinfo/python-list
NNTPLIB STRANGE ERROR
HI,
when I want use python nntplib:
>>> import nntplib
>>> s=nntplib.NNTP('news.t-com.hr')
>>> s.group('hr.mag.bug')
THEN ERROR IS:
Traceback (most recent call last):
File "", line 1, in -toplevel-
s.group('hr.mag.bug')
File "C:\Python24\lib\nntplib.py", line 346, in group
resp = self.shortcmd('GROUP ' + name)
File "C:\Python24\lib\nntplib.py", line 260, in shortcmd
return self.getresp()
File "C:\Python24\lib\nntplib.py", line 215, in getresp
resp = self.getline()
File "C:\Python24\lib\nntplib.py", line 204, in getline
line = self.file.readline()
File "C:\Python24\lib\socket.py", line 340, in readline
data = self._sock.recv(self._rbufsize)
error: (10053, 'Software caused connection abort')
--
http://mail.python.org/mailman/listinfo/python-list
