How to prevent truncating of string in unit test python

To replace [… chars] and [truncated]… with actual characters (no matter how long, and no matter what the type of the compared values are), add this to your *_test.py file: if ‘unittest.util’ in __import__(‘sys’).modules: # Show full diff in self.assertEqual. __import__(‘sys’).modules[‘unittest.util’]._MAX_LENGTH = 999999999 Indeed, as other answers have noted, setting self.maxDiff = None doesn’t help, … Read more

Slice a string containing Unicode chars

Possible solutions to codepoint slicing I know I can use the chars() iterator and manually walk through the desired substring, but is there a more concise way? If you know the exact byte indices, you can slice a string: let text = “Hello привет”; println!(“{}”, &text[2..10]); This prints “llo пр”. So the problem is to … Read more

How to convert String to UnsafePointer and length

You have to convert the string to UTF-8 data first let string = “foo bar” let data = string.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)! and then write it to the output stream let outputStream: NSOutputStream = … // the stream that you want to write to let bytesWritten = outputStream.write(UnsafePointer(data.bytes), maxLength: data.length) The UnsafePointer() cast is necessary because … Read more

What is the most efficient way in Python to convert a string to all lowercase stripping out all non-ascii alpha characters?

Another solution (not that pythonic, but very fast) is to use string.translate – though note that this will not work for unicode. It’s also worth noting that you can speed up Dana’s code by moving the characters into a set (which looks up by hash, rather than performing a linear search each time). Here are … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)