Bulding python module using C

A

Andrew Degtiariov

Hello.
After some unhappy tries to write own module I attempt to compile
noddy3.c from Python-Docs-2.3.4.
I build noddy3.so using setup.py (showing bellow) and compilation process
pass witout any warning. Bu while i try run test (test.py) it failed with:
<attribute 'first' of 'noddy3.Noddy' objects>
Traceback (most recent call last):
File "test.py", line 6, in ?
n.first = 'test'
TypeError: can't set attributes of built-in/extension type 'noddy3.Noddy'

Where was i wrong?

--- Begin of test.py ---
import sys
import noddy3

n = noddy3.Noddy
print n.first
n.first = 'test'
print n.first
sys.exit(0)
--- End of test.py ---

--- Begin setup.py ---
#! /usr/bin/env python

import sys

from distutils.core import setup, Extension

setup( name="noddy3",
version="3",
author="Primer from python documentation",
author_email="(e-mail address removed)",
license="unknown",
url="http://www.python.org/",
ext_modules = [ Extension( "noddy3", ["noddy3.c"],
libraries = [ ],
) ] )
--- End of test.py ---
 
M

Michael Hoffman

Andrew said:
Traceback (most recent call last):
File "test.py", line 6, in ?
n.first = 'test'
TypeError: can't set attributes of built-in/extension type 'noddy3.Noddy'

Where was i wrong?

You are trying to set an attribute on the type instead of an *instance*
of the type.
n = noddy3.Noddy

n = noddy3.Noddy()
 
A

Andrew Degtiariov

You are trying to set an attribute on the type instead of an *instance*
of the type.


n = noddy3.Noddy()
Yes, you right. It is stupid for my self, sorry :-(
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top