googlefinance python3 error - python-3.x

Hi guys I'm using python3 and install googlefinace module(https://pypi.python.org/pypi/googlefinance) and the example says it's works
>>> from googlefinance import getQuotes
>>> import json
>>> print json.dumps(getQuotes('AAPL'), indent=2)
but I type this code using my terminal access python3
>>> from googlefinance import getQuotes
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/googlefinance/__init__.py", line 55
print "url: ", url
^
SyntaxError: Missing parentheses in call to 'print'
so what's the problem please help me

In python3 print syntax contains parenthesis. There for it is giving you syntax error. Use correct print syntax. print (url)

Related

How can I execute python module on Python3 if I encountered print without parants

I want to launch pybrain tests on Python3 but I get error:
Traceback (most recent call last):
File "runtests.py", line 107, in <module>
runner.run(make_test_suite())
File "runtests.py", line 72, in make_test_suite
test_package = __import__(test_package_path, fromlist=module_names)
File "B:\msys64\mingw64\bin\WinPython\Python373\lib\site-packages\pybrain\tests\__init__.py", line 1, in <module>
from helpers import gradientCheck, buildAppropriateDataset, xmlInvariance, \
File "B:\msys64\mingw64\bin\WinPython\Python373\Lib\site-packages\pybrain\tests\helpers.py", line 42
print 'Module has no parameters'
^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print('Module has no parameters')?
I looked helpers.py and found that prints are without parents(as operators, I think it was in Python2).How can I fix that?Can I import some module to
execute with such problem, for example six, but I don t know what it does.

Simple function won't run, beginner coder at work

I'm learning Python and it's early days for me. The following small bit of code won't run, the error message is
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'logdata' is not defined
The file is called "logdata.py". The faulty(?) code is;
def logthis(addme):
f=open("log.txt", "a+")
f.write(addme)
f.close()
logthis('teststring')
If there is a better place for a basic question like this please let me know, I'm sure i'll have plenty more to come as i learn Python, thanks!
I think, you have some extra lines of code in beginning of file which uses undefined identifier (variable, function etc.) with name logdata. Something like this.
>>> def f():
... print(logdata)
...
>>> f()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 2, in f
NameError: name 'logdata' is not defined
>>>
If so, just define/initialize that. Finally, your code will work fine then as I have already tested it as follows.
>>> def logthis(addme):
... f = open("log.txt", "a+")
... f.write(addme)
... f.close()
...
>>> logthis('teststring')
>>>
>>> # Read the newly created file content
...
>>> f = open("log.txt", "r")
>>> f.read()
'teststring'
>>>

undefined unicode in python3

I am trying to follow scrapy docs in scrapy (python3)
using scrapy shell "any_website"
from scrapy.loader.processors import MapCompose, Join
MapCompose(unicode.strip)([u' I',u' am\n'])
I am getting this error `Traceback (most recent call last):
File "/usr/lib/python3.6/code.py", line 91, in runcode
exec(code, self.locals)
File "<console>", line 1, in <module>
NameError: name 'unicode' is not defined
`
this is affecting my scrapy Item Loader when I use (same error happens)
l = ItemLoader(item=PropertiesItem(), response=response)
l.add_xpath('title', '//*[#itemprop="name"][1]/text()',MapCompose(unicode.strip, unicode.title))
the example on the scrapy docs is pretty straightforward but I am getting this error is it because I use python3 ?
in python2.x:
item = unicode(item, 'utf-8')
in python3.x:
item = str(item.encode('utf-8'))
Python 3 renamed the unicode type to str, the old str type has been replaced by bytes
renaming unicode occurrences with str will worked

Why import of regular expressions falling a traceback error?

Having assignment "Extracting Data With Regular Expressions". For this I'm importing regex, but the code is not working. what is my mistake?
I checked the code without "import", it does work. Lines 2-7 are working. But it got a traceback error on "import re" line 1.
import re
fname = input('Enter file: ')
if len(fname) < 1 : fname = "sample.txt"
hand = open(fname)
hd = hand.read()
for line in hand:
line = line.rstrip()
nm = re.findall('[0-9]+',line)
print(nm)
C:\Users\Desktop\new>re.py
Enter file:
Traceback (most recent call last):
File "C:\Users\Desktop\new\re.py", line 1, in <module>
import re
File "C:\Users\Desktop\new\re.py", line 9, in <module>
[enter image description here][1]nm = re.findall('[0-9]+',line)
AttributeError: module 're' has no attribute 'findall'
Because you have called your file re.py, the import will actually import this file instead of the built-in module for regular expressions.
Just rename your file to something different and it should work as expected.

%s error when trying to put a variable into a string python

Trying to build a "launcher" type thing for youtube-dl(program that lets you download youtube videos), and getting an error. I understand what the error means but it makes no sense as I am(I think) doing exactly what python wants.
This is my code:
import os
import sys
x = input('Enter link for youtube Video you would like to download: ')
ytdp = open('C:\\Games\\ytdp.bat', 'w')
ytdp.write('cd C:\\Users\Jake\Music')
ytdp.write('\n')
ytdp.write('youtube-dl %s')% (x)
ytdp.close()
os.startfile('C:\\Games\ytdp.bat')
sys.exit()
This is the error I get when running the code
Traceback (most recent call last):
File "C:\Users\Jake\Desktop\Youtube video downloader.py", line 8, in <module>
ytdp.write('youtube-dl %s')% (xx)
TypeError: unsupported operand type(s) for %: 'int' and 'str'
ytdp.write('youtube-dl %s')% (xx)
Should be
ytdp.write('youtube-dl %s'% (xx))
Here is some more info on it

Resources