Re: Python application distribution

2008-05-01 Thread Martin v. Löwis
> I haven't figured out a way to do this but see no reason why it cannot be > done. I have a decent size application written in 100% Python. I would > like to distribute this application, but only the .pyc files. Since the > .pyc's are just the compiled sources I figured it would work, but if I

Re: Preventing 'bad' filenames from raising errors in os.path

2008-05-02 Thread Martin v. Löwis
> Now, I can understand if you don't like the "WindowsError" as that is > obviously platform specific. The try/except pattern however is the way > errors are handled in python and the best and most appropriate way to > deal with it. The above example just shows that at the very least > there isn't

Re: IPv6 and Python

2008-05-02 Thread Martin v. Löwis
> My hosting company provides me a common IPv4 address. > I'd like to set up my workstation (Windows XP or Linux Debian, doesn't > really matter) to temporarily use IPv6 for trying to add such feature > to my library (I work on both Windows XP and Linux). > Could someone point me to some resources

Re: portable /dev/null

2008-05-02 Thread Martin v. Löwis
> I have functions that take a file object and write to it. In some cases I > just want to throw out what is written to that file object. I want > something like open('/dev/null', 'w'), but portable. > > It needs to have an underlying file descriptor/file handle, as it will be > passed to non pyth

Re: IPv6 and Python

2008-05-03 Thread Martin v. Löwis
> Thanks a lot. I've been able to listen on ::1:21 after having > installed IPv6 on both Windows and Linux thanks to your suggestions. > I'd like to ask one more question: is it possible to bind my server on > both IPv4 and IPv6 addresses (note: I do not use multiple threads or > processes)? You c

Re: How to convert unicode string to unsigned char *

2008-05-05 Thread Martin v. Löwis
> some_module.some_thing(the_string) function is a swig generated > function from a C lib. The C lib function expects unsigned char *. > > The generated function is: If you don't want to change the generated function, I recommend to put a wrapper around it, as Jean-Paul suggested: def some_thing

Re: strftime() argument 1 must be str, not unicode

2008-05-07 Thread Andrii V. Mishkovskyi
2008/5/7 Alexandr N Zamaraev <[EMAIL PROTECTED]>: > Subj is bag? > > Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more informatio

Re: strftime() argument 1 must be str, not unicode

2008-05-08 Thread Andrii V. Mishkovskyi
2008/5/8 Tim Roberts <[EMAIL PROTECTED]>: > "Andrii V. Mishkovskyi" <[EMAIL PROTECTED]> wrote: > > >2008/5/7 Alexandr N Zamaraev <[EMAIL PROTECTED]>: > > >> Subj is bag? > >> > >> Python 2.5.2 (r252:60911, Feb 21 2008,

Re: PyXml

2008-05-09 Thread Martin v. Löwis
> What's the story with PyXml? Is it stable/complete or has effort moved > elsewhere? Large parts of PyXML are now part of the standard library. When I stepped back as a maintainer, nobody volunteered to take over. > Can anyone recommend a Python validating parser that validates vs Xml > Schema?

Re: RELEASED Python 2.6a3 and 3.0a5

2008-05-10 Thread Martin v. Löwis
> I'm trying to install on the latest Ubuntu (8.04) and the following > extension modules fail: > > _bsddb, _curses, _curse_panel, _hashlib, _sqlite3, _ssl, _tkinter, > bz2, dbm, gdbm, readline, zlib > > All of them except for _tkinter are included in the preinstalled > Python 2.5.2, so I guess t

Re: Pythonicity of some algorithms

2008-05-10 Thread Martin v. Löwis
> This works for me. But I'd like to know if this is considered > Pythonic, and if there are other, better ways of doing the above in > Python. >From the Python point of view, it's fine. However, it uses busy-wait, which I consider bad style (in any language). > 3) Make a custom thread-safe queue

Re: People still using Tkinter?

2008-05-10 Thread Martin v. Löwis
> I am, but "still" isn't the word, I just started. Good, *complete* > docs seem to be hard to find, but using a combination of the free > resources and going back and forth between them seems to work all > right so far. IMO, the trick really is to also have a Tk documentation around. If you need

Re: Is there a PyPI API?

2008-05-10 Thread Martin v. Löwis
> I just can't figure out how to get the metadata, I guess. See http://wiki.python.org/moin/PyPiXmlRpc Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list

Re: Compiling Python 2.5.2 on AIX 5.2

