string - Getting back the correct values when using classes in Python -


Then I am coming into programming and Python in my study, and in a Python the word scanner object Takes a string and returns a list of tuples that reads in the format (TYPE, WORD), where TYPE is the word type, and word is the word itself, by searching the word for the word in a group of words of that type Determining the type of wordIf there is a word, or a number, then Tupal gives more words like this; If the word is not there, then the tuple gives an "error" and the word, for example, if the input is "Answer for my 3 days", then the list will return such as read something:

 < Code> [('error', 'mine'), ('(' number ',' 3 '), (' error '), (' error ', gone), (' number ',' answer ') 'Error', 'for'),, 'day')]   

or something like that.

However, when I try to input the code and run it from the main project to get the work done, in the command line, the only value I put in return was the message Was

  & lt; __ Main __. 0x7fe88b5cd750 & gt;   

No matter what I tried to add to the code again, and whatever I tried to declare the last printed sentence, I gave it to main . Object in the form of the value of the string in the scanner

Here is the code I created for reference: import from otherfunc import numconv class scan (object): def __init __ (self, string): self.string = String def scanner (self): direction = ['north', 'south', 'east', 'west', 'down', 'up', 'left', 'right', '', '' For the word in word = word: if word is in the direction: analysis = ('direction', word) word = ['door', '' '' '' '' '' '' '' '' '' ' 'Bear', 'princess', 'cabinet'] words = division (self. String) sentence =) sentence. Aileph in verb (analysis) verb: analysis = ('verb', word) sentence .append (analysis) alif word in stop: analysis = ('stop', word) sentence.append (analysis) elif word noun: analysis = ("Noun", word) sentence.append (analysis) Other: value = numc Onv (word) if value! = None: Analysis = Value Sentence. Append (Analysis) Other: Analysis = ('Error', word) Sentence. Append (Analysis) Return Sentence string = raw_input ("Type your sentence here:") Sentlist = scan (string) print sentlist

And here I have the code for the module imported into the code above:

  class numconv (object): def __init __ (Self, s): self.s = s def Convert_number (self, s): try: self.value = int (s) return ("number", self.value) except valueError: return no one   

thing That is, I have worked to work out its original framework in another format. In that format, I did not declare sections and the files from the files to run the scanner did not just call all the above mentioned things in the "Scan" and "Nankon" sections as modules. But I'm trying to convert it into "class" format, and I'm trying to call the scanner as an example of "scan" classes. And so far, instead of gaining the list of (TYPE, WORD) TUPS, I just put that main object back. Object object as return value. If someone can be very kind, can they explain why I went wrong in trying to convert it into a format, and why only me " main .can object" Returned value in the form when I try to call a square class with a user input string? Thank you.

In your use of class:

  sentlist = scan (string ) Print list;   

You are making an example of class and are printing it. Instead, I believe you want to call the scanner member function:

  mySring = "somestring"; // declares a string s = scanned (myString); // makes an example of a class, finds the string as Arg sillylist = s.scanner (); // function runs the scanner, returning output    

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -