Re: What's your first choice if you have to write a C module for python?

2008-08-26 Thread Christian Heimes
一首诗 wrote: Hi all, I read this interesting post comparing Boost.Python with Pyd: http://pyd.dsource.org/vsboost.html What's your opinion about it? What's your first choice when you have write a C/C++ module for Python? I'm using handwritten C code or Cython/Pyrex to create Python C extensi

Re: Checking if the file is a symlink fails

2008-08-28 Thread Christian Heimes
[EMAIL PROTECTED] wrote: File symLinkTest is a symbolic link. Why S_ISLNK(mode) returns False and S_ISREG(mode) returns True ? Because you are using os.stat() instead of os.lstat(). http://docs.python.org/lib/os-file-dir.html Christian -- http://mail.python.org/mailman/listinfo/python-list

Re: posix semaphore support?

2008-08-29 Thread Christian Heimes
Neal Becker wrote: Is there a posix semaphore wrapper for python? Would that be a good addition? The threading module provides a high level interface to native semaphores, e.g. pthread. Christian -- http://mail.python.org/mailman/listinfo/python-list

Re: Can I write a binary windows executable with Python?

2008-08-29 Thread Christian Heimes
walterbyrd wrote: I have heard about Pysco. But does create a single executable that can run without Python being installed? Or does that just compile the libraries? Psyco is a kind of JIT (just in time) optimizer for Python. It's limited to i386 compatible CPUs (aka X86 architecture). It has

Re: posix semaphore support?

2008-08-29 Thread Christian Heimes
Neal Becker wrote: Does that provide semaphores between unrelated processes? No, it just provides unshared semaphores. You can either create your own Python extensions or you can use ctypes if you need a shared or named semaphore. Depending on your requirements you can choose between sem_in

Re: Processes in Linux from Python

2008-09-01 Thread Christian Heimes
Johny wrote: Is it possible to get a number of the http processes running on Linux directly from Python ? The Python core has no direct API for the job. However you can use the virtual /proc/ file system for the job. Or check out my enumprocess package. http://pypi.python.org/pypi?:action=di

Re: Best way for add new path when embedding python into C

2008-09-01 Thread Christian Heimes
Pau Freixes wrote: The best way for add new path before call PyImport_Import is adding new string item into sys path object ? The same way you'd add a path in Python: PyObject *sys_path; PyObject *path; sys_path = PySys_GetObject("path"); if (sys_path == NULL) return NULL; path = PyStrin

Re: Py 2.6 changes

2008-09-01 Thread Christian Heimes
[EMAIL PROTECTED] wrote: I presume it's better for me to not hold my breath while I wait CPython to be written in C99 :-) First you have to convince Microsoft to release C99 compiler ... good luck! Christian -- http://mail.python.org/mailman/listinfo/python-list

Re: encoding

2008-09-01 Thread Christian Heimes
Gandalf wrote: if i want to print utf-8 string i should writre: print u"hello word" but what happen if i want to print variable? u"hello world" is *not* an utf-8 encoded string. It's a unicode string. I suggest you read http://www.joelonsoftware.com/articles/Unicode.html Christian -- http

Re: source for the property function

2008-09-02 Thread Christian Heimes
Rowland Smith wrote: Anyone know where the source code for the built-in property function is located in a python distribution? I would like to see how it works - mainly, how does it know which class it is being called from? Property is not a function but a type. Properties are a common usage

Re: Numeric literal syntax

2008-09-02 Thread Christian Heimes
Fredrik Lundh wrote: Peter Pearson wrote: (startled noises) It is a delight to find a reference to that half-century-old essay (High Finance) by the wonderful C. Northcote Parkinson, but how many readers will catch the allusion? anyone that's been involved in open source on the development si

Re: indices question

2008-09-05 Thread Christian Heimes
Lanny wrote: Please don't tell me that "list indices must be integers" because I know that, Why can't I put a varible thats an integer instead? raw_input() always returns a string. You have to convert the string into an integer using int(). Christian -- http://mail.python.org/mailman/list

Re: Test if list contains another list

2008-09-08 Thread Christian Heimes
mathieu wrote: Hi there, I am trying to write something very simple to test if a list contains another one: a = [1,2,3] b = [3,2,1,4] but 'a in b' returns False. How do I check that a is indeed contained in b ? Use sets: >>> a = [1,2,3] >>> b = [3,2,1,4] >>> set(a).issubset(set(b)) True

Re: exit()

2008-09-08 Thread Christian Heimes
Gary Robinson wrote: In Python 2.5.2, I notice that, in the interpreter or in a script, I can exit with: exit() The exit callable is defined in the site module. Check out site.py! It shouldn't be used in code. It was added to help newbies to 'escape' from an interactive Python shell.

Re: The difference between __XX__ and XX method

2008-09-08 Thread Christian Heimes
AON LAZIO wrote: Hi, Pythoners. I would like to know that in some class, it uses __XX__ but in some it uses only XX for example, class Test: def __som__(self): ... def som(self): ... What does "__XX__" make the method different from XX? Thanks in advance

Re: PYTHONSITEDIR environment variable

2008-09-09 Thread Christian Heimes
ago wrote: Wouldn't it be possible to support a PYTHONSITEDIR environment variable in site.py for this purpose? I have attached a possible patch. In what follows, if PYTHONSITEDIR is defined, that dir is used as the only source of site-packages, extra paths can easily be added by creating a .pth

Re: PYTHONSITEDIR environment variable

2008-09-09 Thread Christian Heimes
ago wrote: The only thing I would add is that in my experience I often use different working-envs for different projects, so I'd prefer to have a more generic solution as opposed to a single working-env per user. The latter could still be achieved by setting the appropriate environment variable i

Re: which of these 2 quicksorts is faster?

2008-09-10 Thread Christian Heimes
Fredrik Lundh wrote: what makes you think you can write a better sort than the built-in algorithm by typing in some toy quick-sort implementations from a "sorting for dummies" article? Anybody who can FULLY understand Tim's text at http://svn.python.org/projects/python/branches/release25-maint

Re: which of these 2 quicksorts is faster?

2008-09-10 Thread Christian Heimes
Fredrik Lundh wrote: what makes you think you can write a better sort than the built-in algorithm by typing in some toy quick-sort implementations from a "sorting for dummies" article? Anybody who can FULLY understand Tim's text at http://svn.python.org/projects/python/branches/release25-maint

Re: I want to use a C++ library from Python

2008-09-10 Thread Christian Heimes
Diez B. Roggisch wrote: Which actually isn't really helpful, as a DLL itself says nothing about what language was used to create it - and sending the OP to e.g. ctypes makes no sense at all in the face of C++. The library - or more precisely the calling convention of the library - is related t

Re: Refcount problem in ceval.c

2008-09-10 Thread Christian Heimes
Berthold Höllmann wrote: Is there any "common" reason to for such a strange object on the command stack, or is it more likely that any of my extension modules is causing havoc? It's very likely that your extension has a reference counting bug. It looks like you are either missing a Py_INCREF o

Re: Accessing __slots__ from C

2008-09-10 Thread Christian Heimes
Chris wrote: Hi, I'd like to be able to access an attribute of a particular Python object as fast as possible from some C code. I wondered if using __slots__ to store the attribute would allow me to do this in a faster way. The reason I'd like to do this is because I need to access the attribu

Re: PHP's str_replace ?

2008-09-10 Thread Christian Heimes
Anjanesh Lekshminarayanan wrote: import re new_str = re.sub('[aeiou]', '-', str) Wow - this is neat. Thanks But probably slower and definitely harder to understand. For simple problems the str methods are usually faster than a regular expression. Christian -- http://mail.python.org/mailman

Re: subprocess.Popen hangs at times?

2008-09-10 Thread Christian Heimes
Kenneth McDonald wrote: When making calls of the form Popen(cmd, shell=True, stdout=subprocess.PIPE), we've been getting occasional, predictable hangs. Will Popen accumulate a certain amount of stdout and then block until its read? We don't want to use threads, so just want to read the entire

Re: Simple UDP server

2008-09-10 Thread Christian Heimes
Tzury Bar Yochay wrote: So what if it is connectionless. It would make sense if you get a load of users who sends large sets of binary data to each other. Transmitting large binary data over UDP? That makes only sense for few applications like video and audio streaming. UDP does neither guaran

Re: Working with environment variables.

2008-09-10 Thread Christian Heimes
aditya shukla wrote: now this dosen't change the value of the variable which was set earlier .Please help me in fixing this issue. Are you trying to modify or add an environment var so the change is visible from the calling shell? That's not possible. You can't change the env var of a parent

