Re: floatref

2010-07-14 Thread Christian Heimes
> I know, I just wondered if there is a *standard* solution. Yeah, you have to reset your brain and switch to Python mode. *scnr* Seriously, your inquiry sounds like you are trying to code C in Python. I'm using Python for more than seven years and I've never felt the need for a mutable float ref

Re: Is Python portable/Can I install it on an USB Stick?

2010-07-14 Thread Christian Heimes
> Is Python portable? > > Can I install it on an USB Stick? > > Or is Python installing (at least on WinXP) services or register some DLLs or > write something into Registry? Yes, a single user installation of Python is portable. An installation for every user is not portable since it installs

Re: Code generator and visitor pattern

2010-07-15 Thread Christian Heimes
> Since Python isn't stringly typed, single-dispatch isn't available per > se. So is the "double-dispatch" Visitor pattern, which is usually used > in OO systems to implement code generators. So, what is the de facto > method in Python to handle source code generation? Do you mean strongly typed l

Re: __getattribute__ hook and len() problem

2010-07-15 Thread Christian Heimes
> And yet, p.__len__() returns 3. I though len(object) simply > called object.__len__. Not exactly, all __magic__ methods of new style classes are called like getattr(type(obj), "__len__")(obj). As a result magic methods are never looked up on the object, including hooks like __getattr_() and __ge

Re: Best Pythonic Approach to Annotation/Metadata?

2010-07-16 Thread Christian Heimes
> def to_JSON(self): > returnDict = {} > for member in filter(someMethod, inspect.getmembers(self)): > returnDict[member[0]] = member[1] > return json.dumps(returnDict) By the way you don't need filter here. The getmembers() function has a filter functions. It's cal

Re: How is memory managed in python?

2010-07-20 Thread Christian Heimes
> In my web application (Django) I call a function for some request which > loads like 500 MB data from the database uses it to do some calculation and > stores the output in disk. I just wonder even after this request is served > the apache / python process is still shows using that 500 MB, why is

Re: hasattr + __getattr__: I think this is Python bug

2010-07-20 Thread Christian Heimes
Am 20.07.2010 12:10, schrieb dmitrey: > hi all, > I have a class (FuncDesigner oofun) that has no attribute "size", but > it is overloaded in __getattr__, so if someone invokes > "myObject.size", it is generated (as another oofun) and connected to > myObject as attribute. How about using a propert

Re: How is memory managed in python?

