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

add upload_media_with_file function. #398

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

add upload_media_with_file function. #398

wants to merge 1 commit into from

Conversation

ghost
Copy link

@ghost ghost commented Oct 8, 2015

This function takes a file name as an argument , there is a function to upload the media on Twitter.

@@ -144,6 +144,10 @@ def upload_media(self, **params):
"""
return self.post('https://upload.twitter.com/1.1/media/upload.json', params=params)

def upload_media_with_file(self, filename):
with open(filename, 'rb') as f:
return self.upload_media(media=f)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we do something like this?

content = None
_file = open(filename, 'rb')
with _file:
    content = self.upload_media(media=_file)

_file.close()
return content

Other versions of Python (not CPython) don't automatically close references.

See http://stackoverflow.com/questions/19039704/is-python-retaining-a-reference-to-a-file-opened-in-a-list

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

Successfully merging this pull request may close these issues.

1 participant