Re: Accessing __slots__ from C

2008-09-11 Thread Christian Heimes
Chris wrote: Ok, thanks for the confirmation. We'd been hoping to avoid creating such a struct... Don't worry, a C extension with its own struct isn't hard to write. Your C code can access the member variables w/o using any Python API. You'll get the full speed of C. :] Christian -- http:/

Re: setattr in class

2008-09-12 Thread Christian Heimes
Bojan Mihelac wrote: I guess A class not yet exists in line 4. Is it possible to achive adding dynamic attributes without using exec? Correct, the class doesn't exist until the end of the class body. You can either do it outside the class definition or you can use a metaclass. Christian --

Re: Getting Linux partition info programmatically

2008-09-12 Thread Christian Heimes
python dev wrote: Hello everyone, I am trying to get a list of all the partitions (along with their respective file system types) listed in the /media directory. Does anybody know if there is a way to do this using Python, or do I have to get this information by parsing the output of a Linux co

Re: How do I add permanently to Pythons sys.path?

2008-09-16 Thread Christian Heimes
Python wrote: a temp solution is to append it to that list: sys.path.append('C:/Python25/Progs/') a permanent solution is to add it to the environment variable (no idea where to set this in windows) $PYTHONPATH = "/C:/Python25/Progs/" Don't append a / or \!Use "C:/Python25/Progs" instead of

Re: new style classes, __new__, __init__

2008-09-16 Thread Christian Heimes
Torsten Mohr wrote: I just found an article that describes it better, this example works: class C2(object): def __new__(cls, a): obj = object.__new__(cls) print "new called" obj.a = 8 return obj __new__ = staticmethod(__new__) Staticmethod isnt' requir

Re: Python newbie question re Strings and integers

2008-09-18 Thread Christian Heimes
rmac wrote: the following code attempts to extract a symbol name from a string: extensionStart = int(filename.rfind('.')) filenameStart = int(filename.rfind('/')) #print 'Extension Start - ' + str(extensionStart) #print 'FileName Start - ' + str(filenameStart) currentSymbol=f

Re: How to make a reverse for loop in python?

2008-09-20 Thread Christian Heimes
Alex Snast wrote: Another quick question please, is the List data structure just a dynamic array? If so how can you use static size array, linked list, AVL trees etcetera. You should treat Python lists as an opaque item. You shouldn't concern yourself with the implementation details. Python li

Re: Not fully OO ?

2008-09-20 Thread Christian Heimes
Kay Schluehr wrote: Actually it is simply wrong in the mentioned case and here is the proof: def foo(): return 2+2 import dis dis.dis(foo) 2 0 LOAD_CONST 2 (4) 3 RETURN_VALUE OO is a heuristic method used to understand the semantics of a programming

Re: Problems running on hp dual core processor

2008-09-22 Thread Christian Heimes
Dennis Lee Bieber wrote: Interesting... The only win32ui* on my machine (running v2.4) is a win32ui.pyd (D, not C) and it is part of the PythonWin IDE obtained as part of the ActiveState installer for windows. Oh, and /how much RAM/? ".099g" sounds rather small; my PDA has ".5G"

Re: Python style: exceptions vs. sys.exit()

2008-09-23 Thread Christian Heimes
Drake wrote: I have a general question of Python style, or perhaps just good programming practice. My group is developing a medium-sized library of general-purpose Python functions, some of which do I/O. Therefore it is possible for many of the library functions to raise IOError Exceptions. The

Re: Visualize class inheritance hierarchy

2008-09-23 Thread Christian Heimes
Rob Kirkpatrick wrote: I'm assuming this has been discussed before, but I'm lacking any Google keywords that bring up the appropriate discussion. You are looking for "mro" aka method resolution order. The inspect module contains several helper functions to inspect a class hierarchy. The foll

Re: python 3.x third party modules

2008-09-24 Thread Christian Heimes
Almar Klein wrote: Can anyone say something about that? Will it take a month, a year? A year or more is realistic. A couple of years is even more realistic. Large projects are moving slowly and Python 3.0 introduces some heavy changes. The separation of text (unicode str) and data (bytes) tak

Re: Module import path when embedding python in C

