仅限Windows上的python

编程入门 行业动态 更新时间:2024-10-27 00:27:42
仅限Windows上的python __init__错误(python __init__ error on Windows only)

我对python很新...

import sys, os, time, py4chan, urllib from urllib2 import urlopen, URLError, HTTPError def refreshthread(boardin,no): global thread global topic board = py4chan.Board(boardin) thread = board.getThread(int(no)) topic = thread.topic time.sleep(2.5) def dlfile(url, folder): try: f = urlopen(url) with open(folder + "/" + os.path.basename(url), "wb") as local_file: local_file.write(f.read()) print "Downloaded to " + str(folder + "/" + os.path.basename(url)) except HTTPError, e: print "HTTP Error:", e.code, url except URLError, e: print "URL Error:", e.reason, url def getsize(uri): file = urllib.urlopen(uri) size = file.headers.get("content-length") file.close() return str(int(size) / 1024) def main(): boardtag = str(raw_input("Board: ")) threadno = int(raw_input("Thread id: ")) folder = str(raw_input("Save to folder: ")) print "Getting thread information..." refreshthread(boardtag,threadno) print "Subject: " + topic.Subject while(True): if not os.path.exists(folder): os.makedirs(folder) refreshthread(boardtag,threadno) for imgurl in thread.Files(): if imgurl is not None and not os.path.exists(folder + "/" + os.path.basename(imgurl)): print "A wild image appears! " + "(" + getsize(imgurl) + "kb)" dlfile(imgurl,folder) else: pass if __name__ == '__main__': main()

我在linux上对此进行了编码并且运行得很好,但是如果我在Windows上运行它,我会收到此错误:

TypeError: __init__() takes exactly 4 arguments (2 given)

这很奇怪,因为我还没有定义init 。 这可能是另一个模块的init吗?

如果我编写其他脚本,py4chan模块似乎工作正常。 两台机器也有相同的python版本。

编辑 (完整错误):

Getting thread information... Traceback (most recent call last): File "4chan.py", line 59, in <module> main() File "4chan.py", line 46, in main refreshthread(boardtag,threadno) File "4chan.py", line 15, in refreshthread board = py4chan.Board(boardin) TypeError: __init__() takes exactly 4 arguments (2 given)

* 编辑: *好的,我有两个不同的同名模块。 一切正常。 我不应该被允许进入这个网站。

I am quite new to python...

import sys, os, time, py4chan, urllib from urllib2 import urlopen, URLError, HTTPError def refreshthread(boardin,no): global thread global topic board = py4chan.Board(boardin) thread = board.getThread(int(no)) topic = thread.topic time.sleep(2.5) def dlfile(url, folder): try: f = urlopen(url) with open(folder + "/" + os.path.basename(url), "wb") as local_file: local_file.write(f.read()) print "Downloaded to " + str(folder + "/" + os.path.basename(url)) except HTTPError, e: print "HTTP Error:", e.code, url except URLError, e: print "URL Error:", e.reason, url def getsize(uri): file = urllib.urlopen(uri) size = file.headers.get("content-length") file.close() return str(int(size) / 1024) def main(): boardtag = str(raw_input("Board: ")) threadno = int(raw_input("Thread id: ")) folder = str(raw_input("Save to folder: ")) print "Getting thread information..." refreshthread(boardtag,threadno) print "Subject: " + topic.Subject while(True): if not os.path.exists(folder): os.makedirs(folder) refreshthread(boardtag,threadno) for imgurl in thread.Files(): if imgurl is not None and not os.path.exists(folder + "/" + os.path.basename(imgurl)): print "A wild image appears! " + "(" + getsize(imgurl) + "kb)" dlfile(imgurl,folder) else: pass if __name__ == '__main__': main()

I coded this on linux and it runs perfectly, but if I run this on windows, I get this error:

TypeError: __init__() takes exactly 4 arguments (2 given)

Which is quite strange as I haven't defined init. Could this be an init from another module?

The py4chan module seems to work fine if i code other scripts. Both machines have same python version too.

EDIT(Full error):

Getting thread information... Traceback (most recent call last): File "4chan.py", line 59, in <module> main() File "4chan.py", line 46, in main refreshthread(boardtag,threadno) File "4chan.py", line 15, in refreshthread board = py4chan.Board(boardin) TypeError: __init__() takes exactly 4 arguments (2 given)

*Edit:*Okay, i had two different modules of the same name. All working now. I shouldn't be allowed on this website.

最满意答案

py4chan.Board类需要用3个参数构造,而不是1. refreshthread函数中的这一行:

board = py4chan.Board(boardin)

应该看看这个:

board = py4chan.Board(base_url, post_url, filesize)

The py4chan.Board class needs to be constructed with 3 arguments, not 1. This line in the refreshthread function:

board = py4chan.Board(boardin)

Should look something this:

board = py4chan.Board(base_url, post_url, filesize)

更多推荐

本文发布于:2023-08-07 23:06:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1466143.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:仅限   Windows   python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!