Questions tagged «python-3.x»

对于特定于该语言版本3+的有关Python编程的问题。如果您的问题不是特定于版本的,则使用更通用的[python]标记。将[python-2.x]标记用于Python 2问题。

2
Python 3在线解释器/ Shell
从目前的情况来看,这个问题不适合我们的问答形式。我们希望答案会得到事实,参考或专业知识的支持,但是这个问题可能会引起辩论,争论,民意测验或进一步的讨论。如果您认为此问题可以解决并且可以重新提出,请访问帮助中心以获取指导。 8年前关闭。 是否有使用Python 3 的在线解释器,例如http://codepad.org/或http://www.trypython.org/? 回答 由于问题已经结束,因此我在这里给出另一个答案。 Wandbox提供了多种语言的在线REPL,包括Python 2.x和3.x,C ++和Java。


3
“模块”没有属性“ urlencode”
当我尝试遵循与URL编码相关的Python Wiki的示例时: >>> import urllib >>> params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0}) >>> f = urllib.urlopen("http://www.musi-cal.com/cgi-bin/query", params) >>> print f.read() 在第二行引发错误: Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'module' object has no attribute 'urlencode' 我想念什么?

11
FutureWarning:逐元素比较失败;返回标量,但将来将执行元素比较
我0.19.1在Python 3上使用Pandas 。我在这些代码行上收到警告。我正在尝试获取一个包含所有Peter在column处存在string的行号的列表Unnamed: 5。 df = pd.read_excel(xls_path) myRows = df[df['Unnamed: 5'] == 'Peter'].index.tolist() 它产生一个警告: "\Python36\lib\site-packages\pandas\core\ops.py:792: FutureWarning: elementwise comparison failed; returning scalar, but in the future will perform elementwise comparison result = getattr(x, name)(y)" 这是什么FutureFarning,由于它似乎起作用,因此我应该忽略它。

2
python字符串前的a前缀是什么意思?
在python源代码中,我偶然发现在类似如下的字符串之前看到一个小b: b"abcdef" 我知道u表示unicode字符串的r前缀和原始字符串文字的前缀。 b它看起来像一个没有任何前缀的纯字符串,它代表什么?在哪种源代码中有用?

2
TypeError:无法在re.findall()中的类似字节的对象上使用字符串模式
我正在尝试学习如何自动从页面获取URL。在下面的代码中,我试图获取网页的标题: import urllib.request import re url = "http://www.google.com" regex = r'<title>(,+?)</title>' pattern = re.compile(regex) with urllib.request.urlopen(url) as response: html = response.read() title = re.findall(pattern, html) print(title) 我得到这个意外的错误: Traceback (most recent call last): File "path\to\file\Crawler.py", line 11, in <module> title = re.findall(pattern, html) File "C:\Python33\lib\re.py", line 201, in findall return _compile(pattern, …

13
ImportError:没有名为“编码”的模块
我最近重新安装了ubuntu并升级到16.04,无法使用python: $ python manage.py runserver Could not find platform independent libraries <prefix> Could not find platform dependent libraries <exec_prefix> Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] Fatal Python error: Py_Initialize: Unable to get the locale encoding ImportError: No module named 'encodings' Aborted 在这一点上,python本身不起作用 $ python Could not find platform independent libraries <prefix> …




1
这种奇怪的结肠行为在做什么?
我正在使用Python 3.6.1,遇到了一些非常奇怪的事情。我有一个简单的字典作业错字,花了很长时间才找到。 context = {} context["a"]: 2 print(context) 输出量 {} 代码context["a"]: 2在做什么?SyntaxErrorIMO应该什么时候都没有提出。起初,我认为它正在创建一个切片。但是,键入repr(context["a"]: 2)会引发SyntaxError。我也输入context["a"]: 2了控制台,但控制台没有打印任何内容。我以为也许它回来了None,但是我不太确定。 我还认为它可能是if语句的一行,但这也不应该是正确的语法。 此外,context["a"]应提出一个KeyError。 我很困惑。到底是怎么回事?
104 python  python-3.x 

6
'dict'对象没有属性'has_key'
在Python中遍历图形时,我收到此错误: 'dict'对象没有属性'has_key' 这是我的代码: def find_path(graph, start, end, path=[]): path = path + [start] if start == end: return path if not graph.has_key(start): return None for node in graph[start]: if node not in path: newpath = find_path(graph, node, end, path) if newpath: return newpath return None 该代码旨在查找从一个节点到另一节点的路径。代码源:http : //cs.mwsu.edu/~terry/courses/4883/lectures/graphs.html 为什么会出现此错误,我该如何解决?




By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.