2008-09-26 Thread Christian Heimes
graph wrote: Does anyone know why PySys_GetObject wasn't documented until somewhat recently (http://bugs.python.org/issue1245) if it has been part of the system module interface since at least Python 1.5.2? Is it not supposed to be used? What's the difference the above and importing the sys mod

Re: str() should convert ANY object to a string without EXCEPTIONS !

2008-09-28 Thread Christian Heimes
Steven D'Aprano wrote: str(b'123') # b prefix is added "b'123'" Perhaps I'm misinterpreting it, but from here it looks to me that str() is doing what repr() used to do, and I'm really not sure that's a good thing. I would have expected that str(b'123') in Python 3 should do the same thing a

Re: Unable to write % character to a file using writelines() method

2008-09-28 Thread Christian Heimes
[EMAIL PROTECTED] wrote: Hi, I'm using the writelines() method to write some lines to a text file. But I'm unable to write the % character to the file using the following format: fdTolFile.writelines("\n\tdiff Not in %s '%' range" %(toleranceInPer)) Try %% :) Christian -- http://mail.pyth

Re: What is not objects in Python?

2008-09-28 Thread Christian Heimes
process wrote: What is not an object in Python? Everything that is not part of Python's syntax is an object, including all string and number types, classes, metaclasses, functions, models, code and more. It's technically not possible to have something like e.g. an int that isn't an object.

Re: Detecting dir (tree) changes fast?

2008-09-29 Thread Christian Heimes
robert wrote: I want to detect changes in a directory tree fast with minimum overhead/load. In order to check the need for sync tasks at high frequency. It must not be 100% reliable (its also forced time periodic), so kind of hashing would be ok. How? Almost every modern OS has some sort of s

Re: OS.SYSTEM ERROR !!!

2008-09-30 Thread Christian Heimes
Blubaugh, David A. wrote: To All, I have been attempting to execute the following program within the Python environment: Myprogram.exe, which means this is an executable file!! I would usually execute this program (with the appropriate arguments) by going to following directory within MS-DOS

Re: OS.SYSTEM ERROR !!!

2008-09-30 Thread Christian Heimes
[EMAIL PROTECTED] wrote: I would add the following line right before your call to os.system: os.chdir(r'C:\myprogramfolder\run') I wouldn't. os.chdir() tends to introduce all sorts of trouble. It's a quick n'dirty hack for a small script but no solution for a large program or library. Chri

Re: Wait or not?

2008-10-01 Thread Christian Heimes
Eric wrote: I've been wanting to learn Python for a while now but I can't decide on whether to wait for Python 3's final release and learn it or just go ahead and learn 2.x. Would it be hard to make the transition being a noob? I suggest you stick to Python 2.5 or 2.6 for now. It's going to tak

Re: * for generic unpacking and not just for arguments?

2009-11-29 Thread Christian Heimes
Russell Warren wrote: > but the code below is not? > x = (3, 4) (1, 2, *x) == (1, 2, 3, 4) > Traceback (most recent call last): > File "", line 1, in > invalid syntax: , line 1, pos 8 > > Why does it only work when unpacking arguments for a function? Is it > because the code below i

Re: os.remove() permission problem

2009-11-30 Thread Christian Heimes
Victor Subervi wrote: > When I go into the python interpreter and execute that statement, it > succeeds. What have I missed? You are confusing the permissions of a Unix file system. In order to create or a remove a file from a directory you need the x and w permission to enter the directory (x) an

Re: Inspect module - getargspec raise TypeError for built-in functions

2009-12-01 Thread Christian Heimes
Nadav Chernin wrote: > When I use getargspec(func) for user-defined function, all is working > OK, but using it for built-in functions raise TypeError: That's just fine and to be expected. It's not possible to inspect a C function. Only functions implemented in Python have the necessary metadata.

Re: os.remove() permission problem

2009-12-01 Thread Christian Heimes
Victor Subervi wrote: > Well, that's what I've tried. I've loaded the permissions up, 0777, and it > still throws the same error. I've also tried os.chmod(file, 0777) from the > script, and I get the same permissions error. I can do all of this from the > python prompt. I've set the ownership of th

Re: "file" does not work with the "with" statement!

