Re: Calling into Python from a C thread

2009-02-09 Thread Christian Heimes
Philip Semanchuk wrote: > Yes, that's accurate except for the word "forgot". To forget something > one must first know it. =) I found the threading API documentation > difficult to follow, but I suppose that what I'm doing is a little > unusual so if it is not well-documented territory, that's what

Re: Escaping my own chroot...

2009-02-11 Thread Christian Heimes
Dennis Lee Bieber schrieb: > That's the whole purpose of chroot()... As far as the process is > concerned, the chroot() path is now the top of the file system, so there > is no where above it you can get to... Yes, you can get with some hacks. > chroot() is meant for cases where one may be

Re: Can I 'LOOK' through urllib?

2009-02-11 Thread Christian Heimes
Muddy Coder schrieb: > Hi Folks, > > I feel good after played urllib with fun! > > Now I want to LOOK to server through urllib. I read the urllib docs, > but I did not find such a function. For example, if there are many > files located in http://www.somedomain.com/data_folder, but I don't > know

Re: A little bit else I would like to discuss

2009-02-12 Thread Christian Heimes
azrael wrote: > I think that there should be a list on python.org of supported or > sugested modules for some need. For example Database access. Or GUI > Building. It is a complete pain in the ass. Let's face the true, TK is > out of date. There should be another one used and appended to the > stan

Re: is there a project running (GUI Builder for Python ) ?

2009-02-12 Thread Christian Heimes
azrael wrote: > On Feb 12, 8:25 pm, J Kenneth King wrote: >> azrael writes: >>> To be honest, in compare to Visual Studio, Gui Builders for wx >>> widgets are really bad. >> That's because Visual Studio is a Microsoft product to build >> interfaces for Microsoft products. >> >> wx on the other ha

Re: A little bit else I would like to discuss

2009-02-12 Thread Christian Heimes
Martin wrote: [typos igored as requested ;)] > How does "small and agile" work with "batteries included"? The Python slogan says "batteries included", not "fusion reactor included". > agile:: > Would describe faster extension of the standard lib (rrd, yaml should > IMHO already be in the standa

Re: Problem building Python extension

2009-02-13 Thread Christian Heimes
martijnsteenw...@gmail.com wrote: > Thanks a lot for your reply. I downloaded & installed Visual C# 2008 > express, but unfortunately this doesn't change anything in running the > setup file. Unfortunately, still no pyd file is produced... > > Did I something wrong? Yeah, you installed the C# env

Re: *nix tail -f multiple log files with Thread

2009-02-13 Thread Christian Heimes
David schrieb: > Hi everyone, > > I copied a program from C to track multiple log files. I would like to > be able to print a label when a log file is updated. Here is the program; Don't use threads for the job. On Unix the preferred way is select()'ing or poll()'ing multiple file descriptors. C

Re: Easier to wrap C or C++ libraries?

2009-02-14 Thread Christian Heimes
Hrvoje Niksic schrieb: > "Diez B. Roggisch" writes: > >> The answer is easy: if you use C, you can use ctypes to create a >> wrapper - with pure python, no compilation, no platform issues. > > The last part is not true. ctypes doesn't work on 64-bit > architectures, nor does it work when Python

Re: Pythonic way to determine if a string is a number

2009-02-15 Thread Christian Heimes
pyt...@bdurham.com schrieb: > What's the Pythonic way to determine if a string is a number? By > number I mean a valid integer or float. > > I searched the string and cMath libraries for a similar function > without success. I can think of at least 3 or 4 ways to build my > own function. > > Here

Re: relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC

2009-02-15 Thread Christian Heimes
tkevans schrieb: > Found a couple of references to this in the newsgroup, but no > solutions. > > I'm trying to build libsbml-3.3.0 with python 2.5.4 support on RHEL > 5.3. This RedHat distro has python 2.4.5, and libsbml builds ok with > that release. > > After building 2.5.4 (./configure CFLAG

Re: Pythonic way to determine if a string is a number

2009-02-15 Thread Christian Heimes
Philip Semanchuk schrieb: > > On Feb 15, 2009, at 12:46 PM, pyt...@bdurham.com wrote: > >> What's the Pythonic way to determine if a string is a number? By >> number I mean a valid integer or float. > > > try: >int(number) >is_an_int = True > except: >is_an_int = False Please don't

Re: Pythonic way to determine if a string is a number

2009-02-15 Thread Christian Heimes
Roy Smith wrote: > I agree that the bare except is incorrect in this situation, but I don't > agree that you should *never* use them. A bare except should be used when followed by a raise try: func() except: log_error() raise > They make sense when you need to recover from any error th

Re: printing bytes to stdout in Py3

2009-02-17 Thread Christian Heimes
Peter Billam schrieb: > Greetings. (Newbie warning as usual) In Python3, sys.stdout is a > io.TextIOWrapper object; but I want to output bytes > (e.g. muscript -midi t > t.mid ) > and they're coming out stringified :-( How can I either change the > encoding on sys.stdout, or close sys.stdout and

Re: memory recycling/garbage collecting problem

2009-02-17 Thread Christian Heimes
Yuanxin Xi wrote: > Could anyone please explain why this happens? It seems some memory > are not freed. I'm running into problems with this as my program is > very memory cosuming and need to frequently free some object to reuse > the memory. What is the best way to free the memory of b complete

Re: memory recycling/garbage collecting problem

2009-02-17 Thread Christian Heimes
Tim Wintle wrote: > Basically malloc() and free() are computationally expensive, so Python > tries to call them as little as possible - but it's quite clever at > knowing what to do - e.g. if a list has already grown large then python > assumes it might grow large again and keeps hold of a percenta

Re: Will multithreading make python less popular?

2009-02-17 Thread Christian Heimes
rushen...@gmail.com wrote: > As you mentioned, using multi cores makes programs more fast and more > popular. But what about stackless python? Does it interpret same set > of python libraries with Cpython or Does it have a special sub set? Your assumption is wrong. Multiple cores are able to speed

Re: printing bytes to stdout in Py3

2009-02-17 Thread Christian Heimes
Casey wrote: > Is this really the 'official' way to do this? This isn't meant to be > confrontational or trolling; I honestly don't know the answer and I > had similar questions when I first started with the 3.0 release > candidates and I have yet to find a good answer in the Python v3.0 > documen

Re: Threads vs. processes, what to consider in choosing ?

2009-02-17 Thread Christian Heimes
Philip Semanchuk wrote: > The general rule is that it is a lot easier to share data between > threads than between processes. The multiprocessing library makes the > latter easier but is only part of the standard library in Python >= 2.6. > The design of your application matters a lot. For instance

Re: printing bytes to stdout in Py3

2009-02-17 Thread Christian Heimes
Casey schrieb: > On Feb 17, 12:33 pm, Christian Heimes wrote: >> Yes, it's really the official way. You can google up the discussion >> between me and Guido on the python-dev list if you don't trust me. ;) >> The docs concur with me, too. >> >>

Re: "Maximum recursion depth exceeded"...why?

2009-02-17 Thread Christian Heimes
Thomas Allen schrieb: > I must not be understanding something. This is a simple recursive > function that prints all HTML files in argv[1] as its scans the > directory's contents. Why do I get a RuntimeError for recursion depth > exceeded? > > #!/usr/bin/env python > > import os, sys > > def mai

Re: _socket.so source?

2009-02-17 Thread Christian Heimes
mbarry schrieb: > Hello, > > > The socket module in Python uses _socket.so for most of its behavior. > I want to modify the code that generates the _socket.so file. > I need the source file and instructions on how to compile and build > _socket.so for Windows. > Can anyone point me to where I can

Re: "Maximum recursion depth exceeded"...why?

2009-02-17 Thread Christian Heimes
Thomas Allen wrote: > I'm referring to the same code, but with a print: > > for file in os.listdir(dir): > if os.path.isdir(file): > print "D", file > > in place of the internal call to absToRel...and only one line prints > such a message. I mean, if I can't trust my OS or its Python

Re: "Maximum recursion depth exceeded"...why?

2009-02-17 Thread Christian Heimes
Thomas Allen wrote: > If you'd read the messages in this thread you'd understand why I'm not > using os.walk(): I'm not using it because I need my code to be aware > of the current recursion depth so that the correct number of "../" are > substituted in. I'm well aware of your messages and your re

Re: Building python with sqlite3

2009-02-18 Thread Christian Heimes
Justin Li schrieb: > I'm building and installing Ptyhon 2.6.1 on Linux. After configure, > make, make install, to import sqlite3 leads to ImportError. It looks > like I have to build Python with sqlite. I have sqlite3 installed on > my system. How should I build Python with it? I did not find any >

Re: Will multithreading make python less popular?

2009-02-19 Thread Christian Heimes
rushen...@gmail.com schrieb: > Thank you Steve, > > I really wanted to learn python, but as i said i don't want to make a > dead investment. I hope someone can fix these design errors and maybe > can write an interpreter in python :) Good luck with Java! You have just traded one "design flaw" for

Re: Explanation for trailing comma in example from Learning Python?

2009-02-19 Thread Christian Heimes
Carl Schumann wrote: > I could see the logic in always or never having a trailing comma. What > I don't understand here is why only the single element case has a > trailing comma. Any explanations please? Does this code shad some light on the trailing comma? :) >>> (1) == 1 True >>> (1,) == 1

Re: Will multithreading make python less popular?

2009-02-19 Thread Christian Heimes
Mensanator wrote: > When I run I Python program, the Windows task manager shows both > cores running (usually a 60/40 split) for an overall 50% usage. > > What am I actually seeing? If Python only uses one of the cores, > why do both light up? Is everything much more complicated (due to > OS sched

Re: Will multithreading make python less popular?

2009-02-19 Thread Christian Heimes
Mensanator wrote: > I thought of that, but the usual Windows crap accounts for only a > couple percent prior to the Python program running. Christian Heimes > answer sounds more realistic. > > But what do I know? Be happy that your program makes use of both cores? :] You ca

Re: Killing subservient threads

2009-02-20 Thread Christian Heimes
Gabriel Genellina wrote: > 1) make the child window set a flag in the thread (let's say, > t.terminate = True). And make the polling thread check the flag > periodically (you possibly already have a loop there - just break the > loop when you detect that self.terminate became true) threading.Condi

Re: Find the location of a loaded module

2009-02-20 Thread Christian Heimes
Aaron Scott schrieb: > I'm running into a problem that's rapidly reaching keyboard-smashing > levels. I'm trying to import a module into Python, but it seems like > Python is almost randomly loading the module from an entirely > different directory, one that shouldn't be in the module search path.

Re: Using clock() in threading on Windows

2009-02-20 Thread Christian Heimes
Maxim Khitrov wrote: > The threading module uses time.time in _Condition and _Thread classes > to implement timeouts. On Windows, time() typically has a resolution > of 15.625ms. In addition, if the system clock is changed (though ntp, > for example) it would reflect that change, causing the timeou

Re: "Byte" type?

2009-02-21 Thread Christian Heimes
John Nagle wrote >If "bytes", a new keyword, works differently in 2.6 and 3.0, that was > really > dumb. There's no old code using "bytes". So converting code to 2.6 means > it has to be converted AGAIN for 3.0. That's a good reason to ignore > 2.6 as > defective. Please don't call somethin

Re: "Byte" type?

2009-02-22 Thread Christian Heimes
Hendrik van Rooyen wrote: > "Christian Heimes" wrote: > >> John Nagle wrote >>>If "bytes", a new keyword, works differently in 2.6 and 3.0, that was >>> really >>> dumb. There's no old code using "bytes". So conver

Re: Reference or Value?

2009-02-22 Thread Christian Heimes
Torsten Mohr schrieb: > Hi, > > how is the rule in Python, if i pass objects to a function, when is this > done by reference and when is it by value? > > def f1(a): > a = 7 > > b = 3 > f1(b) > print b > => 3 > > Integers are obviously passed by value, lists and dicts by reference. > > Is t

And now for something completely different ...

2008-11-22 Thread Christian Heimes
To whom it might concern. Monty Python has opened an official Monty Python channel on Youtube. http://www.youtube.com/user/MontyPython High quality Monty Python movies - powered by Python :) Have fun! Christian -- http://mail.python.org/mailman/listinfo/python-list

Re: 3.0rc3: 'os.extsep' gone ... ?

2008-11-23 Thread Christian Heimes
bMotu wrote: IDLE 2.6 import os os.extsep '.' running XP this result is fine ... ! IDLE 3.0rc3 import os os.extsep Traceback (most recent call last): File "", line 1, in os.extsep AttributeError: 'module' object has no attribute 'extsep' why is this attribute gone in 3.0rc3 ? where

Re: No complex rationals in Python 3.0

2008-11-24 Thread Christian Heimes
Rock wrote: I appreciate the inclusion of the fractions module in Python 2.6 and therefore in Python 3.0. But I feel there's something missing: no possibility for complex rationals (or arbitrary precision) integers. I was just checking the complex number support in Python, compared, for instance,

Re: 'new' module deprecation in python2.6

2008-11-29 Thread Christian Heimes
David Pratt wrote: Hi Mike. Many thanks for your reply and thank you for reference. I have code that looks like the following so initially looking at what will need to be done as it doesn't appear new will survive. So first need to find way of translating this sort of thing using types. I see

Re: building an extension module with autotools?

2008-12-03 Thread Christian Heimes
Gerhard Häring wrote: #!/bin/sh python setup.py build cp build/lib.*/*.so . python test.py "python setup.py build_ext -i" is your friend. It installs the extensions inplace. No need for cp here. :) Christian -- http://mail.python.org/mailman/listinfo/python-list

Re: Python 3 read() function

2008-12-04 Thread Christian Heimes
Cro wrote: Good day. I have installed Python 3 and i have a problem with the builtin read() function. [code] huge = open ( 'C:/HUGE_FILE.pcl', 'rb', 0 ) import io vContent = io.StringIO() vContent = huge.read() # This line takes hours to process !!! vSplitContent = vContent.split ( 'BIN;SP1;PW0.

Re: Python 3 read() function

2008-12-04 Thread Christian Heimes
Terry Reedy wrote: Timing of os interaction may depend on os. I verified above on WinXp with 4 meg Pythonxy.chm file. Eye blink versus 3 secs, duplicated. I think something is wrong that needs fixing in 3.0.1. http://bugs.python.org/issue4533 I've attached a patch to the bug. reading was

Re: slow Python 3.0 write performance?

2008-12-05 Thread Christian Heimes
Istvan Albert wrote: I see, thanks for the clarification. I will make the point though that this makes python 3.0 unsuited for anyone who has to process data. One could live with slowdowns of say 20-50 percent, to get the goodies that 3.0 offers, but when a process that takes 1 second suddenly s

Re: slow Python 3.0 write performance?

2008-12-05 Thread Christian Heimes
MRAB wrote: Does pysco with with Python 3.0 (the homepage says 2.5)? If it does then that might help! :-) No, it won't help. -- http://mail.python.org/mailman/listinfo/python-list

Re: slow Python 3.0 write performance?

2008-12-06 Thread Christian Heimes
Istvan Albert wrote: A previous poster suggested that in this case the slowdown is caused by the new io code being written in python rather than C. For text mode Python 3's write() method is slower than Python 2.x's method because all text is encoded. The slowdown is mostly caused by addition

Re: dict subclass and pickle bug (?)

2008-12-07 Thread Christian Heimes
James Stroud wrote: Hello All, I subclassed dict and overrode __setitem__. When instances are unpickled, the __setstate__ is not called before the keys are assigned via __setitem__ in the unpickling protocol. I googled a bit and found that this a bug filed in 2003: http://bugs.python.org/is

Re: StringIO in 2.6 and beyond

2008-12-08 Thread Christian Heimes
Bill McClain wrote: I've just installed 2.6, had been using 2.4. This was working for me: #! /usr/bin/env python import StringIO out = StringIO.StringIO() print >> out, 'hello' I used 2to3, and added import from future to get: #! /usr/bin/env python from __future__ imp

Re: python3.0 - any hope it will get faster?

2008-12-09 Thread Christian Heimes
Helmut Jarausch wrote: I know that processing unicode is inherently slower, but still I was surprised that it's so much slower. Is there any hope Python-3.0 will get faster or is the main potential for optimizations exhausted, already? That's not to start a flame war! I know computers get faste

Re: broken ncurses on python 3.0

2008-12-11 Thread Christian Heimes
icarus wrote: OS: win32, python 3.0 I've been trying to run some curses demos and I get this: C:\Python\Lib\curses>python textpad.py Traceback (most recent call last): File "textpad.py", line 3, in import curses File "C:\Python\lib\curses\__init__.py", line 15, in from _curses imp

Re: Best way of debigging a C extension

