Re: time difference interms of day

2010-10-24 Thread Jonas H.
On 10/24/2010 07:55 PM, mukkera harsha wrote: On, doing now - startup I want the program to return in terms of days. How ? >>> import datetime >>> now = datetime.datetime.now() >>> after_few_seconds = datetime.datetime.now() >>> after_few_seconds - now datetime.timedelta(0, 14, 256614) >>> (aft

Re: embarrassing class question

2010-10-21 Thread Jonas H.
On 10/21/2010 08:09 PM, Brendan wrote: Two modules: x.py: class x(object): pass y.py: from x import x class y(x): pass Now from the python command line: import y dir(y) ['__builtins__', '__doc__', '__file__', '__name__', '__package__', 'x', 'y'] I do not understand why class 'x' sh

Re: Minimal D

2010-10-17 Thread Jonas H.
On 10/16/2010 06:04 PM, Kruptein wrote: Hey, I've written a small "IDE". It is written in python using the python toolkit and offers an advanced text-editor, file-manager, ftp-client, sql- client(in development) and more towards the future. You definitely want to have a look at PEP8. -- http:/

Re: My first Python program

2010-10-13 Thread Jonas H.
On 10/13/2010 11:26 PM, Seebs wrote: stderr.write( "WARNING:" " Pants on fire\n") Hmm. So I just indent stuff inside the ()s or whatever? I can work with that. I think common is stderr.write("WARNING: ", "Pants on fire") or stderr.write(

Re: My first Python program

2010-10-13 Thread Jonas H.
On 10/13/2010 06:48 PM, Seebs wrote: Is it safe for me to assume that all my files will have been flushed and closed? I'd normally assume this, but I seem to recall that not every language makes those guarantees. Not really. Files will be closed when the garbage collector collects the file ob

Re: Reading after a symbol..

2010-10-12 Thread Jonas H.
On 10/12/2010 10:48 PM, Pratik Khemka wrote: Likewise I want to read the number after the '#' and store it in num. The problem is that the number can be a 1/2/3/4 digit number. So is there a way in which I can define num so that it contains the number after '#' irrespective of how many digits

Re: My first Python program

2010-10-12 Thread Jonas H.
On 10/12/2010 09:14 PM, Seebs wrote: http://github.com/wrpseudo/pseudo/blob/master/makewrappers Just a few pointers, looks quite good to me for a newbie :) * Less action in __init__. * Use `open` instead of `file` to open a file * Have a look at context managers for file handling (avoids doing

Re: Help with pointers when calling from python to C

2010-10-08 Thread Jonas H.
On 10/08/2010 05:23 PM, Carolyn MacLeod wrote: "How do I pass an integer by reference to a C function?" That's impossible in pure Python. The only thing I can think of is a wrapper in C. -- http://mail.python.org/mailman/listinfo/python-list

Re: frozendict (v0.1)

2010-10-08 Thread Jonas H.
On 10/08/2010 03:27 PM, kj wrote: I tried to understand this by looking at the C source but I gave up after 10 fruitless minutes. (This has been invariably the outcome of all my attempts at finding my way through the Python C source.) It's not you. CPython's code is ... [censored] Anyway, you

Re: frozendict (v0.1)

2010-10-08 Thread Jonas H.
On 10/08/2010 02:23 AM, kj wrote: I imagine that frozenset is better than sorted(tuple(...)) here, but it's not obvious to me why. dicts are unsorted. That means their item-order is undefined. So are sets. If you want a hash that is independent from the order of items, you could ensure the it

Re: [C-API] Weird sys.exc_info reference segfault

2010-10-06 Thread Jonas H.
On 10/06/2010 02:01 PM, Antoine Pitrou wrote: It shouldn't. Are you sure you're calling PyType_Ready in the module initialization routine? Yeah. The problem was that the type struct was declared 'static' in another module so the changes `PyType_Ready` made to the struct weren't applied correc

Re: How to save a binary file?

2010-10-05 Thread Jonas H.
On 10/05/2010 11:11 PM, hid...@gmail.com wrote: Hello, how i can save a binary file, i read in the manual in the IO area but doesn' t show how to save it. Here is the code what i am using: s = open('/home/hidura/test.jpeg', 'wb') s.write(str.encode(formFields[5])) s.close() So where's the probl

Re: [C-API] Weird sys.exc_info reference segfault

2010-10-05 Thread Jonas H.
On 10/04/2010 11:41 PM, Antoine Pitrou wrote: Well, it should work, but you have to call PyType_Ready() to fill in the NULL fields with default values (for those where it's necessary). Does it solve it for you? Yes, thank you! Although I do not understand which fields I have to provide. I want

Re: [C-API] Weird sys.exc_info reference segfault

2010-10-04 Thread Jonas H.
On 10/04/2010 10:46 AM, Jonas H. wrote: On 10/03/2010 11:52 PM, Antoine Pitrou wrote: You probably have a problem in your tp_dealloc implementation. `tp_dealloc` is NULL... Alright, `tp_dealloc` must not be NULL because it's called by `_Py_Dealloc`. The C-API tutorial is quite conf

Re: [C-API] Weird sys.exc_info reference segfault

2010-10-04 Thread Jonas H.
On 10/03/2010 11:52 PM, Antoine Pitrou wrote: You probably have a problem in your tp_dealloc implementation. `tp_dealloc` is NULL... -- http://mail.python.org/mailman/listinfo/python-list

Re: [C-API] Weird sys.exc_info reference segfault

2010-10-03 Thread Jonas H.
On 10/03/2010 03:47 PM, Antoine Pitrou wrote: You shouldn't call PyObject_FREE yourself, but instead rely on Py_DECREF to deallocate it if the reference count drops to zero. So, instead of commenting out Py_DECREF and keeping PyObject_FREE, I'd recommend doing the reverse. That way, if a referenc

Re: [C-API] Weird sys.exc_info reference segfault

2010-10-03 Thread Jonas H.
On 10/03/2010 01:16 AM, Antoine Pitrou wrote: You should check that you aren't doing anything wrong with "env" and "start_response" (like deallocate them forcefully). I commented out the `Py_DECREF(start_response)` after the `app` call and the crash was gone. `start_response` is created via `P

[C-API] Weird sys.exc_info reference segfault

2010-10-02 Thread Jonas H.
Hello list, I have a really weird reference problem with `sys.exc_info`, and, if I'm right, function frames. The software in question is bjoern, a WSGI web server written in C, which you can find at http://github.com/jonashaag/bjoern. This WSGI application: def app(env, start_response):

[C-API] malloc error in PyDict_New

2010-03-26 Thread Jonas H.
Hi there, I'm currently diving into Python C programming and I have a problem with `PyDict_New`. My application receives a SIGABRT from malloc every time I execute `PyDict_New`. malloc throws the following error: malloc.c:3096: sYSMALLOc: Assertion `(old_top == (((mbinptr) (((char *) &