2009-12-10 Thread Christian Heimes
Michele Simionato wrote: > Python 2.5, but it could be an artifact of the way I am looking if a > file is closed. > I have subclassed the file builtin, added a .close method and it was > not called by the > "with" statement. This during debugging, but now I have found another > reason to explain wh

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

2009-12-17 Thread Christian Heimes
Jonathan Hartley wrote: > Only this week I sent a py2exe-derived executable to someone else (a > non-developer) and it would not run on their WinXP machine ("'The > system cannot execute the specified program'") - my current favourite > hypothesis is that my omission of this dll or something simila

Re: Python (and me) getting confused finding keys

2009-12-22 Thread Christian Heimes
John schrieb: > Hi there, > > I have a rather lengthy program that troubles me for quite some time. After > some debugging, I arrived at the following assertion error: > > for e in edges.keys(): > assert edges.has_key(e) > > Oops!? Is there ANY way that something like this can possibly ha

Re: IOError - cannot create file (linux daemon-invoked script)

2010-01-02 Thread Christian Heimes
cassiope wrote: > The strange thing is that even with the right user-id, I cannot seem > to write to the directory, getting an IOError exception. Changing the > directory to world-writable fixes this. I can confirm the uid and gid > for the script by having the script print these values just befo

Re: Writing a string.ishex function

2010-01-14 Thread Christian Heimes
Iain King wrote: > better would be: > def ishex(s): > for c in s: > if c not in string.hexdigits: > return False > return True Even more elegant and probably a faster solutions: --- from string import hexdigits hexdigits = frozenset(hexdigits) def ishex(s): return

Re: list.pop(0) vs. collections.dequeue

2010-01-22 Thread Christian Heimes
Steve Howell wrote: > Is that really true in CPython? It seems like you could advance the > pointer instead of shifting all the elements. It would create some > nuances with respect to reclaiming the memory, but it seems like an > easy way to make lists perform better under a pretty reasonable us

Re: list.pop(0) vs. collections.dequeue

2010-01-22 Thread Christian Heimes
Steve Howell wrote: > I disagree that Python code rarely pops elements off the top of a > list. There are perfectly valid use cases for wanting a list over a > dequeue without having to pay O(N) for pop(0). Maybe we are just > quibbling over the meaning of "rarely." I was speaking from my own po

Re: list.pop(0) vs. collections.dequeue

2010-01-22 Thread Christian Heimes
Arnaud Delobelle wrote: > I made the comment you quoted. In CPython, it is O(n) to delete/insert > an element at the start of the list - I know it because I looked at the > implementation a while ago. This is why collections.deque exists I > guess. I don't know how they are implemented but inser

Re: list.pop(0) vs. collections.dequeue

2010-01-22 Thread Christian Heimes
Steve Howell wrote: > That maybe would be an argument for just striking the paragraph from > the tutorial. If it's rare that people pop the head off the list in > code that is performance critical or prominent, why bother to even > mention it in the tutorial? How else are you going to teach new P

Re: list.pop(0) vs. collections.dequeue

2010-01-23 Thread Christian Heimes
Steve Howell wrote: > Another benchmark is that deques are slower than lists for accessing > elements. deques are optimized for accessing, inserting and removing data from both ends. For anything else it's slower than the list type. The fact was explained in this very thread yesterday. Christian

Re: Default path for files

2010-01-24 Thread Christian Heimes
Rotwang wrote: > import os > os.chdir() > > to site.py (or any other module which is automatically imported during > initialisation) change the default location to every time I used > Python? First of all you shouldn't alter the site module ever! The optional sitecustomize module exists to mak

Re: Broken Python 2.6 installation on Ubuntu Linux 8.04

2010-01-24 Thread Christian Heimes
Benjamin Kaplan wrote: > Extensions written in C must be recompiled for every version of > Python. Since you're using a version of Python not available through > the package manager, your packages are also not available through > that. You'll have to download the sources for those and compile them

Re: myths about python 3

2010-01-27 Thread Christian Heimes
John Nagle wrote: > 1. Python 3 is supported by major Linux distributions. > > FALSE - most distros are shipping with Python 2.4, or 2.5 at best. You are wrong. Modern versions of Debian / Ubuntu are using Python 2.6. My Ubuntu box has python3.0, too. > 2. Python 3 is supported by multip

Re: Python 3.1 simplejson install