2008-12-11 Thread Christian Heimes
Paul Moore wrote: I have gdb (although I've hardly used it, but I can learn :-)) but if I try building my extension with python setup.py build --debug, I get an error because -lpython25_d does not exist. I'm not surprised by this, as I don't have a debug build of Python - but that should be OK, I

Re: Best way of debigging a C extension

2008-12-11 Thread Christian Heimes
Diez B. Roggisch schrieb: > I never tried this on windows - but what happens if you start python > inside GDB, and then set breakpoints inside your extension? > > This works flawlessly for me under *nix. > > The debug-build of python isn't needed for this - and I doubt a bit that > it helps you m

Re: Best way of debigging a C extension

2008-12-11 Thread Christian Heimes
Paul Moore schrieb: > The trouble is, I only have mingw to build extensions, not MSVC7.1 - > so I can't build Python (and I don't know if I still have the toolkit > compiler to build with that - I certainly don't have all the pieces > installed). With Python 2.6, I guess things will be better as I

Re: Python is slow

2008-12-12 Thread Christian Heimes
sturlamolden schrieb: > On Dec 12, 3:04 pm, Luis M. González wrote: > >> Why don't you guys google a little bit to know what's being done to >> address python's "slowness"?? > > Nothing is being done, and woth Py3k it got even worse. Indeed, it *is* slower for now. As I already said in another

Re: Python Dictionary Algorithm Question

2008-12-16 Thread Christian Heimes
Brigette Hodson schrieb: > Hello! I am in a beginning algorithms class this semester and I am working > on a presentation. I want to discuss in some detail the algorithm python > uses to determine the hash function for python dictionaries. Does anyone > know what this algorithm is? Or where I can g

Re: sys.maxint in Python 2.6.1 (amd64) on Windows XP x64

2008-12-16 Thread Christian Heimes
Lin schrieb: > Hi, > > I installed the amd64 version of Python 2.6.1 on my Windows XP x64 > system. I was expecting sys.maxint to be 9223372036854775807 (or 2 ^63 > -1), but instead I got 2147483647 (i.e., 2^31-1) just like what I got > from a 32-bit version of Python. Is this by design or does it

Re: subprocess returncode windows

2008-12-16 Thread Christian Heimes
Andrew schrieb: > Hello, > > I'm running into a strange situation with getting incorrect > returncodes / exit status from python subprocess.call. I'm using a > python script (runtime 2.6.1 on windows) to automate the deploy of > java applications to glassfish application server. Below is an exampl

Re: sys.maxint in Python 2.6.1 (amd64) on Windows XP x64

2008-12-16 Thread Christian Heimes
Lin schrieb: > Ah, this makes sense. Thanks.. The main reason I'm trying 64-bit > Python is that I want to write files bigger than 4GB. This should work > on Windows x64, right? (i.e., are the pointers bona fide 64 bit?) You can create files with more than 4GB on a 32bit OS, too. It depends on

Re: getting object instead of string from dir()

2008-12-17 Thread Christian Heimes
Rominsky schrieb: > I am trying to use dir to generate a list of methods, variables, etc. > I would like to be able to go through the list and seperate the > objects by type using the type() command, but the dir command returns > a list of strings. When I ask for the type of an element, the answer

Re: New Python 3.0 string formatting - really necessary?

2008-12-19 Thread Christian Heimes
walterbyrd schrieb: > On Dec 19, 9:13 am, "Giampaolo Rodola'" wrote: >> You can use the old 2.x syntax also in Python 3.x: > > Yeah, but it's deprecated, and - as I understand it - may be removed > completely in future versions. Also, in the future, if you are working > with code from another dev

Re: New Python 3.0 string formatting - really necessary?

2008-12-19 Thread Christian Heimes
r schrieb: > I was actually looking forward to 3.0, but the more I hear about 3.0, > the more I am turned off. I think there are a lot of other > pythonista's and pythoneers out there who agree but are not saying > anything. This syntax for string formatting is completely ridiculous. No, it's very

Re: New Python 3.0 string formatting - really necessary?

2008-12-21 Thread Christian Heimes
Patrick Mullen schrieb: > 2) In my experience, major version changes tend to be slower than > before. When a lot of things change, especially if very low-level > things change, as happened in python 3.0, the new code has not yet > went through many years of revision and optimization that the old c

Re: no sign() function ?

2008-12-22 Thread Christian Heimes
Pierre-Alain Dorange schrieb: > I don't find any sign(x) function in the math library (return the sign > of the value). > I've read that math module is a wrapper to C math lib and that C math > lib has not sign(), so... Starting with Python 2.6 the math and cmath modules have a copysign function.

Re: I always wonder ...