2010-07-20 Thread Christian Heimes
Am 20.07.2010 17:50, schrieb Vishal Rana: > Hi Christian, > > I am not sure which one is used in this case, I use htop to see the memory > used by apache / python. In its default configuration htop reports three different types of memory usage: virt, res and shr (virtual, resident and shared memo

Re: Change Encoding in Py 2.5

2010-07-23 Thread Christian Heimes
> I think it is discouraged because it *will* break things in the standard > library and builtins. It's discouraged in the same way that pouring sugar > into the petrol tank of your car is discouraged. Mythbusters have tested this urban legend. In their test the engine run better with sugar. [1]

Re: time between now and the next 2:30 am?

2010-07-23 Thread Christian Heimes
> Your case could be handled by something like: > > from datetime import datetime > from dateutil.relativedelta import relativedelta > > target = datetime.now() + relativedelta(days=+1, hour=2, minute=30, > second=0, microsecond=0) > rem

Re: Multiple versions of Python coexisting in the same OS

2010-07-25 Thread Christian Heimes
Am 25.07.2010 21:32, schrieb Thomas Jollans: > If a script uses sys.executable instead of "python", there is no > problem, at all. It's true that sys.executable is the best way if you have to start a new Python interpreter. However sys.executable may not be set for NT services. So there may be a p

Re: Binary compatibility across Python versions?

2010-07-26 Thread Christian Heimes
> Specifically, I'm concerned with binaries created by SWIG for a C++ > library that our project uses. We'd like to ship precompiled binaries > for Linux, OS X and Windows for Python 2.5 and 2.6. I'm hoping that it > is sufficient to create binaries for each Python for each platform (3 > *

Re: Check in interpreter if running a debug version of python

2010-07-27 Thread Christian Heimes
> Can I check in the interpreter if I am running a debug version of > python? I don't mean if __debug__ is set, I want to know if python was > compiled in debug mode. Python has multiple flavors of debug builds. hasattr(sys, "gettotalrefcount") is only available if Py_REF_DEBUG is enabled. This

Re: Check in interpreter if running a debug version of python

2010-07-27 Thread Christian Heimes
> Starting with Python 2.7 and 3.2 you can do this: > sysconfig.get_config_var("Py_DEBUG") > 1 > > (returns None if the var doesn't exist) IIRC sysconfig.get_config_var() still depends on parsing the pyconfig.h file. This won't work on Windows because we are using project and config setting

Re: Newbie question regarding SSL and certificate verification

2010-07-29 Thread Christian Heimes
> I know very little about security, but one thing I think I know. Never > use security software version 1.0 or greater. It was written by an > author insufficiently paranoid. OpenSSL 1.0.0a was released about a month ago. ;) -- http://mail.python.org/mailman/listinfo/python-list

Re: default behavior

2010-07-29 Thread Christian Heimes
> Inheriting from "int" is not too helpful, because you can't assign > to the value of the base class. "self=1" won't do what you want. It's useful if you remember that you can set the default value by overwriting __new__. >>> class int1(int): ... def __new__(cls, value=1): ... retur

Re: The untimely dimise of a weak-reference

2010-07-30 Thread Christian Heimes
Am 30.07.2010 16:06, schrieb Vincent van Beveren: > I did not know the object did not keep track of its bound methods. What > advantage is there in creating a new bound method object each time its > referenced? It seems kind of expensive. Instances of a class have no means of storing the bound m

Re: default behavior

2010-07-31 Thread Christian Heimes
Am 30.07.2010 14:34, schrieb wheres pythonmonks: > I was hoping not to do that -- e.g., actually reuse the same > underlying data. Maybe dict(x), where x is a defaultdict is smart? I > agree that a defaultdict is safe to pass to most routines, but I guess > I could imagine that a try/except block

Re: default behavior

2010-07-31 Thread Christian Heimes
> The truth, as Christian says above and as Raymond Hettinger recently > pointed out [1], is that __missing__ is used to *define* defaultdict as > a subclass of dict -- it's not used *by* defaultdict. Your answer is confusing even me. ;) Let me try an easier to understand explanation. defaultdi

Re: Why is python not written in C++ ?

2010-08-01 Thread Christian Heimes
Am 02.08.2010 01:08, schrieb candide: > Python is an object oriented langage (OOL). The Python main > implementation is written in pure and "old" C90. Is it for historical > reasons? Python is written in C89 to support as many platforms as possible. We deliberately don't use any new features and

Re: run subprocesses in parallel

2010-08-02 Thread Christian Heimes
> I want to run several subprocesses. Like so: > > p1 = Popen("mycmd1" + " myarg", shell=True) > p2 = Popen("mycmd2" + " myarg", shell=True) > > pn = Popen("mycmdn" + " myarg", shell=True) > > What would be the most elegant and secure way to run all n > subprocesses in parallel? They alread

Re: Why is python not written in C++ ?

2010-08-02 Thread Christian Heimes
Am 03.08.2010 01:03, schrieb Aahz: > http://www.netfunny.com/rhf/jokes/98/May/stroustrup.html I don't understand why the URL contains the word "joke". Every word is true. Hell yeah! :) Christian -- http://mail.python.org/mailman/listinfo/python-list

Re: default behavior

2010-08-03 Thread Christian Heimes
> So I'd rather not mention __missing__ in the first paragraph, which > describes the functionality provided *by* the defaultdict class. How > about adding this para at the end: > > defaultdict is defined using functionality that is available to *any* > subclass of dict: a missing-key lookup

Re: default behavior

2010-08-03 Thread Christian Heimes
> I just went and read the entry that had the bogus claim -- personally, I > didn't see any confusion. I would like to point out the __missing__ is > *not* part of dicts (tested on 2.5 and 2.6 -- don't have 2.7 installed yet). I beg your pardon but you are wrong. __missing__ is available for al

Re: default behavior

2010-08-03 Thread Christian Heimes
> Perhaps punctuation will help clarify my intent: > > __missing__ is *not* part of (dict)s, as shown by dir(dict()): Indeed, that's correct. Can we agree, that __missing__ is an optional feature of the dict interface, that can be implemented in subclasses of dict? Christian -- http://mail.pyt

Re: Is there any way to minimize str()/unicode() objects memory usage [Python 2.6.4] ?