2008-05-10 Thread Martin v. Löwis
> Opening mmap with access=ACCESS_COPY > Modifying copy-on-write memory map. > Traceback (most recent call last): > File "Lib/test/test_mmap.py", line 393, in > test_both() > File "Lib/test/test_mmap.py", line 247, in test_both > m.flush() > EnvironmentError: [Errno 22] Invalid arg

Re: problem with Tix in Python2.5

2008-09-08 Thread Martin v. Löwis
> i couldn't find any binary distribution of tix8.4.So i think i have to > reinstall python. > i also have numpy and PIL installed.If i reinstall python on top of > the current python directory will i lose them? You should run a "repair" installation. In Add-and-remove-programs, select Python, the

Re: Python on Windows XP 64-bit: python not found in registry

2008-09-12 Thread Martin v. Löwis
> Anybody here that had the same problem and solved it? Did you install the 32-bit or the 64-bit installer? If the 64-bit installer, did you also install 32-bit or 64-bit installers for iPython, PIL, and easy_install? If you try to use 32-bit extensions or installers to locate a 64-bit Python, t

Re: How to emit Cyrillic and Chinese via unicode from console mode?

2008-09-14 Thread Martin v. Löwis
> Can someone point me to an example of a little program that emits non-ascii > Unicode characters (Russian or Chinese perhaps)? The unicode > Russian/Cyrillic alphabet starts at 0x410. Is this possible to do in a > console mode program? If not, I guess I would want to use pywin32 to create > a

Re: PYPI, some troubles

2008-09-17 Thread Martin v. Löwis
> 1. when I commit a new release to PYPI, I can use stored data (by my > browser: Name, package summary, keywords etc), but in the last line > (classification) I had to chose all those lines from the very > beginning, moreover, if I click at one of them without pressing "CTRL" > all my choices drop

Re: XML Processing

2008-09-18 Thread Andrii V. Mishkovskyi
2008/9/18 Robert Rawlins <[EMAIL PROTECTED]>: > Guys, > > > > I'm running python 2.5 and currently using ElementTree to perform my XML > parsing and creation. ElementTree really is a great package for doing this, > however, I've been tasked by our deployment guys to try and move away from > externa

Re: Automated Build System ?

2008-09-18 Thread Martin v. Löwis
> I'm working on a python Package which includes some extension modules > and unit tests. I want to automate some tasks like "build extsion > module, then copy xxx.pyd to folder yyy and run all unit tests from > folder ". > > I used google but found no hints to existing solutions. > Can anybod

Re: CTypes on a 64 bit machine truncates pointers to 32 bits?

2008-09-18 Thread Martin v. Löwis
foolib = cdll.LoadLibrary('foo.so') foolib.foo(0xF) > 0 Shouldn't you tell ctypes that the argument and the result of foo is a pointer? Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list

Re: Not fully OO ?

2008-09-20 Thread Martin v. Löwis
> for-in could be a useful addition to Python? looks like Guido's used > his time machine again, then, since it's been around since the pre-1.0 > days: > > http://www.python.org/doc/ref/for.html He somehow must have misinterpreted http://www.astro.ufl.edu/~warner/prog/python.html which has

Re: Quick sort implementation in python

2008-09-25 Thread Martin v. Löwis
> Now as you can see I'm passing my list object to both functions along > with their first, last indices I cannot really see that. More specifically, it isn't definite what the type of the "a" argument is, nor does the specific type of "a" matter for the algorithm. It could be a list, or it could

Re: Quick sort implementation in python

2008-09-26 Thread Martin v. Löwis
>> Can you please explain how you did that in C? IOW, how did you do >> the partition function (template) in case you don't have random >> access to the collection? >> > > Why exactly do you need random access for partition function? This is a counter-question, not an answer. Let me ask again: Ho

Re: Python 3.0 and repr

2008-09-28 Thread Martin v. Löwis
> What are others' opinions? Any insight to this design decision? The intention is that all printable characters in a string get displayed in repr. This was in particular requested by Japanese users (but also by other users of non-ASCII characters) which complained that repr() is fairly useless i

Re: How to emit UTF-8 from console mode?

2008-09-30 Thread Martin v. Löwis
> LC_CTYPE=en_US.UTF-8 urxvt-X.exe& > perl -wle "binmode STDOUT, q[:utf8]; print chr() for 0x410 .. 0x430;" > Can someone help me translate it into python? LC_CTYPE=en_US.UTF-8 urxvt-X.exe& python -c 'for i in range(0x410, 0x431):print unichr(i),' > I would not expect it to work > from cmd.exe

