What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 130 Stack Exchange communities.

I've tried indenting everything, except for syntax highlighting which I was going to edit after my post it's "blocking" the code correctly, but the code formatting checker keeps rejecting it. What am I doing wrong?

EDIT: Apparently I've seen I can post it here. Maybe someone knows what's wrong? I've even indented stuff that's not code, but rather terminal commands, just to be safe:

I'm having one hell of a time with SWIG, due in part to the lack of good C++ examples to learn from. I finally got my first program to compile with SWIG, but am having troubles running it. Let me just get right to the code...

setup.py:

#!/usr/bin/env python

"""
setup.py file for SWIG example
"""

from distutils.core import setup, Extension


decklist_module = Extension('_decklist',
                           sources=['decklist_wrap.cxx', 'decklist.cpp'],
                           )

setup (name = 'decklist',
       version = '0.1',
       author      = "Me",
       description = """Testing!""",
       ext_modules = [decklist_module],
       py_modules = ["decklist"],
       ) 

decklist.hpp:

#include <boost/unordered_map.hpp>



class DeckList{
private:
        boost::unordered_map<std::string, int> mainBoard;
        boost::unordered_map<std::string, int> sideBoard;
    public:
        void addCard(std::string name, int cardCount);
        int getCount(std::string cardName);
        DeckList();
        ~DeckList();

};
decklist.cpp: #ifndef DECKLIST_H #define DECKLIST_H #include "decklist.hpp" #include

DeckList::DeckList(){

}

void DeckList::addCard(std::string cardName, int cardCount){
    mainBoard[cardName] = cardCount;
}

int DeckList::getCount(std::string cardName){
    return mainBoard[cardName];
}

#endif    

decklist.i:

//decklist.i
%module decklist
%{
    #include "decklist.hpp"
%}
#include "decklist.hpp"

Now on the terminal (I am on Ubuntu Natty Narwhal), I run the following two commands:

swig -python -c++ decklist.i
python setup.py build_ext --inplace

The second gives me the following response:

running build_ext
building '_decklist' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c decklist_wrap.cxx -o build/temp.linux-x86_64-2.7/decklist_wrap.o
cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c decklist.cpp -o build/temp.linux-x86_64-2.7/decklist.o
cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
g++ -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions build/temp.linux-x86_64-2.7/decklist_wrap.o build/temp.linux-x86_64-2.7/decklist.o -o /home/aespiel1/deck/_decklist.so

But I wind up with: decklist.cpp decklist.hpp decklist.i decklist.py decklist.pyc _decklist.so decklist_wrap.cxx setup.py and a build folder with .o files for both the decklist_wrap and decklist files.

If I run python in idle and switch into this directory and import:

import decklist

I get:

Traceback (most recent call last): File "", line 1, in import decklist ImportError: No module named decklist

Strangely, if I run it from the terminal, I can import decklist. But then a command like:

dl = decklist.DeckList()   

gives:

Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'DeckList'

What am I doing wrong? I am so frustrated.

share|improve this question
3  
It exists because too many posts were posted without formatting for the code, which caused unreadable code. It's pretty new, so maybe it will be improved over time but it does help keep the site cleaner and with better looking code - thousands of people do post code, every hour. –  Shadow Wizard Aug 4 '11 at 21:02
    
@Siva - that's not relevant - the new feature won't let him post it that's the whole problem here. –  Shadow Wizard Aug 4 '11 at 21:03
4  
Can you add the code to this post so that we can take a look at it? –  M. Tibbits Aug 4 '11 at 21:08
3  
Posting a screenshot of the question that's being rejected would make it possible for someone to help you –  Brad Mace Aug 4 '11 at 21:23
1  
The code formatting checker is a relatively new feature, you're posting a fair amount of code, and Python-SWIG questions are fairly rare so I'm guessing you have indeed found a bug. Looks like a fun one for the devs to figure out. –  Brad Mace Aug 5 '11 at 5:09
    
    
possible duplicate of Why is my Stack Exchange code formatting considered wrong? –  Pops Aug 5 '11 at 14:07
    
I tried the things in those discussions and nothing helped. –  user650261 Aug 5 '11 at 14:27

2 Answers 2

Check out this question:
Why is my Stack Exchange code formatting considered wrong?

If no luck, try changing your browser font size according to this post it might also help.

share|improve this answer
1  
meta.stackexchange.com/questions/99733/… was that other question you were thinking of. –  Troyen Aug 4 '11 at 22:39
    
Thanks for finding it, edited the answer now. –  Shadow Wizard Aug 5 '11 at 5:52
    
Thanks for the comment, but neither of those worked. I've already tried indenting; as you can see, there is nothing in my post that looks like code that hasn't been formatted to look like code. Changing my browser's font size did nothing. –  user650261 Aug 5 '11 at 12:51
up vote 1 down vote accepted

I solved my own problem.

It turns out the checker saw my list of files in my directory and thought it was code.

This is clearly a bug; those are not code and should not need to be treated as such. Or if they should be treated by such, that should be documented in the help.

How can this be forwarded to the stackoverflow support center?

Btw, thanks for the helpful replies.

share|improve this answer
    
A list of files needs to be formatted somehow. Either as code or as a bulleted list. There's no bug here; possibly the error message could be made more clear, but the point still gets across that there's a formatting problem with your post. –  Cody Gray Aug 6 '11 at 9:42
    
The error message HAS to be made more clear. It is NOWHERE in the help, and a file list is NOT code. –  user650261 Aug 8 '11 at 13:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .