![]() |
![]() ![]() |
![]() |
![]()
Post
#1
|
|
Grupa: Zarejestrowani Postów: 21 Pomógł: 0 Dołączył: 5.02.2007 Ostrzeżenie: (0%) ![]() ![]() |
Kawałek kodu skryptu:
Kod def phpbb2_posts(): '''Create table phpbb2_posts''' mybb_posts = open_dump('posts') phpbb2_posts = list() enable_bbcode = 1 enable_html = 0 enable_smilies = 1 enable_sig = 1 post_edit_time = 'NULL' post_edit_count = 0 #We need to get the ID of the newest topic newest_topic = 1 for row in xrange(len(mybb_posts)): post_id = int(mybb_posts[row][0]) #pid topic_id = int(mybb_posts[row][1]) #tid forum_id = int(mybb_posts[row][3]) #fid poster_id = int(mybb_posts[row][6]) #uid post_time = int(mybb_posts[row][8]) #dateline poster_ip = mybb_posts[row][10].rstrip("'").lstrip("'") #ipaddress #poster_ip must be hex string_end = len(poster_ip) start = 0 string_hex = '' for number_block in xrange(4): end = poster_ip.find('.', start, string_end) #Last number block of the ip address (XXX.XXX.XXX.XXX) if number_block == 3: end = string_end number = int(poster_ip[start:end]) //tutaj wypada 305 linja start = end + 1 hexnumber = "%x" %number if len(hexnumber) == 1: hexnumber = '0' + hexnumber string_hex += str(hexnumber) poster_ip = "'" + string_hex + "'" post_username = mybb_posts[row][7] #username phpbb2_posts.append((post_id, topic_id, forum_id, poster_id, post_time, poster_ip, post_username, enable_bbcode, enable_html,enable_smilies, enable_sig, post_edit_time, post_edit_count)) if topic_id > newest_topic: newest_topic = topic_id columns_names = ('post_id', 'topic_id', 'forum_id', 'poster_id', 'post_time','poster_ip', 'post_username', 'enable_bbcode', 'enable_html', 'enable_smilies', 'enable_sig', 'post_edit_time', 'post_edit_count') #We need the the ID of the last post of each topic topic_last_post_id_list = list() #Now this is a bad solution, I guess #We create a list with newest_topic elements for i in xrange(newest_topic + 1): topic_last_post_id_list += ["''"] for row in xrange(len(phpbb2_posts)): #phpbb2_posts[row][1] is the thread number #phpbb2_posts[row][0] is the post number topic_last_post_id_list[phpbb2_posts[row][1]] = phpbb2_posts[row][0] return phpbb2_posts, columns_names, topic_last_post_id_list Błąd(zaznaczylem wam w kodzie u góry która to 305linja): Cytat Traceback (most recent call last): File "C:\skrypt.py", line 897, in <module> phpbb2_posts() File "C:\skrypt.py", line 305, in phpbb2_posts number = int(poster_ip[start:end]) ValueError: invalid literal for int() with base 10: '' Z uwagi że nigdy nie zagłebiałem się w ten język może mi ktoś powiedzieć co tutaj jest nie tak ? Ten post edytował Grzesiek1 13.11.2007, 17:06:21 |
|
|
![]()
Post
#2
|
|
![]() Grupa: Zarejestrowani Postów: 866 Pomógł: 32 Dołączył: 2.06.2004 Skąd: Wrocław Ostrzeżenie: (0%) ![]() ![]() |
Google wie więcej
![]() int(x) w pythonie zmienia "x" (string najcześciej) na liczbę typu integer. number = int(poster_ip[start:end]) "number" to jest nazwa zmiennej która ma przechowywać to czym jest "poster_ip[start:end]" ale w postaci liczby nie zaś np. stringu (ciągu znaków). Error zaś mówi że "poster_ip[start:end]" nie składa się ze znaków z zakresu 0-9 więc nie może zmienić tego na liczbę. poster_ip = mybb_posts[row][10].rstrip("'").lstrip("'") #ipaddress zmienna poster_ip to chyba jakaś wartość wyciągnięta z bazy danych na 99% sądząc po komentarzu jest adres IP rstrip i lstrip to są funkcje które usuwają dany znak z prawej i lewej strony danego ciągu znaków, w tym wypadku apostrof "'" Moim zdaniem problem leży w tym że są jakieś śmieci w zmiennej poster_ip zamiast tego co powinno być, ale nie powiem Ci nic więcej, bo kod nie ma wcięć które powinien mieć jeśli to Python a mi się nie chce domyślać co gdzie i jak ![]() Ten post edytował sztosz 12.11.2007, 21:13:50 -------------------- |
|
|
![]()
Post
#3
|
|
Grupa: Zarejestrowani Postów: 21 Pomógł: 0 Dołączył: 5.02.2007 Ostrzeżenie: (0%) ![]() ![]() |
Jak by ktos był ciekaw co było źle to chodziło o cudzysłowia w pliku na którym operowała ta funkcja, poprawiłem i działa.
|
|
|
![]() ![]() |
![]() |
Aktualny czas: 21.08.2025 - 08:40 |