GithubHelp home page GithubHelp logo

Problem with Python3.2 about howdoi HOT 14 CLOSED

gleitz avatar gleitz commented on June 17, 2024
Problem with Python3.2

from howdoi.

Comments (14)

gleitz avatar gleitz commented on June 17, 2024

Thanks for the bug report. What is the howdoi command you are running? I just tried the latest version from master and it appears to be working:

$ python3 howdoi/howdoi.py format date bash
DATE=`date +%Y-%m-%d`

from howdoi.

keelzebub avatar keelzebub commented on June 17, 2024

It's happening with me, too - using the command "howdoi perl join", with python verson 3.2.3

from howdoi.

gleitz avatar gleitz commented on June 17, 2024

Aha. I am using Python 3.3. Let me see if I can install Python 3.2 and figure out what the issue is...

from howdoi.

gleitz avatar gleitz commented on June 17, 2024

I'm guessing this is the issue

Unicode literals causing invalid syntax

from howdoi.

gleitz avatar gleitz commented on June 17, 2024

I believe the following steps will fix the issue:

  • Please change all instances of u"foo" to "foo"
  • Put this at the top of the file: from __future__ import unicode_literals

Please let me know if that works for you and I'll add it to the main codebase.

from howdoi.

gleitz avatar gleitz commented on June 17, 2024

And here is why I was not seeing an issue with Python 3.3 but you do in 3.2

http://www.python.org/dev/peps/pep-0414/

from howdoi.

kensington avatar kensington commented on June 17, 2024

Sorry, I should have mentioned originally that Python3.3 did work fine. With the changes suggested above it's working with Python3.2.

from howdoi.

gleitz avatar gleitz commented on June 17, 2024

Perfect. Thanks for your help! I'll check in the changes and do a point release

from howdoi.

gleitz avatar gleitz commented on June 17, 2024

When I added from __future__ import unicode_literals I got the following error in Python2. Seems to be an issue with lxml (used by PyQuery)

$ python howdoi/howdoi.py get this to work in python3
Traceback (most recent call last):
  File "howdoi/howdoi.py", line 168, in <module>
    command_line_runner()
  File "howdoi/howdoi.py", line 165, in command_line_runner
    print(howdoi(args))
  File "howdoi/howdoi.py", line 142, in howdoi
    return get_instructions(args) or 'Sorry, couldn\'t find any help with that topic\n'
  File "howdoi/howdoi.py", line 120, in get_instructions
    links = get_links(args['query'])
  File "howdoi/howdoi.py", line 48, in get_links
    return [a.attrib['href'] for a in html('.l')]
  File "lxml.etree.pyx", line 2261, in lxml.etree._Attrib.__getitem__ (src/lxml/lxml.etree.c:53908)
KeyError: u'href'

However it turns out I don't need Unicode strings at all so I just removed all the references to u'foo'. I've merged the changes into the master branch and have updated pypi. Please let me know if you see any other issues.

from howdoi.

dnatag avatar dnatag commented on June 17, 2024

It seems Python 2.7 do need u'...', otherwise, you will get UnicodeEncodeError.
Try this query: howdoi.py -n3 python unittest
I got:
Traceback (most recent call last):
File "howdoi.py", line 166, in
command_line_runner()
File "howdoi.py", line 163, in command_line_runner
print(howdoi(args))
File "howdoi.py", line 140, in howdoi
return get_instructions(args) or 'Sorry, couldn't find any help with that topic\n'
File "howdoi.py", line 131, in get_instructions
answer = ANSWER_HEADER.format(current_position, answer)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' in position 350: ordinal not in range(128)

from howdoi.

kensington avatar kensington commented on June 17, 2024

Cannot reproduce previous comment with Python 2.7 and howdoi 1.1.2

from howdoi.

gleitz avatar gleitz commented on June 17, 2024

I'm having difficulty as well. Would to please provide an example that
breaks?
On Mar 22, 2013 10:44 AM, "kensington" [email protected] wrote:

Cannot reproduce previous comment with Python 2.7 and howdoi 1.1.2


Reply to this email directly or view it on GitHubhttps://github.com//issues/52#issuecomment-15307558
.

from howdoi.

dnatag avatar dnatag commented on June 17, 2024

Here is the query and I am using latest git copy of howdoi.py. Not sure the version number.
howdoi -n 3 python unittest

from howdoi.

gleitz avatar gleitz commented on June 17, 2024

Thanks for pointing out the issue, @dnatag. I've submitted a fix to the master branch as well as a test for this error.

Please let me know if you run into any more issues.

from howdoi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.