Re: How to emit UTF-8 from console mode?

2008-10-01 Thread Martin v. Löwis
> But what are we doing here? Can you convince me that we are emitting UTF-8? Most definitely not. We are emitting cp1251. > I need UTF-8 because I need to experiment with some OS function calls that > give me UTF-16 and I need to emit UTF-16 or UTF-8. Try setting the code page to 65001, and e

Re: windows help files ?

2008-10-02 Thread Martin v. Löwis
> 1. how can I launch the windows help file (CHM), from python with a > keyword as argument ? Run hh.exe. If you want it to navigate to specific page, also pass that page on the command line (finding out the exact syntax is left as an exercise) > 2. now when my program should also run under Linu

Re: "Exploding" (**myvariable) a dict with unicode keys

2008-10-03 Thread Martin v. Löwis
Devin wrote: > So Python can have unicode variable names but you can't > "explode" (**myvariable) a dict with unicode keys? WTF? That works fine for me. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list

Re: "Exploding" (**myvariable) a dict with unicode keys

2008-10-03 Thread Martin v. Löwis
Devin wrote: > On Oct 3, 1:57 pm, Peter Otten <[EMAIL PROTECTED]> wrote: >> "Martin v. Löwis" wrote: >>> Devin wrote: >>>> So Python can have unicode variable names but you can't >>>> "explode" (**myvariable) a dict wit

Re: "Exploding" (**myvariable) a dict with unicode keys

2008-10-04 Thread Martin v. Löwis
> Oh. I read somewhere that UTF-8 variable names we're supported. I > thought I even saw a colleague using Kanji. In source code (string literals, comments), surely. Not in variable names, not in 2.x. To rephrase Bruno's comment: Python supports UTF-8 as a source encoding. That doesn't mean that

Re: Replacement in unicodestrings?

2008-10-04 Thread Martin v. Löwis
> s_str=repr(s.encode('UTF-8')) It would be easier to encode this in cp1252 here, as this is apparently the encoding that you want to use in the RTF file, too. You could then loop over the string, replacing all bytes >= 128 with \\'%.2x As yet another alternative, you could create a Unico

Re: Problem with lower() for unicode strings in russian

2008-10-05 Thread Martin v. Löwis
> I have a set of strings (all letters are capitalized) at utf-8, That's the problem. If these are really utf-8 encoded byte strings, then .lower likely won't work. It uses the C library's tolower API, which works on a byte level, i.e. can't work for multi-byte encodings. What you need to do is t

Re: embedding Python: how to avoid memory leaks?

2006-03-09 Thread Martin v. Löwis
Andrew Trevorrow wrote: > Our app (http://golly.sourceforge.net/) currently uses calls > like these every time a user decides to run a script: > >Py_Initialize(); >PyRun_SimpleString("execfile('foo.py')"); >Py_Finalize(); > > But even if foo.py is *empty* the above calls result in a m

Re: encoding problem

2006-03-09 Thread Martin v. Löwis
Yves Glodt wrote: > It seems in general I have trouble with special characters... > What is the python way to deal with éàè öäü etc... > > print 'é' fails here, > print u'é' as well :-( > > How am I supposed to print non-ascii characters the correct way? The second form should be used, but not i

Re: String functions: what's the difference?

2006-03-09 Thread Martin v. Löwis
Harro de Jong wrote: > I've tried all three, but the function is so small (test a single letter) I > can't measure the difference. I'm using time.time() to see how long it takes > to > execute the function. > I could use a loop to increase execution time, but then I might be measuring > mostly

Re: embedding Python: how to avoid memory leaks?

2006-03-09 Thread Martin v. Löwis
Andrew Trevorrow wrote: > Surely that's a bug that should be fixed. There should be some way > to tell Python "release all the memory you've ever allocated and > start again with a clean slate". This bug cannot be fixed in any foreseeable future. > I've been told that the next version of Python

Re: embedding Python: how to avoid memory leaks?

2006-03-10 Thread Martin v. Löwis
Torsten Bronger wrote: I couldn't get the PyRun_*File* calls to work on Windows, presumably because of the FILE* problem mentioned in the docs. > Well, I don't really *know*, but it's hard to believe to me that the > file descriptor format changed within the Microsoft product series. The

Re: XML international characters

2006-03-10 Thread Martin v. Löwis
Andreas R. wrote: > When parsing XML documents containing international characters, such as > the Norwegian characters Æ, Ø, Å, I get an exception in Python's SAX > module. What is the correct way to parse such characters in Python? I've > searched for methods to somehow escape the characters, with

Re: recycling internationalized garbage

2006-03-14 Thread Martin v. Löwis
Ross Ridge wrote: > [EMAIL PROTECTED] wrote: > >>try: >>(uni, dummy) = utf8dec(s) >>except: >>(uni, dummy) = iso88591dec(s, 'ignore') > > > Is there really any point in even trying to decode with UTF-8? You > might as well just assume ISO 8859-1. The point is that you c

Re: recycling internationalized garbage

2006-03-15 Thread Martin v. Löwis
Ross Ridge wrote: > It should be obvious that any 8-bit single-byte character set can > produce byte sequences that are valid in UTF-8. It is certainly possible to interpret UTF-8 data as if they were in a specific single-byte encoding. However, the text you then obtain is not meaningful in any l

Re: Python vs. Java gzip performance

2006-03-17 Thread Martin v. Löwis
Bill wrote: > The Java version of this code is roughly 2x-3x faster than the Python > version. I can get around this problem by replacing the Python > GzipFile object with a os.popen call to gzcat, but then I sacrifice > portability. Is there something that can be improved in the Python > version

Re: Getting .NET SDK to work with Python 2.4.2

2006-03-19 Thread Martin v. Löwis
Dave wrote: > So i go to the cmd and go to the directory and type > "python setup.py build" (Will have to install after) and it comes up > with this(after everything else runs smoothly): > running build_ext > error: The .NET SDK needs to be installed before building extensions > for python. The er

Re: Python 2.5 Schedule

2006-03-19 Thread Martin v. Löwis
Pekka Niiranen wrote: > what I would like to see in (www.python.org) is > Windows installation package (*.msi) > compiled with option "--enable-unicode=ucs4". > See http://www.xml.com/pub/a/2005/06/15/py-xml.html Just enabling that option is not enough: the resulting binary likely crashes. In addi

Re: C API: Testing my reference counting

2006-03-20 Thread Martin v. Löwis
lord trousers wrote: > Is there a way I can get hold of these kinds of statistics for > debugging? This is best done when Python is build in debug mode. sys.gettotalrefcount then gives you the number of INCREF calls for which no DECREF has been made; you said that this shouldn't change. If it doe

Re: Python 2.5 Schedule

2006-03-20 Thread Martin v. Löwis
Ben Finney wrote: >> - ASCII is the default coding > > Er? How did this happen? > > To be specific, what about all the movement toward UTF-8? See PEP 263. ASCII is the default encoding for source code; if you want to use UTF-8 in source code, either put # -*- coding: utf-8 -*- into the fil

Re: why isn't Unicode the default encoding?

2006-03-20 Thread Martin v. Löwis
John Salerno wrote: > Robert Kern wrote: > >> http://www.joelonsoftware.com/articles/Unicode.html > > That was fascinating. Thank you. So as it turns out, Unicode and UTF-8 > are not the same thing? Am I right to say that UTF-8 stores the first > 128 Unicode code points in a single byte, and

Re: why isn't Unicode the default encoding?

2006-03-20 Thread Martin v. Löwis
> I figured this might have something to do with it, but then again I > thought that Unicode was created as a subset of ASCII and Latin-1 so > that they would be compatible...but I guess it's never that easy. :) The real problem is that the Python string type is used to represent two very differ

Re: why isn't Unicode the default encoding?

2006-03-20 Thread Martin v. Löwis
John Salerno wrote: > Interesting. So then the read() method, if given a numeric argument for > bytes to read, would act differently depending on if you were using > Unicode or not? The read method currently returns a byte string, not a Unicode string. It's not clear to me how the numeric argume

Re: Python vs. Java gzip performance

2006-03-21 Thread Martin v. Löwis
Caleb Hattingh wrote: > What does ".readlines()" do differently that makes it so much slower > than ".read().splitlines(True)"? To me, the "one obvious way to do it" > is ".readlines()". readlines reads 100 bytes (at most) at a time. I'm not sure why it does that (probably in order to not read fu

Re: Python vs. Java gzip performance

2006-03-22 Thread Martin v. Löwis
Felipe Almeida Lessa wrote: > def readlines(self, sizehint=None): > if sizehint is None: > return self.read().splitlines(True) > # ... > > Is it okay? Or is there any embedded problem I couldn't see? It's dangerous, if the file is really large - it might exhaust your mem

Re: LONG_BIT PROBLEM on Sun Solaris 5.8 linking python

2006-03-22 Thread Martin v. Löwis
Nancy wrote: > I know there are lots of messages about this already posted but Im > seeing this on Solaris 5.8. Sunfire > I'm using the sun compiler. All the other messages blamed it on linux > red hat gcc compilers and glib. Thanks. So what is the value of SIZEOF_LONG in pyconfig.h? When you com

Re: encoding problems (é and è)

2006-03-24 Thread Martin v. Löwis
John Machin wrote: >> and, for things like u'\u0565\u0582' (ARMENIAN SMALL LIGATURE ECH >> YIWN), it does not even work. > > Sorry, I don't understand. > 0565 is stand-alone ECH > 0582 is stand-alone YIWN > 0587 is the ligature. > What doesn't work? At first guess, in the absence of an Armenian

Re: encoding problems (é and è)

2006-03-25 Thread Martin v. Löwis
Serge Orlov wrote: > The problem is that U+0587 is a ligature in Western Armenian dialect > (hy locale) and a character in Eastern Armenian dialect (hy_AM locale). > It is strange the code point is marked as compatibility char. It either > mistake or political decision. It used to be a ligature bef

Re: Building Python extensions from sources on Windows

2006-03-25 Thread Martin v. Löwis
TPJ wrote: > And that's the problem: I understand the fact, that in order to build a > non-pure distrubution, all the C sources have to be compiled (to dll > libraries?). But there's the problem: I don't know which one compiler > should I use. Do I have to use the same compiler, that the Python has

Re: Accessing func_name from inside a function

2006-03-25 Thread Martin v. Löwis
James Thiele wrote: > Is there a standard way of getting the name of a function from inside > the function? No, there isn't. Martin -- http://mail.python.org/mailman/listinfo/python-list

Re: python -U problem for 2.4.3c1 on Windows 2000 (was Does -U option really exist?)

2006-03-27 Thread Martin v. Löwis
Petr Prikryl wrote: > I did observe the problem when using the -U > option on Windows 2000. Seems like some infinite > recursion in cp1250.py -- see below. > > I did not try it with earlier versions of Python. > > Can this be reproduced on your computer? I can't try right now. However, I can r

Re: print() in Python 3000 return value?

2006-04-02 Thread Martin v. Löwis
James Thiele wrote: > I noticed in PEP 3000 that print will become a function. The PEP > references a thread where Guido explains this decision. The thread does > not specify what the function will return. Has this been decided? My intuition is that it should be a procedure (i.e. returning None).

Re: print() in Python 3000 return value?

2006-04-02 Thread Martin v. Löwis
bayerj wrote: >> Sorry? 2+2 here returns 4, and certainly should with your Python. > > Err. Never mind. I was thinking about assignments, like > x += 2 > > which returns None. Actually, assignment, in Python, is a statement, not an expression. Statements don't return anything, not even Non

Re: Unicode, command-line and idle

2006-04-06 Thread Martin v. Löwis
[EMAIL PROTECTED] wrote: > This works if I use the console but gives the following error if I use > IDLE: > > Traceback (most recent call last): > File "C:\test.py", line 4, in ? > text2 = unicode(raw_input(), sys.stdin.encoding) > AttributeError: PyShell instance has no attribute 'encoding'

Re: What does 'repair Python 2.5a1' do?

2006-04-07 Thread Martin v. Löwis
Thomas Heller wrote: > What does the repair command in the 2.5a1 msi installer do? > > Apparently it does not replace changed files, although it seems > to replace deleted files. MSI's repair procedure is somewhat complicated. Invoking repair just sets the REINSTALL property to ALL: http://msdn.

Re: unicode wrap unicode object?

2006-04-08 Thread Martin v. Löwis
ygao wrote: > I must use utf-8 for chinese. Sure. But please don't do that: import sys reload(sys) sys.setdefaultencoding("utf-8") As Fredrik says, you should really avoid changing the default encoding. s='\xe9\xab\x98' #this uff-8 string ss=U'\xe9\xab\x98' ss1=ss.

Re: freeze.py builds, but binary doesn't even run locally (shared GTK problem?)

2006-04-08 Thread Martin v. Löwis
[EMAIL PROTECTED] wrote: > from _gtk import * > > ImportError: No module named _gtk If you look at the freeze output, you'll notice that _gtk is not linked into your application: It is a shared library (.so), so it can't be frozen. Instead, the resulting binary will look for _gtk.so on sys.p

Re: how relevant is C today?

2006-04-08 Thread Martin v. Löwis
John Salerno wrote: > Because of my 'novice-ness' in programming, I had always thought that C > was replaced by C++ and wasn't really used anymore today. I know that's > not the case at all now, but I'm still curious how much C is used > anymore in programming today, and what purpose it serves. Is

Re: how relevant is C today?

2006-04-09 Thread Martin v. Löwis
John Zenger wrote: > Your message makes me sad, as if I heard someone say "never read a book > without a specific inducement; if you know someone is going to ask you > about the book, start reading it today, but if you don't know what you > are going to use the book for, reading it will be a waste

Re: how relevant is C today?

2006-04-09 Thread Martin v. Löwis
Grant Edwards wrote: >> As for *learning* the languages: never learn a language >> without a specific inducement. > > That's silly. Learning (weather a computer language, a natural > language, or anything else) is never a bad thing. The more > languages you know, the more you understand about la

Re: how relevant is C today?

2006-04-09 Thread Martin v. Löwis
Carl Friedrich Bolz wrote: > I don't exactly see why this is a contradiction. "Specific inducement" > does not necessarily mean that you have to have an external cause to > learn a language -- be it your job or whatever. Nobody hinders you from > creating that inducement yourself. It's just very ha

Re: RIIA in Python 2.5 alpha: "with... as"

2006-04-11 Thread Martin v. Löwis
Alexander Myodov wrote: > Sorry, I misworded the question - RIIA is indeed present at least by > the reason that the examples from PEP pass. Agree, my problem is a bit > different, and I a bit mixed up initialization/acquisition with > lifetime blocks. So, seems that we indeed have one and still do

Re: Manipulating sets from the 2.4 C API?

2006-04-11 Thread Martin v. Löwis
Dave Opstad wrote: > If I want to handle sets should I just use a dictionary's keys and > ignore the values, or is there some more explicit set support somewhere > I'm not seeing? Indeed, there is. To create a new set, do PyObject_Call(PySet_Type, ""); To, say, invoke the add method, do

Re: list.clear() missing?!?

2006-04-11 Thread Martin v. Löwis
Felipe Almeida Lessa wrote: > I love benchmarks, so as I was testing the options, I saw something very > strange: > > $ python2.4 -mtimeit 'x = range(10); ' > 100 loops, best of 3: 6.7 msec per loop > $ python2.4 -mtimeit 'x = range(10); del x[:]' > 100 loops, best of 3: 6.35 msec per loop

Re: list.clear() missing?!?

2006-04-11 Thread Martin v. Löwis
Ville Vainio wrote: > It's just that, when I have an object, and am wondering how I can clear > it, I tend to look what methods it has first and go to google looking > for "idioms" second. I guess del on a list is not that common, so people tend to not know that it works on lists (and slices!), to

Re: list.clear() missing?!?

2006-04-12 Thread Martin v. Löwis
Steven D'Aprano wrote: >>> $ python2.4 -mtimeit 'x = range(10); ' >>> 100 loops, best of 3: 6.7 msec per loop >>> $ python2.4 -mtimeit 'x = range(10); del x[:]' >>> 100 loops, best of 3: 6.35 msec per loop >>> $ python2.4 -mtimeit 'x = range(10); x[:] = []' >>> 100 loops, best of 3: 6.3

Re: Passing a packed C structure to a c module

2006-04-14 Thread Martin v. Löwis
Philippe Martin wrote: > Is it possible to define a packed C structure in python and pass it to the c > module, or should the wrapper do that ? You can create a packed structure using string concatenation, and with the help of the struct module. However, this gives you a string object in the end,

Re: Passing a packed C structure to a c module

2006-04-14 Thread Martin v. Löwis
Philippe Martin wrote: > It's a pretty big structure: painfull to pass each item as a param. So how else would you like to pass them? Define the API you want, and then just implement it. It still shouldn't require to define the layout in Python. Regards, Martin -- http://mail.python.org/mailman/

Re: Passing a packed C structure to a c module

2006-04-14 Thread Martin v. Löwis
Philippe Martin wrote: > The call actually is an IOCtl: depending on the control code, the structure > has a different format. Ah. In that case, I recommend to use the ioctl module; you won't need a C wrapper, then. > Although the number of control codes/structures is finite, it would make the >

Re: [Python-Dev] Building Python with the free MS Toolkit compiler

2006-04-15 Thread Martin v. Löwis
Paul Moore wrote: > I've just added some instructions on how to build Python on Windows > with the free MS Toolkit C++ compiler. They are at > http://wiki.python.org/moin/Building_Python_with_the_free_MS_C_Toolkit. Cool! If you think that adding/changing files in Python would simplify the process,

Re: semantics of ** (unexpected/inconsistent?)

2009-11-29 Thread Martin v. Löwis
>> I think you answered your own question. 3**2 comes first in the order >> of operations, followed by the negation. > > No, that's not the problem, I'm ok with the operator precedence of - vs ** > > My problem is why I don't get the same result if I use the literal -3 or > a variable that contai

Re: Creating a datetime object from a C Extention

2009-11-30 Thread Martin v. Löwis
> I'm writing a python C Extension and need to create datetime objects but > when I call > value = PyDateTime_FromDateAndTime(ti->tm_year+1900, ti->tm_mon, > ti->tm_mday, ti->tm_hour, ti->tm_min, ti->tm_sec, u); > I get an SegFault. > > ti = {tm_sec = 25, tm_min = 37, tm_hour = 8, tm_mday = 30, tm

Re: Can't print Chinese to HTTP

2009-11-30 Thread Martin v. Löwis
Gnarlodious wrote: > Hello. The "upgrade to Python 3.1 has been disaster so far. I can't > figure out how to print Chinese to a browser. If my script is: > > #!/usr/bin/python > print("Content-type:text/html\n\n") > print('晉') > > the Chinese string simply does not print. It works in interactive

Re: Python3: Sane way to deal with broken encodings

2009-12-08 Thread Martin v. Loewis
> Thus my Python script dies a horrible death: > > File "./update_db", line 67, in > for line in open(tempfile, "r"): > File "/usr/local/lib/python3.1/codecs.py", line 300, in decode > (result, consumed) = self._buffer_decode(data, self.errors, final) > UnicodeDecodeError: 'utf8' code

Re: freeze in python3

2009-12-10 Thread Martin v. Loewis
> For example, initerrno should now be PyInit_errno. Am I missing something? No; freeze hasn't been ported to Python 3 yet. Contributions are welcome. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list

Re: When will Python 3 be fully deployed

2009-12-12 Thread Martin v. Loewis
> In addition to Ned Deily's previous comments, I'd like to note that 2to3 > assumes the source is valid 2.6 code - you have to ensure the code runs > fine with Python 2.6 before using 2to3 to convert to 3.x That's wrong - 2to3 works just fine on, say, 2.3 code that has never been run on 2.6. Reg

Re: how to register with pypi

2009-12-21 Thread Martin v. Loewis
> I'm stuck on the "PGP Key ID". When I whip out my trusty Ubuntu and run > pgp -kg, I get a 16-digit "DSA / EIGamal" key. > > When I enter it into http://pypi.python.org/pypi?%3Aaction=register_form > , I get a helpful "PGP Key ID is invalid". > > Should I try a key of some other algorithm? If

Re: how to register with pypi

2009-12-21 Thread Martin v. Loewis
>> The key ID should be an eight-digit string, such as EA5BBD71 (i.e. a >> 32-bit key ID). > > pretend I was someone who had never ever used PGP before. > > pgp -kg, then what? I don't have pgp, only gpg. In gpg --list-keys, it's the 32-bit ID that gets listed. Try -kv. If you have never used P

Re: how to register with pypi - no such setup.py

2009-12-24 Thread Martin v. Loewis
> Any tips? A binary distribution won't have a setup.py, because you can install it by other means (such as Windows Installer), instead of running setup.py What you want is a source distribution (sdist). Even if you want to create a binary distribution, don't use the bdist command, but some spec

Re: how to register with pypi - no such setup.py

2009-12-26 Thread Martin v. Loewis
Phlip wrote: >> What you want is a source distribution (sdist). > > Thanks. Yes, this is prob'ly documented somewhere. > > Now my next problem - how to get pypi.python.org to stop burning up > version numbers each time I test this? I don't speak English well enough to understand what "to burn up

Re: Which version of MSVC?90.DLL's to distribute with Python 2.6 based Py2exe executables?

2009-12-26 Thread Martin v. Loewis
> FYI, my experience is that an entire manifest must be distributed. As > the manifest in question actually lists 3 DLLs, IIUC, you must ship all > 4 files - the 3 DLLs and the manifest, even if only one of the DLLs is > actually used. You don't actually need to include all three DLLs. Just inclu

Re: Which version of MSVC?90.DLL's to distribute with Python 2.6 based Py2exe executables?

2009-12-26 Thread Martin v. Loewis
> Does anyone have any recommendations on which version of the > MSVC?90.DLL's need to be distributed with a Python 2.6.4 PY2EXE (0.6.9) > based executable? You'll need to include Microsoft.VC90.CRT.manifest and msvcr90.dll. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list

Re: Which version of MSVC?90.DLL's to distribute with Python 2.6 based Py2exe executables?

2009-12-27 Thread Martin v. Loewis
> Thank you for your answers. From my research and testing on this topic: Unfortunately, I can't answer these questions for py2exe. In principle, it would hope that it is possible to include the DLLs *in* the executable, if the py2exe mode is used where it includes all DLLs. Regards, Martin -- h

Re: Python OOP Problem

2009-12-28 Thread Martin v. Loewis
Миклухо wrote: > Hi, all. My problem is: > 1) I have a database(postgresql) > 2)I'm getting some string from database(string is a classname - > written by me). > 3)I need to construct new object from this string. > In java it's done by Class.forName().newInstance(); > > For instance: > 1)I receive

