Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python3 error #1

Closed
finlay-liu opened this issue Nov 11, 2016 · 1 comment
Closed

python3 error #1

finlay-liu opened this issue Nov 11, 2016 · 1 comment

Comments

@finlay-liu
Copy link

when use in py3 there is a import error.

Python 3.5.2 (default, Sep 10 2016, 08:21:44)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pullword
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.5/dist-packages/pullword/__init__.py", line 3, in <module>
    from pullword import pullword
  File "/usr/local/lib/python3.5/dist-packages/pullword/pullword.py", line 25
    print pw.url
           ^
SyntaxError: Missing parentheses in call to 'print'
>>> quit()

then fix the import bug, then i find i cannot use the the method:

lyz@~$ python3
Python 3.5.2 (default, Sep 10 2016, 08:21:44)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pullword import pullword
>>> word_list = pullword(u"华中科技大学", threshold=0.7)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'module' object is not callable
>>> word_list = pullword("华中科技大学", threshold=0.7)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'module' object is not callable
@ccx1997
Copy link

ccx1997 commented Apr 28, 2019

To use the api in python3, you can replace the vanilla pullword.py content with the following code:

import requests
post_url = "http://api.pullword.com/post.php"

class ServerError(Exception):
     def __init__(self, value):
         self.value = value
     def __str__(self):
         return repr(self.value)

def split_word(words):
    words = words.split()
    words_list = []
    for i in words:
        if len(i) == 0:
            continue
        words_list.append(i.split(":"))
    return words_list


def pullword(source="", threshold=0, debug=1):
    payload = {"source":source, "param1":threshold, "param2":debug}
    pw = requests.post(post_url, data=payload)
    print(pw.url)
    if pw.status_code != 200:
        raise ServerError("server return %s"%pw.status_code)
    words = pw.content.decode()
    print(words)
    return split_word(words)

Then you can do like the following demo:

from pullword.pullword import pullword
res = pullword(u'其实我天生奔放贪玩', debug=1, threshold=0.7)
print(res)

So everything is OK!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants