Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Invalid Syntax
#1
Hello Everyone,

As I'm new to python, i tried some script but while running that script getting an error i.e. "There's an error in your program: invalid syntax" for PyObject*. Any one faced same issue please reply back.

spammodul.c

#include <Python.h>

static PyObject *
spam_system(PyObject *self, PyObject *args)
{
const char *command;
int sts;

if (!PyArg_ParseTuple(args, "s", &command))
return NULL;
sts = system(command);
return PyLong_FromLong(sts);
}

python script
import spam
status = spam.system("ls -l")

Thanks and Regards
Mamta Parida
Reply
#2
What's the whole error?
And what's the whole spammodul.c?
Reply
#3
Please post the code in Python code tags, and full error message in error tags. Use ctrl+shift+v when you copy code, so indentation is preserved. You can find help here.
Reply
#4
Quote:The error which i received is mentioned below

Traceback (most recent call last):
File "D:\Python\Git\python-c-extension-master\00-HelloWorld\test.py", line 3, in <module>
import helloworld
ImportError: No module named helloworld

when i'm executing the test.py file this error is displaying on to the python script. Request you to provide any solution for it why this is happening. Any compiler i need to install on my system

Please don't pm. The whole point of a forum is so that if someone else has a similar issue, they can find the solution easily.
Reply
#5
The code you posted in your first message is NOT python but C. If you try running it as a python program you get syntax errors!

Quote:ImportError: No module named helloworld
The error message is rather clear in my opinion: you try importing a python module called "helloworld" but it doesn't exist or it is not in a place that can be found by python.
Reply
#6
Obviously OP is learning/trying to build Python C extension.
Rest of @squenson's comment apply - i.e. no spam module (post#1) or helloworld module (post#4)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  print(data) is suddenly invalid syntax db042190 6 1,195 Jun-14-2023, 02:55 PM
Last Post: deanhystad
  SyntaxError: invalid syntax ?? korenron 15 5,729 Jan-25-2022, 11:46 AM
Last Post: korenron
  Invalid syntax with an f-string Mark17 7 7,813 Jan-14-2022, 04:44 PM
Last Post: Mark17
  invalid syntax in my class CompleteNewb 2 1,904 Dec-13-2021, 09:39 AM
Last Post: Larz60+
Exclamation Invalid syntax error(Predict Ethereum Price) lulu43366 2 3,167 Sep-24-2021, 01:24 PM
Last Post: lulu43366
  Unexplained Invalid syntax Error cybertooth 5 3,254 Aug-02-2021, 10:05 AM
Last Post: cybertooth
  [split] SyntaxError: invalid syntax Code_X 3 2,759 May-04-2021, 05:15 PM
Last Post: Yoriz
  Invalid syntax error - need help fixing calgk01 3 3,282 Feb-23-2021, 08:41 PM
Last Post: nilamo
  Invalid syntax using conditionals if - else jperezqu 1 2,334 Jan-13-2021, 07:32 PM
Last Post: bowlofred
  invalid syntax in line 5. Help Asadzangibaloch 2 2,392 Dec-10-2020, 04:26 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020