Python: Difference between revisions
No edit summary |
No edit summary |
||
Line 20: | Line 20: | ||
gazeFiles = [path.join(x, y) for x in gazeFolders for y in os.listdir(x)] | gazeFiles = [path.join(x, y) for x in gazeFolders for y in os.listdir(x)] | ||
</syntaxhighlight> | </syntaxhighlight> | ||
===Read entire text file into a list=== | |||
[https://stackoverflow.com/questions/3925614/how-do-you-read-a-file-into-a-list-in-python/3925701] | |||
<syntaxhighlight lang="python"> | |||
with open('C:/path/numbers.txt') as f: | |||
lines = f.read().splitlines() | |||
</syntaxhighlight> | |||
=Libraries= | =Libraries= | ||
==Numpy== | ==Numpy== |
Revision as of 18:59, 23 September 2019
Installation
Use Anaconda.
Basic Usage
Lambda Function
lambda x: x * 2
Filesystem Read and Write
List all files in a folder
gazeDir = "Gaze_txt_files"
# List of folders in root folder
gazeFolders = [path.join(gazeDir, x) for x in os.listdir(gazeDir)]
# List of files 2 folders down
gazeFiles = [path.join(x, y) for x in gazeFolders for y in os.listdir(x)]
Read entire text file into a list
with open('C:/path/numbers.txt') as f:
lines = f.read().splitlines()