Re: Python OOP Problem

2009-12-28 Thread Martin v. Loewis
>> name2class = { "MyObject" : MyObject, >>"MyOtherObject" : MyOtherObject, >>"Etc" : Etc } >> >> Then, when you receive the string class_name, you do >> >> o = name2class[class_name] >> o.myfunction() >> > The class needs to be instantiated, so the one line should b

Re: Which version of MSVC?90.DLL's to distribute with Python 2.6 based Py2exe executables?

2009-12-29 Thread Martin v. Loewis
>> However, this takes a few seconds to run. Is there a sensible way for >> me to only run this if the required DLL is not already installed? How >> should I be detecting that? Look at windows\winsxs\ >> Also: Will this work on 64 bit machines? Or do I not need to worry >> about that? If you shi

Re: Exception as the primary error handling mechanism?

2010-01-01 Thread Martin v. Loewis
Peng Yu wrote: > I observe that python library primarily use exception for error > handling rather than use error code. [...] > It says "Another popular design flaw—namely, throwing exceptions for > expected outcomes—also causes inefficiencies because catching and > handling exceptions is almost al

Re: Exception as the primary error handling mechanism?

2010-01-01 Thread Martin v. Loewis
> You do understand that exceptions aren't just for errors? They are raised > under specific circumstances. Whether that circumstance is an error or > not is entirely up to the caller. I think that's a fairly narrow definition of the word error, and probably also the source of confusion in this

