Thursday 15 August 2013

Does this code correctly identify python strings -


I have some code that I think should return all the parts of a dragon statement that are not in the string. However, I am not sure as much as the harsh I want. Basically, it only finds the next string delimiter and stays in the "string" position until it is closed by the same delimiter. Did I do anything wrong for something strange that I did not think? Will anyway be incompatible with the dragon? In order of precedence, # string delimiter string_delims = ['' '', '', '', '', '', '' '] #A statement without a def def Get _get_non_string (text): out = "state = none true: # not in string if state == none: vals = [string_delims in [text.find (s) for s # if only For valve-1 (i.e. no substring), there will be no difference in the zip (wal + [none], string_dialize + [none]): if val == none: out + = return the text if the wall & Gt; = 0: i = val = Destroy break = = text [: i] text = text [i + len (delim):] else: i = text.find (state) if i & lt; 0: increase syntax error ("cyobolic subsystem: eol Examples input:

  get_non_string ("hello") "text" string "string" string = text [i + len (delim)] stat = none   

/ Pre>

Python can detect Python code:

  import import token To chop the imports Import to IO import store class token (collections.nametuple ('Token', 'num val start end line')): @property def name (auto): return token.tok_name [self.num] def get_non_string (text): Result = [] tokenize.generate_tokens (io.BytesIO (text).) For token: token = token (* tok) # print (tok.name, tok.val) if tok.name! = 'STRING': Results .append (tok.val) return '' .join (results) print (get_non_string ("hello" 'everybody' '' :) '' ''))   

The yield

  Hello!   

Heavy weight lifting is done by.

No comments:

Post a Comment