Tuesday, 15 February 2011

python - Pythonic way of reading text file using Swift -


I know the dragon and I'm trying to learn Swift ... I'm trying to explain how A plain text file with a full file path

In Python,

  #! Open file to read for line in / usr / bin / python path = '/users/mu/desktop/test_file.txt' in_file In_file.split ('\ n'): #Open (Path, 'W') . Read (to read the # Open Line) Open the file and print the line print  

Try this: Understand: "No member name string in string is Wide Contentofffile"

In Python, it's so easy. There should be a very easy way to read a text file and make a list of strings separated by line breaks.

My question is how to read a text file so that you can repeat through lines <

  {println (line)} for the line in the in_file  

You can use NSFileManager and NSString to parse lines eg:

  var path = "somePath" file manager = NSFileManager.defaultManager (): Give data: NSData = fileManager.contentsAtPath (path)! Var strs = NSString (data: data, encoding: NSUTF8StringEncoding)  

No comments:

Post a Comment