Skip to main content

Pythonista and how to get a file from pc to github to ipad


Did ever wanted to code with an ipad... maybe with python? Well, one of the best way to do it is with pythonista... beautiful app that allows you to make beautiful code with python... and even create beautiful games or app with awesome gui.

You may have the wish to bring some code from your pc or mac to pythonista. Even if it is easy do the opposite by email for example, I did't know how to get the code from the pc to the ipad.

So, I went in the forum and I discovered a solution someone have found yet.

You just need to make a program in pythonista and import requests, then create a file with a name that you want that will store the code on the ipad and then grab the code from somewhere in the internet (I put it a github repository, for example) and get the text out of it... and save it to the ipad... that's all... 3 or 4 lines of code and you're done.

Here the code is (and you can make this also elsewhere to grab code from your repository to work on your code in different places and with different instruments...):


import requests as r
with open("gamesofcards.py","w",encoding="utf-8") as file:
    file.write(r.get("https://apprendimento.github.io/gamesofcards.py").text)
print("File copied in the current directory")


File copied in the current directory

Comments

Popular posts from this blog

Widgets for Jupyter Notebook: a text input widget

Widgets for Jupyter notebook ¶ Let's import the module ipywidgets into the Jupyter Notebook from ipywidgets import widgets from ipywidgets import * from traitlets import * Now we import the display function from IPython ¶ let's attach a function to the event on_submit After we run this cell, we can go up and write something in the text widget and after you submit the text you wrote will be printed after the cell from IPython.display import display text = widgets . Text () display ( text ) def handle_submit ( sender ): print ( "Thank you for entering this text:" , text . value ) text . on_submit ( handle_submit ) Thank you for entering this text: Ciao

Image in Jupyter and PIL step by step

Hi, """ Hi, we will see a step by step tutorial about PIL and IPython.core.display modules to create images from other images and diplaying them in Jupyter notebook """ # What we will do # Create a card # 1. Take a pic of a heart # 2. Create an image blanck the size of a card 90*130 # 3. Paste the heart in the middle # 4. show the card """ As first step wi will simply display an image on the notebook. I will show two way to display the image with 'display' from IPhyton a. Using the open method of PIL.Image (named Img) b. Using the Image method from the IPython.core.display module """ # 1. Take the pic of a heart from IPython.core.display import Image , display from PIL import Image as Img heart = 'img/heart.png' display ( Image ( heart )) display ( Img . open ( heart )) # 2. Create an image blanck the size of a card 90*130 # 3. Paste the heart in the middle #...

Let's draw a circle with PIL in Python

Let's continue making our coding around PIL. Let's start with some basic drawing: a circle from PIL import Image , ImageDraw img = Image . new ( "RGB" ,( 60 , 60 ), 'white' ) dr = ImageDraw . Draw ( img ) dr . ellipse (( 0 , 0 , 60 , 60 ), 'yellow' ) img . show () this is the image produced *If you use jupyter notebook, just write img at the end to see the output.