2008-12-22 Thread Christian Heimes
s...@pobox.com schrieb: > shouldn't people who spend all their time trolling be doing something > else: studying, working, writing patches which solve the problems they > perceive to exist in the troll subject? Is there some online troll game > running where the players earn points for genera

Re: I always wonder ...

2008-12-22 Thread Christian Heimes
> you are truly an open minded, intelligent Human being. Thanks for > blessing use with your wisdom here. We need more like you. Every > thought, action, fact, must always be questioned, that is what makes > us human! *plonk* -- http://mail.python.org/mailman/listinfo/python-list

Re: python3 urlopen(...).read() returns bytes

2008-12-22 Thread Christian Heimes
Glenn G. Chappell schrieb: > I just ran 2to3 on a py2.5 script that does pattern matching on the > text of a web page. The resulting script crashed, because when I did > > f = urllib.request.urlopen(url) > text = f.read() > > then "text" is a bytes object, not a string, and so I can't do

Re: python3 urlopen(...).read() returns bytes

2008-12-22 Thread Christian Heimes
ajaksu schrieb: > That said, a "decode to declared HTTP header encoding" version of > urlopen could be useful to give some users the output they want (text > from network io) or to make it clear why bytes is the safe way. Yeah, your idea sounds both useful and feasible. A patch is welcome! :) Chr

Re: python3 urlopen(...).read() returns bytes

2008-12-22 Thread Christian Heimes
3.0 really everybody has to deal with encodings. There is no more implicit conversion between ASCII text and unicode. http://www.joelonsoftware.com/articles/Unicode.html explains it in great detail. > > On Dec 22, 1:41 pm, ajaksu wrote: >> On Dec 22, 8:25 pm, Christian Heimes wrote:

Re: python3 urlopen(...).read() returns bytes

2008-12-23 Thread Christian Heimes
ajaksu wrote: > On Dec 22, 9:05 pm, Christian Heimes wrote: >> ajaksu schrieb: >> >>> That said, a "decode to declared HTTP header encoding" version of >>> urlopen could be useful to give some users the output they want (text >>> from netwo

Re: no sign() function ?

2008-12-23 Thread Christian Heimes
All algorithm including my own suffer from one mistake. Nobody accounts for NaN (not a number). You have to check for NaNs, too. NaNs have no sign at all. You could also try to do some fancy bit mask operation like >>> ord(struct.pack("d", 0.)[7]) & 0x80 0 >>> ord(struct.pack("d", -0.)[7]) & 0x80

Re: Using exceptions in defined in an extension module inside another extension module

2008-12-24 Thread Christian Heimes
Floris Bruynooghe schrieb: > What I can't work out however is how to then be able to raise this > exception in another extension module. Just defining it as "extern" > doesn't work, even if I make sure the first module -that creates the > exception- gets loaded first. Because the symbol is define

Re: Syntax error for print

2008-12-25 Thread Christian Heimes
jsm4...@gmail.com schrieb: > Thanks Bearophile. > > I should have used a tutorial for Python 3.0 > > I was reading tutorial for Python 2.5 Get Python 2.5 or 2.6, seriously. Python 3.0 is not (yet) supported by most tutorials, third party extensions and books. Christian -- http://mail.python.or

Re: SyntaxError: encoding problem: with BOM

2008-12-25 Thread Christian Heimes
NoName schrieb: >> NoName, Asking people to download a zip file from a website written in >> a language and character set that they probably are not familiar with >> is liable to make them rather nervous and not bother. It's not a good >> way to ask for help. > > sorry:) > > Now i know where prob

Re: multiprocessing vs thread performance

2008-12-29 Thread Christian Heimes
mk wrote: > Am I doing smth wrong in code below? Or do I have to use > multiprocessing.Pool to get any decent results? You have missed an important point. A well designed application does neither create so many threads nor processes. The creation of a thread or forking of a process is an expensive

Re: type conversion

2009-01-02 Thread Christian Heimes
Hamish McKenzie schrieb: > I actually have no idea what ur talking about... aren't conversations > threaded by subject? Nope, they are threaded by message id. The subject is used as fallback only. Christian -- http://mail.python.org/mailman/listinfo/python-list

Re: How to declare python ints in C extensions?

2009-01-04 Thread Christian Heimes
Philip Semanchuk schrieb: > This works for me: >PyModule_AddIntConstant(module, "O_CREAT", O_CREAT); > > I've had to learn a lot about writing extensions from looking at the > Python source code. Lots of valuable tricks to be learned there. This trick makes it even easier: #ifndef PyModule_A

Re: Detecting a GUI session

2009-01-07 Thread Christian Heimes
Leith Bade schrieb: > I would like to know whether my GUI program is being run under python or > pythonw. > > I would like to know this so I can redirect stderr when their is no > console window (pythonw) otherwise leave it spitting to the console > window (python). > > This is because I debug

Re: redirecting stderr back..

2009-01-09 Thread Christian Heimes
rh0dium schrieb: > Hi All, > > Can someone tell me how to redirect stderr back to the console once > you've moved it? sys.stderr = sys.__stderr__ or better: orig_stderr = sys.stderr try: sys.stderr = open(...) ... finally: sys.stderr = orig_stderr Christian -- http://mail.python.o

Re: redirecting stderr back..

2009-01-09 Thread Christian Heimes
Robert Kern schrieb: > Christian Heimes wrote: >> rh0dium schrieb: >>> Hi All, >>> >>> Can someone tell me how to redirect stderr back to the console once >>> you've moved it? >> >> sys.stderr = sys.__stderr__ >> >>

Re: Python 2.6: Determining if a method is inherited

2008-10-05 Thread Christian Heimes
Terry Reedy wrote: In 3.0, the test returns true because function attributes only get wrapped when bound. In the meanwhile, " 'object' in repr(X.__lt__)" should do it for you. This session should give you some hints how to archive your goal :) Have fun! >>> import types >>> class A(object):

