Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Better and simpler Python example #17

Closed
wants to merge 1 commit into from
Closed

Conversation

honzajavorek
Copy link
Contributor

Aims of these changes are:

  • simplify the example
  • introduce the requests library http://docs.python-requests.org/, which is ubiquitous in Python ecosystem these days
  • introduce Python2/Python3 compatibility (tested on both)
  • fix minor issues with formatting and indentation
  • remove unnecessary conversions of body payload according to Content-Type - we already get it as string, we can use it directly as string I suppose

This proposal should supersede both https://github.com/apiaryio/language-templates/tree/python-requests and https://github.com/apiaryio/language-templates/tree/python3 branches. It should also fix #5.

Also fixes https://trello.com/c/Zp06pT75/133-strange-indentation-in-python-examples-in-new-docs (internal).

cc @Almad

Aims of these changes are:
- simplify the example
- introduce the requests library http://docs.python-requests.org/, which is ubiquitous in Python ecosystem these days
- introduce Python2/Python3 compatibility (tested on both)
- fix minor issues with formatting and indentation
- remove unnecessary conversions of body payload according to Content-Type - we already get it as string, we can use it directly as string I suppose

This proposal should supersede both https://github.com/apiaryio/language-templates/tree/python-requests and https://github.com/apiaryio/language-templates/tree/python3 branches. It should also fix #5.
@Almad
Copy link
Contributor

Almad commented Aug 6, 2014

@honzajavorek Internal note: is there an example for v3 as well?

values = dumps(<%= @body %>)
<% else if @method isnt 'GET' and @body: %>
values = <%= @helpers.escape @body %>
<pre class="incoming"><code class="language-python">from __future__ import print_function
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're not passing in any parameters other than the first parameter, there is no need to do from __future__ import print_function. It will only become a tuple if there is a trailing , inside the parenthesis.

$ python2.6

>>> print('example')
example

>>> print('example', 'item')
('example', 'item')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 good point! knew that, but did not realize this fact can simplify the example

@jsarenik
Copy link

Closing until @honzajavorek gets back to it. Can reopen then.

@jsarenik jsarenik closed this Dec 27, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

python template should use 'requests'
4 participants