Output cell to file with Colaboratory

Even if I googled with Colaboratory cell file output, it did not come out.

Original story: Cell magics @ ipython

manner

yesno.py


%%writefile yesno.py
#!/usr/bin/env python

import re

def main():
  check=input('Please enter Yes or No:')
  print(YN(check))

def YN(string):
  if re.match('(?i)ye?s?',string):
    return 'YES'
  elif re.match('(?i)no?',string):
    return 'NO'
  else: return 'Yes/Not no'

if __name__ == '__main__':
  main()

%% writefile yesno.py is the command

If you check with ! cat -n yes no.py

 1	#!/usr/bin/env python
 2	
 3	import re
 4	
 5	def main():

6 check = input ('Please enter Yes or No:') 7 print(YN(check)) 8 9 def YN(string): 10 if re.match('(?i)ye?s?',string): 11 return'YES' 12 elif re.match('(?i)no?',string): 13 return'NO' 14 else: return'Yes/No' 15 16 if name == 'main': 17 main() The file is output immediately after the command, so be careful when describing the shebang.

This

check.py


import yesno

if yesno.YN(('Yes')) == 'YES': print('Yeah')

Result: Yeah

You will be able to use it.

Summary

When studying Python with Colaboratory, there are times when I am at a loss as to how to do the tasks written based on local files.

If you use it together with Download file with Python, you can probably do it with Colaboratory.

Recommended Posts

Output cell to file with Colaboratory
Output to syslog with Loguru
[Python] Write to csv file with Python
Write standard output to a file
Try to output audio with M5STACK
Make it possible to output a log to a file with go echo
Output color characters to pretty with python
Output Python log to console with GAE
How to search Google Drive with Google Colaboratory
Rich cell output with Jupyter Notebook (IPython)
How to read a CSV file with Python 2/3
I want to knock 100 data sciences with Colaboratory
[Python] How to read excel file with pandas
Convert svg file to png / ico with Python
I tried to output LLVM IR with Python
Output python log to both console and file
Save the object to a file with pickle
I want to write to a file with Python
Create a cylinder with open3d + STL file output
Output test function docstring to report with pytest-html
2017-02-19 Python> Link> Redirect to output file immediately> sys.stdout.flush ()
To output a value even in the middle of a cell with Jupyter Notebook
Procedure to load MNIST with python and output to png
Output PDF with Django
Markdown output with Django
Convert 202003 to 2020-03 with pandas
Convert a text file with hexadecimal values to a binary file
I tried to touch the CSV file with Python
How to load files in Google Drive with Google Colaboratory
Output log to console with Flask + Nginx on Docker
How to measure mp3 file playback time with python
Output PDF with WeasyPrint
How to output CSV of multi-line header with pandas
How to convert JSON file to CSV file with Python Pandas
File upload with django
Read json file with Python, format it, and output json
[Python-pptx] Output PowerPoint font information to csv with python
How to analyze with Google Colaboratory using Kaggle API
Output a binary dump in binary and revert to a binary file
Building an environment to use CaboCha with google colaboratory
How to put a hyperlink to "file: // hogehoge" with sphinx-> pdf
How to check ORM behavior in one file with django
Until you edit an SVG file with AutoCAD to PNG.
Output CloudWatch Logs to S3 with AWS Lambda (Pythyon ver)
[Python Kivy] How to create an exe file with pyinstaller
[Python] How to output a pandas table to an excel file
How to read an Excel file (.xlsx) with Pandas [Python]
I tried to divide the file into folders with Python
Try to decipher the garbled attachment file name with Python
How to output additional information when logging with python's logging module
Try to implement linear regression using Pytorch with Google Colaboratory
Try to factorial with recursion
Connect to BigQuery with Python
Convert HTML to text file
Draw netCDF file with python
Test standard output with Pytest
Post to slack with Python 3
Study Python with Google Colaboratory
Connect to Postgresql with GO
Upload a file to Dropbox
Fast file transfer with fabric