Re: In Python 2.6, bytes is str

2008-10-07 Thread Christian Heimes
Bryan Olson wrote: Python 3 has the 'bytes' type, which the string type I've long wanted in various languages. Among other advantages, it is immutable, and therefore bytes objects can be dict keys. There's a mutable version too, called "bytearray". In Python 2.6, the name 'bytes' is defined

Re: Making Non Callable Objects Callable

2008-10-07 Thread Christian Heimes
exiquio wrote: I am trying to figure out if there is a way to make an object in python callable, modules in particular. I wrongly assume that defining '__call__' in the the objects __dict__ would work. Any help would be appreciated. No, that doesn't work. Several magic methods (__*__) aren't lo

Re: Quality control in open source development

2008-10-08 Thread Christian Heimes
Dave wrote: If licensees can redisribute as they like, isn't this a huge problem? Is this dealt with be restricting use of the Python trademarks? Just curious.. From http://www.python.org/psf/summary/ --- The PSF also holds and protects the trademarks behind the Python programming language. T

Re: MRO inconsistency: why?

2008-10-08 Thread Christian Heimes
Ravi wrote: Why the following code gives inconsistent method resolution order error: [...] Your problem can be reduced to: >>> class A(object): ... pass ... >>> A.__mro__ (, ) >>> class B(object, A): ... pass ... Traceback (most recent call last): File "", line 1, in TypeError: Erro

Re: no unbound methods in py3k

2008-10-08 Thread Christian Heimes
Thomas Heller wrote: but this is very ugly, imo. Is there another way? The raw_func instances that I have are not descriptors (they do not implement a __get__() method...) I've written PyInstanceMethod_Type for this use case. It's not (yet) available for Python code. Barry hasn't decided whet

Re: default value in __init__

2008-10-09 Thread Christian Heimes
kenneth wrote: the 'd' variable already contains the 'self.d' value of the first instance and not the default argument {}. Am I doing some stupid error, or this is a problem ? No, it always contains the default argument because default values are created just ONE TIME. http://effbot.org/pyfa

Re: no unbound methods in py3k

2008-10-09 Thread Christian Heimes
Thomas Heller wrote: Ok, so one has to write an extension to access or expose it. Oh, wait - there's ctypes: I wrote the type to help the Pyrex and Cython developers to port their software to 3.0. I planed to expose the type as __builtin__.instancemethod but forgot it. Maybe we can convince

Re: Wanted: something more Pythonic than _winreg.

2008-10-10 Thread Christian Heimes
Jonathan Fine wrote: Hello I'm using the _winreg module to change Windows registry settings, but its rather low level, and I'd prefer to be working with something more Pythonic. Does anyone have any recommendations? Yeah, please implement a nice wrapper and submit a patch to bugs.python.o

Re: C API with *args and **kw

