Tadzio
(usa Linux Mint)
Enviado em 04/11/2013 - 23:24h
você conseguirá entender tudo se ler a documentação. não tem quase nada de python (programação) aí.
b = len(re.sub('\D', '', sys.argv[-1]))
sys.argv[-1])
último argumento ('D=400')
das expressões regulares:
re.sub(pattern, repl, string, count=0, flags=0)
Return the string obtained by replacing the leftmost non-overlapping occurrences of pattern in string by the replacement repl. If the pattern isn’t found, string is returned unchanged. repl can be a string or a function; if it is a string, any backslash escapes in it are processed. That is, \n is converted to a single newline character, \r is converted to a carriage return, and so forth. Unknown escapes such as \j are left alone. Backreferences, such as \6, are replaced with the substring matched by group 6 in the pattern.
\D
When the UNICODE flag is not specified, matches any non-digit character; this is equivalent to the set [^0-9]. With UNICODE, it will match anything other than character marked as digits in the Unicode character properties database.
sugiro que você experimente para realmente entender o que cada opção faz:
#b = len(re.sub('\D', '', sys.argv[-1]))
print sys.argv
print sys.argv[-1]
print sys.argv[0]
print sys.argv[1]
print re.sub('\D', '', sys.argv[-1])
print re.sub('\D', '1', sys.argv[-1])
print re.sub('\d', '', sys.argv[-1])
print re.sub('\d', '1', sys.argv[-1])
print len(re.sub('\D', '', sys.argv[-1]))
print len(re.sub('\d', '', sys.argv[-1]))
e assim por diante...