2010-01-29 Thread Christian Heimes
dirknbr wrote: > I am trying to install simplejson on Python 3.1 on Windows. When I do > 'python setup.py install' I get 'except DisutilsPlatformError, x: > SyntaxError' with a dash under the comma. There is no need to install simplejson yourself. Python 3 and 2.6 already have a JSON package calle

Re: myths about python 3

2010-01-30 Thread Christian Heimes
Blog wrote: > WTF? Where'd you hear about version 2.8? FRI, 2.7 is and will be THE > LAST version of the 2.x series - "the" End-Of-Life for Python 2 Where do you get your information from? Your answer is the first that clearly marks the end of lifetime for the 2.x series. I didn't know that and I

Re: pep370 python 2.6?

2009-09-27 Thread Christian Heimes
Neal Becker wrote: > Is pep370 (per-user site-packages) available on 2.6? Yes -- http://mail.python.org/mailman/listinfo/python-list

Re: module path?

2009-10-06 Thread Christian Heimes
Dave Angel wrote: > The property is called __file__ > > So in this case,filename = settings.__file__ Actually it's an attribute set by Python's import machine. Since the __file__ attribute may contain a relative path it's a good idea to use os.path.abspath(__file__). Christian -- http://ma

Re: mktime, how to handle dates before 01-01-1970 ?

2009-10-06 Thread Christian Heimes
Ben Finney wrote: > If you're committed to changing the epoch anyway, I would recommend > using http://en.wikipedia.org/wiki/Astronomical_year_numbering> > (epoch at 4004 BCE) since it is widely used to unify dates referring to > human history. I prefer JDN or MJD (http://en.wikipedia.org/wiki/JDN

Re: how to use WSGI applications with apache

2009-10-07 Thread Christian Heimes
Chris Colbert wrote: > if you want to use it with apapache, you need mod_wsgi. Or you can use mod_proxy alone or with mod_rewrite if you want to stick to the builtin webserver of cherrypy. Christian -- http://mail.python.org/mailman/listinfo/python-list

Re: mktime, how to handle dates before 01-01-1970 ?

2009-10-07 Thread Christian Heimes
M.-A. Lemburg schrieb: > Christian Heimes wrote: >> Ben Finney wrote: >>> If you're committed to changing the epoch anyway, I would recommend >>> using http://en.wikipedia.org/wiki/Astronomical_year_numbering> >>> (epoch at 4004 BCE) since it is widel

Re: How to install 64-bit python on Ubuntu

2009-10-07 Thread Christian Heimes
Curious schrieb: > On Oct 7, 4:07 pm, Roger Binns wrote: >> Curious wrote: >>> Ubuntu comes pre-installed with Python2.6 but this python installation >>> is a 32 bit installation. >> For 64 bit Ubuntu you are mistaken: >> >> $ file /usr/bin/python2.6 >> /usr/bin/python2.6: ELF 64-bit LSB executabl

Re: No threading.start_new_thread(), useful addition?

2009-10-08 Thread Christian Heimes
Laszlo Nagy wrote: > But really thread.start_new_thread is better: > > import thread.start_new_thread as thr > > thr(my_function,arg1,arg2) Please don't use the thread module directly, especially the start_new_thread function. It a low level function that bypasses the threading framework. The is

Re: No threading.start_new_thread(), useful addition?

2009-10-08 Thread Christian Heimes
Hendrik van Rooyen wrote: > What does the Threading module buy me, other than a formal OO approach? * the interpreter won't know about your thread when you bypass the threading module and use the thread module directly. The thread isn't in the list of active threads and the interpreter is unable t

Re: No threading.start_new_thread(), useful addition?

2009-10-08 Thread Christian Heimes
Ulrich Eckhardt wrote: > No, as this one doesn't give me a handle to the thread. I also find this > barely readable, for sure it doesn't beat the readability of the proposed > function. Roll your own convenient function, though. :) At work we have this short function in our tool box: def daemonth

Re: Is there a better way to code variable number of return arguments?

2009-10-08 Thread Christian Heimes
Dr. Phillip M. Feldman schrieb: > I currently have a function that uses a list internally but then returns the > list items as separate return > values as follows: > > if len(result)==1: return result[0] > if len(result)==2: return result[0], result[1] > > (and so on). Is there a cleaner way to

Re: No threading.start_new_thread(), useful addition?

2009-10-09 Thread Christian Heimes
Laszlo Nagy wrote: > IMHO it is much cleaner to implement this as a decorator. Pro: > transparent passing of positional and keyword arguments, keeps function > documentation. You are entitled to your opinion but I STRONGLY recommend against your decorator. You MUST NOT start threads a a side eff

Re: What is the correct way to define __hash__?

2009-10-12 Thread Christian Heimes
Peng Yu schrieb: > Hi, > > I'm wondering what is the general way to define __hash__. I could add > up all the members. But I am wondering if this would cause a > performance issue for certain classes. > def __hash__(self): > return self._a + self._b The hash of a tuple is based on the ha

Re: id( ) function question

2009-10-14 Thread Christian Heimes
raffaele ponzini schrieb: > Dear all, > I have a question concerning the output of the id() function. > In particular since is should: > "" > Return the identity of an object. This is guaranteed to be unique among > simultaneously existing objects. (Hint: it's the object's memory address.) > "" >

Re: id( ) function question

2009-10-14 Thread Christian Heimes
Andre Engels schrieb: > What is going on is that a few objects that are often used, in > particular the small (how small is small depends on the > implementation) integers, are 'preloaded'. When one of these is then > referred to, a new object is not created, but the pre-defined object > is used. 1

Re: id( ) function question

2009-10-14 Thread Christian Heimes
Chris Rebert wrote: > The built-ins aren't mutable, and the singletons are each immutable > and/or unique; so in no case do objects that are both different and > mutable have the same ID. Correct, the fact allows you to write code like "type(egg) is str" to check if an object *is* an instance of s

Re: id( ) function question

2009-10-15 Thread Christian Heimes
Mel wrote: > As Python has evolved the semantics have got richer, and the implementation > has got trickier with proxy objects and wrapped functions and more. > Whatever use there was for `is` in ordinary code is vanishing. 'is' has important use cases but it's not trivial to use if you leave t

Re: Tracking down DLL load errors in Windows ?

2009-10-15 Thread Christian Heimes
Fred P wrote: > Is there any tool and/or methodology I could use to at least pinpoint the > exact DLL that libpyexiv2 is failing to load, and ideally also the reason > why ?... The depencency walker http://www.dependencywalker.com/ works fine for me. Christian -- http://mail.python.org/mailma

Re: How to schedule system calls with Python

2009-10-16 Thread Christian Heimes
MRAB wrote: > You could use multithreading: put the commands into a queue; start the > same number of worker threads as there are processors; each worker > thread repeatedly gets a command from the queue and then runs it using > os.system(); if a worker thread finds that the queue is empty when it

Re: restriction on sum: intentional bug?

2009-10-16 Thread Christian Heimes
Alan G Isaac schrieb: > I expected this to be fixed in Python 3: > sum(['ab','cd'],'') > Traceback (most recent call last): >File "", line 1, in > TypeError: sum() can't sum strings [use ''.join(seq) instead] > > Of course it is not a good way to join strings, > but it should work, shou

Re: restriction on sum: intentional bug?

2009-10-16 Thread Christian Heimes
Alan G Isaac schrieb: > On 10/16/2009 3:40 PM, Tim Chase wrote: >> What's always wrong is giving me an *error* when the semantics are >> perfectly valid. > > > Exactly. > Which is why I expected this to be fixed in Python 3. It's not going to happen. Christian -- http://mail.python.org/mailma

Re: restriction on sum: intentional bug?

2009-10-17 Thread Christian Heimes
Alan G Isaac wrote: > On 10/16/2009 5:03 PM, Christian Heimes wrote: >> It's not going to happen. > > That's a prediction, not a justification. It's not a prediction, it's a statement. It's not going to happend because it violates Guido's gut fe

Re: Reverse Iteration Through Integers

2009-10-18 Thread Christian Heimes
Benjamin Middaugh schrieb: > I'm trying to make an integer that is the reverse of an existing integer > such that 169 becomes 961. I guess I don't know enough yet to figure out > how to do this without a ton of awkward-looking code. I've tried for > loops without much success. I guess I need a g

Re: problem with pythonw.exe

2009-10-23 Thread Christian Heimes
Martin Shaw wrote: > I have a tkinter application running on my windows xp work machine and I am > attempting to stop the console from appearing when the application runs. > I've researched around and the way to do this appears to be to use > pythonw.exe instead of python.exe. However when I try to

Re: Error building Python 2.6.3 and 2.6.4rc2

2009-10-24 Thread Christian Heimes
Michael Ströder wrote: > - snip - > /usr/src/Python-2.6.4rc2> make > 'import site' failed; use -v for traceback > Traceback (most recent call last): > File "./setup.py", line 15, in > from distutils.command.build_ext import build_ext >

Re: C++: Py_CompileString crash

2009-10-26 Thread Christian Heimes
KillSwitch wrote: > int main(int argc, char *argv[]) > { > Py_Initialize(); > > const char* filename = "asdf.py"; > > const char* str = "print('lol')"; > > Py_CompileString(str, filename, 0); > > Py_Finalize(); > system("PAUSE"); > return 0; > } > > On

Re: lmlx & & caracter

2009-10-27 Thread Christian Heimes
Toff wrote: > hello > > i can't parse a file with lxml > > > > > > > http://download.mozilla.org/? > product=firefox-3.5&os=win&lang=fr" /> > > > =

Re: Are *.pyd's universal?

2009-10-29 Thread Christian Heimes
Bakes wrote: > Can I use a pyd compiled on linux in a Windows distribution? > > Or must I recompile it for windows users? On Linux and several other Unices the suffix is .so and not .pyd. The compiled extensions depend on the Python version, operating system as well as platform and architecture.

Re: How to get a unique function name for methods

2009-10-29 Thread Christian Heimes
Philip Guo wrote: > Does anyone know how to get this information either from a code object or > from a related object? I am hacking the interpreter, so I have full access > to everything. Does this help? >>> class A(object): ... def method(self): ... pass ... >>> A.method.im_class >

Re: If a class Child inherits from Parent, how to implement Child.some_method if Parent.some_method() returns Parent instance ?

2009-10-29 Thread Christian Heimes
metal wrote: > But this style makes code full with ugly self.__class__ > > Any standard/pythonic way out there? You are already using one standard way to implement an alternative constructor. If you don't need any instance attributes you can use another way: class Egg(object): @classmethod

Re: Are *.pyd's universal?

2009-10-29 Thread Christian Heimes
Lawrence D'Oliveiro schrieb: > In message , Christian > Heimes wrote: > >> On Linux and several other Unices the suffix is .so and not .pyd. > > Why is that? Or conversely, why isn't it .dll under Windows? .so is the common suffix of shared libraries on Linux. I

Re: Firebird DBs use Kinterbasdb or sqlalchemy?

2009-10-30 Thread Christian Heimes
Jorge wrote: > Hi, > to access firebird data bases which shall I use kinterbasdb or sqlalchemy. You have to use kinterbasdb. SQLAlchemy is not a DBA but an ORM. Christian -- http://mail.python.org/mailman/listinfo/python-list

Re: How convert string '1e7' to an integer?

2009-11-07 Thread Christian Heimes
Peng Yu wrote: > It seems that int() does not convert '1e7'. I'm wondering what > function to use to convert '1e7' to an integer? 1e7 is a way to express a float in science and math. Try float("1e7") Christian -- http://mail.python.org/mailman/listinfo/python-list

Re: Threaded import hang in cPickle.dumps

2009-11-11 Thread Christian Heimes
Zac Burns wrote: > Using python 2.6 > > cPickle.dumps has an import which is causing my application to hang. > (figured out by overriding builtin.__import__ with a print and seeing > that this is the last line of code being run. I'm running > cPickle.dumps in a thread, which leads me to believe th

Re: How can a module know the module that imported it?

2009-11-11 Thread Christian Heimes
kj wrote: > Because the problem that gave rise to this question is insignificant. > I would want to know the answer in any case. *Can* it be done in > Python at all? > > OK, if you must know: > > With Perl one can set a module-global variable before the module > is loaded. This provides a very

Re: python with echo

2009-11-12 Thread Christian Heimes
Diez B. Roggisch wrote: > with open("/sys/class/net/wlan1/device/tx_power", "w") as f: > f.write("%i" % POWER) IIRC the sys and proc virtual file system requires new line at the end of a modifier. At least echo appends \n unless it's told otherwise. Christian -- http://mail.python.org/mail

<    3   4   5   6   7   8   9   10   11   >