2008-10-14 Thread Christian Heimes
Miki wrote: Hello All, I'm try to write the C equivalent of: Use PyArg_ParseTupleAndKeywords() to parse the args and kwargs objects. Christian -- http://mail.python.org/mailman/listinfo/python-list

Re: replace mothod for only one object but not for a class

2008-10-14 Thread Christian Heimes
Bruno Desthuilliers wrote: If the class is a new-style one [1], it just requires invoking the descriptor protocol by yourself to get a bound method, ie: Another note about new style classes: You can NOT overwrite most magic methods (__*__) on the instance. Most magic methods are only looked up

Re: Python certification

2008-10-17 Thread Christian Heimes
srinivasan srinivas wrote: Hi, I m planning to do certification in Python?? Is therr any good certification available in Python like Sun certification for java?? The topic has been discussed on the internal Python Software Foundation list multiple times but w/o a definite answer. Christian

Re: Script can't find input file despite being in the same directory

2008-10-17 Thread Christian Heimes
Robocop wrote: I have a simple little script that reads in postscript code, appends it, then writes it to a new postscript file. Everything worked fine a month ago, but after rearranging my directory tree a bit my script fails to find the base postscript file. The line in question is: for li

Re: keyword in package name.

2008-10-19 Thread Christian Heimes
Marc 'BlackJack' Rintsch wrote: `com_spam.app1`!? I would even recommend this with domains that don't clash with keywords because if several people start to use this package name convention you will get name clashes at package level. Say there are two vendors with a `com` TLD, how do you inst

Re: 2.6, 3.0, and truly independent intepreters

2008-10-23 Thread Christian Heimes
Andy wrote: 2) Barriers to "free threading". As Jesse describes, this is simply just the GIL being in place, but of course it's there for a reason. It's there because (1) doesn't hold and there was never any specs/ guidance put forward about what should and shouldn't be done in multi- threaded a

Re: substitution __str__ method of an instance

2008-10-23 Thread Christian Heimes
netimen wrote: How can I substitute __str__ method of an instance? It's not possible. For performance and other reasons most __*__ methods are looked up on the type only. Christian -- http://mail.python.org/mailman/listinfo/python-list

Re: why does math.pow yields OverflowError (while python itself can calculate that large number)

2008-10-23 Thread Christian Heimes
Tzury Bar Yochay wrote: Because math.pow returns a float; 100 ** 155 won't fit in a float. Sure that is the reason. May I rephrase, my question: Why not returning another type as long as we can calculate it? After all, math module is likely to be used on large numbers as well. Because it's ve

Re: @property decorator doesn't raise exceptions

2008-10-24 Thread Christian Heimes
Rafe wrote: Hi, I've encountered a problem which is making debugging less obvious than it should be. The @property decorator doesn't always raise exceptions. It seems like it is bound to the class but ignored when called. I can see the attribute using dir(self.__class__) on an instance, but when

Re: [Python 2.6] print_function and unicode_literals cannot be used at the same time?

2008-10-26 Thread Christian Heimes
?? wrote: Any ideas? Code 1: from __future__ import print_function, unicode_literals import sys print(type('HELLO, WORLD!'), file=sys.stderr) You have to do each future import in a separate line: >>> from __future__ import unicode_literals >>> from __future__ import print_function >>> pr

Re: 404 not found on for Python 2.6 Itanium

2008-10-28 Thread Christian Heimes
[EMAIL PROTECTED] wrote: Anyone know where else I can download 2.6 for x64 windows? x64 is AMD64 aka X64_86 and not the Itanium version. Itanium is IA64. We don't build Python for IA64 anymore. Christian -- http://mail.python.org/mailman/listinfo/python-list

Re: efficient Python object count

2008-11-06 Thread Christian Heimes
darrenr wrote: Hello, Does anyone know of an efficient way to get a count of the total number of Python objects in CPython? The best solution I've been able to find is len(gc.get_objects()) which unfortunately has to walk a C linked list *and* creates a list containing all of the objects, when a

Re: Does Python have Multiple Inheritance ?

2008-11-07 Thread Christian Heimes
Aaron Gray wrote: Wikipedia says Python has Multiple Inheritance, is this true ? http://en.wikipedia.org/wiki/Multiple_inheritance Yes -- http://mail.python.org/mailman/listinfo/python-list

<    1   2   3   4   5   6   7   8   9   10   >