Even if I googled with Colaboratory cell file output
, it did not come out.
Original story: Cell magics @ ipython
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.
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