ask help for a proble with invalid syntax

Discussion in 'Python' started by leo zhao, Oct 13, 2009.

  1. leo zhao

    leo zhao Guest

    I try to a run a python numpy programe, however the python can't run
    this program.
    my python version is 2.6.2 , numpy version is 1.3.0, however, the
    program can run in previous numpy version(1.2.0), who can help me to
    solve the problem, I will deeply appreciate!
    the program is below:



    import sys
    import os
    from datetime import *
    from random import *
    from numpy import *
    import py4cs.multipleloop as mp


    class ConsProd(object):
    total_production =[0.0,0.0,0.0]
    tech = 1.0
    goods =['z','x','y']
    def __init__(seld,identifier):
    self.identifier = identifier
    self.demand_veector = array([0.0,0.0]
    if len(G.cps1) > number_of_1individuals:
    self.make = ConsProd.goods[0]
    self.tech = ConsProd.tech
    self.gross_production = (self. tech*G.L,0.0,0.0)
    ConsProd.total_production[0] += self.gross_production
    [0]
    G.cps1[self] = self.gross_production[0]
    elif number_of_1individuals >= len(G.cps1) and len(G.cps2) <
    number_of_2indibiduals:
    self.make = ConsProd.goods[1]
    self.tech = ConsProd.tech
    self.gross_production = (0.0,self. tech*G.L,0.0)
    ConsProd.total_production[1] += self.gross_production
    [1]
    G.cps2[self] = self.gross_production[0]
    else:
    self.make = ConsProd.goods[2]
    self.tech = ConsProd.tech
    self.gross_production = (0.0,0.0,self. tech*G.L)
    ConsProd.total_production[2] += self.gross_production
    [2]
    G.cps3[self] = self.gross_production[2]

    the hint is the small window at python:


    syntax error:
    There' an error in your program: invalid syntax.
     
    leo zhao, Oct 13, 2009
    #1
    1. Advertising

  2. leo zhao

    Robert Kern Guest

    On 2009-10-13 17:09 PM, leo zhao wrote:
    > I try to a run a python numpy programe, however the python can't run
    > this program.
    > my python version is 2.6.2 , numpy version is 1.3.0, however, the
    > program can run in previous numpy version(1.2.0), who can help me to
    > solve the problem, I will deeply appreciate!
    > the program is below:


    > the hint is the small window at python:
    >
    >
    > syntax error:
    > There' an error in your program: invalid syntax.


    Always copy-and-paste the complete error message. Do not try to paraphrase or
    retype the message.

    Your problem is this line:

    self.demand_veector = array([0.0,0.0]

    It should be this:

    self.demand_veector = array([0.0,0.0])

    --
    Robert Kern

    "I have come to believe that the whole world is an enigma, a harmless enigma
    that is made terrible by our own mad attempt to interpret it as though it had
    an underlying truth."
    -- Umberto Eco
     
    Robert Kern, Oct 13, 2009
    #2
    1. Advertising

  3. leo zhao

    MRAB Guest

    leo zhao wrote:
    > I try to a run a python numpy programe, however the python can't run
    > this program.
    > my python version is 2.6.2 , numpy version is 1.3.0, however, the
    > program can run in previous numpy version(1.2.0), who can help me to
    > solve the problem, I will deeply appreciate!
    > the program is below:
    >
    >
    >
    > import sys
    > import os
    > from datetime import *
    > from random import *
    > from numpy import *
    > import py4cs.multipleloop as mp
    >
    >
    > class ConsProd(object):
    > total_production =[0.0,0.0,0.0]
    > tech = 1.0
    > goods =['z','x','y']
    > def __init__(seld,identifier):
    > self.identifier = identifier
    > self.demand_veector = array([0.0,0.0]


    Missing ")".

    > if len(G.cps1) > number_of_1individuals:
    > self.make = ConsProd.goods[0]
    > self.tech = ConsProd.tech
    > self.gross_production = (self. tech*G.L,0.0,0.0)
    > ConsProd.total_production[0] += self.gross_production
    > [0]
    > G.cps1[self] = self.gross_production[0]
    > elif number_of_1individuals >= len(G.cps1) and len(G.cps2) <
    > number_of_2indibiduals:
    > self.make = ConsProd.goods[1]
    > self.tech = ConsProd.tech
    > self.gross_production = (0.0,self. tech*G.L,0.0)
    > ConsProd.total_production[1] += self.gross_production
    > [1]
    > G.cps2[self] = self.gross_production[0]
    > else:
    > self.make = ConsProd.goods[2]
    > self.tech = ConsProd.tech
    > self.gross_production = (0.0,0.0,self. tech*G.L)
    > ConsProd.total_production[2] += self.gross_production
    > [2]
    > G.cps3[self] = self.gross_production[2]
    >
    > the hint is the small window at python:
    >
    >
    > syntax error:
    > There' an error in your program: invalid syntax.
    >

    There are also a number of spelling mistakes.
     
    MRAB, Oct 13, 2009
    #3
  4. On Tue, 13 Oct 2009 23:54:58 +0100, MRAB wrote:

    >> syntax error:
    >> There' an error in your program: invalid syntax.
    >>

    > There are also a number of spelling mistakes.


    Shame on you MRAB, you'll letting down the fine old Internet tradition
    that anytime you point out somebody else's spelling mistakes, you make
    more, and worse, errors yourself :)

    You should have written:

    "There is also a number off speling mistekes."

    Don't let it happen agian.


    *wink*



    --
    Steven
     
    Steven D'Aprano, Oct 14, 2009
    #4
  5. leo zhao

    John Machin Guest

    On Oct 14, 9:09 am, leo zhao <> wrote:
    > I  try to a run a python numpy programe, however the python can't run
    > this program.
    > my python version is 2.6.2 , numpy  version is 1.3.0, however, the
    > program can run in previous numpy version(1.2.0), who can help me to
    > solve the problem, I will deeply appreciate!
    > the program is below:
    >
    > import sys
    > import os
    > from datetime import *
    > from random import *
    > from numpy import *


    Possibly nothing to do with your immediate problem, but 'from amodule
    import *' is not recommended ... just import the objects that you
    need.


    > import py4cs.multipleloop as mp
    >
    > class ConsProd(object):
    >     total_production =[0.0,0.0,0.0]
    >     tech = 1.0
    >     goods =['z','x','y']


    Lists as class attributes? Are you sure that that's what you want?

    >     def __init__(seld,identifier):


    Typo above: seld instead of self. This and other problems mentioned
    below make it hard to believe this code runs with any version of
    anything.

    >         self.identifier = identifier
    >         self.demand_veector = array([0.0,0.0]


    veector or vector?

    You are missing a ")" from the end of the above line. That should
    cause a syntax error when it hits the ":" in the next line.

    >         if len(G.cps1) > number_of_1individuals:


    G is not defined.
    number_of_1individuals is not defined.

    >                self.make = ConsProd.goods[0]
    >                self.tech = ConsProd.tech
    >                self.gross_production = (self. tech*G.L,0.0,0.0)
    >                ConsProd.total_production[0] += self.gross_production
    > [0]
    >                G.cps1[self] = self.gross_production[0]


    self as a dictionary key?? Have supplied a __hash__ method for the
    class?

    >         elif number_of_1individuals >= len(G.cps1) and len(G.cps2) <
    > number_of_2indibiduals:


    number_of_2indibiduals or number_of_2individuals?? In any case,
    neither of these is defined.

    >                self.make = ConsProd.goods[1]
    >                self.tech = ConsProd.tech
    >                self.gross_production = (0.0,self. tech*G.L,0.0)
    >                ConsProd.total_production[1] += self.gross_production
    > [1]
    >                G.cps2[self] = self.gross_production[0]
    >         else:
    >                self.make = ConsProd.goods[2]
    >                self.tech = ConsProd.tech
    >                self.gross_production = (0.0,0.0,self. tech*G.L)
    >                ConsProd.total_production[2] += self.gross_production
    > [2]
    >                G.cps3[self] = self.gross_production[2]
    >
    > the hint is the small window at python:


    What is "the small window at python"??

    >
    > syntax error:
    > There' an error in your program: invalid syntax.


    I doubt that that is an exact copy of the error message. You haven't
    included a copy of the line where the syntax error is alleged to
    occur. If you provide an exact copy of the error message etc that you
    see on your screen (use copy/paste), we should be able to help you.

    Note that if you have a Python syntax error, it is very unlikely that
    it would "work" with one version of Numpy and not "work" with another
    version -- unless of course you have changed the source code between
    Numpy versions.

    HTH,
    John
     
    John Machin, Oct 14, 2009
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. aa

    proble with web.config

    aa, Dec 23, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    568
    Kevin Spencer
    Dec 23, 2003
  2. Andrew
    Replies:
    2
    Views:
    370
    Andrew
    Sep 3, 2004
  3. John M

    proble on using visual studio

    John M, May 12, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    380
    John M
    May 12, 2005
  4. rvino

    proble with substitution

    rvino, Aug 23, 2007, in forum: Perl
    Replies:
    0
    Views:
    2,165
    rvino
    Aug 23, 2007
  5. Sanny

    Socket .readLine() proble.

    Sanny, Oct 4, 2007, in forum: Java
    Replies:
    12
    Views:
    10,077
    Gordon Beaton
    Oct 8, 2007
Loading...

Share This Page