2010-08-06 Thread Christian Heimes
> I'm running into some performance / memory bottlenecks on large lists. > Is there any easy way to minimize/optimize memory usage? > > Simple str() and unicode objects() [Python 2.6.4/Linux/x86]: sys.getsizeof('') 24 bytes sys.getsizeof('0')25 bytes sys.getsizeof(u'')2

Re: Why is python not written in C++ ?

2010-08-09 Thread Christian Heimes
> I highly doubt the Python source would build with a C++ compiler. > > C++ is "'mostly' 'backwards' compatible" with C insofar as you can > pretty easily write C code that is also legal (and semantically > equivalent) C++. But if you don't actively try to write code that is > compatible with bot

Re: Python parsing XML file problem with SAX

2010-08-09 Thread Christian Heimes
Am 10.08.2010 01:20, schrieb Aahz: > The docs say, "Parses an XML section into an element tree incrementally". > Sure sounds like it retains the entire parsed tree in RAM. Not good. > Again, how do you parse an XML file larger than your available memory > using something other than SAX? The docum

Re: Floating numbers

2010-08-12 Thread Christian Heimes
> Is there a way I can keep my floating point number as I typed it? For > example, I want 34.52 to be 34.52 and NOT 34.520002. This isn't a Python issue. Python uses IEEE 754 [1] double precision floats like most other languages. 34.52 can't be stored in a float. The next valid float is 34.520

Re: Simple Python Sandbox

2010-08-14 Thread Christian Heimes
> For example, when you go to save your bit of code, it will go in and if > it finds __ anywhere in the text it just replaces it with xx. And, since > getattr is not available, '_' + '_' won't get you anywhere. That's not as secure as you might think. First of all you can write "_" in more way tha

Re: Contains/equals

2010-08-19 Thread Christian Heimes
Am 19.08.2010 17:00, schrieb Alex Hall: > In Python, as I understand it, you can define this behavior. > > class c(object): > def __init__(self, a=1, b=2): > self.a=a; self.b=b > > def __eq__(self, obj): > if self.a==obj.a and self.b==obj.b: return True > return False Yes, but you have t

Re: Contains/equals

2010-08-19 Thread Christian Heimes
Am 19.08.2010 20:53, schrieb Tim Chase: > On 08/19/10 12:42, Steven D'Aprano wrote: >> On Thu, 19 Aug 2010 11:00:03 -0400, Alex Hall wrote: >> >>> def __eq__(self, obj): >>>if self.a==obj.a and self.b==obj.b: return True >>>return False >> >> That would be the same as: >> >> def __eq_

Re: bug? context managers vs ImportErrors

2010-08-19 Thread Christian Heimes
> Why is 'e' ending up as a string rather than the ImportError object? > > This is with Python 2.6.5 if that makes a difference... It's a known bug in Python 2.6 and earlier. See http://docs.python.org/whatsnew/2.7.html#porting-to-python-2-7 Due to a bug in Python 2.6, the exc_value parameter to

Re: MD6 in Python

2009-06-05 Thread Christian Heimes
mik...@gmail.com schrieb: > As every one related to security probably knows, Rivest (and his > friends) have a new hashing algorithm which is supposed to have none > of the weaknesses of MD5 (and as a side benefit - not too many rainbow > tables yet). His code if publicly available under the MIT li

Re: MD6 in Python

2009-06-05 Thread Christian Heimes
Terry Reedy schrieb: > Christian Heimes wrote: >> mik...@gmail.com schrieb: >>> As every one related to security probably knows, Rivest (and his >>> friends) have a new hashing algorithm which is supposed to have none >>> of the weaknesses of MD5 (and as a

Re: MD6 in Python

2009-06-05 Thread Christian Heimes
Terry Reedy wrote: > A wrapper could go on PyPI now so it can be tested in use *before* going > in the stdlib. No commit or pre-review needed either. Here you go http://pypi.python.org/pypi/md6 It's still a bit rough, totally untested but it should work. Christian -- http://mail.python.org/ma

Re: MD6 in Python

2009-06-05 Thread Christian Heimes
Aahz wrote: > Um, what? You mean 3.1rc1, right? Nevertheless, my understanding is > that 2.7 is mostly restricted to code landed in 3.1, so your second > statement is roughly correct. Oh, d...! Of course you are right, Aahz. As far as I can remember 2.7 will only contain backports of 3.1 feature

Re: Changing Hash Values Across Versions

2009-06-11 Thread Christian Heimes
Phil Thompson schrieb: > How stable should the implementation of, for example, a string's hash > across different Python versions? > > Is it defined that hash("foo") will return the same value for Python 2.5.1, > 2.6.1 and 2.6.2? The hash of an object is an internal implementation detail. The has

Re: Question about None

2009-06-12 Thread Christian Heimes
Paul LaFollette schrieb: > Kind people, > > Using Python 3.0 on a Gatesware machine (XP). > I am building a class in which I want to constrain the types that can > be stored in various instance variables. For instance, I want to be > certain that self.loc contains an int. This is straightforward

Re: install Python-2.4.4 from source (parallel to existing Python-2.6)

2009-06-12 Thread Christian Heimes
Simon wrote: > I installed Python-2.4.4.tar.bz2 from python.org, using gcc-4.3 (within > openSUSE 11.1 x86_64) via 'make altinstall'. > > First, I tried to configure with the following flags: > --prefix=/opt/python-24 --enable-framework --with-pydebug > This provoked an error during compilation vi

Re: install Python-2.4.4 from source (parallel to existing Python-2.6)

2009-06-12 Thread Christian Heimes
Simon schrieb: > Christian Heimes wrote: >> Simon wrote: >>> I installed Python-2.4.4.tar.bz2 from python.org, using gcc-4.3 (within >>> openSUSE 11.1 x86_64) via 'make altinstall'. >>> >>> First, I tried to configure with the following flags

Re: waling a directory with very many files

2009-06-14 Thread Christian Heimes
tom schrieb: > i can traverse a directory using os.listdir() or os.walk(). but if a > directory has a very large number of files, these methods produce very > large objects talking a lot of memory. > > in other languages one can avoid generating such an object by walking > a directory as a liked l

Re: waling a directory with very many files

2009-06-14 Thread Christian Heimes
Andre Engels wrote: > What kind of directories are those that just a list of files would > result in a "very large" object? I don't think I have ever seen > directories with more than a few thousand files... I've seen directories with several hundreds of thousand files. Depending on the file syste

Re: waling a directory with very many files

2009-06-14 Thread Christian Heimes
Terry Reedy wrote: > You did not specify version. In Python3, os.walk has become a generater > function. So, to answer your question, use 3.1. I'm sorry to inform you that Python 3.x still returns a list, not a generator. ython 3.1rc1+ (py3k:73396, Jun 12 2009, 22:45:18) [GCC 4.3.3] on linux2

Re: doctests and decorators

2009-06-16 Thread Christian Heimes
Eric Snow schrieb: > Apparently there is a known issue with doctests, in which tests in > functions using externally defined decorators are ignored. The > recommended fix is to update the order of checks in the _from_module > method of DocTestFinder in the doctest module. The bug and fix are > di

Re: strptime issue in multi-threaded application

2009-06-16 Thread Christian Heimes
Joe Holloway schrieb: > We recently uplifted our web application to run on Python 2.6.2. > We've noticed on a couple occasions that calls into time.strptime have > failed with this exception: > > ImportError: Failed to import _strptime because the import lockis > [sic] held by another thread. The

Re: Regarding Python is scripting language or not

2009-06-17 Thread Christian Heimes
Terry Reedy wrote: > If you mean 'be an instance of a class', which I think is the most > natural reading, then Python *is* object-oriented and, if I understand > what I have read correctly (so that ints are just (unboxed) ints and not > members of an int class), Java *is not*! A friend of mine ca

Re: Status of Python threading support (GIL removal)?

2009-06-19 Thread Christian Heimes
OdarR wrote: > I don't see such improvement in the Python library, or maybe you can > indicate us some meaningfull example...? > > I currently only use CPython, with PIL, Reportlab...etc. > I don't see improvement on a Core2duo CPU and Python. How to proceed > (following what you wrote) ? I've se

Re: Status of Python threading support (GIL removal)?

2009-06-19 Thread Christian Heimes
OdarR schrieb: > On 19 juin, 21:41, Carl Banks wrote: >> He's saying that if your code involves extensions written in C that >> release the GIL, the C thread can run on a different core than the >> Python-thread at the same time. The GIL is only required for Python >> code, and C code that uses t

Re: Status of Python threading support (GIL removal)?

2009-06-19 Thread Christian Heimes
Aahz wrote: > In article <157e0345-74e0-4144-a2e6-2b4cc854c...@z7g2000vbh.googlegroups.com>, > Carl Banks wrote: >> I wish Pythonistas would be more willing to acknowledge the (few) >> drawbacks of the language (or implementation, in this case) instead of >> all this rationalization. > > Pleas

Re: docs error for PyBuffer_FillInfo?

2009-06-21 Thread Christian Heimes
Diez B. Roggisch wrote: > > And obviously enough, compiling my wrapper fails because there is an > argument missing. > > So, I'm in need for a guide on how to use PyBuffer_FillInfo properly - > all I've got is a void* and a total size of the buffer. The second argument points to the (optional) o

Re: os.system vs subprocess

2009-06-21 Thread Christian Heimes
Nate wrote: > gmapcreator = subprocess.Popen("java -Xms128M -Xmx512M -jar > gmapcreator.jar -dfile=censettings.xml", stdin=subprocess.PIPE, > stdout=subprocess.PIPE, stderr=subprocess.PIPE) Try this: gmapcreator = subprocess.Popen( ["java", "-Xms128M", "-Xmx512M", "-jar", "gmapcreator.jar",

Re: os.system vs subprocess

2009-06-21 Thread Christian Heimes
Nate wrote: > Thanks for your response. Related to this talk about shells, maybe you > could point me towards a resource where I could read about how windows > commands are processed w/w/o shells? I guess I assumed all subprocess > commands were intepreted by the same thing, cmd.exe., or perhaps t

Re: Get name of class without instance

2009-06-24 Thread Christian Heimes
Terry Reedy wrote: > Bryan wrote: > >> How come dir(Foo) does not show __name__? That is how I was >> investigating the possibilities. > > Interesting question. Seems like an oversight. dir(some_module) and > dir(some_function) include '__name__'. I suggest you search the tracker > for existing

Re: [RELEASED] Python 3.1 final

2009-06-28 Thread Christian Heimes
Paul Moore schrieb: > 2009/6/28 "Martin v. Löwis" : >>> However, sys.std{in,out,err} are still created as text streams, and AFAICT >>> there's nothing you can do about this from within your code. >> That's intentional, and not going to change. You can access the >> underlying byte streams if you wa

Re: python extend c++ module

2009-06-29 Thread Christian Heimes
找尋自己的一片天 schrieb: > I found it's quite strange when compiling. I didn't use extern "C" at all > , how can python get the right c++ funciton name without any compile error?? > > I found that it first use gcc to compile noddy3.cpp and then link by g++. > > Could anyone explain what

Re: python library call equivalent to `which' command

2009-06-29 Thread Christian Heimes
Tim Pinkawa wrote: > def which(file): > for path in os.environ["PATH"].split(":"): > if file in os.listdir(path): > print "%s/%s" % (path, file) "if file in os.list()" is slow and not correct. You have to check if the file is either a real file or a symlink to a

Re: python library call equivalent to `which' command

2009-06-29 Thread Christian Heimes
Tim Pinkawa wrote: > I realize four lines of Python does not replicate the functionality of > which exactly. It was intended to give the original poster something > to start with. Agreed! > I am curious about it being slow, though. Is there a faster way to get > the contents of a directory than o

Re: identify checksum type?

2009-06-29 Thread Christian Heimes
PK schrieb: > Given a checksum value, whats the best way to find out what type it is? > > meaning. I can use hashlib module and compute a md5 or sha1 for a given data > etc..but given a checksum value say "d2bda52ee39249acc55a75a0f3566105" whats > the best way for me to identify if its a sha1 or m

Re: identify checksum type?

2009-06-30 Thread Christian Heimes
Scott David Daniels wrote: > fortunately, the hashlib checksums can be distinguished by their length Unfortunately the world knows more hash algorithms than the Python standard library. :) Christian -- http://mail.python.org/mailman/listinfo/python-list

Re: A question about fill_free_list(void) function

2009-07-01 Thread Christian Heimes
Pedram schrieb: > Hello community, > I'm reading the CPython interpreter source code, > first, if you have something that I should know for better reading > this source code, I would much appreciate that :) > second, in intobject.c file, I read the following code in > fill_free_list function that I

Re: Searching equivalent to C++ RAII or deterministic destructors

2009-07-02 Thread Christian Heimes
Dave Angel wrote: > Look also at 'del' a command in the language which explicitly deletes an > object. No, you are either explaining it the wrong way or you have been fallen for a common misinterpretation of the del statement. The del statement only removes the object from the current scope. This

Re: Creating alot of class instances?

2009-07-05 Thread Christian Heimes
kk wrote: > I will be querying some data and create class instances based on the > data I gather. But the problem as I mentioned is that I do not know > the names and the number of the end class instances. They will be > based on the content of the data. So how can I create class instances > within

Re: library search path when compiling python

2009-07-07 Thread Christian Heimes
nn wrote: > I am trying to compile python with ssl support but the libraries are > not in /usr/lib but in /opt/freeware/lib. How do I add that folder to > the default library search path? > > It looks like configure --libdir=DIR might do the job but I don't want > to replace the default lib search

Re: Check file is locked?

2009-07-07 Thread Christian Heimes
dudeja.ra...@gmail.com wrote: > How to check if a particular file is locked by some application? (i.e. the > file is opened by some application)? It depends on your operating system. By the way most operating systems don't lock a file when it's opened for reading or writing or even executed. Chri

Re: problem with subprocess

2009-07-10 Thread Christian Heimes
gabrielmonnerat wrote: >> I am using subprocess because I need store the pid. Any suggestions? > Sorry, I was forgot the parameter shell=True. > i.e > In [20]: subprocess.call('DISPLAY=:99 > /opt/ooo-dev3/program/soffice.bin',shell=True) You should avoid using the shell=True parameter. It may resu

Re: python make dies :libtk8.5.so: cannot open shared object file: No such file or directory

2009-07-13 Thread Christian Heimes
Tony Lay wrote: > # cd /usr/local/lib > > # ls -la | grep libtk8.5.so > > -r-xr-xr-x 1 root root 1112606 Jul 10 13:28 libtk8.5.so > > Am I missing something, it’s there? Is /usr/local/lib in your library search path? It looks like it isn't. Check /etc/ld.so.conf and /etc/ld.so.conf.d/. Chri

Re: python _binary_ code

2009-07-13 Thread Christian Heimes
sanju ps schrieb: > Hi > > Can anyone give me solution to create a python binary file (bytecode) other > than pyc file .So my source code be secure.. I am working on ubuntu 9.04 > with python2.6.. I It's impossible to secure your code if it runs on an untrusted computer. This is true for all pro

Re: missing 'xor' Boolean operator

2009-07-14 Thread Christian Heimes
Chris Rebert wrote: > Using the xor bitwise operator is also an option: > bool(x) ^ bool(y) I prefer something like: bool(a) + bool(b) == 1 It works even for multiple tests (super xor): if bool(a) + bool(b) + bool(c) + bool(d) != 1: raise ValueError("Exactly one of a, b, c and d mus

Re: dictionary inherit and method overriding

2009-07-15 Thread Christian Heimes
fdb wrote: > Hi all, > > I need to extend and not replace the __getitem__ method of a dict class. > > Here is sample the code: > class myDict(dict): > def __getitem__(self, y): > print("Doing something") > dict.__getitem__(self, y) > a=myDict() >

Re: missing 'xor' Boolean operator

2009-07-15 Thread Christian Heimes
pdpi wrote: > On Jul 15, 12:08 am, Christian Heimes wrote: >> Chris Rebert wrote: >>> Using the xor bitwise operator is also an option: >>> bool(x) ^ bool(y) >> I prefer something like: >> >> bool(a) + bool(b) == 1 >> >> It works even

Re: python command running old version

2009-07-18 Thread Christian Heimes
Tim Edwards wrote: > Besides changing the path order, how do I ensure it runs the new > version? I'm sure I'll bang my head on the desk in shame as soon as > I'm reminded. hash -r Christian -- http://mail.python.org/mailman/listinfo/python-list

Re: python, ctypes, callbacks -- access violation when calling callback

2009-07-19 Thread Christian Heimes
resurtm wrote: > Can anybody explain my errors when trying to pass callback to DLL > function? > > Thanks for advices and solutions! You have to keep a reference to the callback alive yourself. ctypes doesn't increase the refernece counter of the function when you define a callback. As soon as th

Re: Help understanding the decisions *behind* python?

2009-07-20 Thread Christian Heimes
Niels L. Ellegaard wrote: > Phillip B Oldham writes: > >> We often find we need to do manipulations like the above without >> changing the order of the original list, and languages like JS allow >> this. We can't work out how to do this in python though, other than >> duplicating the list, sortin

Re: doted filenames in import statements

2009-07-21 Thread Christian Heimes
Chris Rebert wrote: > You want the imp.load_module() function: > http://docs.python.org/library/imp.html#imp.load_module > > __import__() only operates on module/package names. I'm not sure how > you even got it to work with a filename... It used to work with filenames but it was a bug. I guess s

Looking for os.listdir() generator

2009-07-23 Thread Christian Heimes
Hello, I'm looking for a generator version of os.listdir() for Python 2.5 and newer. I know somebody has worked on it because I've seen a generator version in a posting on some list or blog a while ago. I can't find it anymore. It seems my Google fu is lacking today. All I can find is a very old v

Re: import vs imp and friends.

2009-07-23 Thread Christian Heimes
Emanuele D'Arrigo wrote: > Now the question. Apart from checking sys.module first and eventually > adding the new module to it if it isn't there already, and apart from > setting __file__, is there anything else that import does and this > snippet doesn't? The import statement does several things.

Re: ANN: psyco V2

2009-07-23 Thread Christian Heimes
Neuruss wrote: > It seems psyco.org is still in the transfer process... > Is there any charitable soul with a link to a Windows binary? :-) It seems like Christian is already working on Windows binaries. We are having a discussing about an obscure MinGW bug on the Python developer list. It looks l

Re: ANN: psyco V2

2009-07-23 Thread Christian Heimes
Christian Tismer wrote: > Psyco V2 will run on X86 based 32 bit Linux, 32 bit Windows, > and Mac OS X. Psyco is not supporting 64 bit, yet. But it > is well being considered. Can you estimate how much work needs to be done in order to get Psyco working on 64bit POSIX (Linux) systems? Christian -

Re: Bridging Python and C

2009-07-23 Thread Christian Heimes
Mohan Parthasarathy wrote: > Hi, > I am a newbie. It looks like there are quite a few ways to bridge Python and > C. I have a bunch of C code and I just need Python wrappers for it. If i > google for this I get SWIG, Boost etc. And I also see > > http://www.python.org/doc/2.5.2/ext/intro.html > >

Re: Looking for os.listdir() generator

2009-07-23 Thread Christian Heimes
Nick Craig-Wood wrote: > Christian Heimes wrote: >> I'm looking for a generator version of os.listdir() for Python 2.5 and >> newer. I know somebody has worked on it because I've seen a generator >> version in a posting on some list or blog a while ago. I can

Re: sqlite3 performance problems only in python

2009-07-23 Thread Christian Heimes
Stef Mientki schrieb: > hello, > > until now I used only small / simple databases in Python with sqlite3. > Now I've a large and rather complex database. > > The most simple query (with just a result of 100 rows), > takes about 70 seconds. > And all that time is consumed in "cursor.fetchall" > >

Re: how can a child thread notify a parent thread its status?

2009-07-24 Thread Christian Heimes
scriptlear...@gmail.com wrote: > My parent thread keeps a counter for the number of free child workers > (say 100) and initializes some child threads and call child.start(). > Once the number of free child workers reach 0, the parent thread will > wait until some at least one child thread finishes

Re: Questions about unicodedata in python 2.6.2

2009-07-28 Thread Christian Heimes
Weidong schrieb: > I am trying to build python 2.6.2 from the source by following the > instructions in README that comes with the source. The configure and > make steps are fine, but there is an error in "make install" step. > This "make install" attempts to build a lot of lib, and it complains >

Re: Questions about unicodedata in python 2.6.2

2009-07-28 Thread Christian Heimes
Weidong wrote: > Thanks for your response! I configured it in the same way as you > said, but without "--enable-unicode=ucs4". The ocnfig.log shows that > checking for UCS-4 was failed. So I assume that by default UCS-2 was > used. There was no other problme in the "make" step. Correct > The

Re: Semaphore Techniques

2009-07-28 Thread Christian Heimes
John D Giotta schrieb: > I'm looking to run a process with a limit of 3 instances, but each > execution is over a crontab interval. I've been investigating the > threading module and using daemons to limit active thread objects, but > I'm not very successful at grasping the documentation. > > Is i

Re: Semaphore Techniques

2009-07-29 Thread Christian Heimes
John D Giotta schrieb: > I'm working with up to 3 process "session" per server, each process > running three threads. > I was wishing to tie back the 3 "session"/server to a semaphore, but > everything (and everyone) say semaphores are only good per process. That's not true. Named semaphores are t

Re: Does python have the capability for driver development ?

2009-07-30 Thread Christian Heimes
Martin P. Hellwig wrote: > Well the pyc, which I thought was the Python bytecode, is then > interpreted by the VM. Python is often referred as byte-code interpreted language. Most modern languages are interpreted languages. The list [1] is rather long. Technically speaking even native code is inte

Re: Run pyc file without specifying python path ?

2009-07-30 Thread Christian Heimes
Barak, Ron wrote: > Your solution sort of defeats my intended purpose (sorry for not divulging my > 'hidden agenda'). > I wanted my application to "hide" the fact that it's a python script, and > look as much as possible like it's a compiled program. > The reason I don't just give my user a py fi

Re: Can you easy_install from your localhost?

2009-07-30 Thread Christian Heimes
Ronn Ross schrieb: > I have a package i would like to store locally. If it is stored locally can > I do something like ' easy_install http://localhost/package ' ? Thanks You can do: easy_install /path/to/package-0.1.tar.gz or you can put your packages into /some/directory/simple/packagename/pa

Re: Newbie thwarted by sys.path on Vista

2009-08-02 Thread Christian Heimes
Michael M Mason wrote: I'm running Python 3.1 on Vista and I can't figure out how to add my own directory to sys.path. The docs suggest that I can either add it to the PYTHONPATH environment variable or to the PythonPath key in the registry. However, PYTHONPATH doesn't exist, and updating t

Re: Is python buffer overflow proof?

2009-08-02 Thread Christian Heimes
Marcus Wanner wrote: I believe that python is buffer overflow proof. In fact, I think that even ctypes is overflow proof... No, ctypes isn't buffer overflow proof. ctypes can break and crash a Python interpreter easily. Christian -- http://mail.python.org/mailman/listinfo/python-list

Re: Python docs disappointing

2009-08-02 Thread Christian Heimes
Mohan Parthasarathy schrieb: I am a newbie and about a month old with Python. There is a wealth of material about Python and I am really enjoying learning Python. One thing that could have helped Python documentation is that instead of the very "raw" doc string, it could have used something like

Re: Is python buffer overflow proof?

2009-08-04 Thread Christian Heimes
John Nagle wrote: A more useful question is whether the standard libraries are being run through any of the commercial static checkers for possible buffer overflows. The CPython interpreter is constantly checked with http://www.coverity.com/. Although Python is used for critical stuff at

Re: trouble with complex numbers

2009-08-05 Thread Christian Heimes
Dr. Phillip M. Feldman wrote: When I try to compute the phase of a complex number, I get an error message: In [3]: from cmath import * In [4]: x=1+1J In [5]: phase(x) NameError: name 'phase' is not defined AttributeError: 'complex' object has no attribute 'phase' Any advice will be appreciate

Re: PEP 8 exegetics: conditional imports?

2009-08-07 Thread Christian Heimes
kj wrote: I seek the wisdom of the elders. Is there a consensus on the matter of conditional imports? Are they righteous? Or are they the way of the wicked? imports in functions are dangerous and may lead to dead locks if they are mixed with threads. An import should never start a thread an

Re: exec("dir()",d)

2009-08-09 Thread Christian Heimes
Emanuele D'Arrigo schrieb: Greetings everybody, I don't quite understand why if I do this: d = {} exec("dir()", d) 1) d is no longer empty 2) the content of d now looks like __builtins__.__dict__ but isn't quite it d == __builtins__.__dict__ returns false. Can anybody shed some light? RTF

Re: How to find out in which module an instance of a class is created?

2009-08-09 Thread Christian Heimes
Johannes Janssen wrote: > class A(object): > def __init__(self, mod=__name__): > self.mod = mod won't work. In this case mod would always be "foo". You have to inspect the stack in order to get the module of the caller. The implementation of warnings.warn() gives you some

Re: How to launch a function at regular time intervals ?

2009-08-12 Thread Christian Heimes
David wrote: Has anyone run into a similar problem (and solved it) ? Yeah, here is my implementation as a perpetual timer based some cherrypy code and threading timer. import threading class PerpetualTimer(threading._Timer): """A subclass of threading._Timer whose run() method repeats.

Re: py-rrdTool - install fails

2009-08-14 Thread Christian Heimes
guthrie schrieb: I want to do some rrd in a python cgi script, but am having trouble getting an easy install module. py-rrdTool looks good, but is distributed in c source, and is missing a header file in the distribution. Thus the install fails when it tries to reference rrd.h which is not there

<    5   6   7   8   9   10   11   >