Re: Exception as the primary error handling mechanism?

2010-01-02 Thread Martin v. Loewis
> I mentioned an "exception stack" above, though I'm not 100% sure if that is > the proper term. I think that exceptions can be stacked upon each other > (e.g. an HTTPD throwing a high-level RequestError when it encounters a low- > level IOError) and that that is also how the backtrace is implem

Re: Exception as the primary error handling mechanism?

2010-01-02 Thread Martin v. Loewis
> For my own interest, I want understand the run time behavior of python > and what details causes it much slower. Although people choose python > for its programming efficiency, but sometimes the runtime still > matters. This is an important aspect of the language. I'm wondering > this is not even

Re: Dangerous behavior of list(generator)

2010-01-02 Thread Martin v. Loewis
>> Bottom line, I'm going to have to remove this pattern from my code: >> >> foo = (foo for foo in foos if foo.bar).next() I recommend to rewrite this like so: def first(gen): try: return gen.next() except StopIteration: raise ValueError, "No first value" foo = first(foo for foo in

Re: Dangerous behavior of list(generator)

2010-01-02 Thread Martin v. Loewis
> I'm asking about why the behavior of a StopIteration exception being > handled from the `expression` of a generator expression to mean "stop > the loop" is accepted by "the devs" as acceptable. I may be late to this discussion, but the answer is "most definitely yes". *Any* exception leads to t

Re: python xmlrpc client with ssl client certificates and standard modules

2010-01-04 Thread Martin v. Loewis
> I can do xmlrpc over ssl WITHOUT certificates with following code: > > import xmlrpclib > server_url = 'https://myserver' > server = xmlrpclib.Server(server_url); > > > and I can perform a https get request WITH certificates with below snippet: > > import httplib > conn = httplib.HTTPSConnect

Re: python xmlrpc client with ssl client certificates and standard modules

2010-01-06 Thread Martin v. Loewis
> My next task is how to find out at the client side, that the server > certificate is a properly signed one. As Heikki says, you'll need Python 2.6 for that. You'll probably need to extend your transport implementation. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list

<    17   18   19   20   21   22   23   24   25   >