Ahoj všem,
píšu si "prográmek" a narazil jsem na subj
-----cut-----------------------
log.write(data)
pristr=log.readline()
r=re.search(r'([0-9]+)',pristr)
pristr=r.group()
-----end cut---------------------
když udělám tuto posloupnost příkazů v pythonu je vše jak má být a dosáhnu očekávaného výsledku. Ale když to pustím jako python scipt.py tak mi to vypíše:
Traceback (most recent call last):
File "server.py", line 41, in <module>
pristr=(r.group())
AttributeError: 'NoneType' object has no attribute 'group'
zkoušel jsem kolem toho googlit, ale bohužel bez úspěchu. Určitě dělám nějakou začátečnickou stupidnot :smile19: . Můžete mě někdo postrčit?
-----
Dík
Vilik13
Fórum › Python
AttributeError: 'NoneType' object has no attribute 'group'

Jednoducho sa v reťazci pristr nenašla zhoda pre daný regulárny výraz a preto ti metóda search vráti None. No a None nemá žiadnu metódu group. Preto najprv testuj r na None a zavolaj group len ak je tam platný objekt typu MatchObject.
To m->29 :
No to bych pochopil, ale proč tam není když tam má být - viz:
Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> import re
>>> log=open("scan_data.log","r",0)
>>> pristr=log.readline()
>>> print pristr
METER: 011605000029317
>>> r=re.search(r'([0-9]+)',pristr)
>>> r.group()
'011605000029317'
>>> pristr=r.group()
>>> print pristr
011605000029317
>>>
Proč to tady funguje a v programu ne? 100% je to nějaká blbost kterou si neuvědomuji...
To vilik13 : V tom tvém výřezu děláš
log.write(data)
Kde je potom čtecí hlava?
Přidej příspěvek
Ano, opravdu chci reagovat → zobrazí formulář pro přidání příspěvku
×Vložení zdrojáku
×Vložení obrázku
×Vložení videa
































Uživatelé prohlížející si toto vlákno
Podobná vlákna
AttributeError: 'NoneType' object has no attribute 'group' — založil vilik13
AttributeError: 'gtk.DrawingArea' object has no attribute 'draw_rect… — založil Matěj Andrle
Object reference not set to an instance of an object. — založil whysper
Failed to find premain-class manifest attribute in — založil lIIIxxxIIIl
GROUP BY vs. ORDER BY — založil tobik
Moderátoři diskuze