Re: In C extension .pyd, sizeof INT64 = 4?

2007-06-12 Thread Martin v. Lo
Allen schrieb:
> My C extension works wrong, and debug it, found that sizeof (INT64) =
> 4, not 8.
> I compile on Windows XP platform.
> Please tell me how to fix it to support INT64?

What *is* INT64? It's not a builtin type of standard C, it isn't
defined by Microsoft C, and it isn't predefined by Python.

So it must be something that you have defined, and apparently
incorrectly. How did you define it?

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

Re: how to refer to partial list, slice is too slow?

2007-05-10 Thread Martin v. Lo
人言落日是天涯,望极天涯不见家 schrieb:
> I'm a python newbie. It seems the slice operation will do copy.
> for example:
 a = [1,2,3,4,5,6,7,8,9,0]
 b = a[7:]
 b
> [8, 9, 0]
 a.remove(9)
 a
> [1, 2, 3, 4, 5, 6, 7, 8, 0]
 b
> [8, 9, 0]
> 
> if the list have large members, the slice operations will consume many
> times.
> for instance, I have a long string named it as S, the size is more
> than 100K
> I want to parser it one part-to-part. first, I process the first 100
> byte, and pass the remainder to the next parser function. I pass the
> S[100:] as an argument of the next parser function. but this operation
> will cause a large bytes copy. Is there any way to just make a
> reference to the remainder string not copy?

You can use itertools.islice:

py> a = [1,2,3,4,5,6,7,8,9,0]
py> b = itertools.islice(a, 7)
py> b

py> b.next()
1
py> b.next()
2
py> b.next()
3
py> b.next()
4
py> b.next()
5
py> b.next()
6
py> b.next()
7
py> b.next()
Traceback (most recent call last):
  File "", line 1, in ?
StopIteration

HTH,
Martin
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: how to print the GREEK CAPITAL LETTER delta under utf-8 encoding

2007-05-28 Thread Martin v. Lo
人言落日是天涯,望极天涯不见家 schrieb:
> I lookup the utf-8 form of delta from the link.
> http://www.fileformat.info/info/unicode/char/0394/index.htm
> 
> and then I want to print it in the python ( I work under windows)
> 
> #!/usr/bin/python
> #coding=utf-8
> 
> print "\xce\x94"
> 
> but the result is not the 'delta' but an unknown character.

I assume you print to the terminal (cmd.exe). This cannot work;
the terminal (usually) does not interpret the characters in UTF-8.
Instead, you should print a Unicode string, e.g.

print u"\N{GREEK CAPITAL LETTER DELTA}"

or

print u'\u0394'

This should work as long as your terminal supports printing
the letter at all.

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

Re: how to print the GREEK CAPITAL LETTER delta under utf-8 encoding

2007-05-29 Thread Martin v. Lo
> yes, it could print to the terminal(cmd.exe), but when I write these
> string to file. I got the follow error:
> 
>   File "E:\Tools\filegen\filegen.py", line 212, in write
> self.file.write(data)
> UnicodeEncodeError: 'ascii' codec can't encode character u'\u0394' in
> position 0
> : ordinal not in range(128)

Yes, when writing to a file, you need to define an encoding, e.g.

self.file.write(data.encode("utf-8"))

You can use codecs.open() instead of open(),
so that you can just use self.file.write(data)

Alternatively, you can find out what sys.stdout.encoding is,
and use that when encoding data for the terminal (falling back
to "utf-8" when .encoding is not available on the file).

> but other text, in which include "chinese characters" got from
> os.listdir(...),  are written to the file OK. why?

Your version of Windows uses a code page that supports Chinese
characters in the byte-oriented character set. These are normally
encoded using the "mbcs" encoding (except that the terminal likely
uses a different encoding). So if you use "mbcs" instead of "utf-8",
you might be able to read the text as well.

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

Re: How to print this character u'\u20ac' to DOS terminal

2007-05-29 Thread Martin v. Lo
人言落日是天涯,望极天涯不见家 schrieb:
> Who could explain the follow issue ?

 print u'\u0394'
> Δ
 print u'\u20ac'
> Traceback (most recent call last):
>   File "", line 1, in 
> UnicodeEncodeError: 'gbk' codec can't encode character u'\u20ac' in
> position 0:
> illegal multibyte sequence
> 
> My terminal is cmd.exe under windows XP.
> what's the different between the two character ? what can I do if I
> want to print the u'\u20ac'?

The problem is that your terminal uses (some form of) the GBK encoding;
see http://zh.wikipedia.org/wiki/GBK for details on GBK.

It seems that GBK (or, rather, code page 936) supports the delta
character, but not the euro sign.

To change that, you can use "chcp" in your terminal window.
For example, if you do "chcp 850", you should be able to
display the euro sign (but will simultaneously use the ability
to display the letter delta, and the chinese letters).

I don't know whether the terminal supports an UTF-8 code
page; you can try setting the terminal's code page to
65001 (which should be UTF-8).

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

Re: Linking debug C++ DLL with python dlls

2007-11-08 Thread Martin v. Lo
> So I decided to download and build the debug version of python2.5.1/
> As it seems I also need to compile all relevant extension modules
> (*.pyd) in debug as well - is this correct?

That's correct.

> I tried to change the code above (just for fun) so in both cases i'll
> use python25.lib and in debug compilation I got linker errors on
> unresolved externals. seems like the debug version exports more
> methods than the release version.

Correct.

> Is there a way to have my C++ code compile in debug mode (with _DEBUG)
> but use the python25 release lib/dll? This way I don't need to have
> additional set of debug extension modules.

Try removing the definition of Py_DEBUG that is implied by _DEBUG.

Notice, however, that it is risky to mix different CRT versions
(debug and nodebug) in a single application; this could cause memory
leaks and crashes. In particular, it *will* cause crashes if you
pass FILE* opened by the debug CRT to PyRun_File and friends. That's
an inherent limitation of Windows DLLs, and the way Microsoft set
up global variables in the VC CRT.

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


Re: Unicode File Names

2008-10-17 Thread Martin v. Lo
> Step 4: Either wait for Python 2.7 or apply the patch to your own copy
> of zipfile ...

Actually, this is released in Python 2.6, see r62724.

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