[Tutor] Python twitter "errors":[{"message":"Could not authenticate you", "code":32
Dear All, I'm trying to execute the examples from https://github.com/sixohsix/twitter with the current library version installed by pip install (1.14.3). #!/usr/bin/env python # -- coding: utf-8 -- from twitter import * con_secret='DACs' # "Consumer Secret" con_secret_key='jold' # "Consumer Key" token='2554' # "Access token" token_key='HHSD' # "Access Token Secret" t = Twitter( auth=OAuth(token, token_key, con_secret, con_secret_key)) t.statuses.user_timeline(screen_name="RenateBergmann") The reply is: twitter.api.TwitterHTTPError: Twitter sent status 401 for URL: 1.1/statuses/user_timeline.json using parameters: (oauth_consumer_key=DA...&oauth_nonce=...&oauth_signature_method=HMAC-SHA1&oauth_timestamp=&oauth_token=&oauth_version=1.0&screen_name=RenateBergmann&oauth_signature=..) details: {"errors":[{"message":"Could not authenticate you","code":32}]} What's the issue? Have I used the right tokens and keys? The labeling in the script is a bit different from the Twitter api page. Is Python 2.7 the proper version? The documentation said 2.6, but someone told me I had to use 2.7. Is the authentication method correct? It should be, because this is an example from the Github readme. I'm a beginner, so maybe it's only a slight mistake? Thank you in advance. -- Christian ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python twitter "errors":[{"message":"Could not authenticate you", "code":32
On 08/08/14 05:57, Chris wrote: I'm trying to execute the examples from https://github.com/sixohsix/twitter with the current library version installed by pip install (1.14.3). Since this list is for the core language and standard library this is a bit off list. You might get more response direct from the author or a twitter specific mailing list(if one exists). Failing that maybe the main Python list. However... con_secret='DACs' # "Consumer Secret" con_secret_key='jold' # "Consumer Key" token='2554' # "Access token" token_key='HHSD' # "Access Token Secret" Example code often uses fictitious security keys. Are you sure these values are genuine values that work if you use them to access twitter directly? t = Twitter( auth=OAuth(token, token_key, con_secret, con_secret_key)) t.statuses.user_timeline(screen_name="RenateBergmann") The reply is: twitter.api.TwitterHTTPError: Twitter sent status 401 for URL: 1.1/statuses/user_timeline.json using parameters: (oauth_consumer_key=DA...&oauth_nonce=...&oauth_signature_method=HMAC-SHA1&oauth_timestamp=&oauth_token=&oauth_version=1.0&screen_name=RenateBergmann&oauth_signature=..) details: {"errors":[{"message":"Could not authenticate you","code":32}]} What's the issue? Have I used the right tokens and keys? Do you mean you used the same keys as in the example? Or have you tested the keys work via some other method of access? Is Python 2.7 the proper version? The documentation said 2.6, but someone told me I had to use 2.7. I doubt the differences between 2.6 and 2.7 are your problem. Is the authentication method correct? It should be, because this is an example from the Github readme. I can't help there I know nothing about Twitter, far less its API! -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Error in get pixel value in coordinate (x, y) using getPixel(x, y)
On Thu, Aug 07, 2014 at 06:49:02PM +0700, Whees Northbee wrote: > Please help me... I'm using python 2.7.6, numpy 1.8.1, opencv 2.4.9.. > I want to get pixel value in one number like 255 not each value like these > R(190), G(23), B(45) from coordinate (x,y)... > I try these code > m_samples[k][i][j]=getPixel(img,row,col) > > But get error: > NameError: name 'getPixel' is not defined > > If I change the format become: > m_samples[k][i][j]=img.getPixel(row,col) > > Still error: > AttributeError: 'numpy.ndarray' object has no attribute 'getpixel' > > Please help me.. We cannot help you unless you help us. Where does getPixel come from? What does the documentation for it say? getPixel is not a built-in Python function, and I don't believe it is a standard numpy or opencv function (although I could be wrong). So unless you tell us where getPixel comes from, we have no possible way of telling how to use it. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Printing multi-line variables horizontally
Hello, Python novice back again. :) I'm making progress in my learning process, but struggling whenever attempting to creatively go beyond what's required in the various chapter assignments. For example, there's a simple random die roller program that looks like the following: # Craps Roller # Demonstrates random number generation import random # generate random numbers 1 - 6 die1 = random.randint(1, 6) die2 = random.randrange(6) + 1 total = die1 + die2 print("You rolled a", die1, "and a", die2, "for a total of", total) input("\n\nPress the enter key to exit.") I wanted to make it a little more interesting by using ascii art representations of the six die. When printing, however, they do so vertically and not horizontally. Here's a snippet of the code: die_1 = """ .-. | | | o | | | `-'""" die_2 = """ .-. |o| | | |o| `-'""" print(die_1, die_2) So, how would I get this to display horizontally? Like so... .-. .-. | | |o| | o | | | | | |o| `-' `-' Thanks, Greg ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Printing multi-line variables horizontally
On Fri, Aug 8, 2014 at 4:50 AM, Greg Markham wrote: > Hello, > > Python novice back again. :) I'm making progress in my learning process, > but struggling whenever attempting to creatively go beyond what's required > in the various chapter assignments. For example, there's a simple random > die roller program that looks like the following: > > > # Craps Roller > # Demonstrates random number generation > > import random > > # generate random numbers 1 - 6 > die1 = random.randint(1, 6) > die2 = random.randrange(6) + 1 > > total = die1 + die2 > > print("You rolled a", die1, "and a", die2, "for a total of", total) > > input("\n\nPress the enter key to exit.") > > > I wanted to make it a little more interesting by using ascii art > representations of the six die. When printing, however, they do so > vertically and not horizontally. Here's a snippet of the code: > > > die_1 = """ > .-. > | | > | o | > | | > `-'""" > > die_2 = """ > .-. > |o| > | | > |o| > `-'""" > > print(die_1, die_2) > > > So, how would I get this to display horizontally? > > Like so... > .-. .-. > | | |o| > | o | | | > | | |o| > `-' `-' > This isn't so easy because as you print the first die, your cursor ends up at the bottom of its display. There is a module called curses which lets you manipulate the terminal. It has functions to get the x,y position on the screen, and to set it (i. e. move the cursor). You might want to play with that. If you want to get your feet wet with unicode, you could use the dice characters (see: http://www.unicode.org/charts/PDF/U2600.pdf). >>> dice_1 = '\u2680' >>> print (dice_1) ⚀ >>> print (dice_1, dice_2) ⚀ ⚁ They are pretty small. > Thanks, > > Greg > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > -- Joel Goldstick http://joelgoldstick.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Printing multi-line variables horizontally
On 08/08/2014 01:50 AM, Greg Markham wrote: die_1 = """ .-. | | | o | | | `-'""" die_2 = """ .-. |o| | | |o| `-'""" I'll leave the cleanup as an exercise for you. HTH, Emile ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Printing multi-line variables horizontally
On 08/08/14 09:50, Greg Markham wrote: I wanted to make it a little more interesting by using ascii art representations of the six die. When printing, however, they do so vertically and not horizontally. Here's a snippet of the code: die_1 = """ .-. | | | o | | | `-'""" The triple quoted strings have newlines embedded in them. print(die_1, die_2) So, how would I get this to display horizontally? Like so... .-. .-. | | |o| | o | | | | | |o| `-' `-' You can split the strings and print each pair side by side separated by a gap. Sometjing like die_1 = """ .-. | | | o | | | `-'""".split() etc... separator = " " for index,line in enumerate(die1): print (line + separator + die2[index]) Untested, but I hope you get the idea. PS. Personally I'd keep the dies in a list(or dict) so you can access die1 as dies[0] and die2 as dies[1] The index/key is then easily determined from the roll value. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Printing multi-line variables horizontally
On Fri, Aug 8, 2014 at 1:50 AM, Greg Markham wrote: > Hello, > > Python novice back again. :) I'm making progress in my learning process, > but struggling whenever attempting to creatively go beyond what's required > in the various chapter assignments. For example, there's a simple random > die roller program that looks like the following: Hi Greg, It looks like each die has the same dimensions. What I mean is that it looks like each "die" has the same number of lines, and each line is the same width. Is that assumption correct? If so, then that might simplify matters for you. It sounds like you're trying to build a "row" of dice. To do so, you might be able to loop over the lines of both dice at once to get the composite image. That is: row[0] = die_1_lines[0] + die_2_lines[0] row[1] = die_1_lines[1] + die_2_lines[1] ... where we take horizontal slices of each dice and stick them side by side. To make this work, we need to be able to get at individual lines. To break a string into a list of lines, see https://docs.python.org/2/library/stdtypes.html#str.splitlines ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Printing multi-line variables horizontally
On 08/08/2014 18:56, Joel Goldstick wrote: On Fri, Aug 8, 2014 at 4:50 AM, Greg Markham wrote: Hello, Python novice back again. :) I'm making progress in my learning process, but struggling whenever attempting to creatively go beyond what's required in the various chapter assignments. For example, there's a simple random die roller program that looks like the following: # Craps Roller # Demonstrates random number generation import random # generate random numbers 1 - 6 die1 = random.randint(1, 6) die2 = random.randrange(6) + 1 total = die1 + die2 print("You rolled a", die1, "and a", die2, "for a total of", total) input("\n\nPress the enter key to exit.") I wanted to make it a little more interesting by using ascii art representations of the six die. When printing, however, they do so vertically and not horizontally. Here's a snippet of the code: die_1 = """ .-. | | | o | | | `-'""" die_2 = """ .-. |o| | | |o| `-'""" print(die_1, die_2) So, how would I get this to display horizontally? Like so... .-. .-. | | |o| | o | | | | | |o| `-' `-' Does this http://code.activestate.com/recipes/473893-sudoku-solver/ help at all, especially the show function right at the top? This isn't so easy because as you print the first die, your cursor ends up at the bottom of its display. There is a module called curses which lets you manipulate the terminal. It has functions to get the x,y position on the screen, and to set it (i. e. move the cursor). You might want to play with that. The Python curses module is *nix only but see this https://pypi.python.org/pypi/UniCurses/1.2 as an alternative for other platforms. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Printing multi-line variables horizontally
On 08/08/2014 10:58 AM, emile wrote: On 08/08/2014 01:50 AM, Greg Markham wrote: die_1 = """ .-. | | | o | | | `-'""" die_2 = """ .-. |o| | | |o| `-'""" Not quite sure how this part was dropped... >>> for line in zip(die_1.split("\n"),die_2.split("\n")): print line ... ('', '') ('.-.', '.-.') ('| |', '|o|') ('| o |', '| |') ('| |', '|o|') ("`-'", "`-'") I'll leave the cleanup as an exercise for you. HTH, Emile ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Pigs can fly?
Hi everyone, I'm curious if anyone has encountered: http://codegolf.stackexchange.com/questions/35623/are-pigs-able-to-fly As soon as I saw this problem, I felt strongly compelled to play with this. :P Of course, I can't show any solutions, but I thought the problem might be interesting to others here. Even without the code minimization constraints due to "code golf" I still think it's a worthwhile problem to work out. It's one of those problems that exercises multiple skills for the intermediate Python programmer, such as input/output, parsing, knowing your data structures, and writing good test cases. And it makes a good case that interesting and fun problems can be mathematical, and yet have nothing to do with basic arithmetic. What's really being asked in the problem is a graph traversal in disguise. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Printing multi-line variables horizontally
On Fri, Aug 08, 2014 at 01:50:53AM -0700, Greg Markham wrote: [...] > So, how would I get this to display horizontally? > > Like so... > .-. .-. > | | |o| > | o | | | > | | |o| > `-' `-' Nice question! I recommend that you try to solve the problem yourself, if you can, but once you've given it a good solid try, you can have a look at my solution and see if you can understand it. Feel free to ask questions as needed. S P O I L E R S P A C E . . . N O C H E A T I N G def expand(rows, width, height): """Expand a list of strings to exactly width chars and height rows. >>> block = ["abcde", ... "fgh", ... "ijklmno"] >>> result = expand(block, 8, 4) >>> for row in result: ... print (repr(row)) ... 'abcde ' 'fgh ' 'ijklmno ' '' """ if len(rows) > height: raise ValueError('too many rows') extra = ['']*(height - len(rows)) rows = rows + extra for i, row in enumerate(rows): if len(row) > width: raise ValueError('row %d is too wide' % i) rows[i] = row + ' '*(width - len(row)) return rows def join(strings, sep=" "): """Join a list of strings side-by-side, returning a single string. >>> a = '''On peut rire de tout, ... mais pas avec tout le ... monde. ... -- Pierre Desproges''' >>> b = '''You can laugh about ... everything, but not ... with everybody.''' >>> values = ["Quote:", a, b] >>> print (join(values, sep="")) #doctest:+NORMALIZE_WHITESPACE Quote:On peut rire de tout,You can laugh about mais pas avec tout leeverything, but not monde. with everybody. -- Pierre Desproges """ blocks = [s.split('\n') for s in strings] h = max(len(block) for block in blocks) for i, block in enumerate(blocks): w = max(len(row) for row in block) blocks[i] = expand(block, w, h) result = [] for row in zip(*blocks): result.append(sep.join(row)) return '\n'.join(result) -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor