Error opening pages with python [closed] - python

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I am trying to open websites in python. Lets cut to the chase.
import webbrowser
webbrowser.open('http://google.com')
(my code)
Traceback (most recent call last):
File "C:\Python27\webbrowser.py", line 1, in <module>
import webbrowser
File "C:\Python27\webbrowser.py", line 3, in <module>
webbrowser.open('http://google.com')
AttributeError: 'module' object has no attribute 'open'
PS C:\Users\ug>
(my error)
What did I do wrong?

import webbrowser
alink = 'http://eample.com'
new = 2
webbrowser.open(alink, new=new)
If this doesn't work, run this and post the output: dir(webbrowser)
webbrowser.py is the same name as the import module. Try renaming the file to wbrowser.py and see if this helps.

To summarize and clarify the comments:
Rename C:\Python27\webbrowser.py to webbrowser_test.py
Delete C:\Python27\webbrowser.pyc and C:\Python27\webbrowser.pyo
Run python webbrowser_test.py and you should get the desired results.

Related

Error on python - TypeError: 'str' object is not callable [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 months ago.
Improve this question
I'm starting to code right now, but I've searched on google and found an answer: I know the problem is a variable that is already predefined in python that needs to be renamed, but I can't find it. Can someone help me?
import os
import pandas as pd
lista_arquivo = os.listdir(fr"C:\Users\Master\Desktop\cursos\projetos\PYTHON\Faturamento_AM")
print(lista_arquivo)
tabela_total = pd.DataFrame()
for arquivo in lista_arquivo:
if "abril.xlsx" in arquivo():
tabela = pd.read_excel(fr"C:\Users\Master\Desktop\cursos\projetos\PYTHON\Faturamento_AM\{arquivo}")
tabela_total = tabela_total.append(tabela)
print(arquivo)
print(tabela_total)
tabela_faturamento = tabela_total.groupby('Faturamento').sum()
print(tabela_faturamento)
TypeError: 'str' object is not callable
I tried renaming the file, putting 'r', 'f' before the directory path, putting {file} at the end of the directory path...
you have a typo in
if "abril.xlsx" in arquivo():
it should be:
if "abril.xlsx" in arquivo:
When you are adding () to the variable name it is trying to "call" it - execute as a function, but it is string, that's why you're getting error

Why am i getting "NameError: name 'bs4' is not defined" error while trying to import BeautifulSoup? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
> soup=bs4.BeautifulSoup(r.Text, "xml")
Traceback (most recent call last):
File "<ipython-input-14-ad3307f493a7>", line 1, in <module>
soup=bs4.BeautifulSoup(r.Text, "xml")
**NameError: name 'bs4' is not defined**
How can i fix this problem? I'm trying to make an application with BeautifulSoup.
You have to import bs4 first (assuming you have installed bs4), i.e.
> import bs4
> soup=bs4.BeautifulSoup(r.Text, "xml")
your code should be like this
import bs4
soup=bs4.BeautifulSoup(r.Text, "xml")

'NoneType' object is not callable when I learn web scraping [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I'm a new web scraping coder.
My code is this:
from urllib2 import urlopen
from bs4 import BeautifulSoup
html=urlopen("http://www.pythonscraping.com/pages/warandpeace.html")
bsObj=BeautifulSoup(html,"html.parser")
namelist=bsObj.findall("span",{"class":"green"})
for name in namelist:
print(name.get_text())
And the console is this:
Traceback (most recent call last): File "F:\Eclipseworkspace\PythonLearn1_12\src\Test1\__init__.py", line 5, in <module>
namelist=bsObj.findall("span",{"class":"green"}) TypeError: 'NoneType' object is not callable
I think you simply made a typo, findAll is with a uppercase A or you can use find_all (with underscore) which is actually the method one should use in bs4.
The reason you get this error is because a BeautifulSoup object will treat generic attributes (attributes not part of the dir(..) as find-requests). If the query is not found, it returns None for every queried attribute that is not specified.
>>> repr(bsObj.findall)
'None'
so now you call (bsObj.findall(..)) on a None object and that will not work.
namelist=bsObj.find_all("span",{"class":"green"})
Old Version: findAll
New Version: find_all
Wrong Version: findall

What's the error mean for `$in` in Pymongo? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
for element in self.table1.find({'ji': {'$ne': ""}}):
gongLiNian = int(element['gongLiNian'])
gongLiNianScope = [str(gongLiNian-1), str(gongLiNian), str(gongLiNian+1)]
res = self.table2.find_one({'guanZhi' : element['guanZhi'],
'gongLiNian' : {'$in', gongLiNianScope},
'name' : element['name']})
For this code, here is the error:
Traceback (most recent call last):
File "C:\Users\elqstux\Desktop\study\History\oneJi.py", line 172, in <module>
oneJi.run()
File "C:\Users\elqstux\Desktop\study\History\oneJi.py", line 158, in run
res1 = self.step1()
File "C:\Users\elqstux\Desktop\study\History\oneJi.py", line 44, in step1
'gongLiNian' : {'$in', gongLiNianScope},
TypeError: unhashable type: 'list'
But i can't find any clue from the error.Could you give me some advise?
See the comma here:
{'$in', gongLiNianScope}
that is a syntax to initialize a set and you can put only hashable data types into a set.
Instead, you meant to have a dictionary:
{'$in': gongLiNianScope}

What is wrong with this extremely simple numpy script? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I run the following in Python 2.7
import numpy
a = numpy.ndarray(shape=(2,2), dtype=float, order='F')
print numpy.mean(a)
numpy.savetext('foo.txt', a)
and get this result
[me#foo bar]$ python f.py
8.79658981512e-317
Traceback (most recent call last):
File "f.py", line 4, in <module>
numpy.savetext('foo.txt', a)
AttributeError: 'module' object has no attribute 'savetext'
What's wrong?
It's numpy.savetxt, without the e.

Categories

Resources